123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117 |
- package com.mixsmart.utils;
- 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){
- if(data instanceof List){
- List<Object> values = (List<Object>) data;
- if(values.size()>fd.getValues().size()){
- /*当生成的数据超过实际容量的时候,会自动追加页数*/
- if(fd.getCoordsList().size()==1){
- 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);
- }
- }
- }
- }
|