package com.gkhy.safePlatform.equipment.controller;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
import com.gkhy.safePlatform.commons.enums.ResultCodes;
|
import com.gkhy.safePlatform.commons.query.PageQuery;
|
import com.gkhy.safePlatform.commons.utils.BeanCopyUtils;
|
import com.gkhy.safePlatform.commons.utils.PageUtils;
|
import com.gkhy.safePlatform.commons.vo.ResultVO;
|
import com.gkhy.safePlatform.equipment.entity.*;
|
import com.gkhy.safePlatform.equipment.model.dto.req.KeypointEquipmentInfoImportExcel;
|
import com.gkhy.safePlatform.equipment.model.dto.req.KeypointEquipmentInfoQueryCriteria;
|
import com.gkhy.safePlatform.equipment.model.dto.resp.KeypointEquipmentInfoDto;
|
import com.gkhy.safePlatform.equipment.model.dto.resp.KeypointEquipmentInfoExcel;
|
import com.gkhy.safePlatform.equipment.service.KeypointEquipmentInfoService;
|
import com.gkhy.safePlatform.equipment.utils.DateUtils;
|
import com.gkhy.safePlatform.equipment.utils.poihelper.ExcelLogs;
|
import com.gkhy.safePlatform.equipment.utils.poihelper.ExcelUtil;
|
import com.google.common.collect.Lists;
|
import org.apache.commons.collections.CollectionUtils;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.multipart.MultipartFile;
|
|
import javax.annotation.Resource;
|
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletResponse;
|
import java.io.IOException;
|
import java.io.Serializable;
|
import java.net.URLEncoder;
|
import java.sql.Timestamp;
|
import java.util.*;
|
import java.util.stream.Collectors;
|
|
/**
|
* 重点监管装置/设备 详细信息(KeypointEquipmentInfo)表控制层
|
*
|
* @author xurui
|
* @since 2022-07-19 13:36:27
|
*/
|
@RestController
|
@RequestMapping("keypointEquipmentInfo")
|
public class KeypointEquipmentInfoController {
|
/**
|
* 服务对象
|
*/
|
@Resource
|
private KeypointEquipmentInfoService keypointEquipmentInfoService;
|
|
|
@Autowired
|
public HttpServletRequest request;
|
|
@Autowired
|
public HttpServletResponse response;
|
|
/**
|
* 分页查询所有数据
|
*
|
* @param pageQuery 查询实体
|
* @return 所有数据
|
*/
|
@PostMapping(value = "/page/list")
|
public ResultVO selectAll(@RequestBody PageQuery<KeypointEquipmentInfoQueryCriteria> pageQuery){
|
PageUtils.checkCheck(pageQuery);
|
return this.keypointEquipmentInfoService.queryAll(pageQuery);
|
}
|
|
|
/**
|
* 通过主键查询单条数据
|
*
|
* @param id 主键
|
* @return 单条数据
|
*/
|
@GetMapping(value = "/selectOne/{id}")
|
public ResultVO selectOne(@PathVariable Serializable id) {
|
return new ResultVO<>(ResultCodes.OK,this.keypointEquipmentInfoService.selectOne(id));
|
}
|
|
/**
|
* 新增或者修改数据
|
*
|
* @param infoDto 实体对象
|
* @return 修改结果
|
*/
|
@PostMapping(value = "/addOrUpdate")
|
public ResultVO update(@RequestBody KeypointEquipmentInfoDto infoDto) {
|
if(infoDto.getEquipmentTypeId() == null){
|
return new ResultVO<>(ResultCodes.CLIENT_PARAM_ILLEGAL,"缺少equipmentTypeId");
|
}
|
keypointEquipmentInfoService.addOrUpdate(infoDto);
|
return new ResultVO<>(ResultCodes.OK);
|
|
}
|
|
/**
|
* 删除数据
|
*
|
* @param ids 主键结合
|
* @return 删除结果
|
*/
|
@RequestMapping(value = "/delete",method = RequestMethod.POST)
|
public ResultVO delete(@RequestBody Long[] ids) {
|
if(ids == null){
|
return new ResultVO<>(ResultCodes.CLIENT_PARAM_ILLEGAL);
|
}
|
List<Long> idList = Arrays.asList(ids);
|
this.keypointEquipmentInfoService.removeByIds(idList);
|
return new ResultVO<>(ResultCodes.OK);
|
}
|
|
|
/**
|
* 下载模板
|
*
|
*/
|
@GetMapping(value = "/exportTemplate")
|
public void exportTemplate() throws IOException {
|
Map<String,String> map = new LinkedHashMap<>();
|
map.put("1","类型/类别外键 ");
|
map.put("2","装置/部位名称");
|
map.put("3","所属单位部门/外键");
|
map.put("4","具体位置");
|
map.put("5","负责人姓名");
|
map.put("6","联系人/外键");
|
map.put("7","录入人/外键");
|
map.put("8","责任人/外键");
|
map.put("9","装置部位分类 1:关键装置 2:重点部位");
|
map.put("10","检查周期");
|
map.put("11","应急预案/外键");
|
map.put("12","主要危险有害因素");
|
map.put("13","易导致风险");
|
map.put("14","应急处置措施");
|
map.put("15","现场图片地址路径");
|
|
|
String fileName = URLEncoder.encode("重点监管装置设备数据导入模板.xls", "UTF-8");
|
response.setContentType("application/vnd.ms-excel");
|
response.setHeader("Content-Disposition", "attachment;filename=" + fileName + ".xlsx");
|
response.setHeader("Access-Control-Expose-Headers", "Content-Disposition");
|
|
ExcelUtil.exportExcel(map,new ArrayList<>() , response.getOutputStream());
|
response.getOutputStream().close();
|
}
|
|
|
/**
|
* 导入数据
|
*
|
*/
|
@RequestMapping(value = "/importData")
|
public ResultVO importData(MultipartFile file) throws IOException {
|
String contentType = file.getContentType();
|
if(!"application/vnd.ms-excel".equals(contentType)
|
&& !"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet".equals(contentType)) {
|
return new ResultVO<>(ResultCodes.CLIENT_PARAM_ILLEGAL, "上传的excel格式错误");
|
}
|
|
Collection<KeypointEquipmentInfoImportExcel> importExcel = ExcelUtil.importExcel(KeypointEquipmentInfoImportExcel.class, file.getInputStream(), "yyyy-MM-dd HH:mm:ss", new ExcelLogs() , 0);
|
|
if (CollectionUtils.isEmpty(importExcel)) {
|
return new ResultVO<>(ResultCodes.OK);
|
}
|
|
List<KeypointEquipmentInfo> respList = BeanCopyUtils.copyBeanList((List<KeypointEquipmentInfoImportExcel>)importExcel, KeypointEquipmentInfo.class);
|
|
keypointEquipmentInfoService.saveBatch(respList);
|
return new ResultVO<>(ResultCodes.OK);
|
}
|
|
|
|
|
/**
|
* 导出一览数据
|
*
|
*/
|
@GetMapping(value = "/exportData")
|
public void exportData(KeypointEquipmentInfoQueryCriteria queryCriteria) throws IOException {
|
Map<String,String> map = new LinkedHashMap<>();
|
map.put("0","ID");
|
map.put("1","类型/类别外键");
|
map.put("2","装置/部位名称");
|
map.put("3","所属单位部门/外键");
|
map.put("4","具体位置");
|
map.put("5","负责人姓名");
|
map.put("6","联系人/外键");
|
map.put("7","录入人/外键");
|
map.put("8","责任人/外键");
|
map.put("9","装置部位分类 1:关键装置 2:重点部位");
|
map.put("10","检查周期");
|
map.put("11","应急预案/外键");
|
map.put("12","主要危险有害因素");
|
map.put("13","易导致风险");
|
map.put("14","应急处置措施");
|
map.put("15","现场图片地址路径");
|
|
String key = DateUtils.date2String(new Date(), DateUtils.PATTERN_ALLTIME_NOSIGN) ;
|
String fileName = URLEncoder.encode("重点监管装置设备"+key+".xls", "UTF-8");
|
response.setContentType("application/vnd.ms-excel");
|
response.setHeader("Content-Disposition", "attachment;filename=" + fileName + ".xlsx");
|
response.setHeader("Access-Control-Expose-Headers", "Content-Disposition");
|
|
|
List<KeypointEquipmentInfoExcel> respList = BeanCopyUtils.copyBeanList(keypointEquipmentInfoService.queryAll(queryCriteria), KeypointEquipmentInfoExcel.class);
|
|
ExcelUtil.exportExcel(map,respList , response.getOutputStream(),DateUtils.PATTERN_STANDARD);
|
response.getOutputStream().close();
|
}
|
|
|
|
public static void main(String[] args) {
|
KeypointEquipmentInfoDto infoDto = new KeypointEquipmentInfoDto();
|
List<EquipmentRepairDetail> repairDetails = Lists.newArrayList();
|
EquipmentRepairDetail repairDetail = new EquipmentRepairDetail();
|
repairDetail.setInfoTpe(0);
|
repairDetail.setRepairPersonId(0L);
|
repairDetail.setRepairStartDate(new Timestamp(new java.util.Date().getTime()));
|
repairDetail.setRepairEndDate(new Timestamp(new java.util.Date().getTime()));
|
repairDetail.setRepairPersonDepartmentId(0L);
|
repairDetail.setRepairMemo("");
|
repairDetail.setRepairStatus(0);
|
repairDetail.setExceptionInfo("");
|
repairDetails.add(repairDetail);
|
infoDto.setRepaireDetailList(repairDetails);
|
|
//
|
infoDto.setCheckDetailList(new ArrayList());
|
|
//
|
List<EquipmentTestDetail> testDetails = Lists.newArrayList();
|
EquipmentTestDetail equipmentTestDetail = new EquipmentTestDetail();
|
equipmentTestDetail.setTestPersonId(0L);
|
equipmentTestDetail.setTestDate(new Timestamp(new java.util.Date().getTime()));
|
equipmentTestDetail.setTestPersonDepartmentId(0L);
|
equipmentTestDetail.setTestMemo("");
|
equipmentTestDetail.setTestResult(0);
|
equipmentTestDetail.setTestStatus("");
|
testDetails.add(equipmentTestDetail);
|
infoDto.setTestDetailList(testDetails);
|
|
List<EquipmentTakecareDetail> takecareDetails = Lists.newArrayList();
|
EquipmentTakecareDetail takecareDetail = new EquipmentTakecareDetail();
|
takecareDetail.setEquipmentId(0L);
|
takecareDetail.setTakecareMemo("");
|
takecareDetail.setLeadingPersonId(0L);
|
takecareDetail.setTakecareDate(new Timestamp(new java.util.Date().getTime()));
|
takecareDetail.setLeadingPersonDepartmentId(0L);
|
takecareDetails.add(takecareDetail);
|
infoDto.setTakecareDetailList(takecareDetails);
|
|
List<EquipmentTakecareStardardDetail> takecareStardardDetails = Lists.newArrayList();
|
EquipmentTakecareStardardDetail takecareStardardDetail = new EquipmentTakecareStardardDetail();
|
takecareStardardDetail.setFilePath("123");
|
takecareStardardDetails.add(takecareStardardDetail);
|
infoDto.setTakecareStardardeDetailList(takecareStardardDetails);
|
|
|
List<EquipmentCheckStandardDetail> theckStandardeDetails = Lists.newArrayList();
|
EquipmentCheckStandardDetail theckStandardeDetail = new EquipmentCheckStandardDetail();
|
theckStandardeDetail.setIndexNum("1");
|
theckStandardeDetail.setCheckContent("2");
|
theckStandardeDetail.setCheckTarget("3");
|
theckStandardeDetail.setUnit("4");
|
theckStandardeDetail.setCheckPart("5");
|
theckStandardeDetail.setRate("6");
|
theckStandardeDetails.add(theckStandardeDetail);
|
infoDto.setCheckStandardeDetailList(theckStandardeDetails);
|
|
|
infoDto.setName("3123");
|
infoDto.setDepartmentId(0L);
|
infoDto.setPosition("312");
|
infoDto.setLeadingPersonName("312");
|
infoDto.setConnectPersonId(0L);
|
infoDto.setInputPersonId(0L);
|
infoDto.setResponsibilityPersonId(0L);
|
infoDto.setPartType(0);
|
infoDto.setCheckCycle("");
|
infoDto.setEmergencePlanId(0L);
|
infoDto.setDangerousElement("");
|
infoDto.setToDangerous("份12");
|
infoDto.setTreatment("发生的");
|
infoDto.setScenePic("");
|
System.out.println(JSONObject.toJSONString(infoDto));
|
|
|
}
|
}
|