main
黄海 2 years ago
parent d0138ce7e5
commit 7c64fc6244

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

@ -1,7 +1,9 @@
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;
@ -10,7 +12,9 @@ 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 {
@ -123,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
*
@ -160,4 +176,47 @@ public class CollectModel {
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