|
|
package com.dsideal.QingLong.Collect.Model;
|
|
|
|
|
|
import cn.hutool.core.date.DateTime;
|
|
|
import cn.hutool.core.io.FileUtil;
|
|
|
import com.dsideal.QingLong.Collect.Const.DataTypeConst;
|
|
|
import com.dsideal.QingLong.Interceptor.IsLoginInterface;
|
|
|
import com.dsideal.QingLong.Util.ChineseCharacterUtil;
|
|
|
import com.dsideal.QingLong.Util.CommonUtil;
|
|
|
import com.jfinal.aop.Before;
|
|
|
import com.jfinal.ext.interceptor.GET;
|
|
|
import com.jfinal.kit.Kv;
|
|
|
import com.jfinal.kit.StrKit;
|
|
|
import com.jfinal.plugin.activerecord.Db;
|
|
|
import com.jfinal.plugin.activerecord.Page;
|
|
|
import com.jfinal.plugin.activerecord.Record;
|
|
|
import com.jfinal.plugin.activerecord.SqlPara;
|
|
|
import org.apache.poi.ss.usermodel.*;
|
|
|
import org.apache.poi.ss.util.CellRangeAddress;
|
|
|
import org.apache.poi.ss.util.CellRangeAddressList;
|
|
|
import org.apache.poi.xssf.usermodel.*;
|
|
|
|
|
|
import java.io.FileInputStream;
|
|
|
import java.io.IOException;
|
|
|
import java.text.ParseException;
|
|
|
import java.text.SimpleDateFormat;
|
|
|
import java.util.*;
|
|
|
|
|
|
public class CollectModel {
|
|
|
/**
|
|
|
* 功能:操作数据库表
|
|
|
*
|
|
|
* @param table_name
|
|
|
*/
|
|
|
public void dropTable(String table_name) {
|
|
|
String sql = "DROP TABLE IF EXISTS " + table_name;
|
|
|
Db.update(sql);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 功能:获取有哪些角色是数据采集自定义上报系统的发布角色
|
|
|
* -- 某人是否有发的角色+有哪些发的角色
|
|
|
*
|
|
|
* @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 int 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);
|
|
|
//任务编号
|
|
|
int job_id = record.getInt("job_id");
|
|
|
|
|
|
//2、保存Sheet表信息
|
|
|
int sheetIdx = 0;
|
|
|
for (Kv kv : kvList) {
|
|
|
String table_name = "ds_job_" + job_id + "_" + sheetIdx;
|
|
|
int sheet_index = kv.getInt("sheet_index");
|
|
|
String sheet_name = kv.getStr("sheet_name");
|
|
|
int start_row = kv.getInt("start_row");
|
|
|
int end_row = kv.getInt("end_row");
|
|
|
int start_column = kv.getInt("start_column");
|
|
|
int end_column = kv.getInt("end_column");
|
|
|
int data_start_row = kv.getInt("data_start_row");
|
|
|
int column_num = kv.getInt("column_num");
|
|
|
sheetIdx++;
|
|
|
|
|
|
Record rSheet = new Record();
|
|
|
rSheet.set("job_id", job_id);
|
|
|
rSheet.set("sheet_index", sheet_index);
|
|
|
rSheet.set("sheet_name", sheet_name);
|
|
|
rSheet.set("is_check", 0);
|
|
|
rSheet.set("table_name", table_name);
|
|
|
rSheet.set("start_row", start_row);
|
|
|
rSheet.set("end_row", end_row);
|
|
|
rSheet.set("start_column", start_column);
|
|
|
rSheet.set("end_column", end_column);
|
|
|
rSheet.set("data_start_row", data_start_row);
|
|
|
rSheet.set("column_num", column_num);
|
|
|
rSheet.set("upload_excel_filename", upload_excel_filename);
|
|
|
Db.save("t_collect_job_sheet", "job_id,sheet_index", rSheet);
|
|
|
}
|
|
|
|
|
|
//3、保存Sheet表中各个列的信息
|
|
|
List<Record> writeList = new ArrayList<>();
|
|
|
sheetIdx = 0;
|
|
|
for (Kv kv : kvList) {
|
|
|
List<Record> list = (List<Record>) kv.get("list");
|
|
|
int colIdx = 0;
|
|
|
for (Record r : list) {
|
|
|
String column_name = r.getStr("column_name");
|
|
|
String memo = r.getStr("memo");
|
|
|
Record writeRecord = new Record();
|
|
|
writeRecord.set("job_id", job_id);
|
|
|
writeRecord.set("sheet_index", sheetIdx);
|
|
|
writeRecord.set("column_index", colIdx);
|
|
|
writeRecord.set("column_name", column_name);
|
|
|
writeRecord.set("original_name", memo);
|
|
|
writeRecord.set("data_type_id", 1);
|
|
|
writeRecord.set("allow_blank", true);
|
|
|
writeRecord.set("options", "");
|
|
|
writeList.add(writeRecord);
|
|
|
colIdx++;
|
|
|
}
|
|
|
sheetIdx++;
|
|
|
}
|
|
|
Db.batchSave("t_collect_job_sheet_col", writeList, 100);
|
|
|
|
|
|
return job_id;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 功能:获取数据类型的数据字典
|
|
|
*
|
|
|
* @return
|
|
|
*/
|
|
|
public List<Record> getDataTypeDict() {
|
|
|
String sql = "select * from t_collect_datatype order by id";
|
|
|
return Db.find(sql);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 功能:根据数据类型id,换算出它在各侧的数据类型描述
|
|
|
*
|
|
|
* @param data_type_id
|
|
|
* @param type_id 1:web_data_type 2:pg_data_type 3:excel_data_type
|
|
|
* @return
|
|
|
*/
|
|
|
public List<Record> listDataTypeDict = null;
|
|
|
|
|
|
public String getDataType(int data_type_id, int type_id) {
|
|
|
if (listDataTypeDict == null) listDataTypeDict = getDataTypeDict();
|
|
|
for (Record record : listDataTypeDict) {
|
|
|
if (record.getInt("id") == data_type_id) {
|
|
|
if (type_id == DataTypeConst.WEB_DATA_TYPE) return record.getStr("web_data_type");
|
|
|
if (type_id == DataTypeConst.PG_DATA_TYPE) return record.getStr("pg_data_type");
|
|
|
if (type_id == DataTypeConst.EXCEL_DATA_TYPE) return record.getStr("excel_data_type");
|
|
|
}
|
|
|
}
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 功能:根据任务ID,获取有哪些Sheet表
|
|
|
*
|
|
|
* @param job_id
|
|
|
*/
|
|
|
public List<Record> getSheets(int job_id) {
|
|
|
String sql = "select * from t_collect_job_sheet where job_id=? order by sheet_index";
|
|
|
return Db.find(sql, job_id);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 功能:获取指定任务+指定 Sheet_index的Sheet相关信息
|
|
|
*
|
|
|
* @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的表结构,也就是列的信息
|
|
|
*
|
|
|
* @param job_id
|
|
|
* @param sheet_index
|
|
|
* @return
|
|
|
*/
|
|
|
public List<Record> getSheetStruct(int job_id, int sheet_index) {
|
|
|
String sql = "select * from t_collect_job_sheet_col where job_id=? and sheet_index=? order by column_index";
|
|
|
return Db.find(sql, job_id, sheet_index);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 功能:保存用户修改后的Sheet表数据信息
|
|
|
*
|
|
|
* @param writeList
|
|
|
*/
|
|
|
public void saveSheet(int job_id, int sheet_index, List<Record> writeList, String table_name) {
|
|
|
if (writeList.size() == 0) return;
|
|
|
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完成
|
|
|
sql = "update t_collect_job_sheet set table_name=?,is_check=1,check_time=? where job_id=? and sheet_index=?";
|
|
|
Db.update(sql, table_name, 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 upload_excel_filename_finish) {
|
|
|
String sql = "update t_collect_job set job_name=?,upload_excel_filename_finish=? where job_id=?";
|
|
|
Db.update(sql, job_name, upload_excel_filename_finish, job_id);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 功能:查询任务信息
|
|
|
*
|
|
|
* @param job_id
|
|
|
* @return
|
|
|
*/
|
|
|
public Record getJob(int job_id) {
|
|
|
String sql = "select * from t_collect_job where job_id=?";
|
|
|
return Db.findFirst(sql, job_id);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 功能:是不是指定任务的所有Sheet全部都确认通过
|
|
|
*
|
|
|
* @param job_id
|
|
|
* @return
|
|
|
*/
|
|
|
public Kv checkAllSheetIsCheck(int job_id) {
|
|
|
Kv kv = Kv.create();
|
|
|
String sql = "select count(1) as c from t_collect_job_sheet where job_id=? and is_check=0";
|
|
|
int c = Db.findFirst(sql, job_id).getInt("c");
|
|
|
if (c > 0) {
|
|
|
kv.set("success", false);
|
|
|
kv.set("message", "存在" + c + "个未确认的Sheet,不能保存任务!");
|
|
|
return kv;
|
|
|
}
|
|
|
kv.set("success", true);
|
|
|
return kv;
|
|
|
}
|
|
|
|
|
|
|
|
|
/**
|
|
|
* 功能:创建表
|
|
|
*
|
|
|
* @return
|
|
|
*/
|
|
|
public Kv createTable(int job_id, int sheet_index) {
|
|
|
Record input = getSheet(job_id, sheet_index);
|
|
|
String table_name = input.getStr("table_name");//数据库表名
|
|
|
//先删除后创建
|
|
|
dropTable(table_name);
|
|
|
|
|
|
//获取数据表结构
|
|
|
List<Record> list = getSheetStruct(job_id, sheet_index);
|
|
|
String sheetName = input.getStr("sheet_name");
|
|
|
String upload_excel_filename = getJob(job_id).getStr("upload_excel_filename");
|
|
|
String colSql = "", commentSql = "";
|
|
|
for (Record record : list) {
|
|
|
String column_name = record.getStr("column_name").toLowerCase();
|
|
|
int data_type_id = record.getInt("data_type_id");
|
|
|
String column_type = getDataType(data_type_id, DataTypeConst.PG_DATA_TYPE);
|
|
|
colSql += column_name + " " + column_type;
|
|
|
String original_name = record.getStr("original_name");
|
|
|
if (record.getBoolean("allow_blank") == null || !record.getBoolean("allow_blank")) colSql += " NOT NULL ";
|
|
|
colSql += ",";
|
|
|
commentSql += "COMMENT ON COLUMN \"public\".\"" + table_name + "\".\"" + column_name + "\" IS '" + original_name + "';\n";
|
|
|
}
|
|
|
String finalSql = "CREATE TABLE \"public\".\"" + table_name + "\" (";
|
|
|
finalSql += "\"id\" serial4,";
|
|
|
finalSql += "\"bureau_id\" char(36) NOT NULL,";
|
|
|
finalSql += "\"person_id\" char(36) NOT NULL,";
|
|
|
finalSql += colSql;
|
|
|
finalSql += "PRIMARY KEY (\"id\")";
|
|
|
finalSql += ");\n";
|
|
|
|
|
|
finalSql += "COMMENT ON COLUMN \"public\".\"" + table_name + "\".\"id\" IS '主键,自增长ID';\n";
|
|
|
finalSql += "COMMENT ON COLUMN \"public\".\"" + table_name + "\".\"bureau_id\" IS '单位ID';\n";
|
|
|
finalSql += "COMMENT ON COLUMN \"public\".\"" + table_name + "\".\"person_id\" IS '上传人员ID';\n";
|
|
|
finalSql += commentSql;
|
|
|
finalSql += "COMMENT ON TABLE \"public\".\"" + table_name + "\" IS '" + sheetName + "';";
|
|
|
//添加索引
|
|
|
finalSql += "CREATE INDEX ON \"public\".\"" + table_name + "\" (\"bureau_id\");";
|
|
|
finalSql += "CREATE INDEX ON \"public\".\"" + table_name + "\" (\"person_id\");";
|
|
|
Db.update(finalSql);
|
|
|
|
|
|
//写入模板与表结构的关系t_collect_mapping
|
|
|
String sql = "delete from t_collect_mapping where table_name=?";
|
|
|
Db.update(sql, table_name);
|
|
|
|
|
|
String sheet_name = input.getStr("sheet_name");
|
|
|
List<Record> writeList = new ArrayList<>();
|
|
|
for (int i = 0; i < list.size(); i++) {
|
|
|
Record record = new Record();
|
|
|
record.set("table_name", table_name);
|
|
|
record.set("column_name", list.get(i).getStr("column_name"));
|
|
|
record.set("excel_column_idx", i);
|
|
|
record.set("original_name", list.get(i).getStr("original_name"));
|
|
|
record.set("allow_blank", list.get(i).getBoolean("allow_blank"));
|
|
|
record.set("column_type", convertDataType(list.get(i).getStr("data_type_id")));
|
|
|
record.set("upload_excel_filename", upload_excel_filename);
|
|
|
record.set("sheet_index", sheet_index);
|
|
|
record.set("sheet_name", sheet_name);
|
|
|
record.set("options", list.get(i).getStr("options"));
|
|
|
writeList.add(record);
|
|
|
}
|
|
|
Db.batchSave("t_collect_mapping", writeList, 100);
|
|
|
|
|
|
//记录模板文件的头文件位置,开始行,结束行,开始列,结束列
|
|
|
sql = "delete from t_collect_job_sheet where upload_excel_filename=? and table_name=?";
|
|
|
Db.update(sql, upload_excel_filename, table_name);
|
|
|
|
|
|
Kv kv = Kv.create();
|
|
|
kv.set("success", true);
|
|
|
kv.set("message", "表结构创建成功!");
|
|
|
return kv;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 功能:PG数据库数据类型与EXCEL中数据类型的转换关系
|
|
|
*
|
|
|
* @param pgColumnDataType
|
|
|
* @return
|
|
|
*/
|
|
|
public String convertDataType(String pgColumnDataType) {
|
|
|
String res = "String";
|
|
|
if (pgColumnDataType.startsWith("varchar")) res = "String";
|
|
|
else if (pgColumnDataType.startsWith("int")) res = "Integer";
|
|
|
else if (pgColumnDataType.startsWith("double")) res = "Double";
|
|
|
else if (pgColumnDataType.startsWith("date")) res = "Date";
|
|
|
return res;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 功能:判断表是不是存在
|
|
|
*
|
|
|
* @param tableName
|
|
|
* @return
|
|
|
*/
|
|
|
public boolean isTableExist(String tableName) {
|
|
|
String sql = "select count(*) as c from pg_class where relname = ?";
|
|
|
return Db.findFirst(sql, tableName).getInt("c") == 1;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 功能:获取指定模板+指定Sheet的全部配置信息
|
|
|
*
|
|
|
* @param upload_excel_filename
|
|
|
* @param sheet_index
|
|
|
* @return
|
|
|
*/
|
|
|
public Record getSheetConfig(String upload_excel_filename, int sheet_index) {
|
|
|
String sql = "select * from t_collect_job_sheet where upload_excel_filename=? and sheet_index=?";
|
|
|
return Db.findFirst(sql, upload_excel_filename, sheet_index);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 功能:获取指定模板+指定Sheet的个数
|
|
|
*
|
|
|
* @param upload_excel_filename
|
|
|
* @return
|
|
|
*/
|
|
|
public int getSheetCount(String upload_excel_filename) {
|
|
|
String sql = "select * from t_collect_job_sheet where upload_excel_filename=?";
|
|
|
List<Record> list = Db.find(sql, upload_excel_filename);
|
|
|
return list.size();
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 功能:获取指定模板+指定Sheet中所有列的限制条件
|
|
|
*
|
|
|
* @param upload_excel_filename
|
|
|
* @param sheet_index
|
|
|
* @return
|
|
|
*/
|
|
|
public List<Record> getSheetMapping(String upload_excel_filename, int 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);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 功能:导入数据
|
|
|
*
|
|
|
* @throws ParseException
|
|
|
*/
|
|
|
public void importData(String upload_excel_filename, XSSFWorkbook wb,
|
|
|
int sheetIdx, String bureau_id, String person_id) throws ParseException {
|
|
|
//读取sheet页
|
|
|
XSSFSheet sheet = wb.getSheetAt(sheetIdx);
|
|
|
//通过表名获取到它的读取起始行,终止列
|
|
|
String sql = "select * from t_collect_job_sheet where upload_excel_filename=? and sheet_index=?";
|
|
|
Record record = Db.findFirst(sql, upload_excel_filename, sheetIdx);
|
|
|
String table_name = record.getStr("table_name");
|
|
|
|
|
|
//先删除
|
|
|
sql = "delete from " + table_name + " where bureau_id=?";
|
|
|
Db.update(sql, bureau_id);
|
|
|
|
|
|
int data_start_row = record.getInt("data_start_row");
|
|
|
int column_num = record.getInt("column_num");
|
|
|
|
|
|
//获取字段与EXCEL列的映射信息
|
|
|
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) {
|
|
|
int excel_column_idx = r.getInt("excel_column_idx");
|
|
|
String column_name = r.getStr("column_name");
|
|
|
String column_type = r.getStr("column_type");
|
|
|
Record rt = new Record();
|
|
|
rt.set("column_name", column_name);
|
|
|
rt.set("column_type", column_type);
|
|
|
_map.put(excel_column_idx, rt);
|
|
|
}
|
|
|
//开始读取数据
|
|
|
List<Record> writeList = new ArrayList<>();
|
|
|
for (int i = data_start_row; i <= sheet.getLastRowNum(); i++) {
|
|
|
//获得行
|
|
|
XSSFRow row = sheet.getRow(i);
|
|
|
|
|
|
//遍历列
|
|
|
if (row != null) {
|
|
|
Record writeRecord = new Record();
|
|
|
writeRecord.set("bureau_id", bureau_id);
|
|
|
writeRecord.set("person_id", person_id);
|
|
|
for (int j = 0; j < column_num; j++) {
|
|
|
XSSFCell cell = row.getCell(j);
|
|
|
String colType = _map.get(j).getStr("column_type");
|
|
|
String colName = _map.get(j).getStr("column_name");
|
|
|
|
|
|
//cell可能是被合并的单元格
|
|
|
if (isMerged(sheet, cell)) {
|
|
|
String value = getValue(cell).toString();
|
|
|
if (StrKit.isBlank(value)) {
|
|
|
for (int k = i - 1; ; k--) {
|
|
|
String prev = getValue(sheet.getRow(k).getCell(j)).toString();
|
|
|
if (!StrKit.isBlank(prev)) {
|
|
|
value = prev;
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
writeRecord.set(colName, value);
|
|
|
} else {
|
|
|
if (colType.equals("Integer"))
|
|
|
writeRecord.set(colName, (int) Double.parseDouble(getValue(cell).toString()));
|
|
|
else if (colType.equals("String"))
|
|
|
writeRecord.set(colName, getValue(cell).toString());
|
|
|
else if (colType.equals("Double"))
|
|
|
writeRecord.set(colName, Double.parseDouble(getValue(cell).toString()));
|
|
|
else if (colType.equals("Date")) {
|
|
|
String dateString = getValue(cell).toString();
|
|
|
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
|
|
|
Date date = dateFormat.parse(dateString);
|
|
|
writeRecord.set(colName, date);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
writeList.add(writeRecord);
|
|
|
}
|
|
|
}
|
|
|
// 写入数据
|
|
|
Db.batchSave(table_name, writeList, 100);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 功能:获取表结构信息
|
|
|
*/
|
|
|
public Kv getTableStruct(XSSFWorkbook wb, int sheetIdx) {
|
|
|
Kv kv = Kv.create();
|
|
|
//读取sheet页
|
|
|
XSSFSheet sheet = wb.getSheetAt(sheetIdx);
|
|
|
//找到表头
|
|
|
List<Integer> _list = getHead(sheet);
|
|
|
//表名称
|
|
|
String sheetName = wb.getSheetName(sheetIdx);
|
|
|
//只允许1行或2行
|
|
|
if (_list.size() == 0 || _list.size() > 2) {
|
|
|
kv.set("success", false);
|
|
|
kv.set("message", "表 “" + sheetName + "” 没有正确设置表头背景色,要求表头可以为一行或两行,不支持更多行数,而且必须背景色是同一种非空白颜色!");
|
|
|
return kv;
|
|
|
}
|
|
|
// 标题,定义为表头上面的部分
|
|
|
Row st = sheet.getRow(_list.get(0) - 1);//下标从0开始
|
|
|
Row ed = sheet.getRow(_list.get(_list.size() - 1) - 1);//下标从0开始
|
|
|
List<Record> list = new ArrayList<>();
|
|
|
|
|
|
String column_name, original_name;
|
|
|
for (int colNum = 0; colNum < ed.getLastCellNum(); colNum++) {
|
|
|
if (StrKit.isBlank(ed.getCell(colNum).toString())) {
|
|
|
original_name = CommonUtil.removeKuoHao(st.getCell(colNum).toString().replace("\n", ""));
|
|
|
column_name = ChineseCharacterUtil.getColumnNameByMemo(CommonUtil.removeKuoHao(st.getCell(colNum).toString()));
|
|
|
Record record = new Record();
|
|
|
record.set("original_name", original_name);
|
|
|
record.set("column_name", column_name);
|
|
|
list.add(record);
|
|
|
} else {
|
|
|
int k = colNum;
|
|
|
while (StrKit.isBlank(st.getCell(k).toString())) k--;
|
|
|
original_name = st.getCell(k).toString().replace("\n", "")
|
|
|
+ "_" + ed.getCell(colNum).toString().replace("\n", "");
|
|
|
column_name = ChineseCharacterUtil.getColumnNameByMemo(CommonUtil.removeKuoHao(st.getCell(k).toString()))
|
|
|
+ "_" + ChineseCharacterUtil.getColumnNameByMemo(CommonUtil.removeKuoHao(ed.getCell(colNum).toString()));
|
|
|
Record record = new Record();
|
|
|
record.set("original_name", original_name);
|
|
|
record.set("column_name", column_name.toLowerCase());
|
|
|
list.add(record);
|
|
|
}
|
|
|
}
|
|
|
kv.set("success", true);
|
|
|
kv.set("message", "表结构获取成功!");
|
|
|
kv.set("list", list);
|
|
|
kv.set("start_row", st.getRowNum());//表头开始行
|
|
|
kv.set("end_row", ed.getRowNum());//表头结束行
|
|
|
kv.set("start_column", 0);//表头开始列
|
|
|
kv.set("end_column", ed.getLastCellNum() - 1);//表头结束列
|
|
|
|
|
|
kv.set("data_start_row", ed.getRowNum() + 1);//真实数据的起始行索引
|
|
|
kv.set("column_num", ed.getLastCellNum());//一共多少列
|
|
|
kv.set("sheet_index", sheetIdx);//Sheet索引号
|
|
|
kv.set("sheet_name", sheetName);//Sheet名称
|
|
|
return kv;
|
|
|
}
|
|
|
|
|
|
|
|
|
/**
|
|
|
* 功能:检查两个EXCEL文件的指定行+指定列是不是内容一致,返回值是不一致的位置集合,位置用数对 Map.Entry<Integer, Integer>描述
|
|
|
*
|
|
|
* @param f1 模板文件
|
|
|
* @param f2 上传文件
|
|
|
* @return 不一样的位置集合
|
|
|
* @throws IOException
|
|
|
*/
|
|
|
public List<Map.Entry<Integer, Integer>> checkYiZhi(String f1, String f2, int sheetIdx) throws IOException {
|
|
|
Record record = getSheetConfig(FileUtil.getName(f1), sheetIdx);
|
|
|
int start_row = record.getInt("start_row");
|
|
|
int end_row = record.getInt("end_row");
|
|
|
int start_column = record.getInt("start_column");
|
|
|
int end_column = record.getInt("end_column");
|
|
|
|
|
|
FileInputStream file1 = new FileInputStream(f1);
|
|
|
FileInputStream file2 = new FileInputStream(f2);
|
|
|
List<Map.Entry<Integer, Integer>> errList = new ArrayList<>();
|
|
|
Workbook wb1 = WorkbookFactory.create(file1);
|
|
|
Workbook wb2 = WorkbookFactory.create(file2);
|
|
|
|
|
|
Sheet sheet1 = wb1.getSheetAt(sheetIdx);
|
|
|
Sheet sheet2 = wb2.getSheetAt(sheetIdx);
|
|
|
|
|
|
for (int i = start_row; i <= end_row; i++) {
|
|
|
Row row1 = sheet1.getRow(i);
|
|
|
Row row2 = sheet2.getRow(i);
|
|
|
for (int j = start_column; j <= end_column; j++) {
|
|
|
Cell cell1 = row1.getCell(j);
|
|
|
Cell cell2 = row2.getCell(j);
|
|
|
if (cell1 != null && cell2 != null) {
|
|
|
if (!cell1.getStringCellValue().equals(cell2.getStringCellValue())) {
|
|
|
Map.Entry<Integer, Integer> pair = new AbstractMap.SimpleEntry<>((i + 1), (j + 1));
|
|
|
errList.add(pair);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
file1.close();
|
|
|
file2.close();
|
|
|
return errList;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* )
|
|
|
* 获取单元格vo
|
|
|
*
|
|
|
* @param cell 单元格
|
|
|
* @return
|
|
|
*/
|
|
|
public String getColor(XSSFCell cell) {
|
|
|
if (cell != null) {
|
|
|
//背景颜色
|
|
|
CellStyle cellStyle = cell.getCellStyle();
|
|
|
XSSFColor xssfColor = (XSSFColor) cellStyle.getFillForegroundColorColor();
|
|
|
byte[] bytes;
|
|
|
if (xssfColor != null) {
|
|
|
bytes = xssfColor.getRGB();
|
|
|
return String.format("#%02X%02X%02X", bytes[0], bytes[1], bytes[2]);
|
|
|
}
|
|
|
}
|
|
|
return "BLANK";
|
|
|
}
|
|
|
|
|
|
|
|
|
/**
|
|
|
* 功能:查找指定Sheet中的表头开始位置与结束位置,目前只支持一个Sheet一个导入模板,并且,只支持单行或双行表头
|
|
|
*
|
|
|
* @param sheet
|
|
|
* @return
|
|
|
*/
|
|
|
public List<Integer> getHead(XSSFSheet sheet) {
|
|
|
List<Integer> list = new ArrayList<>();
|
|
|
//整行都是同一种非空白颜色,视为表头
|
|
|
// 遍历行
|
|
|
for (int i = 0; i <= sheet.getLastRowNum(); i++) {
|
|
|
//获得行
|
|
|
XSSFRow row = sheet.getRow(i);
|
|
|
//遍历列
|
|
|
if (row != null) {
|
|
|
Map<String, Integer> _map = new HashMap<>();
|
|
|
for (int j = 0; j < row.getLastCellNum(); j++) {
|
|
|
//获取单元格
|
|
|
XSSFCell cell = row.getCell(j);
|
|
|
if (cell == null) continue;
|
|
|
String color = getColor(cell);
|
|
|
//记录背景颜色数量
|
|
|
if (_map.containsKey(color))
|
|
|
_map.put(color, _map.get(color) + 1);
|
|
|
else
|
|
|
_map.put(color, 1);
|
|
|
}
|
|
|
if (_map.size() == 1 && _map.entrySet().iterator().next().getKey().startsWith("#")) {
|
|
|
list.add(i + 1);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
return list;
|
|
|
}
|
|
|
|
|
|
|
|
|
/**
|
|
|
* 功能:对于指定Cell中文字进行加红色(*)提醒
|
|
|
*
|
|
|
* @param wb
|
|
|
* @param cell
|
|
|
*/
|
|
|
public void addStar(XSSFWorkbook wb, XSSFCell cell) {
|
|
|
XSSFFont fontRed = wb.createFont();//第一种字体
|
|
|
fontRed.setBold(true);
|
|
|
fontRed.setColor(IndexedColors.RED.getIndex());
|
|
|
fontRed.setFontHeightInPoints((short) 14);
|
|
|
fontRed.setFontName("黑体");
|
|
|
|
|
|
XSSFFont fontBlack = wb.createFont();//第二种字体
|
|
|
fontBlack.setColor(IndexedColors.BLACK.getIndex());
|
|
|
fontBlack.setFontName("宋体");
|
|
|
fontRed.setBold(true);
|
|
|
fontBlack.setFontHeightInPoints((short) 12);
|
|
|
String txt = cell.getStringCellValue();
|
|
|
|
|
|
int len = txt.length();
|
|
|
if (len == 0) {
|
|
|
System.out.println(cell.getSheet().getSheetName());
|
|
|
System.out.println(cell.getRowIndex() + " " + cell.getColumnIndex());
|
|
|
System.out.println(cell.getStringCellValue());
|
|
|
System.out.println("发现问题:" + txt);
|
|
|
System.exit(0);
|
|
|
}
|
|
|
|
|
|
txt += "(*)";
|
|
|
XSSFRichTextString richText = new XSSFRichTextString(txt);//全部文字
|
|
|
|
|
|
richText.applyFont(0, len - 1, fontBlack); // 从第0个字符到第2个字符应用font1
|
|
|
richText.applyFont(len, len + 3, fontRed); // 从第2个字符到第4个字符应用font2
|
|
|
cell.setCellValue(richText);//设置文字
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 功能:给指定单元格加边框
|
|
|
*
|
|
|
* @param wb
|
|
|
* @param cell
|
|
|
*/
|
|
|
public void fillColor(Workbook wb, Cell cell, short colorIdx) {
|
|
|
// 创建单元格样式
|
|
|
CellStyle style = wb.createCellStyle();
|
|
|
style.setAlignment(HorizontalAlignment.CENTER);
|
|
|
style.setVerticalAlignment(VerticalAlignment.CENTER);
|
|
|
style.setBorderTop(BorderStyle.THIN);
|
|
|
style.setBorderBottom(BorderStyle.THIN);
|
|
|
style.setBorderLeft(BorderStyle.THIN);
|
|
|
style.setBorderRight(BorderStyle.THIN);
|
|
|
// 创建字体样式
|
|
|
Font font = wb.createFont();
|
|
|
font.setFontName("宋体");//字体
|
|
|
font.setBold(true);//加粗
|
|
|
font.setFontHeightInPoints((short) 12);//字号
|
|
|
style.setFont(font);
|
|
|
// 设置背景颜色
|
|
|
style.setFillForegroundColor(colorIdx);
|
|
|
style.setFillPattern(FillPatternType.SOLID_FOREGROUND);
|
|
|
// 应用样式到单元格
|
|
|
cell.setCellStyle(style);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 功能:移除所有批注信息
|
|
|
*
|
|
|
* @param sheet
|
|
|
*/
|
|
|
public void RemoveAllComment(XSSFSheet sheet) {
|
|
|
// 遍历所有行和单元格,移除批注
|
|
|
for (Row row : sheet) {
|
|
|
for (Cell cell : row) {
|
|
|
if (cell.getCellComment() != null) {
|
|
|
cell.removeCellComment();
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 功能:将指定Sheet表中所有数据区域进行样式还原
|
|
|
*
|
|
|
* @param wb
|
|
|
* @param sheet
|
|
|
*/
|
|
|
public void resetStyle(XSSFWorkbook wb, XSSFSheet sheet, int dataStartRow) {
|
|
|
// 遍历所有行和单元格,移除批注
|
|
|
for (int row = dataStartRow; row <= sheet.getLastRowNum(); row++) {
|
|
|
for (int col = 0; col < sheet.getRow(row).getLastCellNum(); col++) {
|
|
|
Cell cell = sheet.getRow(row).getCell(col);
|
|
|
fillColor(wb, cell, IndexedColors.WHITE.getIndex());
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 功能:修改指定单元格的样式
|
|
|
*
|
|
|
* @param wb
|
|
|
* @return
|
|
|
*/
|
|
|
public void addComment(Workbook wb, Cell cell, String str) {
|
|
|
Sheet sheet = cell.getSheet();
|
|
|
// 判断单元格上是否存在批注
|
|
|
if (cell.getCellComment() != null) {
|
|
|
// 如果存在批注,先删除
|
|
|
cell.removeCellComment();
|
|
|
}
|
|
|
// 创建批注
|
|
|
Drawing<?> drawing = sheet.createDrawingPatriarch();
|
|
|
CreationHelper factory = wb.getCreationHelper();
|
|
|
ClientAnchor anchor = factory.createClientAnchor();
|
|
|
anchor.setCol1(cell.getColumnIndex());
|
|
|
anchor.setCol2(cell.getColumnIndex() + 2);
|
|
|
anchor.setRow1(cell.getRow().getRowNum());
|
|
|
anchor.setRow2(cell.getRow().getRowNum() + 3);
|
|
|
Comment comment = drawing.createCellComment(anchor);
|
|
|
comment.setString(factory.createRichTextString(str));
|
|
|
// 将批注添加到单元格
|
|
|
cell.setCellComment(comment);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 功能:在EXCEL的指定范围内添加上下拉框,内容通过String[]提供
|
|
|
*
|
|
|
* @param workbook
|
|
|
* @param sheetIdx
|
|
|
* @param firstRow
|
|
|
* @param lastRow
|
|
|
* @param firstCol
|
|
|
* @param lastCol
|
|
|
* @return
|
|
|
*/
|
|
|
public void addValidation(Workbook workbook, int sheetIdx, String options, int firstRow, int lastRow, int firstCol, int lastCol) {
|
|
|
String[] optionArray = options.split(",");
|
|
|
Sheet sheet = workbook.getSheetAt(sheetIdx);
|
|
|
|
|
|
// 删除已有的校验
|
|
|
DataValidationHelper dvHelper = sheet.getDataValidationHelper();
|
|
|
DataValidationConstraint dvConstraint = dvHelper.createCustomConstraint("DELETE_ALL");
|
|
|
CellRangeAddressList addressList = new CellRangeAddressList(0, 0, 0, 0); // 设置一个范围,例如整个表格范围
|
|
|
DataValidation validation = dvHelper.createValidation(dvConstraint, addressList);
|
|
|
validation.setSuppressDropDownArrow(true);
|
|
|
sheet.addValidationData(validation);
|
|
|
|
|
|
// 创建数据验证对象
|
|
|
DataValidationHelper validationHelper = sheet.getDataValidationHelper();
|
|
|
DataValidationConstraint constraint = validationHelper.createExplicitListConstraint(optionArray);
|
|
|
addressList = new CellRangeAddressList(firstRow, lastRow, firstCol, lastCol); // 指定单元格范围
|
|
|
validation = validationHelper.createValidation(constraint, addressList);
|
|
|
// 应用数据验证到单元格
|
|
|
sheet.addValidationData(validation);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 功能:获取指定Cell的内容值
|
|
|
*
|
|
|
* @param cell
|
|
|
* @return
|
|
|
*/
|
|
|
public Object getValue(XSSFCell cell) {
|
|
|
switch (cell.getCellType()) {
|
|
|
case CellType.STRING:
|
|
|
String cellValueString = cell.getStringCellValue();
|
|
|
return cellValueString;
|
|
|
case CellType.NUMERIC:
|
|
|
//日期格式
|
|
|
if (DateUtil.isCellDateFormatted(cell)) {
|
|
|
Date dateValue = cell.getDateCellValue();
|
|
|
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
|
|
|
String formattedDate = sdf.format(dateValue);
|
|
|
return formattedDate;
|
|
|
}
|
|
|
double cellValueNumeric = cell.getNumericCellValue();
|
|
|
return cellValueNumeric;
|
|
|
case CellType.BOOLEAN:
|
|
|
boolean cellValueBoolean = cell.getBooleanCellValue();
|
|
|
return cellValueBoolean;
|
|
|
case CellType.BLANK:
|
|
|
cellValueString = cell.getStringCellValue();
|
|
|
return cellValueString;
|
|
|
// 其他类型的处理
|
|
|
default:
|
|
|
cellValueString = cell.getStringCellValue();
|
|
|
return cellValueString;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 功能:判断一个单元格是不是被合并了
|
|
|
*
|
|
|
* @param sheet
|
|
|
* @return
|
|
|
*/
|
|
|
public boolean isMerged(XSSFSheet sheet, XSSFCell cell) {
|
|
|
// 判断单元格是否被合并
|
|
|
for (CellRangeAddress range : sheet.getMergedRegions()) {
|
|
|
if (cell.getRowIndex() >= range.getFirstRow() && cell.getRowIndex() <= range.getLastRow()
|
|
|
&& cell.getColumnIndex() >= range.getFirstColumn() && cell.getColumnIndex() <= range.getLastColumn()) {
|
|
|
return true;
|
|
|
}
|
|
|
}
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 功能:获取任务列表,支持关键字查询
|
|
|
*
|
|
|
* @param job_name
|
|
|
*/
|
|
|
public Page<Record> getJobList(String job_name, int page, int limit) throws ParseException {
|
|
|
Kv kv = Kv.create();
|
|
|
if (!StrKit.isBlank(job_name)) kv.set("job_name", job_name);
|
|
|
SqlPara sqlPara = Db.getSqlPara("Collect.getJobList", kv);
|
|
|
String sql = sqlPara.getSql();
|
|
|
Page<Record> pageRecord = Db.paginateByFullSql(page, limit, CommonUtil.getTotalSql(sql), sql);
|
|
|
|
|
|
for (Record record : pageRecord.getList()) {
|
|
|
if (record.getInt("job_type") == 1) record.set("job_type_name", "表单");
|
|
|
else if (record.getInt("job_type") == 2) record.set("job_type_name", "EXCEL模板");
|
|
|
|
|
|
if (record.getInt("publish_state") == 1) record.set("publish_state_name", "已发布");
|
|
|
else if (record.getInt("publish_state") == 0) {
|
|
|
record.set("publish_state_name", "待发布");
|
|
|
record.set("fill_progress", "-");
|
|
|
}
|
|
|
// 获取当前时间的毫秒数
|
|
|
long currentTime = System.currentTimeMillis();
|
|
|
|
|
|
Calendar calendar = Calendar.getInstance();
|
|
|
Date deadline_time = record.getDate("deadline_time");
|
|
|
if (deadline_time == null) {
|
|
|
String dateString = "2100-01-01"; // 假设这是你的初始日期字符串
|
|
|
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
|
|
|
deadline_time = dateFormat.parse(dateString);
|
|
|
}
|
|
|
calendar.setTime(deadline_time);
|
|
|
calendar.add(Calendar.DAY_OF_MONTH, 1);
|
|
|
record.set("jiezhi", calendar.getTime().getTime() < currentTime);
|
|
|
|
|
|
if (record.getStr("create_time") != null) {
|
|
|
record.set("create_time", record.getStr("create_time").split(" ")[0]);
|
|
|
} else {
|
|
|
record.set("create_time", "-");
|
|
|
}
|
|
|
if (record.getStr("publish_time") != null) {
|
|
|
record.set("publish_time", record.getStr("publish_time").split(" ")[0]);
|
|
|
} else {
|
|
|
record.set("publish_time", "-");
|
|
|
}
|
|
|
if (record.getStr("deadline_time") != null) {
|
|
|
record.set("deadline_time", record.getStr("deadline_time").split(" ")[0]);
|
|
|
} else {
|
|
|
record.set("deadline_time", "-");
|
|
|
}
|
|
|
}
|
|
|
return pageRecord;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 功能:获取学校类型
|
|
|
*
|
|
|
* @return
|
|
|
*/
|
|
|
public List<Record> getSchoolType() {
|
|
|
SqlPara sqlPara = Db.getSqlPara("Collect.getSchoolType");
|
|
|
return Db.find(sqlPara);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 功能:获取单位类型
|
|
|
*
|
|
|
* @return
|
|
|
*/
|
|
|
public List<Record> getBureauType() {
|
|
|
SqlPara sqlPara = Db.getSqlPara("Collect.getBureauType");
|
|
|
return Db.find(sqlPara);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 市直属下拉框
|
|
|
*
|
|
|
* @return
|
|
|
*/
|
|
|
public List<Record> getShiZhiType() {
|
|
|
SqlPara sqlPara = Db.getSqlPara("Collect.getShiZhiType");
|
|
|
return Db.find(sqlPara);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 功能:获取单位列表
|
|
|
*
|
|
|
* @param org_type_id
|
|
|
* @param school_type_id
|
|
|
* @param level_id
|
|
|
* @param city_id
|
|
|
* @param area_id
|
|
|
* @return
|
|
|
*/
|
|
|
public Page<Record> getBureauList(int org_type_id, int school_type_id,
|
|
|
int level_id, String city_id, String area_id,
|
|
|
int page, int limit) {
|
|
|
Kv kv = Kv.create();
|
|
|
if (org_type_id != -1) kv.set("org_type_id", org_type_id);
|
|
|
if (school_type_id != -1) kv.set("school_type_id", school_type_id);
|
|
|
if (level_id != -1) kv.set("level_id", level_id);
|
|
|
if (!StrKit.isBlank(city_id)) kv.set("city_id", city_id);
|
|
|
if (!StrKit.isBlank(area_id)) kv.set("area_id", area_id);
|
|
|
SqlPara sqlPara = Db.getSqlPara("Collect.getBureauList", kv);
|
|
|
String sql = sqlPara.getSql();
|
|
|
Page<Record> pageRecord = Db.paginateByFullSql(page, limit, CommonUtil.getTotalSql(sql), sql);
|
|
|
return pageRecord;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 功能:发布任务
|
|
|
*
|
|
|
* @param job_id
|
|
|
* @param deadline_time
|
|
|
* @param shiZhiSchool 市直属学校:1选中,0未选中
|
|
|
* @param shiZhiJiaoFu 市直属教辅单位:1选中,0未选中
|
|
|
* @param quXiaoJiaoYuJu 区县教育局:1选中,0未选中
|
|
|
* @param bureauIds 按单位选择的单位ids
|
|
|
*/
|
|
|
public void publishJob(int job_id, String deadline_time, int shiZhiSchool,
|
|
|
int shiZhiJiaoFu, int quXiaoJiaoYuJu, String bureauIds) throws ParseException {
|
|
|
Set<String> bureauSet = new HashSet<>();
|
|
|
if (shiZhiSchool == 1) {
|
|
|
Page<Record> list = getBureauList(9, -1, 1, null, null, 1, 9999);
|
|
|
for (Record record : list.getList()) {
|
|
|
bureauSet.add(record.getStr("org_id"));
|
|
|
}
|
|
|
}
|
|
|
if (shiZhiJiaoFu == 1) {
|
|
|
Page<Record> list = getBureauList(5, -1, 1, null, null, 1, 9999);
|
|
|
for (Record record : list.getList()) {
|
|
|
bureauSet.add(record.getStr("org_id"));
|
|
|
}
|
|
|
}
|
|
|
if (quXiaoJiaoYuJu == 1) {
|
|
|
Page<Record> list = getBureauList(4, -1, 1, null, null, 1, 9999);
|
|
|
for (Record record : list.getList()) {
|
|
|
bureauSet.add(record.getStr("org_id"));
|
|
|
}
|
|
|
}
|
|
|
for (String s : bureauIds.split(",")) {
|
|
|
bureauSet.add(s);
|
|
|
}
|
|
|
//写主表
|
|
|
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
|
|
|
Date date = dateFormat.parse(deadline_time);
|
|
|
String sql = "update t_collect_job set publish_time=now(),publish_state=1,deadline_time=? where job_id=?";
|
|
|
Db.update(sql, date, job_id);
|
|
|
//写任务分派表
|
|
|
List<Record> list = new ArrayList<>();
|
|
|
for (String s : bureauSet) {
|
|
|
Record record = new Record();
|
|
|
record.set("job_id", job_id);
|
|
|
record.set("bureau_id", s);
|
|
|
record.set("is_finish", 0);
|
|
|
list.add(record);
|
|
|
}
|
|
|
Db.batchSave("t_collect_job_bureau", list, 100);
|
|
|
}
|
|
|
} |