|
|
|
package com.epmet.controller;
|
|
|
|
|
|
|
|
import com.alibaba.excel.EasyExcel;
|
|
|
|
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.NumConstant;
|
|
|
|
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.page.PageData;
|
|
|
|
import com.epmet.commons.tools.security.dto.TokenDto;
|
|
|
|
import com.epmet.commons.tools.utils.*;
|
|
|
|
import com.epmet.commons.tools.validator.ValidatorUtils;
|
|
|
|
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.NatListCommonExcelResultDTO;
|
|
|
|
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.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 javax.servlet.ServletOutputStream;
|
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
|
import java.io.FileOutputStream;
|
|
|
|
import java.io.IOException;
|
|
|
|
import java.io.InputStream;
|
|
|
|
import java.net.URLEncoder;
|
|
|
|
import java.nio.file.Path;
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.UUID;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 核酸上报记录
|
|
|
|
*
|
|
|
|
* @author generator generator@elink-cn.com
|
|
|
|
* @since v1.0.0 2022-03-25
|
|
|
|
*/
|
|
|
|
@Slf4j
|
|
|
|
@RestController
|
|
|
|
@RequestMapping("icNat")
|
|
|
|
public class IcNatController implements ResultDataResolver {
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
private IcNatService icNucleinService;
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
private EpmetCommonServiceOpenFeignClient commonServiceOpenFeignClient;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 记录一下核酸记录模块的业务程序逻辑,防止后续理不清 ic_nat:基础信息表 ic_nat_relation:关系表
|
|
|
|
* 1.数字平台导入时,按身份证检测时间查询数据,查到数据不是导入的状态则记录下并跳过,是导入数据更新结果,未查到直接新增
|
|
|
|
* 是否居民以及userId值查询数据平台居民,能查到就相应的赋值;
|
|
|
|
* 2.居民端录入可以录自己的或别人的,但是数据属于当前录入的组织;
|
|
|
|
* 3.数据平台录入可以为已有居民录入也可以录新数据,新数据则是否居民和userId无值;
|
|
|
|
* 4.导入数据不允许修改删除,录入数据可以修改删除,删除时相应的删除基础表和可能存在的所有关心表数据,
|
|
|
|
* 数据同步可多次重复,只是修改对应的关系表数据,基础信息表数据公用;
|
|
|
|
* 5.同一条数据被A街道和A社区都同步了,街道在看本辖区数据时会看到两条,但是只有A街道的那一条才能看到取消同步按钮;
|
|
|
|
* 6.数据库一个人一个检测时间只存在一条记录,以导入数据结果为准,已导入的各项值都不能修改,即使错误也只能通过导入修改;
|
|
|
|
* 7.新增、删除居民时会相应的修改基础信息表是否居民以及userId的值;
|
|
|
|
* 注:1.导入数据不允许修改是觉得导入数据是官方提供的且没有问题的数据,不需要在平台有维护操作,只要看就可以了;
|
|
|
|
* 2.是否居民的查询条件以及是否居民的列标题在看整个客户列表数据时这两个都隐藏
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @Author sun
|
|
|
|
* @Description 核酸检测-上报核酸记录
|
|
|
|
**/
|
|
|
|
//@NoRepeatSubmit
|
|
|
|
@PostMapping("add")
|
|
|
|
public Result add(@LoginUser TokenDto tokenDto, @RequestBody AddIcNatFormDTO formDTO) {
|
|
|
|
ValidatorUtils.validateEntity(formDTO, AddIcNatFormDTO.Nat.class);
|
|
|
|
formDTO.setCustomerId(tokenDto.getCustomerId());
|
|
|
|
formDTO.setStaffId(tokenDto.getUserId());
|
|
|
|
formDTO.setClient(tokenDto.getClient());
|
|
|
|
icNucleinService.add(formDTO);
|
|
|
|
return new Result();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @Author sun
|
|
|
|
* @Description 核酸检测-居民端我的上报
|
|
|
|
**/
|
|
|
|
@NoRepeatSubmit
|
|
|
|
@PostMapping("mynatlist")
|
|
|
|
public Result<List<MyNatListResultDTO>> myNatList(@LoginUser TokenDto tokenDto, @RequestBody MyNatListFormDTO formDTO) {
|
|
|
|
formDTO.setCustomerId(tokenDto.getCustomerId());
|
|
|
|
formDTO.setUserId(tokenDto.getUserId());
|
|
|
|
return new Result<List<MyNatListResultDTO>>().ok(icNucleinService.myNatList(formDTO));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @Author sun
|
|
|
|
* @Description 【核酸】核酸检测信息列表
|
|
|
|
**/
|
|
|
|
@NoRepeatSubmit
|
|
|
|
@PostMapping("natlist")
|
|
|
|
public Result<PageData<NatListResultDTO>> natList(@LoginUser TokenDto tokenDto, @RequestBody MyNatListFormDTO formDTO) {
|
|
|
|
formDTO.setCustomerId(tokenDto.getCustomerId());
|
|
|
|
formDTO.setUserId(tokenDto.getUserId());
|
|
|
|
return new Result<PageData<NatListResultDTO>>().ok(icNucleinService.natList(formDTO));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @Author sun
|
|
|
|
* @Description 【核酸】核酸检测信息详情
|
|
|
|
**/
|
|
|
|
@NoRepeatSubmit
|
|
|
|
@PostMapping("detail")
|
|
|
|
public Result<IcNatDTO> detail(@RequestBody MyNatListFormDTO formDTO) {
|
|
|
|
ValidatorUtils.validateEntity(formDTO, MyNatListFormDTO.Detail.class);
|
|
|
|
return new Result<IcNatDTO>().ok(icNucleinService.detail(formDTO));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @Author sun
|
|
|
|
* @Description 【核酸】核酸检测信息修改
|
|
|
|
**/
|
|
|
|
@NoRepeatSubmit
|
|
|
|
@PostMapping("edit")
|
|
|
|
public Result edit(@LoginUser TokenDto tokenDto, @RequestBody AddIcNatFormDTO formDTO) {
|
|
|
|
ValidatorUtils.validateEntity(formDTO, AddIcNatFormDTO.Edit.class);
|
|
|
|
formDTO.setCustomerId(tokenDto.getCustomerId());
|
|
|
|
formDTO.setStaffId(tokenDto.getUserId());
|
|
|
|
icNucleinService.edit(formDTO);
|
|
|
|
return new Result();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @Author sun
|
|
|
|
* @Description 【核酸】核酸检测信息删除/取消同步
|
|
|
|
**/
|
|
|
|
@NoRepeatSubmit
|
|
|
|
@PostMapping("del")
|
|
|
|
public Result del(@RequestBody MyNatListFormDTO formDTO) {
|
|
|
|
ValidatorUtils.validateEntity(formDTO, MyNatListFormDTO.Del.class);
|
|
|
|
icNucleinService.del(formDTO);
|
|
|
|
return new Result<>();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @Author sun
|
|
|
|
* @Description 【核酸】核酸检测信息同步
|
|
|
|
**/
|
|
|
|
@NoRepeatSubmit
|
|
|
|
@PostMapping("synchro")
|
|
|
|
public Result synchro(@LoginUser TokenDto tokenDto, @RequestBody MyNatListFormDTO formDTO) {
|
|
|
|
ValidatorUtils.validateEntity(formDTO, MyNatListFormDTO.Synchro.class);
|
|
|
|
formDTO.setCustomerId(tokenDto.getCustomerId());
|
|
|
|
formDTO.setUserId(tokenDto.getUserId());
|
|
|
|
icNucleinService.synchro(formDTO);
|
|
|
|
return new Result();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @Author sun
|
|
|
|
* @Description 【核酸】核酸检测信息取消同步
|
|
|
|
**/
|
|
|
|
@NoRepeatSubmit
|
|
|
|
@PostMapping("cancelsynchro")
|
|
|
|
public Result cancelSynchro(@LoginUser TokenDto tokenDto, @RequestBody MyNatListFormDTO formDTO) {
|
|
|
|
ValidatorUtils.validateEntity(formDTO, MyNatListFormDTO.Synchro.class);
|
|
|
|
formDTO.setCustomerId(tokenDto.getCustomerId());
|
|
|
|
formDTO.setUserId(tokenDto.getUserId());
|
|
|
|
icNucleinService.cancelSynchro(formDTO);
|
|
|
|
return new Result<>();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 导入excel
|
|
|
|
* @return
|
|
|
|
*/
|
|
|
|
@PostMapping("import")
|
|
|
|
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) {
|
|
|
|
log.error("method exception", e);
|
|
|
|
} 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 【核酸】核酸检测信息下载模板
|
|
|
|
**/
|
|
|
|
@RequestMapping(value = "import-template-download", method = {RequestMethod.GET, RequestMethod.POST})
|
|
|
|
public void downloadTemplate(HttpServletResponse response) throws IOException {
|
|
|
|
response.setCharacterEncoding("UTF-8");
|
|
|
|
response.addHeader(HttpHeaders.ACCESS_CONTROL_EXPOSE_HEADERS, "Content-Disposition");
|
|
|
|
//response.setHeader(HttpHeaders.CONTENT_TYPE, "application/vnd.ms-excel");
|
|
|
|
response.setHeader(HttpHeaders.CONTENT_TYPE, "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
|
|
|
|
response.setHeader(HttpHeaders.CONTENT_DISPOSITION, "attachment;filename=" + URLEncoder.encode("核酸检测导入模板", "UTF-8") + ".xlsx");
|
|
|
|
|
|
|
|
InputStream is = this.getClass().getClassLoader().getResourceAsStream("excel/ic_nat.xlsx");
|
|
|
|
try {
|
|
|
|
ServletOutputStream os = response.getOutputStream();
|
|
|
|
IOUtils.copy(is, os);
|
|
|
|
} finally {
|
|
|
|
if (is != null) {
|
|
|
|
is.close();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @Author sun
|
|
|
|
* @Description 【核酸】核酸检测信息列表
|
|
|
|
**/
|
|
|
|
@NoRepeatSubmit
|
|
|
|
@PostMapping("export")
|
|
|
|
public void export(@LoginUser TokenDto tokenDto, @RequestBody MyNatListFormDTO formDTO, HttpServletResponse response) {
|
|
|
|
formDTO.setCustomerId(tokenDto.getCustomerId());
|
|
|
|
formDTO.setUserId(tokenDto.getUserId());
|
|
|
|
|
|
|
|
//formDTO.setCustomerId("45687aa479955f9d06204d415238f7cc");
|
|
|
|
//formDTO.setUserId("73ae6280e46a6653a5605d51d5462725");
|
|
|
|
|
|
|
|
formDTO.setIsPage(false);
|
|
|
|
|
|
|
|
ExcelWriter excelWriter = null;
|
|
|
|
formDTO.setPageSize(NumConstant.TEN_THOUSAND);
|
|
|
|
int pageNo = formDTO.getPageNo();
|
|
|
|
try {
|
|
|
|
// 这里 需要指定写用哪个class去写
|
|
|
|
String fileName = "核酸检测信息.xlsx";
|
|
|
|
if ("all".equals(formDTO.getOrgType())) {
|
|
|
|
excelWriter = EasyExcel.write(ExcelUtils.getOutputStreamForExcel(fileName, response), NatListResultDTO.class).build();
|
|
|
|
}else {
|
|
|
|
excelWriter = EasyExcel.write(ExcelUtils.getOutputStreamForExcel(fileName, response), NatListCommonExcelResultDTO.class).build();
|
|
|
|
}
|
|
|
|
|
|
|
|
WriteSheet writeSheet = EasyExcel.writerSheet("Sheet1").build();
|
|
|
|
PageData<NatListResultDTO> data = null;
|
|
|
|
do {
|
|
|
|
data = icNucleinService.natList(formDTO);
|
|
|
|
data.getList().forEach(o-> {
|
|
|
|
o.setNatResult(NumConstant.ONE_STR.equals(o.getNatResult()) ? "阳性" : "阴性");
|
|
|
|
o.setIsResiUser(NumConstant.ONE_STR.equals(o.getIsResiUser()) ? "是" : "否");
|
|
|
|
});
|
|
|
|
formDTO.setPageNo(++pageNo);
|
|
|
|
if ("current".equals(formDTO.getOrgType())) {
|
|
|
|
List<NatListResultDTO> list = ConvertUtils.sourceToTarget(data.getList(), NatListResultDTO.class);
|
|
|
|
excelWriter.write(list, writeSheet);
|
|
|
|
}else{
|
|
|
|
excelWriter.write(data.getList(), writeSheet);
|
|
|
|
}
|
|
|
|
} while (CollectionUtils.isNotEmpty(data.getList()) && data.getList().size() == formDTO.getPageSize());
|
|
|
|
|
|
|
|
}catch (Exception e){
|
|
|
|
log.error("export exception", e);
|
|
|
|
}finally {
|
|
|
|
// 千万别忘记finish 会帮忙关闭流
|
|
|
|
if (excelWriter != null) {
|
|
|
|
excelWriter.finish();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|