diff --git a/WebRoot/Excel/73f90e5f-e534-4db5-977f-2e3a0ee3c0ef.xlsx b/WebRoot/Excel/73f90e5f-e534-4db5-977f-2e3a0ee3c0ef.xlsx new file mode 100644 index 00000000..abb68ee7 Binary files /dev/null and b/WebRoot/Excel/73f90e5f-e534-4db5-977f-2e3a0ee3c0ef.xlsx differ diff --git a/src/main/java/com/dsideal/QingLong/Collect/Model/CollectModel.java b/src/main/java/com/dsideal/QingLong/Collect/Model/CollectModel.java index 79ac1a21..d561665a 100644 --- a/src/main/java/com/dsideal/QingLong/Collect/Model/CollectModel.java +++ b/src/main/java/com/dsideal/QingLong/Collect/Model/CollectModel.java @@ -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 getTableDataByJobId(int job_id, String table_name) { - List 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 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 jobList) { - String sql = "select job_id from t_collect_job where parent_id=?"; - List 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 getTableStructInfo(String table_name) { + public List 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 data = getTableDataByJobId(job_id, table_name); + List 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 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 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 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; + } + /** * 功能:导出Form表单式录入的汇集数据EXCEL * @@ -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 _map = new HashMap<>(); List listStruct = getTableStructInfo(table_name); @@ -2294,7 +2317,7 @@ public class CollectModel { _map.put(idx++, r); } //获取数据 - List data = getTableDataByJobId(job_id, table_name); + List 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 res = new ArrayList<>();