| | |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import com.deepoove.poi.XWPFTemplate; |
| | | import com.deepoove.poi.config.Configure; |
| | | import com.deepoove.poi.config.ConfigureBuilder; |
| | | import com.yuanchu.mom.common.GetLook; |
| | | import com.yuanchu.mom.common.PrintChina; |
| | | import com.yuanchu.mom.dto.InsOrderPlanDTO; |
| | | import com.yuanchu.mom.dto.SampleProductDto; |
| | | 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; |
| | | import com.yuanchu.mom.utils.GiveCode; |
| | | import com.yuanchu.mom.utils.QueryWrappers; |
| | | import com.yuanchu.mom.vo.InsOrderPlanVO; |
| | | import lombok.AllArgsConstructor; |
| | | import org.springframework.beans.factory.annotation.Value; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | import org.springframework.util.ResourceUtils; |
| | | |
| | | import javax.annotation.Resource; |
| | | import java.io.FileNotFoundException; |
| | | import java.io.FileOutputStream; |
| | | import java.io.IOException; |
| | | import java.time.LocalDateTime; |
| | | import java.time.format.DateTimeFormatter; |
| | | import java.util.*; |
| | | import java.util.stream.Collectors; |
| | | import java.util.concurrent.CompletableFuture; |
| | | import java.util.concurrent.atomic.AtomicInteger; |
| | | |
| | | /** |
| | | * 检验任务-业务实现层 |
| | | */ |
| | | @Service |
| | | @AllArgsConstructor |
| | | //@AllArgsConstructor |
| | | public class InsOrderPlanServiceImpl extends ServiceImpl<InsOrderMapper, InsOrder> implements InsOrderPlanService { |
| | | |
| | | @Resource |
| | | private InsSampleMapper insSampleMapper; |
| | | |
| | | @Resource |
| | | private InsSampleUserMapper insSampleUserMapper; |
| | | |
| | | @Resource |
| | | private GetLook getLook; |
| | | |
| | | @Resource |
| | | private InsOrderMapper insOrderMapper; |
| | | |
| | | @Resource |
| | | private InsOrderService insOrderService; |
| | | |
| | | @Resource |
| | | private StandardTemplateService standardTemplateService; |
| | | |
| | | @Resource |
| | | private InsOrderStateMapper insOrderStateMapper; |
| | | @Resource |
| | | private InsProductMapper insProductMapper; |
| | | |
| | | @Value("${wordUrl}") |
| | | private String wordUrl; |
| | | |
| | | @Resource |
| | | private GiveCode giveCode; |
| | | |
| | | @Resource |
| | | private InsReportMapper insReportMapper; |
| | | |
| | | private InsProductResultMapper insProductResultMapper; |
| | | |
| | | private InsProductMapper insProductMapper; |
| | | |
| | |
| | | } |
| | | } |
| | | 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 { |
| | |
| | | } |
| | | |
| | | @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 && 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); |
| | |
| | | insOrderStateMapper.update(null, Wrappers.<InsOrderState>lambdaUpdate().eq(InsOrderState::getInsOrderId, orderId).eq(InsOrderState::getLaboratory, laboratory).set(InsOrderState::getInsTime, LocalDateTime.now()).set(InsOrderState::getInsState, num).set(InsOrderState::getVerifyTell, tell).set(InsOrderState::getVerifyUser, getLook.selectPowerByMethodAndUserId(null).get("userId"))); |
| | | List<InsOrderState> insOrderStates = insOrderStateMapper.selectList(Wrappers.<InsOrderState>lambdaQuery().eq(InsOrderState::getInsOrderId, orderId)); |
| | | long count = insOrderStates.stream().filter(a -> a.getInsState() == 5).count(); |
| | | if (count == insOrderStates.size()) { |
| | | XWPFTemplate template = XWPFTemplate.compile("template.docx").render( |
| | | if (count == insOrderStates.size() && num == 5) { |
| | | InsOrder insOrder = insOrderMapper.selectById(orderId); |
| | | Map<String, String> user = insProductMapper.selectUserById(insOrder.getUserId()); |
| | | List<SampleProductDto> samples = insSampleMapper.selectSampleProductListByOrderId(orderId); |
| | | samples.forEach(System.out::println); |
| | | InsReport insReport = new InsReport(); |
| | | insReport.setCode(giveCode.giveCode("JCZX/TX-", "ins_report", "-", "yyMMdd")); |
| | | insReport.setInsOrderId(orderId); |
| | | String url; |
| | | try { |
| | | url = ResourceUtils.getURL("classpath:static/report-template.docx").getPath(); |
| | | } catch (FileNotFoundException e) { |
| | | throw new ErrorException("找不到模板文件"); |
| | | } |
| | | XWPFTemplate template = XWPFTemplate.compile(url).render( |
| | | new HashMap<String, Object>() {{ |
| | | put("title", "Hi, poi-tl Word模板引擎"); |
| | | put("order", insOrder); |
| | | put("report", insReport); |
| | | put("user", user); |
| | | put("samples", samples); |
| | | put("sampleSize", samples.size() + samples.get(0).getUnit()); |
| | | }}); |
| | | try { |
| | | template.writeAndClose(new FileOutputStream("output.docx")); |
| | | String name = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yy_MM_dd_HH_mm_ss")) + ".docx"; |
| | | template.writeAndClose(new FileOutputStream(wordUrl + "/" + name)); |
| | | insReport.setUrl("/word/"+ name); |
| | | insReportMapper.insert(insReport); |
| | | } catch (IOException e) { |
| | | throw new RuntimeException(e); |
| | | } |
| | | List<InsSample> insSamples = insSampleMapper.selectList(Wrappers.<InsSample>lambdaQuery().eq(InsSample::getInsOrderId, orderId)); |
| | | insSamples.forEach(a -> { |
| | | System.out.println(a); |
| | | List<InsProduct> insProducts = insProductMapper.selectList(Wrappers.<InsProduct>lambdaQuery().eq(InsProduct::getInsSampleId, a.getId())); |
| | | insProducts.forEach(System.out::println); |
| | | }); |
| | | } |
| | | return 1; |
| | | } |