From 346a022986af7a7938f413751d6a44f82649f2a3 Mon Sep 17 00:00:00 2001 From: haungxing <1203316822@qq.com> Date: Fri, 29 Dec 2023 08:46:20 +0800 Subject: [PATCH] =?UTF-8?q?#=20=E7=BA=BF=E4=B8=8B=E5=B7=A5=E4=BD=9C?= =?UTF-8?q?=E7=A5=A8=E5=B7=A5=E4=BD=9C=E6=B5=81=E7=A8=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../process/constant/TicketProcessConstant.java | 5 + .../feign/IOfflineTicketProcessClient.java | 24 ++++ .../feign/OfflineTicketProcessClientFallback.java | 15 +++ .../serviceimpl/OfflineTicketProcessImpl.java | 41 +++++++ .../hzims-middle/src/main/resources/db/1.0.2.sql | 1 + .../task/service/impl/EventServiceImpl.java | 5 + .../inspect/task/service/impl/TaskServiceImpl.java | 2 +- .../feign/OfflineTicketProcessClient.java | 26 +++++ .../controller/TicketProcessController.java | 5 + .../twoTicket/service/TicketProcessService.java | 8 ++ .../service/impl/FirstWorkTicketServiceImpl.java | 100 +++++++++++----- .../service/impl/TicketProcessServiceImpl.java | 119 +++++++++++++++++++ .../file/线下工作票审批流程.bpmn20.xml | 129 +++++++++++++++++++++ 13 files changed, 448 insertions(+), 32 deletions(-) create mode 100644 hzims-service-api/ticket-api/src/main/java/com/hnac/hzims/ticket/ticketprocess/feign/IOfflineTicketProcessClient.java create mode 100644 hzims-service-api/ticket-api/src/main/java/com/hnac/hzims/ticket/ticketprocess/feign/OfflineTicketProcessClientFallback.java create mode 100644 hzims-service/hzims-middle/src/main/java/com/hnac/hzims/middle/processflow/strategy/serviceimpl/OfflineTicketProcessImpl.java create mode 100644 hzims-service/hzims-middle/src/main/resources/db/1.0.2.sql create mode 100644 hzims-service/ticket/src/main/java/com/hnac/hzims/ticket/redisConsume/feign/OfflineTicketProcessClient.java create mode 100644 hzims-service/ticket/src/main/resources/file/线下工作票审批流程.bpmn20.xml diff --git a/hzims-service-api/middle-api/src/main/java/com/hnac/hzims/middle/process/constant/TicketProcessConstant.java b/hzims-service-api/middle-api/src/main/java/com/hnac/hzims/middle/process/constant/TicketProcessConstant.java index 83c9aaa..5a7d5d3 100644 --- a/hzims-service-api/middle-api/src/main/java/com/hnac/hzims/middle/process/constant/TicketProcessConstant.java +++ b/hzims-service-api/middle-api/src/main/java/com/hnac/hzims/middle/process/constant/TicketProcessConstant.java @@ -52,4 +52,9 @@ public class TicketProcessConstant { * 值班计划 */ public static final String DUTY_REC = "duty_rec"; + + /** + * 线下工作票 + */ + public static final String OFFLINE_WORK_TICKET = "offlineWorkTicket"; } diff --git a/hzims-service-api/ticket-api/src/main/java/com/hnac/hzims/ticket/ticketprocess/feign/IOfflineTicketProcessClient.java b/hzims-service-api/ticket-api/src/main/java/com/hnac/hzims/ticket/ticketprocess/feign/IOfflineTicketProcessClient.java new file mode 100644 index 0000000..58452e0 --- /dev/null +++ b/hzims-service-api/ticket-api/src/main/java/com/hnac/hzims/ticket/ticketprocess/feign/IOfflineTicketProcessClient.java @@ -0,0 +1,24 @@ +package com.hnac.hzims.ticket.ticketprocess.feign; + +import com.hnac.hzims.middle.process.to.ProcessWorkFlowResponse; +import com.hnac.hzims.ticket.constants.TicketConstants; +import org.springblade.core.tool.api.R; +import org.springframework.cloud.openfeign.FeignClient; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; + +@FeignClient(value = TicketConstants.APP_NAME,fallback = OfflineTicketProcessClientFallback.class) +public interface IOfflineTicketProcessClient { + + String API = "/offlineTicket"; + String FIND_PENDING = API + "/findPending"; + + /** + * 线下工作票处理 + * @param response 流程信息 + * @return 处理结果 + */ + @PostMapping(FIND_PENDING) + R findPending(@RequestBody ProcessWorkFlowResponse response); + +} diff --git a/hzims-service-api/ticket-api/src/main/java/com/hnac/hzims/ticket/ticketprocess/feign/OfflineTicketProcessClientFallback.java b/hzims-service-api/ticket-api/src/main/java/com/hnac/hzims/ticket/ticketprocess/feign/OfflineTicketProcessClientFallback.java new file mode 100644 index 0000000..11b12dc --- /dev/null +++ b/hzims-service-api/ticket-api/src/main/java/com/hnac/hzims/ticket/ticketprocess/feign/OfflineTicketProcessClientFallback.java @@ -0,0 +1,15 @@ +package com.hnac.hzims.ticket.ticketprocess.feign; + +import com.hnac.hzims.middle.process.to.ProcessWorkFlowResponse; +import org.springblade.core.tool.api.R; +import org.springframework.stereotype.Component; + +@Component +public class OfflineTicketProcessClientFallback implements IOfflineTicketProcessClient { + + @Override + public R findPending(ProcessWorkFlowResponse response) { + return R.fail("工作票处理流程失败!"); + } + +} diff --git a/hzims-service/hzims-middle/src/main/java/com/hnac/hzims/middle/processflow/strategy/serviceimpl/OfflineTicketProcessImpl.java b/hzims-service/hzims-middle/src/main/java/com/hnac/hzims/middle/processflow/strategy/serviceimpl/OfflineTicketProcessImpl.java new file mode 100644 index 0000000..b6be99a --- /dev/null +++ b/hzims-service/hzims-middle/src/main/java/com/hnac/hzims/middle/processflow/strategy/serviceimpl/OfflineTicketProcessImpl.java @@ -0,0 +1,41 @@ +package com.hnac.hzims.middle.processflow.strategy.serviceimpl; + + +import com.hnac.hzims.middle.process.to.ProcessWorkFlowResponse; +import com.hnac.hzims.middle.processflow.service.ProcessDictService; +import com.hnac.hzims.middle.processflow.strategy.abstracts.ProcessAbstractService; +import com.hnac.hzims.middle.processflow.strategy.entity.WorkflowQueue; +import com.hnac.hzims.ticket.ticketprocess.feign.IOfflineTicketProcessClient; +import lombok.AllArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springblade.core.log.exception.ServiceException; +import org.springblade.core.tool.api.R; +import org.springframework.stereotype.Service; +import org.springframework.util.Assert; + +import static com.hnac.hzims.middle.process.constant.TicketProcessConstant.OFFLINE_WORK_TICKET; + +@Slf4j +@Service +@AllArgsConstructor +public class OfflineTicketProcessImpl extends ProcessAbstractService { + + private final ProcessDictService processDictService; + private final IOfflineTicketProcessClient offlineTicketProcessClient; + + @Override + public Boolean isWorkflowProcess(WorkflowQueue flowQueue) { + String dictValue = processDictService.selectDictValueByKey(OFFLINE_WORK_TICKET); + return dictValue.equals(flowQueue.getProcessDefinitionKey()); + } + + @Override + public void calculate(ProcessWorkFlowResponse response) { + log.info("线下工作票调用fein接口消费开始---param",response); + R result = offlineTicketProcessClient.findPending(response); + Assert.isTrue(result.isSuccess(),() -> { + throw new ServiceException("线下工作票处理失败!"); + }); + log.info("线下工作票调用fein接口消费结束---"); + } +} diff --git a/hzims-service/hzims-middle/src/main/resources/db/1.0.2.sql b/hzims-service/hzims-middle/src/main/resources/db/1.0.2.sql new file mode 100644 index 0000000..ec8d18f --- /dev/null +++ b/hzims-service/hzims-middle/src/main/resources/db/1.0.2.sql @@ -0,0 +1 @@ +INSERT INTO `process_dict` (`dict_code`, `dict_sort`, `dict_key`, `dict_value`, `dict_label`, `dict_type`, `is_default`, `status`, `create_dept`, `create_time`, `update_time`, `remark`) VALUES (9, 9, 'offlineWorkTicket', 'offlineWorkTicket', '线下工作票', '线下工作票', 'Y', 0, NULL, '2023-12-28 16:35:10', '2023-12-28 16:35:14', '线下工作票流程'); diff --git a/hzims-service/inspect/src/main/java/com/hnac/hzinfo/inspect/task/service/impl/EventServiceImpl.java b/hzims-service/inspect/src/main/java/com/hnac/hzinfo/inspect/task/service/impl/EventServiceImpl.java index 3f0ed50..f5f8b84 100644 --- a/hzims-service/inspect/src/main/java/com/hnac/hzinfo/inspect/task/service/impl/EventServiceImpl.java +++ b/hzims-service/inspect/src/main/java/com/hnac/hzinfo/inspect/task/service/impl/EventServiceImpl.java @@ -1,5 +1,6 @@ package com.hnac.hzinfo.inspect.task.service.impl; +import com.alibaba.fastjson.JSON; import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.google.common.collect.Lists; import com.hnac.hzims.operational.defect.constants.DefectConstant; @@ -15,6 +16,7 @@ import com.hnac.hzinfo.inspect.task.mapper.TaskEventMapper; import com.hnac.hzinfo.inspect.task.service.*; import com.hnac.hzinfo.inspect.task.vo.EventAddVO; import com.hnac.hzinfo.inspect.task.vo.EventRecordAddVO; +import lombok.extern.slf4j.Slf4j; import org.springblade.core.log.exception.ServiceException; import org.springblade.core.log.logger.BladeLogger; import org.springblade.core.mp.base.BaseServiceImpl; @@ -43,6 +45,7 @@ import java.util.List; * @author Chill */ @Service +@Slf4j public class EventServiceImpl extends BaseServiceImpl implements IEventService { @Autowired @@ -187,7 +190,9 @@ public class EventServiceImpl extends BaseServiceImpllambdaQuery().eq(TaskUserEntity::getTaskId,eventVO.getTaskId()).eq(TaskUserEntity::getUserId,user == null ? eventVO.getUserId() : user.getUserId())); + log.info("taskUserEntity:"+JSON.toJSONString(taskUserEntity)); if(taskUserEntity==null){ throw new ServiceException("该任务已被别人领取"); } diff --git a/hzims-service/inspect/src/main/java/com/hnac/hzinfo/inspect/task/service/impl/TaskServiceImpl.java b/hzims-service/inspect/src/main/java/com/hnac/hzinfo/inspect/task/service/impl/TaskServiceImpl.java index 16b509d..6a7deb2 100644 --- a/hzims-service/inspect/src/main/java/com/hnac/hzinfo/inspect/task/service/impl/TaskServiceImpl.java +++ b/hzims-service/inspect/src/main/java/com/hnac/hzinfo/inspect/task/service/impl/TaskServiceImpl.java @@ -282,7 +282,7 @@ public class TaskServiceImpl extends BaseServiceImpl imp taskUserService.update(Wrappers.lambdaUpdate().set(TaskUserEntity::getClaimStatus, ClaimStatusEnum.COLLECT.getStatus()).set(TaskUserEntity::getClaimTime, LocalDateTime.now()).eq(TaskUserEntity::getTaskId, task.getId()).eq(TaskUserEntity::getUserId, userId)); //如果是抢占任务,删除能够抢占此任务的其他人 if (PlanContants.PlanMethodEnum.SEIZE.getMethod().equals(task.getMethod())) { - taskUserService.remove(Wrappers.lambdaQuery().eq(TaskUserEntity::getTaskId, task.getId()).ne(TaskUserEntity::getId, userId)); + taskUserService.remove(Wrappers.lambdaQuery().eq(TaskUserEntity::getTaskId, task.getId()).ne(TaskUserEntity::getUserId, userId)); } task.setStatus(Integer.valueOf(TaskStatusEnum.UNDERWAY_STATUS.getStatus())); task.setStartTime(LocalDateTime.now()); diff --git a/hzims-service/ticket/src/main/java/com/hnac/hzims/ticket/redisConsume/feign/OfflineTicketProcessClient.java b/hzims-service/ticket/src/main/java/com/hnac/hzims/ticket/redisConsume/feign/OfflineTicketProcessClient.java new file mode 100644 index 0000000..dfb763e --- /dev/null +++ b/hzims-service/ticket/src/main/java/com/hnac/hzims/ticket/redisConsume/feign/OfflineTicketProcessClient.java @@ -0,0 +1,26 @@ +package com.hnac.hzims.ticket.redisConsume.feign; + + +import com.hnac.hzims.middle.process.to.ProcessWorkFlowResponse; +import com.hnac.hzims.ticket.ticketprocess.feign.IOfflineTicketProcessClient; +import com.hnac.hzims.ticket.twoTicket.service.TicketProcessService; +import lombok.AllArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springblade.core.tool.api.R; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RestController; + +@RestController +@AllArgsConstructor +@Slf4j +public class OfflineTicketProcessClient implements IOfflineTicketProcessClient { + + private final TicketProcessService processService; + + @Override + @PostMapping(FIND_PENDING) + public R findPending(@RequestBody ProcessWorkFlowResponse response) { + return R.status(processService.offlineTicketFindPending(response)); + } +} diff --git a/hzims-service/ticket/src/main/java/com/hnac/hzims/ticket/twoTicket/controller/TicketProcessController.java b/hzims-service/ticket/src/main/java/com/hnac/hzims/ticket/twoTicket/controller/TicketProcessController.java index c0d95ca..71b2b24 100644 --- a/hzims-service/ticket/src/main/java/com/hnac/hzims/ticket/twoTicket/controller/TicketProcessController.java +++ b/hzims-service/ticket/src/main/java/com/hnac/hzims/ticket/twoTicket/controller/TicketProcessController.java @@ -45,6 +45,11 @@ public class TicketProcessController { return R.data(ticketId); } + @ApiOperation("开启工作票线下流程") + @PostMapping("/startUpOfflineTicket") + public R startUpOfflineTicket(@RequestBody WorkTicketVo workTicketVo) { + return R.data(ticketProcessService.startUpOfflineTicket(workTicketVo)); + } /** * 工作票待处理 diff --git a/hzims-service/ticket/src/main/java/com/hnac/hzims/ticket/twoTicket/service/TicketProcessService.java b/hzims-service/ticket/src/main/java/com/hnac/hzims/ticket/twoTicket/service/TicketProcessService.java index 9c67a63..1c58149 100644 --- a/hzims-service/ticket/src/main/java/com/hnac/hzims/ticket/twoTicket/service/TicketProcessService.java +++ b/hzims-service/ticket/src/main/java/com/hnac/hzims/ticket/twoTicket/service/TicketProcessService.java @@ -27,6 +27,12 @@ public interface TicketProcessService { */ void findPending(ProcessWorkFlowResponse response); + /** + * 线下工作票流程处理 + * @param response 流程信息 + * @return 处理结果 + */ + Boolean offlineTicketFindPending(ProcessWorkFlowResponse response); /** @@ -46,4 +52,6 @@ public interface TicketProcessService { * @param value */ public void getDataConversion(Map dataConversion, String key, Object value); + + Long startUpOfflineTicket(WorkTicketVo workTicketVo); } diff --git a/hzims-service/ticket/src/main/java/com/hnac/hzims/ticket/twoTicket/service/impl/FirstWorkTicketServiceImpl.java b/hzims-service/ticket/src/main/java/com/hnac/hzims/ticket/twoTicket/service/impl/FirstWorkTicketServiceImpl.java index 28b5102..677cb96 100644 --- a/hzims-service/ticket/src/main/java/com/hnac/hzims/ticket/twoTicket/service/impl/FirstWorkTicketServiceImpl.java +++ b/hzims-service/ticket/src/main/java/com/hnac/hzims/ticket/twoTicket/service/impl/FirstWorkTicketServiceImpl.java @@ -8,6 +8,7 @@ import com.alibaba.fastjson.JSONObject; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; import com.baomidou.mybatisplus.core.toolkit.Wrappers; +import com.google.common.collect.Lists; import com.hnac.hzims.message.entity.config.PushConfigEntity; import com.hnac.hzims.message.fegin.IMessageConfigClient; import com.hnac.hzims.operational.access.dto.OperAccessTaskDTO; @@ -21,13 +22,11 @@ import com.hnac.hzims.ticket.allTicket.service.TicketInfoEvaluateService; import com.hnac.hzims.ticket.allTicket.vo.TicketInfoStatisticVO; import com.hnac.hzims.ticket.constants.TicketConstants; import com.hnac.hzims.ticket.constants.WorkTicketConstants; +import com.hnac.hzims.ticket.twoTicket.constant.TicketConstant; import com.hnac.hzims.ticket.twoTicket.entity.WorkTicketFinish; import com.hnac.hzims.ticket.twoTicket.service.IFirstWorkTicketService; import com.hnac.hzims.ticket.twoTicket.service.IWorkTicketFinishService; -import com.hnac.hzims.ticket.utils.AsposeUtil; -import com.hnac.hzims.ticket.utils.ExcelUtil; -import com.hnac.hzims.ticket.utils.ObjectUtils; -import com.hnac.hzims.ticket.utils.PdfUtils; +import com.hnac.hzims.ticket.utils.*; import com.hnac.hzims.ticket.workTicket.dto.*; import com.hnac.hzims.ticket.workTicket.entity.*; import com.hnac.hzims.ticket.workTicket.mapper.WorkDelayNoScopeMapper; @@ -39,7 +38,7 @@ import com.hnac.hzims.ticket.workTicket.wrapper.WorkTicketInfoWrapper; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.apache.poi.ss.usermodel.Workbook; -import org.apache.poi.xwpf.usermodel.XWPFDocument; +import org.apache.poi.xwpf.usermodel.*; import org.springblade.core.log.exception.ServiceException; import org.springblade.core.mp.base.BaseServiceImpl; import org.springblade.core.secure.utils.AuthUtil; @@ -54,14 +53,19 @@ import org.springblade.system.user.feign.IUserClient; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Service; import org.springframework.util.Assert; +import org.springframework.util.ResourceUtils; import org.springframework.web.context.request.RequestContextHolder; import org.springframework.web.context.request.ServletRequestAttributes; import javax.servlet.http.HttpServletResponse; +import java.io.File; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import java.math.BigDecimal; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; import java.text.SimpleDateFormat; import java.time.LocalDateTime; import java.time.format.DateTimeFormatter; @@ -69,6 +73,8 @@ import java.util.*; import java.util.stream.Collectors; import java.util.stream.IntStream; +import static org.aspectj.weaver.tools.cache.SimpleCacheFactory.path; + /** * @author hx */ @@ -280,13 +286,23 @@ public class FirstWorkTicketServiceImpl extends BaseServiceImpl params = this.getTicketParamById(ticketId,workTicketInfoEntity); String tempFileName = WorkTicketConstants.TicketSignageEnum.getTempFileNameByType(workTicketInfoEntity.getType()); Assert.isTrue(StringUtil.isNotBlank(tempFileName),() -> { throw new ServiceException("未找到模板文件,预览失败!"); }); String wordPath = this.getFileSavePath() + params.get("code") + "_" + params.get("addressEquName") +".docx"; - this.exportTicketWord("template/"+tempFileName, wordPath, params); + List documents; + try { + documents = this.getDocuments(workTicketInfoEntity, params); + } catch (Exception e) { + throw new RuntimeException(e); + } + try { + this.exportTicketWord(documents,wordPath); + } catch (IOException e) { + throw new RuntimeException(e); + } String pdfPath = this.getFileSavePath() + params.get("code") + "_" + params.get("addressEquName") +".pdf"; AsposeUtil.wordToPdf(wordPath,pdfPath); PdfUtils.readPdf(response,pdfPath); @@ -371,38 +387,60 @@ public class FirstWorkTicketServiceImpl extends BaseServiceImpl getDocuments(WorkTicketInfoEntity workTicketInfo,Map params) { + List result = Lists.newArrayList(); + XWPFDocument document = this.fillDocument("template/" + WorkTicketConstants.TicketSignageEnum.getTempFileNameByType(workTicketInfo.getType()), params); + result.add(document); + //安全隔离措施附页 (true,展示附件,false,不展示附件) + if (workTicketInfo.getIsSafety()) { + XWPFDocument xwpfDocument = this.fillDocument("template/" + TicketConstant.SECURE_PAGE, params); + result.add(xwpfDocument); + } + //危险点分析与预控措施票 (true,展示附件,false,不展示附件) + if (workTicketInfo.getIsHazard()) { + XWPFDocument xwpfDocument = this.fillDocument("template/" + TicketConstant.SAFETY_PAGE, params); + result.add(xwpfDocument); + } + //动火工作票 (true,展示附件,false,不展示附件) + if (workTicketInfo.getIsRailway()) { + XWPFDocument xwpfDocument = this.fillDocument("template/" + TicketConstant.FLIGHT_PAGE, params); + result.add(xwpfDocument); + } + //有限空间监测记录单(true,展示附件,false,不展示附件) + if (workTicketInfo.getIsLimited()) { + XWPFDocument xwpfDocument = this.fillDocument("template/" + TicketConstant.SPACE_PAGE, params); + result.add(xwpfDocument); + } + //每日开工和收工时间附页 + if (workTicketInfo.getIsStart()) { + XWPFDocument xwpfDocument = this.fillDocument("template/" + TicketConstant.START_PAGE, params); + result.add(xwpfDocument); + } + return result; + } + + private XWPFDocument fillDocument(String templatePath, Map params) { XWPFDocument xwpfDocument = null; try { xwpfDocument = WordExportUtil.exportWord07(templatePath, params); } catch (Exception e) { e.printStackTrace(); } - FileOutputStream outputStream = null; - try { - outputStream = new FileOutputStream(savePath); - } catch (FileNotFoundException e) { - throw new RuntimeException(e); - } - try { - xwpfDocument.write(outputStream); - } - catch(Exception e) { - e.printStackTrace(); + return xwpfDocument; + } + + private void exportTicketWord(List documents, String savePath) throws IOException { + FileOutputStream out = new FileOutputStream(savePath, true); + Path file = Paths.get(path); + if(Files.exists(file)) { + Files.delete(file); } - finally { - try { - outputStream.close(); - } catch (IOException e) { - throw new RuntimeException(e); - } + new File(savePath).createNewFile(); + for (XWPFDocument document : documents) { + document.write(out); } + out.close(); } @Override diff --git a/hzims-service/ticket/src/main/java/com/hnac/hzims/ticket/twoTicket/service/impl/TicketProcessServiceImpl.java b/hzims-service/ticket/src/main/java/com/hnac/hzims/ticket/twoTicket/service/impl/TicketProcessServiceImpl.java index 44d27ce..0d1e79c 100644 --- a/hzims-service/ticket/src/main/java/com/hnac/hzims/ticket/twoTicket/service/impl/TicketProcessServiceImpl.java +++ b/hzims-service/ticket/src/main/java/com/hnac/hzims/ticket/twoTicket/service/impl/TicketProcessServiceImpl.java @@ -7,6 +7,7 @@ import com.alibaba.fastjson.JSONObject; import com.baomidou.mybatisplus.core.toolkit.CollectionUtils; import com.baomidou.mybatisplus.core.toolkit.IdWorker; import com.baomidou.mybatisplus.core.toolkit.ObjectUtils; +import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.hnac.hzims.common.logs.utils.StringUtils; import com.hnac.hzims.message.MessageConstants; import com.hnac.hzims.message.dto.BusinessMessageDTO; @@ -61,6 +62,7 @@ import org.springblade.system.user.feign.IUserClient; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import org.springframework.util.Assert; import javax.servlet.ServletOutputStream; import javax.servlet.http.HttpServletResponse; @@ -488,6 +490,64 @@ public class TicketProcessServiceImpl implements TicketProcessService { } + @Override + public Boolean offlineTicketFindPending(ProcessWorkFlowResponse response) { + log.info("线下工作票接收到的工作票数据为:{}",JSON.toJSONString(response)); + FristWorkTicketVo ticketResponse = JSONObject.parseObject(JSON.toJSONString(response.getVariables()),FristWorkTicketVo.class); + Assert.isTrue(ObjectUtil.isNotEmpty(ticketResponse),() -> { + log.error("接收到的数据为:{}",JSON.toJSONString(response.getVariables())); + throw new ServiceException("线下工作票处理流程环节接收数据失败,请联系管理员"); + }); + WorkTicketVo workTicketVo = ticketResponse.getWorkTicketVo(); + WorkTicketInfoEntity workTicket = workTicketVo.getWorkTicket(); + WorkTicketInfoEntity info = firstWorkTicketService.getById(workTicket.getId()); + if(ObjectUtil.isEmpty(info)) { + return true; + } + workTicket.setProcessInstanceId(response.getProcessInstanceId()); + this.saveWorkTicket(workTicket,response); + List safetyMeasuresList = workTicketVo.getSafetyMeasuresList(); + if(CollectionUtil.isNotEmpty(safetyMeasuresList)) { + workTicketSafetyMeasureService.saveOrUpdateBatch(safetyMeasuresList); + } + List workTicketContentDtoList = workTicketVo.getWorkTicketContentDtoList(); + if(CollectionUtil.isNotEmpty(workTicketContentDtoList)) { + contentService.saveOrUpdateBatch(workTicketContentDtoList); + } + WorkTicketFinish workTicketFinish = workTicketVo.getWorkTicketFinish(); + if(CollectionUtil.isNotEmpty(workTicketContentDtoList)) { + workTicketFinishService.saveOrUpdate(workTicketFinish); + } + // 推送消息 + new Thread(() -> this.sendMessage(workTicket,response.getUserId())).start(); + return true; + } + + /** + * 推送消息 + * @param ticketInfo 票据信息 + */ + private void sendMessage(WorkTicketInfoEntity ticketInfo,String userIds) { + BusinessMessageDTO businessMessageDTO = new BusinessMessageDTO(); + businessMessageDTO.setBusinessClassify("business"); + businessMessageDTO.setBusinessKey(MessageConstants.BusinessClassifyEnum.TICKETMESSAGE.getKey()); + businessMessageDTO.setSubject(MessageConstants.BusinessClassifyEnum.TICKETMESSAGE.getDescription()); + businessMessageDTO.setTaskId(ticketInfo.getId()); + businessMessageDTO.setTenantId(ticketInfo.getTenantId()); + String content = "您有一张线下工作票待审批,工作内容: ".concat(ticketInfo.getWorkContent()).concat(",审批环节: ").concat(ticketInfo.getTaskName()); + businessMessageDTO.setContent(content); + businessMessageDTO.setDeptId(ticketInfo.getCreateDept()); + R deptName = sysClient.getDeptName(ticketInfo.getCreateDept()); + if (deptName.isSuccess()) { + businessMessageDTO.setDeptName(deptName.getData()); + } + businessMessageDTO.setUserIds(userIds); + businessMessageDTO.setCreateUser(ticketInfo.getCreateUser()); + R booleanR = messageClient.sendAppAndWsMsgByUsers(businessMessageDTO); + if (!booleanR.isSuccess()) { + throw new ServiceException("消息推送失败"); + } + } /** * 保存流程描述 @@ -1298,6 +1358,65 @@ public class TicketProcessServiceImpl implements TicketProcessService { } } + @Override + @Transactional + public Long startUpOfflineTicket(WorkTicketVo workTicketVo) { + WorkTicketInfoEntity workTicket = workTicketVo.getWorkTicket(); + this.saveOfflineTicket(workTicket); + this.saveSafetyMeasures(workTicketVo.getSafetyMeasuresList(), workTicketVo.getWorkTicket()); + this.saveWorkTicketContentDto(workTicketVo.getWorkTicketContentDtoList(), workTicketVo.getWorkTicket()); + // 开启工作流 + String processInstanceId = this.startOfflineTicketProcess(workTicketVo); + return workTicket.getId(); + } + + /** + * 开启线下工作票流程 + * @param workTicketVo 工作票 + * @return 工作流实例ID + */ + private String startOfflineTicketProcess(WorkTicketVo workTicketVo) { + WorkTicketInfoEntity workTicket = workTicketVo.getWorkTicket(); + Map params = new HashMap<>(); + workTicketVo.setWorkTicket(workTicket); + params.put("workTicketVo",workTicketVo); + R flowR = + flowClient.startProcessInstanceContainNameByKey("offlineWorkTicket",String.valueOf(workTicket.getId()),workTicket.getWorkContent(), params); + Assert.isTrue(flowR.isSuccess(),() -> { + throw new ServiceException("开启工作流失败,请联系管理员"); + }); + return flowR.getData().getProcessInstanceId(); + } + + /** + * 保存线下工作票 + * @param workTicket 工作票信息 + */ + private void saveOfflineTicket(WorkTicketInfoEntity workTicket) { + StationEntity stationEntity = new StationEntity(); + stationEntity.setCode(workTicket.getSignageCode()); + R stationR = stationClient.getOne(stationEntity); + Assert.isTrue(stationR.isSuccess() && Func.isNotEmpty(stationR.getData().getSignage()),() -> { + throw new ServiceException("获取站点两票抬头失败"); + }); + + workTicket.setSignage(stationR.getData().getSignage()); + workTicket.setSignageCode(stationR.getData().getCode()); + String code = processDictFeignService.getTicketByCode(workTicket.getSignage(), this.getTicketWichCode(workTicket.getType())); + workTicket.setCode(code); + Assert.isTrue(StringUtils.isNotBlank(code),() -> { + throw new ServiceException("生成两票编号失败,请联系管理员!"); + }); + workTicket.setStepOperator(AuthUtil.getUserName()); + workTicket.setIsSafety(false); + workTicket.setIsHazard(false); + workTicket.setIsRailway(false); + workTicket.setIsLimited(false); + Assert.isTrue(firstWorkTicketService.save(workTicket),()-> { + throw new ServiceException("工作票保存失败"); + }); + } + /** * 工作类型生成工作票类型 */ diff --git a/hzims-service/ticket/src/main/resources/file/线下工作票审批流程.bpmn20.xml b/hzims-service/ticket/src/main/resources/file/线下工作票审批流程.bpmn20.xml new file mode 100644 index 0000000..4d87dfc --- /dev/null +++ b/hzims-service/ticket/src/main/resources/file/线下工作票审批流程.bpmn20.xml @@ -0,0 +1,129 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file