1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768 |
- 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<AdmComponent> implements IAdmComponentService, IAdmComAndEquipService {
- @Autowired
- private DmpRwdClient rwdClient;
- @Autowired
- private ObjectMapper objectMapper;
- @Override
- public List<AdmComponent> doInsertExt(InstanceUrlParam context, Class<AdmComponent> clazz, List<AdmComponent> voList) {
- if(CollUtil.isEmpty(voList)) {
- return null;
- }
- Set<String> classCodes = voList.stream().map(AdmComponent::getClassCode).collect(Collectors.toSet());
- //查询定义类型
- QueryCriteria criteriaObject = getDmpCriteria(context, classCodes, AdmComponent.OBJ_TYPE);
- JSONObject paraPe = null;
- try {
- String paraStr = objectMapper.writeValueAsString(criteriaObject);
- paraPe = JSONObject.parseObject(paraStr);
- } catch (JsonProcessingException e) {
- throw new RuntimeException("转换查询条件出错:" + e.getMessage());
- }
- DmpResult<JSONArray> resultDef = rwdClient.queryDefClass(context, paraPe);
- Map<String, ObjectTypeDefine> 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);
- }
- }
|