From 3594a911312b92561b08c478ef0319cf1ae2b0d8 Mon Sep 17 00:00:00 2001
From: XiaoRuby <3114200645@qq.com>
Date: 星期一, 11 九月 2023 11:20:15 +0800
Subject: [PATCH] Merge remote-tracking branch 'origin/master'
---
standard-server/src/main/java/com/yuanchu/mom/service/impl/MaterialServiceImpl.java | 259 ++++++++++++++++++++++++++++++++++++++++++++++-----
1 files changed, 231 insertions(+), 28 deletions(-)
diff --git a/standard-server/src/main/java/com/yuanchu/mom/service/impl/MaterialServiceImpl.java b/standard-server/src/main/java/com/yuanchu/mom/service/impl/MaterialServiceImpl.java
index 722e4c3..35e9113 100644
--- a/standard-server/src/main/java/com/yuanchu/mom/service/impl/MaterialServiceImpl.java
+++ b/standard-server/src/main/java/com/yuanchu/mom/service/impl/MaterialServiceImpl.java
@@ -3,16 +3,19 @@
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
-import com.yuanchu.mom.pojo.Material;
-import com.yuanchu.mom.pojo.dto.MaterialTreeDto;
-import com.yuanchu.mom.service.MaterialService;
-import com.yuanchu.mom.mapper.MaterialMapper;
-import com.yuanchu.mom.utils.JackSonUtil;
+import com.yuanchu.mom.mapper.*;
+import com.yuanchu.mom.pojo.*;
+import com.yuanchu.mom.pojo.dto.MaterialDto;
+import com.yuanchu.mom.service.*;
+import com.yuanchu.mom.utils.MyUtil;
import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
+import java.util.ArrayList;
import java.util.List;
import java.util.Map;
+import java.util.stream.Collectors;
/**
* @author Administrator
@@ -20,43 +23,243 @@
* @createDate 2023-07-26 15:52:50
*/
@Service
-public class MaterialServiceImpl extends ServiceImpl<MaterialMapper, Material>
- implements MaterialService {
+public class MaterialServiceImpl extends ServiceImpl<MaterialMapper, Material> implements MaterialService {
@Resource
MaterialMapper materialMapper;
+ @Resource
+ StandardMapper standardMapper;
+
+ @Resource
+ SpecificationsMapper specificationsMapper;
+
+ @Resource
+ TechnologyService technologyService;
+
+ @Resource
+ TechnologyTemplateMapper technologyTemplateMapper;
+
+ @Resource
+ ProductService productService;
+
+ @Resource
+ TechnicalModelMapper technicalModelMapper;
+
+ @Resource
+ MbomService mbomService;
+
+ @Resource
+ MbomModelMapper mbomModelMapper;
+
+ @Resource
+ TechniqueService techniqueService;
+
+ @Resource
+ TechniqueModelMapper techniqueModelMapper;
+
+ @Resource
+ DeviceMapper deviceMapper;
+
+ @Resource
+ TechnologyMapper technologyMapper;
+
+ @Resource
+ ProductMapper productMapper;
+
+ @Resource
+ MbomMapper mbomMapper;
+
+ @Resource
+ TechniqueMapper techniqueMapper;
+
+ //鏍囧噯MOM-->宸︿晶浜旂骇鏍戝睍绀�
@Override
- public List<MaterialTreeDto> selectTreeByMaterial() {
- List<MaterialTreeDto> materialTreeDtos = materialMapper.selectTreeByMaterial();
- materialTreeDtos.forEach(System.out::println);
+ public List<Map<String, Object>> selectTreeByMaterial() {
return materialMapper.selectTreeByMaterial();
}
+ //(1,2绾�)鏂板-->鐗╂枡,鏍囧噯,鍨嬪彿
@Override
- public List<Map<String, Object>> selectMaterialIdAndNameAndCode() {
- LambdaQueryWrapper<Material> wrapper = new LambdaQueryWrapper<>();
- wrapper.select(Material::getId, Material::getName, Material::getCode);
- return materialMapper.selectMaps(wrapper);
+ @Transactional(rollbackFor = Exception.class)
+ public String addMaterial(MaterialDto materialDto) {
+ //鏍¢獙娣诲姞鐗╂枡鏄惁閲嶅
+ List<Material> materialList = materialMapper.selectList(Wrappers.<Material>query()
+ .eq("type", materialDto.getType())
+ .eq("father", materialDto.getFather()));
+ for (Material material : materialList) {
+ if (material.getName().equals(materialDto.getName())) {
+ return "璇ョ被鍨嬩骇鍝佸ぇ绫讳笅鏈夎浜у搧鍚嶇О";
+ }
+ }
+ /*鏂板鐗╂枡琛�*/
+ Material material = new Material();
+ material.setCode(MyUtil.getTimeSixNumberCode("ML", "ML"));
+ material.setName(materialDto.getName());
+ material.setType(materialDto.getType());
+ material.setFather(materialDto.getFather());
+ materialMapper.insert(material);
+ /*鏂板鏍囧噯琛�*/
+ Standard standard = new Standard();
+ standard.setName(materialDto.getStandard());
+ standard.setMaterial_id(material.getId());
+ standardMapper.insert(standard);
+ /*鏂板鍨嬪彿琛�*/
+ Specifications specifications = new Specifications();
+ specifications.setName(materialDto.getSpecifications());
+ specifications.setStandardId(standard.getId());
+ specificationsMapper.insert(specifications);
+ /*鏂板鏍囧噯BOM-->宸ヨ壓璺嚎(鎵归噺娣诲姞)*///0锛氭鑳惰繛鎺ュ櫒锛�1锛氶噾灞炶繛鎺ュ櫒锛�2锛氭箍鎻掓嫈鐢佃繛鎺ュ櫒锛�3锛氬垎鏀粍浠�
+ Integer type = null;
+ if (materialDto.getFather().equals("姗¤兌杩炴帴鍣�")){
+ type=0;
+ }else if (materialDto.getFather().equals("閲戝睘杩炴帴鍣�")){
+ type=1;
+ }else if(materialDto.getFather().equals("婀挎彃鎷旂數杩炴帴鍣�")){
+ type=2;
+ }else if(materialDto.getFather().equals("鍒嗘敮缁勪欢")){
+ type=3;
+ }else return "娣诲姞鐗╂枡銆�" + materialDto.getName() + "銆戞垚鍔�";
+ List<TechnologyTemplate> technologyTemplateList = technologyTemplateMapper.selectList(Wrappers.<TechnologyTemplate>query().eq("type", type));
+ List<Technology> technologyList = technologyTemplateList.stream().map(technologyTemplate -> {
+ Technology technology = new Technology();
+ technology.setSpecificationsId(specifications.getId());
+ technology.setFather(technologyTemplate.getFather());
+ technology.setName(technologyTemplate.getName());
+ technology.setDeviceGroup(technologyTemplate.getDeviceGroup());
+ return technology;
+ }).collect(Collectors.toList());
+ technologyService.saveBatch(technologyList);
+ /*鏂板鏍囧噯BOM-->鎶�鏈寚鏍�(鎵归噺娣诲姞)*/
+ //鏂板鐨勫伐鑹鸿矾绾縤d闆嗗悎
+ List<Integer> technologyIds = technologyList.stream().map(Technology::getId).collect(Collectors.toList());
+ //鍩虹鏁版嵁涓伐鑹鸿矾绾縤d闆嗗悎
+ List<Integer> techTemIds = technologyTemplateList.stream().map(TechnologyTemplate::getId).collect(Collectors.toList());
+ //涓よ�呴暱搴︿竴瀹氫竴鏍�
+ List<Product> productList = new ArrayList<>();
+ for (int i = 0; i < technologyIds.size(); i++) {
+ List<TechnicalModel> technicalModelList = technicalModelMapper.selectList(Wrappers.<TechnicalModel>query().eq("tech_tem_id", techTemIds.get(i)));
+ for (TechnicalModel technicalModel : technicalModelList) {
+ Product product = new Product();
+ product.setFather(technicalModel.getFather());
+ product.setName(technicalModel.getName());
+ product.setUnit(technicalModel.getUnit());
+ product.setTechnologyId(technologyIds.get(i));
+ productList.add(product);
+ }
+ }
+ productService.saveBatch(productList);
+ /*鏂板鏍囧噯BOM-->鐗╂枡娓呭崟(鎵归噺娣诲姞)*/
+ List<Mbom> mbomList = new ArrayList<>();
+ for (int i = 0; i < technologyIds.size(); i++) {
+ List<MbomModel> mbomModelList = mbomModelMapper.selectList(Wrappers.<MbomModel>query().eq("tech_tem_id", techTemIds.get(i)));
+ for (MbomModel mbomModel : mbomModelList) {
+ Mbom mbom = new Mbom();
+ mbom.setUnit(mbomModel.getUnit());
+ mbom.setName(mbomModel.getName());
+ mbom.setSupplier(mbomModel.getSupplier());
+ mbom.setQualityTraceability(mbomModel.getQualityTraceability());
+ mbom.setSpecifications(mbomModel.getSpecifications());
+ mbom.setTechnologyId(technologyIds.get(i));
+ mbomList.add(mbom);
+ }
+ }
+ mbomService.saveBatch(mbomList);
+ /*鏂板鏍囧噯BOM-->鐢熶骇宸ヨ壓(鎵归噺娣诲姞)*/
+ List<Technique> techniqueList = new ArrayList<>();
+ for (int i = 0; i < technologyIds.size(); i++) {
+ List<TechniqueModel> techniqueModelList = techniqueModelMapper.selectList(Wrappers.<TechniqueModel>query().eq("tech_tem_id", techTemIds.get(i)));
+ for (TechniqueModel techniqueModel : techniqueModelList) {
+ //鏌ヨ璁惧鍚嶇О
+ Device device = deviceMapper.selectById(techniqueModel.getDeviceId());
+ //鏌ヨ鍩虹鐢熶骇宸ヨ壓涓瘡涓澶囩殑鍏蜂綋椤圭洰
+ TechnicalModel technicalModel = technicalModelMapper.selectById(techniqueModel.getTechnicalModelId());
+ Technique technique = new Technique();
+ technique.setTechnologyId(technologyIds.get(i));
+ technique.setDevice(device.getName());
+ technique.setProductFather(technicalModel.getFather());
+ technique.setProduct(technicalModel.getName());
+ technique.setUnit(technicalModel.getUnit());
+ techniqueList.add(technique);
+ }
+ }
+ techniqueService.saveBatch(techniqueList);
+ return "娣诲姞鐗╂枡銆�" + materialDto.getName() + "銆戞垚鍔�";
}
- //鏌ヨ鎵�鏈夌墿鏂欎俊鎭�
+
+ //娣诲姞鍚屼竴涓瀷鍙峰伐鑹鸿矾绾�,鎶�鏈寚鏍�,鐗╂枡娓呭崟,鐢熶骇宸ヨ壓鐨勭増鏈�
@Override
- public List<Material> selectMaterial() {
- return materialMapper.selectList(Wrappers.<Material>query());
+ @Transactional(rollbackFor = Exception.class)
+ public Integer addVersion(Integer specificationsId, Integer version) {
+ List<Technology> technologyList = technologyMapper.selectList(Wrappers.<Technology>query()
+ .eq("specifications_id", specificationsId)
+ .eq("version", version));
+ /*涓婁竴涓増鏈殑宸ヨ壓璺嚎id闆嗗悎*/
+ List<Integer> techTemIds = technologyList.stream().map(Technology::getId).collect(Collectors.toList());
+ for (Technology technology : technologyList) {
+ technology.setId(null);
+ //鏈�鏂扮増鏈�+1
+ technology.setVersion(technologyMapper.selectVerByTec(specificationsId).get(0) + 1);
+ }
+ technologyService.saveBatch(technologyList);
+ /*宸ヨ壓璺嚎鐨勭増鏈柊澧炵殑鍚屾椂璇ュ伐鑹鸿矾绾夸笅涓嬬殑鎶�鏈寚鏍�,鐢熶骇宸ヨ壓,鐗╂枡娓呭崟閮借鏂板*/
+ //鏂板鐗堟湰鐨勫伐鑹鸿矾绾縤d闆嗗悎
+ List<Integer> technologyIds = technologyList.stream().map(Technology::getId).collect(Collectors.toList());
+ //涓よ�呴暱搴︿竴瀹氫竴鏍�
+ List<Product> productList = new ArrayList<>();
+ for (int i = 0; i < technologyIds.size(); i++) {
+ List<Product> products = productMapper.selectList(Wrappers.<Product>query().eq("technology_id", techTemIds.get(i)));
+ for (Product pro : products) {
+ Product product = new Product();
+ product.setFather(pro.getFather());
+ product.setName(pro.getName());
+ product.setUnit(pro.getUnit());
+ product.setRequired(pro.getRequired());
+ product.setInternal(pro.getInternal());
+ product.setVersion(pro.getVersion()+1);
+ product.setTechnologyId(technologyIds.get(i));
+ productList.add(product);
+ }
+ }
+ productService.saveBatch(productList);
+ /*鏂板鏍囧噯BOM-->鐗╂枡娓呭崟(鎵归噺娣诲姞)*/
+ List<Mbom> mbomList = new ArrayList<>();
+ for (int i = 0; i < technologyIds.size(); i++) {
+ List<Mbom> mboms = mbomMapper.selectList(Wrappers.<Mbom>query().eq("technology_id", techTemIds.get(i)));
+ for (Mbom mb : mboms) {
+ Mbom mbom = new Mbom();
+ mbom.setUnit(mb.getUnit());
+ mbom.setName(mb.getName());
+ mbom.setSupplier(mb.getSupplier());
+ mbom.setQualityTraceability(mb.getQualityTraceability());
+ mbom.setSpecifications(mb.getSpecifications());
+ mbom.setVersion(mb.getVersion()+1);
+ mbom.setNum(mb.getNum());
+ mbom.setTechnologyId(technologyIds.get(i));
+ mbomList.add(mbom);
+ }
+ }
+ mbomService.saveBatch(mbomList);
+ /*鏂板鏍囧噯BOM-->鐢熶骇宸ヨ壓(鎵归噺娣诲姞)*/
+ List<Technique> techniqueList = new ArrayList<>();
+ for (int i = 0; i < technologyIds.size(); i++) {
+ List<Technique> techniques = techniqueMapper.selectList(Wrappers.<Technique>query().eq("technology_id", techTemIds.get(i)));
+ for (Technique teque : techniques) {
+ Technique technique = new Technique();
+ technique.setTechnologyId(technologyIds.get(i));
+ technique.setDevice(teque.getDevice());
+ technique.setProductFather(teque.getProductFather());
+ technique.setProduct(teque.getProduct());
+ technique.setUnit(teque.getUnit());
+ technique.setVersion(teque.getVersion()+1);
+ techniqueList.add(technique);
+ }
+ }
+ techniqueService.saveBatch(techniqueList);
+ return technologyList.get(0).getVersion();
}
- //鏍规嵁鐗╂枡鍚嶇О鏌ヨ鐗╂枡id鍜岀墿鏂欑紪鐮�
- @Override
- public List<Material> selectMcodeId(String name) {
- return materialMapper.selectMcodeId(name);
- }
-
- //鏍规嵁鐗╂枡鍚嶇О鍜岀墿鏂欑紪鐮佹煡璇㈢墿鏂檌d,瑙勬牸淇℃伅鍜屽瀷鍙蜂俊鎭�
- @Override
- public List<Map> selectIdByCoNa(String name, String code) {
- return materialMapper.selectIdByCoNa(name,code);
- }
}
--
Gitblit v1.9.3