Commit fd9f7de7 by 王志超

feat: 变更行动工单列表,过滤行动人和行动部门

parent 6f82da45
......@@ -350,10 +350,9 @@ public class ChangeSubFlowBiz {
log.info("[querySubFlowList] page:{}, pageSize:{}, queryReq:{}", page, pageSize, JSON.toJSONString(queryReq));
// 根据主单条件(flowId, itemId, supplier, onlyMyFollowed)查询主单,获取 changeRecordIds
List<Long> changeRecordIds = null;
if (queryReq.getFlowId() != null || StringUtils.isNotBlank(queryReq.getItemId())
if (queryReq.getFlowId() != null || StringUtils.isNotBlank(queryReq.getItemId())
|| StringUtils.isNotBlank(queryReq.getSupplier()) || queryReq.getOnlyMyFollowed()) {
changeRecordIds = filterFlowRecordIds(queryReq);
List<Long> changeRecordIds = filterFlowRecordIds(queryReq);
if (CollectionUtils.isEmpty(changeRecordIds)) {
// 如果主单查询结果为空,直接返回
PageVO pageVO = buildPageVo(0L, pageSize, page);
......@@ -362,28 +361,28 @@ public class ChangeSubFlowBiz {
result.setChangeSubFlowList(new ArrayList<>());
return result;
}
queryReq.setChangeRecordIds(changeRecordIds);
}
// 根据行动项条件(changeExecUser, changeExecDepartment)查询执行项,获取 subFlowId 列表
List<String> subFlowIds = filterSubFlowIdsByExecCondition(queryReq);
if (subFlowIds != null && CollectionUtils.isEmpty(subFlowIds)) {
// 如果子单ID列表为空,直接返回
PageVO pageVO = buildPageVo(0L, pageSize, page);
ChangeSubFlowListVO result = new ChangeSubFlowListVO();
result.setPageVo(pageVO);
result.setChangeSubFlowList(new ArrayList<>());
return result;
if (StringUtils.isNotBlank(queryReq.getChangeExecUser())
|| StringUtils.isNotBlank(queryReq.getChangeExecDepartment())) {
List<String> subFlowIds = filterSubFlowIdsByExecCondition(queryReq);
if (CollectionUtils.isEmpty(subFlowIds)) {
// 如果子单ID列表为空,直接返回
PageVO pageVO = buildPageVo(0L, pageSize, page);
ChangeSubFlowListVO result = new ChangeSubFlowListVO();
result.setPageVo(pageVO);
result.setChangeSubFlowList(new ArrayList<>());
return result;
}
queryReq.setSubFlowIds(subFlowIds);
}
// 第三步:将查询条件填充到 queryReq,用 changeRecordIds + subFlowIds + 其他条件(subFlowNode, startTime, endTime)直接查询子单
queryReq.setChangeRecordIds(changeRecordIds);
queryReq.setSubFlowIds(subFlowIds);
// 清空主单和行动项相关的查询条件,因为已经通过 changeRecordIds 和 subFlowIds 过滤了
queryReq.setFlowId(null);
queryReq.setItemId(null);
queryReq.setSupplier(null);
queryReq.setChangeExecUser(null);
queryReq.setChangeExecDepartment(null);
queryReq.setOnlyMyFollowed(null);
queryReq.setCurrentUser(null);
......@@ -542,60 +541,27 @@ public class ChangeSubFlowBiz {
* 根据行动项条件(changeExecUser, changeExecDepartment)查询执行项,获取 subFlowId 列表
*
* @param queryReq 查询条件
* @return subFlowId 列表,如果没有行动项条件则返回 null
* @return subFlowId 列表
*/
private List<String> filterSubFlowIdsByExecCondition(ChangeSubFlowListQueryReq queryReq) {
// 如果没有行动项条件,返回 null
if (StringUtils.isBlank(queryReq.getChangeExecUser())
&& StringUtils.isBlank(queryReq.getChangeExecDepartment())) {
return null;
}
List<Long> subFlowRecordIds = new ArrayList<>();
// 根据 changeExecUser 查询(只查询 email,使用 LIKE)
if (StringUtils.isNotBlank(queryReq.getChangeExecUser())) {
List<Long> userSubFlowRecordIds = changeFlowExecService.querySubFlowRecordIdsByExecUser(queryReq.getChangeExecUser());
if (CollectionUtils.isNotEmpty(userSubFlowRecordIds)) {
subFlowRecordIds.addAll(userSubFlowRecordIds);
}
}
// 根据 changeExecDepartment 查询
if (StringUtils.isNotBlank(queryReq.getChangeExecDepartment())) {
List<Long> deptSubFlowRecordIds = changeFlowExecService.querySubFlowRecordIdsByExecDepartment(queryReq.getChangeExecDepartment());
if (CollectionUtils.isNotEmpty(deptSubFlowRecordIds)) {
if (CollectionUtils.isNotEmpty(subFlowRecordIds)) {
// 取交集
subFlowRecordIds = subFlowRecordIds.stream()
.filter(deptSubFlowRecordIds::contains)
.collect(Collectors.toList());
} else {
subFlowRecordIds = deptSubFlowRecordIds;
}
}
}
// 使用合并查询,根据字段是否为 null 来查询
List<Long> subFlowRecordIds = changeFlowExecService
.querySubFlowRecordIdsByExecCondition(queryReq.getChangeExecUser(), queryReq.getChangeExecDepartment());
// 如果行动项查询结果为空,返回空列表
if (CollectionUtils.isEmpty(subFlowRecordIds)) {
return new ArrayList<>();
}
// 根据 subFlowRecordId 查询子单,获取 subFlowId 列表
List<ChangeSubFlowRecord> subFlowRecords = subFlowRecordIds.stream()
.map(id -> changeSubFlowRecordMapper.selectByPrimaryKey(id))
.filter(Objects::nonNull)
.collect(Collectors.toList());
// 根据 subFlowRecordId 批量查询子单,获取 subFlowId 列表
List<ChangeSubFlowRecord> subFlowRecords = changeSubFlowRecordMapper.selectByIds(subFlowRecordIds);
if (CollectionUtils.isEmpty(subFlowRecords)) {
return new ArrayList<>();
}
return subFlowRecords.stream()
.map(ChangeSubFlowRecord::getSubFlowId)
.filter(StringUtils::isNotBlank)
.distinct()
.collect(Collectors.toList());
return subFlowRecords.stream().map(ChangeSubFlowRecord::getSubFlowId).filter(StringUtils::isNotBlank).distinct()
.collect(Collectors.toList());
}
/**
......
......@@ -58,16 +58,10 @@ public interface ChangeFlowExecService {
List<ChangeExecRecord> getBySubFlowRecordId(Long subFlowRecordId);
/**
* 根据变更行动人查询变更行动工单记录ID列表
* @param changeExecUser 变更行动人(邮箱或姓名)
* 根据变更行动人和部门查询变更行动工单记录ID列表(合并查询)
* @param changeExecUser 变更行动人(邮箱),可为空
* @param changeExecDepartment 变更行动部门,可为空
* @return 变更行动工单记录ID列表
*/
List<Long> querySubFlowRecordIdsByExecUser(String changeExecUser);
/**
* 根据变更行动部门查询变更行动工单记录ID列表
* @param changeExecDepartment 变更行动部门
* @return 变更行动工单记录ID列表
*/
List<Long> querySubFlowRecordIdsByExecDepartment(String changeExecDepartment);
List<Long> querySubFlowRecordIdsByExecCondition(String changeExecUser, String changeExecDepartment);
}
\ No newline at end of file
......@@ -86,18 +86,13 @@ public class ChangeFlowExecServiceImpl implements ChangeFlowExecService {
}
@Override
public List<Long> querySubFlowRecordIdsByExecUser(String changeExecUser) {
if (StringUtils.isBlank(changeExecUser)) {
public List<Long> querySubFlowRecordIdsByExecCondition(String changeExecUser, String changeExecDepartment) {
// 如果两个条件都为空,返回空列表
if (StringUtils.isBlank(changeExecUser) && StringUtils.isBlank(changeExecDepartment)) {
return new ArrayList<>();
}
return changeExecRecordMapper.querySubFlowRecordIdsByExecUser("%" + changeExecUser + "%");
}
@Override
public List<Long> querySubFlowRecordIdsByExecDepartment(String changeExecDepartment) {
if (StringUtils.isBlank(changeExecDepartment)) {
return new ArrayList<>();
}
return changeExecRecordMapper.querySubFlowRecordIdsByExecDepartment(changeExecDepartment);
// 如果 changeExecUser 不为空,添加 LIKE 通配符
String userCondition = StringUtils.isNotBlank(changeExecUser) ? "%" + changeExecUser + "%" : null;
return changeExecRecordMapper.querySubFlowRecordIdsByExecCondition(userCondition, changeExecDepartment);
}
}
......@@ -52,18 +52,23 @@ public interface ChangeExecRecordMapper extends tk.mybatis.mapper.common.Mapper<
List<ChangeExecRecord> selectBySubFlowRecordId(@Param("subFlowRecordId") Long subFlowRecordId);
/**
* 根据变更行动人查询变更行动工单记录ID列表(只查询 email,使用 LIKE)
* @param changeExecUser 变更行动人(邮箱)
* 根据变更行动人和部门查询变更行动工单记录ID列表(合并查询)
* @param changeExecUser 变更行动人(邮箱),可为空
* @param changeExecDepartment 变更行动部门,可为空
* @return 变更行动工单记录ID列表
*/
@Select("SELECT DISTINCT(sub_flow_record_id) FROM TB_YX_QC_CHANGE_EXEC_RECORD WHERE sub_flow_record_id IS NOT NULL AND change_exec_user_email LIKE #{changeExecUser}")
List<Long> querySubFlowRecordIdsByExecUser(@Param("changeExecUser") String changeExecUser);
/**
* 根据变更行动部门查询变更行动工单记录ID列表
* @param changeExecDepartment 变更行动部门
* @return 变更行动工单记录ID列表
*/
@Select("SELECT DISTINCT(sub_flow_record_id) FROM TB_YX_QC_CHANGE_EXEC_RECORD WHERE sub_flow_record_id IS NOT NULL AND change_exec_department = #{changeExecDepartment}")
List<Long> querySubFlowRecordIdsByExecDepartment(@Param("changeExecDepartment") String changeExecDepartment);
@Select({
"<script>",
"SELECT DISTINCT(sub_flow_record_id) FROM TB_YX_QC_CHANGE_EXEC_RECORD",
"WHERE sub_flow_record_id IS NOT NULL",
"<if test='changeExecUser != null'>",
"AND change_exec_user_email LIKE #{changeExecUser}",
"</if>",
"<if test='changeExecDepartment != null'>",
"AND change_exec_department LIKE CONCAT('%',#{changeExecDepartment},'%')",
"</if>",
"</script>"
})
List<Long> querySubFlowRecordIdsByExecCondition(@Param("changeExecUser") String changeExecUser,
@Param("changeExecDepartment") String changeExecDepartment);
}
......@@ -52,6 +52,20 @@ public interface ChangeSubFlowRecordMapper extends tk.mybatis.mapper.common.Mapp
List<ChangeSubFlowRecord> selectByChangeRecordIds(@Param("changeRecordIds") List<Long> changeRecordIds);
/**
* 批量根据ID列表查询变更行动工单列表
* @param ids ID列表
* @return 变更行动工单列表
*/
@Select("<script>" +
"SELECT * FROM TB_YX_QC_CHANGE_SUB_FLOW_RECORD " +
"WHERE id IN " +
"<foreach collection='ids' item='id' open='(' separator=',' close=')'>" +
"#{id}" +
"</foreach>" +
"</script>")
List<ChangeSubFlowRecord> selectByIds(@Param("ids") List<Long> ids);
/**
* 根据条件查询变更行动工单列表
* @param queryReq 查询条件
* @return 变更行动工单列表
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment