yuxc
2023-06-06 dfb9b1cc0b412334d0ab7891caac061a8243a0cb
Source/UBCS/ubcs-service/ubcs-code/src/main/java/com/vci/ubcs/code/service/impl/CodeReferBtmTypeServiceImpl.java
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,113 @@
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<BtmTypeVO> referDataGrid(BaseQueryObject baseQueryObject) throws ServiceException {
      Map<String, String> conditionMap = baseQueryObject.getConditionMap();
      conditionMap.put("domain", AppConstant.APPLICATION_NAME_CODE);
      baseQueryObject.setConditionMap(conditionMap);
      R<Page<BtmTypeVO>> btmTypeClientRefPage = btmTypeClient.getRefPage(baseQueryObject);
      if(btmTypeClientRefPage.getCode() != 200){
         throw new ServiceException("业务类型feign接口调用错误");
      }
      return btmTypeClientRefPage.getData();
   }
   /**
    * èŽ·å–ä¸šåŠ¡ç±»åž‹åŒ…å«çš„å±žæ€§ï¼Œä¸åˆ†é¡µ
    * @param baseQueryObject æŸ¥è¯¢å¯¹è±¡
    * @return å±žæ€§çš„信息
    */
   @Override
   public Page<BtmTypeAttributeVO> 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<BtmTypeAttributeVO> 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<BtmTypeAttributeVO> 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<BtmTypeAttributeVO> 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<BtmTypeAttributeVO> btmTypeAttributeVOPage = new Page<>();
      btmTypeAttributeVOPage.setRecords(attrList);
      return btmTypeAttributeVOPage;
   }
}