| | |
| | | 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.query.QueryWrapper; |
| | | import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper; |
| | | 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 org.springframework.transaction.annotation.Transactional; |
| | | |
| | | import javax.annotation.Resource; |
| | | import java.util.*; |
| | | import java.util.concurrent.atomic.AtomicBoolean; |
| | | import java.util.stream.Collectors; |
| | | |
| | | /** |
| | |
| | | * @since 2023-08-03 13:03:36 |
| | | */ |
| | | @Service |
| | | @Slf4j |
| | | public class InspectionServiceImpl extends ServiceImpl<InspectionMapper, Inspection> implements InspectionService { |
| | | |
| | | @Resource |
| | |
| | | //新增检验单-->选择检验项目版本 |
| | | @Override |
| | | public List<Integer> chooseVer(String name, String mcode, String specifications) { |
| | | Integer specificationId = getSpecificationId(name, mcode, specifications); |
| | | return productMapper.chooseVersion(specificationId); |
| | | return productMapper.chooseVersion(Integer.parseInt(specifications)); |
| | | } |
| | | |
| | | //新增检验单-->选择检验项目版本-->查看该版本下我们要做的项目要求 |
| | | @Override |
| | | public List<Map<String, Object>> lookProByVer(String name, String mcode, String specifications, Integer version, String experiment) { |
| | | Integer specificationId = getSpecificationId(name, mcode, specifications); |
| | | Integer specificationId = Integer.parseInt(specifications); |
| | | /*如果试验项目为空则是成品检验或者原材料检验则是展示该版本的所有项目检验要求参数*/ |
| | | if (ObjectUtils.isEmpty(experiment)) { |
| | | return productMapper.pageProductInformation(specificationId, version); |
| | |
| | | */ |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public Integer addInspect(Integer id, InspectionVo inspectionVo) { |
| | | public Integer addInspect(Integer id, InspectionVo inspectionVo) throws ApplicationException { |
| | | log.info(inspectionVo.toString()); |
| | | /*新增检验申请表*/ |
| | | Inspection inspection = Inspection.builder() |
| | | .startTime(inspectionVo.getStartTime()) |
| | |
| | | .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 = null; |
| | | if(ObjectUtils.isNotEmpty(inspectionVo.getSpecificationId())){ |
| | | specificationId =Integer.parseInt(inspectionVo.getSpecificationId()); |
| | | }else{ |
| | | specificationId=getSpecificationId(inspectionVo.getName(), inspectionVo.getMcode(), inspectionVo.getSpecifications()); |
| | | } |
| | | 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())) { |
| | | //获取试验项目信息(结构,导线外径) |
| | |
| | | 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) { |
| | |
| | | queryWrapper |
| | | .eq(InspectionProduct::getInspectionMaterialId, inspectionMaterial.getId()); |
| | | List<InspectionProduct> inspectionProducts = inspectionProductMapper.selectList(queryWrapper); |
| | | System.out.println(inspectionProducts); |
| | | //这里查到的设备id和检验员id要查询名称 |
| | | List<InsProductVo> insProductVos = inspectionProducts.stream().map(insProduct -> { |
| | | //将一个对象的值赋值给另一个对象 |
| | |
| | | BeanUtils.copyProperties(insProduct, insProductVo); |
| | | //获取设备名(前提是如果存在) |
| | | if (insProduct.getInstrumentId() != null) { |
| | | String equipmentName = instrumentService.getById(insProduct.getInstrumentId()).getEquipmentName(); |
| | | insProductVo.setInstrumentName(equipmentName); |
| | | insProductVo.setInstrumentId(insProduct.getInstrumentId()); |
| | | } |
| | | //获取用户名(前提是如果存在) |
| | | if (insProduct.getUserProId() != null) { |
| | | String userName = userMapper.selectById(insProduct.getUserProId()).getName(); |
| | | insProductVo.setUserName(userName); |
| | | insProductVo.setUserId(insProduct.getUserProId()); |
| | | } |
| | | //项目关联物料id |
| | | insProductVo.setInspectionMaterialId(inspectionMaterial.getId()); |
| | |
| | | return inspectionProductMapper.update(null,inspectionProductUpdateWrapper)>0; |
| | | } |
| | | |
| | | @Override |
| | | public List<Material> getMaterielTypeIsOne() { |
| | | QueryWrapper<Material>queryWrapper=new QueryWrapper<>(); |
| | | queryWrapper.lambda() |
| | | .select(Material::getName,Material::getId,Material::getCode) |
| | | .eq(Material::getType,1) |
| | | .eq(Material::getState,1); |
| | | return materialMapper.selectList(queryWrapper); |
| | | } |
| | | |
| | | @Override |
| | | public Map<String, Object> getSpecification(Integer id) { |
| | | return materialMapper.getTreeByMaterialId(id); |
| | | } |
| | | |
| | | /*根据样品名称,样品编号,型号规格获取型号id*/ |
| | | private Integer getSpecificationId(String name, String mcode, String specification) { |
| | | //获取物料id |