123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241 |
- package com.ruoyi.project.pssr.controller;
- import com.ruoyi.common.utils.StringUtils;
- 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.pssr.domain.*;
- import com.ruoyi.project.pssr.domain.TPssrOverhaulExchanger;
- import com.ruoyi.project.pssr.service.ITPssrApproveService;
- import com.ruoyi.project.pssr.service.ITPssrOverhaulExchangerService;
- import com.ruoyi.project.pssr.service.ITPssrSubcontentService;
- import org.activiti.engine.*;
- import org.activiti.engine.impl.identity.Authentication;
- import org.activiti.engine.runtime.ProcessInstance;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.security.access.prepost.PreAuthorize;
- import org.springframework.web.bind.annotation.*;
- import java.util.*;
- /**
- * 检修项目-换热器Controller
- *
- * @author ssy
- * @date 2024-09-18
- */
- @RestController
- @RequestMapping("/pssr/overhaulExchanger")
- public class TPssrOverhaulExchangerController extends BaseController {
- @Autowired
- private ITPssrOverhaulExchangerService tPssrOverhaulExchangerService;
- @Autowired
- private ITPssrApproveService tPssrApproveService;
- @Autowired
- private RuntimeService runtimeService;
- @Autowired
- private HistoryService historyService;
- @Autowired
- private ITPssrSubcontentService tPssrSubcontentService;
- /**
- * 查询检修项目-换热器列表
- */
- @PreAuthorize("@ss.hasPermi('pssr:overhaulExchanger:list')")
- @GetMapping("/list")
- public TableDataInfo list(TPssrOverhaulExchanger tPssrOverhaulExchanger) {
- if ("1".equals(tPssrOverhaulExchanger.getConfirmedPerson())){
- tPssrOverhaulExchanger.setConfirmedPerson(getUserId().toString());
- }
- startPage();
- List<TPssrOverhaulExchanger> list = tPssrOverhaulExchangerService.selectTPssrOverhaulExchangerList(tPssrOverhaulExchanger);
- return getDataTable(list);
- }
- /**
- * 导出检修项目-换热器列表
- */
- @PreAuthorize("@ss.hasPermi('pssr:overhaulExchanger:export')")
- @Log(title = "检修项目-换热器", businessType = BusinessType.EXPORT)
- @GetMapping("/export")
- public AjaxResult export(TPssrOverhaulExchanger tPssrOverhaulExchanger) {
- List<TPssrOverhaulExchanger> list = tPssrOverhaulExchangerService.selectTPssrOverhaulExchangerList(tPssrOverhaulExchanger);
- ExcelUtil<TPssrOverhaulExchanger> util = new ExcelUtil<TPssrOverhaulExchanger>(TPssrOverhaulExchanger.class);
- return util.exportExcel(list, "overhaulExchanger");
- }
- /**
- * 获取检修项目-换热器详细信息
- */
- @PreAuthorize("@ss.hasPermi('pssr:overhaulExchanger:query')")
- @GetMapping(value = "/{id}")
- public AjaxResult getInfo(@PathVariable("id") Long id) {
- return AjaxResult.success(tPssrOverhaulExchangerService.selectTPssrOverhaulExchangerById(id));
- }
- /**
- * 新增检修项目-换热器
- */
- @PreAuthorize("@ss.hasPermi('pssr:overhaulExchanger:add')")
- @Log(title = "检修项目-换热器", businessType = BusinessType.INSERT)
- @PostMapping
- public AjaxResult add(@RequestBody TPssrOverhaulExchanger tPssrOverhaulExchanger) {
- tPssrOverhaulExchanger.setApproveStatus(0L);
- return toAjax(tPssrOverhaulExchangerService.insertTPssrOverhaulExchanger(tPssrOverhaulExchanger));
- }
- /**
- * 修改检修项目-换热器
- */
- @PreAuthorize("@ss.hasPermi('pssr:overhaulExchanger:edit')")
- @Log(title = "检修项目-换热器", businessType = BusinessType.UPDATE)
- @PutMapping
- public AjaxResult edit(@RequestBody TPssrOverhaulExchanger tPssrOverhaulExchanger) {
- return toAjax(tPssrOverhaulExchangerService.updateTPssrOverhaulExchanger(tPssrOverhaulExchanger));
- }
- /**
- * 删除检修项目-换热器
- */
- @PreAuthorize("@ss.hasPermi('pssr:overhaulExchanger:remove')")
- @Log(title = "检修项目-换热器", businessType = BusinessType.DELETE)
- @DeleteMapping("/{ids}")
- public AjaxResult remove(@PathVariable Long[] ids) {
- return toAjax(tPssrOverhaulExchangerService.deleteTPssrOverhaulExchangerByIds(ids));
- }
- /**
- * 确认检修项目-换热器
- */
- @PreAuthorize("@ss.hasPermi('pssr:overhaulExchanger:edit')")
- @Log(title = "检修项目-换热器", businessType = BusinessType.UPDATE)
- @PutMapping("/confirmExchanger")
- public AjaxResult confirmExchanger(@RequestBody TPssrOverhaulExchanger tPssrOverhaulExchanger) {
- if (tPssrOverhaulExchanger.getIds() != null && tPssrOverhaulExchanger.getIds().length > 0) {
- for (Long id : tPssrOverhaulExchanger.getIds()) {
- TPssrOverhaulExchanger exchanger = tPssrOverhaulExchangerService.selectTPssrOverhaulExchangerById(id);
- if (exchanger.getCompletionDate()==null){
- exchanger.setCompletionDate(new Date());
- }
- exchanger.setApproveStatus(2L);
- exchanger.setUpdatedate(new Date());
- exchanger.setUpdaterCode(String.valueOf(getUserId()));
- tPssrOverhaulExchangerService.updateTPssrOverhaulExchanger(exchanger);
- }
- } else {
- TPssrOverhaulExchanger exchanger = new TPssrOverhaulExchanger();
- exchanger.setSubId(tPssrOverhaulExchanger.getSubId());
- exchanger.setConfirmedPerson(getUserId().toString());
- exchanger.setApproveStatus(1L);
- for (TPssrOverhaulExchanger overhaulExchanger : tPssrOverhaulExchangerService.selectTPssrOverhaulExchangerList(exchanger)) {
- if (overhaulExchanger.getCompletionDate()==null){
- overhaulExchanger.setCompletionDate(new Date());
- }
- overhaulExchanger.setApproveStatus(2L);
- overhaulExchanger.setUpdatedate(new Date());
- overhaulExchanger.setUpdaterCode(String.valueOf(getUserId()));
- tPssrOverhaulExchangerService.updateTPssrOverhaulExchanger(overhaulExchanger);
- }
- }
- //查询当前待审批的确认人
- TPssrOverhaulExchanger entity = new TPssrOverhaulExchanger();
- entity.setSubId(tPssrOverhaulExchanger.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();
- }
- }
- //无待审批任务结束当前用户流程
- TPssrApprove approve = new TPssrApprove();
- approve.setSubId(tPssrOverhaulExchanger.getSubId());
- // 因为流程关系所以approve一定会有且只有一条数据
- TPssrApprove tPssrApprove = tPssrApproveService.selectTPssrApproveList(approve).get(0);
- TPssrApproveController.handleConfirmApprove(tPssrApprove,getUserId().toString());
- return AjaxResult.success();
- }
- @PutMapping("/turnDownExchanger")
- public AjaxResult turnDownExchanger(@RequestBody TPssrOverhaulExchanger tPssrOverhaulExchanger) {
- if (tPssrOverhaulExchanger.getIds() != null) {
- String userId = getUserId().toString();
- // 修改已选择数据的状态
- for (Long id : tPssrOverhaulExchanger.getIds()) {
- TPssrOverhaulExchanger blind = new TPssrOverhaulExchanger();
- blind.setId(id);
- blind.setApproveStatus(1L);
- blind.setUpdatedate(new Date());
- blind.setUpdaterCode(getUserId().toString());
- tPssrOverhaulExchangerService.updateTPssrOverhaulExchanger(blind);
- }
- // 查询当前流程
- TPssrApprove approve = tPssrApproveService.selectTPssrApproveBySubId(tPssrOverhaulExchanger.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();
- }
- }
|