diff --git a/pom.xml b/pom.xml index e10c5f69..d7146001 100644 --- a/pom.xml +++ b/pom.xml @@ -114,6 +114,7 @@ ${fastjson.version} + com.github.pagehelper pagehelper-spring-boot-starter diff --git a/src/main/java/com/qs/serve/common/util/JsonUtil.java b/src/main/java/com/qs/serve/common/util/JsonUtil.java index 2e7c66b7..69fae846 100644 --- a/src/main/java/com/qs/serve/common/util/JsonUtil.java +++ b/src/main/java/com/qs/serve/common/util/JsonUtil.java @@ -7,6 +7,7 @@ import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.JavaType; import com.fasterxml.jackson.databind.MapperFeature; import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule; import lombok.experimental.UtilityClass; import java.util.ArrayList; @@ -31,6 +32,7 @@ public class JsonUtil { static { MAPPER.configure(MapperFeature.ACCEPT_CASE_INSENSITIVE_PROPERTIES, true); MAPPER.setSerializationInclusion(JsonInclude.Include.NON_NULL); + //MAPPER.registerModule(new JavaTimeModule()); } /** diff --git a/src/main/java/com/qs/serve/modules/tbs/common/TbsSeeYonConst.java b/src/main/java/com/qs/serve/modules/tbs/common/TbsSeeYonConst.java index d75ccb76..24bd83b8 100644 --- a/src/main/java/com/qs/serve/modules/tbs/common/TbsSeeYonConst.java +++ b/src/main/java/com/qs/serve/modules/tbs/common/TbsSeeYonConst.java @@ -24,6 +24,12 @@ public interface TbsSeeYonConst { return DevEnvironmentConfig.isDev()?"CostBill_Test":"CostBill"; } } + /** 费用申请2-协议类 */ + class CostApplyContractConf{ + public static String Code(){ + return DevEnvironmentConfig.isDev()?"contractApply_Test":"contractApply"; + } + } /** 核销 */ class CostCheckConf{ diff --git a/src/main/java/com/qs/serve/modules/tbs/entity/dto/TbsContractCostSubItem.java b/src/main/java/com/qs/serve/modules/tbs/entity/dto/TbsContractCostSubItem.java new file mode 100644 index 00000000..34cf01ed --- /dev/null +++ b/src/main/java/com/qs/serve/modules/tbs/entity/dto/TbsContractCostSubItem.java @@ -0,0 +1,53 @@ +package com.qs.serve.modules.tbs.entity.dto; + +import lombok.AllArgsConstructor; +import lombok.Data; + +import java.math.BigDecimal; +import java.time.LocalDate; + +/** + * @author YenHex + * @since 2023/5/9 + */ +public class TbsContractCostSubItem { + + @Data + public static class Activity{ + private String activityCode; + private String activityPurpose; + private String costCode; + private String startDate; + private String endDate; + private String writeOffDate; + private String productType; + private String product; + private String accountCode; + private String accountName; + private String costCenterNo; + private String costCenterName; + private BigDecimal applyMoney; + + } + + @Data + public static class Payment{ + private String payItem; + private String payCondition; + private BigDecimal money; + private String payDate; + private String actualPayDate; + private Integer payCompleteState; + private String payRemark; + } + + @Data + public static class ToDoItem{ + private String serviceDescription; + private String deliveryStandard; + private String deliveryDate; + private String agreeRemark; + + } + +} diff --git a/src/main/java/com/qs/serve/modules/tbs/service/impl/TbsCostApplyOperationServiceImpl.java b/src/main/java/com/qs/serve/modules/tbs/service/impl/TbsCostApplyOperationServiceImpl.java index c5e8502f..783fc9ad 100644 --- a/src/main/java/com/qs/serve/modules/tbs/service/impl/TbsCostApplyOperationServiceImpl.java +++ b/src/main/java/com/qs/serve/modules/tbs/service/impl/TbsCostApplyOperationServiceImpl.java @@ -5,10 +5,20 @@ import com.qs.serve.common.model.enums.BudgetLogOptFlag; import com.qs.serve.common.model.consts.BudgetLogRollbackFlag; import com.qs.serve.common.model.dto.R; import com.qs.serve.common.util.Assert; +import com.qs.serve.common.util.AuthContextUtils; +import com.qs.serve.common.util.SpringUtils; +import com.qs.serve.common.util.StringUtils; import com.qs.serve.modules.seeyon.entity.CtpAffair; +import com.qs.serve.modules.seeyon.entity.SyAffairStateResult; +import com.qs.serve.modules.seeyon.entity.bo.CtpAddNodeDTO; +import com.qs.serve.modules.seeyon.entity.bo.CtpAddNodeParam; +import com.qs.serve.modules.seeyon.enums.SyAffairState; import com.qs.serve.modules.seeyon.service.SeeYonOperationService; import com.qs.serve.modules.seeyon.service.SeeYonRequestService; +import com.qs.serve.modules.sys.entity.SysPostUser; +import com.qs.serve.modules.sys.entity.SysUser; import com.qs.serve.modules.sys.mapper.SysUserMapper; +import com.qs.serve.modules.sys.service.SysPostUserService; import com.qs.serve.modules.sys.service.SysUserService; import com.qs.serve.modules.tbs.common.TbsActivityState; import com.qs.serve.modules.tbs.common.TbsCostApplyState; @@ -28,7 +38,10 @@ import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Service; import java.time.LocalDateTime; +import java.util.ArrayList; import java.util.List; +import java.util.Locale; +import java.util.Map; import java.util.stream.Collectors; /** @@ -68,11 +81,101 @@ public class TbsCostApplyOperationServiceImpl implements SeeYonOperationService return TbsSeeYonConst.CostApplyConf.Code(); } + + @Override + public String checkAffairSummery(String targetId) { + TbsCostApply tbsCostApply = costApplyService.getById(targetId); + String templateCode = getTemplateCode(); + if(tbsCostApply.getContractFlag()!=null&&tbsCostApply.getContractFlag().equals(1)){ + templateCode = TbsSeeYonConst.CostApplyContractConf.Code(); + } + R result = getRequestService().checkAffairSummery(templateCode,targetId); + if(result.getData()==null){ + return "next"; + } + return result.getData(); + } + + @Override + public R addNode(CtpAddNodeParam param) { + getRequestService().testConnection(); + TbsCostApply tbsCostApply = costApplyService.getById(param.getTargetId()); + CtpAddNodeDTO addNodeDTO = new CtpAddNodeDTO(); + addNodeDTO.setBackToMe(param.getBackToMe()); + addNodeDTO.setTargetId(param.getTargetId()); + List selectUserIds = new ArrayList<>(); + SysUser loginUser = getUserMapper().selectById(AuthContextUtils.getSysUserId()); + for (String userId : param.getUserIds()) { + SysUser user = getUserMapper().selectById(userId); + if(loginUser.getSyUserId().equals(user.getSyUserId())){ + return R.error("不能选择相同的OA账号的员工"); + } + if(StringUtils.hasText(user.getSyUserId())&&!user.getSyUserId().equals("0")){ + selectUserIds.add(user.getSyUserId()); + } + } + if(selectUserIds.size()==0){ + Assert.throwEx("选中的用户未绑定OA凭证"); + } + addNodeDTO.setUserIds(selectUserIds); + SysUser sysUser = getUserMapper().selectById(AuthContextUtils.getSysUserId()); + addNodeDTO.setUserCode(sysUser.getAccount()); + addNodeDTO.setUserSyId(sysUser.getSyUserId()); + String templateCode = getTemplateCode(); + if(tbsCostApply.getContractFlag()!=null&&tbsCostApply.getContractFlag().equals(1)){ + templateCode = TbsSeeYonConst.CostApplyContractConf.Code(); + } + addNodeDTO.setTemplateCode(templateCode); + R result = getRequestService().addNode(addNodeDTO); + if(result.getData()!=null&&result.getData().toLowerCase(Locale.ROOT).contains("ok")){ + return R.ok(); + } + return R.error(result.getMsg()); + } + @Override public SeeYonRequestService getRequestService() { return requestService; } + @Override + public R> pageAffair(String targetId) { + boolean existFormId = checkSyFormIdIsNotNull(targetId); + if (!existFormId){ + return R.ok(new ArrayList<>()); + } + String templateCode = getTemplateCode(); + TbsCostApply costApply = costApplyService.getById(targetId); + if(costApply.getContractFlag()!=null&&costApply.getContractFlag().equals(1)){ + templateCode = TbsSeeYonConst.CostApplyContractConf.Code(); + } + R> syResult = getRequestService().commonListAffairs(targetId,null,templateCode); + List ctpAffairs = syResult.getData(); + if(ctpAffairs.size()>0){ + List oaUserIds = ctpAffairs.stream().map(CtpAffair::getMemberId).collect(Collectors.toList()); + List userList = getSysUserService().listByOaMemberIds(oaUserIds); + SysPostUserService postUserService = SpringUtils.getBean(SysPostUserService.class); + List userIds = userList.stream().map(SysUser::getId).collect(Collectors.toList()); + List postUserList = postUserService.listByUserIds(userIds); + Map> postMap = postUserList.stream().collect(Collectors.groupingBy(SysPostUser::getUserId)); + List result = new ArrayList<>(); + for (CtpAffair ctpAffair : ctpAffairs) { + CtpAffairVo ctpAffairVo = new CtpAffairVo(); + ctpAffairVo.setAffairInfo(ctpAffair); + for (SysUser user : userList) { + if(ctpAffair.getMemberId().equals(user.getSyUserId())){ + ctpAffairVo.setUserInfo(user.toSysUserVo()); + List postUsers = postMap.get(user.getId()); + ctpAffairVo.setUserPostList(postUsers); + } + } + result.add(ctpAffairVo); + } + return R.ok(result); + } + return R.ok(new ArrayList<>()); + } + @Override public SysUserMapper getUserMapper() { return userMapper; @@ -187,7 +290,42 @@ public class TbsCostApplyOperationServiceImpl implements SeeYonOperationService @Override public R commitAffair(TbsAffairCommitBo affairCommit) { - return SeeYonOperationService.super.commitAffair(affairCommit); + getRequestService().testConnection(); + TbsCostApply costApply = costApplyService.getById(affairCommit.getCostApplyId()); + if(!costApply.getChargeState().equals(TbsCostApplyState.State_1_apply.getCode())){ + Assert.throwEx("费用申请处于未非审批状态"); + } + String syFormId = costApply.getSyFormId(); + String templateCode = getTemplateCode(); + //判断是否协议类 + if(costApply.getContractFlag()!=null&&costApply.getContractFlag().equals(1)){ + templateCode = TbsSeeYonConst.CostApplyContractConf.Code(); + } + R result = getRequestService().commonCommit(affairCommit, templateCode ,syFormId); + boolean isBackCommit = affairCommit.getState()==2; + if(result.getStatus()==200){ + // 判断是否含有下个节点 + String flag = result.getData(); + //审批中(next)、完成(finish)、拒绝(refused) + if("finish".equals(flag)){ + this.doFinished(affairCommit); + return R.ok(); + }else if ("stop".equals(flag)){ + if(isBackCommit){ + this.doBacked(affairCommit); + return R.ok(); + }else { + this.doRefuse(affairCommit); + return R.ok(); + } + }else if ("next".equals(flag)){ + this.doNext(affairCommit); + return R.ok(); + } + }else if (result.getStatus()==500){ + return result; + } + return R.ok(); } @Override @@ -236,4 +374,29 @@ public class TbsCostApplyOperationServiceImpl implements SeeYonOperationService } return null; } + + @Override + public R runCompensate(String targetId) { + testConnection(); + String templateCode = getTemplateCode(); + TbsCostApply costApply = costApplyService.getById(targetId); + if(costApply.getContractFlag()!=null&&costApply.getContractFlag().equals(1)){ + templateCode = TbsSeeYonConst.CostApplyContractConf.Code(); + } + SyAffairStateResult stateResult =checkAffairState(targetId,templateCode); + SyAffairState affairState = stateResult.getState(); + if(affairState.equals(SyAffairState.next)){ + return R.ok(compensateNext(targetId)); + }else if(affairState.equals(SyAffairState.backed)){ + return R.ok(compensateBacked(targetId)); + }else if(affairState.equals(SyAffairState.finished)){ + return R.ok(compensateFinished(targetId)); + }else if(affairState.equals(SyAffairState.refuse)){ + return R.ok(compensateRefuse(targetId)); + }else if(affairState.equals(SyAffairState.error)){ + return R.error("数据异常请联系管理员"); + }else{ + return R.error("OA无相关审批数据"); + } + } } diff --git a/src/main/java/com/qs/serve/modules/tbs/service/impl/TbsCostApplyServiceImpl.java b/src/main/java/com/qs/serve/modules/tbs/service/impl/TbsCostApplyServiceImpl.java index ca1ce96c..8f546549 100644 --- a/src/main/java/com/qs/serve/modules/tbs/service/impl/TbsCostApplyServiceImpl.java +++ b/src/main/java/com/qs/serve/modules/tbs/service/impl/TbsCostApplyServiceImpl.java @@ -14,8 +14,6 @@ import com.qs.serve.common.util.model.DateFormatString; import com.qs.serve.modules.bir.entity.BirActivityCenterGoods; import com.qs.serve.modules.bir.entity.dto.BirRoiCostDTO; import com.qs.serve.modules.bir.entity.vo.YtdQtdToOAVo; -import com.qs.serve.modules.bir.service.BirActivityCenterGoodsService; -import com.qs.serve.modules.bir.service.BirCenterRateService; import com.qs.serve.modules.bir.service.BirRoiRateService; import com.qs.serve.modules.bms.entity.BmsRegion; import com.qs.serve.modules.bms.entity.BmsRegion2; @@ -42,6 +40,7 @@ import com.qs.serve.modules.tbs.common.util.TbsBudgetLogBuildUtil; import com.qs.serve.modules.tbs.entity.*; import com.qs.serve.modules.tbs.entity.dto.TbsCenterGoodBirDTO; import com.qs.serve.modules.tbs.entity.dto.TbsBudgetCostResult; +import com.qs.serve.modules.tbs.entity.dto.TbsContractCostSubItem; import com.qs.serve.modules.tbs.entity.dto.TbsCostSubItem; import com.qs.serve.modules.tbs.mapper.*; import com.qs.serve.modules.tbs.service.*; @@ -83,17 +82,17 @@ public class TbsCostApplyServiceImpl extends ServiceImpl payConditions = null; if(tbsCostApply.getContractFlag()!=null&&tbsCostApply.getContractFlag().equals(1)){ LambdaQueryWrapper lqw = new LambdaQueryWrapper<>(); lqw.eq(TbsActivityPayCondition::getCostApplyId,id); - List payConditions = tbsActivityPayConditionMapper.selectList(lqw); + payConditions = tbsActivityPayConditionMapper.selectList(lqw); if(payConditions.size()<1){ Assert.throwEx("请补充支付条件"); } @@ -218,68 +218,147 @@ public class TbsCostApplyServiceImpl extends ServiceImpl data = new HashMap<>(10); - String actTitles = activityList.stream().map(TbsActivity::getActTitle).collect(Collectors.joining("; ")); - data.put("costApplyCode",tbsCostApply.getCode()); - data.put("applyUserCode",sysUser.getCode()); - data.put("applyUserName",sysUser.getName()); - data.put("supplierName",tbsCostApply.getSupplierName()); - data.put("supplierCode",tbsCostApply.getSupplierCode()); - data.put("title",tbsCostApply.getChargeTheme()); - data.put("rowDate",DateUtils.format(LocalDateTime.now(), DateFormatString.DATE_TIME)); - data.put("rowState","03"); - data.put("orgId",tbsCostApply.getId()+""); - data.put("targetId",tbsCostApply.getId()+""); - data.put("targetCode",tbsCostApply.getCode()); - data.put("exsp1",TbsSeeYonConst.CostApplyConf.Code()); - data.put("money",tbsCostApply.getTotalActivityAmount()); - - //记录主表费率参数 - try { - this.buildMainData4ROI(tbsCostApply, data); - } catch (Exception e) { - e.printStackTrace(); - } + if(tbsCostApply.getContractFlag()!=null&&tbsCostApply.getContractFlag().equals(1)){ - //拓展添加审批关联区域 - String saleRegionId = supplier.handleSaleRegionId(); - String bizRegionId = supplier.handleBizRegionId(); - BmsRegion saleRegion = regionMapper.selectById(saleRegionId); - BmsRegion2 bizRegion = region2Mapper.selectById(bizRegionId); - String saleRegionNames = saleRegion!=null?saleRegion.getPathNames():"null_申请时未录入"; - String bizRegionNames = bizRegion!=null?bizRegion.getPathNames():"null_申请时未录入"; + data.put("title",tbsCostApply.getChargeTheme()); + data.put("orgId",tbsCostApply.getId().toString()); + data.put("costApplyCode", tbsCostApply.getCode()); + data.put("applyUserCode", sysUser.getCode()); + data.put("applyUserName", sysUser.getName()); + data.put("supplierName", tbsCostApply.getSupplierName()); + data.put("supplierCode", tbsCostApply.getSupplierCode()); + data.put("targetId", tbsCostApply.getId()+""); + data.put("targetCode", tbsCostApply.getCode()); + data.put("exsp1",TbsSeeYonConst.CostApplyContractConf.Code()); + //添加跳转地址业务 + String urlKey = "exsp5"+IdUtil.simpleUUID(); + String baseJumpUrl = JumpToUtil.getUrl(projectProperties.getHostUrl(),TbsSeeYonConst.CostApplyConf.Code(),urlKey); + data.put("exsp5",urlKey); + data.put("cmsLink",baseJumpUrl); + + data.put("rowDate",DateUtils.format(LocalDateTime.now(), DateFormatString.DATE_TIME)); + data.put("rowState","03"); + + //拓展添加审批关联区域 + String saleRegionId = supplier.handleSaleRegionId(); + String bizRegionId = supplier.handleBizRegionId(); + BmsRegion saleRegion = regionMapper.selectById(saleRegionId); + BmsRegion2 bizRegion = region2Mapper.selectById(bizRegionId); + String saleRegionNames = saleRegion!=null?saleRegion.getPathNames():"null_申请时未录入"; + String bizRegionNames = bizRegion!=null?bizRegion.getPathNames():"null_申请时未录入"; + + //拓展添加审批关联 + data.put("biz_region",bizRegionNames); + data.put("exsp2",saleRegionNames); + data.put("dataState",TbsCostApplyState.State_1_apply.getCode()+""); + + //创建协议类data数据 + data.put("serialNumber",tbsCostApply.getCode()); + data.put("applySubject",tbsCostApply.getChargeTheme()); + data.put("supplierCode",tbsCostApply.getSupplierCode()); + data.put("supplierName",tbsCostApply.getSupplierName()); + data.put("totalSalesMoney",tbsCostApply.getTotalActivityAmount()); + data.put("totalExpenseRate",tbsCostApply.getTotalActivityPreNotAmount()); + data.put("remark",tbsCostApply.getRemark()); + + data.put("payee",""); + data.put("bankName",""); + data.put("bankAccount",""); + data.put("sealID",""); + data.put("sealName",""); + data.put("sealNum","0"); + data.put("fileNum","0"); + + LambdaQueryWrapper lqw = new LambdaQueryWrapper<>(); + lqw.eq(TbsCostContract::getCostApplyId,tbsCostApply.getId()); + List contracts = costContractMapper.selectList(lqw); + if(contracts.size()>0){ + TbsCostContract contract = contracts.get(0); + data.put("contractName",contract.getContractName()); + data.put("contractTotalMoney",contract.getContractAmount()); + data.put("signDate",contract.getSignTime()==null?null:contract.getSignTime().toString()); + data.put("expireDate",contract.getExpireTime()==null?null:contract.getExpireTime().toString()); + data.put("contractContent",contract.getContractCondition()); + data.put("contractFile",""); + } - //拓展添加审批关联 - data.put("biz_region",bizRegionNames); - data.put("exsp2",saleRegionNames); - data.put("data_state",TbsCostApplyState.State_1_apply.getCode()+""); + //创建子表数据 + List subList = new ArrayList<>(); + + //活动明细 + LambdaQueryWrapper actCgLqw = new LambdaQueryWrapper<>(); + actCgLqw.eq(TbsActivityCenterGoods::getCostApplyId,id); + List activityCenterGoodsList = tbsActivityCenterGoodsMapper.selectList(actCgLqw); + for (TbsActivityCenterGoods centerGoods : activityCenterGoodsList) { + TbsActivity currActivity = null; + for (TbsActivity activity : activityList) { + if(centerGoods.getActivityId().equals(activity.getId())){ + currActivity = activity; + break; + } + } + TbsContractCostSubItem.Activity dataActivity = new TbsContractCostSubItem.Activity(); + dataActivity.setActivityCode(currActivity.getActivityCode()); + dataActivity.setActivityPurpose(currActivity.getActTitle()); + dataActivity.setCostCode(tbsCostApply.getCode()); + dataActivity.setStartDate(currActivity.getActStartDate()==null?null:currActivity.getActStartDate().toString()); + dataActivity.setEndDate(currActivity.getActEndDate()==null?null:currActivity.getActEndDate().toString()); + dataActivity.setWriteOffDate(currActivity.getPreCheckDate()==null?null:currActivity.getPreCheckDate().toString()); + dataActivity.setProductType(centerGoods.getTargetType()); + dataActivity.setProduct(centerGoods.getTargetName()); + dataActivity.setAccountCode(centerGoods.getSubjectCode()); + dataActivity.setAccountName(centerGoods.getSubjectName()); + dataActivity.setCostCenterNo(centerGoods.getCenterType()); + dataActivity.setCostCenterName(centerGoods.getCenterName()); + dataActivity.setApplyMoney(centerGoods.getCenterGoodsAmount()); + subList.add(dataActivity); + } - //添加跳转地址业务 - String urlKey = "exsp5"+IdUtil.simpleUUID(); - String baseJumpUrl = JumpToUtil.getUrl(projectProperties.getHostUrl(),TbsSeeYonConst.CostApplyConf.Code(),urlKey); - data.put("exsp5",urlKey); - data.put("cmsLink",baseJumpUrl); - data.put("activitySummary",actTitles); + // 付款条件 + for (TbsActivityPayCondition payCondition : payConditions) { + TbsActivity currActivity = null; + for (TbsActivity activity : activityList) { + if(payCondition.getActivityId().equals(activity.getId())){ + currActivity = activity; + break; + } + } + TbsContractCostSubItem.Payment subPayment = new TbsContractCostSubItem.Payment(); + subPayment.setPayItem(payCondition.getTitle()); + subPayment.setPayCondition(payCondition.getConditionMsg()); + subPayment.setMoney(currActivity.getTotalAmount()); + subPayment.setPayDate(payCondition.getPaymentDate()!=null?payCondition.getPaymentDate().toString():null); + subPayment.setActualPayDate(null); + subPayment.setPayCompleteState(payCondition.getPreNotifyStatus()); + subPayment.setPayRemark(payCondition.getRemark()); + subList.add(subPayment); + } - //添加科目和成本中心 - List tbsActivityCenters = tbsActivityCenterService.listByCostApplyId(Long.parseLong(id)); - List tbsActivitySubjects = tbsActivitySubjectService.listByCostApplyId(Long.parseLong(id)); - List subjectNames = tbsActivitySubjects.stream().map(TbsActivitySubject::getSubjectName).distinct().collect(Collectors.toList()); - List subList = new ArrayList<>(); - //创建子表数据 - this.buildSubList(result, tbsActivityCenters, subjectNames, subList); + // 协议条款 + LambdaQueryWrapper todoLqw = new LambdaQueryWrapper<>(); + todoLqw.eq(TbsCostTodo::getCostApplyId,tbsCostApply.getId()); + List costTodoList = tbsCostTodoMapper.selectList(todoLqw); + for (TbsCostTodo costTodo : costTodoList) { + TbsContractCostSubItem.ToDoItem toDoItem = new TbsContractCostSubItem.ToDoItem(); + toDoItem.setServiceDescription(costTodo.getDescr()); + toDoItem.setDeliveryStandard(costTodo.getPayMsg()); + toDoItem.setDeliveryDate(costTodo.getPrePayDate()==null?null : costTodo.getPrePayDate().toString()); + toDoItem.setAgreeRemark(costTodo.getRemark()); + subList.add(toDoItem); + } + //关联 + data.put("sub", subList); - //创建商品抬头列表 - List tbsActivityGoods = tbsActivityGoodsService.listByCostApplyId(Long.parseLong(id)); - Set bands = new HashSet<>(); - for (TbsActivityGoods tbsActivityGood : tbsActivityGoods) { - String band = tbsActivityGood.getTargetLevelPathNames().split("_")[0]; - bands.add(band); + }else { + //创建通用的费用申请Data + this.buildCommonApplyData(id, tbsCostApply, activityList, supplier, result, sysUser, data); } - String goods = bands.stream().collect(Collectors.joining(",")); - data.put("chanPinPinLei",goods); - data.put("sub",subList); + //修改申请编码 + String templateCode = tbsCostApply.getContractFlag().equals(1) + ?TbsSeeYonConst.CostApplyContractConf.Code() + :TbsSeeYonConst.CostApplyConf.Code(); BaseCreateProcessBo createProcess = new BaseCreateProcessBo(); - createProcess.setTemplateCode(TbsSeeYonConst.CostApplyConf.Code()); + createProcess.setTemplateCode(templateCode); createProcess.setMemberLoginName(sysUser.getSyAccount()); createProcess.setSubjectTitle(TbsSeeYonConst.PRE_TITLE_COST_APPLY + tbsCostApply.getChargeTheme()); createProcess.setTargetId(tbsCostApply.getId()+""); @@ -290,7 +369,7 @@ public class TbsCostApplyServiceImpl extends ServiceImpl formIdResult = seeYonService.getFormId(TbsSeeYonConst.CostApplyConf.Code(),tbsCostApply.getId()); + R formIdResult = seeYonService.getFormId(templateCode,tbsCostApply.getId()); if(formIdResult.getStatus()==200){ formId = formIdResult.getData(); } @@ -355,7 +434,7 @@ public class TbsCostApplyServiceImpl extends ServiceImpl activityList, BmsSupplier supplier, TbsBudgetCostResult result, SysUser sysUser, Map data) { + String actTitles = activityList.stream().map(TbsActivity::getActTitle).collect(Collectors.joining("; ")); + data.put("costApplyCode", tbsCostApply.getCode()); + data.put("applyUserCode", sysUser.getCode()); + data.put("applyUserName", sysUser.getName()); + data.put("supplierName", tbsCostApply.getSupplierName()); + data.put("supplierCode", tbsCostApply.getSupplierCode()); + data.put("title", tbsCostApply.getChargeTheme()); + data.put("rowDate",DateUtils.format(LocalDateTime.now(), DateFormatString.DATE_TIME)); + data.put("rowState","03"); + data.put("orgId", tbsCostApply.getId()+""); + data.put("targetId", tbsCostApply.getId()+""); + data.put("targetCode", tbsCostApply.getCode()); + data.put("exsp1",TbsSeeYonConst.CostApplyConf.Code()); + data.put("money", tbsCostApply.getTotalActivityAmount()); + + //记录主表费率参数 + try { + this.buildMainData4ROI(tbsCostApply, data); + } catch (Exception e) { + e.printStackTrace(); + } + + //拓展添加审批关联区域 + String saleRegionId = supplier.handleSaleRegionId(); + String bizRegionId = supplier.handleBizRegionId(); + BmsRegion saleRegion = regionMapper.selectById(saleRegionId); + BmsRegion2 bizRegion = region2Mapper.selectById(bizRegionId); + String saleRegionNames = saleRegion!=null?saleRegion.getPathNames():"null_申请时未录入"; + String bizRegionNames = bizRegion!=null?bizRegion.getPathNames():"null_申请时未录入"; + + //拓展添加审批关联 + data.put("biz_region",bizRegionNames); + data.put("exsp2",saleRegionNames); + data.put("data_state",TbsCostApplyState.State_1_apply.getCode()+""); + + //添加跳转地址业务 + String urlKey = "exsp5"+IdUtil.simpleUUID(); + String baseJumpUrl = JumpToUtil.getUrl(projectProperties.getHostUrl(),TbsSeeYonConst.CostApplyConf.Code(),urlKey); + data.put("exsp5",urlKey); + data.put("cmsLink",baseJumpUrl); + data.put("activitySummary",actTitles); + + //添加科目和成本中心 + List tbsActivityCenters = tbsActivityCenterService.listByCostApplyId(Long.parseLong(id)); + List tbsActivitySubjects = tbsActivitySubjectService.listByCostApplyId(Long.parseLong(id)); + List subjectNames = tbsActivitySubjects.stream().map(TbsActivitySubject::getSubjectName).distinct().collect(Collectors.toList()); + List subList = new ArrayList<>(); + //创建子表数据 + try { + this.buildSubList(result, tbsActivityCenters, subjectNames, subList); + } catch (Exception e) { + e.printStackTrace(); + } + //创建商品抬头列表 + List tbsActivityGoods = tbsActivityGoodsService.listByCostApplyId(Long.parseLong(id)); + Set bands = new HashSet<>(); + for (TbsActivityGoods tbsActivityGood : tbsActivityGoods) { + String band = tbsActivityGood.getTargetLevelPathNames().split("_")[0]; + bands.add(band); + } + String goods = bands.stream().collect(Collectors.joining(",")); + data.put("chanPinPinLei",goods); + data.put("sub",subList); + } + /** * 记录主表费率参数 * @param tbsCostApply @@ -372,21 +517,21 @@ public class TbsCostApplyServiceImpl extends ServiceImpl data) { YtdQtdToOAVo ytdQtdToOAVo = birRoiRateService.buildYtdAndQtdData(tbsCostApply); data.put("ytdCusExpenseRate",ytdQtdToOAVo.getYtdCustomerPercent()==null? - BigDecimal.ZERO:BigDecimal.valueOf(ytdQtdToOAVo.getYtdCustomerPercent()).setScale(2, RoundingMode.HALF_UP).toString()); + "0":BigDecimal.valueOf(ytdQtdToOAVo.getYtdCustomerPercent()).setScale(2, RoundingMode.HALF_UP)+""); data.put("ytdEmpExpenseRate",ytdQtdToOAVo.getYtdUserPercent()==null? - BigDecimal.ZERO:BigDecimal.valueOf(ytdQtdToOAVo.getYtdUserPercent()).setScale(2, RoundingMode.HALF_UP).toString()); + "0":BigDecimal.valueOf(ytdQtdToOAVo.getYtdUserPercent()).setScale(2, RoundingMode.HALF_UP)+""); data.put("ytdAdminiExpenseRate",ytdQtdToOAVo.getYtdRegionPercent()==null? - BigDecimal.ZERO:BigDecimal.valueOf(ytdQtdToOAVo.getYtdRegionPercent()).setScale(2, RoundingMode.HALF_UP).toString()); + "0":BigDecimal.valueOf(ytdQtdToOAVo.getYtdRegionPercent()).setScale(2, RoundingMode.HALF_UP)+""); data.put("ytdSalesExpenseRate",ytdQtdToOAVo.getYtdRegion2Percent()==null? - BigDecimal.ZERO:BigDecimal.valueOf(ytdQtdToOAVo.getYtdRegion2Percent()).setScale(2, RoundingMode.HALF_UP).toString()); + "0":BigDecimal.valueOf(ytdQtdToOAVo.getYtdRegion2Percent()).setScale(2, RoundingMode.HALF_UP)+""); data.put("cusExpenseRate",ytdQtdToOAVo.getQtdCustomerPercent()==null? - BigDecimal.ZERO:BigDecimal.valueOf(ytdQtdToOAVo.getQtdCustomerPercent()).setScale(2, RoundingMode.HALF_UP).toString()); + "0":BigDecimal.valueOf(ytdQtdToOAVo.getQtdCustomerPercent()).setScale(2, RoundingMode.HALF_UP)+""); data.put("empExpenseRate",ytdQtdToOAVo.getQtdUserPercent()==null? - BigDecimal.ZERO:BigDecimal.valueOf(ytdQtdToOAVo.getQtdUserPercent()).setScale(2, RoundingMode.HALF_UP).toString()); + "0":BigDecimal.valueOf(ytdQtdToOAVo.getQtdUserPercent()).setScale(2, RoundingMode.HALF_UP)+""); data.put("salesExpenseRate",ytdQtdToOAVo.getQtdRegionPercent()==null? - BigDecimal.ZERO:BigDecimal.valueOf(ytdQtdToOAVo.getQtdRegionPercent()).setScale(2, RoundingMode.HALF_UP).toString()); + "0":BigDecimal.valueOf(ytdQtdToOAVo.getQtdRegionPercent()).setScale(2, RoundingMode.HALF_UP)+""); data.put("adminiExpenseRate",ytdQtdToOAVo.getQtdRegion2Percent()==null? - BigDecimal.ZERO:BigDecimal.valueOf(ytdQtdToOAVo.getQtdRegion2Percent()).setScale(2, RoundingMode.HALF_UP).toString()); + "0":BigDecimal.valueOf(ytdQtdToOAVo.getQtdRegion2Percent()).setScale(2, RoundingMode.HALF_UP)+""); //插入记录表前移除历史记录 // tbsCostPercentMapper.delByCostApplyId(tbsCostApply.getId()); @@ -423,241 +568,181 @@ public class TbsCostApplyServiceImpl extends ServiceImpl tbsBudgetCostItems = result.getBudgetMatchList(); + List scheduleItemBudgetIds = tbsBudgetCostItems.stream().map(a->a.getScheduleItemBudgetId()).distinct().collect(Collectors.toList()); + List tbsScheduleItemBudgets = tbsScheduleItemBudgetMapper.selectBatchIds(scheduleItemBudgetIds); + /*for(TbsScheduleItemBudget tbsScheduleItemBudget : tbsScheduleItemBudgets){ + subList.add( + new TbsCostSubItem.Amount( + tbsScheduleItemBudget.getBudgetAmount(), + tbsScheduleItemBudget.getPreDispatchAmount(), + tbsScheduleItemBudget.compareTargetExpenseRate() + ) + ); + }*/ + //查询发货金额,并按月份分割 -// int year = LocalDate.now().getYear(); -// int month = LocalDate.now().getMonthValue(); -// month = month>1?month:1; -// int startMonthNum = year*100 + 1; -// int endMonthNum = year*100 + month; -// BirRoiRateService roiRateService = SpringUtils.getBean(BirRoiRateService.class); -// BirRoiCostDTO costDTO = new BirRoiCostDTO(); -// costDTO.setStartMonthNum(startMonthNum); -// costDTO.setEndMonthNum(endMonthNum); - - //获取BIR表的数据,用于计算实际费用率 -// LambdaQueryWrapper birLwq = new LambdaQueryWrapper<>(); -// birLwq.in(BirActivityCenterGoods::getCenterId,tbsActivityCenters.stream().map(a->a.getCenterId()).collect(Collectors.toList())); -// birLwq.ge(BirActivityCenterGoods::getKeyNum,startMonthNum); -// birLwq.le(BirActivityCenterGoods::getKeyNum,endMonthNum); -// List birActivityCenterGoodsList = birActivityCenterGoodsService.list(birLwq); -// Map> birCenterCostMap = birActivityCenterGoodsList.stream().collect(Collectors.groupingBy(a->a.getCenterType() + "-"+a.getCenterId())); - //成本中心去重 - Map> centerMapList = tbsActivityCenters.stream().collect(Collectors.groupingBy(a->a.getCenterType()+"-"+a.getCenterId())); - List centerList = centerMapList.values().stream().map(a->a.get(0)).collect(Collectors.toList()); - - for(TbsActivityCenter center : centerList){ - TbsCostSubItem.CostCenterTranStr costCenter = centerRateService.buildCostCenter(center.getCenterType(),center.getCenterId(),center.getCenterName()); + int year = LocalDate.now().getYear(); + int month = LocalDate.now().getMonthValue(); + int startMonthNum = Integer.parseInt(year+"01"); + int endMonthNum = Integer.parseInt(year+"01"); + tbsActivityCenters.stream().collect(Collectors.groupingBy(TbsActivityCenter::getCenterType)); + BirRoiRateService roiRateService = SpringUtils.getBean(BirRoiRateService.class); + BirRoiCostDTO costDTO = new BirRoiCostDTO(); + costDTO.setStartMonthNum(startMonthNum); + costDTO.setEndMonthNum(endMonthNum); + /*成本中心维度*/ + //发货单 + Map> supplierCodeMapWithCenterType = new HashMap<>(); + Map> centerMapList = tbsActivityCenters.stream().collect(Collectors.groupingBy(TbsActivityCenter::getCenterType)); + for (String centerType : centerMapList.keySet()) { + List centerIds =centerMapList.get(centerType).stream().map(TbsActivityCenter::getCenterId).collect(Collectors.toList()); + List supplierCodeList = roiRateService.getSupplierCodesByCenter(costDTO,centerType,centerIds); + //发货单 + List dispatchSumVos = null; + if(supplierCodeList!=null&&supplierCodeList.size()>0){ + dispatchSumVos = dispatchDataMapper.querySumCost(startMonthNum,endMonthNum,supplierCodeList); + supplierCodeMapWithCenterType.put(centerType,dispatchSumVos); + }else { + //防止后面获取空指针 + supplierCodeMapWithCenterType.put(centerType,new ArrayList<>()); + } + } + + //查询ROI底表,并拼接DTO + List centerGoodDTOS = new ArrayList<>(); + List birActivityCenterGoodsList = new ArrayList<>(); + //按成本中心维度分组 + Map> birGroupByCenter = birActivityCenterGoodsList.stream() + .collect(Collectors.groupingBy(a->a.getCenterType()+"_"+a.getCenterId())); + + for (TbsActivityCenter activityCenter : tbsActivityCenters) { + String centerKey = activityCenter.getCenterType()+"_"+activityCenter.getCenterId(); + //创建成本中心维度对象 + TbsCostSubItem.CostCenter costCenter = this.buildCostCenterParam(result, tbsScheduleItemBudgets, + year, month, supplierCodeMapWithCenterType, birGroupByCenter, activityCenter, centerKey); subList.add(costCenter); -// String centerType = center.getCenterType(); -// String centerId = center.getCenterId(); -// String centerKey = centerType + "-" + centerId; -// TbsCostSubItem.CostCenterTranStr costCenter = new TbsCostSubItem.CostCenterTranStr(center.getCenterName(),centerType+"-"+centerId); -// /* --------------- 全年目标费用率YTD 目标预计发货,目标预算 --------------------------- */ -// //通过成本中心TYPE和ID取预算 -// LambdaQueryWrapper budgetLambdaQueryWrapper = new LambdaQueryWrapper<>(); -// budgetLambdaQueryWrapper.eq(TbsBudget::getCenterId,centerId); -// budgetLambdaQueryWrapper.eq(TbsBudget::getCenterType,centerType); -// List tbsBudgetList = tbsBudgetMapper.selectList(budgetLambdaQueryWrapper); -// //通过预算ID取预算的发货和金额 -// LambdaQueryWrapper scheduleItemBudgetLambdaQueryWrapper = new LambdaQueryWrapper<>(); -// scheduleItemBudgetLambdaQueryWrapper.in(TbsScheduleItemBudget::getBudgetId,tbsBudgetList.stream().map(a->a.getId()).collect(Collectors.toList())); -// List scheduleItemBudgetList = tbsScheduleItemBudgetMapper.selectList(scheduleItemBudgetLambdaQueryWrapper); -// //合计目标发货和金定额 -// BigDecimal targetBudgetAmout = scheduleItemBudgetList.stream().map(a->a.getBudgetAmount()).reduce(BigDecimal.ZERO,BigDecimal::add); -// BigDecimal targetDispatchAmout = scheduleItemBudgetList.stream().map(a->a.getPreDispatchAmount()==null?BigDecimal.ZERO:a.getPreDispatchAmount()).reduce(BigDecimal.ZERO,BigDecimal::add); -// costCenter.setTargetSales(targetDispatchAmout.toString()); -// costCenter.setAreaBudget(targetBudgetAmout.toString()); -// BigDecimal targetExpenseRate = BigDecimal.ZERO; -// if(targetDispatchAmout.compareTo(BigDecimal.ZERO)!=0) { -// targetExpenseRate = targetBudgetAmout.divide(targetDispatchAmout, 2, BigDecimal.ROUND_HALF_DOWN); -// costCenter.setTargetExpenseRate(targetExpenseRate.toString()); -// costCenter.setYtdTargetExpenseRate(targetExpenseRate.toString()); -// } -//// costCenter.setTargetExpenseRate(targetExpenseRate); -// costCenter.setYtdTargetBudget(targetBudgetAmout.toString()); -// costCenter.setYtdTargetSales(targetDispatchAmout.toString()); -//// costCenter.setYtdTargetExpenseRate(targetExpenseRate); -// -//// costCenter.setQtdTargetBudget(BigDecimal.ZERO); -//// costCenter.setQtdTargetSales(BigDecimal.ZERO); -//// costCenter.setQtdTargetExpenseRate(BigDecimal.ZERO); -//// costCenter.setMtdTargetBudget(BigDecimal.ZERO); -//// costCenter.setMtdTargetSales(BigDecimal.ZERO); -//// costCenter.setMtdTargetExpenseRate(BigDecimal.ZERO); -// /* ------------------------------------------------------------------------- */ -// //实际发贷数 -// List supplierCodeList = roiRateService.getSupplierCodesByCenter(costDTO,centerType,Arrays.asList(centerId)); -// List dispatchSumVos = dispatchDataMapper.querySumCost(startMonthNum,endMonthNum,supplierCodeList); -// List birCenterCost = birCenterCostMap.containsKey(centerKey)?birCenterCostMap.get(centerKey):new ArrayList<>(); -// -// /* --------------- 实际费用率YTD --------------------------------------------- */ -// BigDecimal ytdRealDipatch = dispatchSumVos.stream().map(a->a.getDispatchSumCost()).reduce(BigDecimal.ZERO,BigDecimal::add); -// BigDecimal ytdRealCost = birCenterCost.stream().map(a->a.getSplitUsedAmount()).reduce(BigDecimal.ZERO,BigDecimal::add); -// costCenter.setYtdRealCost(ytdRealCost.toString()); -// costCenter.setYtdRealSales(ytdRealDipatch.toString()); -// BigDecimal ytdRealExpenseRate = BigDecimal.ZERO; -// if(ytdRealDipatch.compareTo(BigDecimal.ZERO)!=0) { -// ytdRealExpenseRate = ytdRealCost.divide(ytdRealDipatch, 2, BigDecimal.ROUND_HALF_DOWN); -// costCenter.setYtdRealExpenseRate(ytdRealExpenseRate.toString()); -// } -//// costCenter.setYtdRealExpenseRate(ytdRealExpenseRate); -// /* ------------------------------------------------------------------------- */ -// -// /* --------------- 实际费用率QTD --------------------------------------------- */ -// List yearQuarter = QuarterUtil.getQuarterNumbers(year, month); -// BigDecimal qtdRealDipatch = dispatchSumVos.stream().filter(a->yearQuarter.contains(a.getYearMonth())).map(a->a.getDispatchSumCost()).reduce(BigDecimal.ZERO,BigDecimal::add); -// BigDecimal qtdRealCost = birCenterCost.stream().filter(a->yearQuarter.contains(a.getKeyNum())).map(a->a.getSplitUsedAmount()).reduce(BigDecimal.ZERO,BigDecimal::add); -// costCenter.setQtdRealCost(qtdRealCost.toString()); -// costCenter.setQtdRealSales(qtdRealDipatch.toString()); -// BigDecimal qtdRealExpenseRate = BigDecimal.ZERO; -// if(qtdRealDipatch.compareTo(BigDecimal.ZERO)!=0) { -// qtdRealExpenseRate = qtdRealCost.divide(qtdRealDipatch, 2, BigDecimal.ROUND_HALF_DOWN); -// costCenter.setQtdRealExpenseRate(qtdRealExpenseRate.toString()); -// } -//// costCenter.setQtdRealExpenseRate(qtdRealExpenseRate); -// /* ------------------------------------------------------------------------- */ -// -// /* --------------- 实际费用率MTD --------------------------------------------- */ -// Integer yearMonth = year*100 + month; -// BigDecimal mtdRealDipatch = dispatchSumVos.stream().filter(a->yearMonth.equals(a.getYearMonth())).map(a->a.getDispatchSumCost()).reduce(BigDecimal.ZERO,BigDecimal::add); -// BigDecimal mtdRealCost = birCenterCost.stream().filter(a->yearMonth.equals(a.getKeyNum())).map(a->a.getSplitUsedAmount()).reduce(BigDecimal.ZERO,BigDecimal::add); -// costCenter.setMtdRealCost(mtdRealCost.toString()); -// costCenter.setMtdRealSales(mtdRealDipatch.toString()); -// BigDecimal mtdRealExpenseRate = BigDecimal.ZERO; -// if(mtdRealDipatch.compareTo(BigDecimal.ZERO)!=0) { -// mtdRealExpenseRate = mtdRealCost.divide(mtdRealDipatch, 2, BigDecimal.ROUND_HALF_DOWN); -// costCenter.setMtdRealExpenseRate(mtdRealExpenseRate.toString()); -// } -//// costCenter.setMtdRealExpenseRate(mtdRealExpenseRate); -// /* ------------------------------------------------------------------------- */ - - -// subList.add(costCenter); } + } + /** + * 创建成本中心维度对象 + * @param result + * @param tbsScheduleItemBudgets + * @param year + * @param month + * @param supplierCodeMapWithCenterType + * @param birGroupByCenter + * @param activityCenter + * @param centerKey + * @return + */ + @NotNull + private TbsCostSubItem.CostCenter buildCostCenterParam(TbsBudgetCostResult result, List tbsScheduleItemBudgets, int year, int month, Map> supplierCodeMapWithCenterType, Map> birGroupByCenter, TbsActivityCenter activityCenter, String centerKey) { + TbsCostSubItem.CostCenter costCenter = new TbsCostSubItem.CostCenter(activityCenter.getCenterName(), + activityCenter.getCenterType()+"_"+ activityCenter.getCenterId()); + //设置目标销量、目标预算 + for (TbsBudget budget : result.getBudgetList()) { + boolean eqType = activityCenter.getCenterType().equals(budget.getCenterType()); + boolean eqCost = activityCenter.getCenterId().equals(budget.getCenterId()); + if (eqType && eqCost) { + BigDecimal totalBudgetAmount = BigDecimal.ZERO; + BigDecimal totalPreDispatchAmount = BigDecimal.ZERO; + for (TbsScheduleItemBudget itemBudget : tbsScheduleItemBudgets) { + if (itemBudget.getBudgetId().equals(budget.getId())) { + if (itemBudget.getBudgetAmount() != null) { + totalBudgetAmount = totalBudgetAmount.add(itemBudget.getBudgetAmount()); + } + if (itemBudget.getPreDispatchAmount() != null) { + totalPreDispatchAmount = totalBudgetAmount.add(itemBudget.getPreDispatchAmount()); + } + } + } + costCenter.setAreaBudget(totalBudgetAmount); + costCenter.setTargetSales(totalPreDispatchAmount); + if (totalPreDispatchAmount.compareTo(BigDecimal.ZERO) != 0) { + costCenter.setTargetExpenseRate(totalBudgetAmount.divide(totalPreDispatchAmount, BigDecimal.ROUND_DOWN)); + } + //暂保持目标相关数据一致 + costCenter.setYtdTargetSales(costCenter.getTargetSales()); + costCenter.setYtdTargetBudget(costCenter.getAreaBudget()); + costCenter.setYtdTargetExpenseRate(costCenter.getTargetExpenseRate()); + costCenter.setQtdTargetSales(costCenter.getTargetSales()); + costCenter.setQtdTargetBudget(costCenter.getAreaBudget()); + costCenter.setQtdTargetExpenseRate(costCenter.getTargetExpenseRate()); +// costCenter.setMtdTargetSales(); +// costCenter.setMtdTargetBudget(); +// costCenter.setMtdTargetExpenseRate(); + break; + + } + } + //发货金额 + List erpDispatchSumVoList = supplierCodeMapWithCenterType.get(centerKey); + + //所有相关费率记录 + List centerGoods = birGroupByCenter.get(centerKey); + if(CollectionUtil.isNotEmpty(centerGoods)){ + //年费率 + TbsCenterGoodBirDTO bir4Year = this.getTbsCenterGoodBirDTO(centerGoods,erpDispatchSumVoList); + costCenter.setYtdRealSales(bir4Year.getRealSales()); + costCenter.setYtdRealCost(bir4Year.getRealCost()); + costCenter.setYtdRealExpenseRate(bir4Year.getRealExpenseRate()); + + //季度 + List yearMonthList =QuarterUtil.getQuarterNumbers(year, month); + List centerGoodsQuarter = centerGoods.stream() + .filter(a-> yearMonthList.contains(a.getKeyNum())) + .collect(Collectors.toList()); + TbsCenterGoodBirDTO bir4Quarter = this.getTbsCenterGoodBirDTO(centerGoodsQuarter,erpDispatchSumVoList); + costCenter.setQtdRealSales(bir4Quarter.getRealSales()); + costCenter.setQtdRealCost(bir4Quarter.getRealCost()); + costCenter.setQtdRealExpenseRate(bir4Quarter.getRealExpenseRate()); + + //月份 + String mStr = month >9? month +"":"0"+ month; + Integer currYearMonth = Integer.parseInt(year +mStr); + List centerGoodsM = centerGoods.stream() + .filter(a-> currYearMonth.equals(a.getKeyNum())) + .collect(Collectors.toList()); + TbsCenterGoodBirDTO bir4Month = this.getTbsCenterGoodBirDTO(centerGoodsM,erpDispatchSumVoList); + costCenter.setMtdRealSales(bir4Month.getRealSales()); + costCenter.setMtdRealCost(bir4Month.getRealCost()); + costCenter.setMtdRealExpenseRate(bir4Month.getRealExpenseRate()); + } + return costCenter; } -// /** -// * 创建成本中心维度对象(弃) -// * @param result -// * @param tbsScheduleItemBudgets -// * @param year -// * @param month -// * @param supplierCodeMapWithCenterType -// * @param birGroupByCenter -// * @param activityCenter -// * @param centerKey -// * @return -// */ -// @NotNull -// private TbsCostSubItem.CostCenter buildCostCenterParam(TbsBudgetCostResult result, List tbsScheduleItemBudgets, -// int year, int month, Map> supplierCodeMapWithCenterType, -// Map> birGroupByCenter, -// TbsActivityCenter activityCenter, String centerKey) { -// TbsCostSubItem.CostCenter costCenter = new TbsCostSubItem.CostCenter(activityCenter.getCenterName(), -// activityCenter.getCenterType()+"_"+ activityCenter.getCenterId()); -// //设置目标销量、目标预算 -// for (TbsBudget budget : result.getBudgetList()) { -// boolean eqType = activityCenter.getCenterType().equals(budget.getCenterType()); -// boolean eqCost = activityCenter.getCenterId().equals(budget.getCenterId()); -// if (eqType && eqCost) { -// BigDecimal totalBudgetAmount = BigDecimal.ZERO; -// BigDecimal totalPreDispatchAmount = BigDecimal.ZERO; -// //从命中的预算周期中取出目标发货 和 目标预算 进行合计 -// for (TbsScheduleItemBudget itemBudget : tbsScheduleItemBudgets) { -// if (itemBudget.getBudgetId().equals(budget.getId())) { -// if (itemBudget.getBudgetAmount() != null) { -// totalBudgetAmount = totalBudgetAmount.add(itemBudget.getBudgetAmount()); -// } -// if (itemBudget.getPreDispatchAmount() != null) { -// totalPreDispatchAmount = totalBudgetAmount.add(itemBudget.getPreDispatchAmount()); -// } -// } -// } -// costCenter.setAreaBudget(totalBudgetAmount); -// costCenter.setTargetSales(totalPreDispatchAmount); -// if (totalPreDispatchAmount.compareTo(BigDecimal.ZERO) != 0) { -// costCenter.setTargetExpenseRate(totalBudgetAmount.divide(totalPreDispatchAmount,2, BigDecimal.ROUND_DOWN)); -// } -// //暂保持目标相关数据一致 -// costCenter.setYtdTargetSales(costCenter.getTargetSales().setScale(2,BigDecimal.ROUND_DOWN)); -// costCenter.setYtdTargetBudget(costCenter.getAreaBudget().setScale(2, RoundingMode.DOWN)); -// costCenter.setYtdTargetExpenseRate(costCenter.getTargetExpenseRate().setScale(2, RoundingMode.DOWN)); -//// costCenter.setQtdTargetSales(costCenter.getTargetSales()); -//// costCenter.setQtdTargetBudget(costCenter.getAreaBudget()); -//// costCenter.setQtdTargetExpenseRate(costCenter.getTargetExpenseRate()); -//// costCenter.setMtdTargetSales(); -//// costCenter.setMtdTargetBudget(); -//// costCenter.setMtdTargetExpenseRate(); -// break; -// -// } -// } -// //发货金额 -// List erpDispatchSumVoList = supplierCodeMapWithCenterType.get(centerKey); -// -// //所有相关费率记录 -// List centerGoods = birGroupByCenter.get(centerKey); -// if(CollectionUtil.isNotEmpty(centerGoods)){ -// //年费率 -// TbsCenterGoodBirDTO bir4Year = this.getTbsCenterGoodBirDTO(centerGoods,erpDispatchSumVoList); -// costCenter.setYtdRealSales(bir4Year.getRealSales()); -// costCenter.setYtdRealCost(bir4Year.getRealCost()); -// costCenter.setYtdRealExpenseRate(bir4Year.getRealExpenseRate()); -// -// //季度 -// List yearMonthList =QuarterUtil.getQuarterNumbers(year, month); -// List centerGoodsQuarter = centerGoods.stream() -// .filter(a-> yearMonthList.contains(a.getKeyNum())) -// .collect(Collectors.toList()); -// TbsCenterGoodBirDTO bir4Quarter = this.getTbsCenterGoodBirDTO(centerGoodsQuarter,erpDispatchSumVoList); -// costCenter.setQtdRealSales(bir4Quarter.getRealSales()); -// costCenter.setQtdRealCost(bir4Quarter.getRealCost()); -// costCenter.setQtdRealExpenseRate(bir4Quarter.getRealExpenseRate()); -// -// //月份 -// String mStr = month >9? month +"":"0"+ month; -// Integer currYearMonth = Integer.parseInt(year +mStr); -// List centerGoodsM = centerGoods.stream() -// .filter(a-> currYearMonth.equals(a.getKeyNum())) -// .collect(Collectors.toList()); -// TbsCenterGoodBirDTO bir4Month = this.getTbsCenterGoodBirDTO(centerGoodsM,erpDispatchSumVoList); -// costCenter.setMtdRealSales(bir4Month.getRealSales()); -// costCenter.setMtdRealCost(bir4Month.getRealCost()); -// costCenter.setMtdRealExpenseRate(bir4Month.getRealExpenseRate()); -// } -// return costCenter; -// } - -// /** -// * 创建 成本中心 DTO(弃) -// * @param centerGoods -// * @param erpDispatchSumVoList -// * @return -// */ -// @NotNull -// private TbsCenterGoodBirDTO getTbsCenterGoodBirDTO(List centerGoods,List erpDispatchSumVoList) { -// BigDecimal totalRealDispatch = BigDecimal.ZERO; -// BigDecimal totalRealCost; -// BigDecimal totalRealCheck = BigDecimal.ZERO; -// BigDecimal totalRealRelease = BigDecimal.ZERO; -// for (BirActivityCenterGoods centerGood : centerGoods) { -// totalRealCheck = totalRealCheck.add(centerGood.getSplitUsedAmount()); -// totalRealRelease = totalRealRelease.add(centerGood.getSplitReleaseAmount()); -// for (ErpDispatchSumVo dispatchSumVo : erpDispatchSumVoList) { -// if(centerGood.getKeyNum().equals(dispatchSumVo.getYearMonth())){ -// totalRealDispatch = totalRealDispatch.add(dispatchSumVo.getDispatchSumCost()); -// } -// } -// } -// totalRealCost = totalRealCheck.add(totalRealRelease); -// TbsCenterGoodBirDTO birDTO = new TbsCenterGoodBirDTO(); -// birDTO.setRealCost(totalRealCost); -// birDTO.setRealCheck(totalRealCheck); -// birDTO.setRealRelease(totalRealRelease); -// birDTO.initRealExpenseRate(); -// return birDTO; -// } + /** + * 创建 成本中心 DTO + * @param centerGoods + * @param erpDispatchSumVoList + * @return + */ + @NotNull + private TbsCenterGoodBirDTO getTbsCenterGoodBirDTO(List centerGoods,List erpDispatchSumVoList) { + BigDecimal totalRealDispatch = BigDecimal.ZERO; + BigDecimal totalRealCost; + BigDecimal totalRealCheck = BigDecimal.ZERO; + BigDecimal totalRealRelease = BigDecimal.ZERO; + for (BirActivityCenterGoods centerGood : centerGoods) { + totalRealCheck = totalRealCheck.add(centerGood.getSplitUsedAmount()); + totalRealRelease = totalRealRelease.add(centerGood.getSplitReleaseAmount()); + for (ErpDispatchSumVo dispatchSumVo : erpDispatchSumVoList) { + if(centerGood.getKeyNum().equals(dispatchSumVo.getYearMonth())){ + totalRealDispatch = totalRealDispatch.add(dispatchSumVo.getDispatchSumCost()); + } + } + } + totalRealCost = totalRealCheck.add(totalRealRelease); + TbsCenterGoodBirDTO birDTO = new TbsCenterGoodBirDTO(); + birDTO.setRealCost(totalRealCost); + birDTO.setRealCheck(totalRealCheck); + birDTO.setRealRelease(totalRealRelease); + birDTO.initRealExpenseRate(); + return birDTO; + } /**