Browse Source

Merge branch 'master' of http://git.elinkit.com.cn:7070/r/epmet-cloud

feature/evaluate
wangxianzhang 3 years ago
parent
commit
1d063554e2
  1. 28
      epmet-module/gov-org/gov-org-client/src/main/java/com/epmet/dto/result/CurrentUserCommunityInfoResultDTO.java
  2. 12
      epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/controller/CustomerAgencyController.java
  3. 4
      epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/dao/CustomerAgencyDao.java
  4. 11
      epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/service/CustomerAgencyService.java
  5. 13
      epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/service/impl/CustomerAgencyServiceImpl.java
  6. 15
      epmet-module/gov-org/gov-org-server/src/main/resources/mapper/CustomerAgencyDao.xml
  7. 70
      epmet-user/epmet-user-server/src/main/java/com/epmet/controller/ChangeWelfareController.java
  8. 2
      epmet-user/epmet-user-server/src/main/java/com/epmet/dao/ChangeWelfareDao.java
  9. 3
      epmet-user/epmet-user-server/src/main/java/com/epmet/dao/IcResiUserDao.java
  10. 63
      epmet-user/epmet-user-server/src/main/java/com/epmet/excel/ChangeWelfareImportExcel.java
  11. 35
      epmet-user/epmet-user-server/src/main/java/com/epmet/excel/error/ChangeWelfareErrorExcel.java
  12. 11
      epmet-user/epmet-user-server/src/main/java/com/epmet/service/ChangeWelfareService.java
  13. 243
      epmet-user/epmet-user-server/src/main/java/com/epmet/service/impl/ChangeWelfareServiceImpl.java
  14. BIN
      epmet-user/epmet-user-server/src/main/resources/excel/pli_change_welfare.xlsx
  15. 8
      epmet-user/epmet-user-server/src/main/resources/mapper/ChangeWelfareDao.xml
  16. 4
      epmet-user/epmet-user-server/src/main/resources/mapper/IcResiUserDao.xml

28
epmet-module/gov-org/gov-org-client/src/main/java/com/epmet/dto/result/CurrentUserCommunityInfoResultDTO.java

@ -0,0 +1,28 @@
package com.epmet.dto.result;
import lombok.Data;
import java.io.Serializable;
/**
* @Description 当前登陆人的所属社区
* @Author wgf
* @Date 2020/11/30 22:35
*/
@Data
public class CurrentUserCommunityInfoResultDTO implements Serializable {
private static final long serialVersionUID = 4360690752084258055L;
/**
* 组织ID
*/
private String orgId;
/**
* 名称
*/
private String orgName;
}

12
epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/controller/CustomerAgencyController.java

@ -505,5 +505,17 @@ public class CustomerAgencyController {
return customerAgencyService.getCommunityInfoByUserId(userId);
}
/**
* @param tokenDTO
* @return com.epmet.commons.tools.utils.Result<com.epmet.dto.result.CommunityInfoResultDTO>
* @Author wgf
* @Description 获取当前登录人的所属社区
* @Date 2022/11/30 22:41
**/
@PostMapping("getCurrentUserCommunityInfo")
public Result<List<CurrentUserCommunityInfoResultDTO>> getCurrentUserCommunityInfo(@LoginUser TokenDto tokenDTO) {
return customerAgencyService.getCurrentUserCommunityInfo(tokenDTO);
}
}

4
epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/dao/CustomerAgencyDao.java

@ -398,5 +398,9 @@ public interface CustomerAgencyDao extends BaseDao<CustomerAgencyEntity> {
List<String> getUsingCommunityList(@Param("customerId") String customerId, @Param("agencyId") String agencyId, @Param("agencyOrgIdPath") String agencyOrgIdPath, @Param("endDate") Date endDate);
List<String> getCommunitysByOrgIdPath(@Param("customerId") String customerId, @Param("orgId") String orgId, @Param("orgIdPath") String orgIdPath);
List<CurrentUserCommunityInfoResultDTO> getCurrentUserCommunityInfo(@Param("customerId") String customerId,@Param("staffAgencyId")String staffAgencyId);
}

11
epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/service/CustomerAgencyService.java

@ -18,7 +18,9 @@
package com.epmet.service;
import com.epmet.commons.mybatis.service.BaseService;
import com.epmet.commons.tools.annotation.LoginUser;
import com.epmet.commons.tools.page.PageData;
import com.epmet.commons.tools.security.dto.TokenDto;
import com.epmet.commons.tools.utils.Result;
import com.epmet.dto.CustomerAgencyDTO;
import com.epmet.dto.form.*;
@ -344,4 +346,13 @@ public interface CustomerAgencyService extends BaseService<CustomerAgencyEntity>
* @Date 2022/6/21 22:41
**/
Result<CommunityInfoResultDTO> getCommunityInfoByUserId(String userId);
/**
* @param tokenDTO
* @return com.epmet.commons.tools.utils.Result<com.epmet.dto.result.CommunityInfoResultDTO>
* @Author wgf
* @Description 获取当前登录人的所属社区
* @Date 2022/11/30 22:41
**/
Result<List<CurrentUserCommunityInfoResultDTO>> getCurrentUserCommunityInfo(TokenDto tokenDTO);
}

13
epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/service/impl/CustomerAgencyServiceImpl.java

@ -35,6 +35,7 @@ import com.epmet.commons.tools.redis.RedisUtils;
import com.epmet.commons.tools.redis.common.CustomerOrgRedis;
import com.epmet.commons.tools.redis.common.CustomerStaffRedis;
import com.epmet.commons.tools.redis.common.bean.AgencyInfoCache;
import com.epmet.commons.tools.security.dto.TokenDto;
import com.epmet.commons.tools.utils.ConvertUtils;
import com.epmet.commons.tools.utils.Result;
import com.epmet.constant.CustomerAgencyConstant;
@ -1594,4 +1595,16 @@ public class CustomerAgencyServiceImpl extends BaseServiceImpl<CustomerAgencyDao
return new Result<CommunityInfoResultDTO>().ok(communityInfoResultDTO);
}
@Override
public Result<List<CurrentUserCommunityInfoResultDTO>> getCurrentUserCommunityInfo(TokenDto tokenDTO) {
CustomerStaffInfoCacheResult staffInfoCacheResult = CustomerStaffRedis.getStaffInfo(tokenDTO.getCustomerId(), tokenDTO.getUserId());
if (null == staffInfoCacheResult || StringUtils.isBlank(staffInfoCacheResult.getAgencyId())) {
log.warn("com.epmet.service.impl.CustomerAgencyServiceImpl.getMySubAgencyList,没有找到工作人员所属的机关信息,用户Id:{}", tokenDTO.getUserId());
throw new EpmetException(EpmetErrorCode.EPMET_COMMON_OPERATION_FAIL.getCode(),"获取用户组织信息异常","获取用户组织信息异常");
}
List<CurrentUserCommunityInfoResultDTO> list = baseDao.getCurrentUserCommunityInfo(tokenDTO.getCustomerId(),staffInfoCacheResult.getAgencyId());
return new Result<List<CurrentUserCommunityInfoResultDTO>>().ok(list);
}
}

15
epmet-module/gov-org/gov-org-server/src/main/resources/mapper/CustomerAgencyDao.xml

@ -1040,4 +1040,19 @@
having community_count > 0
order by created_time desc) t
</select>
<select id="getCurrentUserCommunityInfo"
resultType="com.epmet.dto.result.CurrentUserCommunityInfoResultDTO">
select
ID AS orgId,
ORGANIZATION_NAME AS orgName
from customer_agency
where DEL_FLAG = 0
and LEVEL = 'community'
AND CUSTOMER_ID = #{customerId}
<if test="staffAgencyId != null and staffAgencyId != ''">
AND PIDS like concat('%',#{staffAgencyId},'%')
</if>
</select>
</mapper>

70
epmet-user/epmet-user-server/src/main/java/com/epmet/controller/ChangeWelfareController.java

@ -1,8 +1,13 @@
package com.epmet.controller;
import cn.afterturn.easypoi.excel.entity.TemplateExportParams;
import com.epmet.commons.tools.annotation.LoginUser;
import com.epmet.commons.tools.annotation.MaskResponse;
import com.epmet.commons.tools.aop.NoRepeatSubmit;
import com.epmet.commons.tools.exception.EpmetException;
import com.epmet.commons.tools.page.PageData;
import com.epmet.commons.tools.security.dto.TokenDto;
import com.epmet.commons.tools.utils.ExcelPoiUtils;
import com.epmet.commons.tools.utils.ExcelUtils;
import com.epmet.commons.tools.utils.Result;
import com.epmet.commons.tools.validator.AssertUtils;
@ -10,14 +15,23 @@ import com.epmet.commons.tools.validator.ValidatorUtils;
import com.epmet.commons.tools.validator.group.AddGroup;
import com.epmet.commons.tools.validator.group.DefaultGroup;
import com.epmet.commons.tools.validator.group.UpdateGroup;
import com.epmet.constants.ImportTaskConstants;
import com.epmet.dto.ChangeWelfareDTO;
import com.epmet.dto.CheckWelfareByIdCardDTO;
import com.epmet.dto.form.ImportTaskCommonFormDTO;
import com.epmet.dto.result.ImportTaskCommonResultDTO;
import com.epmet.excel.ChangeWelfareExcel;
import com.epmet.feign.EpmetCommonServiceOpenFeignClient;
import com.epmet.service.ChangeWelfareService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.io.FilenameUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import javax.servlet.http.HttpServletResponse;
import java.io.InputStream;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@ -30,11 +44,15 @@ import java.util.Map;
*/
@RestController
@RequestMapping("changeWelfare")
@Slf4j
public class ChangeWelfareController {
@Autowired
private ChangeWelfareService changeWelfareService;
@Autowired
private EpmetCommonServiceOpenFeignClient commonServiceOpenFeignClient;
@RequestMapping("page")
@MaskResponse(fieldNames = {"mobile", "idCard"}, fieldsMaskType = {MaskResponse.MASK_TYPE_MOBILE, MaskResponse.MASK_TYPE_ID_CARD})
public Result<PageData<ChangeWelfareDTO>> page(@RequestParam Map<String, Object> params){
@ -109,4 +127,56 @@ public class ChangeWelfareController {
return changeWelfareService.checkWelfareByIdCard(dto);
}
/**
* Desc: 福利人员导入
* @param
* @author wgf
* @date 2022/11/28 13:40
*/
@PostMapping("pointImport")
public Result pointImport(@LoginUser TokenDto tokenDto, @RequestParam("file") MultipartFile file){
if (file.isEmpty()) {
throw new EpmetException("请上传文件");
}
// 校验文件类型
String extension = FilenameUtils.getExtension(file.getOriginalFilename());
if (!"xls".equals(extension) && !"xlsx".equals(extension)) {
throw new EpmetException("文件类型不匹配");
}
ImportTaskCommonFormDTO importTaskForm = new ImportTaskCommonFormDTO();
importTaskForm.setOriginFileName(file.getOriginalFilename());
importTaskForm.setOperatorId(tokenDto.getUserId());
importTaskForm.setBizType(ImportTaskConstants.IC_POINT_NUCLEIC_MONITORING);
Result<ImportTaskCommonResultDTO> result = commonServiceOpenFeignClient.createImportTask(importTaskForm);
if (!result.success()) {
throw new EpmetException(9999,"存在进行中的导入");
}
InputStream inputStream = null;
try {
inputStream = file.getInputStream();
}catch (Exception e){
ImportTaskCommonFormDTO input = new ImportTaskCommonFormDTO();
input.setOperatorId(tokenDto.getUserId());
input.setTaskId(result.getData().getTaskId());
input.setProcessStatus(ImportTaskConstants.PROCESS_STATUS_FINISHED_FAIL);
commonServiceOpenFeignClient.finishImportTask(input);
log.error("读取文件失败");
}
changeWelfareService.importFile(tokenDto,inputStream,result.getData().getTaskId());
return new Result();
}
/**
* 导出模板
* @param response
* @throws Exception
*/
@PostMapping("exporttemplate")
public void exportTemplate( HttpServletResponse response) throws Exception {
TemplateExportParams templatePath = new TemplateExportParams("excel/pli_change_welfare.xlsx");
ExcelPoiUtils.exportExcel(templatePath ,new HashMap<>(),"福利人员模板",response);
}
}

2
epmet-user/epmet-user-server/src/main/java/com/epmet/dao/ChangeWelfareDao.java

@ -45,4 +45,6 @@ public interface ChangeWelfareDao extends BaseDao<ChangeWelfareEntity> {
* @return com.epmet.commons.tools.utils.Result
*/
void removeWelfare(ChangeWelfareDTO dto);
List<String> getAllWelfareIdCard(@Param("customerId") String customerId);
}

3
epmet-user/epmet-user-server/src/main/java/com/epmet/dao/IcResiUserDao.java

@ -444,4 +444,7 @@ public interface IcResiUserDao extends BaseDao<IcResiUserEntity> {
List<IcResiUserDTO> getResiUserList(ComparisonFormDTO formDTO);
List<RHZKStatisticsResultDTO> getUserByRenHu(RHZKStatisticsFormDTO formDTO);
List<IcResiUserDTO> getImportUserList(@Param("customerId")String customerId,@Param("agencyId")String agencyId);
}

63
epmet-user/epmet-user-server/src/main/java/com/epmet/excel/ChangeWelfareImportExcel.java

@ -0,0 +1,63 @@
package com.epmet.excel;
import cn.afterturn.easypoi.excel.annotation.Excel;
import cn.afterturn.easypoi.excel.annotation.ExcelIgnore;
import lombok.Data;
/**
* 福利表
*
* @author generator generator@elink-cn.com
* @since v1.0.0 2022-05-09
*/
@Data
public class ChangeWelfareImportExcel {
@Excel(name = "姓名")
private String name;
@Excel(name = "证件号")
private String idCard;
@Excel(name = "手机号")
private String mobile;
@Excel(name = "性别",replace = { "男_1", "女_0", " _null"} )
private String gender;
// @Excel(name = "类型")
// private String type;
@Excel(name = "福利原因")
private String joinReason;
// @Excel(name = "客户ID")
// private String customerId;
@ExcelIgnore
private Boolean addStatus = false;
@ExcelIgnore
private Integer num;
/**
* 加入时间
*/
@ExcelIgnore
private String joinDate;
/**
* epmet用户主键
*/
@ExcelIgnore
private String userId;
/**
* epmet网格ID
*/
@ExcelIgnore
private String gridId;
}

35
epmet-user/epmet-user-server/src/main/java/com/epmet/excel/error/ChangeWelfareErrorExcel.java

@ -0,0 +1,35 @@
package com.epmet.excel.error;
import cn.afterturn.easypoi.excel.annotation.Excel;
import cn.afterturn.easypoi.excel.annotation.ExcelIgnore;
import lombok.Data;
/**
* 福利表
*
* @author generator generator@elink-cn.com
* @since v1.0.0 2022-05-09
*/
@Data
public class ChangeWelfareErrorExcel {
@Excel(name = "行号",width = 10)
private Integer num;
@Excel(name = "姓名",width = 30)
private String name;
@Excel(name = "证件号",width = 30)
private String idCard;
@Excel(name = "手机号",width = 20)
private String mobile;
@Excel(name = "福利原因",width = 40)
private String joinReason;
@Excel(name = "错误信息", width = 200)
private String errorMsg;
}

11
epmet-user/epmet-user-server/src/main/java/com/epmet/service/ChangeWelfareService.java

@ -2,11 +2,13 @@ package com.epmet.service;
import com.epmet.commons.mybatis.service.BaseService;
import com.epmet.commons.tools.page.PageData;
import com.epmet.commons.tools.security.dto.TokenDto;
import com.epmet.commons.tools.utils.Result;
import com.epmet.dto.ChangeWelfareDTO;
import com.epmet.dto.CheckWelfareByIdCardDTO;
import com.epmet.entity.ChangeWelfareEntity;
import java.io.InputStream;
import java.util.List;
import java.util.Map;
@ -104,4 +106,13 @@ public interface ChangeWelfareService extends BaseService<ChangeWelfareEntity> {
* @return com.epmet.commons.tools.utils.Result
*/
Result saveWelfareInfo(ChangeWelfareDTO dto);
/**
* Desc: 福利人员导入
* @param tokenDto
* @param inputStream
* @author wgf
* @date 2022/11/28 15:35
*/
void importFile(TokenDto tokenDto, InputStream inputStream, String taskId);
}

243
epmet-user/epmet-user-server/src/main/java/com/epmet/service/impl/ChangeWelfareServiceImpl.java

@ -1,32 +1,67 @@
package com.epmet.service.impl;
import cn.afterturn.easypoi.excel.ExcelExportUtil;
import cn.afterturn.easypoi.excel.entity.ExportParams;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.epmet.commons.mybatis.service.impl.BaseServiceImpl;
import com.epmet.commons.tools.constant.FieldConstant;
import com.epmet.commons.tools.constant.NumConstant;
import com.epmet.commons.tools.dto.result.CustomerStaffInfoCacheResult;
import com.epmet.commons.tools.exception.EpmetException;
import com.epmet.commons.tools.exception.ExceptionUtils;
import com.epmet.commons.tools.page.PageData;
import com.epmet.commons.tools.redis.common.CustomerOrgRedis;
import com.epmet.commons.tools.redis.common.CustomerStaffRedis;
import com.epmet.commons.tools.redis.common.bean.AgencyInfoCache;
import com.epmet.commons.tools.security.dto.TokenDto;
import com.epmet.commons.tools.security.user.LoginUserUtil;
import com.epmet.commons.tools.utils.ConvertUtils;
import com.epmet.commons.tools.utils.DateUtils;
import com.epmet.commons.tools.utils.ExcelPoiUtils;
import com.epmet.commons.tools.utils.Result;
import com.epmet.commons.tools.validator.ValidatorUtils;
import com.epmet.commons.tools.validator.group.DefaultGroup;
import com.epmet.commons.tools.validator.group.UpdateGroup;
import com.epmet.constants.ImportTaskConstants;
import com.epmet.dao.ChangeWelfareDao;
import com.epmet.dao.IcResiUserDao;
import com.epmet.dto.ChangeWelfareDTO;
import com.epmet.dto.CheckWelfareByIdCardDTO;
import com.epmet.dto.IcResiUserDTO;
import com.epmet.dto.form.IcResiUserPageFormDTO;
import com.epmet.dto.form.ImportTaskCommonFormDTO;
import com.epmet.dto.form.RentTenantDataFormDTO;
import com.epmet.dto.result.RentTenantDataResultDTO;
import com.epmet.dto.result.UploadImgResultDTO;
import com.epmet.entity.ChangeWelfareEntity;
import com.epmet.excel.ChangeWelfareImportExcel;
import com.epmet.excel.error.ChangeWelfareErrorExcel;
import com.epmet.feign.EpmetCommonServiceOpenFeignClient;
import com.epmet.feign.GovOrgFeignClient;
import com.epmet.feign.OssFeignClient;
import com.epmet.redis.ChangeWelfareRedis;
import com.epmet.service.ChangeWelfareService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.fileupload.FileItem;
import org.apache.commons.fileupload.FileItemFactory;
import org.apache.commons.fileupload.disk.DiskFileItemFactory;
import org.apache.commons.lang3.StringUtils;
import org.apache.http.entity.ContentType;
import org.apache.poi.ss.usermodel.Workbook;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.multipart.commons.CommonsMultipartFile;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.stream.Collectors;
/**
* 福利表
@ -35,6 +70,7 @@ import java.util.*;
* @since v1.0.0 2022-05-09
*/
@Service
@Slf4j
public class ChangeWelfareServiceImpl extends BaseServiceImpl<ChangeWelfareDao, ChangeWelfareEntity> implements ChangeWelfareService {
@Autowired
@ -46,6 +82,18 @@ public class ChangeWelfareServiceImpl extends BaseServiceImpl<ChangeWelfareDao,
@Autowired
private IcResiUserServiceImpl icResiUserServiceImpl;
@Autowired
private EpmetCommonServiceOpenFeignClient commonServiceOpenFeignClient;
@Autowired
private OssFeignClient ossFeignClient;
@Autowired
private GovOrgFeignClient govOrgFeignClient;
@Autowired
private IcResiUserDao icResiUserDao;
@Override
public PageData<ChangeWelfareDTO> page(Map<String, Object> params) {
params.put("customerId", loginUserUtil.getLoginUserCustomerId());
@ -163,4 +211,199 @@ public class ChangeWelfareServiceImpl extends BaseServiceImpl<ChangeWelfareDao,
return new Result();
}
/**
* Desc: 福利人员导入
* @param tokenDto
* @param inputStream
* @param taskId
* @author wgf
* @date 2022/11/28 15:35
*/
@Override
@Async
public void importFile(TokenDto tokenDto, InputStream inputStream, String taskId) {
List<ChangeWelfareErrorExcel> errorInfo = new ArrayList<>();
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
try {
List<ChangeWelfareImportExcel> list = ExcelPoiUtils.importExcel(inputStream, 0,1,ChangeWelfareImportExcel.class);
if (CollectionUtils.isEmpty(list)){
closeTask(taskId,tokenDto.getUserId(), ImportTaskConstants.PROCESS_STATUS_FINISHED_FAIL,"");
return;
}
CustomerStaffInfoCacheResult staffInfo = CustomerStaffRedis.getStaffInfo(tokenDto.getCustomerId(), tokenDto.getUserId());
if (null == staffInfo){
throw new EpmetException("未查询到工作人员信息"+tokenDto.getUserId());
}
AgencyInfoCache agencyInfo = CustomerOrgRedis.getAgencyInfo(staffInfo.getAgencyId());
if (null == agencyInfo){
throw new EpmetException("未查询到组织信息"+staffInfo.getAgencyId());
}
// 获取所有居民信息
IcResiUserPageFormDTO formDTO = new IcResiUserPageFormDTO();
formDTO.setCustomerId(tokenDto.getCustomerId());
formDTO.setStaffId(tokenDto.getUserId());
formDTO.setListType("resi");
formDTO.setConditions(new ArrayList<>());
// 获取居民信息
CustomerStaffInfoCacheResult staffInfoCache = CustomerStaffRedis.getStaffInfo(tokenDto.getCustomerId(), tokenDto.getUserId());
List<IcResiUserDTO> userList = icResiUserDao.getImportUserList(tokenDto.getCustomerId(),staffInfoCache.getAgencyId());
// 获取证件号List
List<String> idCardList = userList.stream().map(IcResiUserDTO::getIdCard).collect(Collectors.toList());
// 获取已存在福利人员
List<String> welfareList = baseDao.getAllWelfareIdCard(tokenDto.getCustomerId());
for (int i = 0; i < list.size(); i++) {
list.get(i).setNum(i+1);
if (StringUtils.isBlank(list.get(i).getIdCard()) && !list.get(i).getAddStatus()){
errorInfo.add(getErrorInfo(list.get(i), "证件号不能为空",i+1));
list.get(i).setAddStatus(true);
list.get(i).setIdCard("10110"); // 后面有逻辑用到了证件号,10110代表证件号为空
continue;
}
// 校验是否为居民
if (!idCardList.contains(list.get(i).getIdCard()) && !list.get(i).getAddStatus()){
errorInfo.add(getErrorInfo(list.get(i), "身份证号为【" + list.get(i).getIdCard() + "】的居民信息未找到,请确认该居民信息存在",i+1));
list.get(i).setAddStatus(true);
continue;
}else if(idCardList.contains(list.get(i).getIdCard()) && !list.get(i).getAddStatus()){
// 组装居民数据
for(IcResiUserDTO icResiUserDTO : userList){
if(list.get(i).getIdCard().equals(icResiUserDTO.getIdCard())){
list.get(i).setGender(icResiUserDTO.getGender());
list.get(i).setMobile(icResiUserDTO.getMobile());
list.get(i).setName(icResiUserDTO.getName());
list.get(i).setUserId(icResiUserDTO.getId());
list.get(i).setGridId(icResiUserDTO.getGridId());
break;
}
}
list.get(i).setJoinDate(sdf.format(new Date()));
}
// 校验数据库是否存在该福利人员
if (welfareList.contains(list.get(i).getIdCard()) && !list.get(i).getAddStatus()){
errorInfo.add(getErrorInfo(list.get(i), "该福利人员已存在",i+1));
list.get(i).setAddStatus(true);
continue;
}
}
if (list.size() > errorInfo.size()){
Map<String, Long> groupByIdCard = list.stream().collect(Collectors.groupingBy(ChangeWelfareImportExcel::getIdCard, Collectors.counting()));
groupByIdCard.forEach((idCard,count) -> {
if (!"10110".equals(idCard) && Integer.valueOf(count.toString()).compareTo(1) != 0){
for (ChangeWelfareImportExcel i : list) {
if (idCard.equals(i.getIdCard()) && !i.getAddStatus()){
errorInfo.add(getErrorInfo(i,"数据重复",i.getNum()));
i.setAddStatus(true);
}
}
}
});
}
Map<Boolean, List<ChangeWelfareImportExcel>> groupByStatus = list.stream().collect(Collectors.groupingBy(ChangeWelfareImportExcel::getAddStatus));
List<ChangeWelfareImportExcel> needInsert = groupByStatus.get(false);
if (CollectionUtils.isNotEmpty(needInsert)){
List<ChangeWelfareEntity> entities = ConvertUtils.sourceToTarget(needInsert, ChangeWelfareEntity.class);
entities.forEach(e -> {
// 设置客户ID
e.setCustomerId(tokenDto.getCustomerId());
});
insertBatch(entities);
}
if (CollectionUtils.isNotEmpty(errorInfo)){
String url = importOssUpload(errorInfo, ChangeWelfareErrorExcel.class);
closeTask(taskId,tokenDto.getUserId(), ImportTaskConstants.PROCESS_STATUS_FINISHED_FAIL,url);
}else {
closeTask(taskId,tokenDto.getUserId(),ImportTaskConstants.PROCESS_STATUS_FINISHED_SUCCESS,"");
}
}catch (Exception e){
log.error(e.getMessage());
closeTask(taskId,tokenDto.getUserId(),ImportTaskConstants.PROCESS_STATUS_FINISHED_FAIL,"");
}
}
/**
* Desc: 关闭任务
* @param taskId
* @param userId
* @param status
* @param url
* @author wgf
* @date 2022/11/28 09:05
*/
public void closeTask(String taskId,String userId,String status,String url){
ImportTaskCommonFormDTO input = new ImportTaskCommonFormDTO();
input.setOperatorId(userId);
input.setTaskId(taskId);
input.setProcessStatus(status);
input.setResultDescFilePath(url);
commonServiceOpenFeignClient.finishImportTask(input);
}
/**
* Desc: 构造错误信息
* @param dto
* @param info
* @param num
* @author wgf
* @date 2022/11/28 17:17
*/
public ChangeWelfareErrorExcel getErrorInfo(ChangeWelfareImportExcel dto, String info, Integer num){
ChangeWelfareErrorExcel result = ConvertUtils.sourceToTarget(dto, ChangeWelfareErrorExcel.class);
result.setErrorMsg(info);
result.setNum(num);
return result;
}
/**
* Desc: 文件上传并返回url
* @param errorRows
* @param tClass
* @author wgf
* @date 2022/11/28 17:17
*/
public <T> String importOssUpload(Collection<?> errorRows, Class<T> tClass) throws IOException {
Workbook workbook = ExcelExportUtil.exportExcel(new ExportParams("导入失败的数据列表","导入失败的数据列表"),
tClass, errorRows);
// 文件名
String resultDescFileName = UUID.randomUUID().toString().concat(".xls");
FileItemFactory factory = new DiskFileItemFactory(16, null);
FileItem fileItem = factory.createItem("file", ContentType.APPLICATION_OCTET_STREAM.toString(), true, resultDescFileName);
OutputStream os = fileItem.getOutputStream();
Result<UploadImgResultDTO> uploadResult = null;
try {
workbook.write(os);
uploadResult = ossFeignClient.uploadImportTaskDescFile(new CommonsMultipartFile(fileItem));
} catch (Exception e) {
String errormsg = ExceptionUtils.getErrorStackTrace(e);
log.error("上传错误描述文件:{}", errormsg);
} finally {
try {
os.close();
} catch (IOException e) {
String errormsg = ExceptionUtils.getErrorStackTrace(e);
log.error("上传错误描述文件关闭输出流:{}", errormsg);
}
try {
fileItem.delete();
} catch (Exception e) {
String errormsg = ExceptionUtils.getErrorStackTrace(e);
log.error("上传错误描述文件删除临时文件:{}", errormsg);
}
}
if (uploadResult == null || !uploadResult.success()) {
log.error("调用OSS上传结果描述文件失败");
return null;
}
return uploadResult.getData().getUrl();
}
}

BIN
epmet-user/epmet-user-server/src/main/resources/excel/pli_change_welfare.xlsx

Binary file not shown.

8
epmet-user/epmet-user-server/src/main/resources/mapper/ChangeWelfareDao.xml

@ -90,6 +90,14 @@
AND ID_CARD = #{idCard}
</if>
</update>
<select id="getAllWelfareIdCard" resultType="java.lang.String">
select
ID_CARD
from pli_change_welfare
where CUSTOMER_ID=#{customerId}
and del_flag='0'
</select>
</mapper>

4
epmet-user/epmet-user-server/src/main/resources/mapper/IcResiUserDao.xml

@ -1483,5 +1483,9 @@
AND b.id is null
order by a.pids ASC, a.created_time DESC
</select>
<select id="getImportUserList" resultType="com.epmet.dto.IcResiUserDTO">
select * from ic_resi_user where pids like concat('%',#{agencyId},'%') and status='0' and customer_id=#{customerId}
</select>
</mapper>

Loading…
Cancel
Save