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

View File

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