From 95c01301f65379e7634e4619bf4c49186aa5be41 Mon Sep 17 00:00:00 2001 From: 疯狂的狮子Li <15040126243@163.com> Date: 星期五, 07 二月 2025 14:19:28 +0800 Subject: [PATCH] !644 同步修复一些问题 Merge pull request !644 from 疯狂的狮子Li/dev --- ruoyi-modules/ruoyi-workflow/src/main/java/org/dromara/workflow/service/impl/TestLeaveServiceImpl.java | 70 ++++++++++++++++++++++++++++------- 1 files changed, 56 insertions(+), 14 deletions(-) diff --git a/ruoyi-modules/ruoyi-workflow/src/main/java/org/dromara/workflow/service/impl/TestLeaveServiceImpl.java b/ruoyi-modules/ruoyi-workflow/src/main/java/org/dromara/workflow/service/impl/TestLeaveServiceImpl.java index 9d14bc8..2c43173 100644 --- a/ruoyi-modules/ruoyi-workflow/src/main/java/org/dromara/workflow/service/impl/TestLeaveServiceImpl.java +++ b/ruoyi-modules/ruoyi-workflow/src/main/java/org/dromara/workflow/service/impl/TestLeaveServiceImpl.java @@ -1,20 +1,25 @@ package org.dromara.workflow.service.impl; +import cn.hutool.core.convert.Convert; +import cn.hutool.core.date.DateUtil; +import cn.hutool.core.map.MapUtil; +import cn.hutool.core.util.ObjectUtil; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; +import org.dromara.common.core.domain.event.ProcessDeleteEvent; import org.dromara.common.core.domain.event.ProcessEvent; import org.dromara.common.core.domain.event.ProcessTaskEvent; import org.dromara.common.core.enums.BusinessStatusEnum; import org.dromara.common.core.service.WorkflowService; import org.dromara.common.core.utils.MapstructUtils; -import org.dromara.common.core.utils.StreamUtils; import org.dromara.common.core.utils.StringUtils; import org.dromara.common.mybatis.core.domain.BaseEntity; import org.dromara.common.mybatis.core.page.PageQuery; import org.dromara.common.mybatis.core.page.TableDataInfo; +import org.dromara.workflow.common.ConditionalOnEnable; import org.dromara.workflow.domain.TestLeave; import org.dromara.workflow.domain.bo.TestLeaveBo; import org.dromara.workflow.domain.vo.TestLeaveVo; @@ -24,8 +29,8 @@ import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; -import java.util.Collection; import java.util.List; +import java.util.Map; /** * 璇峰亣Service涓氬姟灞傚鐞� @@ -33,6 +38,7 @@ * @author may * @date 2023-07-21 */ +@ConditionalOnEnable @RequiredArgsConstructor @Service @Slf4j @@ -46,9 +52,7 @@ */ @Override public TestLeaveVo queryById(Long id) { - TestLeaveVo testLeaveVo = baseMapper.selectVoById(id); - testLeaveVo.setProcessInstanceId(workflowService.getInstanceIdByBusinessKey(String.valueOf(id))); - return testLeaveVo; + return baseMapper.selectVoById(id); } /** @@ -84,6 +88,9 @@ */ @Override public TestLeaveVo insertByBo(TestLeaveBo bo) { + long day = DateUtil.betweenDay(bo.getStartDate(), bo.getEndDate(), true); + // 鎴鏃ユ湡涔熺畻涓�澶� + bo.setLeaveDays((int) day + 1); TestLeave add = MapstructUtils.convert(bo, TestLeave.class); if (StringUtils.isBlank(add.getStatus())) { add.setStatus(BusinessStatusEnum.DRAFT.getStatus()); @@ -110,37 +117,72 @@ */ @Override @Transactional(rollbackFor = Exception.class) - public Boolean deleteWithValidByIds(Collection<Long> ids) { - List<String> idList = StreamUtils.toList(ids, String::valueOf); - workflowService.deleteRunAndHisInstance(idList); - return baseMapper.deleteBatchIds(ids) > 0; + public Boolean deleteWithValidByIds(List<Long> ids) { + workflowService.deleteInstance(ids); + return baseMapper.deleteByIds(ids) > 0; } /** - * 鎬讳綋娴佺▼鐩戝惉(渚嬪: 鎻愪氦 閫�鍥� 鎾ら攢 缁堟 浣滃簾绛�) + * 鎬讳綋娴佺▼鐩戝惉(渚嬪: 鑽夌锛屾挙閿�锛岄��鍥烇紝浣滃簾锛岀粓姝紝宸插畬鎴愮瓑) + * 姝e父浣跨敤鍙渶#processEvent.flowCode=='leave1' + * 绀轰緥涓轰簡鏂逛究鍒欎娇鐢╯tartsWith鍖归厤浜嗗叏閮ㄧず渚媖ey * * @param processEvent 鍙傛暟 */ - @EventListener(condition = "#processEvent.key=='leave1'") + @EventListener(condition = "#processEvent.flowCode.startsWith('leave')") public void processHandler(ProcessEvent processEvent) { log.info("褰撳墠浠诲姟鎵ц浜唟}", processEvent.toString()); - TestLeave testLeave = baseMapper.selectById(Long.valueOf(processEvent.getBusinessKey())); + TestLeave testLeave = baseMapper.selectById(Long.valueOf(processEvent.getBusinessId())); testLeave.setStatus(processEvent.getStatus()); + // 鐢ㄤ簬渚嬪瀹℃壒闄勪欢 瀹℃壒鎰忚绛� 瀛樺偍鍒颁笟鍔¤〃鍐� 鑷鏍规嵁涓氬姟瀹炵幇瀛樺偍娴佺▼ + Map<String, Object> params = processEvent.getParams(); + if (MapUtil.isNotEmpty(params)) { + // 鍘嗗彶浠诲姟鎵╁睍(閫氬父涓洪檮浠�) + String hisTaskExt = Convert.toStr(params.get("hisTaskExt")); + // 鍔炵悊浜� + String handler = Convert.toStr(params.get("handler")); + // 鍔炵悊鎰忚 + String message = Convert.toStr(params.get("message")); + } + if (processEvent.isSubmit()) { + testLeave.setStatus(BusinessStatusEnum.WAITING.getStatus()); + } baseMapper.updateById(testLeave); } /** * 鎵ц鍔炵悊浠诲姟鐩戝惉 + * 绀轰緥锛氫篃鍙�氳繃 @EventListener(condition = "#processTaskEvent.flowCode=='leave1'")杩涜鍒ゆ柇 + * 鍦ㄦ柟娉曚腑鍒ゆ柇娴佺▼鑺傜偣key + * if ("xxx".equals(processTaskEvent.getNodeCode())) { + * //鎵ц涓氬姟閫昏緫 + * } * * @param processTaskEvent 鍙傛暟 */ - @EventListener(condition = "#processTaskEvent.keyNode=='leave1_Activity_14633hx'") + @EventListener(condition = "#processTaskEvent.flowCode.startsWith('leave')") public void processTaskHandler(ProcessTaskEvent processTaskEvent) { log.info("褰撳墠浠诲姟鎵ц浜唟}", processTaskEvent.toString()); - TestLeave testLeave = baseMapper.selectById(Long.valueOf(processTaskEvent.getBusinessKey())); + TestLeave testLeave = baseMapper.selectById(Long.valueOf(processTaskEvent.getBusinessId())); testLeave.setStatus(BusinessStatusEnum.WAITING.getStatus()); baseMapper.updateById(testLeave); } + /** + * 鐩戝惉鍒犻櫎娴佺▼浜嬩欢 + * 姝e父浣跨敤鍙渶#processDeleteEvent.flowCode=='leave1' + * 绀轰緥涓轰簡鏂逛究鍒欎娇鐢╯tartsWith鍖归厤浜嗗叏閮ㄧず渚媖ey + * + * @param processDeleteEvent 鍙傛暟 + */ + @EventListener(condition = "#processDeleteEvent.flowCode.startsWith('leave')") + public void processDeleteHandler(ProcessDeleteEvent processDeleteEvent) { + log.info("鐩戝惉鍒犻櫎娴佺▼浜嬩欢锛屽綋鍓嶄换鍔℃墽琛屼簡{}", processDeleteEvent.toString()); + TestLeave testLeave = baseMapper.selectById(Long.valueOf(processDeleteEvent.getBusinessId())); + if (ObjectUtil.isNull(testLeave)) { + return; + } + baseMapper.deleteById(testLeave.getId()); + } } -- Gitblit v1.9.3