| | |
| | | import cn.hutool.core.collection.CollectionUtil; |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.baomidou.mybatisplus.core.metadata.IPage; |
| | | import com.baomidou.mybatisplus.core.toolkit.IdWorker; |
| | | import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | |
| | | import java.util.List; |
| | | import java.util.Objects; |
| | | import java.util.Optional; |
| | | import java.util.concurrent.atomic.AtomicInteger; |
| | | import java.util.stream.Collectors; |
| | | |
| | | /** |
| | |
| | | //三级参数 134 |
| | | List<SysDictItem> dictTwo = dictUtils.getDict("second_param"); |
| | | List<SysDictItem> dictThree = dictUtils.getDict("third_param"); |
| | | List<SysDictItem> type = dictUtils.getDict("technology_param"); |
| | | List<Integer> count = new ArrayList<Integer>(); |
| | | int num = 0; |
| | | for (int i = 0; i < paramTemplates.size(); i++) { |
| | |
| | | throw new RuntimeException(("字典中无此三级参数,请检查后再次导入,参数为:---------》" + p.getParamItemThree())); |
| | | } |
| | | }); |
| | | |
| | | Optional.ofNullable(p.getParamType()).ifPresent(t -> { |
| | | int size = type.stream().filter(d -> Objects.equals(p.getParamType(), d.getLabel())).collect(Collectors.toList()).size(); |
| | | if (size < 1) { |
| | | throw new RuntimeException(("字典中无此参数类型,请检查后再次导入,类型为:---------》" + p.getParamType())); |
| | | } |
| | | }); |
| | | }); |
| | | for (int i = 0; i < paramTemplates.size(); i++) { |
| | | for (int j = 0; j < count.size(); j++) { |
| | | if(i==count.get(j)-1){ |
| | | |
| | | }else { |
| | | |
| | | List<List<ParamTemplate>>listParamTemplates = new ArrayList<List<ParamTemplate>>(); |
| | | for (int j = 0; j < count.size()-1; j++) { |
| | | List<ParamTemplate> paramTemplateLists = new ArrayList<>(); |
| | | for (int i = count.get(j); i < count.get(j+1); i++) { |
| | | paramTemplateLists.add(paramTemplates.get(i)); |
| | | } |
| | | listParamTemplates.add(paramTemplateLists); |
| | | } |
| | | listParamTemplates.forEach(l-> { |
| | | System.out.println("========================================="); |
| | | l.forEach(System.out::println); |
| | | }); |
| | | List<List<Param>>paramList=new ArrayList<>(); |
| | | AtomicInteger nums = new AtomicInteger(); |
| | | List<Long>secondIds=new ArrayList(); |
| | | for (int i = 0; i < listParamTemplates.size(); i++) { |
| | | List<ParamTemplate> l = listParamTemplates.get(i); |
| | | List<Param>paramList1=new ArrayList<>(); |
| | | System.out.println("========================================="); |
| | | l.forEach(System.out::println); |
| | | ParamTemplate paramTemplate = l.get(0); |
| | | System.out.println("数组数据=======》"+paramTemplate); |
| | | Param paramFirst=new Param(); |
| | | paramFirst.setCode("ZS-CS"+IdWorker.getIdStr()); |
| | | //一级参数 |
| | | String paramItem = paramTemplate.getParamItem(); |
| | | paramFirst.setParameterItem(paramItem); |
| | | if(l.size()<=1){ |
| | | Optional.ofNullable(paramTemplate.getParamType()).ifPresent(o->{ |
| | | List<SysDictItem> collect = type.stream().filter(t -> Objects.equals(paramTemplate.getParamType(), t.getLabel())).collect(Collectors.toList()); |
| | | paramFirst.setType(collect.get(0).getValue()); |
| | | }); |
| | | paramFirst.setParameterFormat(paramTemplate.getParamFormat()); |
| | | paramFirst.setUnit(paramTemplate.getUnit()); |
| | | } |
| | | paramFirst.setId(IdWorker.getId()); |
| | | System.out.println("一级--------》"+paramFirst); |
| | | paramList1.add(paramFirst); |
| | | if(l.size()>1){ |
| | | for (int k = 0; k < l.size(); k++) { |
| | | ParamTemplate c = l.get(k); |
| | | if(c.getParamItemTwo()!=null){ |
| | | Param second=new Param(); |
| | | second.setId(IdWorker.getId()); |
| | | secondIds.add(second.getId()); |
| | | second.setCode(dictTwo.stream().filter(d -> Objects.equals(c.getParamItemTwo(), d.getLabel())).collect(Collectors.toList()).get(0).getId()+""); |
| | | second.setParameterItem(c.getParamItemTwo()); |
| | | if(c.getParamItemThree()==null){ |
| | | second.setType(type.stream().filter(d -> Objects.equals(c.getParamType(), d.getLabel())).collect(Collectors.toList()).get(0).getValue()); |
| | | second.setParameterFormat(c.getParamFormat()); |
| | | second.setUnit(c.getUnit()); |
| | | } |
| | | second.setParentId(paramList1.get(0).getId()); |
| | | paramList1.add(second); |
| | | } |
| | | if (c.getParamItemThree()!=null){ |
| | | Param third=new Param(); |
| | | third.setId(IdWorker.getId()); |
| | | long paramItemTwo = secondIds.get(secondIds.size()-1); |
| | | //System.out.println(nums.get()+"所属二级======》"+secondIds.get(secondIds.size()-1)); |
| | | third.setParentId(paramItemTwo); |
| | | third.setParameterItem(c.getParamItemThree()); |
| | | third.setCode(dictThree.stream().filter(d -> Objects.equals(c.getParamItemThree(), d.getLabel())).collect(Collectors.toList()).get(0).getId()+""); |
| | | third.setType(type.stream().filter(d -> Objects.equals(c.getParamType(), d.getLabel())).collect(Collectors.toList()).get(0).getValue()); |
| | | third.setParameterFormat(c.getParamFormat()); |
| | | third.setUnit(c.getUnit()); |
| | | paramList1.add(third); |
| | | } |
| | | } |
| | | } |
| | | paramList.add(paramList1); |
| | | } |
| | | list.forEach(l->{ |
| | | System.out.println("======================"); |
| | | l.forEach(System.out::println); |
| | | System.out.println("=================="); |
| | | paramList.forEach(p->{ |
| | | p.forEach(cc->{ |
| | | System.out.println(cc); |
| | | baseMapper.insert(cc); |
| | | }); |
| | | }); |
| | | } |
| | | |