|
@@ -0,0 +1,144 @@
|
|
|
+package com.sd.business.service.craft.impl;
|
|
|
+
|
|
|
+import cn.hutool.core.bean.BeanUtil;
|
|
|
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
+import com.ruoyi.common.core.domain.BaseIdPo;
|
|
|
+import com.ruoyi.common.utils.wrapper.IWrapper;
|
|
|
+import com.sd.business.entity.craft.dto.CraftProductionLineDto;
|
|
|
+import com.sd.business.entity.craft.dto.CraftProductionLineSelectDto;
|
|
|
+import com.sd.business.entity.craft.po.CraftProductionLine;
|
|
|
+import com.sd.business.entity.craft.po.CraftProductionLineProcess;
|
|
|
+import com.sd.business.entity.craft.vo.CraftProductionLineProcessVo;
|
|
|
+import com.sd.business.entity.craft.vo.CraftProductionLineVo;
|
|
|
+import com.sd.business.mapper.craft.CraftProductionLineMapper;
|
|
|
+import com.sd.business.service.craft.CraftProcessService;
|
|
|
+import com.sd.business.service.craft.CraftProductionLineProcessService;
|
|
|
+import com.sd.business.service.craft.CraftProductionLineService;
|
|
|
+import com.sd.framework.util.Assert;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
+
|
|
|
+import java.util.Collections;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
+
|
|
|
+/**
|
|
|
+ * <p>
|
|
|
+ * 工艺_产线 服务实现类
|
|
|
+ * </p>
|
|
|
+ *
|
|
|
+ * @author
|
|
|
+ * @since 2023-07-26
|
|
|
+ */
|
|
|
+@Service
|
|
|
+public class CraftProductionLineServiceImpl extends ServiceImpl<CraftProductionLineMapper, CraftProductionLine> implements CraftProductionLineService {
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private CraftProductionLineProcessService craftProductionLineProcessService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private CraftProcessService craftProcessService;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Page<CraftProductionLineVo> getPage(CraftProductionLineSelectDto dto) {
|
|
|
+ IWrapper<CraftProductionLine> wrapper = getWrapper();
|
|
|
+ wrapper.orderByDesc("cpl", CraftProductionLine::getId);
|
|
|
+ wrapper.like("cpl", CraftProductionLine::getCode, dto.getCode());
|
|
|
+ wrapper.like("cpl", CraftProductionLine::getName, dto.getName());
|
|
|
+ Page<CraftProductionLineVo> page = this.baseMapper.getPage(dto.getPage(), wrapper);
|
|
|
+ List<CraftProductionLineVo> records = page.getRecords();
|
|
|
+ if (records.size() == 0) {
|
|
|
+ return page;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 获取产线明细
|
|
|
+ List<Long> craftProductionLineIdList = records.stream().map(BaseIdPo::getId).collect(Collectors.toList());
|
|
|
+ List<CraftProductionLineProcess> tempCraftProductionLineProcessList = craftProductionLineProcessService.list(q -> q
|
|
|
+ .in(CraftProductionLineProcess::getCraftProductionLineId, craftProductionLineIdList)
|
|
|
+ .orderByAsc(CraftProductionLineProcess::getSort)
|
|
|
+ );
|
|
|
+ List<CraftProductionLineProcessVo> craftProductionLineProcessList =
|
|
|
+ BeanUtil.copyToList(tempCraftProductionLineProcessList, CraftProductionLineProcessVo.class);
|
|
|
+
|
|
|
+ // 赋值工序名称
|
|
|
+ craftProcessService.attributeAssign(
|
|
|
+ craftProductionLineProcessList,
|
|
|
+ CraftProductionLineProcess::getCraftProcessId,
|
|
|
+ (item, craftProcess) -> item.setCraftProcessName(craftProcess.getName()));
|
|
|
+
|
|
|
+ // 赋值产线明细
|
|
|
+ Map<Long, List<CraftProductionLineProcessVo>> craftProductionLineProcessMap = craftProductionLineProcessList
|
|
|
+ .stream().collect(Collectors.groupingBy(CraftProductionLineProcess::getCraftProductionLineId));
|
|
|
+ records.forEach(item -> item.setCraftProductionLineProcessList(
|
|
|
+ craftProductionLineProcessMap.getOrDefault(item.getId(), Collections.emptyList())));
|
|
|
+
|
|
|
+ return page;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public CraftProductionLineVo detail(Long id) {
|
|
|
+ CraftProductionLine craftProductionLine = this.getById(id);
|
|
|
+ Assert.notNull(craftProductionLine, "未知产线");
|
|
|
+ CraftProductionLineVo result = BeanUtil.toBean(craftProductionLine, CraftProductionLineVo.class);
|
|
|
+
|
|
|
+ // 获取产线明细
|
|
|
+ List<CraftProductionLineProcess> tempCraftProductionLineProcessList = craftProductionLineProcessService.list(q -> q
|
|
|
+ .eq(CraftProductionLineProcess::getCraftProductionLineId, id)
|
|
|
+ .orderByAsc(CraftProductionLineProcess::getSort)
|
|
|
+ );
|
|
|
+ List<CraftProductionLineProcessVo> craftProductionLineProcessList =
|
|
|
+ BeanUtil.copyToList(tempCraftProductionLineProcessList, CraftProductionLineProcessVo.class);
|
|
|
+
|
|
|
+ // 赋值工序名称
|
|
|
+ craftProcessService.attributeAssign(
|
|
|
+ craftProductionLineProcessList,
|
|
|
+ CraftProductionLineProcess::getCraftProcessId,
|
|
|
+ (item, craftProcess) -> item.setCraftProcessName(craftProcess.getName()));
|
|
|
+
|
|
|
+ // 赋值产线明细
|
|
|
+ result.setCraftProductionLineProcessList(craftProductionLineProcessList);
|
|
|
+
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ @Override
|
|
|
+ public void add(CraftProductionLineDto dto) {
|
|
|
+ this.save(dto);
|
|
|
+
|
|
|
+ List<CraftProductionLineProcess> craftProductionLineProcessList = dto.getCraftProductionLineProcessList();
|
|
|
+ for (int i = 0; i < craftProductionLineProcessList.size(); i++) {
|
|
|
+ CraftProductionLineProcess craftProductionLineProcess = craftProductionLineProcessList.get(i);
|
|
|
+ craftProductionLineProcess.setCraftProductionLineId(dto.getId());
|
|
|
+ craftProductionLineProcess.setSort(i + 1);
|
|
|
+ }
|
|
|
+ craftProductionLineProcessService.saveBatch(craftProductionLineProcessList);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ @Override
|
|
|
+ public void edit(CraftProductionLineDto dto) {
|
|
|
+ this.updateById(dto);
|
|
|
+
|
|
|
+ List<CraftProductionLineProcess> craftProductionLineProcessList = dto.getCraftProductionLineProcessList();
|
|
|
+ for (int i = 0; i < craftProductionLineProcessList.size(); i++) {
|
|
|
+ CraftProductionLineProcess craftProductionLineProcess = craftProductionLineProcessList.get(i);
|
|
|
+ craftProductionLineProcess.setCraftProductionLineId(dto.getId());
|
|
|
+ craftProductionLineProcess.setSort(i + 1);
|
|
|
+ }
|
|
|
+ craftProductionLineProcessService.editLinked(craftProductionLineProcessList,
|
|
|
+ CraftProductionLineProcess::getCraftProductionLineId, dto.getId());
|
|
|
+ }
|
|
|
+
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ @Override
|
|
|
+ public void delete(Long id) {
|
|
|
+ this.removeById(id);
|
|
|
+ craftProductionLineProcessService.remove(q -> q.eq(CraftProductionLineProcess::getCraftProductionLineId, id));
|
|
|
+ }
|
|
|
+
|
|
|
+}
|