This commit is contained in:
linfso 2024-11-21 19:40:19 +08:00
parent 5aef70e088
commit c7105c2229
2 changed files with 35 additions and 15 deletions

View File

@ -12,6 +12,7 @@ package com.xdadan.erp.emis.service.impl;
import java.math.BigDecimal;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.CountDownLatch;
@ -74,12 +75,16 @@ public class EmisCommissionProfitServiceImpl extends EmisBaseService implements
@Async
@Override
public void autoDoProfit() {
Map<String,Map<String,String> > profitMap = new HashMap<>();
// 获取需要出账的运单列表
EmisWaybill qEmisWaybill = new EmisWaybill();
List<EmisWaybill> list = emisWaybillMapper.selectWaitDoProfitList(qEmisWaybill);
// 多线程并发处理
if(!CollectionUtil.isEmpty(list)){
List<List<EmisWaybill> > mutiOrderList = ListUtils.partition(list, 100);
int realGroupSize=mutiOrderList.size();
@ -99,6 +104,10 @@ public class EmisCommissionProfitServiceImpl extends EmisBaseService implements
try {
latch.await(300, TimeUnit.SECONDS);
// 线程结束后计算所有员工提成
reCalcEmpProfitSumMoney(null,null);
} catch (InterruptedException e) {
e.printStackTrace();
}finally {
@ -163,7 +172,6 @@ public class EmisCommissionProfitServiceImpl extends EmisBaseService implements
@Transactional
public void reCalcProfitByBillCode(String billCode)
{
String lockKey="reCalcProfitByBillCode"+billCode;
// 加锁查询
log.error("reCalcProfitByBillCode start:"+billCode);
@ -221,7 +229,6 @@ public class EmisCommissionProfitServiceImpl extends EmisBaseService implements
else if (postTypeIndex == ProfitPostType.DZ_EMP.typeCode) {
calcDzProfit(waybill);
}
}
// 运单打上已计算提成标记
@ -236,19 +243,30 @@ public class EmisCommissionProfitServiceImpl extends EmisBaseService implements
}
private int reCalcEmpProfitSumMoney(String empName,String billMonth){
// 获取统计数据
List<EmisCommissionProfit> listProfit=emisCommissionProfitMapper.selectProfitStatList(empName,billMonth);
for (EmisCommissionProfit profitItem:listProfit) {
// 查询是否有数据,没有则插入
int isExists=emisCommissionProfitMapper.checkUnique(profitItem);
if(isExists==1){
emisCommissionProfitMapper.updateProfitMoney(profitItem);
}else{
String profitNo=WaybillHelper.genProfitNo();
profitItem.setProfitNo(profitNo);
emisCommissionProfitMapper.insertEmisCommissionProfit(profitItem);
String lockKey="reCalcEmpProfitSumMoney_"+empName+billMonth;
// 加锁查询
log.error("reCalcEmpProfitSumMoney start:"+empName+billMonth);
redissonService.lock(lockKey, 300);
try {
// 获取统计数据
List<EmisCommissionProfit> listProfit=emisCommissionProfitMapper.selectProfitStatList(empName,billMonth);
for (EmisCommissionProfit profitItem:listProfit) {
// 查询是否有数据,没有则插入
int isExists=emisCommissionProfitMapper.checkUnique(profitItem);
if(isExists==1){
emisCommissionProfitMapper.updateProfitMoney(profitItem);
}else{
String profitNo=WaybillHelper.genProfitNo();
profitItem.setProfitNo(profitNo);
emisCommissionProfitMapper.insertEmisCommissionProfit(profitItem);
}
}
}catch (Exception ex){
redissonService.unlock(lockKey);
ex.printStackTrace();
}
redissonService.unlock(lockKey);
log.error("reCalcProfitByBillCode end:"+empName+billMonth);
return 1;
}

View File

@ -32,11 +32,13 @@
<select id="selectProfitStatList" parameterType="String" resultMap="EmisCommissionProfitResult">
select emp_name ,bill_month, sum(money) as money
from emis_commission_dtl a
where a.emp_name = #{empName}
where del_flag='0'
<if test="empName != null and empName != ''">
a.emp_name = #{empName}
</if>
<if test="billMonth != null and billMonth != ''">
and bill_month=#{billMonth}
</if>
group by emp_name,bill_month
</select>