IntelligentRecognition/ah-jjsp-service/.svn/pristine/8e/8e08d66a3d63c2a6d18e9ffd3fd...

594 lines
25 KiB
Plaintext
Raw Normal View History

2024-05-24 16:09:40 +08:00
package com.sercurityControl.proteam.dutyTask.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.DateTimeHelper;
import com.securityControl.common.core.web.domain.AjaxResult;
import com.securityControl.common.log.annotation.Log;
import com.securityControl.common.log.enums.BusinessType;
import com.securityControl.common.log.enums.OperationType;
import com.securityControl.common.security.utils.SecurityUtils;
import com.sercurityControl.proteam.dutyTask.domain.*;
import com.sercurityControl.proteam.dutyTask.service.WorkPermitService;
import com.sercurityControl.proteam.util.BaseController;
import com.sercurityControl.proteam.util.ImportExcelHelper;
import com.sercurityControl.proteam.util.InterfaceUtil;
import com.sercurityControl.proteam.util.ResultModel;
import lombok.extern.slf4j.Slf4j;
import org.apache.poi.util.IOUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
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 sun.misc.BASE64Encoder;
import javax.annotation.Resource;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
/**
* 作业许可及销号控制层
*/
@RestController
@RequestMapping("/pot/workPermit/")
@Slf4j
public class WorkPermitController extends BaseController {
Logger logger = LoggerFactory.getLogger(WorkPermitController.class);
@Resource(name = "WorkPermitService")
private WorkPermitService service;
/**
* @return com.securityControl.common.core.web.domain.AjaxResult
* @author cw chen
* @description 作业许可及风险销号数据
* @Param entity
* @date 2023-05-11 10:37
*/
@PostMapping(value = "getWorkPermitAndXhList")
public AjaxResult getWorkPermitAndXhList(WorkPermitAndXhEntity entity) {
try {
List<WorkPermitAndXhEntity> list = new ArrayList<>();
if (Objects.equals("1",entity.getType()) && Objects.equals("", entity.getStatus())) {
// 作业许可-全部
for (int i = 0; i < 3; i++) {
entity.setStatus(i + "");
List<WorkPermitAndXhEntity> list2 = service.getWorkPermitAndXhList(entity);
list.addAll(list2);
}
} else {
// 作业许可/风险销号
List<WorkPermitAndXhEntity> list2 = service.getWorkPermitAndXhList(entity);
list.addAll(list2);
}
return AjaxResult.success("success", list);
} catch (Exception e) {
return AjaxResult.error("服务异常,请稍后重试", null);
}
}
/**
* @return com.securityControl.common.core.web.domain.AjaxResult
* @author cw chen
* @description 作业许可-> 许可和不许可数量
* @Param entity
* @date 2023-07-17 16:31
*/
@PostMapping("getWorkPermitAndXhNum")
public AjaxResult getWorkPermitAndXhNum(WorkPermitAndXhEntity entity) {
Map<String, Object> map = new HashMap<>(16);
try {
map = service.getWorkPermitAndXhNum(entity);
} catch (Exception e) {
logger.error("作业许可-> 许可和不许可数量", e);
map.put("permit", 0);
map.put("notPermit", 0);
map.put("cancel", 0);
map.put("notCancel", 0);
}
return AjaxResult.success("success", map);
}
/**
* @return com.securityControl.common.core.web.domain.AjaxResult
* @author cw chen
* @description 根据作业票id获取准入人员
* @Param entity
* @date 2023-05-12 8:57
*/
@PostMapping(value = "getAccessPeopleByIdList")
public AjaxResult getAccessPeopleByIdList(WorkPermitAndXhEntity entity) {
try {
List<Map<String, String>> list = service.getAccessPeopleByIdList(entity);
Collections.sort(list, new Comparator<Map<String, String>>() {
@Override
public int compare(Map<String, String> o1, Map<String, String> o2) {
String accessInfo = o1.get("accessInfo");
String accessInfo2 = o2.get("accessInfo");
return accessInfo.compareTo(accessInfo2);
}
});
return AjaxResult.success("success", list);
} catch (Exception e) {
return AjaxResult.error("服务异常,请稍后重试", null);
}
}
/**
* @return com.securityControl.common.core.web.domain.AjaxResult
* @author cw chen
* @description 根据作业票id获取班组骨干
* @Param entity
* @date 2023-05-11 15:56
*/
@PostMapping(value = "getBackboneByIdList")
public AjaxResult getBackboneByIdList(WorkPermitAndXhEntity entity) {
try {
List<Map<String, String>> list = service.getBackboneByIdList(entity);
Collections.sort(list, new Comparator<Map<String, String>>() {
@Override
public int compare(Map<String, String> o1, Map<String, String> o2) {
String isPass = o1.get("isPass");
String isPass2 = o2.get("isPass");
return isPass.compareTo(isPass2);
}
});
return AjaxResult.success("success", list);
} catch (Exception e) {
return AjaxResult.error("服务异常,请稍后重试", null);
}
}
/**
* @return java.util.Map<java.lang.String, java.lang.Object>
* @author cw chen
* @description 作业许可及销号->骨干成绩
* @Param entity
* @date 2023-05-08 15:19
*/
@PostMapping(value = "getBackboneScoreList")
@Log(title = "作业许可及销号", menu = "作业许可及销号->骨干成绩", businessType = BusinessType.QUERY, details = "骨干成绩列表")
public Map<String, Object> getBackboneScoreList(BackboneScoreEntity entity) {
PageHelper.startPage(Integer.parseInt(entity.getPage()), Integer.parseInt(entity.getLimit()));
Map<String, Object> map = new HashMap<String, Object>(16);
try {
PageInfo<BackboneScoreEntity> pageInfo = service.getBackboneScoreList(entity);
map.put("code", 200);
map.put("msg", "获取数据成功");
map.put("count", pageInfo.getTotal());
map.put("curr", Integer.parseInt(entity.getPage()));
map.put("limit", Integer.parseInt(entity.getLimit()));
map.put("data", pageInfo.getList());
} catch (Exception e) {
map.put("code", 500);
map.put("msg", "获取数据失败");
map.put("count", 0);
map.put("curr", Integer.parseInt(entity.getPage()));
map.put("limit", Integer.parseInt(entity.getLimit()));
map.put("data", null);
logger.error("数据获取失败", e);
}
return map;
}
/**
* @return void
* @author cw chen
* @description 骨干成绩导入模板下载
* @Param request
* @Param response
* @date 2023-05-08 16:22
*/
@GetMapping("downLoadExcelModel")
@Log(title = "作业许可及销号", menu = "作业许可及销号->骨干成绩", businessType = BusinessType.QUERY, details = "骨干成绩导入模板下载", grade = OperationType.DOWNLOAD_BUSINESS)
public void downLoadExcelModel(HttpServletRequest request, HttpServletResponse response) {
InputStream inputStream = null;
ServletOutputStream servletOutputStream = null;
try {
String path = "download/" + "backbone_score.xls";
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("project_model.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();
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
if (servletOutputStream != null) {
servletOutputStream.close();
}
if (inputStream != null) {
inputStream.close();
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
/**
* @return void
* @author cw chen
* @description 导入骨干成绩
* @Param file
* @Param request
* @Param response
* @date 2023-05-08 16:33
*/
@PostMapping("/importExcel")
@Log(title = "作业许可及销号", menu = "作业许可及销号->骨干成绩", businessType = BusinessType.IMPORT, details = "导入骨干成绩", grade = OperationType.IMPORT_BUSINESS)
public void importExcel(MultipartFile file, HttpServletRequest request, HttpServletResponse response) {
try {
List<JSONObject> lstObj = (List<JSONObject>) ImportExcelHelper.readExcel(file, BackboneScoreEntity.class);
List<BackboneScoreEntity> list = new ArrayList<>();
List<JSONObject> lstError = new ArrayList<>();
String nowTime = DateTimeHelper.getNowTime();
// String regex = "^[1-9]\\d{5}[1-9]\\d{3}((0[1-9])||(1[0-2]))((0[1-9])||(1\\d)||(2\\d)||(3[0-1]))\\d{3}([0-9]||X)$";
// Pattern p = Pattern.compile(regex);
if (lstObj != null && lstObj.size() > 0) {
list = new ArrayList<>();
lstError = new ArrayList<>();
for (JSONObject obj : lstObj) {
if (StringUtils.isBlank(obj.getString("idNumber"))) {
JSONObject error = new JSONObject();
error.put("errorRow", obj.getString("rowNo"));
error.put("errorLine", "身份证号");
error.put("errorData", "");
error.put("errorMsg", "身份证号不能为空");
lstError.add(error);
continue;
}
/*if (!p.matcher(obj.getString("idNumber")).find()) {
JSONObject error = new JSONObject();
error.put("errorRow", obj.getString("rowNo"));
error.put("errorLine", "身份证号");
error.put("errorData", obj.getString("idNumber"));
error.put("errorMsg", "身份证号不合法");
lstError.add(error);
continue;
}*/
BackboneScoreEntity o = new BackboneScoreEntity();
o.setUserCode(obj.getString("userCode"));
o.setUserName(obj.getString("userName"));
o.setIdNumber(obj.getString("idNumber"));
o.setUnit(obj.getString("unit"));
o.setPart(obj.getString("part"));
o.setScore(obj.getString("score"));
o.setQualified(obj.getString("qualified"));
o.setTestTime(obj.getString("testTime"));
o.setEffectiveTime(obj.getString("effectiveTime"));
o.setWorkType(obj.getString("workType"));
o.setPeopleType(obj.getString("peopleType"));
o.setCreateTime(nowTime);
o.setUpdateTime(nowTime);
list.add(o);
}
}
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.addBackboneScore(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("服务异常");
try {
sendJson(response, resultModel);
} catch (IOException e) {
e.printStackTrace();
}
}
}
/**
* @return com.securityControl.common.core.web.domain.AjaxResult
* @author cw chen
* @description 编辑状态
* @Param entity
* @date 2023-05-08 17:49
*/
@PostMapping(value = "editPeopleStatus")
@Log(title = "编辑状态", menu = "作业许可及销号->骨干成绩", businessType = BusinessType.UPDATE, details = "编辑状态")
public AjaxResult editPeopleStatus(BackboneScoreEntity entity) {
try {
entity.setUpdateTime(DateTimeHelper.getNowTime());
service.editPeopleStatus(entity);
return AjaxResult.success("修改成功");
} catch (Exception e) {
logger.error("编辑状态", e);
return AjaxResult.error("服务异常,请稍后重试");
}
}
/**
* @return com.securityControl.common.core.web.domain.AjaxResult
* @author cw chen
* @description 删除/批量删除骨干
* @Param idNumbers
* @date 2023-05-09 9:44
*/
@PostMapping(value = "delPeople")
@Log(title = "删除骨干人员", menu = "作业许可及销号->骨干成绩", businessType = BusinessType.UPDATE, details = "删除骨干人员")
public AjaxResult delPeople(String idNumbers) {
try {
if (StringUtils.isNotBlank(idNumbers)) {
service.delPeople(idNumbers);
return AjaxResult.success("删除成功");
} else {
return AjaxResult.error("未选择骨干人员");
}
} catch (Exception e) {
logger.error("删除骨干人员", e);
return AjaxResult.error("服务异常,请稍后重试");
}
}
@PostMapping("addOrEditPeople")
@Log(title = "新增/修改骨干人员", menu = "作业许可及销号->骨干成绩", businessType = BusinessType.UPDATE, details = "新增/修改骨干人员")
public AjaxResult addOrEditPeople(BackboneScoreEntity entity) {
String regex = "^[1-9][0-9]{5}(19|20)[0-9]{2}((01|03|05|07|08|10|12)(0[1-9]|[1-2][0-9]|31)|(04|06|09|11)(0[1-9]|[1-2][0-9]|30)|02(0[1-9]|[1-2][0-9]))[0-9]{3}([0-9]|x|X)$";
Pattern p = Pattern.compile(regex);
if (!p.matcher(entity.getIdNumber()).find()) {
return AjaxResult.error("身份证号不合法");
}
String nowTime = DateTimeHelper.getNowTime();
entity.setCreateTime(nowTime);
entity.setUpdateTime(nowTime);
try {
int result = service.peopleIsExist(entity);
if (StringUtils.isBlank(entity.getId())) {
// 新增
if (result > 0) {
return AjaxResult.error("骨干人员已存在,请勿重复添加");
} else {
entity.setType(1);
service.addOrEditPeople(entity);
return AjaxResult.success("新增成功");
}
} else {
// 修改
boolean flag = entity.isFlag();
if (!flag) {
if (result > 0) {
return AjaxResult.error("骨干人员已存在,请勿重复修改");
}
entity.setType(2);
service.addOrEditPeople(entity);
} else {
entity.setType(2);
service.addOrEditPeople(entity);
}
return AjaxResult.success("修改成功");
}
} catch (Exception e) {
logger.error("新增/修改骨干人员", e);
return AjaxResult.error("服务异常,请稍后重试");
}
}
/**
* @return com.securityControl.common.core.web.domain.AjaxResult
* @author cw chen
* @description 骨干人员详情
* @Param idNumber
* @date 2023-05-09 10:47
*/
@PostMapping("getPeopleById")
@Log(title = "骨干成绩详情查看", menu = "作业许可及销号->骨干成绩", businessType = BusinessType.QUERY, details = "骨干成绩详情查看")
public AjaxResult getPeopleById(String idNumber) {
try {
BackboneScoreEntity entity = service.getPeopleById(idNumber);
return AjaxResult.success("success", entity);
} catch (Exception e) {
logger.error("骨干成绩详情", e);
return AjaxResult.error("服务异常,请稍后重试", null);
}
}
/**
* @return com.securityControl.common.core.web.domain.AjaxResult
* @author cw chen
* @description 更新作业许可及销号
* @Param o
* @date 2023-05-10 16:04
*/
@PostMapping(value = "updateTicketEssenCondition")
@Log(title = "更新作业许可及销号", menu = "作业许可及销号", businessType = BusinessType.UPDATE, details = "更新作业许可及销号")
public AjaxResult updateTicketEssenCondition(TicketEssenCondition o) {
try {
if (Objects.equals("1", o.getType())) {
o.setPermitTime(DateTimeHelper.getNowTime());
o.setCancelStatus("1");
} else if (Objects.equals("2", o.getType())) {
o.setCancelStatus("2");
} else if (Objects.equals("3", o.getType())) {
o.setCancelStatus("3");
o.setCancelUser(SecurityUtils.getLoginUser().getSysUser().getNickName());
o.setCancelTime(DateTimeHelper.getNowTime());
}
service.updateTicketEssenCondition(o);
return AjaxResult.success("更新成功");
} catch (Exception e) {
logger.error("更新作业许可及销号", e);
return AjaxResult.error("服务异常,请稍后重试", null);
}
}
/**
* @return com.securityControl.common.core.web.domain.AjaxResult
* @author cw chen
* @description 作业许可及销号必备条件详情
* @Param o
* @date 2023-05-10 16:15
*/
@PostMapping(value = "queryTicketEssenCondition")
@Log(title = "作业许可及销号必备条件详情", menu = "作业许可及销号", businessType = BusinessType.QUERY, details = "作业许可及销号必备条件详情")
public AjaxResult queryTicketEssenCondition(TicketEssenCondition o) {
try {
TicketEssenCondition entity = service.queryTicketEssenCondition(o);
return AjaxResult.success("success", entity);
} catch (Exception e) {
logger.error("作业许可及销号必备条件详情", e);
return AjaxResult.error("服务异常,请稍后重试", null);
}
}
/**
* @return com.securityControl.common.core.web.domain.AjaxResult
* @author cw chen
* @description 根据文件id获取作业票的base64
* @Param fileId
* @date 2023-05-11 14:05
*/
@PostMapping("getFileById")
public AjaxResult getFileById(String fileId) {
try {
String base64Url = InterfaceUtil.getTicketImageData(fileId);
// String base64Url = encodeBase64File("C:\\Users\\cwchen\\Desktop\\测试pdf文件\\送变电食堂开发.pdf");
return AjaxResult.success("success", base64Url);
} catch (Exception e) {
logger.error("施工方案", e);
return AjaxResult.error("error");
}
}
public static String encodeBase64File(String path) throws Exception {
File file = new File(path);
FileInputStream inputFile = new FileInputStream(file);
byte[] buffer = new byte[inputFile.available()];
inputFile.read(buffer);
inputFile.close();
return new BASE64Encoder().encode(buffer);
}
/**
* @return java.util.Map<java.lang.String, java.lang.Object>
* @author cw chen
* @description 作业票列表
* @Param dto
* @date 2023-06-20 16:22
*/
@PostMapping(value = "getTicketList")
@Log(title = "作业票", menu = "作业票->作业票列表", businessType = BusinessType.QUERY, details = "作业票列表")
public Map<String, Object> getTicketList(TicketDto dto) {
PageHelper.startPage(Integer.parseInt(dto.getPage()), Integer.parseInt(dto.getLimit()));
Map<String, Object> map = new HashMap<String, Object>(16);
try {
PageInfo<TicketVo> pageInfo = service.getTicketList(dto);
map.put("code", 200);
map.put("msg", "获取数据成功");
map.put("count", pageInfo.getTotal());
map.put("curr", Integer.parseInt(dto.getPage()));
map.put("limit", Integer.parseInt(dto.getLimit()));
map.put("data", pageInfo.getList());
} catch (Exception e) {
map.put("code", 500);
map.put("msg", "获取数据失败");
map.put("count", 0);
map.put("curr", Integer.parseInt(dto.getPage()));
map.put("limit", Integer.parseInt(dto.getLimit()));
map.put("data", null);
logger.error("数据获取失败", e);
}
return map;
}
/**
* @return com.securityControl.common.core.web.domain.AjaxResult
* @author cw chen
* @description 地市作业票数量和占比
* @Param dto
* @date 2023-06-20 17:21
*/
@PostMapping(value = "getOrgNumAndRate")
public AjaxResult getOrgNumAndRate(TicketDto dto) {
try {
List<Map<String, Object>> list = service.getOrgNumAndRate(dto);
return AjaxResult.success(list);
} catch (Exception e) {
e.printStackTrace();
logger.error("地市作业票数量和占比", e);
return AjaxResult.success(null);
}
}
@PostMapping(value = "getTicketEssenConditionList")
@Log(title = "作业许可及销号-许可及销号作业票列表", menu = "作业许可及销号->许可及销号作业票列表", businessType = BusinessType.QUERY, details = "许可及销号作业票列表")
public Map<String, Object> getTicketEssenConditionList(TicketEssenConVo entity) {
PageHelper.startPage(Integer.parseInt(entity.getPage()), Integer.parseInt(entity.getLimit()));
Map<String, Object> map = new HashMap<String, Object>(16);
try {
PageInfo<TicketEssenConVo> pageInfo = service.getTicketEssenConditionList(entity);
map.put("code", 200);
map.put("msg", "获取数据成功");
map.put("count", pageInfo.getTotal());
map.put("curr", Integer.parseInt(entity.getPage()));
map.put("limit", Integer.parseInt(entity.getLimit()));
map.put("data", pageInfo.getList());
} catch (Exception e) {
map.put("code", 500);
map.put("msg", "获取数据失败");
map.put("count", 0);
map.put("curr", Integer.parseInt(entity.getPage()));
map.put("limit", Integer.parseInt(entity.getLimit()));
map.put("data", null);
logger.error("数据获取失败", e);
}
return map;
}
/**
* @return com.securityControl.common.core.web.domain.AjaxResult
* @author cw chen
* @description 删除作业销号及许可
* @Param vo
* @date 2023-08-09 9:55
*/
@PostMapping("delData")
public AjaxResult delData(TicketEssenConVo vo) {
try {
service.delData(vo);
return AjaxResult.success("删除成功");
} catch (Exception e) {
logger.error("删除作业销号及许可", e);
return AjaxResult.error("删除失败");
}
}
}