diff --git a/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/security/user/LoginUserUtil.java b/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/security/user/LoginUserUtil.java index 70307f6551..ce92400ae0 100644 --- a/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/security/user/LoginUserUtil.java +++ b/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/security/user/LoginUserUtil.java @@ -1,11 +1,9 @@ package com.epmet.commons.tools.security.user; import com.epmet.commons.tools.constant.AppClientConstant; -import com.epmet.commons.tools.utils.HttpContextUtils; -import org.apache.commons.lang3.StringUtils; +import com.epmet.commons.tools.utils.EpmetRequestHolder; import org.springframework.stereotype.Component; -import javax.servlet.http.HttpServletRequest; import java.util.List; /** @@ -14,24 +12,21 @@ import java.util.List; @Component public class LoginUserUtil { - //@Autowired - //private - /** * 查询登录用户的id * @return */ public String getLoginUserId() { - HttpServletRequest request = HttpContextUtils.getHttpServletRequest(); - if (request == null) { - return null; - } - - String userId = request.getHeader(AppClientConstant.USER_ID); - if (StringUtils.isBlank(userId)) { - return null; - } - return userId; + //HttpServletRequest request = HttpContextUtils.getHttpServletRequest(); + //if (request == null) { + // return null; + //} + // + //String userId = request.getHeader(AppClientConstant.USER_ID); + //if (StringUtils.isBlank(userId)) { + // return null; + //} + return EpmetRequestHolder.getHeader(AppClientConstant.USER_ID); } /** @@ -39,16 +34,16 @@ public class LoginUserUtil { * @return */ public String getLoginUserApp() { - HttpServletRequest request = HttpContextUtils.getHttpServletRequest(); - if (request == null) { - return null; - } - - String app = request.getHeader(AppClientConstant.APP); - if (StringUtils.isBlank(app)) { - return null; - } - return app; + //HttpServletRequest request = HttpContextUtils.getHttpServletRequest(); + //if (request == null) { + // return null; + //} + // + //String app = request.getHeader(AppClientConstant.APP); + //if (StringUtils.isBlank(app)) { + // return null; + //} + return EpmetRequestHolder.getHeader(AppClientConstant.APP); } /** @@ -56,16 +51,16 @@ public class LoginUserUtil { * @return */ public String getLoginUserClient() { - HttpServletRequest request = HttpContextUtils.getHttpServletRequest(); - if (request == null) { - return null; - } - - String client = request.getHeader(AppClientConstant.CLIENT); - if (StringUtils.isBlank(client)) { - return null; - } - return client; + //HttpServletRequest request = HttpContextUtils.getHttpServletRequest(); + //if (request == null) { + // return null; + //} + // + //String client = request.getHeader(AppClientConstant.CLIENT); + //if (StringUtils.isBlank(client)) { + // return null; + //} + return EpmetRequestHolder.getHeader(AppClientConstant.CLIENT); } /** @@ -73,16 +68,16 @@ public class LoginUserUtil { * @return */ public String getLoginUserCustomerId() { - HttpServletRequest request = HttpContextUtils.getHttpServletRequest(); - if (request == null) { - return null; - } - - String client = request.getHeader(AppClientConstant.CUSTOMER_ID); - if (StringUtils.isBlank(client)) { - return null; - } - return client; + //HttpServletRequest request = HttpContextUtils.getHttpServletRequest(); + //if (request == null) { + // return null; + //} + // + //String client = request.getHeader(AppClientConstant.CUSTOMER_ID); + //if (StringUtils.isBlank(client)) { + // return null; + //} + return EpmetRequestHolder.getHeader(AppClientConstant.CUSTOMER_ID); } /** diff --git a/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/utils/FileUtils.java b/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/utils/FileUtils.java index b8a12015bb..00784bc7db 100644 --- a/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/utils/FileUtils.java +++ b/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/utils/FileUtils.java @@ -15,6 +15,47 @@ import java.nio.file.Paths; @Slf4j public class FileUtils { + /** + * epmet文件根路径 + */ + private static Path epmetFilePath; + + static { + // linux || mac + epmetFilePath = Paths.get("/opt/epmet_files"); + // windows + } + + /** + * 获取在epmetfiles下的文件路径,输入相对路径即可获取完整绝对路径 + * @param pathParts 目录片段,可以是文件夹或者文件名 + * @return + */ + public static Path getPathUnderEpmetFilesDir(String... pathParts) { + Path path; + if (pathParts == null || pathParts.length == 0) { + path = epmetFilePath.resolve("temp"); + } else { + path = Paths.get(epmetFilePath.toString(), pathParts); + } + return path; + } + + /** + * 创建并且返回epmet_files下的文件夹 + * @param dirParts 文件夹列表 + * @return + * @throws IOException + */ + public static Path getAndCreateDirUnderEpmetFilesDir(String... dirParts) throws IOException { + Path pathUnderEpmetFilesDir = getPathUnderEpmetFilesDir(dirParts); + if (Files.notExists(pathUnderEpmetFilesDir)) { + Files.createDirectories(pathUnderEpmetFilesDir); + } + + return pathUnderEpmetFilesDir; + } + /** * 创建临时文件 * diff --git a/epmet-module/epmet-common-service/common-service-client/src/main/java/com/epmet/constants/ImportTaskConstants.java b/epmet-module/epmet-common-service/common-service-client/src/main/java/com/epmet/constants/ImportTaskConstants.java index 6212a35cb6..8e7ef7eedb 100644 --- a/epmet-module/epmet-common-service/common-service-client/src/main/java/com/epmet/constants/ImportTaskConstants.java +++ b/epmet-module/epmet-common-service/common-service-client/src/main/java/com/epmet/constants/ImportTaskConstants.java @@ -15,6 +15,10 @@ public interface ImportTaskConstants { String BIZ_TYPE_COMMUNITY_SELF_ORG = "community_self_org"; String BIZ_TYPE_PARTY_UNIT = "party_unit"; String BIZ_TYPE_PARTY_ACTIVITY = "party_activity"; + /** + * 核酸检测 + */ + String BIZ_TYPE_IC_NAT = "ic_nat"; /** * 处理状态:处理中 diff --git a/epmet-module/epmet-common-service/common-service-client/src/main/java/com/epmet/dto/form/ImportTaskCommonFormDTO.java b/epmet-module/epmet-common-service/common-service-client/src/main/java/com/epmet/dto/form/ImportTaskCommonFormDTO.java index 9eea1fe6c2..08fc2f0995 100644 --- a/epmet-module/epmet-common-service/common-service-client/src/main/java/com/epmet/dto/form/ImportTaskCommonFormDTO.java +++ b/epmet-module/epmet-common-service/common-service-client/src/main/java/com/epmet/dto/form/ImportTaskCommonFormDTO.java @@ -2,10 +2,14 @@ package com.epmet.dto.form; import com.epmet.commons.tools.dto.form.PageFormDTO; import com.epmet.commons.tools.validator.group.QueryGroup; +import lombok.AllArgsConstructor; import lombok.Data; +import lombok.NoArgsConstructor; import javax.validation.constraints.NotBlank; +@AllArgsConstructor +@NoArgsConstructor @Data public class ImportTaskCommonFormDTO extends PageFormDTO { diff --git a/epmet-user/epmet-user-client/src/main/java/com/epmet/dto/form/CancelAttentionFormDTO.java b/epmet-user/epmet-user-client/src/main/java/com/epmet/dto/form/CancelAttentionFormDTO.java deleted file mode 100644 index bd9e48906c..0000000000 --- a/epmet-user/epmet-user-client/src/main/java/com/epmet/dto/form/CancelAttentionFormDTO.java +++ /dev/null @@ -1,33 +0,0 @@ -package com.epmet.dto.form; - -import lombok.Data; - -import javax.validation.constraints.NotBlank; -import javax.validation.constraints.NotNull; -import java.io.Serializable; -import java.util.List; - -/** - * @Author zxc - * @DateTime 2022/3/28 13:47 - * @DESC - */ -@Data -public class CancelAttentionFormDTO implements Serializable { - - private static final long serialVersionUID = 2252387281427013057L; - - public interface CancelAttentionForm{} - - /** - * 身份证 - */ - @NotBlank(message = "idCard不能为空",groups = CancelAttentionForm.class) - private String idCard; - - /** - * 关注类型,核酸检测:2,疫苗接种:1 - */ - @NotNull(message = "attentionType不能为空",groups = CancelAttentionForm.class) - private Integer attentionType ; -} diff --git a/epmet-user/epmet-user-client/src/main/java/com/epmet/dto/form/CancelAttentionPackageFormDTO.java b/epmet-user/epmet-user-client/src/main/java/com/epmet/dto/form/CancelAttentionPackageFormDTO.java index db47f3520a..f0c8f9a900 100644 --- a/epmet-user/epmet-user-client/src/main/java/com/epmet/dto/form/CancelAttentionPackageFormDTO.java +++ b/epmet-user/epmet-user-client/src/main/java/com/epmet/dto/form/CancelAttentionPackageFormDTO.java @@ -3,6 +3,8 @@ package com.epmet.dto.form; import lombok.Data; import javax.validation.Valid; +import javax.validation.constraints.NotBlank; +import javax.validation.constraints.NotNull; import java.io.Serializable; import java.util.List; @@ -15,6 +17,19 @@ import java.util.List; public class CancelAttentionPackageFormDTO implements Serializable { private static final long serialVersionUID = 2198470055930997870L; - @Valid - private List list; + + public interface CancelAttentionPackageForm{} + + + /** + * 身份证 + */ + @NotNull(message = "idCard不能为空",groups = CancelAttentionPackageForm.class) + private List idCards; + + /** + * 关注类型,核酸检测:2,疫苗接种:1 + */ + @NotNull(message = "attentionType不能为空",groups = CancelAttentionPackageForm.class) + private Integer attentionType ; } diff --git a/epmet-user/epmet-user-client/src/main/java/com/epmet/dto/form/LoginUserDetailsFormDTO.java b/epmet-user/epmet-user-client/src/main/java/com/epmet/dto/form/LoginUserDetailsFormDTO.java index 7c1af89a00..76e5c31d4d 100644 --- a/epmet-user/epmet-user-client/src/main/java/com/epmet/dto/form/LoginUserDetailsFormDTO.java +++ b/epmet-user/epmet-user-client/src/main/java/com/epmet/dto/form/LoginUserDetailsFormDTO.java @@ -1,8 +1,12 @@ package com.epmet.dto.form; +import lombok.AllArgsConstructor; import lombok.Data; +import lombok.NoArgsConstructor; @Data +@AllArgsConstructor +@NoArgsConstructor public class LoginUserDetailsFormDTO { private String app; private String client; diff --git a/epmet-user/epmet-user-client/src/main/java/com/epmet/dto/result/NatListResultDTO.java b/epmet-user/epmet-user-client/src/main/java/com/epmet/dto/result/NatListResultDTO.java index 7a62c359a8..a65563bb5b 100644 --- a/epmet-user/epmet-user-client/src/main/java/com/epmet/dto/result/NatListResultDTO.java +++ b/epmet-user/epmet-user-client/src/main/java/com/epmet/dto/result/NatListResultDTO.java @@ -3,6 +3,8 @@ package com.epmet.dto.result; import com.alibaba.excel.annotation.ExcelIgnore; import com.alibaba.excel.annotation.ExcelProperty; import com.alibaba.excel.annotation.write.style.ColumnWidth; +import com.alibaba.excel.annotation.write.style.HeadStyle; +import com.alibaba.excel.enums.poi.FillPatternTypeEnum; import com.fasterxml.jackson.annotation.JsonFormat; import lombok.Data; @@ -13,6 +15,7 @@ import java.util.Date; * @Description 核酸检测-我的上报记录 * @Author sun */ +@HeadStyle(fillPatternType = FillPatternTypeEnum.SOLID_FOREGROUND, fillForegroundColor = 44) @Data public class NatListResultDTO implements Serializable { private static final long serialVersionUID = 1L; diff --git a/epmet-user/epmet-user-server/deploy/docker-compose-dev.yml b/epmet-user/epmet-user-server/deploy/docker-compose-dev.yml index e1e35559ff..7d9ac90396 100644 --- a/epmet-user/epmet-user-server/deploy/docker-compose-dev.yml +++ b/epmet-user/epmet-user-server/deploy/docker-compose-dev.yml @@ -8,6 +8,7 @@ services: network_mode: host # 不会创建新的网络 volumes: - "/opt/epmet-cloud-logs/dev:/logs" + - "/opt/epmet_files/:/opt/epmet_files" environment: RUN_INSTRUCT: "java -Xms256m -Xmx512m -jar ./epmet-user.jar" restart: "unless-stopped" diff --git a/epmet-user/epmet-user-server/deploy/docker-compose-prod.yml b/epmet-user/epmet-user-server/deploy/docker-compose-prod.yml index bc63091248..1fbe59593f 100644 --- a/epmet-user/epmet-user-server/deploy/docker-compose-prod.yml +++ b/epmet-user/epmet-user-server/deploy/docker-compose-prod.yml @@ -8,6 +8,7 @@ services: network_mode: host # 不会创建新的网络 volumes: - "/opt/epmet-cloud-logs/prod:/logs" + - "/opt/epmet_files/:/opt/epmet_files" environment: RUN_INSTRUCT: "java -Xms256m -Xmx1024m -jar ./epmet-user.jar" restart: "unless-stopped" diff --git a/epmet-user/epmet-user-server/deploy/docker-compose-test.yml b/epmet-user/epmet-user-server/deploy/docker-compose-test.yml index 5537d14081..c880913294 100644 --- a/epmet-user/epmet-user-server/deploy/docker-compose-test.yml +++ b/epmet-user/epmet-user-server/deploy/docker-compose-test.yml @@ -8,6 +8,7 @@ services: network_mode: host # 不会创建新的网络 volumes: - "/opt/epmet-cloud-logs/test:/logs" + - "/opt/epmet_files/:/opt/epmet_files" environment: RUN_INSTRUCT: "java -Xms32m -Xmx512m -jar ./epmet-user.jar" restart: "unless-stopped" diff --git a/epmet-user/epmet-user-server/src/main/java/com/epmet/controller/IcEpidemicSpecialAttentionController.java b/epmet-user/epmet-user-server/src/main/java/com/epmet/controller/IcEpidemicSpecialAttentionController.java index f7325eca20..42fcc20c23 100644 --- a/epmet-user/epmet-user-server/src/main/java/com/epmet/controller/IcEpidemicSpecialAttentionController.java +++ b/epmet-user/epmet-user-server/src/main/java/com/epmet/controller/IcEpidemicSpecialAttentionController.java @@ -86,7 +86,7 @@ public class IcEpidemicSpecialAttentionController { */ @PostMapping("cancel-attention") public Result cancelAttention(@RequestBody CancelAttentionPackageFormDTO formDTO){ - ValidatorUtils.validateEntity(formDTO, CancelAttentionFormDTO.CancelAttentionForm.class); + ValidatorUtils.validateEntity(formDTO, CancelAttentionPackageFormDTO.CancelAttentionPackageForm.class); icEpidemicSpecialAttentionService.cancelAttention(formDTO); return new Result(); } diff --git a/epmet-user/epmet-user-server/src/main/java/com/epmet/controller/IcNatController.java b/epmet-user/epmet-user-server/src/main/java/com/epmet/controller/IcNatController.java index a52e4e2a59..fd3d23f2f6 100644 --- a/epmet-user/epmet-user-server/src/main/java/com/epmet/controller/IcNatController.java +++ b/epmet-user/epmet-user-server/src/main/java/com/epmet/controller/IcNatController.java @@ -5,31 +5,54 @@ import com.alibaba.excel.ExcelWriter; import com.alibaba.excel.write.metadata.WriteSheet; import com.epmet.commons.tools.annotation.LoginUser; import com.epmet.commons.tools.aop.NoRepeatSubmit; +import com.epmet.commons.tools.constant.AppClientConstant; +import com.epmet.commons.tools.constant.ServiceConstant; +import com.epmet.commons.tools.exception.EpmetErrorCode; +import com.epmet.commons.tools.exception.EpmetException; +import com.epmet.commons.tools.exception.ExceptionUtils; +import com.epmet.commons.tools.feign.ResultDataResolver; import com.epmet.commons.tools.constant.NumConstant; import com.epmet.commons.tools.page.PageData; import com.epmet.commons.tools.security.dto.TokenDto; +import com.epmet.commons.tools.utils.EpmetRequestHolder; +import com.epmet.commons.tools.utils.FileUtils; import com.epmet.commons.tools.utils.ExcelUtils; import com.epmet.commons.tools.utils.Result; 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.IcNatDTO; import com.epmet.dto.form.AddIcNatFormDTO; +import com.epmet.dto.form.ImportTaskCommonFormDTO; import com.epmet.dto.form.MyNatListFormDTO; +import com.epmet.dto.result.ImportTaskCommonResultDTO; import com.epmet.dto.result.MyNatListResultDTO; import com.epmet.dto.result.NatListResultDTO; +import com.epmet.feign.EpmetCommonServiceOpenFeignClient; import com.epmet.service.IcNatService; import lombok.extern.slf4j.Slf4j; +import org.apache.commons.io.IOUtils; +import lombok.extern.slf4j.Slf4j; import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.io.IOUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpHeaders; import org.springframework.web.bind.annotation.*; +import org.springframework.web.multipart.MultipartFile; +import java.io.*; +import java.nio.file.Files; +import java.nio.file.Path; import javax.servlet.ServletOutputStream; import javax.servlet.http.HttpServletResponse; import java.io.IOException; import java.io.InputStream; import java.net.URLEncoder; import java.util.List; +import java.util.Map; +import java.util.UUID; /** @@ -41,11 +64,14 @@ import java.util.List; @Slf4j @RestController @RequestMapping("icNat") -public class IcNatController { +public class IcNatController implements ResultDataResolver { @Autowired private IcNatService icNucleinService; + @Autowired + private EpmetCommonServiceOpenFeignClient commonServiceOpenFeignClient; + /** * @Author sun @@ -133,6 +159,60 @@ public class IcNatController { return new Result(); } + /** + * 导入excel + * @return + */ + @PostMapping("importExcel") + public Result importExcel(MultipartFile file) { + String userId = EpmetRequestHolder.getHeader(AppClientConstant.USER_ID); + + // 1.暂存文件 + String originalFilename = file.getOriginalFilename(); + String extName = originalFilename.substring(originalFilename.lastIndexOf(".")); + + Path fileSavePath; + try { + Path importPath = FileUtils.getAndCreateDirUnderEpmetFilesDir("ic_nat", "import"); + fileSavePath = importPath.resolve(UUID.randomUUID().toString().concat(extName)); + } catch (IOException e) { + String errorMsg = ExceptionUtils.getErrorStackTrace(e); + log.error("【核酸检测导入】创建临时存储文件失败:{}", errorMsg); + throw new EpmetException(EpmetErrorCode.EPMET_COMMON_OPERATION_FAIL.getCode(), "文件上传失败", "文件上传失败"); + } + + InputStream is = null; + FileOutputStream os = null; + + try { + is = file.getInputStream(); + os = new FileOutputStream(fileSavePath.toString()); + IOUtils.copy(is, os); + } catch (Exception e) { + e.printStackTrace(); + } finally { + org.apache.poi.util.IOUtils.closeQuietly(is); + org.apache.poi.util.IOUtils.closeQuietly(os); + } + + // 2.生成导入任务记录 + ImportTaskCommonFormDTO importTaskForm = new ImportTaskCommonFormDTO(); + importTaskForm.setOperatorId(userId); + importTaskForm.setBizType(ImportTaskConstants.BIZ_TYPE_IC_NAT); + importTaskForm.setOriginFileName(originalFilename); + + ImportTaskCommonResultDTO rstData = getResultDataOrThrowsException(commonServiceOpenFeignClient.createImportTask(importTaskForm), + ServiceConstant.EPMET_COMMON_SERVICE, + EpmetErrorCode.EPMET_COMMON_OPERATION_FAIL.getCode(), + "excel导入核酸检测信息错误", + "导入居民核酸检测信息失败"); + + // 3.执行导入 + icNucleinService.execAsyncExcelImport(fileSavePath, rstData.getTaskId()); + + return new Result(); + } + /** * @Author sun * @Description 【核酸】核酸检测信息下载模板 @@ -179,7 +259,7 @@ public class IcNatController { // 这里 需要指定写用哪个class去写 String fileName = "核酸检测信息.xlsx"; excelWriter = EasyExcel.write(ExcelUtils.getOutputStreamForExcel(fileName, response),NatListResultDTO.class).build(); - WriteSheet writeSheet = EasyExcel.writerSheet().build(); + WriteSheet writeSheet = EasyExcel.writerSheet("Sheet1").build(); PageData data = null; do { data = icNucleinService.natList(formDTO); diff --git a/epmet-user/epmet-user-server/src/main/java/com/epmet/dao/IcEpidemicSpecialAttentionDao.java b/epmet-user/epmet-user-server/src/main/java/com/epmet/dao/IcEpidemicSpecialAttentionDao.java index cc1d3ba4a1..11b6b3ab09 100644 --- a/epmet-user/epmet-user-server/src/main/java/com/epmet/dao/IcEpidemicSpecialAttentionDao.java +++ b/epmet-user/epmet-user-server/src/main/java/com/epmet/dao/IcEpidemicSpecialAttentionDao.java @@ -5,6 +5,7 @@ import com.epmet.dto.form.VaccinationListFormDTO; import com.epmet.dto.result.VaccinationListResultDTO; import com.epmet.entity.IcEpidemicSpecialAttentionEntity; import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Param; import java.util.List; @@ -33,4 +34,22 @@ public interface IcEpidemicSpecialAttentionDao extends BaseDao natList(VaccinationListFormDTO formDTO); + /** + * Desc: 取消关注 + * @param list + * @param attentionType + * @author zxc + * @date 2022/3/28 16:59 + */ + void cancelAttention(@Param("list")List list,@Param("attentionType")Integer attentionType); + + /** + * Desc: 查询已经存在的关注 + * @param attentionType + * @param list + * @author zxc + * @date 2022/3/28 17:29 + */ + List getExistList(@Param("attentionType")Integer attentionType,@Param("list")List list); + } \ No newline at end of file diff --git a/epmet-user/epmet-user-server/src/main/java/com/epmet/entity/IcNatEntity.java b/epmet-user/epmet-user-server/src/main/java/com/epmet/entity/IcNatEntity.java index 84d875c391..1fee4076a4 100644 --- a/epmet-user/epmet-user-server/src/main/java/com/epmet/entity/IcNatEntity.java +++ b/epmet-user/epmet-user-server/src/main/java/com/epmet/entity/IcNatEntity.java @@ -1,5 +1,7 @@ package com.epmet.entity; +import com.baomidou.mybatisplus.annotation.FieldFill; +import com.baomidou.mybatisplus.annotation.TableField; import com.baomidou.mybatisplus.annotation.TableName; import com.epmet.commons.mybatis.entity.BaseEpmetEntity; import lombok.Data; @@ -24,6 +26,7 @@ public class IcNatEntity extends BaseEpmetEntity { /** * 客户Id CUSTOMER.id */ + @TableField(fill = FieldFill.INSERT) private String customerId; /** diff --git a/epmet-user/epmet-user-server/src/main/java/com/epmet/excel/data/IcNatImportExcelData.java b/epmet-user/epmet-user-server/src/main/java/com/epmet/excel/data/IcNatImportExcelData.java new file mode 100644 index 0000000000..6e8d252c1f --- /dev/null +++ b/epmet-user/epmet-user-server/src/main/java/com/epmet/excel/data/IcNatImportExcelData.java @@ -0,0 +1,61 @@ +package com.epmet.excel.data; + +import com.alibaba.excel.annotation.ExcelProperty; +import com.alibaba.excel.annotation.write.style.ColumnWidth; +import com.epmet.dto.form.AddIcNatFormDTO; +import lombok.Data; + +import javax.validation.constraints.NotBlank; +import javax.validation.constraints.NotNull; +import java.util.Date; + +/** + * 核酸检测信息导入excel数据 + */ +@Data +public class IcNatImportExcelData { + + @NotBlank(message = "姓名为必填项") + @ExcelProperty("姓名") + private String name; + + @NotBlank(message = "手机号为必填项") + @ExcelProperty("手机号") + private String mobile; + + @NotBlank(message = "身份证号为必填项") + @ExcelProperty("身份证号") + private String idCard; + + @NotNull(message = "检测时间为必填项") + @ExcelProperty("检测时间") + private Date natTime; + + @NotBlank(message = "检测地点为必填项") + @ExcelProperty("检测地点") + private String natAddress; + + @NotBlank(message = "检测结果为必填项") + @ExcelProperty("检测结果") + private String natResultZh; + + @Data + public static class ErrorRow { + + @ExcelProperty("姓名") + @ColumnWidth(20) + private String name; + + @ExcelProperty("手机号") + @ColumnWidth(20) + private String mobile; + + @ColumnWidth(20) + @ExcelProperty("身份证号") + private String idCard; + + @ColumnWidth(60) + @ExcelProperty("错误信息") + private String errorInfo; + } +} diff --git a/epmet-user/epmet-user-server/src/main/java/com/epmet/excel/handler/IcNatExcelImportListener.java b/epmet-user/epmet-user-server/src/main/java/com/epmet/excel/handler/IcNatExcelImportListener.java new file mode 100644 index 0000000000..f6c83e9440 --- /dev/null +++ b/epmet-user/epmet-user-server/src/main/java/com/epmet/excel/handler/IcNatExcelImportListener.java @@ -0,0 +1,126 @@ +package com.epmet.excel.handler; + +import com.alibaba.excel.context.AnalysisContext; +import com.alibaba.excel.read.listener.ReadListener; +import com.epmet.commons.tools.exception.ExceptionUtils; +import com.epmet.commons.tools.exception.ValidateException; +import com.epmet.commons.tools.utils.ConvertUtils; +import com.epmet.commons.tools.validator.ValidatorUtils; +import com.epmet.entity.IcNatEntity; +import com.epmet.excel.data.IcNatImportExcelData; +import com.epmet.service.impl.IcNatServiceImpl; +import lombok.extern.slf4j.Slf4j; +import org.apache.commons.lang3.StringUtils; + +import java.util.ArrayList; +import java.util.List; + +/** + * 核酸检测excel导入监听器 + */ +@Slf4j +public class IcNatExcelImportListener implements ReadListener { + + /** + * 最大条数阈值 + */ + public static final int MAX_THRESHOLD = 2; + + private String currentUserId; + /** + * 当前组织ID + */ + private String currentAgencyId; + + private String currentAgencyPids; + + /** + * 数据 + */ + private List datas = new ArrayList<>(); + + /** + * 错误项列表 + */ + private List errorRows = new ArrayList<>(); + + private IcNatServiceImpl icNatService; + + public IcNatExcelImportListener(String currentUserId, String currentAgencyId, String currentAgencyPids, IcNatServiceImpl icNatService) { + this.currentUserId = currentUserId; + this.currentAgencyId = currentAgencyId; + this.currentAgencyPids = currentAgencyPids; + this.icNatService = icNatService; + } + + @Override + public void invoke(IcNatImportExcelData data, AnalysisContext context) { + + try { + // 先校验数据 + ValidatorUtils.validateEntity(data); + + String natResult = "0"; + String natResultZh = data.getNatResultZh(); + if (StringUtils.isNotBlank(natResultZh)) { + natResult = natResultZh.equals("阴性") ? "0" : "1"; + } + + IcNatEntity icNatEntity = ConvertUtils.sourceToTarget(data, IcNatEntity.class); + icNatEntity.setAgencyId(currentAgencyId); + icNatEntity.setPids(currentAgencyPids); + icNatEntity.setUserId(currentUserId); + icNatEntity.setUserType("other"); + icNatEntity.setNatResult(natResult); + icNatEntity.setAttachmentType(""); + icNatEntity.setAttachmentUrl(""); + datas.add(icNatEntity); + + if (datas.size() == MAX_THRESHOLD) { + execPersist(); + } + } catch (Exception e) { + String errorMsg = null; + if (e instanceof ValidateException) { + errorMsg = ((ValidateException) e).getMsg(); + } else { + errorMsg = "未知错误"; + log.error("【核酸检测信息导入】出错:{}", ExceptionUtils.getErrorStackTrace(e)); + } + + IcNatImportExcelData.ErrorRow errorRow = new IcNatImportExcelData.ErrorRow(); + errorRow.setName(data.getName()); + errorRow.setMobile(data.getMobile()); + errorRow.setIdCard(data.getIdCard()); + errorRow.setErrorInfo(errorMsg); + errorRows.add(errorRow); + } + } + + @Override + public void doAfterAllAnalysed(AnalysisContext context) { + // 最后几条达不到阈值,这里必须再调用一次 + execPersist(); + } + + /** + * 执行持久化 + */ + private void execPersist() { + try { + if (datas != null && datas.size() > 0) { + icNatService.batchPersist(datas); + } + } finally { + datas.clear(); + } + } + + /** + * 获取错误行 + * @return + */ + public List getErrorRows() { + return errorRows; + } +} diff --git a/epmet-user/epmet-user-server/src/main/java/com/epmet/service/IcEpidemicSpecialAttentionService.java b/epmet-user/epmet-user-server/src/main/java/com/epmet/service/IcEpidemicSpecialAttentionService.java index 2ed2223152..3690df2640 100644 --- a/epmet-user/epmet-user-server/src/main/java/com/epmet/service/IcEpidemicSpecialAttentionService.java +++ b/epmet-user/epmet-user-server/src/main/java/com/epmet/service/IcEpidemicSpecialAttentionService.java @@ -3,7 +3,6 @@ package com.epmet.service; import com.epmet.commons.mybatis.service.BaseService; import com.epmet.commons.tools.page.PageData; import com.epmet.dto.IcEpidemicSpecialAttentionDTO; -import com.epmet.dto.form.CancelAttentionFormDTO; import com.epmet.dto.form.CancelAttentionPackageFormDTO; import com.epmet.dto.form.VaccinationAddFormDTO; import com.epmet.dto.form.VaccinationListFormDTO; @@ -107,7 +106,7 @@ public interface IcEpidemicSpecialAttentionService extends BaseService { * @Description 【核酸】核酸检测信息同步 **/ void synchro(MyNatListFormDTO formDTO); + + /** + * 执行Excel导入 + * @param filePath + */ + void execAsyncExcelImport(Path filePath, String importTaskId); } diff --git a/epmet-user/epmet-user-server/src/main/java/com/epmet/service/impl/IcEpidemicSpecialAttentionServiceImpl.java b/epmet-user/epmet-user-server/src/main/java/com/epmet/service/impl/IcEpidemicSpecialAttentionServiceImpl.java index f87b2c3184..aac9eceb61 100644 --- a/epmet-user/epmet-user-server/src/main/java/com/epmet/service/impl/IcEpidemicSpecialAttentionServiceImpl.java +++ b/epmet-user/epmet-user-server/src/main/java/com/epmet/service/impl/IcEpidemicSpecialAttentionServiceImpl.java @@ -20,6 +20,7 @@ import com.epmet.entity.IcEpidemicSpecialAttentionEntity; import com.epmet.service.IcEpidemicSpecialAttentionService; import com.github.pagehelper.PageHelper; import com.github.pagehelper.PageInfo; +import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @@ -29,6 +30,7 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.Map; +import java.util.stream.Collectors; /** * 疫情特别关注 @@ -153,7 +155,21 @@ public class IcEpidemicSpecialAttentionServiceImpl extends BaseServiceImpl entities = ConvertUtils.sourceToTarget(formDTO.getList(), IcEpidemicSpecialAttentionEntity.class); + List idCards = entities.stream().map(m -> m.getIdCard()).collect(Collectors.toList()); + Integer attentionType = entities.get(NumConstant.ZERO).getAttentionType(); + List existList = baseDao.getExistList(attentionType, idCards); + if (CollectionUtils.isNotEmpty(existList)){ + for (String s : existList) { + for (int i = NumConstant.ZERO; i < entities.size(); i++) { + if (s.equals(entities.get(i).getIdCard())){ + entities.remove(i); + continue; + } + } + } + } entities.forEach(e -> { + e.setIsAttention(NumConstant.ONE); e.setOrgId(agencyInfo.getId()); e.setPid(agencyInfo.getPid()); @@ -179,13 +195,16 @@ public class IcEpidemicSpecialAttentionServiceImpl extends BaseServiceImpl implements IcNatService { +public class IcNatServiceImpl extends BaseServiceImpl implements IcNatService, ResultDataResolver { + + @Autowired + private EpmetCommonServiceOpenFeignClient commonServiceOpenFeignClient; + + @Autowired + private EpmetUserOpenFeignClient epmetUserOpenFeignClient; + @Autowired private IcNoticeService icNoticeService; + @Autowired + private OssFeignClient ossFeignClient; + /** * @Author sun * @Description 核酸检测-上报核酸记录 @@ -213,4 +259,95 @@ public class IcNatServiceImpl extends BaseServiceImpl imp insert(entity); } + @Async + @Override + public void execAsyncExcelImport(Path filePath, String importTaskId) { + String userId = null; + + try { + userId = EpmetRequestHolder.getHeader(AppClientConstant.USER_ID); + String app = EpmetRequestHolder.getHeader(AppClientConstant.APP); + String client = EpmetRequestHolder.getHeader(AppClientConstant.CLIENT); + + LoginUserDetailsFormDTO ludf = new LoginUserDetailsFormDTO(app, client, userId); + LoginUserDetailsResultDTO loginUserDetails = getResultDataOrThrowsException(epmetUserOpenFeignClient.getLoginUserDetails(ludf), ServiceConstant.EPMET_USER_SERVER, + EpmetErrorCode.SERVER_ERROR.getCode(), "调用user出错", ""); + + IcNatExcelImportListener listener = new IcNatExcelImportListener(userId, loginUserDetails.getAgencyId(), loginUserDetails.getOrgIdPath(), this); + + EasyExcel.read(filePath.toFile(), IcNatImportExcelData.class, listener).headRowNumber(2).sheet(0).doRead(); + + Path errorDescFile = null; + String errorDesFileUrl = null; + List errorRows = listener.getErrorRows(); + + // 生成并上传错误文件 + try { + // 文件生成 + Path errorDescDir = FileUtils.getAndCreateDirUnderEpmetFilesDir("ic_nat", "import", "error_des"); + String fileName = UUID.randomUUID().toString().concat(".xlsx"); + errorDescFile = errorDescDir.resolve(fileName); + + FileItemFactory factory = new DiskFileItemFactory(16, errorDescDir.toFile()); + FileItem fileItem = factory.createItem("file", ContentType.APPLICATION_OCTET_STREAM.toString(), true, fileName); + OutputStream os = fileItem.getOutputStream(); + + EasyExcel.write(os, IcNatImportExcelData.ErrorRow.class).sheet("导入失败列表").doWrite(errorRows); + + // 文件上传oss + Result errorDesFileUploadResult = ossFeignClient.uploadImportTaskDescFile(new CommonsMultipartFile(fileItem)); + if (errorDesFileUploadResult.success()) { + errorDesFileUrl = errorDesFileUploadResult.getData().getUrl(); + } + } finally { + if (Files.exists(errorDescFile)) { + Files.delete(errorDescFile); + } + } + + ImportTaskCommonFormDTO importFinishTaskForm = new ImportTaskCommonFormDTO(); + importFinishTaskForm.setTaskId(importTaskId); + importFinishTaskForm.setProcessStatus(errorRows.size() <= 0 ? ImportTaskConstants.PROCESS_STATUS_FINISHED_SUCCESS : ImportTaskConstants.PROCESS_STATUS_FINISHED_FAIL); + importFinishTaskForm.setOperatorId(userId); + importFinishTaskForm.setResultDesc(""); + importFinishTaskForm.setResultDescFilePath(errorDesFileUrl); + + Result result = commonServiceOpenFeignClient.finishImportTask(importFinishTaskForm); + if (!result.success()) { + log.error("【核酸检测导入】finishImportTask失败"); + } + } catch (Exception e) { + String errorMsg = ExceptionUtils.getErrorStackTrace(e); + log.error("【核酸检测导入】出错:{}", errorMsg); + + ImportTaskCommonFormDTO importFinishTaskForm = new ImportTaskCommonFormDTO(); + importFinishTaskForm.setTaskId(importTaskId); + importFinishTaskForm.setProcessStatus(ImportTaskConstants.PROCESS_STATUS_FINISHED_FAIL); + importFinishTaskForm.setOperatorId(userId); + importFinishTaskForm.setResultDesc("导入失败"); + + Result result = commonServiceOpenFeignClient.finishImportTask(importFinishTaskForm); + if (!result.success()) { + log.error("【核酸检测导入】导入记录状态修改为'完成'失败"); + } + } finally { + // 删除临时文件 + if (Files.exists(filePath)) { + try { + Files.delete(filePath); + } catch (IOException e) { + e.printStackTrace(); + } + } + } + + } + + /** + * 批量持久化 + * @param entities + */ + public void batchPersist(List entities) { + insertBatch(entities); + } } diff --git a/epmet-user/epmet-user-server/src/main/resources/mapper/IcEpidemicSpecialAttentionDao.xml b/epmet-user/epmet-user-server/src/main/resources/mapper/IcEpidemicSpecialAttentionDao.xml index 63c556f0c0..ef7660a3c4 100644 --- a/epmet-user/epmet-user-server/src/main/resources/mapper/IcEpidemicSpecialAttentionDao.xml +++ b/epmet-user/epmet-user-server/src/main/resources/mapper/IcEpidemicSpecialAttentionDao.xml @@ -3,6 +3,20 @@ + + + UPDATE ic_epidemic_special_attention + SET UPDATED_TIME = NOW(), + IS_ATTENTION = 0 + WHERE del_flag = 0 + AND attention_type = #{attentionType} + AND id_card IN ( + + #{l} + + ) + + + + + \ No newline at end of file