main
黄海 2 years ago
parent 2a4274dce5
commit dff16e56b7

@ -4,4 +4,24 @@
校办干事
长春市第二中学
刘德华 liudehua 123456
刘德华 liudehua 123456
# Q:如何设计才能让指定角色发的统计任务,让哪些指定角色接收到?
select * from t_base_org_type_principalship where name like '%校办干事%'
252,253,254
select * from t_base_org_type_principalship where name like '%资产%'
255
答:需要增加一个关系表,描述哪个角色发的任务,哪些角色可以接收到
t_importexcel_role_map
内容:
255 252 资产管理干事 幼儿园校办干事
255 253 资产管理干事 中小学校办干事
255 254 资产管理干事 职业学校校办干事
结论:
1发的角色可以是多个收的角色只能是一个
2如果某人有多个发的角色那么取第一个如果以后反馈不方便就修改为发现某人有多个发的角色那么让他选择一个。

@ -1,28 +1,102 @@
package com.dsideal.QingLong.Collect.Controller;
import com.YunXiao.Model.BaseModel;
import com.dsideal.QingLong.Collect.Model.CollectModel;
import com.dsideal.QingLong.Interceptor.IsLoginInterface;
import com.dsideal.QingLong.Interceptor.IsSysAdminInterface;
import com.dsideal.QingLong.Util.CommonUtil;
import com.dsideal.QingLong.Util.ExcelUtil;
import com.dsideal.QingLong.Util.SessionKit;
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.plugin.activerecord.Record;
import com.jfinal.kit.Kv;
import com.jfinal.upload.UploadFile;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import java.util.List;
import java.io.*;
import java.net.URISyntaxException;
import java.util.*;
public class CollectController extends Controller {
CollectModel cm = new CollectModel();
/**
* 10
* http://10.10.21.20:9000/QingLong/yunxiao/getTop10
* EXCEL
*/
@Before({GET.class})
@Before({POST.class})
@IsLoginInterface({})
@IsSysAdminInterface({"1"})
public void getTop10() {
public void uoloadTemplate() throws URISyntaxException, IOException {
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);
return;
}
//发布角色,目前写死成第一个,如果以后有用户反馈需要角色切换,就再开发功能进行应对
int publish_role_id = roleList.get(0).getInt("duties_id");
String fileName = excelFile.getFileName();
String suffix = fileName.substring(fileName.lastIndexOf(".") + 1).trim();
if (!suffix.equals("xlsx")) {
renderJson(CommonUtil.returnMessageJson(false, "上传文件类型错误系统只允许上传xlsx格式"));
return;
}
//判断文件大小大于20b则返回错误信息并终止上传删除上传文件
long size = excelFile.getFile().length();
if (size > 1024 * 1024 * 2) {
Map map = new HashMap();
map.put("success", false);
map.put("message", "xlsx文件大小大于2MB,请检查是否正确!");
renderJson(map);
return;
}
String basePath = CommonUtil.getClassPath() + "/Excel";
String upload_excel_filename = UUID.randomUUID().toString().toLowerCase() + ".xlsx";
String templateXls = basePath + "/" + upload_excel_filename;
//判断目录是不是存在
File file = new File(basePath);
if (!file.exists()) {
file.mkdirs();// 创建文件夹
}
excelFile.getFile().renameTo(new File(templateXls));
//检查这个上传的文件是不是合规比如是不是每个Sheet都有浅蓝色背景的表头
//解析上传EXCEL中的每个Sheet解析出表头信息表名描述等信息
InputStream is = new FileInputStream(templateXls);
XSSFWorkbook wb = new XSSFWorkbook(is);
int sheetCount = wb.getNumberOfSheets();//Sheet表数量
Kv kv = Kv.create();
List<Kv> kvList = new ArrayList<>();
for (int i = 0; i < sheetCount; i++) {
try {
Kv kvStruct = ExcelUtil.getTableStruct(wb, i);
if (!kvStruct.getBoolean("success")) {
kv.set("success", false);
kv.set("message", "发现错误:" + kvStruct.getStr("message"));
renderJson(kv);
return;
}
kvStruct.set("upload_excel_filename", upload_excel_filename);
kvList.add(kvStruct);
} catch (Exception err) {
kv.set("success", false);
kv.set("message", "“" + wb.getSheetName(i) + "”表配置错误,请检查后重新上传!");
renderJson(kv);
wb.close();
return;
}
}
//通过后记录新增加了一个任务模板文件共N个模板记录到数据库表中然后提供给前台这些数据信息
cm.addExcelJob(publish_role_id,person_id,kvList,upload_excel_filename);
Map map = new HashMap();
map.put("success", true);
map.put("message", "模板上传成功!");
renderJson(map);
}
}

@ -1,5 +1,46 @@
package com.dsideal.QingLong.Collect.Model;
import cn.hutool.core.date.DateTime;
import com.jfinal.kit.Kv;
import com.jfinal.plugin.activerecord.Db;
import com.jfinal.plugin.activerecord.Record;
import java.util.List;
public class CollectModel {
/**
*
* -- +
*
* @return
*/
public List<Record> getPersonPublishJobRole(String person_id) {
String sql = "select person_id,duties_id from t_person_duty_charge where duties_id in (select publish_role_id from t_collect_role_map group by publish_role_id) and person_id=?";
return Db.find(sql, person_id);
}
/**
*
*
* @param publish_role_id
* @param person_id
* @param kvList
*/
public void addExcelJob(int publish_role_id, String person_id, List<Kv> kvList, String upload_excel_filename) {
//1、保存任务信息
Record record = new Record();
record.set("upload_excel_filename", upload_excel_filename);
record.set("job_name", "未命名任务 " + DateTime.now());
record.set("create_time", DateTime.now());
record.set("person_id", person_id);
record.set("publish_state", 0);
record.set("publish_role_id", publish_role_id);
record.set("job_type", 2);
Db.save("t_collect_job", "job_id", record);
//2、保存Sheet表信息
for (Kv kv : kvList) {
}
}
}

@ -66,8 +66,8 @@ public class ImportExcelKit {
finalSql += "CREATE INDEX ON \"public\".\"" + tableName + "\" (\"person_id\");";
Db.update(finalSql);
//写入模板与表结构的关系t_importexcel_mapping
String sql = "delete from t_importexcel_mapping where table_name=?";
//写入模板与表结构的关系t_collect_mapping
String sql = "delete from t_collect_mapping where table_name=?";
Db.update(sql, tableName);
int sheet_index = input.getInt("sheet_index");
@ -87,10 +87,10 @@ public class ImportExcelKit {
record.set("options", list.get(i).getStr("options"));
writeList.add(record);
}
Db.batchSave("t_importexcel_mapping", writeList, 100);
Db.batchSave("t_collect_mapping", writeList, 100);
//记录模板文件的头文件位置,开始行,结束行,开始列,结束列
sql = "delete from t_importexcel_config where upload_excel_filename=? and table_name=?";
sql = "delete from t_collect_config where upload_excel_filename=? and table_name=?";
Db.update(sql, upload_excel_filename, tableName);
int start_row = input.getInt("start_row");
@ -111,7 +111,7 @@ public class ImportExcelKit {
record.set("sheet_name", sheet_name);
record.set("data_start_row", data_start_row);
record.set("column_num", column_num);
Db.save("t_importexcel_config", "id", record);
Db.save("t_collect_config", "id", record);
Kv kv = Kv.create();
kv.set("success", true);
@ -147,7 +147,7 @@ public class ImportExcelKit {
* @return
*/
public static Record getSheetConfig(String upload_excel_filename, int sheet_index) {
String sql = "select * from t_importexcel_config where upload_excel_filename=? and sheet_index=?";
String sql = "select * from t_collect_config where upload_excel_filename=? and sheet_index=?";
return Db.findFirst(sql, upload_excel_filename, sheet_index);
}
@ -158,7 +158,7 @@ public class ImportExcelKit {
* @return
*/
public static int getSheetCount(String upload_excel_filename) {
String sql = "select * from t_importexcel_config where upload_excel_filename=?";
String sql = "select * from t_collect_config where upload_excel_filename=?";
List<Record> list = Db.find(sql, upload_excel_filename);
return list.size();
}
@ -171,7 +171,7 @@ public class ImportExcelKit {
* @return
*/
public static List<Record> getSheetMapping(String upload_excel_filename, int sheet_index) {
String sql = "select * from t_importexcel_mapping where upload_excel_filename=? and sheet_index=?";
String sql = "select * from t_collect_mapping where upload_excel_filename=? and sheet_index=?";
return Db.find(sql, upload_excel_filename, sheet_index);
}
@ -187,7 +187,7 @@ public class ImportExcelKit {
//读取sheet页
XSSFSheet sheet = wb.getSheetAt(sheetIdx);
//通过表名获取到它的读取起始行,终止列
String sql = "select * from t_importexcel_config where upload_excel_filename=? and sheet_index=?";
String sql = "select * from t_collect_config where upload_excel_filename=? and sheet_index=?";
Record record = Db.findFirst(sql, upload_excel_filename, sheetIdx);
String table_name = record.getStr("table_name");
@ -199,7 +199,7 @@ public class ImportExcelKit {
int column_num = record.getInt("column_num");
//获取字段与EXCEL列的映射信息
sql = "select * from t_importexcel_mapping where upload_excel_filename=? and sheet_index=?";
sql = "select * from t_collect_mapping where upload_excel_filename=? and sheet_index=?";
List<Record> list = Db.find(sql, upload_excel_filename, sheetIdx);
Map<Integer, Record> _map = new HashMap<>();
for (Record r : list) {

Loading…
Cancel
Save