md
This commit is contained in:
parent
ca626b151e
commit
877a754f48
@ -644,20 +644,44 @@ public class EmisCommonController extends EmisBaseController
|
||||
* 自动出账触发
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("/autoDoProfitTrigger")
|
||||
public AjaxResult autoDoProfitTrigger(EmisWaybill emisWaybill){
|
||||
String lockKey="autoDoProfitTrigger";
|
||||
log.info("autoDoProfitTrigger start");
|
||||
@GetMapping("/autoDoBillProfitTrigger")
|
||||
public AjaxResult autoDoBillProfitTrigger(EmisWaybill emisWaybill){
|
||||
String lockKey="autoDoBillProfitTrigger";
|
||||
log.info("autoDoBillProfitTrigger start");
|
||||
|
||||
// 加锁查询
|
||||
redissonService.lock(lockKey,300);
|
||||
try{
|
||||
emisCommissionProfitService.autoDoProfit(emisWaybill);
|
||||
emisCommissionProfitService.autoDoBillProfit(emisWaybill);
|
||||
}catch(Exception ex){
|
||||
ex.printStackTrace();
|
||||
log.error("autoDoProfitTrigger exception:"+ex.getMessage());
|
||||
log.error("autoDoBillProfitTrigger exception:"+ex.getMessage());
|
||||
}
|
||||
log.info("autoDoProfitTrigger end");
|
||||
log.info("autoDoBillProfitTrigger end");
|
||||
|
||||
redissonService.unlock(lockKey);
|
||||
return AjaxResult.success("发送成功");
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 自动出账触发
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("/autoDoBatchProfitTrigger")
|
||||
public AjaxResult autoDoBatchProfitTrigger(EmisTmsSiteBatch emisTmsSiteBatch){
|
||||
String lockKey="autoDoBatchProfitTrigger";
|
||||
log.info("autoDoBatchProfitTrigger start");
|
||||
|
||||
// 加锁查询
|
||||
redissonService.lock(lockKey,300);
|
||||
try{
|
||||
emisCommissionProfitService.autoDoBatchProfit(emisTmsSiteBatch);
|
||||
}catch(Exception ex){
|
||||
ex.printStackTrace();
|
||||
log.error("autoDoBatchProfitTrigger exception:"+ex.getMessage());
|
||||
}
|
||||
log.info("autoDoBatchProfitTrigger end");
|
||||
|
||||
redissonService.unlock(lockKey);
|
||||
return AjaxResult.success("发送成功");
|
||||
|
||||
@ -41,6 +41,13 @@ public interface EmisTmsSiteBatchMapper extends BaseMapper<EmisTmsSiteBatch>
|
||||
*/
|
||||
public List<EmisTmsSiteBatch> selectEmisTmsSiteBatchList(EmisTmsSiteBatch emisTmsSiteBatch);
|
||||
|
||||
/**
|
||||
* 获取待处理提成批次列表
|
||||
* @param emisTmsSiteBatch
|
||||
* @return
|
||||
*/
|
||||
public List<EmisTmsSiteBatch> selectWaitDoProfitList(EmisTmsSiteBatch emisTmsSiteBatch);
|
||||
|
||||
/**
|
||||
* 新增
|
||||
*
|
||||
|
||||
@ -11,6 +11,7 @@ package com.xdadan.erp.emis.service;
|
||||
|
||||
import java.util.List;
|
||||
import com.xdadan.erp.emis.domain.EmisCommissionProfit;
|
||||
import com.xdadan.erp.emis.domain.EmisTmsSiteBatch;
|
||||
import com.xdadan.erp.emis.domain.EmisWaybill;
|
||||
|
||||
/**
|
||||
@ -30,9 +31,15 @@ public interface IEmisCommissionProfitService
|
||||
|
||||
|
||||
/**
|
||||
* 自动计算提成
|
||||
* 自动计算运单提成
|
||||
*/
|
||||
public void autoDoProfit(EmisWaybill emisWaybill);
|
||||
public void autoDoBillProfit(EmisWaybill emisWaybill);
|
||||
|
||||
/**
|
||||
* 自动计算批次提成
|
||||
* @param tmsSiteBatch
|
||||
*/
|
||||
public void autoDoBatchProfit(EmisTmsSiteBatch tmsSiteBatch);
|
||||
|
||||
|
||||
/**
|
||||
|
||||
@ -75,16 +75,13 @@ public class EmisCommissionProfitServiceImpl extends EmisBaseService implements
|
||||
*/
|
||||
@Async
|
||||
@Override
|
||||
public void autoDoProfit(EmisWaybill emisWaybill) {
|
||||
public void autoDoBillProfit(EmisWaybill emisWaybill) {
|
||||
|
||||
Map<String,Map<String,String> > profitMap = new HashMap<>();
|
||||
// 获取需要出账的运单列表
|
||||
List<EmisWaybill> list = emisWaybillMapper.selectWaitDoProfitList(emisWaybill);
|
||||
|
||||
// 多线程并发处理
|
||||
if(!CollectionUtil.isEmpty(list)){
|
||||
|
||||
|
||||
List<List<EmisWaybill> > mutiOrderList = ListUtils.partition(list, 100);
|
||||
int realGroupSize=mutiOrderList.size();
|
||||
|
||||
@ -94,11 +91,11 @@ public class EmisCommissionProfitServiceImpl extends EmisBaseService implements
|
||||
long startTime=System.currentTimeMillis();
|
||||
|
||||
for(int i=0; i<realGroupSize;i++){
|
||||
Runnable doRunnable=new EmisCommissionProfitServiceImpl.MultiDoThread(
|
||||
Runnable doRunnable=new EmisCommissionProfitServiceImpl.MultiDoBillThread(
|
||||
mutiOrderList.get(i),
|
||||
latch,
|
||||
"MultiDoThread==>"+i);
|
||||
Thread doThread = new Thread(doRunnable, " Profit MultiDoThread-"+i);
|
||||
"MultiDoBillThread==>"+i);
|
||||
Thread doThread = new Thread(doRunnable, " Profit MultiDoBillThread-"+i);
|
||||
doThread.start();
|
||||
}
|
||||
|
||||
@ -113,17 +110,63 @@ public class EmisCommissionProfitServiceImpl extends EmisBaseService implements
|
||||
}finally {
|
||||
}
|
||||
long endTime=System.currentTimeMillis(); //获取结束时间
|
||||
log.info("Profit MultiDoThread End escape time: "+(endTime-startTime)+"ms");
|
||||
log.info("Profit MultiDoBillThread End escape time: "+(endTime-startTime)+"ms");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 自动计算批次提成
|
||||
*/
|
||||
@Async
|
||||
@Override
|
||||
public void autoDoBatchProfit(EmisTmsSiteBatch tmsSiteBatch) {
|
||||
|
||||
Map<String,Map<String,String> > profitMap = new HashMap<>();
|
||||
// 获取需要出账的运单列表
|
||||
List<EmisTmsSiteBatch> list = emisTmsSiteBatchMapper.selectWaitDoProfitList(tmsSiteBatch);
|
||||
// 多线程并发处理
|
||||
if(!CollectionUtil.isEmpty(list)){
|
||||
List<List<EmisTmsSiteBatch> > mutiBatchList = ListUtils.partition(list, 100);
|
||||
int realGroupSize=mutiBatchList.size();
|
||||
|
||||
// 计数处理
|
||||
CountDownLatch latch = new CountDownLatch(realGroupSize);
|
||||
//多线程运行
|
||||
long startTime=System.currentTimeMillis();
|
||||
|
||||
for(int i=0; i<realGroupSize;i++){
|
||||
Runnable doRunnable=new EmisCommissionProfitServiceImpl.MultiDoBatchThread(
|
||||
mutiBatchList.get(i),
|
||||
latch,
|
||||
"MultiDoBatchThread==>"+i);
|
||||
Thread doThread = new Thread(doRunnable, " Profit MultiDoBatchThread-"+i);
|
||||
doThread.start();
|
||||
}
|
||||
|
||||
try {
|
||||
latch.await(300, TimeUnit.SECONDS);
|
||||
|
||||
// 线程结束后计算所有员工提成
|
||||
reCalcEmpProfitSumMoney(null,null);
|
||||
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}finally {
|
||||
}
|
||||
long endTime=System.currentTimeMillis(); //获取结束时间
|
||||
log.info("Profit MultiDoBatchThread End escape time: "+(endTime-startTime)+"ms");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// 多线程处理
|
||||
class MultiDoThread implements Runnable {
|
||||
class MultiDoBillThread implements Runnable {
|
||||
private List<EmisWaybill> dataList = null;
|
||||
private CountDownLatch latch = null;
|
||||
private String name;
|
||||
|
||||
public MultiDoThread(
|
||||
public MultiDoBillThread(
|
||||
List<EmisWaybill> dataList,
|
||||
CountDownLatch latch ,
|
||||
String name
|
||||
@ -136,6 +179,7 @@ public class EmisCommissionProfitServiceImpl extends EmisBaseService implements
|
||||
private void doData(){
|
||||
|
||||
long start = System.currentTimeMillis();
|
||||
// 计算运单提成
|
||||
for (EmisWaybill waybill : dataList) {
|
||||
try {
|
||||
reCalcProfitByBillCode(waybill.getBillCode());
|
||||
@ -145,12 +189,13 @@ public class EmisCommissionProfitServiceImpl extends EmisBaseService implements
|
||||
}
|
||||
|
||||
long end4 = System.currentTimeMillis();
|
||||
|
||||
log.info(this.name+" escape time xxxx666:" + (end4 - start) + "ms");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
log.debug(this.name+":Do profit thread start!");
|
||||
log.debug(this.name+":Do profit by bill thread start!");
|
||||
try {
|
||||
doData();
|
||||
}catch(Exception ex){
|
||||
@ -158,10 +203,57 @@ public class EmisCommissionProfitServiceImpl extends EmisBaseService implements
|
||||
}
|
||||
|
||||
latch.countDown();
|
||||
log.debug(this.name+":Do profit thread thread end!");
|
||||
log.debug(this.name+":Do profit by bill thread thread end!");
|
||||
}
|
||||
}
|
||||
|
||||
// 多线程处理
|
||||
class MultiDoBatchThread implements Runnable {
|
||||
private List<EmisTmsSiteBatch> batchList = null;
|
||||
private CountDownLatch latch = null;
|
||||
private String name;
|
||||
|
||||
public MultiDoBatchThread(
|
||||
List<EmisTmsSiteBatch> batchList,
|
||||
CountDownLatch latch ,
|
||||
String name
|
||||
){
|
||||
this.batchList = batchList;
|
||||
this.latch = latch;
|
||||
this.name=name;
|
||||
}
|
||||
|
||||
private void doData(){
|
||||
|
||||
long start = System.currentTimeMillis();
|
||||
// 计算批次提成
|
||||
for (EmisTmsSiteBatch batchItem : batchList) {
|
||||
try {
|
||||
reCalcProfitByBatchNo(batchItem.getBatchNo());
|
||||
}catch (Exception ex){
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
long end4 = System.currentTimeMillis();
|
||||
|
||||
log.info(this.name+" escape time xxxx666:" + (end4 - start) + "ms");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
log.debug(this.name+":Do profit by batch thread start!");
|
||||
try {
|
||||
doData();
|
||||
}catch(Exception ex){
|
||||
ex.printStackTrace();
|
||||
}
|
||||
|
||||
latch.countDown();
|
||||
log.debug(this.name+":Do profit by batch thread thread end!");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
@ -391,6 +483,8 @@ public class EmisCommissionProfitServiceImpl extends EmisBaseService implements
|
||||
emisCommissionDtl.setBillCode(waybill.getBillCode());
|
||||
emisCommissionDtl.setFeeType(quoteItem.getFeeType());
|
||||
|
||||
emisCommissionDtl.setBillType("1");
|
||||
|
||||
emisCommissionDtl.setBillMonth(billMonth);
|
||||
emisCommissionDtl.setMoney(BigDecimal.valueOf(profitMoney));
|
||||
|
||||
@ -511,6 +605,8 @@ public class EmisCommissionProfitServiceImpl extends EmisBaseService implements
|
||||
emisCommissionDtl.setBillCode(waybill.getBillCode());
|
||||
emisCommissionDtl.setFeeType(quoteItem.getFeeType());
|
||||
|
||||
emisCommissionDtl.setBillType("1");
|
||||
|
||||
emisCommissionDtl.setBillMonth(billMonth);
|
||||
emisCommissionDtl.setMoney(BigDecimal.valueOf(profitMoney));
|
||||
|
||||
@ -630,6 +726,8 @@ public class EmisCommissionProfitServiceImpl extends EmisBaseService implements
|
||||
emisCommissionDtl.setBillCode(waybill.getBillCode());
|
||||
emisCommissionDtl.setFeeType(quoteItem.getFeeType());
|
||||
|
||||
emisCommissionDtl.setBillType("1");
|
||||
|
||||
emisCommissionDtl.setBillMonth(billMonth);
|
||||
emisCommissionDtl.setMoney(BigDecimal.valueOf(profitMoney));
|
||||
|
||||
@ -755,6 +853,8 @@ public class EmisCommissionProfitServiceImpl extends EmisBaseService implements
|
||||
emisCommissionDtl.setBillCode(waybill.getBillCode());
|
||||
emisCommissionDtl.setFeeType(quoteItem.getFeeType());
|
||||
|
||||
emisCommissionDtl.setBillType("1");
|
||||
|
||||
emisCommissionDtl.setBillMonth(billMonth);
|
||||
emisCommissionDtl.setMoney(BigDecimal.valueOf(profitMoney));
|
||||
|
||||
@ -880,6 +980,8 @@ public class EmisCommissionProfitServiceImpl extends EmisBaseService implements
|
||||
emisCommissionDtl.setBillCode(waybill.getBillCode());
|
||||
emisCommissionDtl.setFeeType(quoteItem.getFeeType());
|
||||
|
||||
emisCommissionDtl.setBillType("1");
|
||||
|
||||
emisCommissionDtl.setBillMonth(billMonth);
|
||||
emisCommissionDtl.setMoney(BigDecimal.valueOf(profitMoney));
|
||||
|
||||
@ -1007,6 +1109,8 @@ public class EmisCommissionProfitServiceImpl extends EmisBaseService implements
|
||||
emisCommissionDtl.setBillCode(waybill.getBillCode());
|
||||
emisCommissionDtl.setFeeType(quoteItem.getFeeType());
|
||||
|
||||
emisCommissionDtl.setBillType("1");
|
||||
|
||||
emisCommissionDtl.setBillMonth(billMonth);
|
||||
emisCommissionDtl.setMoney(BigDecimal.valueOf(profitMoney));
|
||||
|
||||
@ -1138,6 +1242,7 @@ public class EmisCommissionProfitServiceImpl extends EmisBaseService implements
|
||||
EmisCommissionDtl emisCommissionDtl = new EmisCommissionDtl();
|
||||
emisCommissionDtl.setBillCode(waybill.getBillCode());
|
||||
emisCommissionDtl.setFeeType(quoteItem.getFeeType());
|
||||
emisCommissionDtl.setBillType("1");
|
||||
|
||||
emisCommissionDtl.setBillMonth(billMonth);
|
||||
emisCommissionDtl.setMoney(BigDecimal.valueOf(profitMoney));
|
||||
@ -1219,7 +1324,7 @@ public class EmisCommissionProfitServiceImpl extends EmisBaseService implements
|
||||
double profitMoney = 0.0D;
|
||||
// 按柜内票数
|
||||
if ("5".equals(quoteItem.getCalcType())) {
|
||||
calcExprStr = calcExp.replaceAll("w", siteBatch.getTotalWaybillQty())
|
||||
calcExprStr = calcExp.replaceAll("w", siteBatch.getTotalWaybillQty().toString())
|
||||
.replaceAll("s", exprItem.getInitialWeight().toString())
|
||||
.replaceAll("d", exprItem.getAdditionalWeight().toString());
|
||||
log.info("按柜内票数:计算公式:" + calcExprStr + ",按柜内票数:"+siteBatch.getTotalWaybillQty());
|
||||
@ -1231,21 +1336,18 @@ public class EmisCommissionProfitServiceImpl extends EmisBaseService implements
|
||||
|
||||
// 插入提成
|
||||
if(BigDecimal.valueOf(profitMoney).compareTo(BigDecimal.ZERO)>0) {
|
||||
String[] empCodeArr = empName.split(",");
|
||||
for(int i=0;i<empCodeArr.length;i++) {
|
||||
|
||||
SysUser empUser = getEmisStaffByCode(empCodeArr[i]);
|
||||
String[] empNameArr = empName.split(",");
|
||||
for(int i=0;i<empNameArr.length;i++) {
|
||||
|
||||
EmisCommissionDtl emisCommissionDtl = new EmisCommissionDtl();
|
||||
emisCommissionDtl.setBillCode(siteBatch.getBatchNo());
|
||||
emisCommissionDtl.setBillType
|
||||
emisCommissionDtl.setBillType("2");
|
||||
emisCommissionDtl.setFeeType(quoteItem.getFeeType());
|
||||
|
||||
emisCommissionDtl.setBillMonth(billMonth);
|
||||
emisCommissionDtl.setMoney(BigDecimal.valueOf(profitMoney));
|
||||
|
||||
emisCommissionDtl.setEmpCode(empUser.getEmpCode());
|
||||
emisCommissionDtl.setEmpName(empUser.getEmpName());
|
||||
emisCommissionDtl.setEmpName(empNameArr[i]);
|
||||
|
||||
emisCommissionDtl.setCalcExpr(calcExprStr);
|
||||
emisCommissionDtl.setQuoteId(exprItem.getQuoteId());
|
||||
|
||||
@ -141,6 +141,19 @@
|
||||
order by create_time desc
|
||||
</select>
|
||||
|
||||
<!-- 查询待提成运单 -->
|
||||
<select id="selectWaitDoProfitList" parameterType="EmisTmsSiteBatch" resultMap="EmisTmsSiteBatchResult">
|
||||
SELECT
|
||||
batch_no
|
||||
FROM
|
||||
emis_tms_site_batch a
|
||||
WHERE a.del_flag = '0' AND a.bl_profit = '0'
|
||||
<if test="params.billMonth != null and params.billMonth != ''">
|
||||
and DATE_FORMAT(a.etd,'%Y%m')= #{params.billMonth}
|
||||
</if>
|
||||
ORDER BY a.etd DESC
|
||||
</select>
|
||||
|
||||
<select id="checkUnique" parameterType="EmisTmsSiteBatch" resultType="int">
|
||||
select count(1) from emis_tms_site_batch
|
||||
where del_flag='0'
|
||||
|
||||
Loading…
Reference in New Issue
Block a user