CustomFunction.java 94 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580
  1. package com.mixsmart.utils;
  2. import cn.hutool.core.date.*;
  3. import cn.hutool.core.util.ArrayUtil;
  4. import cn.hutool.core.util.NumberUtil;
  5. import com.alibaba.fastjson.JSON;
  6. import com.jfireel.expression.Expression;
  7. import com.jfireel.expression.node.CalculateNode;
  8. import com.jfireel.expression.node.impl.OperatorResultNode;
  9. import com.jfireel.expression.node.impl.StaticObjectMethodNode;
  10. import com.jfireel.expression.node.impl.VariableNode;
  11. import com.jfireel.expression.token.Token;
  12. import org.apache.commons.collections4.MapUtils;
  13. import org.jsoup.Jsoup;
  14. import org.springblade.core.tool.utils.*;
  15. import org.springblade.manager.formula.ElementBlock;
  16. import org.springblade.manager.formula.ItemBlock;
  17. import org.springblade.manager.formula.KeyMapper;
  18. import java.io.FileInputStream;
  19. import java.math.BigDecimal;
  20. import java.text.ParseException;
  21. import java.text.SimpleDateFormat;
  22. import java.util.*;
  23. import java.util.concurrent.atomic.AtomicInteger;
  24. import java.util.regex.Matcher;
  25. import java.util.regex.Pattern;
  26. import java.util.stream.Collectors;
  27. import java.util.stream.IntStream;
  28. import static java.math.BigDecimal.ROUND_CEILING;
  29. import static java.math.BigDecimal.ROUND_HALF_UP;
  30. /**
  31. * @author yangyj
  32. */
  33. public class CustomFunction {
  34. /**
  35. * 类调用地址前缀
  36. */
  37. public static final String CLASS_CALL = "T(com.mixsmart.utils.CustomFunction).";
  38. public static final String CONCAT = "@";
  39. public static final Set<String> KEYWORD_SET = new HashSet<>();
  40. static {
  41. KEYWORD_SET.add("first");
  42. KEYWORD_SET.add("last");
  43. KEYWORD_SET.add("empty");
  44. }
  45. /**
  46. * @return java.lang.String
  47. * @Description 根据桩号类型生成桩号
  48. * @Param [stationType]
  49. * @Author yangyj
  50. * @Date 2021.01.20 17:43
  51. **/
  52. public static String createStation(Object stationType) {
  53. if (StringUtils.isNotEmpty(stationType)) {
  54. Matcher m = RegexUtils.matcher("[~|-]", handleNull(stationType));
  55. if (m.find()) {
  56. StringBuilder sb = new StringBuilder();
  57. String splitchar = m.group(0);
  58. String[] arr = stationType.toString().split(splitchar);
  59. for (String str : arr) {
  60. sb.append(singleStation(str)).append(splitchar);
  61. }
  62. if (sb.length() > 0) {
  63. return sb.deleteCharAt(sb.length() - 1).toString();
  64. }
  65. } else {
  66. return singleStation(stationType);
  67. }
  68. }
  69. return "";
  70. }
  71. /**
  72. * @return java.lang.String[] result[0]:返回桩号前缀;result[1]:实际显示前缀;result[2]:里程数
  73. * @Description 记录表5输入桩号代码解析,2G1#1+100>>2G1K0+100
  74. * @Param [stake]
  75. * @Author yangyj
  76. * @Date 2021.04.09 11:49
  77. **/
  78. public static String[] decodeStake(Object stake) {
  79. String[] result = new String[]{"", "", ""};
  80. if (StringUtils.isNotEmpty(stake)) {
  81. String stakeStr = StringUtils.repaceBlank(stake.toString().toUpperCase());
  82. Matcher m;
  83. if (stake.toString().contains("+")) {
  84. m = RegexUtils.matcher("(([A-Z0-9]*)(#\\d*)?)\\+([\\d||\\.]*)", stakeStr);
  85. if (m.find()) {
  86. String partNoD = m.group(1);
  87. String partNoV = m.group(2);
  88. String kilometer = m.group(4);
  89. result[0] = partNoD;
  90. result[1] = partNoV;
  91. result[2] = kilometer;
  92. }
  93. } else {
  94. m = RegexUtils.matcher("([A-Z]*)([\\d||\\.]*)", stakeStr);
  95. if (m.find()) {
  96. String partNo = m.group(1);
  97. String kilometer = m.group(2);
  98. result[0] = partNo;
  99. result[1] = partNo;
  100. result[2] = kilometer;
  101. }
  102. }
  103. }
  104. return result;
  105. }
  106. public static String[] standardStake(Object stake) {
  107. String[] result = new String[]{"", ""};
  108. if (StringUtils.isNotEmpty(stake)) {
  109. String stakeStr = StringUtils.repaceBlank(stake.toString().toUpperCase());
  110. Matcher m = RegexUtils.matcher("([A-Z0-9]{0,3})K(\\d{1,3})\\+([\\d||\\.]*)", stakeStr);
  111. Matcher m2 = RegexUtils.matcher("([A-Z]{0,3})([\\d||\\.]+)", stakeStr);
  112. if (m.find()) {
  113. String partNo = m.group(1);
  114. double km = Double.parseDouble(m.group(2));
  115. double meter = Double.parseDouble(m.group(3));
  116. result[0] = partNo;
  117. int scale = getScale(meter);
  118. result[1] = StringUtils.number2String(km * 1000 + meter, scale);
  119. } else if (m2.find()) {
  120. result[0] = m2.group(1);
  121. result[1] = m2.group(2);
  122. }
  123. }
  124. return result;
  125. }
  126. /**
  127. * @return int
  128. * @Description 获取最大小数位
  129. * @Param [number]
  130. * @Author yangyj
  131. * @Date 2021.12.23 15:08
  132. **/
  133. public static Integer getScale(Object... number) {
  134. int max = 0;
  135. for (Object n : number) {
  136. if (StringUtils.isNotEmpty(n)) {
  137. String[] sa = n.toString().split(",");
  138. for (String s : sa) {
  139. Matcher m = RegexUtils.matcher("(\\d)+.(\\d)+", s);
  140. if (m.find()) {
  141. max = Math.max(new StringBuilder(m.group()).reverse().toString().indexOf("."), max);
  142. }
  143. }
  144. }
  145. }
  146. return max;
  147. }
  148. public static String singleStation(Object station) {
  149. if (StringUtils.isNotEmpty(station)) {
  150. Object zhdata = station;
  151. String zhdatastr = zhdata.toString().toUpperCase();
  152. if (zhdatastr.contains("+") && zhdatastr.contains("K")) {
  153. return zhdatastr;
  154. }
  155. String[] stake = decodeStake(zhdatastr);
  156. String partNo = stake[1];
  157. String kilometer = stake[2];
  158. if (StringUtils.isNotEmpty(kilometer)) {
  159. partNo = handleNull(partNo);
  160. int ks = (int) Math.floor(Double.parseDouble(kilometer) / 1000);
  161. double ke = new BigDecimal(kilometer).subtract(new BigDecimal(String.valueOf(ks * 1000))).doubleValue();
  162. String temp = "" + ke;
  163. if ((int) Double.parseDouble(temp) == Double.parseDouble(temp)) {
  164. temp = String.valueOf((int) Double.parseDouble(temp));
  165. }
  166. String sf = "000";
  167. if (temp.length() < 3) {
  168. temp = sf.substring(0, 3 - temp.length()) + temp;
  169. }
  170. if ((temp.contains(".") && temp.indexOf(".") <= 2)) {
  171. temp = sf.substring(0, 3 - temp.indexOf(".")) + temp;
  172. }
  173. return partNo + "K" + ks + "+" + temp;
  174. }
  175. }
  176. return "";
  177. }
  178. public static Object calculate(Object a, Object b, Object scaleObj, Integer type) {
  179. boolean nullFlag = false;
  180. if (type == null) {
  181. return null;
  182. }
  183. if (StringUtils.isEmpty(a) && StringUtils.isEmpty(b)) {
  184. return null;
  185. }
  186. if (StringUtils.isEmpty(a) && type == 7) {
  187. nullFlag = true;
  188. a = 0;
  189. }
  190. if (StringUtils.isEmpty(b) && type == 7) {
  191. nullFlag = true;
  192. b = 0;
  193. }
  194. if (StringUtils.isNotEmpty(a) && StringUtils.isNotEmpty(b)) {
  195. try {
  196. int scale = StringUtils.handleObj2Integer(scaleObj);
  197. String aStr = a.toString();
  198. String bStr = b.toString();
  199. double ad = Double.parseDouble(aStr);
  200. double bd = 0;
  201. if (type == 6) {
  202. //判断设计值是否包含"/"
  203. if (bStr.contains("/")) {
  204. bd = bStr.split("/").length;
  205. return (int) (ad * bd);
  206. } else {
  207. return (int) ad;
  208. }
  209. }
  210. bd = Double.parseDouble(bStr);
  211. double result = 0;
  212. if (type == 1) {
  213. result = ad + bd;
  214. } else if (type == 2) {
  215. result = ad - bd;
  216. } else if (type == 3) {
  217. result = ad * bd;
  218. } else if (type == 4) {
  219. result = ad / bd;
  220. } else if (type == 5) {
  221. result = ad % bd;
  222. } else if (type == 7 && ad * bd != 0 && !nullFlag) {
  223. return (int) Math.ceil(ad * bd);
  224. } else {
  225. return null;
  226. }
  227. BigDecimal big = new BigDecimal(result);
  228. return big.setScale(scale, ROUND_HALF_UP);
  229. } catch (NumberFormatException e) {
  230. e.printStackTrace();
  231. }
  232. }
  233. return null;
  234. }
  235. public static boolean isNumber(Object value) {
  236. if (Func.isEmpty(value)) {
  237. return false;
  238. }
  239. if (value instanceof Number) {
  240. return true;
  241. }
  242. String pattern = "^[+-]?\\d+(\\.\\d+)?$";
  243. Pattern r = Pattern.compile(pattern);
  244. Matcher m = r.matcher(String.valueOf(value));
  245. return m.matches();
  246. }
  247. public static boolean isNotNumber(Object value) {
  248. return !isNumber(value);
  249. }
  250. public static Object sum(List<Object> list) {
  251. if (ListUtils.isNotEmpty(list)) {
  252. return list.stream().filter(StringUtils::isNumber).map(StringUtils::handleNull).mapToDouble(Double::parseDouble).sum();
  253. }
  254. return "";
  255. }
  256. public static Object avg(List<Object> list) {
  257. if (ListUtils.isNotEmpty(list)) {
  258. OptionalDouble op = list.stream().filter(StringUtils::isNumber).map(StringUtils::handleNull).mapToDouble(Double::parseDouble).average();
  259. if (op.isPresent()) {
  260. return op.getAsDouble();
  261. }
  262. }
  263. return "";
  264. }
  265. /**
  266. * @return java.util.List<java.lang.Object>
  267. * @Description 分段求平均值
  268. * @Param [data 原数据, n 分段数]
  269. * @Author yangyj
  270. * @Date 2023.04.28 10:13
  271. **/
  272. public static List<Object> avg4segment(List<Object> data, int n) {
  273. if (data.isEmpty()) {
  274. return null;
  275. }
  276. if (n <= 1) {
  277. return Collections.singletonList(avg(data));
  278. }
  279. Map<Integer, List<Object>> group = IntStream.range(0, data.size())
  280. .boxed()
  281. .collect(Collectors.groupingBy(i -> i / n, LinkedHashMap::new, Collectors.mapping(data::get, Collectors.toList())));
  282. return group.values().stream().map(CustomFunction::avg).collect(Collectors.toList());
  283. }
  284. public static Object max(List<Object> list) {
  285. if (ListUtils.isNotEmpty(list)) {
  286. OptionalDouble op = list.stream().filter(StringUtils::isNumber).map(StringUtils::handleNull).mapToDouble(Double::parseDouble).max();
  287. if (op.isPresent()) {
  288. return op.getAsDouble();
  289. }
  290. }
  291. return "";
  292. }
  293. public static Object min(List<Object> list) {
  294. if (ListUtils.isNotEmpty(list)) {
  295. OptionalDouble op = list.stream().filter(StringUtils::isNumber).map(StringUtils::handleNull).mapToDouble(Double::parseDouble).min();
  296. if (op.isPresent()) {
  297. return op.getAsDouble();
  298. }
  299. }
  300. return "";
  301. }
  302. public static Object count(Object data) {
  303. List<Object> list = obj2ListNe(data);
  304. if (ListUtils.isNotEmpty(list)) {
  305. if (list.stream().anyMatch(e -> !StringUtils.isNumber(e))) {
  306. return list.stream().filter(StringUtils::isNotEmpty).count();
  307. }
  308. return list.stream().filter(StringUtils::isNumber).map(StringUtils::handleNull).mapToDouble(Double::parseDouble).count();
  309. }
  310. return "";
  311. }
  312. /**
  313. * @return java.lang.Object
  314. * @Description 输出勾选复选框
  315. * @Param [o1, o2]
  316. * @Author yangyj
  317. * @Date 2021.06.29 10:35
  318. **/
  319. public static Object checkbox(Object o1, Object o2) {
  320. if (StringUtils.isNotEmpty(o1) && StringUtils.isNotEmpty(o2)) {
  321. if (o1.equals(o2)) {
  322. return "\u2611";
  323. }
  324. }
  325. return "";
  326. }
  327. /**
  328. * @return java.lang.Object
  329. * @Description 返回n个空格,用于输出字符串格式化
  330. * @Param [n]
  331. * @Author yangyj
  332. * @Date 2021.06.29 11:41
  333. **/
  334. public static Object space(Object n) {
  335. if (StringUtils.isNumber(n)) {
  336. return String.join("", Collections.nCopies(Integer.parseInt(n.toString()), "\u0020"));
  337. }
  338. return "";
  339. }
  340. /**
  341. * @return boolean
  342. * @Description 字符串中是包含中文
  343. * @Param [chars]
  344. * @Author yangyj
  345. * @Date 2021.09.17 14:31
  346. **/
  347. public static boolean containsZH(Object chars) {
  348. Matcher m = RegexUtils.matcher("[\u4e00-\u9fa5]", handleNull(chars));
  349. return m.find();
  350. }
  351. /**
  352. * @return boolean
  353. * @Description 字符串中是包含数字
  354. * @Param [chars]
  355. * @Author yangyj
  356. * @Date 2021.09.17 14:31
  357. **/
  358. public static boolean containsD(Object chars) {
  359. Matcher m = RegexUtils.matcher("\\d", handleNull(chars));
  360. return m.find();
  361. }
  362. /**
  363. * @return java.lang.String
  364. * @Description 封装超链接
  365. * @Param [uri]
  366. * @Author yangyj
  367. * @Date 2021.10.14 16:15
  368. **/
  369. public static String uri(Object uri) {
  370. if (StringUtils.isNotEmpty(uri)) {
  371. return "URI<" + handleNull(uri) + ">";
  372. }
  373. return "";
  374. }
  375. /**
  376. * @return java.lang.Object
  377. * @Description 获取相隔多少天后的日期
  378. * @Param [date, n:相隔天数,正数代表未来,负数代表历史]
  379. * @Author yangyj
  380. * @Date 2021.10.27 10:21
  381. **/
  382. public static Object dateAfter(Object date, Object n) {
  383. if (StringUtils.isNotEmpty(date) && StringUtils.isNumber(n)) {
  384. if (date instanceof List) {
  385. date = ((List) date).get(0);
  386. }
  387. DateTime dt = new DateTime(date.toString());
  388. dt.offset(DateField.HOUR_OF_DAY, 24 * Integer.parseInt(n.toString()));
  389. //return dt.toString(DatePattern.UTC_PATTERN);
  390. return dt.toString(DatePattern.CHINESE_DATE_PATTERN);
  391. }
  392. return "";
  393. }
  394. public static Object weather(List<Object> date,Map<String,Object> map){
  395. if(ListUtils.isNotEmpty(date)&&map!=null){
  396. return date.stream().map(StringUtils::handleNull).filter(StringUtils::isNotEmpty).map(e->map.get(new DateTime(e).toString(DatePattern.NORM_DATE_PATTERN))).collect(Collectors.toList());
  397. }
  398. return "";
  399. }
  400. public static Object dateMax(Object range) {
  401. if (StringUtils.isNotEmpty(range)) {
  402. String[] s = Func.toStr(range).replaceAll("[\\[\\]]", "").split(",\\s+");
  403. return dateCp(s[0], s[1], false);
  404. }
  405. return StringPool.EMPTY;
  406. }
  407. public static Object dateMin(Object range) {
  408. if (StringUtils.isNotEmpty(range)) {
  409. String[] s = Func.toStr(range).replaceAll("[|]", "").split(",");
  410. return dateCp(s[0], s[1], true);
  411. }
  412. return StringPool.EMPTY;
  413. }
  414. private static Object dateCp(Object d1, Object d2, Boolean isAsc) {
  415. if (d1 != null && d2 != null) {
  416. Map<DateTime, Object> map = new HashMap<>();
  417. DateTime dt1 = new DateTime(d1.toString());
  418. DateTime dt2 = new DateTime(d2.toString());
  419. map.put(dt1, d1);
  420. map.put(dt2, d2);
  421. List<DateTime> list = new ArrayList<>();
  422. list.add(dt1);
  423. list.add(dt2);
  424. if (isAsc) {
  425. return map.get(dcp(list, Comparator.naturalOrder()));
  426. } else {
  427. return map.get(dcp(list, Comparator.reverseOrder()));
  428. }
  429. }
  430. return StringPool.EMPTY;
  431. }
  432. /**
  433. * @return java.lang.Object
  434. * @Description 优良占比
  435. * @Param [data, cp]
  436. * @Author yangyj
  437. * @Date 2022.12.21 12:00
  438. **/
  439. public static Object proportion(List<Object> data, String cp) {
  440. if (Func.isNotEmpty(data) && Func.isNotBlank(cp)) {
  441. data = data.stream().filter(Func::isNotEmpty).map(e -> e.toString().replaceAll("\\s+", "")).collect(Collectors.toList());
  442. return StringUtils.number2String(100 * ((double) data.stream().filter(e -> StringUtils.isEquals(e, cp)).count()) / (double) data.size(), 1);
  443. }
  444. return "";
  445. }
  446. public static Object goodSize(List<Object> data, String cp) {
  447. if (Func.isNotEmpty(data) && Func.isNotBlank(cp)) {
  448. data = data.stream().filter(Func::isNotEmpty).map(e -> e.toString().replaceAll("\\s+", "")).collect(Collectors.toList());
  449. return data.stream().filter(e -> StringUtils.isEquals(e, cp)).count();
  450. }
  451. return "";
  452. }
  453. /**
  454. * @return java.lang.Object
  455. * @Description 阶梯合格率
  456. * @Param [data]
  457. * @Author yangyj
  458. * @Date 2022.12.21 11:59
  459. **/
  460. public static Object ladder(List<Object> data) {
  461. if (Func.isNotEmpty(data)) {
  462. OptionalDouble op = data.stream().map(StringUtils::handleNull).filter(StringUtils::isNumber).mapToDouble(Double::parseDouble).min();
  463. if (op.isPresent()) {
  464. return op.getAsDouble() >= 90 ? 90 : 70;
  465. }
  466. }
  467. return "";
  468. }
  469. /**
  470. * @return java.lang.Object
  471. * @Description 主要工序质量等级
  472. * @Param [data]
  473. * @Author yangyj
  474. * @Date 2022.12.21 14:18
  475. **/
  476. public static Object major(List<Object> data) {
  477. if (Func.isNotEmpty(data) && data.stream().anyMatch(StringUtils::isNotEmpty)) {
  478. return data.stream().map(StringUtils::handleNull).distinct().collect(Collectors.toList()).stream().anyMatch(e -> e.contains("合格")) ? "合格" : "优良";
  479. }
  480. return "";
  481. }
  482. /**
  483. * @return java.lang.Object
  484. * @Description 单元工程质量等级评定
  485. * @Param [rate, level]
  486. * @Author yangyj
  487. * @Date 2022.12.21 14:33
  488. **/
  489. public static Object unit(Object rate, Object level) {
  490. if (StringUtils.isNotEmpty(rate, level)) {
  491. return StringUtils.obj2Double(rate.toString()) > 50 && "优良".equals(level.toString()) ? "优良" : "合格";
  492. }
  493. return "";
  494. }
  495. /**
  496. * @return java.lang.Object
  497. * @Description 主控项目数量
  498. * @Param [data]
  499. * @Author yangyj
  500. * @Date 2022.12.21 15:37
  501. **/
  502. public static Object reasonable(List<Object> data) {
  503. if (ListUtils.isNotEmpty(data)) {
  504. return data.stream().map(e -> StringUtils.handleNull(e).replace("/", "")).filter(StringUtils::isNotEmpty).count();
  505. }
  506. return "";
  507. }
  508. /**
  509. * @return cn.hutool.core.date.DateTime
  510. * @Description 时间比较获取
  511. * @Param [list:时间集合, comparator 比较器 ]
  512. * @Author yangyj
  513. * @Date 2022.11.10 10:47
  514. **/
  515. public static DateTime dcp(List<DateTime> list, Comparator<? super DateTime> comparator) {
  516. return list.stream().reduce((a, b) -> comparator.compare(a, b) <= 0 ? a : b).orElse(null);
  517. }
  518. public static String dateToStr(Date date, String formatter) {
  519. String value = null;
  520. if (null != date) {
  521. if (StringUtils.isEmpty(formatter)) {
  522. formatter = "yyyy-MM-dd HH:mm:ss";
  523. }
  524. SimpleDateFormat dateFormat = new SimpleDateFormat(formatter);
  525. value = dateFormat.format(date);
  526. dateFormat = null;
  527. }
  528. return value;
  529. }
  530. public static String summary(List<String> tableNames) {
  531. if (ListUtils.isNotEmpty(tableNames)) {
  532. return tableNames.stream().map(e -> e.replaceAll("_(PL)?_\\d+$", "")).distinct().collect(Collectors.joining(StringPool.NEWLINE));
  533. }
  534. return StringPool.EMPTY;
  535. }
  536. ;
  537. public String checkItems(List<String> items, List<Object> l1, List<Object> l2, List<Object> l3, List<Object> l4, List<Object> l5, List<Object> l6, List<Object> l7, List<Object> l8, List<Object> l9, List<Object> l10, List<Object> l11, List<Object> l12) {
  538. List<List<Object>> data = new ArrayList<>(Arrays.asList(l1, l2, l3, l4, l5, l6, l7, l8, l9, l10, l11, l12));
  539. List<String> result = new ArrayList<>();
  540. for (int i = 0; i < data.size(); i++) {
  541. List<Object> list = data.get(i);
  542. if (list.stream().anyMatch(StringUtils::isNotEmpty)) {
  543. result.add(items.get(i));
  544. }
  545. }
  546. if (ListUtils.isNotEmpty(result)) {
  547. return String.join("、", result);
  548. }
  549. return StringPool.EMPTY;
  550. }
  551. /**
  552. * @return java.lang.Object
  553. * @Description 计算t1~t2,t3~t4 两个时间段的合计时间,unit 输入数值的单位
  554. * @Param [t1, t2, t3, t4, unit]
  555. * @Author yangyj
  556. * @Date 2021.07.02 15:47
  557. **/
  558. public static Object totalTime(Object t1, Object t2, Object t3, Object t4, Object unit) {
  559. if (StringUtils.isNotEmpty(t1) && StringUtils.isNotEmpty(t2) && StringUtils.isNotEmpty(t3) && StringUtils.isNotEmpty(t4) && StringUtils.isNotEmpty(unit)) {
  560. return conversionUnit((Long.parseLong(minutesPassedRecent(t1, t2).toString()) + Long.parseLong(minutesPassedRecent(t3, t4).toString())), unit);
  561. }
  562. return "";
  563. }
  564. /**
  565. * @return java.lang.Object
  566. * @Description 字符串日期转指定格式日期
  567. * @Param [date, format:输出格式]
  568. * @Author yangyj
  569. * @Date 2021.07.02 15:55
  570. **/
  571. public static Object dateFormatter(Object date, Object format) {
  572. if (StringUtils.isNotEmpty(date) && StringUtils.isNotEmpty(format)) {
  573. Matcher m = RegexUtils.matcher("(\\d{4})\\D(\\d{2})\\D(\\d{2})日?\\s*(\\d{0,2})(\\D\\d{1,2})?", date.toString());
  574. if (m.find()) {
  575. String yyyy = handleNull(m.group(1));
  576. String MM = handleNull(m.group(2));
  577. String dd = handleNull(m.group(3));
  578. String HH = handleNull(m.group(4));
  579. String mm = handleNull(m.group(5));
  580. String d = handleNull(format);
  581. if (StringUtils.isNotEmpty(yyyy)) {
  582. d = d.replace("yyyy", yyyy);
  583. }
  584. if (StringUtils.isNotEmpty(MM)) {
  585. d = d.replace("MM", MM);
  586. }
  587. if (StringUtils.isNotEmpty(dd)) {
  588. d = d.replace("dd", dd);
  589. }
  590. if (StringUtils.isNotEmpty(HH)) {
  591. d = d.replace("HH", HH);
  592. }
  593. if (StringUtils.isNotEmpty(mm)) {
  594. mm = mm.replaceAll("\\D", "");
  595. d = d.replace("mm", mm);
  596. }
  597. return d;
  598. }
  599. }
  600. return "";
  601. }
  602. /**
  603. * @return java.lang.Object
  604. * @Description 求偏差值
  605. * @Param [list, design]
  606. * @Author yangyj
  607. * @Date 2021.09.18 10:43
  608. **/
  609. public static Object deviation(Object list, Object design) {
  610. if (StringUtils.isNotEmpty(list) && StringUtils.isNumber(design)) {
  611. List<Object> result = new ArrayList<>();
  612. List<Object> tmp;
  613. if (list instanceof List) {
  614. tmp = (List<Object>) list;
  615. } else {
  616. tmp = Arrays.asList(list.toString().split("[,|\\-~,]"));
  617. }
  618. int dev = StringUtils.handObj2Integer(design);
  619. for (Object e : tmp) {
  620. if (containsZH(e)) {
  621. /*不允许包含中文*/
  622. return "";
  623. }
  624. result.add(StringUtils.handObj2Integer(e) - dev);
  625. }
  626. if (ListUtils.isNotEmpty(result)) {
  627. return result;
  628. }
  629. }
  630. return "";
  631. }
  632. /**
  633. * @return java.lang.Object
  634. * @Description 把日期格式化成 'xxxx年xx月xx日 星期x' 字符串
  635. * @Param [date]
  636. * @Author yangyj
  637. * @Date 2021.06.21 14:27
  638. **/
  639. public static Object toDateAndWeek(Object date) {
  640. if (StringUtils.isNotEmpty(date)) {
  641. Date d = parseDate(handleNull(date));
  642. String[] weekDays = {"星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六"};
  643. Calendar calendar = Calendar.getInstance();
  644. assert d != null;
  645. calendar.setTime(d);
  646. String week = weekDays[calendar.get(Calendar.DAY_OF_WEEK) - 1];
  647. return dateToStr(d, "yyyy年MM月dd日") + " " + week;
  648. }
  649. return null;
  650. }
  651. /**
  652. * @return java.lang.Object
  653. * @Description
  654. * @Param [data , unit 输入单位]
  655. * @Author yangyj
  656. * @Date 2022.10.13 14:13
  657. **/
  658. public static Object conversionUnit(Object data, Object unit) {
  659. if (StringUtils.isNumber(data) && StringUtils.isNotEmpty(unit)) {
  660. //统一转化成毫秒在处理
  661. long ms = 0;
  662. long l = Long.parseLong(data.toString());
  663. final long s = 1000L;
  664. final long m = s * 60;
  665. final long H = m * 60;
  666. final long D = H * 24;
  667. final long M = D * 30;
  668. final long Y = D * 365;
  669. if (StringUtils.isEquals("Y", unit.toString())) {
  670. ms = l * Y;
  671. } else if (StringUtils.isEquals("M", unit.toString())) {
  672. ms = l * M;
  673. } else if (StringUtils.isEquals("D", unit.toString())) {
  674. ms = l * D;
  675. } else if (StringUtils.isEquals("H", unit.toString())) {
  676. ms = l * H;
  677. } else if (StringUtils.isEquals("m", unit.toString())) {
  678. ms = l * m;
  679. }
  680. StringBuilder sb = new StringBuilder();
  681. if (ms / Y != 0) {
  682. sb.append(ms / Y).append("年");
  683. ms = ms % Y;
  684. }
  685. if (ms / M != 0) {
  686. sb.append(ms / M).append("月");
  687. ms = ms % M;
  688. }
  689. if (ms / D != 0) {
  690. sb.append(ms / D).append("日");
  691. ms = ms % D;
  692. }
  693. if (ms / H != 0) {
  694. sb.append(ms / H).append("时");
  695. ms = ms % H;
  696. }
  697. if (ms / m != 0) {
  698. sb.append(ms / m).append("分");
  699. ms = ms % m;
  700. }
  701. if (sb.length() > 0) {
  702. return sb.toString();
  703. }
  704. }
  705. return "";
  706. }
  707. public static Object fileSize(Object data) {
  708. return fileSize(data, null);
  709. }
  710. public static Object fileSize(Object data, Object unit) {
  711. if (StringUtils.isNumber(data)) {
  712. if (StringUtils.isEmpty(unit)) {
  713. unit = "K";
  714. }
  715. //统一转化成KB在处理
  716. long ms = 0;
  717. long l = Long.parseLong(data.toString());
  718. final long KB = 1L;
  719. final long MB = 1024 * KB;
  720. final long GB = 1024 * MB;
  721. final long TB = 1024 * GB;
  722. if (StringUtils.isEquals("K", unit.toString().toUpperCase())) {
  723. ms = l * KB;
  724. } else if (StringUtils.isEquals("M", unit.toString().toUpperCase())) {
  725. ms = l * MB;
  726. } else if (StringUtils.isEquals("G", unit.toString().toUpperCase())) {
  727. ms = l * GB;
  728. } else if (StringUtils.isEquals("T", unit.toString().toUpperCase())) {
  729. ms = l * TB;
  730. }
  731. if (ms / TB != 0) {
  732. return new BigDecimal(ms).divide(new BigDecimal(TB), 2, ROUND_HALF_UP) + "TB";
  733. }
  734. if (ms / GB != 0) {
  735. return new BigDecimal(ms).divide(new BigDecimal(GB), 1, ROUND_HALF_UP) + "GB";
  736. }
  737. if (ms / MB != 0) {
  738. return new BigDecimal(ms).divide(new BigDecimal(MB), 0, ROUND_HALF_UP) + "MB";
  739. }
  740. return ms + "KB";
  741. }
  742. return "";
  743. }
  744. public static Object daysPassed(Object t1, Object t2) {
  745. return timePassed(t1, t2, "D", 0, "yyyy-MM-dd");
  746. }
  747. public static Object hoursPassed(Object t1, Object t2) {
  748. return timePassed(t1, t2, "H", 0, "yyyy-MM-dd HH");
  749. }
  750. public static Object minutesPassed(Object t1, Object t2) {
  751. return timePassed(t1, t2, "m", 0, "yyyy-MM-dd HH:mm");
  752. }
  753. /**
  754. * @return java.lang.Object
  755. * @Description 输入时间格式:mm:ss(例如01:33)
  756. * @Param [t1, t2]
  757. * @Author yangyj
  758. * @Date 2021.07.02 17:45
  759. **/
  760. public static Object minutesPassedRecent(Object t1, Object t2) {
  761. String year = Calendar.getInstance().get(Calendar.YEAR) + ".";
  762. int month = Calendar.getInstance().get(Calendar.MONTH) + 1;
  763. String mstr = "";
  764. if (month < 10) {
  765. mstr = "0" + month + ".";
  766. } else {
  767. mstr = month + ".";
  768. }
  769. int day = Calendar.getInstance().get(Calendar.DATE) + 1;
  770. String dstr = "";
  771. if (day < 10) {
  772. dstr = "0" + day + " ";
  773. } else {
  774. dstr = day + " ";
  775. }
  776. t1 = year + mstr + dstr + t1;
  777. t2 = year + mstr + dstr + t2;
  778. return timePassed(t1, t2, "m", 0, "yyyy-MM-dd HH:mm");
  779. }
  780. public static Object hoursPassedRecent(Object t1, Object t2) {
  781. String year = Calendar.getInstance().get(Calendar.YEAR) + "年";
  782. t1 = year + t1;
  783. t1 = t1.toString().replace("日", " ").replace("时", " ");
  784. t2 = year + t2;
  785. t2 = t2.toString().replace("日", " ").replace("时", " ");
  786. return timePassed(t1, t2, "H", 0, "yyyy-MM-dd HH");
  787. }
  788. public static Date parseDate(String dateStr) {
  789. if (StringUtils.isEmpty(dateStr)) {
  790. return null;
  791. }
  792. if (!dateStr.contains("-")) {
  793. dateStr = StringUtils.repaceBlank(dateStr);
  794. Matcher m = RegexUtils.matcher("\\d{4}(.)\\d{2}(.)\\d{2}(.?)", dateStr);
  795. if (m.find()) {
  796. Set<String> set = new HashSet<>();
  797. set.add(m.group(1));
  798. set.add(m.group(2));
  799. if (StringUtils.isNotEmpty(m.group(3))) {
  800. set.add(m.group(3));
  801. }
  802. if (!set.isEmpty()) {
  803. for (String str : set) {
  804. dateStr = dateStr.replace(str, "-");
  805. }
  806. }
  807. }
  808. }
  809. Date datetime = null;
  810. SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
  811. try {
  812. datetime = dateFormat.parse(dateStr);
  813. } catch (ParseException e) {
  814. e.printStackTrace();
  815. }
  816. return datetime;
  817. }
  818. public static Date parseDate(Object date, String format) {
  819. if (date instanceof Date) {
  820. return (Date) date;
  821. }
  822. if (date == null || StringUtils.isEmpty(format)) {
  823. return null;
  824. }
  825. String dateStr = date.toString();
  826. if (!dateStr.toString().contains("-")) {
  827. Matcher m = RegexUtils.matcher("\\d{4}(.)\\d{2}(.)\\d{2}(日?)", dateStr);
  828. if (m.find()) {
  829. Set<String> set = new HashSet<>();
  830. set.add(m.group(1));
  831. set.add(m.group(2));
  832. if (StringUtils.isNotEmpty(m.group(3))) {
  833. dateStr = dateStr.replace(m.group(3), "");
  834. }
  835. if (!set.isEmpty()) {
  836. for (String str : set) {
  837. dateStr = dateStr.replace(str, "-");
  838. }
  839. }
  840. }
  841. }
  842. Date datetime = null;
  843. SimpleDateFormat dateFormat = new SimpleDateFormat(format);
  844. try {
  845. datetime = dateFormat.parse(dateStr);
  846. } catch (ParseException e) {
  847. e.printStackTrace();
  848. }
  849. return datetime;
  850. }
  851. public static String handleNull(Object obj) {
  852. if (null == obj) {
  853. return "";
  854. } else {
  855. return obj.toString().trim();
  856. }
  857. }
  858. /**
  859. * @return java.lang.Object
  860. * @Description 返回时间间隔差
  861. * @Param [t1:开始时间, t2:结束时间, mode:返回值单位:Y年 M月 D日 H时 m分,scale:保留小数位, format:输入日期格式]
  862. * @Author yangyj
  863. * @Date 2021.07.01 09:57
  864. **/
  865. public static Object timePassed(Object t1, Object t2, Object mode, Object scale, Object format) {
  866. if (t1 != null && t2 != null && StringUtils.isNotEmpty(mode) && StringUtils.isNotEmpty(scale) && StringUtils.isNotEmpty(format)) {
  867. // Date d1 = parseDate(t1,handleNull(format));
  868. // Date d2 = parseDate(t2,handleNull(format));
  869. DateTime d1 = new DateTime(t1.toString());
  870. DateTime d2 = new DateTime(t2.toString());
  871. // if(d1.after(d2)&&StringUtils.isEquals("H",mode)){
  872. // /*假如是计算相差单位是小时,当开始时间大于结束时间,需要考虑跨年的情况*/
  873. // Calendar c =Calendar.getInstance();
  874. // c.setTime(d1);
  875. // c.add(Calendar.YEAR, -1);
  876. // d1=new DateTime(c.getTime());
  877. // }
  878. long range = d2.getTime() - d1.getTime();
  879. long r = 0;
  880. if (StringUtils.isEquals("Y", mode.toString())) {
  881. r = range / (1000L * 3600 * 24 * 365);
  882. } else if (StringUtils.isEquals("M", mode.toString())) {
  883. r = range / (1000L * 3600 * 24 * 30);
  884. } else if (StringUtils.isEquals("D", mode.toString())) {
  885. r = range / (1000L * 3600 * 24);
  886. } else if (StringUtils.isEquals("H", mode.toString())) {
  887. r = range / (1000L * 3600);
  888. } else if (StringUtils.isEquals("m", mode.toString())) {
  889. r = range / (1000L * 60);
  890. }
  891. BigDecimal b = new BigDecimal(r);
  892. if (!StringUtils.isNumber(scale)) {
  893. scale = 0;
  894. }
  895. return b.setScale(Integer.parseInt(scale.toString()), ROUND_HALF_UP);
  896. }
  897. return "";
  898. }
  899. public static Object k2d(Object k) {
  900. Matcher mt = RegexUtils.matcher("[A-Z]*(\\d*)\\+([\\d|\\.]*)", k.toString());
  901. if (mt.find()) {
  902. return Double.parseDouble(mt.group(1)) * 1000 + Double.parseDouble(mt.group(2));
  903. }
  904. return -1;
  905. }
  906. /**
  907. * @return java.lang.Object
  908. * @Description 开方
  909. * @Param [a:被开方数, scale:结果的小数位]
  910. * @Author yangyj
  911. * @Date 2020.12.10 15:10
  912. **/
  913. public static Object sqrt(Object a) {
  914. if (StringUtils.isNumber(a)) {
  915. return Math.sqrt(Double.parseDouble(a.toString()));
  916. }
  917. return "";
  918. }
  919. /**
  920. * @return java.lang.Object
  921. * @Description 平方
  922. * @Param [a:开方数, scale:结果的小数位]
  923. * @Author yangyj
  924. * @Date 2020.12.10 15:10
  925. **/
  926. public static Object pow(Object a, Object b) {
  927. if (StringUtils.isNumber(a) && StringUtils.isNumber(b)) {
  928. return Math.pow(Double.parseDouble(a.toString()), Double.parseDouble(b.toString()));
  929. }
  930. return "";
  931. }
  932. public static Object pow(Object a) {
  933. if (StringUtils.isNumber(a)) {
  934. return Math.pow(Double.parseDouble(a.toString()), 2);
  935. }
  936. return "";
  937. }
  938. /**
  939. * @return java.lang.Object
  940. * @Description 立方
  941. * @Param [base]
  942. * @Author yangyj
  943. * @Date 2022.06.24 16:48
  944. **/
  945. public static Object cube(Object base) {
  946. return pow(base, 3);
  947. }
  948. /**
  949. * @return java.util.List<java.lang.Object>
  950. * @Description 生成用户指定范围实测值
  951. * @Param [n 数量, design 设计值, scope 偏差范围, rate 合格率0~1, scale保留小数位]
  952. * @Author yangyj
  953. * @Date 2021.08.27 14:47
  954. **/
  955. public static List<Object> cmv(Object n, Object design, Object scope, Object rate, Object scale) {
  956. if (StringUtils.isNotEmpty(n) && StringUtils.isNotEmpty(design) && StringUtils.isNotEmpty(scope) && StringUtils.isNotEmpty(rate) && StringUtils.isNotEmpty(scale)) {
  957. return rangeList(n, design, scope, 1, scale, rate);
  958. }
  959. return null;
  960. }
  961. /**
  962. * @return java.lang.Object
  963. * @Description 累加器
  964. * @Param [scale:保留小数位, args:累加对象,支持动态数量]
  965. * @Author yangyj
  966. * @Date 2021.05.18 10:40
  967. **/
  968. public static Object _sumObj(Object scale, Object... args) {
  969. double result = 0d;
  970. boolean flag = false;
  971. for (Object obj : args) {
  972. if (StringUtils.isNotEmpty(obj) && StringUtils.isNumber(obj)) {
  973. result += Double.parseDouble(obj.toString());
  974. flag = true;
  975. }
  976. }
  977. if (flag) {
  978. BigDecimal r = new BigDecimal(result);
  979. return r.setScale((int) Double.parseDouble(scale.toString()), ROUND_HALF_UP);
  980. }
  981. return "";
  982. }
  983. /**
  984. * @return java.lang.Object
  985. * @Description 空白或者/都判断为空
  986. * @Param [data]
  987. * @Author yangyj
  988. * @Date 2022.04.01 15:04
  989. **/
  990. public static Object isNotEmpty(Object data) {
  991. List<Object> list = obj2List(data);
  992. return list.stream().map(StringUtils::handleNull).anyMatch(e -> !e.contains("/"));
  993. }
  994. public static Object isPass(Object data) {
  995. List<Object> list = obj2List(data);
  996. return list.stream().map(StringUtils::handleNull).map(e -> !e.contains("/") && StringUtils.isNotEmpty(e) ? "合格" : "").collect(Collectors.toList());
  997. }
  998. public static List<Object> b445check(List<Object> data, Object designs, Object dev, Object xN) {
  999. return b445check(data, designs, dev, xN, null);
  1000. }
  1001. /**
  1002. * @return [共检数量, 合格数量, 不合格数量...]
  1003. * @Description 河南项目检查结果
  1004. * @Param [data, designs, dev, xN, hz]
  1005. * @Author yangyj
  1006. * @Date 2022.08.01 11:06
  1007. **/
  1008. public static List<Object> b445check(List<Object> data, Object designs, Object dev, Object xN, Object hz) {
  1009. List<Object> result = new ArrayList<>();
  1010. designs = designFormat(designs);
  1011. if (StringUtils.isNotEmpty(data, designs, dev)) {
  1012. if (StringUtils.isEmpty(xN)) {
  1013. /*偏差范围单位转换倍率默认是1*/
  1014. /*同一个项目偏差范围单位理应一样,所以不用考虑多个值的情况*/
  1015. xN = 1;
  1016. }
  1017. if (StringUtils.handleNull(designs).contains("/")) {
  1018. /*多个设计值*/
  1019. String[] designArr = designs.toString().split("/");
  1020. String[] devArr = dev.toString().split("/");
  1021. int total = 0;
  1022. int pass = 0;
  1023. List<List<Object>> dl = dataSpaceSplit(data, designArr);
  1024. for (int i = 0; i < designArr.length; i++) {
  1025. Object[] obs = ck(dl.size() > i ? dl.get(i) : dl.get(dl.size() - 1), designArr[i], devArr.length > i ? devArr[i] : devArr[devArr.length - 1], xN);
  1026. total += StringUtils.handleObj2Integer(obs[0]);
  1027. pass += StringUtils.handleObj2Integer(obs[1]);
  1028. }
  1029. if (total > 0) {
  1030. result.add(total);
  1031. result.add(pass);
  1032. result.add(total - pass);
  1033. }
  1034. } else {
  1035. Object[] target = ck(data, designs, dev, xN);
  1036. if (StringUtils.handObj2Integer(target[0]) > 0) {
  1037. result.add(target[0]);
  1038. result.add(target[1]);
  1039. result.add(StringUtils.handObj2Integer(target[0]) - StringUtils.handObj2Integer(target[1]));
  1040. }
  1041. }
  1042. } else if (ListUtils.isNotEmpty(data)) {
  1043. if (data.parallelStream().anyMatch(StringUtils::isNotEmpty)) {
  1044. data = data.parallelStream().filter(StringUtils::isNotEmpty).collect(Collectors.toList());
  1045. result.add(data.size());
  1046. result.add(data.size());
  1047. result.add(0);
  1048. }
  1049. }
  1050. if (result.size() == 0) {
  1051. result.addAll(Collections.nCopies(3, ""));
  1052. }
  1053. return result;
  1054. }
  1055. public static Object designFormat(Object design) {
  1056. if (StringUtils.isNotEmpty(design)) {
  1057. return Arrays.stream(design.toString().split("[^\\d.]")).filter(StringUtils::isNotEmpty).collect(Collectors.joining("/"));
  1058. }
  1059. return "";
  1060. }
  1061. public static List<List<Object>> dataSpaceSplit(List<Object> data, String[] designArr) {
  1062. List<List<Object>> result = new ArrayList<>();
  1063. if (ListUtils.isNotEmpty(data) && designArr != null) {
  1064. /*首尾去空*/
  1065. data = listTrim(data);
  1066. String tmp = data.stream().map(StringUtils::handleNull).collect(Collectors.joining(","));
  1067. tmp = tmp.replaceAll(",,,+", ",,");
  1068. List<List<Object>> preliminary = Arrays.stream(tmp.split(",,")).map(CustomFunction::obj2ListNe).collect(Collectors.toList());
  1069. /*默认容量16,小于12不会自动扩容*/
  1070. LinkedHashMap<Integer, List<Object>> classify = new LinkedHashMap<>();
  1071. for (int i = 0; i < preliminary.size(); i++) {
  1072. int key = i % designArr.length;
  1073. classify.merge(key, preliminary.get(i), (v1, v2) -> {
  1074. v1.addAll(v2);
  1075. return v1;
  1076. });
  1077. }
  1078. result = new ArrayList<>(classify.values());
  1079. }
  1080. return result;
  1081. }
  1082. public static List<Object> listTrim(List<Object> list) {
  1083. List<Object> result = new ArrayList<>();
  1084. if (ListUtils.isNotEmpty(list)) {
  1085. int end = list.size();
  1086. for (int i = list.size() - 1; i >= 0; i--) {
  1087. if (StringUtils.isNotEmpty(list.get(i)) || i == 0) {
  1088. end = i + 1;
  1089. break;
  1090. }
  1091. }
  1092. int start = 0;
  1093. for (int i = 0; i < list.size(); i++) {
  1094. if (StringUtils.isNotEmpty(list.get(i))) {
  1095. start = i;
  1096. break;
  1097. }
  1098. }
  1099. return list.subList(start, end);
  1100. }
  1101. return result;
  1102. }
  1103. public static final String ELE_CODE_REG = "(?<=E\\[)[^]]+(?=\\])";
  1104. public static final Pattern P = Pattern.compile(ELE_CODE_REG);
  1105. public static List<String> parseElementCode(String s) {
  1106. List<String> result = new ArrayList<>();
  1107. Matcher m = P.matcher(s);
  1108. while (m.find()) {
  1109. result.add(m.group().replace("'", ""));
  1110. }
  1111. return result;
  1112. }
  1113. public static String coefficient(String dev, double xN) {
  1114. if (StringUtils.isNotEmpty(dev) && xN != 1) {
  1115. String[] da = dev.split("[,,]");
  1116. int scale = StringUtils.getScale(xN);
  1117. dev = StringUtils.number2StringZero(Double.parseDouble(da[0]) * xN, scale) + "," + StringUtils.number2StringZero(Double.parseDouble(da[1]) * xN, scale);
  1118. }
  1119. return dev;
  1120. }
  1121. public static List<Object> b445random(Object hz, Object design, Object dev, Object failed, Object xN) {
  1122. List<Object> measureOut = new ArrayList<>();
  1123. String hzStr = StringUtils.handleNull(hz);
  1124. String designStr = StringUtils.handleNull(design);
  1125. String deviationStr = StringUtils.handleNull(dev);
  1126. if (StringUtils.isNotEmpty(hzStr, designStr, deviationStr)) {
  1127. String passStr = StringUtils.handleNull(failed);
  1128. if (StringUtils.isEmpty(passStr)) {
  1129. passStr = "0";
  1130. }
  1131. String[] rateIn = hzStr.split("/");
  1132. rateIn = Arrays.stream(rateIn).filter(StringUtils::isNotEmpty).toArray(String[]::new);
  1133. String[] designIn = designStr.split("/");
  1134. designIn = Arrays.stream(designIn).filter(StringUtils::isNotEmpty).toArray(String[]::new);
  1135. String[] deviationIn = deviationStr.split("/");
  1136. deviationIn = Arrays.stream(deviationIn).filter(StringUtils::isNotEmpty).toArray(String[]::new);
  1137. if (xN != null) {
  1138. deviationIn = Arrays.stream(deviationIn).map(e -> coefficient(e, Double.parseDouble(xN.toString()))).toArray(String[]::new);
  1139. }
  1140. String[] passIn = passStr.split("/");
  1141. passIn = Arrays.stream(passIn).filter(StringUtils::isNotEmpty).toArray(String[]::new);
  1142. if (designIn.length > 0) {
  1143. for (int i = 0; i < designIn.length; i++) {
  1144. String e = designIn[i];
  1145. int _hz = Integer.parseInt(i < rateIn.length ? rateIn[i] : rateIn[rateIn.length - 1]);
  1146. String _deviation = i < deviationIn.length ? deviationIn[i] : deviationIn[deviationIn.length - 1];
  1147. String _pass = i < passIn.length ? passIn[i] : passIn[passIn.length - 1];
  1148. int _scale = StringUtils.getScale(e, _deviation);
  1149. String delimiter = StringUtils.handleNull(matcherFindGroup("[^0-9.]", e, 0, false));
  1150. if (StringUtils.isEmpty(delimiter)) {
  1151. delimiter = CONCAT;
  1152. }
  1153. String[] _des = e.split("[" + delimiter + "]");
  1154. List<Object> _tmp = new ArrayList<>();
  1155. for (String _de : _des) {
  1156. List<Object> list;
  1157. double passD = Double.parseDouble(_pass);
  1158. /**大于0小于1则表示合格率,否则是不合格数量*/
  1159. double rate = (0 < passD && passD < 1) ? passD : (_hz - passD) / _hz;
  1160. list = cmv(_hz, _de, _deviation, rate, _scale);
  1161. if (ListUtils.isNotEmpty(list)) {
  1162. if (list.size() > _tmp.size()) {
  1163. _tmp.addAll(list);
  1164. } else {
  1165. for (int n = 0; n < _tmp.size(); n++) {
  1166. /*假如设计值是DxD1这种形式,则需要把生成的实测值拼接起来*/
  1167. _tmp.set(n, StringUtils.join(_tmp.get(n), list.get(n), delimiter));
  1168. }
  1169. }
  1170. }
  1171. }
  1172. measureOut.addAll(_tmp);
  1173. }
  1174. }
  1175. }
  1176. return measureOut;
  1177. }
  1178. /**
  1179. * @return java.lang.Object
  1180. * @Description 共检点合格点公式
  1181. * @Param [data 数据, remark超出10个后的提示, design实际值, dev偏差值]
  1182. * @Author yangyj
  1183. * @Date 2022.02.11 10:09
  1184. **/
  1185. public static Object checkpoints(Object data, Object remark, Object design, Object dev, Object xN) {
  1186. if (data != null) {
  1187. if (data instanceof String && ((String) data).contains("NumberFormatException")) {
  1188. return data;
  1189. }
  1190. Object[] R = ck(data, design, dev, xN);
  1191. if (R[0] != null && R[1] != null && R[2] != null) {
  1192. int checkpoints = Integer.parseInt(R[0].toString());
  1193. int passpoints = Integer.parseInt(R[1].toString());
  1194. List<Object> result = (List<Object>) R[2];
  1195. boolean over = checkpoints > result.size();
  1196. if (checkpoints <= 0) {
  1197. return "/";
  1198. } else if (ListUtils.isNotEmpty(result) && result.size() <= 10 && !over) {
  1199. result = result.stream().map(obj -> {
  1200. if (StringUtils.isNumber(obj)) {
  1201. if (obj.toString().contains(".")) {
  1202. BigDecimal big = new BigDecimal(obj.toString());
  1203. String s = big.toString();
  1204. return s.replaceAll("(0+|\\.0+)$", "");
  1205. }
  1206. }
  1207. return obj;
  1208. }).collect(Collectors.toList());
  1209. return join(result, "、");
  1210. } else {
  1211. if (StringUtils.isEmpty(remark)) {
  1212. remark = "共检点,合格点";
  1213. }
  1214. return remark.toString().replace("共检", "共检" + checkpoints).replace("合格", "合格" + passpoints);
  1215. }
  1216. }
  1217. }
  1218. return "/";
  1219. }
  1220. public static Object[] ck(Object data, Object design, Object dev, Object xN) {
  1221. Object[] r = new Object[3];
  1222. List<Object> result = new ArrayList<>();
  1223. List<Object> datas = obj2List(removeEmpty(data));
  1224. if (ListUtils.isNotEmpty(datas)) {
  1225. int checkpoints = 0;
  1226. int passpoints = 0;
  1227. List<Object> designList = obj2List(design);
  1228. if (ListUtils.isNotEmpty(designList)) {
  1229. design = designList.get(0);
  1230. }
  1231. for (Object e : datas) {
  1232. String s = handleNull(e);
  1233. if (StringUtils.isNotEmpty(s)) {
  1234. if (containsZH(s)) {
  1235. Matcher m = RegexUtils.matcher("[\u4e00-\u9fa5]+(\\d+)\\D*合格(\\d+)\\D+", s);
  1236. if (m.find()) {
  1237. checkpoints += Integer.parseInt(m.group(1));
  1238. passpoints += Integer.parseInt(m.group(2));
  1239. }
  1240. } else {
  1241. result.add(s);
  1242. }
  1243. }
  1244. }
  1245. result = result.stream().map(StringUtils::handleNull).map(String::trim).filter(e -> !StringUtils.isEquals("/", e)).collect(Collectors.toList());
  1246. if (result.size() > 0) {
  1247. List<Object> pl = passList(design, dev, result, xN);
  1248. passpoints += pl.size();
  1249. result = obj2List(result);
  1250. checkpoints += result.size();
  1251. } else {
  1252. System.out.println();
  1253. }
  1254. r[0] = checkpoints;
  1255. r[1] = passpoints;
  1256. r[2] = result;
  1257. }
  1258. return r;
  1259. }
  1260. public static Object tree(List<String> treeNodes, String param) {
  1261. if (CollectionUtil.isNotEmpty(treeNodes) && Func.isNotBlank(param)) {
  1262. List<String> nodes = new ArrayList<>(treeNodes);
  1263. //Collections.reverse(nodes);
  1264. List<String> result = new ArrayList<>();
  1265. param = param.trim().replaceAll("(?i:c)", "");
  1266. List<String> list = Arrays.asList(param.split("[^.\\d]"));
  1267. List<Integer> index = list.stream().map(Integer::parseInt).collect(Collectors.toList());
  1268. for (Integer i : index) {
  1269. if (i < nodes.size()) {
  1270. result.add(nodes.get(i));
  1271. }
  1272. }
  1273. return String.join("", result);
  1274. }
  1275. return "";
  1276. }
  1277. public static Object tableNames(List<String> treeNodes) {
  1278. if (CollectionUtil.isNotEmpty(treeNodes)) {
  1279. List<String> nodes = new ArrayList<>(treeNodes);
  1280. return nodes.stream().filter(e -> StringUtils.isNotEmpty(e) && !e.contains("A15")).map(e -> e.replaceAll("_(PL)?_\\d+$", "")).distinct().collect(Collectors.joining("\n"));
  1281. }
  1282. return "";
  1283. }
  1284. public static Object qrate(Object design, Object dev, Object data) {
  1285. return qrate(design, dev, data, 0, 1);
  1286. }
  1287. public static Object qrate(Object design, Object dev, Object data, Object scale) {
  1288. return qrate(design, dev, data, scale, 1);
  1289. }
  1290. /**
  1291. * @return java.lang.Object
  1292. * @Description Qualified rate of measured value 计算合格率
  1293. * @Param [design: 设计值, dev:偏差范围或规定值, xN:偏差值单位转设计值单位倍率, data:数据, scale:保留小数位]
  1294. * @Author yangyj
  1295. * @Date 2022.01.14 09:56
  1296. **/
  1297. public static Object qrate(Object design, Object dev, Object data, Object scale, Object xN) {
  1298. if (data != null && StringUtils.isNotEmpty(design, dev, xN)) {
  1299. Object[] R = ck(data, design, dev, xN);
  1300. if (R[0] != null && R[1] != null && Math.abs(Double.parseDouble(R[0].toString())) > 0) {
  1301. String result = StringUtils.number2String(Double.parseDouble(R[1].toString()) * 100 / Double.parseDouble(R[0].toString()), scale);
  1302. if (result.contains(".")) {
  1303. result = result.replaceAll("(0+|\\.0+)$", "");
  1304. }
  1305. return result;
  1306. }
  1307. }
  1308. return "";
  1309. }
  1310. public static Object easyRate(Object data) {
  1311. if (null != data) {
  1312. List<Object> datas = obj2List(data);
  1313. if (datas.stream().anyMatch(CustomFunction::containsZH)) {
  1314. return 100;
  1315. }
  1316. }
  1317. return "";
  1318. }
  1319. /**
  1320. * @return java.lang.Object
  1321. * @Description 检查内容
  1322. * @Param [items, names]
  1323. * @Author yangyj
  1324. * @Date 2023.02.24 14:56
  1325. **/
  1326. public static Object checkContent(Object items, Object names) {
  1327. if (items != null && names != null) {
  1328. List<Object> result = new ArrayList<>();
  1329. List<Object> content = obj2List(items);
  1330. List<Object> list = obj2List(names);
  1331. for (int i = 0; i < list.size(); i++) {
  1332. Object cp = content.get(i);
  1333. if (StringUtils.isNotEmpty(cp) && StringUtils.isNotEquals("/", cp)) {
  1334. result.add(list.get(i));
  1335. }
  1336. }
  1337. if (ListUtils.isNotEmpty(result)) {
  1338. return result.stream().map(StringUtils::handleNull).collect(Collectors.joining(StringPool.COMMA));
  1339. }
  1340. }
  1341. return "";
  1342. }
  1343. /**
  1344. * @return java.lang.Object
  1345. * @Description 筛选合格的部分
  1346. * @Param [design, dev, data, xN]
  1347. * @Author yangyj
  1348. * @Date 2022.02.12 13:59
  1349. **/
  1350. public static List<Object> passList(Object design, Object dev, Object data, Object xN) {
  1351. List<Object> result = new ArrayList<>();
  1352. List<Object> datas = obj2List(data);
  1353. datas = (List<Object>) removeEmpty(datas);
  1354. Double[] range = scopeParse(dev, design, xN);
  1355. assert range != null;
  1356. double finalMin = range[0];
  1357. double finalMax = range[1];
  1358. List<Object> l1 = datas.stream().map(StringUtils::handleNull).filter(e -> e.contains("*") || e.contains("X") || e.contains("x") || e.contains("×") || e.contains("/")).collect(Collectors.toList());
  1359. if (ListUtils.isNotEmpty(l1)) {
  1360. for (Object obj : l1) {
  1361. String[] arr = obj.toString().split("[×xX*/]");
  1362. if (Arrays.stream(Arrays.stream(arr).toArray()).allMatch(StringUtils::isNumber)) {
  1363. if (Arrays.stream(Arrays.stream(arr).toArray()).map(StringUtils::handleNull).map(Double::parseDouble).noneMatch(e -> e > finalMax || e < finalMin)) {
  1364. result.add(obj);
  1365. }
  1366. }
  1367. }
  1368. }
  1369. List<Object> l2 = datas.stream().filter(StringUtils::isNumber).map(StringUtils::handleNull).map(Double::parseDouble).filter(e -> e <= finalMax && e >= finalMin).collect(Collectors.toList());
  1370. if (ListUtils.isNotEmpty(l2)) {
  1371. result.addAll(l2);
  1372. }
  1373. return result;
  1374. }
  1375. public static Double[] scopeParse(Object dev, Object design, Object xN) {
  1376. if (StringUtils.isNotEmpty(dev)) {
  1377. Double[] result = new Double[2];
  1378. double designD = Double.parseDouble(design.toString());
  1379. double xND = Double.parseDouble(xN.toString());
  1380. String devStr = dev.toString();
  1381. devStr = devStr.replaceAll("[\\[\\]]+", "");
  1382. double min = 0;
  1383. double max = 0;
  1384. devStr = devStr.replaceAll("\\s+", "");
  1385. if (devStr.contains("≤") || devStr.contains("<=") || devStr.contains("<")) {
  1386. devStr = devStr.replace("≤", "").replace("<=", "");
  1387. max = designD + Double.parseDouble(devStr) * xND;
  1388. } else if (devStr.contains("≥") || devStr.contains(">=") || devStr.contains(">")) {
  1389. devStr = devStr.replace("≥", "").replace(">=", "");
  1390. min = designD + Double.parseDouble(devStr) * xND;
  1391. max = Double.MAX_VALUE;
  1392. } else if (devStr.contains(",") || devStr.contains(",")) {
  1393. String[] arr = devStr.split("[,,]");
  1394. min = designD + Double.parseDouble(arr[0]) * xND;
  1395. max = designD + Double.parseDouble(arr[1]) * xND;
  1396. } else if (devStr.contains("%")) {
  1397. devStr = devStr.replace("%", "");
  1398. double devD = Math.abs(Double.parseDouble(devStr) * designD / 100);
  1399. min = designD - devD;
  1400. max = designD + devD;
  1401. } else if (devStr.contains("±")) {
  1402. devStr = devStr.replace("±", "");
  1403. double devD = Math.abs(Double.parseDouble(devStr) * xND);
  1404. min = designD - devD;
  1405. max = designD + devD;
  1406. }
  1407. result[0] = min;
  1408. result[1] = max;
  1409. return result;
  1410. }
  1411. return null;
  1412. }
  1413. /**
  1414. * @return java.util.List<java.lang.Object>
  1415. * @Description specifiedRangeList
  1416. * @Param [hz:频率, design:设计值, dev:偏差范围, xN 偏差范围单位和设计值单位的比值,例如毫米:厘米=0.1, scale:保存小数位, passRate:合格率[0,1]]
  1417. * @Author yangyj
  1418. * @Date 2022.03.31 09:16
  1419. **/
  1420. public static List<Object> rangeList(Object hz, Object design, Object dev, Object xN, Object scale, Object passRate) {
  1421. List<Object> result = new ArrayList<>();
  1422. if (StringUtils.isNotEmpty(design, dev, hz)) {
  1423. if (StringUtils.isEmpty(scale)) {
  1424. scale = 0;
  1425. }
  1426. if (StringUtils.isEmpty(passRate)) {
  1427. passRate = 1;
  1428. }
  1429. if (StringUtils.isEmpty(xN)) {
  1430. xN = 1;
  1431. }
  1432. Double[] range = scopeParse(dev, design, xN);
  1433. int scaleI = Integer.parseInt(scale.toString());
  1434. int min = 0, max = 0;
  1435. assert range != null;
  1436. if (range.length > 0) {
  1437. min = (int) (range[0] * Math.pow(10, scaleI));
  1438. max = (int) (range[1] * Math.pow(10, scaleI));
  1439. }
  1440. Random rd = new Random();
  1441. int hzi = new BigDecimal(hz.toString()).multiply(new BigDecimal(passRate.toString())).setScale(0, ROUND_CEILING).intValue();
  1442. for (int i = 0; i < hzi; i++) {
  1443. BigDecimal tb = new BigDecimal(rd.nextInt(max - min + 1) + min).divide(BigDecimal.valueOf(Math.pow(10, scaleI)), scaleI, ROUND_HALF_UP);
  1444. if (scaleI > 0) {
  1445. result.add(tb.doubleValue());
  1446. } else {
  1447. result.add(tb.intValue());
  1448. }
  1449. }
  1450. int total = StringUtils.handleObj2Integer(hz);
  1451. if (total - hzi > 0) {
  1452. for (int k = 0; k < total - hzi; k++) {
  1453. BigDecimal tb;
  1454. if (rd.nextBoolean()) {
  1455. tb = new BigDecimal(rd.nextInt(((max - min) / 2)) + max + 1).divide(BigDecimal.valueOf(Math.pow(10, scaleI)), scaleI, ROUND_HALF_UP);
  1456. } else {
  1457. tb = new BigDecimal(min - 1 - rd.nextInt(((max - min) / 2))).divide(BigDecimal.valueOf(Math.pow(10, scaleI)), scaleI, ROUND_HALF_UP);
  1458. }
  1459. if (scaleI > 0) {
  1460. result.add(tb.doubleValue());
  1461. } else {
  1462. result.add(tb.intValue());
  1463. }
  1464. }
  1465. if (ListUtils.isNotEmpty(result)) {
  1466. Collections.shuffle(result);
  1467. }
  1468. }
  1469. }
  1470. return result;
  1471. }
  1472. /**
  1473. * @return java.util.List<java.lang.Object>
  1474. * @Description obj 转List
  1475. * @Param [obj]
  1476. * @Author yangyj
  1477. * @Date 2022.01.13 15:40
  1478. **/
  1479. public static List<Object> obj2List(Object obj) {
  1480. List<Object> result = new ArrayList<>();
  1481. if (obj != null) {
  1482. List<Object> datas = new ArrayList<>();
  1483. if (obj instanceof List) {
  1484. datas = (List<Object>) obj;
  1485. } else {
  1486. datas.add(obj);
  1487. }
  1488. if (ListUtils.isNotEmpty(datas)) {
  1489. for (Object e : datas) {
  1490. boolean fi = StringUtils.isNotEmpty(e) && !CustomFunction.containsZH(e.toString()) && (e.toString().contains("、") || e.toString().contains(",") || e.toString().contains(" ") || e.toString().contains(","));
  1491. if (fi) {
  1492. String s = e.toString().trim();
  1493. if (s.contains(" ")) {
  1494. s = s.replaceAll("\\s+", "、");
  1495. }
  1496. Object[] bs = s.split("[、,,]");
  1497. result.addAll(Arrays.asList(bs));
  1498. } else {
  1499. result.add(e);
  1500. }
  1501. }
  1502. }
  1503. }
  1504. return result;
  1505. }
  1506. /**
  1507. * @return java.lang.Object
  1508. * @Description 对象转字符串,list取第一个对象
  1509. * @Param [obj]
  1510. * @Author yangyj
  1511. * @Date 2022.02.11 15:14
  1512. **/
  1513. public static Object o2Str(Object obj) {
  1514. String result = "";
  1515. if (obj != null) {
  1516. List<Object> datas = obj2List(obj);
  1517. if (ListUtils.isNotEmpty(datas)) {
  1518. return handleNull(datas.get(0));
  1519. }
  1520. }
  1521. return result;
  1522. }
  1523. public static Object gfn(Object ob1, Object ob2, Object ob3) {
  1524. return _gfn(ob1, ob2, ob3);
  1525. }
  1526. public static Object gfn(Object ob1, Object ob2) {
  1527. return _gfn(ob1, ob2);
  1528. }
  1529. public static Object gfn(List<Object> list) {
  1530. if (ListUtils.isNotEmpty(list)) {
  1531. return _gfn(list.toArray());
  1532. }
  1533. return "";
  1534. }
  1535. /**
  1536. * @Description 返回第一个不为空的对象
  1537. * @Param
  1538. * @Author yangyj
  1539. * @Date 2022.01.04 13:57
  1540. **/
  1541. public static Object _gfn(Object... obs) {
  1542. if (obs != null) {
  1543. for (Object ob : obs) {
  1544. if (ob instanceof List) {
  1545. List<Object> list = obj2List(ob);
  1546. if (ListUtils.isNotEmpty(list) && list.stream().anyMatch(StringUtils::isNotEmpty)) {
  1547. return ob;
  1548. }
  1549. } else if (ob instanceof Map) {
  1550. if (MapUtils.isNotEmpty((Map) ob)) {
  1551. return ob;
  1552. }
  1553. } else {
  1554. if (StringUtils.isNotEmpty(ob) && StringUtils.isNotEquals("/", ob)) {
  1555. return ob;
  1556. }
  1557. }
  1558. }
  1559. }
  1560. return null;
  1561. }
  1562. public Object checkItemName(List<Object> data, List<Object> names) {
  1563. if (ListUtils.isNotEmpty(data) && ListUtils.isNotEmpty(names) && data.size() != names.size()) {
  1564. StringBuilder sb = new StringBuilder();
  1565. for (int i = 0; i < data.size(); i++) {
  1566. List<Object> datas = obj2ListNe(data.get(i));
  1567. if (datas.stream().anyMatch(e -> StringUtils.isNotEmpty(e) && StringUtils.isNotEquals("/", e))) {
  1568. sb.append(names.get(i)).append(",");
  1569. }
  1570. }
  1571. if (sb.length() > 1) {
  1572. sb.deleteCharAt(sb.length() - 1);
  1573. }
  1574. return sb.toString();
  1575. }
  1576. return "";
  1577. }
  1578. /**
  1579. * @return java.lang.Object
  1580. * @Description 三元运算 bool?o1:o2 ,默认返回空字符串
  1581. * @Param [bool, o1, o2]
  1582. * @Author yangyj
  1583. * @Date 2021.01.29 13:54
  1584. **/
  1585. public static Object ifValObj(Object bool, Object o1, Object o2) {
  1586. Boolean fi;
  1587. if (bool instanceof Boolean) {
  1588. fi = (Boolean) bool;
  1589. } else {
  1590. return "";
  1591. }
  1592. return fi ? o1 : o2;
  1593. }
  1594. /*太多写错公式名称的,应该是下面的方法名称比较容易接受*/
  1595. public static Object isValObj(Object bool, Object o1, Object o2) {
  1596. return ifValObj(bool, o1, o2);
  1597. }
  1598. /**
  1599. * @return java.lang.Object
  1600. * @Description 判断o1中是否包含字符串o2
  1601. * @Param [o1, o2]
  1602. * @Author yangyj
  1603. * @Date 2021.01.29 14:04
  1604. **/
  1605. public static Object contains(Object o1, Object o2) {
  1606. if (o1 != null && StringUtils.isNotEmpty(o2)) {
  1607. List<Object> datas = obj2List(o1);
  1608. return datas.stream().map(StringUtils::handleNull).anyMatch(e -> e.contains(o2.toString()));
  1609. }
  1610. return false;
  1611. }
  1612. /**
  1613. * @return java.lang.Object
  1614. * @Description 判断两个对象是否相等
  1615. * @Param [o1, o2]
  1616. * @Author yangyj
  1617. * @Date 2021.08.23 16:51
  1618. **/
  1619. public static Object eq(Object o1, Object o2) {
  1620. return StringUtils.isEquals(o1, o2);
  1621. }
  1622. /**
  1623. * @return java.lang.Object
  1624. * @Description 计算数据集的合格率
  1625. * @Param [list:数据集, design:设计值, dev:偏差范围, scale:保存小数位]
  1626. * @Author yangyj
  1627. * @Date 2021.10.26 09:34
  1628. **/
  1629. public static Object getListTick(Object list, Object design, Object dev, Object scale) {
  1630. if (list != null && design != null && StringUtils.isNotEmpty(dev)) {
  1631. if (!StringUtils.isNumber(scale)) {
  1632. scale = 0;
  1633. }
  1634. Matcher m = RegexUtils.matcher("(-?\\d+(\\.\\d+)?)[h|H]?[,|,](\\+?\\d+(\\.\\d+)?)[h|H]?", dev.toString().replaceAll("[(|)]", ""));
  1635. if (list instanceof List && m.find()) {
  1636. List<Object> arrayList = (ArrayList<Object>) list;
  1637. double tick = 0;
  1638. double designD = Double.parseDouble(handleNull(design));
  1639. double h = 1;
  1640. if (dev.toString().toUpperCase(Locale.ROOT).contains("H")) {
  1641. h = designD;
  1642. }
  1643. for (Object obj : arrayList) {
  1644. double dx = Double.parseDouble(handleNull(obj)) - designD;
  1645. if (Double.parseDouble(m.group(1)) * h <= dx && dx <= Double.parseDouble(m.group(3)) * h) {
  1646. tick++;
  1647. }
  1648. }
  1649. if (tick > 0) {
  1650. BigDecimal a = new BigDecimal(tick);
  1651. BigDecimal b = new BigDecimal(arrayList.size());
  1652. return a.divide(b, 8, ROUND_HALF_UP).multiply(new BigDecimal(100)).setScale(StringUtils.handleObj2Integer(scale.toString()), ROUND_HALF_UP);
  1653. } else {
  1654. return "0";
  1655. }
  1656. }
  1657. }
  1658. return "";
  1659. }
  1660. /**
  1661. * @return java.lang.Object
  1662. * @Description 获取最后一个对象
  1663. * @Param [list]
  1664. * @Author yangyj
  1665. * @Date 2021.08.09 14:37
  1666. **/
  1667. public static Object listAt(Object o, Object indexObj) {
  1668. if (o == null) {
  1669. return "";
  1670. }
  1671. if (o instanceof List) {
  1672. List<Object> list = obj2ListNe(o);
  1673. int index = 0;
  1674. if (NumberUtil.isNumber(indexObj.toString())) {
  1675. index = StringUtils.handObj2Integer(indexObj) - 1;
  1676. } else if (StringUtils.isEquals("last", indexObj) || StringUtils.isEmpty(indexObj)) {
  1677. index = list.size() - 1;
  1678. }
  1679. if (ListUtils.isNotEmpty(list)) {
  1680. if (list.size() > index && index >= 0) {
  1681. return list.get(index);
  1682. } else {
  1683. return list.get(list.size() - 1);
  1684. }
  1685. }
  1686. } else {
  1687. return o.toString();
  1688. }
  1689. return "";
  1690. }
  1691. /**
  1692. * @Description 关键字转换
  1693. * @Param [cn]
  1694. * @Author yangyj
  1695. * @Date 2022.10.10 17:24
  1696. **/
  1697. public static void formulaKeyWord(CalculateNode cn) {
  1698. if (cn.type().equals(Token.OPERATOR_RESULT)) {
  1699. OperatorResultNode opn = (OperatorResultNode) cn;
  1700. formulaKeyWord(opn.getLeftOperand());
  1701. formulaKeyWord(opn.getRightOperand());
  1702. } else if (cn.type().equals(Token.METHOD_RESULT)) {
  1703. StaticObjectMethodNode cmn = (StaticObjectMethodNode) cn;
  1704. CalculateNode[] array = cmn.getArgsNodes();
  1705. if (ArrayUtil.isNotEmpty(array)) {
  1706. for (int i = 0; i < array.length; i++) {
  1707. CalculateNode c = array[i];
  1708. if (c instanceof StaticObjectMethodNode) {
  1709. formulaKeyWord(c);
  1710. } else if (c instanceof VariableNode) {
  1711. if (KEYWORD_SET.contains(c.literals())) {
  1712. /*关键字需要包裹起来*/
  1713. array[i] = new VariableNode("'" + c.literals() + "'");
  1714. }
  1715. }
  1716. }
  1717. }
  1718. cmn.setArgsNodes(array);
  1719. }
  1720. }
  1721. public static List<Object> obj2ListNe(Object obj) {
  1722. List<Object> list = obj2List(obj);
  1723. return list.parallelStream().filter(StringUtils::isNotEmpty).collect(Collectors.toList());
  1724. }
  1725. /*obj2ListNe别名*/
  1726. public static List<Object> objToListNe(Object obj) {
  1727. return obj2ListNe(obj);
  1728. }
  1729. /**
  1730. * @return java.lang.Object
  1731. * @Description 过滤掉List中的空对象
  1732. * @Param [o]
  1733. * @Author yangyj
  1734. * @Date 2021.07.28 11:16
  1735. **/
  1736. public static Object removeEmpty(Object o) {
  1737. List<Object> result = new ArrayList<>();
  1738. if (o instanceof List) {
  1739. for (Object e : (List<Object>) o) {
  1740. if (StringUtils.isNotEmpty(e)) {
  1741. result.add(e);
  1742. }
  1743. }
  1744. } else {
  1745. result.add(o);
  1746. }
  1747. return result;
  1748. }
  1749. /**
  1750. * @return
  1751. * @Description 设置保留小数位
  1752. * @Param
  1753. * @Author yangyj
  1754. * @Date 2021.12.31 17:14
  1755. **/
  1756. public static Object setScale(Object o, Object scale) {
  1757. if (StringUtils.isNumber(scale) && o != null) {
  1758. if (o instanceof List || o.toString().contains(",") || o.toString().contains("、")) {
  1759. List<Object> result = new ArrayList<>();
  1760. List<Object> tmp = obj2ListNe(o);
  1761. for (Object e : tmp) {
  1762. if (StringUtils.isNumber(e)) {
  1763. result.add(StringUtils.number2String(e, scale));
  1764. } else {
  1765. result.add("");
  1766. }
  1767. }
  1768. if (o instanceof String) {
  1769. String delimiter = "、";
  1770. if (o.toString().contains(",")) {
  1771. delimiter = ",";
  1772. }
  1773. return result.stream().map(StringUtils::handleNull).collect(Collectors.joining(delimiter));
  1774. }
  1775. return result;
  1776. } else {
  1777. if (StringUtils.isNumber(o)) {
  1778. return StringUtils.number2String(o, scale);
  1779. }
  1780. }
  1781. }
  1782. return "";
  1783. }
  1784. public static Object abs(Object o) {
  1785. /**
  1786. * @Description 测试
  1787. * @Param [o]
  1788. * @return java.lang.Object
  1789. * @Author yangyj
  1790. * @Date 2022.03.21 15:43
  1791. **/
  1792. if (o != null) {
  1793. if (o instanceof List) {
  1794. List<Object> result = new ArrayList<>();
  1795. List<Object> datas = obj2List(o);
  1796. if (ListUtils.isNotEmpty(datas)) {
  1797. for (Object e : datas) {
  1798. if (StringUtils.isNotEmpty(e)) {
  1799. result.add(e.toString().replaceAll("^-", ""));
  1800. }
  1801. }
  1802. }
  1803. return result;
  1804. } else {
  1805. return o.toString().replaceAll("^-", "");
  1806. }
  1807. }
  1808. return null;
  1809. }
  1810. /**
  1811. * @return java.lang.Object
  1812. * @Description 返回正则式匹配内容
  1813. * @Param [regex:正则式, value:匹配的字符串, i:group(i), g:是否返回全局搜索,全局搜索返回的是列表]
  1814. * @Author yangyj
  1815. * @Date 2021.01.08 16:31
  1816. **/
  1817. public static Object matcherFindGroup(String regex, String value, int i, boolean g) {
  1818. Matcher m = RegexUtils.matcher(regex, value);
  1819. List<Object> result = new ArrayList<>();
  1820. while (m.find()) {
  1821. result.add(m.group(i));
  1822. }
  1823. if (ListUtils.isNotEmpty(result)) {
  1824. if (g) {
  1825. return result;
  1826. } else {
  1827. return result.get(0);
  1828. }
  1829. }
  1830. return null;
  1831. }
  1832. /**
  1833. * @return java.lang.Object
  1834. * @Description 放大缩小
  1835. * @Author yangyj
  1836. * @Date 2022.01.14 14:17
  1837. **/
  1838. public static Object xN(Object o, Object xN) {
  1839. String cur = "";
  1840. try {
  1841. if (StringUtils.isNotEmpty(o) && StringUtils.isNumber(xN)) {
  1842. double xND = Double.parseDouble(xN.toString());
  1843. List<Object> outList = new ArrayList<>();
  1844. if (o instanceof List) {
  1845. List<Object> datas = obj2ListNe(o);
  1846. for (Object e : datas) {
  1847. if (StringUtils.isNotEmpty(e)) {
  1848. String[] as = e.toString().split("[^\\d.-]");
  1849. Object m = matcherFindGroup("[^\\d.-]", e.toString(), 0, false);
  1850. StringBuilder d = new StringBuilder();
  1851. for (int i = 0; i < as.length; i++) {
  1852. String s = as[i];
  1853. cur = s;
  1854. int scale = (int) Math.max(getScale(s) - Math.log10(xND), 0);
  1855. d.append(StringUtils.number2String(Double.parseDouble(s) * xND, scale)).append(i != as.length - 1 && m != null ? m : "");
  1856. }
  1857. outList.add(d.toString());
  1858. }
  1859. }
  1860. if (ListUtils.isNotEmpty(outList)) {
  1861. return outList;
  1862. }
  1863. } else {
  1864. List<Object> datas = Arrays.asList(o.toString().split("[、, ,]"));
  1865. Matcher m = RegexUtils.matcher("[、, ,]", o.toString());
  1866. String s = "、";
  1867. if (m.find()) {
  1868. s = handleNull(m.group());
  1869. }
  1870. if (ListUtils.isNotEmpty(datas)) {
  1871. for (Object e : datas) {
  1872. if (StringUtils.isNotEmpty(e)) {
  1873. int scale = (int) Math.max(getScale(s) - Math.log10(xND), 0);
  1874. cur = e.toString();
  1875. outList.add(StringUtils.number2String(Double.parseDouble(e.toString()) * xND, scale));
  1876. }
  1877. }
  1878. }
  1879. if (ListUtils.isNotEmpty(outList)) {
  1880. return StringUtils.join(outList.stream().map(StringUtils::handleNull).collect(Collectors.toList()), s);
  1881. }
  1882. }
  1883. }
  1884. } catch (NumberFormatException e) {
  1885. e.printStackTrace();
  1886. String error = "";
  1887. if (e.getMessage().contains("multiple points")) {
  1888. error = cur + "包含多个小数点";
  1889. } else {
  1890. error = cur;
  1891. }
  1892. return "NumberFormatException(数字格式异常,请检查)" + error;
  1893. }
  1894. return "";
  1895. }
  1896. /* public static void main(String[] args) {
  1897. List<Object> list = Arrays.asList(1,-1,"-4*8");
  1898. obj2ListNe(xN(list,10)).forEach(System.out::println);
  1899. }*/
  1900. public static Object repeat(Object data) {
  1901. List<Object> result = new ArrayList<>();
  1902. if (data != null) {
  1903. List<Object> list = obj2List(removeEmpty(data));
  1904. /*外观质量,这种中文描述去重*/
  1905. if (list.stream().filter(CustomFunction::containsZH).anyMatch(e -> e.toString().contains("\n"))) {
  1906. AtomicInteger index = new AtomicInteger(1);
  1907. result = list.stream().flatMap(e -> Arrays.stream(e.toString().split("\\n+"))).map(String::trim).map(e -> e.replaceAll("^\\d+[、.\\s]*", "")).distinct().map(e -> (index.getAndIncrement()) + "、" + e + "\n").collect(Collectors.toList());
  1908. } else {
  1909. result = list.stream().distinct().collect(Collectors.toList());
  1910. }
  1911. }
  1912. return result;
  1913. }
  1914. public static List<Object> diffusion(List<Object> data) {
  1915. List<Object> result = new ArrayList<>();
  1916. if (data != null) {
  1917. Optional<Object> op = data.stream().filter(StringUtils::isNotEmpty).findFirst();
  1918. if (op.isPresent()) {
  1919. Object copy = op.get();
  1920. return data.stream().map(e -> StringUtils.isEmpty(e) ? copy : e)
  1921. .collect(Collectors.toList());
  1922. }
  1923. }
  1924. return result;
  1925. }
  1926. /**
  1927. * @return java.lang.Object
  1928. * @Description 截取list subList(list,1,5) 返回list的第1到第5个元素
  1929. * @Param [o]
  1930. * @Author yangyj
  1931. * @Date 2021.07.28 11:16
  1932. **/
  1933. public static Object subList(Object o, Object start, Object end) {
  1934. List<Object> result = new ArrayList<>();
  1935. if (o instanceof List) {
  1936. result = (List<Object>) o;
  1937. int s = StringUtils.handleObj2Integer(start);
  1938. int e = StringUtils.handleObj2Integer(end);
  1939. s = Math.max(s, 1);
  1940. if (e <= 0) {
  1941. e = result.size();
  1942. }
  1943. return result.subList(s - 1, e);
  1944. }
  1945. return result;
  1946. }
  1947. /**
  1948. * @return java.lang.Object
  1949. * @Description 获取G8测点偏差
  1950. * @Param [cd, pc]
  1951. * @Author yangyj
  1952. * @Date 2022.02.25 11:05
  1953. **/
  1954. public static Object g8dx(Object cd, Object pc) {
  1955. if (cd != null && pc != null) {
  1956. List<Object> result = new ArrayList<>();
  1957. List<Object> stakes = obj2List(cd);
  1958. List<Object> dx = obj2List(pc);
  1959. if (ListUtils.isNotEmpty(stakes) && dx.size() >= stakes.size()) {
  1960. Object bmd = stakes.get(0);
  1961. if (StringUtils.isNotEmpty(bmd)) {
  1962. for (int i = 0; i < stakes.size(); i++) {
  1963. Object cp = stakes.get(i);
  1964. if (StringUtils.isNotEmpty(cp) && StringUtils.isNotEquals(bmd, cp)) {
  1965. Matcher m = RegexUtils.matcher("(?i)zd\\d+", cp.toString());
  1966. if (!m.find()) {
  1967. result.add(dx.get(i));
  1968. }
  1969. }
  1970. }
  1971. return result;
  1972. }
  1973. }
  1974. }
  1975. return "";
  1976. }
  1977. public static Object g8stakes(Object cd) {
  1978. if (cd != null) {
  1979. List<Object> result = new ArrayList<>();
  1980. List<Object> stakes = obj2List(cd);
  1981. if (ListUtils.isNotEmpty(stakes)) {
  1982. Object bmd = stakes.get(0);
  1983. if (StringUtils.isNotEmpty(bmd)) {
  1984. for (Object cp : stakes) {
  1985. if (StringUtils.isNotEmpty(cp) && StringUtils.isNotEquals(bmd, cp)) {
  1986. Matcher m = RegexUtils.matcher("(?i)zd\\d+", cp.toString());
  1987. if (!m.find()) {
  1988. result.add(cp);
  1989. }
  1990. }
  1991. }
  1992. return result;
  1993. }
  1994. }
  1995. }
  1996. return "";
  1997. }
  1998. public static List<Object> g8c103(Object cd, Object sj, Object sc, Object dx) {
  1999. List<Object> result = new ArrayList<>();
  2000. if (cd != null && sj != null && sc != null && dx != null) {
  2001. List<Object> cds = obj2List(cd);
  2002. List<Object> sjs = obj2List(sj);
  2003. List<Object> scs = obj2List(sc);
  2004. List<Object> dxs = obj2List(dx);
  2005. int min = Math.min(Math.min(sjs.size(), scs.size()), dxs.size());
  2006. if (ListUtils.isNotEmpty(cds) && min >= cds.size()) {
  2007. Object bmd = cds.get(0);
  2008. if (StringUtils.isNotEmpty(bmd)) {
  2009. for (int i = 0; i < cds.size(); i++) {
  2010. Object cp = cds.get(i);
  2011. if (StringUtils.isNotEmpty(cp) && StringUtils.isNotEquals(bmd, cp)) {
  2012. Matcher m = RegexUtils.matcher("(?i)zd\\d+", cp.toString());
  2013. if (!m.find()) {
  2014. if (StringUtils.isNumber(cp)) {
  2015. result.add("");
  2016. result.add("");
  2017. result.add("");
  2018. result.add(dxs.get(i));
  2019. } else {
  2020. result.add(sjs.get(i));
  2021. result.add(scs.get(i));
  2022. result.add(dxs.get(i));
  2023. result.add("");
  2024. }
  2025. }
  2026. }
  2027. }
  2028. }
  2029. }
  2030. }
  2031. return result;
  2032. }
  2033. public static List<Object> g8zzds(Object cd, Object dx, Object fi) {
  2034. List<Object> result = new ArrayList<>();
  2035. if (cd != null && dx != null) {
  2036. List<Object> cds = obj2List(cd);
  2037. List<Object> dxs = obj2List(dx);
  2038. boolean bol = (boolean) fi;
  2039. int min = dxs.size();
  2040. if (ListUtils.isNotEmpty(cds) && min >= cds.size()) {
  2041. Object bmd = cds.get(0);
  2042. List<String> l1 = new ArrayList<>();
  2043. List<String> l2 = new ArrayList<>();
  2044. List<String> l3 = new ArrayList<>();
  2045. List<String> dyn;
  2046. if (bol) {
  2047. dyn = l3;
  2048. } else {
  2049. dyn = l2;
  2050. }
  2051. if (StringUtils.isNotEmpty(bmd)) {
  2052. for (int i = 0; i < cds.size(); i++) {
  2053. Object cp = cds.get(i);
  2054. if (StringUtils.isNotEmpty(cp) && StringUtils.isNotEquals(bmd, cp)) {
  2055. Matcher m = RegexUtils.matcher("(?i)zd\\d+", cp.toString());
  2056. if (!m.find()) {
  2057. if (StringUtils.isNumber(cp)) {
  2058. dyn.add(handleNull(dxs.get(i)));
  2059. } else {
  2060. l1.add(handleNull(dxs.get(i)));
  2061. }
  2062. }
  2063. }
  2064. }
  2065. result.add(StringUtils.join(l1, ","));
  2066. result.add(StringUtils.join(l2, ","));
  2067. result.add(StringUtils.join(l3, ","));
  2068. }
  2069. }
  2070. }
  2071. return result;
  2072. }
  2073. public static List<Object> gcc(Object zh, Object sj, Object sc, Object dx, Object mode) {
  2074. List<Object> result = new ArrayList<>();
  2075. if (zh != null && sj != null && sc != null && dx != null) {
  2076. List<Object> cds = obj2List(zh);
  2077. List<Object> sjs = obj2List(sj);
  2078. List<Object> scs = obj2List(sc);
  2079. List<Object> dxs = obj2List(dx);
  2080. int min = Math.min(Math.min(dxs.size(), sjs.size()), scs.size());
  2081. if (ListUtils.isNotEmpty(cds) && min >= cds.size()) {
  2082. Object bmd = cds.get(0);
  2083. if (StringUtils.isNotEmpty(bmd)) {
  2084. for (int i = 0; i < cds.size(); i++) {
  2085. Object cp = cds.get(i);
  2086. if (StringUtils.isNotEmpty(cp) && StringUtils.isNotEquals(bmd, cp)) {
  2087. Matcher m = RegexUtils.matcher("(?i)zd\\d+", cp.toString());
  2088. if (!m.find()) {
  2089. if (StringUtils.isEquals(mode, 0)) {
  2090. if (!Pattern.matches(".+(?i)v$", cp.toString())) {
  2091. result.add(sjs.get(i));
  2092. result.add(scs.get(i));
  2093. result.add(dxs.get(i));
  2094. }
  2095. } else if (StringUtils.isEquals(mode, 1)) {
  2096. if (Pattern.matches(".+(?i)v$", cp.toString())) {
  2097. result.add(sjs.get(i));
  2098. result.add(scs.get(i));
  2099. result.add(dxs.get(i));
  2100. }
  2101. }
  2102. }
  2103. }
  2104. }
  2105. }
  2106. }
  2107. }
  2108. return result;
  2109. }
  2110. /**
  2111. * @return java.lang.Object
  2112. * @Description list 去头尾
  2113. * @Param [o]
  2114. * @Author yangyj
  2115. * @Date 2021.12.31 14:53
  2116. **/
  2117. public static Object removeHT(Object o) {
  2118. List<Object> result = new ArrayList<>();
  2119. if (o instanceof List) {
  2120. result = (List<Object>) o;
  2121. if (result.size() > 2) {
  2122. int end = result.size();
  2123. for (int i = result.size() - 1; i > 1; i--) {
  2124. if (StringUtils.isNotEmpty(result.get(i))) {
  2125. end = i;
  2126. break;
  2127. }
  2128. }
  2129. return subList(result, 2, end);
  2130. }
  2131. }
  2132. return result;
  2133. }
  2134. public static Object removeByReg(Object o, Object reg) {
  2135. List<Object> result = new ArrayList<>();
  2136. if (o instanceof List && StringUtils.isNotEmpty(reg)) {
  2137. result = (List<Object>) o;
  2138. return result.stream().map(StringUtils::handleNull).filter(e -> !Pattern.matches(reg.toString(), e)).collect(Collectors.toList());
  2139. }
  2140. return result;
  2141. }
  2142. /**
  2143. * @return java.lang.Object
  2144. * @Description 获取动态行某列内容
  2145. * @Param [data, field]
  2146. * @Author yangyj
  2147. * @Date 2022.01.08 10:02
  2148. **/
  2149. public static Object getColumn(Object data, Object field) {
  2150. if (StringUtils.isNotEmpty(field)) {
  2151. List<HashMap<String, Object>> _data = objToArray(data);
  2152. if (ListUtils.isNotEmpty(_data)) {
  2153. return _data.stream().map(e -> e.get(field.toString())).collect(Collectors.toList());
  2154. }
  2155. }
  2156. return data;
  2157. }
  2158. /**
  2159. * @return java.lang.Object
  2160. * @Description 合并多个list
  2161. * @Param [listArr]
  2162. * @Author yangyj
  2163. * @Date 2021.12.31 15:10
  2164. **/
  2165. public static Object mergeList(Object l1, Object l2) {
  2166. return _mergeList(l1, l2);
  2167. }
  2168. public static Object mergeList(Object l1, Object l2, Object l3) {
  2169. return _mergeList(l1, l2, l3);
  2170. }
  2171. public static Object mergeList(Object l1, Object l2, Object l3, Object l4) {
  2172. return _mergeList(l1, l2, l3, l4);
  2173. }
  2174. public static Object mergeList(Object l1, Object l2, Object l3, Object l4, Object l5) {
  2175. return _mergeList(l1, l2, l3, l4, l5);
  2176. }
  2177. public static Object mergeList(Object l1, Object l2, Object l3, Object l4, Object l5, Object l6) {
  2178. return _mergeList(l1, l2, l3, l4, l5, l6);
  2179. }
  2180. public static Object mergeList(Object l1, Object l2, Object l3, Object l4, Object l5, Object l6, Object l7) {
  2181. return _mergeList(l1, l2, l3, l4, l5, l6, l7);
  2182. }
  2183. public static Object mergeList(Object l1, Object l2, Object l3, Object l4, Object l5, Object l6, Object l7, Object l8) {
  2184. return _mergeList(l1, l2, l3, l4, l5, l6, l7, l8);
  2185. }
  2186. public static Object _mergeList(Object... listArr) {
  2187. List<Object> result = new ArrayList<>();
  2188. if (listArr != null && listArr.length >= 2) {
  2189. List<List<Object>> tmp = new ArrayList<>();
  2190. int max = 0;
  2191. for (Object o : listArr) {
  2192. List<Object> list = Collections.singletonList("");
  2193. if (o instanceof List) {
  2194. list = (List<Object>) o;
  2195. max = Math.max(max, list.size());
  2196. }
  2197. tmp.add(list);
  2198. }
  2199. if (ListUtils.isNotEmpty(tmp)) {
  2200. for (int i = 0; i < max; i++) {
  2201. for (List<Object> _l : tmp) {
  2202. if (_l.size() > i) {
  2203. result.add(_l.get(i));
  2204. } else {
  2205. result.add("");
  2206. }
  2207. }
  2208. }
  2209. }
  2210. }
  2211. return result;
  2212. }
  2213. /**
  2214. * @return java.lang.Object
  2215. * @Description list 转 string
  2216. * @Param [o, separator:分隔符]
  2217. * @Author yangyj
  2218. * @Date 2021.07.28 15:50
  2219. **/
  2220. public static Object join(Object o1, Object separator) {
  2221. Optional<Object> op = Optional.ofNullable(o1);
  2222. if (op.isPresent()) {
  2223. String s = StringUtils.handleNull(separator);
  2224. if (StringUtils.isEmpty(s)) {
  2225. s = "、";
  2226. }
  2227. return op.map(CustomFunction::obj2ListNe).orElse(Collections.singletonList("")).stream().map(StringUtils::handleNull).collect(Collectors.joining(s));
  2228. }
  2229. ;
  2230. return "";
  2231. }
  2232. /**
  2233. * @return java.lang.Object
  2234. * @Description String 转List
  2235. * @Param [o, separator]
  2236. * @Author yangyj
  2237. * @Date 2021.12.03 15:09
  2238. **/
  2239. public static Object split(Object o, Object separator) {
  2240. if (StringUtils.isNotEmpty(o, separator)) {
  2241. System.out.println(separator);
  2242. String[] arr = o.toString().split(separator.toString());
  2243. return Arrays.stream(arr).collect(Collectors.toList());
  2244. }
  2245. return null;
  2246. }
  2247. public static Object split(Object o) {
  2248. return split(o, "/|,|、|,|;|;|\\\\|(\\s+)");
  2249. }
  2250. /**
  2251. * @Description 删除下标为index的元素
  2252. * @Param [o, index]
  2253. * @Author yangyj
  2254. * @Date 2021.07.28 15:52
  2255. **/
  2256. public static void rem(Object o, Object index) {
  2257. if (o instanceof List && StringUtils.isNumber(index)) {
  2258. ((List<Object>) o).remove(StringUtils.handleObj2Integer(index).intValue());
  2259. }
  2260. }
  2261. /**
  2262. * @return java.lang.Object
  2263. * @Description 根据百分比返回子集list内容
  2264. * @Param [obj:数据源, percent:0-100]
  2265. * @Author yangyj
  2266. * @Date 2020.12.04 09:24
  2267. **/
  2268. public static Object getListPercent(Object obj, Object percent) {
  2269. if (obj != null && percent != null) {
  2270. if (obj instanceof List) {
  2271. ArrayList<Object> list = (ArrayList<Object>) obj;
  2272. Collections.shuffle(list);
  2273. int n = (int) Math.round((Double.parseDouble(percent.toString()) / 100) * list.size());
  2274. if (n <= list.size()) {
  2275. return list.subList(0, n);
  2276. }
  2277. return list;
  2278. }
  2279. }
  2280. return "";
  2281. }
  2282. /**
  2283. * @return java.util.ArrayList<java.util.HashMap < java.lang.String, java.lang.Object>>
  2284. * @Description 把Object 转换成 ArrayList<HashMap<String, Object>>
  2285. * @Param [obj]
  2286. * @Author yangyj
  2287. * @Date 2020.12.11 09:44
  2288. **/
  2289. public static List<HashMap<String, Object>> objToArray(Object obj) {
  2290. if (obj instanceof ArrayList) {
  2291. return (List<HashMap<String, Object>>) obj;
  2292. } else if (obj instanceof HashMap) {
  2293. List<HashMap<String, Object>> array = new ArrayList<>();
  2294. HashMap<String, Object> map = (HashMap<String, Object>) obj;
  2295. if (map.size() > 0) {
  2296. array.add(map);
  2297. }
  2298. return array;
  2299. }
  2300. return null;
  2301. }
  2302. public static Object dXd(Object design, Object data) {
  2303. return dXd(design, data, 1, 0);
  2304. }
  2305. public static Object dXd(Object design, Object data, Object xN, Integer mode) {
  2306. int scale = 0;
  2307. if (StringUtils.isNotEmpty(design, data, xN)) {
  2308. scale = getScale(design, data);
  2309. scale = (int) (scale - Math.log10(Double.parseDouble(xN.toString())));
  2310. }
  2311. if (StringUtils.isEmpty(mode)) {
  2312. mode = 0;
  2313. }
  2314. return dXd(design, data, xN, scale, mode);
  2315. }
  2316. /**
  2317. * @return java.lang.Object
  2318. * @Description 求偏差公式 支持AXA-BXB=DXD或者A-B=D的格式
  2319. * @Param [design:设计值, data:实测值, xN:倍率, scale:保留小数位,mode:1乘法,其它默认减法]
  2320. * @Author yangyj
  2321. * @Date 2022.01.20 09:45
  2322. **/
  2323. public static Object dXd(Object design, Object data, Object xN, Object scale, Integer mode) {
  2324. if (StringUtils.isNotEmpty(design, data)) {
  2325. if (StringUtils.isEmpty(xN)) {
  2326. xN = 1;
  2327. }
  2328. if (StringUtils.isEmpty(scale)) {
  2329. scale = 0;
  2330. }
  2331. String delimiter = handleNull(matcherFindGroup("[^0-9.]", design.toString(), 0, false));
  2332. if (StringUtils.isEmpty(delimiter)) {
  2333. delimiter = CONCAT;
  2334. }
  2335. String[] dArr = handleNull(design).split("[" + delimiter + "]");
  2336. String[] bArr = handleNull(data).split("[" + delimiter + "]");
  2337. Object _dx = null;
  2338. for (int n = 0; n < dArr.length; n++) {
  2339. BigDecimal a = new BigDecimal(dArr[n]);
  2340. BigDecimal b = new BigDecimal(bArr[n]);
  2341. String _data;
  2342. if (StringUtils.isEquals(1, mode)) {
  2343. _data = b.multiply(a).multiply(new BigDecimal(xN.toString())).setScale(Integer.parseInt(scale.toString()), ROUND_HALF_UP).toString();
  2344. } else {
  2345. _data = b.subtract(a).multiply(new BigDecimal(xN.toString())).setScale(Integer.parseInt(scale.toString()), ROUND_HALF_UP).toString();
  2346. }
  2347. if (StringUtils.isNotEmpty(_dx)) {
  2348. _dx = StringUtils.join(_dx, _data, delimiter);
  2349. } else {
  2350. _dx = _data;
  2351. }
  2352. }
  2353. return _dx;
  2354. }
  2355. return "";
  2356. }
  2357. /**
  2358. * @return java.lang.Object
  2359. * @Description 总体标准差
  2360. * @Param [data, scale]
  2361. * @Author yangyj
  2362. * @Date 2022.04.14 11:32
  2363. **/
  2364. public static Object sd(Object data, Object scale) {
  2365. if (data != null && StringUtils.isNumber(scale)) {
  2366. data = removeEmpty(data);
  2367. List<Object> datas = obj2List(data);
  2368. int total = datas.size();
  2369. List<String> _datas = datas.stream().map(StringUtils::handleNull).collect(Collectors.toList());
  2370. double avgVal = _datas.stream().mapToDouble(Double::parseDouble).average().orElse(0D);
  2371. double result = Math.sqrt(_datas.stream().mapToDouble(Double::parseDouble).map(e -> Math.pow(e - avgVal, 2)).sum() / total);
  2372. return StringUtils.number2String(result, scale);
  2373. }
  2374. return "";
  2375. }
  2376. }