374 lines
17 KiB
Plaintext
374 lines
17 KiB
Plaintext
package com.sercurityControl.proteam.controller;
|
|
|
|
import com.alibaba.fastjson2.JSONObject;
|
|
import com.github.pagehelper.PageHelper;
|
|
import com.github.pagehelper.PageInfo;
|
|
import com.securityControl.common.core.utils.StringUtils;
|
|
import com.securityControl.common.core.utils.aes.Aes;
|
|
import com.securityControl.common.core.utils.aes.StringHelper;
|
|
import com.securityControl.common.core.utils.poi.ExcelUtil;
|
|
import com.securityControl.common.core.web.domain.AjaxResult;
|
|
import com.securityControl.common.core.web.page.TableDataInfo;
|
|
import com.securityControl.common.log.annotation.Log;
|
|
import com.securityControl.common.log.enums.BusinessType;
|
|
import com.securityControl.common.log.enums.OperationType;
|
|
import com.sercurityControl.proteam.domain.ClassData;
|
|
import com.sercurityControl.proteam.domain.ProClassMettingVo;
|
|
import com.sercurityControl.proteam.domain.ProData;
|
|
import com.sercurityControl.proteam.domain.TicketData;
|
|
import com.sercurityControl.proteam.domain.vo.DeviceVo;
|
|
import com.sercurityControl.proteam.domain.vo.PreservationVo;
|
|
import com.sercurityControl.proteam.domain.vo.ReturnCodeEntity;
|
|
import com.sercurityControl.proteam.mapper.ProDataMapper;
|
|
import com.sercurityControl.proteam.service.ProDataService;
|
|
import com.sercurityControl.proteam.util.BaseController;
|
|
import com.sercurityControl.proteam.util.ImportExcelUtils;
|
|
import com.sercurityControl.proteam.util.ResultModel;
|
|
import io.swagger.annotations.Api;
|
|
import io.swagger.annotations.ApiOperation;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import org.apache.poi.util.IOUtils;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
|
|
import org.springframework.web.bind.annotation.GetMapping;
|
|
import org.springframework.web.bind.annotation.PostMapping;
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
import org.springframework.web.multipart.MultipartHttpServletRequest;
|
|
import org.springframework.web.multipart.commons.CommonsMultipartResolver;
|
|
|
|
import javax.annotation.Resource;
|
|
import javax.servlet.ServletOutputStream;
|
|
import javax.servlet.http.HttpServletRequest;
|
|
import javax.servlet.http.HttpServletResponse;
|
|
import java.io.IOException;
|
|
import java.io.InputStream;
|
|
import java.net.URLEncoder;
|
|
import java.nio.charset.StandardCharsets;
|
|
import java.util.*;
|
|
import java.util.concurrent.ExecutionException;
|
|
import java.util.concurrent.Future;
|
|
|
|
@Api(tags = "工程信息")
|
|
@Slf4j
|
|
@RestController
|
|
@RequestMapping("/pot/preservation")
|
|
public class PreservationController extends BaseController {
|
|
@Autowired
|
|
private ProDataService service;
|
|
|
|
@Autowired
|
|
private ProDataMapper mapper;
|
|
|
|
@Resource(name = "testTaskExecutor")
|
|
private ThreadPoolTaskExecutor testTaskExecutor;
|
|
|
|
@PostMapping("getProjectPreservation")
|
|
@Log(title = "工程管理", menu = "工程管理->工程维护", businessType = BusinessType.QUERY, grade = OperationType.QUERY_BUSINESS, details = "工程维护列表")
|
|
public Map<String,Object> getProjectPreservation(PreservationVo preservationVo) {
|
|
PageHelper.startPage(preservationVo.getPage(), preservationVo.getLimit());
|
|
List<PreservationVo> preservationList = service.getProjectPreservation(preservationVo);
|
|
PageInfo<PreservationVo> pageInfo = new PageInfo<PreservationVo>(preservationList);
|
|
System.out.println("输出分页后的数据:" + pageInfo.getList());
|
|
Map<String, Object> map = new HashMap<String, Object>(16);
|
|
map.put("code", 200);
|
|
map.put("msg", "");
|
|
map.put("count", pageInfo.getTotal());
|
|
map.put("curr", preservationVo.getPage());
|
|
map.put("limit", preservationVo.getLimit());
|
|
map.put("data", pageInfo.getList());
|
|
return map;
|
|
}
|
|
|
|
@PostMapping("getPreservation")
|
|
@Log(title = "工程管理", menu = "工程管理->工程维护", businessType = BusinessType.QUERY, details = "工程维护查看详情", grade = OperationType.QUERY_BUSINESS)
|
|
public PreservationVo getDeviceDetail(String keyId) {
|
|
PreservationVo preservatioVo = null;
|
|
try {
|
|
// String keyId = Aes.aesDecrypt(params);
|
|
preservatioVo = service.getPreservation(keyId);
|
|
return preservatioVo;
|
|
} catch (Exception e) {
|
|
// log.error(e.toString(),e);
|
|
}
|
|
return preservatioVo;
|
|
}
|
|
|
|
@PostMapping("deletePreservation")
|
|
@Log(title = "工程管理", menu = "工程管理->工程维护", businessType = BusinessType.DELETE, details = "删除工程维护", grade = OperationType.DELETE_BUSINESS)
|
|
public ReturnCodeEntity deletePreservation(String keyId) {
|
|
ReturnCodeEntity entity = new ReturnCodeEntity();
|
|
try {
|
|
// String keyId = Aes.aesDecrypt(params);
|
|
entity = service.deletePreservation(keyId);
|
|
} catch (Exception e) {
|
|
entity.setCode("202");
|
|
entity.setMsg("解析异常,请联系管理员");
|
|
}
|
|
return entity;
|
|
}
|
|
|
|
@PostMapping("batchDeletePreservation")
|
|
@Log(title = "工程管理", menu = "工程管理->工程维护", businessType = BusinessType.DELETE, details = "批量删除工程维护", grade = OperationType.DELETE_BUSINESS)
|
|
public ReturnCodeEntity batchDeletePreservation(String keyId) {
|
|
ReturnCodeEntity entity = new ReturnCodeEntity();
|
|
try {
|
|
if(keyId.equals("")){
|
|
entity.setCode("202");
|
|
entity.setMsg("请选中,再进行批量删除");
|
|
}else {
|
|
List<String> list = Arrays.asList(keyId.split(";"));
|
|
entity = service.batchDeletePreservation(list);
|
|
}
|
|
} catch (Exception e) {
|
|
entity.setCode("202");
|
|
entity.setMsg("解析异常,请联系管理员");
|
|
}
|
|
return entity;
|
|
}
|
|
|
|
@PostMapping("deleteAllPreservation")
|
|
@Log(title = "工程管理", menu = "工程管理->工程维护", businessType = BusinessType.DELETE, details = "全部删除工程维护", grade = OperationType.DELETE_BUSINESS)
|
|
public ReturnCodeEntity deleteAllPreservation(PreservationVo preservationVo) {
|
|
ReturnCodeEntity entity = new ReturnCodeEntity();
|
|
try {
|
|
// String keyId = Aes.aesDecrypt(params);
|
|
entity = service.deleteAllPreservation(preservationVo);
|
|
} catch (Exception e) {
|
|
entity.setCode("202");
|
|
entity.setMsg("解析异常,请联系管理员");
|
|
}
|
|
return entity;
|
|
}
|
|
|
|
@PostMapping("insertPreservation")
|
|
@Log(title = "工程管理", menu = "工程管理->工程维护", businessType = BusinessType.INSERT, details = "新增工程维护", grade = OperationType.ADD_BUSINESS)
|
|
public ReturnCodeEntity insertPreservation(PreservationVo preservationVo) {
|
|
ReturnCodeEntity entity = new ReturnCodeEntity();
|
|
try {
|
|
entity = service.insertPreservation(preservationVo);
|
|
} catch (Exception e) {
|
|
entity.setCode("202");
|
|
entity.setMsg("解析异常,请联系管理员");
|
|
}
|
|
return entity;
|
|
}
|
|
|
|
@PostMapping("updatePreservation")
|
|
@Log(title = "工程管理", menu = "工程管理->工程维护", businessType = BusinessType.UPDATE, details = "修改工程维护", grade = OperationType.UPDATE_BUSINESS)
|
|
public ReturnCodeEntity updatePreservation(PreservationVo preservationVo) {
|
|
ReturnCodeEntity entity = new ReturnCodeEntity();
|
|
try {
|
|
entity = service.updatePreservation(preservationVo);
|
|
} catch (Exception e) {
|
|
entity.setCode("202");
|
|
entity.setMsg("解析异常,请联系管理员");
|
|
}
|
|
return entity;
|
|
}
|
|
|
|
@PostMapping("/importExcel")
|
|
public void importExcel(MultipartFile file, HttpServletRequest request, HttpServletResponse response) throws IOException {
|
|
try {
|
|
CommonsMultipartResolver multipartResolver = new CommonsMultipartResolver();
|
|
MultipartHttpServletRequest multiReq = multipartResolver.resolveMultipart(request);
|
|
// 违章类型id
|
|
List<JSONObject> lstObj = ImportExcelUtils.readExcel(file, PreservationController.class, null);
|
|
List<PreservationVo> list = new ArrayList<>();
|
|
List<JSONObject> lstError = new ArrayList<>();
|
|
// 验证表格中的数据是否重复
|
|
// List<JSONObject> errList = dataIsRepeat(lstObj);
|
|
|
|
if (lstObj != null && lstObj.size() > 0) {
|
|
list = new ArrayList<>();
|
|
lstError = new ArrayList<>();
|
|
for (JSONObject obj : lstObj) {
|
|
String rowRow = obj.getString("rowNo");
|
|
// if (StringHelper.isEmpty(obj.getString("unit"))) {
|
|
// addError(lstError, rowRow, "单位", "", "单位不能为空");
|
|
// continue;
|
|
// }
|
|
// if (StringHelper.isEmpty(obj.getString("pro_name"))) {
|
|
// addError(lstError, rowRow, "工程名称", "", "工程名称不能为空");
|
|
// continue;
|
|
// }
|
|
// else {
|
|
// PreservationVo preservationVo = new PreservationVo();
|
|
// preservationVo.setPro_name(obj.getString("pro_name"));
|
|
// int num = mapper.getNumByPro_name(preservationVo);
|
|
// if (num > 0) {
|
|
// addError(lstError, rowRow, "工程名称", obj.getString("pro_name"), "工程名称已存在");
|
|
// continue;
|
|
// }
|
|
// }
|
|
PreservationVo vo = new PreservationVo();
|
|
vo.setUnit(obj.getString("unit"));
|
|
vo.setAq_code(obj.getString("aq_code"));
|
|
vo.setPro_name(obj.getString("pro_name"));
|
|
vo.setZsgcfw(obj.getString("zsgcfw"));
|
|
vo.setGcgm(obj.getString("gcgm"));
|
|
vo.setAqzj(obj.getString("aqzj"));
|
|
vo.setOrg(obj.getString("org"));
|
|
vo.setJldw(obj.getString("jldw"));
|
|
vo.setSgdw(obj.getString("sgdw"));
|
|
vo.setGcwz(obj.getString("gcwz"));
|
|
vo.setJhkgsj(obj.getString("jhkgsj"));
|
|
vo.setJhjgsj(obj.getString("jhjgsj"));
|
|
vo.setGcjd(obj.getString("gcjd"));
|
|
vo.setGczt(obj.getString("gczt"));
|
|
vo.setRisklevel(obj.getString("risklevel"));
|
|
vo.setRisk_ly(obj.getString("risk_ly"));
|
|
vo.setUpdate_time(obj.getString("update_time"));//统一视频code
|
|
vo.setNext_time(obj.getString("next_time"));//
|
|
vo.setNext_import(obj.getString("next_import"));
|
|
vo.setRemarks(obj.getString("remarks"));
|
|
list.add(vo);
|
|
}
|
|
}
|
|
// lstError.addAll(errList);
|
|
ResultModel resultModel = new ResultModel();
|
|
// if (lstError != null && lstError.size() > 0) {
|
|
// resultModel.setSuccess(false);
|
|
// resultModel.setStatus(200);
|
|
// resultModel.setMsg("导入成功");
|
|
// resultModel.setData(lstError);
|
|
// } else if (lstError.size() == 0) {
|
|
// service.addImportData(list);
|
|
// resultModel.setSuccess(true);
|
|
// resultModel.setStatus(200);
|
|
// resultModel.setMsg("导入成功");
|
|
// resultModel.setData(null);
|
|
// }
|
|
service.addImportData(list);
|
|
resultModel.setSuccess(true);
|
|
resultModel.setStatus(200);
|
|
resultModel.setMsg("导入成功");
|
|
resultModel.setData(null);
|
|
sendJson(response, resultModel);
|
|
} catch (Exception ex) {
|
|
ex.printStackTrace();
|
|
resultModel = new ResultModel();
|
|
resultModel.setSuccess(false);
|
|
resultModel.setStatus(1000);
|
|
resultModel.setMsg(ex.getMessage());
|
|
sendJson(response, resultModel);
|
|
}
|
|
}
|
|
|
|
// public List<JSONObject> dataIsRepeat(List<JSONObject> lstObj) throws ExecutionException, InterruptedException {
|
|
// List<JSONObject> errorList = new ArrayList<JSONObject>();
|
|
// List<String> list1 = new ArrayList<String>();
|
|
//
|
|
// Future<List<JSONObject>> future = testTaskExecutor.submit(() -> {
|
|
// List<JSONObject> errList1 = new ArrayList<JSONObject>();
|
|
// for (JSONObject obj : lstObj) {
|
|
// if (StringUtils.isNotBlank(obj.getString("pro_name"))) {
|
|
// list1.add(obj.getString("pro_name"));
|
|
// } else {
|
|
// list1.add("");
|
|
// }
|
|
// }
|
|
// List<JSONObject> same1 = same(list1);
|
|
// same1.forEach(item -> {
|
|
// List<Object> errorRow = new ArrayList<>();
|
|
// String[] rowNos = item.getString("rowNo").split(",");
|
|
// for (int i = 0; i < rowNos.length; i++) {
|
|
// errorRow.add(lstObj.get(Integer.parseInt(rowNos[i]) - 1).getString("rowNo"));
|
|
// }
|
|
// JSONObject error = new JSONObject();
|
|
// error.put("errorRow", StringUtils.join(errorRow, ","));
|
|
// error.put("errorLine", "工程名称");
|
|
// error.put("errorData", item.getString("pro_name"));
|
|
// error.put("errorMsg", "工程名称重复,重复行:" + StringUtils.join(errorRow, ","));
|
|
// errList1.add(error);
|
|
// });
|
|
// return errList1;
|
|
// });
|
|
// errorList.addAll(future.get());
|
|
// return errorList;
|
|
// }
|
|
//
|
|
// public void addError(List<JSONObject> lstError, String errorRow, String errorLine, String errorData, String errorMsg) {
|
|
// JSONObject error = new JSONObject();
|
|
// error.put("errorRow", errorRow);
|
|
// error.put("errorLine", errorLine);
|
|
// error.put("errorData", errorData);
|
|
// error.put("errorMsg", errorMsg);
|
|
// lstError.add(error);
|
|
//
|
|
// }
|
|
// public static List<JSONObject> same(List<String> list) {
|
|
// List<JSONObject> errList = new ArrayList<JSONObject>();
|
|
// Map<String, String> map = new HashMap<String, String>();
|
|
// for (int i = 0; i < list.size(); i++) {
|
|
// String key = list.get(i);
|
|
// if (key == null || Objects.equals("", key)) {
|
|
// continue;
|
|
// }
|
|
// String old = map.get(key);
|
|
// if (old != null) {
|
|
// map.put(key, old + "," + (i + 1));
|
|
// } else {
|
|
// map.put(key, "" + (i + 1));
|
|
// }
|
|
// }
|
|
// Iterator<String> it = map.keySet().iterator();
|
|
// while (it.hasNext()) {
|
|
// String key = it.next();
|
|
// String value = map.get(key);
|
|
// if (value.indexOf(",") != -1) {
|
|
// JSONObject error = new JSONObject();
|
|
// error.put("data", key);
|
|
// error.put("rowNo", value);
|
|
// System.out.println(key + " 重复,行: " + value);
|
|
// errList.add(error);
|
|
// }
|
|
// }
|
|
// return errList;
|
|
// }
|
|
|
|
@GetMapping("exportPreservation")
|
|
@Log(title = "工程管理", menu = "工程管理->工程维护", businessType = BusinessType.EXPORT, details = "导出工程维护", grade = OperationType.EXPORT_BUSINESS)
|
|
public void exportPreservation(HttpServletResponse response, PreservationVo preservationVo) {
|
|
List<PreservationVo> studentsList = service.getProjectPreservation(preservationVo);
|
|
ExcelUtil<PreservationVo> util = new ExcelUtil<PreservationVo>(PreservationVo.class);
|
|
util.exportExcel(response, studentsList, "工程维护");
|
|
}
|
|
|
|
@ApiOperation("模板下载")
|
|
@GetMapping("/downloadExcel")
|
|
@Log(title = "工程管理", menu = "工程管理->工程维护", businessType = BusinessType.QUERY, details = "模板下载", grade = OperationType.DOWNLOAD_BUSINESS)
|
|
public void downloadExcel(HttpServletRequest request, HttpServletResponse response) {
|
|
InputStream inputStream = null;
|
|
ServletOutputStream servletOutputStream = null;
|
|
try {
|
|
String path = "download/" + "preservation.xlsx";
|
|
inputStream = this.getClass().getClassLoader().getResourceAsStream(path);
|
|
response.setContentType("application/vnd.ms-excel");
|
|
response.addHeader("Cache-Control", "no-cache, no-store, must-revalidate");
|
|
response.addHeader("charset", "utf-8");
|
|
response.addHeader("Pragma", "no-cache");
|
|
String encodeName = URLEncoder.encode("工程维护导入摸板.xlsx", StandardCharsets.UTF_8.toString());
|
|
response.setHeader("Content-Disposition", "attachment; filename=\"" + encodeName + "\"; filename*=utf-8''" + encodeName);
|
|
servletOutputStream = response.getOutputStream();
|
|
IOUtils.copy(inputStream, servletOutputStream);
|
|
response.flushBuffer();
|
|
//log.info("文件下载成功!!");
|
|
} catch (Exception e) {
|
|
e.printStackTrace();
|
|
} finally {
|
|
try {
|
|
if (servletOutputStream != null) {
|
|
servletOutputStream.close();
|
|
}
|
|
if (inputStream != null) {
|
|
inputStream.close();
|
|
}
|
|
} catch (Exception e) {
|
|
e.printStackTrace();
|
|
}
|
|
}
|
|
}
|
|
}
|