123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301 |
- package com.persagy.proxy.dictionary.controller;
- import cn.hutool.core.collection.CollUtil;
- import cn.hutool.core.collection.CollectionUtil;
- import cn.hutool.core.util.StrUtil;
- import com.persagy.proxy.adm.constant.AdmDictCategoryEnum;
- import com.persagy.proxy.adm.request.AdmDictQueryCriteria;
- import com.persagy.proxy.adm.request.AdmQueryCriteria;
- import com.persagy.proxy.dictionary.model.AdmDict;
- import com.persagy.proxy.dictionary.service.IAdmDictService;
- import com.persagy.proxy.object.model.AdmEquipment;
- import com.persagy.proxy.object.model.AdmObjectInfo;
- import com.persagy.proxy.dictionary.model.AdmObjectType;
- import com.persagy.proxy.adm.request.AdmResponse;
- import com.persagy.proxy.object.service.IAdmEquipmentService;
- import com.persagy.proxy.report.service.IAdmLabslService;
- import com.persagy.proxy.adm.utils.AdmContextUtil;
- import com.persagy.proxy.common.entity.InstanceUrlParam;
- import lombok.extern.slf4j.Slf4j;
- import org.apache.commons.lang.StringUtils;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.beans.factory.annotation.Value;
- import org.springframework.web.bind.annotation.PostMapping;
- import org.springframework.web.bind.annotation.RequestBody;
- import org.springframework.web.bind.annotation.RequestMapping;
- import org.springframework.web.bind.annotation.RestController;
- import javax.ws.rs.QueryParam;
- import java.util.ArrayList;
- import java.util.Iterator;
- import java.util.List;
- import java.util.Map;
- import java.util.stream.Collectors;
- /**
- * @ClassName AdmLabslController
- * @Description: 蜡笔森林定制接口
- * @Author linhuili
- * @Date 2021/9/17 20:01
- * @Version V1.0
- **/
- @RestController
- @RequestMapping("/labsl")
- @Slf4j
- public class AdmLabslController {
- @Autowired
- private IAdmLabslService service;
- @Value("${middleware.group.code}")
- private String groupCode ="XG";
- @Autowired
- private IAdmEquipmentService iAdmEquipmentService;
- @Autowired
- private IAdmDictService admDictService;
- /**
- * 查询项目下的设备类型
- * @return
- * @throws Exception
- */
- @PostMapping("/category")
- public AdmResponse queryCategory() throws Exception {
- InstanceUrlParam context = AdmContextUtil.toDmpContext();
- if(StringUtils.isEmpty(context.getGroupCode())){
- context.setGroupCode(groupCode);
- }
- return querySystemEquipTree(AdmContextUtil.toDmpContext(),AdmObjectType.class);
- //return service.queryCategory(context, AdmObjectInfo.class);
- }
- /**
- * 查询项目下的空间类型
- * @return
- * @throws Exception
- */
- @PostMapping("/zone/type")
- public AdmResponse queryZoneType() throws Exception {
- InstanceUrlParam context = AdmContextUtil.toDmpContext();
- if(StringUtils.isEmpty(context.getGroupCode())){
- context.setGroupCode(groupCode);
- }
- return service.queryZoneType(context, AdmObjectInfo.class);
- }
- /**
- * 查询项目下的建筑楼层
- * @return
- * @throws Exception
- */
- @PostMapping("/building/floor")
- public AdmResponse queryBuildFloor(@QueryParam("projectId") String projectId) throws Exception {
- InstanceUrlParam context = AdmContextUtil.toDmpContext();
- if(StringUtils.isEmpty(context.getGroupCode())){
- context.setGroupCode(groupCode);
- }
- return service.queryBuildFloor(context, AdmObjectInfo.class);
- }
- /* *//**
- * 查询设备包含设备类型
- * @return
- * @throws Exception
- *//*
- @PostMapping("/query/equip")
- public AdmResponse queryEquipType(@QueryParam("projectId") AdmQueryCriteria request) throws Exception {
- InstanceUrlParam context = AdmContextUtil.toDmpContext();
- return iAdmEquipmentService.doQuery(context, AdmObjectInfo.class);
- }*/
- /**
- * 查询设备包含设备类型
- * @return
- * @throws Exception
- */
- @PostMapping("/query/equip")
- public AdmResponse queryEquipType(@RequestBody AdmQueryCriteria request) throws Exception {
- InstanceUrlParam context = AdmContextUtil.toDmpContext();
- if(StringUtils.isEmpty(context.getGroupCode())){
- context.setGroupCode(groupCode);
- }
- // 组装上下文条件
- request.setName(AdmEquipment.OBJ_TYPE);
- //过滤条件处理
- String filters = request.getFilters();
- Boolean specialQueryFlag = false;
- StringBuilder newFilters = new StringBuilder();
- StringBuilder specailFilters = new StringBuilder();
- if(StringUtils.isEmpty(filters)){
- return iAdmEquipmentService.doQuery(context, request, AdmEquipment.class);
- }
- //处理查询条件
- specialQueryFlag = handleRequestCriteria(filters, newFilters, specailFilters, specialQueryFlag);
- List<AdmEquipment> result = new ArrayList<>();
- List<AdmEquipment> specailContent = new ArrayList<>();
- AdmQueryCriteria specifal = new AdmQueryCriteria();
- specifal = request;
- specifal.setFilters(specailFilters.toString());
- int totalCount = 0 ;
- request.setFilters(newFilters.toString());
- AdmResponse queryResponse = iAdmEquipmentService.doQuery(context, request, AdmEquipment.class);
- List<AdmEquipment> content = (List<AdmEquipment>)queryResponse.getContent();
- if(queryResponse.getTotal() != null){
- totalCount += queryResponse.getTotal().intValue();
- }
- if(specialQueryFlag){
- //查询未明确建筑,未明确楼层
- Long count = CollectionUtil.isEmpty(queryResponse.getContent()) ? 0 : Long.valueOf(queryResponse.getContent().size());
- Integer pageSize = request.getPageSize();
- if(count < pageSize){
- long specailPageSize = pageSize - count;
- specifal.setPageSize((int) specailPageSize);
- AdmResponse specailQueryResponse = iAdmEquipmentService.doQuery(context, specifal, AdmEquipment.class);
- specailContent = (List<AdmEquipment>)specailQueryResponse.getContent();
- if(specailQueryResponse.getTotal() != null){
- totalCount += specailQueryResponse.getTotal().intValue();
- }
- }
- }
- if(CollUtil.isNotEmpty(content)){
- result.addAll(content);
- }
- if(CollUtil.isNotEmpty(specailContent)){
- result.addAll(specailContent);
- }
- AdmResponse response = AdmResponse.success(result);
- response.setTotal(Long.valueOf(totalCount));
- response.setCount(CollectionUtil.isEmpty(result) ? 0 : Long.valueOf(result.size()));
- response.setPageNumber(request.getPageNumber());
- response.setPageSize(request.getPageSize());
- return response;
- }
- /**
- * 处理查询条件
- * @param filters
- * @param newFilters
- * @param specailFilters
- * @param specialQueryFlag
- */
- private boolean handleRequestCriteria(String filters,StringBuilder newFilters,StringBuilder specailFilters,Boolean specialQueryFlag){
- String[] filter = filters.split(";");
- for(int i =0 ;i< filter.length;i++){
- if(filter[i].contains("not")){
- String[] param = filter[i].split(" ");
- filter[i] = StrUtil.format("{} $notcontains {}",param[1],param[3]);
- }
- if(filter[i].contains(" in [") && filter[i].contains("]or")){
- //针对未明确建筑,未明确楼层查询单独处理
- String[] split = filter[i].split("]or");
- newFilters.append(split[0]+"]");
- specailFilters.append(split[1]);
- //标记特殊查询标识
- specialQueryFlag = true;
- newFilters.append(" ; ");
- specailFilters.append(" ; ");
- }else{
- newFilters.append(filter[i]);
- specailFilters.append(filter[i]);
- if(i != filter.length -1){
- newFilters.append(" ; ");
- specailFilters.append(" ; ");
- }
- }
- }
- return specialQueryFlag;
- }
- /**
- * 根据设备id统计设备所属的专业
- * @return
- * @throws Exception
- */
- @PostMapping("/major/category")
- public AdmResponse queryMajorCategory(@QueryParam("projectId") String projectId,
- @RequestBody List<String> ids) throws Exception {
- InstanceUrlParam context = AdmContextUtil.toDmpContext();
- if(StringUtils.isEmpty(context.getGroupCode())){
- context.setGroupCode(groupCode);
- }
- if(CollUtil.isEmpty(ids)){
- return AdmResponse.success(new ArrayList<>());
- }
- List<String> newIds = ids.stream().filter(id->!"fisnull".equals(id)).collect(Collectors.toList());
- if(CollUtil.isEmpty(newIds)){
- return AdmResponse.success(new ArrayList<>());
- }
- return service.queryMajorCategory(context, newIds , AdmObjectType.class);
- }
- /**
- * 查询项目下已有的系统设备类型树
- * @param context
- * @param clazz
- * @return
- * @throws Exception
- */
- private <T> AdmResponse querySystemEquipTree(InstanceUrlParam context, Class<T> clazz) throws Exception {
- AdmDictQueryCriteria request = new AdmDictQueryCriteria();
- //查询项目下已有的设备类型
- request.setName("equipment");
- AdmResponse dictResponse = iAdmEquipmentService.queryEquipClassCode(context, request, AdmEquipment.class);
- List<String> classCodes = (List<String>)dictResponse.getContent();
- if(CollUtil.isEmpty(classCodes)){
- return AdmResponse.success(new ArrayList<>());
- }
- Map<String, List<String>> classCodeMap = classCodes.stream().collect(Collectors.groupingBy(item->item.substring(0,4),Collectors.toList()));
- //查询系统设备类树
- AdmDict admDict = new AdmDict();
- admDict.setType(AdmDictCategoryEnum.MAJOR_SYSTEM_EQUIP.getValue());
- AdmResponse categoryResponse = admDictService.queryCategory(context, admDict, clazz);
- List<AdmObjectType> objectTypes = (List<AdmObjectType>) categoryResponse.getContent();
- if(CollUtil.isEmpty(objectTypes)){
- return AdmResponse.success(new ArrayList<>());
- }
- //过滤设备实体中不存在的类型
- Iterator<AdmObjectType> it = objectTypes.iterator();
- while(it.hasNext()){
- AdmObjectType major = it.next();
- //过滤系统
- List<AdmObjectType> systemList = major.getChildren();
- if(CollUtil.isNotEmpty(systemList)){
- Iterator<AdmObjectType> systemListIter = systemList.iterator();
- while (systemListIter.hasNext()){
- AdmObjectType objectType = systemListIter.next();
- List<String> objTypes = classCodeMap.get(objectType.getCode());
- if(CollUtil.isEmpty(objTypes)){
- systemListIter.remove();
- continue;
- }
- //过滤子级:设备类型
- List<AdmObjectType> children = objectType.getChildren();
- if(CollUtil.isEmpty(children)){
- systemListIter.remove();
- continue;
- }
- Iterator<AdmObjectType> chidIterator = children.iterator();
- while (chidIterator.hasNext()){
- AdmObjectType next = chidIterator.next();
- if(!objTypes.contains(next.getCode())){
- chidIterator.remove();
- }
- }
- }
- }
- if(CollUtil.isEmpty(systemList)){
- it.remove();
- }
- }
- return AdmResponse.success(objectTypes);
- }
- }
|