ludc
2023-07-11 728546f4621e893019dea545f14b6e617301b15b
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
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;
    }
 
 
}