查询表字段测试
This commit is contained in:
parent
d8f9e86248
commit
b4a1915aaf
|
|
@ -1,7 +1,9 @@
|
|||
package com.weaver.seconddev.jcl.organization.controller;
|
||||
|
||||
import com.weaver.common.authority.annotation.WeaPermission;
|
||||
import com.weaver.ebuilder.form.client.entity.field.ModuleField;
|
||||
import com.weaver.seconddev.jcl.organization.service.EmployeeRelationService;
|
||||
import org.apache.commons.collections.CollectionUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
|
@ -12,6 +14,7 @@ import org.springframework.web.bind.annotation.RestController;
|
|||
import javax.ws.rs.Produces;
|
||||
import javax.ws.rs.core.MediaType;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@RestController
|
||||
|
|
@ -74,4 +77,53 @@ public class EmployeeRelationController {
|
|||
return actionMap;
|
||||
}
|
||||
|
||||
/**
|
||||
* 员工管理-查询表全部字段
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("/getTableColumns")
|
||||
@WeaPermission(publicPermission = true)
|
||||
public Map<String, Object> getTableColumns(
|
||||
@RequestParam("tableSchema") String tableSchema,
|
||||
@RequestParam("tableName") String tableName){
|
||||
Map<String, Object> actionMap = new HashMap<>();
|
||||
// 根据表名查询所有字段
|
||||
List<Map<String, Object>> mapList = employeeRelationService.getTableColumnsOfTableName(tableSchema,tableName);
|
||||
if(CollectionUtils.isNotEmpty(mapList)){
|
||||
log.error("getTableColumns.mapList:{}", mapList);
|
||||
actionMap.put("code","200");
|
||||
actionMap.put("msg","接口调用成功!");
|
||||
}else{
|
||||
actionMap.put("code","201");
|
||||
actionMap.put("msg","返回数据为空!");
|
||||
}
|
||||
actionMap.put("mapList",mapList);
|
||||
log.error("getTableColumns.actionMap:{}", actionMap);
|
||||
return actionMap;
|
||||
}
|
||||
|
||||
/**
|
||||
* 员工管理-查询表全部字段(系统方法)
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("/getTableColumnsBySys")
|
||||
@WeaPermission(publicPermission = true)
|
||||
public Map<String, Object> getTableColumnsBySys(
|
||||
@RequestParam("tableName") String tableName){
|
||||
Map<String, Object> actionMap = new HashMap<>();
|
||||
// 根据表名查询所有字段
|
||||
List<ModuleField> tableColumns = employeeRelationService.getTableColumns(tableName);
|
||||
if(CollectionUtils.isNotEmpty(tableColumns)){
|
||||
log.error("getTableColumnsBySys.tableColumns:{}", tableColumns);
|
||||
actionMap.put("code","200");
|
||||
actionMap.put("msg","接口调用成功!");
|
||||
}else{
|
||||
actionMap.put("code","201");
|
||||
actionMap.put("msg","返回数据为空!");
|
||||
}
|
||||
actionMap.put("tableColumns",tableColumns);
|
||||
log.error("getTableColumnsBySys.actionMap:{}", actionMap);
|
||||
return actionMap;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,5 +1,7 @@
|
|||
package com.weaver.seconddev.jcl.organization.service;
|
||||
|
||||
import com.weaver.ebuilder.form.client.entity.field.ModuleField;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
|
|
@ -8,4 +10,8 @@ public interface EmployeeRelationService {
|
|||
boolean checkIsNotBlackList(String userName,String mobile,String email,String identity);
|
||||
|
||||
void updateLeaderDaInfo(Map<String, Object> map);
|
||||
|
||||
List<Map<String, Object>> getTableColumnsOfTableName(String tableSchema,String tableName);
|
||||
|
||||
List<ModuleField> getTableColumns(String tableName);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,12 @@
|
|||
package com.weaver.seconddev.jcl.organization.service.impl;
|
||||
|
||||
import com.alibaba.nacos.common.utils.CollectionUtils;
|
||||
import com.weaver.ebuilder.datasource.api.conn.RecordDataSource;
|
||||
import com.weaver.ebuilder.datasource.api.conn.WeaverConnection;
|
||||
import com.weaver.ebuilder.form.client.entity.field.FieldsQueryDto;
|
||||
import com.weaver.ebuilder.form.client.entity.field.ModuleField;
|
||||
import com.weaver.ebuilder.form.client.service.emobile.IEtFormDatasetService;
|
||||
import com.weaver.ebuilder.teams.etform.org.bean.EBSimpleEmployee;
|
||||
import com.weaver.seconddev.jcl.organization.controller.EmployeeRelationController;
|
||||
import com.weaver.seconddev.jcl.organization.service.EmployeeRelationService;
|
||||
import com.weaver.seconddev.jcl.organization.util.DatabaseUtils;
|
||||
|
|
@ -10,6 +16,9 @@ import org.slf4j.LoggerFactory;
|
|||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.sql.CallableStatement;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Types;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
|
|
@ -20,31 +29,32 @@ public class EmployeeRelationServiceImpl implements EmployeeRelationService {
|
|||
|
||||
@Autowired
|
||||
private DatabaseUtils databaseUtils;
|
||||
@Autowired
|
||||
private IEtFormDatasetService etFormDataSetService;
|
||||
|
||||
|
||||
@Override
|
||||
public boolean checkIsNotBlackList(String userName, String mobile, String email, String identity) {
|
||||
boolean flag =false;
|
||||
String sql="";
|
||||
if(StringUtils.isNotBlank(identity)){
|
||||
sql="select id from uf_jcl_ryhmd where zjhm = '" + identity + "' and IS_DELETE = 0 and delete_type = 0 and TENANT_KEY = 't7n9jpeaoa' " ;
|
||||
log.error("queryLeaderPdByYear.sql:{}",sql);
|
||||
}else{
|
||||
if(StringUtils.isNotBlank(userName)){
|
||||
if(StringUtils.isNotBlank(mobile)){
|
||||
sql="select id from uf_jcl_ryhmd where xm = '" + userName + "' and lxdh = '" + mobile + "' and IS_DELETE = 0 and delete_type = 0 and TENANT_KEY = 't7n9jpeaoa' " ;
|
||||
log.error("queryLeaderPdByYear.sql:{}",sql);
|
||||
}else {
|
||||
sql="select id from uf_jcl_ryhmd where xm = '" + userName + "' and yx = '" + email + "' and IS_DELETE = 0 and delete_type = 0 and TENANT_KEY = 't7n9jpeaoa' " ;
|
||||
log.error("queryLeaderPdByYear.sql:{}",sql);
|
||||
boolean flag = false;
|
||||
String sql = "";
|
||||
if (StringUtils.isNotBlank(identity)) {
|
||||
sql = "select id from uf_jcl_ryhmd where zjhm = '" + identity + "' and IS_DELETE = 0 and delete_type = 0 and TENANT_KEY = 't7n9jpeaoa' ";
|
||||
log.error("queryLeaderPdByYear.sql:{}", sql);
|
||||
} else {
|
||||
if (StringUtils.isNotBlank(userName)) {
|
||||
if (StringUtils.isNotBlank(mobile)) {
|
||||
sql = "select id from uf_jcl_ryhmd where xm = '" + userName + "' and lxdh = '" + mobile + "' and IS_DELETE = 0 and delete_type = 0 and TENANT_KEY = 't7n9jpeaoa' ";
|
||||
log.error("queryLeaderPdByYear.sql:{}", sql);
|
||||
} else {
|
||||
sql = "select id from uf_jcl_ryhmd where xm = '" + userName + "' and yx = '" + email + "' and IS_DELETE = 0 and delete_type = 0 and TENANT_KEY = 't7n9jpeaoa' ";
|
||||
log.error("queryLeaderPdByYear.sql:{}", sql);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Map<String, Object> rs = databaseUtils.execute("LOGIC", "weaver-ebuilder-form-service", sql);
|
||||
List<Map<String, Object>> recordList = databaseUtils.getDataSourceList(rs);
|
||||
log.error("queryLeaderPdByYear.recordList:{}",recordList);
|
||||
if(CollectionUtils.isNotEmpty(recordList)){
|
||||
log.error("queryLeaderPdByYear.recordList:{}", recordList);
|
||||
if (CollectionUtils.isNotEmpty(recordList)) {
|
||||
flag = true;
|
||||
}
|
||||
return flag;
|
||||
|
|
@ -56,10 +66,66 @@ public class EmployeeRelationServiceImpl implements EmployeeRelationService {
|
|||
String xm = String.valueOf(map.get("xm"));
|
||||
String df = String.valueOf(map.get("df"));
|
||||
String dj = String.valueOf(map.get("dj"));
|
||||
log.error("updateLeaderDaInfo.map:{}",map);
|
||||
String sql="update uf_jcl_gbkhba set ndzhjxkhdf = '" + df + "',ndzhjxkhdj ='" + dj + "' where nd = '" + khny.substring(0, 4) + "' and bkhr = '" + xm + "' ";
|
||||
log.error("updateLeaderDaInfo.sql:{}",sql);
|
||||
log.error("updateLeaderDaInfo.map:{}", map);
|
||||
String sql = "update uf_jcl_gbkhba set ndzhjxkhdf = '" + df + "',ndzhjxkhdj ='" + dj + "' where nd = '" + khny.substring(0, 4) + "' and bkhr = '" + xm + "' ";
|
||||
log.error("updateLeaderDaInfo.sql:{}", sql);
|
||||
Map<String, Object> rs = databaseUtils.execute("LOGIC", "weaver-ebuilder-form-service", sql);
|
||||
log.error("updateEmployeeDjInfo.rs:{}",rs);
|
||||
log.error("updateEmployeeDjInfo.rs:{}", rs);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Map<String, Object>> getTableColumnsOfTableName(String tableSchema,String tableName) {
|
||||
String sql = "SELECT COLUMN_NAME FROM INFORMATION_SCHEMA.COLUMNS\n" +
|
||||
"WHERE TABLE_SCHEMA = '" + tableSchema + "' AND TABLE_NAME = '" + tableName + "' ";
|
||||
log.error("getTableColumnsOfTableName.sql:{}", sql);
|
||||
Map<String, Object> rs = databaseUtils.execute("LOGIC", "weaver-ebuilder-form-service", sql);
|
||||
List<Map<String, Object>> recordList = databaseUtils.getDataSourceList(rs);
|
||||
log.error("getTableColumnsOfTableName.recordList:{}", recordList);
|
||||
return recordList;
|
||||
}
|
||||
@Override
|
||||
public List<ModuleField> getTableColumns(String tableName) {
|
||||
//todo (500报错)
|
||||
Long aLong = Long.valueOf(tableName);
|
||||
FieldsQueryDto fieldsQueryDto = new FieldsQueryDto();
|
||||
fieldsQueryDto.setObjId(aLong);
|
||||
EBSimpleEmployee employee = new EBSimpleEmployee();
|
||||
employee.setEmployeeId("1081920975146483713");
|
||||
employee.setTenantKey("t7n9jpeaoa");
|
||||
fieldsQueryDto.setEbSimpleEmployee(employee);
|
||||
List<ModuleField> fields = etFormDataSetService.getFields(fieldsQueryDto);
|
||||
log.error("getTableColumns.fields:{}", fields);
|
||||
return fields;
|
||||
}
|
||||
|
||||
|
||||
private void GetTableAlterStatements() {
|
||||
//1.获取连接池实例
|
||||
com.weaver.ebuilder.datasource.api.conn.ConnectionPool pool = com.weaver.ebuilder.datasource.api.conn.ConnectionPool.getInstanse();
|
||||
log.error("GetTableAlterStatements.pool:{}", pool);
|
||||
//2.从连接池获取WeaverConnection对象
|
||||
WeaverConnection conn = pool.getConnection(3L);
|
||||
log.error("GetTableAlterStatements.conn:{}", conn);
|
||||
String dbtype = pool.getDbtype();
|
||||
log.error("GetTableAlterStatements.dbtype:{}", dbtype);
|
||||
try {
|
||||
//3.调用存储过程(需声明两个OUT参数:flag和msg)
|
||||
CallableStatement cstmt = conn.prepareCall("{call存储过程名(?, ?, ?, ?, ?)}");
|
||||
log.error("GetTableAlterStatements.cstmt:{}", cstmt);
|
||||
//输入参数设置 cstmt.setString(1, "参数值");
|
||||
cstmt.registerOutParameter(2, Types.INTEGER); // flag OUT cstmt.registerOutParameter(3, Types.VARCHAR); // msg OUT //执行存储过程 cstmt.execute();
|
||||
//获取输出参数 int flag = cstmt.getInt(2);
|
||||
String msg = cstmt.getString(3);
|
||||
if("mysql".equals(dbtype)){
|
||||
//.....
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error("存储过程调用异常", e);
|
||||
} finally {
|
||||
//4.释放连接(必须显式释放)
|
||||
if (conn != null) {
|
||||
pool.releaseConnection(3L, conn); //归还到连接池 }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue