ludc
2024-08-06 2d014981bfa74a5653456349dc6dcd229f18c7a2
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
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
package com.vci.web.controller;
 
import com.vci.corba.common.PLException;
import com.vci.starter.web.annotation.controller.VciUnCheckRight;
import com.vci.starter.web.annotation.log.VciBusinessLog;
import com.vci.starter.web.enumpck.BooleanEnum;
import com.vci.starter.web.exception.VciBaseException;
import com.vci.starter.web.pagemodel.BaseQueryObject;
import com.vci.starter.web.pagemodel.BaseResult;
import com.vci.starter.web.pagemodel.DataGrid;
import com.vci.starter.web.pagemodel.Tree;
import com.vci.starter.web.util.BeanUtil;
import com.vci.starter.web.util.ControllerUtil;
import com.vci.starter.web.util.LangBaseUtil;
import com.vci.starter.web.util.VciBaseUtil;
import com.vci.pagemodel.OsBtmTypeAttributeVO;
import com.vci.pagemodel.OsBtmTypeVO;
import com.vci.pagemodel.OsERVO;
import com.vci.web.service.OsAttributeServiceI;
import com.vci.web.service.OsBtmServiceI;
import com.vci.web.service.WebBtmIOServiceI;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.web.bind.annotation.*;
 
import javax.servlet.http.HttpServletResponse;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
 
import static com.vci.constant.FrameWorkBusLangCodeConstant.DATA_OID_NOT_EXIST;
 
/**
 * 业务类型的控制器
 * @author weidy
 * @date 2021/8/23
 */
@RequestMapping("/btmTypeController")
@VciBusinessLog(modelName="业务类型")
@RestController
public class WebBtmTypeController {
 
    /**
     * 日志
     */
    private Logger logger = LoggerFactory.getLogger(getClass());
 
    /**
     * 业务类型的服务
     */
    @Autowired
    private OsBtmServiceI btmService;
 
    /**
     * 业务类型导入导出服务
     */
    @Autowired
    private WebBtmIOServiceI btmIOService;
 
    /**
     * 属性的服务
     */
    @Lazy
    @Autowired(required = false)
    private OsAttributeServiceI attributeService;
 
    /**
     * 业务类型列表
     * @param baseQueryObject 查询条件
     * @return 列表的内容
     */
    @GetMapping( "/gridBtmType")
    @VciBusinessLog(operateName = "业务类型列表")
    public DataGrid<OsBtmTypeVO> gridBtmType(BaseQueryObject baseQueryObject){
        return btmService.referDataGrid(baseQueryObject.getConditionMap(),baseQueryObject.getPageHelper());
    }
 
    /**
     * 获取名字以filter开始的业务类型(for 查询),主要用于属性池的业务类型选择对话框
     * @param btmName 查询条件
     * @return 列表的内容
     */
    @GetMapping( "/getBizTypes")
    @VciBusinessLog(operateName = "业务类型列表(主要用于对话框使用)")
    @VciUnCheckRight
    public BaseResult getBizTypes(String btmName){
        try {
            return BaseResult.dataList(Arrays.asList(btmService.getBizTypes(btmName)));
        }catch (Exception e) {
            e.printStackTrace();
            String exceptionMessage = "获取业务类型时出现错误,原因:" + VciBaseUtil.getExceptionMessage(e);
            logger.error(exceptionMessage);
            return BaseResult.fail(exceptionMessage);
        }
    }
 
 
    /**
     * 获取所有业务类型(树形结构)
     * @return 查询结果
     */
    @GetMapping( "/getTreeBizTypes")
    @VciBusinessLog(operateName = "获取所有业务类型(树形结构)")
    @VciUnCheckRight
    public BaseResult<List<Tree>> getTreeBizTypes(){
        try {
            return btmService.getTreeBizTypes();
        }catch (Exception e) {
            e.printStackTrace();
            String exceptionMessage = "获取业务类型时出现错误,原因:" + VciBaseUtil.getExceptionMessage(e);
            logger.error(exceptionMessage);
            return BaseResult.fail(exceptionMessage);
        }
    }
 
    /**
     * 获取业务类型包含的属性
     * @param btmId 业务类型名称
     * @return 属性的信息
     */
    @GetMapping(value = "/getAllAttributesByBtmId")
    @VciBusinessLog(operateName = "查看业务类型的属性")
    public BaseResult<List<OsBtmTypeAttributeVO>> getAllAttributesByBtmId(String btmId){
        List<OsBtmTypeAttributeVO> osBtmTypeAttributeVOS = btmService.listAttributeByBtmIdHasDefault(btmId);
        return BaseResult.dataList(osBtmTypeAttributeVOS);
    }
 
    /**
     * 参照的业务类型
     * @param baseQueryObject 查询条件
     * @return 列表的内容
     */
    @GetMapping( "/referDataGrid")
    @VciBusinessLog(operateName = "参照业务类型")
    public DataGrid<OsBtmTypeVO> referDataGrid(BaseQueryObject baseQueryObject){
        return btmService.referDataGrid(baseQueryObject.getConditionMap(),baseQueryObject.getPageHelper());
    }
 
    /**
     * 获取业务类型包含的属性,不分页
     * @param baseQueryObject 查询对象
     * @return 属性的信息
     */
    @GetMapping(value = "/gridAttributesByBtmId")
    @VciBusinessLog(operateName = "查看业务类型的属性")
    public DataGrid<OsBtmTypeAttributeVO> gridAttributesByBtmId(BaseQueryObject baseQueryObject){
        String btmTypeId = baseQueryObject.getConditionMap().containsKey("btmTypeId")?baseQueryObject.getConditionMap().get("btmTypeId"):"";
        if(StringUtils.isBlank(btmTypeId)){
            return new DataGrid<OsBtmTypeAttributeVO>();
        }
        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<OsBtmTypeAttributeVO> boAttrs = btmService.listAttributeByBtmId(btmTypeId);
        if(boAttrs == null){
            boAttrs = new ArrayList<>();
        }
        if(BooleanEnum.TRUE.getValue().equalsIgnoreCase(hasDefaultAttr)){
            //加默认的属性
            List<OsBtmTypeAttributeVO> finalBoAttrs = boAttrs;
            attributeService.getDefaultAttributeVOs().stream().forEach(attr->{
                OsBtmTypeAttributeVO attributeVO = new OsBtmTypeAttributeVO();
                BeanUtil.convert(attr,attributeVO);
                attributeVO.setAttributeLength(attr.getAttrLength());
                attributeVO.setAttrDataType(attr.getAttributeDataType());
                attributeVO.setReferBtmTypeId(attr.getBtmTypeId());
                attributeVO.setReferBtmTypeName(attr.getBtmTypeName());
                finalBoAttrs.add(attributeVO);
            });
            boAttrs = finalBoAttrs;
        }
        List<OsBtmTypeAttributeVO> 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());
        DataGrid<OsBtmTypeAttributeVO> dataGrid = new DataGrid<OsBtmTypeAttributeVO>();
        dataGrid.setTotal(attrList.size());;
        dataGrid.setData(attrList);
        return dataGrid;
    }
 
 
    /**
     * 使用主键获取业务类型包含的属性,不分页
     * @param baseQueryObject 查询对象
     * @return 属性的信息
     */
    @GetMapping(value = "/gridAttributeByBtmTypeOid")
    @VciBusinessLog(operateName = "使用业务类型主键查看包含的属性")
    public DataGrid<OsBtmTypeAttributeVO> gridAttributesByBtmTypeOid(String btmTypeOid,BaseQueryObject baseQueryObject){
        if(StringUtils.isBlank(btmTypeOid)){
            return new DataGrid<OsBtmTypeAttributeVO>();
        }
        String attrId = baseQueryObject.getConditionMap().containsKey("name")?baseQueryObject.getConditionMap().get("name").replace("*",""):"";
        String attrName = baseQueryObject.getConditionMap().containsKey("label") ? baseQueryObject.getConditionMap().get("label").replace("*","") : "";
        OsBtmTypeVO btmTypeVO = btmService.selectByOid(btmTypeOid);
        List<OsBtmTypeAttributeVO> boAttrs = btmService.listAttributeByBtmId(btmTypeVO.getId());
        List<OsBtmTypeAttributeVO> attrList = boAttrs.stream().filter(s->{
            boolean usedFlag = true;
            if(StringUtils.isNotBlank(attrId) && !s.getId().contains(attrId)){
                usedFlag = false;
            }
            if(StringUtils.isNotBlank(attrName) && !s.getName().contains(attrName)){
                usedFlag = false;
            }
            return usedFlag;
        }).collect(Collectors.toList());
        DataGrid<OsBtmTypeAttributeVO> dataGrid = new DataGrid<OsBtmTypeAttributeVO>();
        dataGrid.setTotal(attrList.size());;
        dataGrid.setData(attrList);
        return dataGrid;
    }
 
 
    /**
     * 使用主键获取业务类型的对象
     * @param oid 主键
     * @return 业务类型的对象
     */
    @GetMapping("/getBtmTypeByOid")
    public BaseResult<OsBtmTypeVO> getBtmTypeByOid(String oid){
        OsBtmTypeVO btmTypeVO = btmService.selectByOid(oid);
        if(btmTypeVO == null){
            return BaseResult.fail(DATA_OID_NOT_EXIST);
        }
        return BaseResult.success(btmTypeVO);
    }
    /**
     * 导出业务类型的信息到word中
     * @param btmTypeIds 业务类型的编号,用逗号分割
     * @param response 响应对象
     * @return 执行结果
     */
    @PostMapping("/exportBtmType2Word")
    @VciBusinessLog(operateName = "导出业务类型到word中")
    public void exportDataBaseToWord(String btmTypeIds, HttpServletResponse response) throws FileNotFoundException, VciBaseException {
        String exportWordFileName = btmIOService.exportBtmTypesToWord(VciBaseUtil.str2List(btmTypeIds));
        if(StringUtils.isNotBlank(exportWordFileName)){
            try {
                ControllerUtil.writeFileToResponse(response, exportWordFileName);
            }catch (FileNotFoundException e){
                try {
                    ControllerUtil.writeDataToResponse(response,LangBaseUtil.getErrorMsg(e).getBytes(StandardCharsets.UTF_8),null);
                } catch (IOException ex) {
                    ex.printStackTrace();
                }
            } catch (IOException e) {
                try {
                    ControllerUtil.writeDataToResponse(response,LangBaseUtil.getErrorMsg(e).getBytes(StandardCharsets.UTF_8),null);
                } catch (IOException ex) {
                    ex.printStackTrace();
                }
            }
        }
    }
 
    /**
     * 导出数据库的表信息到excel
     * @param response 响应对象
     * @param btmTypeIds 业务类型的编号,用逗号分割
     */
    @PostMapping("/exportBtmType2Excel")
    @VciBusinessLog(operateName = "导出业务类型到excel中")
    public void exportAllTableToExcel(String btmTypeIds,HttpServletResponse response){
        String excelFileName = btmIOService.exportBtmTypesToExcel(VciBaseUtil.str2List(btmTypeIds));
        try {
            ControllerUtil.writeFileToResponse(response,excelFileName);
        } catch (IOException e) {
            try {
                ControllerUtil.writeDataToResponse(response,LangBaseUtil.getErrorMsg(e).getBytes(StandardCharsets.UTF_8),null);
            } catch (IOException ex) {
                ex.printStackTrace();
            }
        }
    }
 
    /**
     * 根据业务类型生成业务类型使用的ER图
     * @param id 业务类型ID
     * @return 执行结果
     */
    @GetMapping("/createERDiagram")
    public BaseResult createERDiagram(String id){
        OsERVO osERVO = btmService.createERDiagram(id);
        return BaseResult.success(osERVO);
    }
 
    /**
     * 获取使用这个业务类型的E-R图
     * @param id 业务类型编号
     * @return 执行结果
     */
    @GetMapping("/createERUsed")
    public BaseResult createERUsed(String id){
        return BaseResult.success(btmService.createERUsed(id));
    }
}