commit by Kalman.CHENG ☆
This commit is contained in:
@@ -1,43 +0,0 @@
|
||||
package com.dsideal.dsBase.Collect.Const;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
|
||||
public class DataType {
|
||||
|
||||
public static final int WEB_DATA_TYPE = 1; //前台看到的数据类型
|
||||
public static final int PG_DATA_TYPE = 2;//postgresql数据库侧的数据类型
|
||||
public static final int EXCEL_DATA_TYPE = 3;//excel侧的数据类型
|
||||
|
||||
/**
|
||||
* 1:文本 2:数字 3:小数 4:日期
|
||||
* textarea:不传fieldType,默认是文本
|
||||
* select:不传fieldType,默认是数字
|
||||
* radio:不传fieldType,默认是数字
|
||||
* checkbox:不传fieldType,默认是文本
|
||||
* date:不传fieldType,默认是日期
|
||||
* rate:不传fieldType,默认是数字
|
||||
* image:不传fieldType,默认是文本
|
||||
* file:不传fieldType,默认是文本
|
||||
* blockquote:为布局组件,不用设置为字段
|
||||
* line:为布局组件,不用设置为字段
|
||||
* input:需要参照fieldType,1,2,3进行设置字段类型
|
||||
*
|
||||
* @param jo
|
||||
* @return
|
||||
*/
|
||||
public static int getFormDataType(JSONObject jo) {
|
||||
String tag = jo.getString("tag");
|
||||
if (tag.equals("textarea")) return 1;
|
||||
if (tag.equals("select")) return 1;
|
||||
if (tag.equals("radio")) return 1;
|
||||
if (tag.equals("checkbox")) return 1;
|
||||
if (tag.equals("date")) return 4;
|
||||
if (tag.equals("rate")) return 2;
|
||||
if (tag.equals("image")) return 1;
|
||||
if (tag.equals("file")) return 1;
|
||||
if (tag.equals("blockquote")) return 0;
|
||||
if (tag.equals("line")) return 0;
|
||||
if (tag.equals("input")) return jo.getInteger("fieldType");
|
||||
return 1;
|
||||
}
|
||||
}
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -1,308 +0,0 @@
|
||||
package com.dsideal.dsBase.DataShare.Controller;
|
||||
|
||||
import cn.hutool.core.io.FileUtil;
|
||||
import com.dsideal.dsBase.Const.IdentityConst;
|
||||
import com.dsideal.dsBase.DataShare.Model.DataShareModel;
|
||||
import com.dsideal.dsBase.Interceptor.*;
|
||||
import com.dsideal.dsBase.Util.CommonUtil;
|
||||
import com.jfinal.aop.Before;
|
||||
import com.jfinal.core.Controller;
|
||||
import com.jfinal.ext.interceptor.GET;
|
||||
import com.jfinal.ext.interceptor.POST;
|
||||
import com.jfinal.kit.Kv;
|
||||
import com.jfinal.kit.PathKit;
|
||||
import com.jfinal.kit.PropKit;
|
||||
import com.jfinal.kit.StrKit;
|
||||
import com.jfinal.plugin.activerecord.Page;
|
||||
import com.jfinal.plugin.activerecord.Record;
|
||||
import com.jfinal.upload.UploadFile;
|
||||
import io.github.yedaxia.apidocs.ApiDoc;
|
||||
|
||||
import java.io.*;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
@ApiDoc
|
||||
public class DataShareController extends Controller {
|
||||
DataShareModel dm = new DataShareModel();
|
||||
|
||||
/**
|
||||
* 获取接入系统列表
|
||||
*
|
||||
* @param keyword 关键字
|
||||
* @param exclude 排除系统ID,不显示在列表中,0表示不排除,其他表示排除
|
||||
* @param page 页码
|
||||
* @param limit 每页数量
|
||||
*/
|
||||
@Before({GET.class})
|
||||
@IsLoginInterface({})
|
||||
@IsSysAdminInterface({"1"})
|
||||
@IsNumericInterface({"page", "limit"})
|
||||
public void listSystem(String keyword, int exclude, int page, int limit) {
|
||||
Page<Record> dt = dm.listSystem(keyword, exclude, page, limit);
|
||||
renderJson(CommonUtil.renderJsonForLayUI(dt));
|
||||
}
|
||||
|
||||
/**
|
||||
* 增加一个数据共享系统
|
||||
*
|
||||
* @param system_name 系统名称
|
||||
* @param user_name 访问账号
|
||||
* @param redirect_url 回调地址
|
||||
*/
|
||||
@Before({POST.class})
|
||||
@IsLoginInterface({})
|
||||
@IsSysAdminInterface({"1"})
|
||||
@EmptyInterface({"system_name", "user_name"})
|
||||
public void addSystem(String system_name, String user_name, String redirect_url) {
|
||||
if (dm.isExistUserName(user_name)) {
|
||||
Kv kv = Kv.by("success", false);
|
||||
kv.set("message", "访问账号已存在,请更换!");
|
||||
renderJson(kv);
|
||||
return;
|
||||
}
|
||||
if (dm.isExistRedirectUrl(redirect_url)) {
|
||||
Kv kv = Kv.by("success", false);
|
||||
kv.set("message", "指定的回调地址已存在,请检查后重新提交!");
|
||||
renderJson(kv);
|
||||
return;
|
||||
}
|
||||
dm.addSystem(system_name, user_name, redirect_url);
|
||||
Kv kv = Kv.by("success", true);
|
||||
kv.set("message", "保存成功!");
|
||||
renderJson(kv);
|
||||
}
|
||||
|
||||
/**
|
||||
* 功能:上传系统的EXCEL文档
|
||||
*/
|
||||
@Before({POST.class})
|
||||
@IsLoginInterface({})
|
||||
@IsSysAdminInterface({"1"})
|
||||
public void saveUploadFile() {
|
||||
UploadFile uf = getFile();//得到文件对象
|
||||
int system_id = getInt("system_id");
|
||||
String fileName = uf.getFileName();
|
||||
String suffix = fileName.substring(fileName.lastIndexOf(".") + 1).trim();
|
||||
if (!suffix.equals("xlsx")) {
|
||||
renderJson(CommonUtil.returnMessageJson(false, "上传文件类型错误!系统只允许上传Excel文档!"));
|
||||
return;
|
||||
}
|
||||
//判断文件大小大于20mb则返回错误信息,并终止上传,删除上传文件
|
||||
long size = uf.getFile().length();
|
||||
if (size > 1024 * 1024 * 20) {
|
||||
Kv kv = Kv.by("success", false).set("message", "文件大小大于20MB,请检查是否正确!!");
|
||||
renderJson(kv);
|
||||
return;
|
||||
}
|
||||
String basePath = PathKit.getWebRootPath() + "/upload/";
|
||||
if (!FileUtil.exist(basePath)) FileUtil.mkdir(basePath);
|
||||
String file_id = UUID.randomUUID().toString().toUpperCase();
|
||||
String filePath = basePath + file_id + "." + suffix;
|
||||
uf.getFile().renameTo(new File(filePath));
|
||||
String url = PropKit.get("filePrefix") + "/upload/" + file_id + "." + suffix;
|
||||
//记录到数据库
|
||||
dm.saveUploadFile(system_id, url);
|
||||
//返回结果
|
||||
Kv kv = Kv.by("success", true);
|
||||
kv.set("message", "上传成功!");
|
||||
kv.set("url", url);
|
||||
renderJson(kv);
|
||||
}
|
||||
|
||||
/**
|
||||
* 功能:下载EXCEL文档说明
|
||||
*
|
||||
* @param system_id 系统id
|
||||
*/
|
||||
@Before({GET.class})
|
||||
@IsLoginInterface({})
|
||||
@IsNumericInterface({"system_id"})
|
||||
@IsSysAdminInterface({"1"})
|
||||
public void downloadXlsx(int system_id) {
|
||||
Record record = dm.getSystemById(system_id);
|
||||
boolean Error = false;
|
||||
String url = "";
|
||||
if (record == null) {
|
||||
Error = true;
|
||||
} else {
|
||||
url = record.getStr("url");
|
||||
if (StrKit.isBlank(url)) {
|
||||
Error = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (Error) {
|
||||
Kv kv = Kv.by("success", false);
|
||||
kv.set("message", "此系统还没有上传说明文档,无法下载!");
|
||||
renderJson(kv);
|
||||
return;
|
||||
}
|
||||
String system_name = record.getStr("system_name");
|
||||
String[] array = url.split("/");
|
||||
String file_name = array[array.length - 1];
|
||||
String basePath = PathKit.getWebRootPath() + "/upload/";
|
||||
renderFile(new File(basePath + file_name), "【" + system_name + "】文档说明.xlsx");
|
||||
}
|
||||
|
||||
/**
|
||||
* 功能:根据系统ID获取系统信息
|
||||
*
|
||||
* @param system_id
|
||||
*/
|
||||
@Before({GET.class})
|
||||
@IsLoginInterface({})
|
||||
@IsSysAdminInterface({"1"})
|
||||
@IsNumericInterface({"system_id"})
|
||||
public void getSystemById(int system_id) {
|
||||
Record record = dm.getSystemById(system_id);
|
||||
renderJson(record);
|
||||
}
|
||||
|
||||
/**
|
||||
* 功能:删除系统
|
||||
*
|
||||
* @param system_id
|
||||
*/
|
||||
@Before({POST.class})
|
||||
@IsLoginInterface({})
|
||||
@IsSysAdminInterface({"1"})
|
||||
@IsNumericInterface({"system_id"})
|
||||
public void delSystem(int system_id) {
|
||||
dm.delSystem(system_id);
|
||||
Kv kv = Kv.by("success", true);
|
||||
kv.set("message", "保存成功!");
|
||||
renderJson(kv);
|
||||
}
|
||||
|
||||
/**
|
||||
* 功能:修改系统名称
|
||||
*
|
||||
* @param system_id
|
||||
* @param system_name
|
||||
* @param redirect_url
|
||||
*/
|
||||
@Before({POST.class})
|
||||
@IsLoginInterface({})
|
||||
@IsSysAdminInterface({"1"})
|
||||
@IsNumericInterface({"system_id"})
|
||||
@EmptyInterface({"system_name"})
|
||||
public void updateSystem(int system_id, String system_name, String redirect_url) {
|
||||
dm.updateSystem(system_id, system_name, redirect_url);
|
||||
Kv kv = Kv.by("success", true);
|
||||
kv.set("message", "保存成功!");
|
||||
renderJson(kv);
|
||||
}
|
||||
|
||||
/**
|
||||
* 功能:指定的系统,它订阅哪些业务系统的数据表
|
||||
*
|
||||
* @param system_id
|
||||
* @param subscribe_system_ids
|
||||
*/
|
||||
@Before({POST.class})
|
||||
@IsLoginInterface({})
|
||||
@IsSysAdminInterface({"1"})
|
||||
@IsNumericInterface({"system_id"})
|
||||
public void subscribe(int system_id, String subscribe_system_ids) {
|
||||
dm.subscribe(system_id, subscribe_system_ids);
|
||||
Kv kv = Kv.by("success", true);
|
||||
kv.set("message", "保存成功!");
|
||||
renderJson(kv);
|
||||
}
|
||||
|
||||
/**
|
||||
* 功能:修改系统的密码
|
||||
*
|
||||
* @param system_id
|
||||
*/
|
||||
@Before({POST.class})
|
||||
@IsLoginInterface({})
|
||||
@IsSysAdminInterface({"1"})
|
||||
@IsNumericInterface({"system_id"})
|
||||
public void changePwd(int system_id) {
|
||||
dm.changePwd(system_id, CommonUtil.generatePassword(10));
|
||||
Kv kv = Kv.by("success", true);
|
||||
kv.set("message", "修改成功!");
|
||||
renderJson(kv);
|
||||
}
|
||||
|
||||
/**
|
||||
* 功能:记录指定系统它有哪些数据表
|
||||
*
|
||||
* @param system_id
|
||||
* @param table_names
|
||||
*/
|
||||
@Before({POST.class})
|
||||
@IsLoginInterface({})
|
||||
@IsSysAdminInterface({"1"})
|
||||
@IsNumericInterface({"system_id"})
|
||||
public void share(int system_id, String table_names) {
|
||||
if (!StrKit.isBlank(table_names) && !dm.isExistTable(table_names)) {
|
||||
Kv kv = Kv.by("success", false);
|
||||
kv.set("message", "检查到数据表在数据库中不存在的情况,请检查后重新录入!");
|
||||
renderJson(kv);
|
||||
return;
|
||||
}
|
||||
//检查一下共享的表是不是已经被其它系统共享过?
|
||||
if (!StrKit.isBlank(table_names) && !dm.checkShareTable(system_id, table_names)) {
|
||||
Kv kv = Kv.by("success", false);
|
||||
kv.set("message", "检查到要共享的数据表已经被其它业务系统共享,请检查后重新录入!");
|
||||
renderJson(kv);
|
||||
return;
|
||||
}
|
||||
|
||||
dm.share(system_id, table_names);
|
||||
Kv kv = Kv.by("success", true);
|
||||
kv.set("message", "保存成功!");
|
||||
renderJson(kv);
|
||||
}
|
||||
|
||||
/**
|
||||
* 功能:获取指定系统它有哪些数据表
|
||||
*
|
||||
* @param system_id
|
||||
*/
|
||||
@Before({GET.class})
|
||||
@IsLoginInterface({})
|
||||
@IsSysAdminInterface({"1"})
|
||||
@IsNumericInterface({"system_id"})
|
||||
public void getShareTable(int system_id) {
|
||||
List<Record> list = dm.getShareTable(system_id);
|
||||
renderJson(list);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 第三方接入系统获取执行票据Token
|
||||
*
|
||||
* @param user_name 分配给第三方的用户名
|
||||
* @param pwd 分配给第三方的密码
|
||||
*/
|
||||
@Before({POST.class})
|
||||
public void getToken(String user_name, String pwd) {
|
||||
//获取 token
|
||||
String token = dm.getToken(user_name, pwd);
|
||||
if (token != null) {
|
||||
Kv kv = Kv.by("token", token);
|
||||
kv.set("success", true);
|
||||
kv.set("message", "获取成功!");
|
||||
/*
|
||||
identity_id=1 系统管理员
|
||||
identity_id=2 市州管理员
|
||||
identity_id=3 县区管理员
|
||||
identity_id=4 单位/学校管理员
|
||||
identity_id=5 教师
|
||||
identity_id=6 学生
|
||||
identity_id=7 家长
|
||||
identity_id=8 第三方接入的系统
|
||||
|
||||
header的Authorization中放入token,再通过header传过来,
|
||||
*/
|
||||
kv.set("identity_id", IdentityConst.SHARE_SYSTEM);//第三方业务系统,视为8号身份人群
|
||||
renderJson(kv);
|
||||
return;
|
||||
}
|
||||
renderJson(Kv.by("success", false).set("message", "用户名与密码不正确!"));
|
||||
}
|
||||
}
|
@@ -1,390 +0,0 @@
|
||||
package com.dsideal.dsBase.DataShare.Model;
|
||||
|
||||
import com.dsideal.dsBase.Util.CommonUtil;
|
||||
import com.dsideal.dsBase.Util.PgUtil;
|
||||
import com.dsideal.dsBase.Util.RsaUtils;
|
||||
import com.jfinal.kit.Kv;
|
||||
import com.jfinal.kit.StrKit;
|
||||
import com.jfinal.plugin.activerecord.Db;
|
||||
import com.jfinal.plugin.activerecord.Page;
|
||||
import com.jfinal.plugin.activerecord.Record;
|
||||
import com.jfinal.plugin.activerecord.SqlPara;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
public class DataShareModel {
|
||||
|
||||
public Page<Record> listSystem(String keyword, int exclude, int page, int limit) {
|
||||
if (StrKit.isBlank(keyword)) keyword = "";
|
||||
Kv kv = Kv.by("keyword", keyword);
|
||||
if (exclude > 0) {
|
||||
kv.set("exclude", exclude);
|
||||
}
|
||||
SqlPara sp = Db.getSqlPara("DataShare.listSystem", kv);
|
||||
Page<Record> list = Db.paginate(page, limit, sp);
|
||||
for (Record record : list.getList()) {
|
||||
String subscribe_system_ids = record.getStr("subscribe_system_ids");
|
||||
if (StrKit.isBlank(subscribe_system_ids)) record.set("subscribe_system_count", 0);
|
||||
else {
|
||||
record.set("subscribe_system_count", subscribe_system_ids.split(",").length);
|
||||
}
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
/**
|
||||
* 功能:判断用户名是否重复
|
||||
*
|
||||
* @param user_name
|
||||
* @return
|
||||
*/
|
||||
public boolean isExistUserName(String user_name) {
|
||||
String sql = "select * from t_datashare_system where user_name=?";
|
||||
return !Db.find(sql, user_name).isEmpty();
|
||||
}
|
||||
|
||||
public void addSystem(String system_name, String user_name, String redirect_url) {
|
||||
Record record = new Record();
|
||||
record.set("system_name", system_name);
|
||||
record.set("user_name", user_name);
|
||||
record.set("redirect_url", redirect_url);
|
||||
String pwd = CommonUtil.generatePassword(10);
|
||||
record.set("pwd", pwd);
|
||||
if (PgUtil.isExistUser(user_name)) {
|
||||
PgUtil.delUser(user_name);
|
||||
}
|
||||
PgUtil.createUser(user_name, pwd);
|
||||
Db.save("t_datashare_system", "system_id", record);
|
||||
}
|
||||
|
||||
/**
|
||||
* 功能:删除系统
|
||||
*
|
||||
* @param system_id
|
||||
*/
|
||||
public void delSystem(int system_id) {
|
||||
//1、删除此系统的用户
|
||||
String user_name = getSystemById(system_id).getStr("user_name");
|
||||
PgUtil.delUser(user_name);
|
||||
//2、删除数据表记录
|
||||
Db.deleteById("t_datashare_system", "system_id", system_id);
|
||||
|
||||
//3、共享了哪些表
|
||||
String sql = "select * from t_datashare_table where system_id=?";
|
||||
List<Record> shareTableList = Db.find(sql, system_id);
|
||||
//4、删除此系统共享表
|
||||
sql = "delete from t_datashare_table where system_id=?";
|
||||
Db.update(sql, system_id);
|
||||
|
||||
//5、删除所有其它系统对此系统的订阅
|
||||
List<Integer> subSystemList = getSubSystemList(system_id);
|
||||
sql = "select * from t_datashare_system";
|
||||
List<Record> list = Db.find(sql);
|
||||
for (Record record : list) {
|
||||
int sub_system_id = record.getInt("system_id");
|
||||
String subscribe_system_ids = record.getStr("subscribe_system_ids");
|
||||
String new_subscribe_system_ids = "";
|
||||
if (!StrKit.isBlank(subscribe_system_ids)) {
|
||||
for (String s : subscribe_system_ids.split(",")) {
|
||||
if (!s.equals(system_id + "")) new_subscribe_system_ids += s + ",";
|
||||
}
|
||||
}
|
||||
if (!new_subscribe_system_ids.isEmpty()) {
|
||||
new_subscribe_system_ids = new_subscribe_system_ids.substring(0, new_subscribe_system_ids.length() - 1);//去最后的逗号
|
||||
}
|
||||
sql = "update t_datashare_system set subscribe_system_ids=? where system_id=?";
|
||||
Db.update(sql, new_subscribe_system_ids, sub_system_id);
|
||||
}
|
||||
//5、回收其它订阅系统对它共享表的授权
|
||||
for (Record record : shareTableList) {
|
||||
String table_name = record.getStr("table_name");
|
||||
for (Integer v_system_id : subSystemList) {
|
||||
String v_user_name = getSystemById(v_system_id).getStr("user_name");
|
||||
PgUtil.revokeUserPrivilege(v_user_name, table_name, PgUtil.READ);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 功能:检查要共享的表是不是已经被其它业务系统共享过?
|
||||
*
|
||||
* @param table_names
|
||||
* @return
|
||||
*/
|
||||
public boolean checkShareTable(int system_id, String table_names) {
|
||||
String sql = "select * from t_datashare_table";
|
||||
List<Record> list = Db.find(sql);
|
||||
Map<String, Integer> _map = new HashMap<>();
|
||||
for (Record record : list) {
|
||||
_map.put(record.getStr("table_name"), record.getInt("system_id"));
|
||||
}
|
||||
for (String s : table_names.split(",")) {
|
||||
if (_map.containsKey(s)) {
|
||||
if (_map.get(s) != system_id) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 功能:更新系统
|
||||
*
|
||||
* @param system_id
|
||||
* @param system_name
|
||||
*/
|
||||
public void updateSystem(int system_id, String system_name, String redirect_url) {
|
||||
String sql = "update t_datashare_system set system_name=?,redirect_url=? where system_id=?";
|
||||
Db.update(sql, system_name, redirect_url, system_id);
|
||||
}
|
||||
|
||||
/**
|
||||
* 功能:获取系统信息
|
||||
*
|
||||
* @param system_id
|
||||
* @return
|
||||
*/
|
||||
public Record getSystemById(int system_id) {
|
||||
return Db.findById("t_datashare_system", "system_id", system_id);
|
||||
}
|
||||
|
||||
/**
|
||||
* 功能:系统SYSTEM_ID被哪些其它系统订阅过
|
||||
*
|
||||
* @param system_id
|
||||
* @return
|
||||
*/
|
||||
public List<Integer> getSubSystemList(int system_id) {
|
||||
List<Integer> res = new ArrayList<>();
|
||||
String sql = "select * from t_datashare_system";
|
||||
List<Record> list = Db.find(sql);
|
||||
for (Record record : list) {
|
||||
boolean flag = false;
|
||||
String subscribe_system_ids = record.getStr("subscribe_system_ids");
|
||||
if (!StrKit.isBlank(subscribe_system_ids)) {
|
||||
for (String s : subscribe_system_ids.split(",")) {
|
||||
if (Integer.parseInt(s) == system_id) {
|
||||
flag = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (flag) {
|
||||
res.add(record.getInt("system_id"));
|
||||
}
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
/**
|
||||
* 功能:记录指定系统它有哪些数据表
|
||||
*
|
||||
* @param system_id
|
||||
* @param table_names
|
||||
*/
|
||||
public void share(int system_id, String table_names) {
|
||||
//0、系统的ID与数据库用户名
|
||||
Record systemRecord = getSystemById(system_id);
|
||||
String user_name = systemRecord.getStr("user_name");
|
||||
|
||||
//原来共享的表
|
||||
List<Record> oldTables = getShareTable(system_id);
|
||||
|
||||
//1、回收原来共享表的写权限
|
||||
for (Record r : oldTables) {//原来有哪些共享表?
|
||||
String table_name = r.getStr("table_name");
|
||||
PgUtil.revokeUserPrivilege(user_name, table_name, PgUtil.WRITE);
|
||||
}
|
||||
|
||||
//2、重新分配新共享表的写权限
|
||||
if (!StrKit.isBlank(table_names)) {
|
||||
for (String s : table_names.split(",")) {
|
||||
PgUtil.grantUserPrivilege(user_name, s, PgUtil.WRITE);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//3、原来订阅这个系统有第三方系统有哪些,它们的用户都需要取消对原来表的读授权
|
||||
List<String> listUser = new ArrayList<>();
|
||||
List<Integer> lSystem = getSubSystemList(system_id);
|
||||
for (int i = 0; i < lSystem.size(); i++) {
|
||||
String sub_user_name = getSystemById(lSystem.get(i)).getStr("user_name");
|
||||
listUser.add(sub_user_name);
|
||||
}
|
||||
|
||||
for (Record r : oldTables) {//原来有哪些共享表?
|
||||
String table_name = r.getStr("table_name");
|
||||
for (String s : listUser) {
|
||||
PgUtil.revokeUserPrivilege(s, table_name, PgUtil.READ);
|
||||
}
|
||||
}
|
||||
//4、原来访问的这个系统的第三方系统,它们的用户都需要授予新表的读权限
|
||||
if (!StrKit.isBlank(table_names)) {
|
||||
for (String table_name : table_names.split(",")) {
|
||||
for (String user : listUser) {
|
||||
PgUtil.grantUserPrivilege(user, table_name, PgUtil.READ);
|
||||
}
|
||||
}
|
||||
}
|
||||
//5、删除旧数据
|
||||
String sql = "delete from t_datashare_table where system_id=?";
|
||||
Db.update(sql, system_id);
|
||||
|
||||
//6、保存新数据
|
||||
if (!StrKit.isBlank(table_names)) {
|
||||
for (String s : table_names.split(",")) {
|
||||
systemRecord = new Record();
|
||||
systemRecord.set("system_id", system_id);
|
||||
systemRecord.set("table_name", s);
|
||||
Db.save("t_datashare_table", "id", systemRecord);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 功能:订阅了哪些系统
|
||||
*
|
||||
* @param system_id
|
||||
* @param subscribe_system_ids
|
||||
*/
|
||||
public void subscribe(int system_id, String subscribe_system_ids) {
|
||||
Record record = getSystemById(system_id);
|
||||
String user_name = record.getStr("user_name");
|
||||
|
||||
//如果不再有订阅的系统
|
||||
if (StrKit.isBlank(subscribe_system_ids)) {
|
||||
//这个系统已经订阅了哪些系统的哪些表
|
||||
String sql = "select subscribe_system_ids from t_datashare_system where system_id=?";
|
||||
String exist_subscribe_system_ids = Db.queryStr(sql, system_id);
|
||||
//对于这些表都需要回收此用户的读权限
|
||||
for (String s : exist_subscribe_system_ids.split(",")) {
|
||||
List<Record> list = getShareTable(Integer.parseInt(s));
|
||||
for (Record r : list) {
|
||||
PgUtil.revokeUserPrivilege(user_name, r.getStr("table_name"), PgUtil.READ);
|
||||
}
|
||||
}
|
||||
sql = "update t_datashare_system set subscribe_system_ids=null where system_id=?";
|
||||
Db.update(sql, system_id);
|
||||
return;
|
||||
}
|
||||
//如果是修改为新的订阅系统
|
||||
for (String s : subscribe_system_ids.split(",")) {
|
||||
int sub_system_id = Integer.parseInt(s);
|
||||
//获取此系统的所有表
|
||||
List<Record> records = getShareTable(sub_system_id);
|
||||
for (Record r : records) {
|
||||
String table_name = r.getStr("table_name");
|
||||
PgUtil.grantUserPrivilege(user_name, table_name, PgUtil.READ);
|
||||
}
|
||||
}
|
||||
String sql = "update t_datashare_system set subscribe_system_ids=? where system_id=?";
|
||||
Db.update(sql, subscribe_system_ids, system_id);
|
||||
}
|
||||
|
||||
/**
|
||||
* 功能:获取指定系统它有哪些数据表
|
||||
*
|
||||
* @param system_id
|
||||
*/
|
||||
public List<Record> getShareTable(int system_id) {
|
||||
String sql = "select * from t_datashare_table where system_id=?";
|
||||
return Db.find(sql, system_id);
|
||||
}
|
||||
|
||||
/**
|
||||
* 功能:判断指定的一组表是不是有不存在的
|
||||
*
|
||||
* @param table_names
|
||||
* @return
|
||||
*/
|
||||
public boolean isExistTable(String table_names) {
|
||||
for (String s : table_names.split(",")) {
|
||||
if (!PgUtil.isExistTable(s)) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 功能:保存上传文件
|
||||
*
|
||||
* @param system_id
|
||||
* @param url
|
||||
*/
|
||||
public void saveUploadFile(int system_id, String url) {
|
||||
String sql = "update t_datashare_system set url=? where system_id=?";
|
||||
Db.update(sql, url, system_id);
|
||||
}
|
||||
|
||||
/**
|
||||
* 功能:修改接入系统密码
|
||||
*
|
||||
* @param system_id
|
||||
* @param pwd
|
||||
*/
|
||||
public void changePwd(int system_id, String pwd) {
|
||||
String user_name = getSystemById(system_id).getStr("user_name");
|
||||
PgUtil.changePwd(user_name, pwd);
|
||||
String sql = "update t_datashare_system set pwd=? where system_id=?";
|
||||
Db.update(sql, pwd, system_id);
|
||||
}
|
||||
|
||||
/**
|
||||
* 功能:检查redirect_url 是否已存在
|
||||
*
|
||||
* @param redirect_url
|
||||
* @return
|
||||
*/
|
||||
public boolean isExistRedirectUrl(String redirect_url) {
|
||||
if (StrKit.isBlank(redirect_url)) return false;
|
||||
String sql = "select * from t_datashare_system where redirect_url=?";
|
||||
return Db.findFirst(sql, redirect_url) != null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 第三方系统,根据用户名密码获取token
|
||||
*
|
||||
* @param user_name 分配的用户名
|
||||
* @param pwd 分配的密码
|
||||
* @return 获取到的token, 如果用户名与密码无效,则返回null
|
||||
*/
|
||||
public String getToken(String user_name, String pwd) {
|
||||
String sql = "select * from t_datashare_system where user_name=? and pwd=?";
|
||||
Record record = Db.findFirst(sql, user_name, pwd);
|
||||
if (record == null) return null;
|
||||
return RsaUtils.encryptedDataOnJava(user_name + " " + System.currentTimeMillis(), RsaUtils.PUBLICKEY);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 验证token是否正确
|
||||
*
|
||||
* @param token 要验证的token
|
||||
* @return
|
||||
*/
|
||||
public Record checkToken(String token) {
|
||||
Record record = new Record();
|
||||
try {
|
||||
String decryptedData = RsaUtils.decryptDataOnJava(token, RsaUtils.PRIVATEKEY);
|
||||
String[] x = decryptedData.split(" ");
|
||||
String time = x[1];
|
||||
//判断时间戳是否超时,与当前时间相差60*24*31分钟
|
||||
if (System.currentTimeMillis() - Long.parseLong(time) > 1000 * 60 * 24 * 31) {
|
||||
record.set("message", "票据超时!");
|
||||
record.set("success", false);
|
||||
} else {
|
||||
//计算两个时间戳之间的差值,单位为秒
|
||||
long diff = (System.currentTimeMillis() - Long.parseLong(time)) / 1000;
|
||||
System.out.println("票据有效,时间差为:" + diff + "秒");
|
||||
record.set("message", "票据有效,时间差为:" + diff + "秒");
|
||||
record.set("success", true);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
record.set("success", false);
|
||||
record.set("message", "票据无效!");
|
||||
}
|
||||
return record;
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -563,6 +563,7 @@ public class StudentImportExcelUtil {
|
||||
record.set("operator", operator);
|
||||
record.set("t_teaching_date", new DateTime());
|
||||
record.set("ip_address", IpUtil.ipToLong(ip_address));
|
||||
record.set("update_ts", DateTime.now());
|
||||
studentList.add(record);
|
||||
}
|
||||
Db.batchSave("t_sys_loginperson", studentList, 1000);
|
||||
|
@@ -483,6 +483,7 @@ public class TeacherImportExcelUtil {
|
||||
record.set("t_teaching_date", rs.get(i).getDate("teach_date"));
|
||||
record.set("operator", operator);
|
||||
record.set("ip_address", IpUtil.ipToLong(ip_address));
|
||||
record.set("update_ts", DateTime.now());
|
||||
saveRs.add(record);
|
||||
}
|
||||
int[] result = Db.batchSave("t_sys_loginperson", saveRs, 200);
|
||||
@@ -573,8 +574,8 @@ public class TeacherImportExcelUtil {
|
||||
|
||||
//存在不存在空的都回写一下
|
||||
FileOutputStream excelFileOutPutStream = new FileOutputStream(templateXls);
|
||||
wb.write(excelFileOutPutStream);
|
||||
excelFileOutPutStream.flush();
|
||||
wb.write(excelFileOutPutStream);
|
||||
|
||||
//2、检查是不是都完整填写
|
||||
if (ErrorBlankJO.getBoolean("Error")) {
|
||||
|
@@ -1,7 +1,8 @@
|
||||
package com.dsideal.dsBase.Interceptor;
|
||||
|
||||
import com.dsideal.dsBase.DataShare.Model.DataShareModel;
|
||||
import com.dsideal.dsBase.Util.RsaUtils;
|
||||
import com.dsideal.dsBase.Util.SessionKit;
|
||||
import com.dsideal.dsBase.Util.TokenUtil;
|
||||
import com.jfinal.aop.Interceptor;
|
||||
import com.jfinal.aop.Invocation;
|
||||
import com.jfinal.core.Controller;
|
||||
@@ -14,7 +15,6 @@ import com.jfinal.plugin.activerecord.Record;
|
||||
*/
|
||||
|
||||
public class IsLoginInterceptor implements Interceptor {
|
||||
DataShareModel dm = new DataShareModel();
|
||||
|
||||
@Override
|
||||
public void intercept(Invocation inv) {
|
||||
@@ -39,7 +39,7 @@ public class IsLoginInterceptor implements Interceptor {
|
||||
//检查是不是header的Authorization中有合法Token
|
||||
String Authorization = con.getRequest().getHeader("Authorization");
|
||||
if (Authorization != null) {
|
||||
Record record = dm.checkToken(Authorization);
|
||||
Record record = TokenUtil.checkToken(Authorization);
|
||||
System.out.println(record);
|
||||
if (record.getBoolean("success")) {
|
||||
isTrue = true;
|
||||
@@ -60,4 +60,7 @@ public class IsLoginInterceptor implements Interceptor {
|
||||
//con.redirect("/QingLong/");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
@@ -1,9 +1,9 @@
|
||||
package com.dsideal.dsBase.Interceptor;
|
||||
|
||||
import com.dsideal.dsBase.Const.IdentityConst;
|
||||
import com.dsideal.dsBase.DataShare.Model.DataShareModel;
|
||||
import com.dsideal.dsBase.Util.CommonUtil;
|
||||
import com.dsideal.dsBase.Util.SessionKit;
|
||||
import com.dsideal.dsBase.Util.TokenUtil;
|
||||
import com.jfinal.aop.Interceptor;
|
||||
import com.jfinal.aop.Invocation;
|
||||
import com.jfinal.core.Controller;
|
||||
@@ -16,7 +16,6 @@ import com.jfinal.plugin.activerecord.Record;
|
||||
*/
|
||||
|
||||
public class IsSysAdminInterceptor implements Interceptor {
|
||||
DataShareModel dm = new DataShareModel();
|
||||
|
||||
@Override
|
||||
public void intercept(Invocation inv) {
|
||||
@@ -40,7 +39,7 @@ public class IsSysAdminInterceptor implements Interceptor {
|
||||
int identityId = -1;
|
||||
String Authorization = con.getRequest().getHeader("Authorization");
|
||||
if (Authorization != null) {
|
||||
Record record = dm.checkToken(Authorization);
|
||||
Record record = TokenUtil.checkToken(Authorization);
|
||||
if (record.getBoolean("success")) {
|
||||
identityId = IdentityConst.SHARE_SYSTEM;
|
||||
}
|
||||
|
@@ -4,7 +4,6 @@ import cn.hutool.captcha.CaptchaUtil;
|
||||
import cn.hutool.captcha.LineCaptcha;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.dsideal.dsBase.Base.Model.BaseModel;
|
||||
import com.dsideal.dsBase.Collect.Model.CollectModel;
|
||||
import com.dsideal.dsBase.Interceptor.*;
|
||||
import com.dsideal.dsBase.LoginPerson.Model.LoginPersonModel;
|
||||
import com.dsideal.dsBase.Util.*;
|
||||
@@ -233,12 +232,6 @@ public class LoginPersonController extends Controller {
|
||||
@Before({GET.class})
|
||||
public void logout() {
|
||||
SessionKit.clear(getRequest(), getResponse());
|
||||
CollectModel cm = new CollectModel();
|
||||
if (cm.IS_THIRD_PARTY() == 1) {
|
||||
String url = "https://space.ccsjy.cn/manage/account/logout";
|
||||
redirect(url);
|
||||
return;
|
||||
}
|
||||
redirect("/plogin.html");
|
||||
}
|
||||
|
||||
|
@@ -131,6 +131,7 @@ public class OrganizationModel {
|
||||
record.set("city_id", city_id);
|
||||
record.set("area_id", area_id);
|
||||
record.set("b_use", 1);
|
||||
record.set("org_pk_num", org_pk_num);
|
||||
record.set("is_bureau", 1);
|
||||
record.set("operator", operator);
|
||||
record.set("ip_address", IpUtil.ipToLong(ip_address));
|
||||
@@ -194,6 +195,7 @@ public class OrganizationModel {
|
||||
//是部门
|
||||
record.set("main_school_id", -1);
|
||||
record.set("bureau_id", bureau_id);
|
||||
record.set("org_pk_num", 0);
|
||||
List<Record> rs = getAreaIdByParentId(bureau_id);
|
||||
if (rs != null && !rs.isEmpty()) {
|
||||
city_id = rs.getFirst().getStr("city_id");
|
||||
|
@@ -3,8 +3,6 @@ package com.dsideal.dsBase;
|
||||
import cn.hutool.core.io.FileUtil;
|
||||
import com.dsideal.dsBase.Base.Controller.BaseController;
|
||||
import com.dsideal.dsBase.Classes.Controller.ClassController;
|
||||
import com.dsideal.dsBase.Collect.Controller.CollectController;
|
||||
import com.dsideal.dsBase.DataShare.Controller.DataShareController;
|
||||
import com.dsideal.dsBase.Dm.Controller.DmController;
|
||||
import com.dsideal.dsBase.Global.Controller.GlobalController;
|
||||
import com.dsideal.dsBase.Handler.LoginHandler;
|
||||
@@ -83,10 +81,6 @@ public class Start extends JFinalConfig {
|
||||
//菜单管理
|
||||
me.add("/menu", MenuController.class);
|
||||
|
||||
//数据共享
|
||||
me.add("/dataShare", DataShareController.class);
|
||||
//数据上报汇集子系统
|
||||
me.add("/collect", CollectController.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@@ -0,0 +1,37 @@
|
||||
package com.dsideal.dsBase.Util;
|
||||
|
||||
import com.jfinal.plugin.activerecord.Record;
|
||||
|
||||
public class TokenUtil {
|
||||
|
||||
/**
|
||||
* 验证token是否正确
|
||||
*
|
||||
* @param token 要验证的token
|
||||
* @return
|
||||
*/
|
||||
public static Record checkToken(String token) {
|
||||
Record record = new Record();
|
||||
try {
|
||||
String decryptedData = RsaUtils.decryptDataOnJava(token, RsaUtils.PRIVATEKEY);
|
||||
String[] x = decryptedData.split(" ");
|
||||
String time = x[1];
|
||||
//判断时间戳是否超时,与当前时间相差60*24*31分钟
|
||||
if (System.currentTimeMillis() - Long.parseLong(time) > 1000 * 60 * 24 * 31) {
|
||||
record.set("message", "票据超时!");
|
||||
record.set("success", false);
|
||||
} else {
|
||||
//计算两个时间戳之间的差值,单位为秒
|
||||
long diff = (System.currentTimeMillis() - Long.parseLong(time)) / 1000;
|
||||
System.out.println("票据有效,时间差为:" + diff + "秒");
|
||||
record.set("message", "票据有效,时间差为:" + diff + "秒");
|
||||
record.set("success", true);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
record.set("success", false);
|
||||
record.set("message", "票据无效!");
|
||||
}
|
||||
return record;
|
||||
}
|
||||
|
||||
}
|
@@ -2,10 +2,10 @@
|
||||
driverClassName=org.postgresql.Driver
|
||||
user=postgres
|
||||
password=DsideaL147258369
|
||||
jdbcUrl=jdbc:postgresql://10.10.14.71:5432/szjz_db?reWriteBatchedInserts=true
|
||||
jdbcUrl=jdbc:postgresql://10.10.14.66:5432/szjz_db?reWriteBatchedInserts=true
|
||||
|
||||
# redis
|
||||
redis_ip=10.10.14.14
|
||||
redis_ip=10.10.14.66
|
||||
redis_port=18890
|
||||
|
||||
# 首页
|
||||
|
@@ -3,7 +3,7 @@ undertow.devMode=false
|
||||
undertow.port=9000
|
||||
undertow.host=0.0.0.0
|
||||
#undertow.resourcePath=/usr/local/tomcat8/webapps/QingLong,classpath:static
|
||||
undertow.resourcePath=D:/dsWork/QingLong/WebRoot,classpath:static
|
||||
undertow.resourcePath=D:/dsWork/dsProject/dsPgBase/WebRoot,classpath:static
|
||||
|
||||
# 目录名称
|
||||
undertow.contextPath=/QingLong
|
||||
|
Reference in New Issue
Block a user