123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255 |
- package com.persagy.proxy.adm.controller;
- import cn.hutool.core.collection.CollUtil;
- import com.persagy.proxy.adm.constant.AdmCommonConstant;
- import com.persagy.proxy.adm.model.AdmBuilding;
- import com.persagy.proxy.adm.model.AdmFloor;
- import com.persagy.proxy.adm.model.AdmSpace;
- 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.IAdmSpaceService;
- import com.persagy.proxy.common.entity.InstanceUrlParam;
- 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.List;
- /**
- * Adm 空间 API
- * @author lvxy
- * @date 2021/8/16
- */
- @RestController
- @RequestMapping("/object/zone")
- public class AdmSpaceController {
- @Autowired
- private IAdmSpaceService service;
- @Autowired
- private IAdmBuildingService buildingService;
- @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());
- vos = service.doInsert(context, AdmSpace.class, vos);
- return AdmResponse.success(vos);
- }
- /**
- * 根据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);
- 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 AdmQueryCriteria request) throws Exception {
- // 组装上下文条件
- InstanceUrlParam context = new InstanceUrlParam(groupCode, null, projectId, AdmCommonConstant.APP_ID);
- request.setName("space");
- return service.doQuery(context, request, AdmSpace.class);
- }
- /**
- * 查询业务空间的建筑楼层,包含受影响的空间数量
- * @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 createRequest
- * @return
- * @throws Exception
- */
- @PostMapping("/update-fl-bd")
- public AdmResponse updateFlBd(@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);
- }
- /**
- * 更新分区对象信息-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);
- 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 AdmQueryCriteria request) throws Exception {
- // 组装上下文条件
- InstanceUrlParam context = new InstanceUrlParam(groupCode, null, projectId, AdmCommonConstant.APP_ID);
- request.setName("space");
- return service.doQuery(context, request, AdmSpace.class);
- }
- /**
- * 获取项目下已有的空间类型
- * @param projectId
- * @param request
- * @return
- * @throws Exception
- */
- @PostMapping("/space-type")
- public AdmResponse querySpaceType(@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);
- }
- /**
- * 查询业务空间所有类型
- * @param projectId
- * @param request
- * @return
- * @throws Exception
- */
- @PostMapping("/type")
- public AdmResponse queryType(@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);
- }
- /**
- * 上传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);
- }
- }
|