package com.persagy.proxy.adm.service.impl; import cn.hutool.core.collection.CollUtil; import cn.hutool.core.util.StrUtil; import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; import com.persagy.dmp.basic.model.QueryCriteria; import com.persagy.dmp.define.entity.ObjectTypeDefine; import com.persagy.proxy.adm.model.AdmComponent; import com.persagy.proxy.adm.service.IAdmComAndEquipService; import com.persagy.proxy.adm.service.IAdmComponentService; import com.persagy.proxy.adm.utils.ObjectNameUtil; import com.persagy.proxy.common.client.DmpRwdClient; import com.persagy.proxy.common.entity.DmpResult; import com.persagy.proxy.common.entity.InstanceUrlParam; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import java.util.List; import java.util.Map; import java.util.Set; import java.util.stream.Collectors; /** * ADM 组件 服务 * @author lvxy * @date 2021/8/19 */ @Service public class AdmComponentServiceImpl extends AbstractAdmBaseServiceImpl implements IAdmComponentService, IAdmComAndEquipService { @Autowired private DmpRwdClient rwdClient; @Autowired private ObjectMapper objectMapper; @Override public List doInsertExt(InstanceUrlParam context, Class clazz, List voList) { if(CollUtil.isEmpty(voList)) { return null; } Set classCodes = voList.stream().map(AdmComponent::getClassCode).collect(Collectors.toSet()); //查询定义类型 QueryCriteria criteriaObject = getDmpCriteria(context, classCodes, "component"); JSONObject paraPe = null; try { String paraStr = objectMapper.writeValueAsString(criteriaObject); paraPe = JSONObject.parseObject(paraStr); } catch (JsonProcessingException e) { throw new RuntimeException("转换查询条件出错:" + e.getMessage()); } DmpResult resultDef = rwdClient.queryDefClass(context, paraPe); Map finalDefClassMap = getDefineMap(resultDef); // 设备名字处理 voList.forEach(component -> { if (StrUtil.isNotEmpty(component.getName()) && CollUtil.isNotEmpty(finalDefClassMap) && finalDefClassMap.containsKey(component.getClassCode())) { ObjectTypeDefine defclass = finalDefClassMap.get(component.getClassCode()); component.setName(ObjectNameUtil.objectName(defclass.getName()+"-")); }else{ component.setName(ObjectNameUtil.objectName("部件-")); } }); return doInsert(context, clazz, voList); } }