package com.persagy.proxy.adm.service.impl; import cn.hutool.core.collection.CollUtil; import com.persagy.proxy.adm.model.AdmDict; import com.persagy.proxy.adm.model.AdmEquipment; import com.persagy.proxy.adm.model.AdmObjectType; import com.persagy.proxy.adm.model.AdmSystem; import com.persagy.proxy.adm.request.AdmQueryCriteria; import com.persagy.proxy.adm.request.AdmResponse; import com.persagy.proxy.adm.service.IAdmDictService; import com.persagy.proxy.adm.service.IAdmEquipmentService; import com.persagy.proxy.adm.service.IAdmSystemService; import com.persagy.proxy.common.entity.InstanceUrlParam; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import java.util.ArrayList; import java.util.List; import java.util.Map; /** * ADM 系统 实现类 * @author lvxy * @date 2021/8/18 */ @Service public class AdmSystemServiceImpl extends AbstractAdmBaseServiceImpl implements IAdmSystemService { @Autowired private IAdmDictService dictService; @Autowired private IAdmEquipmentService equipmentService; @Override public AdmResponse doQuery(InstanceUrlParam context, AdmQueryCriteria request, Class clazz) { AdmResponse response = super.doQuery(context, request, clazz); // 系统需要补充分类名称属性 ensureSpecialValues(context, (List) response.getContent()); return response; } @Override public void ensureSpecialValues(InstanceUrlParam context, List vos) { if(CollUtil.isEmpty(vos)) { return; } // 查询对象类型 - 只找到这个接口,应提供一个按编码查编码名称Map的接口 AdmDict admDict = AdmDict.builder().type(AdmSystem.OBJ_TYPE).build(); AdmResponse dicRs = dictService.queryCategory(context, admDict, AdmObjectType.class); List dicList = (List) dicRs.getContent(); if(CollUtil.isEmpty(dicList)) { return; } // 转换为编码名称Map Map codeNameMap = CollUtil.fieldValueAsMap(dicList, "code", "name"); // 给系统赋值 - 同时收集设备对象,扩展设备对象赋值 List equipmentList = new ArrayList<>(); for(AdmSystem vo:vos) { vo.setCategoryName(codeNameMap.get(vo.getClassCode())); // 收集设备对象 if(CollUtil.isEmpty(vo.getEquipmentList())) { continue; } equipmentList.addAll(vo.getEquipmentList()); } // 对象扩展属性赋值 equipmentService.ensureSpecialValues(context, equipmentList); } }