Date: Wed, 10 Apr 2024 19:42:33 +0800
Subject: [PATCH 03/50] =?UTF-8?q?=E6=95=B0=E6=8D=AE=E6=9D=83=E9=99=90?=
=?UTF-8?q?=E8=B0=83=E6=95=B4?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../rule/dept/DeptDataPermissionRule.java | 42 +++++++++--------
.../task/BpmProcessInstanceController.java | 8 +++-
.../task/BpmProcessInstanceExtMapper.java | 46 +++++++------------
.../config/DataPermissionConfiguration.java | 21 ++++-----
.../task/BpmProcessInstanceServiceImpl.java | 2 +-
5 files changed, 55 insertions(+), 64 deletions(-)
diff --git a/yudao-framework/yudao-spring-boot-starter-biz-data-permission/src/main/java/cn/iocoder/yudao/framework/datapermission/core/rule/dept/DeptDataPermissionRule.java b/yudao-framework/yudao-spring-boot-starter-biz-data-permission/src/main/java/cn/iocoder/yudao/framework/datapermission/core/rule/dept/DeptDataPermissionRule.java
index bff515ed..d40d7f5e 100644
--- a/yudao-framework/yudao-spring-boot-starter-biz-data-permission/src/main/java/cn/iocoder/yudao/framework/datapermission/core/rule/dept/DeptDataPermissionRule.java
+++ b/yudao-framework/yudao-spring-boot-starter-biz-data-permission/src/main/java/cn/iocoder/yudao/framework/datapermission/core/rule/dept/DeptDataPermissionRule.java
@@ -1,6 +1,7 @@
package cn.iocoder.yudao.framework.datapermission.core.rule.dept;
import cn.hutool.core.collection.CollUtil;
+import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import cn.iocoder.yudao.framework.common.enums.UserTypeEnum;
@@ -22,27 +23,22 @@ import net.sf.jsqlparser.expression.operators.relational.EqualsTo;
import net.sf.jsqlparser.expression.operators.relational.ExpressionList;
import net.sf.jsqlparser.expression.operators.relational.InExpression;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Map;
-import java.util.Set;
+import java.util.*;
/**
* 基于部门的 {@link DataPermissionRule} 数据权限规则实现
- *
+ *
* 注意,使用 DeptDataPermissionRule 时,需要保证表中有 dept_id 部门编号的字段,可自定义。
- *
+ *
* 实际业务场景下,会存在一个经典的问题?当用户修改部门时,冗余的 dept_id 是否需要修改?
* 1. 一般情况下,dept_id 不进行修改,则会导致用户看不到之前的数据。【yudao-server 采用该方案】
* 2. 部分情况下,希望该用户还是能看到之前的数据,则有两种方式解决:【需要你改造该 DeptDataPermissionRule 的实现代码】
- * 1)编写洗数据的脚本,将 dept_id 修改成新部门的编号;【建议】
- * 最终过滤条件是 WHERE dept_id = ?
- * 2)洗数据的话,可能涉及的数据量较大,也可以采用 user_id 进行过滤的方式,此时需要获取到 dept_id 对应的所有 user_id 用户编号;
- * 最终过滤条件是 WHERE user_id IN (?, ?, ? ...)
- * 3)想要保证原 dept_id 和 user_id 都可以看的到,此时使用 dept_id 和 user_id 一起过滤;
- * 最终过滤条件是 WHERE dept_id = ? OR user_id IN (?, ?, ? ...)
- *
-
+ * 1)编写洗数据的脚本,将 dept_id 修改成新部门的编号;【建议】
+ * 最终过滤条件是 WHERE dept_id = ?
+ * 2)洗数据的话,可能涉及的数据量较大,也可以采用 user_id 进行过滤的方式,此时需要获取到 dept_id 对应的所有 user_id 用户编号;
+ * 最终过滤条件是 WHERE user_id IN (?, ?, ? ...)
+ * 3)想要保证原 dept_id 和 user_id 都可以看的到,此时使用 dept_id 和 user_id 一起过滤;
+ * 最终过滤条件是 WHERE dept_id = ? OR user_id IN (?, ?, ? ...)
*/
@AllArgsConstructor
@Slf4j
@@ -60,10 +56,15 @@ public class DeptDataPermissionRule implements DataPermissionRule {
private final PermissionApi permissionApi;
+ // TODO: 2024/4/10 注意 - 如果需要降级低权的话 要把需要的表名称加在这里 并且在方法上开启数据权限 并且添加 DataPermissionConfiguration 对象
+ private static final List LOW_POWER_TABLES = Arrays.asList(
+ "bpm_process_instance_ext"
+ );
+
/**
* 基于部门的表字段配置
* 一般情况下,每个表的部门编号字段是 dept_id,通过该配置自定义。
- *
+ *
* key:表名
* value:字段名
*/
@@ -71,7 +72,7 @@ public class DeptDataPermissionRule implements DataPermissionRule {
/**
* 基于用户的表字段配置
* 一般情况下,每个表的部门编号字段是 dept_id,通过该配置自定义。
- *
+ *
* key:表名
* value:字段名
*/
@@ -113,18 +114,19 @@ public class DeptDataPermissionRule implements DataPermissionRule {
}
// 情况一,如果是 ALL 可查看全部,则无需拼接条件
- if (deptDataPermission.getAll()) {
+ // 并且 (低权 和 支持地权) 都不成立
+ if (deptDataPermission.getAll() && !((deptDataPermission.getSelf() || CollectionUtil.isNotEmpty(deptDataPermission.getDeptIds())) && LOW_POWER_TABLES.contains(tableName))) {
return null;
}
// 情况二,即不能查看部门,又不能查看自己,则说明 100% 无权限
if (CollUtil.isEmpty(deptDataPermission.getDeptIds())
- && Boolean.FALSE.equals(deptDataPermission.getSelf())) {
+ && Boolean.FALSE.equals(deptDataPermission.getSelf())) {
return new EqualsTo(null, null); // WHERE null = null,可以保证返回的数据为空
}
// 情况三,拼接 Dept 和 User 的条件,最后组合
- Expression deptExpression = buildDeptExpression(tableName,tableAlias, deptDataPermission.getDeptIds());
+ Expression deptExpression = buildDeptExpression(tableName, tableAlias, deptDataPermission.getDeptIds());
Expression userExpression = buildUserExpression(tableName, tableAlias, deptDataPermission.getSelf(), loginUser.getId());
if (deptExpression == null && userExpression == null) {
// TODO 芋艿:获得不到条件的时候,暂时不抛出异常,而是不返回数据
@@ -180,7 +182,7 @@ public class DeptDataPermissionRule implements DataPermissionRule {
public void addDeptColumn(Class extends BaseDO> entityClass, String columnName) {
String tableName = TableInfoHelper.getTableInfo(entityClass).getTableName();
- addDeptColumn(tableName, columnName);
+ addDeptColumn(tableName, columnName);
}
public void addDeptColumn(String tableName, String columnName) {
diff --git a/yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/controller/admin/task/BpmProcessInstanceController.java b/yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/controller/admin/task/BpmProcessInstanceController.java
index c10b3375..3ef62b01 100644
--- a/yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/controller/admin/task/BpmProcessInstanceController.java
+++ b/yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/controller/admin/task/BpmProcessInstanceController.java
@@ -25,7 +25,6 @@ import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUti
@RestController
@RequestMapping("/bpm/process-instance")
@Validated
-@DataPermission(enable = false)
public class BpmProcessInstanceController {
@Resource
@@ -34,6 +33,7 @@ public class BpmProcessInstanceController {
@GetMapping("/my-page")
@Operation(summary = "获得我的实例分页列表", description = "在【我的流程】菜单中,进行调用")
@PreAuthorize("@ss.hasPermission('bpm:process-instance:query')")
+ @DataPermission(enable = false)
public CommonResult> getMyProcessInstancePage(
@Valid BpmProcessInstanceMyPageReqVO pageReqVO) {
return success(processInstanceService.getMyProcessInstancePage(getLoginUserId(), pageReqVO));
@@ -42,6 +42,7 @@ public class BpmProcessInstanceController {
@PostMapping("/create")
@Operation(summary = "新建流程实例")
@PreAuthorize("@ss.hasPermission('bpm:process-instance:query')")
+ @DataPermission(enable = false)
public CommonResult createProcessInstance(@Valid @RequestBody BpmProcessInstanceCreateReqVO createReqVO) {
return success(processInstanceService.createProcessInstance(getLoginUserId(), createReqVO));
}
@@ -50,6 +51,7 @@ public class BpmProcessInstanceController {
@Operation(summary = "获得指定流程实例", description = "在【流程详细】界面中,进行调用")
@Parameter(name = "id", description = "流程实例的编号", required = true)
@PreAuthorize("@ss.hasPermission('bpm:process-instance:query')")
+ @DataPermission(enable = false)
public CommonResult getProcessInstance(@RequestParam("id") String id) {
return success(processInstanceService.getProcessInstanceVO(id));
}
@@ -57,6 +59,7 @@ public class BpmProcessInstanceController {
@DeleteMapping("/cancel")
@Operation(summary = "取消流程实例", description = "撤回发起的流程")
@PreAuthorize("@ss.hasPermission('bpm:process-instance:cancel')")
+ @DataPermission(enable = false)
public CommonResult cancelProcessInstance(@Valid @RequestBody BpmProcessInstanceCancelReqVO cancelReqVO) {
processInstanceService.cancelProcessInstance(getLoginUserId(), cancelReqVO);
return success(true);
@@ -69,6 +72,7 @@ public class BpmProcessInstanceController {
@GetMapping("/process_instance_group_name_statistics")
@Operation(summary = "根据流程名称分组,统计各个流程的具体实例数据", description = "根据流程名称分组,统计各个流程的具体实例数据")
//@PreAuthorize("@ss.hasPermission('bpm:task:update')")
+ @DataPermission(enable = false)
public CommonResult> getProcessInstancesGroupByModelName(@Valid BpmProcessInstanceStatisticsReqVO reqVO) {
List list = processInstanceService.getProcessInstancesGroupByModelName(reqVO);
return success(list);
@@ -80,6 +84,7 @@ public class BpmProcessInstanceController {
*/
@GetMapping("/process_instance_result_status_statistics")
@Operation(summary = "流程实例的状态统计查询", description = "根据流程状态(处理中,通过,不通过,取消),统计各个状态的数据量")
+ @DataPermission(enable = false)
public CommonResult> getProcessInstancesGroupByResultStatus(@Valid BpmProcessInstanceStatisticsReqVO reqVO) {
List list = processInstanceService.getProcessInstancesGroupByResultStatus(reqVO);
return success(list);
@@ -95,6 +100,7 @@ public class BpmProcessInstanceController {
@GetMapping("/getUserProcessTpo10")
@Operation(summary = "获得用户审批耗时最长Top10", description = "在工作台-给数据权限是可以查看全部数据的用户查询使用")
+ @DataPermission(enable = false)
public CommonResult> getUserProcessTpo10(@Valid BpmProcessInstanceStatisticsReqVO reqVO) {
List list = processInstanceService.getUserProcessTpo10(reqVO);
return success(list);
diff --git a/yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/dal/mysql/task/BpmProcessInstanceExtMapper.java b/yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/dal/mysql/task/BpmProcessInstanceExtMapper.java
index 4916ce68..8128614e 100644
--- a/yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/dal/mysql/task/BpmProcessInstanceExtMapper.java
+++ b/yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/dal/mysql/task/BpmProcessInstanceExtMapper.java
@@ -8,10 +8,7 @@ import cn.iocoder.yudao.module.bpm.controller.admin.task.vo.instance.BpmProcessI
import cn.iocoder.yudao.module.bpm.controller.admin.task.vo.instance.BpmProcessInstanceStatisticsReqVO;
import cn.iocoder.yudao.module.bpm.controller.admin.task.vo.instance.BpmProcessInstanceStatisticsRespVO;
import cn.iocoder.yudao.module.bpm.dal.dataobject.task.BpmProcessInstanceExtDO;
-import cn.iocoder.yudao.module.bpm.dal.dataobject.task.BpmTaskExtDO;
import org.apache.ibatis.annotations.Mapper;
-import org.apache.ibatis.annotations.Param;
-import org.apache.ibatis.annotations.Select;
import java.util.List;
@@ -21,7 +18,7 @@ public interface BpmProcessInstanceExtMapper extends BaseMapperX selectCCPage(Long userId, BpmProcessInstanceMyPageReqVO reqVO) {
return selectPage(reqVO, new LambdaQueryWrapperX()
// .eqIfPresent(BpmProcessInstanceExtDO::getStartUserId, userId)
- .likeIfPresent(BpmProcessInstanceExtDO::getCcids, "["+userId+"]")
+ .likeIfPresent(BpmProcessInstanceExtDO::getCcids, "[" + userId + "]")
.eqIfPresent(BpmProcessInstanceExtDO::getProcessDefinitionId, reqVO.getProcessDefinitionId())
.eqIfPresent(BpmProcessInstanceExtDO::getCategory, reqVO.getCategory())
.eqIfPresent(BpmProcessInstanceExtDO::getStatus, reqVO.getStatus())
@@ -53,36 +50,25 @@ public interface BpmProcessInstanceExtMapper extends BaseMapperX getProcessInstancesGroupByModelName(BpmProcessInstanceStatisticsReqVO reqVO) ;
+ List getProcessInstancesGroupByModelName(BpmProcessInstanceStatisticsReqVO reqVO);
- List getProcessInstancesGroupByResultStatus(BpmProcessInstanceStatisticsReqVO reqVO) ;
+ List getProcessInstancesGroupByResultStatus(BpmProcessInstanceStatisticsReqVO reqVO);
+
+ default PageResult selectStatisticePage(BpmProcessInstanceMyPageReqVO reqVO) {
+ //如果为空,那么查询全部
+ return selectPage(reqVO, new LambdaQueryWrapperX()
+ .likeIfPresent(BpmProcessInstanceExtDO::getName, reqVO.getName())
+ .eqIfPresent(BpmProcessInstanceExtDO::getProcessDefinitionId, reqVO.getProcessDefinitionId())
+ .eqIfPresent(BpmProcessInstanceExtDO::getCategory, reqVO.getCategory())
+ .eqIfPresent(BpmProcessInstanceExtDO::getStatus, reqVO.getStatus())
+ .eqIfPresent(BpmProcessInstanceExtDO::getResult, reqVO.getResult())
+ .betweenIfPresent(BpmProcessInstanceExtDO::getCreateTime, reqVO.getCreateTime())
+ .orderByDesc(BpmProcessInstanceExtDO::getId));
- default PageResult selectStatisticePage(Long[] userIds, BpmProcessInstanceMyPageReqVO reqVO) {
- if( userIds == null ) {
- //如果为空,那么查询全部
- return selectPage(reqVO, new LambdaQueryWrapperX()
- .likeIfPresent(BpmProcessInstanceExtDO::getName, reqVO.getName())
- .eqIfPresent(BpmProcessInstanceExtDO::getProcessDefinitionId, reqVO.getProcessDefinitionId())
- .eqIfPresent(BpmProcessInstanceExtDO::getCategory, reqVO.getCategory())
- .eqIfPresent(BpmProcessInstanceExtDO::getStatus, reqVO.getStatus())
- .eqIfPresent(BpmProcessInstanceExtDO::getResult, reqVO.getResult())
- .betweenIfPresent(BpmProcessInstanceExtDO::getCreateTime, reqVO.getCreateTime())
- .orderByDesc(BpmProcessInstanceExtDO::getId));
- }else {
- return selectPage(reqVO, new LambdaQueryWrapperX()
- .likeIfPresent(BpmProcessInstanceExtDO::getName, reqVO.getName())
- .eqIfPresent(BpmProcessInstanceExtDO::getProcessDefinitionId, reqVO.getProcessDefinitionId())
- .eqIfPresent(BpmProcessInstanceExtDO::getCategory, reqVO.getCategory())
- .eqIfPresent(BpmProcessInstanceExtDO::getStatus, reqVO.getStatus())
- .eqIfPresent(BpmProcessInstanceExtDO::getResult, reqVO.getResult())
- .betweenIfPresent(BpmProcessInstanceExtDO::getCreateTime, reqVO.getCreateTime())
- .in(BpmProcessInstanceExtDO::getStartUserId,userIds)
- .orderByDesc(BpmProcessInstanceExtDO::getId));
- }
}
- List getUserProcessTpo10(BpmProcessInstanceStatisticsReqVO reqVO) ;
+ List getUserProcessTpo10(BpmProcessInstanceStatisticsReqVO reqVO);
- List selectUnfinishProcessCount(BpmProcessInstanceStatisticsReqVO reqVO) ;
+ List selectUnfinishProcessCount(BpmProcessInstanceStatisticsReqVO reqVO);
}
diff --git a/yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/framework/datapermission/config/DataPermissionConfiguration.java b/yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/framework/datapermission/config/DataPermissionConfiguration.java
index 0c0c3938..140c9c14 100644
--- a/yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/framework/datapermission/config/DataPermissionConfiguration.java
+++ b/yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/framework/datapermission/config/DataPermissionConfiguration.java
@@ -8,20 +8,17 @@ import org.springframework.context.annotation.Configuration;
/**
* 工作流 模块的数据权限 Configuration
*
-
+
*/
-//@Configuration(proxyBeanMethods = false)
+@Configuration(proxyBeanMethods = false)
public class DataPermissionConfiguration {
-// @Bean
-// public DeptDataPermissionRuleCustomizer sysDeptDataPermissionRuleCustomizer() {
-// return rule -> {
-// // dept
-// rule.addDeptColumn(AdminUserDO.class);
-// rule.addDeptColumn(DeptDO.class, "id");
-// // user
-// rule.addUserColumn(BpmProcessInstanceExtDO.class, "start_user_id");
-// };
-// }
+ @Bean
+ public DeptDataPermissionRuleCustomizer sysDeptDataPermissionRuleCustomizer() {
+ return rule -> {
+ // user
+ rule.addUserColumn(BpmProcessInstanceExtDO.class, "start_user_id");
+ };
+ }
}
diff --git a/yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/service/task/BpmProcessInstanceServiceImpl.java b/yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/service/task/BpmProcessInstanceServiceImpl.java
index ab87c40d..8a53a6aa 100644
--- a/yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/service/task/BpmProcessInstanceServiceImpl.java
+++ b/yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/service/task/BpmProcessInstanceServiceImpl.java
@@ -1 +1 @@
-package cn.iocoder.yudao.module.bpm.service.task;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.lang.Assert;
import cn.hutool.core.util.StrUtil;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.util.number.NumberUtils;
import cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils;
import cn.iocoder.yudao.framework.web.core.util.WebFrameworkUtils;
import cn.iocoder.yudao.module.bpm.api.task.dto.BpmProcessInstanceCreateReqDTO;
import cn.iocoder.yudao.module.bpm.controller.admin.task.vo.instance.*;
import cn.iocoder.yudao.module.bpm.controller.admin.task.vo.task.BpmTaskApproveReqVO;
import cn.iocoder.yudao.module.bpm.convert.task.BpmProcessInstanceConvert;
import cn.iocoder.yudao.module.bpm.dal.dataobject.definition.BpmProcessDefinitionExtDO;
import cn.iocoder.yudao.module.bpm.dal.dataobject.definition.BpmTaskAssignRuleDO;
import cn.iocoder.yudao.module.bpm.dal.dataobject.definition.BpmUserGroupDO;
import cn.iocoder.yudao.module.bpm.dal.dataobject.task.BpmProcessInstanceExtDO;
import cn.iocoder.yudao.module.bpm.dal.mysql.definition.BpmTaskAssignRuleMapper;
import cn.iocoder.yudao.module.bpm.dal.mysql.task.BpmProcessInstanceExtMapper;
import cn.iocoder.yudao.module.bpm.dal.mysql.task.BpmTaskExtMapper;
import cn.iocoder.yudao.module.bpm.enums.task.BpmConstants;
import cn.iocoder.yudao.module.bpm.enums.task.BpmProcessInstanceDeleteReasonEnum;
import cn.iocoder.yudao.module.bpm.enums.task.BpmProcessInstanceResultEnum;
import cn.iocoder.yudao.module.bpm.enums.task.BpmProcessInstanceStatusEnum;
import cn.iocoder.yudao.module.bpm.framework.bpm.core.event.BpmProcessInstanceResultEventPublisher;
import cn.iocoder.yudao.module.bpm.service.definition.BpmProcessDefinitionService;
import cn.iocoder.yudao.module.bpm.service.definition.BpmUserGroupService;
import cn.iocoder.yudao.module.bpm.service.message.BpmMessageService;
import cn.iocoder.yudao.module.system.api.dept.DeptApi;
import cn.iocoder.yudao.module.system.api.dept.dto.DeptRespDTO;
import cn.iocoder.yudao.module.system.api.permission.PermissionApi;
import cn.iocoder.yudao.module.system.api.permission.dto.DeptDataPermissionRespDTO;
import cn.iocoder.yudao.module.system.api.user.AdminUserApi;
import cn.iocoder.yudao.module.system.api.user.dto.AdminUserRespDTO;
import lombok.extern.slf4j.Slf4j;
import org.flowable.engine.HistoryService;
import org.flowable.engine.RuntimeService;
import org.flowable.engine.TaskService;
import org.flowable.engine.delegate.event.FlowableCancelledEvent;
import org.flowable.engine.history.HistoricProcessInstance;
import org.flowable.engine.repository.ProcessDefinition;
import org.flowable.engine.runtime.ProcessInstance;
import org.flowable.task.api.Task;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.validation.annotation.Validated;
import javax.annotation.Resource;
import javax.validation.Valid;
import java.lang.reflect.Field;
import java.text.DecimalFormat;
import java.time.LocalDateTime;
import java.util.*;
import java.util.stream.Collectors;
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertList;
import static cn.iocoder.yudao.framework.web.core.util.WebFrameworkUtils.getLoginUserId;
import static cn.iocoder.yudao.module.bpm.enums.ErrorCodeConstants.*;
/**
* 流程实例 Service 实现类
*
* ProcessDefinition & ProcessInstance & Execution & Task 的关系:
* 1.
*
* HistoricProcessInstance & ProcessInstance 的关系:
* 1.
*
* 简单来说,前者 = 历史 + 运行中的流程实例,后者仅是运行中的流程实例
*
*/
@Service
@Validated
@Slf4j
public class BpmProcessInstanceServiceImpl implements BpmProcessInstanceService {
@Resource
private TaskService engineTaskService;
@Resource
private BpmTaskAssignRuleMapper taskRuleMapper;
@Resource
private BpmUserGroupService userGroupService;
@Resource
private RuntimeService runtimeService;
@Resource
private BpmProcessInstanceExtMapper processInstanceExtMapper;
@Resource
@Lazy // 解决循环依赖
private BpmTaskService taskService;
@Resource
private BpmProcessDefinitionService processDefinitionService;
@Resource
private HistoryService historyService;
@Resource
private AdminUserApi adminUserApi;
@Resource
private DeptApi deptApi;
@Resource
private BpmProcessInstanceResultEventPublisher processInstanceResultEventPublisher;
@Resource
@Lazy // 解决循环依赖
private BpmMessageService messageService;
@Override
public ProcessInstance getProcessInstance(String id) {
return runtimeService.createProcessInstanceQuery().processInstanceId(id).singleResult();
}
@Override
public List getProcessInstances(Set ids) {
return runtimeService.createProcessInstanceQuery().processInstanceIds(ids).list();
}
@Override
public PageResult getMyProcessInstancePage(Long userId,
BpmProcessInstanceMyPageReqVO pageReqVO) {
// 通过 BpmProcessInstanceExtDO 表,先查询到对应的分页
PageResult pageResult = processInstanceExtMapper.selectPage(userId, pageReqVO);
if (CollUtil.isEmpty(pageResult.getList())) {
return new PageResult<>(pageResult.getTotal());
}
// 获得流程 Task Map
List processInstanceIds = convertList(pageResult.getList(), BpmProcessInstanceExtDO::getProcessInstanceId);
Map> taskMap = taskService.getTaskMapByProcessInstanceIds(processInstanceIds);
List ids = taskMap.values().stream()
.flatMap(Collection::stream)
.map(Task::getAssignee)
.collect(Collectors.toList());
List longIds = ids.stream()
.map(Long::valueOf)
.collect(Collectors.toList());
// 获得 User Map
Map userMap = adminUserApi.getUserMap(longIds);
// 转换返回
return BpmProcessInstanceConvert.INSTANCE.convertPage(pageResult, taskMap, userMap);
}
@Override
@Transactional(rollbackFor = Exception.class)
public String createProcessInstance(Long userId, @Valid BpmProcessInstanceCreateReqVO createReqVO) {
// 获得流程定义
ProcessDefinition definition = processDefinitionService.getProcessDefinition(createReqVO.getProcessDefinitionId());
// 发起流程
return createProcessInstance0(userId, definition, createReqVO.getVariables(), null);
}
@Override
public String createProcessInstance(Long userId, @Valid BpmProcessInstanceCreateReqDTO createReqDTO) {
// 获得流程定义
ProcessDefinition definition = processDefinitionService.getActiveProcessDefinition(createReqDTO.getProcessDefinitionKey());
// 发起流程
return createProcessInstance0(userId, definition, createReqDTO.getVariables(), createReqDTO.getBusinessKey());
}
@Override
public BpmProcessInstanceRespVO getProcessInstanceVO(String id) {
// 获得流程实例
HistoricProcessInstance processInstance = getHistoricProcessInstance(id);
if (processInstance == null) {
return null;
}
BpmProcessInstanceExtDO processInstanceExt = processInstanceExtMapper.selectByProcessInstanceId(id);
Assert.notNull(processInstanceExt, "流程实例拓展({}) 不存在", id);
// 获得流程定义
ProcessDefinition processDefinition = processDefinitionService
.getProcessDefinition(processInstance.getProcessDefinitionId());
Assert.notNull(processDefinition, "流程定义({}) 不存在", processInstance.getProcessDefinitionId());
BpmProcessDefinitionExtDO processDefinitionExt = processDefinitionService.getProcessDefinitionExt(
processInstance.getProcessDefinitionId());
Assert.notNull(processDefinitionExt, "流程定义拓展({}) 不存在", id);
String bpmnXml = processDefinitionService.getProcessDefinitionBpmnXML(processInstance.getProcessDefinitionId());
// 获得 User
AdminUserRespDTO startUser = adminUserApi.getUser(NumberUtils.parseLong(processInstance.getStartUserId())).getCheckedData();
DeptRespDTO dept = null;
if (startUser != null) {
dept = deptApi.getDept(startUser.getDeptId()).getCheckedData();
}
// 拼接结果
return BpmProcessInstanceConvert.INSTANCE.convert2(processInstance, processInstanceExt,
processDefinition, processDefinitionExt, bpmnXml, startUser, dept);
}
@Override
public void cancelProcessInstance(Long userId, @Valid BpmProcessInstanceCancelReqVO cancelReqVO) {
// 校验流程实例存在
ProcessInstance instance = getProcessInstance(cancelReqVO.getId());
if (instance == null) {
throw exception(PROCESS_INSTANCE_CANCEL_FAIL_NOT_EXISTS);
}
// 只能取消自己的
if (!Objects.equals(instance.getStartUserId(), String.valueOf(userId))) {
throw exception(PROCESS_INSTANCE_CANCEL_FAIL_NOT_SELF);
}
// 通过删除流程实例,实现流程实例的取消,
// 删除流程实例,正则执行任务 ACT_RU_TASK. 任务会被删除。通过历史表查询
deleteProcessInstance(cancelReqVO.getId(),
BpmProcessInstanceDeleteReasonEnum.CANCEL_TASK.format(cancelReqVO.getReason()));
}
/**
* 获得历史的流程实例
*
* @param id 流程实例的编号
* @return 历史的流程实例
*/
@Override
public HistoricProcessInstance getHistoricProcessInstance(String id) {
return historyService.createHistoricProcessInstanceQuery().processInstanceId(id).singleResult();
}
@Override
public List getHistoricProcessInstances(Set ids) {
return historyService.createHistoricProcessInstanceQuery().processInstanceIds(ids).list();
}
@Override
public void createProcessInstanceExt(ProcessInstance instance) {
// 获得流程定义
ProcessDefinition definition = processDefinitionService.getProcessDefinition2(instance.getProcessDefinitionId());
// 插入 BpmProcessInstanceExtDO 对象
BpmProcessInstanceExtDO instanceExtDO = new BpmProcessInstanceExtDO()
.setProcessInstanceId(instance.getId())
.setProcessDefinitionId(definition.getId())
.setName(instance.getProcessDefinitionName())
.setStartUserId(Long.valueOf(instance.getStartUserId()))
.setCategory(definition.getCategory())
.setStatus(BpmProcessInstanceStatusEnum.RUNNING.getStatus())
.setResult(BpmProcessInstanceResultEnum.PROCESS.getResult());
processInstanceExtMapper.insert(instanceExtDO);
}
@Override
public void updateProcessInstanceExtCancel(FlowableCancelledEvent event) {
// 判断是否为 Reject 不通过。如果是,则不进行更新.
// 因为,updateProcessInstanceExtReject 方法,已经进行更新了
if (BpmProcessInstanceDeleteReasonEnum.isRejectReason((String)event.getCause())) {
return;
}
// 需要主动查询,因为 instance 只有 id 属性
// 另外,此时如果去查询 ProcessInstance 的话,字段是不全的,所以去查询了 HistoricProcessInstance
HistoricProcessInstance processInstance = getHistoricProcessInstance(event.getProcessInstanceId());
// 更新拓展表
BpmProcessInstanceExtDO instanceExtDO = new BpmProcessInstanceExtDO()
.setProcessInstanceId(event.getProcessInstanceId())
.setEndTime(LocalDateTime.now()) // 由于 ProcessInstance 里没有办法拿到 endTime,所以这里设置
.setStatus(BpmProcessInstanceStatusEnum.FINISH.getStatus())
.setResult(BpmProcessInstanceResultEnum.CANCEL.getResult());
processInstanceExtMapper.updateByProcessInstanceId(instanceExtDO);
// 发送流程实例的状态事件
processInstanceResultEventPublisher.sendProcessInstanceResultEvent(
BpmProcessInstanceConvert.INSTANCE.convert(this, processInstance, instanceExtDO.getResult()));
}
@Override
public void updateProcessInstanceExtComplete(ProcessInstance instance) {
// 需要主动查询,因为 instance 只有 id 属性
// 另外,此时如果去查询 ProcessInstance 的话,字段是不全的,所以去查询了 HistoricProcessInstance
HistoricProcessInstance processInstance = getHistoricProcessInstance(instance.getId());
// 更新拓展表
BpmProcessInstanceExtDO instanceExtDO = new BpmProcessInstanceExtDO()
.setProcessInstanceId(instance.getProcessInstanceId())
.setEndTime(LocalDateTime.now()) // 由于 ProcessInstance 里没有办法拿到 endTime,所以这里设置
.setStatus(BpmProcessInstanceStatusEnum.FINISH.getStatus())
.setResult(BpmProcessInstanceResultEnum.APPROVE.getResult()); // 如果正常完全,说明审批通过
processInstanceExtMapper.updateByProcessInstanceId(instanceExtDO);
Map processVariables = runtimeService.getVariables(instance.getProcessInstanceId());
String reason = (String)processVariables.get("approve_reason") ;
// 发送流程被通过的消息
messageService.sendMessageWhenProcessInstanceApprove(BpmProcessInstanceConvert.INSTANCE.convert2ApprovedReq(instance,reason));
// 发送流程实例的状态事件
processInstanceResultEventPublisher.sendProcessInstanceResultEvent(
BpmProcessInstanceConvert.INSTANCE.convert(this, processInstance, instanceExtDO.getResult()));
}
@Override
@Transactional(rollbackFor = Exception.class)
public void updateProcessInstanceExtReject(String id, String reason) {
// 需要主动查询,因为 instance 只有 id 属性
ProcessInstance processInstance = getProcessInstance(id);
// 删除流程实例,以实现驳回任务时,取消整个审批流程
deleteProcessInstance(id, StrUtil.format(BpmProcessInstanceDeleteReasonEnum.REJECT_TASK.format(reason)));
// 更新 status + result
// 注意,不能和上面的逻辑更换位置。因为 deleteProcessInstance 会触发流程的取消,进而调用 updateProcessInstanceExtCancel 方法,
// 设置 result 为 BpmProcessInstanceStatusEnum.CANCEL,显然和 result 不一定是一致的
BpmProcessInstanceExtDO instanceExtDO = new BpmProcessInstanceExtDO().setProcessInstanceId(id)
.setStatus(BpmProcessInstanceStatusEnum.FINISH.getStatus())
.setResult(BpmProcessInstanceResultEnum.REJECT.getResult());
processInstanceExtMapper.updateByProcessInstanceId(instanceExtDO);
// 发送流程被不通过的消息
messageService.sendMessageWhenProcessInstanceReject(BpmProcessInstanceConvert.INSTANCE.convert2RejectReq(processInstance, reason));
// 发送流程实例的状态事件
processInstanceResultEventPublisher.sendProcessInstanceResultEvent(
BpmProcessInstanceConvert.INSTANCE.convert(this, processInstance, instanceExtDO.getResult()));
}
private void deleteProcessInstance(String id, String reason) {
runtimeService.deleteProcessInstance(id, reason);
}
private String createProcessInstance0(Long userId, ProcessDefinition definition,
Map variables, String businessKey) {
// 校验流程定义
if (definition == null) {
throw exception(PROCESS_DEFINITION_NOT_EXISTS);
}
if (definition.isSuspended()) {
throw exception(PROCESS_DEFINITION_IS_SUSPENDED);
}
// 创建流程实例
ProcessInstance instance = runtimeService.createProcessInstanceBuilder()
.processDefinitionId(definition.getId())
.businessKey(businessKey)
.name(definition.getName().trim())
.variables(variables)
.start();
// 设置流程名字
runtimeService.setProcessInstanceName(instance.getId(), definition.getName());
// 补全流程实例的拓展表
processInstanceExtMapper.updateByProcessInstanceId(new BpmProcessInstanceExtDO().setProcessInstanceId(instance.getId())
.setFormVariables(variables));
/** 创建流程后,添加抄送人 End add by yj 2024.1.4 */
processCCToUsers(definition,instance) ;
/** 通过自己发起的流程 */
approveSelfTask(instance.getId()) ;
return instance.getId();
}
private void approveSelfTask(String processInstanceId ) {
List tasks =engineTaskService.createTaskQuery().processInstanceId(processInstanceId).list() ;
if( tasks != null && tasks.size() > 0) {
Task task = tasks.get(0) ;
String assigneeId = task.getAssignee();
//如果当前登陆用户是审批人,那么自动审批通过
if( assigneeId.equals( SecurityFrameworkUtils.getLoginUserId().toString() )) {
BpmTaskApproveReqVO reqVO = new BpmTaskApproveReqVO() ;
reqVO.setId(task.getId()) ;
reqVO.setReason(BpmConstants.AUTO_APPRAVAL);
taskService.approveTask(getLoginUserId(), reqVO);
}
}
}
/**
* 获得抄送我的流程实例的分页
*
* @param userId 用户编号
* @param pageReqVO 分页请求
* @return 流程实例的分页
*/
public PageResult getMyCCProcessInstancePage(Long userId,
BpmProcessInstanceMyPageReqVO pageReqVO) {
// 通过 BpmProcessInstanceExtDO 表,先查询到对应的分页
PageResult pageResult = processInstanceExtMapper.selectCCPage(userId, pageReqVO);
if (CollUtil.isEmpty(pageResult.getList())) {
return new PageResult<>(pageResult.getTotal());
}
// 获得流程 Task Map
List processInstanceIds = convertList(pageResult.getList(), BpmProcessInstanceExtDO::getProcessInstanceId);
Map> taskMap = taskService.getTaskMapByProcessInstanceIds(processInstanceIds);
// 转换返回
return BpmProcessInstanceConvert.INSTANCE.convertPage(pageResult, taskMap,null);
}
public List getProcessInstancesGroupByModelName(BpmProcessInstanceStatisticsReqVO pageReqVO){
pageReqVO = getUserids(pageReqVO) ;
return processInstanceExtMapper.getProcessInstancesGroupByModelName(pageReqVO) ;
}
public List getProcessInstancesGroupByResultStatus(BpmProcessInstanceStatisticsReqVO pageReqVO){
pageReqVO = getUserids(pageReqVO) ;
return processInstanceExtMapper.getProcessInstancesGroupByResultStatus(pageReqVO) ;
}
public PageResult getStatisticsProcessInstancePage(@Valid BpmProcessInstanceMyPageReqVO pageReqVO) {
pageReqVO = getUserids(pageReqVO) ;
// 通过 BpmProcessInstanceExtDO 表,先查询到对应的分页
PageResult pageResult = processInstanceExtMapper.selectStatisticePage(pageReqVO.getUserIds(), pageReqVO);
if (CollUtil.isEmpty(pageResult.getList())) {
return new PageResult<>(pageResult.getTotal());
}
// 获得流程 Task Map
List processInstanceIds = convertList(pageResult.getList(), BpmProcessInstanceExtDO::getProcessInstanceId);
Map> taskMap = taskService.getTaskMapByProcessInstanceIds(processInstanceIds);
List ids = taskMap.values().stream()
.flatMap(Collection::stream)
.map(Task::getAssignee)
.collect(Collectors.toList());
List longIds = ids.stream()
.map(Long::valueOf)
.collect(Collectors.toList());
//获得 审批人 User Map
Map assigneeUserMap = adminUserApi.getUserMap(longIds);
//获得 发起人 User Map
List bpieDOs = pageResult.getList() ;
longIds = new ArrayList<>() ;
for (BpmProcessInstanceExtDO bpieDO: bpieDOs) {
longIds.add(bpieDO.getStartUserId()) ;
}
Map startUserMap = adminUserApi.getUserMap(longIds);
// 转换返回
return BpmProcessInstanceConvert.INSTANCE.convertStatisticsPage(pageResult, taskMap, assigneeUserMap,startUserMap);
}
@Resource
PermissionApi permissionApi;
/**
* 根据数据权限,查询关联操作的用户IDS
* @param pageReqVO
* @return
* @param
*/
private T getUserids(T pageReqVO) {
try {
Class clazz = (Class) pageReqVO.getClass();
Field idField = clazz.getDeclaredField("userIds");
idField.setAccessible(true); // 设置可访问性
Long[] userIds = null;
Long userId = WebFrameworkUtils.getLoginUserId();
DeptDataPermissionRespDTO deptDataPermission = permissionApi.getDeptDataPermission(userId).getCheckedData();
//查询全部
if (deptDataPermission.getAll()) {
//idField.set(pageReqVO, null); // 设置属性值
return pageReqVO;
}
// 情况二,即不能查看部门,又不能查看自己,则说明 100% 无权限
if (CollUtil.isEmpty(deptDataPermission.getDeptIds())
&& Boolean.FALSE.equals(deptDataPermission.getSelf())) {
//设置成0,一个不存在的用户Id,就查询不到数据了。
userIds = new Long[]{0L};
idField.set(pageReqVO, userIds);
return pageReqVO;
}
//情况三 至查询自己
if (deptDataPermission.getSelf()) {
userIds = new Long[]{userId};
idField.set(pageReqVO, userIds);
return pageReqVO;
}
Set deptIds = deptDataPermission.getDeptIds();
//查询部门关联的用户Id
List users = adminUserApi.getUserListByDeptIds(deptIds).getCheckedData();
List tempList = new ArrayList<>();
for (AdminUserRespDTO user : users) {
Long id = user.getId();
tempList.add(id);
}
tempList.add(userId);
userIds = tempList.stream().toArray(Long[]::new); //将临时的List集合转换成数组集合
idField.set(pageReqVO, userIds);
return pageReqVO;
}catch (Exception exception){
exception.printStackTrace();
throw exception(BPM_SYSTEM_BUG);
}
}
/**
* /创建流程后,添加抄送人 Begin add by yj 2024.1.4
* 在设计流程的时候,需要添加一个任务块 名字必须叫Activity_cc 分配权限的时候,需要选择用户组。
*
* @param definition
* @param instance
*/
private void processCCToUsers(ProcessDefinition definition, ProcessInstance instance) {
//获取bpm_task_assign_reule (Bpm 任务规则表)的流程中有没有配置抄送节点 固定抄送名称为:Activity_cc
String processDefinitionId = definition.getId() ;
List rules = taskRuleMapper.selectListByProcessDefinitionId(processDefinitionId, null);
for(BpmTaskAssignRuleDO rule :rules ){
String key = rule.getTaskDefinitionKey() ; //任务名称
Integer type = rule.getType() ;
if( !key.isEmpty() && key.equals(BpmConstants.CC_NAME) && type == 40 ) {
StringBuffer str = new StringBuffer() ;
Set options = rule.getOptions() ;
List list = new ArrayList(options);
for(Long groupId : list) {
//需要根据这个groupId,查询这个组中的用户id
BpmUserGroupDO userGroup = userGroupService.getUserGroup(groupId);
Set userIds = userGroup.getMemberUserIds() ;
List userIdList = new ArrayList(userIds);
for(Long user_id : userIdList) {
str.append("[").append(user_id).append("]") ;
}
}
String ccids = str.toString() ;
//根据processDefinitionId 将ccids保存到bpm_process_instance_ext中的ccids字段
BpmProcessInstanceExtDO instanceExtDO = new BpmProcessInstanceExtDO().setProcessDefinitionId(processDefinitionId)
.setCcids(ccids) .setProcessInstanceId(instance.getProcessInstanceId());
processInstanceExtMapper.updateByProcessInstanceId(instanceExtDO);
break ;
}
}
}
@Resource
private BpmTaskExtMapper taskExtMapper;
@Override
public List getUserProcessTpo10(BpmProcessInstanceStatisticsReqVO pageReqVO) {
//按审核人分组查询,统计已完成流程数量及平均耗时间
List respVOS = processInstanceExtMapper.getUserProcessTpo10(pageReqVO);
if( respVOS == null || respVOS.size() == 0) {
return null ;
}
List idList = respVOS.stream()
.map(BpmProcessFinishStatisticsRespVO::getUserId)
.collect(Collectors.toList());
//根据userId,查询UserMap
Map userMap = adminUserApi.getUserMap(idList) ;
Long[] idsArray = new Long[userMap.size()];
// 使用 map 的 keySet() 方法获取键集合
Set keys = userMap.keySet();
// 遍历键集合,将每个键添加到数组中
int index = 0;
for (Long key : keys) {
idsArray[index++] = key;
}
pageReqVO.setUserIds(idsArray) ;
//按审核人分组查询,未审批完成的流程数量
List bpmTaskExtDOs = processInstanceExtMapper.selectUnfinishProcessCount( pageReqVO ) ;
//按审核人分组查询,未完成的记录数
Map unFinfishCountCountMap = new HashMap<>();
for (BpmProcessFinishStatisticsRespVO item : bpmTaskExtDOs) {
unFinfishCountCountMap.put(item.getUserId(), item.getUnFinfishCount());
}
respVOS.forEach(respVO -> respVO.setName( userMap.get(respVO.getUserId()).getNickname()));
respVOS.forEach(respVO -> respVO.setUnFinfishCount( unFinfishCountCountMap.get(respVO.getUserId())));
//获取排行榜第一记录的耗时,作为基础数据
double num = Double.parseDouble(respVOS.get(0).getUserTime()); // 先将字符串转换为双精度浮点数
int baseNumber = (int)num; // 再通过类型转换操作符将其转换为整数
DecimalFormat df = new DecimalFormat("#.00");
respVOS.forEach(respVO -> {
//格式化流程完成率
float finfishCount = (float) respVO.getFinfishCount() ;
float unFinfishCount = respVO.getUnFinfishCount() == null ? 0: respVO.getUnFinfishCount();
float all = finfishCount + unFinfishCount ;
float result = finfishCount / all;
float rate = result * 100 ;
respVO.setCompletionRate(df.format(rate)+"%") ;
double dValue = Double.parseDouble(respVO.getUserTime()); // 将字符串转换为double类型
int roundedValue = (int) Math.round(dValue); // 使用Math.round()进行四舍五入,并转换为int类型
respVO.setUserTime(roundedValue+"") ;
//格式化进度百度比, 参照最高的数据进行百分比显示
double percentage = ((int)Double.parseDouble(respVO.getUserTime()) / (double) baseNumber) * 100;
respVO.setPercentage((int) Math.round(percentage)) ;
//设置未完成
respVO.setUnFinfishCount( Integer.valueOf((int)unFinfishCount)) ;
});
return respVOS ;
}
@Override
public BpmProcessInstanceExtDO getProcessInstanceDO(String id) {
return processInstanceExtMapper.selectByProcessInstanceId(id);
}
}
\ No newline at end of file
+package cn.iocoder.yudao.module.bpm.service.task;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.lang.Assert;
import cn.hutool.core.util.StrUtil;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.util.number.NumberUtils;
import cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils;
import cn.iocoder.yudao.framework.web.core.util.WebFrameworkUtils;
import cn.iocoder.yudao.module.bpm.api.task.dto.BpmProcessInstanceCreateReqDTO;
import cn.iocoder.yudao.module.bpm.controller.admin.task.vo.instance.*;
import cn.iocoder.yudao.module.bpm.controller.admin.task.vo.task.BpmTaskApproveReqVO;
import cn.iocoder.yudao.module.bpm.convert.task.BpmProcessInstanceConvert;
import cn.iocoder.yudao.module.bpm.dal.dataobject.definition.BpmProcessDefinitionExtDO;
import cn.iocoder.yudao.module.bpm.dal.dataobject.definition.BpmTaskAssignRuleDO;
import cn.iocoder.yudao.module.bpm.dal.dataobject.definition.BpmUserGroupDO;
import cn.iocoder.yudao.module.bpm.dal.dataobject.task.BpmProcessInstanceExtDO;
import cn.iocoder.yudao.module.bpm.dal.mysql.definition.BpmTaskAssignRuleMapper;
import cn.iocoder.yudao.module.bpm.dal.mysql.task.BpmProcessInstanceExtMapper;
import cn.iocoder.yudao.module.bpm.dal.mysql.task.BpmTaskExtMapper;
import cn.iocoder.yudao.module.bpm.enums.task.BpmConstants;
import cn.iocoder.yudao.module.bpm.enums.task.BpmProcessInstanceDeleteReasonEnum;
import cn.iocoder.yudao.module.bpm.enums.task.BpmProcessInstanceResultEnum;
import cn.iocoder.yudao.module.bpm.enums.task.BpmProcessInstanceStatusEnum;
import cn.iocoder.yudao.module.bpm.framework.bpm.core.event.BpmProcessInstanceResultEventPublisher;
import cn.iocoder.yudao.module.bpm.service.definition.BpmProcessDefinitionService;
import cn.iocoder.yudao.module.bpm.service.definition.BpmUserGroupService;
import cn.iocoder.yudao.module.bpm.service.message.BpmMessageService;
import cn.iocoder.yudao.module.system.api.dept.DeptApi;
import cn.iocoder.yudao.module.system.api.dept.dto.DeptRespDTO;
import cn.iocoder.yudao.module.system.api.permission.PermissionApi;
import cn.iocoder.yudao.module.system.api.permission.dto.DeptDataPermissionRespDTO;
import cn.iocoder.yudao.module.system.api.user.AdminUserApi;
import cn.iocoder.yudao.module.system.api.user.dto.AdminUserRespDTO;
import lombok.extern.slf4j.Slf4j;
import org.flowable.engine.HistoryService;
import org.flowable.engine.RuntimeService;
import org.flowable.engine.TaskService;
import org.flowable.engine.delegate.event.FlowableCancelledEvent;
import org.flowable.engine.history.HistoricProcessInstance;
import org.flowable.engine.repository.ProcessDefinition;
import org.flowable.engine.runtime.ProcessInstance;
import org.flowable.task.api.Task;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.validation.annotation.Validated;
import javax.annotation.Resource;
import javax.validation.Valid;
import java.lang.reflect.Field;
import java.text.DecimalFormat;
import java.time.LocalDateTime;
import java.util.*;
import java.util.stream.Collectors;
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertList;
import static cn.iocoder.yudao.framework.web.core.util.WebFrameworkUtils.getLoginUserId;
import static cn.iocoder.yudao.module.bpm.enums.ErrorCodeConstants.*;
/**
* 流程实例 Service 实现类
*
* ProcessDefinition & ProcessInstance & Execution & Task 的关系:
* 1.
*
* HistoricProcessInstance & ProcessInstance 的关系:
* 1.
*
* 简单来说,前者 = 历史 + 运行中的流程实例,后者仅是运行中的流程实例
*
*/
@Service
@Validated
@Slf4j
public class BpmProcessInstanceServiceImpl implements BpmProcessInstanceService {
@Resource
private TaskService engineTaskService;
@Resource
private BpmTaskAssignRuleMapper taskRuleMapper;
@Resource
private BpmUserGroupService userGroupService;
@Resource
private RuntimeService runtimeService;
@Resource
private BpmProcessInstanceExtMapper processInstanceExtMapper;
@Resource
@Lazy // 解决循环依赖
private BpmTaskService taskService;
@Resource
private BpmProcessDefinitionService processDefinitionService;
@Resource
private HistoryService historyService;
@Resource
private AdminUserApi adminUserApi;
@Resource
private DeptApi deptApi;
@Resource
private BpmProcessInstanceResultEventPublisher processInstanceResultEventPublisher;
@Resource
@Lazy // 解决循环依赖
private BpmMessageService messageService;
@Override
public ProcessInstance getProcessInstance(String id) {
return runtimeService.createProcessInstanceQuery().processInstanceId(id).singleResult();
}
@Override
public List getProcessInstances(Set ids) {
return runtimeService.createProcessInstanceQuery().processInstanceIds(ids).list();
}
@Override
public PageResult getMyProcessInstancePage(Long userId,
BpmProcessInstanceMyPageReqVO pageReqVO) {
// 通过 BpmProcessInstanceExtDO 表,先查询到对应的分页
PageResult pageResult = processInstanceExtMapper.selectPage(userId, pageReqVO);
if (CollUtil.isEmpty(pageResult.getList())) {
return new PageResult<>(pageResult.getTotal());
}
// 获得流程 Task Map
List processInstanceIds = convertList(pageResult.getList(), BpmProcessInstanceExtDO::getProcessInstanceId);
Map> taskMap = taskService.getTaskMapByProcessInstanceIds(processInstanceIds);
List ids = taskMap.values().stream()
.flatMap(Collection::stream)
.map(Task::getAssignee)
.collect(Collectors.toList());
List longIds = ids.stream()
.map(Long::valueOf)
.collect(Collectors.toList());
// 获得 User Map
Map userMap = adminUserApi.getUserMap(longIds);
// 转换返回
return BpmProcessInstanceConvert.INSTANCE.convertPage(pageResult, taskMap, userMap);
}
@Override
@Transactional(rollbackFor = Exception.class)
public String createProcessInstance(Long userId, @Valid BpmProcessInstanceCreateReqVO createReqVO) {
// 获得流程定义
ProcessDefinition definition = processDefinitionService.getProcessDefinition(createReqVO.getProcessDefinitionId());
// 发起流程
return createProcessInstance0(userId, definition, createReqVO.getVariables(), null);
}
@Override
public String createProcessInstance(Long userId, @Valid BpmProcessInstanceCreateReqDTO createReqDTO) {
// 获得流程定义
ProcessDefinition definition = processDefinitionService.getActiveProcessDefinition(createReqDTO.getProcessDefinitionKey());
// 发起流程
return createProcessInstance0(userId, definition, createReqDTO.getVariables(), createReqDTO.getBusinessKey());
}
@Override
public BpmProcessInstanceRespVO getProcessInstanceVO(String id) {
// 获得流程实例
HistoricProcessInstance processInstance = getHistoricProcessInstance(id);
if (processInstance == null) {
return null;
}
BpmProcessInstanceExtDO processInstanceExt = processInstanceExtMapper.selectByProcessInstanceId(id);
Assert.notNull(processInstanceExt, "流程实例拓展({}) 不存在", id);
// 获得流程定义
ProcessDefinition processDefinition = processDefinitionService
.getProcessDefinition(processInstance.getProcessDefinitionId());
Assert.notNull(processDefinition, "流程定义({}) 不存在", processInstance.getProcessDefinitionId());
BpmProcessDefinitionExtDO processDefinitionExt = processDefinitionService.getProcessDefinitionExt(
processInstance.getProcessDefinitionId());
Assert.notNull(processDefinitionExt, "流程定义拓展({}) 不存在", id);
String bpmnXml = processDefinitionService.getProcessDefinitionBpmnXML(processInstance.getProcessDefinitionId());
// 获得 User
AdminUserRespDTO startUser = adminUserApi.getUser(NumberUtils.parseLong(processInstance.getStartUserId())).getCheckedData();
DeptRespDTO dept = null;
if (startUser != null) {
dept = deptApi.getDept(startUser.getDeptId()).getCheckedData();
}
// 拼接结果
return BpmProcessInstanceConvert.INSTANCE.convert2(processInstance, processInstanceExt,
processDefinition, processDefinitionExt, bpmnXml, startUser, dept);
}
@Override
public void cancelProcessInstance(Long userId, @Valid BpmProcessInstanceCancelReqVO cancelReqVO) {
// 校验流程实例存在
ProcessInstance instance = getProcessInstance(cancelReqVO.getId());
if (instance == null) {
throw exception(PROCESS_INSTANCE_CANCEL_FAIL_NOT_EXISTS);
}
// 只能取消自己的
if (!Objects.equals(instance.getStartUserId(), String.valueOf(userId))) {
throw exception(PROCESS_INSTANCE_CANCEL_FAIL_NOT_SELF);
}
// 通过删除流程实例,实现流程实例的取消,
// 删除流程实例,正则执行任务 ACT_RU_TASK. 任务会被删除。通过历史表查询
deleteProcessInstance(cancelReqVO.getId(),
BpmProcessInstanceDeleteReasonEnum.CANCEL_TASK.format(cancelReqVO.getReason()));
}
/**
* 获得历史的流程实例
*
* @param id 流程实例的编号
* @return 历史的流程实例
*/
@Override
public HistoricProcessInstance getHistoricProcessInstance(String id) {
return historyService.createHistoricProcessInstanceQuery().processInstanceId(id).singleResult();
}
@Override
public List getHistoricProcessInstances(Set ids) {
return historyService.createHistoricProcessInstanceQuery().processInstanceIds(ids).list();
}
@Override
public void createProcessInstanceExt(ProcessInstance instance) {
// 获得流程定义
ProcessDefinition definition = processDefinitionService.getProcessDefinition2(instance.getProcessDefinitionId());
// 插入 BpmProcessInstanceExtDO 对象
BpmProcessInstanceExtDO instanceExtDO = new BpmProcessInstanceExtDO()
.setProcessInstanceId(instance.getId())
.setProcessDefinitionId(definition.getId())
.setName(instance.getProcessDefinitionName())
.setStartUserId(Long.valueOf(instance.getStartUserId()))
.setCategory(definition.getCategory())
.setStatus(BpmProcessInstanceStatusEnum.RUNNING.getStatus())
.setResult(BpmProcessInstanceResultEnum.PROCESS.getResult());
processInstanceExtMapper.insert(instanceExtDO);
}
@Override
public void updateProcessInstanceExtCancel(FlowableCancelledEvent event) {
// 判断是否为 Reject 不通过。如果是,则不进行更新.
// 因为,updateProcessInstanceExtReject 方法,已经进行更新了
if (BpmProcessInstanceDeleteReasonEnum.isRejectReason((String)event.getCause())) {
return;
}
// 需要主动查询,因为 instance 只有 id 属性
// 另外,此时如果去查询 ProcessInstance 的话,字段是不全的,所以去查询了 HistoricProcessInstance
HistoricProcessInstance processInstance = getHistoricProcessInstance(event.getProcessInstanceId());
// 更新拓展表
BpmProcessInstanceExtDO instanceExtDO = new BpmProcessInstanceExtDO()
.setProcessInstanceId(event.getProcessInstanceId())
.setEndTime(LocalDateTime.now()) // 由于 ProcessInstance 里没有办法拿到 endTime,所以这里设置
.setStatus(BpmProcessInstanceStatusEnum.FINISH.getStatus())
.setResult(BpmProcessInstanceResultEnum.CANCEL.getResult());
processInstanceExtMapper.updateByProcessInstanceId(instanceExtDO);
// 发送流程实例的状态事件
processInstanceResultEventPublisher.sendProcessInstanceResultEvent(
BpmProcessInstanceConvert.INSTANCE.convert(this, processInstance, instanceExtDO.getResult()));
}
@Override
public void updateProcessInstanceExtComplete(ProcessInstance instance) {
// 需要主动查询,因为 instance 只有 id 属性
// 另外,此时如果去查询 ProcessInstance 的话,字段是不全的,所以去查询了 HistoricProcessInstance
HistoricProcessInstance processInstance = getHistoricProcessInstance(instance.getId());
// 更新拓展表
BpmProcessInstanceExtDO instanceExtDO = new BpmProcessInstanceExtDO()
.setProcessInstanceId(instance.getProcessInstanceId())
.setEndTime(LocalDateTime.now()) // 由于 ProcessInstance 里没有办法拿到 endTime,所以这里设置
.setStatus(BpmProcessInstanceStatusEnum.FINISH.getStatus())
.setResult(BpmProcessInstanceResultEnum.APPROVE.getResult()); // 如果正常完全,说明审批通过
processInstanceExtMapper.updateByProcessInstanceId(instanceExtDO);
Map processVariables = runtimeService.getVariables(instance.getProcessInstanceId());
String reason = (String)processVariables.get("approve_reason") ;
// 发送流程被通过的消息
messageService.sendMessageWhenProcessInstanceApprove(BpmProcessInstanceConvert.INSTANCE.convert2ApprovedReq(instance,reason));
// 发送流程实例的状态事件
processInstanceResultEventPublisher.sendProcessInstanceResultEvent(
BpmProcessInstanceConvert.INSTANCE.convert(this, processInstance, instanceExtDO.getResult()));
}
@Override
@Transactional(rollbackFor = Exception.class)
public void updateProcessInstanceExtReject(String id, String reason) {
// 需要主动查询,因为 instance 只有 id 属性
ProcessInstance processInstance = getProcessInstance(id);
// 删除流程实例,以实现驳回任务时,取消整个审批流程
deleteProcessInstance(id, StrUtil.format(BpmProcessInstanceDeleteReasonEnum.REJECT_TASK.format(reason)));
// 更新 status + result
// 注意,不能和上面的逻辑更换位置。因为 deleteProcessInstance 会触发流程的取消,进而调用 updateProcessInstanceExtCancel 方法,
// 设置 result 为 BpmProcessInstanceStatusEnum.CANCEL,显然和 result 不一定是一致的
BpmProcessInstanceExtDO instanceExtDO = new BpmProcessInstanceExtDO().setProcessInstanceId(id)
.setStatus(BpmProcessInstanceStatusEnum.FINISH.getStatus())
.setResult(BpmProcessInstanceResultEnum.REJECT.getResult());
processInstanceExtMapper.updateByProcessInstanceId(instanceExtDO);
// 发送流程被不通过的消息
messageService.sendMessageWhenProcessInstanceReject(BpmProcessInstanceConvert.INSTANCE.convert2RejectReq(processInstance, reason));
// 发送流程实例的状态事件
processInstanceResultEventPublisher.sendProcessInstanceResultEvent(
BpmProcessInstanceConvert.INSTANCE.convert(this, processInstance, instanceExtDO.getResult()));
}
private void deleteProcessInstance(String id, String reason) {
runtimeService.deleteProcessInstance(id, reason);
}
private String createProcessInstance0(Long userId, ProcessDefinition definition,
Map variables, String businessKey) {
// 校验流程定义
if (definition == null) {
throw exception(PROCESS_DEFINITION_NOT_EXISTS);
}
if (definition.isSuspended()) {
throw exception(PROCESS_DEFINITION_IS_SUSPENDED);
}
// 创建流程实例
ProcessInstance instance = runtimeService.createProcessInstanceBuilder()
.processDefinitionId(definition.getId())
.businessKey(businessKey)
.name(definition.getName().trim())
.variables(variables)
.start();
// 设置流程名字
runtimeService.setProcessInstanceName(instance.getId(), definition.getName());
// 补全流程实例的拓展表
processInstanceExtMapper.updateByProcessInstanceId(new BpmProcessInstanceExtDO().setProcessInstanceId(instance.getId())
.setFormVariables(variables));
/** 创建流程后,添加抄送人 End add by yj 2024.1.4 */
processCCToUsers(definition,instance) ;
/** 通过自己发起的流程 */
approveSelfTask(instance.getId()) ;
return instance.getId();
}
private void approveSelfTask(String processInstanceId ) {
List tasks =engineTaskService.createTaskQuery().processInstanceId(processInstanceId).list() ;
if( tasks != null && tasks.size() > 0) {
Task task = tasks.get(0) ;
String assigneeId = task.getAssignee();
//如果当前登陆用户是审批人,那么自动审批通过
if( assigneeId.equals( SecurityFrameworkUtils.getLoginUserId().toString() )) {
BpmTaskApproveReqVO reqVO = new BpmTaskApproveReqVO() ;
reqVO.setId(task.getId()) ;
reqVO.setReason(BpmConstants.AUTO_APPRAVAL);
taskService.approveTask(getLoginUserId(), reqVO);
}
}
}
/**
* 获得抄送我的流程实例的分页
*
* @param userId 用户编号
* @param pageReqVO 分页请求
* @return 流程实例的分页
*/
public PageResult getMyCCProcessInstancePage(Long userId,
BpmProcessInstanceMyPageReqVO pageReqVO) {
// 通过 BpmProcessInstanceExtDO 表,先查询到对应的分页
PageResult pageResult = processInstanceExtMapper.selectCCPage(userId, pageReqVO);
if (CollUtil.isEmpty(pageResult.getList())) {
return new PageResult<>(pageResult.getTotal());
}
// 获得流程 Task Map
List processInstanceIds = convertList(pageResult.getList(), BpmProcessInstanceExtDO::getProcessInstanceId);
Map> taskMap = taskService.getTaskMapByProcessInstanceIds(processInstanceIds);
// 转换返回
return BpmProcessInstanceConvert.INSTANCE.convertPage(pageResult, taskMap,null);
}
public List getProcessInstancesGroupByModelName(BpmProcessInstanceStatisticsReqVO pageReqVO){
pageReqVO = getUserids(pageReqVO) ;
return processInstanceExtMapper.getProcessInstancesGroupByModelName(pageReqVO) ;
}
public List getProcessInstancesGroupByResultStatus(BpmProcessInstanceStatisticsReqVO pageReqVO){
pageReqVO = getUserids(pageReqVO) ;
return processInstanceExtMapper.getProcessInstancesGroupByResultStatus(pageReqVO) ;
}
public PageResult getStatisticsProcessInstancePage(@Valid BpmProcessInstanceMyPageReqVO pageReqVO) {
// 通过 BpmProcessInstanceExtDO 表,先查询到对应的分页
PageResult pageResult = processInstanceExtMapper.selectStatisticePage(pageReqVO);
if (CollUtil.isEmpty(pageResult.getList())) {
return new PageResult<>(pageResult.getTotal());
}
// 获得流程 Task Map
List processInstanceIds = convertList(pageResult.getList(), BpmProcessInstanceExtDO::getProcessInstanceId);
Map> taskMap = taskService.getTaskMapByProcessInstanceIds(processInstanceIds);
List ids = taskMap.values().stream()
.flatMap(Collection::stream)
.map(Task::getAssignee)
.collect(Collectors.toList());
List longIds = ids.stream()
.map(Long::valueOf)
.collect(Collectors.toList());
//获得 审批人 User Map
Map assigneeUserMap = adminUserApi.getUserMap(longIds);
//获得 发起人 User Map
List bpieDOs = pageResult.getList() ;
longIds = new ArrayList<>() ;
for (BpmProcessInstanceExtDO bpieDO: bpieDOs) {
longIds.add(bpieDO.getStartUserId()) ;
}
Map startUserMap = adminUserApi.getUserMap(longIds);
// 转换返回
return BpmProcessInstanceConvert.INSTANCE.convertStatisticsPage(pageResult, taskMap, assigneeUserMap,startUserMap);
}
@Resource
PermissionApi permissionApi;
/**
* 根据数据权限,查询关联操作的用户IDS
* @param pageReqVO
* @return
* @param
*/
private T getUserids(T pageReqVO) {
try {
Class clazz = (Class) pageReqVO.getClass();
Field idField = clazz.getDeclaredField("userIds");
idField.setAccessible(true); // 设置可访问性
Long[] userIds = null;
Long userId = WebFrameworkUtils.getLoginUserId();
DeptDataPermissionRespDTO deptDataPermission = permissionApi.getDeptDataPermission(userId).getCheckedData();
//查询全部
if (deptDataPermission.getAll()) {
//idField.set(pageReqVO, null); // 设置属性值
return pageReqVO;
}
// 情况二,即不能查看部门,又不能查看自己,则说明 100% 无权限
if (CollUtil.isEmpty(deptDataPermission.getDeptIds())
&& Boolean.FALSE.equals(deptDataPermission.getSelf())) {
//设置成0,一个不存在的用户Id,就查询不到数据了。
userIds = new Long[]{0L};
idField.set(pageReqVO, userIds);
return pageReqVO;
}
//情况三 至查询自己
if (deptDataPermission.getSelf()) {
userIds = new Long[]{userId};
idField.set(pageReqVO, userIds);
return pageReqVO;
}
Set deptIds = deptDataPermission.getDeptIds();
//查询部门关联的用户Id
List users = adminUserApi.getUserListByDeptIds(deptIds).getCheckedData();
List tempList = new ArrayList<>();
for (AdminUserRespDTO user : users) {
Long id = user.getId();
tempList.add(id);
}
tempList.add(userId);
userIds = tempList.stream().toArray(Long[]::new); //将临时的List集合转换成数组集合
idField.set(pageReqVO, userIds);
return pageReqVO;
}catch (Exception exception){
exception.printStackTrace();
throw exception(BPM_SYSTEM_BUG);
}
}
/**
* /创建流程后,添加抄送人 Begin add by yj 2024.1.4
* 在设计流程的时候,需要添加一个任务块 名字必须叫Activity_cc 分配权限的时候,需要选择用户组。
*
* @param definition
* @param instance
*/
private void processCCToUsers(ProcessDefinition definition, ProcessInstance instance) {
//获取bpm_task_assign_reule (Bpm 任务规则表)的流程中有没有配置抄送节点 固定抄送名称为:Activity_cc
String processDefinitionId = definition.getId() ;
List rules = taskRuleMapper.selectListByProcessDefinitionId(processDefinitionId, null);
for(BpmTaskAssignRuleDO rule :rules ){
String key = rule.getTaskDefinitionKey() ; //任务名称
Integer type = rule.getType() ;
if( !key.isEmpty() && key.equals(BpmConstants.CC_NAME) && type == 40 ) {
StringBuffer str = new StringBuffer() ;
Set options = rule.getOptions() ;
List list = new ArrayList(options);
for(Long groupId : list) {
//需要根据这个groupId,查询这个组中的用户id
BpmUserGroupDO userGroup = userGroupService.getUserGroup(groupId);
Set userIds = userGroup.getMemberUserIds() ;
List userIdList = new ArrayList(userIds);
for(Long user_id : userIdList) {
str.append("[").append(user_id).append("]") ;
}
}
String ccids = str.toString() ;
//根据processDefinitionId 将ccids保存到bpm_process_instance_ext中的ccids字段
BpmProcessInstanceExtDO instanceExtDO = new BpmProcessInstanceExtDO().setProcessDefinitionId(processDefinitionId)
.setCcids(ccids) .setProcessInstanceId(instance.getProcessInstanceId());
processInstanceExtMapper.updateByProcessInstanceId(instanceExtDO);
break ;
}
}
}
@Resource
private BpmTaskExtMapper taskExtMapper;
@Override
public List getUserProcessTpo10(BpmProcessInstanceStatisticsReqVO pageReqVO) {
//按审核人分组查询,统计已完成流程数量及平均耗时间
List respVOS = processInstanceExtMapper.getUserProcessTpo10(pageReqVO);
if( respVOS == null || respVOS.size() == 0) {
return null ;
}
List idList = respVOS.stream()
.map(BpmProcessFinishStatisticsRespVO::getUserId)
.collect(Collectors.toList());
//根据userId,查询UserMap
Map userMap = adminUserApi.getUserMap(idList) ;
Long[] idsArray = new Long[userMap.size()];
// 使用 map 的 keySet() 方法获取键集合
Set keys = userMap.keySet();
// 遍历键集合,将每个键添加到数组中
int index = 0;
for (Long key : keys) {
idsArray[index++] = key;
}
pageReqVO.setUserIds(idsArray) ;
//按审核人分组查询,未审批完成的流程数量
List bpmTaskExtDOs = processInstanceExtMapper.selectUnfinishProcessCount( pageReqVO ) ;
//按审核人分组查询,未完成的记录数
Map unFinfishCountCountMap = new HashMap<>();
for (BpmProcessFinishStatisticsRespVO item : bpmTaskExtDOs) {
unFinfishCountCountMap.put(item.getUserId(), item.getUnFinfishCount());
}
respVOS.forEach(respVO -> respVO.setName( userMap.get(respVO.getUserId()).getNickname()));
respVOS.forEach(respVO -> respVO.setUnFinfishCount( unFinfishCountCountMap.get(respVO.getUserId())));
//获取排行榜第一记录的耗时,作为基础数据
double num = Double.parseDouble(respVOS.get(0).getUserTime()); // 先将字符串转换为双精度浮点数
int baseNumber = (int)num; // 再通过类型转换操作符将其转换为整数
DecimalFormat df = new DecimalFormat("#.00");
respVOS.forEach(respVO -> {
//格式化流程完成率
float finfishCount = (float) respVO.getFinfishCount() ;
float unFinfishCount = respVO.getUnFinfishCount() == null ? 0: respVO.getUnFinfishCount();
float all = finfishCount + unFinfishCount ;
float result = finfishCount / all;
float rate = result * 100 ;
respVO.setCompletionRate(df.format(rate)+"%") ;
double dValue = Double.parseDouble(respVO.getUserTime()); // 将字符串转换为double类型
int roundedValue = (int) Math.round(dValue); // 使用Math.round()进行四舍五入,并转换为int类型
respVO.setUserTime(roundedValue+"") ;
//格式化进度百度比, 参照最高的数据进行百分比显示
double percentage = ((int)Double.parseDouble(respVO.getUserTime()) / (double) baseNumber) * 100;
respVO.setPercentage((int) Math.round(percentage)) ;
//设置未完成
respVO.setUnFinfishCount( Integer.valueOf((int)unFinfishCount)) ;
});
return respVOS ;
}
@Override
public BpmProcessInstanceExtDO getProcessInstanceDO(String id) {
return processInstanceExtMapper.selectByProcessInstanceId(id);
}
}
\ No newline at end of file
From 98873d8b89790fa1a55ab03314d40b9cb2e8f8e5 Mon Sep 17 00:00:00 2001
From: aikai
Date: Wed, 10 Apr 2024 21:13:16 +0800
Subject: [PATCH 04/50] =?UTF-8?q?=E5=BC=80=E5=8F=91=E7=8E=AF=E5=A2=83?=
=?UTF-8?q?=E9=85=8D=E7=BD=AE?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
yudao-gateway/src/main/resources/bootstrap.yaml | 2 +-
.../yudao-module-bpm-biz/src/main/resources/bootstrap.yaml | 2 +-
.../yudao-module-infra-biz/src/main/resources/bootstrap.yaml | 2 +-
.../yudao-module-system-biz/src/main/resources/bootstrap.yaml | 2 +-
.../src/main/resources/bootstrap.yaml | 2 +-
5 files changed, 5 insertions(+), 5 deletions(-)
diff --git a/yudao-gateway/src/main/resources/bootstrap.yaml b/yudao-gateway/src/main/resources/bootstrap.yaml
index 55165083..ba7a42c4 100644
--- a/yudao-gateway/src/main/resources/bootstrap.yaml
+++ b/yudao-gateway/src/main/resources/bootstrap.yaml
@@ -3,7 +3,7 @@ spring:
name: gateway-server
profiles:
- active: local #local
+ active: dev #local
# active: prod
server:
port: 48080
diff --git a/yudao-module-bpm/yudao-module-bpm-biz/src/main/resources/bootstrap.yaml b/yudao-module-bpm/yudao-module-bpm-biz/src/main/resources/bootstrap.yaml
index 90fc58af..f2da21dc 100644
--- a/yudao-module-bpm/yudao-module-bpm-biz/src/main/resources/bootstrap.yaml
+++ b/yudao-module-bpm/yudao-module-bpm-biz/src/main/resources/bootstrap.yaml
@@ -3,7 +3,7 @@ spring:
name: bpm-server
profiles:
- active: local #local
+ active: dev #local
# active: prod
server:
diff --git a/yudao-module-infra/yudao-module-infra-biz/src/main/resources/bootstrap.yaml b/yudao-module-infra/yudao-module-infra-biz/src/main/resources/bootstrap.yaml
index b28d9964..64e03794 100644
--- a/yudao-module-infra/yudao-module-infra-biz/src/main/resources/bootstrap.yaml
+++ b/yudao-module-infra/yudao-module-infra-biz/src/main/resources/bootstrap.yaml
@@ -3,7 +3,7 @@ spring:
name: infra-server
profiles:
- active: local #local
+ active: dev #local
# active: prod
server:
diff --git a/yudao-module-system/yudao-module-system-biz/src/main/resources/bootstrap.yaml b/yudao-module-system/yudao-module-system-biz/src/main/resources/bootstrap.yaml
index 7abdef88..9498addd 100644
--- a/yudao-module-system/yudao-module-system-biz/src/main/resources/bootstrap.yaml
+++ b/yudao-module-system/yudao-module-system-biz/src/main/resources/bootstrap.yaml
@@ -3,7 +3,7 @@ spring:
name: system-server
profiles:
- active: local #local
+ active: dev #local
# active: prod
server:
diff --git a/zn-module-smartfactory/zn-module-smartfactory-biz/src/main/resources/bootstrap.yaml b/zn-module-smartfactory/zn-module-smartfactory-biz/src/main/resources/bootstrap.yaml
index 7591aed7..818d6381 100644
--- a/zn-module-smartfactory/zn-module-smartfactory-biz/src/main/resources/bootstrap.yaml
+++ b/zn-module-smartfactory/zn-module-smartfactory-biz/src/main/resources/bootstrap.yaml
@@ -3,7 +3,7 @@ spring:
name: smartfactory-server
profiles:
- active: local
+ active: dev
server:
port: 48090
From 72f6b89fd9480bc026aed6d6e809e3cd646e3dc5 Mon Sep 17 00:00:00 2001
From: aikai
Date: Thu, 11 Apr 2024 13:04:55 +0800
Subject: [PATCH 05/50] =?UTF-8?q?=E5=BC=80=E5=8F=91=E7=8E=AF=E5=A2=83?=
=?UTF-8?q?=E9=85=8D=E7=BD=AE=E5=B0=8F=E7=A8=8B=E5=BA=8F=E9=85=8D=E7=BD=AE?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../src/main/resources/application-dev.yaml | 4 ++--
.../src/main/resources/application-local.yaml | 4 ++--
2 files changed, 4 insertions(+), 4 deletions(-)
diff --git a/yudao-module-system/yudao-module-system-biz/src/main/resources/application-dev.yaml b/yudao-module-system/yudao-module-system-biz/src/main/resources/application-dev.yaml
index 72d23f84..96835b0f 100644
--- a/yudao-module-system/yudao-module-system-biz/src/main/resources/application-dev.yaml
+++ b/yudao-module-system/yudao-module-system-biz/src/main/resources/application-dev.yaml
@@ -125,8 +125,8 @@ wx:
miniapp: # 小程序配置(必填),参见 https://github.com/Wechat-Group/WxJava/blob/develop/spring-boot-starters/wx-java-miniapp-spring-boot-starter/README.md 文档
# appid: wx62056c0d5e8db250
# secret: 333ae72f41552af1e998fe1f54e1584a
- appid: wx63c280fe3248a3e7 # wenhualian的接口测试号
- secret: 6f270509224a7ae1296bbf1c8cb97aed
+ appid: wxea777d1b1e12eb32 # wenhualian的接口测试号
+ secret: 2db58956286099e58e959fa537e046b0
config-storage:
type: RedisTemplate # 采用 RedisTemplate 操作 Redis,会自动从 Spring 中获取
key-prefix: wa # Redis Key 的前缀
diff --git a/yudao-module-system/yudao-module-system-biz/src/main/resources/application-local.yaml b/yudao-module-system/yudao-module-system-biz/src/main/resources/application-local.yaml
index 6a749708..bc7aa1a6 100644
--- a/yudao-module-system/yudao-module-system-biz/src/main/resources/application-local.yaml
+++ b/yudao-module-system/yudao-module-system-biz/src/main/resources/application-local.yaml
@@ -143,8 +143,8 @@ wx:
miniapp: # 小程序配置(必填),参见 https://github.com/Wechat-Group/WxJava/blob/develop/spring-boot-starters/wx-java-miniapp-spring-boot-starter/README.md 文档
# appid: wx62056c0d5e8db250
# secret: 333ae72f41552af1e998fe1f54e1584a
- appid: wx2919e237e6018bea # wenhualian的接口测试号
- secret: ad7ab17918f6defa85a9677778eb7780
+ appid: wxea777d1b1e12eb32 # wenhualian的接口测试号
+ secret: 2db58956286099e58e959fa537e046b0
config-storage:
type: RedisTemplate # 采用 RedisTemplate 操作 Redis,会自动从 Spring 中获取
key-prefix: wa # Redis Key 的前缀
From ebe9f0c445a44421a361257978dd382bcf419fe4 Mon Sep 17 00:00:00 2001
From: aikai
Date: Thu, 11 Apr 2024 16:02:56 +0800
Subject: [PATCH 06/50] =?UTF-8?q?=E9=87=87=E8=B4=AD=E6=94=AF=E4=BB=98=20?=
=?UTF-8?q?=E8=BF=94=E5=9B=9E=E9=87=87=E8=B4=AD=E8=AF=A6=E6=83=85json?=
=?UTF-8?q?=E6=95=B0=E6=8D=AE?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../admin/oa/vo/procurepay/BpmOAProcurePayItemRespVO.java | 5 +++++
.../admin/oa/vo/procurepay/BpmOAProcurePayRespVO.java | 7 +++++++
.../admin/oa/vo/procurepay/BpmOAProcurePaySaveReqVO.java | 3 +++
.../main/resources/mapper/oa/BpmOAProcurePayItemMapper.xml | 1 +
4 files changed, 16 insertions(+)
diff --git a/yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/controller/admin/oa/vo/procurepay/BpmOAProcurePayItemRespVO.java b/yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/controller/admin/oa/vo/procurepay/BpmOAProcurePayItemRespVO.java
index 5a4bb4ef..e5a252c0 100644
--- a/yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/controller/admin/oa/vo/procurepay/BpmOAProcurePayItemRespVO.java
+++ b/yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/controller/admin/oa/vo/procurepay/BpmOAProcurePayItemRespVO.java
@@ -1,5 +1,6 @@
package cn.iocoder.yudao.module.bpm.controller.admin.oa.vo.procurepay;
+import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import org.springframework.format.annotation.DateTimeFormat;
@@ -7,6 +8,7 @@ import org.springframework.format.annotation.DateTimeFormat;
import java.time.LocalDateTime;
import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND;
+import static cn.iocoder.yudao.framework.common.util.date.DateUtils.TIME_ZONE_DEFAULT;
@Schema(description = "管理后台 - 采购收款明细 Response VO")
@Data
@@ -45,6 +47,7 @@ public class BpmOAProcurePayItemRespVO {
@Schema(description = "期望交付日期")
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
+ @JsonFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND, timezone = TIME_ZONE_DEFAULT)
private LocalDateTime expectedDeliveryDate;
@Schema(description = "备注")
@@ -56,4 +59,6 @@ public class BpmOAProcurePayItemRespVO {
@Schema(description = "采购总金额大写")
private String totalMoneyChinese;
+ @Schema(description = "采购详情json数据")
+ private String procureDetailJson;
}
\ No newline at end of file
diff --git a/yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/controller/admin/oa/vo/procurepay/BpmOAProcurePayRespVO.java b/yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/controller/admin/oa/vo/procurepay/BpmOAProcurePayRespVO.java
index b3f51e9a..1b4fbc3b 100644
--- a/yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/controller/admin/oa/vo/procurepay/BpmOAProcurePayRespVO.java
+++ b/yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/controller/admin/oa/vo/procurepay/BpmOAProcurePayRespVO.java
@@ -1,13 +1,18 @@
package cn.iocoder.yudao.module.bpm.controller.admin.oa.vo.procurepay;
import cn.iocoder.yudao.module.bpm.controller.admin.upload.UploadUserFile;
+import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
+import org.springframework.format.annotation.DateTimeFormat;
import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.List;
+import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND;
+import static cn.iocoder.yudao.framework.common.util.date.DateUtils.TIME_ZONE_DEFAULT;
+
@Schema(description = "管理后台 - 采购支付 Response VO")
@Data
public class BpmOAProcurePayRespVO {
@@ -22,6 +27,8 @@ public class BpmOAProcurePayRespVO {
private String reason;
@Schema(description = "支付日期")
+ @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
+ @JsonFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND, timezone = TIME_ZONE_DEFAULT)
private LocalDateTime payTime;
@Schema(description = "采购付款总金额", requiredMode = Schema.RequiredMode.REQUIRED)
diff --git a/yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/controller/admin/oa/vo/procurepay/BpmOAProcurePaySaveReqVO.java b/yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/controller/admin/oa/vo/procurepay/BpmOAProcurePaySaveReqVO.java
index e3bae9f4..99bac792 100644
--- a/yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/controller/admin/oa/vo/procurepay/BpmOAProcurePaySaveReqVO.java
+++ b/yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/controller/admin/oa/vo/procurepay/BpmOAProcurePaySaveReqVO.java
@@ -10,6 +10,8 @@ import java.math.BigDecimal;
import org.springframework.format.annotation.DateTimeFormat;
import java.time.LocalDateTime;
+import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND;
+
@Schema(description = "管理后台 - 采购支付新增/修改 Request VO")
@Data
public class BpmOAProcurePaySaveReqVO {
@@ -25,6 +27,7 @@ public class BpmOAProcurePaySaveReqVO {
private String reason;
@Schema(description = "支付日期")
+ @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
private LocalDateTime payTime;
@Schema(description = "采购付款总金额", requiredMode = Schema.RequiredMode.REQUIRED)
diff --git a/yudao-module-bpm/yudao-module-bpm-biz/src/main/resources/mapper/oa/BpmOAProcurePayItemMapper.xml b/yudao-module-bpm/yudao-module-bpm-biz/src/main/resources/mapper/oa/BpmOAProcurePayItemMapper.xml
index cfa7974e..9a2e29de 100644
--- a/yudao-module-bpm/yudao-module-bpm-biz/src/main/resources/mapper/oa/BpmOAProcurePayItemMapper.xml
+++ b/yudao-module-bpm/yudao-module-bpm-biz/src/main/resources/mapper/oa/BpmOAProcurePayItemMapper.xml
@@ -18,6 +18,7 @@
b.reason,
b.procure_type,
b.expected_delivery_date,
+ b.procure_detail_json as procureDetailJson,
b.remarks,
b.total_money,
b.total_money_chinese
From 55ed940e2fe4331a3c1b58873ce18a3e1cf395cb Mon Sep 17 00:00:00 2001
From: aikai
Date: Thu, 11 Apr 2024 17:53:48 +0800
Subject: [PATCH 07/50] =?UTF-8?q?=E6=97=A5=E5=BF=97=E8=AF=84=E8=AE=BA?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../app/comment/WorkLogCommentController.java | 44 ++++++++
.../app/comment/dto/CommentDTO.java | 17 +++
.../app/comment/vo/CommentPageListVO.java | 53 +++++++++
.../comment/vo/WorkLogCommentPageReqVO.java | 43 +++++++
.../app/comment/vo/WorkLogCommentRespVO.java | 52 +++++++++
.../comment/vo/WorkLogCommentSaveReqVO.java | 37 ++++++
.../dataobject/comment/WorkLogCommentDO.java | 59 ++++++++++
.../mysql/comment/WorkLogCommentMapper.java | 44 ++++++++
.../comment/WorkLogCommentService.java | 66 +++++++++++
.../comment/WorkLogCommentServiceImpl.java | 105 ++++++++++++++++++
.../mapper/comment/WorkLogCommentMapper.xml | 48 ++++++++
11 files changed, 568 insertions(+)
create mode 100644 yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/app/comment/WorkLogCommentController.java
create mode 100644 yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/app/comment/dto/CommentDTO.java
create mode 100644 yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/app/comment/vo/CommentPageListVO.java
create mode 100644 yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/app/comment/vo/WorkLogCommentPageReqVO.java
create mode 100644 yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/app/comment/vo/WorkLogCommentRespVO.java
create mode 100644 yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/app/comment/vo/WorkLogCommentSaveReqVO.java
create mode 100644 yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/dataobject/comment/WorkLogCommentDO.java
create mode 100644 yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/comment/WorkLogCommentMapper.java
create mode 100644 yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/comment/WorkLogCommentService.java
create mode 100644 yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/comment/WorkLogCommentServiceImpl.java
create mode 100644 yudao-module-system/yudao-module-system-biz/src/main/resources/mapper/comment/WorkLogCommentMapper.xml
diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/app/comment/WorkLogCommentController.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/app/comment/WorkLogCommentController.java
new file mode 100644
index 00000000..9b4d7ea9
--- /dev/null
+++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/app/comment/WorkLogCommentController.java
@@ -0,0 +1,44 @@
+package cn.iocoder.yudao.module.system.controller.app.comment;
+
+import cn.iocoder.yudao.framework.common.pojo.CommonResult;
+import cn.iocoder.yudao.module.system.controller.app.comment.dto.CommentDTO;
+import cn.iocoder.yudao.module.system.controller.app.comment.vo.CommentPageListVO;
+import cn.iocoder.yudao.module.system.service.comment.WorkLogCommentService;
+import com.baomidou.mybatisplus.core.metadata.IPage;
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import io.swagger.v3.oas.annotations.Operation;
+import io.swagger.v3.oas.annotations.tags.Tag;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.validation.annotation.Validated;
+import org.springframework.web.bind.annotation.*;
+
+import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
+
+@Tag(name = "管理后台 - 工作日志评论")
+@RestController
+@RequestMapping("/system/work-log-comment")
+@Validated
+public class WorkLogCommentController {
+
+ @Autowired
+ private WorkLogCommentService workLogCommentService;
+
+ @Operation(summary = "用户工作日志评论-分页查询评论列表")
+ @GetMapping(value = "/queryCommentPageList")
+ public CommonResult> queryCommentPageList(CommentDTO dto,
+ @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
+ @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize) {
+ Page page = new Page<>(pageNo, pageSize);
+ IPage pageList = workLogCommentService.queryCommentPageList(page, dto);
+ return success(pageList);
+ }
+
+// @Operation(summary = "用户动态评论-评论/回复评论")
+// @PostMapping(value = "/addComment")
+// public CommonResult addComment(@RequestBody MemberDynamicCommentAddDTO dto) {
+// workLogCommentService.addComment(dto);
+// return success("添加成功!");
+// }
+
+
+}
\ No newline at end of file
diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/app/comment/dto/CommentDTO.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/app/comment/dto/CommentDTO.java
new file mode 100644
index 00000000..4e488434
--- /dev/null
+++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/app/comment/dto/CommentDTO.java
@@ -0,0 +1,17 @@
+package cn.iocoder.yudao.module.system.controller.app.comment.dto;
+
+import com.fasterxml.jackson.databind.annotation.JsonSerialize;
+import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
+import io.swagger.v3.oas.annotations.media.Schema;
+import lombok.Data;
+
+@Data
+public class CommentDTO {
+ @Schema(description = "工作日志id", required = true)
+ @JsonSerialize(using = ToStringSerializer.class)
+ private Long workLogId;
+ @Schema(description = "评论类型(0|评论;1|回评")
+ private Integer type;
+ @Schema(description = "是否需要显示日志内容 0否 1是 默认否")
+ private Integer isShowWorkLogContent;
+}
diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/app/comment/vo/CommentPageListVO.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/app/comment/vo/CommentPageListVO.java
new file mode 100644
index 00000000..70812e1c
--- /dev/null
+++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/app/comment/vo/CommentPageListVO.java
@@ -0,0 +1,53 @@
+package cn.iocoder.yudao.module.system.controller.app.comment.vo;
+
+import com.fasterxml.jackson.annotation.JsonFormat;
+import com.fasterxml.jackson.databind.annotation.JsonSerialize;
+import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
+import io.swagger.v3.oas.annotations.media.Schema;
+import lombok.Data;
+import org.springframework.format.annotation.DateTimeFormat;
+
+@Data
+public class CommentPageListVO {
+ @JsonSerialize(using = ToStringSerializer.class)
+ @Schema(description = "id")
+ private Long id;
+ @Schema(description = "工作日志ID")
+ @JsonSerialize(using = ToStringSerializer.class)
+ private Long workLogId;
+ @Schema(description = "评论用户ID")
+ @JsonSerialize(using = ToStringSerializer.class)
+ private Long userId;
+ @Schema(description = "评论用户头像")
+ private String avatar;
+ @Schema(description = "评论用户名称")
+ private String userName;
+
+ @Schema(description = "被评论用户ID")
+ @JsonSerialize(using = ToStringSerializer.class)
+ private Long commentUserId;
+ @Schema(description = "被评论用户头像")
+ private String commentAvatar;
+ @Schema(description = "被评论用户名称")
+ private String commentUserName;
+
+ @Schema(description = "评论内容")
+ private String comment;
+ @Schema(description = "评论类型(0|评论;1|回评)")
+ private Integer type;
+
+ @Schema(description = "被回评内容")
+ private String replyComment;
+
+ @Schema(description = "工作日志内容(部分)")
+ private String workLogContent;
+ @Schema(description = "工作日志名称")
+ private String workLogName;
+ @Schema(description = "工作日志模版id")
+ private Long workFormId;
+
+ @JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
+ @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
+ @Schema(description = "创建日期")
+ private String createTime;
+}
diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/app/comment/vo/WorkLogCommentPageReqVO.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/app/comment/vo/WorkLogCommentPageReqVO.java
new file mode 100644
index 00000000..960e4e63
--- /dev/null
+++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/app/comment/vo/WorkLogCommentPageReqVO.java
@@ -0,0 +1,43 @@
+package cn.iocoder.yudao.module.system.controller.app.comment.vo;
+
+import lombok.*;
+import java.util.*;
+import io.swagger.v3.oas.annotations.media.Schema;
+import cn.iocoder.yudao.framework.common.pojo.PageParam;
+import org.springframework.format.annotation.DateTimeFormat;
+import java.time.LocalDateTime;
+
+import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND;
+
+@Schema(description = "管理后台 - 工作日志评论分页 Request VO")
+@Data
+@EqualsAndHashCode(callSuper = true)
+@ToString(callSuper = true)
+public class WorkLogCommentPageReqVO extends PageParam {
+
+ @Schema(description = "动态ID", example = "26393")
+ private Long workLogId;
+
+ @Schema(description = "评论ID(回复评论的ID)", example = "25541")
+ private Long commentId;
+
+ @Schema(description = "评论用户ID", example = "17082")
+ private Long userId;
+
+ @Schema(description = "被评论用户ID", example = "22388")
+ private Long commentUserId;
+
+ @Schema(description = "评论内容")
+ private String comment;
+
+ @Schema(description = "评论类型(0|评论;1|回评)", example = "1")
+ private Boolean type;
+
+ @Schema(description = "楼栋标识")
+ private String buildingCode;
+
+ @Schema(description = "创建时间")
+ @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
+ private LocalDateTime[] createTime;
+
+}
\ No newline at end of file
diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/app/comment/vo/WorkLogCommentRespVO.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/app/comment/vo/WorkLogCommentRespVO.java
new file mode 100644
index 00000000..be061652
--- /dev/null
+++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/app/comment/vo/WorkLogCommentRespVO.java
@@ -0,0 +1,52 @@
+package cn.iocoder.yudao.module.system.controller.app.comment.vo;
+
+import io.swagger.v3.oas.annotations.media.Schema;
+import lombok.*;
+import java.util.*;
+import java.util.*;
+import org.springframework.format.annotation.DateTimeFormat;
+import java.time.LocalDateTime;
+import com.alibaba.excel.annotation.*;
+
+@Schema(description = "管理后台 - 工作日志评论 Response VO")
+@Data
+@ExcelIgnoreUnannotated
+public class WorkLogCommentRespVO {
+
+ @Schema(description = "id", requiredMode = Schema.RequiredMode.REQUIRED, example = "21304")
+ @ExcelProperty("id")
+ private Long id;
+
+ @Schema(description = "动态ID", example = "26393")
+ @ExcelProperty("动态ID")
+ private Long workLogId;
+
+ @Schema(description = "评论ID(回复评论的ID)", example = "25541")
+ @ExcelProperty("评论ID(回复评论的ID)")
+ private Long commentId;
+
+ @Schema(description = "评论用户ID", example = "17082")
+ @ExcelProperty("评论用户ID")
+ private Long userId;
+
+ @Schema(description = "被评论用户ID", example = "22388")
+ @ExcelProperty("被评论用户ID")
+ private Long commentUserId;
+
+ @Schema(description = "评论内容")
+ @ExcelProperty("评论内容")
+ private String comment;
+
+ @Schema(description = "评论类型(0|评论;1|回评)", example = "1")
+ @ExcelProperty("评论类型(0|评论;1|回评)")
+ private Boolean type;
+
+ @Schema(description = "楼栋标识")
+ @ExcelProperty("楼栋标识")
+ private String buildingCode;
+
+ @Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED)
+ @ExcelProperty("创建时间")
+ private LocalDateTime createTime;
+
+}
\ No newline at end of file
diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/app/comment/vo/WorkLogCommentSaveReqVO.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/app/comment/vo/WorkLogCommentSaveReqVO.java
new file mode 100644
index 00000000..1dab74c1
--- /dev/null
+++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/app/comment/vo/WorkLogCommentSaveReqVO.java
@@ -0,0 +1,37 @@
+package cn.iocoder.yudao.module.system.controller.app.comment.vo;
+
+import io.swagger.v3.oas.annotations.media.Schema;
+import lombok.*;
+import java.util.*;
+import javax.validation.constraints.*;
+import java.util.*;
+
+@Schema(description = "管理后台 - 工作日志评论新增/修改 Request VO")
+@Data
+public class WorkLogCommentSaveReqVO {
+
+ @Schema(description = "id", requiredMode = Schema.RequiredMode.REQUIRED, example = "21304")
+ private Long id;
+
+ @Schema(description = "动态ID", example = "26393")
+ private Long workLogId;
+
+ @Schema(description = "评论ID(回复评论的ID)", example = "25541")
+ private Long commentId;
+
+ @Schema(description = "评论用户ID", example = "17082")
+ private Long userId;
+
+ @Schema(description = "被评论用户ID", example = "22388")
+ private Long commentUserId;
+
+ @Schema(description = "评论内容")
+ private String comment;
+
+ @Schema(description = "评论类型(0|评论;1|回评)", example = "1")
+ private Boolean type;
+
+ @Schema(description = "楼栋标识")
+ private String buildingCode;
+
+}
\ No newline at end of file
diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/dataobject/comment/WorkLogCommentDO.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/dataobject/comment/WorkLogCommentDO.java
new file mode 100644
index 00000000..7016fa3a
--- /dev/null
+++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/dataobject/comment/WorkLogCommentDO.java
@@ -0,0 +1,59 @@
+package cn.iocoder.yudao.module.system.dal.dataobject.comment;
+
+import lombok.*;
+import java.util.*;
+import java.time.LocalDateTime;
+import java.time.LocalDateTime;
+import com.baomidou.mybatisplus.annotation.*;
+import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO;
+
+/**
+ * 工作日志评论 DO
+ *
+ * @author 艾楷
+ */
+@TableName("work_log_comment")
+@KeySequence("work_log_comment_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。
+@Data
+@EqualsAndHashCode(callSuper = true)
+@ToString(callSuper = true)
+@Builder
+@NoArgsConstructor
+@AllArgsConstructor
+public class WorkLogCommentDO extends BaseDO {
+
+ /**
+ * id
+ */
+ @TableId
+ private Long id;
+ /**
+ * 动态ID
+ */
+ private Long workLogId;
+ /**
+ * 评论ID(回复评论的ID)
+ */
+ private Long commentId;
+ /**
+ * 评论用户ID
+ */
+ private Long userId;
+ /**
+ * 被评论用户ID
+ */
+ private Long commentUserId;
+ /**
+ * 评论内容
+ */
+ private String comment;
+ /**
+ * 评论类型(0|评论;1|回评)
+ */
+ private Boolean type;
+ /**
+ * 楼栋标识
+ */
+ private String buildingCode;
+
+}
\ No newline at end of file
diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/comment/WorkLogCommentMapper.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/comment/WorkLogCommentMapper.java
new file mode 100644
index 00000000..af112886
--- /dev/null
+++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/comment/WorkLogCommentMapper.java
@@ -0,0 +1,44 @@
+package cn.iocoder.yudao.module.system.dal.mysql.comment;
+
+import java.util.*;
+
+import cn.iocoder.yudao.framework.common.pojo.PageResult;
+import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
+import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
+import cn.iocoder.yudao.module.system.controller.app.comment.dto.CommentDTO;
+import cn.iocoder.yudao.module.system.dal.dataobject.comment.WorkLogCommentDO;
+import com.baomidou.mybatisplus.core.metadata.IPage;
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import org.apache.ibatis.annotations.Mapper;
+import cn.iocoder.yudao.module.system.controller.app.comment.vo.*;
+import org.apache.ibatis.annotations.Param;
+
+/**
+ * 工作日志评论 Mapper
+ *
+ * @author 艾楷
+ */
+@Mapper
+public interface WorkLogCommentMapper extends BaseMapperX {
+
+ default PageResult selectPage(WorkLogCommentPageReqVO reqVO) {
+ return selectPage(reqVO, new LambdaQueryWrapperX()
+ .eqIfPresent(WorkLogCommentDO::getWorkLogId, reqVO.getWorkLogId())
+ .eqIfPresent(WorkLogCommentDO::getCommentId, reqVO.getCommentId())
+ .eqIfPresent(WorkLogCommentDO::getUserId, reqVO.getUserId())
+ .eqIfPresent(WorkLogCommentDO::getCommentUserId, reqVO.getCommentUserId())
+ .eqIfPresent(WorkLogCommentDO::getComment, reqVO.getComment())
+ .eqIfPresent(WorkLogCommentDO::getType, reqVO.getType())
+ .eqIfPresent(WorkLogCommentDO::getBuildingCode, reqVO.getBuildingCode())
+ .betweenIfPresent(WorkLogCommentDO::getCreateTime, reqVO.getCreateTime())
+ .orderByDesc(WorkLogCommentDO::getId));
+ }
+
+ /**
+ *
+ * @param page
+ * @param dto
+ * @return
+ */
+ IPage queryCommentPageList(@Param("page") Page page, @Param("dto") CommentDTO dto);
+}
\ No newline at end of file
diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/comment/WorkLogCommentService.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/comment/WorkLogCommentService.java
new file mode 100644
index 00000000..ea657381
--- /dev/null
+++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/comment/WorkLogCommentService.java
@@ -0,0 +1,66 @@
+package cn.iocoder.yudao.module.system.service.comment;
+
+import java.util.*;
+import javax.validation.*;
+
+import cn.iocoder.yudao.module.system.controller.app.comment.dto.CommentDTO;
+import cn.iocoder.yudao.module.system.controller.app.comment.vo.*;
+import cn.iocoder.yudao.module.system.dal.dataobject.comment.WorkLogCommentDO;
+import cn.iocoder.yudao.framework.common.pojo.PageResult;
+import cn.iocoder.yudao.framework.common.pojo.PageParam;
+import com.baomidou.mybatisplus.core.metadata.IPage;
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+
+/**
+ * 工作日志评论 Service 接口
+ *
+ * @author 艾楷
+ */
+public interface WorkLogCommentService {
+
+ /**
+ * 创建工作日志评论
+ *
+ * @param createReqVO 创建信息
+ * @return 编号
+ */
+ Long createWorkLogComment(@Valid WorkLogCommentSaveReqVO createReqVO);
+
+ /**
+ * 更新工作日志评论
+ *
+ * @param updateReqVO 更新信息
+ */
+ void updateWorkLogComment(@Valid WorkLogCommentSaveReqVO updateReqVO);
+
+ /**
+ * 删除工作日志评论
+ *
+ * @param id 编号
+ */
+ void deleteWorkLogComment(Long id);
+
+ /**
+ * 获得工作日志评论
+ *
+ * @param id 编号
+ * @return 工作日志评论
+ */
+ WorkLogCommentDO getWorkLogComment(Long id);
+
+ /**
+ * 获得工作日志评论分页
+ *
+ * @param pageReqVO 分页查询
+ * @return 工作日志评论分页
+ */
+ PageResult getWorkLogCommentPage(WorkLogCommentPageReqVO pageReqVO);
+
+ /**
+ *
+ * @param page
+ * @param dto
+ * @return
+ */
+ IPage queryCommentPageList(Page page, CommentDTO dto);
+}
\ No newline at end of file
diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/comment/WorkLogCommentServiceImpl.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/comment/WorkLogCommentServiceImpl.java
new file mode 100644
index 00000000..d61ca0c7
--- /dev/null
+++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/comment/WorkLogCommentServiceImpl.java
@@ -0,0 +1,105 @@
+package cn.iocoder.yudao.module.system.service.comment;
+
+import cn.iocoder.yudao.framework.common.pojo.PageResult;
+import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
+import cn.iocoder.yudao.module.system.controller.app.comment.dto.CommentDTO;
+import cn.iocoder.yudao.module.system.controller.app.comment.vo.CommentPageListVO;
+import cn.iocoder.yudao.module.system.controller.app.comment.vo.WorkLogCommentPageReqVO;
+import cn.iocoder.yudao.module.system.controller.app.comment.vo.WorkLogCommentSaveReqVO;
+import cn.iocoder.yudao.module.system.dal.dataobject.comment.WorkLogCommentDO;
+import cn.iocoder.yudao.module.system.dal.mysql.comment.WorkLogCommentMapper;
+import com.baomidou.mybatisplus.core.metadata.IPage;
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import org.springframework.stereotype.Service;
+import org.springframework.validation.annotation.Validated;
+
+import javax.annotation.Resource;
+import java.util.Arrays;
+import java.util.List;
+import java.util.Map;
+import java.util.stream.Collectors;
+
+/**
+ * 工作日志评论 Service 实现类
+ *
+ * @author 艾楷
+ */
+@Service
+@Validated
+public class WorkLogCommentServiceImpl implements WorkLogCommentService {
+
+ @Resource
+ private WorkLogCommentMapper workLogCommentMapper;
+
+ @Override
+ public Long createWorkLogComment(WorkLogCommentSaveReqVO createReqVO) {
+ // 插入
+ WorkLogCommentDO workLogComment = BeanUtils.toBean(createReqVO, WorkLogCommentDO.class);
+ workLogCommentMapper.insert(workLogComment);
+ // 返回
+ return workLogComment.getId();
+ }
+
+ @Override
+ public void updateWorkLogComment(WorkLogCommentSaveReqVO updateReqVO) {
+ // 校验存在
+// validateWorkLogCommentExists(updateReqVO.getId());
+ // 更新
+ WorkLogCommentDO updateObj = BeanUtils.toBean(updateReqVO, WorkLogCommentDO.class);
+ workLogCommentMapper.updateById(updateObj);
+ }
+
+ @Override
+ public void deleteWorkLogComment(Long id) {
+ // 校验存在
+// validateWorkLogCommentExists(id);
+ // 删除
+ workLogCommentMapper.deleteById(id);
+ }
+
+// private void validateWorkLogCommentExists(Long id) {
+// if (workLogCommentMapper.selectById(id) == null) {
+// throw exception(WORK_LOG_COMMENT_NOT_EXISTS);
+// }
+// }
+
+ @Override
+ public WorkLogCommentDO getWorkLogComment(Long id) {
+ return workLogCommentMapper.selectById(id);
+ }
+
+ @Override
+ public PageResult getWorkLogCommentPage(WorkLogCommentPageReqVO pageReqVO) {
+ return workLogCommentMapper.selectPage(pageReqVO);
+ }
+
+ @Override
+ public IPage queryCommentPageList(Page page, CommentDTO dto) {
+ IPage pageList = workLogCommentMapper.queryCommentPageList(page, dto);
+ if (dto.getIsShowWorkLogContent() != null && dto.getIsShowWorkLogContent() == 1) {
+ List records = pageList.getRecords();
+ //模版ids过滤
+ List workFormIds = records.stream().map(CommentPageListVO::getWorkFormId).collect(Collectors.toList());
+ // TODO: 2024/4/11 查询模版列表
+
+ pageList.getRecords().forEach(item -> {
+ // TODO: 2024/4/11 - 这里需要通过模版id
+ item.setWorkLogContent(null);
+ });
+ }
+ return pageList;
+ }
+
+
+ public static void main(String[] args) {
+ List records = Arrays.asList(
+ new CommentPageListVO().setWorkLogId(1L).setWorkFormId("1"),
+ new CommentPageListVO().setWorkLogId(1L).setWorkFormId("1"),
+ new CommentPageListVO().setWorkLogId(1L).setWorkFormId("1"),
+ new CommentPageListVO().setWorkLogId(2L).setWorkFormId("1"));
+ Map collect = records.stream().collect(Collectors.toMap(CommentPageListVO::getWorkLogId, CommentPageListVO::getWorkFormId));
+ System.out.println(collect);
+
+ }
+
+}
\ No newline at end of file
diff --git a/yudao-module-system/yudao-module-system-biz/src/main/resources/mapper/comment/WorkLogCommentMapper.xml b/yudao-module-system/yudao-module-system-biz/src/main/resources/mapper/comment/WorkLogCommentMapper.xml
new file mode 100644
index 00000000..e3538cf0
--- /dev/null
+++ b/yudao-module-system/yudao-module-system-biz/src/main/resources/mapper/comment/WorkLogCommentMapper.xml
@@ -0,0 +1,48 @@
+
+
+
+
+
+
+
+
\ No newline at end of file
From 299f5293f5df8a92000e98e9f114b2baa31aac89 Mon Sep 17 00:00:00 2001
From: aikai
Date: Thu, 11 Apr 2024 19:37:18 +0800
Subject: [PATCH 08/50] =?UTF-8?q?=E6=97=A5=E5=BF=97=E8=AF=84=E8=AE=BA?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../app/comment/WorkLogCommentController.java | 12 ++---
.../comment/vo/WorkLogCommentSaveReqVO.java | 11 +----
.../dataobject/comment/WorkLogCommentDO.java | 2 +-
.../comment/WorkLogCommentServiceImpl.java | 47 +++++++++++--------
4 files changed, 36 insertions(+), 36 deletions(-)
diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/app/comment/WorkLogCommentController.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/app/comment/WorkLogCommentController.java
index 9b4d7ea9..c62032d3 100644
--- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/app/comment/WorkLogCommentController.java
+++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/app/comment/WorkLogCommentController.java
@@ -3,6 +3,7 @@ package cn.iocoder.yudao.module.system.controller.app.comment;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.module.system.controller.app.comment.dto.CommentDTO;
import cn.iocoder.yudao.module.system.controller.app.comment.vo.CommentPageListVO;
+import cn.iocoder.yudao.module.system.controller.app.comment.vo.WorkLogCommentSaveReqVO;
import cn.iocoder.yudao.module.system.service.comment.WorkLogCommentService;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
@@ -33,12 +34,11 @@ public class WorkLogCommentController {
return success(pageList);
}
-// @Operation(summary = "用户动态评论-评论/回复评论")
-// @PostMapping(value = "/addComment")
-// public CommonResult addComment(@RequestBody MemberDynamicCommentAddDTO dto) {
-// workLogCommentService.addComment(dto);
-// return success("添加成功!");
-// }
+ @PostMapping("/create")
+ @Operation(summary = "创建工作日志评论")
+ public CommonResult createWorkLogComment(@RequestBody WorkLogCommentSaveReqVO createReqVO) {
+ return success(workLogCommentService.createWorkLogComment(createReqVO));
+ }
}
\ No newline at end of file
diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/app/comment/vo/WorkLogCommentSaveReqVO.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/app/comment/vo/WorkLogCommentSaveReqVO.java
index 1dab74c1..5ff39ca8 100644
--- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/app/comment/vo/WorkLogCommentSaveReqVO.java
+++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/app/comment/vo/WorkLogCommentSaveReqVO.java
@@ -10,18 +10,12 @@ import java.util.*;
@Data
public class WorkLogCommentSaveReqVO {
- @Schema(description = "id", requiredMode = Schema.RequiredMode.REQUIRED, example = "21304")
- private Long id;
-
- @Schema(description = "动态ID", example = "26393")
+ @Schema(description = "工作日志ID", example = "26393")
private Long workLogId;
@Schema(description = "评论ID(回复评论的ID)", example = "25541")
private Long commentId;
- @Schema(description = "评论用户ID", example = "17082")
- private Long userId;
-
@Schema(description = "被评论用户ID", example = "22388")
private Long commentUserId;
@@ -31,7 +25,4 @@ public class WorkLogCommentSaveReqVO {
@Schema(description = "评论类型(0|评论;1|回评)", example = "1")
private Boolean type;
- @Schema(description = "楼栋标识")
- private String buildingCode;
-
}
\ No newline at end of file
diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/dataobject/comment/WorkLogCommentDO.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/dataobject/comment/WorkLogCommentDO.java
index 7016fa3a..16a9b3bf 100644
--- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/dataobject/comment/WorkLogCommentDO.java
+++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/dataobject/comment/WorkLogCommentDO.java
@@ -28,7 +28,7 @@ public class WorkLogCommentDO extends BaseDO {
@TableId
private Long id;
/**
- * 动态ID
+ * 工作日志ID
*/
private Long workLogId;
/**
diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/comment/WorkLogCommentServiceImpl.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/comment/WorkLogCommentServiceImpl.java
index d61ca0c7..3de49267 100644
--- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/comment/WorkLogCommentServiceImpl.java
+++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/comment/WorkLogCommentServiceImpl.java
@@ -1,20 +1,24 @@
package cn.iocoder.yudao.module.system.service.comment;
+import cn.hutool.core.util.StrUtil;
+import cn.hutool.json.JSONObject;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
+import cn.iocoder.yudao.framework.web.core.util.WebFrameworkUtils;
import cn.iocoder.yudao.module.system.controller.app.comment.dto.CommentDTO;
import cn.iocoder.yudao.module.system.controller.app.comment.vo.CommentPageListVO;
import cn.iocoder.yudao.module.system.controller.app.comment.vo.WorkLogCommentPageReqVO;
import cn.iocoder.yudao.module.system.controller.app.comment.vo.WorkLogCommentSaveReqVO;
import cn.iocoder.yudao.module.system.dal.dataobject.comment.WorkLogCommentDO;
+import cn.iocoder.yudao.module.system.dal.dataobject.worklog.LogFormDO;
import cn.iocoder.yudao.module.system.dal.mysql.comment.WorkLogCommentMapper;
+import cn.iocoder.yudao.module.system.service.worklog.LogFormService;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.stereotype.Service;
import org.springframework.validation.annotation.Validated;
import javax.annotation.Resource;
-import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
@@ -30,11 +34,15 @@ public class WorkLogCommentServiceImpl implements WorkLogCommentService {
@Resource
private WorkLogCommentMapper workLogCommentMapper;
+ @Resource
+ private LogFormService logFormService;
@Override
public Long createWorkLogComment(WorkLogCommentSaveReqVO createReqVO) {
// 插入
WorkLogCommentDO workLogComment = BeanUtils.toBean(createReqVO, WorkLogCommentDO.class);
+ Long userId = WebFrameworkUtils.getLoginUserId();
+ workLogComment.setUserId(userId);
workLogCommentMapper.insert(workLogComment);
// 返回
return workLogComment.getId();
@@ -76,30 +84,31 @@ public class WorkLogCommentServiceImpl implements WorkLogCommentService {
@Override
public IPage queryCommentPageList(Page page, CommentDTO dto) {
IPage pageList = workLogCommentMapper.queryCommentPageList(page, dto);
- if (dto.getIsShowWorkLogContent() != null && dto.getIsShowWorkLogContent() == 1) {
- List records = pageList.getRecords();
+ List records = pageList.getRecords();
+ if (dto.getIsShowWorkLogContent() != null && dto.getIsShowWorkLogContent() == 1 && !records.isEmpty()) {
//模版ids过滤
List workFormIds = records.stream().map(CommentPageListVO::getWorkFormId).collect(Collectors.toList());
- // TODO: 2024/4/11 查询模版列表
-
+ // 查询模版列表
+ List formList = logFormService.getFormList(workFormIds);
+ Map formMap = formList.stream().collect(Collectors.toMap(LogFormDO::getId, item -> item));
pageList.getRecords().forEach(item -> {
- // TODO: 2024/4/11 - 这里需要通过模版id
- item.setWorkLogContent(null);
+ LogFormDO logFormDO = formMap.get(item.getWorkFormId());
+ List fields = logFormDO.getFields();
+ StringBuilder workLogContent = new StringBuilder();
+ if (StrUtil.isNotEmpty(item.getWorkLogContent())) {
+ JSONObject workLogContentJson = new JSONObject(item.getWorkLogContent());
+ for (String fieldItem : fields) {
+ JSONObject fieldJson = new JSONObject(fieldItem);
+ String fieldStr = fieldJson.getStr("field");
+ String title = fieldJson.getStr("title");
+ String field = workLogContentJson.getStr(fieldStr);
+ workLogContent.append(title).append(":").append(field);
+ }
+ }
+ item.setWorkLogContent(workLogContent.toString());
});
}
return pageList;
}
-
- public static void main(String[] args) {
- List records = Arrays.asList(
- new CommentPageListVO().setWorkLogId(1L).setWorkFormId("1"),
- new CommentPageListVO().setWorkLogId(1L).setWorkFormId("1"),
- new CommentPageListVO().setWorkLogId(1L).setWorkFormId("1"),
- new CommentPageListVO().setWorkLogId(2L).setWorkFormId("1"));
- Map collect = records.stream().collect(Collectors.toMap(CommentPageListVO::getWorkLogId, CommentPageListVO::getWorkFormId));
- System.out.println(collect);
-
- }
-
}
\ No newline at end of file
From 080cc6bea595c1ed943d05d7da5f93cd66874ef2 Mon Sep 17 00:00:00 2001
From: aikai
Date: Fri, 12 Apr 2024 12:01:19 +0800
Subject: [PATCH 09/50] =?UTF-8?q?=E6=97=A5=E5=BF=97=E8=AF=84=E8=AE=BA?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../src/main/resources/mapper/comment/WorkLogCommentMapper.xml | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/yudao-module-system/yudao-module-system-biz/src/main/resources/mapper/comment/WorkLogCommentMapper.xml b/yudao-module-system/yudao-module-system-biz/src/main/resources/mapper/comment/WorkLogCommentMapper.xml
index e3538cf0..144d974b 100644
--- a/yudao-module-system/yudao-module-system-biz/src/main/resources/mapper/comment/WorkLogCommentMapper.xml
+++ b/yudao-module-system/yudao-module-system-biz/src/main/resources/mapper/comment/WorkLogCommentMapper.xml
@@ -20,7 +20,8 @@
d.avatar AS commentAvatar,
d.nickname AS commentUserName,
a.COMMENT AS COMMENT,
- a.type AS type e.COMMENT AS replyComment,
+ a.type AS type,
+ e.COMMENT AS replyComment,
b.name as workLogName,
b.form_variables AS workLogContent,
From fda0fb5027b76e76ad3302040a95c006d7fd3da0 Mon Sep 17 00:00:00 2001
From: aikai
Date: Fri, 12 Apr 2024 15:05:17 +0800
Subject: [PATCH 10/50] =?UTF-8?q?=E8=8E=B7=E5=8F=96=E8=AF=84=E8=AE=BA?=
=?UTF-8?q?=E7=B1=BB=E5=9E=8B=E6=95=B0=E9=87=8F?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../app/comment/WorkLogCommentController.java | 6 ++
.../app/comment/dto/CommentDTO.java | 8 +-
.../app/comment/vo/CommentTypeCountVO.java | 16 ++++
.../comment/WorkLogCommentService.java | 23 ++++--
.../comment/WorkLogCommentServiceImpl.java | 20 +++++
.../worklog/LogInstanceServiceImpl.java | 76 +++++++++----------
.../mapper/comment/WorkLogCommentMapper.xml | 3 +
7 files changed, 105 insertions(+), 47 deletions(-)
create mode 100644 yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/app/comment/vo/CommentTypeCountVO.java
diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/app/comment/WorkLogCommentController.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/app/comment/WorkLogCommentController.java
index c62032d3..2cc45650 100644
--- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/app/comment/WorkLogCommentController.java
+++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/app/comment/WorkLogCommentController.java
@@ -3,6 +3,7 @@ package cn.iocoder.yudao.module.system.controller.app.comment;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.module.system.controller.app.comment.dto.CommentDTO;
import cn.iocoder.yudao.module.system.controller.app.comment.vo.CommentPageListVO;
+import cn.iocoder.yudao.module.system.controller.app.comment.vo.CommentTypeCountVO;
import cn.iocoder.yudao.module.system.controller.app.comment.vo.WorkLogCommentSaveReqVO;
import cn.iocoder.yudao.module.system.service.comment.WorkLogCommentService;
import com.baomidou.mybatisplus.core.metadata.IPage;
@@ -40,5 +41,10 @@ public class WorkLogCommentController {
return success(workLogCommentService.createWorkLogComment(createReqVO));
}
+ @GetMapping("/queryCommentTypeCount")
+ @Operation(summary = "获取评论类型数量")
+ public CommonResult queryCommentTypeCount() {
+ return success(workLogCommentService.queryCommentTypeCount());
+ }
}
\ No newline at end of file
diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/app/comment/dto/CommentDTO.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/app/comment/dto/CommentDTO.java
index 4e488434..8f33d89d 100644
--- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/app/comment/dto/CommentDTO.java
+++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/app/comment/dto/CommentDTO.java
@@ -7,11 +7,17 @@ import lombok.Data;
@Data
public class CommentDTO {
- @Schema(description = "工作日志id", required = true)
+ @Schema(description = "工作日志id")
@JsonSerialize(using = ToStringSerializer.class)
private Long workLogId;
@Schema(description = "评论类型(0|评论;1|回评")
private Integer type;
@Schema(description = "是否需要显示日志内容 0否 1是 默认否")
private Integer isShowWorkLogContent;
+
+ @Schema(description = "是否查看自己的评论记录 0否 1是")
+ private Integer checkMyselfFlag;
+
+ @Schema(description = "用户id")
+ private Long userId;
}
diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/app/comment/vo/CommentTypeCountVO.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/app/comment/vo/CommentTypeCountVO.java
new file mode 100644
index 00000000..09e474ba
--- /dev/null
+++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/app/comment/vo/CommentTypeCountVO.java
@@ -0,0 +1,16 @@
+package cn.iocoder.yudao.module.system.controller.app.comment.vo;
+
+import io.swagger.v3.oas.annotations.media.Schema;
+import lombok.Data;
+
+@Data
+public class CommentTypeCountVO {
+
+ @Schema(description = "全部数量")
+ private Integer allNum;
+ @Schema(description = "评论数量")
+ private Integer commentNum;
+ @Schema(description = "回复数量")
+ private Integer replyNum;
+
+}
diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/comment/WorkLogCommentService.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/comment/WorkLogCommentService.java
index ea657381..8eeaa7b8 100644
--- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/comment/WorkLogCommentService.java
+++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/comment/WorkLogCommentService.java
@@ -1,16 +1,17 @@
package cn.iocoder.yudao.module.system.service.comment;
-import java.util.*;
-import javax.validation.*;
-
-import cn.iocoder.yudao.module.system.controller.app.comment.dto.CommentDTO;
-import cn.iocoder.yudao.module.system.controller.app.comment.vo.*;
-import cn.iocoder.yudao.module.system.dal.dataobject.comment.WorkLogCommentDO;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
-import cn.iocoder.yudao.framework.common.pojo.PageParam;
+import cn.iocoder.yudao.module.system.controller.app.comment.dto.CommentDTO;
+import cn.iocoder.yudao.module.system.controller.app.comment.vo.CommentPageListVO;
+import cn.iocoder.yudao.module.system.controller.app.comment.vo.CommentTypeCountVO;
+import cn.iocoder.yudao.module.system.controller.app.comment.vo.WorkLogCommentPageReqVO;
+import cn.iocoder.yudao.module.system.controller.app.comment.vo.WorkLogCommentSaveReqVO;
+import cn.iocoder.yudao.module.system.dal.dataobject.comment.WorkLogCommentDO;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import javax.validation.Valid;
+
/**
* 工作日志评论 Service 接口
*
@@ -57,10 +58,16 @@ public interface WorkLogCommentService {
PageResult getWorkLogCommentPage(WorkLogCommentPageReqVO pageReqVO);
/**
- *
* @param page
* @param dto
* @return
*/
IPage queryCommentPageList(Page page, CommentDTO dto);
+
+ /**
+ * 获取评论类型数量
+ *
+ * @return
+ */
+ CommentTypeCountVO queryCommentTypeCount();
}
\ No newline at end of file
diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/comment/WorkLogCommentServiceImpl.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/comment/WorkLogCommentServiceImpl.java
index 3de49267..9edc4631 100644
--- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/comment/WorkLogCommentServiceImpl.java
+++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/comment/WorkLogCommentServiceImpl.java
@@ -7,12 +7,14 @@ import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import cn.iocoder.yudao.framework.web.core.util.WebFrameworkUtils;
import cn.iocoder.yudao.module.system.controller.app.comment.dto.CommentDTO;
import cn.iocoder.yudao.module.system.controller.app.comment.vo.CommentPageListVO;
+import cn.iocoder.yudao.module.system.controller.app.comment.vo.CommentTypeCountVO;
import cn.iocoder.yudao.module.system.controller.app.comment.vo.WorkLogCommentPageReqVO;
import cn.iocoder.yudao.module.system.controller.app.comment.vo.WorkLogCommentSaveReqVO;
import cn.iocoder.yudao.module.system.dal.dataobject.comment.WorkLogCommentDO;
import cn.iocoder.yudao.module.system.dal.dataobject.worklog.LogFormDO;
import cn.iocoder.yudao.module.system.dal.mysql.comment.WorkLogCommentMapper;
import cn.iocoder.yudao.module.system.service.worklog.LogFormService;
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.stereotype.Service;
@@ -83,6 +85,10 @@ public class WorkLogCommentServiceImpl implements WorkLogCommentService {
@Override
public IPage queryCommentPageList(Page page, CommentDTO dto) {
+ if (dto.getCheckMyselfFlag() == 1) {
+ Long userId = WebFrameworkUtils.getLoginUserId();
+ dto.setUserId(userId);
+ }
IPage pageList = workLogCommentMapper.queryCommentPageList(page, dto);
List records = pageList.getRecords();
if (dto.getIsShowWorkLogContent() != null && dto.getIsShowWorkLogContent() == 1 && !records.isEmpty()) {
@@ -111,4 +117,18 @@ public class WorkLogCommentServiceImpl implements WorkLogCommentService {
return pageList;
}
+ @Override
+ public CommentTypeCountVO queryCommentTypeCount() {
+ Long userId = WebFrameworkUtils.getLoginUserId();
+ CommentTypeCountVO vo = new CommentTypeCountVO();
+ Integer commentNum = Math.toIntExact(workLogCommentMapper.selectCount(new LambdaQueryWrapper()
+ .eq(WorkLogCommentDO::getUserId, userId)));
+ Integer replyNum = Math.toIntExact(workLogCommentMapper.selectCount(new LambdaQueryWrapper()
+ .eq(WorkLogCommentDO::getCommentUserId, userId)));
+ vo.setCommentNum(commentNum);
+ vo.setReplyNum(replyNum);
+ vo.setAllNum(commentNum + replyNum);
+ return vo;
+ }
+
}
\ No newline at end of file
diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/worklog/LogInstanceServiceImpl.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/worklog/LogInstanceServiceImpl.java
index 457860ad..c09750a3 100644
--- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/worklog/LogInstanceServiceImpl.java
+++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/worklog/LogInstanceServiceImpl.java
@@ -74,44 +74,44 @@ public class LogInstanceServiceImpl implements LogInstanceService {
Set