|
@@ -2,15 +2,19 @@ package com.persagy.proxy.adm.controller;
|
|
|
|
|
|
import cn.hutool.core.collection.CollUtil;
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
+import com.fasterxml.jackson.databind.node.ObjectNode;
|
|
|
+import com.persagy.dmp.basic.utils.JsonNodeUtils;
|
|
|
import com.persagy.proxy.adm.model.AdmEquipment;
|
|
|
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.IAdmEquipmentService;
|
|
|
import com.persagy.proxy.adm.utils.AdmContextUtil;
|
|
|
+import com.persagy.proxy.adm.utils.ObjectNameUtil;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
+import java.util.ArrayList;
|
|
|
import java.util.List;
|
|
|
|
|
|
/**
|
|
@@ -33,8 +37,7 @@ public class AdmEquipmentController {
|
|
|
* @throws Exception
|
|
|
*/
|
|
|
@PostMapping("/count")
|
|
|
- public AdmResponse count(
|
|
|
- @RequestBody AdmQueryCriteria request) throws Exception {
|
|
|
+ public AdmResponse count(@RequestBody AdmQueryCriteria request) throws Exception {
|
|
|
request.setName(AdmEquipment.OBJ_TYPE);
|
|
|
request.setOnlyCount(true);
|
|
|
return service.doQuery(AdmContextUtil.toDmpContext(), request, AdmEquipment.class);
|
|
@@ -49,6 +52,15 @@ public class AdmEquipmentController {
|
|
|
@PostMapping("/create")
|
|
|
public AdmResponse create(@RequestBody AdmCreateRequest<AdmEquipment> createRequest) throws Exception {
|
|
|
List<AdmEquipment> vos = CollUtil.newArrayList(createRequest.getContent());
|
|
|
+ if(CollUtil.isEmpty(vos)){
|
|
|
+ return AdmResponse.success();
|
|
|
+ }
|
|
|
+ //创建设备
|
|
|
+ vos.stream().forEach(equipment -> {
|
|
|
+ if (StrUtil.isEmpty(equipment.getName())){
|
|
|
+ equipment.setName(ObjectNameUtil.objectName("设备-"));
|
|
|
+ }
|
|
|
+ });
|
|
|
vos = service.doInsertEuip(AdmContextUtil.toDmpContext(), AdmEquipment.class, vos);
|
|
|
return AdmResponse.success(vos);
|
|
|
}
|
|
@@ -77,6 +89,21 @@ public class AdmEquipmentController {
|
|
|
public AdmResponse update(@RequestBody AdmCreateRequest<AdmEquipment> createRequest) throws Exception {
|
|
|
List<AdmEquipment> vos = CollUtil.newArrayList(createRequest.getContent());
|
|
|
//vos = service.doUpdateEuip(AdmContextUtil.toDmpContext(), AdmEquipment.class, vos);
|
|
|
+ //针对设备更新时,所有更新的字段都放到信息点中的情况特殊处理
|
|
|
+ if(CollUtil.isNotEmpty(vos)){
|
|
|
+ List<AdmEquipment> equipmentList = new ArrayList<>(vos.size());
|
|
|
+ vos.stream().forEach(equipment -> {
|
|
|
+ if(CollUtil.isNotEmpty(equipment.getInfos())){
|
|
|
+ AdmEquipment admEquipment = new AdmEquipment();
|
|
|
+ admEquipment.setId(equipment.getId());
|
|
|
+ admEquipment.setInfos(equipment.getInfos());
|
|
|
+ ObjectNode objectNode = JsonNodeUtils.toObjectNode(admEquipment, "infos", null);
|
|
|
+ AdmEquipment admEquipmentNew = JsonNodeUtils.toEntity(objectNode, AdmEquipment.class, "infos");
|
|
|
+ equipmentList.add(admEquipmentNew);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ vos = equipmentList;
|
|
|
+ }
|
|
|
vos = service.doUpdate(AdmContextUtil.toDmpContext(), AdmEquipment.class, vos);
|
|
|
return AdmResponse.success(vos);
|
|
|
}
|
|
@@ -130,8 +157,7 @@ public class AdmEquipmentController {
|
|
|
* @throws Exception
|
|
|
*/
|
|
|
@GetMapping("/query-equip")
|
|
|
- public AdmResponse queryEquip(
|
|
|
- @RequestBody AdmQueryCriteria request) throws Exception {
|
|
|
+ public AdmResponse queryEquip(@RequestBody AdmQueryCriteria request) throws Exception {
|
|
|
//request.setName("equipment");
|
|
|
if(StrUtil.isNotEmpty(request.getFilters())){
|
|
|
request.setFilters(String.join(";",request.getFilters(),"objType in ['equipment','component']"));
|
|
@@ -150,6 +176,15 @@ public class AdmEquipmentController {
|
|
|
@PostMapping("/creat-equip-pro")
|
|
|
public AdmResponse createExt(@RequestBody AdmCreateRequest<AdmEquipment> admEquipment) throws Exception {
|
|
|
List<AdmEquipment> vos = CollUtil.newArrayList(admEquipment.getContent());
|
|
|
+ if(CollUtil.isEmpty(vos)){
|
|
|
+ return AdmResponse.success();
|
|
|
+ }
|
|
|
+ //创建设备
|
|
|
+ vos.stream().forEach(equipment -> {
|
|
|
+ if (StrUtil.isEmpty(equipment.getName())){
|
|
|
+ equipment.setName(ObjectNameUtil.objectName("设备-"));
|
|
|
+ }
|
|
|
+ });
|
|
|
vos = service.doInsertExt(AdmContextUtil.toDmpContext(), AdmEquipment.class, vos);
|
|
|
return AdmResponse.success(vos);
|
|
|
}
|