¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.yuanchu.limslaboratory.service.impl; |
| | | |
| | | import cn.hutool.core.lang.Snowflake; |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | 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 javax.annotation.Resource; |
| | | import java.util.*; |
| | | import java.util.stream.Collectors; |
| | | |
| | | /** |
| | | * ç³è¯·è¡¨(Inspection)表æå¡å®ç°ç±» |
| | | * |
| | | * @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 |
| | | 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 |
| | | 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); |
| | | //è¿éæ¥å°ç设å¤id忣éªå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 |
| | | public boolean updateInspectsById(Integer id) { |
| | | //æ´æ°æ£éªåéé¢çæ£éªç¶æåæ£éªç»è®º |
| | | InspectDetailVo inspectDetailVo = selectInspectsListById(id); |
| | | Inspection inspection = Inspection.builder() |
| | | .id(id) |
| | | .inspectionStatus(inspectDetailVo.getInspectionStatus()) |
| | | .build(); |
| | | inspectionMapper.updateById(inspection); |
| | | //çææ¥åå |
| | | |
| | | return true; |
| | | } |
| | | } |
| | | |