From 386af6fd927464760ed1d69a1a23d41bc91b1941 Mon Sep 17 00:00:00 2001 From: 李林 <z1292839451@163.com> Date: 星期三, 17 四月 2024 18:12:47 +0800 Subject: [PATCH] 调整模板功能 --- inspect-server/src/main/java/com/yuanchu/mom/service/impl/InsOrderPlanServiceImpl.java | 83 ++++++++++++++++++++++++++++------------- 1 files changed, 56 insertions(+), 27 deletions(-) diff --git a/inspect-server/src/main/java/com/yuanchu/mom/service/impl/InsOrderPlanServiceImpl.java b/inspect-server/src/main/java/com/yuanchu/mom/service/impl/InsOrderPlanServiceImpl.java index 36c8f4a..12d2730 100644 --- a/inspect-server/src/main/java/com/yuanchu/mom/service/impl/InsOrderPlanServiceImpl.java +++ b/inspect-server/src/main/java/com/yuanchu/mom/service/impl/InsOrderPlanServiceImpl.java @@ -27,6 +27,8 @@ import com.yuanchu.mom.service.InsOrderService; import com.yuanchu.mom.service.StandardTemplateService; import com.yuanchu.mom.utils.GiveCode; +import com.yuanchu.mom.utils.JackSonUtil; +import com.yuanchu.mom.utils.MatrixToImageWriter; import com.yuanchu.mom.utils.QueryWrappers; import com.yuanchu.mom.vo.InsOrderPlanVO; import org.apache.poi.xwpf.usermodel.TableRowAlign; @@ -76,6 +78,9 @@ @Value("${wordUrl}") private String wordUrl; + + @Value("${twoCode}") + private String twoCode; @Resource private GiveCode giveCode; @@ -149,31 +154,39 @@ 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")); + if(jo.get("insValue") != null){ + 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")); + try { + 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); + }catch (Exception e){} } - iv.add(map); + result.setInsValue(JSON.toJSONString(iv)); } - 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); + if(jo.get("comValue") != null){ + 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)); } - 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") + ""); + if(resValue.get("v")!=null){ + 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") + ""); @@ -419,6 +432,18 @@ table.put("tableSize", tables.size() + 1); }); List<Map<String, String>> deviceList = insOrderMapper.selectDeviceList(deviceSet); + Map<String, String> codeStr = new HashMap<>(); + codeStr.put("鎶ュ憡缂栧彿", insReport.getCode()); + codeStr.put("鏍峰搧鍚嶇О", insOrder.getSample()); + codeStr.put("瑙勬牸鍨嬪彿", samples.get(0).getModel()); + codeStr.put("鍙戞斁鏃ユ湡", LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd"))); + String codePath; + try { + codePath = new MatrixToImageWriter().code(JackSonUtil.marshal(codeStr).replaceAll("\\{","") + .replaceAll("}","").replaceAll(",","").replaceAll("\"",""), twoCode); + } catch (Exception e) { + throw new RuntimeException(e); + } ConfigureBuilder builder = Configure.builder(); builder.useSpringEL(true); XWPFTemplate template = XWPFTemplate.compile(url, builder.build()).render( @@ -432,12 +457,15 @@ put("tableSize", tables.size() + 1); put("standardMethod", standardMethod2); put("deviceList", deviceList); + put("twoCode", Pictures.ofLocal(codePath).create()); }}); try { - String name = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yy_MM_dd_HH_mm_ss")) + ".docx"; + String name = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yy_MM_dd&HH_mm_ss")) + ".docx"; template.writeAndClose(Files.newOutputStream(Paths.get(wordUrl + "/" + name))); insReport.setUrl("/word/" + name); insReportMapper.insert(insReport); + insOrder.setState(4); + insOrderMapper.updateById(insOrder); } catch (IOException e) { throw new RuntimeException(e); } @@ -459,14 +487,15 @@ JSONObject sheet = JSON.parseObject(JSON.toJSONString(JSON.parseArray(JSON.toJSONString(JSON.parseObject(thing).get("data"))).get(0))); JSONObject config = JSON.parseObject(JSON.toJSONString(sheet.get("config"))); List<JSONObject> cellData = JSON.parseArray(JSON.toJSONString(sheet.get("celldata")), JSONObject.class); - List<JSONObject> tableData = new ArrayList<>(); +// List<JSONObject> tableData = new ArrayList<>(); Map<String, Object> style = new HashMap<>(); style.put("rowlen", config.get("rowlen")); style.put("columnlen", config.get("columnlen")); - int r = -1; - if (BeanUtil.isNotEmpty(cellData)) { +// int r = -1; + /*if (BeanUtil.isNotEmpty(cellData)) { for (JSONObject o : cellData) { JSONObject v = JSON.parseObject(JSON.toJSONString(o.get("v"))); + tableData.add(o); if (BeanUtil.isNotEmpty(v.get("ps"))) { JSONObject ps = JSON.parseObject(JSON.toJSONString(v.get("ps"))); if (ps.get("value").equals("妫�楠岄」") && v.get("v").equals(product.getInspectionItem())) { @@ -484,8 +513,8 @@ } } } - } - product.setTemplate(tableData); + }*/ + product.setTemplate(cellData); product.setStyle(style); } } -- Gitblit v1.9.3