123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293 |
- package com.mixsmart.utils;
- import com.alibaba.fastjson.JSONArray;
- import com.alibaba.fastjson.JSONObject;
- import org.springblade.core.tool.utils.Func;
- import org.springblade.manager.bean.TableInfo;
- import org.springblade.manager.dto.Coords;
- import org.springblade.manager.dto.ElementData;
- import org.springblade.manager.dto.FormData;
- import org.springblade.manager.entity.Formula;
- import java.math.BigDecimal;
- import java.util.*;
- import java.util.regex.Matcher;
- import java.util.regex.Pattern;
- import java.util.stream.Collectors;
- /**
- * @author yangyj
- * @Date 2022/7/14 15:55
- * @description TODO
- */
- public class FormulaUtils {
- public static Map<String,Object> triangleSquare(Object ranges){
- Map<String,Object> map =new HashMap<>();
- if(StringUtils.isEmpty(ranges)){
- //z的默认取值范围
- ranges="(0,15)";
- }
- Matcher m = RegexUtils.matcher("(\\-?\\d+)(\\D)(\\+?\\d+)",ranges.toString());
- if(m.find()) {
- System.out.println();
- int min = StringUtils.handObj2Integer(m.group(1));
- int max = StringUtils.handObj2Integer(m.group(3));
- Integer[] r = pythagorean(min, max);
- map.put("X", String.valueOf(r[0]));
- map.put("Y", String.valueOf(r[1]));
- map.put("Z", String.valueOf(r[2]));
- }
- return map;
- }
- /**
- * result[0]^2+result[1]^2=result[2]^2 result[] 元素均为正整数
- */
- public static Integer[] pythagorean(Integer min,Integer max){
- Integer[] result = null;
- List<Integer[]> list = new ArrayList<>();
- for(int i=1;i<=max;i++){
- for(int j=1;j<=max;j++){
- double tmp = Math.sqrt(Math.pow(i,2)+Math.pow(j,2));
- int z= (int) Math.round(tmp);
- if(min<z&&z<=max){
- Integer[] arr = new Integer[]{ i,j,z};
- list.add(arr);
- }
- }
- }
- if(ListUtils.isNotEmpty(list)){
- Random rm = new Random();
- result = list.get(rm.nextInt(list.size()));
- }
- return result;
- }
- public static void write(FormData fd, Object data,Boolean nullOrBlank ){
- if(Func.isEmpty(fd.getValues())){
- /*无定位信息不写入*/
- return;
- }
- /*写入前清空内容*/
- fd.getValues().forEach(t->t.setValue(null));
- if(data instanceof List){
- List<Object> values = (List<Object>) data;
- if(!nullOrBlank){
- values=values.stream().filter(StringUtils::isNotEmpty).collect(Collectors.toList());
- }
- if(values.size()>fd.getValues().size()){
- /*当生成的数据超过实际容量的时候,会自动追加页数*/
- if(fd.getCoordsList().size()==1){
- if(values.stream().filter(CustomFunction::containsZH).anyMatch(e->e.toString().contains("\n"))){
- fd.getValues().get(0).setValue(values.stream().filter(Objects::nonNull).map(Object::toString).collect(Collectors.joining()));
- }else{
- fd.getValues().get(0).setValue(values.stream().map(StringUtils::handleNull).collect(Collectors.joining("、")));
- }
- }else{
- // copy(fd,values);
- for(int n=0;n<fd.getValues().size();n++){
- fd.getValues().get(n).setValue(values.get(n));
- }
- List<Object> overList=values.stream().skip(fd.getValues().size()).collect(Collectors.toList());
- List<Coords> coordsList = fd.getCoordsList();
- int addPage=(int)Math.ceil((double)overList.size()/(double)coordsList.size());
- fd.setAddPages(addPage);
- ElementData last =fd.getValues().get(fd.getValues().size()-1);
- int indexBase=last.getIndex()+1;
- List<ElementData> addList= new ArrayList<>();
- for(int i=0;i<addPage;i++){
- for(int j=0;j<coordsList.size();j++){
- /*超页就尽管写进去,格式化阶段再加表*/
- Coords coords = coordsList.get(j);
- Object v=null;
- int st=i*coordsList.size()+j;
- if(st<overList.size()){
- v= overList.get(st);
- }
- addList.add(new ElementData(indexBase+i,last.getGroupId(),v,coords.getX(),coords.getY()));
- }
- }
- fd.getValues().addAll(addList);
- }
- }else{
- for(int n=0;n<values.size();n++){
- fd.getValues().get(n).setValue(values.get(n));
- }
- }
- }else{
- if(Formula.FULL.equals(fd.getFormula().getOutm())){
- /*填充策略*/
- fd.getValues().forEach(e->e.setValue(data));
- }else{
- fd.getValues().get(0).setValue(data);
- }
- }
- }
- public static List<TableInfo> getTableInfoList(JSONArray dataArray) {
- if (dataArray != null && !dataArray.isEmpty()) {
- List<TableInfo> result = new ArrayList<>();
- for (int m = 0; m < dataArray.size(); m++) {
- TableInfo tableInfo = new TableInfo();
- JSONObject dataInfo2 = dataArray.getJSONObject(m);
- //
- tableInfo.setContractId(dataInfo2.getString("contractId"));
- tableInfo.setPkeyId(dataInfo2.getString("pkeyId"));
- tableInfo.setProjectId(dataInfo2.getString("projectId"));
- //huangjn 填报的类型,施工或监理
- tableInfo.setClassify(dataInfo2.getString("classify"));
- //设置首件信息
- setFirstData(dataInfo2, tableInfo);
- // //设置日志信息
- setTheLogData(dataInfo2, tableInfo);
- dataInfo2.fluentRemove("contractId")
- .fluentRemove("pkeyId")
- .fluentRemove("p_key_id")
- .fluentRemove("projectId")
- .fluentRemove("classify")
- .fluentRemove("pickerKey")
- .fluentRemove("id")
- .fluentRemove("isFirst")
- .fluentRemove("firstNodeId")
- .fluentRemove("isTheLog")
- .fluentRemove("theLogId")
- .fluentRemove("linkTabIds")
- .fluentRemove("recordTime")
- .fluentRemove("businessId")
- .fluentRemove("sourceUrl")
- .fluentRemove("pdfUrl")
- .fluentRemove("firstFileName")
- .fluentRemove("");
- // 计算数据
- LinkedHashMap<String, List<String>> dataMap = dataInfo2.keySet().stream().filter(e -> e.contains("__")).collect(Collectors.groupingBy(e -> e.split("__")[0], LinkedHashMap<String, List<String>>::new, Collectors.toList()));
- LinkedHashMap<String, String> dataMap2 = new LinkedHashMap<>();
- // 字段组合
- for (String k : dataMap.keySet()) {
- if (dataMap.get(k).size() > 1 && !dataMap.get(k).contains("000Z")) {
- String[] ziduan = dataMap.get(k).toArray(new String[]{});
- String temp = "";
- for (int i = 0; i < ziduan.length - 1; i++) {
- for (int j = 0; j < ziduan.length - i - 1; j++) {
- Integer tr = Integer.parseInt((ziduan[j].split("__")[1]).split("_")[0]);
- Integer td = Integer.parseInt(ziduan[j].split("__")[1].split("_")[1]);
- Integer tr_1 = Integer.parseInt(ziduan[j + 1].split("__")[1].split("_")[0]);
- Integer td_1 = Integer.parseInt(ziduan[j + 1].split("__")[1].split("_")[1]);
- if (tr > tr_1 && td == td_1) { //纵向排序
- temp = ziduan[j];
- ziduan[j] = ziduan[j + 1];
- ziduan[j + 1] = temp;
- }
- }
- }
- String lastStr = dataInfo2.getString(ziduan[0]) + "_^_" + ziduan[0].split("__")[1];
- for (int i = 1; i < ziduan.length; i++) {
- String keyData = dataInfo2.getString(ziduan[i]);
- if (!keyData.equals("")) {
- lastStr += "☆" + dataInfo2.getString(ziduan[i]) + "_^_" + ziduan[i].split("__")[1];
- }
- }
- dataMap2.put(k, lastStr);
- } else {
- String dataVal = dataInfo2.getString(dataMap.get(k).get(0));
- dataMap2.put(k, dataVal + "_^_" + dataMap.get(k).get(0).split("__")[1]);
- }
- }
- dataMap2.put("p_key_id", tableInfo.getPkeyId());
- tableInfo.setDataMap(dataMap2);
- result.add(tableInfo);
- }
- return result;
- }
- return null;
- }
- public static void setFirstData(JSONObject dataInfo2, TableInfo tableInfo) {
- //huangjn 判断是否是首件
- if (dataInfo2.containsKey("isFirst")) {
- tableInfo.setIsFirst(dataInfo2.getString("isFirst"));
- }
- //huangjn 判断是否是首件
- //首件资料绑定的节点
- if (dataInfo2.containsKey("firstNodeId")) {
- tableInfo.setFirstNodeId(dataInfo2.getString("firstNodeId"));
- }
- //首件ID(编辑时有值,新增时为空)
- if (dataInfo2.containsKey("firstId")) {
- tableInfo.setFirstId(dataInfo2.getString("firstId"));
- }
- //源文件
- if (dataInfo2.containsKey("sourceUrl")) {
- tableInfo.setSourceUrl(dataInfo2.getString("sourceUrl"));
- }
- //pdfUrl
- if (dataInfo2.containsKey("pdfUrl")) {
- tableInfo.setPdfUrl(dataInfo2.getString("pdfUrl"));
- }
- //文件名称
- if (dataInfo2.containsKey("firstFileName")) {
- tableInfo.setFirstFileName(dataInfo2.getString("firstFileName"));
- }
- //关联的信息
- if (dataInfo2.containsKey("linkProcessList")) {
- tableInfo.setLinkProcessList(dataInfo2.getJSONArray("linkProcessList"));
- }
- }
- /**
- * 设置日志信息
- */
- public static void setTheLogData(JSONObject dataInfo2, TableInfo tableInfo) {
- //huangjn 判断是否是日志
- if (dataInfo2.containsKey("isTheLog")) {
- tableInfo.setIsTheLog(dataInfo2.getString("isTheLog"));
- }
- //huangjn 判断是否是日志
- //huangjn 日志ID
- if (dataInfo2.containsKey("theLogId")) {
- tableInfo.setTheLogId(dataInfo2.getString("theLogId"));
- }
- //huangjn 日志ID
- //huangjn 日志勾选的工序
- if (dataInfo2.containsKey("linkTabIds")) {
- tableInfo.setLinkTabIds(dataInfo2.getJSONArray("linkTabIds"));
- }
- //huangjn 日志勾选的工序
- //huangjn 日志所选时间
- if (dataInfo2.containsKey("recordTime")) {
- tableInfo.setRecordTime(dataInfo2.getString("recordTime"));
- }
- //huangjn 日志所选时间
- //huangjn 每份填报数据的id,目前日志专用
- if (dataInfo2.containsKey("id")) {
- tableInfo.setBusinessId(dataInfo2.getString("id"));
- }
- //huangjn 每份填报数据的id,目前日志专用
- }
- /*从元素名称中解析项目名称*/
- public static String parseItemName(String eName){
- String[] candidate= StringUtils.handleNull(eName).replaceAll("^[^\\u4e00-\\u9fa5]+","").replaceAll("\\s+","").split("[((].+[))]|_");
- if(candidate.length>0){
- return Arrays.stream(candidate).filter(e->!e.contains("实测项目")&&!e.contains("△")).findFirst().orElse(eName);
- }
- return eName;
- }
- // public static void main(String[] args) {
- // System.out.println(parseItemName("实 测 项 目_3△_内轮廓高度(mm)_不小于设计值_实测值或实测偏差值"));
- // }
- }
|