|
@@ -0,0 +1,253 @@
|
|
|
+package com.sd.business.service.bom.impl;
|
|
|
+
|
|
|
+import cn.hutool.core.bean.BeanUtil;
|
|
|
+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.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.sd.business.entity.bom.dto.BomDto;
|
|
|
+import com.sd.business.entity.bom.dto.BomSelectDto;
|
|
|
+import com.sd.business.entity.bom.dto.BomSpecDto;
|
|
|
+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.BomClassifyService;
|
|
|
+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>
|
|
|
+ * bom 服务实现类
|
|
|
+ * </p>
|
|
|
+ *
|
|
|
+ * @author
|
|
|
+ * @since 2023-12-04
|
|
|
+ */
|
|
|
+@Service
|
|
|
+public class BomServiceImpl extends ServiceImpl<BomMapper, Bom> implements BomService {
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private BomClassifyService bomClassifyService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private BomSpecService bomSpecService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private FileInfoService fileInfoService;
|
|
|
+
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Page<BomVo> getPage(BomSelectDto dto) {
|
|
|
+
|
|
|
+ List<Long> queryBomIdList = null;
|
|
|
+ List<Long> queryBomClassifyIdList = new ArrayList<>();
|
|
|
+ if (!StrUtil.isAllBlank(dto.getColour(), dto.getBomSpecCode(), dto.getBomSpecName())) {
|
|
|
+ queryBomIdList = bomSpecService.listObject(BomSpec::getBomId, i -> i
|
|
|
+ .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()));
|
|
|
+ if (queryBomIdList.isEmpty()) {
|
|
|
+ return new Page<>();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (ObjectUtil.isNotNull(dto.getBomClassifyId())) {
|
|
|
+ queryBomClassifyIdList.addAll(bomClassifyService.getChildrenIdList(dto.getBomClassifyId()));
|
|
|
+ }
|
|
|
+ if (ObjectUtil.isNotNull(dto.getBomClassifyIdList())) {
|
|
|
+ queryBomClassifyIdList.addAll(bomClassifyService.getChildrenIdList(dto.getBomClassifyIdList()));
|
|
|
+ }
|
|
|
+
|
|
|
+ Page<BomVo> page = Sql.create(BomVo.class)
|
|
|
+ .selectAll(Bom.class)
|
|
|
+ .from(Bom.class)
|
|
|
+ .orderByDesc(Bom::getId)
|
|
|
+ .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::getId, queryBomIdList)
|
|
|
+ .in(Bom::getBomClassifyId, queryBomClassifyIdList)
|
|
|
+ .page(dto);
|
|
|
+ List<BomVo> records = page.getRecords();
|
|
|
+ if (records.isEmpty()) {
|
|
|
+ return page;
|
|
|
+ }
|
|
|
+
|
|
|
+ List<Long> bomIdList = records.stream().map(BaseIdPo::getId).collect(Collectors.toList());
|
|
|
+ Map<Long, List<BomSpec>> bomSpecIdMap = bomSpecService.mapKGroup(BomSpec::getBomId, q -> q
|
|
|
+ .in(BomSpec::getBomId, bomIdList)
|
|
|
+ .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;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public BomVo detail(Long id) {
|
|
|
+
|
|
|
+ BomVo vo = Sql.create(BomVo.class)
|
|
|
+ .selectAll(Bom.class)
|
|
|
+ .from(Bom.class)
|
|
|
+ .eq(Bom::getId, id)
|
|
|
+ .one();
|
|
|
+
|
|
|
+ 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<>();
|
|
|
+
|
|
|
+ dto.setId(IdWorker.getId());
|
|
|
+
|
|
|
+ ObsFile mainImgFile = dto.getMainImgFile();
|
|
|
+ if (mainImgFile == null) {
|
|
|
+ dto.setMainImgUrl("");
|
|
|
+ } else {
|
|
|
+ FileInfo fileInfo = new FileInfo();
|
|
|
+ fileInfo.setId(mainImgFile.getId());
|
|
|
+ fileInfo.setBusinessId(dto.getId());
|
|
|
+ fileInfo.setBusinessType(ObsFileUtil.defaultFileType);
|
|
|
+ fileInfoList.add(fileInfo);
|
|
|
+ dto.setMainImgUrl(mainImgFile.getFileUrl());
|
|
|
+ }
|
|
|
+
|
|
|
+ List<BomSpecDto> bomSpecDtoList = dto.getBomSpecList();
|
|
|
+ List<BomSpec> bomSpecList = bomSpecDtoList.stream()
|
|
|
+ .peek(item -> {
|
|
|
+ item.setId(ObjectUtil.defaultIfNull(item.getId(), IdWorker.getId()));
|
|
|
+ item.setBomId(dto.getId());
|
|
|
+
|
|
|
+ ObsFile imgFile = item.getImgFile();
|
|
|
+ if (imgFile == null) {
|
|
|
+ item.setMainImgUrl("");
|
|
|
+ } else {
|
|
|
+ FileInfo fileInfo = new FileInfo();
|
|
|
+ fileInfo.setId(imgFile.getId());
|
|
|
+ fileInfo.setBusinessId(item.getId());
|
|
|
+ fileInfo.setBusinessType(ObsFileUtil.defaultFileType);
|
|
|
+ fileInfoList.add(fileInfo);
|
|
|
+ item.setMainImgUrl(imgFile.getFileUrl());
|
|
|
+ }
|
|
|
+ })
|
|
|
+ .map(item -> BeanUtil.toBean(item, BomSpec.class))
|
|
|
+ .collect(Collectors.toList());
|
|
|
+
|
|
|
+ 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();
|
|
|
+ if (mainImgFile == null) {
|
|
|
+ dto.setMainImgUrl("");
|
|
|
+ } else {
|
|
|
+ FileInfo fileInfo = new FileInfo();
|
|
|
+ fileInfo.setId(mainImgFile.getId());
|
|
|
+ fileInfo.setBusinessId(dto.getId());
|
|
|
+ fileInfo.setBusinessType(ObsFileUtil.defaultFileType);
|
|
|
+ fileInfoList.add(fileInfo);
|
|
|
+ dto.setMainImgUrl(mainImgFile.getFileUrl());
|
|
|
+ }
|
|
|
+
|
|
|
+ List<BomSpecDto> bomSpecDtoList = dto.getBomSpecList();
|
|
|
+ List<BomSpec> bomSpecList = bomSpecDtoList.stream()
|
|
|
+ .peek(item -> {
|
|
|
+ item.setId(ObjectUtil.defaultIfNull(item.getId(), IdWorker.getId()));
|
|
|
+ item.setBomId(dto.getId());
|
|
|
+
|
|
|
+ ObsFile imgFile = item.getImgFile();
|
|
|
+ if (imgFile == null) {
|
|
|
+ item.setMainImgUrl("");
|
|
|
+ } else {
|
|
|
+ FileInfo fileInfo = new FileInfo();
|
|
|
+ fileInfo.setId(imgFile.getId());
|
|
|
+ fileInfo.setBusinessId(item.getId());
|
|
|
+ fileInfo.setBusinessType(ObsFileUtil.defaultFileType);
|
|
|
+ fileInfoList.add(fileInfo);
|
|
|
+ item.setMainImgUrl(imgFile.getFileUrl());
|
|
|
+ }
|
|
|
+ })
|
|
|
+ .map(item -> BeanUtil.toBean(item, BomSpec.class))
|
|
|
+ .collect(Collectors.toList());
|
|
|
+
|
|
|
+ // 修改bom
|
|
|
+ this.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) {
|
|
|
+ removeById(id);
|
|
|
+
|
|
|
+ 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));
|
|
|
+ }
|
|
|
+
|
|
|
+}
|