You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

265 lines
10 KiB

package com.epmet.controller;
2 years ago
import com.epmet.commons.tools.annotation.MaskResponse;
import com.epmet.commons.tools.exception.EpmetErrorCode;
import com.epmet.commons.tools.exception.EpmetException;
import com.epmet.commons.tools.exception.ValidateException;
import com.epmet.commons.tools.page.PageData;
import com.epmet.commons.tools.utils.DateUtils;
import com.epmet.commons.tools.utils.FileUtils;
import com.epmet.commons.tools.utils.Result;
import com.epmet.commons.tools.validator.ValidatorUtils;
import com.epmet.dto.form.lingshan.LingShanSpecialTypeSaveFormDTO;
import com.epmet.dto.form.lingshan.LingShanSpecialTypeSaveResultDTO;
import com.epmet.dto.result.LingShanSpecialCrowdListResultDTO;
import com.epmet.enums.LingShanSpecialCrowdTypeEnums;
import com.epmet.excel.data.*;
import com.epmet.service.LingShanSpecialCrowdService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
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.Files;
import java.nio.file.Path;
import java.util.Date;
import java.util.List;
import java.util.Map;
/**
* @description: 灵山社会维稳特殊人群
* @param null:
* @return
* @author: WangXianZhang
* @date: 2023/4/18 9:08 AM
*/
@Slf4j
@RestController
@RequestMapping("lingShan/specialCrowd")
public class LingShanSpecialCrowdController {
@Autowired
private LingShanSpecialCrowdService lingShanSpecialCrowdService;
/**
* @description: 下载导入模板
* @param specialType:
* @return
* @author: WangXianZhang
* @date: 2023/4/21 10:16 AM
*/
@GetMapping("downloadTemplate")
public void downloadTemplate(@RequestParam("specialType") String specialType, HttpServletResponse response) {
InputStream is = null;
LingShanSpecialCrowdTypeEnums st = LingShanSpecialCrowdTypeEnums.getByType(specialType);
if (st == null) {
log.error("【灵山街道-下载特殊人群导入模板】传入的特殊人群类型错误:{}", specialType);
return;
}
try (ServletOutputStream os = response.getOutputStream()) {
is = this.getClass().getClassLoader().getResourceAsStream("excel/lingshan/special_crowd_" + specialType + "_import.xlsx");
response.setHeader("Access-Control-Expose-Headers", "Content-Disposition");
response.setHeader("content-Type", "application/vnd.ms-excel");
response.setHeader("Content-Disposition", "attachment;fileName=" + URLEncoder.encode(st.getName(), "UTF-8"));
IOUtils.copy(is, os);
} catch (IOException e) {
throw new RuntimeException(e);
} finally {
org.apache.poi.util.IOUtils.closeQuietly(is);
}
}
/**
* @description: 特殊人群导入
* @param file:
* @param crowdCategory: 人群类别
* anzhibangjiao
* buliangqingshaonian
* shequjiaozheng
* jiedurenyuan
* xiejiaorenyuan
* zhaoshizhaohuojingshenbing
* @return
* @author: WangXianZhang
* @date: 2023/4/18 9:12 AM
*/
@PostMapping("import")
public Result importSpecialCowd(MultipartFile file, @RequestParam("crowdCategory") String crowdCategory) {
2 years ago
String originalFilename = file.getOriginalFilename();
String suffix = originalFilename.substring(originalFilename.lastIndexOf("."));
// 1.存文件
2 years ago
Path fileSavePath = saveSpecialCrowdTempFile(file, suffix);
// 2.执行业务导入
try {
String taskId = lingShanSpecialCrowdService.importSpecialCrowd(crowdCategory, fileSavePath.toString(), originalFilename);
return new Result().ok(taskId);
} catch (Exception e) {
// 3.出错的话,删除文件。不能在finally中删除,因为正常执行的话,是在异步线程中执行导入,这里删除了,那子线程就获取不到文件了,所以子线程中有单独的删除逻辑
FileUtils.deleteFileIfExists(fileSavePath);
throw e;
}
}
/**
* @description: 保存特殊人群临时文件
* @param file:
* @return
* @author: WangXianZhang
* @date: 2023/4/18 9:46 AM
*/
2 years ago
public Path saveSpecialCrowdTempFile(@RequestParam("file") MultipartFile file, String suffix) {
Path fileSavePath;
FileOutputStream os = null;
try {
Path fileSaveDir = FileUtils.getAndCreateDirUnderEpmetFilesDir("special_crowd_import");
2 years ago
String fileName = DateUtils.format(new Date(), "yyyyMMdd_HHmmss_" + System.nanoTime()) + suffix;
fileSavePath = fileSaveDir.resolve(fileName);
IOUtils.copy(file.getInputStream(), (os = new FileOutputStream(fileSavePath.toString())));
return fileSavePath;
} catch (IOException e) {
log.error("【灵山街道】导入社会维稳数据,缓存文件失败。");
throw new EpmetException(EpmetErrorCode.EPMET_COMMON_OPERATION_FAIL.getCode(), null, null);
} finally {
org.apache.poi.util.IOUtils.closeQuietly(os);
}
}
// /**
// * @description: 安置帮教新增
// * @param azbjData:
// * @return
// * @author: WangXianZhang
// * @date: 2023/4/20 2:50 PM
// */
// @PostMapping("anzhibangjiao/save")
// public Result saveSpecialCrowd(@RequestBody LingShanSpecialCrowdDetailAzbjExcelData azbjData) {
// ValidatorUtils.validateEntity(azbjData);
//
// lingShanSpecialCrowdService.createSpecialCrowd(azbjData, "anzhibangjiao");
// return new Result();
// }
//
// @PostMapping("jiedurenyuan/save")
// public Result saveSpecialCrowd(@RequestBody LingshanSpecialCrowdDetailJdryExcelData jdryData) {
// ValidatorUtils.validateEntity(jdryData);
//
// lingShanSpecialCrowdService.createSpecialCrowd(jdryData, "jiedurenyuan");
// return new Result();
// }
//
// @PostMapping("jingzhanhuanzhe/save")
// public Result saveSpecialCrowd(@RequestBody LingshanSpecialCrowdDetailJzhzExcelData jzhzData) {
// ValidatorUtils.validateEntity(jzhzData);
//
// lingShanSpecialCrowdService.createSpecialCrowd(jzhzData, "jingzhanhuanzhe");
// return new Result();
// }
//
// @PostMapping("shequjiaozheng/save")
// public Result saveSpecialCrowd(@RequestBody LingshanSpecialCrowdDetailSqjzExcelData sqjzData) {
// ValidatorUtils.validateEntity(sqjzData);
//
// lingShanSpecialCrowdService.createSpecialCrowd(sqjzData, "shequjiaozheng");
// return new Result();
// }
//
// @PostMapping("xinfangrenyuan/save")
// public Result saveSpecialCrowd(@RequestBody LingshanSpecialCrowdDetailXfryExcelData xfryData) {
// ValidatorUtils.validateEntity(xfryData);
//
// lingShanSpecialCrowdService.createSpecialCrowd(xfryData, "xinfangrenyuan");
// return new Result();
// }
/**
* @description: 保存
* @param input:
* @return
* @author: WangXianZhang
* @date: 2023/4/23 10:58 AM
*/
@PostMapping("save")
public Result saveSpecialCrowd(@RequestBody LingShanSpecialTypeSaveFormDTO input) {
ValidatorUtils.validateEntity(input);
lingShanSpecialCrowdService.saveSpecialCrowd(input);
return new Result();
}
/**
* @description: 特殊人群详情
* @return
* @author: WangXianZhang
* @date: 2023/4/20 3:44 PM
*/
@GetMapping("getPersonSpecialTypeDetail")
public Result<LingShanSpecialTypeSaveResultDTO> getPersonSpecialTypeDetail(@RequestParam("resiId") String resiId) {
LingShanSpecialTypeSaveResultDTO r = lingShanSpecialCrowdService.getPersonSpecialTypeDetail(resiId);
return new Result<LingShanSpecialTypeSaveResultDTO>().ok(r);
}
/**
* @description: 列表查询
* @param orgId:
* @param orgType:
* @param specialType:
* @param name:
* @param mobile:
* @param idCard:
* @return
* @author: WangXianZhang
* @date: 2023/4/20 5:42 PM
*/
@GetMapping("listSpecialCrowd")
2 years ago
@MaskResponse(fieldNames = {"name", "mobile", "idCard"},
fieldsMaskType = { MaskResponse.MASK_TYPE_CHINESE_NAME, MaskResponse.MASK_TYPE_MOBILE, MaskResponse.MASK_TYPE_ID_CARD })
public Result<PageData<LingShanSpecialCrowdListResultDTO>> listSpecialCrowds(@RequestParam(value = "orgId", required = false) String orgId,
@RequestParam(value = "orgType", required = false) String orgType,
@RequestParam(value = "specialType", required = false) String specialType,
@RequestParam(value = "name", required = false) String name,
@RequestParam(value = "mobile", required = false) String mobile,
@RequestParam(value = "idCard", required = false) String idCard,
@RequestParam(value = "pageNo", required = false, defaultValue = "1") Integer pageNo,
@RequestParam(value = "pageSize", required = false, defaultValue = "20") Integer pageSize) {
PageData<LingShanSpecialCrowdListResultDTO> pd = lingShanSpecialCrowdService.listSpecialCrowds(orgId, orgType, specialType, name, mobile,
idCard, pageNo, pageSize);
return new Result<PageData<LingShanSpecialCrowdListResultDTO>>().ok(pd);
}
/**
* @description: 删除
* @param params:
* @return
* @author: WangXianZhang
* @date: 2023/4/21 9:40 AM
*/
@PostMapping("deleteByType")
public Result deleteByType(@RequestBody Map<String, String> params) {
String resiId = params.get("resiId");
if (StringUtils.isAnyBlank(resiId, resiId)) {
throw new ValidateException("特殊人群类型或身份证不能为空");
}
lingShanSpecialCrowdService.deleteByType(resiId);
return new Result();
}
}