FormulaUtils.java 68 KB

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