From 8abe275e36823f1065300af45e1f7a9a68f549a7 Mon Sep 17 00:00:00 2001 From: Fixiaobai <fixiaobai@163.com> Date: 星期三, 06 九月 2023 16:14:40 +0800 Subject: [PATCH] 修改bug --- inspection-server/src/main/java/com/yuanchu/limslaboratory/service/impl/InspectionServiceImpl.java | 374 +++++++++++++++++++++++++++++++++++++++++++++-------- 1 files changed, 315 insertions(+), 59 deletions(-) diff --git a/inspection-server/src/main/java/com/yuanchu/limslaboratory/service/impl/InspectionServiceImpl.java b/inspection-server/src/main/java/com/yuanchu/limslaboratory/service/impl/InspectionServiceImpl.java index 040aa26..6494553 100644 --- a/inspection-server/src/main/java/com/yuanchu/limslaboratory/service/impl/InspectionServiceImpl.java +++ b/inspection-server/src/main/java/com/yuanchu/limslaboratory/service/impl/InspectionServiceImpl.java @@ -1,93 +1,349 @@ package com.yuanchu.limslaboratory.service.impl; - +import cn.hutool.core.date.DateUtil; +import cn.hutool.core.lang.Snowflake; +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper; -import com.yuanchu.limslaboratory.mapper.InspectionMaterialListMapper; -import com.yuanchu.limslaboratory.mapper.InspectionProductListMapper; -import com.yuanchu.limslaboratory.mapper.PlanMapper; -import com.yuanchu.limslaboratory.pojo.Inspection; -import com.yuanchu.limslaboratory.mapper.InspectionMapper; -import com.yuanchu.limslaboratory.pojo.InspectionMaterialList; -import com.yuanchu.limslaboratory.pojo.InspectionProductList; -import com.yuanchu.limslaboratory.pojo.Plan; -import com.yuanchu.limslaboratory.pojo.dto.InspectionDto; -import com.yuanchu.limslaboratory.service.InspectionProductListService; -import com.yuanchu.limslaboratory.service.InspectionService; +import com.baomidou.mybatisplus.core.metadata.IPage; +import com.baomidou.mybatisplus.core.toolkit.ObjectUtils; +import com.baomidou.mybatisplus.core.toolkit.Wrappers; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.yuanchu.limslaboratory.exception.ApplicationException; +import com.yuanchu.limslaboratory.mapper.*; +import com.yuanchu.limslaboratory.pojo.*; +import com.yuanchu.limslaboratory.pojo.vo.InsProductVo; +import com.yuanchu.limslaboratory.pojo.vo.InspectDetailVo; +import com.yuanchu.limslaboratory.pojo.vo.InspectionVo; +import com.yuanchu.limslaboratory.service.*; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.BeanUtils; import org.springframework.stereotype.Service; -import javax.annotation.Resource; -import java.util.Date; -import java.util.List; +import org.springframework.transaction.annotation.Transactional; +import javax.annotation.Resource; +import java.util.*; +import java.util.concurrent.atomic.AtomicBoolean; +import java.util.stream.Collectors; /** - * <p> - * 鏈嶅姟瀹炵幇绫� - * </p> + * 鐢宠琛�(Inspection)琛ㄦ湇鍔″疄鐜扮被 * - * @author 姹熻嫃榈烽洀缃戠粶绉戞妧鏈夐檺鍏徃 - * @since 2023-07-17 + * @author zss + * @since 2023-08-03 13:03:36 */ @Service +@Slf4j public class InspectionServiceImpl extends ServiceImpl<InspectionMapper, Inspection> implements InspectionService { @Resource - private InspectionMapper inspectionMapper; + InspectionMapper inspectionMapper; @Resource - private PlanMapper planMapper; + InspectionMaterialMapper inspectionMaterialMapper; @Resource - InspectionMaterialListMapper inspectionMaterialListMapper; + InspectionProductService inspectionProductService; @Resource - InspectionProductListMapper inspectionProductListMapper; + InspectionProductMapper inspectionProductMapper; - //娣诲姞妫�楠岀敵璇峰崟 + @Resource + MaterialMapper materialMapper; + + @Resource + StandardService standardService; + + @Resource + SpecificationsService specificationsService; + + @Resource + ProductMapper productMapper; + + @Resource + InstrumentService instrumentService; + + @Resource + UserMapper userMapper; + + @Resource + RawMaterialMapper rawMaterialMapper; + + @Resource + LinkDetectionMapper linkDetectionMapper; + + + /** + * 鏌ヨ妫�楠岀敵璇峰崟鍒楄〃 + * + * @param message + * @return + */ @Override - public Inspection addInspection(String userName, int type) { - Inspection inspection = new Inspection(type, 0, 1, 1, userName); - int judge = inspectionMapper.insert(inspection); - return judge > 0 ? inspection : null; + public IPage<Map<String, Object>> selectInspectsList(Page<Object> page, String message) { + return inspectionMapper.selectInspectsList(page, message); } - //鏌ヨ鎵�鏈夋楠屽崟鍒楄〃 + //鏂板妫�楠屽崟-->閫夋嫨妫�楠岄」鐩増鏈� @Override - public List<InspectionDto> selectAllInspection(int pageSize, int countSize, Integer state) { - return inspectionMapper.selectAllInspection((pageSize - 1) * countSize, pageSize * countSize, state); + public List<Integer> chooseVer(String name, String mcode, String specifications) { + return productMapper.chooseVersion(Integer.parseInt(specifications)); } - //浣滃簾鐢宠妫�楠屽崟 + //鏂板妫�楠屽崟-->閫夋嫨妫�楠岄」鐩増鏈�-->鏌ョ湅璇ョ増鏈笅鎴戜滑瑕佸仛鐨勯」鐩姹� @Override - public boolean delInspectionByInsId(String inspectionId) { - //妫�楠屽崟浣滃簾 - Inspection inspection = inspectionMapper.selectById(inspectionId); + public List<Map<String, Object>> lookProByVer(String name, String mcode, String specifications, Integer version, String experiment) { + Integer specificationId = Integer.parseInt(specifications); + /*濡傛灉璇曢獙椤圭洰涓虹┖鍒欐槸鎴愬搧妫�楠屾垨鑰呭師鏉愭枡妫�楠屽垯鏄睍绀鸿鐗堟湰鐨勬墍鏈夐」鐩楠岃姹傚弬鏁�*/ + if (ObjectUtils.isEmpty(experiment)) { + return productMapper.pageProductInformation(specificationId, version); + } + /*濡傛灉涓嶄负绌哄垯鏄鎵樻楠�,鍙睍绀烘垜浠妫�楠岀殑椤圭洰瑕佹眰鍙傛暟*/ + //鑾峰彇璇曢獙椤圭洰淇℃伅(缁撴瀯,瀵肩嚎澶栧緞) + List<String> experiments = Arrays.stream(experiment.split(",")).collect(Collectors.toList()); + //鏍规嵁鍨嬪彿id鍜岄」鐩俊鎭煡璇㈤」鐩俊鎭� + List<Map<String, Object>> products = new ArrayList<>(); + for (String exper : experiments) { + List<Map<String, Object>> list = productMapper.selFath(specificationId, exper, version); + if (ObjectUtils.isEmpty(list)) { + Map<String, Object> project = productMapper.selNam(specificationId, exper, version); + products.add(project); + } + products.addAll(list); + } + return products; + } + + /** + * 鏂板妫�楠岀敵璇疯〃 + * @param id 鐢ㄦ埛id + * @param + * @return + */ + @Override + @Transactional(rollbackFor = Exception.class) + public Integer addInspect(Integer id, InspectionVo inspectionVo) throws ApplicationException { + log.info(inspectionVo.toString()); + /*鏂板妫�楠岀敵璇疯〃*/ + Inspection inspection = Inspection.builder() + .startTime(inspectionVo.getStartTime()) + .endTime(inspectionVo.getEndTime()) + .type(inspectionVo.getType()) + .code(new Snowflake(1, 1).nextIdStr()) + .userId(id) + .build(); + inspectionMapper.insert(inspection); + /*濡傛灉鏄師鏉愭枡妫�楠�,鏂板涔嬪悗瑕佹洿鏀瑰師鏉愭枡鎶ユ鐨勭姸鎬佸拰妫�楠屼汉,妫�楠屾棩鏈�*/ + if (inspectionVo.getType()==0) { + RawMaterial rawMaterial = new RawMaterial(); + rawMaterial.setId(inspectionVo.getId()); + rawMaterial.setType(1); + rawMaterial.setInspectionDate(DateUtil.date()); + rawMaterial.setSurveyor(userMapper.selectById(id).getName()); + rawMaterialMapper.updateById(rawMaterial); + } + /*濡傛灉鏄鎵樻楠�,鏂板涔嬪悗瑕佹洿鏀瑰鎵樻姤妫�鐨勭姸鎬�*/ + else if (inspectionVo.getType()==2){ + LinkDetection linkDetection = new LinkDetection(); + linkDetection.setId(inspectionVo.getId()); + linkDetection.setInspectionStatus(2); + linkDetectionMapper.updateById(linkDetection); + } + /*鏂板妫�楠屾牱鍝佽〃*/ + InspectionMaterial inspectionMaterial = InspectionMaterial.builder() + .code(inspectionVo.getMcode()) + .name(inspectionVo.getName()) + .num(inspectionVo.getNum()) + .unit(inspectionVo.getUnit()) + .supplier(inspectionVo.getSupplier()) + .specificationsId(inspectionVo.getSpecificationId()) + .specifications(inspectionVo.getSpecifications()) + .formTime(inspectionVo.getFormTime()) + .inspectionId(inspection.getId()) + .notes(inspectionVo.getNotes()) + .build(); + inspectionMaterialMapper.insert(inspectionMaterial); + /*鏂板妫�楠岄」鐩〃*/ + //鏍规嵁鏍峰搧鍚嶇О缂栧彿浠ュ強鍨嬪彿瑙勬牸鑾峰彇鍨嬪彿id + Integer specificationId = Integer.parseInt(inspectionVo.getSpecificationId()); + //if(ObjectUtils.isNotEmpty(inspectionVo.getSpecificationId())){ + // specificationId =Integer.parseInt(inspectionVo.getSpecificationId()); + //}else{ + // specificationId=getSpecificationId(inspectionVo.getName(), inspectionVo.getMcode(), inspectionVo.getSpecifications()); + //} + //濡傛灉璇曢獙椤圭洰瀛楁涓嶄负绌哄垯鎸夎瀛楁鐨勯」鐩繘琛屽尮閰� + if (ObjectUtils.isNotEmpty(inspectionVo.getExperiment())) { + //鑾峰彇璇曢獙椤圭洰淇℃伅(缁撴瀯,瀵肩嚎澶栧緞) + List<String> experiments = Arrays.stream(inspectionVo.getExperiment().split(",")).collect(Collectors.toList()); + //鏍规嵁鍨嬪彿id鍜岄」鐩俊鎭煡璇㈤」鐩俊鎭� + List<Product> products = new ArrayList<>(); + for (String experiment : experiments) { + List<Product> productList1 = productMapper.selectList(Wrappers.<Product>query() + .eq("specifications_id", specificationId) + .eq("father", experiment) + .eq("version", inspectionVo.getVersion())); + if (ObjectUtils.isEmpty(productList1)) { + Product product = productMapper.selectOne(Wrappers.<Product>query() + .eq("specifications_id", specificationId) + .isNull("father") + .eq("name", experiment) + .eq("version", inspectionVo.getVersion())); + products.add(product); + } else products.addAll(productList1); + } + //灏嗘煡璇㈢殑椤圭洰淇℃伅鏋勫缓鎴愭楠岄」鐩� + ArrayList<InspectionProduct> list = new ArrayList<>(); + for (Product product : products) { + InspectionProduct rawInsProduct = InspectionProduct.builder() + .name(product.getName()) + .unit(product.getUnit()) + .required(product.getRequired()) + .internal(product.getInternal()) + .inspectionMaterialId(inspectionMaterial.getId()) + .build(); + list.add(rawInsProduct); + } + //妫�楠岄」鐩壒閲忔坊鍔� + inspectionProductService.saveBatch(list); + return inspection.getId(); + } + //濡傛灉璇曢獙椤圭洰涓虹┖鍒欐寜鐓у瀷鍙穒d鍦ㄦ爣鍑嗗簱閲岄潰鍏ㄩ儴鍖归厤 + List<Product> productList = + productMapper.selectList(Wrappers.<Product>query() + .eq("specifications_id", specificationId) + .eq("version",inspectionVo.getVersion())); + productList.stream().forEach(p->{ + String internal = Optional.ofNullable(p) + .map(Product::getInternal) + .orElse("绌�"); + String required = Optional.ofNullable(p) + .map(Product::getRequired).orElse("绌�"); + if(Objects.equals("绌�",internal)||Objects.equals(required,"绌�")) { + throw new ApplicationException("椤圭洰鐗堟湰涓嶅彲鐢�"); + } + }); + //灏嗘煡璇㈢殑椤圭洰淇℃伅鏋勫缓鎴愭楠岄」鐩� + ArrayList<InspectionProduct> list = new ArrayList<>(); + for (Product product : productList) { + InspectionProduct rawInsProduct = InspectionProduct.builder() + .name(product.getName()) + .unit(product.getUnit()) + .required(product.getRequired()) + .internal(product.getInternal()) + .inspectionMaterialId(inspectionMaterial.getId()) + .build(); + list.add(rawInsProduct); + } + //妫�楠岄」鐩壒閲忔坊鍔� + inspectionProductService.saveBatch(list); + return inspection.getId(); + } + + //鏍规嵁妫�楠屽崟id鏌ヨ鍘熸潗鏂欐楠屽崟璇︽儏 + @Override + @Transactional(rollbackFor = Exception.class) + public InspectDetailVo selectInspectsListById(Integer id) { + /*灏嗘楠屽崟鍩烘湰淇℃伅鏌ヨ鍑烘潵骞跺皝瑁呭埌RawInspectVo瀵硅薄涓�*/ + Inspection inspection = inspectionMapper.selectById(id); + InspectDetailVo inspectDetailVo = new InspectDetailVo(); + //鎶ユ浜� + User user = userMapper.selectById(inspection.getUserId()); + inspectDetailVo.setUserName(user.getName()); + //鎶ユ寮�濮嬫椂闂村拰缁撴潫鏃堕棿 + inspectDetailVo.setStartTime(inspection.getStartTime()); + inspectDetailVo.setEndTime(inspection.getEndTime()); + //妫�楠岀粨璁� + inspectDetailVo.setInspectionStatus(inspection.getInspectionStatus()); + //鏌ヨ妫�楠岀墿鏂� + InspectionMaterial inspectionMaterial = inspectionMaterialMapper.selectOne(Wrappers.<InspectionMaterial>query().eq("inspection_id", id)); + //鏉ユ枡鏃ユ湡,渚涘簲鍟嗗悕绉�,鍘熸潗鏂欑紪鐮�,鍘熸潗鏂欏悕绉�,瑙勬牸鍨嬪彿,鍗曚綅,鏁伴噺 + BeanUtils.copyProperties(inspectionMaterial, inspectDetailVo); + /*鏌ヨ妫�楠屽崟閲岄潰鐨勬楠岄」鐩�,骞跺皝瑁呭埌RawInspectVo瀵硅薄涓�*/ + LambdaQueryWrapper<InspectionProduct> queryWrapper = new LambdaQueryWrapper<>(); + queryWrapper + .eq(InspectionProduct::getInspectionMaterialId, inspectionMaterial.getId()); + List<InspectionProduct> inspectionProducts = inspectionProductMapper.selectList(queryWrapper); + //杩欓噷鏌ュ埌鐨勮澶噄d鍜屾楠屽憳id瑕佹煡璇㈠悕绉� + List<InsProductVo> insProductVos = inspectionProducts.stream().map(insProduct -> { + //灏嗕竴涓璞$殑鍊艰祴鍊肩粰鍙︿竴涓璞� + InsProductVo insProductVo = new InsProductVo(); + BeanUtils.copyProperties(insProduct, insProductVo); + //鑾峰彇璁惧鍚�(鍓嶆彁鏄鏋滃瓨鍦�) + if (insProduct.getInstrumentId() != null) { + insProductVo.setInstrumentId(insProduct.getInstrumentId()); + } + //鑾峰彇鐢ㄦ埛鍚�(鍓嶆彁鏄鏋滃瓨鍦�) + if (insProduct.getUserProId() != null) { + insProductVo.setUserId(insProduct.getUserProId()); + } + //椤圭洰鍏宠仈鐗╂枡id + insProductVo.setInspectionMaterialId(inspectionMaterial.getId()); + insProductVo.setId(insProduct.getId()); + return insProductVo; + }).collect(Collectors.toList()); + inspectDetailVo.setInsProducts(insProductVos); + return inspectDetailVo; + } + + //浣滃簾妫�楠屽崟 + @Override + @Transactional(rollbackFor = Exception.class) + public String delInspect(Integer id) { + /*浣滃簾妫�楠屽崟*/ + Inspection inspection = new Inspection(); + inspection.setId(id); inspection.setState(0); - int judge1 = inspectionMapper.updateById(inspection); - //妫�楠岃鍒掍綔搴� - UpdateWrapper<Plan> updateWrapper = new UpdateWrapper<>(); - updateWrapper.eq("inspection_id", inspectionId).set("state", 0); - planMapper.update(new Plan(),updateWrapper ); - //妫�楠屾牱鍝佷綔搴�(鏍规嵁鎶ユ鍗昳d鍒犻櫎鏍峰搧淇℃伅) - UpdateWrapper<InspectionMaterialList> wrapper1 = new UpdateWrapper<>(); - wrapper1.eq("inspection_id", inspectionId).set("state", 0); - int judge2 = inspectionMaterialListMapper.update(new InspectionMaterialList(), wrapper1); - return judge1 > 0 && judge2 > 0; - //妫�楠屾牱鍝佷腑鐨勬楠岄」鐩綔搴� - //鏌ュ嚭妫�楠屾牱鍝乮d - + inspectionMapper.updateById(inspection); + /*浣滃簾妫�楠屾牱鍝�*/ + InspectionMaterial inspectionMaterial = inspectionMaterialMapper.selectOne(Wrappers.<InspectionMaterial>query().eq("inspection_id", id)); + inspectionMaterial.setState(0); + inspectionMaterialMapper.updateById(inspectionMaterial); + /*浣滃簾妫�楠岄」鐩�*/ + inspectionProductMapper.updat(inspectionMaterial.getId()); + return "浣滃簾鎴愬姛!"; } - //鎻愪氦鐢宠妫�楠屽崟 + //淇濆瓨妫�楠岄」鐩矗浠讳汉 @Override - public boolean subInspectionByInsId(String inspectionId) { - Inspection inspection = inspectionMapper.selectById(inspectionId); - //鐘舵�佹敼涓哄凡鎻愪氦2 - inspection.setState(2); - int judge = inspectionMapper.updateById(inspection); - //璁″垝琛ㄦ柊澧� - Plan plan = Plan.builder().inspectionId(inspectionId).state(1).userId(inspection.getInspectUserId()).createTime(new Date()).build(); - planMapper.insert(plan); - return judge > 0; + public String chooseUseProId(Integer id, Integer userProId) { + InspectionProduct inspectionProduct = new InspectionProduct(); + inspectionProduct.setId(id); + inspectionProduct.setUserProId(userProId); + inspectionProductMapper.updateById(inspectionProduct); + return "淇濆瓨鎴愬姛!"; } + + @Override + public boolean chooseEquipment(Integer id, Integer equipmentId) { + UpdateWrapper<InspectionProduct>inspectionProductUpdateWrapper=new UpdateWrapper<>(); + inspectionProductUpdateWrapper.lambda().set(InspectionProduct::getInstrumentId,equipmentId) + .eq(InspectionProduct::getId,id); + return inspectionProductMapper.update(null,inspectionProductUpdateWrapper)>0; + } + + /*鏍规嵁鏍峰搧鍚嶇О,鏍峰搧缂栧彿,鍨嬪彿瑙勬牸鑾峰彇鍨嬪彿id*/ + private Integer getSpecificationId(String name, String mcode, String specification) { + //鑾峰彇鐗╂枡id + Material material = materialMapper.selectOne(Wrappers.<Material>query() + .eq("name", name) + .eq("code", mcode)); + if (Objects.isNull(material)){ + return null; + } + //鑾峰彇瑙勬牸鍚嶇О鍜屽瀷鍙峰悕绉� + String[] split = specification.split("-"); + String stName = split[0]; + String spName = split[1]; + //鑾峰彇瑙勬牸id + Standard standard = standardService.getOne(Wrappers.<Standard>query() + .eq("name", stName) + .eq("material_id", material.getId())); + //鑾峰彇鍨嬪彿id + Specifications specifications = specificationsService.getOne(Wrappers.<Specifications>query() + .eq("name", spName) + .eq("standard_id", standard.getId())); + return specifications.getId(); + } + } + -- Gitblit v1.9.3