forked from luyan/epmet-cloud-lingshan
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.
182 lines
6.8 KiB
182 lines
6.8 KiB
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;
|
|
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;
|
|
|
|
|
|
/**
|
|
* 福利表
|
|
*
|
|
* @author generator generator@elink-cn.com
|
|
* @since v1.0.0 2022-05-09
|
|
*/
|
|
@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){
|
|
PageData<ChangeWelfareDTO> page = changeWelfareService.page(params);
|
|
return new Result<PageData<ChangeWelfareDTO>>().ok(page);
|
|
}
|
|
|
|
@RequestMapping(value = "{id}", method = {RequestMethod.POST, RequestMethod.GET})
|
|
public Result<ChangeWelfareDTO> get(@PathVariable("id") String id){
|
|
ChangeWelfareDTO data = changeWelfareService.get(id);
|
|
return new Result<ChangeWelfareDTO>().ok(data);
|
|
}
|
|
|
|
@NoRepeatSubmit
|
|
@PostMapping("save")
|
|
public Result save(@RequestBody ChangeWelfareDTO dto){
|
|
//效验数据
|
|
ValidatorUtils.validateEntity(dto, AddGroup.class, DefaultGroup.class);
|
|
return changeWelfareService.save(dto);
|
|
}
|
|
|
|
@NoRepeatSubmit
|
|
@PostMapping("update")
|
|
public Result update(@RequestBody ChangeWelfareDTO dto){
|
|
//效验数据
|
|
ValidatorUtils.validateEntity(dto, UpdateGroup.class, DefaultGroup.class);
|
|
changeWelfareService.update(dto);
|
|
return new Result();
|
|
}
|
|
|
|
@RequestMapping(value = "delete", method = {RequestMethod.POST, RequestMethod.DELETE})
|
|
public Result delete(@RequestBody String[] ids){
|
|
//效验数据
|
|
AssertUtils.isArrayEmpty(ids, "id");
|
|
changeWelfareService.delete(ids);
|
|
return new Result();
|
|
}
|
|
|
|
@NoRepeatSubmit
|
|
@GetMapping("export")
|
|
public void export(@RequestParam Map<String, Object> params, HttpServletResponse response) throws Exception {
|
|
List<ChangeWelfareDTO> list = changeWelfareService.list(params);
|
|
ExcelUtils.exportEpmetExcel(response, null, list, ChangeWelfareExcel.class);
|
|
}
|
|
|
|
/**
|
|
* @describe: 移除福利人员
|
|
* @author wangtong
|
|
* @date 2022/5/9 11:11
|
|
* @params [dto]
|
|
* @return com.epmet.commons.tools.utils.Result
|
|
*/
|
|
@NoRepeatSubmit
|
|
@PostMapping("removeWelfare")
|
|
public Result removeWelfare(@RequestBody ChangeWelfareDTO dto){
|
|
return changeWelfareService.removeWelfare(dto);
|
|
}
|
|
|
|
|
|
/**
|
|
* @describe: 通过身份证号查询是否属于福利人员,是-true,否-false
|
|
* @author wangtong
|
|
* @date 2022/5/9 13:52
|
|
* @params [dto]
|
|
* @return com.epmet.commons.tools.utils.Result
|
|
*/
|
|
@NoRepeatSubmit
|
|
@GetMapping("checkWelfareByIdCard")
|
|
public Boolean checkWelfareByIdCard(CheckWelfareByIdCardDTO dto){
|
|
//效验数据
|
|
ValidatorUtils.validateEntity(dto, UpdateGroup.class, DefaultGroup.class);
|
|
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);
|
|
}
|
|
|
|
}
|
|
|