|
@@ -1,17 +1,37 @@
|
|
|
package com.sd.business.service.bom.impl;
|
|
|
|
|
|
+import cn.hutool.core.util.ObjectUtil;
|
|
|
+import cn.hutool.core.util.StrUtil;
|
|
|
+import com.baomidou.dynamic.datasource.annotation.DSTransactional;
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.IdWorker;
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.StringPool;
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
+import com.fjhx.file.entity.FileInfo;
|
|
|
+import com.fjhx.file.entity.ObsFile;
|
|
|
+import com.fjhx.file.service.FileInfoService;
|
|
|
+import com.fjhx.file.utils.ObsFileUtil;
|
|
|
+import com.ruoyi.common.core.domain.BaseIdPo;
|
|
|
+import com.ruoyi.common.exception.ServiceException;
|
|
|
import com.sd.business.entity.bom.dto.BomDto;
|
|
|
import com.sd.business.entity.bom.dto.BomSelectDto;
|
|
|
import com.sd.business.entity.bom.po.Bom;
|
|
|
+import com.sd.business.entity.bom.po.BomSpec;
|
|
|
import com.sd.business.entity.bom.vo.BomVo;
|
|
|
import com.sd.business.mapper.bom.BomMapper;
|
|
|
import com.sd.business.service.bom.BomService;
|
|
|
+import com.sd.business.service.bom.BomSpecService;
|
|
|
import com.sd.framework.util.Assert;
|
|
|
import com.sd.framework.util.sql.Sql;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+import java.util.Objects;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
|
|
|
/**
|
|
|
* <p>
|
|
@@ -24,15 +44,58 @@ import org.springframework.stereotype.Service;
|
|
|
@Service
|
|
|
public class BomServiceImpl extends ServiceImpl<BomMapper, Bom> implements BomService {
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private BomSpecService bomSpecService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private FileInfoService fileInfoService;
|
|
|
+
|
|
|
@Override
|
|
|
public Page<BomVo> getPage(BomSelectDto dto) {
|
|
|
|
|
|
+ List<Long> bomIdList = null;
|
|
|
+
|
|
|
+ if (!StrUtil.isAllBlank(dto.getBomSpecCode(), dto.getBomSpecName(), dto.getColour())) {
|
|
|
+ bomIdList = bomSpecService.listObject(BomSpec::getBomId, i -> i
|
|
|
+ .like(StrUtil.isNotBlank(dto.getBomSpecCode()), BomSpec::getCode, dto.getBomSpecCode())
|
|
|
+ .like(StrUtil.isNotBlank(dto.getBomSpecName()), BomSpec::getName, dto.getBomSpecName())
|
|
|
+ .like(StrUtil.isNotBlank(dto.getColour()), BomSpec::getColour, dto.getColour()));
|
|
|
+ if (bomIdList.isEmpty()) {
|
|
|
+ return new Page<>();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
Page<BomVo> page = Sql.create(BomVo.class)
|
|
|
.selectAll(Bom.class)
|
|
|
.from(Bom.class)
|
|
|
+
|
|
|
+ .in(Bom::getId, bomIdList)
|
|
|
+ .like(Bom::getName, dto.getName())
|
|
|
+ .like(Bom::getCode, dto.getCode())
|
|
|
+ .eq(Bom::getSpecies, dto.getSpecies())
|
|
|
+ .eq(Bom::getChromatophore, dto.getChromatophore())
|
|
|
+ .eq(Bom::getEmbossingProcess, dto.getEmbossingProcess())
|
|
|
+ .eq(Bom::getFrontGrain, dto.getFrontGrain())
|
|
|
+ .eq(Bom::getReverseGrain, dto.getReverseGrain())
|
|
|
+ .in(Bom::getBomClassifyId, dto.getBomClassifyIdList())
|
|
|
.orderByDesc(Bom::getId)
|
|
|
.page(dto.getPage());
|
|
|
|
|
|
+ List<BomVo> records = page.getRecords();
|
|
|
+ if (records.isEmpty()) {
|
|
|
+ return page;
|
|
|
+ }
|
|
|
+
|
|
|
+ Map<Long, List<BomSpec>> bomSpecIdMap = bomSpecService.mapKGroup(BomSpec::getBomId, q -> q
|
|
|
+ .in(BomSpec::getBomId, records.stream().map(BaseIdPo::getId).collect(Collectors.toList()))
|
|
|
+ .like(StrUtil.isNotBlank(dto.getColour()), BomSpec::getColour, dto.getColour())
|
|
|
+ .like(StrUtil.isNotBlank(dto.getBomSpecCode()), BomSpec::getCode, dto.getBomSpecCode())
|
|
|
+ .like(StrUtil.isNotBlank(dto.getBomSpecName()), BomSpec::getName, dto.getBomSpecName()));
|
|
|
+
|
|
|
+ for (BomVo record : records) {
|
|
|
+ record.setBomSpecList(bomSpecIdMap.get(record.getId()));
|
|
|
+ }
|
|
|
+
|
|
|
return page;
|
|
|
}
|
|
|
|
|
@@ -45,24 +108,114 @@ public class BomServiceImpl extends ServiceImpl<BomMapper, Bom> implements BomSe
|
|
|
.eq(Bom::getId, id)
|
|
|
.one();
|
|
|
|
|
|
- Assert.notNull(vo, "未知数据");
|
|
|
+ Assert.notNull(vo, "未知bom");
|
|
|
+
|
|
|
+ List<BomSpec> list = bomSpecService.list(q -> q.eq(BomSpec::getBomId, id));
|
|
|
+ vo.setBomSpecList(list);
|
|
|
|
|
|
return vo;
|
|
|
}
|
|
|
|
|
|
+ @DSTransactional
|
|
|
@Override
|
|
|
public void add(BomDto dto) {
|
|
|
+ List<FileInfo> fileInfoList = new ArrayList<>();
|
|
|
+ ObsFile mainImgFile = dto.getMainImgFile();
|
|
|
+
|
|
|
+ dto.setId(IdWorker.getId());
|
|
|
+ dto.setMainImgUrl(mainImgFile == null ? StringPool.EMPTY : mainImgFile.getFileUrl());
|
|
|
+
|
|
|
+ // 绑定主图
|
|
|
+ addFile(dto.getId(), mainImgFile, fileInfoList);
|
|
|
+
|
|
|
+ // 获取bom规格
|
|
|
+ List<BomSpec> bomSpecList = getBomSpecList(dto, fileInfoList);
|
|
|
+
|
|
|
save(dto);
|
|
|
+ bomSpecService.saveBatch(bomSpecList);
|
|
|
+ if (!fileInfoList.isEmpty()) {
|
|
|
+ fileInfoService.updateBatchById(fileInfoList);
|
|
|
+ }
|
|
|
+
|
|
|
}
|
|
|
|
|
|
+ @DSTransactional
|
|
|
@Override
|
|
|
public void edit(BomDto dto) {
|
|
|
+ List<FileInfo> fileInfoList = new ArrayList<>();
|
|
|
+ ObsFile mainImgFile = dto.getMainImgFile();
|
|
|
+
|
|
|
+ dto.setMainImgUrl(mainImgFile == null ? StringPool.EMPTY : mainImgFile.getFileUrl());
|
|
|
+
|
|
|
+ // 绑定主图
|
|
|
+ addFile(dto.getId(), mainImgFile, fileInfoList);
|
|
|
+
|
|
|
+ // 获取bom规格
|
|
|
+ List<BomSpec> bomSpecList = getBomSpecList(dto, fileInfoList);
|
|
|
+
|
|
|
+ // 修改bom
|
|
|
updateById(dto);
|
|
|
+
|
|
|
+ // 修改bom明细
|
|
|
+ List<Long> bomSpecIdList = bomSpecList.stream().map(BomSpec::getId).filter(Objects::nonNull)
|
|
|
+ .distinct().collect(Collectors.toList());
|
|
|
+ bomSpecService.remove(q -> q.eq(BomSpec::getBomId, dto.getId())
|
|
|
+ .notIn(ObjectUtil.isNotEmpty(bomSpecIdList), BaseIdPo::getId, bomSpecIdList));
|
|
|
+ bomSpecService.saveOrUpdateBatch(bomSpecList);
|
|
|
+
|
|
|
+ // 修改文件
|
|
|
+ List<Long> businessIdList = bomSpecList.stream().map(BaseIdPo::getId).collect(Collectors.toList());
|
|
|
+ businessIdList.add(dto.getId());
|
|
|
+ List<Long> fileInfoIdList = fileInfoList.stream().map(BaseIdPo::getId).collect(Collectors.toList());
|
|
|
+ fileInfoService.remove(q -> q.in(FileInfo::getBusinessId, businessIdList)
|
|
|
+ .notIn(ObjectUtil.isNotEmpty(fileInfoIdList), BaseIdPo::getId, fileInfoIdList));
|
|
|
+ if (!fileInfoList.isEmpty()) {
|
|
|
+ fileInfoService.updateBatchById(fileInfoList);
|
|
|
+ }
|
|
|
+
|
|
|
}
|
|
|
|
|
|
+ @DSTransactional
|
|
|
@Override
|
|
|
public void delete(Long id) {
|
|
|
+ Bom bom = getById(id);
|
|
|
+ if (bom == null) {
|
|
|
+ throw new ServiceException("没有找到bom信息");
|
|
|
+ }
|
|
|
+
|
|
|
+ List<Long> businessIdList = bomSpecService.listObject(BaseIdPo::getId, q -> q.eq(BomSpec::getBomId, id));
|
|
|
+ businessIdList.add(id);
|
|
|
+ fileInfoService.remove(q -> q.in(FileInfo::getBusinessId, businessIdList));
|
|
|
+
|
|
|
removeById(id);
|
|
|
+ bomSpecService.remove(q -> q.eq(BomSpec::getBomId, id));
|
|
|
+ }
|
|
|
+
|
|
|
+ private void addFile(Long businessId, ObsFile obsFile, List<FileInfo> fileList) {
|
|
|
+ if (obsFile != null) {
|
|
|
+ FileInfo fileInfo = new FileInfo();
|
|
|
+ fileInfo.setId(obsFile.getId());
|
|
|
+ fileInfo.setBusinessId(businessId);
|
|
|
+ fileInfo.setBusinessType(ObsFileUtil.defaultFileType);
|
|
|
+ fileList.add(fileInfo);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private List<BomSpec> getBomSpecList(BomDto dto, List<FileInfo> fileInfoList) {
|
|
|
+ return dto.getBomSpecList().stream()
|
|
|
+ .peek(item -> {
|
|
|
+ ObsFile imgFile = item.getImgFile();
|
|
|
+
|
|
|
+ item.setId(IdWorker.getId());
|
|
|
+ item.setBomId(dto.getId());
|
|
|
+
|
|
|
+ // 绑定规格图片
|
|
|
+ item.setMainImgUrl(imgFile == null ? StringPool.EMPTY : imgFile.getFileUrl());
|
|
|
+
|
|
|
+ addFile(item.getId(), imgFile, fileInfoList);
|
|
|
+ })
|
|
|
+ .map(item -> (BomSpec) item)
|
|
|
+ .collect(Collectors.toList());
|
|
|
}
|
|
|
|
|
|
}
|