main
黄海 2 years ago
parent e432a9f8e1
commit 895a5e58a4

@ -5,14 +5,13 @@ import cn.hutool.core.date.DateUtil;
import cn.hutool.core.io.FileUtil;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.dsideal.QingLong.Base.Model.BaseModel;
import com.dsideal.QingLong.Classes.Model.ClassModel;
import com.dsideal.QingLong.Collect.Const.DataType;
import com.dsideal.QingLong.Global.Model.GlobalModel;
import com.dsideal.QingLong.LoginPerson.Model.LoginPersonModel;
import com.dsideal.QingLong.Util.ChineseCharacterUtil;
import com.dsideal.QingLong.Util.CommonUtil;
import com.dsideal.QingLong.Util.PoiUtil;
import com.dsideal.QingLong.Util.SessionKit;
import com.jfinal.kit.Kv;
import com.jfinal.kit.StrKit;
import com.jfinal.plugin.activerecord.Db;
@ -2101,34 +2100,11 @@ public class CollectModel {
* @param table_name
* @return
*/
public List<Record> getTableDataByJobId(int job_id, String table_name) {
List<Integer> jobList = new ArrayList<>();
dfsJob(job_id, jobList);
String ids = job_id + ",";
for (Integer x : jobList) {
ids += x + ",";
}
if (ids.length() > 0) ids = ids.substring(0, ids.length() - 1);
String sql = "select * from " + table_name + " where job_id in(" + ids + ")";
public List<Record> getTableDataByJobId(int job_id, String table_name, String bureauIds) {
String sql = "select * from " + table_name + " where job_id ='" + job_id + "' and bureau_id in (" + bureauIds + ")";
return Db.find(sql);
}
/**
* IDS
*
* @param job_id
* @param jobList
*/
public void dfsJob(int job_id, List<Integer> jobList) {
String sql = "select job_id from t_collect_job where parent_id=?";
List<Record> list = Db.find(sql, job_id);
jobList.add(job_id);
for (Record record : list) {
jobList.add(record.getInt("job_id"));
dfsJob(record.getInt("job_id"), jobList);
}
}
/**
*
@ -2136,7 +2112,7 @@ public class CollectModel {
* @param table_name
* @return
*/
public static List<Record> getTableStructInfo(String table_name) {
public List<Record> getTableStructInfo(String table_name) {
String sql = "select col.column_name, col.ordinal_position as o, d.description as column_description from information_schema.columns col join pg_class c on c.relname = col.table_name left join pg_description d on d.objoid = c.oid and d.objsubid = col.ordinal_position where col.table_schema = 'public' and table_name=? order by col.ordinal_position";
return Db.find(sql, table_name);
}
@ -2149,6 +2125,10 @@ public class CollectModel {
* @throws IOException
*/
public void getSummaryExcelForImportExcel(int job_id, int publish_role_id, String filePath) throws IOException { //给定任务编号,获取它有哪些表
Record jobRecord = getJob(job_id);
String bureau_id = jobRecord.getStr("bureau_id");
//下辖单位有哪些
String controlBureauIds = getControlBureauIds(publish_role_id, bureau_id);
// 创建工作簿和工作表
SXSSFWorkbook workbook = new SXSSFWorkbook();//默认100行超100行将写入临时文件
workbook.setCompressTempFiles(false); //是否压缩临时文件,否则写入速度更快,但更占磁盘,但程序最后是会将临时文件删掉的
@ -2179,7 +2159,7 @@ public class CollectModel {
}
//获取数据
List<Record> data = getTableDataByJobId(job_id, table_name);
List<Record> data = getTableDataByJobId(job_id, table_name, controlBureauIds);
Sheet sheet = workbook.createSheet(sheet_name);
// 创建单元格样式对象
CellStyle headerStyle = workbook.createCellStyle();
@ -2267,6 +2247,48 @@ public class CollectModel {
workbook.write(outputStream);
}
/**
*
*
* @param publish_role_id
* @param bureau_id
* @return
*/
public String getControlBureauIds(int publish_role_id, String bureau_id) {
// 1:市 2县区 3单位
int publish_job_type_id = getPublishJobTypeId(publish_role_id);
BaseModel bm = new BaseModel();
Record bureauRecord = bm.getOrgInfoById(bureau_id);
String city_id = bureauRecord.getStr("city_id");
String area_id = bureauRecord.getStr("area_id");
List<String> idList = new ArrayList<>();
String sql;
if (publish_job_type_id == 1) {
//市下所有单位
sql = "select org_id from t_base_organization where city_id=? and org_id=bureau_id";
List<Record> list = Db.find(sql, city_id);
for (Record record : list) {
idList.add(record.getStr("org_id"));
}
} else if (publish_job_type_id == 2) {
//县区下所有单位
sql = "select org_id from t_base_organization where area_id=? and org_id=bureau_id";
List<Record> list = Db.find(sql, area_id);
for (Record record : list) {
idList.add(record.getStr("org_id"));
}
} else {
idList.add(bureau_id);
}
//拼接出单位ids
String bureauIds = "";
for (String s : idList) {
bureauIds += "'"+s + "',";
}
if (bureauIds.length() > 0) bureauIds = bureauIds.substring(0, bureauIds.length() - 1);
return bureauIds;
}
/**
* FormEXCEL
*
@ -2275,9 +2297,10 @@ public class CollectModel {
* @throws IOException
*/
public void getSummaryExcelForFormFill(int job_id, int publish_role_id, String filePath) throws IOException {
//TODO
Record jobRecord = getJob(job_id);
String bureau_id = jobRecord.getStr("bureau_id");
//下辖单位有哪些
String controlBureauIds = getControlBureauIds(publish_role_id, bureau_id);
String table_name = jobRecord.getStr("form_table_name");//表格名称
Map<Integer, Record> _map = new HashMap<>();
List<Record> listStruct = getTableStructInfo(table_name);
@ -2294,7 +2317,7 @@ public class CollectModel {
_map.put(idx++, r);
}
//获取数据
List<Record> data = getTableDataByJobId(job_id, table_name);
List<Record> data = getTableDataByJobId(job_id, table_name, controlBureauIds);
//创建Excel
SXSSFWorkbook workbook = new SXSSFWorkbook();//默认100行超100行将写入临时文件
workbook.setCompressTempFiles(false); //是否压缩临时文件,否则写入速度更快,但更占磁盘,但程序最后是会将临时文件删掉的
@ -2426,7 +2449,7 @@ public class CollectModel {
* @param content
* @return
*/
public static JSONArray parseGridJson(String content) {
public JSONArray parseGridJson(String content) {
JSONArray ja = JSONArray.parseArray(content);
List<JSONObject> res = new ArrayList<>();

Loading…
Cancel
Save