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 createRequest, @QueryParam("projectId") String projectId) throws Exception { // 组装上下文条件 InstanceUrlParam context = new InstanceUrlParam(groupCode, null, projectId, AdmCommonConstant.APP_ID); List 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 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 createRequest, @QueryParam("projectId") String projectId) throws Exception { // 组装上下文条件 InstanceUrlParam context = new InstanceUrlParam(groupCode, null, projectId, AdmCommonConstant.APP_ID); List 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 buildings = (List) response.getContent(); buildings.stream().forEach(building -> { if(CollUtil.isNotEmpty(building.getFloor())){ List 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 createRequest, @QueryParam("projectId") String projectId) throws Exception { // 组装上下文条件 InstanceUrlParam context = new InstanceUrlParam(groupCode, null, projectId, AdmCommonConstant.APP_ID); List 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 createRequest, @QueryParam("projectId") String projectId) throws Exception { // 组装上下文条件 InstanceUrlParam context = new InstanceUrlParam(groupCode, null, projectId, AdmCommonConstant.APP_ID); List 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); } }