Commit 1676528f authored by fangxinjiang's avatar fangxinjiang

薪资审核异步推送EKP

parent 8b928c13
package com.yifu.cloud.plus.v1.yifu.common.core.config;
import ch.qos.logback.core.util.ExecutorServiceUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.aop.interceptor.AsyncUncaughtExceptionHandler;
import org.springframework.context.annotation.Configuration;
......@@ -35,7 +36,7 @@ public class AsyncConfig implements AsyncConfigurer {
* 1)<!-- 线程池维护线程的最少数量,即使没有任务需要执行,也会一直存活 -->
* 2)<!-- 设置allowCoreThreadTimeout=true(默认false)时,核心线程会超时关闭 -->
*/
taskExecutor.setCorePoolSize(2);
taskExecutor.setCorePoolSize(10);
/**
* <!-- 允许的空闲时间,当线程空闲时间达到keepAliveTime时,线程会退出,直到线程数量=corePoolSize -->
* <!-- 如果allowCoreThreadTimeout=true,则会直到线程数量=0 -->
......@@ -46,7 +47,7 @@ public class AsyncConfig implements AsyncConfigurer {
* <!-- 当线程数>=corePoolSize,且任务队列已满时。线程池会创建新线程来处理任务 -->
* <!-- 当线程数=maxPoolSize,且任务队列已满时,线程池会拒绝处理任务而抛出异常,异常见下
*/
taskExecutor.setMaxPoolSize(8);
taskExecutor.setMaxPoolSize(50);
/**
* <!-- 缓存队列(阻塞队列)当核心线程数达到最大时,新任务会放在队列中排队等待执行 -->
*/
......@@ -54,11 +55,13 @@ public class AsyncConfig implements AsyncConfigurer {
/**
* 建议配置threadNamePrefix属性,出问题时可以更方便的进行排查。
**/
taskExecutor.setThreadNamePrefix("CRM_TO_HRO_EXECUTOR");
taskExecutor.setThreadNamePrefix("HRO_TO_EKP_EXECUTOR");
// 捕捉线程队列满的 拒绝处理
taskExecutor.setRejectedExecutionHandler((Runnable r, ThreadPoolExecutor exe) -> {
log.info("当前任务线程池队列已满.");
});
taskExecutor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy());
/* taskExecutor.setRejectedExecutionHandler((Runnable r, ThreadPoolExecutor exe) -> {
log.error("当前任务线程池队列已满.");
});*/
//初始化
taskExecutor.initialize();
return taskExecutor;
......
......@@ -62,6 +62,10 @@ public class Common {
return null == obj || "".equals(obj) || "null".equals(obj);
}
public static boolean isEmpty(List obj) {
return (null == obj || obj.size() == 0);
}
public static boolean isNotNull(Object obj) {
return null != obj && !"".equals(obj) && !"null".equals(obj);
}
......
......@@ -42,6 +42,7 @@ import com.yifu.cloud.plus.v1.yifu.social.mapper.TPaymentInfoMapper;
import com.yifu.cloud.plus.v1.yifu.social.service.TIncomeDetailService;
import com.yifu.cloud.plus.v1.yifu.social.service.TIncomeService;
import com.yifu.cloud.plus.v1.yifu.social.service.TSendEkpErrorService;
import com.yifu.cloud.plus.v1.yifu.social.util.DoJointSocialTask;
import com.yifu.cloud.plus.v1.yifu.social.vo.IncomeExportVo;
import com.yifu.cloud.plus.v1.yifu.social.vo.TIncomeSearchVo;
import com.yifu.cloud.plus.v1.yifu.social.vo.TIncomeVo;
......@@ -78,6 +79,9 @@ public class TIncomeServiceImpl extends ServiceImpl<TIncomeMapper, TIncome> impl
@Autowired
private TPaymentInfoMapper tPaymentInfoMapper;
@Autowired
private DoJointSocialTask doJointSocialTask;
/**
* 收入明细表简单分页查询
*
......@@ -728,29 +732,12 @@ public class TIncomeServiceImpl extends ServiceImpl<TIncomeMapper, TIncome> impl
TIncome income = new TIncome();
BeanUtil.copyProperties(tIncomeDetail, income);
income.setSendStatus(CommonConstants.ZERO_STRING);
this.save(income);
String sendBack = this.getSendBack(income);
if (Common.isEmpty(sendBack) || sendBack.length() != 32) {
sendBack = this.getSendBack(income);
}
income.setSendTime(new Date());
if (Common.isNotNull(sendBack) && sendBack.length() == 32) {
income.setSendStatus(CommonConstants.ONE_STRING);
income.setSendMonth(DateUtil.addMonth(0));
income.setEkpId(sendBack);
} else {
TSendEkpError error = new TSendEkpError();
error.setCreateTime(new Date());
error.setCreateDay(DateUtil.getThisDay());
error.setType(CommonConstants.FOUR_STRING);
error.setCreateUserName("收入表推送");
error.setLinkId(income.getId());
error.setTitle(sendBack);
error.setNums(CommonConstants.ONE_INT);
tSendEkpErrorService.saveError(error);
}
income.setApplyNo(tIncomeDetail.getApplyNo());
return this.updateById(income);
this.save(income);
long start = System.currentTimeMillis();
doJointSocialTask.asynchronousEkpIncome(income);
log.error("线程执行耗时:"+ (System.currentTimeMillis()-start));
return true;
}
/**
......
package com.yifu.cloud.plus.v1.yifu.social.util;
import com.yifu.cloud.plus.v1.yifu.common.core.constant.CommonConstants;
import com.yifu.cloud.plus.v1.yifu.common.core.util.Common;
import com.yifu.cloud.plus.v1.yifu.common.core.util.DateUtil;
import com.yifu.cloud.plus.v1.yifu.ekp.util.EkpIncomeUtil;
import com.yifu.cloud.plus.v1.yifu.ekp.vo.EkpIncomeParamManage;
import com.yifu.cloud.plus.v1.yifu.ekp.vo.EkpIncomeParamRisk;
import com.yifu.cloud.plus.v1.yifu.social.constants.SocialConstants;
import com.yifu.cloud.plus.v1.yifu.social.entity.TIncome;
import com.yifu.cloud.plus.v1.yifu.social.entity.TSendEkpError;
import com.yifu.cloud.plus.v1.yifu.social.mapper.TIncomeMapper;
import com.yifu.cloud.plus.v1.yifu.social.service.TSendEkpErrorService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;
import java.util.Date;
/**
* 主要执行人员档案的员工类型同步更新
* @author huyc
* @Date 2022-07-08
* @Description 多线程的执行demo
*/
@Slf4j
@Component
public class DoJointSocialTask {
@Autowired
private EkpIncomeUtil ekpIncomeUtil;
@Autowired
private TSendEkpErrorService tSendEkpErrorService;
@Autowired
private TIncomeMapper incomeMapper;
/**
* @Description: 合同-批量更换负责人
* @Author: huyc
* @Date: 2022-7-8
* @return: void
**/
@Async
public void asynchronousEkpIncome(TIncome income) {
log.info("推送收入到EKP-线程开始");
try {
String sendBack = this.getSendBack(income);
if (Common.isEmpty(sendBack) || sendBack.length() != 32) {
sendBack = this.getSendBack(income);
}
income.setSendTime(new Date());
if (Common.isNotNull(sendBack) && sendBack.length() == 32) {
income.setSendStatus(CommonConstants.ONE_STRING);
income.setSendMonth(DateUtil.addMonth(0));
income.setEkpId(sendBack);
incomeMapper.updateById(income);
} else {
TSendEkpError error = new TSendEkpError();
error.setCreateTime(new Date());
error.setCreateDay(DateUtil.getThisDay());
error.setType(CommonConstants.FOUR_STRING);
error.setCreateUserName("收入表推送");
error.setLinkId(income.getId());
error.setTitle(sendBack);
error.setNums(CommonConstants.ONE_INT);
tSendEkpErrorService.saveError(error);
}
} catch (Exception e) {
TSendEkpError error = new TSendEkpError();
error.setCreateTime(new Date());
error.setCreateDay(DateUtil.getThisDay());
error.setType(CommonConstants.FOUR_STRING);
error.setCreateUserName("收入表推送");
error.setLinkId(income.getId());
error.setTitle(e.getMessage());
error.setNums(CommonConstants.ONE_INT);
tSendEkpErrorService.saveError(error);
log.error("推送收入到EKP错误", e);
}
log.info("推送收入到EKP结束");
}
/**
* @param income
* @Description: 判断类型发送
* @Author: hgw
* @Date: 2022/9/6 15:15
* @return: java.lang.String
**/
private String getSendBack(TIncome income) {
String sendBack;
if (CommonConstants.ONE_STRING.equals(income.getFeeType())) {
EkpIncomeParamManage sendParam = new EkpIncomeParamManage();
this.copyToEkpManage(income, sendParam);
sendBack = ekpIncomeUtil.sendToEkpManage(sendParam);
} else {
EkpIncomeParamRisk sendParam = new EkpIncomeParamRisk();
this.copyToEkpRisk(income, sendParam);
sendBack = ekpIncomeUtil.sendToEkpRisk(sendParam);
}
return sendBack;
}
/**
* @param income 收入
* @param sendParam 目标格式
* @Description: 转化格式,传到EKP
* @Author: hgw
* @Date: 2022/9/5 16:57
* @return: void
**/
private void copyToEkpManage(TIncome income, EkpIncomeParamManage sendParam) {
// 项目编码
sendParam.setFd_3adfef5e5b9d34(income.getDeptNo());
// 项目名称
sendParam.setFd_3adfef5eb6691c(income.getDeptName());
// 单号
sendParam.setFd_3adfef7f5d2b52("");
// 客户编码
sendParam.setFd_3adfef80202ab2(income.getUnitNo());
// 客户名称
sendParam.setFd_3adfef7fc1c886(income.getUnitName());
// 类型:单选(人,人次,比例,固定值,总额)
// feeMode收费方式:1按比例2金额-人数3金额-人次
if (CommonConstants.ONE_STRING.equals(income.getFeeMode())) {
sendParam.setFd_3adda3037e3bda("比例");
} else if (CommonConstants.TWO_STRING.equals(income.getFeeMode())) {
sendParam.setFd_3adda3037e3bda("人数");
} else {
sendParam.setFd_3adda3037e3bda("人次");
}
// 产生来源:单选(社保,工资,商险)
// sourceType1社保2公积金3商险4薪资
if (CommonConstants.THREE_STRING.equals(income.getSourceType())) {
sendParam.setFd_3adda320daef5a("商险");
} else if (CommonConstants.FOUR_STRING.equals(income.getSourceType())) {
sendParam.setFd_3adda320daef5a("工资");
} else {
sendParam.setFd_3adda320daef5a("社保");
}
// 姓名
sendParam.setFd_3adfef948da848(income.getEmpName());
// 身份证号
sendParam.setFd_3adfef94dcdbb4(income.getEmpIdcard());
// 生成月份
if (Common.isEmpty(income.getCreateMonth()) || income.getCreateMonth().length() != 6) {
sendParam.setFd_3ae0c23b2e9a92(SocialConstants.YEAR_1970);
} else {
sendParam.setFd_3ae0c23b2e9a92(income.getCreateMonth().substring(0, 4)
+ CommonConstants.CENTER_SPLIT_LINE_STRING + income.getCreateMonth().substring(4, 6));
}
// 结算月份
if (Common.isEmpty(income.getPayMonth()) || income.getPayMonth().length() != 6) {
sendParam.setFd_3ae0c23cb3fccc(SocialConstants.YEAR_1970);
} else {
sendParam.setFd_3ae0c23cb3fccc(income.getPayMonth().substring(0, 4)
+ CommonConstants.CENTER_SPLIT_LINE_STRING + income.getPayMonth().substring(4, 6));
}
// 管理费、风险金金额
sendParam.setFd_3adfef963bae28(String.valueOf(income.getMoney()));
// 应收
sendParam.setFd_3adfefa3daae72(String.valueOf(income.getMoney()));
// 结算状态
sendParam.setFd_3adfefaaa3bbd0("未结算");
// 收款状态
sendParam.setFd_3adfefaaef583e("未收");
// 结算单号
sendParam.setFd_3aead3c68b1078("");
// 收款单号
sendParam.setFd_3aeae58b14691c("");
// 管理费id
sendParam.setFd_3b13dae9bd70f8(income.getId());
// 薪酬申请编号
sendParam.setFd_3b3bf13759b850(income.getApplyNo()==null?"":income.getApplyNo());
}
private void copyToEkpRisk(TIncome income, EkpIncomeParamRisk sendParam) {
// 项目编码
sendParam.setFd_3adfef5e5b9d34(income.getDeptNo());
// 项目名称
sendParam.setFd_3adfef5eb6691c(income.getDeptName());
// 单号
sendParam.setFd_3adfef7f5d2b52("");
// 客户编码
sendParam.setFd_3adfef80202ab2(income.getUnitNo());
// 客户名称
sendParam.setFd_3adfef7fc1c886(income.getUnitName());
// 类型:单选(人,人次,比例,固定值,总额)
// feeMode收费方式:1按比例2金额-人数3金额-人次
if (CommonConstants.ONE_STRING.equals(income.getFeeMode())) {
sendParam.setFd_3adda3037e3bda("比例");
} else if (CommonConstants.TWO_STRING.equals(income.getFeeMode())) {
sendParam.setFd_3adda3037e3bda("人数");
} else {
sendParam.setFd_3adda3037e3bda("人次");
}
// 产生来源:单选(社保,工资,商险)
// sourceType1社保2公积金3商险4薪资
if (CommonConstants.THREE_STRING.equals(income.getSourceType())) {
sendParam.setFd_3adda320daef5a("商险");
} else if (CommonConstants.FOUR_STRING.equals(income.getSourceType())) {
sendParam.setFd_3adda320daef5a("工资");
} else {
sendParam.setFd_3adda320daef5a("社保");
}
// 姓名
sendParam.setFd_3adfef948da848(income.getEmpName());
// 身份证号
sendParam.setFd_3adfef94dcdbb4(income.getEmpIdcard());
// 生成月份
if (Common.isEmpty(income.getCreateMonth()) || income.getCreateMonth().length() != 6) {
sendParam.setFd_3ae0c3032cffc8(SocialConstants.YEAR_1970);
} else {
sendParam.setFd_3ae0c3032cffc8(income.getCreateMonth().substring(0, 4)
+ CommonConstants.CENTER_SPLIT_LINE_STRING + income.getCreateMonth().substring(4, 6));
}
// 结算月份
if (Common.isEmpty(income.getPayMonth()) || income.getPayMonth().length() != 6) {
sendParam.setFd_3ae0c3044e5958(SocialConstants.YEAR_1970);
} else {
sendParam.setFd_3ae0c3044e5958(income.getPayMonth().substring(0, 4)
+ CommonConstants.CENTER_SPLIT_LINE_STRING + income.getPayMonth().substring(4, 6));
}
// 管理费、风险金金额
sendParam.setFd_3adfef963bae28(String.valueOf(income.getMoney()));
// 应收
sendParam.setFd_3adfefa3daae72(String.valueOf(income.getMoney()));
// 结算状态
sendParam.setFd_3adfefaaa3bbd0("未结算");
// 收款状态
sendParam.setFd_3adfefaaef583e("未收");
// 结算单号
sendParam.setFd_3aead7204bb594("");
// 收款单号
sendParam.setFd_3aeae59b70fe5a("");
// 风险金id
sendParam.setFd_3b13dac4c03022(income.getId());
// 薪酬申请编号
sendParam.setFd_3b3bf0e75ef6c4(income.getApplyNo()==null?"":income.getApplyNo());
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment