Forráskód Böngészése

试验-保存
1、细集料筛分生成图表

LHB 1 hónapja
szülő
commit
44e0d1cad0

+ 121 - 3
blade-service/blade-manager/src/main/java/org/springblade/manager/service/impl/FormulaServiceImpl.java

@@ -8,6 +8,7 @@ import cn.hutool.log.StaticLog;
 import com.alibaba.fastjson.JSON;
 import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
+import com.alibaba.nacos.shaded.com.google.common.collect.Lists;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
 import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
@@ -5109,9 +5110,9 @@ public class FormulaServiceImpl extends BaseServiceImpl<FormulaMapper, Formula>
                         Long id = SnowFlakeUtil.getId();
 
                         //图片存放路径
-//                        String filePath = ParamCache.getValue(CommonConstant.SYS_LOCAL_URL);
-//                        String listPdf = filePath + "/pdf/" + id + ".png";
-                        String listPdf = "C:\\upload\\pdf\\" + id + ".jpg";
+                        String filePath = ParamCache.getValue(CommonConstant.SYS_LOCAL_URL);
+                        String listPdf = filePath + "/pdf/" + id + ".png";
+//                        String listPdf = "C:\\upload\\pdf\\" + id + ".jpg";
 
                         //土界含水率试验检测记录表
                         if(fd.getCode().contains("m_20230410104313_1645256088125177856")){
@@ -5149,7 +5150,124 @@ public class FormulaServiceImpl extends BaseServiceImpl<FormulaMapper, Formula>
                     f = f.replace(m.group(), putDataWithKey(url, tec));
                 }
             }
+            //细集料图表公式
+            if (f.contains("aggregateChart")) {
+                //x轴坐标 固定的
+                HashMap<Integer, Double> map1 = new HashMap<>();
+                map1.put(0, 4.75);
+                map1.put(1, 2.36);
+                map1.put(2, 1.18);
+                map1.put(3, 0.6);
+                map1.put(4, 0.3);
+                map1.put(5, 0.15);
+                HashMap<Integer, Double> map = new HashMap<>();
+
+
+                String tf = f.replaceAll("^T\\(com.mixsmart.utils.CustomFunction\\)\\.\\w+\\(", "").replaceAll("[)]$", "");
+                List<String> list = Arrays.asList(tf.split(","));
+                if(list.size() == 18){
+
+                    List<List<String>> partition1 = Lists.partition(list, 3);
+                    List<FormData> target = new ArrayList<>();
+                    //重新计算索引
+                    int x = 0;
+                    for (int i = 0; i < partition1.size(); i++) {
+                        List<String> strings = partition1.get(i);
+                        //按组取获取数据
+                        List<FormData> target1 = getFormDataByCode(StringUtils.join( strings,","), tec);
+                        //全部都能获取到数据
+                        if(target1.size() == strings.size()){
+                            target.addAll(target1);
+                            map.put(x,map1.get(i));
+                            x++;
+                        }
+                    }
+
+                    if(CollectionUtil.isNotEmpty(target)){
+                        //分组
+                        List<List<FormData>> partition = Lists.partition(target, 3);
+                        //长度是否匹配
+                        String url = "";
+
+                        double[][] data = new double[partition.size()][5];
+
+                        for (int i = 0; i < partition.size(); i++) {
+                            double[] doubles = new double[5];
+                            //每组的x坐标
+                            doubles[0] = map.get(i);
+                            List<FormData> formData = partition.get(i);
+
+                            //数据是否正常
+                            boolean flag = true;
+
+                            for (int j = 0; j < formData.size(); j++) {
+                                FormData formData1 = formData.get(j);
+                                if (CollectionUtil.isEmpty(formData1.getValues())) {
+                                    flag = false;
+                                    break;
+                                }
+                                if (formData1.getValues().get(0).getValue() == null) {
+                                    flag = false;
+                                    break;
+                                }
+                                String string = formData1.getValues().get(0).getValue().toString();
+                                if (StringUtil.isBlank(string)) {
+                                    flag = false;
+                                    break;
+                                }
+                                //最后一个范围数据
+                                if (string.contains("~")) {
+                                    String[] split = string.split("~");
+                                    if (ConvertUtils.canConvertToDouble(split[0])) {
+                                        doubles[j + 1] = Double.valueOf(split[0]);
+                                    }
+                                    if (ConvertUtils.canConvertToDouble(split[1])) {
+                                        doubles[j + 2] = Double.valueOf(split[1]);
+                                    }
+                                } else {
+                                    if (ConvertUtils.canConvertToDouble(string)) {
+                                        doubles[j + 1] = Double.valueOf(string);
+                                    } else {
+                                        flag = false;
+                                    }
+                                }
+
+
+                            }
+                            //数据正常才添加坐标
+                            if (flag) {
+                                data[i] = doubles;
+                            }
+                        }
+
+                        Long id = SnowFlakeUtil.getId();
+
+                        //图片存放路径
+                        String filePath = ParamCache.getValue(CommonConstant.SYS_LOCAL_URL);
+                        String listPdf = filePath + "/pdf/" + id + ".png";
+//                        String listPdf = "C:\\upload\\pdf\\" + id + ".jpg";
 
+
+                        // 创建图表生成器
+                        SieveAnalysisChart generator = new SieveAnalysisChart(data);
+
+                        // 生成图表并保存为图片
+                        generator.generateChart(listPdf, 800, 400);
+
+                        File tabPDF = ResourceUtil.getFile(listPdf);
+                        //上传至oss
+                        BladeFile bladeFile = this.newIOSSClient.uploadFile(id + ".jpg", listPdf);
+                        if (tabPDF.exists()) {
+                            tabPDF.delete();
+                        }
+                        if (bladeFile != null) {
+                            url = bladeFile.getLink();
+                        }
+                        //生成图片返回
+                        f = putDataWithKey(url, tec);
+                    }
+                }
+            }
             if (f.contains("converge")) {
                 Matcher m = RegexUtils.matcher(FC_REG + "(converge)\\(([^)]+)\\)", f);
                 while (m.find()) {