11 changed files with 800 additions and 8 deletions
@ -0,0 +1,18 @@ |
|||||
|
package com.qs.serve.modules.third.entity; |
||||
|
|
||||
|
import lombok.Data; |
||||
|
|
||||
|
import java.math.BigDecimal; |
||||
|
|
||||
|
/** |
||||
|
* @author YenHex |
||||
|
* @since 2023/2/14 |
||||
|
*/ |
||||
|
@Data |
||||
|
public class ProcessCenterItem { |
||||
|
|
||||
|
private String centerType; |
||||
|
private String centerCode; |
||||
|
private BigDecimal centerRate; |
||||
|
|
||||
|
} |
@ -0,0 +1,15 @@ |
|||||
|
package com.qs.serve.modules.third.entity.param; |
||||
|
|
||||
|
import lombok.Data; |
||||
|
|
||||
|
/** |
||||
|
* @author YenHex |
||||
|
* @since 2025/3/31 |
||||
|
*/ |
||||
|
@Data |
||||
|
public class DHXDelCostParam { |
||||
|
|
||||
|
String code; |
||||
|
String remark; |
||||
|
|
||||
|
} |
@ -0,0 +1,663 @@ |
|||||
|
package com.qs.serve.modules.third.service; |
||||
|
|
||||
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
||||
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
||||
|
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; |
||||
|
import com.qs.serve.common.config.properties.ProjectApisProperties; |
||||
|
import com.qs.serve.common.model.consts.ResultFlag; |
||||
|
import com.qs.serve.common.model.consts.SysConfigKey; |
||||
|
import com.qs.serve.common.model.enums.BudgetLogOptFlag; |
||||
|
import com.qs.serve.common.util.*; |
||||
|
import com.qs.serve.modules.bms.entity.*; |
||||
|
import com.qs.serve.modules.bms.service.*; |
||||
|
import com.qs.serve.modules.goods.entity.GoodsCategory; |
||||
|
import com.qs.serve.modules.goods.entity.GoodsSku; |
||||
|
import com.qs.serve.modules.goods.entity.GoodsSpu; |
||||
|
import com.qs.serve.modules.goods.entity.dto.TbsCenterDto; |
||||
|
import com.qs.serve.modules.goods.service.GoodsCategoryService; |
||||
|
import com.qs.serve.modules.goods.service.GoodsSkuService; |
||||
|
import com.qs.serve.modules.goods.service.GoodsSpuService; |
||||
|
import com.qs.serve.modules.pay.common.PaymentType; |
||||
|
import com.qs.serve.modules.pay.entity.PayPayment; |
||||
|
import com.qs.serve.modules.pay.entity.PayPaymentItem; |
||||
|
import com.qs.serve.modules.pay.service.PayPaymentItemService; |
||||
|
import com.qs.serve.modules.pay.service.PayPaymentService; |
||||
|
import com.qs.serve.modules.seeyon.service.XiaoLuTonService; |
||||
|
import com.qs.serve.modules.sys.entity.SysConfig; |
||||
|
import com.qs.serve.modules.sys.entity.SysSyncLog; |
||||
|
import com.qs.serve.modules.sys.entity.SysUser; |
||||
|
import com.qs.serve.modules.sys.mapper.SysTableTempMapper; |
||||
|
import com.qs.serve.modules.sys.mapper.SysUserCodeMathMapper; |
||||
|
import com.qs.serve.modules.sys.service.SysConfigService; |
||||
|
import com.qs.serve.modules.sys.service.SysSyncLogService; |
||||
|
import com.qs.serve.modules.sys.service.SysUserService; |
||||
|
import com.qs.serve.modules.tbs.common.TbsActivityState; |
||||
|
import com.qs.serve.modules.tbs.common.TbsCostApplyState; |
||||
|
import com.qs.serve.modules.tbs.common.util.TbsBudgetLogBuildUtil; |
||||
|
import com.qs.serve.modules.tbs.entity.*; |
||||
|
import com.qs.serve.modules.tbs.entity.dto.TbsBudgetCostResult; |
||||
|
import com.qs.serve.modules.tbs.entity.so.TbsScheduleItemSearch; |
||||
|
import com.qs.serve.modules.tbs.mapper.TbsBudgetMapper; |
||||
|
import com.qs.serve.modules.tbs.mapper.TbsCostApplyMapper; |
||||
|
import com.qs.serve.modules.tbs.service.*; |
||||
|
import com.qs.serve.modules.third.entity.*; |
||||
|
import com.qs.serve.modules.third.util.ThirtyVerificationUtil; |
||||
|
import com.qs.serve.modules.tzc.common.TzPolicyItemStatus; |
||||
|
import com.qs.serve.modules.tzc.entity.TzcPolicyItem; |
||||
|
import com.qs.serve.modules.tzc.entity.TzcPolicyItemLog; |
||||
|
import com.qs.serve.modules.tzc.mapper.TzcPolicyItemMapper; |
||||
|
import com.qs.serve.modules.tzc.service.TzcPolicyGoodsSyncService; |
||||
|
import com.qs.serve.modules.tzc.service.TzcPolicyItemLogService; |
||||
|
import com.qs.serve.modules.tzc.service.TzcPolicyItemService; |
||||
|
import com.qs.serve.modules.vtb.common.VtbVerificationState; |
||||
|
import com.qs.serve.modules.vtb.entity.VtbVerification; |
||||
|
import com.qs.serve.modules.vtb.entity.VtbVerificationSubject; |
||||
|
import com.qs.serve.modules.vtb.mapper.VtbVerificationSubjectMapper; |
||||
|
import com.qs.serve.modules.vtb.service.VtbFundFlowService; |
||||
|
import com.qs.serve.modules.vtb.service.VtbVerificationService; |
||||
|
import com.qs.serve.modules.vtb.service.VtbVerificationSubjectService; |
||||
|
import lombok.AllArgsConstructor; |
||||
|
import lombok.extern.slf4j.Slf4j; |
||||
|
import org.jetbrains.annotations.NotNull; |
||||
|
import org.springframework.stereotype.Service; |
||||
|
import org.springframework.transaction.annotation.Transactional; |
||||
|
|
||||
|
import java.math.BigDecimal; |
||||
|
import java.math.RoundingMode; |
||||
|
import java.time.LocalDate; |
||||
|
import java.time.LocalDateTime; |
||||
|
import java.util.*; |
||||
|
import java.util.stream.Collectors; |
||||
|
|
||||
|
/** |
||||
|
* @author YenHex |
||||
|
* @since 2023/2/14 |
||||
|
*/ |
||||
|
@Slf4j |
||||
|
@Service |
||||
|
@AllArgsConstructor |
||||
|
public class PortalOfCost2Application { |
||||
|
|
||||
|
private SysUserCodeMathMapper userCodeMathMapper; |
||||
|
private final SysSyncLogService sysSyncLogService; |
||||
|
private TbsActivityService activityService; |
||||
|
private TbsActivityCenterService activityCenterService; |
||||
|
private TbsActivitySubjectService activitySubjectService; |
||||
|
private TbsActivityGoodsService activityGoodsService; |
||||
|
private TbsActivityCenterGoodsService activityCenterGoodsService; |
||||
|
|
||||
|
private BmsSupplierService supplierService; |
||||
|
private BmsSubjectService subjectService; |
||||
|
private BmsCostCenterService costCenterService; |
||||
|
private BmsRegionService saleRegionService; |
||||
|
private BmsRegion2Service bizRegionService; |
||||
|
|
||||
|
private SysUserService userService; |
||||
|
|
||||
|
private TbsCostApplyService costApplyService; |
||||
|
private TbsBudgetCostItemService costItemService; |
||||
|
private TbsBudgetLogService budgetLogService; |
||||
|
private TbsBudgetApplicationService budgetApplicationService; |
||||
|
|
||||
|
|
||||
|
private GoodsSkuService goodsSkuService; |
||||
|
private GoodsSpuService goodsSpuService; |
||||
|
private GoodsCategoryService goodsCategoryService; |
||||
|
|
||||
|
private PayPaymentService paymentService; |
||||
|
|
||||
|
private VtbVerificationService verificationService; |
||||
|
private VtbVerificationSubjectService verificationSubjectService; |
||||
|
|
||||
|
|
||||
|
private ProjectApisProperties projectApisProperties; |
||||
|
|
||||
|
@Transactional(rollbackFor = Exception.class) |
||||
|
public void createCostProcess(ProcessCreateCostApplyBo createBo){ |
||||
|
SysUser user = userService.getByAccount(createBo.getUserCode()); |
||||
|
if(user==null){ |
||||
|
String newUcode = userCodeMathMapper.getNewCode(createBo.getUserCode()); |
||||
|
if(newUcode!=null){ |
||||
|
user = userService.getByAccount(newUcode); |
||||
|
} |
||||
|
} |
||||
|
if(user==null){Assert.throwEx("用户不存在,请重新编辑");} |
||||
|
BmsSupplier supplier = supplierService.getByCode(createBo.getCustomerCode(),createBo.getCustomerBelong()); |
||||
|
if(supplier==null){Assert.throwEx("客户不存在,请重新编辑");} |
||||
|
BmsSubject subject = subjectService.getByCode(createBo.getSubjectCode()); |
||||
|
if(subject==null){Assert.throwEx("科目不存在,请重新编辑");} |
||||
|
|
||||
|
final BigDecimal OneHundred = new BigDecimal("100"); |
||||
|
BigDecimal totalRate = BigDecimal.ZERO; |
||||
|
for (ProcessCenterItem item : createBo.getCenterList()) { |
||||
|
totalRate = totalRate.add(item.getCenterRate()); |
||||
|
if(item.getCenterRate().compareTo(BigDecimal.ZERO)<=0){ |
||||
|
Assert.throwEx("成本中心权重必须大于0"); |
||||
|
} |
||||
|
} |
||||
|
if(totalRate.compareTo(OneHundred)!=0){ |
||||
|
Assert.throwEx("成本中心权重合计必须为100"); |
||||
|
} |
||||
|
// 获取成本中心列表
|
||||
|
Map<String, TbsCenterDto> centerDtoMap = this.getTbsCenterDtoMap(createBo.getCenterList()); |
||||
|
//发票号
|
||||
|
String billNumber = createBo.getBillNumber(); |
||||
|
String disNumber = createBo.getErpCode(); |
||||
|
this.validBillNumAndDisNum(billNumber, disNumber); |
||||
|
//初始化sku列表
|
||||
|
List<ProcessGoodsItem> processGoodsItems = createBo.getGoodsList(); |
||||
|
List<String> invCodeList = new ArrayList<>(); |
||||
|
if(CollectionUtil.isNotEmpty(createBo.getGoodsList())){ |
||||
|
invCodeList = createBo.getGoodsList().stream() |
||||
|
.map(ProcessGoodsItem::getInventoryCode).distinct() |
||||
|
.filter(StringUtils::hasText).collect(Collectors.toList()); |
||||
|
} |
||||
|
if(invCodeList.size()<1){ |
||||
|
Assert.throwEx("请选择存货提交"); |
||||
|
} |
||||
|
String costCode = createBo.getCostCode(); |
||||
|
String costTheme = createBo.getCostTheme(); |
||||
|
List<GoodsSku> skuList = this.initSkuListOfProcess(invCodeList,!costCode.contains("YX06")); |
||||
|
//排除重复的sku
|
||||
|
skuList = this.filterRepSku(invCodeList, skuList); |
||||
|
//常用参数
|
||||
|
final String GOODS_TYPE = "sku"; |
||||
|
LocalDateTime nowTime = LocalDateTime.now(); |
||||
|
LocalDate nowDate = LocalDate.now(); |
||||
|
LocalDate startDate = createBo.getStartDate(); |
||||
|
LocalDate endDate = createBo.getEndDate(); |
||||
|
String erpCode = createBo.getErpCode(); |
||||
|
Long supplierId = Long.parseLong(supplier.getId()); |
||||
|
BigDecimal totalAmount = createBo.getTotalAmount(); |
||||
|
|
||||
|
if(totalAmount.compareTo(BigDecimal.ZERO)==0){ |
||||
|
Assert.throwEx("统计金额不能为0"); |
||||
|
} |
||||
|
|
||||
|
String activityTitle = createBo.getActivityTitle(); |
||||
|
if(!StringUtils.hasText(activityTitle)){ |
||||
|
activityTitle = "由核销API生成的活动"; |
||||
|
} |
||||
|
//构建费用申请
|
||||
|
TbsCostApply costApply = new TbsCostApply(); |
||||
|
costApply.setDisCode(disNumber); |
||||
|
costApply.setBillNumber(billNumber); |
||||
|
costApply.setCode(costCode); |
||||
|
costApply.setMatchType(1); |
||||
|
costApply.setChargeTheme(costTheme); |
||||
|
costApply.setChargeState(TbsCostApplyState.State_3_finished.getCode()); |
||||
|
costApply.setSupplierId(supplierId); |
||||
|
costApply.setSupplierName(supplier.getName()); |
||||
|
costApply.setSupplierCode(supplier.getCode()); |
||||
|
costApply.setUserId(user.getId()); |
||||
|
costApply.setUserCode(user.getCode()); |
||||
|
costApply.setUserName(user.getName()); |
||||
|
costApply.setTotalActivity(1); |
||||
|
costApply.setTotalActivityAmount(totalAmount); |
||||
|
costApply.setTotalActivityUsedAmount(totalAmount); |
||||
|
costApply.setSubmitTime(LocalDateTime.now()); |
||||
|
costApply.setRemark(createBo.getRemark()); |
||||
|
//构建活动
|
||||
|
TbsActivity activity = new TbsActivity(); |
||||
|
activity.setActivityCode(costCode); |
||||
|
activity.setActivityState(TbsActivityState.STATE_1_Finished); |
||||
|
activity.setCostPassFlag(1); |
||||
|
activity.setCostPassTime(nowTime); |
||||
|
activity.setActTitle(activityTitle); |
||||
|
activity.setSupplierId(supplierId); |
||||
|
activity.setSupplierName(supplier.getName()); |
||||
|
activity.setSupplierCode(supplier.getCode()); |
||||
|
activity.setActStartDate(startDate); |
||||
|
activity.setActEndDate(endDate); |
||||
|
activity.setPreStartDate(startDate); |
||||
|
activity.setPreEndDate(endDate); |
||||
|
activity.setPreCheckDate(nowDate); |
||||
|
activity.setTotalAmount(totalAmount); |
||||
|
activity.setUsedAmount(totalAmount); |
||||
|
activity.setFinishedFlag(ResultFlag.OK); |
||||
|
activity.setFinishedTime(nowTime); |
||||
|
//活动-科目
|
||||
|
TbsActivitySubject activitySubject = new TbsActivitySubject(); |
||||
|
activitySubject.setSubjectId(subject.getId()); |
||||
|
activitySubject.setSubjectCode(subject.getSubjectCode()); |
||||
|
activitySubject.setSubjectName(subject.getSubjectName()); |
||||
|
activitySubject.setAmount(totalAmount); |
||||
|
activitySubject.setUsedAmount(totalAmount); |
||||
|
activitySubject.setCountSession(0); |
||||
|
activitySubject.setCountPerson(0); |
||||
|
|
||||
|
// 分配成本中心
|
||||
|
List<TbsActivityCenter> activityCenterList = getTbsActivityCenters(subject, OneHundred, centerDtoMap, totalAmount); |
||||
|
|
||||
|
//活动-商品
|
||||
|
List<TbsActivityGoods> activityGoodsList = new ArrayList<>(); |
||||
|
for (GoodsSku sku : skuList) { |
||||
|
GoodsSpu goodsSpu = goodsSpuService.getById(sku.getSpuId()); |
||||
|
GoodsCategory category1 = goodsCategoryService.getById(goodsSpu.getCategoryFirst()); |
||||
|
GoodsCategory category2 = goodsCategoryService.getById(goodsSpu.getCategorySecond()); |
||||
|
GoodsCategory category3 = goodsCategoryService.getById(goodsSpu.getCategoryThird()); |
||||
|
TbsActivityGoods activityGoods = new TbsActivityGoods(); |
||||
|
activityGoods.setTargetType(GOODS_TYPE); |
||||
|
activityGoods.setTargetId(sku.getId()); |
||||
|
activityGoods.setTargetCode(sku.getSkuCode()); |
||||
|
activityGoods.setTargetName(sku.getSkuName()); |
||||
|
activityGoods.setTargetLevelPathIds(category1.getId()+"_"+category2.getId()+"_"+category3.getId()+"_"+goodsSpu.getId()+"_"+sku.getId()); |
||||
|
activityGoods.setTargetLevelPathNames(category1.getName()+"_"+category2.getName()+"_"+category3.getName()+"_"+goodsSpu.getName()+"_"+sku.getSpecInfos()); |
||||
|
activityGoodsList.add(activityGoods); |
||||
|
} |
||||
|
//活动-商品与成本中心记录
|
||||
|
List<TbsActivityCenterGoods> activityCenterGoodsList = getTbsActivityCenterGoods(supplier, subject, OneHundred, |
||||
|
processGoodsItems, costCode, nowDate, startDate, endDate, supplierId, totalAmount, activity, |
||||
|
activityCenterList, activityGoodsList); |
||||
|
|
||||
|
//保存活动有关数据
|
||||
|
costApplyService.save(costApply); |
||||
|
activity.setCostApplyId(costApply.getId()); |
||||
|
activityService.save(activity); |
||||
|
activitySubject.setCostApplyId(costApply.getId()); |
||||
|
activitySubject.setActivityId(activity.getId()); |
||||
|
activitySubjectService.save(activitySubject); |
||||
|
activityCenterList.forEach(center->{ |
||||
|
center.setCostApplyId(costApply.getId()); |
||||
|
center.setActivityId(activity.getId()); |
||||
|
}); |
||||
|
activityCenterService.saveBatch(activityCenterList); |
||||
|
activityGoodsList.forEach(item->{ |
||||
|
item.setCostApplyId(costApply.getId()); |
||||
|
item.setActivityId(activity.getId()); |
||||
|
}); |
||||
|
activityGoodsService.saveBatch(activityGoodsList); |
||||
|
activityCenterGoodsList.forEach(item->{ |
||||
|
item.setCostApplyId(costApply.getId()); |
||||
|
item.setActivityId(activity.getId()); |
||||
|
}); |
||||
|
activityCenterGoodsService.saveBatch(activityCenterGoodsList); |
||||
|
|
||||
|
//获取匹配的预算结果
|
||||
|
TbsBudgetCostResult budgetCostResult = budgetApplicationService.buildBudgetCostResult( |
||||
|
costApply.getId(), |
||||
|
Arrays.asList(activity), |
||||
|
Arrays.asList(activitySubject), |
||||
|
activityCenterGoodsList, |
||||
|
activityCenterList,false,true,false); |
||||
|
|
||||
|
//不匹配的商品,保存到无预算表
|
||||
|
List<TbsBudgetCostItem> unMatchBudgetItem = budgetCostResult.getBudgetUnMatchList(); |
||||
|
if(unMatchBudgetItem.size()>0){ |
||||
|
String codes = unMatchBudgetItem.stream().map(TbsBudgetCostItem::getTargetCode).collect(Collectors.joining(",")); |
||||
|
Assert.throwEx("未能匹配到预算:"+codes); |
||||
|
} |
||||
|
|
||||
|
//匹配的商品,生成预算日志
|
||||
|
List<TbsBudgetCostItem> matchBudgetItem = budgetCostResult.getBudgetMatchList(); |
||||
|
List<TbsBudgetLog> budgetLogList = new ArrayList<>(); |
||||
|
if(CollectionUtil.isNotEmpty(matchBudgetItem)){ |
||||
|
for (TbsBudgetCostItem costItem : matchBudgetItem) { |
||||
|
TbsBudget currBudget = null; |
||||
|
for (TbsBudget budget : budgetCostResult.getBudgetList()) { |
||||
|
if(costItem.getBudgetId().equals(budget.getId())){ |
||||
|
currBudget = budget; |
||||
|
break; |
||||
|
} |
||||
|
} |
||||
|
TbsBudgetLog budgetLog = TbsBudgetLogBuildUtil.buildTbsBudgetLog(BudgetLogOptFlag.State_1,user, costApply, costItem, currBudget,costItem.getCenterGoodsAmount(),activity); |
||||
|
budgetLogList.add(budgetLog); |
||||
|
} |
||||
|
} |
||||
|
costItemService.saveBatch(matchBudgetItem); |
||||
|
budgetLogService.saveBatch(budgetLogList); |
||||
|
|
||||
|
//保存核销申请
|
||||
|
VtbVerification verification = new VtbVerification(); |
||||
|
verification.setDisCode(disNumber); |
||||
|
verification.setBillNumber(billNumber); |
||||
|
verification.setVerificationCode(costCode); |
||||
|
verification.setVerificationMainCode(verification.getVerificationCode()); |
||||
|
verification.setCostApplyId(costApply.getId()); |
||||
|
verification.setFinishedTime(nowTime); |
||||
|
verification.setVerificationState(VtbVerificationState.Finished.getCode()); |
||||
|
verification.setActivityId(activity.getId()); |
||||
|
verification.setSupplierId(activity.getSupplierId()); |
||||
|
verification.setSupplierCode(activity.getSupplierCode()); |
||||
|
verification.setSupplierName(activity.getSupplierName()); |
||||
|
verification.setUserId(user.getId()); |
||||
|
verification.setUserCode(user.getCode()); |
||||
|
verification.setUserName(user.getName()); |
||||
|
verification.setAmount(totalAmount); |
||||
|
verification.setAmountRecord(totalAmount); |
||||
|
verification.setPaymentState(ResultFlag.OK); |
||||
|
verificationService.save(verification); |
||||
|
|
||||
|
//保存核销费用结果
|
||||
|
VtbVerificationSubject verificationSubject = new VtbVerificationSubject(); |
||||
|
verificationSubject.setVerificationId(verification.getId()); |
||||
|
verificationSubject.setVerificationSubCode(verification.getVerificationCode()+"_1"); |
||||
|
verificationSubject.setCostApplyId(costApply.getId()); |
||||
|
verificationSubject.setActivityId(activity.getId()); |
||||
|
verificationSubject.setSubjectId(subject.getId()); |
||||
|
verificationSubject.setSubjectCode(subject.getSubjectCode()); |
||||
|
verificationSubject.setSubjectName(subject.getSubjectName()); |
||||
|
verificationSubject.setSupplierId(Long.parseLong(supplier.getId())); |
||||
|
verificationSubject.setSupplierCode(supplier.getCode()); |
||||
|
verificationSubject.setSupplierName(supplier.getName()); |
||||
|
verificationSubject.setPayFinishedFlag(ResultFlag.OK); |
||||
|
verificationSubject.setUsedAmount(totalAmount); |
||||
|
verificationSubject.setUsedAmountRecord(totalAmount); |
||||
|
verificationSubject.setCountPerson(0); |
||||
|
verificationSubject.setCountSession(0); |
||||
|
verificationSubjectService.save(verificationSubject); |
||||
|
|
||||
|
//保存支付信息(DHX赠品)
|
||||
|
if(costCode.indexOf("DHX")==0||costCode.contains("YX06")) { |
||||
|
// 赠品支持忽略参数
|
||||
|
boolean ignoreDhxPay = costCode.indexOf("DHX")==0&&createBo.getIgnorePayFlag()!=null&&createBo.getIgnorePayFlag()==1; |
||||
|
if(!ignoreDhxPay){ |
||||
|
this.payToErpAPI(supplier, subject, totalAmount, costApply, activity, activitySubject, |
||||
|
activityCenterList.get(0), activityGoodsList, activityCenterGoodsList, |
||||
|
budgetLogList, verification, verificationSubject); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
} |
||||
|
|
||||
|
@NotNull |
||||
|
private List<TbsActivityCenterGoods> getTbsActivityCenterGoods(BmsSupplier supplier, BmsSubject subject, BigDecimal OneHundred, List<ProcessGoodsItem> processGoodsItems, String costCode, LocalDate nowDate, LocalDate startDate, LocalDate endDate, Long supplierId, BigDecimal totalAmount, TbsActivity activity, List<TbsActivityCenter> activityCenterList, List<TbsActivityGoods> activityGoodsList) { |
||||
|
List<TbsActivityCenterGoods> activityCenterGoodsList = new ArrayList<>(); |
||||
|
|
||||
|
for (TbsActivityCenter activityCenter : activityCenterList) { |
||||
|
BigDecimal yx06Surplus = activityCenter.getCenterAmount(); |
||||
|
BigDecimal yx06SurplusRate = new BigDecimal("100"); |
||||
|
BigDecimal yx06ItemAmt = activityCenter.getCenterAmount() |
||||
|
.divide(new BigDecimal(activityGoodsList.size()), RoundingMode.DOWN); |
||||
|
BigDecimal yx06Rate = yx06ItemAmt.divide(activityCenter.getCenterAmount(), RoundingMode.DOWN); |
||||
|
for (int i = 0; i < activityGoodsList.size(); i++) { |
||||
|
TbsActivityGoods activityGoods = activityGoodsList.get(i); |
||||
|
TbsActivityCenterGoods centerGoods = new TbsActivityCenterGoods(); |
||||
|
centerGoods.setActivityCode(activity.getActivityCode()); |
||||
|
centerGoods.setCenterGoodsCode(activity.getActivityCode()+"_"+(i+1)); |
||||
|
centerGoods.setSupplierId(supplierId); |
||||
|
centerGoods.setSupplierCode(supplier.getCode()); |
||||
|
centerGoods.setSupplierName(supplier.getName()); |
||||
|
//设置成本中心
|
||||
|
centerGoods.setCenterType(activityCenter.getCenterType()); |
||||
|
centerGoods.setCenterId(activityCenter.getCenterId()); |
||||
|
centerGoods.setCenterName(activityCenter.getCenterName()); |
||||
|
centerGoods.setCenterCode(activityCenter.getCenterCode()); |
||||
|
centerGoods.setCenterRate(OneHundred); |
||||
|
centerGoods.setCenterAmount(totalAmount); |
||||
|
//设置科目
|
||||
|
centerGoods.setSubjectId(subject.getId()); |
||||
|
centerGoods.setSubjectCode(subject.getSubjectCode()); |
||||
|
centerGoods.setSubjectName(subject.getSubjectName()); |
||||
|
//设置活动时间
|
||||
|
centerGoods.setActEndDate(endDate); |
||||
|
centerGoods.setActStartDate(startDate); |
||||
|
centerGoods.setPreEndDate(endDate); |
||||
|
centerGoods.setPreStartDate(startDate); |
||||
|
centerGoods.setPreCheckDate(nowDate); |
||||
|
//设置目标
|
||||
|
centerGoods.setTargetId(activityGoods.getTargetId()); |
||||
|
centerGoods.setTargetType(activityGoods.getTargetType()); |
||||
|
centerGoods.setTargetCode(activityGoods.getTargetCode()); |
||||
|
centerGoods.setTargetName(activityGoods.getTargetName()); |
||||
|
centerGoods.setTargetLevelPathIds(activityGoods.getTargetLevelPathIds()); |
||||
|
centerGoods.setTargetLevelPathNames(activityGoods.getTargetLevelPathNames()); |
||||
|
// 分配金额
|
||||
|
if (costCode.contains("YX06")){ |
||||
|
if(i+1== activityGoodsList.size()){ |
||||
|
centerGoods.setCenterGoodsAmount(yx06Surplus); |
||||
|
centerGoods.setCenterGoodsRate(yx06SurplusRate); |
||||
|
centerGoods.setUsedAmount(yx06Surplus); |
||||
|
}else { |
||||
|
yx06SurplusRate = yx06SurplusRate.subtract(yx06Rate); |
||||
|
yx06Surplus = yx06Surplus.subtract(yx06ItemAmt); |
||||
|
centerGoods.setCenterGoodsAmount(yx06ItemAmt); |
||||
|
centerGoods.setCenterGoodsRate(yx06Rate); |
||||
|
centerGoods.setUsedAmount(yx06ItemAmt); |
||||
|
} |
||||
|
}else { |
||||
|
BigDecimal totalSkuAmt = BigDecimal.ZERO; |
||||
|
for (ProcessGoodsItem goodsItem : processGoodsItems) { |
||||
|
if(goodsItem.getInventoryCode().equals(activityGoods.getTargetCode())){ |
||||
|
totalSkuAmt = totalSkuAmt.add(goodsItem.getAmount()); |
||||
|
} |
||||
|
} |
||||
|
BigDecimal rate = totalSkuAmt.divide(totalAmount, RoundingMode.UP); |
||||
|
centerGoods.setCenterGoodsAmount(totalSkuAmt); |
||||
|
centerGoods.setCenterGoodsRate(rate); |
||||
|
centerGoods.setUsedAmount(totalSkuAmt); |
||||
|
} |
||||
|
activityCenterGoodsList.add(centerGoods); |
||||
|
} |
||||
|
} |
||||
|
return activityCenterGoodsList; |
||||
|
} |
||||
|
|
||||
|
@NotNull |
||||
|
private List<TbsActivityCenter> getTbsActivityCenters(BmsSubject subject, BigDecimal OneHundred, Map<String, TbsCenterDto> centerDtoMap, BigDecimal totalAmount) { |
||||
|
List<TbsActivityCenter> activityCenterList = new ArrayList<>(); |
||||
|
BigDecimal surplusAmount = totalAmount; |
||||
|
Set<String> centerTypes = centerDtoMap.keySet(); |
||||
|
Iterator<String> itr = centerTypes.iterator(); |
||||
|
while (itr.hasNext()){ |
||||
|
String centerType = itr.next(); |
||||
|
TbsCenterDto center = centerDtoMap.get(centerType); |
||||
|
BigDecimal rateAmt = null; |
||||
|
if(itr.hasNext()){ |
||||
|
rateAmt = center.getCenterRate() |
||||
|
.divide(OneHundred,2,BigDecimal.ROUND_HALF_UP) |
||||
|
.multiply(totalAmount); |
||||
|
surplusAmount = surplusAmount.subtract(rateAmt); |
||||
|
}else { |
||||
|
// 最后一项使用剩余
|
||||
|
rateAmt = surplusAmount; |
||||
|
} |
||||
|
//活动-成本中心
|
||||
|
TbsActivityCenter activityCenter = new TbsActivityCenter(); |
||||
|
activityCenter.setSubjectId(subject.getId()); |
||||
|
activityCenter.setCenterAmount(rateAmt); |
||||
|
activityCenter.setCenterRate(OneHundred); |
||||
|
activityCenter.setCenterType(centerType); |
||||
|
activityCenter.setCenterId(center.getId()); |
||||
|
activityCenter.setCenterName(center.getCenterName()); |
||||
|
activityCenter.setCenterCode(center.getCenterCode()); |
||||
|
activityCenter.setUsedAmount(rateAmt); |
||||
|
activityCenterList.add(activityCenter); |
||||
|
} |
||||
|
return activityCenterList; |
||||
|
} |
||||
|
|
||||
|
private void validBillNumAndDisNum(String billNumber, String disNumber) { |
||||
|
//拦截是否已保存
|
||||
|
if(StringUtils.hasText(billNumber)){ |
||||
|
LambdaQueryWrapper<PayPayment> payLqw = new LambdaQueryWrapper<>(); |
||||
|
payLqw.eq(PayPayment::getBillNumber, billNumber); |
||||
|
long countPay = paymentService.count(payLqw); |
||||
|
if(countPay>0){Assert.throwEx("发票号已存在,请勿重复提交");} |
||||
|
|
||||
|
LambdaQueryWrapper<TbsCostApply> lqw = new LambdaQueryWrapper<>(); |
||||
|
lqw.eq(TbsCostApply::getBillNumber, billNumber); |
||||
|
long countPay2 = costApplyService.count(lqw); |
||||
|
if(countPay2>0){Assert.throwEx("发票号已存在,请勿重复提交");} |
||||
|
|
||||
|
}else if (StringUtils.hasText(disNumber)){ |
||||
|
LambdaQueryWrapper<PayPayment> payLqw = new LambdaQueryWrapper<>(); |
||||
|
payLqw.eq(PayPayment::getErpCode, disNumber); |
||||
|
long countPay = paymentService.count(payLqw); |
||||
|
if(countPay>0){Assert.throwEx("发货单已存在,请勿重复提交");} |
||||
|
|
||||
|
LambdaQueryWrapper<TbsCostApply> lqw = new LambdaQueryWrapper<>(); |
||||
|
lqw.eq(TbsCostApply::getDisCode, disNumber); |
||||
|
long countPay2 = costApplyService.count(lqw); |
||||
|
if(countPay2>0){Assert.throwEx("发货单已存在,请勿重复提交");} |
||||
|
|
||||
|
}else { |
||||
|
Assert.throwEx("发票号或发货单号不能为空"); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
@NotNull |
||||
|
private Map<String, TbsCenterDto> getTbsCenterDtoMap(List<ProcessCenterItem> centerList) { |
||||
|
Map<String, TbsCenterDto> centerDtoMap = new HashMap<>(); |
||||
|
for (ProcessCenterItem item : centerList) { |
||||
|
String centerCode = item.getCenterCode(); |
||||
|
String centerType = item.getCenterType(); |
||||
|
if (centerType.equals("center")){ |
||||
|
BmsCostCenter costCenter = costCenterService.getByCode(centerCode); |
||||
|
if(costCenter==null){Assert.throwEx("自定义成本中心不存在,请重新编辑:"+centerCode);} |
||||
|
TbsCenterDto centerDto = new TbsCenterDto(costCenter); |
||||
|
centerDto.setCenterRate(item.getCenterRate()); |
||||
|
centerDtoMap.put(centerType+"_"+centerCode,centerDto); |
||||
|
}else if (centerType.equals("saleRegion")){ |
||||
|
BmsRegion region = saleRegionService.getByCode(centerCode); |
||||
|
if(region==null){Assert.throwEx("销售区域不存在,请重新编辑:"+centerCode);} |
||||
|
TbsCenterDto centerDto = new TbsCenterDto(region); |
||||
|
centerDto.setCenterRate(item.getCenterRate()); |
||||
|
centerDtoMap.put(centerType+"_"+centerCode,centerDto); |
||||
|
}else if (centerType.equals("bizRegion")){ |
||||
|
BmsRegion2 region = bizRegionService.getByCode(centerCode); |
||||
|
if(region==null){Assert.throwEx("行政区域不存在,请重新编辑:"+centerCode);} |
||||
|
TbsCenterDto centerDto = new TbsCenterDto(region); |
||||
|
centerDto.setCenterRate(item.getCenterRate()); |
||||
|
centerDtoMap.put(centerType+"_"+centerCode,centerDto); |
||||
|
}else if (centerType.equals("supplier")){ |
||||
|
BmsSupplier supplierCenter = supplierService.getByCode(centerCode,null); |
||||
|
if(supplierCenter==null){Assert.throwEx("供应商不存在,请重新编辑:"+centerCode);} |
||||
|
TbsCenterDto centerDto = new TbsCenterDto(supplierCenter); |
||||
|
centerDto.setCenterRate(item.getCenterRate()); |
||||
|
centerDtoMap.put(centerType+"_"+centerCode,centerDto); |
||||
|
}else { |
||||
|
Assert.throwEx("成本中心类型不存在,请重新编辑:"+centerType); |
||||
|
} |
||||
|
} |
||||
|
return centerDtoMap; |
||||
|
} |
||||
|
|
||||
|
private void payToErpAPI(BmsSupplier supplier, BmsSubject subject, BigDecimal totalAmount, TbsCostApply costApply, |
||||
|
TbsActivity activity, TbsActivitySubject activitySubject, TbsActivityCenter activityCenter, |
||||
|
List<TbsActivityGoods> activityGoodsList, List<TbsActivityCenterGoods> activityCenterGoodsList, |
||||
|
List<TbsBudgetLog> budgetLogList, VtbVerification verification, |
||||
|
VtbVerificationSubject verificationSubject) { |
||||
|
//发货单的
|
||||
|
String json = ThirtyVerificationUtil.buildJson(supplier, subject, totalAmount, activity, verification); |
||||
|
String COST_TO_PAY_API = projectApisProperties.getCostToPay(); |
||||
|
log.info("COST_TO_PAY_API 支付单信息:{} 数据:{}", verification.getVerificationCode(), json); |
||||
|
String rs = HttpUtil.doPost(COST_TO_PAY_API, json, null); |
||||
|
|
||||
|
SysSyncLog syncLog = new SysSyncLog(); |
||||
|
syncLog.setFromPlat("to支付请求"); |
||||
|
syncLog.setUrl(COST_TO_PAY_API); |
||||
|
syncLog.setRequestJson(json); |
||||
|
if(rs==null||!rs.contains("200")){ |
||||
|
log.error("COST_TO_PAY_API \n 请求参数:{},\n 支付单信息:{},\n 结果:{}", json, verification.getVerificationCode(),rs); |
||||
|
syncLog.setEntityClass("ThirtyVerification"); |
||||
|
syncLog.setFailReason(rs); |
||||
|
syncLog.setRemark("支付失败:["+ verification.getVerificationCode()+"]"); |
||||
|
}else { |
||||
|
syncLog.setSuccessStatus(1); |
||||
|
syncLog.setRemark("支付完成:["+ verification.getVerificationCode()+"]"); |
||||
|
} |
||||
|
sysSyncLogService.save(syncLog); |
||||
|
|
||||
|
if (rs == null || !rs.contains("200")) { |
||||
|
log.error("COST_TO_PAY_API \n 请求参数:{},\n 支付单信息:{},\n 结果:{}", json, verification.getVerificationCode(), rs); |
||||
|
//核销调度接口事务补偿
|
||||
|
costApplyService.removeById(costApply.getId()); |
||||
|
activityService.removeById(activity.getId()); |
||||
|
activitySubjectService.removeById(activitySubject.getId()); |
||||
|
activityCenterService.removeById(activityCenter.getId()); |
||||
|
List<Long> goodIds = activityGoodsList.stream().map(TbsActivityGoods::getId).collect(Collectors.toList()); |
||||
|
if (goodIds.size() > 0) { |
||||
|
activityGoodsService.removeBatchByIds(goodIds); |
||||
|
} |
||||
|
List<Long> good2Ids = activityCenterGoodsList.stream().map(TbsActivityCenterGoods::getId).collect(Collectors.toList()); |
||||
|
if (good2Ids.size() > 0) { |
||||
|
activityCenterGoodsService.removeBatchByIds(good2Ids); |
||||
|
} |
||||
|
List<Long> logIds = budgetLogList.stream().map(TbsBudgetLog::getId).collect(Collectors.toList()); |
||||
|
if (logIds.size() > 0) { |
||||
|
budgetLogService.removeBatchByIds(logIds); |
||||
|
} |
||||
|
verificationService.removeById(verification.getId()); |
||||
|
verificationSubjectService.removeById(verificationSubject.getId()); |
||||
|
Assert.throwEx("请求支付失败"); |
||||
|
} |
||||
|
log.info("COST_TO_PAY_API 支付单信息:{},结果:{}", verification.getVerificationCode(), rs); |
||||
|
} |
||||
|
|
||||
|
@NotNull |
||||
|
private List<GoodsSku> filterRepSku(List<String> invCodeList, List<GoodsSku> skuList) { |
||||
|
if (skuList.size() > invCodeList.size()){ |
||||
|
List<GoodsSku> skuList1 = new ArrayList<>(); |
||||
|
Set<String> codes = new HashSet<>(); |
||||
|
for (String invCode : invCodeList) { |
||||
|
for (GoodsSku goodsSku : skuList) { |
||||
|
if(goodsSku.getSkuCode().equals(invCode)){ |
||||
|
if(codes.contains(invCode)){ |
||||
|
continue; |
||||
|
} |
||||
|
codes.add(invCode); |
||||
|
skuList1.add(goodsSku); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
skuList = skuList1; |
||||
|
} |
||||
|
if(skuList.size() < invCodeList.size()){ |
||||
|
Set<String> missCodes = new HashSet<>(); |
||||
|
for (String code : invCodeList) { |
||||
|
boolean anyMatch = skuList.stream().anyMatch(a->a.getSkuCode().equals(code)); |
||||
|
if(!anyMatch){ |
||||
|
missCodes.add(code); |
||||
|
} |
||||
|
} |
||||
|
Assert.throwEx("品类缺失("+ skuList.size()+"-"+ invCodeList.size()+"-"+missCodes.size()+"):"+missCodes.stream().collect(Collectors.joining(","))); |
||||
|
} |
||||
|
if(skuList.size()<1){ |
||||
|
Assert.throwEx("请选择品类再提交"); |
||||
|
} |
||||
|
return skuList; |
||||
|
} |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* 创建流程中,初始化SKU列表 |
||||
|
* @param invCodes |
||||
|
* @param filterEnable YX06赔款单,不需要过滤商品是否下架 |
||||
|
* @return |
||||
|
*/ |
||||
|
private List<GoodsSku> initSkuListOfProcess(List<String> invCodes,boolean filterEnable) { |
||||
|
List<GoodsSku> goodsSkus = null; |
||||
|
if(CollectionUtil.isNotEmpty(invCodes)){ |
||||
|
LambdaQueryWrapper<GoodsSku> skuLqw = new LambdaQueryWrapper<>(); |
||||
|
skuLqw.in(GoodsSku::getSkuCode,invCodes); |
||||
|
skuLqw.eq(filterEnable,GoodsSku::getEnable,1); |
||||
|
goodsSkus = goodsSkuService.list(skuLqw); |
||||
|
if(invCodes.size()!=goodsSkus.size()){ |
||||
|
List<String> skuCodeNotExistList = new ArrayList<>(); |
||||
|
for (String invCode : invCodes) { |
||||
|
boolean notExist = true; |
||||
|
for (GoodsSku sku : goodsSkus) { |
||||
|
if(sku.getSkuCode().equals(invCode)){ |
||||
|
notExist = false; |
||||
|
break; |
||||
|
} |
||||
|
} |
||||
|
if(notExist){ |
||||
|
skuCodeNotExistList.add(invCode); |
||||
|
} |
||||
|
} |
||||
|
if(skuCodeNotExistList.size()>0){ |
||||
|
String invCodesString = skuCodeNotExistList.stream().collect(Collectors.joining(",")); |
||||
|
Assert.throwEx("存货编码["+invCodesString+"]不存在,请重新编辑"); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
if(goodsSkus==null){ |
||||
|
Assert.throwEx("存货编码未设置,请重新编辑"); |
||||
|
} |
||||
|
return goodsSkus; |
||||
|
} |
||||
|
|
||||
|
|
||||
|
} |
Loading…
Reference in new issue