Browse Source

Merge remote-tracking branch 'origin/contract' into v1.0

# Conflicts:
#	src/main/java/com/qs/serve/modules/tbs/service/impl/TbsCostApplyServiceImpl.java
v1.0
Yen 2 years ago
parent
commit
ebe6f8c430
  1. 1
      pom.xml
  2. 2
      src/main/java/com/qs/serve/common/util/JsonUtil.java
  3. 6
      src/main/java/com/qs/serve/modules/tbs/common/TbsSeeYonConst.java
  4. 53
      src/main/java/com/qs/serve/modules/tbs/entity/dto/TbsContractCostSubItem.java
  5. 165
      src/main/java/com/qs/serve/modules/tbs/service/impl/TbsCostApplyOperationServiceImpl.java
  6. 653
      src/main/java/com/qs/serve/modules/tbs/service/impl/TbsCostApplyServiceImpl.java

1
pom.xml

@ -114,6 +114,7 @@
<version>${fastjson.version}</version> <version>${fastjson.version}</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>com.github.pagehelper</groupId> <groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper-spring-boot-starter</artifactId> <artifactId>pagehelper-spring-boot-starter</artifactId>

2
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.JavaType;
import com.fasterxml.jackson.databind.MapperFeature; import com.fasterxml.jackson.databind.MapperFeature;
import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
import lombok.experimental.UtilityClass; import lombok.experimental.UtilityClass;
import java.util.ArrayList; import java.util.ArrayList;
@ -31,6 +32,7 @@ public class JsonUtil {
static { static {
MAPPER.configure(MapperFeature.ACCEPT_CASE_INSENSITIVE_PROPERTIES, true); MAPPER.configure(MapperFeature.ACCEPT_CASE_INSENSITIVE_PROPERTIES, true);
MAPPER.setSerializationInclusion(JsonInclude.Include.NON_NULL); MAPPER.setSerializationInclusion(JsonInclude.Include.NON_NULL);
//MAPPER.registerModule(new JavaTimeModule());
} }
/** /**

6
src/main/java/com/qs/serve/modules/tbs/common/TbsSeeYonConst.java

@ -24,6 +24,12 @@ public interface TbsSeeYonConst {
return DevEnvironmentConfig.isDev()?"CostBill_Test":"CostBill"; return DevEnvironmentConfig.isDev()?"CostBill_Test":"CostBill";
} }
} }
/** 费用申请2-协议类 */
class CostApplyContractConf{
public static String Code(){
return DevEnvironmentConfig.isDev()?"contractApply_Test":"contractApply";
}
}
/** 核销 */ /** 核销 */
class CostCheckConf{ class CostCheckConf{

53
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;
}
}

165
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.consts.BudgetLogRollbackFlag;
import com.qs.serve.common.model.dto.R; import com.qs.serve.common.model.dto.R;
import com.qs.serve.common.util.Assert; 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.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.SeeYonOperationService;
import com.qs.serve.modules.seeyon.service.SeeYonRequestService; 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.mapper.SysUserMapper;
import com.qs.serve.modules.sys.service.SysPostUserService;
import com.qs.serve.modules.sys.service.SysUserService; import com.qs.serve.modules.sys.service.SysUserService;
import com.qs.serve.modules.tbs.common.TbsActivityState; import com.qs.serve.modules.tbs.common.TbsActivityState;
import com.qs.serve.modules.tbs.common.TbsCostApplyState; import com.qs.serve.modules.tbs.common.TbsCostApplyState;
@ -28,7 +38,10 @@ import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.stream.Collectors; import java.util.stream.Collectors;
/** /**
@ -68,11 +81,101 @@ public class TbsCostApplyOperationServiceImpl implements SeeYonOperationService
return TbsSeeYonConst.CostApplyConf.Code(); 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<String> result = getRequestService().checkAffairSummery(templateCode,targetId);
if(result.getData()==null){
return "next";
}
return result.getData();
}
@Override
public R<String> addNode(CtpAddNodeParam param) {
getRequestService().testConnection();
TbsCostApply tbsCostApply = costApplyService.getById(param.getTargetId());
CtpAddNodeDTO addNodeDTO = new CtpAddNodeDTO();
addNodeDTO.setBackToMe(param.getBackToMe());
addNodeDTO.setTargetId(param.getTargetId());
List<String> 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<String> result = getRequestService().addNode(addNodeDTO);
if(result.getData()!=null&&result.getData().toLowerCase(Locale.ROOT).contains("ok")){
return R.ok();
}
return R.error(result.getMsg());
}
@Override @Override
public SeeYonRequestService getRequestService() { public SeeYonRequestService getRequestService() {
return requestService; return requestService;
} }
@Override
public R<List<CtpAffairVo>> 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<List<CtpAffair>> syResult = getRequestService().commonListAffairs(targetId,null,templateCode);
List<CtpAffair> ctpAffairs = syResult.getData();
if(ctpAffairs.size()>0){
List<String> oaUserIds = ctpAffairs.stream().map(CtpAffair::getMemberId).collect(Collectors.toList());
List<SysUser> userList = getSysUserService().listByOaMemberIds(oaUserIds);
SysPostUserService postUserService = SpringUtils.getBean(SysPostUserService.class);
List<String> userIds = userList.stream().map(SysUser::getId).collect(Collectors.toList());
List<SysPostUser> postUserList = postUserService.listByUserIds(userIds);
Map<String,List<SysPostUser>> postMap = postUserList.stream().collect(Collectors.groupingBy(SysPostUser::getUserId));
List<CtpAffairVo> 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<SysPostUser> postUsers = postMap.get(user.getId());
ctpAffairVo.setUserPostList(postUsers);
}
}
result.add(ctpAffairVo);
}
return R.ok(result);
}
return R.ok(new ArrayList<>());
}
@Override @Override
public SysUserMapper getUserMapper() { public SysUserMapper getUserMapper() {
return userMapper; return userMapper;
@ -187,7 +290,42 @@ public class TbsCostApplyOperationServiceImpl implements SeeYonOperationService
@Override @Override
public R<?> commitAffair(TbsAffairCommitBo affairCommit) { 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<String> 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 @Override
@ -236,4 +374,29 @@ public class TbsCostApplyOperationServiceImpl implements SeeYonOperationService
} }
return null; 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无相关审批数据");
}
}
} }

653
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.BirActivityCenterGoods;
import com.qs.serve.modules.bir.entity.dto.BirRoiCostDTO; import com.qs.serve.modules.bir.entity.dto.BirRoiCostDTO;
import com.qs.serve.modules.bir.entity.vo.YtdQtdToOAVo; 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.bir.service.BirRoiRateService;
import com.qs.serve.modules.bms.entity.BmsRegion; import com.qs.serve.modules.bms.entity.BmsRegion;
import com.qs.serve.modules.bms.entity.BmsRegion2; 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.*;
import com.qs.serve.modules.tbs.entity.dto.TbsCenterGoodBirDTO; 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.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.entity.dto.TbsCostSubItem;
import com.qs.serve.modules.tbs.mapper.*; import com.qs.serve.modules.tbs.mapper.*;
import com.qs.serve.modules.tbs.service.*; import com.qs.serve.modules.tbs.service.*;
@ -83,17 +82,17 @@ public class TbsCostApplyServiceImpl extends ServiceImpl<TbsCostApplyMapper,TbsC
private BmsRegionMapper regionMapper; private BmsRegionMapper regionMapper;
private BmsRegion2Mapper region2Mapper; private BmsRegion2Mapper region2Mapper;
private BmsSubjectService subjectService; private BmsSubjectService subjectService;
private TbsCostTodoMapper tbsCostTodoMapper;
private TbsActivitySlottingFeeMapper activitySlottingFeeMapper; private TbsActivitySlottingFeeMapper activitySlottingFeeMapper;
private TbsActivityPayConditionMapper tbsActivityPayConditionMapper; private TbsActivityPayConditionMapper tbsActivityPayConditionMapper;
private TbsActivityMapper tbsActivityMapper; private TbsActivityMapper tbsActivityMapper;
private TbsActivityCenterGoodsMapper tbsActivityCenterGoodsMapper;
private ProjectProperties projectProperties; private ProjectProperties projectProperties;
private BirRoiRateService birRoiRateService; private BirRoiRateService birRoiRateService;
private TbsCostPercentMapper tbsCostPercentMapper; private TbsCostPercentMapper tbsCostPercentMapper;
private TbsScheduleItemBudgetMapper tbsScheduleItemBudgetMapper; private TbsScheduleItemBudgetMapper tbsScheduleItemBudgetMapper;
private final ErpDispatchDataMapper dispatchDataMapper; private final ErpDispatchDataMapper dispatchDataMapper;
private BirActivityCenterGoodsService birActivityCenterGoodsService; private TbsCostContractMapper costContractMapper;
private TbsBudgetMapper tbsBudgetMapper;
private BirCenterRateService centerRateService;
@Override @Override
@ -180,10 +179,11 @@ public class TbsCostApplyServiceImpl extends ServiceImpl<TbsCostApplyMapper,TbsC
} }
} }
List<TbsActivityPayCondition> payConditions = null;
if(tbsCostApply.getContractFlag()!=null&&tbsCostApply.getContractFlag().equals(1)){ if(tbsCostApply.getContractFlag()!=null&&tbsCostApply.getContractFlag().equals(1)){
LambdaQueryWrapper<TbsActivityPayCondition> lqw = new LambdaQueryWrapper<>(); LambdaQueryWrapper<TbsActivityPayCondition> lqw = new LambdaQueryWrapper<>();
lqw.eq(TbsActivityPayCondition::getCostApplyId,id); lqw.eq(TbsActivityPayCondition::getCostApplyId,id);
List<TbsActivityPayCondition> payConditions = tbsActivityPayConditionMapper.selectList(lqw); payConditions = tbsActivityPayConditionMapper.selectList(lqw);
if(payConditions.size()<1){ if(payConditions.size()<1){
Assert.throwEx("请补充支付条件"); Assert.throwEx("请补充支付条件");
} }
@ -218,27 +218,26 @@ public class TbsCostApplyServiceImpl extends ServiceImpl<TbsCostApplyMapper,TbsC
//恢复绑定 //恢复绑定
this.releaseCost(tbsCostApply.getId(),0); this.releaseCost(tbsCostApply.getId(),0);
Map<String, Object> data = new HashMap<>(10); Map<String, Object> data = new HashMap<>(10);
String actTitles = activityList.stream().map(TbsActivity::getActTitle).collect(Collectors.joining("; ")); if(tbsCostApply.getContractFlag()!=null&&tbsCostApply.getContractFlag().equals(1)){
data.put("title",tbsCostApply.getChargeTheme());
data.put("orgId",tbsCostApply.getId().toString());
data.put("costApplyCode", tbsCostApply.getCode()); data.put("costApplyCode", tbsCostApply.getCode());
data.put("applyUserCode", sysUser.getCode()); data.put("applyUserCode", sysUser.getCode());
data.put("applyUserName", sysUser.getName()); data.put("applyUserName", sysUser.getName());
data.put("supplierName", tbsCostApply.getSupplierName()); data.put("supplierName", tbsCostApply.getSupplierName());
data.put("supplierCode", tbsCostApply.getSupplierCode()); 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("targetId", tbsCostApply.getId()+"");
data.put("targetCode", tbsCostApply.getCode()); data.put("targetCode", tbsCostApply.getCode());
data.put("exsp1",TbsSeeYonConst.CostApplyConf.Code()); data.put("exsp1",TbsSeeYonConst.CostApplyContractConf.Code());
data.put("money",tbsCostApply.getTotalActivityAmount()); //添加跳转地址业务
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));
try { data.put("rowState","03");
this.buildMainData4ROI(tbsCostApply, data);
} catch (Exception e) {
e.printStackTrace();
}
//拓展添加审批关联区域 //拓展添加审批关联区域
String saleRegionId = supplier.handleSaleRegionId(); String saleRegionId = supplier.handleSaleRegionId();
@ -251,35 +250,115 @@ public class TbsCostApplyServiceImpl extends ServiceImpl<TbsCostApplyMapper,TbsC
//拓展添加审批关联 //拓展添加审批关联
data.put("biz_region",bizRegionNames); data.put("biz_region",bizRegionNames);
data.put("exsp2",saleRegionNames); data.put("exsp2",saleRegionNames);
data.put("data_state",TbsCostApplyState.State_1_apply.getCode()+""); data.put("dataState",TbsCostApplyState.State_1_apply.getCode()+"");
//添加跳转地址业务 //创建协议类data数据
String urlKey = "exsp5"+IdUtil.simpleUUID(); data.put("serialNumber",tbsCostApply.getCode());
String baseJumpUrl = JumpToUtil.getUrl(projectProperties.getHostUrl(),TbsSeeYonConst.CostApplyConf.Code(),urlKey); data.put("applySubject",tbsCostApply.getChargeTheme());
data.put("exsp5",urlKey); data.put("supplierCode",tbsCostApply.getSupplierCode());
data.put("cmsLink",baseJumpUrl); data.put("supplierName",tbsCostApply.getSupplierName());
data.put("activitySummary",actTitles); 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<TbsCostContract> lqw = new LambdaQueryWrapper<>();
lqw.eq(TbsCostContract::getCostApplyId,tbsCostApply.getId());
List<TbsCostContract> 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","");
}
//添加科目和成本中心
List<TbsActivityCenter> tbsActivityCenters = tbsActivityCenterService.listByCostApplyId(Long.parseLong(id));
List<TbsActivitySubject> tbsActivitySubjects = tbsActivitySubjectService.listByCostApplyId(Long.parseLong(id));
List<String> subjectNames = tbsActivitySubjects.stream().map(TbsActivitySubject::getSubjectName).distinct().collect(Collectors.toList());
List<Object> subList = new ArrayList<>();
//创建子表数据 //创建子表数据
this.buildSubList(result, tbsActivityCenters, subjectNames, subList); List<Object> subList = new ArrayList<>();
//创建商品抬头列表 //活动明细
List<TbsActivityGoods> tbsActivityGoods = tbsActivityGoodsService.listByCostApplyId(Long.parseLong(id)); LambdaQueryWrapper<TbsActivityCenterGoods> actCgLqw = new LambdaQueryWrapper<>();
Set<String> bands = new HashSet<>(); actCgLqw.eq(TbsActivityCenterGoods::getCostApplyId,id);
for (TbsActivityGoods tbsActivityGood : tbsActivityGoods) { List<TbsActivityCenterGoods> activityCenterGoodsList = tbsActivityCenterGoodsMapper.selectList(actCgLqw);
String band = tbsActivityGood.getTargetLevelPathNames().split("_")[0]; for (TbsActivityCenterGoods centerGoods : activityCenterGoodsList) {
bands.add(band); TbsActivity currActivity = null;
for (TbsActivity activity : activityList) {
if(centerGoods.getActivityId().equals(activity.getId())){
currActivity = activity;
break;
} }
String goods = bands.stream().collect(Collectors.joining(",")); }
data.put("chanPinPinLei",goods); 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);
}
// 付款条件
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);
}
// 协议条款
LambdaQueryWrapper<TbsCostTodo> todoLqw = new LambdaQueryWrapper<>();
todoLqw.eq(TbsCostTodo::getCostApplyId,tbsCostApply.getId());
List<TbsCostTodo> 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); data.put("sub", subList);
}else {
//创建通用的费用申请Data
this.buildCommonApplyData(id, tbsCostApply, activityList, supplier, result, sysUser, data);
}
//修改申请编码
String templateCode = tbsCostApply.getContractFlag().equals(1)
?TbsSeeYonConst.CostApplyContractConf.Code()
:TbsSeeYonConst.CostApplyConf.Code();
BaseCreateProcessBo createProcess = new BaseCreateProcessBo(); BaseCreateProcessBo createProcess = new BaseCreateProcessBo();
createProcess.setTemplateCode(TbsSeeYonConst.CostApplyConf.Code()); createProcess.setTemplateCode(templateCode);
createProcess.setMemberLoginName(sysUser.getSyAccount()); createProcess.setMemberLoginName(sysUser.getSyAccount());
createProcess.setSubjectTitle(TbsSeeYonConst.PRE_TITLE_COST_APPLY + tbsCostApply.getChargeTheme()); createProcess.setSubjectTitle(TbsSeeYonConst.PRE_TITLE_COST_APPLY + tbsCostApply.getChargeTheme());
createProcess.setTargetId(tbsCostApply.getId()+""); createProcess.setTargetId(tbsCostApply.getId()+"");
@ -290,7 +369,7 @@ public class TbsCostApplyServiceImpl extends ServiceImpl<TbsCostApplyMapper,TbsC
} }
String flowId = flowIdResult.getData(); String flowId = flowIdResult.getData();
String formId = null; String formId = null;
R<String> formIdResult = seeYonService.getFormId(TbsSeeYonConst.CostApplyConf.Code(),tbsCostApply.getId()); R<String> formIdResult = seeYonService.getFormId(templateCode,tbsCostApply.getId());
if(formIdResult.getStatus()==200){ if(formIdResult.getStatus()==200){
formId = formIdResult.getData(); formId = formIdResult.getData();
} }
@ -355,7 +434,7 @@ public class TbsCostApplyServiceImpl extends ServiceImpl<TbsCostApplyMapper,TbsC
budgetLogService.saveBatch(budgetLogList); budgetLogService.saveBatch(budgetLogList);
} }
//创建流程后回调 //创建流程后回调
BaseCreateCallbackBo callbackBo = new BaseCreateCallbackBo(TbsSeeYonConst.CostApplyConf.Code(),costApply.getId()+""); BaseCreateCallbackBo callbackBo = new BaseCreateCallbackBo(templateCode,costApply.getId()+"");
seeYonService.createCallbackStatus(callbackBo); seeYonService.createCallbackStatus(callbackBo);
activitySlottingFeeMapper.updatePassFlagByCostApplyId(costApply.getId(),2); activitySlottingFeeMapper.updatePassFlagByCostApplyId(costApply.getId(),2);
@ -364,6 +443,72 @@ public class TbsCostApplyServiceImpl extends ServiceImpl<TbsCostApplyMapper,TbsC
} }
private void buildCommonApplyData(String id, TbsCostApply tbsCostApply, List<TbsActivity> activityList, BmsSupplier supplier, TbsBudgetCostResult result, SysUser sysUser, Map<String, Object> 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<TbsActivityCenter> tbsActivityCenters = tbsActivityCenterService.listByCostApplyId(Long.parseLong(id));
List<TbsActivitySubject> tbsActivitySubjects = tbsActivitySubjectService.listByCostApplyId(Long.parseLong(id));
List<String> subjectNames = tbsActivitySubjects.stream().map(TbsActivitySubject::getSubjectName).distinct().collect(Collectors.toList());
List<Object> subList = new ArrayList<>();
//创建子表数据
try {
this.buildSubList(result, tbsActivityCenters, subjectNames, subList);
} catch (Exception e) {
e.printStackTrace();
}
//创建商品抬头列表
List<TbsActivityGoods> tbsActivityGoods = tbsActivityGoodsService.listByCostApplyId(Long.parseLong(id));
Set<String> 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 * @param tbsCostApply
@ -372,21 +517,21 @@ public class TbsCostApplyServiceImpl extends ServiceImpl<TbsCostApplyMapper,TbsC
private void buildMainData4ROI(TbsCostApply tbsCostApply, Map<String, Object> data) { private void buildMainData4ROI(TbsCostApply tbsCostApply, Map<String, Object> data) {
YtdQtdToOAVo ytdQtdToOAVo = birRoiRateService.buildYtdAndQtdData(tbsCostApply); YtdQtdToOAVo ytdQtdToOAVo = birRoiRateService.buildYtdAndQtdData(tbsCostApply);
data.put("ytdCusExpenseRate",ytdQtdToOAVo.getYtdCustomerPercent()==null? 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? 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? 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? 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? 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? 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? 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? 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()); // tbsCostPercentMapper.delByCostApplyId(tbsCostApply.getId());
@ -423,241 +568,181 @@ public class TbsCostApplyServiceImpl extends ServiceImpl<TbsCostApplyMapper,TbsC
subList.add(new TbsCostSubItem.Subject(subjectName)); subList.add(new TbsCostSubItem.Subject(subjectName));
} }
//目标费率和成本中心统计
List<TbsBudgetCostItem> tbsBudgetCostItems = result.getBudgetMatchList();
List<Long> scheduleItemBudgetIds = tbsBudgetCostItems.stream().map(a->a.getScheduleItemBudgetId()).distinct().collect(Collectors.toList());
List<TbsScheduleItemBudget> 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 year = LocalDate.now().getYear();
// int month = LocalDate.now().getMonthValue(); int month = LocalDate.now().getMonthValue();
// month = month>1?month:1; int startMonthNum = Integer.parseInt(year+"01");
// int startMonthNum = year*100 + 1; int endMonthNum = Integer.parseInt(year+"01");
// int endMonthNum = year*100 + month; tbsActivityCenters.stream().collect(Collectors.groupingBy(TbsActivityCenter::getCenterType));
// BirRoiRateService roiRateService = SpringUtils.getBean(BirRoiRateService.class); BirRoiRateService roiRateService = SpringUtils.getBean(BirRoiRateService.class);
// BirRoiCostDTO costDTO = new BirRoiCostDTO(); BirRoiCostDTO costDTO = new BirRoiCostDTO();
// costDTO.setStartMonthNum(startMonthNum); costDTO.setStartMonthNum(startMonthNum);
// costDTO.setEndMonthNum(endMonthNum); costDTO.setEndMonthNum(endMonthNum);
/*成本中心维度*/
//获取BIR表的数据,用于计算实际费用率 //发货单
// LambdaQueryWrapper<BirActivityCenterGoods> birLwq = new LambdaQueryWrapper<>(); Map<String,List<ErpDispatchSumVo>> supplierCodeMapWithCenterType = new HashMap<>();
// birLwq.in(BirActivityCenterGoods::getCenterId,tbsActivityCenters.stream().map(a->a.getCenterId()).collect(Collectors.toList())); Map<String,List<TbsActivityCenter>> centerMapList = tbsActivityCenters.stream().collect(Collectors.groupingBy(TbsActivityCenter::getCenterType));
// birLwq.ge(BirActivityCenterGoods::getKeyNum,startMonthNum); for (String centerType : centerMapList.keySet()) {
// birLwq.le(BirActivityCenterGoods::getKeyNum,endMonthNum); List<String> centerIds =centerMapList.get(centerType).stream().map(TbsActivityCenter::getCenterId).collect(Collectors.toList());
// List<BirActivityCenterGoods> birActivityCenterGoodsList = birActivityCenterGoodsService.list(birLwq); List<String> supplierCodeList = roiRateService.getSupplierCodesByCenter(costDTO,centerType,centerIds);
// Map<String,List<BirActivityCenterGoods>> birCenterCostMap = birActivityCenterGoodsList.stream().collect(Collectors.groupingBy(a->a.getCenterType() + "-"+a.getCenterId())); //发货单
//成本中心去重 List<ErpDispatchSumVo> dispatchSumVos = null;
Map<String,List<TbsActivityCenter>> centerMapList = tbsActivityCenters.stream().collect(Collectors.groupingBy(a->a.getCenterType()+"-"+a.getCenterId())); if(supplierCodeList!=null&&supplierCodeList.size()>0){
List<TbsActivityCenter> centerList = centerMapList.values().stream().map(a->a.get(0)).collect(Collectors.toList()); dispatchSumVos = dispatchDataMapper.querySumCost(startMonthNum,endMonthNum,supplierCodeList);
supplierCodeMapWithCenterType.put(centerType,dispatchSumVos);
for(TbsActivityCenter center : centerList){ }else {
TbsCostSubItem.CostCenterTranStr costCenter = centerRateService.buildCostCenter(center.getCenterType(),center.getCenterId(),center.getCenterName()); //防止后面获取空指针
supplierCodeMapWithCenterType.put(centerType,new ArrayList<>());
}
}
//查询ROI底表,并拼接DTO
List<TbsCenterGoodBirDTO> centerGoodDTOS = new ArrayList<>();
List<BirActivityCenterGoods> birActivityCenterGoodsList = new ArrayList<>();
//按成本中心维度分组
Map<String,List<BirActivityCenterGoods>> 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); 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取预算 * @param result
// LambdaQueryWrapper<TbsBudget> budgetLambdaQueryWrapper = new LambdaQueryWrapper<>(); * @param tbsScheduleItemBudgets
// budgetLambdaQueryWrapper.eq(TbsBudget::getCenterId,centerId); * @param year
// budgetLambdaQueryWrapper.eq(TbsBudget::getCenterType,centerType); * @param month
// List<TbsBudget> tbsBudgetList = tbsBudgetMapper.selectList(budgetLambdaQueryWrapper); * @param supplierCodeMapWithCenterType
// //通过预算ID取预算的发货和金额 * @param birGroupByCenter
// LambdaQueryWrapper<TbsScheduleItemBudget> scheduleItemBudgetLambdaQueryWrapper = new LambdaQueryWrapper<>(); * @param activityCenter
// scheduleItemBudgetLambdaQueryWrapper.in(TbsScheduleItemBudget::getBudgetId,tbsBudgetList.stream().map(a->a.getId()).collect(Collectors.toList())); * @param centerKey
// List<TbsScheduleItemBudget> scheduleItemBudgetList = tbsScheduleItemBudgetMapper.selectList(scheduleItemBudgetLambdaQueryWrapper); * @return
// //合计目标发货和金定额 */
// BigDecimal targetBudgetAmout = scheduleItemBudgetList.stream().map(a->a.getBudgetAmount()).reduce(BigDecimal.ZERO,BigDecimal::add); @NotNull
// BigDecimal targetDispatchAmout = scheduleItemBudgetList.stream().map(a->a.getPreDispatchAmount()==null?BigDecimal.ZERO:a.getPreDispatchAmount()).reduce(BigDecimal.ZERO,BigDecimal::add); private TbsCostSubItem.CostCenter buildCostCenterParam(TbsBudgetCostResult result, List<TbsScheduleItemBudget> tbsScheduleItemBudgets, int year, int month, Map<String, List<ErpDispatchSumVo>> supplierCodeMapWithCenterType, Map<String, List<BirActivityCenterGoods>> birGroupByCenter, TbsActivityCenter activityCenter, String centerKey) {
// costCenter.setTargetSales(targetDispatchAmout.toString()); TbsCostSubItem.CostCenter costCenter = new TbsCostSubItem.CostCenter(activityCenter.getCenterName(),
// costCenter.setAreaBudget(targetBudgetAmout.toString()); activityCenter.getCenterType()+"_"+ activityCenter.getCenterId());
// BigDecimal targetExpenseRate = BigDecimal.ZERO; //设置目标销量、目标预算
// if(targetDispatchAmout.compareTo(BigDecimal.ZERO)!=0) { for (TbsBudget budget : result.getBudgetList()) {
// targetExpenseRate = targetBudgetAmout.divide(targetDispatchAmout, 2, BigDecimal.ROUND_HALF_DOWN); boolean eqType = activityCenter.getCenterType().equals(budget.getCenterType());
// costCenter.setTargetExpenseRate(targetExpenseRate.toString()); boolean eqCost = activityCenter.getCenterId().equals(budget.getCenterId());
// costCenter.setYtdTargetExpenseRate(targetExpenseRate.toString()); if (eqType && eqCost) {
// } BigDecimal totalBudgetAmount = BigDecimal.ZERO;
//// costCenter.setTargetExpenseRate(targetExpenseRate); BigDecimal totalPreDispatchAmount = BigDecimal.ZERO;
// costCenter.setYtdTargetBudget(targetBudgetAmout.toString()); for (TbsScheduleItemBudget itemBudget : tbsScheduleItemBudgets) {
// costCenter.setYtdTargetSales(targetDispatchAmout.toString()); if (itemBudget.getBudgetId().equals(budget.getId())) {
//// costCenter.setYtdTargetExpenseRate(targetExpenseRate); if (itemBudget.getBudgetAmount() != null) {
// totalBudgetAmount = totalBudgetAmount.add(itemBudget.getBudgetAmount());
//// costCenter.setQtdTargetBudget(BigDecimal.ZERO); }
//// costCenter.setQtdTargetSales(BigDecimal.ZERO); if (itemBudget.getPreDispatchAmount() != null) {
//// costCenter.setQtdTargetExpenseRate(BigDecimal.ZERO); totalPreDispatchAmount = totalBudgetAmount.add(itemBudget.getPreDispatchAmount());
//// costCenter.setMtdTargetBudget(BigDecimal.ZERO); }
//// costCenter.setMtdTargetSales(BigDecimal.ZERO); }
//// costCenter.setMtdTargetExpenseRate(BigDecimal.ZERO); }
// /* ------------------------------------------------------------------------- */ costCenter.setAreaBudget(totalBudgetAmount);
// //实际发贷数 costCenter.setTargetSales(totalPreDispatchAmount);
// List<String> supplierCodeList = roiRateService.getSupplierCodesByCenter(costDTO,centerType,Arrays.asList(centerId)); if (totalPreDispatchAmount.compareTo(BigDecimal.ZERO) != 0) {
// List<ErpDispatchSumVo> dispatchSumVos = dispatchDataMapper.querySumCost(startMonthNum,endMonthNum,supplierCodeList); costCenter.setTargetExpenseRate(totalBudgetAmount.divide(totalPreDispatchAmount, BigDecimal.ROUND_DOWN));
// List<BirActivityCenterGoods> birCenterCost = birCenterCostMap.containsKey(centerKey)?birCenterCostMap.get(centerKey):new ArrayList<>(); }
// //暂保持目标相关数据一致
// /* --------------- 实际费用率YTD --------------------------------------------- */ costCenter.setYtdTargetSales(costCenter.getTargetSales());
// BigDecimal ytdRealDipatch = dispatchSumVos.stream().map(a->a.getDispatchSumCost()).reduce(BigDecimal.ZERO,BigDecimal::add); costCenter.setYtdTargetBudget(costCenter.getAreaBudget());
// BigDecimal ytdRealCost = birCenterCost.stream().map(a->a.getSplitUsedAmount()).reduce(BigDecimal.ZERO,BigDecimal::add); costCenter.setYtdTargetExpenseRate(costCenter.getTargetExpenseRate());
// costCenter.setYtdRealCost(ytdRealCost.toString()); costCenter.setQtdTargetSales(costCenter.getTargetSales());
// costCenter.setYtdRealSales(ytdRealDipatch.toString()); costCenter.setQtdTargetBudget(costCenter.getAreaBudget());
// BigDecimal ytdRealExpenseRate = BigDecimal.ZERO; costCenter.setQtdTargetExpenseRate(costCenter.getTargetExpenseRate());
// if(ytdRealDipatch.compareTo(BigDecimal.ZERO)!=0) { // costCenter.setMtdTargetSales();
// ytdRealExpenseRate = ytdRealCost.divide(ytdRealDipatch, 2, BigDecimal.ROUND_HALF_DOWN); // costCenter.setMtdTargetBudget();
// costCenter.setYtdRealExpenseRate(ytdRealExpenseRate.toString()); // costCenter.setMtdTargetExpenseRate();
// } break;
//// costCenter.setYtdRealExpenseRate(ytdRealExpenseRate);
// /* ------------------------------------------------------------------------- */ }
// }
// /* --------------- 实际费用率QTD --------------------------------------------- */ //发货金额
// List<Integer> yearQuarter = QuarterUtil.getQuarterNumbers(year, month); List<ErpDispatchSumVo> erpDispatchSumVoList = supplierCodeMapWithCenterType.get(centerKey);
// 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()); List<BirActivityCenterGoods> centerGoods = birGroupByCenter.get(centerKey);
// costCenter.setQtdRealSales(qtdRealDipatch.toString()); if(CollectionUtil.isNotEmpty(centerGoods)){
// BigDecimal qtdRealExpenseRate = BigDecimal.ZERO; //年费率
// if(qtdRealDipatch.compareTo(BigDecimal.ZERO)!=0) { TbsCenterGoodBirDTO bir4Year = this.getTbsCenterGoodBirDTO(centerGoods,erpDispatchSumVoList);
// qtdRealExpenseRate = qtdRealCost.divide(qtdRealDipatch, 2, BigDecimal.ROUND_HALF_DOWN); costCenter.setYtdRealSales(bir4Year.getRealSales());
// costCenter.setQtdRealExpenseRate(qtdRealExpenseRate.toString()); costCenter.setYtdRealCost(bir4Year.getRealCost());
// } costCenter.setYtdRealExpenseRate(bir4Year.getRealExpenseRate());
//// costCenter.setQtdRealExpenseRate(qtdRealExpenseRate);
// /* ------------------------------------------------------------------------- */ //季度
// List<Integer> yearMonthList =QuarterUtil.getQuarterNumbers(year, month);
// /* --------------- 实际费用率MTD --------------------------------------------- */ List<BirActivityCenterGoods> centerGoodsQuarter = centerGoods.stream()
// Integer yearMonth = year*100 + month; .filter(a-> yearMonthList.contains(a.getKeyNum()))
// BigDecimal mtdRealDipatch = dispatchSumVos.stream().filter(a->yearMonth.equals(a.getYearMonth())).map(a->a.getDispatchSumCost()).reduce(BigDecimal.ZERO,BigDecimal::add); .collect(Collectors.toList());
// BigDecimal mtdRealCost = birCenterCost.stream().filter(a->yearMonth.equals(a.getKeyNum())).map(a->a.getSplitUsedAmount()).reduce(BigDecimal.ZERO,BigDecimal::add); TbsCenterGoodBirDTO bir4Quarter = this.getTbsCenterGoodBirDTO(centerGoodsQuarter,erpDispatchSumVoList);
// costCenter.setMtdRealCost(mtdRealCost.toString()); costCenter.setQtdRealSales(bir4Quarter.getRealSales());
// costCenter.setMtdRealSales(mtdRealDipatch.toString()); costCenter.setQtdRealCost(bir4Quarter.getRealCost());
// BigDecimal mtdRealExpenseRate = BigDecimal.ZERO; costCenter.setQtdRealExpenseRate(bir4Quarter.getRealExpenseRate());
// if(mtdRealDipatch.compareTo(BigDecimal.ZERO)!=0) {
// mtdRealExpenseRate = mtdRealCost.divide(mtdRealDipatch, 2, BigDecimal.ROUND_HALF_DOWN); //月份
// costCenter.setMtdRealExpenseRate(mtdRealExpenseRate.toString()); String mStr = month >9? month +"":"0"+ month;
// } Integer currYearMonth = Integer.parseInt(year +mStr);
//// costCenter.setMtdRealExpenseRate(mtdRealExpenseRate); List<BirActivityCenterGoods> centerGoodsM = centerGoods.stream()
// /* ------------------------------------------------------------------------- */ .filter(a-> currYearMonth.equals(a.getKeyNum()))
.collect(Collectors.toList());
TbsCenterGoodBirDTO bir4Month = this.getTbsCenterGoodBirDTO(centerGoodsM,erpDispatchSumVoList);
// subList.add(costCenter); costCenter.setMtdRealSales(bir4Month.getRealSales());
} costCenter.setMtdRealCost(bir4Month.getRealCost());
costCenter.setMtdRealExpenseRate(bir4Month.getRealExpenseRate());
} }
return costCenter;
// /** }
// * 创建成本中心维度对象(弃)
// * @param result /**
// * @param tbsScheduleItemBudgets * 创建 成本中心 DTO
// * @param year * @param centerGoods
// * @param month * @param erpDispatchSumVoList
// * @param supplierCodeMapWithCenterType * @return
// * @param birGroupByCenter */
// * @param activityCenter @NotNull
// * @param centerKey private TbsCenterGoodBirDTO getTbsCenterGoodBirDTO(List<BirActivityCenterGoods> centerGoods,List<ErpDispatchSumVo> erpDispatchSumVoList) {
// * @return BigDecimal totalRealDispatch = BigDecimal.ZERO;
// */ BigDecimal totalRealCost;
// @NotNull BigDecimal totalRealCheck = BigDecimal.ZERO;
// private TbsCostSubItem.CostCenter buildCostCenterParam(TbsBudgetCostResult result, List<TbsScheduleItemBudget> tbsScheduleItemBudgets, BigDecimal totalRealRelease = BigDecimal.ZERO;
// int year, int month, Map<String, List<ErpDispatchSumVo>> supplierCodeMapWithCenterType, for (BirActivityCenterGoods centerGood : centerGoods) {
// Map<String, List<BirActivityCenterGoods>> birGroupByCenter, totalRealCheck = totalRealCheck.add(centerGood.getSplitUsedAmount());
// TbsActivityCenter activityCenter, String centerKey) { totalRealRelease = totalRealRelease.add(centerGood.getSplitReleaseAmount());
// TbsCostSubItem.CostCenter costCenter = new TbsCostSubItem.CostCenter(activityCenter.getCenterName(), for (ErpDispatchSumVo dispatchSumVo : erpDispatchSumVoList) {
// activityCenter.getCenterType()+"_"+ activityCenter.getCenterId()); if(centerGood.getKeyNum().equals(dispatchSumVo.getYearMonth())){
// //设置目标销量、目标预算 totalRealDispatch = totalRealDispatch.add(dispatchSumVo.getDispatchSumCost());
// for (TbsBudget budget : result.getBudgetList()) { }
// boolean eqType = activityCenter.getCenterType().equals(budget.getCenterType()); }
// boolean eqCost = activityCenter.getCenterId().equals(budget.getCenterId()); }
// if (eqType && eqCost) { totalRealCost = totalRealCheck.add(totalRealRelease);
// BigDecimal totalBudgetAmount = BigDecimal.ZERO; TbsCenterGoodBirDTO birDTO = new TbsCenterGoodBirDTO();
// BigDecimal totalPreDispatchAmount = BigDecimal.ZERO; birDTO.setRealCost(totalRealCost);
// //从命中的预算周期中取出目标发货 和 目标预算 进行合计 birDTO.setRealCheck(totalRealCheck);
// for (TbsScheduleItemBudget itemBudget : tbsScheduleItemBudgets) { birDTO.setRealRelease(totalRealRelease);
// if (itemBudget.getBudgetId().equals(budget.getId())) { birDTO.initRealExpenseRate();
// if (itemBudget.getBudgetAmount() != null) { return birDTO;
// 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<ErpDispatchSumVo> erpDispatchSumVoList = supplierCodeMapWithCenterType.get(centerKey);
//
// //所有相关费率记录
// List<BirActivityCenterGoods> 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<Integer> yearMonthList =QuarterUtil.getQuarterNumbers(year, month);
// List<BirActivityCenterGoods> 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<BirActivityCenterGoods> 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<BirActivityCenterGoods> centerGoods,List<ErpDispatchSumVo> 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;
// }
/** /**

Loading…
Cancel
Save