Commit 453e3c60 authored by 赵啸非's avatar 赵啸非

添加实例查询

parent 85ff6d65
...@@ -18,37 +18,32 @@ public abstract class BaseReq implements Serializable { ...@@ -18,37 +18,32 @@ public abstract class BaseReq implements Serializable {
private Integer size; private Integer size;
/** /**
* 工号 * db地址,默认127.0.0.1
*/ */
private String workNum; private String dbHost;
/** /**
* 标题 * db端口,默认3306
*/ */
private String title; private String dbPort;
/** /**
* 扣分时间 * db名称
*/ */
private Date happenTime; private String dbName;
/** /**
* 规则编码 * db 用户名
*/ */
private String ruleCode; private String userName;
private Long ruleId;
private String phone;
/** /**
* 类型 * db 密码
*/ */
private String performType; private String password;
private Long staffId; private Long id;
} }
...@@ -10,33 +10,12 @@ public class DbSetupEntity extends BaseReq { ...@@ -10,33 +10,12 @@ public class DbSetupEntity extends BaseReq {
*/ */
private String dbFilePath; private String dbFilePath;
/**
* db地址,默认127.0.0.1
*/
private String dbHost;
/**
* db端口,默认3306
*/
private String dbPort;
/**
* db名称
*/
private String dbName;
/** /**
* db驱动 * db驱动
*/ */
private Long driverClassName; private Long driverClassName;
/**
* db 用户名
*/
private String userName;
/**
* db 密码
*/
private String password;
} }
\ No newline at end of file
package com.mortals.xhx.module.setup.mode;
import com.mortals.framework.model.BaseEntityLong;
import lombok.Data;
import java.util.Date;
/**
* 站点实体对象
*
* @author zxfei
* @date 2023-05-07
*/
@Data
public class SiteEntity extends BaseReq {
/**
* 站点名称
*/
private String siteName;
/**
* 站点编号
*/
private String siteCode;
/**
* 区域Id
*/
private String areaID;
/**
* 区域编号
*/
private String areaCode;
/**
* 区域名称
*/
private String areaName;
/**
* 省编码
*/
private String proCode;
/**
* 市编码
*/
private String cityCode;
/**
* 区编码
*/
private String districtCode;
/**
* 站点服务器ip
*/
private String siteIp;
/**
* 站点服务器端口
*/
private String sitePort;
/**
* 经度
*/
private String longitude;
/**
* 纬度
*/
private String latitude;
/**
* 中心联系电话
*/
private String siteTel;
/**
* 中心详细地址
*/
private String detailAddress;
/**
* 中心介绍
*/
private String siteRemark;
/**
* 上午上班开始时间
*/
private Date amWorkStartTime;
/**
* 上午上班结束时间
*/
private Date amWorkEndTime;
/**
* 下午上班开始时间
*/
private Date pmWorkStartTime;
/**
* 下午上班结束时间
*/
private Date pmWorkEndTime;
/**
* 周一 (1.上班,0.不上)
*/
private Integer workday1;
/**
* 周二 (1.上班,0.不上)
*/
private Integer workday2;
/**
* 周三 (1.上班,0.不上)
*/
private Integer workday3;
/**
* 周四 (1.上班,0.不上)
*/
private Integer workday4;
/**
* 周五 (1.上班,0.不上)
*/
private Integer workday5;
/**
* 周六 (1.上班,0.不上)
*/
private Integer workday6;
/**
* 周日 (1.上班,0.不上)
*/
private Integer workday7;
/**
* 在线取号(0.否,1.是)
*/
private Integer onlineTake;
/**
* 在线取号(0.否,1.是)
*/
private Integer appointment;
/**
* 在线取号(0.否,1.是)
*/
private Integer gowMap;
/**
* 楼层
*/
private Integer level;
/**
* 楼栋
*/
private Integer building;
/**
* logo图片地址
*/
private String logoPath;
/**
* 英文名称
*/
private String englishName;
/**
* 负责人
*/
private String leadingOfficial;
/**
* 联系电话
*/
private String leadingOfficialTelephone;
/**
* 部署模块,逗号分隔
*/
private String modelIds;
}
\ No newline at end of file
...@@ -5,6 +5,8 @@ import com.mortals.xhx.module.setup.mode.DbSetupEntity; ...@@ -5,6 +5,8 @@ import com.mortals.xhx.module.setup.mode.DbSetupEntity;
import org.aspectj.weaver.ast.Var; import org.aspectj.weaver.ast.Var;
import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestBody;
import javax.sql.DataSource;
/** /**
* 资源部署 * 资源部署
* *
...@@ -14,16 +16,22 @@ import org.springframework.web.bind.annotation.RequestBody; ...@@ -14,16 +16,22 @@ import org.springframework.web.bind.annotation.RequestBody;
public interface SetupDbService { public interface SetupDbService {
/** /**
* 初始化db * 初始化db
*
* @param dbSetupEntity * @param dbSetupEntity
* @return * @return
*/ */
Rest<String> initDb( DbSetupEntity dbSetupEntity); Rest<String> initDb(DbSetupEntity dbSetupEntity);
/** /**
* 测试数据库连接 * 测试数据库连接
*
* @param dbSetupEntity * @param dbSetupEntity
* @return * @return
*/ */
Rest<String> connect(DbSetupEntity dbSetupEntity); Rest<String> connect(DbSetupEntity dbSetupEntity);
Rest<DataSource> getDataSource(DbSetupEntity dbSetupEntity);
} }
\ No newline at end of file
package com.mortals.xhx.module.setup.service; package com.mortals.xhx.module.setup.service;
import com.mortals.framework.common.Rest; import com.mortals.framework.common.Rest;
import com.mortals.xhx.module.setup.mode.DbSetupEntity;
import com.mortals.xhx.module.setup.mode.ProjectSetupEntity; import com.mortals.xhx.module.setup.mode.ProjectSetupEntity;
import com.mortals.xhx.module.setup.mode.SiteEntity;
import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestBody;
/** /**
...@@ -19,4 +21,13 @@ public interface SetupProjectService { ...@@ -19,4 +21,13 @@ public interface SetupProjectService {
*/ */
Rest<Void> distribute(ProjectSetupEntity projectSetupEntity); Rest<Void> distribute(ProjectSetupEntity projectSetupEntity);
/**
* 修改站点信息
* @param siteEntity
* @return
*/
Rest<String> updateBaseSystem(SiteEntity siteEntity);
} }
\ No newline at end of file
...@@ -19,6 +19,7 @@ import org.springframework.core.io.support.EncodedResource; ...@@ -19,6 +19,7 @@ import org.springframework.core.io.support.EncodedResource;
import org.springframework.jdbc.datasource.init.ScriptUtils; import org.springframework.jdbc.datasource.init.ScriptUtils;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import javax.sql.DataSource;
import java.sql.Connection; import java.sql.Connection;
import java.sql.ResultSet; import java.sql.ResultSet;
import java.sql.SQLException; import java.sql.SQLException;
...@@ -69,16 +70,6 @@ public class SetupDbServiceImpl implements SetupDbService { ...@@ -69,16 +70,6 @@ public class SetupDbServiceImpl implements SetupDbService {
SimpleDataSource simpleDataSource = new SimpleDataSource("jdbc:mysql://" + dbSetupEntity.getDbHost() + ":" + dbSetupEntity.getDbPort() + "?useUnicode=true&characterEncoding=utf8&useSSL=false&serverTimezone=Hongkong" SimpleDataSource simpleDataSource = new SimpleDataSource("jdbc:mysql://" + dbSetupEntity.getDbHost() + ":" + dbSetupEntity.getDbPort() + "?useUnicode=true&characterEncoding=utf8&useSSL=false&serverTimezone=Hongkong"
, dbSetupEntity.getUserName(), dbSetupEntity.getPassword(), "com.mysql.cj.jdbc.Driver"); , dbSetupEntity.getUserName(), dbSetupEntity.getPassword(), "com.mysql.cj.jdbc.Driver");
//判断数据库是否已经存在 如果不存在 则链接默认库mysql 再初始化创建库
DruidDataSource druidDataSource = new DruidDataSource();
druidDataSource.setUrl("jdbc:mysql://" + dbSetupEntity.getDbHost() + ":" + dbSetupEntity.getDbPort() + "?useUnicode=true&characterEncoding=utf8&useSSL=false&serverTimezone=Hongkong");
druidDataSource.setDriverClassName("com.mysql.cj.jdbc.Driver");
druidDataSource.setUsername(dbSetupEntity.getUserName());
druidDataSource.setPassword(dbSetupEntity.getPassword());
//druidDataSource.setConnectionErrorRetryAttempts(3); // 失败后重连的次数
druidDataSource.setBreakAfterAcquireFailure(true);
Connection connection = simpleDataSource.getConnection(); Connection connection = simpleDataSource.getConnection();
boolean databaseExists = databaseExists(connection, dbSetupEntity.getDbName()); boolean databaseExists = databaseExists(connection, dbSetupEntity.getDbName());
...@@ -98,6 +89,19 @@ public class SetupDbServiceImpl implements SetupDbService { ...@@ -98,6 +89,19 @@ public class SetupDbServiceImpl implements SetupDbService {
} }
} }
@Override
public Rest<DataSource> getDataSource(DbSetupEntity dbSetupEntity) {
try {
SimpleDataSource simpleDataSource = new SimpleDataSource("jdbc:mysql://" + dbSetupEntity.getDbHost() + ":" + dbSetupEntity.getDbPort() + "?useUnicode=true&characterEncoding=utf8&useSSL=false&serverTimezone=Hongkong"
, dbSetupEntity.getUserName(), dbSetupEntity.getPassword(), "com.mysql.cj.jdbc.Driver");
return Rest.ok(simpleDataSource);
} catch (Exception e) {
log.error("链接数据库异常", e);
return Rest.fail(e.getMessage());
}
}
//创建数据库 //创建数据库
private boolean createDatabase(Connection conn, String dbName) throws SQLException { private boolean createDatabase(Connection conn, String dbName) throws SQLException {
......
package com.mortals.xhx.module.setup.service.impl; package com.mortals.xhx.module.setup.service.impl;
import cn.hutool.db.DbUtil;
import com.mortals.framework.common.Rest; import com.mortals.framework.common.Rest;
import com.mortals.framework.exception.AppException;
import com.mortals.xhx.common.code.ProductDisEnum; import com.mortals.xhx.common.code.ProductDisEnum;
import com.mortals.xhx.common.code.YesNoEnum;
import com.mortals.xhx.common.utils.ZipUtils; import com.mortals.xhx.common.utils.ZipUtils;
import com.mortals.xhx.module.setup.mode.DbSetupEntity;
import com.mortals.xhx.module.setup.mode.ProjectSetupEntity; import com.mortals.xhx.module.setup.mode.ProjectSetupEntity;
import com.mortals.xhx.module.setup.mode.SiteEntity;
import com.mortals.xhx.module.setup.service.SetupDbService;
import com.mortals.xhx.module.setup.service.SetupProjectService; import com.mortals.xhx.module.setup.service.SetupProjectService;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.checkerframework.checker.units.qual.A;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import javax.sql.DataSource;
import java.io.InputStream; import java.io.InputStream;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
@Service("SetupProjectService") @Service("SetupProjectService")
@Slf4j @Slf4j
...@@ -18,6 +33,9 @@ public class SetupProjectServiceImpl implements SetupProjectService { ...@@ -18,6 +33,9 @@ public class SetupProjectServiceImpl implements SetupProjectService {
@Value("${project.publishPath}") @Value("${project.publishPath}")
private String publishPath; private String publishPath;
@Autowired
private SetupDbService setupDbService;
@Override @Override
public Rest<Void> distribute(ProjectSetupEntity projectSetupEntity) { public Rest<Void> distribute(ProjectSetupEntity projectSetupEntity) {
...@@ -28,4 +46,78 @@ public class SetupProjectServiceImpl implements SetupProjectService { ...@@ -28,4 +46,78 @@ public class SetupProjectServiceImpl implements SetupProjectService {
return Rest.ok(); return Rest.ok();
} }
@Override
public Rest<String> updateBaseSystem(SiteEntity siteEntity) {
//获取数据库连接 如果基础服务不存在 则提示
DbSetupEntity dbSetupEntity = new DbSetupEntity();
dbSetupEntity.setDbName(siteEntity.getDbName());
dbSetupEntity.setDbHost(siteEntity.getDbHost());
dbSetupEntity.setDbPort(siteEntity.getDbPort());
dbSetupEntity.setUserName(siteEntity.getUserName());
dbSetupEntity.setPassword(siteEntity.getPassword());
Rest<String> connect = setupDbService.connect(dbSetupEntity);
if (YesNoEnum.YES.getValue() != connect.getCode()) {
return Rest.fail("数据库连接失败");
}
Rest<DataSource> rest = setupDbService.getDataSource(dbSetupEntity);
DataSource dataSource = rest.getData();
Connection connection = null;
try {
connection = dataSource.getConnection();
//updateSite(connection, dbSetupEntity.getSiteEntity()
} catch (SQLException e) {
throw new RuntimeException(e.getMessage());
}
return null;
}
public boolean updateSite(Connection connection, SiteEntity site) throws AppException {
PreparedStatement statement = null;
ResultSet resultSet = null;
try {
// 构建Sql,参数使用占位符代替
// 手动拼接SQL
String sql = "update mortals_sys_site set ";
List<Object> paramList = new ArrayList<Object>();
//如果某个属性为null,则跳过,不更新此字段
if (site.getSiteName() != null) {
sql += "siteName = ?,";
paramList.add(site.getSiteName());
}
// 去除多余的逗号
sql = sql.substring(0, sql.length() - 1);
sql += " where id = ?";
// 添加id到参数列表中
paramList.add(site.getId());
// 创建PreparedStatement对象
statement = connection.prepareStatement(sql);
// 设置sql中占位符对应的值
for (int i = 0; i < paramList.size(); i++) {
statement.setObject(i + 1, paramList.get(i));
}
int result = statement.executeUpdate();
// 如果影响的行数大于0,表示此用户更新成功
if (result > 0) {
return true;
}
} catch (Exception e) {
log.error("更新站点信息失败", e);
throw new AppException(e.getMessage());
} finally {
DbUtil.close(resultSet, statement, connection);
}
return false;
}
} }
\ No newline at end of file
...@@ -15,6 +15,7 @@ import com.mortals.xhx.common.utils.EncodeUtil; ...@@ -15,6 +15,7 @@ import com.mortals.xhx.common.utils.EncodeUtil;
import com.mortals.xhx.common.utils.ZipUtils; import com.mortals.xhx.common.utils.ZipUtils;
import com.mortals.xhx.module.setup.mode.ProjectSetupEntity; import com.mortals.xhx.module.setup.mode.ProjectSetupEntity;
import com.mortals.xhx.module.setup.mode.ResourceSetupEntity; import com.mortals.xhx.module.setup.mode.ResourceSetupEntity;
import com.mortals.xhx.module.setup.mode.SiteEntity;
import com.mortals.xhx.module.setup.service.SetupProjectService; import com.mortals.xhx.module.setup.service.SetupProjectService;
import lombok.Getter; import lombok.Getter;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
...@@ -125,6 +126,35 @@ public class SetupProjectController { ...@@ -125,6 +126,35 @@ public class SetupProjectController {
return ret.toJSONString(); return ret.toJSONString();
} }
/**
* 服务列表查询
*
* @param projectSetupEntity
* @return
*/
@PostMapping("/update/site")
@UnAuth
public String updateSite(@RequestBody SiteEntity siteEntity) {
JSONObject ret = new JSONObject();
int code = VALUE_RESULT_SUCCESS;
try {
// curl -X GET 'http://127.0.0.1:8848/nacos/v1/ns/catalog/services?pageNo=1&pageSize=100&namespaceId=smart-gov'
String resp = HttpUtil.get(nacosUrl + "/v1/ns/catalog/services?pageNo=1&pageSize=100&namespaceId=smart-gov");
ret.put(KEY_RESULT_DATA, resp);
ret.put(KEY_RESULT_MSG, "项目资源部署成功");
} catch (Exception e) {
code = VALUE_RESULT_FAILURE;
log.error("查询服务状态失败", e);
ret.put(KEY_RESULT_MSG, e.getMessage());
}
ret.put(KEY_RESULT_CODE, code);
return ret.toJSONString();
}
/** /**
* 服务列表查询 * 服务列表查询
* *
......
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