From edc578d6b57d653c748ebaa5607100b1af4c940f Mon Sep 17 00:00:00 2001 From: chengminglong <123204464@qq.com> Date: Tue, 9 Sep 2025 08:13:16 +0800 Subject: [PATCH] =?UTF-8?q?commit=20by=20Kalman.CHENG=20=E2=98=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../WebRoot/component/pear/module/admin.js | 62 +- dsPgBase/WebRoot/login.html | 2 +- .../pear/component/pear/module/admin.js | 3 +- dsPgBase/pom.xml | 2 +- .../dsBase/Collect/Const/DataType.java | 43 - .../Collect/Controller/CollectController.java | 2219 ----------- .../dsBase/Collect/Model/CollectModel.java | 3313 ----------------- .../Controller/DataShareController.java | 308 -- .../DataShare/Model/DataShareModel.java | 390 -- .../StudentImportExcelUtil.java | 1 + .../TeacherImportExcelUtil.java | 3 +- .../Interceptor/IsLoginInterceptor.java | 9 +- .../Interceptor/IsSysAdminInterceptor.java | 5 +- .../Controller/LoginPersonController.java | 7 - .../Organization/Model/OrganizationModel.java | 2 + .../main/java/com/dsideal/dsBase/Start.java | 6 - .../com/dsideal/dsBase/Util/TokenUtil.java | 37 + .../src/main/resources/application.properties | 4 +- .../src/main/resources/undertow.properties | 2 +- 19 files changed, 91 insertions(+), 6327 deletions(-) delete mode 100644 dsPgBase/src/main/java/com/dsideal/dsBase/Collect/Const/DataType.java delete mode 100644 dsPgBase/src/main/java/com/dsideal/dsBase/Collect/Controller/CollectController.java delete mode 100644 dsPgBase/src/main/java/com/dsideal/dsBase/Collect/Model/CollectModel.java delete mode 100644 dsPgBase/src/main/java/com/dsideal/dsBase/DataShare/Controller/DataShareController.java delete mode 100644 dsPgBase/src/main/java/com/dsideal/dsBase/DataShare/Model/DataShareModel.java create mode 100644 dsPgBase/src/main/java/com/dsideal/dsBase/Util/TokenUtil.java diff --git a/dsPgBase/WebRoot/component/pear/module/admin.js b/dsPgBase/WebRoot/component/pear/module/admin.js index f2c30fe3..3491dfd2 100644 --- a/dsPgBase/WebRoot/component/pear/module/admin.js +++ b/dsPgBase/WebRoot/component/pear/module/admin.js @@ -105,38 +105,44 @@ layui.define(['message', 'table', 'jquery', 'element', 'yaml', 'form', 'tab', 'm body.on("click", ".refresh", function () { refresh(); }) - if (isMuiltTab(param) === "true" || isMuiltTab(param) === true) { var indexTabData = {}; - $.ajax({ - type: "GET", - url: "/QingLong/gtzz/getWhiceRole", - async: false, - success: function (res) { - var indexHref = 'html/pages/welcome.html'; - var _id = "indexPage"; + // $.ajax({ + // type: "GET", + // url: "/QingLong/gtzz/getWhiceRole", + // async: false, + // success: function (res) { + // var indexHref = 'html/pages/welcome.html'; + // var _id = "indexPage"; + // + // if (param.other.report) { + // indexHref = 'view/tb/school/task_list_p.html?is_finish=0'; + // _id = "10"; + // } else { + // if (res.role_id == 232) { + // indexHref = 'html/pages/projectManagement/zbzx/index.html'; + // } else if (res.role_id == 234 || res.role_id === 243) { + // indexHref = 'html/pages/projectManagement/xx/index.html'; + // } + // } + // + // indexTabData = { + // id: _id, + // url: indexHref, + // title: param.tab.index.title, + // close: false + // } + // + // } + // }); - if (param.other.report) { - indexHref = 'view/tb/school/task_list_p.html?is_finish=0'; - _id = "10"; - } else { - if (res.role_id == 232) { - indexHref = 'html/pages/projectManagement/zbzx/index.html'; - } else if (res.role_id == 234 || res.role_id === 243) { - indexHref = 'html/pages/projectManagement/xx/index.html'; - } - } - - indexTabData = { - id: _id, - url: indexHref, - title: param.tab.index.title, - close: false - } - - } - }); + indexTabData = { + id: "indexPage", + url: "html/pages/welcome.html", + title: param.tab.index.title, + close: false + } bodyTab = pearTab.render({ elem: 'content', diff --git a/dsPgBase/WebRoot/login.html b/dsPgBase/WebRoot/login.html index 8ffa7256..f5802ee1 100644 --- a/dsPgBase/WebRoot/login.html +++ b/dsPgBase/WebRoot/login.html @@ -32,7 +32,7 @@
-

长春市装备信息管理系统

+

理想智慧大脑基础数据管理系统

diff --git a/dsPgBase/WebRoot/view/hk_old/pear/component/pear/module/admin.js b/dsPgBase/WebRoot/view/hk_old/pear/component/pear/module/admin.js index 7ca48fc9..da729a46 100644 --- a/dsPgBase/WebRoot/view/hk_old/pear/component/pear/module/admin.js +++ b/dsPgBase/WebRoot/view/hk_old/pear/component/pear/module/admin.js @@ -106,7 +106,8 @@ layui.define(['message', 'table', 'jquery', 'element', 'yaml', 'form', 'tab', 'm refresh(); }) - if (isMuiltTab(param) === "true" || isMuiltTab(param) === true) { + // if (isMuiltTab(param) === "true" || isMuiltTab(param) === true) { + if (isMuiltTab(param) === "false" || isMuiltTab(param) === false) { var indexTabData = {}; $.ajax({ diff --git a/dsPgBase/pom.xml b/dsPgBase/pom.xml index 6b9be5ac..b0b56cc4 100644 --- a/dsPgBase/pom.xml +++ b/dsPgBase/pom.xml @@ -37,7 +37,7 @@ 4.4.16 42.7.7 2.13.1 - 2.14.0 + 2.19.0 1.5 3.12.0 2.1.4 diff --git a/dsPgBase/src/main/java/com/dsideal/dsBase/Collect/Const/DataType.java b/dsPgBase/src/main/java/com/dsideal/dsBase/Collect/Const/DataType.java deleted file mode 100644 index f79aa16b..00000000 --- a/dsPgBase/src/main/java/com/dsideal/dsBase/Collect/Const/DataType.java +++ /dev/null @@ -1,43 +0,0 @@ -package com.dsideal.dsBase.Collect.Const; - -import com.alibaba.fastjson.JSONObject; - -public class DataType { - - public static final int WEB_DATA_TYPE = 1; //前台看到的数据类型 - public static final int PG_DATA_TYPE = 2;//postgresql数据库侧的数据类型 - public static final int EXCEL_DATA_TYPE = 3;//excel侧的数据类型 - - /** - * 1:文本 2:数字 3:小数 4:日期 - * textarea:不传fieldType,默认是文本 - * select:不传fieldType,默认是数字 - * radio:不传fieldType,默认是数字 - * checkbox:不传fieldType,默认是文本 - * date:不传fieldType,默认是日期 - * rate:不传fieldType,默认是数字 - * image:不传fieldType,默认是文本 - * file:不传fieldType,默认是文本 - * blockquote:为布局组件,不用设置为字段 - * line:为布局组件,不用设置为字段 - * input:需要参照fieldType,1,2,3进行设置字段类型 - * - * @param jo - * @return - */ - public static int getFormDataType(JSONObject jo) { - String tag = jo.getString("tag"); - if (tag.equals("textarea")) return 1; - if (tag.equals("select")) return 1; - if (tag.equals("radio")) return 1; - if (tag.equals("checkbox")) return 1; - if (tag.equals("date")) return 4; - if (tag.equals("rate")) return 2; - if (tag.equals("image")) return 1; - if (tag.equals("file")) return 1; - if (tag.equals("blockquote")) return 0; - if (tag.equals("line")) return 0; - if (tag.equals("input")) return jo.getInteger("fieldType"); - return 1; - } -} diff --git a/dsPgBase/src/main/java/com/dsideal/dsBase/Collect/Controller/CollectController.java b/dsPgBase/src/main/java/com/dsideal/dsBase/Collect/Controller/CollectController.java deleted file mode 100644 index c51c792d..00000000 --- a/dsPgBase/src/main/java/com/dsideal/dsBase/Collect/Controller/CollectController.java +++ /dev/null @@ -1,2219 +0,0 @@ -package com.dsideal.dsBase.Collect.Controller; - -import cn.hutool.core.io.FileUtil; -import com.alibaba.fastjson.JSONArray; -import com.alibaba.fastjson.JSONObject; -import com.dsideal.dsBase.Base.Model.BaseModel; -import com.dsideal.dsBase.Collect.Const.DataType; -import com.dsideal.dsBase.Collect.Model.CollectModel; -import com.dsideal.dsBase.Handler.RepeatIntercetpor; -import com.dsideal.dsBase.Interceptor.EmptyInterface; -import com.dsideal.dsBase.Interceptor.IsLoginInterface; -import com.dsideal.dsBase.Interceptor.IsNumericInterface; -import com.dsideal.dsBase.Interceptor.LayUiPageInfoInterface; -import com.dsideal.dsBase.LoginPerson.Model.LoginPersonModel; -import com.dsideal.dsBase.Util.*; -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.kit.Kv; -import com.jfinal.kit.PropKit; -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.upload.UploadFile; -import org.apache.pdfbox.Loader; -import org.apache.pdfbox.pdmodel.PDDocument; -import org.apache.pdfbox.pdmodel.PDDocumentInformation; -import org.apache.poi.openxml4j.util.ZipSecureFile; -import org.apache.poi.ss.usermodel.*; -import org.apache.poi.ss.util.CellRangeAddress; -import org.apache.poi.xssf.usermodel.*; - -import javax.servlet.http.HttpServletResponse; -import java.io.*; -import java.net.URLEncoder; -import java.sql.*; -import java.text.ParseException; -import java.util.*; - -public class CollectController extends Controller { - CollectModel cm = new CollectModel(); - BaseModel bm = new BaseModel(); - LoginPersonModel personModel = new LoginPersonModel(); - - /** - * 功能:个人用户填报登录入口,支持天喻对接版本与未对接版本 - * http://10.10.21.20:9000/QingLong/collect/login - */ - public void login() { - if (cm.IS_THIRD_PARTY() == 0) { - redirect("/plogin.html"); - } else { - redirect("https://space.ccsjy.cn/manage/account/login?login_cas_id=35e6ebf6a93f11eea5f9be51404f227d"); - } - } - - /********以下为EXCEL模板上传管理功能****************************************************** - /** - * EXCEL原始模板上传 - */ - @Before({POST.class, RepeatIntercetpor.class}) - @IsLoginInterface({}) - public void uploadTemplate() throws IOException { - UploadFile excelFile = getFile();//得到文件对象 - //操作人员 - String person_id = SessionKit.get(getRequest(), getResponse(), "person_id"); - //根据人员ID,获取人员所在的单位ID - Record rs = personModel.getLoginInfoByPersonId(person_id); - String bureau_id = rs.get("bureau_id"); - - //检查当前登录人员是不是发布任务的角色 - Kv kvCheck = cm.checkPublishRole(person_id); - if (!kvCheck.getBoolean("success")) { - renderJson(kvCheck); - return; - } - //获取登录人员第一个发布任务的角色是什么 - int publish_role_id = kvCheck.getInt("publish_role_id"); - - String fileName = excelFile.getFileName(); - String suffix = fileName.substring(fileName.lastIndexOf(".") + 1).trim(); - if (!suffix.equals("xlsx")) { - renderJson(CommonUtil.returnMessageJson(false, "上传文件类型错误!系统只允许上传xlsx格式!")); - return; - } - //判断文件大小大于2mb则返回错误信息,并终止上传,删除上传文件 - 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 upload_excel_filename = UUID.randomUUID().toString().toLowerCase() + ".xlsx"; - String templateXls =CommonUtil.basePath + "/" + upload_excel_filename; - 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 kvList = new ArrayList<>(); - for (int i = 0; i < sheetCount; i++) { - try { - Kv kvStruct = cm.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个模板,记录到数据库表中,然后提供给前台这些数据信息 - int job_id = cm.addExcelJob(publish_role_id, bureau_id, person_id, kvList, upload_excel_filename); - Map map = new HashMap<>(); - map.put("job_id", job_id); - map.put("success", true); - map.put("message", "模板上传成功!"); - renderJson(map); - } - - /** - * 功能:根据任务ID,获取有哪些Sheet表 - * - * @param job_id - */ - @Before({GET.class}) - @IsLoginInterface({}) - @IsNumericInterface({"job_id"}) - public void getSheets(int job_id) { - List list = cm.getSheets(job_id); - renderJson(CommonUtil.renderJsonForLayUI(list)); - } - - /** - * 功能:获取指定Sheet的表结构,也就是列的信息 - * - * @param job_id - * @param sheet_index - * @return - */ - @Before({GET.class}) - @IsLoginInterface({}) - @IsNumericInterface({"job_id", "sheet_index"}) - public void getSheetStruct(int job_id, int sheet_index) { - //获取数据表的整体配置信息 - Record record = cm.getSheet(job_id, sheet_index); - List list = cm.getSheetStruct(job_id, sheet_index); - Map _map = CommonUtil.renderJsonForLayUI(list); - _map.put("table_name", record.getStr("table_name")); - renderJson(_map); - } - - /** - * 功能:获取数据类型下拉列表 - */ - @Before({GET.class}) - @IsLoginInterface({}) - public void getDataTypeDict() { - List list = cm.getDataTypeDict(); - renderJson(CommonUtil.renderJsonForLayUI(list)); - } - - /** - * 功能:保存Sheet属性 - */ - @Before({POST.class, RepeatIntercetpor.class}) - @IsNumericInterface({"job_id", "sheet_index"}) - @EmptyInterface({"json", "table_name"}) - @IsLoginInterface({}) - public void saveSheet(int job_id, int sheet_index, String json, String table_name) { - boolean isMatch = table_name.matches("[a-z][a-z0-9_]*"); - if (!isMatch) { - Map map = new HashMap<>(); - map.put("success", false); - map.put("message", "字符串包含其他字符或第一个字符不是小写字母"); - renderJson(map); - return; - } - if (!table_name.startsWith("ds_")) { - Map map = new HashMap<>(); - map.put("success", false); - map.put("message", "数据库表名必须以ds_开头!"); - renderJson(map); - } - //操作人员 - 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); - } catch (Exception err) { - Kv kv = Kv.create(); - kv.set("success", false); - kv.set("message", "上报的json数据格式不正确,请检查后重传!"); - renderJson(kv); - return; - } - String old_table_name = cm.getSheet(job_id, sheet_index).getStr("table_name"); - if (old_table_name != null && !old_table_name.equals(table_name) && cm.isTableExist(table_name)) { - Kv kv = Kv.create(); - kv.set("success", false); - kv.set("message", "表名" + table_name + "已存在,不能保存!"); - renderJson(kv); - return; - } - - - //检查字段名称 - String errMsg = ""; - int idx = 1; - - Map countMap = new HashMap<>(); - for (Object o : ja) { - JSONObject jo = (JSONObject) o; - String column_name = jo.getString("column_name"); - - if (StrKit.isBlank(column_name)) { - errMsg += "第" + idx + "列的列名为空!\n"; - continue; - } - if (column_name.length() > 32) { - errMsg += "第" + idx + "列的列名长度大于32位!\n"; - continue; - } - if (!column_name.matches("[a-z][a-z0-9_]*")) { - errMsg += "第" + idx + "列的列名只能是小写字母或者数字、下划线,并且列名不能以数字开头!\n"; - continue; - } - idx++; - - if (countMap.containsKey(column_name)) { - countMap.put(column_name, countMap.get(column_name) + 1); - } else { - countMap.put(column_name, 1); - } - } - if (!StrKit.isBlank(errMsg)) { - Map map = new HashMap<>(); - map.put("success", false); - map.put("message", errMsg); - renderJson(map); - return; - } - boolean flag = false; - String congFu = ""; - for (Map.Entry entry : countMap.entrySet()) { - if (entry.getValue() > 1) { - congFu += entry.getKey() + ","; - flag = true; - } - } - if (flag) { - congFu = congFu.substring(0, congFu.length() - 1); - Kv kv = Kv.create(); - kv.set("success", false); - kv.set("message", "列名" + congFu + "存在重复,不能保存!"); - renderJson(kv); - return; - } - - //保存 - List writeList = new ArrayList<>(); - for (Object o : ja) { - JSONObject jo = (JSONObject) o; - int column_index = jo.getInteger("column_index"); - int data_type_id = jo.getInteger("data_type_id"); - String column_name = jo.getString("column_name"); - String original_name = jo.getString("original_name"); - boolean allow_blank = jo.getBoolean("allow_blank"); - - int readonly = 0; - if (jo.containsKey("readonly")) readonly = jo.getInteger("readonly"); - String options = jo.getString("options"); - Record record = new Record(); - record.set("job_id", job_id); - record.set("sheet_index", sheet_index); - record.set("column_index", column_index); - record.set("data_type_id", data_type_id); - record.set("column_name", column_name); - record.set("original_name", original_name); - record.set("allow_blank", allow_blank); - record.set("options", options); - record.set("readonly", readonly); - writeList.add(record); - } - cm.saveSheet(job_id, sheet_index, writeList, table_name); - Map map = new HashMap<>(); - map.put("success", true); - map.put("message", "保存成功!"); - renderJson(map); - } - - /** - * 功能:保存任务并建表 - * - * @param job_id - */ - @Before({POST.class, RepeatIntercetpor.class}) - @IsLoginInterface({}) - @IsNumericInterface({"job_id"}) - @EmptyInterface({"job_name"}) - public void saveJob(int job_id, String job_name) throws IOException { - //操作人员 - String person_id = SessionKit.get(getRequest(), getResponse(), "person_id"); - //检查当前登录人员是不是发布任务的角色 - Kv kvCheck = cm.checkPublishRole(person_id); - if (!kvCheck.getBoolean("success")) { - renderJson(kvCheck); - return; - } - //检查所有表是不是全部is_check=1 - Kv kvAllCheck = cm.checkAllSheetIsCheck(job_id); - if (!kvAllCheck.getBoolean("success")) { - renderJson(kvAllCheck); - return; - } - List listJobSheet = cm.getSheets(job_id); - //检查是不是某张表中存在字段名称重复的情况 - for (int i = 0; i < listJobSheet.size(); i++) { - if (cm.checkColumnNameDuplicate(job_id, i)) { - Map map = new HashMap<>(); - map.put("success", false); - map.put("message", "第" + (i + 1) + "个Sheet表中存在字段名称重复的情况,请检查后重新保存!"); - renderJson(map); - return; - } - } - - //检查通过,处理建表逻辑 - for (int i = 0; i < listJobSheet.size(); i++) cm.createTable(job_id, i);//创建表 - - //检查是不是需要对指定列进行加红星+Comment操作 - //操作源文件,拷贝出来,生成系统可以下发的模板 - Record jobRecord = cm.getJob(job_id); - - String upload_excel_filename = jobRecord.getStr("upload_excel_filename");//原始模板文件 - - String upload_excel_filename_finish = UUID.randomUUID().toString().toLowerCase() + ".xlsx";//系统中可以提供下载的模板文件 - FileUtil.copy(CommonUtil.basePath + File.separator + upload_excel_filename, CommonUtil.basePath + File.separator + upload_excel_filename_finish, true); - - InputStream is = new FileInputStream(CommonUtil.basePath + File.separator + upload_excel_filename_finish); - XSSFWorkbook wb = new XSSFWorkbook(is); - for (int i = 0; i < listJobSheet.size(); i++) { - Record sheetRecord = listJobSheet.get(i); - int start_row = sheetRecord.getInt("start_row"); - int end_row = sheetRecord.getInt("end_row"); - List list = cm.getSheetStruct(job_id, i); - - int colIdx = 0; - for (Record record : list) { - boolean allow_blank = record.getBoolean("allow_blank"); - XSSFCell cell = wb.getSheetAt(i).getRow(end_row).getCell(colIdx); - - if (!allow_blank) { - //一行时,星号加在一行 - //二行时,星号加在二行 - if (StrKit.isBlank(cell.getStringCellValue())) { - cell = wb.getSheetAt(i).getRow(start_row).getCell(colIdx); - } - PoiUtil.addStar(wb, cell); - PoiUtil.addComment(wb, cell, "此列内容必须输入!"); - } - - int data_type_id = record.getInt("data_type_id"); - if (data_type_id == 2) { - if (!allow_blank) PoiUtil.addComment(wb, cell, "此列内容必须输入,并且需要输入整数!"); - else PoiUtil.addComment(wb, cell, "此列需要输入整数!"); - } - if (data_type_id == 3) { - if (!allow_blank) { - PoiUtil.addComment(wb, cell, "此列内容必须输入,并且需要输入小数!"); - } else { - PoiUtil.addComment(wb, cell, "此列需要输入小数!"); - } - } - if (data_type_id == 4) { - if (!allow_blank) { - PoiUtil.addComment(wb, cell, "此列内容必须输入,并且需要输入日期,格式为yyyy/mm/dd!"); - } else { - PoiUtil.addComment(wb, cell, "此列需要输入日期,格式为yyyy/mm/dd!"); - } - } - colIdx++; - } - } - //检查是不是需要对于指定的Sheet+指定的列生成下拉框 - for (int i = 0; i < listJobSheet.size(); i++) { - Record sheetRecord = listJobSheet.get(i); - int data_start_row = sheetRecord.getInt("data_start_row"); - List list = cm.getSheetStruct(job_id, i); - int colIdx = 0; - for (Record record : list) { - String options = record.getStr("options"); - if (!StrKit.isBlank(options)) { - PoiUtil.addValidation(wb, i, options, data_start_row, data_start_row + 20000, colIdx, colIdx);//范围 - } - //1 文本 - //2 数值 - //4 日期(年-月-日) - //3 数值(小数) - int data_type_id = record.getInt("data_type_id"); - if (data_type_id == 2) { - PoiUtil.setIntegerStyle(wb, i, colIdx, data_start_row, data_start_row + 20000); - } - if (data_type_id == 3) { - PoiUtil.setFloatStyle(wb, i, colIdx, data_start_row, data_start_row + 20000); - } - if (data_type_id == 4) { - PoiUtil.setDateStyle(wb, i, colIdx, data_start_row, data_start_row + 20000); - } - colIdx++; - } - } - - // 取消每一个表单的激活状态 - for (int i = 0; i < listJobSheet.size(); i++) wb.getSheetAt(i).setSelected(false); - // 设置活动表单为第一个表单 - wb.setActiveSheet(0); - - //保存 - FileOutputStream fileOut = new FileOutputStream(CommonUtil.basePath + File.separator + upload_excel_filename_finish); - wb.write(fileOut); - //关闭Excel - wb.close(); - - //保存任务名称 - cm.saveJob(job_id, job_name, upload_excel_filename_finish); - - //返回成功 - Map map = new HashMap<>(); - map.put("success", true); - map.put("message", "保存成功!"); - renderJson(map); - } - - /** - * 功能:重命名任务 - * - * @param job_id - * @param job_name - */ - @Before({POST.class, RepeatIntercetpor.class}) - @IsLoginInterface({}) - @IsNumericInterface({"job_id"}) - @EmptyInterface({"job_name"}) - public void renameJob(int job_id, String job_name) { - cm.renameJob(job_id, job_name); - Map map = new HashMap<>(); - map.put("success", true); - map.put("message", "保存成功!"); - renderJson(map); - } - - /** - * 功能:删除任务 - * - * @param job_id - */ - @Before({POST.class, RepeatIntercetpor.class}) - @IsLoginInterface({}) - @IsNumericInterface({"job_id"}) - public void delJob(int job_id) { - //已发布,并且有人填写的不能删除 - Record record = cm.getJob(job_id); - if (record == null) { - Map map = new HashMap<>(); - map.put("success", true); - map.put("message", "保存成功!"); - renderJson(map); - return; - } -// int publish_state = record.getInt("publish_state"); -// if (publish_state == 1) { -// int is_finish_count = 0; -// List list = cm.getJobFill(job_id); -// for (Record r : list) { -// if (r.getInt("is_finish") == 1) is_finish_count++; -// } -// if (is_finish_count > 0) { -// Map map = new HashMap<>(); -// map.put("success", false); -// map.put("message", "任务已发布,并且存在填报记录,无法删除!"); -// renderJson(map); -// return; -// } -// } - cm.delJob(job_id); - Map map = new HashMap<>(); - map.put("success", true); - map.put("message", "保存成功!"); - renderJson(map); - } - - /** - * 功能:用户导入数据 - */ - @Before({POST.class, RepeatIntercetpor.class}) - @IsLoginInterface({}) - public void importData() throws IOException, ParseException { - // 延迟解析比率 - ZipSecureFile.setMinInflateRatio(-1.0d); - UploadFile excelFile = getFile();//得到文件对象 - int job_id = getInt("job_id"); - if (get("status_code") == null) { - Kv kv = Kv.create(); - kv.set("success", false); - kv.set("message", "status_code必须是4位整数!"); - renderJson(kv); - return; - } - int status_code = getInt("status_code"); - //操作人员 - String person_id = SessionKit.get(getRequest(), getResponse(), "person_id"); - //根据人员ID,获取人员所在的单位ID - Record rs = personModel.getLoginInfoByPersonId(person_id); - String bureau_id = rs.get("bureau_id");//单位ID - String person_name = rs.getStr("person_name");//人员姓名 - String bureau_name = bm.getOrgInfoById(bureau_id).getStr("org_name");//单位名称 - - 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 * 20) { - Map map = new HashMap<>(); - map.put("success", false); - map.put("message", "xlsx文件大小大于20MB,请检查是否正确!"); - renderJson(map); - return; - } - String upload_excel_filename_user = UUID.randomUUID().toString().toLowerCase() + ".xlsx"; - excelFile.getFile().renameTo(new File(CommonUtil.basePath + File.separator + upload_excel_filename_user)); - - Record jobRecord = cm.getJob(job_id); - String upload_excel_filename_finish = jobRecord.getStr("upload_excel_filename_finish");//系统生成的模板文件 - //我提供的模板文件 - String f1 = CommonUtil.basePath + File.separator + upload_excel_filename_finish; - //用户上传的填充完的EXCEL文件 - String f2 = CommonUtil.basePath + File.separator + upload_excel_filename_user; - - //对比两个EXCEL文件 是不是格式一致,也就是是不是上传了正确的模板文件 - int sheetCnt = cm.getSheetCount(upload_excel_filename_finish); - for (int i = 0; i < sheetCnt; i++) { - List> chayi = cm.checkYiZhi(f1, f2, i); - if (chayi.size() > 0) { - Kv kv = Kv.create(); - kv.set("success", false); - kv.set("message", "第" + (i + 1) + "个Sheet表检查过程中发现与要求上传的模板不一致,请重新下载模板填写完成后再次上传!"); - kv.set("upload_excel_filename_user", upload_excel_filename_user); - renderJson(kv); - return; - } - } - //打开EXCEL,进行检查 - InputStream is = new FileInputStream(f2); - XSSFWorkbook wb = new XSSFWorkbook(is); - - //遍历每个Sheet注册好的信息,对用户上传的数据表进行检查 - boolean flag = true; - List blankSheet = new ArrayList<>(); - for (int i = 0; i < sheetCnt; i++) {//表 - //Sheet表 - XSSFSheet sheet = wb.getSheetAt(i); - //移除所有批注 - PoiUtil.RemoveAllComment(sheet); - //数据起始行 - Record r = cm.getSheetConfig(upload_excel_filename_finish, i); - int data_start_row = r.getInt("data_start_row"); - //恢复背景色 - PoiUtil.resetStyle(sheet, data_start_row); - - //数据有效行数 - int lastRowNum = sheet.getLastRowNum(); - if (data_start_row > lastRowNum) blankSheet.add(i); - //遍历每一列 - List list = cm.getSheetMapping(upload_excel_filename_finish, i); - for (Record record : list) {//列 - int excel_column_idx = record.getInt("excel_column_idx");//第几列 - String column_type = record.getStr("column_type");//类型 - String options = record.getStr("options");//下拉框内容 - boolean allow_blank = record.getBoolean("allow_blank");//是不是允许为空 - - if (!allow_blank) { - // 非空项目未填写 - for (int j = data_start_row; j <= lastRowNum; j++) {//行 - XSSFCell cell = sheet.getRow(j).getCell(excel_column_idx); - if (StrKit.isBlank(PoiUtil.getValue(cell).toString())) { - PoiUtil.addComment(wb, cell, "此处不能为空!"); - PoiUtil.changeColor(cell, IndexedColors.YELLOW.getIndex()); - flag = false; - } - } - } - // 下拉列表不是从下拉列表中选择的 - if (!StrKit.isBlank(options)) { - for (int j = data_start_row; j <= lastRowNum; j++) {//行 - XSSFCell cell = sheet.getRow(j).getCell(excel_column_idx); - String value = PoiUtil.getValue(cell).toString(); - if (StrKit.isBlank(value)) value = "&*^&Y&*(&*(&*()*("; - if (options.indexOf(value) < 0) { - PoiUtil.addComment(wb, cell, "未从指定范围内选择有效值!"); - PoiUtil.changeColor(cell, IndexedColors.YELLOW.getIndex()); - flag = false; - } - } - } - - // 检查数据类型是不是和规定的不兼容 - for (int j = data_start_row; j <= lastRowNum; j++) {//行 - XSSFCell cell = sheet.getRow(j).getCell(excel_column_idx); - Object obj = PoiUtil.getValue(cell); - if (allow_blank && StrKit.isBlank(obj.toString())) continue; - if (column_type.equals("Integer") && !CommonUtil.isInteger(obj.toString())) {//要求整数,实际不是整数 - PoiUtil.addComment(wb, cell, "要求是整数,实际数据类型不是整数!"); - PoiUtil.changeColor(cell, IndexedColors.YELLOW.getIndex()); - flag = false; - } else if (column_type.equals("Double") && !CommonUtil.isDouble(obj.toString())) {//要求是浮点数,实际不是浮点数 - PoiUtil.addComment(wb, cell, "要求是小数,实际数据类型不是小数!"); - PoiUtil.changeColor(cell, IndexedColors.YELLOW.getIndex()); - flag = false; - } else if (column_type.equals("Date")) {//要求是日期,实际不是日期 - if (!CommonUtil.isDate(obj.toString())) { - PoiUtil.addComment(wb, cell, "要求是日期格式,实际数据类型不是日期格式!"); - PoiUtil.changeColor(cell, IndexedColors.YELLOW.getIndex()); - flag = false; - } - } - } - } - } - - // 取消每一个表单的激活状态 - for (int i = 0; i < sheetCnt; i++) wb.getSheetAt(i).setSelected(false); - - // 设置活动表单为第一个表单 - wb.setActiveSheet(0); - - //保存文件 - FileOutputStream fileOut = new FileOutputStream(f2); - wb.write(fileOut); - - if (!blankSheet.isEmpty()) { - StringBuilder t = new StringBuilder(); - for (Integer i : blankSheet) t.append(i).append(","); - t = new StringBuilder(t.substring(0, t.length() - 1)); - Kv kv = Kv.create(); - kv.set("success", false); - kv.set("message", "检查到输入的文件中存在空的Sheet表,序号为" + t + ",请下载文件后查看处理后,重新上传!"); - kv.set("upload_excel_filename_user", upload_excel_filename_user); - renderJson(kv); - //关闭Excel - wb.close(); - return; - } - - if (!flag) { - Kv kv = Kv.create(); - kv.set("success", false); - kv.set("message", "检查到输入的文件中存在不合法情况,请下载文件后查看处理后,重新上传!"); - kv.set("upload_excel_filename_user", upload_excel_filename_user); - renderJson(kv); - //关闭Excel - wb.close(); - return; - } - // 检查通过,导入数据 - for (int i = 0; i < sheetCnt; i++) - cm.importData(job_id, upload_excel_filename_finish, wb, i, bureau_id, bureau_name, person_id, person_name); - - //回写完成标记 - cm.writeJobFinish(job_id, status_code, bureau_id, upload_excel_filename_user); - - //关闭Excel - wb.close(); - Kv kv = Kv.create(); - kv.set("success", true); - kv.set("message", "所有数据成功导入!"); - renderJson(kv); - } - - /** - * 功能:获取任务列表,支持关键字查询 - */ - @Before({GET.class}) - @IsLoginInterface({}) - @IsNumericInterface({"self_or_next"}) - public void getJobList(String job_name, int self_or_next, int page, int limit) throws ParseException { - //操作人员 - String person_id = SessionKit.get(getRequest(), getResponse(), "person_id"); - //检查当前登录人员是不是发布任务的角色 - Kv kvCheck = cm.checkPublishRole(person_id); - if (!kvCheck.getBoolean("success")) { - renderJson(kvCheck); - return; - } - //根据人员ID,获取人员所在的单位ID - Record rs = personModel.getLoginInfoByPersonId(person_id); - String bureau_id = rs.get("bureau_id"); - - //获取登录人员第一个发布任务的角色是什么 - int publish_role_id = kvCheck.getInt("publish_role_id"); - Page list = cm.getJobList(bureau_id, publish_role_id, job_name, self_or_next, page, limit); - renderJson(CommonUtil.renderJsonForLayUI(list)); - } - - /** - * 功能:获取单位类型 - * - * @return - */ - @Before({GET.class}) - @IsLoginInterface({}) - public void getBureauType() { - List list = cm.getBureauType(); - renderJson(CommonUtil.renderJsonForLayUI(list)); - } - - /** - * 功能:获取单位列表 - * query_type_id - * 0:查全市 - * 1:只查市直属 - * 2:查登录人员所在县区 - *

- * bureau_type_ids - * 单位类型: - * 1: 下属县区教育局 - * 2:下属学校 - * 3:下属教辅单位 - * 4: 市教育局 - * - * @return - */ - @Before({GET.class}) - @IsLoginInterface({}) - @LayUiPageInfoInterface({"page", "limit"}) - @EmptyInterface({"bureau_type_ids"}) - public void getBureauList(int query_type_id, String bureau_type_ids, String org_name, int page, int limit) { - //操作人员 - String person_id = SessionKit.get(getRequest(), getResponse(), "person_id"); - //根据人员ID,获取人员所在的单位ID - Record rs = personModel.getLoginInfoByPersonId(person_id); - String bureau_id = rs.get("bureau_id"); - - String area_id = bm.getOrgInfoById(bureau_id).getStr("area_id"); - //0:查全市 - //1:只查市直属 - //2:查登录人员所在县区 - Page list = cm.getBureauList(query_type_id, bureau_type_ids, area_id, org_name, page, limit); - renderJson(CommonUtil.renderJsonForLayUI(list)); - } - - /** - * 功能:检查是不是存在县区教育局 - * - * @param bureauIds - * @param groupIds - */ - @Before({GET.class}) - @IsLoginInterface({}) - public void isExistXianQuJiaoYuJu(String bureauIds, String groupIds) { - if (StrKit.isBlank(bureauIds) && StrKit.isBlank(groupIds)) { - Map map = new HashMap<>(); - map.put("success", false); - map.put("message", "bureauIds与groupIds同时为空,需要前端判断进行拦截!"); - renderJson(map); - return; - } - List list = cm.getXianQuJiaoYuJu(bureauIds, groupIds); - boolean exist = false; - if (list != null && list.size() > 0) exist = true; - Map map = new HashMap<>(); - map.put("success", true); - map.put("exist", exist); - map.put("list", list); - if (exist) map.put("message", "存在县区教育局!"); - else map.put("message", "不存在县区教育局!"); - renderJson(map); - } - - /** - * 功能:发布任务 - * - * @param job_id 任务编号 - * @param deadline_time 截止时间 - * @param xiaShuSchool 下属学校:1选中,0未选中 - * @param xiaShuJiaoFu 下属教辅单位:1选中,0未选中 - * @param xiaShuJiaoYuJu 下属教育局:1选中,0未选中 - * @param shiJiaoYuJu 是教育局,1:选中,0:未选中 - * @param bureauIds 按单位选择的单位ids - * @param groupIds 群组ids - * @param memo 说明文字 - * publish_job_type_id: - * 1:市级 - * 2:县区级 - * 3:单位、校级 - * @param fill_type_id 填报任务类型:1:填报,2:转发,3:填报+转发 - *

- * 下面的参数,为任务发布到人时扩展 - * @param allTeacher 所有教师 - * @param allStudent 所有学生 - * @param njIds 哪些年级,比如1,2表示1、2年级所有学生 - * @param personIds 哪些人员(目前只支持教师) - * @param classIds 哪些班级 - */ - @Before({POST.class, RepeatIntercetpor.class}) - @IsLoginInterface({}) - @IsNumericInterface({"job_id", "xiaShuSchool", "xiaShuJiaoFu", "xiaShuJiaoYuJu", "fill_type_id"}) - @EmptyInterface({"deadline_time"}) - public void publishJob(int job_id, String deadline_time, int xiaShuSchool, int xiaShuJiaoFu, int xiaShuJiaoYuJu, int shiJiaoYuJu, - String bureauIds, String groupIds, String memo, - int fill_type_id, //增加的参数 - int allTeacher, int allStudent, String njIds, - String personIds, String classIds) throws ParseException { - //操作人员 - String person_id = SessionKit.get(getRequest(), getResponse(), "person_id"); - //根据人员ID,获取人员所在的单位ID - Record rs = personModel.getLoginInfoByPersonId(person_id); - String bureau_id = rs.get("bureau_id"); - - //检查当前登录人员是不是发布任务的角色 - Kv kvCheck = cm.checkPublishRole(person_id); - if (!kvCheck.getBoolean("success")) { - renderJson(kvCheck); - return; - } - //获取登录人员第一个发布任务的角色是什么 - int publish_role_id = kvCheck.getInt("publish_role_id"); - - String area_id = bm.getOrgInfoById(bureau_id).getStr("area_id"); - - cm.publishJob(publish_role_id, job_id, deadline_time, area_id, - xiaShuSchool, xiaShuJiaoFu, xiaShuJiaoYuJu, shiJiaoYuJu, bureauIds, - groupIds, memo, fill_type_id, allTeacher, allStudent, njIds, - personIds, classIds); - Map map = new HashMap<>(); - map.put("success", true); - map.put("message", "保存成功!"); - renderJson(map); - } - - /** - * 功能:获取任务信息 - * - * @param job_id - */ - @Before({GET.class}) - @IsLoginInterface({}) - @IsNumericInterface({"job_id", "status_code"}) - @EmptyInterface({"target_id"}) - public void getJob(int job_id, String target_id, int status_code) { - //操作人员 - String person_id = SessionKit.get(getRequest(), getResponse(), "person_id"); - //根据人员ID,获取人员所在的单位ID - String bureau_id = ""; - if (cm.IS_THIRD_PARTY() == 0) { - Record rs = personModel.getLoginInfoByPersonId(person_id); - bureau_id = rs.get("bureau_id"); - } else { - bureau_id = cm.getTyPersonBureau(person_id); - } - Record record = cm.getJob(job_id, bureau_id, target_id, status_code); - //不仅要回原来的信息,还需要增加一些属性:如果是上级转发过来的,那么上级要求的完成时间是什么,具体的完成要求是什么 - renderJson(record); - } - - /** - * 功能:获取任务基础信息 - * - * @param job_id - */ - @Before({GET.class}) - @IsLoginInterface({}) - @IsNumericInterface({"job_id"}) - public void getJobBasic(int job_id) { - Record record = cm.getJob(job_id); - renderJson(record); - } - - /** - * 功能:延期任务 - * - * @param job_id - */ - @Before({POST.class, RepeatIntercetpor.class}) - @IsLoginInterface({}) - @IsNumericInterface({"job_id"}) - @EmptyInterface({"deadline_time"}) - public void extensionJob(int job_id, String deadline_time) throws ParseException { - //操作人员 - String person_id = SessionKit.get(getRequest(), getResponse(), "person_id"); - //根据人员ID,获取人员所在的单位ID - Record rs = personModel.getLoginInfoByPersonId(person_id); - String bureau_id = rs.get("bureau_id"); - cm.extensionJob(job_id, deadline_time, bureau_id); - Map map = new HashMap<>(); - map.put("success", true); - map.put("message", "保存成功!"); - renderJson(map); - } - - /** - * 功能:克隆任务 - * - * @param job_id - * @param job_name - */ - @Before({POST.class, RepeatIntercetpor.class}) - @IsLoginInterface({}) - @IsNumericInterface({"job_id"}) - public void cloneJob(int job_id, String job_name) { - cm.cloneJob(job_id, job_name); - Map map = new HashMap<>(); - map.put("success", true); - map.put("message", "保存成功!"); - renderJson(map); - } - - /** - * 功能:查看某个单位对于某个任务的填报情况 - * - * @param job_id - * @param bureau_id - * @param type_id 1:EXCEL下载 2:PDF在线查看 - */ - @Before({GET.class}) - @IsLoginInterface({}) - @IsNumericInterface({"job_id", "type_id", "status_code"}) - public void getJobBureauFillInfo(int job_id, String bureau_id, int type_id, int status_code) throws Exception { - if (StrKit.isBlank(bureau_id)) { - //操作人员 - String person_id = SessionKit.get(getRequest(), getResponse(), "person_id"); - //根据人员ID,获取人员所在的单位ID - Record rs = personModel.getLoginInfoByPersonId(person_id); - bureau_id = rs.get("bureau_id"); - } - // 获取任务名称 - String job_name = cm.getJob(job_id).getStr("job_name"); - // 获取单位名称 - String bureau_name = bm.getOrgInfoById(bureau_id).getStr("org_name"); - - //文件名称 - String excel_filename = job_name + "【" + bureau_name + "】.xlsx"; - String pdfName = job_name + "【" + bureau_name + "】"; - - //1、找到upload_excel_filename_user - Record record = cm.viewFilledJob(job_id, bureau_id, status_code); - String upload_excel_filename_user = record.getStr("upload_excel_filename_user"); - if (StrKit.isBlank(upload_excel_filename_user)) { - Kv kv = Kv.by("success", false); - kv.set("message", "此单位还没有完成数据上报,无法展示填报情况!"); - renderJson(kv); - return; - } - String excelPath = CommonUtil.basePath + File.separator + upload_excel_filename_user; - - if (!FileUtil.exist(excelPath)) { - Kv kv = Kv.by("success", false); - kv.set("message", "文件没有找到,请联系管理员处理异常!"); - renderJson(kv); - return; - } - //2、提供EXCEL - if (type_id == 1) { - renderFile(new File(excelPath), excel_filename); - return; - } - //3、提供PDF - if (type_id == 2) { - String pdfPath = excelPath.replace(".xlsx", ".pdf"); - //AsposeUtil.xls2pdf(excelPath, pdfPath); - - //提供带中文文件名的pdf流 - HttpServletResponse response = getResponse(); - response.reset(); - response.setContentType("application/pdf;charset=UTF-8"); - response.setHeader("Content-Disposition", "inline;filename=" + URLEncoder.encode(pdfName, "UTF-8"));//这里的名字并不起作用 - OutputStream out = response.getOutputStream(); - PDDocument document = Loader.loadPDF(FileUtil.readBytes(pdfPath)); //加载pdf - PDDocumentInformation info = document.getDocumentInformation(); //获得文档属性对象 - //对比原来的代码,就是在文件流写入响应体之前,经过一下pdfbox,修改标题属性,然后pdfbox的save方法可以直接写入到响应体中。 - info.setTitle(pdfName); //修改标题属性 这个标题会被展示 - document.setDocumentInformation(info); - document.save(out); //修改完直接输出到响应体中 - document.close(); - out.close(); - renderNull(); - } - } - - /** - * 功能: 任务发布者,查看发布的任务填充情况 - * - * @param job_id 任务ID - * @param keyword 搜索关键字 - * @param page 第几页 - * @param limit 每页多少个 - * @param status_codes 查看填报进度 - * 1110 1111 单位 市 填报 待/已 - * 1210 1211 单位 县 填报 待/已 - * 2210 2211 人 县 填报 待/已 - * 2310 2311 人 单位 填报 待/已 - */ - @Before({GET.class}) - @IsLoginInterface({}) - @IsNumericInterface({"job_id"}) - @LayUiPageInfoInterface({"page", "limit"}) - @EmptyInterface({"status_codes"}) - public void viewJob(int job_id, String keyword, String status_codes, int self_or_next, int page, int limit) { - if (self_or_next == 0) self_or_next = 2; - //操作人员 - String person_id = SessionKit.get(getRequest(), getResponse(), "person_id"); - //根据人员ID,获取人员所在的单位ID - Record rs = personModel.getLoginInfoByPersonId(person_id); - String bureau_id = rs.get("bureau_id"); - Page list = cm.viewJob(job_id, bureau_id, keyword, status_codes, self_or_next, page, limit); - renderJson(CommonUtil.renderJsonForLayUI(list)); - } - - /** - * 功能:学校(单位)查看我该填报或者我已填报的任务列表 - * - * @param status_codes 状态码 - * @param keyword 搜索关键字 - * @param page 第几页 - * @param limit 每页多少个 - */ - @Before({GET.class}) - @IsLoginInterface({}) - @LayUiPageInfoInterface({"page", "limit"}) - public void viewJobList(String keyword, String status_codes, int page, int limit) { - //操作人员 - String person_id = SessionKit.get(getRequest(), getResponse(), "person_id"); - //根据人员ID,获取人员所在的单位ID - Record rs = personModel.getLoginInfoByPersonId(person_id); - String bureau_id = rs.get("bureau_id"); - - //检查当前登录人员是不是发布任务的角色 - Kv kvCheck = cm.checkPublishRole(person_id); - //获取登录人员第一个发布任务的角色是什么 - int publish_role_id = kvCheck.getInt("publish_role_id"); - - Page list = cm.viewJobList(publish_role_id, bureau_id, keyword, status_codes, page, limit); - renderJson(CommonUtil.renderJsonForLayUI(list)); - } - - - /***** 以下为Form表单式填报模块 *********************************/ - - /** - * 功能:Form表单上传图片或其它附件 - */ - @Before({POST.class, RepeatIntercetpor.class}) - @IsLoginInterface({}) - public void uploadFile() { - UploadFile uf = getFile();//得到文件对象 - String fileName = uf.getFileName(); - String suffix = fileName.substring(fileName.lastIndexOf(".") + 1).trim(); - if (!suffix.equals("doc") && !suffix.equals("docx") - && !suffix.equals("xls") && !suffix.equals("xlsx") - && !suffix.equals("pdf") - && !suffix.equals("jpg") && !suffix.equals("jpeg") && !suffix.equals("png")) { - renderJson(CommonUtil.returnMessageJson(false, "上传文件类型错误!系统只允许上传文档和图片格式!")); - return; - } - //判断文件大小大于20mb则返回错误信息,并终止上传,删除上传文件 - long size = uf.getFile().length(); - if (size > 1024 * 1024 * 20) { - Kv kv = Kv.by("success", false).set("message", "文件大小大于20MB,请检查是否正确!!"); - renderJson(kv); - return; - } - - String file_id = UUID.randomUUID().toString().toUpperCase(); - String filePath = CommonUtil.basePath + File.separator + file_id + "." + suffix; - uf.getFile().renameTo(new File(filePath)); - //计算文件大小 - String file_size = FileSizeUtil.getAutoFileOrFilesSize(filePath); - - //操作人员 - String person_id = SessionKit.get(getRequest(), getResponse(), "person_id"); - //根据人员ID,获取人员所在的单位ID - Record rs = personModel.getLoginInfoByPersonId(person_id); - String bureau_id = rs.getStr("bureau_id"); - int job_id = getInt("job_id"); - int target_type_id = cm.getJob(job_id).getInt("target_type_id"); - String target_id = bureau_id; - if (target_type_id == 2) target_id = person_id; - - String input_id = get("input_id"); - int type_id = getInt("type_id"); - //记录到数据库 - cm.saveUploadFile(job_id, input_id, type_id, target_id, person_id, fileName, file_id, suffix, file_size); - //返回结果 - Kv kv = Kv.by("success", true); - kv.set("message", "上传成功!"); - kv.set("url", "/Excel/" + file_id + "." + suffix); - kv.set("file_id", file_id); - kv.set("file_size", file_size); - kv.set("fileName", fileName); - kv.set("input_id", input_id); - kv.set("type_id", type_id); - renderJson(kv); - } - - /** - * 功能:删除上传的文件 - * - * @param job_id - * @param file_id - */ - @Before({POST.class, RepeatIntercetpor.class}) - public void delUploadFile(int job_id, String file_id) { - cm.delUploadFile(job_id, file_id); - Kv kv = Kv.by("success", true); - kv.set("message", "删除成功!"); - renderJson(kv); - } - - /** - * 功能:获取指定任务,指定单位上传的附件列表 - * - * @param job_id - * @param target_id http://10.10.21.20:9000/QingLong/collect/getJobUploadList?job_id=42 - */ - @Before({GET.class}) - @IsLoginInterface({}) - @IsNumericInterface({"job_id"}) - public void getJobUploadList(int job_id, String target_id) { - //如果不提供单位ID,那么默认值是当前操作人员所在单位,否则按提供为准 - if (StrKit.isBlank(target_id)) { - //操作人员 - String person_id = SessionKit.get(getRequest(), getResponse(), "person_id"); - - if (cm.IS_THIRD_PARTY() == 0) { - //根据人员ID,获取人员所在的单位ID - Record rs = personModel.getLoginInfoByPersonId(person_id); - target_id = rs.get("bureau_id"); - } else { - target_id = cm.getTyPersonBureau(person_id); - } - } - List list = cm.getJobUploadList(job_id, target_id); - renderJson(CommonUtil.renderJsonForLayUI(list)); - } - - /** - * 功能:增加一个表单式的新任务 - * - * @param job_name 任务名称 - * @param target_type_id 1:单位 1,2:人员 - * @param json JSON内容 - * @param table_name 表名 - */ - @Before({POST.class, RepeatIntercetpor.class}) - @IsLoginInterface({}) - @EmptyInterface({"job_name", "json", "table_name"}) - public void addFormJob(int target_type_id, String job_name, String json, String table_name, int self_or_next) { - if (self_or_next == 0) self_or_next = 2; - if (target_type_id == 0) target_type_id = 1;//默认是发布到单位 - boolean isMatch = table_name.matches("[a-z][a-z0-9_]*"); - if (!isMatch) { - Map map = new HashMap<>(); - map.put("success", false); - map.put("message", "字符串包含其他字符或第一个字符不是小写字母"); - renderJson(map); - return; - } - if (!table_name.startsWith("ds_")) { - Map map = new HashMap<>(); - map.put("success", false); - map.put("message", "数据库表名必须以ds_开头!"); - renderJson(map); - } - //操作人员 - String person_id = SessionKit.get(getRequest(), getResponse(), "person_id"); - //根据人员ID,获取人员所在的单位ID - Record rs = personModel.getLoginInfoByPersonId(person_id); - String bureau_id = rs.get("bureau_id"); - //检查当前登录人员是不是发布任务的角色 - Kv kvCheck = cm.checkPublishRole(person_id); - if (!kvCheck.getBoolean("success")) { - renderJson(kvCheck); - return; - } - //获取登录人员第一个发布任务的角色是什么 - int publish_role_id = kvCheck.getInt("publish_role_id"); - - if (cm.isTableExist(table_name)) { - Map map = new HashMap<>(); - map.put("success", false); - map.put("message", "表名" + table_name + "已存在,无法创建,请更换后再次提交!"); - renderJson(map); - return; - } - //检查字段名是否重复 - if (!cm.checkColumnNameDuplicate(json)) { - Map map = new HashMap<>(); - map.put("success", false); - map.put("message", "表名" + table_name + "中存在重复列名或与保留字冲突,不能创建,请检查!"); - renderJson(map); - return; - } - - //通过检查 - int job_id = cm.addFormJob(target_type_id, bureau_id, person_id, publish_role_id, job_name, table_name, json, self_or_next); - Map map = new HashMap<>(); - map.put("success", true); - map.put("message", "保存成功!"); - map.put("job_id", job_id); - renderJson(map); - } - - /** - * 功能:更新一个存在的表单式任务 - * - * @param job_id - * @param json - */ - @Before({POST.class, RepeatIntercetpor.class}) - @IsLoginInterface({}) - @IsNumericInterface({"job_id"}) - @EmptyInterface({"json", "job_name", "table_name"}) - public void updateFormJob(int job_id, String job_name, String json, String table_name) { - if (!table_name.startsWith("ds_")) { - Map map = new HashMap<>(); - map.put("success", false); - map.put("message", "数据库表名必须以ds_开头!"); - renderJson(map); - } - //操作人员 - String person_id = SessionKit.get(getRequest(), getResponse(), "person_id"); - //检查当前登录人员是不是发布任务的角色 - Kv kvCheck = cm.checkPublishRole(person_id); - if (!kvCheck.getBoolean("success")) { - renderJson(kvCheck); - return; - } - - //1、检查输入的表名,是不是在排除了自己本JOB_ID对应的表名外存在,如果是,那么不可以 - String form_table_name = cm.getJob(job_id).getStr("form_table_name"); - - if (!form_table_name.equals(table_name) && cm.isTableExist(table_name)) { - Map map = new HashMap<>(); - map.put("success", false); - map.put("message", "表名" + table_name + "已存在,无法创建,请更换后再次提交!"); - renderJson(map); - return; - } - cm.updateFormJob(job_id, job_name, json, table_name); - Map map = new HashMap<>(); - map.put("success", true); - map.put("message", "保存成功!"); - map.put("job_id", job_id); - renderJson(map); - } - - - /** - * 功能:获取指定任务指定单位的填报内容 - * - * @param job_id - * @param target_id - */ - @Before({GET.class}) - @IsLoginInterface({}) - @IsNumericInterface({"job_id", "status_code"}) - public void getFormFillJob(int job_id, String target_id, int status_code) { - //操作人员 - String person_id = SessionKit.get(getRequest(), getResponse(), "person_id"); - if (StrKit.isBlank(target_id)) {//空代表是登录人员所在单位 - //根据人员ID,获取人员所在的单位ID - Record rs = personModel.getLoginInfoByPersonId(person_id); - target_id = rs.get("bureau_id"); - } else if (target_id.equals("-1")) {//-1代表是登录人员 - target_id = person_id; - } - //否则的话,就是传啥查啥,传单位查单位,传人查人 - String json = cm.getFormFillJob(job_id, target_id, status_code); - renderJson(json); - } - - /****以下为管理组概念*****************************************/ - - /** - * 功能:增加组 - * - * @param group_name 群组名称 - * @param group_type_id 分组类型 - * @param target_ids 成员ds,以逗号隔开,类型参考group_type_id - */ - @Before({POST.class, RepeatIntercetpor.class}) - @IsLoginInterface({}) - @EmptyInterface({"group_name"}) - public void addGroup(String group_name, int group_type_id, String target_ids) { - //操作人员 - String person_id = SessionKit.get(getRequest(), getResponse(), "person_id"); - //根据人员ID,获取人员所在的单位ID - Record rs = personModel.getLoginInfoByPersonId(person_id); - String bureau_id = rs.get("bureau_id"); - - int group_id = cm.addGroup(group_name, group_type_id, target_ids, bureau_id, person_id); - Map map = new HashMap<>(); - map.put("success", true); - map.put("message", "保存成功!"); - map.put("group_id", group_id); - renderJson(map); - } - - /** - * 功能:更新组 - * - * @param group_id - * @param group_name - * @param target_ids - */ - @Before({POST.class, RepeatIntercetpor.class}) - @IsLoginInterface({}) - @IsNumericInterface({"group_id"}) - @EmptyInterface({"group_name", "bureauIds"}) - public void updateGroup(int group_id, String group_name, String target_ids) { - cm.updateGroup(group_id, group_name, target_ids); - Map map = new HashMap<>(); - map.put("success", true); - map.put("message", "保存成功!"); - map.put("group_id", group_id); - renderJson(map); - } - - /** - * 功能:组列表,需要说明是哪种类型的群组 - */ - @Before({GET.class}) - @IsLoginInterface({}) - @IsNumericInterface({"group_type_id"}) - public void listGroup(int group_type_id) { - //操作人员 - String person_id = SessionKit.get(getRequest(), getResponse(), "person_id"); - //根据人员ID,获取人员所在的单位ID - Record rs = personModel.getLoginInfoByPersonId(person_id); - String bureau_id = rs.get("bureau_id"); - - List list = cm.listGroup(bureau_id, group_type_id); - renderJson(CommonUtil.renderJsonForLayUI(list)); - } - - /** - * 功能:删除组 - * - * @param group_id - */ - @Before({POST.class, RepeatIntercetpor.class}) - @IsLoginInterface({}) - @IsNumericInterface({"group_id"}) - public void delGroup(int group_id) { - cm.delGroup(group_id); - Map map = new HashMap<>(); - map.put("success", true); - map.put("message", "保存成功!"); - map.put("group_id", group_id); - renderJson(map); - } - - /** - * 功能:获取组内有哪些单位id - * - * @param group_id - */ - @Before({GET.class}) - @IsLoginInterface({}) - @IsNumericInterface({"group_id"}) - public void getGroup(int group_id) { - List list = cm.getGroupTargetList(group_id); - renderJson(CommonUtil.renderJsonForLayUI(list)); - } - - /** - * 功能:导出指定任务的表结构EXCEL - * - * @param job_id http://10.10.21.20:9000/QingLong/collect/exportTableStructExcel?job_id=1 - */ - @Before({GET.class}) - @IsLoginInterface({}) - @IsNumericInterface({"job_id"}) - public void exportTableStructExcel(int job_id) { - String job_name = cm.getJob(job_id).getStr("job_name"); - String excelPath = CommonUtil.basePath + File.separator + UUID.randomUUID().toString().toLowerCase() + ".xlsx"; - String url = PropKit.get("jdbcUrl"); - String user = PropKit.get("user"); - String password = PropKit.get("password"); - - List jobTables = new ArrayList<>(); - - //当前 job_id下有哪些表 - Record r2 = cm.getJob(job_id); - String form_table_name = r2.getStr("form_table_name"); - if (!StrKit.isBlank(form_table_name)) jobTables.add(form_table_name); - //sheet型 - String sql = "select table_name from t_collect_job_sheet where job_id=?"; - List list = Db.find(sql, job_id); - for (Record record : list) { - jobTables.add(record.getStr("table_name")); - } - - try (Connection conn = DriverManager.getConnection(url, user, password)) { - DatabaseMetaData metaData = conn.getMetaData(); - String[] types = {"TABLE"}; - Workbook workbook = new XSSFWorkbook(); - Sheet sheet = workbook.createSheet(job_name); - ResultSet tables = metaData.getTables(null, null, "ds_%", types); - - int rowNum = 0; - Set isHead = new HashSet<>(); - while (tables.next()) { - String tableName = tables.getString("TABLE_NAME"); - if (!jobTables.contains(tableName)) continue; - - String tableComment = tables.getString("REMARKS"); // 从表的comment中读取注释信息 - ResultSet columns = metaData.getColumns(null, null, tableName, null); - - // 创建表名称的合并单元格 - sheet.addMergedRegion(new CellRangeAddress(rowNum, rowNum, 0, 5)); - Row headerRow = sheet.createRow(rowNum++); - if (!StrKit.isBlank(tableComment)) { - headerRow.createCell(0).setCellValue("表名: " + tableName + " 【" + tableComment + "】"); - } else { - headerRow.createCell(0).setCellValue("表名: " + tableName); - } - CellStyle headerStyle = workbook.createCellStyle(); - - //设置自定义颜色 - headerStyle.setAlignment(HorizontalAlignment.CENTER); - headerStyle.setBorderTop(BorderStyle.THIN); - headerStyle.setBorderBottom(BorderStyle.THIN); - headerStyle.setBorderLeft(BorderStyle.THIN); - headerStyle.setBorderRight(BorderStyle.THIN); - headerStyle.setVerticalAlignment(VerticalAlignment.CENTER); - Font headerFont = workbook.createFont(); - headerFont.setBold(true); - headerFont.setFontName("黑体"); - headerFont.setFontHeightInPoints((short) 18); - headerStyle.setFont(headerFont); - headerRow.getCell(0).setCellStyle(headerStyle); - headerRow.setHeightInPoints(38); // 设置行高 - isHead.add(headerRow.getRowNum()); - - // 创建表格标题 - Row titleRow = sheet.createRow(rowNum++); - titleRow.createCell(0).setCellValue("序号"); - titleRow.createCell(1).setCellValue("字段名"); - titleRow.createCell(2).setCellValue("数据类型"); - titleRow.createCell(3).setCellValue("字段长度"); - titleRow.createCell(4).setCellValue("是否允许空"); - titleRow.createCell(5).setCellValue("描述"); - - // 设置标题样式 - CellStyle titleStyle = workbook.createCellStyle(); - //颜色 - String str = "#d2f4f2"; - String sr = str.substring(1, 3); - String sg = str.substring(3, 5); - String sb = str.substring(5, 7); - //16进制的字符串转为int - int r = Integer.parseInt(sr, 16); - int g = Integer.parseInt(sg, 16); - int b = Integer.parseInt(sb, 16); - XSSFColor rbg = new XSSFColor(new java.awt.Color(r, g, b), new DefaultIndexedColorMap()); - titleStyle.setFillForegroundColor(rbg); - titleStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND); - titleStyle.setAlignment(HorizontalAlignment.CENTER); - titleStyle.setBorderTop(BorderStyle.THIN); - titleStyle.setBorderBottom(BorderStyle.THIN); - titleStyle.setBorderLeft(BorderStyle.THIN); - titleStyle.setBorderRight(BorderStyle.THIN); - titleStyle.setVerticalAlignment(VerticalAlignment.CENTER); - Font titleFont = workbook.createFont(); - titleFont.setFontName("宋体"); - titleFont.setBold(true); - titleFont.setFontHeightInPoints((short) 15); - titleStyle.setFont(titleFont); - for (int j = 0; j < 6; j++) { - titleRow.getCell(j).setCellStyle(titleStyle); - } - - // 设置列宽 - sheet.setColumnWidth(0, 10 * 256); // 序号列宽度 - sheet.setColumnWidth(1, 40 * 256); // 20个字符宽度 - sheet.setColumnWidth(2, 20 * 256); - sheet.setColumnWidth(3, 15 * 256); - sheet.setColumnWidth(4, 20 * 256); - sheet.setColumnWidth(5, 40 * 256); - - // 创建表格数据 - int serialNumber = 1; - while (columns.next()) { - Row dataRow = sheet.createRow(rowNum++); - dataRow.createCell(0).setCellValue(serialNumber++); - dataRow.createCell(1).setCellValue(columns.getString("COLUMN_NAME")); - dataRow.createCell(2).setCellValue(columns.getString("TYPE_NAME")); - dataRow.createCell(3).setCellValue(columns.getString("COLUMN_SIZE")); // 添加字段长度 - dataRow.createCell(4).setCellValue(columns.getString("IS_NULLABLE")); - dataRow.createCell(5).setCellValue(columns.getString("REMARKS")); - - for (int j = 0; j < 6; j++) { - Cell cell = dataRow.getCell(j); - CellStyle dataStyle = workbook.createCellStyle(); - dataStyle.setAlignment(HorizontalAlignment.CENTER); - dataStyle.setBorderTop(BorderStyle.THIN); - dataStyle.setBorderBottom(BorderStyle.THIN); - dataStyle.setBorderLeft(BorderStyle.THIN); - dataStyle.setBorderRight(BorderStyle.THIN); - dataStyle.setVerticalAlignment(VerticalAlignment.CENTER); - - Font dataFont = workbook.createFont(); - dataFont.setFontName("宋体"); - dataFont.setFontHeightInPoints((short) 13); - dataStyle.setFont(dataFont); - cell.setCellStyle(dataStyle); - } - } - } - // 设置其它行的高度 - for (int i = 0; i < rowNum; i++) { - if (!isHead.contains(i)) sheet.getRow(i).setHeightInPoints(28); // 设置行高 - } - - FileOutputStream fileOut = new FileOutputStream(excelPath); - workbook.write(fileOut); - fileOut.close(); - workbook.close(); - //提供下载 - renderFile(new File(excelPath), job_name + "表结构.xlsx"); - } catch (SQLException | IOException e) { - e.printStackTrace(); - } - } - - /** - * 功能:提供form表单上传的文件下载功能 - * - * @param file_id - */ - @Before({GET.class}) - @IsLoginInterface({}) - public void getFormJobFile(String file_id) { - Record record = cm.getFormJobFile(file_id); - String fileName = record.getStr("fileName"); - String suffix = record.getStr("suffix"); - - String filePath = CommonUtil.basePath + File.separator + file_id + "." + suffix; - if (!FileUtil.exist(filePath)) { - Kv kv = Kv.by("success", false); - kv.set("message", "文件没有找到,请联系管理员处理异常!"); - renderJson(kv); - return; - } - renderFile(new File(filePath), fileName); - } - - - /** - * 功能:转发任务 - * 县区教育局资产管理干事 268 - * - * @param job_id 任务ID - * @param status_code 检索出的任务状态 - * @param deadline_time 截止时间 - * @param xiaShuSchool 下属学校:如果是县区教育局,可以指定所有下属学校,如果是学校转发,就只能到人了,此值为0 - * @param xiaShuJiaoFu 下属教辅单位:如果是县区教育局,可以指定所有下属教辅单位,如果是学校转发,就只能到人了,此值为0 - * @param personIds 人员ids列表:向哪些人员进行转发,支持到人员的转发任务 - * @param bureauIds 单位列表:向哪些指定的单位进行转发 - * @param groupIds 组列表:向哪些群组进行转发 - * @param memo 自己的要求说明文字 - * 下面的参数,为任务发布到人时扩展 - * @param allTeacher 所有教师 - * @param allStudent 所有学生 - * @param njIds 哪些年级,比如1,2表示1、2年级所有学生 - * @param personIds 哪些人员(目前只支持教师) - * @param classIds 哪些班级 - */ - @Before({POST.class, RepeatIntercetpor.class}) - @IsLoginInterface({}) - @IsNumericInterface({"job_id", "status_code"}) - public void ForwardJob(int job_id, int status_code, String deadline_time, int xiaShuSchool, int xiaShuJiaoFu, String bureauIds, String groupIds, String memo, - //增加的参数 - int allTeacher, int allStudent, String njIds, - String personIds, String classIds) throws ParseException { - if (status_code == 0) { - Map map = new HashMap<>(); - map.put("success", false); - map.put("message", "status_code参数必须是4位整数!"); - renderJson(map); - return; - } - //操作人员 - String person_id = SessionKit.get(getRequest(), getResponse(), "person_id"); - - //检查当前登录人员是不是发布任务的角色 - Kv kvCheck = cm.checkPublishRole(person_id); - if (!kvCheck.getBoolean("success")) { - renderJson(kvCheck); - return; - } - //获取登录人员第一个发布任务的角色是什么 - int publish_role_id = kvCheck.getInt("publish_role_id"); - - //根据人员ID,获取人员所在的单位ID - Record rs = personModel.getLoginInfoByPersonId(person_id); - String bureau_id = rs.get("bureau_id"); - - //获取当前登录人员所在的县区ID - Record personRecord = personModel.getLoginInfoByPersonId(person_id); - String area_id = personRecord.getStr("area_id"); - - //转发任务 - cm.ForwardJob(publish_role_id, area_id, job_id, status_code, deadline_time, - xiaShuSchool, xiaShuJiaoFu, bureauIds, groupIds, memo, bureau_id, allTeacher, allStudent, njIds, personIds, classIds); - //返回 - Map map = new HashMap<>(); - map.put("success", true); - map.put("message", "保存成功!"); - renderJson(map); - } - - /** - * 功能:转发任务我看下级单位都提交过来了,我可以向上级汇报了 - * - * @param job_id 任务ID - */ - @Before({POST.class, RepeatIntercetpor.class}) - @IsLoginInterface({}) - @IsNumericInterface({"job_id", "status_code"}) - public void setForwardFinish(int job_id, int status_code) { - //操作人员 - String person_id = SessionKit.get(getRequest(), getResponse(), "person_id"); - - //根据人员ID,获取人员所在的单位ID - Record rs = personModel.getLoginInfoByPersonId(person_id); - String bureau_id = rs.get("bureau_id"); - - cm.setForwardFinish(job_id, status_code, bureau_id); - Map map = new HashMap<>(); - map.put("success", true); - map.put("message", "保存成功!"); - renderJson(map); - } - - /** - * 功能:根据任务ID,生成通用的EXCEL导出下载(支持转发) - * - * @param job_id - */ - @Before({GET.class}) - @IsLoginInterface({}) - @IsNumericInterface({"job_id"}) - public void getSummaryExcel(int job_id) throws IOException { - //操作人员 - String person_id = SessionKit.get(getRequest(), getResponse(), "person_id"); - //根据人员ID,获取人员所在的单位ID - Record rs = personModel.getLoginInfoByPersonId(person_id); - - //检查当前登录人员是不是发布任务的角色 - Kv kvCheck = cm.checkPublishRole(person_id); - //获取登录人员第一个发布任务的角色是什么 - int publish_role_id = kvCheck.getInt("publish_role_id"); - - String bureau_id = rs.get("bureau_id"); - Record jobRecord = cm.getJob(job_id); - String job_name = jobRecord.getStr("job_name"); - String tmpFile = UUID.randomUUID().toString().toLowerCase() + ".xlsx"; - String excelPath = CommonUtil.basePath + "/" + tmpFile; - //这里需要知道是哪种类型的,因为不同的类型,生成EXCEL汇总表的方法不同 - int job_type = jobRecord.getInt("job_type");//任务类型:1:表单,2:EXCEL模板 - switch (job_type) { - case 1: - cm.getSummaryExcelForFormFill(job_id, bureau_id, publish_role_id, excelPath); //测试用例 job_id=8 - break; - case 2: - cm.getSummaryExcelForImportExcel(job_id, bureau_id, publish_role_id, excelPath);//测试用例 job_id=47 - break; - } - //提供下载 - renderFile(new File(excelPath), "【" + job_name + "】汇总表.xlsx"); - } - - /** - * 功能:下载指定任务的EXCEL模板 - * - * @param job_id - */ - @Before({GET.class}) - @IsLoginInterface({}) - @IsNumericInterface({"job_id"}) - public void downJobExcelTemplate(int job_id) { - Record jobRecord = cm.getJob(job_id); - String job_name = jobRecord.getStr("job_name"); - String TemplateFile = jobRecord.getStr("upload_excel_filename"); - String excelPath = CommonUtil.basePath + "/" + TemplateFile; - //先不要着急提供下载,需要根据用户的所在单位,来判断是不是需要删除掉一些信息 - //操作人员 - String person_id = SessionKit.get(getRequest(), getResponse(), "person_id"); - //根据人员ID,获取人员所在的单位ID - Record rs = personModel.getLoginInfoByPersonId(person_id); - String bureau_id = rs.get("bureau_id"); - List schoolStageList = cm.getSchoolStage(bureau_id);//有4,5,6哪几个学段 - //查一下,这个任务的相关模板与学段的关系表,哪些表不是当前单位需要填写的,隐藏掉 - File fillExcel = cm.getFillExcelTemplate(job_id, excelPath, schoolStageList); - //提供下载 - renderFile(fillExcel, job_name + ".xlsx"); - } - - /** - * 功能:获取当前人员的发布角色 - */ - @Before({GET.class}) - @IsLoginInterface({}) - public void getCurrentPersonPublishRole() { - //操作人员 - String person_id = SessionKit.get(getRequest(), getResponse(), "person_id"); - //检查当前登录人员是不是发布任务的角色 - Kv kvCheck = cm.checkPublishRole(person_id); - renderJson(kvCheck); - } - - - /** - * 功能:查看我该填报或者我已填报的任务列表(人员) - * - * @param keyword 关键字 - * @param is_finish 是不是已完成填报 - * @param page 第几页 - * @param limit 每页多少个 - */ - @Before({GET.class}) - @IsLoginInterface({}) - @IsNumericInterface({"is_finish"}) - @LayUiPageInfoInterface({"page", "limit"}) - public void viewJobListPerson(String keyword, int is_finish, int page, int limit) { - //操作人员 - String person_id = SessionKit.get(getRequest(), getResponse(), "person_id"); - Page list = cm.viewJobListPerson(person_id, keyword, is_finish, page, limit); - renderJson(CommonUtil.renderJsonForLayUI(list)); - } - - /** - * 功能:获取当前登录人员是否具有发布到下级的权限 - */ - @Before({GET.class}) - @IsLoginInterface({}) - public void canPublishNextLevel() { - //操作人员 - String person_id = SessionKit.get(getRequest(), getResponse(), "person_id"); - boolean flag = cm.canPublishNextLevel(person_id); - JSONObject resultJson = new JSONObject(); - resultJson.put("success", true); - if (flag) - resultJson.put("msg", "具备发布下级权限!"); - else resultJson.put("msg", "不具备发布下级权限!"); - resultJson.put("flag", flag); - renderJson(resultJson); - } - - /*****↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓*/ - /** 以下接口,用于发布到人员的任务,获取选择单位内部门、班级、人员、年级等功能,为了以后与天喻对接,全新实现,方便以后调整*/ - /** - * 功能:填报者保存填报结果 - * - * @param job_id - * @param json - */ - @Before({POST.class, RepeatIntercetpor.class}) - @IsLoginInterface({}) - @IsNumericInterface({"job_id", "status_code"}) - @EmptyInterface({"json"}) - public void saveFormJob(int job_id, int status_code, String json) { - //操作人员 - String person_id = SessionKit.get(getRequest(), getResponse(), "person_id"); - - //检查form表单录入的text域,是不是符合输入要求,不符合的进行提示 - Record rJob = cm.getJob(job_id); - String form_jsonStr = rJob.getStr("form_json"); - //读取原来的结构,根据原来结构的类型进行判断,获取现在需要用什么样的读取方式 - JSONArray ja = cm.parseGridJson(form_jsonStr); - Map _map = new HashMap<>(); - Map _mapLabel = new HashMap<>(); - for (int i = 0; i < ja.size(); i++) { - JSONObject j2 = ja.getJSONObject(i); - int data_type_id = DataType.getFormDataType(j2); - _map.put(j2.getString("id"), data_type_id);//哪个字段是什么类型 - if (j2.getString("tag").equals("input")) { - _mapLabel.put(j2.getString("id"), j2.getString("label")); - } - } - //开始检查 - JSONObject jo = JSONObject.parseObject(json); - for (Map.Entry entry : jo.entrySet()) { - String key = entry.getKey(); - if (key.startsWith("checkbox")) continue; - int data_type_id = _map.get(key); - String value = entry.getValue().toString(); - switch (data_type_id) { - case 0: - continue; - case 1://文本 - break; - case 2://数字 - if (!CommonUtil.isNumeric(value)) { - Map map = new HashMap<>(); - map.put("success", false); - map.put("message", _mapLabel.get(key) + "中输入的数据与要求的整数格式不一致,请重新输入!"); - renderJson(map); - return; - } - break; - case 3://小数 - if (!CommonUtil.isDecimal(value)) { - Map map = new HashMap<>(); - map.put("success", false); - map.put("message", _mapLabel.get(key) + "中输入的数据与要求的小数格式不一致,请重新输入!"); - renderJson(map); - return; - } - break; - case 4: //日期 - if (!CommonUtil.isDate(value)) { - Map map = new HashMap<>(); - map.put("success", false); - map.put("message", _mapLabel.get(key) + "中输入的数据与要求的日期格式不一致,请重新输入!"); - renderJson(map); - return; - } - break; - default: - break; - } - } - String ourBureau_id = ""; - //根据人员ID,获取人员所在的单位ID - String person_name = ""; - String s_class_id = ""; - if (cm.IS_THIRD_PARTY() == 0) { - Record rs = personModel.getLoginInfoByPersonId(person_id); - ourBureau_id = rs.get("bureau_id"); - person_name = rs.getStr("person_name");//人员姓名 - s_class_id = rs.getStr("s_class_id"); - } else { - String bureau_id = cm.getTyPersonBureau(person_id); - ourBureau_id = cm.getMyBureauByTyBureauId(bureau_id).getStr("org_id"); - LoginPersonModel personModel = new LoginPersonModel(); - Record record = personModel.getTyPersonInfo(person_id); - person_name = record.getStr("person_name"); - if (record.getInt("identity_id") == 5) { - s_class_id = "-1";//老师没有班级概念 - } else { - s_class_id = record.getStr("org_id"); - } - } - String bureau_name = bm.getOrgInfoById(ourBureau_id).getStr("org_name");//单位名称 - cm.saveFormJob(job_id, status_code, ourBureau_id, bureau_name, s_class_id, person_id, person_name, json); - Map map = new HashMap<>(); - map.put("success", true); - map.put("message", "保存成功!"); - map.put("job_id", job_id); - renderJson(map); - } - - /** - * 功能:我系统中所有有效单位 - * http://10.10.21.20:9000/QingLong/collect/getAllBureau?is_match=1&page=1&limit=20 - */ - @Before({GET.class, RepeatIntercetpor.class}) - @IsNumericInterface({"is_match", "page", "limit"}) - public void getAllBureau(int is_match, int page, int limit) { - Page dataPage = cm.getAllBureau(is_match, page, limit); - Map result = new HashMap<>(); - result.put("code", 0); - result.put("msg", ""); - result.put("count", dataPage.getTotalRow()); - result.put("data", dataPage.getList()); - renderJson(result); - } - - /** - * 功能:一键匹配 - */ - @Before({POST.class, RepeatIntercetpor.class}) - public void OneKeyMatch() { - int cnt = cm.OneKeyMatch(); - Map result = new HashMap<>(); - result.put("msg", "刷新成功!"); - result.put("count", cnt); - renderJson(result); - } - - /** - * 功能:匹配第三方系统与我们的系统单位ID一致 - * - * @throws InterruptedException - */ - @Before({POST.class, RepeatIntercetpor.class}) - @EmptyInterface({"third_party_id", "org_id"}) - public void matchBureau(String org_id, String third_party_id) { - cm.matchBureau(org_id, third_party_id); - Map map = new HashMap<>(); - map.put("success", true); - map.put("message", "保存成功!"); - renderJson(map); - } - - /** - * 功能:解除第三方系统与我们的系统单位ID的匹配 - * - * @throws InterruptedException - */ - @Before({POST.class, RepeatIntercetpor.class}) - @EmptyInterface({"org_id"}) - public void disMatchBureau(String org_id) { - cm.disMatchBureau(org_id); - Map map = new HashMap<>(); - map.put("success", true); - map.put("message", "保存成功!"); - renderJson(map); - } - - /** - * 功能:获取天喻系统中还未与我系统匹配完成的单位名称 - * - * @param keyword - */ - @Before({GET.class}) - @IsLoginInterface({}) - @IsNumericInterface({"page", "limit"}) - public void getTyBureauList(String keyword, int page, int limit) { - Page dataPage = cm.getTyBureauList(keyword, page, limit); - renderJson(CommonUtil.renderJsonForLayUI(dataPage)); - } - - /** - * 功能:填报系统专用登录接口 - * 此处是不对接第三方基础数据+统一认证的,因为如果对接了第三方基础数据+统一认证,就直接走了天喻的CAS,这里只处理回调就行了,单独实现吧 - * - * @param username - * @param password - */ - @Before({POST.class, RepeatIntercetpor.class}) - public void doFillLogin(String username, String password) { - JSONObject resultJson = new JSONObject(); - String checkCodeKey = ""; - - if (StrKit.isBlank(username)) { - resultJson.put("success", false); - resultJson.put("msg", "用户名不允许为空!"); - renderJson(resultJson); - return; - } - if (StrKit.isBlank(password)) { - resultJson.put("success", false); - resultJson.put("msg", "密码不允许为空!"); - renderJson(resultJson); - return; - } - - //检查缓存中此账号错误了几次 - String PassWordKey = "WrongPassWord_" + username; - int ErrCnt = 4; //最多允许错几次 4+1 - int cntNum = 0; //错几次了 - - if (RedisKit.Exists(PassWordKey)) - cntNum = Integer.parseInt(RedisKit.Get(PassWordKey)); - if (cntNum > ErrCnt) { - resultJson.put("success", false); - resultJson.put("msg", "账号被停用5分钟,请稍后再试!"); - renderJson(resultJson); - return; - } - //与前端配合RSA通用加密解密 - try { - password = RsaUtils.decryptDataOnJava(password, RsaUtils.PRIVATEKEY); - } catch (Exception err) { - password = "!@#$%^&&*^*&(*)(*_)^%^$%$^%$^%"; - } - String passwordEncode = CommonUtil.getLdapPassword(password); - Map loginMap = bm.getLoginInfoByUserName(username); - if (loginMap == null || !passwordEncode.equals(loginMap.get("password").toString())) { - //扩展支持连续输入用户名密码错误,停用账号5分钟功能 2022.06.07 - cntNum = 1; - if (RedisKit.Exists(PassWordKey)) - cntNum = Integer.parseInt(RedisKit.Get(PassWordKey)) + cntNum; - - int finalCntNum = cntNum; - RedisKit.incrBy(PassWordKey, finalCntNum); - RedisKit.Expire(PassWordKey, 60 * 5); - if (cntNum > ErrCnt) { - resultJson.put("success", false); - resultJson.put("msg", "密码连续输入" + (ErrCnt + 1) + "次全部错误,账号将被停用5分钟!"); - renderJson(resultJson); - return; - } - if (cntNum == ErrCnt) { - resultJson.put("success", false); - resultJson.put("msg", "用户名或密码连续错误,你还有1次机会,再次错误后账号将被封掉5分钟!"); - renderJson(resultJson); - return; - } - resultJson.put("success", false); - resultJson.put("msg", "用户名或密码错误!"); - renderJson(resultJson); - return; - } - //去掉限制 - RedisKit.Del(PassWordKey); - RedisKit.Del(checkCodeKey); - //防止用户攻击修改Cookie - Map _map = new HashMap<>(); - _map.put("person_id", loginMap.get("person_id")); - - int identity_id = Integer.parseInt(loginMap.get("identity_id").toString()); - if (identity_id != 5 && identity_id != 6) { - Kv kv = Kv.by("success", false); - kv.set("msg", "只有教师和学生可以使用本登录功能!"); - renderJson(kv); - return; - } - - SessionKit.set(getRequest(), getResponse(), "person_id", loginMap.get("person_id").toString()); - resultJson.put("success", true); - resultJson.put("person_id", loginMap.get("person_id").toString()); - renderJson(resultJson); - } - - - /** - * 功能:获取登录人员所在学校有哪些年级 - * - * @return - */ - @Before({GET.class}) - @IsLoginInterface({}) - public void getSchoolNjList() { - //操作人员 - String person_id = SessionKit.get(getRequest(), getResponse(), "person_id"); - if (cm.IS_THIRD_PARTY() == 0) { - //根据人员ID,获取人员所在的单位ID - Record rs = personModel.getLoginInfoByPersonId(person_id); - String bureau_id = rs.get("bureau_id"); - List list = cm.getSchoolNjList(bureau_id); - renderJson(CommonUtil.renderJsonForLayUI(list)); - } else { - //需要重写根据第三方数据表,获取当前登录人员所在学校有哪些年级 - Record record = personModel.getTyPersonBureauInfo(person_id); - String bureau_id = record.getStr("org_id");//人员所在单位 - List list = cm.getTySchoolNjList(bureau_id); - renderJson(CommonUtil.renderJsonForLayUI(list)); - } - } - - /** - * 功能:获取当前登录人员所有单位的所有部门列表,不带分页 - * - * @return - */ - @Before({GET.class}) - @IsLoginInterface({}) - public void getOrgList(String keyword) { - //操作人员 - String person_id = SessionKit.get(getRequest(), getResponse(), "person_id"); - if (cm.IS_THIRD_PARTY() == 0) { - //根据人员ID,获取人员所在的单位ID - Record rs = personModel.getLoginInfoByPersonId(person_id); - String bureau_id = rs.get("bureau_id"); - List list = cm.getOrgList(bureau_id, keyword); - renderJson(CommonUtil.renderJsonForLayUI(list)); - } else { - //根据第三方数据表,获取当前登录人员所在单位的内部组织机构 - Record record = personModel.getTyPersonBureauInfo(person_id); - String org_id = record.getStr("bureau_id");//人员所在单位 - List list = cm.getTyOrgList(org_id); - renderJson(CommonUtil.renderJsonForLayUI(list)); - } - } - - /** - * 功能:获取指定部门下的人员信息列表,带分页 - * - * @param org_id 单位id - * @param keyword 关键字 - * @param page 第几页 - * @param limit 每页多少个 - * @return - */ - @Before({GET.class}) - @IsLoginInterface({}) - public void getOrgPersonList(String org_id, String keyword, int page, int limit) { - if (cm.IS_THIRD_PARTY() == 0) { - Page list = cm.getOrgPersonList(org_id, keyword, page, limit); - renderJson(CommonUtil.renderJsonForLayUI(list)); - } else { - //需要重写根据第三方数据表,获取指定部门下有哪些人员 - Page list = cm.getTyOrgPersonList(org_id, keyword, page, limit); - renderJson(CommonUtil.renderJsonForLayUI(list)); - } - } - - /** - * 功能:获取当前登录人员所在单位下的+所在年级下所有班级 - * - * @param nj_id 年级id - * @param keyword 关键字 - * @return - */ - @Before({GET.class}) - @IsLoginInterface({}) - public void getClassList(int nj_id, String keyword, int page, int limit) { - //操作人员 - String person_id = SessionKit.get(getRequest(), getResponse(), "person_id"); - if (cm.IS_THIRD_PARTY() == 0) { - //根据人员ID,获取人员所在的单位ID - Record rs = personModel.getLoginInfoByPersonId(person_id); - String bureau_id = rs.get("bureau_id"); - Page list = cm.getClassList(bureau_id, nj_id, keyword, page, limit); - renderJson(CommonUtil.renderJsonForLayUI(list)); - } else { - //需要重写根据第三方数据表,获取指定年级下有哪些班级 - Record record = personModel.getTyPersonBureauInfo(person_id); - String bureau_id = record.getStr("org_id");//人员所在单位 - - Page list = cm.getTyClassList(bureau_id, nj_id, keyword, page, limit); - renderJson(CommonUtil.renderJsonForLayUI(list)); - } - } - - /** - * 功能:是不是对接了第三方系统 - */ - @Before({GET.class}) - @IsLoginInterface({}) - public void isThirdParty() { - Kv kv = Kv.by("success", true); - kv.set("message", "第三方对接获取成功!"); - kv.set("is_third_party", cm.IS_THIRD_PARTY()); - renderJson(kv); - } - - /** - * 功能:更新Excel中Sheet表与学段的对应关系 - */ - @Before({POST.class}) - @IsLoginInterface({}) - public void updateSheetStage(int job_id, int sheet_index, int stage_id, int b_use) { - cm.updateSheetStage(job_id, sheet_index, stage_id, b_use); - Kv kv = Kv.by("success", true); - kv.set("message", "保存成功!"); - renderJson(kv); - } - - /** - * 功能:获取指定任务的模板与学段的对应关系 - * - * @param job_id - */ - @Before({GET.class}) - @IsLoginInterface({}) - public void getSheetStage(int job_id) { - List list = cm.getSheetStage(job_id); - renderJson(CommonUtil.renderJsonForLayUI(list)); - } - - /** - * 功能:一键智能处理哪些Sheet对应哪些学段 - * - * @param job_id - */ - @Before({POST.class}) - @IsLoginInterface({}) - public void intelligenceSheetStage(int job_id) { - cm.intelligenceSheetStage(job_id); - Kv kv = Kv.by("success", true); - kv.set("message", "保存成功!"); - renderJson(kv); - } - - /** - * 功能:一键全选 - * @param job_id - */ - @Before({POST.class}) - @IsLoginInterface({}) - public void oneKeySheetStage(int job_id){ - cm.oneKeySheetStage(job_id); - Kv kv = Kv.by("success", true); - kv.set("message", "保存成功!"); - renderJson(kv); - } -} - diff --git a/dsPgBase/src/main/java/com/dsideal/dsBase/Collect/Model/CollectModel.java b/dsPgBase/src/main/java/com/dsideal/dsBase/Collect/Model/CollectModel.java deleted file mode 100644 index 0b7487bb..00000000 --- a/dsPgBase/src/main/java/com/dsideal/dsBase/Collect/Model/CollectModel.java +++ /dev/null @@ -1,3313 +0,0 @@ -package com.dsideal.dsBase.Collect.Model; - -import cn.hutool.core.date.DateTime; -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.dsBase.Base.Model.BaseModel; -import com.dsideal.dsBase.Classes.Model.ClassModel; -import com.dsideal.dsBase.Collect.Const.DataType; -import com.dsideal.dsBase.Global.Model.GlobalModel; -import com.dsideal.dsBase.Util.ChineseCharacterUtil; -import com.dsideal.dsBase.Util.CommonUtil; -import com.dsideal.dsBase.Util.PoiUtil; -import com.dsideal.dsBase.Util.SimilarUtil; -import com.hankcs.hanlp.seg.common.Term; -import com.hankcs.hanlp.tokenizer.StandardTokenizer; -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.xssf.streaming.SXSSFWorkbook; -import org.apache.poi.xssf.usermodel.*; - -import java.io.*; -import java.text.ParseException; -import java.text.SimpleDateFormat; -import java.util.*; -import java.util.regex.Matcher; -import java.util.regex.Pattern; - -public class CollectModel { - SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd"); - - - /** - * 功能:是不是使用第三方对接基础数据 - * - * @return - */ - public int IS_THIRD_PARTY() { - //GlobalModel model = new GlobalModel(); - //return Integer.parseInt(model.getGlobalValueByKey("third_party_base_data")); - return 0; - } - - /** - * 功能:操作数据库表 - */ - public void dropTable(String table_name) { - String sql = "DROP TABLE IF EXISTS " + table_name; - Db.update(sql); - } - - /** - * 功能:获取有哪些角色是数据采集自定义上报系统的发布角色 - * -- 某人是否有发的角色+有哪些发的角色 - */ - public List getPersonPublishJobRole(String person_id) { - String sql = "select t1.person_id,t1.duties_id,t2.name as duties_name from t_person_duty as t1 left join t_base_org_type_principalship as t2 on t1.duties_id=t2.id where t1.duties_id in (select publish_role_id from t_collect_role_map group by publish_role_id) and t1.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 bureau_id, String person_id, List 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("bureau_id", bureau_id); - record.set("person_id", person_id); - record.set("publish_state", 0); - record.set("publish_role_id", publish_role_id); - record.set("job_type", 2); - record.set("is_save", 0); - 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_finish", ""); - Db.save("t_collect_job_sheet", "job_id,sheet_index", rSheet); - } - - //3、保存Sheet表中各个列的信息 - List writeList = new ArrayList<>(); - sheetIdx = 0; - for (Kv kv : kvList) { - List list = CommonUtil.castList(kv.get("list"), Record.class); - int colIdx = 0; - for (Record r : list) { - String column_name = r.getStr("column_name"); - String original_name = r.getStr("original_name"); - 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", original_name); - 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); - - //2024-04-07 增加模板中SHEET表与学段的初始化默认关系数据 - String sql = "delete from t_collect_sheet_stage where job_id=?"; //先删除一下,万无一失 - Db.update(sql, job_id); - for (Kv kv : kvList) { - int sheet_index = kv.getInt("sheet_index"); - sql = "insert into t_collect_sheet_stage(job_id,sheet_index,stage_id) values(?,?,?)"; - Db.update(sql, job_id, sheet_index, 4);//小学 - Db.update(sql, job_id, sheet_index, 5);//初中 - Db.update(sql, job_id, sheet_index, 6);//高中 - } - return job_id; - } - - /** - * 功能:获取数据类型的数据字典 - * - * @return - */ - public List 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 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 == DataType.WEB_DATA_TYPE) return record.getStr("web_data_type"); - if (type_id == DataType.PG_DATA_TYPE) return record.getStr("pg_data_type"); - if (type_id == DataType.EXCEL_DATA_TYPE) return record.getStr("excel_data_type"); - } - } - return null; - } - - /** - * 功能:根据任务ID,获取有哪些Sheet表 - * - * @param job_id - */ - public List getSheets(int job_id) { - String sql = "select *,(sheet_index+1) as number 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 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 writeList, String table_name) { - if (writeList.isEmpty()) 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); - //修改整体为未保存状态 - sql = "update t_collect_job set is_save=0 where job_id=?"; - Db.update(sql, job_id); - } - - - /** - * 功能:检查当前登录人员是不是有发布任务的角色 - * - * @param person_id - * @return - */ - public Kv checkPublishRole(String person_id) { - Kv kv = Kv.create(); - //有哪些角色是可以发布任务的角色? - List roleList = getPersonPublishJobRole(person_id); - if (roleList.isEmpty()) { - kv.set("success", false); - kv.set("message", "你不具备发布数据采集任务的角色,请让系统管理员进行配置后重试!"); - return kv; - } - //发布角色,目前写死成第一个,如果以后有用户反馈需要角色切换,就再开发功能进行应对 - kv.set("publish_role_id", roleList.getFirst().getInt("duties_id")); - kv.set("publish_role_name", roleList.getFirst().getStr("duties_name")); - 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=?,is_save=1 where job_id=?"; - Db.update(sql, job_name, upload_excel_filename_finish, job_id); - - sql = "update t_collect_job_sheet set upload_excel_filename_finish=? where job_id=?"; - Db.update(sql, upload_excel_filename_finish, job_id); - - sql = "update t_collect_mapping as t1 set upload_excel_filename_finish=t2.upload_excel_filename_finish from t_collect_job_sheet as t2 where t1.table_name=t2.table_name and t2.job_id=?"; - Db.update(sql, 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); - } - - public Record getJob(int job_id, String bureau_id, String target_id, int status_code) { - String sql = "select * from t_collect_job as t1 inner join t_collect_job_target as t2 on t1.job_id=t2.job_id where t1.job_id=? and t2.target_id=? and t2.status_code=?"; - Record record = Db.findFirst(sql, job_id, target_id, status_code); - - // 比如job_id=1 ,这条我是接收者的,而且,有可能是让我转发下级的,有可能是让我转给本级单位人员的,但是,都是一样的填报截止时间和填报要求,所以,提交第一条即可 - sql = "select memo, deadline_time from t_collect_job_target where job_id =? and target_id =? limit 1"; - Record r2 = Db.findFirst(sql, job_id, bureau_id); - if (r2 != null) { - record.set("prev_memo", r2.getStr("memo")); - record.set("prev_deadline_time", r2.getDate("deadline_time")); - } - return record; - } - - - /** - * 功能:建表时有哪些字段名是保留字,不能用的 - * - * @return - */ - public Set getBlzColumn() { - Set set = new HashSet<>(); - set.add("id");//主键 - set.add("bureau_id");//发布单位 - set.add("person_id");//发布者 - set.add("job_id");//任务号 - set.add("class_id");//班级号 - return set; - } - - /** - * 功能:指定任务+指定SheetIndex下,是不是存在字段名称重复的情况 - * - * @param job_id - * @param sheet_index - * @return - */ - public boolean checkColumnNameDuplicate(int job_id, int sheet_index) { - Set blzList = getBlzColumn();//检查是不是与保留字重复 - String sql = "select column_name,count(1) as c from t_collect_job_sheet_col where job_id=? and sheet_index=? group by column_name having count(1)>1"; - List list = Db.find(sql, job_id, sheet_index); - for (Record record : list) { - String column_name = record.getStr("column_name"); - int c = record.getInt("c"); - if (blzList.contains(column_name)) record.set(column_name, c + 1); - } - return !list.isEmpty(); - } - - public boolean checkColumnNameDuplicate(String json) { - Set blzList = getBlzColumn();//检查是不是与保留字重复 - JSONArray ja = JSONArray.parseArray(json); - for (Object o : ja) { - JSONObject jo = (JSONObject) o; - String column_name = jo.getString("id");//字段名 - if (blzList.contains(column_name)) return false; - blzList.add(column_name); - } - return true; - } - - /** - * 功能:是不是指定任务的所有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 list = getSheetStruct(job_id, sheet_index); - String sheetName = input.getStr("sheet_name"); - 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, DataType.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 = "DROP TABLE IF EXISTS " + table_name + ";"; - finalSql += "CREATE TABLE \"public\".\"" + table_name + "\" ("; - finalSql += "\"id\" serial4,"; - finalSql += "\"area_id\" char(36) NOT NULL,"; - finalSql += "\"area_name\" varchar(255) NOT NULL,"; - finalSql += "\"bureau_id\" char(36) NOT NULL,"; - finalSql += "\"bureau_name\" varchar(255) NOT NULL,"; - finalSql += "\"person_id\" char(36) NOT NULL,"; - finalSql += "\"person_name\" varchar(255) NOT NULL,"; - finalSql += "\"job_id\" int4 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 + "\".\"area_id\" IS '县区ID';\n"; - finalSql += "COMMENT ON COLUMN \"public\".\"" + table_name + "\".\"area_name\" IS '县区名称';\n"; - finalSql += "COMMENT ON COLUMN \"public\".\"" + table_name + "\".\"bureau_id\" IS '单位ID';\n"; - finalSql += "COMMENT ON COLUMN \"public\".\"" + table_name + "\".\"bureau_name\" IS '单位名称';\n"; - finalSql += "COMMENT ON COLUMN \"public\".\"" + table_name + "\".\"person_id\" IS '上报人员ID';\n"; - finalSql += "COMMENT ON COLUMN \"public\".\"" + table_name + "\".\"person_id\" IS '上报人员姓名';\n"; - finalSql += "COMMENT ON COLUMN \"public\".\"" + table_name + "\".\"job_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 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).getInt("data_type_id"))); - record.set("upload_excel_filename_finish", ""); - 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); - - Kv kv = Kv.create(); - kv.set("success", true); - kv.set("message", "表结构创建成功!"); - return kv; - } - - /** - * 功能:PG数据库数据类型与EXCEL中数据类型的转换关系 - * - * @return - */ - public String convertDataType(int data_type_id) { - String res = "String"; - if (data_type_id == 1) res = "String"; - else if (data_type_id == 2) res = "Integer"; - else if (data_type_id == 3) res = "Double"; - else if (data_type_id == 4) 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_finish=? 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 distinct(sheet_index) from t_collect_job_sheet where upload_excel_filename_finish=?"; - List list = Db.find(sql, upload_excel_filename); - return list.size(); - } - - /** - * 功能:获取指定模板+指定Sheet中所有列的限制条件 - * - * @param upload_excel_filename_finish - * @param sheet_index - * @return - */ - public List getSheetMapping(String upload_excel_filename_finish, int sheet_index) { - String sql = "select * from t_collect_mapping where upload_excel_filename_finish=? and sheet_index=?"; - return Db.find(sql, upload_excel_filename_finish, sheet_index); - } - - /** - * 功能:获取指定单位的县区相关信息 - * - * @param bureau_id - * @return - */ - public Record getBureauAreaInfo(String bureau_id) { - String sql = "select t1.area_id from t_base_organization as t1 where t1.org_id=?"; - String area_id = Db.findFirst(sql, bureau_id).getStr("area_id"); - Record record = new Record(); - if (area_id.equals("00000000-0000-0000-0000-000000000000")) { - record.set("area_id", area_id); - record.set("area_name", ""); - } else { - sql = "select area_name from t_dm_area where area_id=?"; - String area_name = Db.findFirst(sql, area_id).getStr("area_name"); - record.set("area_id", area_id); - record.set("area_name", area_name); - } - return record; - } - - /** - * 功能:导入数据 - * - * @throws ParseException - */ - public void importData(int job_id, String upload_excel_filename_finish, XSSFWorkbook wb, int sheetIdx, String bureau_id, String bureau_name, String person_id, String person_name) throws ParseException { - //读取sheet页 - XSSFSheet sheet = wb.getSheetAt(sheetIdx); - //通过表名获取到它的读取起始行,终止列 - String sql = "select * from t_collect_job_sheet where upload_excel_filename_finish=? and sheet_index=?"; - Record record = Db.findFirst(sql, upload_excel_filename_finish, sheetIdx); - String table_name = record.getStr("table_name"); - - //先删除 - sql = "delete from " + table_name + " where bureau_id=? and job_id=?"; - Db.update(sql, bureau_id, job_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_finish=? and sheet_index=?"; - List list = Db.find(sql, upload_excel_filename_finish, sheetIdx); - Map _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 writeList = new ArrayList<>(); - for (int i = data_start_row; i <= sheet.getLastRowNum(); i++) { - //获得行 - XSSFRow row = sheet.getRow(i); - Record areaRecord = getBureauAreaInfo(bureau_id); - String area_id = areaRecord.getStr("area_id"); - String area_name = areaRecord.getStr("area_name"); - - //遍历列 - if (row != null) { - Record writeRecord = new Record(); - writeRecord.set("area_id", area_id); - writeRecord.set("area_name", area_name); - writeRecord.set("bureau_id", bureau_id); - writeRecord.set("bureau_name", bureau_name); - writeRecord.set("person_id", person_id); - writeRecord.set("person_name", person_name); - writeRecord.set("job_id", job_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 (PoiUtil.isMerged(sheet, cell)) { - String value = PoiUtil.getValue(cell); - if (StrKit.isBlank(value)) { - for (int k = i - 1; ; k--) { - String prev = PoiUtil.getValue(sheet.getRow(k).getCell(j)); - if (!StrKit.isBlank(prev)) { - value = prev; - break; - } - } - } - writeRecord.set(colName, value); - } else { - switch (colType) { - case "Integer" : - if (StrKit.isBlank(PoiUtil.getValue(cell))) writeRecord.set(colName, null); - else - writeRecord.set(colName, (int) Double.parseDouble(PoiUtil.getValue(cell))); - break; - case "String" : - if (StrKit.isBlank(PoiUtil.getValue(cell))) writeRecord.set(colName, null); - else writeRecord.set(colName, PoiUtil.getValue(cell)); - break; - case "Double" : - if (StrKit.isBlank(PoiUtil.getValue(cell))) writeRecord.set(colName, null); - else writeRecord.set(colName, Double.parseDouble(PoiUtil.getValue(cell))); - break; - case "Date" : - if (StrKit.isBlank(PoiUtil.getValue(cell))) writeRecord.set(colName, null); - else { - String dateString = PoiUtil.getValue(cell); - Date date = dateFormat.parse(dateString); - writeRecord.set(colName, date); - } - } - break; - } - } - 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 _list = PoiUtil.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.getFirst() - 1);//下标从0开始 - Row ed = sheet.getRow(_list.get(_list.size() - 1) - 1);//下标从0开始 - List list = new ArrayList<>(); - - String column_name, original_name; - Set _set = new HashSet<>(); - 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", "")); - if (StrKit.isBlank(original_name)) { - continue; - } - column_name = ChineseCharacterUtil.getColumnNameByMemo(CommonUtil.removeKuoHao(st.getCell(colNum).toString())); - Record record = new Record(); - record.set("original_name", original_name); - - //如果发现字段名称重复,则不断尝试加1,直到找出不重复的字段名称 - int idx = 1; - while (_set.contains(column_name)) { - column_name += idx; - idx++; - } - _set.add(column_name); - - record.set("column_name", column_name); - list.add(record); - } else { - int k = colNum;//如果最后一列有值 - while (StrKit.isBlank(st.getCell(k).toString())) k--; - - if (k == colNum) { - original_name = st.getCell(k).toString().replace("\n", ""); - column_name = ChineseCharacterUtil.getColumnNameByMemo(CommonUtil.removeKuoHao(st.getCell(k).toString())); - } else { - 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())); - } - //如果发现字段名称重复,则不断尝试加1,直到找出不重复的字段名称 - int idx = 1; - while (_set.contains(column_name)) { - column_name += idx; - idx++; - } - _set.add(column_name); - - 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描述 - * - * @param f1 模板文件 - * @param f2 上传文件 - * @return 不一样的位置集合 - * @throws IOException - */ - public List> 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> 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 pair = new AbstractMap.SimpleEntry<>((i + 1), (j + 1)); - errList.add(pair); - } - } - } - } - file1.close(); - file2.close(); - return errList; - } - - /** - * 功能:返回一个状态的下一个状态 - * - * @param status_code - * @return - */ - public int getNextStausCode(int status_code) { - String sql = "select finish_flag from t_collect_status where status_code=?"; - int finish_flag = Db.findFirst(sql, status_code).getInt("finish_flag"); - if (finish_flag == 1) return status_code; - return status_code + 1; - } - - /** - * 回写完成标记 - * - * @param job_id - * @param bureau_id - * @param upload_excel_filename_user - */ - public void writeJobFinish(int job_id, int status_code, String bureau_id, String upload_excel_filename_user) { - String sql = "update t_collect_job_target set fill_time=now(),upload_excel_filename_user=?,status_code=? where job_id=? and target_id=? and status_code=?"; - Db.update(sql, upload_excel_filename_user, getNextStausCode(status_code), job_id, bureau_id, status_code); - } - - /** - * 功能:查看某个单位对于某个任务的填报情况 - * - * @param job_id - * @param target_id - * @return - */ - public Record viewFilledJob(int job_id, String target_id, int status_code) { - String sql = "select * from t_collect_job_target where job_id=? and target_id=? and status_code=?"; - return Db.findFirst(sql, job_id, target_id, status_code); - } - - - /** - * 功能:获取任务列表,支持关键字查询 - * - * @param job_name - */ - public Page getJobList(String bureau_id, int publish_role_id, String job_name, int self_or_next, int page, int limit) throws ParseException { - Kv kv = Kv.create(); - kv.set("bureau_id", bureau_id); - kv.set("publish_role_id", publish_role_id); - if (!StrKit.isBlank(job_name)) kv.set("job_name", job_name); - /** - 1111,1211,2311 finish_count - 1110,1111,1210,1211,2310,2311 total_count, - 1120,1121,1122,2120,2121,2122 forward_count - 1122,2122 forward_finish_count - */ - kv.set("self_or_next", self_or_next); - - SqlPara sqlPara = Db.getSqlPara("Collect.getJobList", kv); - Page pageRecord = Db.paginate(page, limit, sqlPara); - - 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) { - int finish_count = record.getInt("finish_count"); - int total_count = record.getInt("total_count"); - record.set("fill_progress", finish_count + "/" + total_count); - record.set("publish_state_name", "已发布"); - } else { - record.set("fill_progress", "-"); - record.set("publish_state_name", "未发布"); - } - if (record.getInt("is_save") == 0) { - record.set("is_save", 0); - record.set("is_save_name", "未保存"); - } else { - record.set("is_save", 1); - record.set("is_save_name", "已保存"); - } - if (record.getInt("job_type") == 1) { - record.set("is_save", 1); - record.set("is_save_name", "-"); - } - // 获取当前时间的毫秒数 - long currentTime = System.currentTimeMillis(); - - Calendar calendar = Calendar.getInstance(); - Date deadline_time = record.getDate("deadline_time"); - if (deadline_time == null) { - String dateString = "2100-01-01"; // 假设这是你的初始日期字符串 - 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 getBureauType() { - SqlPara sqlPara = Db.getSqlPara("Collect.getBureauType"); - return Db.find(sqlPara); - } - - /** - * 功能:获取当前安装地区市级的教育局,一般应该是一个,怕特殊情况,可以添加多个 - * - * @return - */ - public List getJiaoYuJu() { - //默认查全市 - GlobalModel gm = new GlobalModel(); - String city_id = gm.getGlobalValueByKey("install_area"); - String sql = "select org_id from t_base_organization where org_type_id=4 and city_id=?"; - return Db.find(sql, city_id); - } - - /** - * 功能:获取单位列表 - * query_type_id: - * 0:查全市 - * 1:只查市直属 - * 2:查登录人员所在县区 - * - * @return - */ - public Page getBureauList(int query_type_id, String bureau_type_ids, String area_id, String org_name, int page, int limit) { - Kv kv = Kv.create(); - //单位类型:1:县区教育局,2:学校,3:教辅单位,4:市教育局 - - List bureau_type_list = Arrays.stream(bureau_type_ids.split(",")).toList(); - - //默认查全市 - GlobalModel gm = new GlobalModel(); - String city_id = gm.getGlobalValueByKey("install_area"); - kv.set("city_id", city_id); - //查县区 - if (!StrKit.isBlank(area_id) && !area_id.equals("00000000-0000-0000-0000-000000000000")) { - kv.set("area_id", area_id); - } - /* - 4 教育局 - 5 市直教辅单位 - 8 幼儿园 - 9 中小学 - 10 职业学校 - - 11 教育局 - 12 信息中心 - 14 教辅单位 - 15 幼儿园 - 16 中小学 - org_type_id - */ - List OrgTypeList = new ArrayList<>(); - if (query_type_id == 1) {//市 - for (String s : bureau_type_list) { - if (s.equals("4")) OrgTypeList.add(4);//市教育局 - if (s.equals("1")) OrgTypeList.add(11);//县区教育局 - if (s.equals("2")) {//学校 - OrgTypeList.add(8); - OrgTypeList.add(9); - OrgTypeList.add(10); - } - if (s.equals("3")) OrgTypeList.add(5);//教辅单位 - } - } else if (query_type_id == 2) {//区 - for (String s : bureau_type_list) { - if (s.equals("1")) OrgTypeList.add(11);//县区教育局 - if (s.equals("2")) {//学校 - OrgTypeList.add(15); - OrgTypeList.add(16); - } - if (s.equals("3")) { - OrgTypeList.add(12);//教辅单位 - OrgTypeList.add(14);//教辅单位 - } - } - } - if (OrgTypeList.size() > 0) kv.set("OrgTypeList", OrgTypeList); - if (!StrKit.isBlank(org_name)) kv.set("org_name", org_name); - SqlPara sqlPara = Db.getSqlPara("Collect.getBureauList", kv); - Page pageRecord = Db.paginate(page, limit, sqlPara); - return pageRecord; - } - - /** - * 功能:获取指定单位下所有教师,未来需扩展支持天喻对接 - * - * @param bureau_id - * @return - */ - public List getAllTeacher(String bureau_id) { - String sql = ""; - if (IS_THIRD_PARTY() == 0) { - sql = "select person_id,person_name from t_sys_loginperson where bureau_id=? and identity_id=5"; - } else { - sql = "select user_id as person_id,name as person_name from ds_base_teacher where bureau_id=?"; - } - return Db.find(sql, bureau_id); - } - - /** - * 功能:获取指定单位下所有学生,未来需扩展支持天喻对接 - * - * @param bureau_id - * @return - */ - public List getAllStudent(String bureau_id) { - String sql = ""; - if (IS_THIRD_PARTY() == 0) { - sql = "select person_id,person_name from t_sys_loginperson where bureau_id=? and identity_id=6"; - } else { - sql = "select user_id as person_id,name as person_name from ds_base_student where bureau_id=?"; - } - return Db.find(sql, bureau_id); - } - - /** - * 功能:获取指定单位+班级下所有学生,未来需扩展支持天喻对接 - * - * @param bureau_id - * @param classIds - * @return - */ - public List getBanJiStudent(String bureau_id, String classIds) { - List res = new ArrayList<>(); - if (StrKit.isBlank(classIds)) return res; - - if (IS_THIRD_PARTY() == 0) { - for (String class_id : classIds.split(",")) { - String sql = "select person_id,person_name from t_sys_loginperson where bureau_id=? and identity_id=6 and s_class_id=?"; - List list = Db.find(sql, bureau_id, class_id); - res.addAll(list); - } - return res; - } else { - for (String class_id : classIds.split(",")) { - String sql = "select user_id as person_id,name as person_name from ds_base_student where org_id=?"; - List list = Db.find(sql, class_id); - res.addAll(list); - } - return res; - } - } - - /** - * 功能:获取当前学年 - * - * @return - */ - public int getCurrentXn() { - String sql = "select xn from t_base_term where ksrq<=? and jsrq>=?"; - int currentXn = Db.findFirst(sql, DateTime.now(), DateTime.now()).getInt("xn"); - return currentXn; - } - - /** - * 功能:获取登录人员所在学校有哪些年级 - * - * @param school_id - * @return - */ - public List getSchoolNjList(String school_id) { - String sql = "select distinct stage_id,entry_year from t_base_class where bureau_id=? and b_use=1 order by stage_id,entry_year desc"; - List list = Db.find(sql, school_id); - - int currentXn = getCurrentXn(); - for (Record record : list) { - int stage_id = record.getInt("stage_id"); - int entry_year = record.getInt("entry_year"); - record.set("nj_id", 0); - if (stage_id == 4) {//小学 - int nj_id = currentXn - entry_year + 1; - record.set("nj_id", nj_id); // 1 ~ 6 - record.set("nj_name", nj_id + "年级"); - } else if (stage_id == 5) {//初中 - int nj_id = currentXn - entry_year + 1 + 6; - record.set("nj_id", nj_id); // 7 ~ 9 - record.set("nj_name", nj_id + "年级"); - } else if (stage_id == 6) {//高中 - int nj_id = currentXn - entry_year + 1 + 9; - record.set("nj_id", nj_id);// 10 ~ 12 - if (nj_id == 10) record.set("nj_name", "高一年级"); - else if (nj_id == 11) record.set("nj_name", "高二年级"); - else if (nj_id == 12) record.set("nj_name", "高三年级"); - } - } - return list; - } - - /** - * 功能:获取天喻系统中学校年级列表 - * - * @param school_id - * @return - */ - public List getTySchoolNjList(String school_id) { - String sql = "select org_name from ds_base_class where bureau_id=? order by org_name"; - List list = Db.find(sql, school_id); - - for (Record record : list) { - String org_name = record.getStr("org_name"); - if (org_name.indexOf("高中一年级") >= 0) { - record.set("nj_id", 10); - record.set("nj_name", "高一年级"); - } else if (org_name.indexOf("高中二年级") >= 0) { - record.set("nj_id", 11); - record.set("nj_name", "高二年级"); - } else if (org_name.indexOf("高中三年级") >= 0) { - record.set("nj_id", 12); - record.set("nj_name", "高三年级"); - } else if (org_name.indexOf("九年级") >= 0) { - record.set("nj_id", 9); - record.set("nj_name", "9年级"); - } else if (org_name.indexOf("八年级") >= 0) { - record.set("nj_id", 8); - record.set("nj_name", "8年级"); - } else if (org_name.indexOf("七年级") >= 0) { - record.set("nj_id", 7); - record.set("nj_name", "7年级"); - } else if (org_name.indexOf("六年级") >= 0) { - record.set("nj_id", 6); - record.set("nj_name", "6年级"); - } else if (org_name.indexOf("五年级") >= 0) { - record.set("nj_id", 5); - record.set("nj_name", "五年级"); - } else if (org_name.indexOf("四年级") >= 0) { - record.set("nj_id", 4); - record.set("nj_name", "4年级"); - } else if (org_name.indexOf("三年级") >= 0) { - record.set("nj_id", 3); - record.set("nj_name", "3年级"); - } else if (org_name.indexOf("二年级") >= 0) { - record.set("nj_id", 2); - record.set("nj_name", "2年级"); - } else if (org_name.indexOf("一年级") >= 0) { - record.set("nj_id", 1); - record.set("nj_name", "1年级"); - } - } - return list; - } - - /** - * 功能:获取指定单位+年级下所有学生,未来需扩展支持天喻对接 - * - * @param bureau_id - * @param njIds (1,2,3,4,5,6:小学),(7,8,9:初中),(10,11,12:高中) - * @return - */ - public List getNianJiStudent(String bureau_id, String njIds) { - List res = new ArrayList<>(); - if (StrKit.isBlank(njIds)) return res; - //stage_id 4:小学 5:初中 6:高中 8:幼儿 - List list = new ArrayList<>(); - //当前学年 - int currentXn = getCurrentXn(); - for (String nj : njIds.split(",")) { - int njNum = Integer.parseInt(nj); - Record record = new Record(); - if (njNum <= 6) { - record.set("stage_id", 4);//小学 - record.set("entry_year", currentXn - njNum + 1); - } else if (njNum <= 9) { - record.set("stage_id", 5);//初中 - record.set("entry_year", currentXn - njNum + 6 + 1); - } else { - record.set("stage_id", 6);//高中 - record.set("entry_year", currentXn - njNum + 9 + 1); - } - list.add(record); - } - - //根据年级找所有班级 - for (Record rNj : list) { - int stage_id = rNj.getInt("stage_id"); - int entry_year = rNj.getInt("entry_year"); - String sql = "select class_id from t_base_class where bureau_id=? and stage_id=? and entry_year=? and b_use=1"; - List listClass = Db.find(sql, bureau_id, stage_id, entry_year); - for (Record aClass : listClass) { - //根据班级找学生 - List listStudent = getBanJiStudent(bureau_id, aClass.getStr("class_id")); - res.addAll(listStudent); - } - } - return res; - } - - /** - * 功能:获取单位类型 - * - * @param target_id - * @return - */ - private int getOrgTypeId(String target_id, boolean forPerson) { - String bureau_id = target_id; - if (forPerson) { - String sql = "select bureau_id from t_sys_loginperson where person_id=?"; - Record record = Db.findFirst(sql, target_id); - bureau_id = record.getStr("bureau_id"); - } - String sql = "select org_type_id from t_base_organization where org_id=?"; - Record record = Db.findFirst(sql, bureau_id); - int org_type_id = record.getInt("org_type_id"); - return org_type_id;//其它的统一回3,表示是单位 - } - - /** - * 功能:发布任务 - * - * @param job_id 任务编号 - * @param deadline_time 截止时间 - * @param xiaShuSchool 下属学校:1选中,0未选中 - * @param xiaShuJiaoFu 下属教辅单位:1选中,0未选中 - * @param xiaShuJiaoYuJu 下属教育局:1选中,0未选中 - * @param shiJiaoYuJu 市教育局 - * @param bureauIds 按单位选择的单位ids - * @param groupIds 群组ids - * @param memo 任务描述 - * @param fill_type_id 填报任务类型 1:填报,2:转发,3:填报+转发(只对县区局有效) - * @param allTeacher 所有教师 - * @param allStudent 所有学生 - * @param njIds 哪些年级,比如1,2表示1、2年级所有学生 - * @param personIds 哪些人员(目前只支持教师) - * @param classIds 哪些班级 * - * @param area_id 如果是全区发,那是哪个区 - */ - public void publishJob(int publish_role_id, int job_id, String deadline_time, - String area_id, int xiaShuSchool, int xiaShuJiaoFu, int xiaShuJiaoYuJu, - int shiJiaoYuJu, String bureauIds, String groupIds, String memo, - int fill_type_id, int allTeacher, int allStudent, String njIds, - String personIds, String classIds) throws ParseException { - - // 1:市 2:县区 3:单位 - int publish_job_type_id = getPublishJobTypeId(publish_role_id); - Record jobRecord = getJob(job_id); - String bureau_id = jobRecord.getStr("bureau_id");//发布单位id - - Set targetSet = new HashSet<>(); - //市级发布 - if (publish_job_type_id == 1) { - if (xiaShuSchool == 1) { - //query_type_id=1:只查市直属 - Page list = getBureauList(1, "2", null, null, 1, 9999); - for (Record record : list.getList()) { - Kv kv = Kv.by("target_id", record.getStr("org_id")); - kv.set("target_type_id", 1);//1:单位,2:人员 - targetSet.add(kv); - } - } - if (xiaShuJiaoFu == 1) { - Page list = getBureauList(1, "3", null, null, 1, 9999); - for (Record record : list.getList()) { - Kv kv = Kv.by("target_id", record.getStr("org_id")); - kv.set("target_type_id", 1);//1:单位,2:人员 - targetSet.add(kv); - } - } - if (xiaShuJiaoYuJu == 1) { - Page list = getBureauList(1, "1", null, null, 1, 9999); - for (Record record : list.getList()) { - Kv kv = Kv.by("target_id", record.getStr("org_id")); - kv.set("target_type_id", 1);//1:单位,2:人员 - targetSet.add(kv); - } - } - //市教育局 - if (shiJiaoYuJu == 1) { - List list = getJiaoYuJu(); - for (Record record : list) { - Kv kv = Kv.by("target_id", record.getStr("org_id")); - kv.set("target_type_id", 1);//1:单位,2:人员 - targetSet.add(kv); - } - } - } - //县区级发布 - else if (publish_job_type_id == 2) { - //所有老师 - if (allTeacher == 1) { - for (Record r : getAllTeacher(bureau_id)) { - Kv kv = Kv.by("target_id", r.getStr("person_id")); - kv.set("target_type_id", 2);//1:单位,2:人员 - targetSet.add(kv); - } - } - if (xiaShuSchool == 1) { - //query_type_id=2:查县区属 - Page list = getBureauList(2, "2", area_id, null, 1, 9999); - for (Record record : list.getList()) { - Kv kv = Kv.by("target_id", record.getStr("org_id")); - kv.set("target_type_id", 1);//1:单位,2:人员 - targetSet.add(kv); - } - } - if (xiaShuJiaoFu == 1) { - Page list = getBureauList(2, "3", area_id, null, 1, 9999); - for (Record record : list.getList()) { - Kv kv = Kv.by("target_id", record.getStr("org_id")); - kv.set("target_type_id", 1);//1:单位,2:人员 - targetSet.add(kv); - } - } - } - // 校级发布 - else if (publish_job_type_id == 3) { - //所有老师 - if (allTeacher == 1) { - for (Record r : getAllTeacher(bureau_id)) { - Kv kv = Kv.by("target_id", r.getStr("person_id")); - kv.set("target_type_id", 2);//1:单位,2:人员 - targetSet.add(kv); - } - } - //所有学生 - if (allStudent == 1) { - for (Record r : getAllStudent(bureau_id)) { - Kv kv = Kv.by("target_id", r.getStr("person_id")); - kv.set("target_type_id", 2);//1:单位,2:人员 - targetSet.add(kv); - } - } - //年级 - for (Record r : getNianJiStudent(bureau_id, njIds)) { - Kv kv = Kv.by("target_id", r.getStr("person_id")); - kv.set("target_type_id", 2);//1:单位,2:人员 - targetSet.add(kv); - } - //班级 - for (Record r : getBanJiStudent(bureau_id, classIds)) { - Kv kv = Kv.by("target_id", r.getStr("person_id")); - kv.set("target_type_id", 2);//1:单位,2:人员 - targetSet.add(kv); - } - //人员 - if (!StrKit.isBlank(personIds)) { - for (String s : personIds.split(",")) { - Kv kv = Kv.by("target_id", s); - kv.set("target_type_id", 2);//1:单位,2:人员 - targetSet.add(kv); - } - } - } - //指定单位列表 - if (!StrKit.isBlank(bureauIds)) { - for (String s : bureauIds.split(",")) { - Kv kv = Kv.by("target_id", s); - kv.set("target_type_id", 1);//1:单位,2:人员 - targetSet.add(kv); - } - } - - // 指定群组 - if (!StrKit.isBlank(groupIds)) { - for (String group_id : groupIds.split(",")) { - int group_type_id = getGroup(Integer.parseInt(group_id)).getInt("group_type_id"); - List list = getGroupTargetList(Integer.parseInt(group_id)); - for (Record record : list) { - Kv kv = Kv.by("target_id", record.getStr("target_id")); - kv.set("target_type_id", group_type_id);//1:单位,2:人员 - targetSet.add(kv); - } - } - } - - Date date = dateFormat.parse(deadline_time); - - //先删除后插入,干净又卫生 - String sql = "delete from t_collect_job_target where job_id=?"; - Db.update(sql, job_id); - - //这个任务是发给单位的,还是发给人的 - int target_type_id = jobRecord.getInt("target_type_id");//任务类型 - - //写任务分派表 - List list = new ArrayList<>(); - //现在这个要发送的对象,是单位:1,还是人:2 - // 使用 for-each 循环获取第一个元素 - int now_target_type_id = 0; - for (Kv kv : targetSet) { - now_target_type_id = kv.getInt("target_type_id"); - break; - } - //如果是单位,获取一下单位的target_id,target_name - Map _map; - Set _set = new HashSet<>(); - for (Kv kv : targetSet) { - _set.add(kv.getStr("target_id")); - } - if (now_target_type_id == 1) { - _map = getBureauMap(_set); - } else {//如果是人,获取一下人员的target_id,target_name - _map = getPersonMap(_set); - } - for (Kv kv : targetSet) { - String target_id = kv.getStr("target_id"); - //哪种类型的单位要接受这个任务呢? - int orgTypeId = getOrgTypeId(target_id, now_target_type_id == 2); - List statusCodeList = new ArrayList<>(); - //按发布对象分类 - switch (target_type_id) { - case 1: //单位 - if (publish_job_type_id == 1) {//市 - if (orgTypeId == 9 || orgTypeId == 8 || orgTypeId == 5 || orgTypeId == 4) {// 9:中小学 8:幼儿园 5:教辅单位 4:市教育局 - statusCodeList.add(1110);//单位,市,填报,未进行 - } - if (orgTypeId == 11) {//11:区县教育局 - if (fill_type_id == 1) statusCodeList.add(1110);//单位,市,填报,未完成 - if (fill_type_id == 2) statusCodeList.add(1120);//单位,市,转发下级,未完成 - if (fill_type_id == 3) { - statusCodeList.add(1110);//单位,市,填报,未完成 - statusCodeList.add(1120);//单位,市,转发下级,未完成 - } - } - } - if (publish_job_type_id == 2) {//县区 - //接收者:县区教育局,县区教辅单位,县区学校 - statusCodeList.add(1210); //单位任务,县发起,需填报,未填报 - } - if (publish_job_type_id == 3) {//单位 - //这里不可能进来,因为单位不能向自己单位发布单位填报任务! - } - break; - case 2:// 人员 - if (publish_job_type_id == 1) {//市 - if (orgTypeId == 9 || orgTypeId == 8 || orgTypeId == 5 || orgTypeId == 4) {// 9:中小学 8:幼儿园 5:教辅单位 4:市教育局 - statusCodeList.add(2130);//单位,市,向本级转发,未进行 - } - if (orgTypeId == 11) {//11:区县教育局 - if (fill_type_id == 1) statusCodeList.add(2130); //人员任务,市里发的,要求向本单位转发的,还没有转发的 - if (fill_type_id == 2) statusCodeList.add(2120); //人员任务,市里发的,要求向下级单位转发的,还没有转发的 - if (fill_type_id == 3) { - statusCodeList.add(2130); //人员任务,市里发的,要求向本单位转发的,还没有转发的 - statusCodeList.add(2120); //人员任务,市里发的,要求向下级单位转发的,还没有转发的 - } - } - } - if (publish_job_type_id == 2) {//县区 - //接收者:县区教育局,县区教辅单位,县区学校 - statusCodeList.add(2310); //人员任务,县发起,需转发本单位,未转发 - } - if (publish_job_type_id == 3) {//单位 - statusCodeList.add(2310); //2:人员任务,3:单位发的,1:填报任务,0:没填写 - } - break; - } - for (Integer status_code : statusCodeList) { - Record record = new Record(); - record.set("now_target_type_id", now_target_type_id); - record.set("target_id", target_id); - record.set("target_name", _map.get(target_id)); - record.set("job_id", job_id); - record.set("deadline_time", date); - record.set("bureau_id", bureau_id); - record.set("memo", memo); - record.set("status_code", status_code); - list.add(record); - } - } - Db.batchSave("t_collect_job_target", list, 500); - - //写主表 - sql = "update t_collect_job set publish_time=now(),publish_state=1 where job_id=?"; - Db.update(sql, job_id); - } - - /** - * 功能:获取指定一组单位ID和单位名称的对应关系 - * - * @param set - * @return - */ - public Map getBureauMap(Set set) { - Map map = new HashMap<>(); - String str = ""; - for (String target_id : set) { - str += "'" + target_id + "',"; - } - str = str.substring(0, str.length() - 1); - String sql = "select org_id,org_name from t_base_organization where org_id in (" + str + ")"; - List list = Db.find(sql); - for (Record record : list) { - map.put(record.getStr("org_id"), record.getStr("org_name")); - } - return map; - } - - /** - * 功能:获取指定一组人员ID和人员姓名的对应关系 - * - * @param set - * @return - */ - public Map getPersonMap(Set set) { - Map map = new HashMap<>(); - String str = ""; - for (String target_id : set) { - str += "'" + target_id + "',"; - } - str = str.substring(0, str.length() - 1); - if (IS_THIRD_PARTY() == 0) { - String sql = "select person_id,person_name from t_sys_loginperson where person_id in (" + str + ")"; - List list = Db.find(sql); - for (Record record : list) { - map.put(record.getStr("person_id"), record.getStr("person_name")); - } - } else { - String sql = "select user_id as person_id,name as person_name from ds_base_student where user_id in (" + str + ")"; - List list = Db.find(sql); - for (Record record : list) { - map.put(record.getStr("person_id"), record.getStr("person_name")); - } - sql = "select user_id as person_id,name as person_name from ds_base_teacher where user_id in (" + str + ")"; - list = Db.find(sql); - for (Record record : list) { - map.put(record.getStr("person_id"), record.getStr("person_name")); - } - } - return map; - } - - /** - * 功能:重命名任务 - * - * @param job_id - * @param job_name - */ - public void renameJob(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); - } - - /** - * 功能:删除任务 - * - * @param job_id - */ - public void delJob(int job_id) { - // 检查此任务是否关联的表,只被它一个人使用,如果是,就删除相关表 - String sql = "select form_table_name from t_collect_job where job_id=?"; - String form_table_name = Db.findFirst(sql, job_id).getStr("form_table_name"); - if (!StrKit.isBlank(form_table_name)) { - sql = "select count(1) as c from t_collect_job where form_table_name=? and job_id<>?"; - int c = Db.findFirst(sql, form_table_name, job_id).getInt("c"); - if (c == 0) dropTable(form_table_name); - } - - sql = "select table_name from t_collect_job_sheet where job_id=?"; - List list = Db.find(sql, job_id); - for (Record record : list) { - String table_name = record.getStr("table_name"); - sql = "select count(1) as c from t_collect_job_sheet where job_id<>? and table_name=?"; - int c = Db.findFirst(sql, job_id, table_name).getInt("c"); - if (c == 0) dropTable(table_name); - } - - sql = "delete from t_collect_job where job_id=?"; - Db.update(sql, job_id); - - sql = "delete from t_collect_job_target where job_id=?"; - Db.update(sql, job_id); - - sql = "delete from t_collect_job_sheet where job_id=?"; - Db.update(sql, job_id); - - sql = "delete from t_collect_job_sheet_col where job_id=?"; - Db.update(sql, job_id); - } - - - /** - * 功能:延期任务 - * - * @param job_id 任务号 - */ - public void extensionJob(int job_id, String deadline_time, String bureau_id) throws ParseException { - String sql = "update t_collect_job_target set deadline_time=? where job_id=? and bureau_id=?"; - Date date = dateFormat.parse(deadline_time); - Db.update(sql, date, job_id, bureau_id); - } - - /** - * 功能:克隆任务 - * - * @param job_id - * @param job_name - */ - public void cloneJob(int job_id, String job_name) { - //1、t_collect_job - String sql = "select * from t_collect_job where job_id=?"; - Record record = Db.findFirst(sql, job_id); - record.remove("job_id"); - record.set("job_name", job_name); - record.set("publish_time", null); - record.set("publish_state", 0); - record.set("is_clone", 1); - Db.save("t_collect_job", "job_id", record); - int newJobId = record.getInt("job_id"); - - //2、t_collect_job_sheet - sql = "select * from t_collect_job_sheet where job_id=?"; - List list = Db.find(sql, job_id); - for (Record r : list) { - r.set("job_id", newJobId); - } - Db.batchSave("t_collect_job_sheet", list, 100); - - //3、t_collect_job_sheet_col - sql = "select * from t_collect_job_sheet_col where job_id=?"; - list = Db.find(sql, job_id); - for (Record r : list) { - r.set("job_id", newJobId); - } - Db.batchSave("t_collect_job_sheet_col", list, 100); - } - - /** - * 功能:学校(单位)查看我该填报或者我已填报的任务列表 - * - * @param status_codes 状态码 - * @param bureau_id 单位ID - * @param keyword 搜索关键字 - * @param limit 每页多少个 - * @param page 第几页 - */ - public Page viewJobList(int publish_role_id, String bureau_id, String keyword, String status_codes, int page, int limit) { - Kv kv = Kv.create(); - kv.set("bureau_id", bureau_id); - if (!StrKit.isBlank(keyword)) kv.set("keyword", keyword); - - //判断是 市:1 县区:2 单位:3 - int publish_job_type_id = getPublishJobTypeId(publish_role_id); - if (!StrKit.isBlank(status_codes)) { - List idList = new ArrayList<>(); - for (String s : status_codes.split(",")) { - int status_code = Integer.parseInt(s); - idList.add(status_code); - } - kv.set("idList", idList); - } - - SqlPara sqlPara; - if (publish_job_type_id == 2) { - sqlPara = Db.getSqlPara("Collect.viewJobListForArea", kv); - } else { - sqlPara = Db.getSqlPara("Collect.viewJobList", kv); - } - - Page pageRecord = Db.paginate(page, limit, sqlPara); - for (Record record : pageRecord.getList()) { - record.set("publish_time", record.getStr("publish_time").split(" ")[0]); - record.set("create_time", record.getStr("create_time").split(" ")[0]); - record.set("deadline_time", record.getStr("deadline_time").split(" ")[0]); - if (record.getInt("job_type") == 1) record.set("job_type_name", "表单"); - else if (record.getInt("job_type") == 2) record.set("job_type_name", "EXCEL模板"); - - Date deadline_time = record.getDate("deadline_time"); - Calendar calendar = Calendar.getInstance(); - calendar.setTime(deadline_time); - calendar.add(Calendar.DAY_OF_MONTH, 1); - // 获取当前时间的毫秒数 - long currentTime = System.currentTimeMillis(); - record.set("jiezhi", calendar.getTime().getTime() < currentTime); - } - return pageRecord; - } - - /** - * 功能: 任务发布者,查看发布的任务填充情况 - * - * @param job_id - * @param keyword - * @param status_codes - * @param page - * @param limit - */ - public Page viewJob(int job_id, String bureau_id, String keyword, String status_codes, int self_or_next, int page, int limit) { - Kv kv = Kv.create(); - kv.set("job_id", job_id); - - //创建者单位ID - String creatorBureauId = getJob(job_id).getStr("bureau_id"); - kv.set("creatorBureauId", creatorBureauId); - kv.set("bureau_id", bureau_id); - - if (!StrKit.isBlank(keyword)) kv.set("keyword", keyword); - - List idList = new ArrayList<>(); - for (String s : status_codes.split(",")) { - int status_code = Integer.parseInt(s); - idList.add(status_code); - } - kv.set("idList", idList); - - SqlPara sqlPara; - if (self_or_next == 2) {//看下级,出单位 - sqlPara = Db.getSqlPara("Collect.viewBureauJob", kv); - } else { - sqlPara = Db.getSqlPara("Collect.viewPersonJob", kv); - } - - Page pageRecord = Db.paginate(page, limit, sqlPara); - for (Record record : pageRecord.getList()) { - if (record.getStr("telephone") == null || record.getStr("telephone").trim().equals("-1")) - record.set("telephone", "-"); - if (record.getStr("email") == null || record.getStr("email").trim().equals("-1")) - record.set("email", "-"); - } - return pageRecord; - } - - /** - * 功能:增加一个表单式的新任务 - * - * @param target_type_id 1:单位 1,2:人员 - * @param job_name - * @param json - * @return - */ - public int addFormJob(int target_type_id, String bureau_id, String person_id, int publish_role_id, String - job_name, String table_name, String json, int self_or_next) { - table_name = table_name.toLowerCase(); - //1、保存任务信息 - Record record = new Record(); - record.set("job_name", job_name); - record.set("create_time", DateTime.now()); - record.set("bureau_id", bureau_id); - record.set("person_id", person_id); - record.set("publish_state", 0); - record.set("publish_role_id", publish_role_id); - record.set("job_type", 1); - record.set("is_save", 1); - record.set("form_table_name", table_name); - record.set("target_type_id", target_type_id); - record.set("form_json", json); - record.set("self_or_next", self_or_next); - Db.save("t_collect_job", "job_id", record); - int job_id = record.getInt("job_id"); - //2、需要在这里建表,因为发布时不管建表,只管可见范围 - createTable(job_name, table_name, json); - return job_id; - } - - /** - * 功能:创建表 - * - * @param job_name - * @param table_name - * @param json - */ - private void createTable(String job_name, String table_name, String json) { - table_name = table_name.toLowerCase(); - JSONArray ja = parseGridJson(json); - String colSql = "", commentSql = ""; - for (Object o : ja) { - JSONObject jo = (JSONObject) o; - // 数据类型 - int data_type_id = DataType.getFormDataType(jo); - if (data_type_id == 0) continue;//布局组件不用创建字段 - jo.put("data_type_id", data_type_id); - boolean required = jo.getBoolean("required");//必填 - String original_name = jo.getString("label");//描述 - String column_name = jo.getString("id");//字段名 - String column_type = getDataType(data_type_id, DataType.PG_DATA_TYPE); - colSql += "\"" + column_name + "\" " + column_type; - if (required) 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 += "\"area_id\" char(36) NOT NULL,"; - finalSql += "\"area_name\" varchar(255) NOT NULL,"; - finalSql += "\"bureau_id\" char(36) NOT NULL,"; - finalSql += "\"bureau_name\" varchar(255) NOT NULL,"; - finalSql += "\"person_id\" char(36) NOT NULL,"; - finalSql += "\"person_name\" varchar(255) NOT NULL,"; - finalSql += "\"class_id\" char(36) ,"; - finalSql += "\"class_name\" varchar(255),"; - - finalSql += "\"job_id\" int4 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 + "\".\"area_id\" IS '县区ID';\n"; - finalSql += "COMMENT ON COLUMN \"public\".\"" + table_name + "\".\"area_name\" IS '县区名称';\n"; - finalSql += "COMMENT ON COLUMN \"public\".\"" + table_name + "\".\"bureau_id\" IS '单位ID';\n"; - finalSql += "COMMENT ON COLUMN \"public\".\"" + table_name + "\".\"bureau_name\" IS '单位名称';\n"; - finalSql += "COMMENT ON COLUMN \"public\".\"" + table_name + "\".\"person_id\" IS '上传人员ID';\n"; - finalSql += "COMMENT ON COLUMN \"public\".\"" + table_name + "\".\"person_name\" IS '填报人员姓名';\n"; - finalSql += "COMMENT ON COLUMN \"public\".\"" + table_name + "\".\"class_id\" IS '班级ID';\n"; - finalSql += "COMMENT ON COLUMN \"public\".\"" + table_name + "\".\"class_name\" IS '班级名称';\n"; - finalSql += "COMMENT ON COLUMN \"public\".\"" + table_name + "\".\"job_id\" IS '任务ID';\n"; - finalSql += commentSql; - finalSql += "COMMENT ON TABLE \"public\".\"" + table_name + "\" IS '" + job_name + "';"; - //添加索引 - finalSql += "CREATE INDEX ON \"public\".\"" + table_name + "\" (\"bureau_id\");"; - finalSql += "CREATE INDEX ON \"public\".\"" + table_name + "\" (\"person_id\");"; - Db.update(finalSql); - } - - /** - * 功能:更新一个存在的表单式任务 - * - * @param job_id - * @param json - */ - public void updateFormJob(int job_id, String job_name, String json, String table_name) { - Record record = getJob(job_id); - String form_table_name = record.getStr("form_table_name"); - dropTable(form_table_name); - //更新数据 - String sql = "update t_collect_job set job_name=?,form_json=?,form_table_name=? where job_id=?"; - Db.update(sql, job_name, json, table_name, job_id); - //需要在这里建表,因为发布时不管建表,只管可见范围 - createTable(job_name, table_name, json); - } - - /** - * 功能:填报者保存填报结果 - */ - public void saveFormJob(int job_id, int status_code, String bureau_id, String bureau_name, String s_class_id, String - person_id, String person_name, String json) { - Record rJob = getJob(job_id); - String table_name = rJob.getStr("form_table_name"); - String form_json = rJob.getStr("form_json"); - - //是面向单位的填报,还是面向人员的填报 - int target_type_id = rJob.getInt("target_type_id"); - Record areaRecord = getBureauAreaInfo(bureau_id); - String area_id = areaRecord.get("area_id"); - String area_name = areaRecord.getStr("area_name"); - //先删除后插入,保持健康 - String sql; - if (target_type_id == 1) { - sql = "delete from " + table_name + " where job_id=? and bureau_id=?"; - } else { - sql = "delete from " + table_name + " where job_id=? and person_id=?"; - } - Db.update(sql, job_id, bureau_id); - - JSONObject j1 = JSONObject.parseObject(json); - Record record = new Record(); - if (!s_class_id.equals("-1")) {//学生 - ClassModel cm = new ClassModel(); - if (IS_THIRD_PARTY() == 0) { - String class_name = cm.getClassInfoByClassId(s_class_id).getString("class_name"); - record.set("class_id", s_class_id); - record.set("class_name", class_name); - } else { - if (!s_class_id.equals("-1")) { - String class_name = getTyClassInfoByClassId(s_class_id).getStr("class_name"); - record.set("class_id", s_class_id); - record.set("class_name", class_name); - } else { - record.set("class_id", ""); - record.set("class_name", ""); - } - } - } - record.set("job_id", job_id); - record.set("area_id", area_id); - record.set("area_name", area_name); - record.set("bureau_id", bureau_id); - record.set("bureau_name", bureau_name); - record.set("person_id", person_id); - record.set("person_name", person_name); - - //读取原来的结构,根据原来结构的类型进行判断,获取现在需要用什么样的读取方式 - JSONArray ja = parseGridJson(form_json); - - Map _map = new HashMap<>(); - Set _checkBoxSet = new HashSet<>(); - for (int i = 0; i < ja.size(); i++) { - JSONObject j2 = ja.getJSONObject(i); - int data_type_id = DataType.getFormDataType(j2); - _map.put(j2.getString("id"), data_type_id);//哪个字段是什么类型 - //对于checkbox需要做特殊处理,"tag":"checkbox","tagIcon":"checkbox" - if (j2.getString("tag").equals("checkbox")) { - _checkBoxSet.add(j2.getString("id")); - } - } - Map> checkBoxSelectMap = new HashMap<>(); - for (Map.Entry entry : j1.entrySet()) { - String key = entry.getKey(); - //优先处理checkbox问题 - boolean flag = false; - for (String s : _checkBoxSet) { - if (key.startsWith(s + "[")) { - //如果存在,值肯定是on,只需要记录中括号里面的整数值 - Pattern pattern = Pattern.compile("\\[(\\d+)]"); - Matcher matcher = pattern.matcher(key); - if (matcher.find()) { - int x = Integer.parseInt(matcher.group(1));//数值 - List listSelectNumber = new ArrayList<>(); - if (checkBoxSelectMap.containsKey(s)) listSelectNumber = checkBoxSelectMap.get(s); - listSelectNumber.add(x); - checkBoxSelectMap.put(s, listSelectNumber); - } - flag = true; - } - } - if (flag) { - Pattern pattern = Pattern.compile("^(.*?)\\[\\d+]"); - Matcher matcher = pattern.matcher(key); - if (matcher.find()) { - String result = matcher.group(1); - record.set(result, 1);//表示复选框已填写内容,真正的内容在t_collect_checkbox表中 - } - continue; - } - - int data_type_id = _map.get(key); - switch (data_type_id) { - case 0: - continue; - case 1://文本 - String v1 = entry.getValue().toString(); - record.set(key, v1); - break; - case 2://数字 - int v2; - if (StrKit.isBlank(entry.getValue().toString())) v2 = 0; - else v2 = Integer.parseInt(entry.getValue().toString()); - record.set(key, v2); - break; - case 3://小数 - double v3; - if (StrKit.isBlank(entry.getValue().toString())) v3 = 0; - else v3 = Double.parseDouble(entry.getValue().toString()); - record.set(key, v3); - break; - case 4: //日期 - Date v4 = DateUtil.parse(entry.getValue().toString()); - record.set(key, v4); - break; - default: - break; - } - } - Db.save(table_name, "id", record); - //保存原始JSON数据+修改完成标识 - sql = "update t_collect_job_target set form_fill_json=?,fill_time=now(),status_code=? where job_id=? and target_id=? and status_code=?"; - if (target_type_id == 1) { - Db.update(sql, json, getNextStausCode(status_code), job_id, bureau_id, status_code); - } else { - Db.update(sql, json, getNextStausCode(status_code), job_id, person_id, status_code); - } - - //保存多选结果 - //先删除 - if (target_type_id == 1) { - sql = "delete from t_collect_checkbox where job_id=? and bureau_id=?"; - } else { - sql = "delete from t_collect_checkbox where job_id=? and person_id=?"; - } - Db.update(sql, job_id, bureau_id); - - //后插入 - List writeList = new ArrayList<>(); - for (Map.Entry> entry : checkBoxSelectMap.entrySet()) { - String key = entry.getKey(); - List value = entry.getValue(); - - for (Integer i : value) { - Record r = new Record(); - r.set("job_id", job_id); - r.set("bureau_id", bureau_id); - r.set("person_id", person_id); - r.set("input_id", key); - r.set("value", i); - writeList.add(r); - } - } - if (writeList.size() > 0) Db.batchSave("t_collect_checkbox", writeList, 100); - } - - /** - * 功能:根据天喻的班级编号获取班级实例 - * - * @param s_class_id - * @return - */ - public Record getTyClassInfoByClassId(String s_class_id) { - String sql = "select org_name as class_name from ds_base_class where org_id=?"; - Record record = Db.findFirst(sql, s_class_id); - return record; - } - - /** - * 功能:获取指定任务指定单位的填报内容 - * - * @param job_id - * @param target_id - */ - public String getFormFillJob(int job_id, String target_id, int status_code) { - String sql = "select form_fill_json from t_collect_job_target where target_id=? and job_id=? and status_code=?"; - Record record = Db.findFirst(sql, target_id, job_id, status_code); - if (record == null) return ""; - return record.getStr("form_fill_json"); - } - - /** - * 功能:增加组 - * - * @param group_name - */ - public int addGroup(String group_name, int group_type_id, String target_ids, String bureau_id, String person_id) { - Record record = new Record(); - record.set("group_name", group_name); - record.set("target_ids", target_ids); - record.set("group_type_id", group_type_id); - record.set("bureau_id", bureau_id); - record.set("person_id", person_id); - Db.save("t_collect_group", "group_id", record); - return record.getInt("group_id"); - } - - /** - * 功能:更新组 - * - * @param group_id - * @param group_name - * @param target_ids - */ - public void updateGroup(int group_id, String group_name, String target_ids) { - Record record = Db.findById("t_collect_group", "group_id", group_id); - record.set("group_name", group_name); - record.set("target_ids", target_ids); - Db.update("t_collect_group", "group_id", record); - } - - /** - * 功能:组列表 - */ - public List listGroup(String bureau_id, int group_type_id) { - String sql = "select * from t_collect_group where bureau_id=? and group_type_id=?"; - return Db.find(sql, bureau_id, group_type_id); - } - - /** - * 功能:删除组 - * - * @param group_id - */ - public void delGroup(int group_id) { - String sql = "delete from t_collect_group where group_id=?"; - Db.update(sql, group_id); - } - - /** - * 功能:获取群组类型ID - * - * @param group_id - * @return - */ - public Record getGroup(int group_id) { - Record record = Db.findById("t_collect_group", "group_id", group_id); - return record; - } - - /** - * 功能:获取组内有哪些成员 - * - * @param group_id - */ - public List getGroupTargetList(int group_id) { - List res = new ArrayList<>(); - - Record record = getGroup(group_id); - //群组类型 - int group_type_id = record.getInt("group_type_id"); - - //单位 - List idList = new ArrayList<>(); - String target_ids = record.getStr("target_ids"); - if (!StrKit.isBlank(target_ids)) { - for (String s : target_ids.split(",")) { - idList.add(s); - } - } - Kv kv = Kv.by("idList", idList); - SqlPara sqlPara; - if (group_type_id == 1) { - sqlPara = Db.getSqlPara("Collect.getGroupBureau", kv); - } else { - sqlPara = Db.getSqlPara("Collect.getGroupPerson", kv);//人 - } - List list = Db.find(sqlPara); - if (list.size() > 0) res.addAll(list); - return res; - } - - /** - * 功能:用户填写form表单时,记录他上传的文件信息 - * - * @param job_id - * @param input_id - * @param type_id - * @param target_id - * @param person_id - * @param fileName - * @param file_id - * @param suffix - * @param file_size - */ - public int saveUploadFile(int job_id, String input_id, int type_id, String target_id, String person_id, String - fileName, String file_id, String suffix, String file_size) { - Record record = new Record(); - record.set("job_id", job_id); - record.set("target_id", target_id); - record.set("person_id", person_id); - record.set("fileName", fileName); - record.set("file_id", file_id); - record.set("suffix", suffix); - record.set("file_size", file_size); - record.set("input_id", input_id); - record.set("type_id", type_id); - Db.save("t_collect_uploadfile", "id", record); - return record.getInt("id"); - } - - /** - * 功能:删除上传的文件 - * - * @param job_id - * @param file_id - */ - public void delUploadFile(int job_id, String file_id) { - String sql = "delete from t_collect_uploadfile where job_id=? and file_id=?"; - Db.update(sql, job_id, file_id); - } - - /** - * 功能:获取指定任务,指定单位(人员)上传的附件列表 - * - * @param job_id - * @param target_id - */ - public List getJobUploadList(int job_id, String target_id) { - Kv kv = Kv.create(); - kv.set("job_id", job_id); - if (!StrKit.isBlank(target_id)) kv.set("target_id", target_id); - SqlPara sqlPara = Db.getSqlPara("Collect.getJobUploadList", kv); - return Db.find(sqlPara); - } - - - public Record getFormJobFile(String file_id) { - String sql = "select * from t_collect_uploadfile where file_id=?"; - return Db.findFirst(sql, file_id); - } - - - /** - * 功能:根据发布者角色,判断是 市:1 县区:2 单位:3 - * - * @param publish_role_id - * @return - */ - public int getPublishJobTypeId(int publish_role_id) { - int publish_job_type_id = 3; - if (publish_role_id == 255) {//市资产管理干事,未来可以扩展为一张市级XXX管理干事的角色表 - publish_job_type_id = 1; - } else if (publish_role_id == 268) { - publish_job_type_id = 2; - } - return publish_job_type_id; - } - - /** - * 功能:转发任务 - * - * @param publish_role_id 发布者角色 - * @param area_id 当前人员所在的县区ID - * @param job_id 任务ID - * @param status_code 状态代码 - * @param deadline_time 截止时间 - * @param xiaShuSchool 下属学校 - * @param xiaShuJiaoFu 下属教辅单位 - * @param bureauIds 单位列表 - * @param personIds 人员列表 - * @param groupIds 组列表 - * @param memo 要求 - * @param bureau_id 发布者所在单位 - * 下面的参数,为任务发布到人时扩展 - * @param allTeacher 所有教师 - * @param allStudent 所有学生 - * @param njIds 哪些年级,比如1,2表示1、2年级所有学生 - * @param personIds 哪些人员(目前只支持教师) - * @param classIds 哪些班级 - */ - public void ForwardJob(int publish_role_id, String area_id, int job_id, int status_code, String deadline_time, int xiaShuSchool, - int xiaShuJiaoFu, String bureauIds, String groupIds, String memo, String bureau_id, int allTeacher, int allStudent, String njIds, String personIds, String classIds) throws ParseException { - int now_target_type_id = 1; - - //获取此县区的所有学校 - Set targetSet = new HashSet<>(); - if (xiaShuSchool == 1) { - Page list = getBureauList(2, "2", area_id, null, 1, 9999); - for (Record record : list.getList()) { - targetSet.add(record.getStr("org_id")); - } - } - //获取此县区的所有教辅单位 - if (xiaShuJiaoFu == 1) { - Page list = getBureauList(2, "3", area_id, null, 1, 9999); - for (Record record : list.getList()) { - targetSet.add(record.getStr("org_id")); - } - } - if (!StrKit.isBlank(bureauIds)) { - for (String s : bureauIds.split(",")) { - targetSet.add(s); - } - } - //人员 - if (!StrKit.isBlank(personIds)) { - now_target_type_id = 2; - for (String s : personIds.split(",")) { - targetSet.add(s); - } - } - //群组 - if (!StrKit.isBlank(groupIds)) { - - for (String group_id : groupIds.split(",")) { - Record record = getGroup(Integer.parseInt(group_id)); - int group_type_id = record.getInt("group_type_id"); - if (group_type_id == 2) now_target_type_id = 2; - break; - } - for (String group_id : groupIds.split(",")) { - List list = getGroupTargetList(Integer.parseInt(group_id)); - for (Record record : list) { - targetSet.add(record.getStr("target_id")); - } - } - } - //所有老师 - if (allTeacher == 1) { - now_target_type_id = 2; - for (Record r : getAllTeacher(bureau_id)) { - targetSet.add(r.getStr("person_id")); - } - } - //所有学生 - if (allStudent == 1) { - now_target_type_id = 2; - for (Record r : getAllStudent(bureau_id)) { - targetSet.add(r.getStr("person_id")); - } - } - //年级 - for (Record r : getNianJiStudent(bureau_id, njIds)) { - now_target_type_id = 2; - targetSet.add(r.getStr("person_id")); - } - //班级 - for (Record r : getBanJiStudent(bureau_id, classIds)) { - now_target_type_id = 2; - targetSet.add(r.getStr("person_id")); - } - //人员 - if (!StrKit.isBlank(personIds)) { - now_target_type_id = 2; - for (String s : personIds.split(",")) { - targetSet.add(s); - } - } - - //写任务分派表 - List list = new ArrayList<>(); - - // 1:市 2:县区 3:单位 - int publish_job_type_id = getPublishJobTypeId(publish_role_id); - - //下一个转发状态 - int next_status_code = -1; - Map _map; - if (now_target_type_id == 1) { - _map = getBureauMap(targetSet); - } else { - _map = getPersonMap(targetSet); - } - - for (String s : targetSet) { - switch (publish_job_type_id) { - case 1: - //不会有发布角色是1的,因为市不需要转发 - break; - case 2:// 当前转发人是县区 - //有可能是转到本单位的人员,或者,转给下级的单位 - if (status_code == 1120) { //1120 单位,市,需转发下级,未转发 - next_status_code = 1210;//1210 单位,县,填报,未填报 - } - if (status_code == 2120) { //2120 人员,市,需转发下级,未转发 - next_status_code = 2230;//2230 人员,县,需转发本级,未转发 - } - if (status_code == 2130) { //2130 人员,市,需转发本单位,未转发 - next_status_code = 2210;//2210 人员,县,填报,未填报 - } - break; - // 当前转发人是单位 - case 3: - //肯定是转发到人 - next_status_code = 2310; - break; - } - Record record = new Record(); - record.set("target_id", s); - record.set("now_target_type_id", now_target_type_id); - record.set("target_name", _map.get(s)); - record.set("job_id", job_id); - record.set("deadline_time", dateFormat.parse(deadline_time)); - record.set("bureau_id", bureau_id); - record.set("status_code", next_status_code); - record.set("memo", memo); - list.add(record); - } - Db.batchSave("t_collect_job_target", list, 500); - //回写完成标志 - writeJobFinish(job_id, status_code, bureau_id, null); - } - - /** - * 功能:获取指定的单位或群组号中有哪些县区教育局 - * - * @param bureauIds - * @param groupIds - */ - public List getXianQuJiaoYuJu(String bureauIds, String groupIds) { - Set bureauSet = new HashSet<>(); - if (!StrKit.isBlank(bureauIds)) { - for (String s : bureauIds.split(",")) { - bureauSet.add(s); - } - } - if (!StrKit.isBlank(groupIds)) { - for (String group_id : groupIds.split(",")) { - List list = getGroupTargetList(Integer.parseInt(group_id)); - if (list == null) continue; - for (Record record : list) { - bureauSet.add(record.getStr("target_id")); - } - } - } - //检查这些单位ID,是不是有县区教育局 - List idList = new ArrayList<>(); - for (String s : bureauSet) idList.add(s); - - if (idList.size() > 0) { - Kv kv = Kv.by("idList", idList); - SqlPara sqlPara = Db.getSqlPara("Collect.getXianQuJiaoYuJu", kv); - List list = Db.find(sqlPara); - return list; - } - return null; - } - - /** - * 功能:转发任务我都看下级提交过来了,我可以向上级汇报了 - * - * @param job_id 任务ID - */ - public void setForwardFinish(int job_id, int status_code, String bureau_id) { - String sql = "update t_collect_job_target set status_code=?,forward_finish_time=now() where job_id=? and target_id=? and status_code=?"; - Db.update(sql, getNextStausCode(status_code), job_id, bureau_id, status_code); - } - - /****下面的代码用于生成通用的EXCEL导出功能****/ - - /** - * 功能:根据任务号获取它有哪些Sheet表,对应哪些数据库表 - * - * @param job_id - * @return - */ - public List getAllSheetByJobId(int job_id) { - String sql = "select * from t_collect_job_sheet where job_id=? order by sheet_index"; - return Db.find(sql, job_id); - } - - /** - * 功能:根据表名,获取表的结构信息 - * - * @param table_name - * @return - */ - public List getTableStruct(String table_name) { - String sql = "select column_name,excel_column_idx,original_name from t_collect_mapping where table_name=?"; - return Db.find(sql, table_name); - } - - /** - * 功能:获取指定任务+指定表名下的所有填报数据 - * - * @param job_id - * @param table_name - * @return - */ - 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); - } - - - /** - * 功能:获取指定列的列描述信息 - * - * @param table_name - * @return - */ - 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); - } - - /** - * 功能:生成简单的数据汇集EXCEL - * - * @param job_id - * @param filePath - * @throws IOException - */ - public void getSummaryExcelForImportExcel(int job_id, String bureau_id, int publish_role_id, String filePath) throws IOException { //给定任务编号,获取它有哪些表 - //下辖单位有哪些 - String controlBureauIds = getControlBureauIds(publish_role_id, bureau_id); - // 创建工作簿和工作表 - SXSSFWorkbook workbook = new SXSSFWorkbook();//默认100行,超100行将写入临时文件 - workbook.setCompressTempFiles(false); //是否压缩临时文件,否则写入速度更快,但更占磁盘,但程序最后是会将临时文件删掉的 - - //开始生成EXCEL - List allSheet = getAllSheetByJobId(job_id); - for (Record rSheet : allSheet) { - //表名 - String table_name = rSheet.getStr("table_name"); - String sheet_name = rSheet.getStr("sheet_name"); - //读取表的结构信息 - List list = getTableStruct(table_name); - Map _map = new HashMap<>(); - for (Record record : list) { - Record r = new Record(); - //准备第几列用哪一个字段 - String column_name = record.getStr("column_name"); - if (column_name.equals("id")) continue; - if (column_name.equals("bureau_id")) continue; - if (column_name.equals("person_id")) continue; - if (column_name.equals("class_id")) continue; - if (column_name.equals("job_id")) continue; - if (column_name.equals("area_id")) continue; - - r.set("column_name", record.getStr("column_name")); - r.set("original_name", record.getStr("original_name")); - _map.put(record.getInt("excel_column_idx") + 1, r); - } - - //获取数据 - List data = getTableDataByJobId(job_id, table_name, controlBureauIds); - Sheet sheet = workbook.createSheet(sheet_name); - // 创建单元格样式对象 - CellStyle headerStyle = workbook.createCellStyle(); - // 设置水平居中 - headerStyle.setAlignment(HorizontalAlignment.CENTER); - // 设置垂直居中 - headerStyle.setVerticalAlignment(VerticalAlignment.CENTER); - // 设置边框样式 - headerStyle.setBorderTop(BorderStyle.THIN); - headerStyle.setBorderBottom(BorderStyle.THIN); - headerStyle.setBorderLeft(BorderStyle.THIN); - headerStyle.setBorderRight(BorderStyle.THIN); - - // 创建字体对象并设置字体颜色为白色 - Font font = workbook.createFont(); - font.setFontHeightInPoints((short) 14); - font.setBold(true); - font.setFontName("黑体"); - font.setColor(IndexedColors.BLACK.getIndex()); - // 设置背景色为浅蓝色 #d2f4f2 - //颜色 - String str = "#d2f4f2"; - String sr = str.substring(1, 3); - String sg = str.substring(3, 5); - String sb = str.substring(5, 7); - //16进制的字符串转为int - int r = Integer.parseInt(sr, 16); - int g = Integer.parseInt(sg, 16); - int b = Integer.parseInt(sb, 16); - XSSFColor rbg = new XSSFColor(new java.awt.Color(r, g, b), new DefaultIndexedColorMap()); - headerStyle.setFillForegroundColor(rbg); - headerStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND); - // 将字体应用于样式 - headerStyle.setFont(font); - - // 在第一行创建单元格并设置样式 - Row headerRow = sheet.createRow(0); - Cell headerCell = headerRow.createCell(0); - headerCell.setCellValue("单位"); - headerCell.setCellStyle(headerStyle); - for (int i = 0; i < list.size(); i++) { - headerCell = headerRow.createCell(i + 1); - headerCell.setCellValue(_map.get(i + 1).getStr("original_name")); - headerCell.setCellStyle(headerStyle); - } - - // 创建字体对象并设置字体大小为12 - font = workbook.createFont(); - font.setFontHeightInPoints((short) 12); - - // 创建单元格样式对象并将字体应用于样式 - CellStyle style = workbook.createCellStyle(); - style.setFont(font); - // 设置行高度为28 - sheet.setDefaultRowHeightInPoints(28); - // 设置每个单元格的宽度为30 - sheet.setDefaultColumnWidth(30); - // 设置边框样式 - style.setBorderTop(BorderStyle.THIN); - style.setBorderBottom(BorderStyle.THIN); - style.setBorderLeft(BorderStyle.THIN); - style.setBorderRight(BorderStyle.THIN); - // 设置水平居中 - style.setAlignment(HorizontalAlignment.CENTER); - // 设置垂直居中 - style.setVerticalAlignment(VerticalAlignment.CENTER); - - // 填充数据集的其余行 - for (int i = 1; i <= data.size(); i++) { - Row row = sheet.createRow(i); - Record record = data.get(i - 1); - Cell cell = row.createCell(0); - cell.setCellValue(record.getStr("bureau_name")); - cell.setCellStyle(style); - for (int j = 0; j < list.size(); j++) { - cell = row.createCell(j + 1); - cell.setCellValue(record.getStr(_map.get(j + 1).getStr("column_name"))); - cell.setCellStyle(style); - } - } - } - - // 保存Excel文件 - FileOutputStream outputStream = new FileOutputStream(filePath); - 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 - * - * @param job_id - * @param filePath - * @throws IOException - */ - public void getSummaryExcelForFormFill(int job_id, String bureau_id, int publish_role_id, String filePath) throws IOException { - Record jobRecord = getJob(job_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); - int idx = 0; - for (Record r : listStruct) { - String column_name = r.getStr("column_name"); - //准备第几列用哪一个字段 - if (column_name.equals("id")) continue; - if (column_name.equals("bureau_id")) continue; - if (column_name.equals("person_id")) continue; - if (column_name.equals("class_id")) continue; - if (column_name.equals("job_id")) continue; - if (column_name.equals("area_id")) continue; - _map.put(idx++, r); - } - //获取数据 - List data = getTableDataByJobId(job_id, table_name, controlBureauIds); - //创建Excel - SXSSFWorkbook workbook = new SXSSFWorkbook();//默认100行,超100行将写入临时文件 - workbook.setCompressTempFiles(false); //是否压缩临时文件,否则写入速度更快,但更占磁盘,但程序最后是会将临时文件删掉的 - //开始生成EXCEL - String sheet_name = "填报情况"; - //获取数据 - Sheet sheet = workbook.createSheet(sheet_name); - // 创建单元格样式对象 - CellStyle headerStyle = workbook.createCellStyle(); - // 设置水平居中 - headerStyle.setAlignment(HorizontalAlignment.CENTER); - // 设置垂直居中 - headerStyle.setVerticalAlignment(VerticalAlignment.CENTER); - // 设置边框样式 - headerStyle.setBorderTop(BorderStyle.THIN); - headerStyle.setBorderBottom(BorderStyle.THIN); - headerStyle.setBorderLeft(BorderStyle.THIN); - headerStyle.setBorderRight(BorderStyle.THIN); - - // 创建字体对象并设置字体颜色为白色 - Font font = workbook.createFont(); - font.setFontHeightInPoints((short) 14); - font.setBold(true); - font.setFontName("黑体"); - font.setColor(IndexedColors.BLACK.getIndex()); - // 设置背景色为浅蓝色 #d2f4f2 - //颜色 - String str = "#d2f4f2"; - String sr = str.substring(1, 3); - String sg = str.substring(3, 5); - String sb = str.substring(5, 7); - //16进制的字符串转为int - int r = Integer.parseInt(sr, 16); - int g = Integer.parseInt(sg, 16); - int b = Integer.parseInt(sb, 16); - XSSFColor rbg = new XSSFColor(new java.awt.Color(r, g, b), new DefaultIndexedColorMap()); - headerStyle.setFillForegroundColor(rbg); - headerStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND); - // 将字体应用于样式 - headerStyle.setFont(font); - - // 在第一行创建单元格并设置样式 - Row headerRow = sheet.createRow(0); - Cell headerCell = headerRow.createCell(0); - headerCell.setCellStyle(headerStyle); - for (int i = 0; i < _map.size(); i++) { - headerCell = headerRow.createCell(i); - headerCell.setCellValue(_map.get(i).getStr("column_description")); - headerCell.setCellStyle(headerStyle); - } - - // 创建字体对象并设置字体大小为12 - font = workbook.createFont(); - font.setFontHeightInPoints((short) 12); - - // 创建单元格样式对象并将字体应用于样式 - CellStyle style = workbook.createCellStyle(); - style.setFont(font); - // 设置行高度为28 - sheet.setDefaultRowHeightInPoints(28); - // 设置每个单元格的宽度为30 - sheet.setDefaultColumnWidth(30); - // 设置边框样式 - style.setBorderTop(BorderStyle.THIN); - style.setBorderBottom(BorderStyle.THIN); - style.setBorderLeft(BorderStyle.THIN); - style.setBorderRight(BorderStyle.THIN); - // 设置水平居中 - style.setAlignment(HorizontalAlignment.CENTER); - // 设置垂直居中 - style.setVerticalAlignment(VerticalAlignment.CENTER); - - // 填充数据集的其余行 - for (int i = 1; i <= data.size(); i++) { - Row row = sheet.createRow(i); - Record r2 = data.get(i - 1); - for (int j = 0; j < _map.size(); j++) { - Cell cell = row.createCell(j); - cell.setCellValue(r2.getStr(_map.get(j).getStr("column_name"))); - cell.setCellStyle(style); - } - } - // 保存Excel文件 - FileOutputStream outputStream = new FileOutputStream(filePath); - workbook.write(outputStream); - } - - /** - * 功能:查看我该填报或者我已填报的任务列表(人员) - * - * @param person_id 人员ID - * @param keyword 关键字 - * @param is_finish 是不是已完成填报 - * @param page 第几页 - * @param limit 每页多少个 - */ - public Page viewJobListPerson(String person_id, String keyword, int is_finish, int page, int limit) { - Kv kv = Kv.create(); - kv.set("target_id", person_id); - if (!StrKit.isBlank(keyword)) kv.set("keyword", keyword); - if (is_finish == 1) kv.set("is_finish1", 1); - if (is_finish == 0) kv.set("is_finish0", 1); - - SqlPara sqlPara = Db.getSqlPara("Collect.viewJobListPerson", kv); - Page pageRecord = Db.paginate(page, limit, sqlPara); - - for (Record record : pageRecord.getList()) { - record.set("publish_time", record.getStr("publish_time").split(" ")[0]); - record.set("create_time", record.getStr("create_time").split(" ")[0]); - record.set("deadline_time", record.getStr("deadline_time").split(" ")[0]); - if (record.getInt("job_type") == 1) record.set("job_type_name", "表单"); - else if (record.getInt("job_type") == 2) record.set("job_type_name", "EXCEL模板"); - - Date deadline_time = record.getDate("deadline_time"); - Calendar calendar = Calendar.getInstance(); - calendar.setTime(deadline_time); - calendar.add(Calendar.DAY_OF_MONTH, 1); - // 获取当前时间的毫秒数 - long currentTime = System.currentTimeMillis(); - record.set("jiezhi", calendar.getTime().getTime() < currentTime); - } - return pageRecord; - } - - - /** - * 功能:将可能带有栅格的JSON字符串简化为多个JsonObject - * - * @param content - * @return - */ - public JSONArray parseGridJson(String content) { - JSONArray ja = JSONArray.parseArray(content); - - List res = new ArrayList<>(); - for (int i = 0; i < ja.size(); i++) { - JSONObject jo = ja.getJSONObject(i); - if (jo.containsKey("columns")) { - JSONArray jaColumns = jo.getJSONArray("columns"); - for (int j = 0; j < jaColumns.size(); j++) { - JSONArray jaList = jaColumns.getJSONObject(j).getJSONArray("list"); - for (int k = 0; k < jaList.size(); k++) { - res.add(jaList.getJSONObject(k)); - } - } - } else { - res.add(jo); - } - } - ja.clear(); - for (JSONObject re : res) { - ja.add(re); - } - return ja; - } - - /** - * 获取当前登录人员所有单位的所有部门列表,不带分页 - * - * @param bureau_id - * @return - */ - public List getOrgList(String bureau_id, String keyword) { - Kv kv = Kv.by("bureau_id", bureau_id); - if (!StrKit.isBlank(keyword)) kv.set("keyword", keyword); - SqlPara sqlPara = Db.getSqlPara("Collect.getOrgList", kv); - List list = Db.find(sqlPara); - for (Record record : list) { - if (record.getStr("org_id").equals(bureau_id)) record.set("parent_id", "0"); - } - return list; - } - - /** - * 获取指定部门下的人员信息列表,带分页 - * - * @param org_id - * @param keyword - * @param page - * @param limit - * @return - */ - public Page getOrgPersonList(String org_id, String keyword, int page, int limit) { - Kv kv = Kv.by("org_id", org_id); - if (!StrKit.isBlank(keyword)) kv.set("keyword", keyword); - SqlPara sqlPara = Db.getSqlPara("Collect.getOrgPersonList", kv); - Page pageRecord = Db.paginate(page, limit, sqlPara); - return pageRecord; - } - - public Page getTyOrgPersonList(String org_id, String keyword, int page, int limit) { - Kv kv = Kv.by("org_id", org_id); - if (!StrKit.isBlank(keyword)) kv.set("keyword", keyword); - SqlPara sqlPara = Db.getSqlPara("Collect.getTyOrgPersonList", kv); - Page pageRecord = Db.paginate(page, limit, sqlPara); - return pageRecord; - } - - /** - * 获取当前登录人员所在单位下的+所在年级下所有班级 - * - * @param bureau_id - * @param nj_id - * @param keyword - * @param page - * @param limit - * @return - */ - public Page getClassList(String bureau_id, int nj_id, String keyword, int page, int limit) { - Kv kv = Kv.by("bureau_id", bureau_id); - int currentXn = getCurrentXn(); - int stage_id, entry_year; - if (nj_id <= 6) {//小学 - stage_id = 4; - entry_year = currentXn - nj_id + 1; - } else if (nj_id <= 9) {//初中 - stage_id = 5; - entry_year = currentXn - nj_id + 1 + 6; - } else {//高中 - stage_id = 6; - entry_year = currentXn - nj_id + 1 + 9; - } - kv.set("stage_id", stage_id); - kv.set("entry_year", entry_year); - if (!StrKit.isBlank(keyword)) kv.set("keyword", keyword); - SqlPara sqlPara = Db.getSqlPara("Collect.getClassList", kv); - Page pageRecord = Db.paginate(page, limit, sqlPara); - return pageRecord; - } - - public Page getTyClassList(String bureau_id, int nj_id, String keyword, int page, int limit) { - Kv kv = Kv.by("bureau_id", bureau_id); - String prev = ""; - if (nj_id == 1) { - prev = "一年级"; - } else if (nj_id == 2) { - prev = "二年级"; - } else if (nj_id == 3) { - prev = "三年级"; - } else if (nj_id == 4) { - prev = "四年级"; - } else if (nj_id == 5) { - prev = "五年级"; - } else if (nj_id == 6) { - prev = "六年级"; - } else if (nj_id == 7) { - prev = "七年级"; - } else if (nj_id == 8) { - prev = "八年级"; - } else if (nj_id == 9) { - prev = "九年级"; - } else if (nj_id == 10) { - prev = "高中一年级"; - } else if (nj_id == 11) { - prev = "高中二年级"; - } else if (nj_id == 12) { - prev = "高中三年级"; - } - kv.set("prev", prev); - if (!StrKit.isBlank(keyword)) kv.set("keyword", keyword); - SqlPara sqlPara = Db.getSqlPara("Collect.getTyClassList", kv); - Page pageRecord = Db.paginate(page, limit, sqlPara); - return pageRecord; - } - - /** - * 功能:获取当前登录人员是否具有发布到下级的权限 - */ - public boolean canPublishNextLevel(String person_id) { - String sql = "select duties_id from t_person_duty where person_id=? and duties_id in (select distinct publish_role_id from t_collect_role_map where receive_role_id>0)"; - return Db.find(sql, person_id).size() > 0; - } - - - /** - * 功能:获取我系统中所有已匹配单位 或 未匹配单位 - * - * @return - */ - public Page getAllBureau(int is_match, int page, int limit) { - //返回查询列表 - GlobalModel gm = new GlobalModel(); - String city_id = gm.getGlobalValueByKey("install_area"); - - Kv kv = Kv.by("city_id", city_id); - kv.set("is_match", is_match); - SqlPara sqlPara = Db.getSqlPara("Collect.getAllBureau", kv); - Page pageRecord = Db.paginate(page, limit, sqlPara); - return pageRecord; - } - - - /** - * 功能:匹配第三方系统与我们的系统单位ID一致 - * - * @throws InterruptedException - */ - public void matchBureau(String org_id, String third_party_id) { - Record record = Db.findById("t_base_organization", "org_id", org_id); - record.set("third_party_id", third_party_id); - Db.update("t_base_organization", "org_id", record); - } - - /** - * 功 功能:解除第三方系统与我们的系统单位ID的匹配 - * - * @throws InterruptedException - */ - public void disMatchBureau(String org_id) { - Record record = Db.findById("t_base_organization", "org_id", org_id); - record.set("third_party_id", null); - Db.update("t_base_organization", "org_id", record); - } - - public static String KEY = "TY_BUREAU"; - - /** - * 功能:利用中文分词技术,将两个字符串都进行分词,通过对比完全命中的数量来评估是不是两个单位名称是同一个单位 - * - * @param s1 - * @param s2 - * @return - */ - public static boolean check(String s1, String s2) { - //静态变量 - String[] area = { - "南关区", "宽城区", "朝阳区", "二道区", "绿园区", "双阳区", "九台市", - "农安县", "经开区", "德惠市", "高新区", "净月区", "汽开区", "榆树市", "公主岭市", "长春市" - }; - List areaList = Arrays.stream(area).toList(); - - List termList1 = StandardTokenizer.segment(s1); - Map map = new HashMap<>(); - for (Term term : termList1) { - String key = SimilarUtil.Convert(term.word); - - for (int i = 0; i < areaList.size(); i++) { - if (areaList.get(i).startsWith(key)) { - key = areaList.get(i); - break; - } - } - int x = 0; - if (map.containsKey(key)) x = map.get(key); - map.put(key, x + 1); - } - - List termList2 = StandardTokenizer.segment(s2); - for (Term term : termList2) { - String key = SimilarUtil.Convert(term.word); - for (int i = 0; i < areaList.size(); i++) { - if (areaList.get(i).startsWith(key)) { - key = areaList.get(i); - break; - } - } - int x = 0; - if (map.containsKey(key)) x = map.get(key); - map.put(key, x + 1); - } - // 使用 for-each 循环遍历 Map - for (Map.Entry entry : map.entrySet()) { - if (entry.getValue() == 1) return false; - } - return true; - } - - /** - * 功能:绑定两个组织机构码之间的关联关系 - * - * @param org_id - * @param ty_org_id - */ - public void bind(String org_id, String ty_org_id) { - //与我系统中单位名称完全一致,则自动完成关联 - String sql = "update t_base_organization set third_party_id=? where org_id=?"; - Db.update(sql, ty_org_id, org_id); - } - - /** - * 功能:一键匹配 - */ - public int OneKeyMatch() { - int cnt = 0; - //从天喻获取所有单位名单 - String sql = "select t1.org_id,t1.org_name from ds_base_bureau as t1 where t1.org_id not in (select t2.org_id from t_base_organization as t2 where t2.org_id=t2.bureau_id and t2.third_party_id is not null) order by t1.org_name"; - List list = Db.find(sql); - - List tyList = new ArrayList<>(); - for (Record record : list) { - String org_id = record.getStr("org_id"); - String org_name = record.getStr("org_name"); - JSONObject jo2 = new JSONObject(); - jo2.put("org_id", org_id); - jo2.put("org_name", org_name); - tyList.add(jo2); - } - - String[] array = new String[tyList.size()]; - for (int i = 0; i < tyList.size(); i++) { - array[i] = tyList.get(i).getString("org_name"); - } - - //我们系统中的单位名称 - sql = "select org_id,org_name from t_base_organization where bureau_id=org_id and is_virtual=0 and third_party_id is null"; - List ourList = Db.find(sql); - - for (Record record : ourList) { - String org_name = record.getStr("org_name"); - String org_id = record.getStr("org_id"); - JSONObject jo = SimilarUtil.Get(org_name, array); - int idx = jo.getInteger("idx"); - String ty_org_name = array[idx]; - double similary = jo.getDouble("similary"); - String ty_org_id = tyList.get(idx).getString("org_id"); - if (Math.abs(similary - 1.0) < 0.0001) { - //与我系统中单位名称完全一致,则自动完成关联 - bind(org_id, ty_org_id); - cnt++; - } else { - //没有完全一致的,就让系统推荐一个 - //再用其它的算法检查一下这个推荐的是不是合适 - boolean success = check(org_name, ty_org_name); - if (success) { - bind(org_id, ty_org_id); - cnt++; - } - } - } - return cnt; - } - - /** - * 功能:获取天喻系统中还未与我系统匹配完成的单位名称 - * - * @param keyword - */ - public Page getTyBureauList(String keyword, int page, int limit) { - Kv kv = Kv.create(); - if (!StrKit.isBlank(keyword)) kv.set("keyword", keyword); - SqlPara sqlPara = Db.getSqlPara("Collect.getTyBureauList", kv); - Page pageRecord = Db.paginate(page, limit, sqlPara); - return pageRecord; - } - - /** - * 功能:获取天喻指定单位的组织机构 - * - * @param bureau_id - * @return - */ - public List getTyOrgList(String bureau_id) { - String sql = "select org_id,org_name,parent_id from ds_base_org where bureau_id=?"; - List list = Db.find(sql, bureau_id); - return list; - } - - /** - * 功能:获取人员在天喻系统中的单位信息 - * - * @param person_id - * @return - */ - public String getTyPersonBureau(String person_id) { - String sql = "select bureau_id from ds_base_teacher where user_id=? limit 1"; - Record record = Db.findFirst(sql, person_id); - if (record != null) { - return record.getStr("bureau_id"); - } else { - sql = "select bureau_id from ds_base_student where user_id=? limit 1"; - record = Db.findFirst(sql, person_id); - return record.getStr("bureau_id"); - } - } - - /** - * 功能:将天喻的单位ID转换为我们系统中的单位ID - * - * @param bureau_id - * @return - */ - public Record getMyBureauByTyBureauId(String bureau_id) { - String sql = "select * from t_base_organization where third_party_id=?"; - return Db.findFirst(sql, bureau_id); - } - - /** - * 功能:根据传入的学校ID,获取它有哪些学段 - * - * @param org_id - * @return 时间:2024-04-07 - */ - public List getSchoolStage(String org_id) { - String sql = "select t1.school_type_id from t_base_organization as t1 where t1.org_id=?"; - int school_type_id = Db.queryInt(sql, org_id); - List stage_ids = new ArrayList<>(); - //如果不是学校,那么默认是全部保留 - if (school_type_id == -1) { - stage_ids.add(4); - stage_ids.add(5); - stage_ids.add(6); - return stage_ids; - } - sql = "select t1.stage_id,t2.stage_name,t1.school_type_id,t3.school_type_name from t_dm_schooltype_stage as t1 inner join t_dm_stage as t2 on t1.stage_id=t2.stage_id inner join t_dm_schooltype as t3 on t1.school_type_id=t3.school_type_id where t1.stage_id>=4 and t1.stage_id<=6 and t1.school_type_id=? order by t1.stage_id"; - List list = Db.find(sql, school_type_id); - - for (Record record : list) { - stage_ids.add(record.getInt("stage_id")); - } - return stage_ids; - } - - /** - * 功能:更新Excel中Sheet表与学段的对应关系 - */ - public void updateSheetStage(int job_id, int sheet_index, int stage_id, int b_use) { - String sql = "delete from t_collect_sheet_stage where job_id=? and sheet_index=? and stage_id=?"; - Db.update(sql, job_id, sheet_index, stage_id); - sql = "insert into t_collect_sheet_stage(job_id,sheet_index,stage_id,b_use) values(?,?,?,?)"; - Db.update(sql, job_id, sheet_index, stage_id, b_use); - } - - /** - * 功能:获取指定任务的模板与学段的对应关系 - * - * @param job_id - */ - public List getSheetStage(int job_id) { - String sql = "select t1.sheet_index,t2.sheet_name,t1.stage_id,t1.b_use from t_collect_sheet_stage as t1 inner join t_collect_job_sheet as t2 on t1.job_id=t2.job_id and t1.sheet_index=t2.sheet_index where t1.job_id=? order by t1.sheet_index,t1.stage_id"; - List list = Db.find(sql, job_id); - - List res = new ArrayList<>(); - Map _map = new HashMap(); - for (Record record : list) { - int sheet_index = record.getInt("sheet_index"); - int stage_id = record.getInt("stage_id"); - int b_use = record.getInt("b_use"); - _map.put(sheet_index + "_" + stage_id, b_use); - } - - sql = "select distinct sheet_index,sheet_name from t_collect_job_sheet where job_id=? order by sheet_index"; - List tList = Db.find(sql, job_id); - for (Record record : tList) { - int sheet_index = record.getInt("sheet_index"); - String sheet_name = record.getStr("sheet_name"); - - Record r = new Record(); - r.set("sheet_index", sheet_index); - r.set("sheet_name", sheet_name); - r.set("xiaoxue", _map.get(sheet_index + "_" + 4)); - r.set("chuzhong", _map.get(sheet_index + "_" + 5)); - r.set("gaozhong", _map.get(sheet_index + "_" + 6)); - res.add(r); - } - return res; - } - - /** - * 功能:一键智能处理哪些Sheet对应哪些学段 - * - * @param job_id - */ - public void intelligenceSheetStage(int job_id) { - //1、整体上都修改为0,表示一个都不要 - String sql = "update t_collect_sheet_stage set b_use=0 where job_id=?"; - Db.update(sql, job_id); - - //2、遍历这个任务的所有Sheet表 - sql = "select sheet_index,sheet_name from t_collect_job_sheet where job_id=?"; - List list = Db.find(sql, job_id); - - //3、如果Sheet表的表名中存在小学,初中,高中字样,那么认为这个Sheet表对应小学,初中,高中 - for (Record record : list) { - int sheet_index = record.getInt("sheet_index"); - String sheetName = record.getStr("sheet_name"); - - sql = "update t_collect_sheet_stage set b_use=1 where job_id=? and sheet_index=? and stage_id="; - boolean flag = false; - if (sheetName.indexOf("小学") >= 0) { - flag = true; - sql += "4"; - } else if (sheetName.indexOf("初中") >= 0) { - flag = true; - sql += "5"; - } else if (sheetName.indexOf("高中") >= 0) { - flag = true; - sql += "6"; - }else{ - sql = "update t_collect_sheet_stage set b_use=1 where job_id=? and sheet_index=?"; - Db.update(sql, job_id,sheet_index); - } - if (flag) Db.update(sql, job_id, sheet_index); - } - } - - /** - * 功能:一键全选 - * - * @param job_id - */ - public void oneKeySheetStage(int job_id) { - String sql = "update t_collect_sheet_stage set b_use=1 where job_id=?"; - Db.update(sql, job_id); - } - - /** - * 功能:获取需要隐藏的Sheet表有哪些 - * - * @param job_id - * @param schoolStageList - * @return - */ - public List getHiddenSheetList(int job_id, List schoolStageList) { - //1、此任务有多少个Sheet - String sql = "select sheet_index from t_collect_job_sheet where job_id=?"; - List sheetIndexListAll = Db.find(sql, job_id); - - //2、哪些Sheet是需要保留下来的 - String stageIds = ""; - for (Integer i : schoolStageList) { - stageIds += i + ","; - } - if (stageIds.length() > 0) stageIds = stageIds.substring(0, stageIds.length() - 1); - List sheetIndexListRemain = new ArrayList<>(); - sql = "select sheet_index from t_collect_sheet_stage where job_id=? and stage_id in (" + stageIds + ") and b_use=1 order by sheet_index";//要保留哪些 - List list = Db.find(sql, job_id); - for (Record record : list) { - sheetIndexListRemain.add(record.getInt("sheet_index")); - } - //3、要隐藏掉不需要保留下来的数据 - List hidenSheetIndexList = new ArrayList<>(); - for (Record record : sheetIndexListAll) { - int sheet_index = record.getInt("sheet_index"); - if (!sheetIndexListRemain.contains(sheet_index)) { - //隐藏掉 - hidenSheetIndexList.add(sheet_index); - } - } - return hidenSheetIndexList; - } - - /** - * 功能:通过用户设置过的此模板中,学段与Sheet表的对应关系,删除一些不在上面学段内需要填报的表格,提供新的上报模板文件给用户 - * - * @param job_id - * @param excelPath - * @param schoolStageList - * @return - */ - public File getFillExcelTemplate(int job_id, String excelPath, List schoolStageList) { - //哪些Sheet需要隐藏 - List hiddenSheetList = getHiddenSheetList(job_id, schoolStageList); - - // 生成随机UUID - UUID uuid = UUID.randomUUID(); - // 将UUID转换为字符串 - String uuidString = uuid.toString(); - // 创建临时文件路径 - File tempFile = new File(System.getProperty("java.io.tmpdir") + File.separator + uuidString + ".xlsx"); - - try (FileInputStream fis = new FileInputStream(excelPath); - FileOutputStream fos = new FileOutputStream(tempFile)) { - // 打开Excel文件 - XSSFWorkbook workbook = new XSSFWorkbook(fis); - // 获取要隐藏的工作表 - // 将第x号Sheet设置为隐藏 - for (Integer x : hiddenSheetList) { - workbook.setSheetHidden(x, true); - } - - // 设置单元格保护策略 - CellStyle lockedStyle = workbook.createCellStyle(); - lockedStyle.setLocked(true); // 设置单元格为锁定(即只读) - - CellStyle unlockedStyle = workbook.createCellStyle(); - unlockedStyle.setLocked(false); // 设置单元格为解锁(即可编辑) - - //哪个Sheet表+哪一列是需要只读的? - String sql = "select sheet_index,column_index from t_collect_job_sheet_col where job_id=? and readonly=1"; - List listSheetColumn = Db.find(sql, job_id); - for (Record record : listSheetColumn) { - int sheet_index = record.getInt("sheet_index"); - int column_index = record.getInt("column_index"); - XSSFSheet sheet = workbook.getSheetAt(sheet_index); - // 假设我们要将某一列设置为只读 - for (Row row : sheet) { - for (Cell cell : row) { - if (cell.getColumnIndex() == column_index) { - cell.setCellStyle(lockedStyle); - } else { - cell.setCellStyle(unlockedStyle); - } - } - } - // 启用工作表保护 - sheet.protectSheet("dsideal"); // 设置工作表保护密码 - } - // 将修改后的工作簿写回文件 - workbook.write(fos); - } catch (IOException e) { - e.printStackTrace(); - } - return tempFile; - } -} \ No newline at end of file diff --git a/dsPgBase/src/main/java/com/dsideal/dsBase/DataShare/Controller/DataShareController.java b/dsPgBase/src/main/java/com/dsideal/dsBase/DataShare/Controller/DataShareController.java deleted file mode 100644 index 290b4c6d..00000000 --- a/dsPgBase/src/main/java/com/dsideal/dsBase/DataShare/Controller/DataShareController.java +++ /dev/null @@ -1,308 +0,0 @@ -package com.dsideal.dsBase.DataShare.Controller; - -import cn.hutool.core.io.FileUtil; -import com.dsideal.dsBase.Const.IdentityConst; -import com.dsideal.dsBase.DataShare.Model.DataShareModel; -import com.dsideal.dsBase.Interceptor.*; -import com.dsideal.dsBase.Util.CommonUtil; -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.kit.Kv; -import com.jfinal.kit.PathKit; -import com.jfinal.kit.PropKit; -import com.jfinal.kit.StrKit; -import com.jfinal.plugin.activerecord.Page; -import com.jfinal.plugin.activerecord.Record; -import com.jfinal.upload.UploadFile; -import io.github.yedaxia.apidocs.ApiDoc; - -import java.io.*; -import java.util.List; -import java.util.UUID; - -@ApiDoc -public class DataShareController extends Controller { - DataShareModel dm = new DataShareModel(); - - /** - * 获取接入系统列表 - * - * @param keyword 关键字 - * @param exclude 排除系统ID,不显示在列表中,0表示不排除,其他表示排除 - * @param page 页码 - * @param limit 每页数量 - */ - @Before({GET.class}) - @IsLoginInterface({}) - @IsSysAdminInterface({"1"}) - @IsNumericInterface({"page", "limit"}) - public void listSystem(String keyword, int exclude, int page, int limit) { - Page dt = dm.listSystem(keyword, exclude, page, limit); - renderJson(CommonUtil.renderJsonForLayUI(dt)); - } - - /** - * 增加一个数据共享系统 - * - * @param system_name 系统名称 - * @param user_name 访问账号 - * @param redirect_url 回调地址 - */ - @Before({POST.class}) - @IsLoginInterface({}) - @IsSysAdminInterface({"1"}) - @EmptyInterface({"system_name", "user_name"}) - public void addSystem(String system_name, String user_name, String redirect_url) { - if (dm.isExistUserName(user_name)) { - Kv kv = Kv.by("success", false); - kv.set("message", "访问账号已存在,请更换!"); - renderJson(kv); - return; - } - if (dm.isExistRedirectUrl(redirect_url)) { - Kv kv = Kv.by("success", false); - kv.set("message", "指定的回调地址已存在,请检查后重新提交!"); - renderJson(kv); - return; - } - dm.addSystem(system_name, user_name, redirect_url); - Kv kv = Kv.by("success", true); - kv.set("message", "保存成功!"); - renderJson(kv); - } - - /** - * 功能:上传系统的EXCEL文档 - */ - @Before({POST.class}) - @IsLoginInterface({}) - @IsSysAdminInterface({"1"}) - public void saveUploadFile() { - UploadFile uf = getFile();//得到文件对象 - int system_id = getInt("system_id"); - String fileName = uf.getFileName(); - String suffix = fileName.substring(fileName.lastIndexOf(".") + 1).trim(); - if (!suffix.equals("xlsx")) { - renderJson(CommonUtil.returnMessageJson(false, "上传文件类型错误!系统只允许上传Excel文档!")); - return; - } - //判断文件大小大于20mb则返回错误信息,并终止上传,删除上传文件 - long size = uf.getFile().length(); - if (size > 1024 * 1024 * 20) { - Kv kv = Kv.by("success", false).set("message", "文件大小大于20MB,请检查是否正确!!"); - renderJson(kv); - return; - } - String basePath = PathKit.getWebRootPath() + "/upload/"; - if (!FileUtil.exist(basePath)) FileUtil.mkdir(basePath); - String file_id = UUID.randomUUID().toString().toUpperCase(); - String filePath = basePath + file_id + "." + suffix; - uf.getFile().renameTo(new File(filePath)); - String url = PropKit.get("filePrefix") + "/upload/" + file_id + "." + suffix; - //记录到数据库 - dm.saveUploadFile(system_id, url); - //返回结果 - Kv kv = Kv.by("success", true); - kv.set("message", "上传成功!"); - kv.set("url", url); - renderJson(kv); - } - - /** - * 功能:下载EXCEL文档说明 - * - * @param system_id 系统id - */ - @Before({GET.class}) - @IsLoginInterface({}) - @IsNumericInterface({"system_id"}) - @IsSysAdminInterface({"1"}) - public void downloadXlsx(int system_id) { - Record record = dm.getSystemById(system_id); - boolean Error = false; - String url = ""; - if (record == null) { - Error = true; - } else { - url = record.getStr("url"); - if (StrKit.isBlank(url)) { - Error = true; - } - } - - if (Error) { - Kv kv = Kv.by("success", false); - kv.set("message", "此系统还没有上传说明文档,无法下载!"); - renderJson(kv); - return; - } - String system_name = record.getStr("system_name"); - String[] array = url.split("/"); - String file_name = array[array.length - 1]; - String basePath = PathKit.getWebRootPath() + "/upload/"; - renderFile(new File(basePath + file_name), "【" + system_name + "】文档说明.xlsx"); - } - - /** - * 功能:根据系统ID获取系统信息 - * - * @param system_id - */ - @Before({GET.class}) - @IsLoginInterface({}) - @IsSysAdminInterface({"1"}) - @IsNumericInterface({"system_id"}) - public void getSystemById(int system_id) { - Record record = dm.getSystemById(system_id); - renderJson(record); - } - - /** - * 功能:删除系统 - * - * @param system_id - */ - @Before({POST.class}) - @IsLoginInterface({}) - @IsSysAdminInterface({"1"}) - @IsNumericInterface({"system_id"}) - public void delSystem(int system_id) { - dm.delSystem(system_id); - Kv kv = Kv.by("success", true); - kv.set("message", "保存成功!"); - renderJson(kv); - } - - /** - * 功能:修改系统名称 - * - * @param system_id - * @param system_name - * @param redirect_url - */ - @Before({POST.class}) - @IsLoginInterface({}) - @IsSysAdminInterface({"1"}) - @IsNumericInterface({"system_id"}) - @EmptyInterface({"system_name"}) - public void updateSystem(int system_id, String system_name, String redirect_url) { - dm.updateSystem(system_id, system_name, redirect_url); - Kv kv = Kv.by("success", true); - kv.set("message", "保存成功!"); - renderJson(kv); - } - - /** - * 功能:指定的系统,它订阅哪些业务系统的数据表 - * - * @param system_id - * @param subscribe_system_ids - */ - @Before({POST.class}) - @IsLoginInterface({}) - @IsSysAdminInterface({"1"}) - @IsNumericInterface({"system_id"}) - public void subscribe(int system_id, String subscribe_system_ids) { - dm.subscribe(system_id, subscribe_system_ids); - Kv kv = Kv.by("success", true); - kv.set("message", "保存成功!"); - renderJson(kv); - } - - /** - * 功能:修改系统的密码 - * - * @param system_id - */ - @Before({POST.class}) - @IsLoginInterface({}) - @IsSysAdminInterface({"1"}) - @IsNumericInterface({"system_id"}) - public void changePwd(int system_id) { - dm.changePwd(system_id, CommonUtil.generatePassword(10)); - Kv kv = Kv.by("success", true); - kv.set("message", "修改成功!"); - renderJson(kv); - } - - /** - * 功能:记录指定系统它有哪些数据表 - * - * @param system_id - * @param table_names - */ - @Before({POST.class}) - @IsLoginInterface({}) - @IsSysAdminInterface({"1"}) - @IsNumericInterface({"system_id"}) - public void share(int system_id, String table_names) { - if (!StrKit.isBlank(table_names) && !dm.isExistTable(table_names)) { - Kv kv = Kv.by("success", false); - kv.set("message", "检查到数据表在数据库中不存在的情况,请检查后重新录入!"); - renderJson(kv); - return; - } - //检查一下共享的表是不是已经被其它系统共享过? - if (!StrKit.isBlank(table_names) && !dm.checkShareTable(system_id, table_names)) { - Kv kv = Kv.by("success", false); - kv.set("message", "检查到要共享的数据表已经被其它业务系统共享,请检查后重新录入!"); - renderJson(kv); - return; - } - - dm.share(system_id, table_names); - Kv kv = Kv.by("success", true); - kv.set("message", "保存成功!"); - renderJson(kv); - } - - /** - * 功能:获取指定系统它有哪些数据表 - * - * @param system_id - */ - @Before({GET.class}) - @IsLoginInterface({}) - @IsSysAdminInterface({"1"}) - @IsNumericInterface({"system_id"}) - public void getShareTable(int system_id) { - List list = dm.getShareTable(system_id); - renderJson(list); - } - - - /** - * 第三方接入系统获取执行票据Token - * - * @param user_name 分配给第三方的用户名 - * @param pwd 分配给第三方的密码 - */ - @Before({POST.class}) - public void getToken(String user_name, String pwd) { - //获取 token - String token = dm.getToken(user_name, pwd); - if (token != null) { - Kv kv = Kv.by("token", token); - kv.set("success", true); - kv.set("message", "获取成功!"); - /* - identity_id=1 系统管理员 - identity_id=2 市州管理员 - identity_id=3 县区管理员 - identity_id=4 单位/学校管理员 - identity_id=5 教师 - identity_id=6 学生 - identity_id=7 家长 - identity_id=8 第三方接入的系统 - - header的Authorization中放入token,再通过header传过来, - */ - kv.set("identity_id", IdentityConst.SHARE_SYSTEM);//第三方业务系统,视为8号身份人群 - renderJson(kv); - return; - } - renderJson(Kv.by("success", false).set("message", "用户名与密码不正确!")); - } -} diff --git a/dsPgBase/src/main/java/com/dsideal/dsBase/DataShare/Model/DataShareModel.java b/dsPgBase/src/main/java/com/dsideal/dsBase/DataShare/Model/DataShareModel.java deleted file mode 100644 index 39132c7d..00000000 --- a/dsPgBase/src/main/java/com/dsideal/dsBase/DataShare/Model/DataShareModel.java +++ /dev/null @@ -1,390 +0,0 @@ -package com.dsideal.dsBase.DataShare.Model; - -import com.dsideal.dsBase.Util.CommonUtil; -import com.dsideal.dsBase.Util.PgUtil; -import com.dsideal.dsBase.Util.RsaUtils; -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 java.util.*; - -public class DataShareModel { - - public Page listSystem(String keyword, int exclude, int page, int limit) { - if (StrKit.isBlank(keyword)) keyword = ""; - Kv kv = Kv.by("keyword", keyword); - if (exclude > 0) { - kv.set("exclude", exclude); - } - SqlPara sp = Db.getSqlPara("DataShare.listSystem", kv); - Page list = Db.paginate(page, limit, sp); - for (Record record : list.getList()) { - String subscribe_system_ids = record.getStr("subscribe_system_ids"); - if (StrKit.isBlank(subscribe_system_ids)) record.set("subscribe_system_count", 0); - else { - record.set("subscribe_system_count", subscribe_system_ids.split(",").length); - } - } - return list; - } - - /** - * 功能:判断用户名是否重复 - * - * @param user_name - * @return - */ - public boolean isExistUserName(String user_name) { - String sql = "select * from t_datashare_system where user_name=?"; - return !Db.find(sql, user_name).isEmpty(); - } - - public void addSystem(String system_name, String user_name, String redirect_url) { - Record record = new Record(); - record.set("system_name", system_name); - record.set("user_name", user_name); - record.set("redirect_url", redirect_url); - String pwd = CommonUtil.generatePassword(10); - record.set("pwd", pwd); - if (PgUtil.isExistUser(user_name)) { - PgUtil.delUser(user_name); - } - PgUtil.createUser(user_name, pwd); - Db.save("t_datashare_system", "system_id", record); - } - - /** - * 功能:删除系统 - * - * @param system_id - */ - public void delSystem(int system_id) { - //1、删除此系统的用户 - String user_name = getSystemById(system_id).getStr("user_name"); - PgUtil.delUser(user_name); - //2、删除数据表记录 - Db.deleteById("t_datashare_system", "system_id", system_id); - - //3、共享了哪些表 - String sql = "select * from t_datashare_table where system_id=?"; - List shareTableList = Db.find(sql, system_id); - //4、删除此系统共享表 - sql = "delete from t_datashare_table where system_id=?"; - Db.update(sql, system_id); - - //5、删除所有其它系统对此系统的订阅 - List subSystemList = getSubSystemList(system_id); - sql = "select * from t_datashare_system"; - List list = Db.find(sql); - for (Record record : list) { - int sub_system_id = record.getInt("system_id"); - String subscribe_system_ids = record.getStr("subscribe_system_ids"); - String new_subscribe_system_ids = ""; - if (!StrKit.isBlank(subscribe_system_ids)) { - for (String s : subscribe_system_ids.split(",")) { - if (!s.equals(system_id + "")) new_subscribe_system_ids += s + ","; - } - } - if (!new_subscribe_system_ids.isEmpty()) { - new_subscribe_system_ids = new_subscribe_system_ids.substring(0, new_subscribe_system_ids.length() - 1);//去最后的逗号 - } - sql = "update t_datashare_system set subscribe_system_ids=? where system_id=?"; - Db.update(sql, new_subscribe_system_ids, sub_system_id); - } - //5、回收其它订阅系统对它共享表的授权 - for (Record record : shareTableList) { - String table_name = record.getStr("table_name"); - for (Integer v_system_id : subSystemList) { - String v_user_name = getSystemById(v_system_id).getStr("user_name"); - PgUtil.revokeUserPrivilege(v_user_name, table_name, PgUtil.READ); - } - } - } - - /** - * 功能:检查要共享的表是不是已经被其它业务系统共享过? - * - * @param table_names - * @return - */ - public boolean checkShareTable(int system_id, String table_names) { - String sql = "select * from t_datashare_table"; - List list = Db.find(sql); - Map _map = new HashMap<>(); - for (Record record : list) { - _map.put(record.getStr("table_name"), record.getInt("system_id")); - } - for (String s : table_names.split(",")) { - if (_map.containsKey(s)) { - if (_map.get(s) != system_id) { - return false; - } - } - } - return true; - } - - /** - * 功能:更新系统 - * - * @param system_id - * @param system_name - */ - public void updateSystem(int system_id, String system_name, String redirect_url) { - String sql = "update t_datashare_system set system_name=?,redirect_url=? where system_id=?"; - Db.update(sql, system_name, redirect_url, system_id); - } - - /** - * 功能:获取系统信息 - * - * @param system_id - * @return - */ - public Record getSystemById(int system_id) { - return Db.findById("t_datashare_system", "system_id", system_id); - } - - /** - * 功能:系统SYSTEM_ID被哪些其它系统订阅过 - * - * @param system_id - * @return - */ - public List getSubSystemList(int system_id) { - List res = new ArrayList<>(); - String sql = "select * from t_datashare_system"; - List list = Db.find(sql); - for (Record record : list) { - boolean flag = false; - String subscribe_system_ids = record.getStr("subscribe_system_ids"); - if (!StrKit.isBlank(subscribe_system_ids)) { - for (String s : subscribe_system_ids.split(",")) { - if (Integer.parseInt(s) == system_id) { - flag = true; - break; - } - } - } - if (flag) { - res.add(record.getInt("system_id")); - } - } - return res; - } - - /** - * 功能:记录指定系统它有哪些数据表 - * - * @param system_id - * @param table_names - */ - public void share(int system_id, String table_names) { - //0、系统的ID与数据库用户名 - Record systemRecord = getSystemById(system_id); - String user_name = systemRecord.getStr("user_name"); - - //原来共享的表 - List oldTables = getShareTable(system_id); - - //1、回收原来共享表的写权限 - for (Record r : oldTables) {//原来有哪些共享表? - String table_name = r.getStr("table_name"); - PgUtil.revokeUserPrivilege(user_name, table_name, PgUtil.WRITE); - } - - //2、重新分配新共享表的写权限 - if (!StrKit.isBlank(table_names)) { - for (String s : table_names.split(",")) { - PgUtil.grantUserPrivilege(user_name, s, PgUtil.WRITE); - } - } - - - //3、原来订阅这个系统有第三方系统有哪些,它们的用户都需要取消对原来表的读授权 - List listUser = new ArrayList<>(); - List lSystem = getSubSystemList(system_id); - for (int i = 0; i < lSystem.size(); i++) { - String sub_user_name = getSystemById(lSystem.get(i)).getStr("user_name"); - listUser.add(sub_user_name); - } - - for (Record r : oldTables) {//原来有哪些共享表? - String table_name = r.getStr("table_name"); - for (String s : listUser) { - PgUtil.revokeUserPrivilege(s, table_name, PgUtil.READ); - } - } - //4、原来访问的这个系统的第三方系统,它们的用户都需要授予新表的读权限 - if (!StrKit.isBlank(table_names)) { - for (String table_name : table_names.split(",")) { - for (String user : listUser) { - PgUtil.grantUserPrivilege(user, table_name, PgUtil.READ); - } - } - } - //5、删除旧数据 - String sql = "delete from t_datashare_table where system_id=?"; - Db.update(sql, system_id); - - //6、保存新数据 - if (!StrKit.isBlank(table_names)) { - for (String s : table_names.split(",")) { - systemRecord = new Record(); - systemRecord.set("system_id", system_id); - systemRecord.set("table_name", s); - Db.save("t_datashare_table", "id", systemRecord); - } - } - } - - /** - * 功能:订阅了哪些系统 - * - * @param system_id - * @param subscribe_system_ids - */ - public void subscribe(int system_id, String subscribe_system_ids) { - Record record = getSystemById(system_id); - String user_name = record.getStr("user_name"); - - //如果不再有订阅的系统 - if (StrKit.isBlank(subscribe_system_ids)) { - //这个系统已经订阅了哪些系统的哪些表 - String sql = "select subscribe_system_ids from t_datashare_system where system_id=?"; - String exist_subscribe_system_ids = Db.queryStr(sql, system_id); - //对于这些表都需要回收此用户的读权限 - for (String s : exist_subscribe_system_ids.split(",")) { - List list = getShareTable(Integer.parseInt(s)); - for (Record r : list) { - PgUtil.revokeUserPrivilege(user_name, r.getStr("table_name"), PgUtil.READ); - } - } - sql = "update t_datashare_system set subscribe_system_ids=null where system_id=?"; - Db.update(sql, system_id); - return; - } - //如果是修改为新的订阅系统 - for (String s : subscribe_system_ids.split(",")) { - int sub_system_id = Integer.parseInt(s); - //获取此系统的所有表 - List records = getShareTable(sub_system_id); - for (Record r : records) { - String table_name = r.getStr("table_name"); - PgUtil.grantUserPrivilege(user_name, table_name, PgUtil.READ); - } - } - String sql = "update t_datashare_system set subscribe_system_ids=? where system_id=?"; - Db.update(sql, subscribe_system_ids, system_id); - } - - /** - * 功能:获取指定系统它有哪些数据表 - * - * @param system_id - */ - public List getShareTable(int system_id) { - String sql = "select * from t_datashare_table where system_id=?"; - return Db.find(sql, system_id); - } - - /** - * 功能:判断指定的一组表是不是有不存在的 - * - * @param table_names - * @return - */ - public boolean isExistTable(String table_names) { - for (String s : table_names.split(",")) { - if (!PgUtil.isExistTable(s)) return false; - } - return true; - } - - /** - * 功能:保存上传文件 - * - * @param system_id - * @param url - */ - public void saveUploadFile(int system_id, String url) { - String sql = "update t_datashare_system set url=? where system_id=?"; - Db.update(sql, url, system_id); - } - - /** - * 功能:修改接入系统密码 - * - * @param system_id - * @param pwd - */ - public void changePwd(int system_id, String pwd) { - String user_name = getSystemById(system_id).getStr("user_name"); - PgUtil.changePwd(user_name, pwd); - String sql = "update t_datashare_system set pwd=? where system_id=?"; - Db.update(sql, pwd, system_id); - } - - /** - * 功能:检查redirect_url 是否已存在 - * - * @param redirect_url - * @return - */ - public boolean isExistRedirectUrl(String redirect_url) { - if (StrKit.isBlank(redirect_url)) return false; - String sql = "select * from t_datashare_system where redirect_url=?"; - return Db.findFirst(sql, redirect_url) != null; - } - - /** - * 第三方系统,根据用户名密码获取token - * - * @param user_name 分配的用户名 - * @param pwd 分配的密码 - * @return 获取到的token, 如果用户名与密码无效,则返回null - */ - public String getToken(String user_name, String pwd) { - String sql = "select * from t_datashare_system where user_name=? and pwd=?"; - Record record = Db.findFirst(sql, user_name, pwd); - if (record == null) return null; - return RsaUtils.encryptedDataOnJava(user_name + " " + System.currentTimeMillis(), RsaUtils.PUBLICKEY); - } - - - /** - * 验证token是否正确 - * - * @param token 要验证的token - * @return - */ - public Record checkToken(String token) { - Record record = new Record(); - try { - String decryptedData = RsaUtils.decryptDataOnJava(token, RsaUtils.PRIVATEKEY); - String[] x = decryptedData.split(" "); - String time = x[1]; - //判断时间戳是否超时,与当前时间相差60*24*31分钟 - if (System.currentTimeMillis() - Long.parseLong(time) > 1000 * 60 * 24 * 31) { - record.set("message", "票据超时!"); - record.set("success", false); - } else { - //计算两个时间戳之间的差值,单位为秒 - long diff = (System.currentTimeMillis() - Long.parseLong(time)) / 1000; - System.out.println("票据有效,时间差为:" + diff + "秒"); - record.set("message", "票据有效,时间差为:" + diff + "秒"); - record.set("success", true); - } - } catch (Exception e) { - record.set("success", false); - record.set("message", "票据无效!"); - } - return record; - } -} - - diff --git a/dsPgBase/src/main/java/com/dsideal/dsBase/ExcelImportTemplate/StudentImportExcelUtil.java b/dsPgBase/src/main/java/com/dsideal/dsBase/ExcelImportTemplate/StudentImportExcelUtil.java index 55049b92..84989ace 100644 --- a/dsPgBase/src/main/java/com/dsideal/dsBase/ExcelImportTemplate/StudentImportExcelUtil.java +++ b/dsPgBase/src/main/java/com/dsideal/dsBase/ExcelImportTemplate/StudentImportExcelUtil.java @@ -563,6 +563,7 @@ public class StudentImportExcelUtil { record.set("operator", operator); record.set("t_teaching_date", new DateTime()); record.set("ip_address", IpUtil.ipToLong(ip_address)); + record.set("update_ts", DateTime.now()); studentList.add(record); } Db.batchSave("t_sys_loginperson", studentList, 1000); diff --git a/dsPgBase/src/main/java/com/dsideal/dsBase/ExcelImportTemplate/TeacherImportExcelUtil.java b/dsPgBase/src/main/java/com/dsideal/dsBase/ExcelImportTemplate/TeacherImportExcelUtil.java index 04022bb8..8925bfd8 100644 --- a/dsPgBase/src/main/java/com/dsideal/dsBase/ExcelImportTemplate/TeacherImportExcelUtil.java +++ b/dsPgBase/src/main/java/com/dsideal/dsBase/ExcelImportTemplate/TeacherImportExcelUtil.java @@ -483,6 +483,7 @@ public class TeacherImportExcelUtil { record.set("t_teaching_date", rs.get(i).getDate("teach_date")); record.set("operator", operator); record.set("ip_address", IpUtil.ipToLong(ip_address)); + record.set("update_ts", DateTime.now()); saveRs.add(record); } int[] result = Db.batchSave("t_sys_loginperson", saveRs, 200); @@ -573,8 +574,8 @@ public class TeacherImportExcelUtil { //存在不存在空的都回写一下 FileOutputStream excelFileOutPutStream = new FileOutputStream(templateXls); - wb.write(excelFileOutPutStream); excelFileOutPutStream.flush(); + wb.write(excelFileOutPutStream); //2、检查是不是都完整填写 if (ErrorBlankJO.getBoolean("Error")) { diff --git a/dsPgBase/src/main/java/com/dsideal/dsBase/Interceptor/IsLoginInterceptor.java b/dsPgBase/src/main/java/com/dsideal/dsBase/Interceptor/IsLoginInterceptor.java index 78605a89..200307ea 100644 --- a/dsPgBase/src/main/java/com/dsideal/dsBase/Interceptor/IsLoginInterceptor.java +++ b/dsPgBase/src/main/java/com/dsideal/dsBase/Interceptor/IsLoginInterceptor.java @@ -1,7 +1,8 @@ package com.dsideal.dsBase.Interceptor; -import com.dsideal.dsBase.DataShare.Model.DataShareModel; +import com.dsideal.dsBase.Util.RsaUtils; import com.dsideal.dsBase.Util.SessionKit; +import com.dsideal.dsBase.Util.TokenUtil; import com.jfinal.aop.Interceptor; import com.jfinal.aop.Invocation; import com.jfinal.core.Controller; @@ -14,7 +15,6 @@ import com.jfinal.plugin.activerecord.Record; */ public class IsLoginInterceptor implements Interceptor { - DataShareModel dm = new DataShareModel(); @Override public void intercept(Invocation inv) { @@ -39,7 +39,7 @@ public class IsLoginInterceptor implements Interceptor { //检查是不是header的Authorization中有合法Token String Authorization = con.getRequest().getHeader("Authorization"); if (Authorization != null) { - Record record = dm.checkToken(Authorization); + Record record = TokenUtil.checkToken(Authorization); System.out.println(record); if (record.getBoolean("success")) { isTrue = true; @@ -60,4 +60,7 @@ public class IsLoginInterceptor implements Interceptor { //con.redirect("/QingLong/"); } } + + + } \ No newline at end of file diff --git a/dsPgBase/src/main/java/com/dsideal/dsBase/Interceptor/IsSysAdminInterceptor.java b/dsPgBase/src/main/java/com/dsideal/dsBase/Interceptor/IsSysAdminInterceptor.java index ab5b5881..fa1a9acc 100644 --- a/dsPgBase/src/main/java/com/dsideal/dsBase/Interceptor/IsSysAdminInterceptor.java +++ b/dsPgBase/src/main/java/com/dsideal/dsBase/Interceptor/IsSysAdminInterceptor.java @@ -1,9 +1,9 @@ package com.dsideal.dsBase.Interceptor; import com.dsideal.dsBase.Const.IdentityConst; -import com.dsideal.dsBase.DataShare.Model.DataShareModel; import com.dsideal.dsBase.Util.CommonUtil; import com.dsideal.dsBase.Util.SessionKit; +import com.dsideal.dsBase.Util.TokenUtil; import com.jfinal.aop.Interceptor; import com.jfinal.aop.Invocation; import com.jfinal.core.Controller; @@ -16,7 +16,6 @@ import com.jfinal.plugin.activerecord.Record; */ public class IsSysAdminInterceptor implements Interceptor { - DataShareModel dm = new DataShareModel(); @Override public void intercept(Invocation inv) { @@ -40,7 +39,7 @@ public class IsSysAdminInterceptor implements Interceptor { int identityId = -1; String Authorization = con.getRequest().getHeader("Authorization"); if (Authorization != null) { - Record record = dm.checkToken(Authorization); + Record record = TokenUtil.checkToken(Authorization); if (record.getBoolean("success")) { identityId = IdentityConst.SHARE_SYSTEM; } diff --git a/dsPgBase/src/main/java/com/dsideal/dsBase/LoginPerson/Controller/LoginPersonController.java b/dsPgBase/src/main/java/com/dsideal/dsBase/LoginPerson/Controller/LoginPersonController.java index 7b9bc07e..118ad485 100644 --- a/dsPgBase/src/main/java/com/dsideal/dsBase/LoginPerson/Controller/LoginPersonController.java +++ b/dsPgBase/src/main/java/com/dsideal/dsBase/LoginPerson/Controller/LoginPersonController.java @@ -4,7 +4,6 @@ import cn.hutool.captcha.CaptchaUtil; import cn.hutool.captcha.LineCaptcha; import com.alibaba.fastjson.JSONObject; import com.dsideal.dsBase.Base.Model.BaseModel; -import com.dsideal.dsBase.Collect.Model.CollectModel; import com.dsideal.dsBase.Interceptor.*; import com.dsideal.dsBase.LoginPerson.Model.LoginPersonModel; import com.dsideal.dsBase.Util.*; @@ -233,12 +232,6 @@ public class LoginPersonController extends Controller { @Before({GET.class}) public void logout() { SessionKit.clear(getRequest(), getResponse()); - CollectModel cm = new CollectModel(); - if (cm.IS_THIRD_PARTY() == 1) { - String url = "https://space.ccsjy.cn/manage/account/logout"; - redirect(url); - return; - } redirect("/plogin.html"); } diff --git a/dsPgBase/src/main/java/com/dsideal/dsBase/Organization/Model/OrganizationModel.java b/dsPgBase/src/main/java/com/dsideal/dsBase/Organization/Model/OrganizationModel.java index 18fb870c..fb08f057 100644 --- a/dsPgBase/src/main/java/com/dsideal/dsBase/Organization/Model/OrganizationModel.java +++ b/dsPgBase/src/main/java/com/dsideal/dsBase/Organization/Model/OrganizationModel.java @@ -131,6 +131,7 @@ public class OrganizationModel { record.set("city_id", city_id); record.set("area_id", area_id); record.set("b_use", 1); + record.set("org_pk_num", org_pk_num); record.set("is_bureau", 1); record.set("operator", operator); record.set("ip_address", IpUtil.ipToLong(ip_address)); @@ -194,6 +195,7 @@ public class OrganizationModel { //是部门 record.set("main_school_id", -1); record.set("bureau_id", bureau_id); + record.set("org_pk_num", 0); List rs = getAreaIdByParentId(bureau_id); if (rs != null && !rs.isEmpty()) { city_id = rs.getFirst().getStr("city_id"); diff --git a/dsPgBase/src/main/java/com/dsideal/dsBase/Start.java b/dsPgBase/src/main/java/com/dsideal/dsBase/Start.java index 069648ce..a03b442b 100644 --- a/dsPgBase/src/main/java/com/dsideal/dsBase/Start.java +++ b/dsPgBase/src/main/java/com/dsideal/dsBase/Start.java @@ -3,8 +3,6 @@ package com.dsideal.dsBase; import cn.hutool.core.io.FileUtil; import com.dsideal.dsBase.Base.Controller.BaseController; import com.dsideal.dsBase.Classes.Controller.ClassController; -import com.dsideal.dsBase.Collect.Controller.CollectController; -import com.dsideal.dsBase.DataShare.Controller.DataShareController; import com.dsideal.dsBase.Dm.Controller.DmController; import com.dsideal.dsBase.Global.Controller.GlobalController; import com.dsideal.dsBase.Handler.LoginHandler; @@ -83,10 +81,6 @@ public class Start extends JFinalConfig { //菜单管理 me.add("/menu", MenuController.class); - //数据共享 - me.add("/dataShare", DataShareController.class); - //数据上报汇集子系统 - me.add("/collect", CollectController.class); } @Override diff --git a/dsPgBase/src/main/java/com/dsideal/dsBase/Util/TokenUtil.java b/dsPgBase/src/main/java/com/dsideal/dsBase/Util/TokenUtil.java new file mode 100644 index 00000000..20daba7e --- /dev/null +++ b/dsPgBase/src/main/java/com/dsideal/dsBase/Util/TokenUtil.java @@ -0,0 +1,37 @@ +package com.dsideal.dsBase.Util; + +import com.jfinal.plugin.activerecord.Record; + +public class TokenUtil { + + /** + * 验证token是否正确 + * + * @param token 要验证的token + * @return + */ + public static Record checkToken(String token) { + Record record = new Record(); + try { + String decryptedData = RsaUtils.decryptDataOnJava(token, RsaUtils.PRIVATEKEY); + String[] x = decryptedData.split(" "); + String time = x[1]; + //判断时间戳是否超时,与当前时间相差60*24*31分钟 + if (System.currentTimeMillis() - Long.parseLong(time) > 1000 * 60 * 24 * 31) { + record.set("message", "票据超时!"); + record.set("success", false); + } else { + //计算两个时间戳之间的差值,单位为秒 + long diff = (System.currentTimeMillis() - Long.parseLong(time)) / 1000; + System.out.println("票据有效,时间差为:" + diff + "秒"); + record.set("message", "票据有效,时间差为:" + diff + "秒"); + record.set("success", true); + } + } catch (Exception e) { + record.set("success", false); + record.set("message", "票据无效!"); + } + return record; + } + +} diff --git a/dsPgBase/src/main/resources/application.properties b/dsPgBase/src/main/resources/application.properties index 76b690eb..22a01c64 100644 --- a/dsPgBase/src/main/resources/application.properties +++ b/dsPgBase/src/main/resources/application.properties @@ -2,10 +2,10 @@ driverClassName=org.postgresql.Driver user=postgres password=DsideaL147258369 -jdbcUrl=jdbc:postgresql://10.10.14.71:5432/szjz_db?reWriteBatchedInserts=true +jdbcUrl=jdbc:postgresql://10.10.14.66:5432/szjz_db?reWriteBatchedInserts=true # redis -redis_ip=10.10.14.14 +redis_ip=10.10.14.66 redis_port=18890 # 首页 diff --git a/dsPgBase/src/main/resources/undertow.properties b/dsPgBase/src/main/resources/undertow.properties index ec98cc6e..dcfbc721 100644 --- a/dsPgBase/src/main/resources/undertow.properties +++ b/dsPgBase/src/main/resources/undertow.properties @@ -3,7 +3,7 @@ undertow.devMode=false undertow.port=9000 undertow.host=0.0.0.0 #undertow.resourcePath=/usr/local/tomcat8/webapps/QingLong,classpath:static -undertow.resourcePath=D:/dsWork/QingLong/WebRoot,classpath:static +undertow.resourcePath=D:/dsWork/dsProject/dsPgBase/WebRoot,classpath:static # 目录名称 undertow.contextPath=/QingLong