diff --git a/epmet-module/gov-org/gov-org-client/src/main/java/com/epmet/dto/result/CurrentUserCommunityInfoResultDTO.java b/epmet-module/gov-org/gov-org-client/src/main/java/com/epmet/dto/result/CurrentUserCommunityInfoResultDTO.java new file mode 100644 index 0000000000..3b82e5b77c --- /dev/null +++ b/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; + + +} + diff --git a/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/controller/CustomerAgencyController.java b/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/controller/CustomerAgencyController.java index e9fb4e56ef..ba94cc12ab 100644 --- a/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/controller/CustomerAgencyController.java +++ b/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 + * @Author wgf + * @Description 获取当前登录人的所属社区 + * @Date 2022/11/30 22:41 + **/ + @PostMapping("getCurrentUserCommunityInfo") + public Result> getCurrentUserCommunityInfo(@LoginUser TokenDto tokenDTO) { + return customerAgencyService.getCurrentUserCommunityInfo(tokenDTO); + } + } diff --git a/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/dao/CustomerAgencyDao.java b/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/dao/CustomerAgencyDao.java index fb1fc77855..e2fbd3162a 100644 --- a/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/dao/CustomerAgencyDao.java +++ b/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/dao/CustomerAgencyDao.java @@ -398,5 +398,9 @@ public interface CustomerAgencyDao extends BaseDao { List getUsingCommunityList(@Param("customerId") String customerId, @Param("agencyId") String agencyId, @Param("agencyOrgIdPath") String agencyOrgIdPath, @Param("endDate") Date endDate); List getCommunitysByOrgIdPath(@Param("customerId") String customerId, @Param("orgId") String orgId, @Param("orgIdPath") String orgIdPath); + + List getCurrentUserCommunityInfo(@Param("customerId") String customerId,@Param("staffAgencyId")String staffAgencyId); + + } diff --git a/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/service/CustomerAgencyService.java b/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/service/CustomerAgencyService.java index e71189e0ad..f9ac7182e7 100644 --- a/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/service/CustomerAgencyService.java +++ b/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 * @Date 2022/6/21 22:41 **/ Result getCommunityInfoByUserId(String userId); + + /** + * @param tokenDTO + * @return com.epmet.commons.tools.utils.Result + * @Author wgf + * @Description 获取当前登录人的所属社区 + * @Date 2022/11/30 22:41 + **/ + Result> getCurrentUserCommunityInfo(TokenDto tokenDTO); } diff --git a/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/service/impl/CustomerAgencyServiceImpl.java b/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/service/impl/CustomerAgencyServiceImpl.java index 760f9690ad..a6702963c4 100644 --- a/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/service/impl/CustomerAgencyServiceImpl.java +++ b/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().ok(communityInfoResultDTO); } + @Override + public Result> 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 list = baseDao.getCurrentUserCommunityInfo(tokenDTO.getCustomerId(),staffInfoCacheResult.getAgencyId()); + + return new Result>().ok(list); + } + } diff --git a/epmet-module/gov-org/gov-org-server/src/main/resources/mapper/CustomerAgencyDao.xml b/epmet-module/gov-org/gov-org-server/src/main/resources/mapper/CustomerAgencyDao.xml index d221f07b12..f46e9f038d 100644 --- a/epmet-module/gov-org/gov-org-server/src/main/resources/mapper/CustomerAgencyDao.xml +++ b/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 + diff --git a/epmet-user/epmet-user-server/src/main/java/com/epmet/controller/ChangeWelfareController.java b/epmet-user/epmet-user-server/src/main/java/com/epmet/controller/ChangeWelfareController.java index c1cac171ec..671c4c8681 100644 --- a/epmet-user/epmet-user-server/src/main/java/com/epmet/controller/ChangeWelfareController.java +++ b/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> page(@RequestParam Map 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 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); + } + } diff --git a/epmet-user/epmet-user-server/src/main/java/com/epmet/dao/ChangeWelfareDao.java b/epmet-user/epmet-user-server/src/main/java/com/epmet/dao/ChangeWelfareDao.java index c7f64d3231..14cc96ce66 100644 --- a/epmet-user/epmet-user-server/src/main/java/com/epmet/dao/ChangeWelfareDao.java +++ b/epmet-user/epmet-user-server/src/main/java/com/epmet/dao/ChangeWelfareDao.java @@ -45,4 +45,6 @@ public interface ChangeWelfareDao extends BaseDao { * @return com.epmet.commons.tools.utils.Result */ void removeWelfare(ChangeWelfareDTO dto); + + List getAllWelfareIdCard(@Param("customerId") String customerId); } diff --git a/epmet-user/epmet-user-server/src/main/java/com/epmet/dao/IcResiUserDao.java b/epmet-user/epmet-user-server/src/main/java/com/epmet/dao/IcResiUserDao.java index 23830a2e4c..e6845fefd3 100644 --- a/epmet-user/epmet-user-server/src/main/java/com/epmet/dao/IcResiUserDao.java +++ b/epmet-user/epmet-user-server/src/main/java/com/epmet/dao/IcResiUserDao.java @@ -444,4 +444,7 @@ public interface IcResiUserDao extends BaseDao { List getResiUserList(ComparisonFormDTO formDTO); List getUserByRenHu(RHZKStatisticsFormDTO formDTO); + + List getImportUserList(@Param("customerId")String customerId,@Param("agencyId")String agencyId); + } diff --git a/epmet-user/epmet-user-server/src/main/java/com/epmet/excel/ChangeWelfareImportExcel.java b/epmet-user/epmet-user-server/src/main/java/com/epmet/excel/ChangeWelfareImportExcel.java new file mode 100644 index 0000000000..992be96b4a --- /dev/null +++ b/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; + + +} diff --git a/epmet-user/epmet-user-server/src/main/java/com/epmet/excel/error/ChangeWelfareErrorExcel.java b/epmet-user/epmet-user-server/src/main/java/com/epmet/excel/error/ChangeWelfareErrorExcel.java new file mode 100644 index 0000000000..edadf94704 --- /dev/null +++ b/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; + + +} diff --git a/epmet-user/epmet-user-server/src/main/java/com/epmet/service/ChangeWelfareService.java b/epmet-user/epmet-user-server/src/main/java/com/epmet/service/ChangeWelfareService.java index ab13abb470..184cfd9c9a 100644 --- a/epmet-user/epmet-user-server/src/main/java/com/epmet/service/ChangeWelfareService.java +++ b/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 { * @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); } diff --git a/epmet-user/epmet-user-server/src/main/java/com/epmet/service/impl/ChangeWelfareServiceImpl.java b/epmet-user/epmet-user-server/src/main/java/com/epmet/service/impl/ChangeWelfareServiceImpl.java index 87cf889ab7..c7582ec8ef 100644 --- a/epmet-user/epmet-user-server/src/main/java/com/epmet/service/impl/ChangeWelfareServiceImpl.java +++ b/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 implements ChangeWelfareService { @Autowired @@ -46,6 +82,18 @@ public class ChangeWelfareServiceImpl extends BaseServiceImpl page(Map params) { params.put("customerId", loginUserUtil.getLoginUserCustomerId()); @@ -163,4 +211,199 @@ public class ChangeWelfareServiceImpl extends BaseServiceImpl errorInfo = new ArrayList<>(); + SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); + + try { + List 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 userList = icResiUserDao.getImportUserList(tokenDto.getCustomerId(),staffInfoCache.getAgencyId()); + // 获取证件号List + List idCardList = userList.stream().map(IcResiUserDTO::getIdCard).collect(Collectors.toList()); + + // 获取已存在福利人员 + List 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 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> groupByStatus = list.stream().collect(Collectors.groupingBy(ChangeWelfareImportExcel::getAddStatus)); + List needInsert = groupByStatus.get(false); + if (CollectionUtils.isNotEmpty(needInsert)){ + List 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 String importOssUpload(Collection errorRows, Class 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 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(); + } + } diff --git a/epmet-user/epmet-user-server/src/main/resources/excel/pli_change_welfare.xlsx b/epmet-user/epmet-user-server/src/main/resources/excel/pli_change_welfare.xlsx new file mode 100644 index 0000000000..a9aa1b3e6a Binary files /dev/null and b/epmet-user/epmet-user-server/src/main/resources/excel/pli_change_welfare.xlsx differ diff --git a/epmet-user/epmet-user-server/src/main/resources/mapper/ChangeWelfareDao.xml b/epmet-user/epmet-user-server/src/main/resources/mapper/ChangeWelfareDao.xml index 51524b85c6..518f868cac 100644 --- a/epmet-user/epmet-user-server/src/main/resources/mapper/ChangeWelfareDao.xml +++ b/epmet-user/epmet-user-server/src/main/resources/mapper/ChangeWelfareDao.xml @@ -90,6 +90,14 @@ AND ID_CARD = #{idCard} + diff --git a/epmet-user/epmet-user-server/src/main/resources/mapper/IcResiUserDao.xml b/epmet-user/epmet-user-server/src/main/resources/mapper/IcResiUserDao.xml index 2383d57e49..ab9c03c402 100644 --- a/epmet-user/epmet-user-server/src/main/resources/mapper/IcResiUserDao.xml +++ b/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 +