123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371 |
- package com.persagy.proxy.adm.controller;
- import cn.hutool.core.collection.CollUtil;
- import cn.hutool.core.util.StrUtil;
- import cn.hutool.json.JSONUtil;
- import com.alibaba.fastjson.JSONObject;
- import com.fasterxml.jackson.databind.node.JsonNodeFactory;
- import com.fasterxml.jackson.databind.node.ObjectNode;
- import com.persagy.dmp.basic.model.QueryCriteria;
- import com.persagy.proxy.adm.constant.AdmCommonConstant;
- import com.persagy.proxy.adm.model.*;
- import com.persagy.proxy.adm.request.AdmCreateRequest;
- import com.persagy.proxy.adm.request.AdmQueryCriteria;
- import com.persagy.proxy.adm.request.AdmResponse;
- import com.persagy.proxy.adm.service.IAdmBuildingService;
- import com.persagy.proxy.adm.service.IAdmFloorService;
- import com.persagy.proxy.adm.service.IAdmRelationService;
- import com.persagy.proxy.adm.service.IAdmSpaceService;
- import com.persagy.proxy.common.entity.InstanceUrlParam;
- import com.persagy.proxy.common.entity.RelationDTO;
- 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.Arrays;
- import java.util.List;
- /**
- * Adm 空间 API
- * @author lvxy
- * @date 2021/8/16
- */
- @RestController
- @RequestMapping("/object/zone")
- public class AdmSpaceController {
- @Autowired
- private IAdmSpaceService service;
- @Autowired
- private IAdmBuildingService buildingService;
- @Autowired
- private IAdmRelationService relationService;
- @Autowired
- private IAdmFloorService floorService;
- @Value("${middleware.group.code}")
- private String groupCode;
- /**
- * 统计
- * @param projectId
- * @param request
- * @return
- * @throws Exception
- */
- @PostMapping("/count")
- public AdmResponse count(@QueryParam("projectId") String projectId,
- @RequestBody AdmQueryCriteria request) throws Exception {
- // 组装上下文条件
- InstanceUrlParam context = new InstanceUrlParam(groupCode, null, projectId, AdmCommonConstant.APP_ID);
- request.setName("space");
- request.setOnlyCount(true);
- return service.doQuery(context, request, AdmSpace.class);
- }
- /**
- * 创建
- * @param createRequest
- * @return
- * @throws Exception
- */
- @PostMapping("/create")
- public AdmResponse create(@RequestBody AdmCreateRequest<AdmSpace> createRequest, @QueryParam("projectId") String projectId) throws Exception {
- // 组装上下文条件
- InstanceUrlParam context = new InstanceUrlParam(groupCode, null, projectId, AdmCommonConstant.APP_ID);
- List<AdmSpace> vos = CollUtil.newArrayList(createRequest.getContent());
- String msg = null;
- for (AdmSpace admSpace : vos) {
- if(StrUtil.isEmpty(admSpace.getClassCode())){
- msg = "classCode不可以为空!";
- break;
- }
- }
- if(StrUtil.isNotEmpty(msg)){
- vos = service.doInsertExt(context, AdmSpace.class, vos);
- return AdmResponse.success(vos);
- }else{
- return AdmResponse.failure(msg);
- }
- }
- /**
- * 根据ID删除
- * @param vos
- * @return
- * @throws Exception
- */
- @PostMapping("/delete")
- public AdmResponse delete(@QueryParam("projectId") String projectId, @RequestBody List<AdmSpace> vos) throws Exception {
- // 组装上下文条件
- InstanceUrlParam context = new InstanceUrlParam(groupCode, null, projectId, AdmCommonConstant.APP_ID);
- service.doDelete(context, vos);
- QueryCriteria queryCriteria = new QueryCriteria();
- vos.forEach(vo -> {
- /** 清除空间和建筑楼层的的数据 */
- dealRelation(vo.getId(),context,queryCriteria,"Bd2Sp");
- dealRelation(vo.getId(),context,queryCriteria,"Fl2Sp");
- });
- return AdmResponse.success();
- }
- /**
- * 更新分区对象信息
- * @param createRequest
- * @return
- * @throws Exception
- */
- @PostMapping("/update")
- public AdmResponse update(@RequestBody AdmCreateRequest<AdmSpace> createRequest, @QueryParam("projectId") String projectId) throws Exception {
- // 组装上下文条件
- InstanceUrlParam context = new InstanceUrlParam(groupCode, null, projectId, AdmCommonConstant.APP_ID);
- List<AdmSpace> vos = CollUtil.newArrayList(createRequest.getContent());
- vos = service.doUpdate(context, AdmSpace.class, vos);
- return AdmResponse.success(vos);
- }
- /**
- * 查询
- * @param projectId
- * @param request
- * @return
- * @throws Exception
- */
- @PostMapping("/query")
- public AdmResponse query(@QueryParam("projectId") String projectId,
- @RequestBody AdmDCSQueryRequest request) throws Exception {
- // 组装上下文条件
- InstanceUrlParam context = new InstanceUrlParam(groupCode, null, projectId, AdmCommonConstant.APP_ID);
- return service.doQuerySpaces(context, request);
- }
- /**
- * 查询业务空间的建筑楼层,包含受影响的空间数量
- * @param projectId
- * @param request
- * @return
- * @throws Exception
- */
- @PostMapping("/building-floor")
- public AdmResponse queryBuildingFloor(@QueryParam("projectId") String projectId,
- @RequestBody AdmQueryCriteria request) throws Exception {
- // 组装上下文条件
- InstanceUrlParam context = new InstanceUrlParam(groupCode, null, projectId, AdmCommonConstant.APP_ID);
- request.setName("building");
- AdmQueryCriteria criteriaFloor = new AdmQueryCriteria();
- criteriaFloor.setName("floor");
- AdmQueryCriteria criteriaSpace = new AdmQueryCriteria();
- criteriaSpace.setName("spaceList");
- criteriaSpace.setFilters("state = 1");
- criteriaFloor.setCascade(CollUtil.newArrayList(criteriaSpace));
- request.setCascade(CollUtil.newArrayList(criteriaFloor));
- AdmResponse response = buildingService.doQueryBuildingFloor(context, request);
- List<AdmBuilding> buildings = (List<AdmBuilding>) response.getContent();
- buildings.stream().forEach(building -> {
- if(CollUtil.isNotEmpty(building.getFloor())){
- List<AdmFloor> floors = building.getFloor();
- floors.stream().forEach(floor -> {
- if(CollUtil.isNotEmpty(floor.getSpaceList())){
- floor.setCount(String.valueOf(floor.getSpaceList().size()));
- floor.setSpaceList(null);
- }else{
- floor.setCount("0");
- }
- });
- }
- });
- return response;
- }
- /**
- * 修改业务空间对象和建筑楼层的关系
- * spaceId 业务空间id,id 楼层或建筑id,type 业务空间的类型
- * @param voList
- * @return
- * @throws Exception
- */
- @PostMapping("/update-fl-bd")
- public AdmResponse updateFlBd(@RequestBody List<AdmUpDataFloorAndBuildingRequests> voList, @QueryParam("projectId") String projectId) throws Exception {
- if(CollUtil.isEmpty(voList)){
- return AdmResponse.failure("不可以传入空数据");
- }
- // 组装上下文条件
- InstanceUrlParam context = new InstanceUrlParam(groupCode, null, projectId, AdmCommonConstant.APP_ID);
- //TODO 循环删除 需要改为 批量删除
- List<RelationDTO> RSpInBd_up = new ArrayList<>();
- List<RelationDTO> RSpInFl_up = new ArrayList<>();
- List<AdmSpace> space_up = new ArrayList<>();
- QueryCriteria queryCriteria = new QueryCriteria();
- voList.stream().forEach(requestData -> {
- String spaceId = requestData.getSpaceId();
- String id = requestData.getId();
- String type = requestData.getType();//classCode
- /** 清除空间和建筑楼层的的数据 */
- dealRelation(spaceId,context,queryCriteria,"Bd2Sp");
- dealRelation(spaceId,context,queryCriteria,"Fl2Sp");
- if(StrUtil.isNotEmpty(id)){
- if(id.startsWith("Fl") && StrUtil.isNotEmpty(spaceId)){
- AdmQueryCriteria admQueryCriteria = new AdmQueryCriteria();
- admQueryCriteria.setName("floor");
- AdmResponse admResponseFl = floorService.doQuery(context, admQueryCriteria, AdmFloor.class);
- if(CollUtil.isNotEmpty(admResponseFl.getContent())){
- AdmFloor floor = JSONUtil.toBean(admResponseFl.getContent().get(0).toString(), AdmFloor.class);
- if (floor!=null){
- //更新关系
- RelationDTO rBd_up = new RelationDTO();
- rBd_up.setObjTo(spaceId);
- rBd_up.setRelCode("Bd2Sp");
- rBd_up.setObjFrom(floor.getBuildingId());
- RSpInBd_up.add(rBd_up);
- RelationDTO rFl_up = new RelationDTO();
- rFl_up.setObjTo(spaceId);
- rFl_up.setRelCode("Fl2Sp");
- rFl_up.setObjFrom(floor.getId());
- RSpInFl_up.add(rFl_up);
- //更新实体
- AdmSpace space = new AdmSpace();
- space.setId(spaceId);
- space.setObjectType("space");
- space.setZoneType(type);
- space.setClassCode(type);
- space.setBuildingId(floor.getBuildingId());
- space.setFloorId(floor.getId());
- space_up.add(space);
- }
- }
- }else if(id.startsWith("Bd")){
- //更新关系
- RelationDTO rBd_up = new RelationDTO();
- rBd_up.setObjTo(spaceId);
- rBd_up.setRelCode("Bd2Sp");
- rBd_up.setObjFrom(id);
- RSpInBd_up.add(rBd_up);
- //更新实体
- AdmSpace space = new AdmSpace();
- space.setId(spaceId);
- space.setObjectType("space");
- space.setZoneType(type);
- space.setClassCode(type);
- space.setBuildingId(id);
- space.setFloorId(null);
- space_up.add(space);
- }
- }
- });
- service.doUpdate(context, AdmSpace.class, space_up);
- relationService.doSave(context, RSpInBd_up);
- relationService.doSave(context, RSpInFl_up);
- return AdmResponse.success(space_up);
- }
- /**
- * 更新分区对象信息-Outline
- * @param createRequest
- * @return
- * @throws Exception
- */
- @PostMapping("/update-outline")
- public AdmResponse updateOutLine(@RequestBody AdmCreateRequest<AdmSpace> createRequest, @QueryParam("projectId") String projectId) throws Exception {
- // 组装上下文条件
- InstanceUrlParam context = new InstanceUrlParam(groupCode, null, projectId, AdmCommonConstant.APP_ID);
- List<AdmSpace> vos = CollUtil.newArrayList(createRequest.getContent());
- vos = service.doUpdate(context, AdmSpace.class, vos);
- //TODO 更新计算关系ZoneSpaceBaseService.upDateOutline
- return AdmResponse.success(vos);
- }
- /**
- * 查询空间信息-outline 级联查询:建筑(building),楼层(floor),空间类型(objectType)
- * @param projectId
- * @param request
- * @return
- * @throws Exception
- */
- @PostMapping("/query-outline")
- public AdmResponse queryOutline(@QueryParam("projectId") String projectId,
- @RequestBody AdmDCSQueryRequest request) throws Exception {
- // 组装上下文条件
- InstanceUrlParam context = new InstanceUrlParam(groupCode, null, projectId, AdmCommonConstant.APP_ID);
- request.setName("space");
- request.setProjection(null);
- List<String> list = new ArrayList<>();
- list.add("id");
- list.add("name");
- list.add("localId");
- list.add("localName");
- list.add("outline");
- list.add("floorSequenceId");
- list.add("modelId");
- list.add("infos");
- list.add("properties");
- request.setProjection(list);
- return service.doQuerySpaces(context, request);
- }
- /**
- * 获取项目下已有的空间类型
- * @param projectId
- * @return
- * @throws Exception
- */
- @PostMapping("/space-type")
- public List<JSONObject> querySpaceType(@QueryParam("projectId") String projectId) throws Exception {
- // 组装上下文条件
- InstanceUrlParam context = new InstanceUrlParam(groupCode, null, projectId, AdmCommonConstant.APP_ID);
- return service.doQuerySpaceTypes(context);
- }
- /**
- * 查询业务空间所有类型
- * @param projectId
- * @param request
- * @return
- * @throws Exception
- */
- @PostMapping("/type")
- public AdmResponse queryType(@QueryParam("projectId") String projectId,
- @RequestBody AdmDCSQueryRequest request) throws Exception {
- // 组装上下文条件
- InstanceUrlParam context = new InstanceUrlParam(groupCode, null, projectId, AdmCommonConstant.APP_ID);
- return service.doQueryType(context, request);
- }
- /**
- * 上传EXCEL 识别镜头信息点
- * @param projectId
- * @param request
- * @return
- * @throws Exception
- */
- @PostMapping("/import")
- public AdmResponse importExcel(@QueryParam("projectId") String projectId,
- @RequestBody AdmQueryCriteria request) throws Exception {
- // 组装上下文条件
- InstanceUrlParam context = new InstanceUrlParam(groupCode, null, projectId, AdmCommonConstant.APP_ID);
- request.setName("space");
- return service.doQuery(context, request, AdmSpace.class);
- }
- private void dealRelation(String spaceId, InstanceUrlParam context, QueryCriteria queryCriteria, String relCode){
- ObjectNode rBd = JsonNodeFactory.instance.objectNode();
- rBd.put("objTo",spaceId);
- rBd.put("relCode",relCode);
- queryCriteria.setCriteria(rBd);
- relationService.doDelete(context, queryCriteria);
- }
- }
|