FormulaUtils.java 69 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582
  1. package com.mixsmart.utils;
  2. import cn.hutool.core.date.DatePattern;
  3. import cn.hutool.core.date.DateTime;
  4. import cn.hutool.log.StaticLog;
  5. import com.alibaba.fastjson.JSON;
  6. import com.alibaba.fastjson.JSONArray;
  7. import com.alibaba.fastjson.JSONObject;
  8. import com.alibaba.fastjson.annotation.JSONField;
  9. import com.itextpdf.text.pdf.PdfReader;
  10. import com.itextpdf.text.pdf.parser.*;
  11. import com.jfireel.expression.Expression;
  12. import org.apache.commons.lang.math.NumberUtils;
  13. import org.apache.http.*;
  14. import org.apache.http.client.HttpClient;
  15. import org.apache.http.client.entity.UrlEncodedFormEntity;
  16. import org.apache.http.client.methods.HttpGet;
  17. import org.apache.http.client.methods.HttpPost;
  18. import org.apache.http.entity.StringEntity;
  19. import org.apache.http.impl.client.HttpClientBuilder;
  20. import org.apache.http.impl.client.HttpClients;
  21. import org.apache.http.message.BasicNameValuePair;
  22. import org.apache.http.util.EntityUtils;
  23. import org.apache.poi.hssf.usermodel.HSSFDataFormatter;
  24. import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
  25. import org.apache.poi.ss.usermodel.*;
  26. import java.awt.Color;
  27. import org.jfree.chart.ChartFactory;
  28. import org.jfree.chart.ChartPanel;
  29. import org.jfree.chart.ChartUtils;
  30. import org.jfree.chart.JFreeChart;
  31. import org.jfree.chart.axis.NumberAxis;
  32. import org.jfree.chart.axis.NumberTickUnit;
  33. import org.jfree.chart.plot.PlotOrientation;
  34. import org.jfree.chart.plot.ValueMarker;
  35. import org.jfree.chart.plot.XYPlot;
  36. import org.jfree.chart.renderer.xy.XYSplineRenderer;
  37. import org.jfree.chart.title.TextTitle;
  38. import org.jfree.data.xy.XYSeries;
  39. import org.jfree.data.xy.XYSeriesCollection;
  40. import org.jsoup.Jsoup;
  41. import org.jsoup.nodes.Document;
  42. import org.jsoup.nodes.Element;
  43. import org.jsoup.select.Elements;
  44. import org.springblade.common.utils.BaseUtils;
  45. import org.springblade.common.utils.SnowFlakeUtil;
  46. import org.springblade.core.tool.utils.*;
  47. import org.springblade.manager.bean.TableInfo;
  48. import org.springblade.manager.dto.*;
  49. import org.springblade.manager.entity.Formula;
  50. import org.springblade.manager.entity.WbsTreeContract;
  51. import org.springblade.manager.formula.NodeTable;
  52. import org.springblade.manager.formula.impl.CompositeDataAccess;
  53. import org.springblade.manager.formula.impl.TableElementConverter;
  54. import org.springblade.manager.utils.FileUtils;
  55. import org.springblade.manager.vo.*;
  56. import org.springframework.core.annotation.AnnotationUtils;
  57. import reactor.core.publisher.Mono;
  58. import java.awt.*;
  59. import java.awt.Font;
  60. import java.awt.Shape;
  61. import java.awt.geom.Ellipse2D;
  62. import java.awt.geom.Rectangle2D;
  63. import java.io.*;
  64. import java.lang.annotation.Annotation;
  65. import java.lang.reflect.Field;
  66. import java.math.BigDecimal;
  67. import java.nio.charset.StandardCharsets;
  68. import java.security.MessageDigest;
  69. import java.security.NoSuchAlgorithmException;
  70. import java.util.*;
  71. import java.util.List;
  72. import java.util.concurrent.ThreadLocalRandom;
  73. import java.util.concurrent.atomic.AtomicInteger;
  74. import java.util.function.BiFunction;
  75. import java.util.function.Function;
  76. import java.util.regex.Matcher;
  77. import java.util.regex.Pattern;
  78. import java.util.stream.Collectors;
  79. import java.util.stream.IntStream;
  80. import java.util.stream.Stream;
  81. import static java.util.regex.Pattern.*;
  82. /**
  83. * @author yangyj
  84. * @Date 2022/7/14 15:55
  85. * @description 公式工具类
  86. */
  87. public class FormulaUtils {
  88. public static final String ELE_CODE_REG= "(?<=E\\[)[^]]+(?=])";
  89. public static final Pattern P = Pattern.compile(ELE_CODE_REG);
  90. /**元素标识*/
  91. public final static String E="E";
  92. /*确定各个元素在计算时的步长,算法:step=最长单元格数/当前元素单元格数*/
  93. public static LinkedHashMap<String,FormData> step(List<FormData> ele){
  94. LinkedHashMap<String,FormData> fdMap =new LinkedHashMap<>();
  95. FormData maxFormData = Collections.max(ele, Comparator.comparingInt((FormData ef)->ef.getValues().size()));
  96. FormData minFormData = Collections.min(ele, Comparator.comparingInt((FormData ef)->ef.getValues().size()));
  97. if (maxFormData.getValues().size() != minFormData.getValues().size()) {
  98. int baseLength = maxFormData.getValues().size();
  99. for (FormData formData : ele) {
  100. formData.setStep(baseLength / formData.getValues().size());
  101. }
  102. }
  103. ele.forEach(e->{
  104. fdMap.put(e.getCode(),e);
  105. });
  106. return fdMap;
  107. }
  108. /*确定公式执行环境变量*/
  109. public static List<LocalVariable> slice2Local(String f, LinkedHashMap<String,FormData> fdMap, TableElementConverter tec){
  110. CompositeDataAccess cda = new CompositeDataAccess(fdMap);
  111. List<LocalVariable> local= new ArrayList<>();
  112. while (cda.hasNext()){
  113. LinkedHashMap<String,ElementData> tip= cda.next();
  114. Map<String, Object> variable = new HashMap<>(tec.constantMap);
  115. @SuppressWarnings("unchecked")
  116. Map<String,Object> em= (Map<String, Object>) variable.computeIfAbsent(E, k->new HashMap<>());
  117. Integer index= new ArrayList<>(tip.values()).get(0).getIndex();
  118. for(Map.Entry<String,ElementData> se:tip.entrySet()){
  119. Object value=se.getValue().getValue();
  120. if(CustomFunction.isNumber(value)){
  121. if(StringUtils.isDouble(value)||f.contains("/")){
  122. em.put(se.getKey(),Double.parseDouble(value.toString()));
  123. }else{
  124. em.put(se.getKey(),StringUtils.handleObj2Integer(value));
  125. }
  126. }else{
  127. em.put(se.getKey(),StringUtils.handleNull(value).replaceAll("[ ]+","").trim());
  128. }
  129. }
  130. local.add(new LocalVariable(index,f,variable));
  131. }
  132. return local;
  133. }
  134. public static void putEle(String f,List<FormData> ele,Map<String, Object> currentMap,FormData fd){
  135. @SuppressWarnings("unchecked")
  136. Map<String,Object> em = (Map<String, Object>) currentMap.computeIfAbsent(E,(k)-> new HashMap<>());
  137. /*如果输入输出元素都是1对1*/
  138. if(f.split("[/+\\-*]").length>1&&!f.contains("{}")&&ele.stream().map(e->e.getCoordsList().size()).max(Comparator.comparingInt(e->e)).orElse(1)==1&&fd.getCoordsList().size()==1){
  139. ele.forEach(e->{
  140. Object value=e.getValues().get(0).getValue();
  141. if(CustomFunction.isNumber(value)){
  142. if(StringUtils.isDouble(value)||f.contains("/")){
  143. em.put(e.getCode(), Double.parseDouble(value.toString()));
  144. }else{
  145. em.put(e.getCode(),StringUtils.handleObj2Integer(value));
  146. }
  147. }else{
  148. em.put(e.getCode(),value);
  149. }
  150. });
  151. }else{
  152. ele.forEach(e-> em.put(e.getCode(),e.getRawValue()));
  153. }
  154. }
  155. public static final Random RD = new Random();
  156. public static Map<String,Object> triangleSquare(Object ranges){
  157. Map<String,Object> map =new HashMap<>();
  158. if(StringUtils.isEmpty(ranges)){
  159. //z的默认取值范围
  160. ranges="(0,15)";
  161. }
  162. Matcher m = RegexUtils.matcher("(\\-?\\d+)(\\D)(\\+?\\d+)",ranges.toString());
  163. if(m.find()) {
  164. int min = StringUtils.handObj2Integer(m.group(1));
  165. int max = StringUtils.handObj2Integer(m.group(3));
  166. Integer[] r = pythagorean(min, max);
  167. map.put("X", String.valueOf(r[0]));
  168. map.put("Y", String.valueOf(r[1]));
  169. map.put("Z", String.valueOf(r[2]));
  170. }
  171. return map;
  172. }
  173. /* public static void main(String[] args) {
  174. IntStream.range(0,10).boxed().forEach(i->{
  175. System.out.println(triangleSquare("-5,5"));
  176. });
  177. }*/
  178. /**
  179. * @Description 字符串相似度
  180. * @Param [s1, s2]
  181. * @return double
  182. * @Author yangyj
  183. * @Date 2023.04.12 18:01
  184. **/
  185. public static double getJaccardSimilarity(String s1, String s2) {
  186. Set<Character> set1 = new HashSet<>();
  187. Set<Character> set2 = new HashSet<>();
  188. for (char c : s1.toCharArray()) {
  189. set1.add(c);
  190. }
  191. for (char c : s2.toCharArray()) {
  192. set2.add(c);
  193. }
  194. Set<Character> intersection = new HashSet<>(set1);
  195. intersection.retainAll(set2);
  196. Set<Character> union = new HashSet<>(set1);
  197. union.addAll(set2);
  198. return (double) intersection.size() / union.size();
  199. }
  200. public static Double similarity(String s1,String s2){
  201. return getJaccardSimilarity(parseItemName(s1),parseItemName(s2));
  202. }
  203. /**
  204. * result[0]^2+result[1]^2=result[2]^2 result[] 元素均为正整数
  205. */
  206. public static Integer[] pythagorean(Integer min,Integer max){
  207. Integer[] result = null;
  208. List<Integer[]> list = new ArrayList<>();
  209. for(int i=1;i<=max;i++){
  210. for(int j=1;j<=max;j++){
  211. double tmp = Math.sqrt(Math.pow(i,2)+Math.pow(j,2));
  212. int z= (int) Math.round(tmp);
  213. if(min<z&&z<=max){
  214. Integer[] arr = new Integer[]{RD.nextBoolean()?i:-i,RD.nextBoolean()?j:-j,z};
  215. list.add(arr);
  216. }
  217. }
  218. }
  219. if(ListUtils.isNotEmpty(list)){
  220. Random rm = new Random();
  221. result = list.get(rm.nextInt(list.size()));
  222. }
  223. return result;
  224. }
  225. /*public static void main(String[] args) {
  226. FormData fd = new FormData();
  227. fd.setEName("1111");
  228. List<ElementData> list = new ArrayList<>();
  229. list.add(new ElementData(1,1,1));
  230. test(fd);
  231. System.out.println(fd.getEName());
  232. }*/
  233. /**写人元素数据,每个元素都是一个集合,每页的单元格数量乘以页数就是总长度*/
  234. public static void write(FormData fd, Object data){
  235. write(fd,data,false);
  236. }
  237. public static void write(FormData fd, Object data,Boolean retainEmpty ){
  238. if(Func.isEmpty(fd.getValues())){
  239. /*无定位信息不写入*/
  240. return;
  241. }
  242. try {
  243. /*一个单元格且存在多张,全部设置为自动拓展 20230816*/
  244. if(fd.getCoordsList().size()==1&&fd.getValues().size()>1&&fd.getFormula()!=null){
  245. fd.getFormula().setOutm(Formula.FULL);
  246. }
  247. /*写入前清空内容*/
  248. fd.getValues().forEach(t->t.setValue(null));
  249. if(data instanceof List){
  250. List<Object> values = (List<Object>) data;
  251. if(!retainEmpty){
  252. /*不包含空白内容*/
  253. values=values.stream().filter(StringUtils::isNotEmpty).collect(Collectors.toList());
  254. }
  255. if(values.size()>fd.getValues().size()){
  256. if(fd.getCoordsList().size()==1){
  257. /*元素只绑定了一个单元格的情况*/
  258. if(values.stream().filter(CustomFunction::containsZH).anyMatch(e->e.toString().contains("\n"))){
  259. fd.getValues().get(0).setValue(values.stream().filter(Objects::nonNull).map(Object::toString).collect(Collectors.joining()));
  260. }else{
  261. /*日期类型的元素只获取最后一个非空*/
  262. if(StringUtils.isEquals(4,fd.getEType())){
  263. fd.getValues().get(0).setValue(values.stream().filter(StringUtils::isNotEmpty).reduce((first, second) -> second).orElse(null));
  264. }else if(values.stream().filter(StringUtils::isNotEmpty).distinct().count()==1L){
  265. /*如果输入元素全是是一样的内容,则输入出元素则每个单元格也写入一样的内容*/
  266. values.stream().filter(StringUtils::isNotEmpty).findFirst().ifPresent(t->{
  267. for(int n=0;n<fd.getValues().size();n++){
  268. fd.getValues().get(n).setValue(t);
  269. }
  270. });
  271. }else{
  272. fd.getValues().get(0).setValue(values.stream().filter(StringUtils::isNotEmpty).map(StringUtils::handleNull).collect(Collectors.joining("、")));
  273. }
  274. }
  275. }else{
  276. for(int n=0;n<fd.getValues().size();n++){
  277. fd.getValues().get(n).setValue(values.get(n));
  278. }
  279. List<Object> overList=values.stream().skip(fd.getValues().size()).collect(Collectors.toList());
  280. List<Coords> coordsList = fd.getCoordsList();
  281. int addPage=(int)Math.ceil((double)overList.size()/(double)coordsList.size());
  282. fd.setAddPages(addPage);
  283. ElementData last =fd.getValues().get(fd.getValues().size()-1);
  284. int indexBase=last.getIndex()+1;
  285. List<ElementData> addList= new ArrayList<>();
  286. for(int i=0;i<addPage;i++){
  287. for(int j=0;j<coordsList.size();j++){
  288. /*超页就尽管写进去,格式化阶段再加表*/
  289. Coords coords = coordsList.get(j);
  290. Object v=null;
  291. int st=i*coordsList.size()+j;
  292. if(st<overList.size()){
  293. v= overList.get(st);
  294. }
  295. addList.add(new ElementData(indexBase+i,last.getGroupId(),v,coords.getX(),coords.getY()));
  296. }
  297. }
  298. fd.getValues().addAll(addList);
  299. }
  300. }else{
  301. for (int n = 0; n < values.size(); n++) {
  302. fd.getValues().get(n).setValue(values.get(n));
  303. }
  304. }
  305. }else{
  306. if(fd.getFormula()!=null&&Formula.FULL.equals(fd.getFormula().getOutm())){
  307. /*填充策略*/
  308. fd.getValues().forEach(e->e.setValue(data));
  309. }else{
  310. fd.getValues().get(0).setValue(data);
  311. }
  312. }
  313. fd.setUpdate(1);
  314. }catch (Exception e){
  315. e.printStackTrace();
  316. }
  317. }
  318. public static final String TBN_FN="TBN";
  319. /*把模型类转换成共识配置选项*/
  320. public static List<WbsFormElementVO> toElementVos(Class<?> clazz) {
  321. return DataModel.toElementVos(clazz);
  322. /* List<WbsFormElementVO> vos =new ArrayList<>();
  323. try {
  324. Field tbnField = clazz.getField(TBN_FN);
  325. String TBN = (String) tbnField.get(null);
  326. for (Field field : clazz.getDeclaredFields()) {
  327. JSONField jf = field.getAnnotation(JSONField.class);
  328. if (jf != null) {
  329. WbsFormElementVO vo = new WbsFormElementVO();
  330. vo.setEName(jf.label());
  331. vo.setTableElementKey(TBN+ StringPool.COLON +jf.name());
  332. vo.setInitTableName(TBN);
  333. vo.setId(BaseUtils.str2Long(vo.getTableElementKey()));
  334. vos.add(vo);
  335. }
  336. }
  337. }catch (Exception e){
  338. e.printStackTrace();
  339. }
  340. return vos;*/
  341. }
  342. public static String getEleKey(Class<?> clazz, String fieldName){
  343. try {
  344. Field field = clazz.getDeclaredField(fieldName);
  345. String TBN = (String) clazz.getField(TBN_FN).get(null);
  346. JSONField jf = AnnotationUtils.findAnnotation(field, JSONField.class);
  347. if (jf != null) {
  348. return TBN+StringPool.COLON+jf.name();
  349. }
  350. } catch (Exception e) {
  351. e.printStackTrace();
  352. }
  353. return StringPool.EMPTY;
  354. }
  355. public static JSONField getJSONField(Class<?> clazz, String fieldName){
  356. try {
  357. Field field = clazz.getDeclaredField(fieldName);
  358. String TBN = (String) clazz.getField(TBN_FN).get(null);
  359. JSONField jf = AnnotationUtils.findAnnotation(field, JSONField.class);
  360. if (jf != null) {
  361. return jf;
  362. }
  363. } catch (Exception e) {
  364. e.printStackTrace();
  365. }
  366. return null;
  367. }
  368. /*获取指定模型的页码元素*/
  369. public static String getPageCode(Class<?> clazz){
  370. return getEleKey(clazz,"pageCount");
  371. }
  372. public static JSONField getPageFormat(Class<?> clazz){
  373. return getJSONField(clazz,"pageCount");
  374. }
  375. /*根据数据模型实例生成带数据的元素,用于修改*/
  376. public static <T> LinkedHashMap<String,FormData> toFormDataMap(T bean){
  377. LinkedHashMap<String,FormData> result = new LinkedHashMap<>();
  378. if(bean!=null){
  379. try {
  380. @SuppressWarnings("unchecked")
  381. Map<String,String> map= JSON.parseObject(JSON.toJSONString(bean),Map.class);
  382. Class<?> clazz=bean.getClass();
  383. String TBN = (String) clazz.getField(TBN_FN).get(null);
  384. for (Field field : clazz.getDeclaredFields()) {
  385. JSONField jf = field.getAnnotation(JSONField.class);
  386. if (jf != null) {
  387. FormData fd = new FormData();
  388. fd.setCode(TBN+ StringPool.COLON +jf.name());
  389. fd.setEName(jf.label());
  390. fd.getValues().add(new ElementData(0,0,map.get(fd.getKey()),0,0));
  391. fd.getCoordsList().add(new Coords("0","0"));
  392. result.put(fd.getCode(),fd);
  393. }
  394. }
  395. }catch (Exception e){
  396. e.printStackTrace();
  397. }
  398. }
  399. return result;
  400. }
  401. /*根据数据模型建立空元素,待写入数据*/
  402. public static <T> LinkedHashMap<String,FormData> toFormDataMap(Class<T> clazz){
  403. LinkedHashMap<String,FormData> result = new LinkedHashMap<>();
  404. try {
  405. String TBN = (String) clazz.getField(TBN_FN).get(null);
  406. for (Field field : clazz.getDeclaredFields()) {
  407. JSONField jf = field.getAnnotation(JSONField.class);
  408. if (jf != null) {
  409. FormData fd = new FormData();
  410. fd.setCode(TBN+ StringPool.COLON +jf.name());
  411. fd.setEName(jf.label());
  412. fd.getCoordsList().add(new Coords("0","0"));
  413. result.put(fd.getCode(),fd);
  414. }
  415. }
  416. }catch (Exception e){
  417. e.printStackTrace();
  418. }
  419. return result;
  420. }
  421. /*把结果数据回写到元素*/
  422. public static<T>void put2FormData( LinkedHashMap<String,FormData> fdm,Map<String,Function<List<T>,List<Object>>> functionMap,List<T> dataList){
  423. fdm.values().stream()
  424. .filter(fd -> functionMap.containsKey(fd.getCode()))
  425. .forEach(fd -> {
  426. List<Object> raw = functionMap.get(fd.getCode()).apply(dataList);
  427. raw.stream().map(ElementData::new).forEach(fd.getValues()::add);
  428. });
  429. }
  430. /*根据数据模型对象,生成数据集合按字段获取数据的函数*/
  431. public static <T> Map<String, Function<List<T>, List<Object>>> fieldDataFcMap(Class<?> clazz) {
  432. Map<String, Function<T, Object>> fieldMap = functionMapBuilder(clazz);
  433. Map<String, Function<List<T>, List<Object>>> functionMap = new HashMap<>();
  434. for (Map.Entry<String, Function<T, Object>> functionEntry : fieldMap.entrySet()) {
  435. Function<List<T>, List<Object>> mapper = list -> list.stream().map(functionEntry.getValue()).collect(Collectors.toList());
  436. functionMap.put(functionEntry.getKey(), mapper);
  437. }
  438. return functionMap;
  439. }
  440. /*数据模型按字段生成内容获取函数*/
  441. public static <T> Map<String,Function<T,Object>> functionMapBuilder(Class<?> clazz){
  442. Map<String, Function<T, Object>> functionMap = new HashMap<>();
  443. try {
  444. String tbn=clazz.getField(TBN_FN).get(null).toString();
  445. for (Field field : clazz.getDeclaredFields()) {
  446. JSONField jf = field.getAnnotation(JSONField.class);
  447. if(jf!=null) {
  448. /*ordinal<=100的情况下才会生成动态行字段输出函数*/
  449. if(jf.ordinal()<=100) {
  450. String key = tbn + StringPool.COLON + jf.name();
  451. String fieldName = field.getName();
  452. Function<T, Object> function = getFunction(clazz, fieldName);
  453. functionMap.put(key, function);
  454. }
  455. }
  456. }
  457. }catch (Exception e){
  458. e.printStackTrace();
  459. }
  460. return functionMap;
  461. }
  462. private static <T> Function<T, Object> getFunction(Class<?> clazz, String fieldName) {
  463. return certificate -> {
  464. try {
  465. Field field = clazz.getDeclaredField(fieldName);
  466. field.setAccessible(true);
  467. return field.get(certificate);
  468. } catch (Exception e) {
  469. e.printStackTrace();
  470. return null;
  471. }
  472. };
  473. }
  474. /*list转TreeNode*/
  475. public static <K,T> Map<K, TreeNode<T>> list2TreeNode(Function<TreeNode<T>,K> keyMapper,List<T> list,Function<T,TreeNode<T>> fc,Function<TreeNode<T>,K> classifier){
  476. Map<K, TreeNode<T>> mTreeMap = new HashMap<>();
  477. if (Func.isNotEmpty(list)) {
  478. for (T mt : list) {
  479. try {
  480. TreeNode<T> treeNode = fc.apply(mt);
  481. mTreeMap.put(keyMapper.apply(treeNode), treeNode);
  482. }catch (Exception e){
  483. e.printStackTrace();
  484. }
  485. }
  486. Map<K, List<TreeNode<T>>> group = mTreeMap.values().stream().collect(Collectors.groupingBy(classifier));
  487. group.forEach((k, v) -> {
  488. TreeNode<T> parent = mTreeMap.get(k);
  489. if (parent != null) {
  490. v = v.stream().sorted(Comparator.comparingInt(TreeNode::getSort)).collect(Collectors.toList());
  491. parent.setChildren(v);
  492. v.forEach(e -> e.setParent(parent));
  493. }
  494. });
  495. }
  496. return mTreeMap;
  497. }
  498. /*TreeNode 排序*/
  499. public static <T> void treeNodeSort(int base,TreeNode<T> top){
  500. top.setSort(base);
  501. if(top.hasChildren()){
  502. for(TreeNode<T> child:top.getChildren()){
  503. child.setSort(base++);
  504. }
  505. }
  506. }
  507. /*回溯标记*/
  508. public static <T> void treeNodeChecked( TreeNode<T> tmp){
  509. int loop = 10;
  510. do{
  511. if(tmp.isChecked()) {
  512. /*已经检出则停止循环*/
  513. loop=0;
  514. }else{
  515. tmp.setChecked(true);
  516. tmp=tmp.getParent();
  517. }
  518. }while (tmp!=null&&loop-->0);
  519. }
  520. /*获取层级链*/
  521. public static <T> List<T> treeNodeChains( TreeNode<T> tmp){
  522. List<T> result = new ArrayList<>();
  523. int loop = 10;
  524. do{
  525. /*不包括顶层*/
  526. if(tmp.getParentId()!=0L) {
  527. result.add(tmp.getValue());
  528. }
  529. tmp=tmp.getParent();
  530. }while (tmp!=null&&loop-->0);
  531. Collections.reverse(result);
  532. return result;
  533. }
  534. /**从元素名称中解析项目名称,细化项目匹配用*/
  535. public static String parseItemName(String eName){
  536. if (StringUtils.isEmpty(eName)) {
  537. return eName;
  538. }
  539. String str = eName.replaceAll("\\s", "");
  540. Pattern pattern = compile("[((][^\\u4e00-\\u9fa5]+[))]|_+");
  541. String[] candidate = pattern.split(str);
  542. /*非中文非罗马数字1到10*/
  543. String regex = "[^\\u4e00-\\u9fa5\\u2160-\\u2169))((]+";
  544. Pattern p = compile(regex);
  545. return Arrays.stream(candidate)
  546. .filter(s -> !isContainKeywords(s))
  547. .map(s -> filterString(s, p))
  548. .collect(Collectors.joining());
  549. }
  550. /*A15检查内容专用*/
  551. public static String checkItemName(String eName){
  552. if (StringUtils.isEmpty(eName)) {
  553. return eName;
  554. }
  555. /*分割字符串,选取第一个匹配的子串*/
  556. String str = eName.replaceAll("\\s", "");
  557. Pattern pattern = compile("[((][^\\u4e00-\\u9fa5]+[))]|_+");
  558. String[] candidate = pattern.split(str);
  559. String regex = "[^\\u4e00-\\u9fa5]+";
  560. return Arrays.stream(candidate).map(s->s.replaceAll(regex,"")).distinct().filter(StringUtils::isNotEmpty).filter(s->!isContainKeywords2(s)).findFirst().orElse("");
  561. }
  562. private static String filterString(String s, Pattern p) {
  563. s=s.replaceAll("【[^【】]+】","");
  564. Matcher matcher = p.matcher(s);
  565. return matcher.replaceAll("").replaceAll(getRegex(), "").replaceAll("(设计|合格).*","");
  566. }
  567. private static String getRegex() {
  568. return "(在合格标准内|满足设计要求|质量评定|评定|判定|项目|总数|抽测|实测|偏差|尺量|关键|一般)";
  569. }
  570. private static boolean isContainKeywords(String s) {
  571. List<String> keywords = Arrays.asList( ":", "个","附录","抽查","测","求","小于","大于","检查","仪","按","不","各","记录","且","规定","值或实","≤","≥","平均");
  572. return keywords.stream().anyMatch(s::contains);
  573. }
  574. private static boolean isContainKeywords2(String s) {
  575. List<String> keywords = Arrays.asList( "项目");
  576. return keywords.stream().anyMatch(s::contains);
  577. }
  578. /**回归·测试变量*/
  579. public static List<String> itemNames =Arrays.asList(
  580. ""
  581. ,"压 实 度 (%)下路床 特重、极重交通荷载等级 设计值"
  582. ,"1△_压 实 度 (%)_下路床_轻、中及重交通 荷载等级_0.3m~0.8m_≧96_≧95_≧94_实测值或实测偏差值"
  583. ,"1△_压 实 度 (%)_下路提_轻、中及重交通 荷载等级_&gt;1.5m_≧93_≧92_≧90_实测值或实测偏差值"
  584. ,"1△_压 实 度 (%)_上路提_轻、中及重交通 荷载等级_0.8m~1.5m_≧94_≧94_≧93_实测值或实测偏差值"
  585. ,"压 实 度 (%)下路提 轻、中及重交通荷载等级 设计值"
  586. ,"压 实 度 (%)下路床 特重、极重交通荷载等级 合格率"
  587. ,"压 实 度 (%)下路提 轻、中及重交通荷载等级\t合格率"
  588. ,"5△_保护层 厚度 (mm)_基础、锚碇、墩台身、墩柱_±10_实测值或实测偏差值"
  589. ,"钢筋骨架尺寸宽、高或直径 (mm)_尺量:按骨架总数30%抽测_±5_实测值或实测偏差值"
  590. ,"钢筋骨架尺寸长 (mm)_±10_尺量:按骨架总数30%抽测_实测值或实测偏差值"
  591. , "受力钢筋间距 (mm)同排 梁、板、拱肋及拱上建筑 设计值"
  592. ,"受力钢筋间距 (mm)同排 梁、板、拱肋及拱上建筑 合格率"
  593. ," 箍筋、构造钢筋、螺旋筋间距(mm) 设计值"
  594. ,"箍筋、构造钢筋、螺旋筋间距(mm) 合格率"
  595. ,"实测项目_桩位 (mm)_群桩_≤100_质量评定_合格判定"
  596. ,"实测项目_桩位 (mm)_群桩_≤100_实测值或实测偏差值"
  597. ,"实测项目_桩位 (mm)_排架桩_实测值或实测偏差值"
  598. ,"实测项目_桩位 (mm)_排架桩_质量评定_合格判定"
  599. ,"实测项目_桩位 (mm)_群桩_≤100_质量评定_合格率(%)"
  600. ,"实测项目_桩位 (mm)_排架桩_质量评定_合格率(%)"
  601. ,"3△_支座高程(mm)_满足设计要求;设 计未要求时±5_水准仪:测每支座中心线_实测值或实测偏差值"
  602. ,"基底承载力(KPa)_不小于设计_直观或动力触探试验_实测值或实测偏差值"
  603. ,"实 测 项 目_花卉数量_满足设计要求_实测值或实测偏差值"
  604. ,"实 测 项 目_2△_草坪、草本地被覆盖率(%)_取弃土场绿 地_≥90_实测值或实测偏差值"
  605. ,"轴线偏位(mm)_全站仪:20m检查3点_实测值或实测偏差值"
  606. ,"1△_基材混合物喷射厚度(mm)_设计厚度±10_实测值或实测偏差值"
  607. ,"1△_混凝土强度 (MPA)_在合格标准内_按附录D检查_实测值或实测偏差值"
  608. ,"边坡坡度_不陡于设计值_水准仪:每200m测2点,且不少于5点_实测值或实测偏差值"
  609. ,"几何尺寸(mm)_±50_尺量:长、宽、高、壁厚各2点_实测值或实测偏差值"
  610. ,"4△_桩长(mm)_不小于设计_查施工记录_实测值或偏差值"
  611. ,"单桩每延米喷粉 (浆)量_不小于设计_查施工记录_实测值或偏差值"
  612. ,"搭接宽度(mm)_≥150【纵向】_尺量:抽查2%_实测值或实测偏差值",
  613. "搭接宽度(mm)_≥50(横向)_尺量:抽查2%_实测值或实测偏差值"
  614. ,"竖直度(mm)_挖孔桩_0.5%桩长,且≤200_铅锤线:每桩检测_实测值或实测偏差值"
  615. , "2△_压浆压力值 (Mpa)_满足施工技术 规范规定_查油压表读书;每管道检查_实测值或实测偏差值"
  616. , "基底承载力(KPa)_不小于设计_实测值或实测偏差值"
  617. ,"1△_受力钢筋间距 (mm)_两排以上间距_±5_实测值或实测偏差值"
  618. ,"1△梁(板)长度 (mm)_±5_实测值或实测偏差值"
  619. ,"墙面平整度(mm)_施工缝、变形缝处≤20_实测值或实测偏差值"
  620. ,"基底承载力(KPa)_不小于设计_实测值或实测偏差值"
  621. ,"1△_拱部超挖(mm)_Ⅱ、Ⅲ、Ⅳ级围岩(中硬岩 、软岩)_平均150,最大250_实测值或实测偏差值"
  622. ,"实 测 项 目_关键项目_压实度(%)_上路堤_轻、中及重交通荷载等级_0.8~1.5m_≥94_≥94_≥93_检查情况 (实测值)"
  623. );
  624. /*
  625. public static void main(String[] args) {
  626. itemNames.stream().map(FormulaUtils::parseItemName).forEach(System.out::println);
  627. //itemNames.stream().map(FormulaUtils::checkItemName).forEach(System.out::println);
  628. }
  629. */
  630. public static Object getValue(Cell cell) {
  631. if (cell != null) {
  632. switch (cell.getCellTypeEnum()) {
  633. case STRING:
  634. return cell.getStringCellValue() == null ? null : cell.getStringCellValue().trim();
  635. case NUMERIC:
  636. HSSFDataFormatter dataFormatter = new HSSFDataFormatter();
  637. return dataFormatter.formatCellValue(cell);
  638. case BOOLEAN:
  639. return cell.getBooleanCellValue();
  640. case ERROR:
  641. return cell.getErrorCellValue();
  642. case FORMULA:
  643. try {
  644. return cell.getStringCellValue();
  645. } catch (IllegalStateException e) {
  646. return "";
  647. }
  648. default:
  649. cell.setCellType(CellType.STRING);
  650. return cell.getStringCellValue() == null ? null : cell.getStringCellValue().trim();
  651. }
  652. }
  653. return null;
  654. }
  655. public static List<ElementData> getElementDataList(String coords,String values){
  656. if(StringUtils.isNotEmpty(coords,values)){
  657. List<Coords> coordsList = Stream.of(coords).flatMap(s -> Arrays.stream(s.split(";"))).map(s -> {
  658. String[] xy = s.split("_");
  659. return new Coords(xy[1], xy[0]);
  660. }).collect(Collectors.toList());
  661. return str2ElementData(values,coordsList,null,null);
  662. }
  663. return Collections.emptyList();
  664. }
  665. public static List<ElementData> str2ElementData(String pg, List<Coords> coordsList ,String code,Integer index){
  666. List<ElementData> eds = new ArrayList<>();
  667. if(StringUtils.isNotEmpty(pg)&&ListUtils.isNotEmpty(coordsList)) {
  668. if(code==null){
  669. code="code";
  670. }
  671. if(index==null){
  672. index=1;
  673. }
  674. String[] val = pg.split("☆");
  675. Map<String, Object> tmpMap = new LinkedHashMap<>();
  676. for (String s : val) {
  677. String[] t = s.split("_\\^_");
  678. String[] c = t[1].split("_");
  679. tmpMap.put(StringUtils.join(code, 0, index, Func.toInt(c[1]), Func.toInt(c[0]), StringPool.AT), t[0]);
  680. }
  681. for (Coords c : coordsList) {
  682. Object data = null;
  683. String key = StringUtils.join(code, 0, index, c.getX(), c.getY(), StringPool.AT);
  684. if (tmpMap.containsKey(key)) {
  685. data = tmpMap.get(key);
  686. }
  687. eds.add(new ElementData(index, 0, data, c.getX(), c.getY()));
  688. }
  689. }
  690. return eds;
  691. }
  692. /**
  693. * @Description Poi 动态执行公式 测试
  694. * @Param [url]
  695. * @Author yangyj
  696. * @Date 2023.05.05 14:28
  697. **/
  698. public static void evaluateFormulaCell(String url) {
  699. try {
  700. url="C:/Users/yangyj/Desktop/test.xlsx";
  701. Workbook workbook = WorkbookFactory.create(new File(url));
  702. Sheet sheet = workbook.getSheetAt(0);
  703. Cell cell = sheet.getRow(0).getCell(0);
  704. FormulaEvaluator evaluator = workbook.getCreationHelper().createFormulaEvaluator();
  705. CellType cellType = evaluator.evaluateFormulaCellEnum(cell);
  706. if (cellType == CellType.NUMERIC) {
  707. double value = cell.getNumericCellValue();
  708. System.out.println("公式计算结果:" + value);
  709. } else if (cellType == CellType.STRING) {
  710. String value = cell.getStringCellValue();
  711. System.out.println("公式计算结果:" + value);
  712. }
  713. cell.setCellFormula("B1+C1+D1");
  714. evaluator.clearAllCachedResultValues();
  715. cellType = evaluator.evaluateFormulaCellEnum(cell);
  716. if (cellType == CellType.NUMERIC) {
  717. double value = cell.getNumericCellValue();
  718. System.out.println("公式计算结果:" + value);
  719. } else if (cellType == CellType.STRING) {
  720. String value = cell.getStringCellValue();
  721. System.out.println("公式计算结果:" + value);
  722. }
  723. }catch (IOException | InvalidFormatException e){
  724. e.printStackTrace();
  725. }
  726. }
  727. public static Map<String, String> getElementCell(String uri){
  728. return getElementCell(uri,null,null);
  729. }
  730. public static Map<String, String> getElementCell(String uri,String key) {
  731. return getElementCell(uri,key,null);
  732. }
  733. public static Map<String, String> getElementCell(String uri,String key,Document document) {
  734. try {
  735. String filter=" [keyname]";
  736. if(Func.isNotBlank(key)){
  737. filter="[keyname^="+key+"__]";
  738. }
  739. if(document==null){
  740. InputStream inputStreamByUrl = FileUtils.getInputStreamByUrl(uri);
  741. document=Jsoup.parse(IoUtil.readToString(inputStreamByUrl));
  742. }
  743. Map<String,String> result= document
  744. .select("table").first()
  745. .select(filter).stream()
  746. .map(d -> d.attr("keyname")).filter(StringUtils::isNotEmpty).map(e -> e.split("__"))
  747. .collect(
  748. Collectors.toMap(
  749. b -> b[0],
  750. b -> b[1],
  751. (v1, v2) -> v1 + ";" + v2
  752. )
  753. );
  754. if(result.size()>0){
  755. for(Map.Entry<String,String> entry:result.entrySet()){
  756. entry.setValue(FormulaUtils.coordsSorted(entry.getValue()));
  757. }
  758. }
  759. return result;
  760. }catch (Exception e){
  761. e.printStackTrace();
  762. return new HashMap<>();
  763. }
  764. }
  765. public static Map<String, String> getElementExcelCoords(String uri){
  766. return getElementExcelCoords(uri,null,null);
  767. }
  768. public static Map<String, String> getElementExcelCoords(Document document){
  769. return getElementExcelCoords(null,null,document);
  770. }
  771. public static Map<String, String> getElementExcelCoords(String uri,String key,Document document){
  772. try {
  773. String filter=" [keyname]";
  774. if(Func.isNotBlank(key)){
  775. filter="[keyname^="+key+"__]";
  776. }
  777. if(document==null){
  778. InputStream inputStreamByUrl = FileUtils.getInputStreamByUrl(uri);
  779. document=Jsoup.parse(IoUtil.readToString(inputStreamByUrl));
  780. }
  781. Map<String,String> result= document
  782. .select("table").first()
  783. .select(filter).stream()
  784. .filter(d -> Func.isNotEmpty(d.attr("keyname"))).filter(StringUtils::isNotEmpty).map(e ->new String[]{e.attr("keyname").split("__")[0],e.attr("y1")+"_"+e.attr("x1")})
  785. .collect(
  786. Collectors.toMap(
  787. b -> b[0],
  788. b -> b[1],
  789. (v1, v2) -> v1 + ";" + v2
  790. )
  791. );
  792. if(result.size()>0){
  793. for(Map.Entry<String,String> entry:result.entrySet()){
  794. entry.setValue(FormulaUtils.coordsSorted(entry.getValue()));
  795. }
  796. }
  797. return result;
  798. }catch (Exception e){
  799. e.printStackTrace();
  800. return new HashMap<>();
  801. }
  802. }
  803. /*解析html里的电签关键字*/
  804. public static Map<String,String> getESignMap(Document document){
  805. Map<String,String> result = new HashMap<>();
  806. if(document!=null) {
  807. Elements list = document.getElementsByAttribute("dqid");
  808. if (list != null && !list.isEmpty()) {
  809. list.stream().forEach(e -> {
  810. String dqid = e.attr("dqid");
  811. int y1=0;
  812. int x1=0;
  813. if (!e.hasAttr("y1") && !e.hasAttr("x1")&&e.children().size()>0) {
  814. Element element = e.children().get(0);
  815. y1 = Func.toInt(element.attr("y1"));
  816. x1 = Func.toInt(element.attr("x1"));
  817. }else {
  818. y1 = Func.toInt(e.attr("y1"));
  819. x1 = Func.toInt(e.attr("x1"));
  820. }
  821. result.put(y1+"_"+x1,dqid);
  822. });
  823. }
  824. }
  825. return result;
  826. }
  827. public static List<ElementData> setScale(Integer scale, List<ElementData> data){
  828. if(scale==null){
  829. scale=StringUtils.getScale(data.stream().map(ElementData::getValue).filter(StringUtils::isDouble).collect(Collectors.toList()));
  830. }
  831. Integer finalScale = scale;
  832. return data.stream().peek(e->{if(StringUtils.isDouble(e.getValue())){e.setValue(StringUtils.number2StringZero(e.getValue(),finalScale));}}).collect(Collectors.toList());
  833. }
  834. /**
  835. * @Description 定位信息排序
  836. * @Param [coords]
  837. * @return java.lang.String
  838. * @Author yangyj
  839. * @Date 2023.07.11 15:39
  840. **/
  841. public static String coordsSorted(String coords){
  842. if(StringUtils.isNotEmpty(coords)){
  843. List<String> dataList=Arrays.asList(coords.split(";"));
  844. if(dataList.size()>2){
  845. LinkedList<Integer> list=dataList.stream().map(e->e.split("_")[1]).distinct().map(Integer::parseInt).sorted(Comparator.comparingInt(e->e)).collect(Collectors.toCollection(LinkedList::new));
  846. if(list.getLast()-list.getFirst()>list.size()-1){
  847. coords=dataList.stream()
  848. .sorted(Comparator.comparingInt((String str) -> Integer.parseInt(str.split("_")[1]))
  849. .thenComparingInt(str -> Integer.parseInt(str.split("_")[0])))
  850. .collect(Collectors.joining(";"));
  851. }
  852. }
  853. }
  854. return coords;
  855. }
  856. public static String coordsSorted2(String coords){
  857. if(StringUtils.isNotEmpty(coords)){
  858. List<String> dataList=Arrays.asList(coords.split(";"));
  859. if(dataList.size()>2){
  860. /*判断分区:根据行列长度*/
  861. List<Integer> row =dataList.stream().map(e->e.split("_")[0]).distinct().map(Integer::parseInt).collect(Collectors.toList());
  862. List<Integer> column=dataList.stream().map(e->e.split("_")[1]).distinct().map(Integer::parseInt).collect(Collectors.toList());
  863. if(row.size()>=column.size()){
  864. /*纵向*/
  865. if(column.size()>1){
  866. List<List<Integer>> consecutiveGroups = IntStream.range(0, column.size())
  867. .boxed()
  868. .collect(Collectors.collectingAndThen(
  869. Collectors.groupingBy(
  870. i -> i - column.get(i),
  871. LinkedHashMap::new,
  872. Collectors.mapping(column::get, Collectors.toList())
  873. ),
  874. map -> new ArrayList<>(map.values())
  875. ));
  876. }
  877. }
  878. /* 确定区内方向:*/
  879. }
  880. }
  881. return coords;
  882. }
  883. /* public static void main(String[] args) {
  884. List<Integer> column = Arrays.asList(1, 2, 3, 5, 6, 7, 9, 11, 17);
  885. List<List<Integer>> consecutiveGroups = IntStream.range(0, column.size())
  886. .boxed()
  887. .collect(Collectors.collectingAndThen(
  888. Collectors.groupingBy(
  889. i -> i - column.get(i),
  890. LinkedHashMap::new,
  891. Collectors.mapping(column::get, Collectors.toList())
  892. ),
  893. map -> new ArrayList<>(map.values())
  894. ));
  895. AtomicInteger i = new AtomicInteger(column.get(0));
  896. List<List<Integer>> consecutiveGroups2= new ArrayList<>(column.stream().collect(Collectors.groupingBy(e -> e - i.getAndSet(e) > 1, LinkedHashMap::new, Collectors.toList())).values());
  897. System.out.println();
  898. }*/
  899. public static List<Object> slice(List<LocalVariable> local, String formula){
  900. int min =0;
  901. List<Object> result = new ArrayList<>();
  902. try {
  903. pretreatment(local,formula);
  904. List<Object> r= local.stream().map(e-> {
  905. /*所有依赖元素的内容必须非空才进行计算,否则返回空值*/
  906. return e.hasEmptyElementValue()?"": Expression.parse(e.getFormula()).calculate(e.getCurrentMap()).toString();
  907. }).collect(Collectors.toList());
  908. if(CollectionUtil.isNotEmpty(r)&&r.stream().anyMatch(StringUtils::isNotEmpty)){
  909. result.addAll(r);
  910. }
  911. }catch (Exception e){
  912. StaticLog.error("公式:{},执行出错",formula);
  913. }
  914. return result;
  915. }
  916. public static void pretreatment(List<LocalVariable> local,String formula){
  917. formula=StringUtils.removeMultiSpace(formula);
  918. if(formula.contains("LIST")){
  919. Matcher m=RegexUtils.matcher("\\(([^)]*)\\)/LIST",formula);
  920. while (m.find()){
  921. List<String> codes=getCodeList(m.group(1).replaceAll("[+-]",","));
  922. local=local.stream().peek(e->{
  923. @SuppressWarnings("unckecked")
  924. Map<String,Object> map = (Map<String, Object>) e.getCurrentMap().getOrDefault("E",new HashMap<>());
  925. int listSize=(int)codes.stream().filter(c->StringUtils.isNotEmpty(map.get(c))).count();
  926. if(listSize<=0||listSize>codes.size()){
  927. listSize=codes.size();
  928. }
  929. map.put("LIST",listSize);
  930. }).collect(Collectors.toList());
  931. }
  932. }
  933. }
  934. /**从方法参数中获取全部code*/
  935. public static List<String> getCodeList(String param){
  936. List<String> list = new ArrayList<>();
  937. if(StringUtils.isNotEmpty(param)){
  938. Arrays.stream(param.split(",")).forEach(s->{
  939. list.add(s.replaceAll("[E\\[\\]']",""));
  940. });
  941. }
  942. return list;
  943. }
  944. /**从时间段中获取最后一个日期*/
  945. static final String RANGE_DATE_REG="^\\[(\\d{4}[年.\\-]\\d{2}[月.\\-]\\d{2}[日]?),\\s+(\\d{4}[年.\\-]\\d{2}[月.\\-]\\d{2}[日]?)]$";
  946. public static String range2end(String t){
  947. if(t!=null&&Pattern.matches(RANGE_DATE_REG,t)){
  948. t=t.replaceAll("^\\[|]$","").split(",")[1].trim();
  949. }
  950. return t;
  951. }
  952. public static List<String> duration2date(String duration){
  953. try {
  954. if (duration != null && Pattern.matches(RANGE_DATE_REG, duration)) {
  955. return Arrays.stream(duration.replaceAll("^\\[|]$", "").split(",")).map(String::trim).map(s -> new DateTime(s).toString(DatePattern.NORM_DATE_PATTERN)).collect(Collectors.toList());
  956. }
  957. return Collections.singletonList(new DateTime(duration).toString(DatePattern.NORM_DATE_PATTERN));
  958. }catch (Exception e){
  959. return Collections.singletonList(new DateTime().toString(DatePattern.NORM_DATE_PATTERN));
  960. }
  961. }
  962. public static FormData createFormDataFast(String name,String code,String values,String coords){
  963. if(StringUtils.isNotEmpty(code,name)){
  964. if(StringUtils.isNotEmpty(coords)) {
  965. /*定位信息存在才合法*/
  966. List<Coords> coordsList = Stream.of(coords).flatMap(s -> Arrays.stream(s.split(";"))).map(s -> {
  967. String[] xy = s.split("_");
  968. return new Coords(xy[1], xy[0]);
  969. }).collect(Collectors.toList());
  970. List<ElementData> eds = new ArrayList<>();
  971. if (StringUtils.isNotEmpty(values)) {
  972. String[] pages = values.split(";;");
  973. for (int index = 0; index < pages.length; index++) {
  974. String pg = pages[index];
  975. if (Func.isNotBlank(pg)) {
  976. String[] val = pg.split("☆");
  977. Map<String, Object> tmpMap = new LinkedHashMap<>();
  978. for (String s : val) {
  979. String[] t = s.split("_\\^_");
  980. String[] c = t[1].split("_");
  981. tmpMap.put(StringUtils.join(code, 0, index, Func.toInt(c[1]), Func.toInt(c[0]), StringPool.AT), t[0]);
  982. }
  983. for (Coords c : coordsList) {
  984. Object data = null;
  985. String key = StringUtils.join(code, 0, index, c.getX(), c.getY(), StringPool.AT);
  986. if (tmpMap.containsKey(key)) {
  987. data = tmpMap.get(key);
  988. }
  989. eds.add(new ElementData(index, 0, data, c.getX(), c.getY()));
  990. }
  991. }
  992. }
  993. } else {
  994. eds = coordsList.stream().map(c -> new ElementData(0, 0, null, c.getX(), c.getY())).collect(Collectors.toList());
  995. }
  996. FormData one = new FormData(code, eds, null, coords);
  997. one.setEName(name);
  998. /*备份原始数据,用于更新比较*/
  999. one.init();
  1000. return one;
  1001. }
  1002. }
  1003. return null;
  1004. }
  1005. public static void mainT(String[] args) throws IOException {
  1006. XYSeries series = new XYSeries("Data Series");
  1007. series.add(10.2, 1.82);
  1008. series.add(11.9, 1.86);
  1009. series.add(15.9, 1.87);
  1010. series.add(19.3, 1.85);
  1011. series.add(20.3, 1.80);
  1012. XYSeriesCollection dataset = new XYSeriesCollection();
  1013. dataset.addSeries(series);
  1014. JFreeChart chart = ChartFactory.createXYLineChart(
  1015. "测试散点图", // 标题
  1016. "X", // 横轴标题
  1017. "Y", // 纵轴标题
  1018. dataset, // 数据集
  1019. PlotOrientation.VERTICAL, // 图表方向
  1020. true, // 是否显示图例
  1021. false, // 是否生成工具提示
  1022. false // 是否生成URL链接
  1023. );
  1024. // 设置字体
  1025. Font titleFont = new Font("SimSun", Font.PLAIN, 18); // 指定使用宋体字体
  1026. Font axisFont = new Font("SimSun", Font.PLAIN, 12); // 指定使用宋体字体
  1027. // 设置标题字体
  1028. TextTitle title = chart.getTitle();
  1029. title.setFont(titleFont);
  1030. XYPlot plot = (XYPlot) chart.getPlot();
  1031. XYSplineRenderer renderer = new XYSplineRenderer();
  1032. plot.setRenderer(renderer);
  1033. plot.setBackgroundPaint(Color.WHITE);
  1034. // Set the line stroke and shape for the renderer
  1035. renderer.setSeriesStroke(0, new BasicStroke(2.0f));
  1036. Shape circle = new Ellipse2D.Double(-3, -3, 6, 6);
  1037. renderer.setSeriesShape(0, circle);
  1038. renderer.setSeriesPaint(0, Color.BLUE);
  1039. // 自定义 X 轴刻度
  1040. NumberAxis domainAxis = (NumberAxis) plot.getDomainAxis();
  1041. domainAxis.setTickUnit(new NumberTickUnit(5)); // 设置刻度间隔
  1042. domainAxis.setRange(0.0, 25); // 设置轴的范围
  1043. // 自定义 Y 轴刻度
  1044. NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
  1045. rangeAxis.setTickUnit(new NumberTickUnit(0.01)); // 设置刻度间隔
  1046. rangeAxis.setRange(1.79, 1.90); // 设置轴的范围
  1047. // 添加横杠
  1048. for(int i=175;i<190;i++){
  1049. ValueMarker marker = new ValueMarker((double) i /100);
  1050. marker.setPaint(Color.BLUE); // 横杠的颜色
  1051. plot.addRangeMarker(marker);
  1052. }
  1053. ChartPanel chartPanel = new ChartPanel(chart);
  1054. chartPanel.setPreferredSize(new Dimension(500, 400));
  1055. // 保存图表为图片
  1056. int width = 800;
  1057. int height = 600;
  1058. ChartUtils.saveChartAsPNG(new File("C:/Users/yangyj/Desktop/Swap_space/poi_statistics.png"), chart, width, height);
  1059. }
  1060. /**字符串sha256映射*/
  1061. public static String sha256(String input) {
  1062. try {
  1063. MessageDigest digest = MessageDigest.getInstance("SHA-256");
  1064. byte[] encodedHash = digest.digest(input.getBytes(StandardCharsets.UTF_8));
  1065. StringBuilder hexString = new StringBuilder();
  1066. for (byte b : encodedHash) {
  1067. String hex = Integer.toHexString(0xff & b);
  1068. if (hex.length() == 1) {
  1069. hexString.append('0');
  1070. }
  1071. hexString.append(hex);
  1072. }
  1073. return hexString.toString();
  1074. } catch (NoSuchAlgorithmException e) {
  1075. e.printStackTrace();
  1076. }
  1077. return "";
  1078. }
  1079. /**根据步长获取字符*/
  1080. public static String getEveryNthChar(String input, int step) {
  1081. StringBuilder result = new StringBuilder();
  1082. for (int i = 0; i < input.length(); i += step) {
  1083. result.append(input.charAt(i));
  1084. }
  1085. return result.toString();
  1086. }
  1087. /**最大循环次数*/
  1088. public static int MAX_LOOP=20;
  1089. /**
  1090. * @Description 当前提交表单数据公式执行最小影响元素范围
  1091. * @Param [curTableNames:当前提交页面对应表编号, processFds:当前工序包含的所有元素]
  1092. * @Author yangyj
  1093. * @Date 2023.10.09 15:26
  1094. **/
  1095. public static List<FormData> registerFd(List<String> curTableNames, List<FormData> processFds){
  1096. Map<Boolean,List<FormData>> group = processFds.stream().collect(Collectors.partitioningBy(e->curTableNames.contains(e.getTableName())));
  1097. List<FormData> curFormDatas =group.get(true);
  1098. /*提交叶包含元素*/
  1099. List<FormData> initiator= new ArrayList<>(curFormDatas);
  1100. List<FormData> other=group.get(false);
  1101. /*当前提交页元素影响到的元素都要重新执行公式*/
  1102. pick(curFormDatas,other,curFormDatas,fds->fds.stream().map(FormData::getCode).collect(Collectors.toSet()));
  1103. /*当前提交页的元素公式依赖加载*/
  1104. pick(initiator,other,curFormDatas,fds->fds.stream().filter(f->f.executable()&&f.getFormula().getRely()!=null).flatMap(f->f.getFormula().getRelyList().stream()).collect(Collectors.toSet()));
  1105. return curFormDatas;
  1106. }
  1107. /**
  1108. * @Description 调训符合条件的元素
  1109. * @Param [initiator 初始集合, other 待选集合, curFormDatas 结果集, function:挑选方法]
  1110. * @Author yangyj
  1111. * @Date 2023.10.12 14:53
  1112. **/
  1113. public static void pick(List<FormData> initiator,List<FormData> other,List<FormData> curFormDatas ,Function<List<FormData>,Set<String>> function){
  1114. List<FormData> curFormDatasAdd=new ArrayList<>(initiator);
  1115. int loop=0;
  1116. do{
  1117. loop++;
  1118. Set<String> codeSet= function.apply(curFormDatasAdd);
  1119. Map<Boolean,List<FormData>> groupTmp = other.stream().collect(Collectors.partitioningBy(e->codeSet.contains(e.getCode())));
  1120. curFormDatasAdd=groupTmp.get(true);
  1121. if(curFormDatasAdd.isEmpty()){
  1122. loop=MAX_LOOP;
  1123. }else{
  1124. curFormDatas.addAll(curFormDatasAdd);
  1125. }
  1126. other=groupTmp.get(false);
  1127. }while (!other.isEmpty()&&loop<MAX_LOOP);
  1128. }
  1129. /**最小加载页面,只要包含当前提交元素的页面都需要加载*/
  1130. public static Map<String,List<Long>> relatedPages(List<FormData> curFormDatas ,List<NodeTable> tableAll){
  1131. Set<String> initTableNames= curFormDatas.stream().map(FormData::getTableName).collect(Collectors.toSet());
  1132. return tableAll.stream().filter(e->initTableNames.contains(e.getInitTableName())).collect(Collectors.groupingBy(NodeTable::getInitTableName,Collectors.mapping(NodeTable::getPKeyId,Collectors.toList())));
  1133. }
  1134. /*比较两组单元格内容是否一样*/
  1135. public static boolean compareElementDataList(List<ElementData> before ,List<ElementData> cur){
  1136. if(Func.isNotEmpty(before)&&Func.isNotEmpty(cur)&&before.size()==cur.size()){
  1137. String sa= before.stream().map(ElementData::stringValue).collect(Collectors.joining());
  1138. String sc= cur.stream().map(ElementData::stringValue).collect(Collectors.joining());
  1139. return sa.equals(sc);
  1140. }
  1141. return false;
  1142. }
  1143. /**分割treeCode*/
  1144. public static List<String> treeCodeSplit(String treeCode){
  1145. List<String> result = new ArrayList<>();
  1146. if(Func.isNotBlank(treeCode)){
  1147. /*字符总长度*/
  1148. int max =treeCode.length()-3,
  1149. /*累计字符长度字符*/
  1150. sum=0,
  1151. /*第几次循环*/
  1152. count=0;
  1153. do{
  1154. result.add(treeCode.substring(0, sum+=Math.min(3,++count)));
  1155. }while (sum<max&&count<MAX_LOOP);
  1156. }
  1157. return result;
  1158. }
  1159. /* public static void main(String[] args) {
  1160. System.out.println(milestone("k8+120.23"));
  1161. }*/
  1162. /*从测点名称中获取里程*/
  1163. public static Double milestone(String s){
  1164. Pattern pattern=Pattern.compile("(?i)K(\\d+)\\+([\\d.]+)");
  1165. Matcher matcher = pattern.matcher(s);
  1166. if(matcher.find()){
  1167. return Double.parseDouble(matcher.group(1))*1000+ Double.parseDouble(matcher.group(2));
  1168. }
  1169. return null;
  1170. }
  1171. public static void sort( List<FormData> list,int n){
  1172. /*System.out.println("剩余计算次数:"+n+"次");*/
  1173. if(move(list)&&n>0){
  1174. sort(list,--n);
  1175. }
  1176. }
  1177. public static Boolean move( List<FormData> list){
  1178. for(int i=0;i<list.size();i++){
  1179. FormData f=list.get(i);
  1180. Matcher m =P.matcher(f.getFormula().getFormula());
  1181. List<String> cp = new ArrayList<>();
  1182. while (m.find()){
  1183. cp.add(m.group());
  1184. }
  1185. Map<Boolean,List<FormData>> map= list.stream().skip(i+1).collect(Collectors.partitioningBy(e->cp.contains(e.getCode())));
  1186. List<FormData> match =map.get(true);
  1187. if(CollectionUtil.isNotEmpty(match)){
  1188. for(FormData r:match){
  1189. list.remove(r);
  1190. }
  1191. list.addAll(0,match);
  1192. return true;
  1193. }
  1194. }
  1195. return false;
  1196. }
  1197. public static void relyParse(Formula f){
  1198. if(Func.isNotBlank(f.getFormula())){
  1199. List<String> l = new ArrayList<>();
  1200. Matcher m = P.matcher(f.getFormula());
  1201. while (m.find()){
  1202. String tmp =m.group().replaceAll("'","");
  1203. String cp=tmp;
  1204. if(tmp.indexOf(StringPool.COLON)!=tmp.lastIndexOf(StringPool.COLON)){
  1205. tmp=tmp.substring(tmp.indexOf(":")+1);
  1206. /*移除跨节点标识*/
  1207. f.setFormula(f.getFormula().replace(cp,tmp));
  1208. }
  1209. l.add(tmp);
  1210. }
  1211. if(l.size()>0){
  1212. f.setRely(String.join(",", l));
  1213. }else{
  1214. f.setRely("");
  1215. }
  1216. }
  1217. }
  1218. /*复制表页*/
  1219. public static WbsTreeContract copyPage(WbsTreeContract origin){
  1220. WbsTreeContract target = new WbsTreeContract();
  1221. BeanUtil.copy(origin, target);
  1222. target.setPKeyId(SnowFlakeUtil.getId());
  1223. target.setCreateTime(new Date());
  1224. String nodeName = origin.getNodeName();
  1225. String[] oldName = nodeName.split("__");
  1226. if (oldName.length>1) {
  1227. nodeName = oldName[0] + "__" + (Integer.parseInt(oldName[1]) + 1);
  1228. } else {
  1229. nodeName = nodeName + "__" + 1;
  1230. }
  1231. target.setNodeName(nodeName);
  1232. target.setIsCopeTab(2);
  1233. target.setIsTabPdf(1); // pdf 不能预览
  1234. target.setIsBussShow(1); // 是否隐藏表
  1235. target.setTabFileType(1);//没有上传附件
  1236. target.setPdfUrl("");
  1237. return target;
  1238. }
  1239. public static String recovery(List<ElementData> dataList) {
  1240. if (Func.isNotEmpty(dataList)) {
  1241. return dataList.stream().filter(e -> !e.isEmpty()).map(e -> e.stringValue() + "_^_" + e.getY() + "_" + e.getX()).collect(Collectors.joining("☆"));
  1242. }
  1243. return "";
  1244. }
  1245. private static final Map<Character, Integer> CHINESE_TO_ARABIC = new HashMap<>();
  1246. static {
  1247. CHINESE_TO_ARABIC.put('零', 0);
  1248. CHINESE_TO_ARABIC.put('一', 1);
  1249. CHINESE_TO_ARABIC.put('二', 2);
  1250. CHINESE_TO_ARABIC.put('三', 3);
  1251. CHINESE_TO_ARABIC.put('四', 4);
  1252. CHINESE_TO_ARABIC.put('五', 5);
  1253. CHINESE_TO_ARABIC.put('六', 6);
  1254. CHINESE_TO_ARABIC.put('七', 7);
  1255. CHINESE_TO_ARABIC.put('八', 8);
  1256. CHINESE_TO_ARABIC.put('九', 9);
  1257. CHINESE_TO_ARABIC.put('十', 10);
  1258. CHINESE_TO_ARABIC.put('百', 100);
  1259. CHINESE_TO_ARABIC.put('千', 1000);
  1260. CHINESE_TO_ARABIC.put('万', 10000);
  1261. }
  1262. public static int chineseToArabic(String chineseNumber) {
  1263. int result = 0;
  1264. int multiplier = 1;
  1265. for (int i = chineseNumber.length() - 1; i >= 0; i--) {
  1266. char c = chineseNumber.charAt(i);
  1267. if (CHINESE_TO_ARABIC.containsKey(c)) {
  1268. int value = CHINESE_TO_ARABIC.get(c);
  1269. if(value!=0&&value%10==0&&i!=0){
  1270. multiplier=value;
  1271. }else{
  1272. result=result+value*multiplier;
  1273. }
  1274. } else {
  1275. throw new IllegalArgumentException("Invalid Chinese numeral: " + c);
  1276. }
  1277. }
  1278. return result;
  1279. }
  1280. /*public static void main(String[] args) {
  1281. *//* System.out.println(chineseToArabic("二十九"));
  1282. System.out.println(chineseToArabic("一"));
  1283. System.out.println(chineseToArabic("十一"));*//*
  1284. System.out.println(chineseToArabic("十"));
  1285. *//* System.out.println(chineseToArabic("一百二十"));
  1286. System.out.println(chineseToArabic("一百二十二"));
  1287. System.out.println(chineseToArabic("一百零二"));*//*
  1288. }*/
  1289. /*获取引用code的元素*/
  1290. public static Stream<FormData> beRelyFrom( Map<String, FormData> formDataMap ,String code){
  1291. return formDataMap.values().stream().filter(e->e.executable()&& code.equals(e.getFormula().getRely()));
  1292. }
  1293. public static Stream<FormData> beRelyFrom( Map<String, FormData> formDataMap ,String tableNumber ,String keys){
  1294. Set<String> keySet = Arrays.stream(keys.split(",")).map(s->tableNumber+":"+s.trim()).collect(Collectors.toSet());
  1295. return formDataMap.values().stream().filter(e->e.executable()&& keySet.contains(e.getFormula().getRely()));
  1296. }
  1297. /*根据code查找元素 */
  1298. public static Optional<FormData> elementFindByCode( Map<String, FormData> formDataMap ,String code){
  1299. return formDataMap.values().stream().filter(e->code.equals(e.getCode())).findAny();
  1300. }
  1301. /*根据key查找元素 ,用于元素范围在同一张表情况*/
  1302. public static Optional<FormData> elementFindByKey( Map<String, FormData> fdm ,String key){
  1303. return fdm.values().stream().filter(e->key.equals(e.getCode().split(":")[1])).findAny();
  1304. }
  1305. /*创建T集合的指定字段fb的合计方法*/
  1306. public static <T> Function<List<T>, String> createSumFunction(Function<T,BigDecimal> fb) {
  1307. return (pl) -> pl.stream()
  1308. .map(fb)
  1309. .reduce(BigDecimal.ZERO, BigDecimal::add)
  1310. .toString();
  1311. }
  1312. public static List<TableInfo> getTableInfoList(JSONArray dataArray) {
  1313. if (dataArray != null && !dataArray.isEmpty()) {
  1314. List<TableInfo> result = new ArrayList<>();
  1315. for (int m = 0; m < dataArray.size(); m++) {
  1316. TableInfo tableInfo = new TableInfo();
  1317. com.alibaba.fastjson.JSONObject dataInfo2 = dataArray.getJSONObject(m);
  1318. //
  1319. tableInfo.setContractId(dataInfo2.getString("contractId"));
  1320. tableInfo.setPkeyId(dataInfo2.getString("pkeyId"));
  1321. tableInfo.setProjectId(dataInfo2.getString("projectId"));
  1322. //huangjn 填报的类型,施工或监理
  1323. tableInfo.setClassify(dataInfo2.getString("classify"));
  1324. //设置首件信息
  1325. setFirstData(dataInfo2, tableInfo);
  1326. //设置日志信息
  1327. setTheLogData(dataInfo2, tableInfo);
  1328. dataInfo2.fluentRemove("contractId")
  1329. .fluentRemove("pkeyId")
  1330. .fluentRemove("p_key_id")
  1331. .fluentRemove("projectId")
  1332. .fluentRemove("classify")
  1333. .fluentRemove("pickerKey")
  1334. .fluentRemove("id")
  1335. .fluentRemove("isFirst")
  1336. .fluentRemove("firstNodeId")
  1337. .fluentRemove("isTheLog")
  1338. .fluentRemove("theLogId")
  1339. .fluentRemove("linkTabIds")
  1340. .fluentRemove("recordTime")
  1341. .fluentRemove("businessId")
  1342. .fluentRemove("sourceUrl")
  1343. .fluentRemove("pdfUrl")
  1344. .fluentRemove("firstFileName")
  1345. .fluentRemove("");
  1346. // 计算数据
  1347. LinkedHashMap<String, List<String>> dataMap = dataInfo2.keySet().stream().filter(e -> e.contains("__")).collect(Collectors.groupingBy(e -> e.split("__")[0], LinkedHashMap<String, List<String>>::new, Collectors.toList()));
  1348. LinkedHashMap<String, String> dataMap2 = new LinkedHashMap<>();
  1349. // 字段组合
  1350. for (String k : dataMap.keySet()) {
  1351. if (dataMap.get(k).size() > 1 && !dataMap.get(k).contains("000Z")) {
  1352. String[] ziduan = dataMap.get(k).toArray(new String[]{});
  1353. String temp = "";
  1354. for (int i = 0; i < ziduan.length - 1; i++) {
  1355. for (int j = 0; j < ziduan.length - i - 1; j++) {
  1356. Integer tr = Integer.parseInt((ziduan[j].split("__")[1]).split("_")[0]);
  1357. Integer td = Integer.parseInt(ziduan[j].split("__")[1].split("_")[1]);
  1358. Integer tr_1 = Integer.parseInt(ziduan[j + 1].split("__")[1].split("_")[0]);
  1359. Integer td_1 = Integer.parseInt(ziduan[j + 1].split("__")[1].split("_")[1]);
  1360. if (tr > tr_1 && td.equals(td_1)) { //纵向排序
  1361. temp = ziduan[j];
  1362. ziduan[j] = ziduan[j + 1];
  1363. ziduan[j + 1] = temp;
  1364. }
  1365. }
  1366. }
  1367. String lastStr = dataInfo2.getString(ziduan[0]) + "_^_" + ziduan[0].split("__")[1];
  1368. for (int i = 1; i < ziduan.length; i++) {
  1369. String keyData = dataInfo2.getString(ziduan[i]);
  1370. if (org.apache.commons.lang.StringUtils.isNotEmpty(keyData) && !keyData.equals("")) {
  1371. lastStr += "☆" + dataInfo2.getString(ziduan[i]) + "_^_" + ziduan[i].split("__")[1];
  1372. }
  1373. }
  1374. dataMap2.put(k, lastStr);
  1375. } else {
  1376. String dataVal = dataInfo2.getString(dataMap.get(k).get(0));
  1377. if (org.apache.commons.lang.StringUtils.isNotEmpty(dataVal)) {
  1378. if (dataVal.contains("Ljava")) {
  1379. Object o = dataInfo2.get(dataMap.get(k).get(0));
  1380. dataVal = JSON.toJSONString(o).replace("\"", "");
  1381. }
  1382. dataMap2.put(k, dataVal + "_^_" + dataMap.get(k).get(0).split("__")[1]);
  1383. }
  1384. }
  1385. }
  1386. dataInfo2.put("p_key_id", tableInfo.getPkeyId());
  1387. dataInfo2.put("classify",tableInfo.getClassify());
  1388. dataInfo2.put("contractId",tableInfo.getContractId());
  1389. dataInfo2.put("projectId",tableInfo.getProjectId());
  1390. tableInfo.setDataMap(dataMap2);
  1391. result.add(tableInfo);
  1392. }
  1393. return result;
  1394. }
  1395. return null;
  1396. }
  1397. public static void setFirstData(com.alibaba.fastjson.JSONObject dataInfo2, TableInfo tableInfo) {
  1398. //huangjn 判断是否是首件
  1399. if (dataInfo2.containsKey("isFirst")) {
  1400. tableInfo.setIsFirst(dataInfo2.getString("isFirst"));
  1401. }
  1402. //huangjn 判断是否是首件
  1403. //首件资料绑定的节点
  1404. if (dataInfo2.containsKey("firstNodeId")) {
  1405. tableInfo.setFirstNodeId(dataInfo2.getString("firstNodeId"));
  1406. }
  1407. //首件ID(编辑时有值,新增时为空)
  1408. if (dataInfo2.containsKey("firstId")) {
  1409. tableInfo.setFirstId(dataInfo2.getString("firstId"));
  1410. }
  1411. //源文件
  1412. if (dataInfo2.containsKey("sourceUrl")) {
  1413. tableInfo.setSourceUrl(dataInfo2.getString("sourceUrl"));
  1414. }
  1415. //pdfUrl
  1416. if (dataInfo2.containsKey("pdfUrl")) {
  1417. tableInfo.setPdfUrl(dataInfo2.getString("pdfUrl"));
  1418. }
  1419. //文件名称
  1420. if (dataInfo2.containsKey("firstFileName")) {
  1421. tableInfo.setFirstFileName(dataInfo2.getString("firstFileName"));
  1422. }
  1423. //关联的信息
  1424. if (dataInfo2.containsKey("linkProcessList")) {
  1425. tableInfo.setLinkProcessList(dataInfo2.getJSONArray("linkProcessList"));
  1426. }
  1427. }
  1428. public static void setTheLogData(JSONObject dataInfo2, TableInfo tableInfo) {
  1429. //huangjn 判断是否是日志
  1430. if (dataInfo2.containsKey("isTheLog")) {
  1431. tableInfo.setIsTheLog(dataInfo2.getString("isTheLog"));
  1432. }
  1433. //huangjn 判断是否是日志
  1434. //huangjn 日志ID
  1435. if (dataInfo2.containsKey("theLogId")) {
  1436. tableInfo.setTheLogId(dataInfo2.getString("theLogId"));
  1437. }
  1438. //huangjn 日志ID
  1439. //huangjn 日志勾选的工序
  1440. if (dataInfo2.containsKey("linkTabIds")) {
  1441. tableInfo.setLinkTabIds(dataInfo2.getJSONArray("linkTabIds"));
  1442. }
  1443. //huangjn 日志勾选的工序
  1444. //huangjn 日志所选时间
  1445. if (dataInfo2.containsKey("recordTime")) {
  1446. tableInfo.setRecordTime(dataInfo2.getString("recordTime"));
  1447. }
  1448. //huangjn 日志所选时间
  1449. //huangjn 每份填报数据的id,目前日志专用
  1450. if (dataInfo2.containsKey("id")) {
  1451. tableInfo.setBusinessId(dataInfo2.getString("id"));
  1452. }
  1453. //huangjn 每份填报数据的id,目前日志专用
  1454. }
  1455. }