|
@@ -1,16 +1,39 @@
|
|
|
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.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.ruoyi.common.exception.ServiceException;
|
|
|
+import com.ruoyi.common.utils.SecurityUtils;
|
|
|
import com.ruoyi.common.utils.wrapper.IWrapper;
|
|
|
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.BomOperatingLog;
|
|
|
+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.BomOperatingLogService;
|
|
|
import com.sd.business.service.bom.BomService;
|
|
|
+import com.sd.business.service.bom.BomSpecService;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
+
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+import java.util.Objects;
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
|
/**
|
|
@@ -24,11 +47,48 @@ import org.springframework.stereotype.Service;
|
|
|
@Service
|
|
|
public class BomServiceImpl extends ServiceImpl<BomMapper, Bom> implements BomService {
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private BomSpecService bomSpecService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private FileInfoService fileInfoService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private BomOperatingLogService bomOperatingLogService;
|
|
|
+
|
|
|
@Override
|
|
|
public Page<BomVo> getPage(BomSelectDto dto) {
|
|
|
IWrapper<Bom> wrapper = getWrapper();
|
|
|
wrapper.orderByDesc("b", Bom::getId);
|
|
|
+ wrapper.like("b", Bom::getName, dto.getName());
|
|
|
+ wrapper.like("b", Bom::getCode, dto.getCode());
|
|
|
+ wrapper.eq("b", Bom::getSpecies, dto.getSpecies());
|
|
|
+ wrapper.eq("b", Bom::getChromatophore, dto.getChromatophore());
|
|
|
+ wrapper.eq("b", Bom::getEmbossingProcess, dto.getEmbossingProcess());
|
|
|
+ wrapper.eq("b", Bom::getFrontGrain, dto.getFrontGrain());
|
|
|
+ wrapper.eq("b", Bom::getReverseGrain, dto.getReverseGrain());
|
|
|
+ if (StrUtil.isNotBlank(dto.getColour())) {
|
|
|
+ List<Long> bomIdList = bomSpecService.listObject(BomSpec::getBomId, i -> i.like(BomSpec::getColour, dto.getColour()));
|
|
|
+ if (bomIdList.size() == 0) {
|
|
|
+ return new Page<>();
|
|
|
+ }
|
|
|
+ wrapper.eq("b", Bom::getId, bomIdList);
|
|
|
+ }
|
|
|
+
|
|
|
Page<BomVo> page = this.baseMapper.getPage(dto.getPage(), wrapper);
|
|
|
+ List<BomVo> records = page.getRecords();
|
|
|
+ if (records.size() == 0) {
|
|
|
+ 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));
|
|
|
+
|
|
|
+ for (BomVo record : records) {
|
|
|
+ record.setBomSpecList(bomSpecIdMap.get(record.getId()));
|
|
|
+ }
|
|
|
+
|
|
|
return page;
|
|
|
}
|
|
|
|
|
@@ -36,22 +96,160 @@ public class BomServiceImpl extends ServiceImpl<BomMapper, Bom> implements BomSe
|
|
|
public BomVo detail(Long id) {
|
|
|
Bom Bom = this.getById(id);
|
|
|
BomVo result = BeanUtil.toBean(Bom, BomVo.class);
|
|
|
+
|
|
|
+ List<BomSpec> list = bomSpecService.list(q -> q.eq(BomSpec::getBomId, id));
|
|
|
+ result.setBomSpecList(list);
|
|
|
+
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
@Override
|
|
|
public void add(BomDto bomDto) {
|
|
|
- this.save(bomDto);
|
|
|
+ List<FileInfo> fileInfoList = new ArrayList<>();
|
|
|
+
|
|
|
+ bomDto.setId(IdWorker.getId());
|
|
|
+
|
|
|
+ ObsFile mainImgFile = bomDto.getMainImgFile();
|
|
|
+ if (mainImgFile == null) {
|
|
|
+ bomDto.setMainImgUrl("");
|
|
|
+ } else {
|
|
|
+ FileInfo fileInfo = new FileInfo();
|
|
|
+ fileInfo.setId(mainImgFile.getId());
|
|
|
+ fileInfo.setBusinessId(bomDto.getId());
|
|
|
+ fileInfo.setBusinessType(ObsFileUtil.defaultFileType);
|
|
|
+ fileInfoList.add(fileInfo);
|
|
|
+
|
|
|
+ bomDto.setMainImgUrl(mainImgFile.getFileName());
|
|
|
+ }
|
|
|
+
|
|
|
+ List<BomSpecDto> bomSpecDtoList = bomDto.getBomSpecDtoList();
|
|
|
+ List<BomSpec> bomSpecList = bomSpecDtoList.stream()
|
|
|
+ .peek(item -> {
|
|
|
+ item.setId(IdWorker.getId());
|
|
|
+ item.setBomId(bomDto.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.getFileName());
|
|
|
+ }
|
|
|
+ })
|
|
|
+ .map(item -> BeanUtil.toBean(item, BomSpec.class))
|
|
|
+ .collect(Collectors.toList());
|
|
|
+
|
|
|
+ save(bomDto);
|
|
|
+ bomSpecService.saveBatch(bomSpecList);
|
|
|
+ if (fileInfoList.size() > 0) {
|
|
|
+ fileInfoService.updateBatchById(fileInfoList);
|
|
|
+ }
|
|
|
+
|
|
|
+ BomOperatingLog bomOperatingLog = new BomOperatingLog();
|
|
|
+ bomOperatingLog.setBomId(bomDto.getId());
|
|
|
+ bomOperatingLog.setOperator(SecurityUtils.getLoginUser().getUser().getNickName());
|
|
|
+ bomOperatingLog.setCode(bomDto.getCode());
|
|
|
+ bomOperatingLog.setType(1);
|
|
|
+ bomOperatingLogService.save(bomOperatingLog);
|
|
|
}
|
|
|
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
@Override
|
|
|
public void edit(BomDto bomDto) {
|
|
|
+ List<FileInfo> fileInfoList = new ArrayList<>();
|
|
|
+
|
|
|
+ ObsFile mainImgFile = bomDto.getMainImgFile();
|
|
|
+ if (mainImgFile == null) {
|
|
|
+ bomDto.setMainImgUrl("");
|
|
|
+ } else {
|
|
|
+ FileInfo fileInfo = new FileInfo();
|
|
|
+ fileInfo.setId(mainImgFile.getId());
|
|
|
+ fileInfo.setBusinessId(bomDto.getId());
|
|
|
+ fileInfo.setBusinessType(ObsFileUtil.defaultFileType);
|
|
|
+ fileInfoList.add(fileInfo);
|
|
|
+
|
|
|
+ bomDto.setMainImgUrl(mainImgFile.getFileName());
|
|
|
+ }
|
|
|
+
|
|
|
+ List<BomSpecDto> bomSpecDtoList = bomDto.getBomSpecDtoList();
|
|
|
+ List<BomSpec> bomSpecList = bomSpecDtoList.stream()
|
|
|
+ .peek(item -> {
|
|
|
+ item.setId(ObjectUtil.defaultIfNull(item.getId(), IdWorker.getId()));
|
|
|
+ item.setBomId(bomDto.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.getFileName());
|
|
|
+ }
|
|
|
+ })
|
|
|
+ .map(item -> BeanUtil.toBean(item, BomSpec.class))
|
|
|
+ .collect(Collectors.toList());
|
|
|
+
|
|
|
+ // 修改bom
|
|
|
this.updateById(bomDto);
|
|
|
+
|
|
|
+ // 修改bom明细
|
|
|
+ List<Long> bomSpecIdList = bomSpecList.stream().map(BomSpec::getId)
|
|
|
+ .filter(Objects::nonNull).distinct().collect(Collectors.toList());
|
|
|
+ bomSpecService.remove(q -> q
|
|
|
+ .eq(BomSpec::getBomId, bomDto.getId())
|
|
|
+ .ne(ObjectUtil.isNotEmpty(bomSpecIdList), BaseIdPo::getId, bomSpecIdList));
|
|
|
+ bomSpecService.saveOrUpdateBatch(bomSpecList);
|
|
|
+
|
|
|
+ // 修改文件
|
|
|
+ List<Long> businessIdList = bomSpecList.stream().map(BaseIdPo::getId).collect(Collectors.toList());
|
|
|
+ businessIdList.add(bomDto.getId());
|
|
|
+ List<Long> fileInfoIdList = fileInfoList.stream().map(BaseIdPo::getId).collect(Collectors.toList());
|
|
|
+ fileInfoService.remove(q -> q
|
|
|
+ .in(FileInfo::getBusinessId, businessIdList)
|
|
|
+ .ne(ObjectUtil.isNotEmpty(fileInfoIdList), BaseIdPo::getId, fileInfoIdList));
|
|
|
+ if (fileInfoList.size() > 0) {
|
|
|
+ fileInfoService.updateBatchById(fileInfoList);
|
|
|
+ }
|
|
|
+
|
|
|
+ BomOperatingLog bomOperatingLog = new BomOperatingLog();
|
|
|
+ bomOperatingLog.setBomId(bomDto.getId());
|
|
|
+ bomOperatingLog.setOperator(SecurityUtils.getLoginUser().getUser().getNickName());
|
|
|
+ bomOperatingLog.setCode(bomDto.getCode());
|
|
|
+ bomOperatingLog.setType(2);
|
|
|
+ bomOperatingLogService.save(bomOperatingLog);
|
|
|
}
|
|
|
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
@Override
|
|
|
public void delete(Long id) {
|
|
|
- this.removeById(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));
|
|
|
+
|
|
|
+ BomOperatingLog bomOperatingLog = new BomOperatingLog();
|
|
|
+ bomOperatingLog.setBomId(bom.getId());
|
|
|
+ bomOperatingLog.setOperator(SecurityUtils.getLoginUser().getUser().getNickName());
|
|
|
+ bomOperatingLog.setCode(bom.getCode());
|
|
|
+ bomOperatingLog.setType(3);
|
|
|
+ bomOperatingLogService.save(bomOperatingLog);
|
|
|
}
|
|
|
|
|
|
}
|