123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458 |
- package com.ruoyi.project.pssr.controller;
- import com.alibaba.fastjson.JSON;
- import com.ruoyi.common.utils.DateUtils;
- import com.ruoyi.common.utils.file.ExcelUtils;
- import com.ruoyi.common.utils.poi.ExcelUtil;
- import com.ruoyi.framework.aspectj.lang.annotation.Log;
- import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
- import com.ruoyi.framework.web.controller.BaseController;
- import com.ruoyi.framework.web.domain.AjaxResult;
- import com.ruoyi.framework.web.page.TableDataInfo;
- import com.ruoyi.project.apply.domain.TApplyLock;
- import com.ruoyi.project.apply.service.ITApplyLockService;
- import com.ruoyi.project.pssr.domain.TPssrApprove;
- import com.ruoyi.project.pssr.domain.TPssrLock;
- import com.ruoyi.project.pssr.domain.TPssrSubcontent;
- import com.ruoyi.project.pssr.domain.TPssrTurndown;
- import com.ruoyi.project.pssr.mapper.TPssrLockMapper;
- import com.ruoyi.project.pssr.service.*;
- import com.ruoyi.project.system.domain.SysUser;
- import com.ruoyi.project.system.service.ISysUserService;
- import org.activiti.engine.ProcessEngine;
- import org.activiti.engine.ProcessEngines;
- import org.activiti.engine.TaskService;
- import org.activiti.engine.task.Task;
- import org.apache.commons.collections4.CollectionUtils;
- import org.apache.poi.ss.usermodel.Cell;
- import org.apache.poi.ss.usermodel.CellStyle;
- import org.apache.poi.ss.usermodel.Row;
- import org.apache.poi.xssf.usermodel.XSSFSheet;
- import org.apache.poi.xssf.usermodel.XSSFWorkbook;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.security.access.prepost.PreAuthorize;
- import org.springframework.web.bind.annotation.*;
- import javax.annotation.Resource;
- import java.io.FileOutputStream;
- import java.io.IOException;
- import java.io.InputStream;
- import java.io.OutputStream;
- import java.util.*;
- /**
- * 锁开锁关阀门状态Controller
- *
- * @author ssy
- * @date 2024-09-18
- */
- @RestController
- @RequestMapping("/pssr/lock")
- public class TPssrLockController extends BaseController {
- @Autowired
- private ITPssrFileService tPssrFileService;
- @Resource
- private TPssrLockMapper tPssrLockMapper;
- @Autowired
- private ITPssrTurndownService tPssrTurndownService;
- @Autowired
- private ITPssrLockService tPssrLockService;
- @Autowired
- private ITPssrApproveService tPssrApproveService;
- @Autowired
- private ITPssrSubcontentService tPssrSubcontentService;
- @Autowired
- private ITPssrAboveallService tPssrAboveallService;
- @Autowired
- private ITApplyLockService tApplyLockService;
- @Autowired
- private ISysUserService sysUserService;
- private String forShort = "sksgfmzt";
- /**
- * 查询锁开锁关阀门状态列表
- */
- @PreAuthorize("@ss.hasPermi('pssr:lock:list')")
- @GetMapping("/list")
- public TableDataInfo list(TPssrLock tPssrLock) {
- try {
- TPssrApprove approve = tPssrApproveService.selectTPssrApproveBySubId(tPssrLock.getSubId());
- if (approve != null) {
- ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();
- TaskService taskService = processEngine.getTaskService();
- Task task = processEngine.getTaskService()//获取任务service
- .createTaskQuery()//创建查询对象
- .taskAssignee(getUserId().toString())
- .processInstanceId(approve.getProcessId()).singleResult();
- if (task != null) {
- if (task.getName().equals("确认人1")){
- tPssrLock.setLockeder(getUserId().toString());
- }else if (task.getName().equals("确认人2")){
- tPssrLock.setConfirm(getUserId().toString());
- }
- }
- }
- } catch (Exception e) {
- e.printStackTrace();
- logger.error("待办确认人查询报错:{}",e.getMessage());
- }
- startPage();
- List<TPssrLock> list = tPssrLockService.selectTPssrLockList(tPssrLock);
- list.forEach(item -> {
- item.setFileList(tPssrFileService.selectTPssrFileListByItem(item.getSubId(), item.getId(), "sksgfmzt"));
- if (item.getApproveStatus() != 2)
- item.setReason(tPssrTurndownService.selectTPssrTurndownByItem(item.getSubId(), item.getId(), "sksgfmzt"));
- });
- return getDataTable(list);
- }
- /**
- * 导出锁开锁关阀门状态列表
- */
- @PreAuthorize("@ss.hasPermi('pssr:lock:export')")
- @Log(title = "锁开锁关阀门状态", businessType = BusinessType.EXPORT)
- @GetMapping("/export")
- public AjaxResult export(TPssrLock tPssrLock) {
- List<TPssrLock> list = tPssrLockService.selectTPssrLockList(tPssrLock);
- return AjaxResult.success(exportTmpl(list));
- }
- public String exportTmpl(List<TPssrLock> list) {
- OutputStream out = null;
- String filename = null;
- try {
- String tempUrl = "static/word/pssr/sksgfmzt.xlsx"; // 模板文件
- InputStream is = null;
- is = Thread.currentThread().getContextClassLoader().getResourceAsStream(tempUrl);
- XSSFWorkbook wb = null;
- wb = new XSSFWorkbook(is);
- XSSFSheet sheet = wb.getSheetAt(0);
- //填充数据
- int rowIndex = 3;
- int num = 1;
- Row originalRow = sheet.getRow(3);
- Cell originalcell = originalRow.getCell(0);
- // 获取单元格样式
- CellStyle originalStyle = originalcell.getCellStyle();
- for (TPssrLock t : list) {
- Row row = sheet.createRow(rowIndex);
- row.setHeight((short) 800);
- row.createCell(0).setCellValue(num);
- row.createCell(1).setCellValue(t.getUnit());
- row.createCell(2).setCellValue(t.getLockPost());
- row.createCell(3).setCellValue(t.getPidNo());
- row.createCell(4).setCellValue(t.getLockCode());
- row.createCell(5).setCellValue(t.getMedium());
- row.createCell(6).setCellValue(t.getPosition());
- row.createCell(7).setCellValue(t.getRiskLevel());
- row.createCell(8).setCellValue(t.getLockSize());
- row.createCell(9).setCellValue(t.getPidStatus());
- row.createCell(10).setCellValue(t.getPositionRight());
- row.createCell(11).setCellValue(t.getStatusRight());
- row.createCell(12).setCellValue(t.getCodeAccord());
- row.createCell(13).setCellValue(t.getFastening());
- row.createCell(14).setCellValue(t.getNoDamage());
- row.createCell(15);
- row.createCell(16);
- try {
- SysUser sysUser = sysUserService.selectUserById(Long.valueOf(t.getLockeder()));
- SysUser sysUser2 = sysUserService.selectUserById(Long.valueOf(t.getConfirm()));
- String confirm1 = sysUser.getSignUrl();
- String confirm2 = sysUser2.getSignUrl();
- ExcelUtils.insertPicture(wb, sheet, confirm1, row.getRowNum(), 15, 1, 1);
- ExcelUtils.insertPicture(wb, sheet, confirm2, row.getRowNum(), 16, 1, 1);
- } catch (NumberFormatException e) {
- throw new RuntimeException(e);
- }
- row.createCell(17).setCellValue(DateUtils.dateTime(t.getConfirmationDate()));
- row.createCell(18).setCellValue(t.getRemarks());
- //渲染样式
- for (int i = 0; i < 19; i++) {
- row.getCell(i).setCellStyle(originalStyle);
- }
- num++;
- rowIndex++;
- }
- filename = "PSSR_09_锁开锁关阀门状态" + ".xlsx";
- out = new FileOutputStream(ExcelUtil.getAbsoluteFile(filename));
- wb.write(out);
- wb.close();
- } catch (IOException e) {
- e.printStackTrace();
- }
- return filename;
- }
- /**
- * 获取锁开锁关阀门状态详细信息
- */
- @PreAuthorize("@ss.hasPermi('pssr:lock:query')")
- @GetMapping(value = "/{id}")
- public AjaxResult getInfo(@PathVariable("id") Long id) {
- TPssrLock item = tPssrLockService.selectTPssrLockById(id);
- item.setFileList(tPssrFileService.selectTPssrFileListByItem(item.getSubId(), item.getId(), "sksgfmzt"));
- if (item.getApproveStatus() != 2)
- item.setReason(tPssrTurndownService.selectTPssrTurndownByItem(item.getSubId(), item.getId(), "sksgfmzt"));
- return AjaxResult.success(item);
- }
- /**
- * 新增锁开锁关阀门状态
- */
- @PreAuthorize("@ss.hasPermi('pssr:lock:add')")
- @Log(title = "锁开锁关阀门状态", businessType = BusinessType.INSERT)
- @PostMapping
- public AjaxResult add(@RequestBody TPssrLock tPssrLock) {
- Set<String> codes = new HashSet<>();
- Set<String> pids = new HashSet<>();
- boolean flag = true;
- for (String pidNo : tPssrLock.getPidNos()) {
- TApplyLock tApplyLock = new TApplyLock();
- tApplyLock.setPidNo(pidNo);
- for (TApplyLock applyLock : tApplyLockService.selectTApplyLockList(tApplyLock)) {
- if (applyLock.getStatus() == 0) {
- TPssrLock lock = new TPssrLock();
- lock.setLockPost(applyLock.getLockPost());
- lock.setLockCode(applyLock.getLockCode());
- lock.setMedium(applyLock.getMedium());
- lock.setRiskLevel(applyLock.getRiskLevel());
- lock.setCodeAccord(tPssrLock.getCodeAccord());
- lock.setSubId(tPssrLock.getSubId());
- lock.setUnit(applyLock.getUnit());
- lock.setPidNo(pidNo);
- lock.setPosition(applyLock.getPosition());
- lock.setLockSize(applyLock.getLockSize());
- lock.setPidStatus(applyLock.getValveStatus());
- lock.setLockeder(tPssrLock.getLockeder());
- lock.setFastening(tPssrLock.getFastening());
- lock.setNoDamage(tPssrLock.getNoDamage());
- lock.setConfirm(tPssrLock.getConfirm());
- lock.setApproveStatus(0L);
- insertOrUpdate(lock);
- } else {
- codes.add(applyLock.getLockCode());
- pids.add(pidNo);
- flag = false;
- }
- }
- }
- if (flag) {
- return AjaxResult.success();
- } else {
- return AjaxResult.success("PID图号为" + JSON.toJSONString(pids) + "中,锁编号为" + JSON.toJSONString(codes) + "的锁未完成锁开锁关流程审批!");
- }
- }
- private void insertOrUpdate(TPssrLock tPssrLock) {
- TPssrLock lock = new TPssrLock();
- lock.setSubId(tPssrLock.getSubId());
- lock.setLockCode(tPssrLock.getLockCode());
- List<TPssrLock> tPssrLocks = tPssrLockService.selectTPssrLockList(lock);
- if (CollectionUtils.isNotEmpty(tPssrLocks)) {
- TPssrLock item = tPssrLocks.get(0);
- tPssrLock.setId(item.getId());
- tPssrLockService.updateTPssrLock(tPssrLock);
- } else {
- tPssrLockService.insertTPssrLock(tPssrLock);
- }
- }
- /**
- * 修改锁开锁关阀门状态
- */
- @PreAuthorize("@ss.hasPermi('pssr:lock:edit')")
- @Log(title = "锁开锁关阀门状态", businessType = BusinessType.UPDATE)
- @PutMapping
- public AjaxResult edit(@RequestBody TPssrLock tPssrLock) {
- if (tPssrLock.getLockeder().equals(tPssrLock.getConfirm())){
- return AjaxResult.error("确认人不能为同一人,请重新选择!");
- }
- tPssrFileService.updateFileRelevance(tPssrLock.getFileIds(), "sksgfmzt", tPssrLock.getId(), tPssrLock.getSubId());
- return toAjax(tPssrLockService.updateTPssrLock(tPssrLock));
- }
- /**
- * 修改锁开锁关阀门状态
- */
- @PreAuthorize("@ss.hasPermi('pssr:lock:edit')")
- @Log(title = "锁开锁关阀门状态", businessType = BusinessType.UPDATE)
- @PutMapping("/editBatch")
- public AjaxResult editb(@RequestBody TPssrLock tPssrLock) {
- if (tPssrLock.getLockeder().equals(tPssrLock.getConfirm())){
- return AjaxResult.error("确认人不能为同一人,请重新选择!");
- }
- return toAjax(tPssrLockMapper.updateTPssrLockByIds(tPssrLock));
- }
- /**
- * 锁开锁关确认
- */
- @PreAuthorize("@ss.hasPermi('pssr:lock:edit')")
- @Log(title = "锁开锁关阀门状态", businessType = BusinessType.UPDATE)
- @PutMapping("/confirmLock")
- public AjaxResult confirmLock(@RequestBody TPssrLock tPssrLock) {
- long queryStatus = 0;
- long approveStatus = 0;
- Date date = null;
- TPssrLock lock = new TPssrLock();
- if (tPssrLock.getTaskType() == 4) {
- //上锁确认
- queryStatus = 1;
- approveStatus = 3;
- date = new Date();
- lock.setLockeder(getUserId().toString());
- } else if (tPssrLock.getTaskType() == 5) {
- //确认人确认
- queryStatus = 3;
- approveStatus = 2;
- date = new Date();
- lock.setConfirm(getUserId().toString());
- }
- // 修改锁开锁关状态
- if (tPssrLock.getIds() != null && tPssrLock.getIds().length > 0) {
- for (Long id : tPssrLock.getIds()) {
- TPssrLock item = tPssrLockService.selectTPssrLockById(id);
- item.setApproveStatus(approveStatus);
- if (approveStatus == 2) {
- item.setConfirmationDate(date);
- }
- tPssrLockService.updateTPssrLock(item);
- }
- } else {
- lock.setSubId(tPssrLock.getSubId());
- lock.setApproveStatus(queryStatus);
- for (TPssrLock item : tPssrLockService.selectTPssrLockList(lock)) {
- if (approveStatus == 2) {
- item.setConfirmationDate(date);
- }
- item.setApproveStatus(approveStatus);
- tPssrLockService.updateTPssrLock(item);
- }
- }
- //查询当前待审批的确认人
- TPssrLock entity = new TPssrLock();
- entity.setSubId(tPssrLock.getSubId());
- entity.setApproveStatus(queryStatus);
- for (TPssrLock item : tPssrLockService.selectTPssrLockList(entity)) {
- if (tPssrLock.getTaskType() == 4) {
- if (item.getLockeder().equals(getUserId().toString())) {
- return AjaxResult.success();
- }
- } else if (tPssrLock.getTaskType() == 5) {
- if (item.getConfirm().equals(getUserId().toString())) {
- return AjaxResult.success();
- }
- }
- }
- //无待审批任务结束当前用户流程
- // 因为流程关系所以approve一定会有且只有一条数据
- TPssrApprove tPssrApprove = tPssrApproveService.selectTPssrApproveBySubId(tPssrLock.getSubId());
- TPssrApproveController.handleConfirmApprove(tPssrApprove, getUserId().toString());
- return AjaxResult.success();
- }
- /**
- * 驳回设计变更
- */
- @PutMapping("/turnDownLock")
- public AjaxResult turnDownLock(@RequestBody List<TPssrLock> tPssrLock) {
- if (CollectionUtils.isNotEmpty(tPssrLock)) {
- String userId = getUserId().toString();
- Long subId = tPssrLock.get(0).getSubId();
- // 修改已选择数据的状态
- for (TPssrLock item : tPssrLock) {
- TPssrLock blind = new TPssrLock();
- blind.setId(item.getId());
- blind.setApproveStatus(1L);
- blind.setUpdatedate(new Date());
- blind.setUpdaterCode(getUserId().toString());
- tPssrLockService.updateTPssrLock(blind);
- // 新增驳回原因数据
- TPssrTurndown turndown = new TPssrTurndown();
- turndown.setForShort(forShort);
- turndown.setSubId(item.getSubId());
- turndown.setItemId(item.getId());
- turndown.setReason(item.getReason());
- turndown.setCreatedate(new Date());
- turndown.setCreaterCode(getUserId().toString());
- tPssrTurndownService.insertTPssrTurndown(turndown);
- }
- // 查询当前流程
- TPssrApprove approve = tPssrApproveService.selectTPssrApproveBySubId(subId);
- ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();
- TaskService taskService = processEngine.getTaskService();
- Task task = processEngine.getTaskService()//获取任务service
- .createTaskQuery()//创建查询对象
- .taskAssignee(userId)
- .processInstanceId(approve.getProcessId()).singleResult();
- String taskId = task.getId();
- // 驳回 查询所有待审批的人员
- TPssrLock blind = new TPssrLock();
- blind.setSubId(subId);
- blind.setApproveStatus(1L);
- Set<String> confirm1 = new HashSet<>();
- Set<String> confirm2 = new HashSet<>();
- for (TPssrLock item : tPssrLockService.selectTPssrLockList(blind)) {
- // 确认人1
- confirm1.add(item.getConfirm());
- // 确认人2
- confirm2.add(item.getLockeder());
- }
- //处理流程节点
- Map<String, Object> param = new HashMap<>();
- param.put("condition", 1);
- param.put("confirmUsers1", new ArrayList<>(confirm1));
- param.put("confirmUsers2", new ArrayList<>(confirm2));
- //认领任务
- processEngine.getTaskService().claim(taskId, userId);
- taskService.addComment(taskId, approve.getProcessId(), "驳回");
- taskService.complete(taskId, param);
- // 修改审批表和sub表
- approve.setApproveStatus(1L);
- approve.setUpdatedate(new Date());
- approve.setUpdaterCode(getUserId().toString());
- tPssrApproveService.updateTPssrApprove(approve);
- TPssrSubcontent subcontent = new TPssrSubcontent();
- subcontent.setId(approve.getSubId());
- subcontent.setApproveStatus(1L);
- subcontent.setUpdatedate(new Date());
- subcontent.setUpdaterCode(getUserId().toString());
- tPssrSubcontentService.updateTPssrSubcontent(subcontent);
- return AjaxResult.success();
- }
- return AjaxResult.error();
- }
- /**
- * 删除锁开锁关阀门状态
- */
- @PreAuthorize("@ss.hasPermi('pssr:lock:remove')")
- @Log(title = "锁开锁关阀门状态", businessType = BusinessType.DELETE)
- @DeleteMapping("/{ids}")
- public AjaxResult remove(@PathVariable Long[] ids) {
- return toAjax(tPssrLockService.deleteTPssrLockByIds(ids));
- }
- }
|