Commit ecdbc7da authored by fangxinjiang's avatar fangxinjiang

公积金导入批量办理

parent bd985407
/*
* Copyright (c) 2018-2025, lengleng All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* Neither the name of the yifu4cloud.com developer nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
* Author: lengleng (wangiegie@gmail.com)
*/
package com.yifu.cloud.plus.v1.yifu.social.vo;
import com.alibaba.excel.annotation.ExcelIgnore;
import com.alibaba.excel.annotation.ExcelProperty;
import com.alibaba.excel.annotation.write.style.HeadFontStyle;
import com.yifu.cloud.plus.v1.yifu.common.core.constant.ExcelAttribute;
import com.yifu.cloud.plus.v1.yifu.common.core.constant.ExcelAttributeConstants;
import com.yifu.cloud.plus.v1.yifu.common.core.vo.RowIndex;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import org.hibernate.validator.constraints.Length;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import java.io.Serializable;
import java.math.BigDecimal;
import java.util.Date;
/**
* 派单信息记录表
*
* @author fxj
* @date 2022-07-15 11:38:05
*/
@Data
public class FundImportHandleVo extends RowIndex implements Serializable {
/**
* 员工姓名
*/
@ExcelAttribute(name = "员工姓名" )
@Schema(description = "员工姓名" )
@ExcelProperty("员工姓名" )
private String empName;
/**
* 身份证号
*/
@ExcelAttribute(name = "身份证号",isNotEmpty = true,errorInfo = "身份证不可为空")
@Schema(description = "身份证号" )
@ExcelProperty("身份证号" )
private String empIdcard;
/**
* 公积金办理状态:0 成功,1失败
*/
@ExcelAttribute(name = "公积金" ,isDataId = true,readConverterExp = "0=成功,1=失败",isNotEmpty = true,errorInfo = "公积金办理状态不可为空")
@Schema(description = "公积金办理状态:0 成功,1失败" )
@ExcelProperty("公积金" )
private String handleStatus;
/**
* 失败原因
*/
@ExcelAttribute(name = "失败原因")
@Schema(description = "失败原因" )
@ExcelProperty("失败原因" )
private String remark;
}
...@@ -584,4 +584,41 @@ public class TDispatchInfoController { ...@@ -584,4 +584,41 @@ public class TDispatchInfoController {
return tDispatchInfoService.dispatchAdd(importVo); return tDispatchInfoService.dispatchAdd(importVo);
} }
/**
* @Author fxj
* @Description 公积金批量办理
* @Date 15:29 2023/5/8
* @Param
* @return
**/
@SneakyThrows
@Operation(summary = "单个派增 权限:social_dispatchinfo_add", description = "单个派增")
@PostMapping("/fundImportHandle")
@PreAuthorize("@pms.hasPermission('fund_import_handle')")
public R<List<ErrorMessage>> fundImportHandle(@RequestBody MultipartFile file) {
YifuUser user = SecurityUtils.getUser();
if (Common.isEmpty(user)) {
return R.failed(CommonConstants.USER_FAIL);
}
// 获取redis分布式事务锁
String key = CacheConstants.FUND_IMPORT_HANDLE_LOCK + CommonConstants.DOWN_LINE_STRING + user.getId();
String requestId;
try {
requestId = RedisDistributedLock.getLock(key, "10");
} catch (Exception e) {
throw new RuntimeException(ResultConstants.NO_GETLOCK_DATA + CommonConstants.DOWN_LINE_STRING + e.getMessage());
}
try {
if (Common.isNotNull(requestId)) {
//主动释放锁
return tDispatchInfoService.fundImportHandle(file.getInputStream());
} else {
return R.failed(ResultConstants.NO_GETLOCK_DATA);
}
} finally {
//主动释放锁
RedisDistributedLock.unlock(key, requestId);
}
}
} }
...@@ -103,6 +103,16 @@ public interface TDispatchInfoMapper extends BaseMapper<TDispatchInfo> { ...@@ -103,6 +103,16 @@ public interface TDispatchInfoMapper extends BaseMapper<TDispatchInfo> {
IPage<TDispatchInfo> getTDispatchFundHandlePage(Page<TDispatchInfo> page, IPage<TDispatchInfo> getTDispatchFundHandlePage(Page<TDispatchInfo> page,
@Param("tDispatchInfo")SocialHandleSearchVo tDispatchInfo, @Param("tDispatchInfo")SocialHandleSearchVo tDispatchInfo,
@Param("idsStr") List<String> idsStr); @Param("idsStr") List<String> idsStr);
/**
* 公积金办理查询
* @Author fxj
* @Date 2019-10-12
* @param tDispatchInfo
* @return
**/
List<TDispatchInfo> getTDispatchFundHandleNoPage(@Param("tDispatchInfo")SocialHandleSearchVo tDispatchInfo,
@Param("idCards") List<String> idCards);
/** /**
* @Author fxj * @Author fxj
* @Description 公积金补交清册 * @Description 公积金补交清册
......
...@@ -108,4 +108,6 @@ public interface TDispatchInfoService extends IService<TDispatchInfo> { ...@@ -108,4 +108,6 @@ public interface TDispatchInfoService extends IService<TDispatchInfo> {
* @return: com.yifu.cloud.plus.v1.yifu.common.core.util.R<java.util.List < com.yifu.cloud.plus.v1.yifu.common.core.util.ErrorMessage>> * @return: com.yifu.cloud.plus.v1.yifu.common.core.util.R<java.util.List < com.yifu.cloud.plus.v1.yifu.common.core.util.ErrorMessage>>
**/ **/
R<List<ErrorMessage>> dispatchAdd(TDispatchImportVo importVo); R<List<ErrorMessage>> dispatchAdd(TDispatchImportVo importVo);
R<List<ErrorMessage>> fundImportHandle(InputStream inputStream);
} }
...@@ -47,6 +47,7 @@ import com.yifu.cloud.plus.v1.yifu.common.core.util.*; ...@@ -47,6 +47,7 @@ import com.yifu.cloud.plus.v1.yifu.common.core.util.*;
import com.yifu.cloud.plus.v1.yifu.common.core.vo.YifuUser; import com.yifu.cloud.plus.v1.yifu.common.core.vo.YifuUser;
import com.yifu.cloud.plus.v1.yifu.common.dapr.util.ArchivesDaprUtil; import com.yifu.cloud.plus.v1.yifu.common.dapr.util.ArchivesDaprUtil;
import com.yifu.cloud.plus.v1.yifu.common.dapr.util.CheckDaprUtil; import com.yifu.cloud.plus.v1.yifu.common.dapr.util.CheckDaprUtil;
import com.yifu.cloud.plus.v1.yifu.common.dapr.util.MenuUtil;
import com.yifu.cloud.plus.v1.yifu.common.dapr.util.UpmsDaprUtils; import com.yifu.cloud.plus.v1.yifu.common.dapr.util.UpmsDaprUtils;
import com.yifu.cloud.plus.v1.yifu.common.mybatis.base.BaseEntity; import com.yifu.cloud.plus.v1.yifu.common.mybatis.base.BaseEntity;
import com.yifu.cloud.plus.v1.yifu.common.security.util.SecurityUtils; import com.yifu.cloud.plus.v1.yifu.common.security.util.SecurityUtils;
...@@ -63,6 +64,7 @@ import com.yifu.cloud.plus.v1.yifu.social.util.ServiceUtil; ...@@ -63,6 +64,7 @@ import com.yifu.cloud.plus.v1.yifu.social.util.ServiceUtil;
import com.yifu.cloud.plus.v1.yifu.social.vo.*; import com.yifu.cloud.plus.v1.yifu.social.vo.*;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import lombok.extern.log4j.Log4j2; import lombok.extern.log4j.Log4j2;
import org.apache.ibatis.annotations.Param;
import org.apache.shardingsphere.transaction.annotation.ShardingTransactionType; import org.apache.shardingsphere.transaction.annotation.ShardingTransactionType;
import org.apache.shardingsphere.transaction.core.TransactionType; import org.apache.shardingsphere.transaction.core.TransactionType;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
...@@ -122,6 +124,7 @@ public class TDispatchInfoServiceImpl extends ServiceImpl<TDispatchInfoMapper, T ...@@ -122,6 +124,7 @@ public class TDispatchInfoServiceImpl extends ServiceImpl<TDispatchInfoMapper, T
ExcelUtil<Object> excelUtil = new ExcelUtil<>(Object.class); ExcelUtil<Object> excelUtil = new ExcelUtil<>(Object.class);
private final MenuUtil menuUtil;
@Autowired @Autowired
private DoSocialTask socialTask; private DoSocialTask socialTask;
...@@ -4942,5 +4945,133 @@ public class TDispatchInfoServiceImpl extends ServiceImpl<TDispatchInfoMapper, T ...@@ -4942,5 +4945,133 @@ public class TDispatchInfoServiceImpl extends ServiceImpl<TDispatchInfoMapper, T
} }
} }
/**
* @Author fxj
* @Description 批量导入办理
* @Date 15:46 2023/5/8
* @Param
* @return
**/
@Transactional(rollbackFor = Exception.class)
@ShardingTransactionType(TransactionType.BASE)
@Override
public R<List<ErrorMessage>> fundImportHandle(InputStream inputStream) {
YifuUser user = SecurityUtils.getUser();
if (Common.isEmpty(user)){
R.failed(CommonConstants.USER_FAIL);
}
List<ErrorMessage> errorMessageList = new ArrayList<>();
ExcelUtil<FundImportHandleVo> util1 = new ExcelUtil<>(FundImportHandleVo.class);
// 写法2:
// 匿名内部类 不用额外写一个DemoDataListener
// 这里 需要指定读用哪个class去读,然后读取第一个sheet 文件流会自动关闭
try {
EasyExcel.read(inputStream, FundImportHandleVo.class, new ReadListener<FundImportHandleVo>() {
/**
* 单次缓存的数据量
*/
public static final int BATCH_COUNT = CommonConstants.BATCH_COUNT;
/**
*临时存储
*/
private List<FundImportHandleVo> cachedDataList = ListUtils.newArrayListWithExpectedSize(BATCH_COUNT);
@Override
public void invoke(FundImportHandleVo data, AnalysisContext context) {
ReadRowHolder readRowHolder = context.readRowHolder();
Integer rowIndex = readRowHolder.getRowIndex();
data.setRowIndex(rowIndex + 1);
ErrorMessage errorMessage = util1.checkEntity(data, data.getRowIndex());
if (Common.isNotNull(errorMessage)) {
errorMessageList.add(errorMessage);
} else {
cachedDataList.add(data);
}
if (cachedDataList.size() >= BATCH_COUNT) {
saveData();
// 存储完成清理 list
cachedDataList = ListUtils.newArrayListWithExpectedSize(BATCH_COUNT);
}
}
@Override
public void doAfterAllAnalysed(AnalysisContext context) {
saveData();
}
/**
* 加上存储数据库
*/
private void saveData() {
log.info("{}条数据,开始存储数据库!", cachedDataList.size());
fundImportHandle(cachedDataList, errorMessageList,user);
log.info("存储数据库成功!");
}
}).sheet().doRead();
} catch (Exception e) {
log.error(CommonConstants.IMPORT_DATA_ANALYSIS_ERROR, e);
return R.failed(CommonConstants.IMPORT_DATA_ANALYSIS_ERROR);
}
return this.judgeAllMessage(errorMessageList);
}
/**
* @Author fxj
* @Description 批量导入办理 处理逻辑
* @Date 16:45 2023/5/8
* @Param
* @return
**/
public void fundImportHandle(List<FundImportHandleVo> excelVOList, List<ErrorMessage> errorMessageList, YifuUser user) {
if (!Common.isNotNull(excelVOList)) {
return;
}
// 个性化校验逻辑
FundImportHandleVo excel;
int flag = 1;
String handleStatus = "2";
SocialHandleSearchVo tDispatchInfo = new SocialHandleSearchVo();
tDispatchInfo.setDeleteFlag(CommonConstants.ZERO_STRING);
menuUtil.setAuthSql(user, tDispatchInfo);
if (Common.isNotNull(tDispatchInfo.getAuthSql()) && tDispatchInfo.getAuthSql().contains(CommonConstants.A_DEPT_ID)) {
tDispatchInfo.setAuthSql(tDispatchInfo.getAuthSql().replace(CommonConstants.A_DEPT_ID, "a.SETTLE_DOMAIN"));
}
tDispatchInfo.setCreateBy(user.getId());
List<TDispatchInfo> dispatchInfos = baseMapper.getTDispatchFundHandleNoPage(tDispatchInfo, excelVOList.stream()
.map(FundImportHandleVo::getEmpIdcard).collect(Collectors.toList()));
Map<String, TDispatchInfo> dispatchMap = new HashMap<>();
if (Common.isNotNull(dispatchInfos)) {
dispatchMap = dispatchInfos.stream().collect(Collectors.toMap(TDispatchInfo::getEmpIdcard, TDispatchInfo -> TDispatchInfo));
}
TDispatchInfo dispatch;
for (int i = 0; i < excelVOList.size(); i++) {
excel = excelVOList.get(i);
if (Common.isEmpty(excel)
|| (!CommonConstants.ZERO_STRING.equals(excel.getHandleStatus())
&& !CommonConstants.ONE_STRING.equals(excel.getHandleStatus()))) {
errorMessageList.add(new ErrorMessage(excel.getRowIndex(), MsgUtils.getMessage(CommonConstants.PARAM_INFO_ERROR)));
continue;
}
if (CommonConstants.ZERO_STRING.equals(excel.getHandleStatus())) {
flag = CommonConstants.ZERO_INT;
handleStatus = CommonConstants.ONE_STRING;
}
if (CommonConstants.ONE_STRING.equals(excel.getHandleStatus())) {
flag = CommonConstants.ONE_INT;
handleStatus = CommonConstants.TWO_STRING;
}
dispatch = dispatchMap.get(excel.getEmpIdcard());
if (Common.isEmpty(dispatch)) {
errorMessageList.add(new ErrorMessage(excel.getRowIndex(), MsgUtils.getMessage(ErrorCodes.FUND_IMPORT_HANDLE_NOT_EXITS)));
continue;
}
try {
// 执行数据插入操作 组装
errorMessageList.addAll(addBatchApplyHandle(Collections.singletonList(dispatch.getId()), CommonConstants.ONE_STRING, user
, flag, handleStatus, null, null, excel.getRemark()));
} catch (Exception e) {
log.error("批量导入办理异常:", e);
errorMessageList.add(new ErrorMessage(excel.getRowIndex(), CommonConstants.SAVE_FAILED));
}
}
}
} }
...@@ -1052,6 +1052,14 @@ ...@@ -1052,6 +1052,14 @@
<include refid="where_getFundRecord"/> <include refid="where_getFundRecord"/>
</select> </select>
<!--tDispatchInfo 公积金办理数据查询 2023-05-08-->
<select id="getTDispatchFundHandleNoPage" resultMap="dispatchPageMap">
SELECT
<include refid="Base_Column_List"/>,
a.PROVIDENT_HOUSEHOLD_NAME
<include refid="where_getFundRecord"/>
</select>
<!--tDispatchInfo 公积金变更清册cout--> <!--tDispatchInfo 公积金变更清册cout-->
<select id="getFundRecordCount" resultType="java.lang.Integer"> <select id="getFundRecordCount" resultType="java.lang.Integer">
SELECT SELECT
...@@ -1236,6 +1244,12 @@ ...@@ -1236,6 +1244,12 @@
#{items} #{items}
</foreach> </foreach>
</if> </if>
<if test="idsStr != null and idsStr.size > 0">
AND a.emp_idcard in
<foreach item="items" index="index" collection="idCards" open="(" separator="," close=")">
#{items}
</foreach>
</if>
/** 社保办理状态:0待办理/1已办理2办理失败3已派减4 办理中 5 部分办理失败 派单社保办理状态 0 未办理 1 全部办理成功(原-已办理) 2 全部办理失败(原-办理失败) 3 部分办理成功 4 办理中 **/ /** 社保办理状态:0待办理/1已办理2办理失败3已派减4 办理中 5 部分办理失败 派单社保办理状态 0 未办理 1 全部办理成功(原-已办理) 2 全部办理失败(原-办理失败) 3 部分办理成功 4 办理中 **/
/*社保代办理 1.派单审核通过 2.派增(type=0):待办理(social_handle_status='0') or 派减(type=1):已办理完成或部分办理失败 且已派减*/ /*社保代办理 1.派单审核通过 2.派增(type=0):待办理(social_handle_status='0') or 派减(type=1):已办理完成或部分办理失败 且已派减*/
AND a.fund_id is not null AND a.fund_id is not null
......
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