Commit 4d2346a4 by 王志超

feat: 变更行动工单列表

parent f2eaa556
...@@ -16,10 +16,14 @@ import com.netease.mail.yanxuan.change.common.enums.ChangeFlowEnum; ...@@ -16,10 +16,14 @@ import com.netease.mail.yanxuan.change.common.enums.ChangeFlowEnum;
import com.netease.mail.yanxuan.change.common.enums.FlowOperationTypeEnum; import com.netease.mail.yanxuan.change.common.enums.FlowOperationTypeEnum;
import com.netease.mail.yanxuan.change.common.enums.FlowxOperationEnum; import com.netease.mail.yanxuan.change.common.enums.FlowxOperationEnum;
import com.netease.mail.yanxuan.change.common.util.DateUtils; import com.netease.mail.yanxuan.change.common.util.DateUtils;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.netease.mail.yanxuan.change.dal.entity.ChangeExecRecord; import com.netease.mail.yanxuan.change.dal.entity.ChangeExecRecord;
import com.netease.mail.yanxuan.change.dal.entity.ChangeRecord; import com.netease.mail.yanxuan.change.dal.entity.ChangeRecord;
import com.netease.mail.yanxuan.change.dal.entity.ChangeSubFlowRecord; import com.netease.mail.yanxuan.change.dal.entity.ChangeSubFlowRecord;
import com.netease.mail.yanxuan.change.dal.mapper.ChangeRecordMapper;
import com.netease.mail.yanxuan.change.dal.mapper.ChangeSubFlowRecordMapper; import com.netease.mail.yanxuan.change.dal.mapper.ChangeSubFlowRecordMapper;
import com.netease.mail.yanxuan.change.dal.meta.model.req.ChangeFlowListQueryReq;
import com.netease.mail.yanxuan.change.dal.meta.model.req.ChangeSubFlowCreateReq; import com.netease.mail.yanxuan.change.dal.meta.model.req.ChangeSubFlowCreateReq;
import com.netease.mail.yanxuan.change.dal.meta.model.req.ChangeSubFlowListQueryReq; import com.netease.mail.yanxuan.change.dal.meta.model.req.ChangeSubFlowListQueryReq;
import com.netease.mail.yanxuan.change.dal.meta.model.req.ChangeSubFlowSubmitReq; import com.netease.mail.yanxuan.change.dal.meta.model.req.ChangeSubFlowSubmitReq;
...@@ -67,6 +71,9 @@ public class ChangeSubFlowBiz { ...@@ -67,6 +71,9 @@ public class ChangeSubFlowBiz {
private ChangeSubFlowRecordMapper changeSubFlowRecordMapper; private ChangeSubFlowRecordMapper changeSubFlowRecordMapper;
@Autowired @Autowired
private ChangeRecordMapper changeRecordMapper;
@Autowired
private ChangeFlowBiz changeFlowBiz; private ChangeFlowBiz changeFlowBiz;
@Autowired @Autowired
...@@ -333,172 +340,154 @@ public class ChangeSubFlowBiz { ...@@ -333,172 +340,154 @@ public class ChangeSubFlowBiz {
public ChangeSubFlowListVO querySubFlowList(Integer page, Integer pageSize, ChangeSubFlowListQueryReq queryReq) { public ChangeSubFlowListVO querySubFlowList(Integer page, Integer pageSize, ChangeSubFlowListQueryReq queryReq) {
log.info("[querySubFlowList] page:{}, pageSize:{}, queryReq:{}", page, pageSize, JSON.toJSONString(queryReq)); log.info("[querySubFlowList] page:{}, pageSize:{}, queryReq:{}", page, pageSize, JSON.toJSONString(queryReq));
// 数据可见范围:仅查看我跟进的工单(默认true) // 根据主单条件(flowId, itemId, supplier, onlyMyFollowed)查询主单,获取 changeRecordIds
final String currentUser; List<Long> changeRecordIds = null;
if (queryReq.getOnlyMyFollowed()) { if (queryReq.getFlowId() != null || StringUtils.isNotBlank(queryReq.getItemId())
String uid = RequestLocalBean.getUid(); || StringUtils.isNotBlank(queryReq.getSupplier()) || queryReq.getOnlyMyFollowed()) {
if (StringUtils.isNotBlank(uid)) { // 构建主单查询条件
currentUser = uid; ChangeFlowListQueryReq mainQueryReq = new ChangeFlowListQueryReq();
queryReq.setCurrentUser(currentUser); mainQueryReq.setFlowId(queryReq.getFlowId());
log.info("[querySubFlowList] 数据可见范围:仅查看我跟进的工单, currentUser:{}", currentUser); mainQueryReq.setItemId(queryReq.getItemId());
} else { mainQueryReq.setSupplier(queryReq.getSupplier());
currentUser = null; mainQueryReq.setOnlyMyFollowed(queryReq.getOnlyMyFollowed());
String currentUser = RequestLocalBean.getUid();
// 数据可见范围:变更负责人=当前用户的变更工单所关联的全部变更行动工单
if (queryReq.getOnlyMyFollowed()) {
if (StringUtils.isNotBlank(currentUser)) {
mainQueryReq.setChangeCommander(currentUser);
}
} }
} else {
currentUser = null;
}
// 先查询所有符合条件的变更行动工单(不进行分页,因为需要在内存中过滤 // 查询主单(不分页,只获取ID
List<ChangeSubFlowRecord> allSubFlowRecords = changeSubFlowRecordMapper.selectByCondition(queryReq); List<ChangeRecord> changeRecords = changeRecordMapper.selectByCondition(mainQueryReq);
if (CollectionUtils.isEmpty(allSubFlowRecords)) { // 如果主单查询结果为空,直接返回
PageVO pageVO = buildPageVo(0L, pageSize, page); if (CollectionUtils.isEmpty(changeRecords)) {
ChangeSubFlowListVO result = new ChangeSubFlowListVO(); PageVO pageVO = buildPageVo(0L, pageSize, page);
result.setPageVo(pageVO); ChangeSubFlowListVO result = new ChangeSubFlowListVO();
result.setChangeSubFlowList(new ArrayList<>()); result.setPageVo(pageVO);
return result; result.setChangeSubFlowList(new ArrayList<>());
} return result;
}
// 批量获取主单信息 changeRecordIds = changeRecords.stream().map(ChangeRecord::getId).distinct().collect(Collectors.toList());
List<Long> changeRecordIds = allSubFlowRecords.stream()
.map(ChangeSubFlowRecord::getChangeRecordId)
.distinct()
.collect(Collectors.toList());
final Map<Long, ChangeRecord> changeRecordMap;
if (CollectionUtils.isNotEmpty(changeRecordIds)) {
List<ChangeRecord> changeRecords = changeRecordIds.stream()
.map(changeFlowService::getById)
.filter(Objects::nonNull)
.collect(Collectors.toList());
changeRecordMap = changeRecords.stream()
.collect(Collectors.toMap(ChangeRecord::getId, r -> r));
} else {
changeRecordMap = new HashMap<>();
} }
// 批量获取行动项信息(用于获取行动人、部门、完成时间等) // 根据行动项条件(changeExecUser, changeExecDepartment)查询执行项,获取 subFlowRecordId,然后查询子单获取 subFlowId 列表
List<Long> subFlowRecordIds = allSubFlowRecords.stream() List<String> subFlowIds = null;
.map(ChangeSubFlowRecord::getId) if (StringUtils.isNotBlank(queryReq.getChangeExecUser())
.collect(Collectors.toList()); || StringUtils.isNotBlank(queryReq.getChangeExecDepartment())) {
Map<Long, List<ChangeExecRecord>> execRecordMap = new HashMap<>(); List<Long> subFlowRecordIds = new ArrayList<>();
if (CollectionUtils.isNotEmpty(subFlowRecordIds)) {
for (Long subFlowRecordId : subFlowRecordIds) { // 根据 changeExecUser 查询
List<ChangeExecRecord> execRecords = changeFlowExecService.getBySubFlowRecordId(subFlowRecordId); if (StringUtils.isNotBlank(queryReq.getChangeExecUser())) {
if (CollectionUtils.isNotEmpty(execRecords)) { List<Long> userSubFlowRecordIds = changeFlowExecService.querySubFlowRecordIdsByExecUser(queryReq.getChangeExecUser());
execRecordMap.put(subFlowRecordId, execRecords); if (CollectionUtils.isNotEmpty(userSubFlowRecordIds)) {
subFlowRecordIds.addAll(userSubFlowRecordIds);
} }
} }
}
// 在内存中过滤 // 根据 changeExecDepartment 查询
List<ChangeSubFlowRecord> filteredSubFlowRecords = allSubFlowRecords.stream() if (StringUtils.isNotBlank(queryReq.getChangeExecDepartment())) {
.filter(subFlowRecord -> { List<Long> deptSubFlowRecordIds = changeFlowExecService.querySubFlowRecordIdsByExecDepartment(queryReq.getChangeExecDepartment());
// 过滤 flowId if (CollectionUtils.isNotEmpty(deptSubFlowRecordIds)) {
if (queryReq.getFlowId() != null) { if (CollectionUtils.isNotEmpty(subFlowRecordIds)) {
ChangeRecord changeRecord = changeRecordMap.get(subFlowRecord.getChangeRecordId()); // 取交集
if (changeRecord == null || !queryReq.getFlowId().equals(changeRecord.getFlowId())) { subFlowRecordIds = subFlowRecordIds.stream()
return false; .filter(deptSubFlowRecordIds::contains)
} .collect(Collectors.toList());
} } else {
subFlowRecordIds = deptSubFlowRecordIds;
// 过滤 itemId
if (StringUtils.isNotBlank(queryReq.getItemId())) {
ChangeRecord changeRecord = changeRecordMap.get(subFlowRecord.getChangeRecordId());
if (changeRecord == null || StringUtils.isBlank(changeRecord.getChangeItem())
|| !changeRecord.getChangeItem().contains(queryReq.getItemId())) {
return false;
}
}
// 过滤 supplier
if (StringUtils.isNotBlank(queryReq.getSupplier())) {
ChangeRecord changeRecord = changeRecordMap.get(subFlowRecord.getChangeRecordId());
if (changeRecord == null || !queryReq.getSupplier().equals(changeRecord.getChangeSupplier())) {
return false;
}
}
// 过滤 changeExecUser
if (StringUtils.isNotBlank(queryReq.getChangeExecUser())) {
List<ChangeExecRecord> execRecords = execRecordMap.get(subFlowRecord.getId());
if (CollectionUtils.isEmpty(execRecords)) {
return false;
}
boolean matched = execRecords.stream().anyMatch(exec ->
(StringUtils.isNotBlank(exec.getChangeExecUserEmail())
&& exec.getChangeExecUserEmail().contains(queryReq.getChangeExecUser()))
|| (StringUtils.isNotBlank(exec.getChangeExecUser())
&& exec.getChangeExecUser().contains(queryReq.getChangeExecUser())));
if (!matched) {
return false;
}
} }
}
}
// 过滤 changeExecDepartment // 如果行动项查询结果为空,直接返回
if (StringUtils.isNotBlank(queryReq.getChangeExecDepartment())) { if (CollectionUtils.isEmpty(subFlowRecordIds)) {
List<ChangeExecRecord> execRecords = execRecordMap.get(subFlowRecord.getId()); PageVO pageVO = buildPageVo(0L, pageSize, page);
if (CollectionUtils.isEmpty(execRecords)) { ChangeSubFlowListVO result = new ChangeSubFlowListVO();
return false; result.setPageVo(pageVO);
} result.setChangeSubFlowList(new ArrayList<>());
boolean matched = execRecords.stream().anyMatch(exec -> return result;
queryReq.getChangeExecDepartment().equals(exec.getChangeExecDepartment())); }
if (!matched) {
return false;
}
}
// 过滤 onlyMyFollowed // 根据 subFlowRecordId 查询子单,获取 subFlowId 列表
if (queryReq.getOnlyMyFollowed() && currentUser != null && StringUtils.isNotBlank(currentUser)) { List<ChangeSubFlowRecord> subFlowRecords = subFlowRecordIds.stream()
ChangeRecord changeRecord = changeRecordMap.get(subFlowRecord.getChangeRecordId()); .map(id -> changeSubFlowRecordMapper.selectByPrimaryKey(id))
boolean matched = false; .filter(Objects::nonNull)
.collect(Collectors.toList());
// 检查主单的 creator, changeCommander, approver if (CollectionUtils.isNotEmpty(subFlowRecords)) {
if (changeRecord != null) { subFlowIds = subFlowRecords.stream()
if (currentUser.equals(changeRecord.getCreator()) .map(ChangeSubFlowRecord::getSubFlowId)
|| currentUser.equals(changeRecord.getChangeCommander())) { .filter(StringUtils::isNotBlank)
matched = true; .distinct()
} else if (StringUtils.isNotBlank(changeRecord.getApprover()) .collect(Collectors.toList());
&& changeRecord.getApprover().contains("\"" + currentUser + "\"")) { }
matched = true;
}
}
// 检查行动工单的 approver // 如果子单ID列表为空,直接返回
if (!matched && StringUtils.isNotBlank(subFlowRecord.getApprover()) if (CollectionUtils.isEmpty(subFlowIds)) {
&& subFlowRecord.getApprover().contains("\"" + currentUser + "\"")) { PageVO pageVO = buildPageVo(0L, pageSize, page);
matched = true; ChangeSubFlowListVO result = new ChangeSubFlowListVO();
} result.setPageVo(pageVO);
result.setChangeSubFlowList(new ArrayList<>());
return result;
}
}
// 检查行动项的 changeExecUserEmail // 第三步:将查询条件填充到 queryReq,用 changeRecordIds + subFlowIds + 其他条件(subFlowNode, startTime, endTime)直接查询子单
if (!matched) { queryReq.setChangeRecordIds(changeRecordIds);
List<ChangeExecRecord> execRecords = execRecordMap.get(subFlowRecord.getId()); queryReq.setSubFlowIds(subFlowIds);
if (CollectionUtils.isNotEmpty(execRecords)) { // 清空主单和行动项相关的查询条件,因为已经通过 changeRecordIds 和 subFlowIds 过滤了
matched = execRecords.stream().anyMatch(exec -> queryReq.setFlowId(null);
currentUser.equals(exec.getChangeExecUserEmail())); queryReq.setItemId(null);
} queryReq.setSupplier(null);
} queryReq.setChangeExecUser(null);
queryReq.setChangeExecDepartment(null);
queryReq.setOnlyMyFollowed(null);
queryReq.setCurrentUser(null);
// 进行分页查询子单
PageHelper.startPage(page, pageSize);
List<ChangeSubFlowRecord> subFlowRecords = changeSubFlowRecordMapper.selectByCondition(queryReq);
PageInfo<ChangeSubFlowRecord> subFlowRecordPageInfo = new PageInfo<>(subFlowRecords);
// 第四步:批量获取主单信息和行动项信息,构建返回列表
List<ChangeSubFlowVO> list = new ArrayList<>();
if (CollectionUtils.isNotEmpty(subFlowRecords)) {
// 批量获取主单信息
List<Long> subFlowChangeRecordIds = subFlowRecords.stream()
.map(ChangeSubFlowRecord::getChangeRecordId)
.distinct()
.collect(Collectors.toList());
final Map<Long, ChangeRecord> changeRecordMap;
if (CollectionUtils.isNotEmpty(subFlowChangeRecordIds)) {
List<ChangeRecord> subFlowChangeRecords = subFlowChangeRecordIds.stream()
.map(changeFlowService::getById)
.filter(Objects::nonNull)
.collect(Collectors.toList());
changeRecordMap = subFlowChangeRecords.stream()
.collect(Collectors.toMap(ChangeRecord::getId, r -> r));
} else {
changeRecordMap = new HashMap<>();
}
if (!matched) { // 批量获取行动项信息(用于获取行动人、部门、完成时间等)
return false; List<Long> subFlowRecordIds = subFlowRecords.stream()
} .map(ChangeSubFlowRecord::getId)
.collect(Collectors.toList());
Map<Long, List<ChangeExecRecord>> execRecordMap = new HashMap<>();
if (CollectionUtils.isNotEmpty(subFlowRecordIds)) {
for (Long subFlowRecordId : subFlowRecordIds) {
List<ChangeExecRecord> execRecords = changeFlowExecService.getBySubFlowRecordId(subFlowRecordId);
if (CollectionUtils.isNotEmpty(execRecords)) {
execRecordMap.put(subFlowRecordId, execRecords);
} }
}
}
return true;
})
.collect(Collectors.toList());
// 手动分页
long total = filteredSubFlowRecords.size();
int start = (page - 1) * pageSize;
int end = Math.min(start + pageSize, filteredSubFlowRecords.size());
List<ChangeSubFlowRecord> pagedSubFlowRecords = start < end
? filteredSubFlowRecords.subList(start, end)
: new ArrayList<>();
List<ChangeSubFlowVO> list = new ArrayList<>();
if (CollectionUtils.isNotEmpty(pagedSubFlowRecords)) {
// 构建返回列表 // 构建返回列表
for (ChangeSubFlowRecord subFlowRecord : pagedSubFlowRecords) { for (ChangeSubFlowRecord subFlowRecord : subFlowRecords) {
ChangeSubFlowVO vo = new ChangeSubFlowVO(); ChangeSubFlowVO vo = new ChangeSubFlowVO();
vo.setSubFlowId(subFlowRecord.getSubFlowId()); vo.setSubFlowId(subFlowRecord.getSubFlowId());
vo.setSubFlowNode(subFlowRecord.getSubFlowNode()); vo.setSubFlowNode(subFlowRecord.getSubFlowNode());
...@@ -570,7 +559,7 @@ public class ChangeSubFlowBiz { ...@@ -570,7 +559,7 @@ public class ChangeSubFlowBiz {
} }
} }
PageVO pageVO = buildPageVo(total, pageSize, page); PageVO pageVO = buildPageVo(subFlowRecordPageInfo.getTotal(), pageSize, page);
ChangeSubFlowListVO result = new ChangeSubFlowListVO(); ChangeSubFlowListVO result = new ChangeSubFlowListVO();
result.setPageVo(pageVO); result.setPageVo(pageVO);
result.setChangeSubFlowList(list); result.setChangeSubFlowList(list);
......
...@@ -63,4 +63,18 @@ public interface ChangeFlowExecService { ...@@ -63,4 +63,18 @@ public interface ChangeFlowExecService {
* @return 行动项列表 * @return 行动项列表
*/ */
List<ChangeExecRecord> getBySubFlowRecordId(Long subFlowRecordId); List<ChangeExecRecord> getBySubFlowRecordId(Long subFlowRecordId);
/**
* 根据变更行动人查询变更行动工单记录ID列表
* @param changeExecUser 变更行动人(邮箱或姓名)
* @return 变更行动工单记录ID列表
*/
List<Long> querySubFlowRecordIdsByExecUser(String changeExecUser);
/**
* 根据变更行动部门查询变更行动工单记录ID列表
* @param changeExecDepartment 变更行动部门
* @return 变更行动工单记录ID列表
*/
List<Long> querySubFlowRecordIdsByExecDepartment(String changeExecDepartment);
} }
\ No newline at end of file
...@@ -11,6 +11,7 @@ import java.util.List; ...@@ -11,6 +11,7 @@ import java.util.List;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
...@@ -88,4 +89,20 @@ public class ChangeFlowExecServiceImpl implements ChangeFlowExecService { ...@@ -88,4 +89,20 @@ public class ChangeFlowExecServiceImpl implements ChangeFlowExecService {
} }
return changeExecRecordMapper.selectBySubFlowRecordId(subFlowRecordId); return changeExecRecordMapper.selectBySubFlowRecordId(subFlowRecordId);
} }
@Override
public List<Long> querySubFlowRecordIdsByExecUser(String changeExecUser) {
if (StringUtils.isBlank(changeExecUser)) {
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);
}
} }
...@@ -53,4 +53,20 @@ public interface ChangeExecRecordMapper extends tk.mybatis.mapper.common.Mapper< ...@@ -53,4 +53,20 @@ public interface ChangeExecRecordMapper extends tk.mybatis.mapper.common.Mapper<
*/ */
@Select("SELECT * FROM TB_YX_QC_CHANGE_EXEC_RECORD WHERE sub_flow_record_id = #{subFlowRecordId}") @Select("SELECT * FROM TB_YX_QC_CHANGE_EXEC_RECORD WHERE sub_flow_record_id = #{subFlowRecordId}")
List<ChangeExecRecord> selectBySubFlowRecordId(@Param("subFlowRecordId") Long subFlowRecordId); List<ChangeExecRecord> selectBySubFlowRecordId(@Param("subFlowRecordId") Long subFlowRecordId);
/**
* 根据变更行动人查询变更行动工单记录ID列表
* @param changeExecUser 变更行动人(邮箱或姓名)
* @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} OR change_exec_user 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);
} }
...@@ -79,5 +79,10 @@ public class ChangeSubFlowListQueryReq { ...@@ -79,5 +79,10 @@ public class ChangeSubFlowListQueryReq {
* 变更记录ID列表(用于过滤) * 变更记录ID列表(用于过滤)
*/ */
private List<Long> changeRecordIds; private List<Long> changeRecordIds;
/**
* 变更行动工单ID列表(用于过滤)
*/
private List<String> subFlowIds;
} }
...@@ -37,6 +37,12 @@ ...@@ -37,6 +37,12 @@
#{item} #{item}
</foreach> </foreach>
</if> </if>
<if test="subFlowIds != null and subFlowIds.size() > 0">
and sub_flow_id in
<foreach collection="subFlowIds" close=")" open="(" item="item" separator=",">
#{item}
</foreach>
</if>
</where> </where>
order by create_time desc order by create_time desc
</select> </select>
......
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