优化任务查询列表

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 ganttColor;
private String flag;
private Date createTime; private Date createTime;

View File

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

View File

@ -1,10 +1,9 @@
package com.ruoyi.mts.service; 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.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.Collection;
import java.util.List; import java.util.List;
@ -48,4 +47,12 @@ public interface IMesPlanRecordService {
* 校验并批量删除生产计划明细日期记录信息 * 校验并批量删除生产计划明细日期记录信息
*/ */
Boolean deleteWithValidByIds(Collection<Long> ids, Boolean isValid); 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 org.springframework.stereotype.Service;
import java.util.*; import java.util.*;
import java.util.stream.Collectors;
/** /**
* 生产计划明细Service业务层处理 * 生产计划明细Service业务层处理
@ -49,38 +50,45 @@ public class MesPlanDetailServiceImpl implements IMesPlanDetailService {
*/ */
@Override @Override
public List<MesPlanDetailVo> queryList(MesPlanDetailBo bo) { public List<MesPlanDetailVo> queryList(MesPlanDetailBo bo) {
// 查询所有父任务
bo.setParentId(0L); bo.setParentId(0L);
LambdaQueryWrapper<MesPlanDetail> parentQuery = buildQueryWrapper(bo); LambdaQueryWrapper<MesPlanDetail> parentQuery = buildQueryWrapper(bo);
List<MesPlanDetailVo> parentList = baseMapper.selectVoList(parentQuery); List<MesPlanDetailVo> parentList = baseMapper.selectVoList(parentQuery);
// 数据处理
//LambdaQueryWrapper<MesPlanDetail> childrenQuery = Wrappers.lambdaQuery(MesPlanDetail.class).ne(TreeEntity::getParentId, 0).orderByAsc(MesPlanDetail::getId); if (CollUtil.isEmpty(parentList)) {
//List<MesPlanDetailVo> childrenList = baseMapper.selectVoList(childrenQuery); return new ArrayList<>(0);
}
//Map<Long, List<MesPlanDetailVo>> childrenCollect = childrenList.stream().collect(Collectors.groupingBy(MesPlanDetailVo::getParentId, Collectors.toList())); 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<>(); LinkedList<MesPlanDetailVo> res = new LinkedList<>();
for (int i = 0; i < parentList.size(); i++) { for (int i = 0; i < parentList.size(); i++) {
MesPlanDetailVo vo = parentList.get(i); MesPlanDetailVo vo = parentList.get(i);
res.add(vo); res.add(vo);
LambdaQueryWrapper<MesPlanDetail> voLqw = Wrappers.lambdaQuery(MesPlanDetail.class).eq(TreeEntity::getParentId, vo.getId()).orderByAsc(MesPlanDetail::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 = baseMapper.selectVoList(voLqw);
//List<MesPlanDetailVo> children = childrenCollect.get(vo.getId()); List<MesPlanDetailVo> children = childrenCollect.get(vo.getId());
if (CollUtil.isNotEmpty(children)) { if (CollUtil.isNotEmpty(children)) {
res.addAll(i + 1, children); res.addAll(i + 1, children);
} }
} }
// 任务添加记录信息
int size = res.size(); int size = res.size();
List<MesPlanDetailVo> data = new ArrayList<>(size << 2); List<MesPlanDetailVo> data = new ArrayList<>(size << 2);
for (int i = 0; i < size; i++) { for (int i = 0; i < size; i++) {
// 默认第一个为计划数据 // 默认第一个为计划数据
MesPlanDetailVo planVo = res.get(i); MesPlanDetailVo planVo = res.get(i);
Long id = planVo.getId(); 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"); planVo.setFlag("plan");
MesPlanRecordBo record = new MesPlanRecordBo(); planVo.setRecord(collect.get("plan"));
record.setDetailId(id);
record.setFlag("plan");
List<MesPlanRecordVo> mesPlanRecordVos = recordService.queryList(record);
planVo.setRecord(mesPlanRecordVos);
data.add(planVo); data.add(planVo);
// 处理实际数据 // 处理实际数据
MesPlanDetailVo actualVo = new MesPlanDetailVo(); MesPlanDetailVo actualVo = new MesPlanDetailVo();
@ -89,9 +97,7 @@ public class MesPlanDetailServiceImpl implements IMesPlanDetailService {
actualVo.setParentId(planVo.getParentId()); actualVo.setParentId(planVo.getParentId());
actualVo.setMainId(planVo.getMainId()); actualVo.setMainId(planVo.getMainId());
actualVo.setFlag("actual"); actualVo.setFlag("actual");
record.setFlag("actual"); actualVo.setRecord(collect.get("actual"));
mesPlanRecordVos = recordService.queryList(record);
actualVo.setRecord(mesPlanRecordVos);
data.add(actualVo); data.add(actualVo);
} }
return data; return data;

View File

@ -129,4 +129,15 @@ public class MesPlanRecordServiceImpl implements IMesPlanRecordService {
} }
return baseMapper.deleteBatchIds(ids) > 0; 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="detailId" column="detail_id"/>
<result property="recordDate" column="record_date"/> <result property="recordDate" column="record_date"/>
<result property="remark" column="remark"/> <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="ossId" column="oss_id"/>
<result property="createBy" column="create_by"/> <result property="createBy" column="create_by"/>
<result property="createTime" column="create_time"/> <result property="createTime" column="create_time"/>
@ -19,5 +17,17 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<result property="delFlag" column="del_flag"/> <result property="delFlag" column="del_flag"/>
</resultMap> </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> </mapper>