|
|
|
@ -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);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|