From b7586ba9b38136c7af8ca9b31f92f570a0b039c2 Mon Sep 17 00:00:00 2001
From: Fixiaobai <fixiaobai@163.com>
Date: 星期一, 21 八月 2023 18:02:35 +0800
Subject: [PATCH] 计量管理-》计量修改 试验管理-》合格率统计
---
inspection-server/src/main/java/com/yuanchu/limslaboratory/service/impl/InspectionServiceImpl.java | 202 ++++++++++++++++++++++++++++++++++++++++++++++++--
1 files changed, 194 insertions(+), 8 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 4cfef0f..70809f8 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,20 +1,206 @@
package com.yuanchu.limslaboratory.service.impl;
-import com.yuanchu.limslaboratory.pojo.Inspection;
-import com.yuanchu.limslaboratory.mapper.InspectionMapper;
-import com.yuanchu.limslaboratory.service.InspectionService;
+import cn.hutool.core.lang.Snowflake;
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+import com.baomidou.mybatisplus.core.metadata.IPage;
+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.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 org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
+import javax.annotation.Resource;
+import java.util.*;
+import java.util.stream.Collectors;
/**
- * <p>
- * 鏈嶅姟瀹炵幇绫�
- * </p>
+ * 鐢宠琛�(Inspection)琛ㄦ湇鍔″疄鐜扮被
*
- * @author 姹熻嫃榈烽洀缃戠粶绉戞妧鏈夐檺鍏徃
- * @since 2023-07-17
+ * @author zss
+ * @since 2023-08-03 13:03:36
*/
@Service
public class InspectionServiceImpl extends ServiceImpl<InspectionMapper, Inspection> implements InspectionService {
+ @Resource
+ InspectionMapper inspectionMapper;
+
+ @Resource
+ InspectionMaterialMapper inspectionMaterialMapper;
+
+ @Resource
+ InspectionProductService inspectionProductService;
+
+ @Resource
+ InspectionProductMapper inspectionProductMapper;
+
+ @Resource
+ MaterialMapper materialMapper;
+
+ @Resource
+ StandardService standardService;
+
+ @Resource
+ SpecificationsService specificationsService;
+
+ @Resource
+ ProductMapper productMapper;
+
+ @Resource
+ InstrumentService instrumentService;
+
+ @Resource
+ UserMapper userMapper;
+
+
+ /**
+ * 鏌ヨ妫�楠岀敵璇峰崟鍒楄〃
+ *
+ * @param message
+ * @return
+ */
+ @Override
+ public IPage<Map<String, Object>> selectInspectsList(Page<Object> page, String message) {
+ return inspectionMapper.selectInspectsList(page, message);
+ }
+
+ /**
+ * 鏂板妫�楠岀敵璇疯〃
+ *
+ * @param id
+ * @param
+ * @return
+ */
+ @Override
+ @Transactional(rollbackFor = Exception.class)
+ public Integer addInspect(Integer id, InspectionVo inspectionVo) {
+ /*鏂板妫�楠岀敵璇疯〃*/
+ 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);
+ /*鏂板妫�楠屾牱鍝佽〃*/
+ InspectionMaterial inspectionMaterial = InspectionMaterial.builder()
+ .code(inspectionVo.getMcode())
+ .name(inspectionVo.getName())
+ .num(inspectionVo.getNum())
+ .unit(inspectionVo.getUnit())
+ .supplier(inspectionVo.getSupplier())
+ .specifications(inspectionVo.getSpecifications())
+ .formTime(inspectionVo.getFormTime())
+ .inspectionId(inspection.getId())
+ .build();
+ inspectionMaterialMapper.insert(inspectionMaterial);
+ /*鏂板妫�楠岄」鐩〃*/
+ //鑾峰彇鐗╂枡id
+ Material material = materialMapper.selectOne(Wrappers.<Material>query()
+ .eq("name", inspectionVo.getName())
+ .eq("code", inspectionVo.getMcode()));
+ //鑾峰彇瑙勬牸鍚嶇О鍜屽瀷鍙峰悕绉�
+ String specification = inspectionVo.getSpecifications();
+ 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()));
+ //鏍规嵁鍨嬪彿id鏌ヨ椤圭洰淇℃伅
+ List<Product> productList = productMapper.selectList(Wrappers.<Product>query().eq("specifications_id", specifications.getId()));
+ 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(material.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) {
+ String equipmentName = instrumentService.getById(insProduct.getInstrumentId()).getEquipmentName();
+ insProductVo.setInstrumentName(equipmentName);
+ }
+ //鑾峰彇鐢ㄦ埛鍚�(鍓嶆彁鏄鏋滃瓨鍦�)
+ if (insProduct.getUserId() != null) {
+ String userName = userMapper.selectById(insProduct.getUserId()).getName();
+ insProductVo.setUserName(userName);
+ }
+ //椤圭洰鍏宠仈鐗╂枡id
+ insProductVo.setInspectionMaterialId(inspectionMaterial.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);
+ 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 "浣滃簾鎴愬姛!";
+ }
+
+
}
+
--
Gitblit v1.9.3