Browse Source

设备报表:设备文件更新

lvxianyun 3 years ago
parent
commit
e726e2de40

+ 69 - 3
src/main/java/com/persagy/proxy/adm/controller/AdmReportEquipController.java

@@ -1,6 +1,7 @@
 package com.persagy.proxy.adm.controller;
 
 import cn.hutool.core.collection.CollUtil;
+import cn.hutool.core.util.ReflectUtil;
 import cn.hutool.core.util.StrUtil;
 import cn.hutool.json.JSONUtil;
 import com.alibaba.fastjson.JSONObject;
@@ -20,6 +21,7 @@ import com.persagy.dmp.digital.client.DigitalRelationFacade;
 import com.persagy.dmp.digital.entity.ObjectRelation;
 import com.persagy.proxy.adm.constant.AdmCommonConstant;
 import com.persagy.proxy.adm.model.*;
+import com.persagy.proxy.adm.model.equip.EquipUpDateEnclosure;
 import com.persagy.proxy.adm.request.AdmCreateRequest;
 import com.persagy.proxy.adm.request.AdmQueryCriteria;
 import com.persagy.proxy.adm.request.AdmResponse;
@@ -35,6 +37,7 @@ import org.springframework.beans.factory.annotation.Value;
 import org.springframework.web.bind.annotation.*;
 
 import javax.ws.rs.QueryParam;
+import java.lang.reflect.Field;
 import java.util.*;
 import java.util.stream.Collectors;
 
@@ -243,6 +246,8 @@ public class AdmReportEquipController {
     }
 
     /**
+     * 跟维新确认过 暂未使用
+     *
      * 根据建筑, 楼层, 业务空间类型, 业务空间id 查询设备
      *
      *  description = "例子: 根据设备类型或部件类型查询(\"Filters\": \"category ='SISU'\")," +
@@ -263,6 +268,7 @@ public class AdmReportEquipController {
     }
 
     /**
+     *  跟维新确认过 暂未使用
      * 根据建筑, 楼层, 业务空间类型, 业务空间id  查询部件
      *
      * 根据建筑, 楼层, 业务空间类型, 业务空间id查询部件", description = "例子: 根据设备类型或部件类型查询(\"Filters\": \"category ='SISU'\")," +
@@ -426,14 +432,52 @@ public class AdmReportEquipController {
     /**
      * 修改设备的附件功能
      * {
-     *     "content":"[{....}]"  EquipUpDateEnclosure 实体list
+     *     "content":"{....}"  EquipUpDateEnclosure 实体list
      * }
      */
     @PostMapping("/update")
     public AdmResponse equipUpDateEnclosure(@QueryParam("projectId") String projectId,@RequestBody ObjectNode equipUpDateEnclosureRequest) {
         //return EquipmentService.equipUpDateEnclosurs(equipUpDateEnclosureRequest)
-        //TODO
-        return null;
+        if(JSONUtil.isNull(equipUpDateEnclosureRequest)){
+            return AdmResponse.failure(ResponseCode.A0400.getDesc()+",不能为空");
+        }
+        InstanceUrlParam context = new InstanceUrlParam(groupCode, null, projectId, AdmCommonConstant.APP_ID);
+        List<EquipUpDateEnclosure> equipUpDateEnclosure = JSONUtil.toList(equipUpDateEnclosureRequest.get("content").toString(), EquipUpDateEnclosure.class);
+        if(CollUtil.isNotEmpty(equipUpDateEnclosure)){
+            Map<String, EquipUpDateEnclosure> equipUpDateEnclosureMap = CollUtil.fieldValueMap(equipUpDateEnclosure, BaseEntity.PROP_ID);
+            if(equipUpDateEnclosureMap.size() < equipUpDateEnclosure.size()) {
+                return AdmResponse.failure("设备id不能为空");
+            }
+            //获取待更新的设备
+            QueryCriteria queryCriteria = new QueryCriteria();
+            ObjectNode criteria = JsonNodeFactory.instance.objectNode();
+            criteria.put("objType", AdmEquipment.OBJ_TYPE);
+            ArrayNode arrayNode = criteria.putObject("id").putArray("$in");
+            equipUpDateEnclosureMap.keySet().stream().forEach(equipId -> arrayNode.add(equipId));
+            queryCriteria.setCriteria(criteria);
+            AdmResponse euips = equipmentService.doQuery(context, queryCriteria, AdmEquipment.class);
+            if(CollUtil.isEmpty(euips.getContent())){
+                return AdmResponse.failure(ResponseCode.A0400.getDesc());
+            }
+            //将需要更新的数据放到待更新的设备中
+            List<AdmEquipment> equipmentList = JSONUtil.toList(euips.getContent().toString(), AdmEquipment.class);
+            //获取所有属性
+            Map<String, Field> fieldMap = ReflectUtil.getFieldMap(EquipUpDateEnclosure.class);
+            //对每个设备更新属性
+            equipmentList.stream().forEach(admEquipment -> {
+                fieldMap.keySet().forEach(fieldName -> {
+                    EquipUpDateEnclosure enclosure = equipUpDateEnclosureMap.get(admEquipment.getId());
+                    List<AdmTaskPic> newAttr = (List<AdmTaskPic>) ReflectUtil.getFieldValue(enclosure,fieldName);
+                    if(CollUtil.isNotEmpty(newAttr)){
+                        dealTaskFiles(admEquipment, fieldName, newAttr);
+                    }
+                });
+            });
+            List<AdmEquipment> vos = equipmentService.doUpdate(context, AdmEquipment.class, equipmentList);
+            return AdmResponse.success(vos);
+        }else{
+            return AdmResponse.failure(ResponseCode.A0400.getDesc());
+        }
     }
 
     /**
@@ -976,4 +1020,26 @@ public class AdmReportEquipController {
         }
         return gatherInfoPoint;
     }
+
+
+    /**
+     * 处理设备属性文件 -> 设备的信息点
+     * @param equip
+     * @param attribute
+     */
+    private void dealTaskFiles(AdmEquipment equip, String attribute, List<AdmTaskPic> upTarget){
+        Map<String, Object> infos =  equip.getInfos();
+        boolean containsKey1 = infos.containsKey(attribute);
+        if (containsKey1) {
+            if (infos.get(attribute) != null && StrUtil.isNotEmpty(infos.get(attribute).toString())){
+                List<AdmTaskPic> list = JSONUtil.toList(infos.get(attribute).toString(), AdmTaskPic.class);
+                list.addAll(upTarget);
+                infos.put(attribute, list);
+            }else {
+                infos.put(attribute, upTarget);
+            }
+        } else {
+            infos.put(attribute, upTarget);
+        }
+    }
 }