Commit e11b19a1 authored by 陈祥烨's avatar 陈祥烨

new

parent 35533eef
package com.yeejoin.amos.api.tool.controller;
import com.yeejoin.amos.api.tool.face.service.TransferDataService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.typroject.tyboot.core.foundation.enumeration.UserType;
import org.typroject.tyboot.core.restful.doc.TycloudOperation;
import org.typroject.tyboot.core.restful.utils.ResponseHelper;
import org.typroject.tyboot.core.restful.utils.ResponseModel;
import java.sql.SQLException;
@CrossOrigin
@RestController
@Api(tags = "数据迁移")
@RequestMapping(value = "/transfer_data")
public class TransferDataResource {
@Autowired
private TransferDataService transferDataService;
@TycloudOperation(ApiLevel = UserType.AGENCY, needAuth = false)
@PutMapping(value = "/relation/")
@ApiOperation(httpMethod = "Put", value = "数据迁移", notes = "数据迁移")
public ResponseModel<String> transferData( ) throws SQLException, ClassNotFoundException {
transferDataService.transferData();
return ResponseHelper.buildResponse("The data has been transferred !");
}
}
package com.yeejoin.amos.api.tool.face.service;
import com.alibaba.fastjson.JSONObject;
import com.yeejoin.amos.api.tool.enums.SourceEnum;
import com.yeejoin.amos.api.tool.face.model.DataBaseLinkModel;
import com.yeejoin.amos.api.tool.face.model.DataBaseNameListModel;
......@@ -9,14 +10,18 @@ import com.yeejoin.amos.api.tool.face.orm.dao.RelationMapper;
import com.yeejoin.amos.api.tool.face.orm.entity.Relation;
import com.yeejoin.amos.api.tool.face.orm.entity.TableColumn;
import com.yeejoin.amos.api.tool.utils.DataBaseUtils;
import com.yeejoin.amos.api.tool.utils.DateUtils;
import org.apache.commons.beanutils.ConvertUtils;
import org.apache.commons.lang3.time.DateFormatUtils;
import org.eclipse.paho.client.mqttv3.MqttException;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;
import org.typroject.tyboot.component.emq.EmqKeeper;
import org.typroject.tyboot.core.foundation.utils.StringUtil;
import org.typroject.tyboot.core.foundation.utils.ValidationUtil;
import org.typroject.tyboot.core.rdbms.service.BaseService;
import javax.servlet.http.HttpServletResponse;
......@@ -42,7 +47,8 @@ public class RelationService extends BaseService<RelationModel, Relation, Relati
JdbcTemplate jdbcTemplate;
@Autowired
private DataBaseNameListService dataBaseNameListService;
@Autowired
public EmqKeeper emqKeeper;
/**
* 根据机构删除
*/
......@@ -259,6 +265,22 @@ public class RelationService extends BaseService<RelationModel, Relation, Relati
}
}
public void print(String id, String msg, String step) {
String percent = "0";
percent = ValidationUtil.equals(step, "end") ? "100" : ValidationUtil.equals(step, "running") ? "50" : "10";
JSONObject event = new JSONObject();
event.put("percent", percent);
event.put("status", "running");
event.put("logInfo", msg);
event.put("time", DateUtils.toDateStr(DateUtils.format()));
try {
emqKeeper.getMqttClient().publish("/topicTable/solidify/" + (id.indexOf(',') != -1 ? id.split(",")[0] : id), event.toString().getBytes(), 0, false);
} catch (MqttException e) {
e.printStackTrace();
}
}
/**
* 导出插入语句
*/
......
......@@ -33,7 +33,6 @@ import java.util.Date;
import java.util.List;
import java.util.Map;
import static com.yeejoin.amos.api.tool.utils.DataBaseUtils.print;
/**
* <p>
......@@ -82,7 +81,8 @@ public class StudioResourceService extends BaseService<StudioResourceModel, Stud
@Autowired
private SqlHelper sqlHelper;
@Autowired
EmqKeeper emqKeeper;
/**
* 列表查询 示例
......@@ -176,6 +176,22 @@ public class StudioResourceService extends BaseService<StudioResourceModel, Stud
}
}
public void print(String id, String msg, String step) {
String percent = "0";
percent = ValidationUtil.equals(step, "end") ? "100" : ValidationUtil.equals(step, "running") ? "50" : "10";
JSONObject event = new JSONObject();
event.put("percent", percent);
event.put("status", "running");
event.put("logInfo", msg);
event.put("time", DateUtils.toDateStr(DateUtils.format()));
try {
emqKeeper.getMqttClient().publish("/topicTable/solidify/" + (id.indexOf(',') != -1 ? id.split(",")[0] : id), event.toString().getBytes(), 0, false);
} catch (MqttException e) {
e.printStackTrace();
}
}
private boolean validationParameters(StudioResourceModel model, Map<String, Object> variables) {
String text = model.getResourceParams();
JSONArray fields = JSONObject.parseArray(text);
......
package com.yeejoin.amos.api.tool.face.service;
import com.yeejoin.amos.api.tool.face.orm.entity.TableColumn;
import com.yeejoin.amos.api.tool.utils.DataBaseUtils;
import org.springframework.stereotype.Service;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@Service
public class TransferDataService {
private static final String TABLE_DES = "mcb_warning_base_source_attribution";
private static final String TABLE_ORI = "qms_explorer";
private static final String DBNAME_DES = "amos_mcb";
private static final String DBNAME_ORI = "amos_studio";
public Connection connectDataBase(String dataBaseName) throws ClassNotFoundException, SQLException {
// 加载数据库驱动
Class.forName("com.mysql.cj.jdbc.Driver");
// 生成url
String dbUrl = "jdbc:mysql://172.16.3.18:3306/" + dataBaseName;
// 连接数据库
return DriverManager.getConnection(dbUrl, "root", "Yeejoin@2020");
}
public void transferData() throws SQLException, ClassNotFoundException {
Connection connection = this.connectDataBase(DBNAME_ORI);
List<Map<String,Object>> maps = DataBaseUtils.getMaps("SELECT * FROM " + TABLE_ORI + " ;" , connection);
connection.close();
connection = this.connectDataBase(DBNAME_DES);
List<TableColumn> columns = DataBaseUtils.getTableColumn(TABLE_DES,connection);
List<Map<String,Object>> dataList = this.convertDataMap(maps, columns);
System.out.println(DataBaseUtils.getInsertSQL(dataList,columns,TABLE_DES));
}
public List<Map<String, Object>> convertDataMap(List<Map<String, Object>> maps, List<TableColumn> columns) {
List<Map<String, Object>> dataList = new ArrayList<>();
for (Map<String, Object> map : maps) {
Map<String, Object> data = new HashMap<>();
for (TableColumn column : columns) {
data.put(column.getColumnName(), null);
}
data.replace("SEQUENCE_NBR", map.get("SEQUENCE_NBR"));
data.replace("NAME", map.get("RESOURCE_NAME"));
data.replace("PARENT_ID", map.get("PARENT_ID"));
data.replace("CODE", map.get("AGENCY_CODE"));
data.replace("REC_USER_ID", map.get("REC_USER_ID"));
data.replace("REC_DATE", map.get("REC_DATE"));
dataList.add(data);
}
return dataList;
}
}
......@@ -6,6 +6,8 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yeejoin.amos.api.tool.face.orm.entity.TableColumn;
import org.eclipse.paho.client.mqttv3.MqttException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;
import org.springframework.util.ObjectUtils;
import org.typroject.tyboot.component.emq.EmqKeeper;
import org.typroject.tyboot.core.foundation.utils.ValidationUtil;
......@@ -19,10 +21,11 @@ import java.net.SocketException;
import java.sql.*;
import java.util.*;
@Component
public class DataBaseUtils {
static EmqKeeper emqKeeper;
/**
* 数据库备份路径
*/
......@@ -157,21 +160,7 @@ public class DataBaseUtils {
return sql;
}
public static void print(String id, String msg, String step) {
String percent = "0";
percent = ValidationUtil.equals(step, "end") ? "100" : ValidationUtil.equals(step, "running") ? "50" : "10";
JSONObject event = new JSONObject();
event.put("percent", percent);
event.put("status", "running");
event.put("logInfo", msg);
event.put("time", DateUtils.toDateStr(DateUtils.format()));
try {
emqKeeper.getMqttClient().publish("/topicTable/solidify/" + (id.indexOf(',') != -1 ? id.split(",")[0] : id), event.toString().getBytes(), 0, false);
} catch (MqttException e) {
e.printStackTrace();
}
}
public static <V> Page<V> listToPage(List<V> list, int current, int size) {
//当前页
......
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