1821349743@qq.com
2023-02-20 a387ff8978bd0e738e83e0277cfa38d7c3ab3080
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
package com.product.data.sync.controller;
 
import com.product.core.config.CoreConst;
import com.product.core.controller.support.AbstractBaseController;
import com.product.core.entity.DataTableEntity;
import com.product.core.entity.FieldSetEntity;
import com.product.core.entity.RequestParameterEntity;
import com.product.core.exception.BaseException;
import com.product.core.spring.context.SpringMVCContextHolder;
import com.product.data.sync.config.CmnConst;
import com.product.data.sync.config.SystemCode;
import com.product.data.sync.service.FunctionSynchrService;
import com.product.data.sync.service.ide.IFunctionSynchrService;
import com.product.module.sys.version.ApiVersion;
import com.product.util.BaseUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
 
import javax.servlet.http.HttpServletRequest;
import java.sql.Connection;
 
/**
 * Copyright LX
 *
 * @Title: FunctionSynchrController
 * @Project: product-server
 * @date: 2021-08-30 14:20
 * @author: ZhouJie
 * @Description: 开发库功能同步
 */
@RequestMapping("/api/functionsync")
@RestController
public class FunctionSynchrController extends AbstractBaseController {
    @Autowired
    public FunctionSynchrService functionSynchrService;
 
    /**
     * 获取JDBC连接
     * @param request
     * @return
     */
    @RequestMapping(value = "/get-connect/{version}", method = RequestMethod.POST)
    @ApiVersion(1)
    public String getConnection(HttpServletRequest request) {
        try {
            // 获取参数
            FieldSetEntity fse = null;
            Object bean = request.getAttribute(CoreConst.API_POST_REQUEST_DATA);
            if (bean != null) {
                RequestParameterEntity reqp = (RequestParameterEntity) bean;
                fse = reqp.getFormData();
            }
            // 判断参数是否为空
            if (bean == null || fse == null) {
                SpringMVCContextHolder.getSystemLogger().error(SystemCode.SYSTEM_FORM_NODATA.getValue(),
                        SystemCode.SYSTEM_FORM_NODATA.getText());
                return this.error(SystemCode.SYSTEM_FORM_NODATA.getValue(), SystemCode.SYSTEM_FORM_NODATA.getText());
            }
            // 判断表名是否正常
            if (!CmnConst.PRODUCT_SYS_DATABASE_SYNC_FUNCTION.equals(fse.getTableName())) {
                SpringMVCContextHolder.getSystemLogger().error(SystemCode.SYSTEM_TABLE_NODATA.getValue(),
                        SystemCode.SYSTEM_TABLE_NODATA.getText());
                return this.error(SystemCode.SYSTEM_TABLE_NODATA.getValue(), SystemCode.SYSTEM_TABLE_NODATA.getText());
            }
            Connection conn = functionSynchrService.getConnection(fse);
            if(conn != null){
                conn.close();
                return OK();
            }
            return this.error(SystemCode.SYSTEM_RUN_CONNECT_CONFIGURE_FAIL.getValue(),
                    SystemCode.SYSTEM_RUN_CONNECT_CONFIGURE_FAIL.getText());
        } catch (BaseException e) {
            e.printStackTrace();
            SpringMVCContextHolder.getSystemLogger().error(e);
            return this.error(e);
        } catch (Exception e) {
            e.printStackTrace();
            SpringMVCContextHolder.getSystemLogger().error(e);
            return this.error(SystemCode.SYSTEM_RUN_CONNECT_CONFIGURE_FAIL.getValue(),
                    SystemCode.SYSTEM_RUN_CONNECT_CONFIGURE_FAIL.getText());
        }
    }
 
    /**
     * 开发库的模块功能树
     * @param request
     * @return
     */
    @RequestMapping(value = "/get-synctree/{version}", method = RequestMethod.POST)
    @ApiVersion(1)
    public String getSyncTree(HttpServletRequest request) {
        try {
            // 获取参数
            FieldSetEntity fse = null;
            Object bean = request.getAttribute(CoreConst.API_POST_REQUEST_DATA);
            if (bean != null) {
                RequestParameterEntity reqp = (RequestParameterEntity) bean;
                fse = reqp.getFormData();
            }
            // 判断参数是否为空
            if (bean == null || fse == null) {
                SpringMVCContextHolder.getSystemLogger().error(SystemCode.SYSTEM_FORM_NODATA.getValue(),
                        SystemCode.SYSTEM_FORM_NODATA.getText());
                return this.error(SystemCode.SYSTEM_FORM_NODATA.getValue(), SystemCode.SYSTEM_FORM_NODATA.getText());
            }
            // 判断表名是否正常
            if (!CmnConst.PRODUCT_SYS_FUNCTIONS.equals(fse.getTableName())) {
                SpringMVCContextHolder.getSystemLogger().error(SystemCode.SYSTEM_TABLE_NODATA.getValue(),
                        SystemCode.SYSTEM_TABLE_NODATA.getText());
                return this.error(SystemCode.SYSTEM_TABLE_NODATA.getValue(), SystemCode.SYSTEM_TABLE_NODATA.getText());
            }
            DataTableEntity dt  = functionSynchrService.getSyncTree(fse);
            return BaseUtil.success(BaseUtil.dataTableToTreeData(dt,"tricode","tricode_parent",null,true),null);
        } catch (BaseException e) {
            e.printStackTrace();
            SpringMVCContextHolder.getSystemLogger().error(e);
            return this.error(e);
        } catch (Exception e) {
            e.printStackTrace();
            SpringMVCContextHolder.getSystemLogger().error(e);
            return this.error(SystemCode.GET_SYNC_DATA_SOURCE_FAIL.getValue(),
                    SystemCode.GET_SYNC_DATA_SOURCE_FAIL.getText());
        }
    }
 
    /**
     * 当前库的模块功能树
     * @param request
     * @return
     */
    @RequestMapping(value = "/get-nowtree/{version}", method = RequestMethod.POST)
    @ApiVersion(1)
    public String getNowTree(HttpServletRequest request) {
        try {
            // 获取参数
            FieldSetEntity fse = null;
            Object bean = request.getAttribute(CoreConst.API_POST_REQUEST_DATA);
            if (bean != null) {
                RequestParameterEntity reqp = (RequestParameterEntity) bean;
                fse = reqp.getFormData();
            }
            // 判断参数是否为空
            if (bean == null || fse == null) {
                SpringMVCContextHolder.getSystemLogger().error(SystemCode.SYSTEM_FORM_NODATA.getValue(),
                        SystemCode.SYSTEM_FORM_NODATA.getText());
                return this.error(SystemCode.SYSTEM_FORM_NODATA.getValue(), SystemCode.SYSTEM_FORM_NODATA.getText());
            }
            // 判断表名是否正常
            if (!CmnConst.PRODUCT_SYS_FUNCTIONS.equals(fse.getTableName())) {
                SpringMVCContextHolder.getSystemLogger().error(SystemCode.SYSTEM_TABLE_NODATA.getValue(),
                        SystemCode.SYSTEM_TABLE_NODATA.getText());
                return this.error(SystemCode.SYSTEM_TABLE_NODATA.getValue(), SystemCode.SYSTEM_TABLE_NODATA.getText());
            }
            DataTableEntity dt  = functionSynchrService.getNowTree(fse);
            return BaseUtil.success(BaseUtil.dataTableToTreeData(dt,"tricode","tricode_parent",null,true),null);
        } catch (BaseException e) {
            e.printStackTrace();
            SpringMVCContextHolder.getSystemLogger().error(e);
            return this.error(e);
        } catch (Exception e) {
            e.printStackTrace();
            SpringMVCContextHolder.getSystemLogger().error(e);
            return this.error(SystemCode.GET_SYNC_DATA_SOURCE_FAIL.getValue(),
                    SystemCode.GET_SYNC_DATA_SOURCE_FAIL.getText());
        }
    }
 
    /**
     * 功能同步
     * @param request
     * @return
     */
    @RequestMapping(value = "/sync-function/{version}", method = RequestMethod.POST)
    @ApiVersion(1)
    public String syncFuntion(HttpServletRequest request) {
        try {
            // 获取参数
            FieldSetEntity fse = null;
            Object bean = request.getAttribute(CoreConst.API_POST_REQUEST_DATA);
            if (bean != null) {
                RequestParameterEntity reqp = (RequestParameterEntity) bean;
                fse = reqp.getFormData();
            }
            // 判断参数是否为空
            if (bean == null || fse == null) {
                SpringMVCContextHolder.getSystemLogger().error(SystemCode.SYSTEM_FORM_NODATA.getValue(),
                        SystemCode.SYSTEM_FORM_NODATA.getText());
                return this.error(SystemCode.SYSTEM_FORM_NODATA.getValue(), SystemCode.SYSTEM_FORM_NODATA.getText());
            }
            // 判断表名是否正常
            if (!CmnConst.PRODUCT_SYS_FUNCTIONS.equals(fse.getTableName())) {
                SpringMVCContextHolder.getSystemLogger().error(SystemCode.SYSTEM_TABLE_NODATA.getValue(),
                        SystemCode.SYSTEM_TABLE_NODATA.getText());
                return this.error(SystemCode.SYSTEM_TABLE_NODATA.getValue(), SystemCode.SYSTEM_TABLE_NODATA.getText());
            }
            //同步前必须修.PRODUCT_SYS_products.PRODUCT_SYS_modules.PRODUCT_SYS_functions 的tricode字段类型
            if (!functionSynchrService.verificationCode()) {
                SpringMVCContextHolder.getSystemLogger().error(SystemCode.SYNC_FUNCTION_DATA_CODE_TYPE_ERR.getValue(),
                        SystemCode.SYNC_FUNCTION_DATA_CODE_TYPE_ERR.getText());
                return this.error(SystemCode.SYNC_FUNCTION_DATA_CODE_TYPE_ERR.getValue(), SystemCode.SYNC_FUNCTION_DATA_CODE_TYPE_ERR.getText());
            }
            IFunctionSynchrService service = (IFunctionSynchrService)getProxyInstance(functionSynchrService);
 
            service.syncFuntion(fse);
            return OK();
        } catch (BaseException e) {
            e.printStackTrace();
            SpringMVCContextHolder.getSystemLogger().error(e);
            return this.error(e);
        } catch (Exception e) {
            e.printStackTrace();
            SpringMVCContextHolder.getSystemLogger().error(e);
            return this.error(SystemCode.SYNC_FUNCTION_DATA_SOURCE_FAIL.getValue(),
                    SystemCode.SYNC_FUNCTION_DATA_SOURCE_FAIL.getText());
        }
    }
 
 
 
}