AdmComponentServiceImpl.java 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. package com.persagy.proxy.adm.service.impl;
  2. import cn.hutool.core.collection.CollUtil;
  3. import cn.hutool.core.util.StrUtil;
  4. import com.alibaba.fastjson.JSONArray;
  5. import com.alibaba.fastjson.JSONObject;
  6. import com.fasterxml.jackson.core.JsonProcessingException;
  7. import com.fasterxml.jackson.databind.ObjectMapper;
  8. import com.persagy.dmp.basic.model.QueryCriteria;
  9. import com.persagy.dmp.define.entity.ObjectTypeDefine;
  10. import com.persagy.proxy.adm.model.AdmComponent;
  11. import com.persagy.proxy.adm.service.IAdmComAndEquipService;
  12. import com.persagy.proxy.adm.service.IAdmComponentService;
  13. import com.persagy.proxy.adm.utils.ObjectNameUtil;
  14. import com.persagy.proxy.common.client.DmpRwdClient;
  15. import com.persagy.proxy.common.entity.DmpResult;
  16. import com.persagy.proxy.common.entity.InstanceUrlParam;
  17. import org.springframework.beans.factory.annotation.Autowired;
  18. import org.springframework.stereotype.Service;
  19. import java.util.List;
  20. import java.util.Map;
  21. import java.util.Set;
  22. import java.util.stream.Collectors;
  23. /**
  24. * ADM 组件 服务
  25. * @author lvxy
  26. * @date 2021/8/19
  27. */
  28. @Service
  29. public class AdmComponentServiceImpl extends AbstractAdmBaseServiceImpl<AdmComponent> implements IAdmComponentService, IAdmComAndEquipService {
  30. @Autowired
  31. private DmpRwdClient rwdClient;
  32. @Autowired
  33. private ObjectMapper objectMapper;
  34. @Override
  35. public List<AdmComponent> doInsertExt(InstanceUrlParam context, Class<AdmComponent> clazz, List<AdmComponent> voList) {
  36. if(CollUtil.isEmpty(voList)) {
  37. return null;
  38. }
  39. Set<String> classCodes = voList.stream().map(AdmComponent::getClassCode).collect(Collectors.toSet());
  40. //查询定义类型
  41. QueryCriteria criteriaObject = getDmpCriteria(context, classCodes, AdmComponent.OBJ_TYPE);
  42. JSONObject paraPe = null;
  43. try {
  44. String paraStr = objectMapper.writeValueAsString(criteriaObject);
  45. paraPe = JSONObject.parseObject(paraStr);
  46. } catch (JsonProcessingException e) {
  47. throw new RuntimeException("转换查询条件出错:" + e.getMessage());
  48. }
  49. DmpResult<JSONArray> resultDef = rwdClient.queryDefClass(context, paraPe);
  50. Map<String, ObjectTypeDefine> finalDefClassMap = getDefineMap(resultDef);
  51. // 设备名字处理
  52. voList.forEach(component -> {
  53. if (StrUtil.isNotEmpty(component.getName()) && CollUtil.isNotEmpty(finalDefClassMap) && finalDefClassMap.containsKey(component.getClassCode())) {
  54. ObjectTypeDefine defclass = finalDefClassMap.get(component.getClassCode());
  55. component.setName(ObjectNameUtil.objectName(defclass.getName()+"-"));
  56. }else{
  57. component.setName(ObjectNameUtil.objectName("部件-"));
  58. }
  59. });
  60. return doInsert(context, clazz, voList);
  61. }
  62. }