Commit 4d2346a4 by 王志超

feat: 变更行动工单列表

parent f2eaa556
......@@ -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.FlowxOperationEnum;
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.ChangeRecord;
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.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.ChangeSubFlowListQueryReq;
import com.netease.mail.yanxuan.change.dal.meta.model.req.ChangeSubFlowSubmitReq;
......@@ -67,6 +71,9 @@ public class ChangeSubFlowBiz {
private ChangeSubFlowRecordMapper changeSubFlowRecordMapper;
@Autowired
private ChangeRecordMapper changeRecordMapper;
@Autowired
private ChangeFlowBiz changeFlowBiz;
@Autowired
......@@ -333,51 +340,140 @@ public class ChangeSubFlowBiz {
public ChangeSubFlowListVO querySubFlowList(Integer page, Integer pageSize, ChangeSubFlowListQueryReq queryReq) {
log.info("[querySubFlowList] page:{}, pageSize:{}, queryReq:{}", page, pageSize, JSON.toJSONString(queryReq));
// 数据可见范围:仅查看我跟进的工单(默认true)
final String currentUser;
// 根据主单条件(flowId, itemId, supplier, onlyMyFollowed)查询主单,获取 changeRecordIds
List<Long> changeRecordIds = null;
if (queryReq.getFlowId() != null || StringUtils.isNotBlank(queryReq.getItemId())
|| StringUtils.isNotBlank(queryReq.getSupplier()) || queryReq.getOnlyMyFollowed()) {
// 构建主单查询条件
ChangeFlowListQueryReq mainQueryReq = new ChangeFlowListQueryReq();
mainQueryReq.setFlowId(queryReq.getFlowId());
mainQueryReq.setItemId(queryReq.getItemId());
mainQueryReq.setSupplier(queryReq.getSupplier());
mainQueryReq.setOnlyMyFollowed(queryReq.getOnlyMyFollowed());
String currentUser = RequestLocalBean.getUid();
// 数据可见范围:变更负责人=当前用户的变更工单所关联的全部变更行动工单
if (queryReq.getOnlyMyFollowed()) {
String uid = RequestLocalBean.getUid();
if (StringUtils.isNotBlank(uid)) {
currentUser = uid;
queryReq.setCurrentUser(currentUser);
log.info("[querySubFlowList] 数据可见范围:仅查看我跟进的工单, currentUser:{}", currentUser);
} else {
currentUser = null;
if (StringUtils.isNotBlank(currentUser)) {
mainQueryReq.setChangeCommander(currentUser);
}
}
// 查询主单(不分页,只获取ID)
List<ChangeRecord> changeRecords = changeRecordMapper.selectByCondition(mainQueryReq);
// 如果主单查询结果为空,直接返回
if (CollectionUtils.isEmpty(changeRecords)) {
PageVO pageVO = buildPageVo(0L, pageSize, page);
ChangeSubFlowListVO result = new ChangeSubFlowListVO();
result.setPageVo(pageVO);
result.setChangeSubFlowList(new ArrayList<>());
return result;
}
changeRecordIds = changeRecords.stream().map(ChangeRecord::getId).distinct().collect(Collectors.toList());
}
// 根据行动项条件(changeExecUser, changeExecDepartment)查询执行项,获取 subFlowRecordId,然后查询子单获取 subFlowId 列表
List<String> subFlowIds = null;
if (StringUtils.isNotBlank(queryReq.getChangeExecUser())
|| StringUtils.isNotBlank(queryReq.getChangeExecDepartment())) {
List<Long> subFlowRecordIds = new ArrayList<>();
// 根据 changeExecUser 查询
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 {
currentUser = null;
subFlowRecordIds = deptSubFlowRecordIds;
}
}
}
// 如果行动项查询结果为空,直接返回
if (CollectionUtils.isEmpty(subFlowRecordIds)) {
PageVO pageVO = buildPageVo(0L, pageSize, page);
ChangeSubFlowListVO result = new ChangeSubFlowListVO();
result.setPageVo(pageVO);
result.setChangeSubFlowList(new ArrayList<>());
return result;
}
// 先查询所有符合条件的变更行动工单(不进行分页,因为需要在内存中过滤)
List<ChangeSubFlowRecord> allSubFlowRecords = changeSubFlowRecordMapper.selectByCondition(queryReq);
// 根据 subFlowRecordId 查询子单,获取 subFlowId 列表
List<ChangeSubFlowRecord> subFlowRecords = subFlowRecordIds.stream()
.map(id -> changeSubFlowRecordMapper.selectByPrimaryKey(id))
.filter(Objects::nonNull)
.collect(Collectors.toList());
if (CollectionUtils.isNotEmpty(subFlowRecords)) {
subFlowIds = subFlowRecords.stream()
.map(ChangeSubFlowRecord::getSubFlowId)
.filter(StringUtils::isNotBlank)
.distinct()
.collect(Collectors.toList());
}
if (CollectionUtils.isEmpty(allSubFlowRecords)) {
// 如果子单ID列表为空,直接返回
if (CollectionUtils.isEmpty(subFlowIds)) {
PageVO pageVO = buildPageVo(0L, pageSize, page);
ChangeSubFlowListVO result = new ChangeSubFlowListVO();
result.setPageVo(pageVO);
result.setChangeSubFlowList(new ArrayList<>());
return result;
}
}
// 第三步:将查询条件填充到 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);
// 进行分页查询子单
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> changeRecordIds = allSubFlowRecords.stream()
List<Long> subFlowChangeRecordIds = subFlowRecords.stream()
.map(ChangeSubFlowRecord::getChangeRecordId)
.distinct()
.collect(Collectors.toList());
final Map<Long, ChangeRecord> changeRecordMap;
if (CollectionUtils.isNotEmpty(changeRecordIds)) {
List<ChangeRecord> changeRecords = changeRecordIds.stream()
if (CollectionUtils.isNotEmpty(subFlowChangeRecordIds)) {
List<ChangeRecord> subFlowChangeRecords = subFlowChangeRecordIds.stream()
.map(changeFlowService::getById)
.filter(Objects::nonNull)
.collect(Collectors.toList());
changeRecordMap = changeRecords.stream()
changeRecordMap = subFlowChangeRecords.stream()
.collect(Collectors.toMap(ChangeRecord::getId, r -> r));
} else {
changeRecordMap = new HashMap<>();
}
// 批量获取行动项信息(用于获取行动人、部门、完成时间等)
List<Long> subFlowRecordIds = allSubFlowRecords.stream()
List<Long> subFlowRecordIds = subFlowRecords.stream()
.map(ChangeSubFlowRecord::getId)
.collect(Collectors.toList());
Map<Long, List<ChangeExecRecord>> execRecordMap = new HashMap<>();
......@@ -390,115 +486,8 @@ public class ChangeSubFlowBiz {
}
}
// 在内存中过滤
List<ChangeSubFlowRecord> filteredSubFlowRecords = allSubFlowRecords.stream()
.filter(subFlowRecord -> {
// 过滤 flowId
if (queryReq.getFlowId() != null) {
ChangeRecord changeRecord = changeRecordMap.get(subFlowRecord.getChangeRecordId());
if (changeRecord == null || !queryReq.getFlowId().equals(changeRecord.getFlowId())) {
return false;
}
}
// 过滤 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())) {
List<ChangeExecRecord> execRecords = execRecordMap.get(subFlowRecord.getId());
if (CollectionUtils.isEmpty(execRecords)) {
return false;
}
boolean matched = execRecords.stream().anyMatch(exec ->
queryReq.getChangeExecDepartment().equals(exec.getChangeExecDepartment()));
if (!matched) {
return false;
}
}
// 过滤 onlyMyFollowed
if (queryReq.getOnlyMyFollowed() && currentUser != null && StringUtils.isNotBlank(currentUser)) {
ChangeRecord changeRecord = changeRecordMap.get(subFlowRecord.getChangeRecordId());
boolean matched = false;
// 检查主单的 creator, changeCommander, approver
if (changeRecord != null) {
if (currentUser.equals(changeRecord.getCreator())
|| currentUser.equals(changeRecord.getChangeCommander())) {
matched = true;
} else if (StringUtils.isNotBlank(changeRecord.getApprover())
&& changeRecord.getApprover().contains("\"" + currentUser + "\"")) {
matched = true;
}
}
// 检查行动工单的 approver
if (!matched && StringUtils.isNotBlank(subFlowRecord.getApprover())
&& subFlowRecord.getApprover().contains("\"" + currentUser + "\"")) {
matched = true;
}
// 检查行动项的 changeExecUserEmail
if (!matched) {
List<ChangeExecRecord> execRecords = execRecordMap.get(subFlowRecord.getId());
if (CollectionUtils.isNotEmpty(execRecords)) {
matched = execRecords.stream().anyMatch(exec ->
currentUser.equals(exec.getChangeExecUserEmail()));
}
}
if (!matched) {
return false;
}
}
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();
vo.setSubFlowId(subFlowRecord.getSubFlowId());
vo.setSubFlowNode(subFlowRecord.getSubFlowNode());
......@@ -570,7 +559,7 @@ public class ChangeSubFlowBiz {
}
}
PageVO pageVO = buildPageVo(total, pageSize, page);
PageVO pageVO = buildPageVo(subFlowRecordPageInfo.getTotal(), pageSize, page);
ChangeSubFlowListVO result = new ChangeSubFlowListVO();
result.setPageVo(pageVO);
result.setChangeSubFlowList(list);
......
......@@ -63,4 +63,18 @@ public interface ChangeFlowExecService {
* @return 行动项列表
*/
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;
import java.util.stream.Collectors;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
......@@ -88,4 +89,20 @@ public class ChangeFlowExecServiceImpl implements ChangeFlowExecService {
}
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<
*/
@Select("SELECT * FROM TB_YX_QC_CHANGE_EXEC_RECORD WHERE sub_flow_record_id = #{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 {
* 变更记录ID列表(用于过滤)
*/
private List<Long> changeRecordIds;
/**
* 变更行动工单ID列表(用于过滤)
*/
private List<String> subFlowIds;
}
......@@ -37,6 +37,12 @@
#{item}
</foreach>
</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>
order by create_time desc
</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