TApproveReserveInvoiceController.java 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  1. package com.ruoyi.project.invoice.controller;
  2. import com.ruoyi.common.utils.DateUtils;
  3. import com.ruoyi.common.utils.poi.ExcelUtil;
  4. import com.ruoyi.framework.aspectj.lang.annotation.Log;
  5. import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
  6. import com.ruoyi.framework.web.controller.BaseController;
  7. import com.ruoyi.framework.web.domain.AjaxResult;
  8. import com.ruoyi.framework.web.page.TableDataInfo;
  9. import com.ruoyi.project.approve.damain.DevTask;
  10. import com.ruoyi.project.invoice.domain.TApproveReserveInvoice;
  11. import com.ruoyi.project.invoice.domain.TInvoiceBookingworkticket;
  12. import com.ruoyi.project.invoice.service.ITApproveReserveInvoiceService;
  13. import com.ruoyi.project.invoice.service.ITInvoiceBookingworkticketService;
  14. import org.activiti.engine.ProcessEngine;
  15. import org.activiti.engine.ProcessEngines;
  16. import org.activiti.engine.RuntimeService;
  17. import org.activiti.engine.TaskService;
  18. import org.activiti.engine.impl.identity.Authentication;
  19. import org.activiti.engine.runtime.ProcessInstance;
  20. import org.activiti.engine.task.Task;
  21. import org.springframework.beans.factory.annotation.Autowired;
  22. import org.springframework.web.bind.annotation.*;
  23. import java.util.*;
  24. /**
  25. * 预约开票申请Controller
  26. *
  27. * @author ruoyi
  28. * @date 2022-08-29
  29. */
  30. @RestController
  31. @RequestMapping("/approve/invoice")
  32. public class TApproveReserveInvoiceController extends BaseController {
  33. @Autowired
  34. private ITApproveReserveInvoiceService tApproveReserveInvoiceService;
  35. @Autowired
  36. private ITInvoiceBookingworkticketService workService;
  37. @Autowired
  38. private TaskService taskService;
  39. @Autowired
  40. private RuntimeService runtimeService;
  41. /**
  42. * 查询预约开票申请列表
  43. */
  44. @GetMapping("/list")
  45. public TableDataInfo list(TApproveReserveInvoice tApproveReserveInvoice) {
  46. startPage();
  47. List<TApproveReserveInvoice> list = tApproveReserveInvoiceService.selectTApproveReserveInvoiceList(tApproveReserveInvoice);
  48. for (TApproveReserveInvoice tApprove : list) {
  49. String[] ids;
  50. ids = tApprove.getInvoiceId().split(",");
  51. List<Object> devList = new ArrayList<>();
  52. for (String id : ids) {
  53. TInvoiceBookingworkticket book = workService.getById(id);
  54. devList.add(book);
  55. }
  56. tApprove.setDevList(devList);
  57. }
  58. return getDataTable(list);
  59. }
  60. /**
  61. * 导出预约开票申请列表
  62. */
  63. @Log(title = "预约开票申请", businessType = BusinessType.EXPORT)
  64. @GetMapping("/export")
  65. public AjaxResult export(TApproveReserveInvoice tApproveReserveInvoice) {
  66. List<TApproveReserveInvoice> list = tApproveReserveInvoiceService.selectTApproveReserveInvoiceList(tApproveReserveInvoice);
  67. ExcelUtil<TApproveReserveInvoice> util = new ExcelUtil<TApproveReserveInvoice>(TApproveReserveInvoice.class);
  68. return util.exportExcel(list, "invoice");
  69. }
  70. /**
  71. * 获取预约开票申请详细信息
  72. */
  73. @GetMapping(value = "/{id}")
  74. public AjaxResult getInfo(@PathVariable("id") Long id) {
  75. TApproveReserveInvoice tApprove = tApproveReserveInvoiceService.selectTApproveReserveInvoiceById(id);
  76. String[] ids;
  77. ids = tApprove.getInvoiceId().split(",");
  78. List<Object> devList = new ArrayList<>();
  79. for (String inId : ids) {
  80. TInvoiceBookingworkticket book = workService.getById(inId);
  81. devList.add(book);
  82. }
  83. tApprove.setDevList(devList);
  84. return AjaxResult.success(tApprove);
  85. }
  86. /**
  87. * 新增预约开票申请
  88. */
  89. @Log(title = "预约开票申请", businessType = BusinessType.INSERT)
  90. @PostMapping
  91. public AjaxResult add(@RequestBody TApproveReserveInvoice tApproveReserveInvoice) {
  92. Long userid = getUserId();
  93. tApproveReserveInvoice.setUserId(userid);
  94. tApproveReserveInvoice.setApNo(DateUtils.dateTimeNow() + userid);
  95. Authentication.setAuthenticatedUserId(userid.toString());
  96. tApproveReserveInvoiceService.insertTApproveReserveInvoice(tApproveReserveInvoice);
  97. long bussniseeKey = tApproveReserveInvoice.getId();
  98. String[] ids;
  99. ids = tApproveReserveInvoice.getInvoiceId().split(",");
  100. for (String id : ids) {
  101. TInvoiceBookingworkticket invoice = workService.getById(id);
  102. invoice.setStatus(1L);
  103. workService.updateById(invoice);
  104. }
  105. //开始工作流、监听
  106. Map<String, Object> variables = new HashMap<>();
  107. variables.put("applyUser", userid.toString());
  108. variables.put("yhzgusers", tApproveReserveInvoice.getUserSupId());//用户主管
  109. variables.put("zzzgusers", tApproveReserveInvoice.getDevSupId());//装置主管
  110. if ("1".equals(tApproveReserveInvoice.getIsToday()))
  111. variables.put("zzgcsusers", tApproveReserveInvoice.getDevEngineerId());//装置工程师
  112. if ("1".equals(tApproveReserveInvoice.getIsSpecial()))
  113. variables.put("zzjlusers", tApproveReserveInvoice.getManagerconId());//装置经理
  114. variables.put("bzusers", tApproveReserveInvoice.getMonitorId());//装置经理
  115. //采用key来启动流程定义并设置流程变量,返回流程实例
  116. ProcessInstance pi = runtimeService.startProcessInstanceByKey("reserveInvoice", String.valueOf(bussniseeKey), variables);
  117. logger.info("流程部署id:" + pi.getDeploymentId());
  118. logger.info("流程定义id:" + pi.getProcessDefinitionId());
  119. logger.info("流程实例id:" + pi.getProcessInstanceId());
  120. tApproveReserveInvoice.setProcessId(pi.getProcessInstanceId());
  121. tApproveReserveInvoiceService.updateTApproveReserveInvoice(tApproveReserveInvoice);
  122. return AjaxResult.success();
  123. }
  124. @Log(title = "预约开票审核处理", businessType = BusinessType.UPDATE)
  125. @PutMapping("/handle")
  126. public AjaxResult handle(@RequestBody DevTask devTask) {
  127. //流程审批意见
  128. String symbol = "";
  129. if (devTask.getComment() != "") {
  130. symbol = ",";
  131. }
  132. //使用任务服务完成任务(提交任务)
  133. String taskId = devTask.getTaskId();
  134. // 使用任务id,获取任务对象,获取流程实例id
  135. Task task = taskService.createTaskQuery().taskId(taskId).singleResult();
  136. //利用任务对象,获取流程实例id
  137. String processInstancesId = task.getProcessInstanceId();
  138. TApproveReserveInvoice invoice = tApproveReserveInvoiceService.selectTApproveReserveInvoiceById(Long.parseLong(devTask.getBusinessKey()));
  139. if (devTask.getCondition().equals("1")) {
  140. devTask.setComment("通过" + symbol + devTask.getComment());
  141. invoice.setStatus(2L);
  142. invoice.setEnddate(new Date());
  143. } else if (devTask.getCondition().equals("0")) {
  144. devTask.setComment("未通过" + symbol + devTask.getComment());
  145. invoice.setStatus(3L);
  146. invoice.setEnddate(new Date());
  147. }
  148. String[] ids;
  149. ids = invoice.getInvoiceId().split(",");
  150. for (String id : ids) {
  151. TInvoiceBookingworkticket invoiceBook = workService.getById(id);
  152. if (devTask.getCondition().equals("1")&&task.getName().equals("各班班长、开票人员确认、整合信息关联至CTS系统")) {
  153. invoiceBook.setStatus(3L);
  154. } else if (devTask.getCondition().equals("0")) {
  155. invoiceBook.setStatus(5L);
  156. }
  157. workService.updateById(invoiceBook);
  158. }
  159. Map<String, Object> param = new HashMap<>();
  160. param.put("condition", devTask.getCondition());
  161. param.put("message", "否");
  162. ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();
  163. TaskService taskService = processEngine.getTaskService();
  164. //认领任务
  165. processEngine.getTaskService()
  166. .claim(taskId, getUserId().toString());
  167. taskService.addComment(taskId, processInstancesId, devTask.getComment());
  168. taskService.complete(taskId, param);
  169. tApproveReserveInvoiceService.updateTApproveReserveInvoice(invoice);
  170. return AjaxResult.success();
  171. }
  172. /**
  173. * 修改预约开票申请
  174. */
  175. @Log(title = "预约开票申请", businessType = BusinessType.UPDATE)
  176. @PutMapping
  177. public AjaxResult edit(@RequestBody TApproveReserveInvoice tApproveReserveInvoice) {
  178. return toAjax(tApproveReserveInvoiceService.updateTApproveReserveInvoice(tApproveReserveInvoice));
  179. }
  180. /**
  181. * 删除预约开票申请
  182. */
  183. @Log(title = "预约开票申请", businessType = BusinessType.DELETE)
  184. @DeleteMapping("/{ids}")
  185. public AjaxResult remove(@PathVariable Long[] ids) {
  186. return toAjax(tApproveReserveInvoiceService.deleteTApproveReserveInvoiceByIds(ids));
  187. }
  188. }