value
2024-04-07 ba7168283fadf8e13761de353c51998fee09bd81
inspect-server/src/main/java/com/yuanchu/mom/service/impl/InsOrderPlanServiceImpl.java
@@ -17,9 +17,9 @@
import com.yuanchu.mom.common.PrintChina;
import com.yuanchu.mom.dto.InsOrderPlanDTO;
import com.yuanchu.mom.dto.SampleProductDto;
import com.yuanchu.mom.exception.ErrorException;
import com.yuanchu.mom.mapper.*;
import com.yuanchu.mom.pojo.*;
import com.yuanchu.mom.exception.ErrorException;
import com.yuanchu.mom.service.InsOrderPlanService;
import com.yuanchu.mom.service.InsOrderService;
import com.yuanchu.mom.service.StandardTemplateService;
@@ -40,6 +40,8 @@
import java.time.format.DateTimeFormatter;
import java.util.*;
import java.util.stream.Collectors;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.atomic.AtomicInteger;
/**
 * 检验任务-业务实现层
@@ -73,6 +75,9 @@
    @Resource
    private InsReportMapper insReportMapper;
    @Resource
    private InsProductResultMapper insProductResultMapper;
    @Override
    public Map<String, Object> selectInsOrderPlanList(Page page, InsOrderPlanDTO insOrderPlanDTO) {
@@ -147,7 +152,7 @@
                                }
                            }
                            if (tableData.size() > 0) {
                                if (Integer.parseInt(o.get("r") + "") == r + 1 || Integer.parseInt(o.get("r") + "") == r) {
                                if ((Integer.parseInt(o.get("r") + "") == r + 1 || Integer.parseInt(o.get("r") + "") == r) && !(o.get("v") + "").equals("{\"ht\":\"0\"}")) {
                                    r = Integer.parseInt(o.get("r") + "");
                                    tableData.add(o);
                                } else {
@@ -166,6 +171,79 @@
    }
    @Override
    @Transactional(rollbackFor = Exception.class)
    public void saveInsContext(Map<String, Object> insContext) {
        Integer userId = getLook.selectPowerByMethodAndUserId(null).get("userId");
        CompletableFuture.supplyAsync(() -> {
            AtomicInteger count = new AtomicInteger();
            insContext.forEach((k, v) -> {
                JSONObject jo = JSON.parseObject(JSON.toJSONString(v));
                InsProduct insProduct = new InsProduct();
                insProduct.setId(Integer.parseInt(k));
                InsProductResult result = insProductResultMapper.selectOne(Wrappers.<InsProductResult>lambdaQuery().eq(InsProductResult::getInsProductId, insProduct.getId()));
                if (BeanUtil.isEmpty(result)) {
                    result = new InsProductResult();
                }
                result.setInsProductId(Integer.parseInt(k));
                JSONArray jsonArray = JSON.parseArray(JSON.toJSONString(jo.get("insValue")));
                List<Map<String, Object>> iv = new ArrayList<>();
                for (Object o : jsonArray) {
                    JSONObject insValue = JSON.parseObject(JSON.toJSONString(o));
                    Map<String, Object> map = new HashMap<>();
                    map.put("v", JSON.parseObject(JSON.toJSONString(insValue.get("v"))).get("v"));
                    if ((insValue.get("u") == null || insValue.get("u").equals("")) && StrUtil.isNotEmpty(JSON.parseObject(JSON.toJSONString(insValue.get("v"))).get("v").toString())) {
                        map.put("u", userId);
                    }else {
                        map.put("u", insValue.get("u"));
                    }
                    iv.add(map);
                }
                result.setInsValue(JSON.toJSONString(iv));
                JSONArray jsonArray2 = JSON.parseArray(JSON.toJSONString(jo.get("comValue")));
                List<Map<String, Object>> cv = new ArrayList<>();
                for (Object o : jsonArray2) {
                    JSONObject comValue = JSON.parseObject(JSON.toJSONString(o));
                    Map<String, Object> map = new HashMap<>();
                    map.put("v", JSON.parseObject(JSON.toJSONString(comValue.get("v"))).get("v"));
                    cv.add(map);
                }
                result.setComValue(JSON.toJSONString(cv));
                JSONObject resValue = JSON.parseObject(JSON.toJSONString(jo.get("resValue")));
                insProduct.setLastValue(JSON.parseObject(JSON.toJSONString(resValue.get("v"))).get("v") + "");
                JSONObject equipValue = JSON.parseObject(JSON.toJSONString(jo.get("equipValue")));
                try {
                    result.setEquipValue(JSON.parseObject(JSON.toJSONString(equipValue.get("v"))).get("v") + "");
                }catch (Exception ignored){
                    result.setEquipValue(null);
                }
                JSONObject insResult = JSON.parseObject(JSON.toJSONString(jo.get("insResult")));
                insProduct.setInsResult(Integer.parseInt(JSON.parseObject(JSON.toJSONString(insResult.get("v"))).get("v") + ""));
                if (BeanUtil.isEmpty(result.getId())) {
                    result.setCreateUser(userId);
                    result.setUpdateUser(userId);
                    insProductResultMapper.insert(result);
                } else {
                    result.setUpdateUser(userId);
                    result.setUpdateTime(LocalDateTime.now());
                    insProductResultMapper.updateById(result);
                }
                insProduct.setUpdateUser(userId);
                insProductMapper.updateById(insProduct);
                if(count.get() == 0){
                    InsSample insSample = insSampleMapper.selectById(insProductMapper.selectById(insProduct.getId()).getInsSampleId());
                    insSample.setInsState(1);
                    count.addAndGet(1);
                }
            });
            return null;
        }).thenAccept(res -> {
        }).exceptionally(e -> {
            e.printStackTrace();
            return null;
        });
    }
    @Override
    public int upPlanUser(Integer userId, Integer orderId) {
        InsSampleUser insSampleUser = new InsSampleUser();
        insSampleUser.setUserId(userId);