|
|
|
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.NumConstant;
|
|
|
|
import com.epmet.commons.tools.dto.form.PageFormDTO;
|
|
|
|
import com.epmet.commons.tools.page.PageData;
|
|
|
|
import com.epmet.commons.tools.security.dto.TokenDto;
|
|
|
|
import com.epmet.commons.tools.utils.ConvertUtils;
|
|
|
|
import com.epmet.commons.tools.utils.ExcelUtils;
|
|
|
|
import com.epmet.commons.tools.utils.Result;
|
|
|
|
import com.epmet.commons.tools.utils.poi.excel.handler.FreezeAndFilter;
|
|
|
|
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.UpdateGroup;
|
|
|
|
import com.epmet.commons.tools.validator.group.DefaultGroup;
|
|
|
|
import com.epmet.dto.IcDangerAreaDTO;
|
|
|
|
import com.epmet.dto.form.DangerAreaListFormDTO;
|
|
|
|
import com.epmet.dto.result.NatListCommonExcelResultDTO;
|
|
|
|
import com.epmet.dto.result.NatListResultDTO;
|
|
|
|
import com.epmet.enums.DangerLevelEnum;
|
|
|
|
import com.epmet.excel.IcDangerAreaResultExcel;
|
|
|
|
import com.epmet.service.IcDangerAreaService;
|
|
|
|
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 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;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 疫情风险地区
|
|
|
|
*
|
|
|
|
* @author generator generator@elink-cn.com
|
|
|
|
* @since v1.0.0 2022-10-31
|
|
|
|
*/
|
|
|
|
@RestController
|
|
|
|
@Slf4j
|
|
|
|
@RequestMapping("icDangerArea")
|
|
|
|
public class IcDangerAreaController {
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
private IcDangerAreaService icDangerAreaService;
|
|
|
|
|
|
|
|
@RequestMapping("page")
|
|
|
|
public Result<PageData<IcDangerAreaDTO>> page(@RequestParam Map<String, Object> params){
|
|
|
|
PageData<IcDangerAreaDTO> page = icDangerAreaService.page(params);
|
|
|
|
return new Result<PageData<IcDangerAreaDTO>>().ok(page);
|
|
|
|
}
|
|
|
|
|
|
|
|
@RequestMapping(value = "{id}",method = {RequestMethod.POST,RequestMethod.GET})
|
|
|
|
public Result<IcDangerAreaDTO> get(@PathVariable("id") String id){
|
|
|
|
IcDangerAreaDTO data = icDangerAreaService.get(id);
|
|
|
|
return new Result<IcDangerAreaDTO>().ok(data);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @Description 新增
|
|
|
|
* @param dto
|
|
|
|
* @param tokenDto
|
|
|
|
* @Author zxc
|
|
|
|
* @Date 2022/11/1 09:09
|
|
|
|
*/
|
|
|
|
@NoRepeatSubmit
|
|
|
|
@PostMapping("save")
|
|
|
|
public Result save(@RequestBody IcDangerAreaDTO dto, @LoginUser TokenDto tokenDto){
|
|
|
|
ValidatorUtils.validateEntity(dto, AddGroup.class, DefaultGroup.class);
|
|
|
|
dto.setCustomerId(tokenDto.getCustomerId());
|
|
|
|
icDangerAreaService.save(dto);
|
|
|
|
return new Result();
|
|
|
|
}
|
|
|
|
|
|
|
|
@NoRepeatSubmit
|
|
|
|
@PostMapping("update")
|
|
|
|
public Result update(@RequestBody IcDangerAreaDTO dto){
|
|
|
|
//效验数据
|
|
|
|
ValidatorUtils.validateEntity(dto, UpdateGroup.class, DefaultGroup.class);
|
|
|
|
icDangerAreaService.update(dto);
|
|
|
|
return new Result();
|
|
|
|
}
|
|
|
|
|
|
|
|
@PostMapping("delete")
|
|
|
|
public Result delete(@RequestBody List<String> ids,@LoginUser TokenDto tokenDto){
|
|
|
|
icDangerAreaService.delete(ids,tokenDto.getUserId());
|
|
|
|
return new Result();
|
|
|
|
}
|
|
|
|
|
|
|
|
@RequestMapping("list")
|
|
|
|
public Result<PageData<IcDangerAreaDTO>> list(@RequestBody DangerAreaListFormDTO formDTO,@LoginUser TokenDto tokenDto){
|
|
|
|
ValidatorUtils.validateEntity(formDTO, PageFormDTO.AddUserInternalGroup.class);
|
|
|
|
formDTO.setCustomerId(tokenDto.getCustomerId());
|
|
|
|
return new Result<PageData<IcDangerAreaDTO>>().ok(icDangerAreaService.list(formDTO));
|
|
|
|
}
|
|
|
|
|
|
|
|
@RequestMapping("export")
|
|
|
|
public void export(@LoginUser TokenDto tokenDto,@RequestBody DangerAreaListFormDTO formDTO,HttpServletResponse response){
|
|
|
|
formDTO.setCustomerId(tokenDto.getCustomerId());
|
|
|
|
ExcelWriter excelWriter = null;
|
|
|
|
int pageNo = NumConstant.ONE;
|
|
|
|
formDTO.setPageSize(NumConstant.ONE_THOUSAND);
|
|
|
|
try {
|
|
|
|
excelWriter = EasyExcel.write(ExcelUtils.getOutputStreamForExcel("风险地区", response), IcDangerAreaResultExcel.class).build();
|
|
|
|
WriteSheet writeSheet = EasyExcel.writerSheet("Sheet1").registerWriteHandler(new FreezeAndFilter()).build();
|
|
|
|
Integer size;
|
|
|
|
do {
|
|
|
|
PageData<IcDangerAreaDTO> list = icDangerAreaService.list(formDTO);
|
|
|
|
List<IcDangerAreaDTO> data = list.getList();
|
|
|
|
if (CollectionUtils.isNotEmpty(data)){
|
|
|
|
data.forEach(d -> {
|
|
|
|
d.setDangerLevel(DangerLevelEnum.getNameByCode(d.getDangerLevel()));
|
|
|
|
});
|
|
|
|
}
|
|
|
|
excelWriter.write(ConvertUtils.sourceToTarget(data,IcDangerAreaResultExcel.class), writeSheet);
|
|
|
|
formDTO.setPageNo(pageNo++);
|
|
|
|
size = data.size();
|
|
|
|
} while (size == NumConstant.ONE_THOUSAND);
|
|
|
|
}catch (Exception e){
|
|
|
|
log.error("export exception", e);
|
|
|
|
}finally {
|
|
|
|
if (excelWriter != null) {
|
|
|
|
excelWriter.finish();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @Description 模板下载
|
|
|
|
* @param response
|
|
|
|
* @Author zxc
|
|
|
|
* @Date 2022/11/1 09:52
|
|
|
|
*/
|
|
|
|
@PostMapping("downloadTemplate")
|
|
|
|
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.openxmlformats-officedocument.spreadsheetml.sheet");
|
|
|
|
response.setHeader(HttpHeaders.CONTENT_DISPOSITION, "attachment;filename=" + URLEncoder.encode("风险地区导入模板", "UTF-8") + ".xlsx");
|
|
|
|
InputStream is = this.getClass().getClassLoader().getResourceAsStream("excel/ic_danger_area_template.xlsx");
|
|
|
|
try {
|
|
|
|
ServletOutputStream os = response.getOutputStream();
|
|
|
|
IOUtils.copy(is, os);
|
|
|
|
} finally {
|
|
|
|
if (is != null) {
|
|
|
|
is.close();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|