优化任务查询列表

This commit is contained in:
cjw 2024-02-23 10:52:16 +08:00
parent 2498326db6
commit 58c18f886c
6 changed files with 66 additions and 26 deletions

View File

@ -53,6 +53,8 @@ public class MesPlanRecordVo implements Serializable {
private String ganttColor;
private String flag;
private Date createTime;

View File

@ -5,6 +5,8 @@ import com.ruoyi.mts.domain.vo.MesPlanRecordVo;
import com.ruoyi.common.core.mapper.BaseMapperPlus;
import org.apache.ibatis.annotations.Mapper;
import java.util.List;
/**
* 生产计划明细日期记录Mapper接口
*
@ -14,4 +16,6 @@ import org.apache.ibatis.annotations.Mapper;
@Mapper
public interface MesPlanRecordMapper extends BaseMapperPlus<MesPlanRecordMapper, MesPlanRecord, MesPlanRecordVo> {
List<MesPlanRecordVo> selectListByMainId(Long mainId);
}

View File

@ -1,10 +1,9 @@
package com.ruoyi.mts.service;
import com.ruoyi.mts.domain.MesPlanRecord;
import com.ruoyi.mts.domain.vo.MesPlanRecordVo;
import com.ruoyi.mts.domain.bo.MesPlanRecordBo;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.core.domain.PageQuery;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.mts.domain.bo.MesPlanRecordBo;
import com.ruoyi.mts.domain.vo.MesPlanRecordVo;
import java.util.Collection;
import java.util.List;
@ -48,4 +47,12 @@ public interface IMesPlanRecordService {
* 校验并批量删除生产计划明细日期记录信息
*/
Boolean deleteWithValidByIds(Collection<Long> ids, Boolean isValid);
/**
* 根据主计划id查询计划所有记录
*
* @param id
* @return
*/
List<MesPlanRecordVo> queryListByMainId(Long id);
}

View File

@ -20,6 +20,7 @@ import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import java.util.*;
import java.util.stream.Collectors;
/**
* 生产计划明细Service业务层处理
@ -49,49 +50,54 @@ public class MesPlanDetailServiceImpl implements IMesPlanDetailService {
*/
@Override
public List<MesPlanDetailVo> queryList(MesPlanDetailBo bo) {
// 查询所有父任务
bo.setParentId(0L);
LambdaQueryWrapper<MesPlanDetail> parentQuery = buildQueryWrapper(bo);
List<MesPlanDetailVo> parentList = baseMapper.selectVoList(parentQuery);
//LambdaQueryWrapper<MesPlanDetail> childrenQuery = Wrappers.lambdaQuery(MesPlanDetail.class).ne(TreeEntity::getParentId, 0).orderByAsc(MesPlanDetail::getId);
//List<MesPlanDetailVo> childrenList = baseMapper.selectVoList(childrenQuery);
//Map<Long, List<MesPlanDetailVo>> childrenCollect = childrenList.stream().collect(Collectors.groupingBy(MesPlanDetailVo::getParentId, Collectors.toList()));
// 数据处理
if (CollUtil.isEmpty(parentList)) {
return new ArrayList<>(0);
}
Long mainId = parentList.get(0).getMainId();
// 查询所有子任务并根据父任务id分组
LambdaQueryWrapper<MesPlanDetail> childrenQuery = Wrappers.lambdaQuery(MesPlanDetail.class).ne(TreeEntity::getParentId, 0).orderByAsc(MesPlanDetail::getId);
List<MesPlanDetailVo> childrenList = baseMapper.selectVoList(childrenQuery);
Map<Long, List<MesPlanDetailVo>> childrenCollect = childrenList.stream().collect(Collectors.groupingBy(MesPlanDetailVo::getParentId, Collectors.toList()));
// 查询任务下所有记录并根据任务id分组
List<MesPlanRecordVo> recordList = recordService.queryListByMainId(mainId);
Map<Long, List<MesPlanRecordVo>> recordCollect = recordList.stream().collect(Collectors.groupingBy(MesPlanRecordVo::getDetailId, Collectors.toList()));
// 父任务合并子任务
LinkedList<MesPlanDetailVo> res = new LinkedList<>();
for (int i = 0; i < parentList.size(); i++) {
MesPlanDetailVo vo = parentList.get(i);
res.add(vo);
LambdaQueryWrapper<MesPlanDetail> voLqw = Wrappers.lambdaQuery(MesPlanDetail.class).eq(TreeEntity::getParentId, vo.getId()).orderByAsc(MesPlanDetail::getId);
List<MesPlanDetailVo> children = baseMapper.selectVoList(voLqw);
//List<MesPlanDetailVo> children = childrenCollect.get(vo.getId());
// LambdaQueryWrapper<MesPlanDetail> voLqw = Wrappers.lambdaQuery(MesPlanDetail.class).eq(TreeEntity::getParentId, vo.getId()).orderByAsc(MesPlanDetail::getId);
// List<MesPlanDetailVo> children = baseMapper.selectVoList(voLqw);
List<MesPlanDetailVo> children = childrenCollect.get(vo.getId());
if (CollUtil.isNotEmpty(children)) {
res.addAll(i + 1, children);
}
}
// 任务添加记录信息
int size = res.size();
List<MesPlanDetailVo> data = new ArrayList<>(size << 2);
for (int i = 0; i < size; i++) {
//默认第一个为计划数据
// 默认第一个为计划数据
MesPlanDetailVo planVo = res.get(i);
Long id = planVo.getId();
List<MesPlanRecordVo> detailRecord = recordCollect.get(id);
Map<String, List<MesPlanRecordVo>> collect = detailRecord.stream().collect(Collectors.groupingBy(MesPlanRecordVo::getFlag, Collectors.toList()));
planVo.setFlag("plan");
MesPlanRecordBo record = new MesPlanRecordBo();
record.setDetailId(id);
record.setFlag("plan");
List<MesPlanRecordVo> mesPlanRecordVos = recordService.queryList(record);
planVo.setRecord(mesPlanRecordVos);
planVo.setRecord(collect.get("plan"));
data.add(planVo);
//处理实际数据
// 处理实际数据
MesPlanDetailVo actualVo = new MesPlanDetailVo();
actualVo.setId(planVo.getId());
actualVo.setName(planVo.getName());
actualVo.setParentId(planVo.getParentId());
actualVo.setMainId(planVo.getMainId());
actualVo.setFlag("actual");
record.setFlag("actual");
mesPlanRecordVos = recordService.queryList(record);
actualVo.setRecord(mesPlanRecordVos);
actualVo.setRecord(collect.get("actual"));
data.add(actualVo);
}
return data;

View File

@ -129,4 +129,15 @@ public class MesPlanRecordServiceImpl implements IMesPlanRecordService {
}
return baseMapper.deleteBatchIds(ids) > 0;
}
/**
* 根据主计划id查询计划所有记录
*
* @param id
* @return
*/
@Override
public List<MesPlanRecordVo> queryListByMainId(Long id) {
return baseMapper.selectListByMainId(id);
}
}

View File

@ -9,8 +9,6 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<result property="detailId" column="detail_id"/>
<result property="recordDate" column="record_date"/>
<result property="remark" column="remark"/>
<result property="startDate" column="start_date"/>
<result property="endDate" column="end_date"/>
<result property="ossId" column="oss_id"/>
<result property="createBy" column="create_by"/>
<result property="createTime" column="create_time"/>
@ -19,5 +17,17 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<result property="delFlag" column="del_flag"/>
</resultMap>
<select id="selectListByMainId" resultType="com.ruoyi.mts.domain.vo.MesPlanRecordVo">
SELECT pr.id,
pr.detail_id,
pr.record_date,
pr.remark,
pr.oss_id,
pr.flag,
pr.gantt_color
FROM mes_plan_record pr
LEFT JOIN mes_plan_detail pd ON pr.detail_id = pd.id
WHERE pd.main_id = #{id}
ORDER BY pr.record_date ASC
</select>
</mapper>