package com.changhong.epc.form.service.budget.impl;
|
|
import com.changhong.autoform.entity.WorkFlowStateEntity;
|
import com.changhong.epc.bean.form.BorrowType;
|
import com.changhong.epc.bean.form.FormDataEntity;
|
import com.changhong.epc.bean.tenant.cost.CostFromMapping;
|
import com.changhong.epc.bean.tenant.system.SystemConfig;
|
import com.changhong.epc.bean.tenant.system.SystemForm;
|
import com.changhong.epc.config.tool.ContextEnvironment;
|
import com.changhong.epc.constter.system.SystemClients;
|
import com.changhong.epc.constter.system.businesscode.BudgetBusinessMeaningCode;
|
import com.changhong.epc.form.mapper.tenant.FormDataMapper;
|
import com.changhong.epc.form.service.budget.CheckFormDataServes;
|
import com.changhong.epc.form.service.budget.department.model.BudgetExtend;
|
import com.changhong.epc.form.tool.FormNameTool;
|
import com.changhong.epc.rely.api.epc.tenant.SystemConfigApi;
|
import com.iemsoft.framework.cloud.core.tools.ObjectUtil;
|
import com.iemsoft.framework.cloud.core.tools.SpringUtil;
|
|
import org.apache.commons.lang3.math.NumberUtils;
|
import org.springframework.stereotype.Service;
|
|
import javax.annotation.Resource;
|
import java.util.ArrayList;
|
import java.util.List;
|
import java.util.Map;
|
import java.util.Objects;
|
import java.util.stream.Collectors;
|
|
@Service("checkFormDataServes")
|
public class CheckFormDataServesImpl implements CheckFormDataServes , BudgetBusinessMeaningCode,SystemClients{
|
|
@Resource
|
private FormDataMapper formDataMapper;
|
|
//@Resource
|
//private IFormOthersOperation formOthersOperation;
|
|
@Override
|
public boolean checkData(WorkFlowStateEntity workFlowStateEntity) {
|
//FormType type = GetConstant.getFormType(workFlowStateEntity.getFormId());
|
|
String type = GetConstant.getMeaningByMdCode(workFlowStateEntity.getFormId()+"_type");
|
|
// System.out.println("表单类型"+type);
|
switch (type) {
|
case YS:
|
return this.checkYS(workFlowStateEntity);//预算验证上级预算余额 ok
|
case SQ:
|
return this.checkSQ(workFlowStateEntity);//申请验证预算单余额 ok
|
case BX:
|
return this.checkBX(workFlowStateEntity);//报销 验证申请单 余额 ok
|
case ZJYS:
|
return this.checkZJYS(workFlowStateEntity);//追加预算验证上级预算余额 ok
|
case HSYS:
|
return this.checkTHYS(workFlowStateEntity);//回收预算验证本条预算余额 ok
|
case HTBX:
|
return this.checkHT(workFlowStateEntity);//合同报销验证预算 ok
|
case GDZCBX:
|
return this.checkGDZCBX(workFlowStateEntity);//固定资产报销单
|
}
|
return true;
|
}
|
|
/**
|
*验证 固定资产报销单
|
*
|
*/
|
public boolean checkGDZCBX(WorkFlowStateEntity workFlowStateEntity){
|
// System.out.println("固定资产报销单:+++"+JSONTool.toJson(workFlowStateEntity));
|
String formName = FormNameTool.getSubFormTableName(workFlowStateEntity.getTenantId(),workFlowStateEntity.getFormId());
|
FormDataEntity formDataEntity = new FormDataEntity();
|
formDataEntity.setFormName(formName);
|
formDataEntity.setDataRowNum(workFlowStateEntity.getDataRowNum());
|
Map<String ,Object> selfData = formDataMapper.searchFormData(formDataEntity);
|
String formId = GetConstant.getFormIdGetConstant(SystemForm.BUDGET_FORM_ID.name());//预算单id
|
formName = FormNameTool.getSubFormTableName(workFlowStateEntity.getTenantId(),formId,BUDGET_SUB_FROM);
|
formDataEntity.setFormName(formName);
|
formDataEntity.setDataRowNum(Integer.parseInt(Objects.toString(selfData.get(TO_WRITE_BUDGET))));
|
Map<String ,Object> father = formDataMapper.searchFormData(formDataEntity);
|
//报销金额合计 expendUseMoney 《= 预算余额 budget_itemBalance
|
// System.out.println("固定资产报销单金额:"+Integer.parseInt(Objects.toString(selfData.get(EXPEND_USE_MONEY))));
|
// System.out.println("选择预算单余额:"+Integer.parseInt(Objects.toString(father.get(BUDGET_ITEM_BALANCE))));
|
if(Integer.parseInt(Objects.toString(father.get(BUDGET_ITEM_BALANCE))) < Integer.parseInt(Objects.toString(selfData.get(EXPEND_USE_MONEY)))){
|
return false;
|
}
|
return true;
|
}
|
|
|
/**
|
*验证预算
|
*
|
*/
|
public boolean checkYS(WorkFlowStateEntity workFlowStateEntity){
|
// System.out.println("预算:+++"+JSONTool.toJson(workFlowStateEntity));
|
String formName = FormNameTool.getSubFormTableName(workFlowStateEntity.getTenantId(),workFlowStateEntity.getFormId());
|
FormDataEntity formDataEntity = new FormDataEntity();
|
formDataEntity.setFormName(formName);
|
formDataEntity.setDataRowNum(workFlowStateEntity.getDataRowNum());
|
//获取本条预算单数据
|
Map<String ,Object> selfData = formDataMapper.searchFormData(formDataEntity);
|
//如果有上级预算 判断 没有 返回true
|
if(selfData.get(TO_WRITE_BUDGET) != null && !"".equals(selfData.get(TO_WRITE_BUDGET))){
|
formName = FormNameTool.getSubFormTableName(workFlowStateEntity.getTenantId(),workFlowStateEntity.getFormId(),BUDGET_SUB_FROM);
|
formDataEntity.setFormName(formName);
|
formDataEntity.setParentDataRowNum(Integer.parseInt(Objects.toString(selfData.get(TO_WRITE_BUDGET))));
|
List<Map<String,Object>> father = formDataMapper.searchSubFormDataList(formDataEntity);
|
formDataEntity.setParentDataRowNum(workFlowStateEntity.getDataRowNum());
|
List<Map<String,Object>> self = formDataMapper.searchSubFormDataList(formDataEntity);
|
for(Map se : self){
|
for(Map fa : father){
|
if (se.get(BUDGET_ITEM_COST_TYPE).equals(fa.get(BUDGET_ITEM_COST_TYPE)) && se.get(BUDGET_SUPER_DEPARTEMENT).equals(fa.get(BUDGET_ITEM_DEPARTMENT))) { //第二个判断是后追加的
|
// System.out.println("预算单预算金额:"+Integer.parseInt(Objects.toString(se.get(BUDGET_ITEM_MONEY))));
|
// System.out.println("上级预算单余额:"+Integer.parseInt(Objects.toString(fa.get(BUDGET_ITEM_BALANCE))));
|
|
if (Integer.parseInt(Objects.toString(fa.get(BUDGET_ITEM_BALANCE))) < Integer.parseInt(Objects.toString(se.get(BUDGET_ITEM_MONEY)))) {
|
return false;
|
}
|
}
|
}
|
}
|
}
|
return true;
|
}
|
|
/**
|
*验证预算追加
|
*
|
*/
|
public boolean checkZJYS(WorkFlowStateEntity workFlowStateEntity){
|
// System.out.println("追加预算:+++"+JSONTool.toJson(workFlowStateEntity));
|
String formName = FormNameTool.getSubFormTableName(workFlowStateEntity.getTenantId(),workFlowStateEntity.getFormId());
|
FormDataEntity formDataEntity = new FormDataEntity();
|
formDataEntity.setFormName(formName);
|
formDataEntity.setDataRowNum(workFlowStateEntity.getDataRowNum());
|
//获取本条追加预算单数据 为了拿到预算单id
|
Map<String ,Object> selfData = formDataMapper.searchFormData(formDataEntity);
|
//获取到预算单
|
String formId = GetConstant.getFormIdGetConstant(SystemForm.BUDGET_FORM_ID.name());//预算单id
|
formName = FormNameTool.getSubFormTableName(workFlowStateEntity.getTenantId(),formId);
|
formDataEntity.setFormName(formName);
|
formDataEntity.setDataRowNum(Integer.parseInt(Objects.toString(selfData.get(CHOOSE_SUPER_BUDGET))));
|
//获取预算单
|
Map<String ,Object> father = formDataMapper.searchFormData(formDataEntity);
|
//获取上级预算单
|
//如果有上级预算 判断 没有 返回true
|
if(father.get(TO_WRITE_BUDGET) != null && !"".equals(father.get(TO_WRITE_BUDGET))){
|
formName = FormNameTool.getSubFormTableName(workFlowStateEntity.getTenantId(),formId,BUDGET_SUB_FROM);
|
formDataEntity.setFormName(formName);
|
formDataEntity.setParentDataRowNum(Integer.parseInt(Objects.toString(selfData.get(CHOOSE_SUPER_BUDGET))));
|
//本级预算单的子表单
|
List<Map<String,Object>> fatherData = formDataMapper.searchSubFormDataList(formDataEntity);
|
|
|
|
|
formName = FormNameTool.getSubFormTableName(workFlowStateEntity.getTenantId(),formId,BUDGET_SUB_FROM);
|
formDataEntity.setFormName(formName);
|
formDataEntity.setParentDataRowNum(Integer.parseInt(Objects.toString(father.get(TO_WRITE_BUDGET))));
|
//上级预算单的子表单
|
List<Map<String,Object>> grFather = formDataMapper.searchSubFormDataList(formDataEntity);
|
//预算追加的子表单数据
|
formName = FormNameTool.getSubFormTableName(workFlowStateEntity.getTenantId(),workFlowStateEntity.getFormId(),BUDGET_SUB_FROM);
|
formDataEntity.setFormName(formName);
|
formDataEntity.setParentDataRowNum(workFlowStateEntity.getDataRowNum());
|
List<Map<String,Object>> self = formDataMapper.searchSubFormDataList(formDataEntity);
|
for(Map se : self){
|
for(Map fa : fatherData){
|
if(se.get(BUDGET_ITEM_DEPARTMENT).equals(fa.get(BUDGET_ITEM_DEPARTMENT)) && se.get(BUDGET_ITEM_COST_TYPE).equals(fa.get(BUDGET_ITEM_COST_TYPE))){
|
for(Map gfa : grFather){
|
if (fa.get(BUDGET_ITEM_COST_TYPE).equals(gfa.get(BUDGET_ITEM_COST_TYPE)) && fa.get(BUDGET_SUPER_DEPARTEMENT).equals(gfa.get(BUDGET_ITEM_DEPARTMENT))) {
|
// System.out.println("预算追加金额:"+Integer.parseInt(Objects.toString(se.get(BUDGET_ADDITIONALMONEY))));
|
// System.out.println("上级预算单余额:"+Integer.parseInt(Objects.toString(gfa.get(BUDGET_ITEM_BALANCE))));
|
if (Integer.parseInt(Objects.toString(gfa.get(BUDGET_ITEM_BALANCE))) < Integer.parseInt(Objects.toString(se.get(BUDGET_ADDITIONALMONEY)))) {
|
return false;
|
}
|
}
|
}
|
}
|
}
|
|
}
|
}else{
|
// System.out.println("没有上级预算,不需要验证");
|
}
|
return true;
|
}
|
|
/**
|
*验证退回回收
|
*
|
*/
|
public boolean checkTHYS(WorkFlowStateEntity workFlowStateEntity){
|
// System.out.println("退回预算:+++"+JSONTool.toJson(workFlowStateEntity));
|
String formName = FormNameTool.getSubFormTableName(workFlowStateEntity.getTenantId(),workFlowStateEntity.getFormId());
|
FormDataEntity formDataEntity = new FormDataEntity();
|
formDataEntity.setFormName(formName);
|
formDataEntity.setDataRowNum(workFlowStateEntity.getDataRowNum());
|
//获取本条回收预算单数据 为了拿到预算单id
|
Map<String ,Object> selfData = formDataMapper.searchFormData(formDataEntity);
|
|
//获取本条回收子表单数据
|
formName = FormNameTool.getSubFormTableName(workFlowStateEntity.getTenantId(),workFlowStateEntity.getFormId(),BUDGET_SUB_FROM);
|
formDataEntity.setFormName(formName);
|
formDataEntity.setParentDataRowNum(workFlowStateEntity.getDataRowNum());
|
List<Map<String,Object>> self = formDataMapper.searchSubFormDataList(formDataEntity);//追加数据
|
|
String formId = GetConstant.getFormIdGetConstant(SystemForm.BUDGET_FORM_ID.name());//预算单id
|
formName = FormNameTool.getSubFormTableName(workFlowStateEntity.getTenantId(),formId,BUDGET_SUB_FROM);
|
formDataEntity.setFormName(formName);
|
formDataEntity.setParentDataRowNum(Integer.parseInt(Objects.toString(selfData.get(CHOOSE_SUPER_BUDGET))));
|
|
List<Map<String,Object>> father = formDataMapper.searchSubFormDataList(formDataEntity);//选择的预算单数据(子表单)
|
for(Map se : self){
|
for(Map fa : father){
|
if (se.get(BUDGET_ITEM_COST_TYPE).equals(fa.get(BUDGET_ITEM_COST_TYPE)) && se.get(BUDGET_ITEM_DEPARTMENT).equals(fa.get(BUDGET_ITEM_DEPARTMENT))) {
|
// System.out.println("回收预算金额:"+Integer.parseInt(Objects.toString(se.get(BUDGET_ADDITIONALMONEY))));
|
// System.out.println("预算单余额:"+Integer.parseInt(Objects.toString(fa.get(BUDGET_ITEM_BALANCE))) );
|
if (Integer.parseInt(Objects.toString(fa.get(BUDGET_ITEM_BALANCE))) < Integer.parseInt(Objects.toString(se.get(BUDGET_ADDITIONALMONEY)))) {
|
return false;
|
}
|
}
|
}
|
}
|
return true;
|
}
|
|
/**
|
*验证 申请使用预算
|
*
|
*/
|
public boolean checkSQ(WorkFlowStateEntity workFlowStateEntity){
|
// System.out.println("申请:+++"+JSONTool.toJson(workFlowStateEntity));
|
String formName = FormNameTool.getSubFormTableName(workFlowStateEntity.getTenantId(),workFlowStateEntity.getFormId());
|
FormDataEntity formDataEntity = new FormDataEntity();
|
formDataEntity.setFormName(formName);
|
formDataEntity.setDataRowNum(workFlowStateEntity.getDataRowNum());
|
//获取本条申请单数据 为了拿到预算单子表单 datarownum
|
Map<String ,Object> selfData = formDataMapper.searchFormData(formDataEntity);
|
String formId = GetConstant.getFormIdGetConstant(SystemForm.BUDGET_FORM_ID.name());//预算单id
|
formName = FormNameTool.getSubFormTableName(workFlowStateEntity.getTenantId(),formId,BUDGET_SUB_FROM);
|
formDataEntity.setFormName(formName);
|
formDataEntity.setDataRowNum(Integer.parseInt(Objects.toString(selfData.get(TO_WRITE_BUDGET))));
|
Map<String ,Object> father = formDataMapper.searchFormData(formDataEntity);
|
|
// System.out.println("申请使用金额:"+Integer.parseInt(Objects.toString(selfData.get(APPLY_USE_MONEY))));
|
// System.out.println("预算单余额:"+Integer.parseInt(Objects.toString(father.get(BUDGET_ITEM_BALANCE))));
|
if(Integer.parseInt(Objects.toString(father.get(BUDGET_ITEM_BALANCE))) < Integer.parseInt(Objects.toString(selfData.get(APPLY_USE_MONEY)))){
|
return false;
|
}
|
return true;
|
}
|
|
|
/**
|
*验证 报销 使用 申请
|
*
|
*/
|
public boolean checkBX(WorkFlowStateEntity workFlowStateEntity){
|
// System.out.println("报销:+++"+JSONTool.toJson(workFlowStateEntity));
|
|
//获取本条数据
|
String formName = FormNameTool.getSubFormTableName(workFlowStateEntity.getTenantId(),workFlowStateEntity.getFormId());
|
FormDataEntity formDataEntity = new FormDataEntity();
|
formDataEntity.setFormName(formName);
|
formDataEntity.setDataRowNum(workFlowStateEntity.getDataRowNum());
|
Map<String ,Object> selfData = formDataMapper.searchFormData(formDataEntity);
|
|
//获取申请单数据
|
String formId = GetConstant.getFormIdGetConstant(SQ_FORMID);//申请单id
|
formName = FormNameTool.getSubFormTableName(workFlowStateEntity.getTenantId(),formId);
|
formDataEntity.setFormName(formName);
|
formDataEntity.setDataRowNum(Integer.parseInt(Objects.toString(selfData.get(TO_WRITE_BUDGET))));
|
Map<String ,Object> fatherData = formDataMapper.searchFormData(formDataEntity);
|
//比较 申请金额 小于 报销金额 返回false
|
// System.out.println("报销金额:"+Integer.parseInt(Objects.toString(selfData.get(EXPEND_USE_MONEY))));
|
// System.out.println("申请单余额:"+Integer.parseInt(Objects.toString(fatherData.get(APPLY_USE_MONEY))));
|
if(Integer.parseInt(Objects.toString(fatherData.get(APPLY_USE_MONEY))) < Integer.parseInt(Objects.toString(selfData.get(EXPEND_USE_MONEY)))){
|
return false;
|
}
|
return true;
|
}
|
|
/**
|
*验证合同报销单 使用预算
|
*/
|
private boolean checkHT(WorkFlowStateEntity workFlowStateEntity){
|
// System.out.println("合同报销单:+++"+JSONTool.toJson(workFlowStateEntity));
|
String formName = FormNameTool.getSubFormTableName(workFlowStateEntity.getTenantId(),workFlowStateEntity.getFormId());
|
FormDataEntity formDataEntity = new FormDataEntity();
|
formDataEntity.setFormName(formName);
|
formDataEntity.setDataRowNum(workFlowStateEntity.getDataRowNum());
|
Map<String ,Object> selfData = formDataMapper.searchFormData(formDataEntity);
|
|
String formId = GetConstant.getFormIdGetConstant(SystemForm.BUDGET_FORM_ID.name());//预算单id
|
formName = FormNameTool.getSubFormTableName(workFlowStateEntity.getTenantId(),formId,BUDGET_SUB_FROM);
|
formDataEntity.setFormName(formName);
|
formDataEntity.setDataRowNum(Integer.parseInt(Objects.toString(selfData.get(TO_WRITE_BUDGET))));
|
Map<String ,Object> father = formDataMapper.searchFormData(formDataEntity);
|
//报销金额合计 expendUseMoney 《= 预算余额 budget_itemBalance
|
// System.out.println("合同报销金额:"+ Integer.parseInt(Objects.toString(selfData.get(EXPEND_USE_MONEY))));
|
// System.out.println("预算单余额:"+Integer.parseInt(Objects.toString(father.get(BUDGET_ITEM_BALANCE))));
|
if(Integer.parseInt(Objects.toString(father.get(BUDGET_ITEM_BALANCE))) < Integer.parseInt(Objects.toString(selfData.get(EXPEND_USE_MONEY)))){
|
return false;
|
}
|
return true;
|
}
|
|
@Override
|
public List<Map<String, Object>> getSumAlreadyPaid(BudgetExtend budgetExtend) {
|
//取出合同报销单Id
|
List<SystemConfig> config = SpringUtil.getBean(SystemConfigApi.class)
|
.getSystemConfigs(SystemConfig.of(FORM_INFO,null));
|
String formId = null;
|
for(SystemConfig con :config){
|
if(SystemForm.CONTRACT_EXPEND_FORM_ID.toString().equals(con.getCkey())){
|
formId = con.getCvalue();
|
break;
|
}
|
}
|
String formName = "formdata_"+budgetExtend.getTenantID()+"_"+formId;
|
List<Integer> list = formDataMapper.selectDataRows(formName, budgetExtend.getDatarowNum(),budgetExtend.getCurrDataRowNum());
|
if(list ==null || list.size()<=0){
|
return new ArrayList<>();
|
}
|
String subFormName = formName+"_subform";
|
return formDataMapper.getSumAlreadyPaid(subFormName,list);
|
|
}
|
|
@Override
|
public Integer checkReimbursement(String borrowMoneyUser, BorrowType borrowType) {
|
// 查询备用金还款
|
ContextEnvironment context = new ContextEnvironment();
|
// 备用金借款
|
if(borrowType == BorrowType.estimateRepaymentReserve) {
|
String day = context.getSystemConfig("estimateRepayment", borrowType.name());
|
if(!NumberUtils.isNumber(day)){
|
return 0;
|
}
|
// 还款
|
String repaymentFormId = context.getSystemConfig(FORM_INFO, SystemForm.REPAYMENT_FORM_ID.name());
|
// 借款
|
String loanFormId = context.getSystemConfig(FORM_INFO, SystemForm.LOAN_FORM_ID.name());
|
|
return formDataMapper.selectRepayment(borrowMoneyUser, repaymentFormId, loanFormId, Integer.valueOf(day));
|
}
|
// 费用借款
|
else {
|
String day = context.getSystemConfig("estimateRepayment", borrowType.name());
|
if(!NumberUtils.isNumber(day)){
|
return 0;
|
}
|
// 查询费用类还款
|
List<CostFromMapping> applyFormIds = formDataMapper.selectApplyFormIds();
|
if (ObjectUtil.empty(applyFormIds)) {
|
return 0;
|
}
|
List<String> formIds = applyFormIds.stream().map(CostFromMapping::getFId).collect(Collectors.toList());
|
return formDataMapper.selectApplyRepayment(formIds, borrowMoneyUser);
|
}
|
}
|
|
}
|