Commit 57b0a72f authored by huyuchen's avatar huyuchen

优化修改

parent e6421469
......@@ -72,6 +72,7 @@ import java.math.BigDecimal;
import java.math.RoundingMode;
import java.net.URLEncoder;
import java.text.NumberFormat;
import java.time.LocalDateTime;
import java.util.*;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ConcurrentHashMap;
......@@ -1427,8 +1428,14 @@ public class TPaymentInfoServiceImpl extends ServiceImpl<TPaymentInfoMapper, TPa
if (Common.isNotNull(redisUtil.get(importSuccessKey))) {
redisUtil.remove(importSuccessKey);
}
//批量插入的集合
List<TPaymentInfo> batchInsertList = new ArrayList<>();
//养老插入的集合
List<TPaymentInfo> batchYlInsertList = new ArrayList<>();
//工伤插入的集合
List<TPaymentInfo> batchGsInsertList = new ArrayList<>();
//失业插入的集合
List<TPaymentInfo> batchSyInsertList = new ArrayList<>();
//医疗插入的集合
List<TPaymentInfo> batchYyInsertList = new ArrayList<>();
//获取所有项目信息
Map<String, TSettleDomainSelectVo> domainMap = this.getSelectVoMapById();
//地区数据
......@@ -1499,29 +1506,42 @@ public class TPaymentInfoServiceImpl extends ServiceImpl<TPaymentInfoMapper, TPa
*/
private void saveData() {
log.info("{}条数据,开始存储数据库!", cachedDataList.size());
importTPaymentSocialHeFei(cachedDataList, errorMessageList, user, type, rowNumber, pensionMoneyMap,
importTPaymentSocialHeFei(cachedDataList, errorMessageList, type, rowNumber, pensionMoneyMap,
bigMoneyMap, unEmpMoneyMap, injuryMoneyMap, medicalMoneyMap, sumNumKey, importSuccessKey
, batchInsertList, areaMap, areaMap2,domainMap);
, batchGsInsertList,batchSyInsertList,batchYlInsertList,batchYyInsertList, areaMap,
areaMap2,domainMap);
log.info("存储数据库成功!");
}
}).sheet().doRead();
pensionMoneyMap.clear();
bigMoneyMap.clear();
unEmpMoneyMap.clear();
injuryMoneyMap.clear();
medicalMoneyMap.clear();
areaMap.clear();
areaMap2.clear();
domainMap.clear();
//批量插入数据
if (!batchInsertList.isEmpty()) {
this.saveBatch(batchInsertList);
batchInsertList.clear();
if (!batchYlInsertList.isEmpty()) {
this.saveBatch(batchYlInsertList);
batchYlInsertList.clear();
}
if (!batchGsInsertList.isEmpty()) {
this.saveBatch(batchGsInsertList);
batchGsInsertList.clear();
}
if (!batchYyInsertList.isEmpty()) {
this.saveBatch(batchYyInsertList);
batchYyInsertList.clear();
}
if (!batchSyInsertList.isEmpty()) {
this.saveBatch(batchSyInsertList);
batchSyInsertList.clear();
}
} catch (Exception e) {
log.error(CommonConstants.IMPORT_DATA_ANALYSIS_ERROR, e);
return R.failed(CommonConstants.IMPORT_DATA_ANALYSIS_ERROR);
}
pensionMoneyMap.clear();
bigMoneyMap.clear();
unEmpMoneyMap.clear();
injuryMoneyMap.clear();
medicalMoneyMap.clear();
areaMap.clear();
areaMap2.clear();
domainMap.clear();
return this.judgeAllMessage(errorMessageList);
}
......@@ -1777,16 +1797,23 @@ public class TPaymentInfoServiceImpl extends ServiceImpl<TPaymentInfoMapper, TPa
paymentInfo.setSettleDomainCode(domain.getDepartNo());
paymentInfo.setUnitId(domain.getCustomerId());
paymentInfo.setUnitName(domain.getCustomerName());
} else {
paymentInfo.setSettleDomainName("");
paymentInfo.setSettleDomainCode("");
paymentInfo.setUnitId("");
paymentInfo.setUnitName("");
}
paymentInfo.setFundProvince(tProvidentFund.getFundProvince());
paymentInfo.setFundCity(tProvidentFund.getFundCity());
paymentInfo.setFundTown(tProvidentFund.getFundTown());
paymentInfo.setProvidentHousehold(tProvidentFund.getProvidentHouseholdName());
}
if (Common.isNotNull(tProvidentFund)) {
paymentInfo.setInauguralTeam(tProvidentFund.getInauguralTeam());
paymentInfo.setInauguralTeam(Common.isEmpty(tProvidentFund.getInauguralTeam()) ? tProvidentFund.getInauguralTeam(): "");
paymentInfo.setEmpNo(tProvidentFund.getEmpNo());
} else {
paymentInfo.setInauguralTeam("");
paymentInfo.setEmpNo("");
}
paymentInfo.setProvidentPayMonth(infoVo.getProvidentPayMonth());
if (null != paymentInfo.getFundProvince()) {
......@@ -1808,6 +1835,8 @@ public class TPaymentInfoServiceImpl extends ServiceImpl<TPaymentInfoMapper, TPa
paymentInfo.setProvidentPayAddr(paymentInfo.getProvidentPayAddr()
+ CommonConstants.CENTER_SPLIT_LINE_STRING + temp);
}
} else {
paymentInfo.setFundTown("");
}
paymentInfo.setProvidentCreateMonth(infoVo.getProvidentCreateMonth());
......@@ -1821,11 +1850,6 @@ public class TPaymentInfoServiceImpl extends ServiceImpl<TPaymentInfoMapper, TPa
paymentInfo.setSumAll(paymentInfo.getProvidentSum());
paymentInfo.setFundId(UUID.randomUUID().toString());
batchInsertList.add(paymentInfo);
//批量插入数据
if (batchInsertList.size() >= 100000) {
this.saveBatch(batchInsertList);
batchInsertList.clear();
}
paymentInfoMap.put(paymentInfo.getProvidentPayAddr()
+ CommonConstants.DOWN_LINE_STRING
+ paymentInfo.getEmpIdcard().trim()
......@@ -1844,14 +1868,18 @@ public class TPaymentInfoServiceImpl extends ServiceImpl<TPaymentInfoMapper, TPa
}
private void importTPaymentSocialHeFei(List<TPaymentHeFeiVo> list, List<ErrorDetailVO> errorMessageList,
YifuUser user, String type, Integer rowNumber,
String type, Integer rowNumber,
ConcurrentHashMap<String, BigDecimal> pensionMoneyMap,
ConcurrentHashMap<String, BigDecimal> bigMoneyMap,
ConcurrentHashMap<String, BigDecimal> unEmpMoneyMap,
ConcurrentHashMap<String, BigDecimal> injuryMoneyMap,
ConcurrentHashMap<String, BigDecimal> medicalMoneyMap,
String sumNumKey, String importSuccessKey,
List<TPaymentInfo> batchInsertList,HashMap<String, String> areaMap,
List<TPaymentInfo> batchGsInsertList,
List<TPaymentInfo> batchSyInsertList,
List<TPaymentInfo> batchYlInsertList,
List<TPaymentInfo> batchYyInsertList,
HashMap<String, String> areaMap,
HashMap<String, String> areaMap2,Map<String,TSettleDomainSelectVo> domainMap) {
// 将以下代码提取出来,使用paymentInfoMap提升性能,避免list多次循环查询数据库浪费性能
......@@ -2039,10 +2067,11 @@ public class TPaymentInfoServiceImpl extends ServiceImpl<TPaymentInfoMapper, TPa
// 1.list.size()不足partSize,直接执行
if (list.size() < partSize) {
CompletableFuture<List<ErrorDetailVO>> listCompletableFuture = CompletableFuture.supplyAsync(()
-> executeImportSocialListThree(user, list, areaMap, areaMap2,
-> executeImportSocialListThree(list, areaMap, areaMap2,
paymentInfoPensionMap, paymentInfoMedicalMap, paymentInfoUnEmpMap, paymentInfoInjuryMap,
paymentInfoBigMap, type, errorMessageList, pensionMoneyMap, bigMoneyMap,
unEmpMoneyMap, injuryMoneyMap, medicalMoneyMap,batchInsertList,domainMap),
unEmpMoneyMap, injuryMoneyMap, medicalMoneyMap, batchGsInsertList,
batchSyInsertList, batchYlInsertList, batchYyInsertList,domainMap),
yfSocialImportThreadPoolExecutor);
completableFutureList.add(listCompletableFuture);
}
......@@ -2053,11 +2082,12 @@ public class TPaymentInfoServiceImpl extends ServiceImpl<TPaymentInfoMapper, TPa
// 处理第一个0位元素
final List<TPaymentHeFeiVo> finalList = list.subList(0, 1);
CompletableFuture<List<ErrorDetailVO>> oneCompletableFuture = CompletableFuture.supplyAsync(()
-> executeImportSocialListThree(user, finalList, areaMap,
-> executeImportSocialListThree(finalList, areaMap,
areaMap2, paymentInfoPensionMap, paymentInfoMedicalMap, paymentInfoUnEmpMap,
paymentInfoInjuryMap, paymentInfoBigMap, type,
errorMessageList, pensionMoneyMap, bigMoneyMap, unEmpMoneyMap, injuryMoneyMap,
medicalMoneyMap,batchInsertList,domainMap), yfSocialImportThreadPoolExecutor);
medicalMoneyMap,batchGsInsertList, batchSyInsertList, batchYlInsertList,
batchYyInsertList,domainMap), yfSocialImportThreadPoolExecutor);
completableFutureList.add(oneCompletableFuture);
lastIdx = 1;
for (int i = 1; i < list.size(); i++) {
......@@ -2067,11 +2097,12 @@ public class TPaymentInfoServiceImpl extends ServiceImpl<TPaymentInfoMapper, TPa
lastIdx = i;
List<TPaymentHeFeiVo> finalTempList1 = tempList;
CompletableFuture<List<ErrorDetailVO>> listCompletableFuture = CompletableFuture.supplyAsync(()
-> executeImportSocialListThree(user, finalTempList1
-> executeImportSocialListThree(finalTempList1
, areaMap, areaMap2, paymentInfoPensionMap, paymentInfoMedicalMap,
paymentInfoUnEmpMap, paymentInfoInjuryMap, paymentInfoBigMap, type,
errorMessageList, pensionMoneyMap, bigMoneyMap, unEmpMoneyMap,
injuryMoneyMap, medicalMoneyMap,batchInsertList,domainMap),
injuryMoneyMap, medicalMoneyMap,batchGsInsertList, batchSyInsertList,
batchYlInsertList, batchYyInsertList,domainMap),
yfSocialImportThreadPoolExecutor);
completableFutureList.add(listCompletableFuture);
tempList = new ArrayList<>();
......@@ -2095,10 +2126,11 @@ public class TPaymentInfoServiceImpl extends ServiceImpl<TPaymentInfoMapper, TPa
List<TPaymentHeFeiVo> finalTempList = tempList;
CompletableFuture<List<ErrorDetailVO>> listCompletableFuture = CompletableFuture.supplyAsync(()
-> executeImportSocialListThree(user, finalTempList, areaMap,
-> executeImportSocialListThree(finalTempList, areaMap,
areaMap2, paymentInfoPensionMap, paymentInfoMedicalMap, paymentInfoUnEmpMap,
paymentInfoInjuryMap, paymentInfoBigMap, type, errorMessageList, pensionMoneyMap,
bigMoneyMap, unEmpMoneyMap, injuryMoneyMap, medicalMoneyMap,batchInsertList,domainMap)
bigMoneyMap, unEmpMoneyMap, injuryMoneyMap, medicalMoneyMap,batchGsInsertList,
batchSyInsertList, batchYlInsertList, batchYyInsertList,domainMap)
, yfSocialImportThreadPoolExecutor);
completableFutureList.add(listCompletableFuture);
}
......@@ -2121,8 +2153,7 @@ public class TPaymentInfoServiceImpl extends ServiceImpl<TPaymentInfoMapper, TPa
}
}
private List<ErrorDetailVO> executeImportSocialListThree(YifuUser user,
List<TPaymentHeFeiVo> list,
private List<ErrorDetailVO> executeImportSocialListThree(List<TPaymentHeFeiVo> list,
HashMap<String, String> areaMap,
HashMap<String, String> areaMap2,
ConcurrentHashMap<String, TPaymentInfo> paymentInfoPensionMap,
......@@ -2136,7 +2167,10 @@ public class TPaymentInfoServiceImpl extends ServiceImpl<TPaymentInfoMapper, TPa
ConcurrentHashMap<String, BigDecimal> unEmpMoneyMap,
ConcurrentHashMap<String, BigDecimal> injuryMoneyMap,
ConcurrentHashMap<String, BigDecimal> medicalMoneyMap,
List<TPaymentInfo> batchInsertList,
List<TPaymentInfo> batchGsInsertList,
List<TPaymentInfo> batchSyInsertList,
List<TPaymentInfo> batchYlInsertList,
List<TPaymentInfo> batchYyInsertList,
Map<String,TSettleDomainSelectVo> domainMap) {
if (Common.isNotNull(list)) {
TPaymentInfo payExists;
......@@ -2154,8 +2188,8 @@ public class TPaymentInfoServiceImpl extends ServiceImpl<TPaymentInfoMapper, TPa
if (Common.isNotNull(socialInfoList)) {
for (TSocialFundInfo tSocialInfo1 : socialInfoList) {
socialMap.put(tSocialInfo1.getEmpIdcard()
+ CommonConstants.DOWN_LINE_STRING + tSocialInfo1.getSocialCity()
+ CommonConstants.DOWN_LINE_STRING + tSocialInfo1.getSocialProvince()
+ CommonConstants.DOWN_LINE_STRING + tSocialInfo1.getSocialCity()
+ CommonConstants.DOWN_LINE_STRING + (null == tSocialInfo1.getSocialTown()
? "null" : tSocialInfo1.getSocialTown()), tSocialInfo1);
}
......@@ -2424,10 +2458,10 @@ public class TPaymentInfoServiceImpl extends ServiceImpl<TPaymentInfoMapper, TPa
payExists.setEmpIdcard(socialInfo.getEmpIdcard());
payExists.setEmpName(socialInfo.getEmpName());
payExists.setSettleDomainId(socialInfo.getSettleDomain());
payExists.setSettleDomainName(socialInfo.getSettleDomainName());
payExists.setSettleDomainCode(socialInfo.getSettleDomainCode());
payExists.setUnitId(socialInfo.getUnitId());
payExists.setUnitName(socialInfo.getUnitName());
payExists.setSettleDomainCode(Common.isEmpty(socialInfo.getSettleDomainCode()) ? socialInfo.getSettleDomainCode(): "");
payExists.setUnitId(Common.isEmpty(socialInfo.getUnitId()) ? socialInfo.getUnitId(): "");
payExists.setSettleDomainName(Common.isEmpty(socialInfo.getSettleDomainName()) ? socialInfo.getSettleDomainName(): "");
payExists.setUnitName(Common.isEmpty(socialInfo.getUnitName()) ? socialInfo.getUnitName(): "");
payExists.setSocialProvince(socialInfo.getSocialProvince());
payExists.setSocialCity(socialInfo.getSocialCity());
payExists.setSocialTown(socialInfo.getSocialTown());
......@@ -2443,10 +2477,15 @@ public class TPaymentInfoServiceImpl extends ServiceImpl<TPaymentInfoMapper, TPa
domain = null;
}
if (Common.isNotNull(domain)) {
payExists.setSettleDomainName(domain.getDepartName());
payExists.setSettleDomainCode(domain.getDepartNo());
payExists.setUnitId(domain.getCustomerId());
payExists.setUnitName(domain.getCustomerName());
payExists.setSettleDomainName(Common.isEmpty(domain.getDepartName()) ? domain.getDepartName(): "");
payExists.setSettleDomainCode(Common.isEmpty(domain.getDepartNo()) ? domain.getDepartNo(): "");
payExists.setUnitId(Common.isEmpty(domain.getCustomerId()) ? domain.getCustomerId(): "");
payExists.setUnitName(Common.isEmpty(domain.getCustomerName()) ? domain.getCustomerName(): "");
} else {
payExists.setSettleDomainName("");
payExists.setSettleDomainCode("");
payExists.setUnitId("");
payExists.setUnitName("");
}
payExists.setSocialProvince(tSocialInfo.getSocialProvince());
payExists.setSocialCity(tSocialInfo.getSocialCity());
......@@ -2454,8 +2493,11 @@ public class TPaymentInfoServiceImpl extends ServiceImpl<TPaymentInfoMapper, TPa
payExists.setSocialHousehold(tSocialInfo.getSocialHouseholdName());
}
if (Common.isNotNull(tSocialInfo)) {
payExists.setInauguralTeam(tSocialInfo.getInauguralTeam());
payExists.setInauguralTeam(Common.isEmpty(tSocialInfo.getInauguralTeam()) ? tSocialInfo.getInauguralTeam(): "");
payExists.setEmpNo(tSocialInfo.getEmpNo());
} else {
payExists.setInauguralTeam("");
payExists.setEmpNo("");
}
payExists.setSocialPayMonth(infoVo.getSocialPayMonth());
......@@ -2476,9 +2518,14 @@ public class TPaymentInfoServiceImpl extends ServiceImpl<TPaymentInfoMapper, TPa
if (Common.isNotNull(temp)) {
payExists.setSocialPayAddr(payExists.getSocialPayAddr() + CommonConstants.CENTER_SPLIT_LINE_STRING + temp);
}
} else {
payExists.setSocialTown("");
}
payExists.setSocialSecurityNo(infoVo.getSocialSecurityNo());
payExists.setSocialCreateMonth(infoVo.getSocialCreateMonth());
payExists.setSumAll(payExists.getSocialSum());
payExists.setCreateTime(LocalDateTime.now());
payExists.setSocialId(UUID.randomUUID().toString());
if (PaymentConstants.PENSION_RISK.equals(infoVo.getRiskType())) {
payExists.setUnitPensionMoney(infoVo.getUnitMoney());
payExists.setUnitPensionSet(infoVo.getUnitSet());
......@@ -2487,6 +2534,8 @@ public class TPaymentInfoServiceImpl extends ServiceImpl<TPaymentInfoMapper, TPa
, payExists.getUnitSocialSum()));
payExists.setSocialSecurityPersonalSum(BigDecimalUtils.safeAdd(payExists.getPersonalPensionMoney()
, payExists.getSocialSecurityPersonalSum()));
payExists.setSocialSum(BigDecimalUtils.safeAdd(payExists.getUnitSocialSum(), payExists.getSocialSecurityPersonalSum()));
batchYlInsertList.add(payExists);
}
if (PaymentConstants.UNEMPLOYEEMENT_RISK.equals(infoVo.getRiskType())) {
payExists.setUnitUnemploymentMoney(infoVo.getUnitMoney());
......@@ -2496,12 +2545,16 @@ public class TPaymentInfoServiceImpl extends ServiceImpl<TPaymentInfoMapper, TPa
, payExists.getUnitSocialSum()));
payExists.setSocialSecurityPersonalSum(BigDecimalUtils.safeAdd(payExists.getPersonalUnemploymentMoney()
, payExists.getSocialSecurityPersonalSum()));
payExists.setSocialSum(BigDecimalUtils.safeAdd(payExists.getUnitSocialSum(), payExists.getSocialSecurityPersonalSum()));
batchSyInsertList.add(payExists);
}
if (PaymentConstants.INJURY_RISK.equals(infoVo.getRiskType())) {
payExists.setUnitInjuryMoney(infoVo.getUnitMoney());
payExists.setUnitInjurySet(infoVo.getUnitSet());
payExists.setUnitSocialSum(BigDecimalUtils.safeAdd(payExists.getUnitInjuryMoney()
, payExists.getUnitSocialSum()));
payExists.setSocialSum(BigDecimalUtils.safeAdd(payExists.getUnitSocialSum(), payExists.getSocialSecurityPersonalSum()));
batchGsInsertList.add(payExists);
}
if (CommonConstants.ONE_STRING.equals(type)) {
payExists.setUnitMedicalMoney(infoVo.getUnitMedicalMoney());
......@@ -2517,17 +2570,8 @@ public class TPaymentInfoServiceImpl extends ServiceImpl<TPaymentInfoMapper, TPa
payExists.setSocialSecurityPersonalSum(BigDecimalUtils.safeAdd(payExists.getPersonalMedicalMoney()
, payExists.getPersonalBigmailmentMoney()
, payExists.getSocialSecurityPersonalSum()));
}
payExists.setSocialSum(BigDecimalUtils.safeAdd(payExists.getUnitSocialSum(), payExists.getSocialSecurityPersonalSum()));
payExists.setSumAll(payExists.getSocialSum());
payExists.setCreateBy(user.getId());
payExists.setCreateName(user.getNickname());
payExists.setSocialId(UUID.randomUUID().toString());
batchInsertList.add(payExists);
//批量插入数据
if (batchInsertList.size() >= 50000) {
this.saveBatch(batchInsertList);
batchInsertList.clear();
payExists.setSocialSum(BigDecimalUtils.safeAdd(payExists.getUnitSocialSum(), payExists.getSocialSecurityPersonalSum()));
batchYyInsertList.add(payExists);
}
}
}
......
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