123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170 |
- package com.persagy.proxy.adm.controller;
- import cn.hutool.core.collection.CollUtil;
- import cn.hutool.core.util.StrUtil;
- import com.persagy.dmp.common.model.entity.BaseEntity;
- 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.*;
- import com.persagy.proxy.adm.utils.AdmContextUtil;
- import com.persagy.proxy.adm.utils.ObjectNameUtil;
- import com.persagy.proxy.common.entity.DmpResult;
- import org.springframework.beans.factory.annotation.Autowired;
- 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.List;
- import java.util.Map;
- /**
- * ADM 建筑 API
- * @author Charlie Yu
- * @date 2021-08-16
- */
- @RestController
- @RequestMapping("/object/building")
- public class AdmBuildingController {
- @Autowired
- private IAdmBuildingService service;
- @Autowired
- private IAdmEquipmentService equipmentService;
- @Autowired
- private IAdmFloorService floorService;
- @Autowired
- private IAdmISpaceService iAdmISpaceService;
- @Autowired
- private IAdmSpaceService spaceService;
- /**
- * 创建
- * @param createRequest
- * @return
- * @throws Exception
- */
- @PostMapping("/create")
- public AdmResponse create(@RequestBody AdmCreateRequest<AdmBuilding> createRequest) throws Exception {
- List<AdmBuilding> vos = CollUtil.newArrayList(createRequest.getContent());
- vos.stream().forEach(admBuilding -> {
- if (StrUtil.isEmpty(admBuilding.getName())){
- admBuilding.setName(ObjectNameUtil.objectName("建筑-"));
- }
- });
- vos = service.doInsert(AdmContextUtil.toDmpContext(), AdmBuilding.class, vos);
- return AdmResponse.success(vos);
- }
- /**
- * 根据ID删除
- * @param vos
- * @return
- * @throws Exception
- */
- @PostMapping("/delete")
- public AdmResponse delete(@RequestBody List<AdmBuilding> vos) throws Exception {
- if(CollUtil.isEmpty(vos)){
- return AdmResponse.failure("参数不能为空");
- }
- //验证楼层 空间 设备 等信息是否存在,不存在关系可以删除
- Map<String, AdmBuilding> admBuildingMap = CollUtil.fieldValueMap(vos, BaseEntity.PROP_ID);
- String msg = "建筑下包含其他对象实例,请解除关系后删除";
- AdmQueryCriteria admQueryCriteria = new AdmQueryCriteria();
- StringBuilder stringBuilder = new StringBuilder();
- stringBuilder.append("buildingId in [");
- admBuildingMap.keySet().stream().forEach(buildingId -> {
- stringBuilder.append("'").append(buildingId).append("'").append(",");
- });
- String filters = StrUtil.sub(stringBuilder.toString(),0, -1);
- filters+= "]";
- admQueryCriteria.setFilters(filters);
- admQueryCriteria.setName(AdmFloor.OBJ_TYPE);
- AdmResponse admResponseF = floorService.doQuery(AdmContextUtil.toDmpContext(), admQueryCriteria, AdmFloor.class);
- if(DmpResult.SUCCESS.equals(admResponseF.getResult()) && CollUtil.isNotEmpty(admResponseF.getContent())){
- return AdmResponse.failure(msg);
- }
- admQueryCriteria.setName(AdmSpace.OBJ_TYPE);
- AdmResponse admResponseSpace = spaceService.doQuery(AdmContextUtil.toDmpContext(), admQueryCriteria, AdmSpace.class);
- if(admResponseSpace.getResult().equals(DmpResult.SUCCESS) && CollUtil.isNotEmpty(admResponseSpace.getContent())){
- return AdmResponse.failure(msg);
- }
- admQueryCriteria.setName(AdmISpace.OBJ_TYPE);
- AdmResponse admResponseISpace = iAdmISpaceService.doQuery(AdmContextUtil.toDmpContext(), admQueryCriteria, AdmISpace.class);
- if(admResponseISpace.getResult().equals(DmpResult.SUCCESS) && CollUtil.isNotEmpty(admResponseISpace.getContent())){
- return AdmResponse.failure(msg);
- }
- admQueryCriteria.setName(AdmEquipment.OBJ_TYPE);
- AdmResponse admResponseEuip = equipmentService.doQuery(AdmContextUtil.toDmpContext(), admQueryCriteria, AdmEquipment.class);
- if(admResponseEuip.getResult().equals(DmpResult.SUCCESS) && CollUtil.isNotEmpty(admResponseEuip.getContent())){
- return AdmResponse.failure(msg);
- }
- service.doDelete(AdmContextUtil.toDmpContext(), vos);
- return AdmResponse.success();
- }
- /**
- * 根据ID删除 - 单条删除
- * @param vos
- * @return
- * @throws Exception
- */
- @PostMapping("/single/delete")
- public AdmResponse deleteSingle(@RequestBody List<AdmBuilding> vos) throws Exception {
- delete(vos);
- return AdmResponse.success();
- }
- /**
- * 更新
- * @param createRequest
- * @return
- * @throws Exception
- */
- @PostMapping("/update")
- public AdmResponse update(@RequestBody AdmCreateRequest<AdmBuilding> createRequest) throws Exception {
- List<AdmBuilding> vos = CollUtil.newArrayList(createRequest.getContent());
- vos.forEach(admBuilding -> {
- if(StrUtil.isEmpty(admBuilding.getName())){
- admBuilding.setName(ObjectNameUtil.objectName("建筑-"));
- }
- });
- vos = service.doUpdate(AdmContextUtil.toDmpContext(), AdmBuilding.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 {
- request.setName(AdmBuilding.OBJ_TYPE);
- return service.doQuery(AdmContextUtil.toDmpContext(), request, AdmBuilding.class);
- }
- /**
- * 统计
- * @param projectId
- * @param request
- * @return
- * @throws Exception
- */
- @PostMapping("/count")
- public AdmResponse count(@QueryParam("projectId") String projectId,
- @RequestBody AdmQueryCriteria request) throws Exception {
- request.setName(AdmBuilding.OBJ_TYPE);
- request.setOnlyCount(true);
- return service.doQuery(AdmContextUtil.toDmpContext(), request, AdmBuilding.class);
- }
- }
|