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());
|
}
|
}
|
|
|
|
}
|