| | |
| | | package com.yuanchu.mom.service.impl; |
| | | |
| | | 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.mom.common.PrintChina; |
| | | import com.yuanchu.mom.dto.InsProductDto; |
| | | import com.yuanchu.mom.exception.ErrorException; |
| | | import com.yuanchu.mom.mapper.InsOrderMapper; |
| | | import com.yuanchu.mom.mapper.InsProductMapper; |
| | | import com.yuanchu.mom.mapper.InsSampleMapper; |
| | | import com.yuanchu.mom.pojo.InsOrder; |
| | | import com.yuanchu.mom.pojo.InsProduct; |
| | | import com.yuanchu.mom.pojo.InsSample; |
| | | import com.yuanchu.mom.service.InsProductService; |
| | | import com.yuanchu.mom.utils.QueryWrappers; |
| | | import com.yuanchu.mom.vo.InsOrderPlanVO; |
| | | import lombok.AllArgsConstructor; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import java.util.List; |
| | | import java.util.*; |
| | | import java.util.stream.Collectors; |
| | | |
| | | @Service |
| | | @AllArgsConstructor |
| | |
| | | |
| | | private InsProductMapper insProductMapper; |
| | | |
| | | private InsOrderMapper insOrderMapper; |
| | | |
| | | private InsSampleMapper insSampleMapper; |
| | | |
| | | @Override |
| | | public int selectOrderManDay(Integer orderId) { |
| | | return insProductMapper.selectOrderManDay(orderId); |
| | | } |
| | | |
| | | @Override |
| | | public int updateInspected(Integer id) { |
| | | insProductMapper.updateInspected(id); |
| | | return 0; |
| | | public int updateInspected(Integer id, String ids) { |
| | | InsOrder insOrder = insOrderMapper.selectById(id); |
| | | insOrder.setIsRevocation(1);//需要审核 |
| | | insOrder.setRevocationInsProductIds(ids); |
| | | insOrderMapper.updateById(insOrder); |
| | | //如果是内部单无需审核撤销 |
| | | if (insOrder.getOrderType().equals("C")) { |
| | | checkUpdate(id, 1); |
| | | } |
| | | return 1; |
| | | } |
| | | |
| | | @Override |
| | | public boolean write(InsProductDto insProductDto) { |
| | | List<InsProduct> insProducts = baseMapper.selectBatchIds(insProductDto.getIds()); |
| | | for (InsProduct insProduct : insProducts) { |
| | | insProduct.setTemperature(insProductDto.getTemperature()); |
| | | insProduct.setHumidity(insProductDto.getHumidity()); |
| | | insProduct.setTemperature(insProductDto.getTemperature()); |
| | | insProduct.setHumidity(insProductDto.getHumidity()); |
| | | } |
| | | return updateBatchById(insProducts); |
| | | } |
| | | |
| | | //查询待检项目 |
| | | @Override |
| | | public Map<String, Object> selectNoProducts(Page page, InsProduct insProduct, Integer orderId, String ids) { |
| | | Map<String, Object> map = new HashMap<>(); |
| | | map.put("head", PrintChina.printChina(InsProduct.class)); |
| | | IPage<InsProduct> insProductIPage = baseMapper.selectNoProducts(page, orderId); |
| | | if (ObjectUtils.isNotEmpty(ids)) { |
| | | List<Integer> collect = Arrays.asList(ids.split(",")).stream() |
| | | .map(Integer::parseInt) |
| | | .collect(Collectors.toList()); |
| | | List<InsProduct> products = insProductIPage.getRecords().stream().filter(record -> collect.contains(record.getId())).collect(Collectors.toList()); |
| | | insProductIPage.setRecords(products); |
| | | } |
| | | map.put("body", insProductIPage); |
| | | return map; |
| | | } |
| | | |
| | | //审核待检撤销 |
| | | @Override |
| | | public void checkUpdate(Integer orderId, Integer state) { |
| | | InsOrder insOrder = insOrderMapper.selectById(orderId); |
| | | if (state == 1) { |
| | | List<String> list = new ArrayList<>(); |
| | | try { |
| | | list = Arrays.asList(insOrder.getRevocationInsProductIds().split(",")); |
| | | } catch (Exception e) { |
| | | throw new ErrorException("还没有选择应该要撤销的检验项目"); |
| | | } |
| | | List<Integer> ids = list.stream() |
| | | .map(Integer::parseInt) |
| | | .collect(Collectors.toList()); |
| | | List<InsSample> insSamples = insSampleMapper.selectList(Wrappers.<InsSample>lambdaQuery().eq(InsSample::getInsOrderId, orderId)); |
| | | List<Integer> collect = insSamples.stream().map(InsSample::getId).collect(Collectors.toList()); |
| | | List<InsProduct> insProducts = insProductMapper.selectList(Wrappers.<InsProduct>lambdaQuery().eq(InsProduct::getState, 1).in(InsProduct::getInsSampleId, collect)); |
| | | if (insProducts.stream().map(InsProduct::getId).collect(Collectors.toList()).equals(ids)) { |
| | | //如果该检验单下的所有项目全部都撤销,那么这个单子也需要撤销 |
| | | insOrder.setState(3); |
| | | } |
| | | else { |
| | | List<InsProduct> products = insProductMapper.selectBatchIds(ids); |
| | | //首先根据选择的项目id进行撤销项目 |
| | | updateBatchById(products.stream().map(insProduct -> { |
| | | insProduct.setState(0); |
| | | return insProduct; |
| | | }).collect(Collectors.toList())); |
| | | //如果该检验单某个样品下的项目全部都撤销了,那么这个样品也需要删掉 |
| | | List<Integer> sampleIds = products.stream().map(InsProduct::getInsSampleId).distinct().collect(Collectors.toList()); |
| | | for (Integer sampleId : sampleIds) { |
| | | Long count = insProductMapper.selectCount(Wrappers.<InsProduct>lambdaQuery() |
| | | .eq(InsProduct::getInsSampleId, sampleId) |
| | | .eq(InsProduct::getState, 1)); |
| | | if(count<=0){ |
| | | insSampleMapper.deleteById(sampleId); |
| | | } |
| | | } |
| | | } |
| | | //insProductMapper.updateInspected(id); |
| | | } |
| | | //不通过 |
| | | insOrder.setIsRevocation(0); |
| | | insOrderMapper.updateById(insOrder); |
| | | |
| | | } |
| | | } |
| | | |
| | | |