ludc
2023-06-09 00062ed2e07d3d705abd1baa10ee483617f10dfb
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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
package com.vci.ubcs.omd.feign;
 
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.vci.ubcs.omd.entity.BtmType;
import com.vci.ubcs.omd.service.IBtmTypeService;
import com.vci.ubcs.omd.vo.BtmTypeVO;
import com.vci.ubcs.omd.wrapper.BtmTypeWrapper;
import com.vci.ubcs.starter.web.pagemodel.BaseQueryObject;
import com.vci.ubcs.starter.web.pagemodel.PageHelper;
import com.vci.ubcs.starter.web.util.VciBaseUtil;
import lombok.AllArgsConstructor;
import org.springblade.core.mp.support.Condition;
import org.springblade.core.mp.support.Query;
import org.springblade.core.tenant.annotation.NonDS;
import org.springblade.core.tool.api.R;
import org.springblade.core.tool.utils.BeanUtil;
import org.springblade.core.tool.utils.Func;
import org.springframework.cglib.beans.BeanMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;
import springfox.documentation.annotations.ApiIgnore;
 
import java.util.*;
 
/**
 * Description: 业务类型服务Feign实现类
 *
 * @author LiHang
 * @date 2023/4/24
 */
@NonDS
@ApiIgnore
@RestController
@AllArgsConstructor
public class BtmTypeClient implements IBtmTypeClient {
 
    private final IBtmTypeService btmTypeService;
 
    private final String DOMAIN = "domain";
 
 
    /**
     * 参照获取业务类型详情信息
     *
     * @param oid 主键
     * @return 业务类型详情信息
     */
    @Override
    @GetMapping(GET_DETAIL)
    public R<BtmTypeVO> getDetail(String oid) {
        return R.data(btmTypeService.getBtmTypeByOid(oid));
    }
 
    /**
     * 参照列表查询
     *
     * @param baseQueryObject 查询条件对象
     * @return 查询结果
     */
    @Override
    @PostMapping(GET_REF_PAGE)
    public R<Page<BtmTypeVO>> getRefPage(BaseQueryObject baseQueryObject) {
        Map<String, String> conditionMap = baseQueryObject.getConditionMap();
        if (conditionMap == null){
            conditionMap = new HashMap<>(16);
        }
        if (!conditionMap.containsKey(DOMAIN)){
            return R.fail("领域值不能为空");
        }
        PageHelper pageHelper = baseQueryObject.getPageHelper();
        if (pageHelper == null){
            pageHelper = new PageHelper(-1);
        }
        String domainValue = conditionMap.get(DOMAIN);
        VciBaseUtil.alertNotNull(domainValue,"领域值");
        conditionMap.remove(DOMAIN);
        BtmType queryObj = new BtmType();
        BeanMap.create(queryObj).putAll(conditionMap);
        Query query = new Query();
        query.setSize(pageHelper.getLimit());
        query.setCurrent(pageHelper.getPage());
        IPage<BtmType> page = btmTypeService.page(Condition.getPage(query), Condition.getQueryWrapper(queryObj).lambda().eq(BtmType::getDomain, domainValue).orderByAsc(BtmType::getId));
        Page<BtmTypeVO> pageVO = new Page<>();
        BeanUtil.copy(page,pageVO);
        pageVO.setRecords(BtmTypeWrapper.build().listEntityVO(page.getRecords()));
        R<Page<BtmTypeVO>> r = R.data(pageVO);
        r.setSuccess(true);
        return r;
    }
 
    /**
     * 参照列表查询
     * @param baseQueryObject 查询条件对象
     * @return 查询结果
     */
    @Override
    @PostMapping(GET_REF)
    public R<List<BtmTypeVO>> getRef(BaseQueryObject baseQueryObject) {
        Map<String, String> conditionMap = baseQueryObject.getConditionMap();
        if (conditionMap == null){
            conditionMap = new HashMap<>(16);
        }
        if (!conditionMap.containsKey(DOMAIN)){
            return R.fail("领域值不能为空");
        }
        String domainValue = conditionMap.get(DOMAIN);
        VciBaseUtil.alertNotNull(domainValue,"领域值");
        conditionMap.remove(DOMAIN);
        BtmType queryObj = new BtmType();
        BeanMap.create(queryObj).putAll(conditionMap);
        List<BtmType> list = btmTypeService.list(Condition.getQueryWrapper(queryObj).lambda().eq(BtmType::getDomain, domainValue).orderByAsc(BtmType::getId));
        return R.data(BtmTypeWrapper.build().listEntityVO(list));
    }
 
    /**
     * 根据英文名称批量查询对象
     *
     * @param ids 对象英文名称 但是不能超过1000
     * @return 业务对象
     */
    @Override
    @PostMapping(GET_BY_IDS)
    public R<List<BtmTypeVO>> selectByIdCollection(List<String> ids) {
        Func.requireNotNull(ids,"业务类型英文名称");
        List<BtmTypeVO> voList = BtmTypeWrapper.build().listEntityVO(
            Optional.ofNullable(btmTypeService.list(
                    Wrappers.<BtmType>query().lambda().in(BtmType::getId, ids)
                )
            ).orElseGet(ArrayList::new)
        );
        return R.data(voList);
    }
 
    /**
     * 批量根据主键获取业务类型
     *
     * @param pkBtmTypeCollection 业务类型主键集合
     * @return 业务类型列表,如果有不存在的不会返回,全部不存在的则返回空列表
     */
    @Override
    @PostMapping(GET_BY_OIDS)
    public R<List<BtmTypeVO>> listBtmTypeByOidCollection(List<String> pkBtmTypeCollection) {
        Func.requireNotNull(pkBtmTypeCollection,"业务类型主键");
        List<BtmTypeVO> voList = BtmTypeWrapper.build().listEntityVO(
            Optional.ofNullable(btmTypeService.list(
                    Wrappers.<BtmType>query().lambda().in(BtmType::getOid, pkBtmTypeCollection)
                )
            ).orElseGet(ArrayList::new)
        );
        return R.data(voList);
    }
 
    /**
     * 获取业务类型,只有默认字段
     *
     * @param btmTypeId 业务类型id
     * @return 默认字段属性
     */
    @Override
    public R<BtmTypeVO> getDefaultAttrByBtmId(String btmTypeId) {
        return R.data(Optional.ofNullable(btmTypeService.getDefaultAttrByBtmId(btmTypeId)).orElseGet(BtmTypeVO::new));
    }
 
    /**
     * 获取业务类型,有所有的字段
     *
     * @param btmTypeId 业务类型id
     * @return 所有字段
     */
    @Override
    public R<BtmTypeVO> getAllAttributeByBtmId(String btmTypeId) {
        return R.data(Optional.ofNullable(btmTypeService.getAllAttributeByBtmId(btmTypeId)).orElseGet(BtmTypeVO::new));
    }
 
    /**
     * 获取业务类型,有所有的字段
     *
     * @param btmTypeOid 业务类型主键
     * @return 所有字段
     */
    @Override
    public R<BtmTypeVO> getAllAttributeByBtmOid(String btmTypeOid) {
        return R.data(Optional.ofNullable(btmTypeService.getAllAttributeByBtmOid(btmTypeOid)).orElseGet(BtmTypeVO::new));
    }
}