123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332 |
- package com.ruoyi.project.pssr.controller;
- import java.io.FileOutputStream;
- import java.io.IOException;
- import java.io.InputStream;
- import java.io.OutputStream;
- import java.util.*;
- import com.ruoyi.common.utils.DateUtils;
- import com.ruoyi.common.utils.StringUtils;
- import com.ruoyi.common.utils.file.ExcelUtils;
- import com.ruoyi.project.pssr.domain.TPssrApprove;
- import com.ruoyi.project.pssr.domain.TPssrOverhaulExchanger;
- import com.ruoyi.project.pssr.domain.TPssrSubcontent;
- import com.ruoyi.project.pssr.service.ITPssrApproveService;
- import com.ruoyi.project.pssr.service.ITPssrOverhaulExchangerService;
- import com.ruoyi.project.pssr.service.ITPssrSubcontentService;
- import com.ruoyi.project.system.domain.SysUser;
- import com.ruoyi.project.system.service.ISysUserService;
- import org.activiti.engine.HistoryService;
- import org.activiti.engine.RuntimeService;
- import org.activiti.engine.impl.identity.Authentication;
- import org.activiti.engine.runtime.ProcessInstance;
- 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.security.access.prepost.PreAuthorize;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.web.bind.annotation.GetMapping;
- import org.springframework.web.bind.annotation.PostMapping;
- import org.springframework.web.bind.annotation.PutMapping;
- import org.springframework.web.bind.annotation.DeleteMapping;
- import org.springframework.web.bind.annotation.PathVariable;
- import org.springframework.web.bind.annotation.RequestBody;
- import org.springframework.web.bind.annotation.RequestMapping;
- import org.springframework.web.bind.annotation.RestController;
- import com.ruoyi.framework.aspectj.lang.annotation.Log;
- import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
- import com.ruoyi.project.pssr.domain.TPssrOverhaulValve;
- import com.ruoyi.project.pssr.service.ITPssrOverhaulValveService;
- import com.ruoyi.framework.web.controller.BaseController;
- import com.ruoyi.framework.web.domain.AjaxResult;
- import com.ruoyi.common.utils.poi.ExcelUtil;
- import com.ruoyi.framework.web.page.TableDataInfo;
- /**
- * 检修项目-阀门Controller
- *
- * @author ssy
- * @date 2024-09-18
- */
- @RestController
- @RequestMapping("/pssr/overhaulValve")
- public class TPssrOverhaulValveController extends BaseController
- {
- @Autowired
- private ITPssrOverhaulValveService tPssrOverhaulValveService;
- @Autowired
- private ITPssrOverhaulExchangerService tPssrOverhaulExchangerService;
- @Autowired
- private ITPssrApproveService tPssrApproveService;
- @Autowired
- private RuntimeService runtimeService;
- @Autowired
- private HistoryService historyService;
- @Autowired
- private ITPssrSubcontentService tPssrSubcontentService;
- @Autowired
- private ISysUserService sysUserService;
- @PutMapping("/turnDownValve")
- public AjaxResult turnDownValve(@RequestBody TPssrOverhaulValve tPssrOverhaulValve) {
- if (tPssrOverhaulValve.getIds() != null) {
- String userId = getUserId().toString();
- // 修改已选择数据的状态
- for (Long id : tPssrOverhaulValve.getIds()) {
- TPssrOverhaulValve blind = new TPssrOverhaulValve();
- blind.setId(id);
- blind.setApproveStatus(1L);
- blind.setUpdatedate(new Date());
- blind.setUpdaterCode(getUserId().toString());
- tPssrOverhaulValveService.updateTPssrOverhaulValve(blind);
- }
- // 查询当前流程
- TPssrApprove approve = tPssrApproveService.selectTPssrApproveBySubId(tPssrOverhaulValve.getSubId());
- try {
- runtimeService.deleteProcessInstance(approve.getProcessId(), "pssr1confirm");
- historyService.deleteHistoricProcessInstance(approve.getProcessId());
- } catch (Exception e) {
- logger.info("无运行时流程");
- }
- // 驳回 查询所有待审批的人员
- //查询所有确认人
- TPssrOverhaulExchanger exchanger = new TPssrOverhaulExchanger();
- exchanger.setSubId(approve.getSubId());
- exchanger.setApproveStatus(1L);
- TPssrOverhaulExchanger overhaul = tPssrOverhaulExchangerService.selectAllConfirmedPersonBySubId(exchanger);
- String confirmers = null;
- if (overhaul != null) {
- confirmers = overhaul.getConfirmedPerson();
- }
- logger.info("=======================confirmers:{}", confirmers);
- Set<String> confirmUsers1 = new HashSet<>();
- if (StringUtils.isNotEmpty(confirmers)) {
- confirmUsers1.addAll(Arrays.asList(confirmers.split(",")));
- }
- // 开始申请流程
- long businessKey = approve.getApproveId();
- //开始工作流、监听
- Authentication.setAuthenticatedUserId(userId);//设置当前申请人
- Map<String, Object> variables = new HashMap<>();
- variables.put("applyUser", userId);
- variables.put("confirmUsers", new ArrayList<>(confirmUsers1));
- variables.put("chargePerson", approve.getSubCharge());
- //采用key来启动流程定义并设置流程变量,返回流程实例
- ProcessInstance pi = runtimeService.startProcessInstanceByKey("pssr1confirm", String.valueOf(businessKey), variables);
- // 修改审批表和sub表
- approve.setProcessId(pi.getProcessInstanceId());
- 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:overhaulValve:list')")
- @GetMapping("/list")
- public TableDataInfo list(TPssrOverhaulValve tPssrOverhaulValve)
- {
- if ("1".equals(tPssrOverhaulValve.getIdentifyingPerson())){
- tPssrOverhaulValve.setIdentifyingPerson(getUserId().toString());
- }
- startPage();
- List<TPssrOverhaulValve> list = tPssrOverhaulValveService.selectTPssrOverhaulValveList(tPssrOverhaulValve);
- return getDataTable(list);
- }
- /**
- * 导出检修项目-阀门列表
- */
- @PreAuthorize("@ss.hasPermi('pssr:overhaulValve:export')")
- @Log(title = "检修项目-阀门", businessType = BusinessType.EXPORT)
- @GetMapping("/export")
- public AjaxResult export(TPssrOverhaulValve tPssrOverhaulValve)
- {
- List<TPssrOverhaulValve> list = tPssrOverhaulValveService.selectTPssrOverhaulValveList(tPssrOverhaulValve);
- return AjaxResult.success(exportTmpl(list));
- }
- public String exportTmpl(List<TPssrOverhaulValve> list) {
- OutputStream out = null;
- String filename = null;
- try {
- String tempUrl = "static/word/pssr/jxxmfm.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 (TPssrOverhaulValve t : list) {
- Row row = sheet.createRow(rowIndex);
- row.setHeight((short) 800);
- row.createCell(0).setCellValue(num);
- row.createCell(1).setCellValue(t.getChangeType());
- row.createCell(2).setCellValue(t.getItem());
- row.createCell(3).setCellValue(t.getPlant());
- row.createCell(4).setCellValue(t.getValvePosition());
- row.createCell(5).setCellValue(t.getType());
- row.createCell(6).setCellValue(t.getPipeSize());
- row.createCell(7).setCellValue(t.getValveClass());
- row.createCell(8).setCellValue(t.getPidNo());
- row.createCell(9).setCellValue(DateUtils.dateTime(t.getDoneDate()));
- row.createCell(10);
- try {
- SysUser sysUser = sysUserService.selectUserById(Long.valueOf(t.getIdentifyingPerson()));
- String confirm1 = sysUser.getSignUrl();
- ExcelUtils.insertPicture(wb, sheet, confirm1, row.getRowNum(), 10, 1, 1);
- } catch (NumberFormatException e) {
- throw new RuntimeException(e);
- }
- row.createCell(11).setCellValue(t.getRemarks());
- //渲染样式
- for (int i = 0; i < 12; i++) {
- row.getCell(i).setCellStyle(originalStyle);
- }
- num++;
- rowIndex++;
- }
- filename = ExcelUtil.encodingFilename("OverhaulValve");
- out = new FileOutputStream(ExcelUtil.getAbsoluteFile(filename));
- wb.write(out);
- wb.close();
- } catch (IOException e) {
- e.printStackTrace();
- }
- return filename;
- }
- /**
- * 获取检修项目-阀门详细信息
- */
- @PreAuthorize("@ss.hasPermi('pssr:overhaulValve:query')")
- @GetMapping(value = "/{id}")
- public AjaxResult getInfo(@PathVariable("id") Long id)
- {
- return AjaxResult.success(tPssrOverhaulValveService.selectTPssrOverhaulValveById(id));
- }
- /**
- * 新增检修项目-阀门
- */
- @PreAuthorize("@ss.hasPermi('pssr:overhaulValve:add')")
- @Log(title = "检修项目-阀门", businessType = BusinessType.INSERT)
- @PostMapping
- public AjaxResult add(@RequestBody TPssrOverhaulValve tPssrOverhaulValve)
- {
- tPssrOverhaulValve.setApproveStatus(0L);
- return toAjax(tPssrOverhaulValveService.insertTPssrOverhaulValve(tPssrOverhaulValve));
- }
- /**
- * 修改检修项目-阀门
- */
- @PreAuthorize("@ss.hasPermi('pssr:overhaulValve:edit')")
- @Log(title = "检修项目-阀门", businessType = BusinessType.UPDATE)
- @PutMapping
- public AjaxResult edit(@RequestBody TPssrOverhaulValve tPssrOverhaulValve)
- {
- return toAjax(tPssrOverhaulValveService.updateTPssrOverhaulValve(tPssrOverhaulValve));
- }
- /**
- * 删除检修项目-阀门
- */
- @PreAuthorize("@ss.hasPermi('pssr:overhaulValve:remove')")
- @Log(title = "检修项目-阀门", businessType = BusinessType.DELETE)
- @DeleteMapping("/{ids}")
- public AjaxResult remove(@PathVariable Long[] ids)
- {
- return toAjax(tPssrOverhaulValveService.deleteTPssrOverhaulValveByIds(ids));
- }
- @PreAuthorize("@ss.hasPermi('pssr:overhaulValve:edit')")
- @Log(title = "检修项目-阀门", businessType = BusinessType.UPDATE)
- @PutMapping("/confirmValve")
- public AjaxResult confirmValve(@RequestBody TPssrOverhaulValve tPssrOverhaulValve) {
- if (tPssrOverhaulValve.getIds() != null && tPssrOverhaulValve.getIds().length > 0) {
- for (Long id : tPssrOverhaulValve.getIds()) {
- TPssrOverhaulValve valve = tPssrOverhaulValveService.selectTPssrOverhaulValveById(id);
- if (valve.getDoneDate()==null){
- valve.setDoneDate(new Date());
- }
- valve.setApproveStatus(2L);
- valve.setUpdatedate(new Date());
- valve.setUpdaterCode(String.valueOf(getUserId()));
- tPssrOverhaulValveService.updateTPssrOverhaulValve(valve);
- }
- } else {
- TPssrOverhaulValve valve = new TPssrOverhaulValve();
- valve.setSubId(tPssrOverhaulValve.getSubId());
- valve.setIdentifyingPerson(getUserId().toString());
- valve.setApproveStatus(1L);
- for (TPssrOverhaulValve overhaulValve : tPssrOverhaulValveService.selectTPssrOverhaulValveList(valve)) {
- if (overhaulValve.getDoneDate()==null){
- overhaulValve.setDoneDate(new Date());
- }
- overhaulValve.setApproveStatus(2L);
- overhaulValve.setUpdatedate(new Date());
- overhaulValve.setUpdaterCode(String.valueOf(getUserId()));
- tPssrOverhaulValveService.updateTPssrOverhaulValve(overhaulValve);
- }
- }
- //查询当前待审批的确认人
- TPssrOverhaulExchanger entity = new TPssrOverhaulExchanger();
- entity.setSubId(tPssrOverhaulValve.getSubId());
- entity.setApproveStatus(1L);
- TPssrOverhaulExchanger exchanger = tPssrOverhaulExchangerService.selectAllConfirmedPersonBySubId(entity);
- if (exchanger!=null) {
- String confirmedPerson = exchanger.getConfirmedPerson();
- logger.info("===========confirmedPerson:{}", confirmedPerson);
- //如果当前用户还有待审批任务
- if (confirmedPerson.contains(getUserId().toString())) {
- return AjaxResult.success();
- }
- }
- //无待审批任务结束当前用户流程
-
- // 因为流程关系所以approve一定会有且只有一条数据
- TPssrApprove tPssrApprove = tPssrApproveService.selectTPssrApproveBySubId(tPssrOverhaulValve.getSubId());
- TPssrApproveController.handleConfirmApprove(tPssrApprove,getUserId().toString());
- return AjaxResult.success();
- }
- }
|