123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262 |
- package com.ruoyi.project.pssr.controller;
- import java.util.*;
- import com.ruoyi.project.pssr.domain.TPssrApprove;
- import com.ruoyi.project.pssr.domain.TPssrSubcontent;
- import com.ruoyi.project.pssr.domain.TPssrLighting;
- import com.ruoyi.project.pssr.service.ITPssrApproveService;
- import com.ruoyi.project.pssr.service.ITPssrSubcontentService;
- import org.activiti.engine.ProcessEngine;
- import org.activiti.engine.ProcessEngines;
- import org.activiti.engine.TaskService;
- import org.activiti.engine.task.Task;
- 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.TPssrLighting;
- import com.ruoyi.project.pssr.service.ITPssrLightingService;
- 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/lighting")
- public class TPssrLightingController extends BaseController
- {
- @Autowired
- private ITPssrLightingService tPssrLightingService;
- @Autowired
- private ITPssrApproveService tPssrApproveService;
- @Autowired
- private ITPssrSubcontentService tPssrSubcontentService;
- /**
- * 查询照明列表
- */
- @PreAuthorize("@ss.hasPermi('pssr:lighting:list')")
- @GetMapping("/list")
- public TableDataInfo list(TPssrLighting tPssrLighting)
- {
- startPage();
- List<TPssrLighting> list = tPssrLightingService.selectTPssrLightingList(tPssrLighting);
- return getDataTable(list);
- }
- /**
- * 导出照明列表
- */
- @PreAuthorize("@ss.hasPermi('pssr:lighting:export')")
- @Log(title = "照明", businessType = BusinessType.EXPORT)
- @GetMapping("/export")
- public AjaxResult export(TPssrLighting tPssrLighting)
- {
- List<TPssrLighting> list = tPssrLightingService.selectTPssrLightingList(tPssrLighting);
- ExcelUtil<TPssrLighting> util = new ExcelUtil<TPssrLighting>(TPssrLighting.class);
- return util.exportExcel(list, "lighting");
- }
- /**
- * 获取照明详细信息
- */
- @PreAuthorize("@ss.hasPermi('pssr:lighting:query')")
- @GetMapping(value = "/{id}")
- public AjaxResult getInfo(@PathVariable("id") Long id)
- {
- return AjaxResult.success(tPssrLightingService.selectTPssrLightingById(id));
- }
- /**
- * 新增照明
- */
- @PreAuthorize("@ss.hasPermi('pssr:lighting:add')")
- @Log(title = "照明", businessType = BusinessType.INSERT)
- @PostMapping
- public AjaxResult add(@RequestBody TPssrLighting tPssrLighting)
- {
- tPssrLighting.setApproveStatus(0L);
- return toAjax(tPssrLightingService.insertTPssrLighting(tPssrLighting));
- }
- /**
- * 修改照明
- */
- @PreAuthorize("@ss.hasPermi('pssr:lighting:edit')")
- @Log(title = "照明", businessType = BusinessType.UPDATE)
- @PutMapping
- public AjaxResult edit(@RequestBody TPssrLighting tPssrLighting)
- {
- return toAjax(tPssrLightingService.updateTPssrLighting(tPssrLighting));
- }
- /**
- * 删除照明
- */
- @PreAuthorize("@ss.hasPermi('pssr:lighting:remove')")
- @Log(title = "照明", businessType = BusinessType.DELETE)
- @DeleteMapping("/{ids}")
- public AjaxResult remove(@PathVariable Long[] ids)
- {
- return toAjax(tPssrLightingService.deleteTPssrLightingByIds(ids));
- }
- /**
- * 确认照明,电伴热
- */
- @PreAuthorize("@ss.hasPermi('pssr:lighting:edit')")
- @Log(title = "照明,电伴热", businessType = BusinessType.UPDATE)
- @PutMapping("/confirmLighting")
- public AjaxResult Lighting(@RequestBody TPssrLighting tPssrLighting) {
- long queryStatus = 0;
- long approveStatus = 0;
- Date date = null;
- if (tPssrLighting.getTaskType() == 4) {
- //拆锁确认
- queryStatus = 1;
- approveStatus = 3;
- date = new Date();
- } else if (tPssrLighting.getTaskType() == 5) {
- //上锁确认
- queryStatus = 3;
- approveStatus = 2;
- date = new Date();
- }
- // 修改状态
- if (tPssrLighting.getIds() != null && tPssrLighting.getIds().length > 0) {
- for (Long id : tPssrLighting.getIds()) {
- TPssrLighting item = tPssrLightingService.selectTPssrLightingById(id);
- item.setApproveStatus(approveStatus);
- if (item.getConfirmationDate()==null && queryStatus==3) {
- item.setConfirmationDate(date);
- }
- tPssrLightingService.updateTPssrLighting(item);
- }
- } else {
- TPssrLighting lock = new TPssrLighting();
- lock.setSubId(tPssrLighting.getSubId());
- lock.setApproveStatus(queryStatus);
- lock.setLightingType(tPssrLighting.getLightingType());
- for (TPssrLighting item : tPssrLightingService.selectTPssrLightingList(lock)) {
- if (item.getConfirmationDate()==null && queryStatus==3) {
- item.setConfirmationDate(date);
- }
- item.setApproveStatus(approveStatus);
- tPssrLightingService.updateTPssrLighting(item);
- }
- }
- //查询当前待审批的确认人
- TPssrLighting entity = new TPssrLighting();
- entity.setSubId(tPssrLighting.getSubId());
- entity.setApproveStatus(queryStatus);
- for (TPssrLighting item : tPssrLightingService.selectTPssrLightingList(entity)) {
- if (tPssrLighting.getTaskType() == 4) {
- if (item.getConfirm1().equals(getUserId().toString())) {
- return AjaxResult.success();
- }
- } else if (tPssrLighting.getTaskType() == 5) {
- if (item.getConfirm2().equals(getUserId().toString())) {
- return AjaxResult.success();
- }
- }
- }
- //无待审批任务结束当前用户流程
- TPssrApprove approve = new TPssrApprove();
- approve.setSubId(tPssrLighting.getSubId());
- // 因为流程关系所以approve一定会有且只有一条数据
- TPssrApprove tPssrApprove = tPssrApproveService.selectTPssrApproveList(approve).get(0);
- TPssrApproveController.handleConfirmApprove(tPssrApprove, getUserId().toString());
- return AjaxResult.success();
- }
- /**
- * 驳回照明,电伴热
- */
- @PutMapping("/turnDownLighting")
- public AjaxResult turnDownLighting(@RequestBody TPssrLighting tPssrLighting) {
- if (tPssrLighting.getIds() != null) {
- String userId = getUserId().toString();
- // 修改已选择数据的状态
- for (Long id : tPssrLighting.getIds()) {
- TPssrLighting blind = new TPssrLighting();
- blind.setId(id);
- blind.setApproveStatus(1L);
- blind.setUpdatedate(new Date());
- blind.setUpdaterCode(getUserId().toString());
- tPssrLightingService.updateTPssrLighting(blind);
- }
- // 查询当前流程
- TPssrApprove approve = tPssrApproveService.selectTPssrApproveBySubId(tPssrLighting.getSubId());
- ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();
- TaskService taskService = processEngine.getTaskService();
- Task task = processEngine.getTaskService()//获取任务service
- .createTaskQuery()//创建查询对象
- .taskAssignee(userId)
- .processInstanceId(approve.getProcessId()).singleResult();
- String taskId = task.getId();
- // 驳回 查询所有待审批的人员
- TPssrLighting blind = new TPssrLighting();
- blind.setSubId(tPssrLighting.getSubId());
- blind.setApproveStatus(1L);
- Set<String> installer = new HashSet<>();
- Set<String> remover = new HashSet<>();
- for (TPssrLighting item : tPssrLightingService.selectTPssrLightingList(blind)) {
- // 安装人员
- installer.add(item.getConfirm1());
- //拆除人员
- remover.add(item.getConfirm2());
- }
- //处理流程节点
- Map<String, Object> param = new HashMap<>();
- param.put("condition", 1);
- param.put("confirmUsers1", new ArrayList<>(installer));
- param.put("confirmUsers2", new ArrayList<>(remover));
- //认领任务
- processEngine.getTaskService().claim(taskId, userId);
- taskService.addComment(taskId, approve.getProcessId(), "驳回至拆除;" + tPssrLighting.getRemarks());
- 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();
- }
- }
|