Commit ce676dd9 authored by Code-KingTT's avatar Code-KingTT

Merge remote-tracking branch 'origin/develop' into develop

parents 90bb8068 245a5681
......@@ -35,7 +35,7 @@ public class ApiInfoResource {
@TycloudOperation(ApiLevel = UserType.AGENCY,needAuth = false)
@PostMapping(value = "/save")
@ApiOperation(httpMethod = "POST", value = "新增", notes = "新增")
public ResponseModel<ApiInfoModel> save(@RequestBody ApiInfoModel apiInfoModel) throws Exception {
public ResponseModel<ApiInfoModel> save(@RequestBody ApiInfoModel apiInfoModel) {
apiInfoModel = apiInfoService.createWithModel(apiInfoModel);
return ResponseHelper.buildResponse(apiInfoModel);
}
......
......@@ -125,8 +125,8 @@ public class DataBaseLinkResource {
@TycloudOperation(ApiLevel = UserType.AGENCY, needAuth = false)
@GetMapping(value = "/agency/list")
@ApiOperation(httpMethod = "GET", value = "机构列表查询", notes = "列表查询")
public ResponseModel<List<AgencyModel>> queryForList(HttpServletRequest request) throws SQLException, IOException {
return ResponseHelper.buildResponse(dataBaseLinkService.queryForAgencyList(request));
public ResponseModel<List<AgencyModel>> queryForList() throws SQLException, IOException {
return ResponseHelper.buildResponse(dataBaseLinkService.queryForAgencyList());
}
......
......@@ -8,6 +8,8 @@ import com.yeejoin.amos.api.tool.face.orm.dao.DataBaseLinkMapper;
import com.yeejoin.amos.api.tool.face.orm.entity.DataBaseLink;
import com.yeejoin.amos.api.tool.utils.AESUtils;
import com.yeejoin.amos.api.tool.utils.DataBaseUtils;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.typroject.tyboot.core.foundation.utils.Bean;
......@@ -15,6 +17,7 @@ import org.typroject.tyboot.core.foundation.utils.ValidationUtil;
import org.typroject.tyboot.core.rdbms.service.BaseService;
import javax.servlet.http.HttpServletRequest;
import javax.sql.DataSource;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
......@@ -32,8 +35,10 @@ import java.util.Map;
@Service
public class DataBaseLinkService extends BaseService<DataBaseLinkModel, DataBaseLink, DataBaseLinkMapper> {
private static final Logger log = LogManager.getLogger(DataBaseLinkService.class);
@Autowired
DataBaseLinkMapper dataBaseLinkMapper;
private DataSource dataSource;
/**
* 新增
*/
......@@ -89,14 +94,18 @@ public class DataBaseLinkService extends BaseService<DataBaseLinkModel, DataBase
/**
* 机构列表查询
*/
public List<AgencyModel> queryForAgencyList(HttpServletRequest request) throws SQLException, IOException {
// URL url = new URL(request.getRequestURL().toString());
DataBaseLink dataBaseLink = getOne(new QueryWrapper<DataBaseLink>().eq("IP",DataBaseUtils.getIp()));
public List<AgencyModel> queryForAgencyList() throws SQLException, IOException {
Connection con = dataSource.getConnection();
URL url = new URL
(con.getMetaData().getURL().replace("jdbc:mysql","http"));
con.close();
log.info(url);
DataBaseLink dataBaseLink = getOne(new QueryWrapper<DataBaseLink>().eq("IP",url.getHost()));
DataBaseLinkModel dataBaseLinkModel = new DataBaseLinkModel();
Bean.toModel(dataBaseLink,dataBaseLinkModel);
Connection connection = this.connectNewDatabase(dataBaseLinkModel);
List<Map<String, Object>> maps =
DataBaseUtils.getMaps("SELECT AGENCY_NAME, AGENCY_CODE, AGENCY_DESC FROM privilege_agency;", connection);
List<Map<String, Object>> maps = DataBaseUtils.getMaps
("SELECT AGENCY_NAME, AGENCY_CODE, AGENCY_DESC FROM privilege_agency;", connection);
connection.close();
List<AgencyModel> records = new ArrayList<>();
for (Map<String, Object> map : maps) {
......
......@@ -2,16 +2,15 @@ package com.yeejoin.amos.api.tool.utils;
import com.alibaba.fastjson.JSON;
import com.yeejoin.amos.api.tool.face.orm.entity.TableColumn;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.ObjectUtils;
import javax.servlet.http.HttpServletRequest;
import java.io.*;
import javax.sql.DataSource;
import java.net.Inet4Address;
import java.net.InetAddress;
import java.net.NetworkInterface;
import java.net.SocketException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.sql.*;
import java.util.*;
......@@ -151,40 +150,5 @@ public class DataBaseUtils {
return sql;
}
public static String getIp() throws IOException {
// InetAddress inetAddress = null;
// boolean isFind = false; // 返回标识
// Enumeration<NetworkInterface> networkInterfaceLists = null;
// try {
// // 获取网络接口
// networkInterfaceLists = (Enumeration<NetworkInterface>) NetworkInterface.getNetworkInterfaces();
// } catch (SocketException e) {
// e.printStackTrace();
// }
// while (networkInterfaceLists.hasMoreElements()) {
// NetworkInterface networkInterface = (NetworkInterface) networkInterfaceLists.nextElement();
// Enumeration<InetAddress> ips = networkInterface.getInetAddresses();
// // 遍历所有ip,获取本地地址中不是回环地址的ipv4地址
// while (ips.hasMoreElements()) {
// inetAddress = (InetAddress) ips.nextElement();
// if (inetAddress instanceof Inet4Address && inetAddress.isSiteLocalAddress()
// && !inetAddress.isLoopbackAddress()) {
// isFind = true;
// break;
// }
// }
// if (isFind) {
// break;
// }
// }
// return inetAddress == null ? "" : inetAddress.getHostAddress();
//获取jar包同级目录
String filePath = System.getProperty("user.dir") + "/config/application-dev.properties";
InputStream in = new BufferedInputStream(Files.newInputStream(Paths.get(filePath)));
Properties properties = new Properties();
properties.load(in);
//获取配置文件数据
return properties.getProperty("eureka.instance.hostname");
}
}
spring.application.name=AMOS-ATL
server.servlet.context-path=/atl
#server.servlet.context-path=/jcs
#server.port=30201
server.port=20000
server.port=30002
#server.port=20000
spring.profiles.active=dev
management.health.elasticsearch.enabled=false
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment