package com.vci.ubcs.code.service.impl; import com.alibaba.cloud.commons.lang.StringUtils; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.vci.ubcs.code.service.ICodeReferBtmTypeService; import com.vci.ubcs.omd.feign.IAttributeClient; import com.vci.ubcs.omd.feign.IBtmAttributeClient; import com.vci.ubcs.omd.feign.IBtmTypeClient; import com.vci.ubcs.omd.vo.AttributeVO; import com.vci.ubcs.omd.vo.BtmTypeAttributeVO; import com.vci.ubcs.omd.vo.BtmTypeVO; import com.vci.ubcs.starter.web.enumpck.BooleanEnum; import com.vci.ubcs.starter.web.pagemodel.BaseQueryObject; import com.vci.ubcs.starter.web.pagemodel.DataGrid; import com.vci.ubcs.starter.web.util.BeanUtil; import org.springblade.core.launch.constant.AppConstant; import org.springblade.core.log.exception.ServiceException; import org.springblade.core.tool.api.R; import org.springframework.stereotype.Service; import javax.annotation.Resource; import java.rmi.ServerException; import java.util.ArrayList; import java.util.List; import java.util.Map; import java.util.stream.Collectors; /** * 对omd中提供的feign接口进行调用,以及处理相关逻辑 * @author ludc * @date 2023/6/1 18:39 */ @Service public class CodeReferBtmTypeServiceImpl implements ICodeReferBtmTypeService { /** * 业务类型服务 */ @Resource private IBtmTypeClient btmTypeClient; /** * 获取业务类型列表 * @param baseQueryObject 查询条件 * @return 列表的内容 */ @Override public Page referDataGrid(BaseQueryObject baseQueryObject) throws ServiceException { Map conditionMap = baseQueryObject.getConditionMap(); conditionMap.put("domain", AppConstant.APPLICATION_NAME_CODE); baseQueryObject.setConditionMap(conditionMap); R> btmTypeClientRefPage = btmTypeClient.getRefPage(baseQueryObject); if(!btmTypeClientRefPage.isSuccess()){ throw new ServiceException("业务类型feign接口调用错误"); } return btmTypeClientRefPage.getData(); } /** * 获取业务类型包含的属性,不分页 * @param baseQueryObject 查询对象 * @return 属性的信息 */ @Override public Page gridAttributesByBtmId(BaseQueryObject baseQueryObject) throws ServiceException { String btmTypeId = baseQueryObject.getConditionMap().containsKey("btmTypeId")?baseQueryObject.getConditionMap().get("btmTypeId"):""; if(StringUtils.isBlank(btmTypeId)){ return new Page<>(); } String hasDefaultAttr = baseQueryObject.getConditionMap().getOrDefault("hasDefaultAttr","false"); String attrId = baseQueryObject.getConditionMap().containsKey("name")?baseQueryObject.getConditionMap().get("name").replace("*",""):""; String attrName = baseQueryObject.getConditionMap().containsKey("label") ? baseQueryObject.getConditionMap().get("label").replace("*","") : ""; List boAttrs = null; try { boAttrs = btmTypeClient.getAllAttributeByBtmId(btmTypeId).getData().getAttributes(); }catch (Exception e){ throw new ServiceException("业务类型feign接口调用错误"); } if(boAttrs == null){ boAttrs = new ArrayList<>(); } if(BooleanEnum.TRUE.getValue().equalsIgnoreCase(hasDefaultAttr)){ // TODO 获取默认的属性 List finalBoAttrs = boAttrs; BtmTypeVO btmTypeVO = btmTypeClient.getDefaultAttrByBtmId(btmTypeId).getData(); btmTypeVO.getAttributes().stream().forEach(attr->{ BtmTypeAttributeVO attributeVO = new BtmTypeAttributeVO(); BeanUtil.convert(attr,attributeVO); attributeVO.setAttributeLength(attr.getAttributeLength()); attributeVO.setAttrDataType(attr.getAttrDataType()); attributeVO.setReferBtmTypeId(attr.getBtmTypeId()); attributeVO.setReferBtmTypeName(attr.getReferBtmTypeName()); finalBoAttrs.add(attributeVO); }); boAttrs = finalBoAttrs; } List attrList = boAttrs.stream().filter(s->{ boolean usedFlag = true; if(StringUtils.isNotBlank(attrId) && !s.getId().contains(attrId.replace("*",""))){ usedFlag = false; } if(StringUtils.isNotBlank(attrName) && !s.getName().contains(attrName.replace("*",""))){ usedFlag = false; } return usedFlag; }).collect(Collectors.toList()); Page btmTypeAttributeVOPage = new Page<>(); btmTypeAttributeVOPage.setRecords(attrList); return btmTypeAttributeVOPage; } }