kgdxpr 2 years ago
commit 6412306c81

@ -30,4 +30,12 @@ t_importexcel_role_map
truncate table t_collect_job restart identity;
truncate table t_collect_job_sheet restart identity;
truncate table t_collect_job_sheet_col restart identity;
truncate table t_collect_mapping restart identity;
truncate table t_collect_mapping restart identity;
# 处理序列
-- 查看所有序列
SELECT relname,pg_sequence_last_value(relname ::text) AS seq_last_value FROM pg_class
WHERE relkind = 'S' AND relowner = (SELECT usesysid FROM pg_user WHERE usename = (SELECT CURRENT_USER));
-- 修改序列名称
ALTER SEQUENCE t_importexcel_process_id_seq RENAME TO t_collect_process_id_seq;

@ -1,10 +1,14 @@
package com.dsideal.QingLong.Collect.Controller;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.dsideal.QingLong.Collect.Model.CollectModel;
import com.dsideal.QingLong.Interceptor.EmptyInterface;
import com.dsideal.QingLong.Interceptor.IsLoginInterface;
import com.dsideal.QingLong.Interceptor.IsNumericInterface;
import com.dsideal.QingLong.Util.CommonUtil;
import com.dsideal.QingLong.Util.ExcelUtil;
import com.dsideal.QingLong.Util.ImportExcelKit;
import com.dsideal.QingLong.Util.SessionKit;
import com.jfinal.aop.Before;
import com.jfinal.core.Controller;
@ -31,17 +35,14 @@ public class CollectController extends Controller {
UploadFile excelFile = getFile();//得到文件对象
//操作人员
String person_id = SessionKit.get(getRequest(), getResponse(), "person_id");
//有哪些角色是可以发布任务的角色?
List<Record> roleList = cm.getPersonPublishJobRole(person_id);
if (roleList.size() == 0) {
Map map = new HashMap();
map.put("success", false);
map.put("message", "你不具备发布数据采集任务的角色,请让系统管理员进行配置后重试!");
renderJson(map);
//检查当前登录人员是不是发布任务的角色
Kv kvCheck = cm.checkPublishRole(person_id);
if (!kvCheck.getBoolean("success")) {
renderJson(kvCheck);
return;
}
//发布角色,目前写死成第一个,如果以后有用户反馈需要角色切换,就再开发功能进行应对
int publish_role_id = roleList.get(0).getInt("duties_id");
//获取登录人员第一个发布任务的角色是什么
int publish_role_id = kvCheck.getInt("publish_role_id");
String fileName = excelFile.getFileName();
String suffix = fileName.substring(fileName.lastIndexOf(".") + 1).trim();
@ -127,8 +128,14 @@ public class CollectController extends Controller {
@IsLoginInterface({})
@IsNumericInterface({"job_id", "sheet_index"})
public void getSheetStruct(int job_id, int sheet_index) {
//获取数据表的整体配置信息
Record record = cm.getSheet(job_id, sheet_index);
Kv kv = Kv.create();
kv.set("record", record);
List<Record> list = cm.getSheetStruct(job_id, sheet_index);
renderJson(CommonUtil.renderJsonForLayUI(list));
kv.set("list", CommonUtil.renderJsonForLayUI(list));
renderJson(kv);
}
/**
@ -146,8 +153,53 @@ public class CollectController extends Controller {
*/
@Before({POST.class})
@IsLoginInterface({})
public void saveSheet() {
public void saveSheet(String json) {
//操作人员
String person_id = SessionKit.get(getRequest(), getResponse(), "person_id");
//检查当前登录人员是不是发布任务的角色
Kv kvCheck = cm.checkPublishRole(person_id);
if (!kvCheck.getBoolean("success")) {
renderJson(kvCheck);
return;
}
JSONArray ja;
try {
ja = JSONArray.parseArray(json);
} catch (Exception err) {
Kv kv = Kv.create();
kv.set("success", false);
kv.set("message", "上报的json数据格式不正确请检查后重传");
renderJson(kv);
return;
}
//保存
List<Record> writeList = new ArrayList<>();
for (Object o : ja) {
JSONObject jo = (JSONObject) o;
int job_id = jo.getInteger("job_id");
int sheet_index = jo.getInteger("sheet_index");
int column_index = jo.getInteger("column_index");
int data_type_id = jo.getInteger("data_type_id");
String column_name = jo.getString("column_name");
String original_name = jo.getString("original_name");
boolean allow_blank = jo.getBoolean("allow_blank");
String options = jo.getString("options");
Record record = new Record();
record.set("job_id", job_id);
record.set("sheet_index", sheet_index);
record.set("column_index", column_index);
record.set("data_type_id", data_type_id);
record.set("column_name", column_name);
record.set("original_name", original_name);
record.set("allow_blank", allow_blank);
record.set("options", options);
writeList.add(record);
}
cm.saveSheet(writeList);
Map map = new HashMap();
map.put("success", true);
map.put("message", "保存成功!");
renderJson(map);
}
/**
@ -159,7 +211,20 @@ public class CollectController extends Controller {
@Before({POST.class})
@IsLoginInterface({})
public void checkSheet(int job_id, int sheet_index) {
//操作人员
String person_id = SessionKit.get(getRequest(), getResponse(), "person_id");
//检查当前登录人员是不是发布任务的角色
Kv kvCheck = cm.checkPublishRole(person_id);
if (!kvCheck.getBoolean("success")) {
renderJson(kvCheck);
return;
}
cm.checkSheet(job_id, sheet_index);
Map map = new HashMap();
map.put("success", true);
map.put("message", "保存成功!");
renderJson(map);
}
/**
@ -169,8 +234,35 @@ public class CollectController extends Controller {
*/
@Before({POST.class})
@IsLoginInterface({})
public void saveJob(int job_id) {
@IsNumericInterface({"job_id"})
@EmptyInterface({"job_name"})
public void saveJob(int job_id, String job_name) {
//操作人员
String person_id = SessionKit.get(getRequest(), getResponse(), "person_id");
//检查当前登录人员是不是发布任务的角色
Kv kvCheck = cm.checkPublishRole(person_id);
if (!kvCheck.getBoolean("success")) {
renderJson(kvCheck);
return;
}
//保存任务名称
cm.saveJob(job_id, job_name);
//判断表是不是已存在
// List<Record> listJobSheet = cm.getJobSheet(job_id);
// for (Kv kv : kvList) {
// String tableName = kv.getStr("table_name");
// if (ImportExcelKit.isTableExist(tableName)) {
// System.out.println("表" + tableName + "已存在,不能删除,程序无法继续!");
// return;
// }
// }
//返回成功
Map map = new HashMap();
map.put("success", true);
map.put("message", "保存成功!");
renderJson(map);
}
/**

@ -1,15 +1,20 @@
package com.dsideal.QingLong.Collect.Model;
import cn.hutool.core.date.DateTime;
import com.dsideal.QingLong.Interceptor.EmptyInterface;
import com.dsideal.QingLong.Interceptor.IsLoginInterface;
import com.dsideal.QingLong.Interceptor.IsNumericInterface;
import com.jfinal.aop.Before;
import com.jfinal.ext.interceptor.GET;
import com.jfinal.ext.interceptor.POST;
import com.jfinal.kit.Kv;
import com.jfinal.plugin.activerecord.Db;
import com.jfinal.plugin.activerecord.Record;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class CollectModel {
@ -89,9 +94,6 @@ public class CollectModel {
writeRecord.set("column_index", colIdx);
writeRecord.set("column_name", column_name);
writeRecord.set("original_name", memo);
writeRecord.set("pg_data_type", "varchar(2048)");
writeRecord.set("web_data_type", "文本");
writeRecord.set("excel_data_type", "String");
writeRecord.set("data_type_id", 1);
writeRecord.set("allow_blank", true);
writeRecord.set("options", "");
@ -125,6 +127,18 @@ public class CollectModel {
return Db.find(sql, job_id);
}
/**
* + Sheet_indexSheet
*
* @param job_id
* @param sheet_index
* @return
*/
public Record getSheet(int job_id, int sheet_index) {
String sql = "select * from t_collect_job_sheet where job_id=? and sheet_index=? order by sheet_index";
return Db.findFirst(sql, job_id, sheet_index);
}
/**
* Sheet
*
@ -137,5 +151,72 @@ public class CollectModel {
return Db.find(sql, job_id, sheet_index);
}
/**
* Sheet
*
* @param writeList
*/
public void saveSheet(List<Record> writeList) {
if (writeList.size() == 0) return;
int job_id = writeList.get(0).getInt("job_id");
int sheet_index = writeList.get(0).getInt("sheet_index");
String sql = "delete from t_collect_job_sheet_col where job_id=? and sheet_index=?";
Db.update(sql, job_id, sheet_index);
Db.batchSave("t_collect_job_sheet_col", writeList, 100);
}
/**
* job_id+sheet_index
*
* @param job_id
* @param sheet_index
*/
public void checkSheet(int job_id, int sheet_index) {
String sql = "update t_collect_job_sheet set is_check=1,check_time=? where job_id=? and sheet_index=?";
Db.update(sql, DateTime.now(), job_id, sheet_index);
}
/**
*
*
* @param person_id
* @return
*/
public Kv checkPublishRole(String person_id) {
Kv kv = Kv.create();
//有哪些角色是可以发布任务的角色?
List<Record> roleList = getPersonPublishJobRole(person_id);
if (roleList.size() == 0) {
kv.set("success", false);
kv.set("message", "你不具备发布数据采集任务的角色,请让系统管理员进行配置后重试!");
return kv;
}
//发布角色,目前写死成第一个,如果以后有用户反馈需要角色切换,就再开发功能进行应对
kv.set("publish_role_id", roleList.get(0).getInt("duties_id"));
kv.set("success", true);
kv.set("message", "检查通过!");
return kv;
}
/**
*
*
* @param job_id
*/
public void saveJob(int job_id, String job_name) {
String sql = "update t_collect_job set job_name=? where job_id=?";
Db.update(sql, job_name, job_id);
}
/**
* JOB_IDSheet
*
* @param job_id
* @return
*/
public List<Record> getJobSheet(int job_id) {
String sql = "select * from t_collect_job_sheet where job_id=?";
return Db.find(sql, job_id);
}
}
Loading…
Cancel
Save