|
|
|
@ -3,10 +3,12 @@ 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;
|
|
|
|
@ -33,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();
|
|
|
|
@ -129,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);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
@ -149,6 +154,14 @@ public class CollectController extends Controller {
|
|
|
|
|
@Before({POST.class})
|
|
|
|
|
@IsLoginInterface({})
|
|
|
|
|
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);
|
|
|
|
@ -159,8 +172,7 @@ public class CollectController extends Controller {
|
|
|
|
|
renderJson(kv);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
//遍历每行数据,根据data_type_id+ t_collect_datatype 表 ,修改 pg_data_type,web_data_type,excel_data_type三个属性
|
|
|
|
|
//然后再保存
|
|
|
|
|
//保存
|
|
|
|
|
List<Record> writeList = new ArrayList<>();
|
|
|
|
|
for (Object o : ja) {
|
|
|
|
|
JSONObject jo = (JSONObject) o;
|
|
|
|
@ -199,7 +211,16 @@ public class CollectController extends Controller {
|
|
|
|
|
@Before({POST.class})
|
|
|
|
|
@IsLoginInterface({})
|
|
|
|
|
public void checkSheet(int job_id, int sheet_index) {
|
|
|
|
|
cm.checkSheet(job_id,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", "保存成功!");
|
|
|
|
@ -213,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);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|