From 9a261c1c166bf9ad0ac5cd8f04a0a6dd0ae1408f Mon Sep 17 00:00:00 2001 From: 354798ggg <1074825718@qq.com> Date: 星期一, 24 七月 2023 14:47:43 +0800 Subject: [PATCH] 项目调整 --- product-server-data-export-import/src/main/java/com/product/module/data/service/SystemDataUpLoadService.java | 882 ++++++++++++ product-server-data-export-import/pom.xml | 56 product-server-data-export-import/src/main/java/com/product/module/data/config/CmnCode.java | 75 + product-server-data-export-import/src/main/java/com/product/module/data/service/OrganizationImportService.java | 1824 +++++++++++++++++++++++++ product-server-data-export-import/src/main/java/com/product/module/data/service/idel/IOrganizationImportService.java | 53 product-server-data-export-import/src/main/java/com/product/module/data/controller/SystemDataUploadController.java | 358 +++++ product-server-data-export-import/src/main/java/com/product/module/data/service/idel/ISystemDataUpLoadService.java | 28 pom.xml | 1 product-server-data-export-import/src/main/java/com/product/module/data/utli/Custemhandler.java | 67 product-server-data-export-import/src/main/java/com/product/module/data/controller/SystemDataExportController.java | 80 + product-server-data-export-import/src/main/java/com/product/module/data/utli/CustomMergeStrategy.java | 98 + product-server-data-export-import/src/main/java/com/product/module/data/service/SystemDataExportService.java | 329 ++++ product-server-data-export-import/src/main/java/com/product/module/data/utli/SystemApiToMethods.java | 243 +++ product-server-data-export-import/src/main/java/com/product/module/data/config/CmnConst.java | 148 ++ 14 files changed, 4,242 insertions(+), 0 deletions(-) diff --git a/pom.xml b/pom.xml index 1e2d309..304a8a4 100644 --- a/pom.xml +++ b/pom.xml @@ -17,6 +17,7 @@ <module>product-server-project-base</module> <module>product-server-project-management</module> <module>product-server-project-contract</module> + <module>product-server-data-export-import</module> <module>product-server-web</module> </modules> <properties> diff --git a/product-server-data-export-import/pom.xml b/product-server-data-export-import/pom.xml new file mode 100644 index 0000000..8b16eef --- /dev/null +++ b/product-server-data-export-import/pom.xml @@ -0,0 +1,56 @@ +<?xml version="1.0"?> +<project + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" + xmlns="http://maven.apache.org/POM/4.0.0" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> + <modelVersion>4.0.0</modelVersion> + <parent> + <groupId>com.lx</groupId> + <artifactId>product-server</artifactId> + <version>2.0.0-release</version> + </parent> + <artifactId>product-server-data-export-import</artifactId> + <name>product-server-data-export-import</name> + <description>product-server-data-export-import</description> + <version>2.0.0-release</version> + <properties> + <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> + </properties> + <dependencies> + <dependency> + <groupId>junit</groupId> + <artifactId>junit</artifactId> + <version>3.8.1</version> + <scope>test</scope> + </dependency> + <dependency> + <groupId>com.lx</groupId> + <artifactId>product-server-core</artifactId> + </dependency> + <dependency> + <groupId>com.lx</groupId> + <artifactId>product-server-common</artifactId> + </dependency> + <dependency> + <groupId>com.lx</groupId> + <artifactId>product-server-util</artifactId> + </dependency> + <dependency> + <groupId>org.apache.httpcomponents</groupId> + <artifactId>httpmime</artifactId> + </dependency> + <dependency> + <groupId>junit</groupId> + <artifactId>junit</artifactId> + <scope>test</scope> + </dependency> + <dependency> + <groupId>com.lx</groupId> + <artifactId>product-server-file</artifactId> + </dependency> + <dependency> + <groupId>com.lx</groupId> + <artifactId>product-server-org-admin</artifactId> + </dependency> + </dependencies> +</project> diff --git a/product-server-data-export-import/src/main/java/com/product/module/data/config/CmnCode.java b/product-server-data-export-import/src/main/java/com/product/module/data/config/CmnCode.java new file mode 100644 index 0000000..a6f85f2 --- /dev/null +++ b/product-server-data-export-import/src/main/java/com/product/module/data/config/CmnCode.java @@ -0,0 +1,75 @@ +package com.product.module.data.config; + +import com.product.common.enums.IEnum; +import com.product.common.enums.ModuleEnum; + +public enum CmnCode implements IEnum { + + SYSTEM_OPERATION_SUCCESS("鎴愬姛", "200"), + SYSTEM_FORM_NODATA("璇锋眰鍙傛暟涓虹┖", ModuleEnum.EXPORT_IMPORT.getValue() + "999"), + SYSTEM_FORM_COUNT("璇锋眰鍙傛暟鏈夎", ModuleEnum.EXPORT_IMPORT.getValue() + "998"), + SYSTEM_TABLE_NODATA("璇锋眰琛ㄥ悕鏈夎", ModuleEnum.EXPORT_IMPORT.getValue() + "997"), + SYSTEM_ACQUIRE_PARAM_FAIL("鑾峰彇鍙傛暟澶辫触", ModuleEnum.EXPORT_IMPORT.getValue() + "996"), + SYSTEM_CPAGES_NOT_NULL("鍒嗛〉鍙傛暟涓嶈兘涓虹┖", ModuleEnum.EXPORT_IMPORT.getValue() + "995"), + + EXPORT_GENERAL_LIST_DATA_IMPORT_FIAL("瀵煎嚭鍒楄〃鏁版嵁澶辫触", ModuleEnum.EXPORT_IMPORT.getValue() + "001"), + EXPORT_FILE_NAME_NOT_EMPTY("瀵煎嚭鏂囦欢鍚嶇О涓嶈兘涓虹┖", ModuleEnum.EXPORT_IMPORT.getValue() + "002"), + EXPORT_UPLOAD_URL_NOT_EMPTY("瀵煎嚭鏁版嵁鎺ュ彛涓嶈兘涓虹┖", ModuleEnum.EXPORT_IMPORT.getValue() + "003"), + EXPORT_PARAMS_NOT_EMPTY("瀵煎嚭鎵�闇�鍙傛暟涓嶈兘涓虹┖", ModuleEnum.EXPORT_IMPORT.getValue() + "004"), + EXPORT_GET_DATA_EMPTY("瀵煎嚭鑾峰彇鏁版嵁涓虹┖", ModuleEnum.EXPORT_IMPORT.getValue() + "005"), + EXPORT_GET_API_METHOD_FILA("瀵煎嚭鑾峰彇method澶辫触", ModuleEnum.EXPORT_IMPORT.getValue() + "006"), + EXPORT_REPORT_DATA_FIAL("瀵煎嚭鑾峰彇method澶辫触", ModuleEnum.EXPORT_IMPORT.getValue() + "007"), + + UPLOAD_TEMPLATE_GET_LIST_FAIL("鑾峰彇妯℃澘瀵煎叆鍒楄〃澶辫触", ModuleEnum.EXPORT_IMPORT.getValue() + "101"), + UPLOAD_TEMPLATE_DELETE_FAIL("鍒犻櫎妯℃澘澶辫触", ModuleEnum.EXPORT_IMPORT.getValue() + "102"), + UPLOAD_TEMPLATE_GET_MAIN_INFO_FAIL("鑾峰彇妯℃澘涓昏〃淇℃伅澶辫触", ModuleEnum.EXPORT_IMPORT.getValue() + "103"), + UPLOAD_TEMPLATE_GET_INFO_FAIL("鑾峰彇妯℃澘璇︽儏澶辫触", ModuleEnum.EXPORT_IMPORT.getValue() + "104"), + UPLOAD_TEMPLATE_ADD_FAIL("鏂板妯℃澘澶辫触", ModuleEnum.EXPORT_IMPORT.getValue() + "105"), + UPLOAD_TEMPLATE_UPDATE_FAIL("淇敼妯℃澘澶辫触", ModuleEnum.EXPORT_IMPORT.getValue() + "106"), + UPLOAD_TEMPLATE_FIND_FAIL("鏌ヨ妯℃澘璇︽儏澶辫触", ModuleEnum.EXPORT_IMPORT.getValue() + "107"), + UPLOAD_TEMPLATE_DOWNLOAD_FAIL("涓嬭浇妯℃澘澶辫触", ModuleEnum.EXPORT_IMPORT.getValue() + "108"), + UPLOAD_TEMPLATE_RECORD_DATA_IMPORT_FILE_FAIL("涓氬姟鏁版嵁瀵煎叆鏂囦欢澶辫触", ModuleEnum.EXPORT_IMPORT.getValue() + "109"), + UPLOAD_TEMPLATE_RECORD_DATA_IMPORT_DATA_FAIL("涓氬姟鏁版嵁瀵煎叆鏁版嵁澶辫触", ModuleEnum.EXPORT_IMPORT.getValue() + "110"), + UPLOAD_TEMPLATE_GET_RECORD_TABLE_FAIL("鑾峰彇涓氬姟琛ㄤ俊鎭け璐�", ModuleEnum.EXPORT_IMPORT.getValue() + "111"), + UPLOAD_TEMPLATE_IMPORT_DATA_FAIL("瀵煎叆鏁版嵁澶辫触", ModuleEnum.EXPORT_IMPORT.getValue() + "112"), + UPLOAD_TEMPLATE_BEFORE_FUNC_EXEC_FAIL("浜嬩欢鍓嶆柟娉曞鐞嗘墽琛屽け璐�", ModuleEnum.EXPORT_IMPORT.getValue() + "113"), + UPLOAD_TEMPLATE_BEFORE_FUNC_EXEC_NO_DATA("鎵ц浜嬩欢鍓嶆柟娉曞鐞嗗悗鏁版嵁涓虹┖", ModuleEnum.EXPORT_IMPORT.getValue() + "114"), + UPLOAD_TEMPLATE_AFTER_FUNC_EXEC_FAIL("浜嬩欢鍚庢柟娉曞鐞嗘墽琛屽け璐�", ModuleEnum.EXPORT_IMPORT.getValue() + "115"), + UPLOAD_TEMPLATE_GET_UPLOAD_RECORD_FAIL("鑾峰彇妯℃澘瀵煎叆璁板綍澶辫触", ModuleEnum.EXPORT_IMPORT.getValue() + "116"), + UPLOAD_TEMPLATE_NOT_ALLOWED_FORMAT("涓嶆敮鎸佺殑妯℃澘鏍煎紡", ModuleEnum.EXPORT_IMPORT.getValue() + "117"), + UPLOAD_TEMPLATE_SAVE_FAIL("妯℃澘淇濆瓨澶辫触", ModuleEnum.EXPORT_IMPORT.getValue() + "118"), + UPLOAD_TEMPLATE_EXISTS_EMPTY_COL("妯℃澘鏂囦欢涓棤娉曞瓨鍦ㄧ┖鍒�", ModuleEnum.EXPORT_IMPORT.getValue() + "119"), + + + GET_MVC_FIRST_PAGE_INFO_FAIL("鑾峰彇mvc鍒楄〃淇℃伅澶辫触", ModuleEnum.EXPORT_IMPORT.getValue() + "120"), + + GET_EXPORT_PROMPT_LIST_FINAL("鑾峰彇鍙傜収鍒楄〃澶辫触", ModuleEnum.EXPORT_IMPORT.getValue() + "121") + ; + private String text; + private String value; + + CmnCode(String text, String value) { + this.text = text; + this.value = value; + } + + /** + * 鑾峰彇鏋氫妇绫诲瀷瀹炰緥瑕佹樉绀虹殑鏂囨湰銆� + * + * @return 杩斿洖鏋氫妇绫诲瀷瀹炰緥鐨勬枃鏈�� + */ + @Override + public String getText() { + return text; + } + + /** + * 鑾峰彇鏋氫妇绫诲瀷瀹炰緥鐨勫�笺�� + * + * @return 杩斿洖鏋氫妇绫诲瀷瀹炰緥鐨勫�笺�� + */ + @Override + public String getValue() { + return value; + } +} diff --git a/product-server-data-export-import/src/main/java/com/product/module/data/config/CmnConst.java b/product-server-data-export-import/src/main/java/com/product/module/data/config/CmnConst.java new file mode 100644 index 0000000..b7e1a75 --- /dev/null +++ b/product-server-data-export-import/src/main/java/com/product/module/data/config/CmnConst.java @@ -0,0 +1,148 @@ +package com.product.module.data.config; + +/** + * @Author cheng + * @Description 甯搁噺 + * @Date 2021/6/10 14:36 + * @Version 1.0 + */ +public class CmnConst { + + // 琛ㄥ悕甯搁噺瀹氫箟 + + // 鍒嗛〉甯搁噺瀹氫箟 + public static final String CPAGE = "cpage"; // 椤垫暟 + public static final String PAGESIZE = "pagesize"; // 姣忛〉鏉℃暟 + + // 琛ㄥ悕 + public static final String TABLE_PRODUCT_SYS_BUTTONS = "product_sys_function_buttons";// mvc-鎸夐挳琛� + public static final String TABLE_PRODUCT_SYS_MVC_PAGE = "product_sys_mvc_page";// mvc-椤甸潰琛� + public static final String TABLE_PRODUCT_SYS_MVC_LINK = "product_sys_link";// mvc-杩炵嚎琛� + public static final String TABLE_PRODUCT_SYS_ATTACHMENT = "product_sys_attachments";// 闄勪欢琛� + public static final String TABLE_PRODUCT_SYS_DATA_UPLOAD_MODEL = "product_sys_data_upload_model";// 鏁版嵁涓婁紶妯℃澘 + public static final String TABLE_PRODUCT_SYS_DATA_UPLOAD_MODEL_SUB = "product_sys_data_upload_model_sub";// 鏁版嵁涓婁紶妯℃澘瀛愯〃 + public static final String TABLE_PRODUCT_SYS_DATA_UPLOAD_RECORD = "product_sys_data_upload_record";// 鏁版嵁妯℃澘瀵煎叆璁板綍琛� + public static final String TABLE_PRODUCT_SYS_ORG_LEVELS = "product_sys_org_levels";// 缁勭粐鏈烘瀯琛� + public static final String TABLE_PRODUCT_SYS_DATA_STRATEGY_MASTER = "product_sys_data_strategy_master"; // 鏁版嵁鏉冮檺涓昏〃 + public static final String TABLE_PRODUCT_SYS_JOB_POSTS_GRADES_MAPPING = "product_sys_job_posts_grades_mapping"; + public static final String TABLE_PRODUCT_SYS_STAFFS = "product_sys_staffs"; + + // 鍏叡甯搁噺瀹氫箟 + public static final String UPDATED_BY = "updated_by"; // 淇敼鑰� + public static final String USER_ACCOUNT = "user_account"; // 淇敼鑰� + public static final String USER_PWD = "user_pwd"; // 淇敼鑰� + public static final String TRICODE = "tricode"; // 淇敼鑰� + public static final String USER_NAME = "user_name"; // 淇敼鑰� + public static final String USER_ID = "USER_ID"; // 淇敼鑰� + public static final String CLIENT_UUID = "client_uuid"; // 瀹㈡埛uuid + public static final String UPDATED_UTC_DATETIME = "updated_utc_datetime"; // 淇敼鏃堕棿 + public static final String CREATED_BY = "created_by"; // 鍒涘缓鑰� + public static final String CREATED_UTC_DATETIME = "created_utc_datetime"; // 鍒涘缓鏃堕棿 + public static final String STAFF_ID = "staff_id"; // 鍛樺伐id + public static final String STAFF_UUID = "staff_uuid"; // 鍛樺伐uuid + public static final String ORG_LEVEL_UUID = "org_level_uuid"; // 缁勭粐鏋舵瀯uuid + public static final String UUID = "uuid"; // uuid + public static final String STAFFS_UUID = "staffs_uuid"; // 鍛樺伐uuid + public static final String IS_USED = "is_used";// 鏄惁 + public static final String SEQUENCE = "sequence";//鎺掑簭 + public static final String TABLE_NAME = "table_name";//瀵煎嚭鎺ュ彛鍙傛暟key + + + public static final String EXPORT_PARAM = "export_param";//瀵煎嚭鎺ュ彛鍙傛暟key + public static final String FILE_NAME = "file_name";//鏂囦欢鍚嶇О + public static final String START_CPAGE = "start_cpage";//寮�濮嬮〉 + public static final String END_CPAGE = "end_cpage";//缁撴潫椤� + public static final String UPLOAD_API_URL = "upload_api_url";//涓婁紶api + + public static final String FIELD_NAME = "field_name"; + public static final String FIELD_DESC = "field_description"; + + //缁勭粐鏈烘瀯 + public static final String FIELD_ORG_LEVEL_NAME = "org_level_name"; + public static final String FIELD_ORG_LEVEL_ALL = "org_level_all"; + public static final String FIELD_ORG_LEVEL_CODE = "org_level_code"; + public static final String FIELD_ORG_LEVEL_CODE_PARENT = "org_level_code_parent"; + public static final String FIELD_ORG_LEVEL_STATUS = "org_level_status"; + public static final String FIELD_ORG_LEVEL_TYPE = "org_level_type"; + + + // 宀椾綅绛夌骇 + public static final String FIELD_GROUP_NAME = "group_name"; + public static final String FIELD_JOB_GRADE_NAME = "job_grade_name"; + public static final String FIELD_JOB_GRADE_CLASS = "job_grade_class"; + + //宀椾綅 + + public static final String FIELD_JOB_POST_NAME = "job_post_name"; + public static final String FIELD_DEPT_UUID = "dept_uuid"; + public static final String FIELD_JOB_POST_GRADE = "job_post_grades_uuid"; + //鍛樺伐 + public static final String FIELD_DIRECT_LEADER_CODE = "direct_leader_code"; + public static final String FIELD_STAFF_CODE = "staff_code"; + public static final String FIELD_GENDER = "gender"; + public static final String FIELD_JOB_POST_GRADE_UUID = "job_post_grade_uuid"; + + + // 閫氱敤 + public static final String FIELD_ORG_LEVEL_UUID = "org_level_uuid"; + // 鏁版嵁妯℃澘涓婁紶琛� + public static final String FIELD_UPLOAD_SIGN = "upload_sign"; + public static final String FIELD_TITLE = "title"; + public static final String FIELD_FUNCTION_UUID = "function_uuid"; + public static final String FIELD_BUTTON_UUID = "button_uuid"; + public static final String FIELD_BEFORE_FUNC = "before_func"; + public static final String FIELD_AFTER_FUNC = "after_func"; + public static final String FIELD_TABLE_NAME = "table_name"; + public static final String FIELD_TEMPLATE_INFO = "template_info"; + public static final String FIELD_SHEET_ORDER = "sheet_order"; + // 鏁版嵁妯℃澘涓婁紶瀛愯〃 + public static final String FIELD_EXCEL_HEADER = "excel_header"; + public static final String FIELD_FIELD_NAME = "field_name"; + public static final String FIELD_FIELD_TYPE = "field_type"; + public static final String FIELD_PROMPT_NAME = "prompt_name"; + public static final String FIELD_IS_MULTI = "is_multi"; + public static final String FIELD_MODEL_UUID = "model_uuid"; + // 闄勪欢琛� + public static final String FIELD_ATTACHMENT_URL = "attachment_url"; + public static final String FIELD_ATTACHMENT_TITLE = "attachment_title";// 澶勭悊涔嬪悗鐨勯檮浠跺悕绉� + // 璁板綍琛� + public static final String FIELD_IMPORT_INFO = "import_info"; + public static final String FIELD_IS_SUCCESS = "is_success"; + // 鏅�氬弬鐓ц〃 + public static final String FIELD_DICT_LABEL = "dict_label"; + public static final String FIELD_DICT_VALUE = "dict_value"; + // 楂樼骇鍙傜収琛� + public static final String FILED_VIEW_FIELD = "view_fields"; + public static final String FILED_VALUE_FIELD = "value_field"; + public static final String FILED_SOURCE_TABLE = "source_table"; + public static final String FILED_FILTER = "filter"; + // mvc鎸夐挳 + public static final String FILED_FUNCTION_UUID = "function_uuid"; + public static final String FILED_BUTTON_NAME = "button_name"; + public static final String FILED_BUTTON_TITLE = "button_title"; + public static final String FILED_STATUS_UUID = "status_uuid"; + public static final String FILED_CATEGORY_UUID = "button_category_uuid"; + public static final String FILED_CLIENT_TYPE_UUID = "client_type_uuid"; + public static final String FILED_ROUTE_NAME = "route_name"; + // mvc椤甸潰 + public static final String FIELD_PAGE_NAME = "page_name"; + public static final String FIELD_PAGE_TYPE = "page_type"; + // mvc杩炵嚎 + public static final String FIELD_LINK_TYPE = "link_type"; + public static final String FIELD_LINE_FROM = "line_from"; + public static final String FIELD_FROM_TYPE = "from_type"; + public static final String FIELD_LINE_TO = "line_to"; + public static final String FIELD_TO_TYPE = "to_type"; + + // 鍥哄畾鐩綍 + public static final String DIR_TEMPLATE = "template";// 妯℃澘鐩綍 + public static final String DIR_IMPORT = "import";// 鏁版嵁瀵煎叆鐩綍 + public static final String DIR_PRINT = "print";// 鎵撳嵃鐩綍 + public static final String DIR_OTHER = "other";// 鍏朵粬鐩綍 + + // 缂撳瓨 + public static final String CACHE_TABLE = "鎵�鏈夎〃淇℃伅"; + public static final String CACHE_FIELD = "鎵�鏈夎〃鍏宠仈淇℃伅"; + public static final String CACHE_COMMON_PROMPT = "鏁版嵁瀛楀吀閰嶇疆淇℃伅"; + public static final String CACHE_ADVANCED_PROMPT = "楂樼骇鍙傜収閰嶇疆淇℃伅"; +} diff --git a/product-server-data-export-import/src/main/java/com/product/module/data/controller/SystemDataExportController.java b/product-server-data-export-import/src/main/java/com/product/module/data/controller/SystemDataExportController.java new file mode 100644 index 0000000..db6e1cc --- /dev/null +++ b/product-server-data-export-import/src/main/java/com/product/module/data/controller/SystemDataExportController.java @@ -0,0 +1,80 @@ +package com.product.module.data.controller; + +import com.alibaba.druid.util.StringUtils; +import com.product.core.config.CoreConst; +import com.product.core.controller.support.AbstractBaseController; +import com.product.core.entity.DataTableEntity; +import com.product.core.entity.FieldSetEntity; +import com.product.core.entity.RequestParameterEntity; +import com.product.core.exception.BaseException; +import com.product.core.spring.context.SpringMVCContextHolder; +import com.product.module.data.config.CmnCode; +import com.product.module.data.config.CmnConst; +import com.product.module.data.service.SystemDataExportService; +import com.product.module.sys.version.ApiVersion; +import com.product.util.BaseUtil; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import javax.servlet.http.HttpServletRequest; +import javax.xml.crypto.Data; + +/** + * @Author cheng + * @Description 鏁版嵁瀵煎嚭 + * @Date 2021/6/10 14:33 + * @Version 1.0 + */ +@RestController +@RequestMapping("/api/data/export") +public class SystemDataExportController extends AbstractBaseController { + + + @Autowired + SystemDataExportService systemDataExportService; + + @PostMapping("general-list/{version}") + @ApiVersion(1) + public String generalListDataExport(HttpServletRequest request) { + try { + FieldSetEntity fse = null; + Object bean = request.getAttribute(CoreConst.API_POST_REQUEST_DATA); + if (bean != null) { + RequestParameterEntity reqp = (RequestParameterEntity) bean; + fse = reqp.getFormData(); + } + if (bean == null || fse == null) { + SpringMVCContextHolder.getSystemLogger().error(CmnCode.SYSTEM_FORM_NODATA.getValue(), CmnCode.SYSTEM_FORM_NODATA.getText()); + return this.error(CmnCode.SYSTEM_FORM_NODATA.getValue(), CmnCode.SYSTEM_FORM_NODATA.getText()); + } + // 鍒ゆ柇鍙傛暟鏄惁姝e父 + if (StringUtils.isEmpty(fse.getString(CmnConst.FILE_NAME))) { + SpringMVCContextHolder.getSystemLogger().error(CmnCode.EXPORT_FILE_NAME_NOT_EMPTY.getValue(), CmnCode.EXPORT_FILE_NAME_NOT_EMPTY.getText()); + return this.error(CmnCode.EXPORT_FILE_NAME_NOT_EMPTY.getValue(), CmnCode.EXPORT_FILE_NAME_NOT_EMPTY.getText()); + } + if (StringUtils.isEmpty(fse.getString(CmnConst.UPLOAD_API_URL))) { + SpringMVCContextHolder.getSystemLogger().error(CmnCode.EXPORT_UPLOAD_URL_NOT_EMPTY.getValue(), CmnCode.EXPORT_UPLOAD_URL_NOT_EMPTY.getText()); + return this.error(CmnCode.EXPORT_UPLOAD_URL_NOT_EMPTY.getValue(), CmnCode.EXPORT_UPLOAD_URL_NOT_EMPTY.getText()); + } + if (BaseUtil.dataTableIsEmpty(fse.getSubDataTable(CmnConst.EXPORT_PARAM))) { + SpringMVCContextHolder.getSystemLogger().error(CmnCode.EXPORT_PARAMS_NOT_EMPTY.getValue(), CmnCode.EXPORT_PARAMS_NOT_EMPTY.getText()); + return this.error(CmnCode.EXPORT_PARAMS_NOT_EMPTY.getValue(), CmnCode.EXPORT_PARAMS_NOT_EMPTY.getText()); + } + systemDataExportService.generalListDataExport(fse.clones()); + return OK(); + } catch (BaseException e) { + e.printStackTrace(); + SpringMVCContextHolder.getSystemLogger().error(e); + return error(e); + } catch (Exception e) { + e.printStackTrace(); + SpringMVCContextHolder.getSystemLogger().error(e); + return error(CmnCode.EXPORT_GENERAL_LIST_DATA_IMPORT_FIAL.getValue(), CmnCode.EXPORT_GENERAL_LIST_DATA_IMPORT_FIAL.getText() + e.getMessage()); + } + } + + + +} diff --git a/product-server-data-export-import/src/main/java/com/product/module/data/controller/SystemDataUploadController.java b/product-server-data-export-import/src/main/java/com/product/module/data/controller/SystemDataUploadController.java new file mode 100644 index 0000000..0a9efe1 --- /dev/null +++ b/product-server-data-export-import/src/main/java/com/product/module/data/controller/SystemDataUploadController.java @@ -0,0 +1,358 @@ +package com.product.module.data.controller; + +import com.alibaba.fastjson.JSONObject; +import com.product.common.lang.StringUtils; +import com.product.core.config.CoreConst; +import com.product.core.controller.support.AbstractBaseController; +import com.product.core.entity.FieldSetEntity; +import com.product.core.entity.RequestParameterEntity; +import com.product.core.exception.BaseException; +import com.product.core.spring.context.SpringMVCContextHolder; +import com.product.file.config.FileCode; +import com.product.module.data.config.CmnCode; +import com.product.module.data.config.CmnConst; +import com.product.module.data.service.SystemDataUpLoadService; +import com.product.module.data.service.idel.ISystemDataUpLoadService; +import com.product.module.sys.version.ApiVersion; +import com.product.util.BaseUtil; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.bind.annotation.RestController; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import java.io.IOException; + +@RestController +@RequestMapping("/api/data-model") +public class SystemDataUploadController extends AbstractBaseController { + @Autowired + private SystemDataUpLoadService systemDataUpLoadService; + + + /** + * 妯℃澘涓婁紶 + * + * @return 缁撴灉 + */ + @RequestMapping(value = "/upload-template/{version}", method = RequestMethod.POST) + @ApiVersion(1) + public String uploadTemplate(HttpServletRequest request) { + try { + Object bean = request.getAttribute(CoreConst.API_POST_REQUEST_DATA); + RequestParameterEntity rpe = (RequestParameterEntity) bean; + ISystemDataUpLoadService iSystemDataUpLoadService = (ISystemDataUpLoadService) getProxyInstance(systemDataUpLoadService); + JSONObject resultObj = iSystemDataUpLoadService.uploadTemplate(rpe); + return BaseUtil.success(resultObj); + } catch (BaseException e) { + SpringMVCContextHolder.getSystemLogger().error(e); + e.printStackTrace(); + return error(e.getCode(), e.getMessage()); + } catch (Exception e) { + SpringMVCContextHolder.getSystemLogger().error(e); + e.printStackTrace(); + return error(FileCode.UPLOAD_FILE_FAIL.getValue(), FileCode.UPLOAD_FILE_FAIL.getText()); + } + } + + /** + * 鏍规嵁宸茬粡涓婁紶鐨別xcel鏂囦欢,瑙f瀽excel琛ㄥご + * + * @param request + * @return + * @throws IOException + */ + @RequestMapping(value = "/analysis-template/{version}", method = RequestMethod.POST) + public String analysisTemplate(HttpServletRequest request) { + try { + FieldSetEntity fse = null; + Object bean = request.getAttribute(CoreConst.API_POST_REQUEST_DATA); + RequestParameterEntity rpe = (RequestParameterEntity) bean; + if (null != rpe && null != rpe.getFormData()) { + fse = rpe.getFormData(); + } + if (fse == null) { + SpringMVCContextHolder.getSystemLogger().error(CmnCode.SYSTEM_FORM_NODATA.getValue(), CmnCode.SYSTEM_FORM_NODATA.getText()); + return this.error(CmnCode.SYSTEM_FORM_NODATA.getValue(), CmnCode.SYSTEM_FORM_NODATA.getText()); + } + JSONObject dataJson = systemDataUpLoadService.analysisTemplate(fse); + return BaseUtil.success(dataJson); + } catch (BaseException e) { + SpringMVCContextHolder.getSystemLogger().error(e); + e.printStackTrace(); + return error(e.getCode(), e.getMessage()); + } catch (Exception e) { + SpringMVCContextHolder.getSystemLogger().error(e); + e.printStackTrace(); + return error(CmnCode.UPLOAD_TEMPLATE_GET_INFO_FAIL.getValue(), CmnCode.UPLOAD_TEMPLATE_GET_INFO_FAIL.getText()); + } + } + + /** + * 涓婁紶妯℃澘鏂板 + * + * @param request + * @return + * @throws BaseException + */ + @RequestMapping(value = "/save-template/{version}", method = RequestMethod.POST) + @ApiVersion(1) + public String saveTemplate(HttpServletRequest request) { + try { + FieldSetEntity fse = null; + Object bean = request.getAttribute(CoreConst.API_POST_REQUEST_DATA); + RequestParameterEntity rpe = (RequestParameterEntity) bean; + if (null != rpe && null != rpe.getFormData()) { + fse = rpe.getFormData(); + } + if (fse == null) { + SpringMVCContextHolder.getSystemLogger().error(CmnCode.SYSTEM_FORM_NODATA.getValue(), CmnCode.SYSTEM_FORM_NODATA.getText()); + return this.error(CmnCode.SYSTEM_FORM_NODATA.getValue(), CmnCode.SYSTEM_FORM_NODATA.getText()); + } + ISystemDataUpLoadService iSystemDataUpLoadService = (ISystemDataUpLoadService) getProxyInstance(systemDataUpLoadService); + iSystemDataUpLoadService.saveTemplate(fse); + return OK(); + } catch (BaseException e) { + SpringMVCContextHolder.getSystemLogger().error(e); + e.printStackTrace(); + return error(e.getCode(), e.getMessage()); + } catch (Exception e) { + SpringMVCContextHolder.getSystemLogger().error(e); + e.printStackTrace(); + return error(CmnCode.UPLOAD_TEMPLATE_SAVE_FAIL.getValue(), CmnCode.UPLOAD_TEMPLATE_SAVE_FAIL.getText()); + } + } + + @PostMapping("/get-prompt/{version}") + @ApiVersion(1) + public String getPromptList() { + try { + return BaseUtil.success(systemDataUpLoadService.getPrompt()); + } catch (BaseException e) { + return this.error(e.getCode(), e.getMessageInfo()); + } catch (Exception e) { + return error(CmnCode.GET_EXPORT_PROMPT_LIST_FINAL.getValue(), CmnCode.GET_EXPORT_PROMPT_LIST_FINAL.getText()); + } + } + + /** + * 妯℃澘鍙拌处-宸﹁竟鏍戠粨鏋� + * + * @return 缁撴灉 + */ + @RequestMapping(value = "/list-template/{version}", method = RequestMethod.POST) + @ApiVersion(1) + public String listTemplate(HttpServletRequest request) { + try { + FieldSetEntity fse = null; + Object bean = request.getAttribute("requestPara"); + if (bean != null) { + RequestParameterEntity reqp = (RequestParameterEntity) bean; + fse = reqp.getFormData(); + } + if (bean == null || fse == null) { + SpringMVCContextHolder.getSystemLogger().error(CmnCode.SYSTEM_FORM_NODATA.getValue(), CmnCode.SYSTEM_FORM_NODATA.getText()); + return this.error(CmnCode.SYSTEM_FORM_NODATA.getValue(), CmnCode.SYSTEM_FORM_NODATA.getText()); + } + if (StringUtils.isEmpty(fse.getTableName()) || !CmnConst.TABLE_PRODUCT_SYS_DATA_UPLOAD_MODEL.equals(fse.getTableName())) { + SpringMVCContextHolder.getSystemLogger().error(CmnCode.SYSTEM_TABLE_NODATA.getValue(), CmnCode.SYSTEM_TABLE_NODATA.getText()); + return this.error(CmnCode.SYSTEM_TABLE_NODATA.getValue(), CmnCode.SYSTEM_TABLE_NODATA.getText()); + } + return OK_List(systemDataUpLoadService.listTemplate(fse)); + } catch (BaseException e) { + SpringMVCContextHolder.getSystemLogger().error(e); + return this.error(e.getCode(), e.getMessageInfo()); + } catch (Exception e) { + SpringMVCContextHolder.getSystemLogger().error(e); + logger.error("", e); + return error(CmnCode.UPLOAD_TEMPLATE_GET_LIST_FAIL.getValue(), CmnCode.UPLOAD_TEMPLATE_GET_LIST_FAIL.getText()); + } + } + + /** + * 鏌ヨ妯℃澘璇︽儏 + * + * @param request + * @return + * @throws BaseException + */ + @RequestMapping(value = "/find-template/{version}", method = RequestMethod.POST) + @ApiVersion(1) + public String findTemplate(HttpServletRequest request) { + try { + FieldSetEntity fse = null; + Object bean = request.getAttribute(CoreConst.API_POST_REQUEST_DATA); + RequestParameterEntity rpe = (RequestParameterEntity) bean; + if (null != rpe && null != rpe.getFormData()) { + fse = rpe.getFormData(); + } + if (fse == null) { + SpringMVCContextHolder.getSystemLogger().error(CmnCode.SYSTEM_FORM_NODATA.getValue(), CmnCode.SYSTEM_FORM_NODATA.getText()); + return this.error(CmnCode.SYSTEM_FORM_NODATA.getValue(), CmnCode.SYSTEM_FORM_NODATA.getText()); + } + return OK_List(systemDataUpLoadService.findTemplate(fse)); + } catch (BaseException e) { + SpringMVCContextHolder.getSystemLogger().error(e); + e.printStackTrace(); + return error(e.getCode(), e.getMessage()); + } catch (Exception e) { + SpringMVCContextHolder.getSystemLogger().error(e); + e.printStackTrace(); + return error(CmnCode.UPLOAD_TEMPLATE_FIND_FAIL.getValue(), CmnCode.UPLOAD_TEMPLATE_FIND_FAIL.getText()); + } + } + + /** + * 鏁版嵁涓婁紶妯℃澘鍒犻櫎鎺ュ彛 + * + * @param request + * @return + */ + @RequestMapping(value = "/delete-template/{version}", method = RequestMethod.POST) + @ApiVersion(1) + public String deleteDataModel(HttpServletRequest request) { + try { + //鑾峰彇浼犲弬鏁版嵁 + FieldSetEntity fse = null; + Object bean = request.getAttribute("requestPara"); + if (bean != null) { + RequestParameterEntity reqp = (RequestParameterEntity) bean; + fse = reqp.getFormData(); + } + if (bean == null || fse == null) { + SpringMVCContextHolder.getSystemLogger().error(CmnCode.SYSTEM_FORM_NODATA.getValue(), CmnCode.SYSTEM_FORM_NODATA.getText()); + return this.error(CmnCode.SYSTEM_FORM_NODATA.getValue(), CmnCode.SYSTEM_FORM_NODATA.getText()); + } + if (StringUtils.isEmpty(fse.getTableName()) || !CmnConst.TABLE_PRODUCT_SYS_DATA_UPLOAD_MODEL.equals(fse.getTableName())) { + SpringMVCContextHolder.getSystemLogger().error(CmnCode.SYSTEM_TABLE_NODATA.getValue(), CmnCode.SYSTEM_TABLE_NODATA.getText()); + return this.error(CmnCode.SYSTEM_TABLE_NODATA.getValue(), CmnCode.SYSTEM_TABLE_NODATA.getText()); + } + ISystemDataUpLoadService iSystemDataUpLoadService = (ISystemDataUpLoadService) getProxyInstance(systemDataUpLoadService); + iSystemDataUpLoadService.deleteModel(fse); + return OK(); + } catch (BaseException e) { + SpringMVCContextHolder.getSystemLogger().error(e); + return this.error(e.getCode(), e.getMessageInfo()); + } catch (Exception e) { + SpringMVCContextHolder.getSystemLogger().error(e); + logger.error("", e); + return error(CmnCode.UPLOAD_TEMPLATE_DELETE_FAIL.getValue(), CmnCode.UPLOAD_TEMPLATE_DELETE_FAIL.getText()); + } + } + + /** + * 妯℃澘涓嬭浇 + * + * @param request + * @return + * @throws BaseException + */ + @RequestMapping(value = "/download-template/{version}", method = RequestMethod.POST) + @ApiVersion(1) + public String downloadTemplate(HttpServletRequest request, HttpServletResponse response) { + try { + FieldSetEntity fse = null; + Object bean = request.getAttribute(CoreConst.API_POST_REQUEST_DATA); + RequestParameterEntity rpe = (RequestParameterEntity) bean; + if (null != rpe && null != rpe.getFormData()) { + fse = rpe.getFormData(); + } + if (fse == null) { + SpringMVCContextHolder.getSystemLogger().error(CmnCode.SYSTEM_FORM_NODATA.getValue(), CmnCode.SYSTEM_FORM_NODATA.getText()); + return this.error(CmnCode.SYSTEM_FORM_NODATA.getValue(), CmnCode.SYSTEM_FORM_NODATA.getText()); + } + systemDataUpLoadService.downloadTemplate(fse, response); + return OK(); + } catch (BaseException e) { + SpringMVCContextHolder.getSystemLogger().error(e); + e.printStackTrace(); + return error(e.getCode(), e.getMessage()); + } catch (Exception e) { + SpringMVCContextHolder.getSystemLogger().error(e); + e.printStackTrace(); + return error(CmnCode.UPLOAD_TEMPLATE_DOWNLOAD_FAIL.getValue(), CmnCode.UPLOAD_TEMPLATE_DOWNLOAD_FAIL.getText()); + } + } + + /** + * 涓氬姟鍔熻兘瀵煎叆-涓婁紶鏂囦欢 + * + * @param request + * @return + * @throws IOException + * @throws BaseException + */ + @RequestMapping(value = "/record-data-import/{version}", method = RequestMethod.POST) + @ApiVersion(1) + public String recordDataImport(HttpServletRequest request) { + try { + FieldSetEntity fse = null; + Object bean = request.getAttribute(CoreConst.API_POST_REQUEST_DATA); + RequestParameterEntity rpe = (RequestParameterEntity) bean; + if (null != rpe && null != rpe.getFormData()) { + fse = rpe.getFormData(); + } + if (fse == null) { + SpringMVCContextHolder.getSystemLogger().error(CmnCode.SYSTEM_FORM_NODATA.getValue(), CmnCode.SYSTEM_FORM_NODATA.getText()); + return this.error(CmnCode.SYSTEM_FORM_NODATA.getValue(), CmnCode.SYSTEM_FORM_NODATA.getText()); + } + if (StringUtils.isEmpty(fse.getTableName()) || !CmnConst.TABLE_PRODUCT_SYS_DATA_UPLOAD_RECORD.equals(fse.getTableName())) { + SpringMVCContextHolder.getSystemLogger().error(CmnCode.SYSTEM_TABLE_NODATA.getValue(), CmnCode.SYSTEM_TABLE_NODATA.getText()); + return this.error(CmnCode.SYSTEM_TABLE_NODATA.getValue(), CmnCode.SYSTEM_TABLE_NODATA.getText()); + } + ISystemDataUpLoadService iSystemDataUpLoadService = (ISystemDataUpLoadService) getProxyInstance(systemDataUpLoadService); + String uuid = iSystemDataUpLoadService.recordDataImport(rpe); + return OK_Add(uuid); + } catch (BaseException e) { + SpringMVCContextHolder.getSystemLogger().error(e); + e.printStackTrace(); + return error(e.getCode(), e.getMessage()); + } catch (Exception e) { + SpringMVCContextHolder.getSystemLogger().error(e); + e.printStackTrace(); + return error(CmnCode.UPLOAD_TEMPLATE_RECORD_DATA_IMPORT_FILE_FAIL.getValue(), CmnCode.UPLOAD_TEMPLATE_RECORD_DATA_IMPORT_FILE_FAIL.getText()); + } + } + + /** + * 涓氬姟鍔熻兘瀵煎叆-瑙f瀽骞朵繚瀛樺埌鏁版嵁搴� + * + * @param request + * @return + * @throws IOException + * @throws BaseException + */ + @RequestMapping(value = "/record-data-save/{version}", method = RequestMethod.POST) + @ApiVersion(1) + public String recordDataSave(HttpServletRequest request) { + try { + FieldSetEntity fse = null; + Object bean = request.getAttribute(CoreConst.API_POST_REQUEST_DATA); + RequestParameterEntity rpe = (RequestParameterEntity) bean; + if (null != rpe && null != rpe.getFormData()) { + fse = rpe.getFormData(); + } + if (fse == null) { + SpringMVCContextHolder.getSystemLogger().error(CmnCode.SYSTEM_FORM_NODATA.getValue(), CmnCode.SYSTEM_FORM_NODATA.getText()); + return this.error(CmnCode.SYSTEM_FORM_NODATA.getValue(), CmnCode.SYSTEM_FORM_NODATA.getText()); + } + if (StringUtils.isEmpty(fse.getTableName()) || !CmnConst.TABLE_PRODUCT_SYS_DATA_UPLOAD_RECORD.equals(fse.getTableName())) { + SpringMVCContextHolder.getSystemLogger().error(CmnCode.SYSTEM_TABLE_NODATA.getValue(), CmnCode.SYSTEM_TABLE_NODATA.getText()); + return this.error(CmnCode.SYSTEM_TABLE_NODATA.getValue(), CmnCode.SYSTEM_TABLE_NODATA.getText()); + } + ISystemDataUpLoadService iSystemDataUpLoadService = (ISystemDataUpLoadService) getProxyInstance(systemDataUpLoadService); + iSystemDataUpLoadService.recordDataSave(fse); + return OK(); + } catch (BaseException e) { + SpringMVCContextHolder.getSystemLogger().error(e); + e.printStackTrace(); + return error(e.getCode(), e.getMessage()); + } catch (Exception e) { + SpringMVCContextHolder.getSystemLogger().error(e); + e.printStackTrace(); + return error(CmnCode.UPLOAD_TEMPLATE_RECORD_DATA_IMPORT_FILE_FAIL.getValue(), CmnCode.UPLOAD_TEMPLATE_RECORD_DATA_IMPORT_FILE_FAIL.getText()); + } + } +} diff --git a/product-server-data-export-import/src/main/java/com/product/module/data/service/OrganizationImportService.java b/product-server-data-export-import/src/main/java/com/product/module/data/service/OrganizationImportService.java new file mode 100644 index 0000000..5e30c98 --- /dev/null +++ b/product-server-data-export-import/src/main/java/com/product/module/data/service/OrganizationImportService.java @@ -0,0 +1,1824 @@ +package com.product.module.data.service; + +import com.google.common.collect.Sets; +import com.google.common.collect.Lists; +import com.google.common.collect.Maps; +import com.product.admin.service.UpdateLoginUserInfoService; +import com.product.common.lang.StringUtils; +import com.product.common.utils.IdcardUtils; +import com.product.core.config.Global; +import com.product.core.dao.BaseDao; +import com.product.core.entity.DataTableEntity; +import com.product.core.entity.FieldSetEntity; +import com.product.core.exception.BaseException; +import com.product.core.service.support.AbstractBaseService; +import com.product.core.spring.context.SpringBeanUtil; +import com.product.core.spring.context.SpringMVCContextHolder; +import com.product.module.data.config.CmnCode; +import com.product.module.data.config.CmnConst; +import com.product.module.data.service.idel.IOrganizationImportService; +import com.product.module.sys.entity.SystemUser; +import com.product.org.admin.service.StaffManagerService; +import com.product.util.BaseUtil; +import com.product.util.CallBack; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import java.util.*; + +/** + * @ClassName OrganizationImportService + * @Description 缁勭粐鏈烘瀯瀵煎叆鏁版嵁澶勭悊 + * @Author cheng + * @Date 2021/12/2 16:14 + */ +@Service +public class OrganizationImportService extends AbstractBaseService implements IOrganizationImportService { + + + @Autowired + StaffManagerService staffManagerService; + + private final String companyLevelSeparator = ">"; + + /** + * 瀵煎叆鍏徃 涔嬪墠 鏁版嵁澶勭悊 + * + * @param dt + * @throws BaseException + */ + @Override + public DataTableEntity importCompanyBefore(DataTableEntity dt) throws BaseException { + ImportErrorEntity errorEntity = new ImportErrorEntity(); + try { + + SystemUser currentUser = SpringMVCContextHolder.getCurrentUser(); + //绠$悊鍛樻潈闄愰獙璇� + managerPermissionValidation(errorEntity, currentUser); + FieldSetEntity managerFieldSet = currentUser.getCurrentManager(); + String managerCompany = managerFieldSet.getString(CmnConst.ORG_LEVEL_UUID); + // 褰撳墠绠$悊鍛樼鐞嗙殑鍏徃 + String managerCompanyUuids = currentUser.getCurrentCompany().getString(CmnConst.ORG_LEVEL_UUID); + if (!BaseUtil.dataTableIsEmpty(dt)) { + //鏁版嵁楠岃瘉缁撴灉 + Map<String, String> fieldType = Maps.newHashMap(); + fieldType.put(CmnConst.SEQUENCE, "int"); + errorEntity = fieldRequiredValidation(dt, new String[]{CmnConst.FIELD_ORG_LEVEL_NAME, CmnConst.FIELD_ORG_LEVEL_ALL, CmnConst.SEQUENCE}, null, f -> { + if (f != null && f[0] != null) { + FieldSetEntity fse = f[0]; + //鍏徃鍚嶇О + String companyName = fse.getString(CmnConst.FIELD_ORG_LEVEL_NAME); + //鍏徃鍏ㄧО + String companyAllName = fse.getString(CmnConst.FIELD_ORG_LEVEL_ALL); + //涓婄骇鍏徃鍏ㄧО + String parentAllName = companyAllName.replace(companyLevelSeparator + companyName, ""); + fse.setValue("parentAllName", parentAllName); + } + }); + DataTableEntity systemData = getBaseDao().listTable(CmnConst.TABLE_PRODUCT_SYS_ORG_LEVELS, " org_level_type=0 AND " + + BaseUtil.buildQuestionMarkFilter(CmnConst.ORG_LEVEL_UUID, managerCompanyUuids.split(","), true), new Object[]{}, "org_level_code"); + // 楠岃瘉閲嶅 & 鍚堝苟閿欒淇℃伅 + errorEntity.mergeError(fieldRepeatValidation(dt, systemData, CmnConst.FIELD_ORG_LEVEL_ALL)); + if (errorEntity.isError) { + errorEntity.newThrowBaseException(); + } + List<FieldSetEntity> data = dt.getData(); + data.sort((a, b) -> { + String Aorg_level_all = a.getString(CmnConst.FIELD_ORG_LEVEL_ALL); + String Borg_level_all = b.getString(CmnConst.FIELD_ORG_LEVEL_ALL); + int lengthA = Aorg_level_all != null ? Aorg_level_all.length() : -1; + int lengthB = Borg_level_all != null ? Borg_level_all.length() : -1; + return lengthA - lengthB; + }); + // 鑾峰彇褰撳墠绠$悊绠$悊鍏徃浠ュ強瀛愬叕鍙� + DataTableEntity allCompany = getBaseDao().listTable(CmnConst.TABLE_PRODUCT_SYS_ORG_LEVELS, " org_level_type=0 AND " + + BaseUtil.buildQuestionMarkFilter(CmnConst.ORG_LEVEL_UUID, managerCompanyUuids.split(","), true), new Object[]{}, "org_level_code"); + Map<String, String> levelCode = Maps.newHashMap(); + if (!BaseUtil.dataTableIsEmpty(allCompany)) { + for (int i = 0; i < allCompany.getRows(); i++) { + String org_level_all = allCompany.getString(i, CmnConst.FIELD_ORG_LEVEL_ALL); + String org_level_code = allCompany.getString(i, CmnConst.FIELD_ORG_LEVEL_CODE); + // 灏嗗叕鍙哥紪鐮佺敤鍏ㄧО瀛樺偍 + levelCode.put(org_level_all, org_level_code); + } + } + for (FieldSetEntity fse : data) { + //褰撳墠琛� + Integer rowIndex = fse.getInteger("~row~"); + //鍏徃鍏ㄧО + String companyAllName = fse.getString(CmnConst.FIELD_ORG_LEVEL_ALL); + //涓婄骇缁勭粐鏈烘瀯鍏ㄧО + String parentAllName = fse.getString("parentAllName"); + //涓婄骇鏈烘瀯缂栫爜 + String code = levelCode.get(parentAllName); + if (StringUtils.isEmpty(code)) { + errorEntity.addError(rowIndex, " 鑾峰彇涓婄骇鏈烘瀯缂栫爜閿欒锛岃妫�鏌ュ叕鍙稿悕绉般�佸叏绉版槸鍚︽纭紝閿欒琛屽彿锛�").append(rowIndex + 1); + continue; + } + //鍒濆鍖栧叕鍙告暟鎹� + initOrganizationFieldSet(fse, currentUser.getClient_uuid(), code, 0); + // 灏嗗綋鍓嶅叕鍙哥敓鎴愮殑org_level_code 鏀惧叆map涓� + levelCode.put(companyAllName, fse.getString(CmnConst.FIELD_ORG_LEVEL_CODE)); + String uuid = null; + try { + // 淇濆瓨鍑洪敊鐩存帴璺宠繃璇ユ潯鏁版嵁 + getBaseDao().add(fse); + } catch (Exception e) { + continue; + } + if (null != uuid) { + // 瀵煎叆鏃跺垱寤鸿鍏徃鐨勬暟鎹潈闄� + FieldSetEntity fs = new FieldSetEntity(); + fs.setTableName(CmnConst.TABLE_PRODUCT_SYS_DATA_STRATEGY_MASTER); +// fs.setValue(CmnConst.ORG_LEVEL_UUID, uuid); + fs.setValue("property_uuid", "001"); + fs.setValue("is_used", "1"); + fs.setValue("effective_start_date", new Date()); + fs.setValue(CmnConst.CREATED_BY, currentUser.getUser_id()); + fs.setValue(CmnConst.CREATED_UTC_DATETIME, new Date()); + getBaseDao().add(fs); + } + } + // 鍥炲啓鍒伴殣钘忕鐞嗗憳鎵�绠$悊鐨勫叕鍙� todo group_concat 澶浼氭姤閿� + getBaseDao().executeUpdate("UPDATE product_sys_org_manager SET org_level_uuid =(SELECT group_concat(UUID) FROM product_sys_org_levels WHERE CLIENT_UUID =? AND ORG_LEVEL_TYPE =0) WHERE CLIENTS_UUID=? AND MANAGER_TYPE=? " + , new Object[]{currentUser.getClient_uuid(), currentUser.getClient_uuid(), 3}); + // 鍥炲啓褰撳墠绠$悊鍛樼鐞嗙殑鍏徃 + if (currentUser.getUserType() == 2 && dt.getUuids() != null) { + if (!StringUtils.isEmpty(managerCompany)) { + managerCompany += ","; + } else { + managerCompany = ""; + } + managerCompany += dt.getUuidsToString(); + String manager_uuid = managerFieldSet.getUUID(); + String sql = "update product_sys_org_manager set org_level_uuid=? where uuid=?"; + getBaseDao().executeUpdate(sql, new Object[]{managerCompany, manager_uuid}); + } + //鎶涘嚭閿欒 + if (errorEntity.isError) { + errorEntity.newThrowBaseException(); + } + UpdateLoginUserInfoService loginUserInfoService = SpringBeanUtil.getBean("updateLoginUserInfoService", UpdateLoginUserInfoService.class); + loginUserInfoService.updateUserInfoByUserId(new Object[]{currentUser.getUser_id()}, false); + return dt; + } else { + errorEntity.newThrowBaseException("瀵煎叆鍏徃澶辫触锛屾湭鎻愬彇鍒版暟鎹�"); + } + } catch (BaseException e) { + throw e; + } catch (Exception e) { + e.printStackTrace(); + errorEntity.addError(0, "瀵煎叆鍏徃澶辫触锛屾湭鐭ラ敊璇� 锛�" + e.getMessage()); + errorEntity.newThrowBaseException(); + } + return null; + } + + /** + * 瀛楁閲嶅楠岃瘉 + * + * @param errorEntity + * @param importData 瀵煎叆鏁版嵁 + * @param systemData 绯荤粺鏁版嵁 锛堝彲閫夛級 + * @param fieldNames 瀛楁鍚嶇О + * @return + * @throws BaseException + */ + protected ImportErrorEntity fieldRepeatValidation(ImportErrorEntity errorEntity, DataTableEntity importData, DataTableEntity systemData, String[] fieldNames) throws BaseException { + if (fieldNames == null || fieldNames.length <= 0) { + return errorEntity; + } + List<FieldSetEntity> dataList = importData.clones().getData(); + Map<String, Object> valueMap = Maps.newHashMap(); + if (!BaseUtil.dataTableIsEmpty(systemData)) { + for (int i = 0; i < systemData.getRows(); i++) { + for (String field : fieldNames) { + String value = systemData.getString(i, field); + if (!StringUtils.isEmpty(value)) { + valueMap.put(field + this.companyLevelSeparator + value, Boolean.FALSE); + } + } + } + } + fieldRepeatValidation(errorEntity, dataList, valueMap, fieldNames); + return errorEntity; + } + + /** + * 瀛楁閲嶅楠岃瘉 + * + * @param dataList 瀵煎叆鏁版嵁 + * @param valueMap + * @param fieldNames 瀛楁鍚嶇О + * @throws BaseException + */ + protected void fieldRepeatValidation(ImportErrorEntity errorEntity, List<FieldSetEntity> dataList, Map<String, Object> valueMap, String[] fieldNames) throws BaseException { + + for (FieldSetEntity fse : dataList) { + DataLocation dataLocation = getDataLocation(fse); + for (String fieldName : fieldNames) { + String value = fse.getString(fieldName); + if (!StringUtils.isEmpty(value)) { + if (valueMap.get(fieldName + this.companyLevelSeparator + value) != null) { + Object val = valueMap.get(fieldName + this.companyLevelSeparator + value); + if (val != null) { + String error; + if (val instanceof Boolean) { + // 绯荤粺涓瓨鍦� + // 绗� N 琛岋紝绗� N 鍒楋紝'琛ㄥご鍚嶇О' ('鏁版嵁鍊�') 鏁版嵁閲嶅锛屽湪绯荤粺涓凡瀛樺湪 + error = "绗� %s 琛岋紝绗� %s 鍒� '%s', 鏁版嵁閲嶅锛屽湪绯荤粺涓凡瀛樺湪"; + error = String.format(error, dataLocation.getRowIndex(), dataLocation.getColIndex(fieldName), dataLocation.getColName(fieldName), value); + } else { + FieldSetEntity fs = (FieldSetEntity) val; + DataLocation historyLocation = getDataLocation(fs); + // 绗琋琛岋紝绗� N鍒楋紝'琛ㄥご鍚嶇О' ('鏁版嵁鍊�') 鏁版嵁鍜岀 %s 琛岋紝绗琋琛岋紝绗� N鍒楋紝'琛ㄥご鍚嶇О' ('鏁版嵁鍊�') 鏁版嵁閲嶅 + error = "绗� %s 琛岋紝绗� %s 鍒� '%s', 鏁版嵁鍜岀 %s 琛岋紝绗� %s 鍒� '%s' ,鏁版嵁閲嶅"; + error = String.format(error, dataLocation.getRowIndex(), dataLocation.getColIndex(fieldName), dataLocation.getColName(fieldName), value, + historyLocation.getRowIndex(), historyLocation.getColIndex(fieldName), historyLocation.getColName(fieldName), value); + } + errorEntity.addError(dataLocation.getRowIndex(), error); + } + } else { + valueMap.put(fieldName + this.companyLevelSeparator + value, fse); + } + } + } + } + } + + /** + * 瀛楁閲嶅楠岃瘉 + * + * @param importData 瀵煎叆鏁版嵁 + * @param systemData 绯荤粺鏁版嵁 锛堝彲閫夛級 + * @param fieldName 瀛楁鍚嶇О + * @return + * @throws BaseException + */ + protected ImportErrorEntity fieldRepeatValidation(DataTableEntity importData, DataTableEntity + systemData, String fieldName) throws BaseException { + return fieldRepeatValidation(new ImportErrorEntity(), importData, systemData, new String[]{fieldName}); + } + + /** + * 瀛楁蹇呭~楠岃瘉 + * + * @param dt + * @return + * @throws BaseException + */ + protected ImportErrorEntity fieldRequiredValidation(DataTableEntity dt, String[] + fieldNames, Map<String, String> fieldType, CallBack<FieldSetEntity> callBack) throws BaseException { + ImportErrorEntity errorEntity = new ImportErrorEntity(); + for (int i = 0; i < dt.getRows(); i++) { + FieldSetEntity fieldSetEntity = dt.getFieldSetEntity(i); + if (callBack != null) { + callBack.method(fieldSetEntity); + } + fieldRequiredValidation(errorEntity, fieldSetEntity, fieldNames, fieldType); + } + + return errorEntity; + } + + /** + * 瀛楁绫诲瀷楠岃瘉 + * 鐩墠鏀寔 int double dateTime + * + * @param errorEntity + * @param fse + * @param fieldTypeMap + * @return + * @throws BaseException + */ + protected boolean fieldTypeValidation(ImportErrorEntity errorEntity, FieldSetEntity + fse, Map<String, String> fieldTypeMap) throws BaseException { + boolean flag = true; + if (fieldTypeMap != null && fieldTypeMap.size() > 0 && fse != null) { + for (Map.Entry<String, String> v : fieldTypeMap.entrySet()) { + String fieldType = v.getValue(); + String key = v.getKey(); + Object value = fse.getObject(key); + if (value == null) { + continue; + } + String type = null; + String msg = ""; + try { + switch (fieldType) { + case "int": + type = "鏁存暟"; + fse.getInteger(key); + continue; + case "dateTime": + type = "鏃ユ湡"; + Date date = fse.getDate(key); + fse.setValue(key, date); + continue; + case "double": + type = "灏忔暟"; + fse.getDouble(key); + continue; + case "mobile_phone": + type = "绉诲姩鐢佃瘽"; + String phone = fse.getString(key); + // 楠岃瘉鏄惁涓轰腑鍥藉ぇ闄� 鎵嬫満鍙� + if (!BaseUtil.isChinaPhoneLegal(phone)) { + throw new BaseException("", ""); + } + continue; + case "id_card": + type = "韬唤璇佸彿鐮�"; + String idCard = fse.getString(key); + // 楠岃瘉韬唤璇佸彿鐮佹槸鍚﹀悎娉� + if (IdcardUtils.validateCard(idCard)) { + msg = BaseUtil.idCardVerification(idCard); + throw new BaseException("", ""); + } + continue; + case "email": + type = "閭"; + String email = fse.getString(key); + // 閭楠岃瘉 + if (!BaseUtil.isEmail(email)) { + throw new BaseException("", ""); + } + continue; + case "sex": + type = "鎬у埆"; + String sex = fse.getString(key); + // 閭楠岃瘉 + if (!"鐢�".equals(sex) && !"濂�".equals(sex)) { + throw new BaseException("", ""); + } + continue; + default: + } + } catch (BaseException e) { + DataLocation dataLocation = getDataLocation(fse); + String error = "绗� %s 琛岋紝绗� %s 鍒楋紝鏁版嵁绫诲瀷閿欒" + (type != null ? "锛岃杈撳叆姝g‘鐨� '%s'鍊�" : ""); + if (type != null) { + error = String.format(error, dataLocation.getRowIndex(), dataLocation.getColIndex(key), type); + } else { + error = String.format(error, dataLocation.getRowIndex(), dataLocation.getColIndex(key)); + } + if (!StringUtils.isEmpty(msg)) { + error += "," + msg; + } + errorEntity.addError(dataLocation.getRowIndex(), error); + flag = false; + } + } + } + + return flag; + } + + + /** + * 瀛楁蹇呭~楠岃瘉 + * + * @param fse + * @return + * @throws BaseException + */ + private boolean fieldRequiredValidation(ImportErrorEntity errorEntity, FieldSetEntity fse, String[] + fieldNames, Map<String, String> fieldType) throws BaseException { + if (fse == null || fieldNames == null || fieldNames.length <= 0) { + return true; + } + DataLocation dataLocation = getDataLocation(fse); + boolean flag = true; + for (String fieldName : fieldNames) { + if (!StringUtils.isEmpty(fieldName)) { + String value = fse.getString(fieldName); + if (StringUtils.isEmpty(value)) { + String error = "绗� %s 琛岋紝绗� %s 鍒� '%s', 涓嶈兘涓虹┖"; + Integer rowIndex = dataLocation.getRowIndex(); + String colIndex = dataLocation.getColIndex(fieldName); + String colName = dataLocation.getColName(fieldName); + error = String.format(error, rowIndex, colIndex, colName); + errorEntity.addError(rowIndex, error); + flag = false; + } + } + } + if (flag) { + return fieldTypeValidation(errorEntity, fse, fieldType); + } else { + fieldTypeValidation(errorEntity, fse, fieldType); + return false; + } + } + + /** + * 瀵煎叆閮ㄩ棬 涔嬪墠 鏁版嵁澶勭悊 + * + * @param dt + * @throws BaseException + */ + @Override + public DataTableEntity importDeptBefore(DataTableEntity dt) throws BaseException { + ImportErrorEntity errorEntity = new ImportErrorEntity(); + if (!BaseUtil.dataTableIsEmpty(dt)) { + try { + SystemUser currentUser = SpringMVCContextHolder.getCurrentUser(); + //绠$悊鍛樻潈闄愰獙璇� + managerPermissionValidation(errorEntity, currentUser); + + Map<String, String> fieldType = Maps.newHashMap(); + fieldType.put(CmnConst.SEQUENCE, "int"); + //鏁版嵁蹇呭~楠岃瘉缁撴灉 + errorEntity = fieldRequiredValidation(dt, new String[]{CmnConst.FIELD_ORG_LEVEL_NAME, CmnConst.FIELD_ORG_LEVEL_ALL, CmnConst.SEQUENCE, CmnConst.ORG_LEVEL_UUID}, fieldType, null); + if (errorEntity.isError) { + errorEntity.newThrowBaseException(); + } + FieldSetEntity currentManager = currentUser.getCurrentManager(); + String managerCompanyUuids = currentManager.getString(CmnConst.ORG_LEVEL_UUID); + String uuidFilter = BaseUtil.buildQuestionMarkFilter("uuid", managerCompanyUuids.split(","), true); + StringBuilder sql = new StringBuilder(8); + sql.append(" select uuid,org_level_name,org_level_code, "); + sql.append(" org_level_code_parent,org_level_all,org_level_type "); + sql.append(" FROM product_sys_org_levels where client_uuid=? and ( "); + sql.append(" ( "); + sql.append(" ").append(uuidFilter); + sql.append(" AND org_level_type=0 ) "); + sql.append(" or ( "); + sql.append(" ").append(uuidFilter.replace("uuid", "org_level_uuid")); + sql.append(" AND org_level_type=1 ) "); + sql.append(" ) order by org_level_code,org_level_type"); + // 绯荤粺鏁版嵁 + DataTableEntity systemData = getBaseDao().listTable(sql.toString(), new Object[]{currentUser.getClient_uuid()}); + importDeptBefore(dt, systemData, currentUser, errorEntity); + return dt; + } catch (BaseException e) { + e.printStackTrace(); + throw e; + } catch (Exception e) { + e.printStackTrace(); + errorEntity.addError(0, "瀵煎叆閮ㄩ棬澶辫触锛屾湭鐭ラ敊璇� 锛�" + e.getMessage()); + errorEntity.newThrowBaseException(); + } + } + errorEntity.newThrowBaseException("瀵煎叆鍏徃澶辫触锛屾湭鎻愬彇鍒版暟鎹�"); + return null; + } + + private void importDeptBefore(DataTableEntity dt, DataTableEntity systemData, SystemUser + user, ImportErrorEntity errorEntity) throws BaseException { + List<FieldSetEntity> data = dt.getData(); + // 鏈烘瀯鍏ㄧО鎺掑簭 + data.sort(Comparator.comparing(a -> a.getString(CmnConst.FIELD_ORG_LEVEL_ALL))); + if (BaseUtil.dataTableIsEmpty(systemData)) { + errorEntity.newThrowBaseException("鑾峰彇绯荤粺鏈烘瀯淇℃伅澶辫触锛岃鑱旂郴绠$悊鍛� "); + } + List<FieldSetEntity> systemDataList = systemData.getData(); + // 鍏徃 + Map<String, FieldSetEntity> companyMap = Maps.newHashMap(); + // 閮ㄩ棬 + Map<String, FieldSetEntity> deptMap = Maps.newHashMap(); + for (FieldSetEntity fse : systemDataList) { + // 鏈烘瀯绫诲瀷 + String orgLevelType = fse.getString(CmnConst.FIELD_ORG_LEVEL_TYPE); + // 鏈烘瀯鍏ㄧО + String org_level_all = fse.getString(CmnConst.FIELD_ORG_LEVEL_ALL); + Map<String, FieldSetEntity> map; + if ("0".equals(orgLevelType)) { + map = companyMap; + } else if ("1".equals(org_level_all)) { + map = deptMap; + } else { + continue; + } + map.put(org_level_all, fse); + } + for (int i = 0; i < dt.getRows(); i++) { + FieldSetEntity fse = dt.getFieldSetEntity(i); + // 鍏徃鍏ㄧО + String companyAllName = fse.getString(CmnConst.ORG_LEVEL_UUID); + // 閮ㄩ棬鍏ㄧО + String deptAllName = fse.getString(CmnConst.FIELD_ORG_LEVEL_ALL); + // 閮ㄩ棬鍚嶇О + String deptName = fse.getString(CmnConst.FIELD_ORG_LEVEL_NAME); + + DataLocation dataLocation = getDataLocation(fse); + FieldSetEntity companyFse = companyMap.get(companyAllName); + if (companyFse == null || StringUtils.isEmpty(companyFse.getUUID())) { + String error = "绗� %s 琛岋紝涓婄骇鏈烘瀯鑾峰彇澶辫触锛屾墍灞炲叕鍙镐笉瀛樺湪锛岃妫�鏌�' %s '鏄惁姝g‘锛�' %s '"; + error = String.format(error, dataLocation.getRowIndex(), dataLocation.getColName(CmnConst.ORG_LEVEL_UUID), companyAllName); + errorEntity.addError(dataLocation.getRowIndex(), error); + continue; + } + String error = "绗� %s 琛岋紝涓婄骇鏈烘瀯鑾峰彇澶辫触锛屼笂绾ч儴闂ㄤ笉瀛樺湪锛岃妫�鏌�' %s '鏄惁姝g‘锛�' %s '"; + // 閮ㄩ棬涓婄骇鍏ㄧО + String parentDeptAllName = getParentAllName(deptAllName, deptName); + if (StringUtils.isEmpty(parentDeptAllName)) { + error = String.format(error, dataLocation.getRowIndex(), dataLocation.getColName(CmnConst.FIELD_ORG_LEVEL_ALL), deptAllName); + errorEntity.addError(dataLocation.getRowIndex(), error); + continue; + } + // 涓婄骇缂栫爜 + String code; + // 涓婄骇鏈烘瀯鐨剈uid + String parentUuid; + if (!parentDeptAllName.equals(companyAllName)) { + FieldSetEntity deptFse = deptMap.get(parentDeptAllName); + if (deptFse == null || StringUtils.isEmpty(deptFse.getUUID())) { + error = String.format(error, dataLocation.getRowIndex(), dataLocation.getColName(CmnConst.FIELD_ORG_LEVEL_ALL), deptAllName); + errorEntity.addError(dataLocation.getRowIndex(), error); + continue; + } + // 鍙栧嚭涓婄骇閮ㄩ棬鐨刢ode浣滀负涓婄骇缂栫爜 + code = deptFse.getString(CmnConst.FIELD_ORG_LEVEL_CODE); + + parentUuid = deptFse.getString(CmnConst.ORG_LEVEL_UUID); + } else { + // 鍙栧嚭涓婄骇鍏徃鐨刢ode浣滀负涓婄骇缂栫爜 + code = companyFse.getString(CmnConst.FIELD_ORG_LEVEL_CODE); + parentUuid = companyFse.getUUID(); + } + initOrganizationFieldSet(fse, user.getClient_uuid(), code, 1); + fse.setValue(CmnConst.ORG_LEVEL_UUID, parentUuid); + getBaseDao().saveFieldSetEntity(fse); + deptMap.put(deptAllName, fse); + } + if (errorEntity.isError) { + errorEntity.newThrowBaseException(); + } + } + + private String getParentAllName(String allName, String name) { + if (!StringUtils.isEmpty(allName) && !StringUtils.isEmpty(name)) { + int index = allName.indexOf(this.companyLevelSeparator + name); + if (index > -1) { + return allName.substring(0, index); + } + } + return ""; + } + + /** + * 瀵煎叆宀椾綅绛夌骇 涔嬪墠 鏁版嵁澶勭悊 + * + * @param dt + * @throws BaseException + */ + @Override + public DataTableEntity importPostLevelBefore(DataTableEntity dt) throws BaseException { + ImportErrorEntity errorEntity = new ImportErrorEntity(); + try { + if (!BaseUtil.dataTableIsEmpty(dt)) { + SystemUser currentUser = SpringMVCContextHolder.getCurrentUser(); + //绠$悊鍛樻潈闄愰獙璇� + managerPermissionValidation(errorEntity, currentUser); + // 褰撳墠绠$悊鍛樼鐞嗙殑鍏徃 + String managerCompanyUuids = currentUser.getCurrentManager().getString(CmnConst.ORG_LEVEL_UUID); + Map<String, List<FieldSetEntity>> groupCompany = Maps.newHashMap(); + Map<String, String> fieldType = Maps.newHashMap(); + fieldType.put(CmnConst.SEQUENCE, "int"); + fieldType.put(CmnConst.FIELD_JOB_GRADE_CLASS, "int"); + StringBuilder sql = new StringBuilder(); + sql.append(" select concat( "); + sql.append(" org_level_uuid,'>',job_grade_name) uuid "); + sql.append(" FROM product_sys_job_post_grades where "); + sql.append(BaseUtil.buildQuestionMarkFilter("org_level_uuid", managerCompanyUuids.split(","), true)); + DataTableEntity systemData = getBaseDao().listTable(sql.toString(), new Object[]{}); + Set<Object> systemDataSet = Sets.newHashSet(); + if (!BaseUtil.dataTableIsEmpty(systemData)) { + systemDataSet.addAll(Arrays.asList(systemData.getUuidsToString().split(","))); + } + for (int i = 0; i < dt.getRows(); i++) { + FieldSetEntity fse = dt.getFieldSetEntity(i); + // 瀛楁蹇呭~楠岃瘉 + boolean validation = fieldRequiredValidation(errorEntity, fse, new String[]{CmnConst.ORG_LEVEL_UUID, CmnConst.FIELD_JOB_GRADE_NAME, CmnConst.SEQUENCE, CmnConst.FIELD_JOB_GRADE_CLASS}, fieldType); + if (!validation) { + // 楠岃瘉鏈�氳繃 璺宠繃璇ユ潯鏁版嵁 + continue; + } + // 鍏徃鍏ㄧО + String companyAllName = fse.getString(CmnConst.ORG_LEVEL_UUID); + + List<FieldSetEntity> groupPostGradeList = groupCompany.get(companyAllName); + if (groupPostGradeList == null) { + groupPostGradeList = Lists.newArrayList(); + groupCompany.put(companyAllName, groupPostGradeList); + } + groupPostGradeList.add(fse); + } + if (errorEntity.isError) { + errorEntity.newThrowBaseException(); + } + Set<String> companyAllNames = groupCompany.keySet(); + sql = new StringBuilder(); + sql.append(" select uuid,org_level_all "); + sql.append(" FROM product_sys_org_levels "); + sql.append(" where "); + sql.append(BaseUtil.buildQuestionMarkFilter("uuid", managerCompanyUuids.split(","), true)); + sql.append(" AND "); + sql.append(BaseUtil.buildQuestionMarkFilter("org_level_all", companyAllNames.toArray(), true)); + // 鏍规嵁鐢ㄦ埛涓婁紶鐨勫叕鍙稿叏绉� & 璇ョ鐞嗗憳绠$悊鐨勬墍鏈夊叕鍙� 杩涜鏌ヨ鍏徃鐨剈uid + DataTableEntity companyInfo = getBaseDao().listTable(sql.toString(), new Object[]{}); + // 瀹氫箟娌℃湁鎵惧埌鍏徃鐨勬暟鎹� 鍐欏叆閿欒鏂规硶 + CallBack<FieldSetEntity> callBack = (value) -> { + for (FieldSetEntity fs : value) { + DataLocation dataLocation = getDataLocation(fs); + String error = "绗� %s 琛岋紝绗� %s 鏁版嵁閿欒,鎵�灞炲叕鍙镐笉瀛樺湪锛岃妫�鏌ュ垪 '%s'"; + errorEntity.addError(dataLocation.getRowIndex(), String.format(error, + dataLocation.getRowIndex(), + dataLocation.getColIndex(CmnConst.ORG_LEVEL_UUID), + dataLocation.getColName(CmnConst.ORG_LEVEL_UUID))); + } + }; + // 娌℃湁鏌ヨ鍒版墍鏈夊叕鍙镐俊鎭� + if (BaseUtil.dataTableIsEmpty(companyInfo)) { + for (List<FieldSetEntity> value : groupCompany.values()) { + // 寰幆鍐欏叆閿欒 + callBack.method(value.toArray(new FieldSetEntity[]{})); + } + errorEntity.newThrowBaseException(); + } else { + // copy 鍏徃鍏ㄧО + Set<String> companyNames = Sets.newHashSet(); + companyNames.addAll(companyAllNames); + // 寰幆鏌ヨ鐨勫叕鍙哥粨鏋� + for (int i = 0; i < companyInfo.getRows(); i++) { + String uuid = companyInfo.getString(i, CmnConst.UUID); + String org_level_all = companyInfo.getString(i, CmnConst.FIELD_ORG_LEVEL_ALL); + if (companyNames.contains(org_level_all)) { + companyNames.remove(org_level_all); + } + List<FieldSetEntity> postGradeList = groupCompany.get(org_level_all); + if (postGradeList != null) { + for (FieldSetEntity fs : postGradeList) { + // 灏嗗叕鍙竨uid鍐欏叆姣忔潯鏁版嵁 + BaseUtil.createCreatorAndCreationTime(currentUser, fs); + fs.setValue(CmnConst.ORG_LEVEL_UUID, uuid); + fs.setValue(CmnConst.IS_USED, 1); + String job_grade_name = fs.getString(CmnConst.FIELD_JOB_GRADE_NAME); +// String group_name = fs.getString(CmnConst.FIELD_GROUP_NAME); + String managerValue = uuid + this.companyLevelSeparator + job_grade_name; + + if (systemDataSet.contains(managerValue)) { + + DataLocation dataLocation = getDataLocation(fs); + String error = "绗� %s 琛岋紝绗� %s 鍒楋紝鏁版嵁閲嶅"; + error = String.format(error, dataLocation.getRowIndex(), dataLocation.getColIndex(CmnConst.FIELD_JOB_GRADE_NAME)); + errorEntity.addError(dataLocation.getRowIndex(), error); + continue; + } + systemDataSet.add(managerValue); + } + if (errorEntity.isError) { + errorEntity.newThrowBaseException(); + } + } + } + // 鍒ゆ柇鏈夋槸鍚︽湁鍏徃娌℃煡璇㈠埌 + if (companyNames != null && companyNames.size() > 0) { + List<FieldSetEntity> postGradeList = Lists.newArrayList(); + for (String companyName : companyNames) { + //灏嗘病鏌ヨ鍒扮殑鍏徃鎵�灞炲矖浣嶇瓑绾у悎骞� + postGradeList.addAll(groupCompany.get(companyName)); + } + if (postGradeList.size() > 0) { + //璋冪敤閿欒缁勮鍥炶皟 + callBack.method(postGradeList.toArray(new FieldSetEntity[]{})); + // 鎶涘嚭閿欒 + errorEntity.newThrowBaseException(); + } + } + // 淇濆瓨鎵�鏈夋暟鎹� + getBaseDao().add(dt); + return dt; + } + } + } catch (Exception e) { + e.printStackTrace(); + + errorEntity.newThrowBaseException("瀵煎叆宀椾綅绛夌骇澶辫触", e); + } + errorEntity.newThrowBaseException("瀵煎叆宀椾綅绛夌骇澶辫触锛屾湭鎻愬彇鍒版暟鎹�"); + return null; + } + + /** + * 瀵煎叆宀椾綅 涔嬪墠 鏁版嵁澶勭悊 + * + * @param dt + * @throws BaseException + */ + @Override + public DataTableEntity importPostBefore(DataTableEntity dt) throws BaseException { + ImportErrorEntity errorEntity = new ImportErrorEntity(); + if (!BaseUtil.dataTableIsEmpty(dt)) { + SystemUser currentUser = SpringMVCContextHolder.getCurrentUser(); + //绠$悊鍛樻潈闄愰獙璇� + managerPermissionValidation(errorEntity, currentUser); + Map<String, String> fieldType = Maps.newHashMap(); + // 褰撳墠绠$悊鍛樼鐞嗙殑鍏徃 + String managerCompanyUuids = currentUser.getCurrentManager().getString(CmnConst.ORG_LEVEL_UUID); + fieldType.put(CmnConst.SEQUENCE, "int"); + String companyFilter = BaseUtil.buildQuestionMarkFilter(CmnConst.ORG_LEVEL_UUID, managerCompanyUuids.split(","), true); + StringBuilder sql = new StringBuilder(8); + sql.append(" SELECT org_level_all uuid, uuid dept_uuid,org_level_uuid FROM product_sys_org_levels where org_level_type=1 and length(org_level_uuid)>0 "); + sql.append(" and "); + sql.append(companyFilter); + DataTableEntity deptData = getBaseDao().listTable(sql.toString(), new Object[]{}); + if (BaseUtil.dataTableIsEmpty(deptData)) { + errorEntity.newThrowBaseException("鎮ㄦ墍绠$悊鐨勫叕鍙告病鏈夊彲渚涢�夋嫨鐨勯儴闂紝璇锋牳瀵归儴闂ㄦ暟鎹�"); + } + sql = new StringBuilder(8); + sql.append(" SELECT job_grade_name uuid,org_level_uuid,uuid grade_uuid "); + sql.append(" FROM product_sys_job_post_grades WHERE "); + sql.append(companyFilter); + // 鏌ヨ褰撳墠绠$悊绠$悊鍏徃鎵�鏈夌殑宀椾綅绛夌骇 + DataTableEntity postGradeData = getBaseDao().listTable(sql.toString(), new Object[]{}); + if (BaseUtil.dataTableIsEmpty(postGradeData)) { +// errorEntity.newThrowBaseException("鎮ㄦ墍绠$悊鐨勫叕鍙告病鏈夊彲渚涢�夋嫨鐨勫矖浣嶇瓑绾э紝璇锋牳瀵瑰矖浣嶇瓑绾ф暟鎹�"); + } + for (int i = 0; i < dt.getRows(); i++) { + FieldSetEntity fse = dt.getFieldSetEntity(i); + // 瀛楁蹇呭~ & 绫诲瀷楠岃瘉 + boolean validationResult = fieldRequiredValidation(errorEntity, fse, new String[]{CmnConst.FIELD_DEPT_UUID, CmnConst.FIELD_JOB_POST_NAME, CmnConst.SEQUENCE}, fieldType); + if (!validationResult) { + // 楠岃瘉鏈�氳繃璺宠繃 + continue; + } + // 閮ㄩ棬鍏ㄧО + String deptAllName = fse.getString(CmnConst.FIELD_DEPT_UUID); + // 宀椾綅绛夌骇鍚嶇О + String[] gradeNames = BaseUtil.ifNull(fse.getString(CmnConst.FIELD_JOB_POST_GRADE), "").split(","); + List<FieldSetEntity> fieldSetEntity = deptData.getFieldSetEntity(deptAllName); + // 閮ㄩ棬鎵�鍦ㄧ殑鍏徃 + String companyUuid = null; + // 閿欒鏍囪瘑 + boolean errorFlag = false; + DataLocation dataLocation = null; + if (fieldSetEntity == null || fieldSetEntity.size() < 1) { + dataLocation = getDataLocation(fse); + String error = "绗� %s 琛岋紝绗� %s 鍒楋紝閮ㄩ棬涓嶅瓨鍦紝璇锋牳瀵� '%s' 鏁版嵁鍦ㄧ郴缁熶腑鏄惁瀛樺湪"; + error = String.format(error, dataLocation.getRowIndex(), dataLocation.getColIndex(CmnConst.FIELD_DEPT_UUID), dataLocation.getColName(CmnConst.FIELD_DEPT_UUID)); + errorEntity.addError(dataLocation.getRowIndex(), error); + errorFlag = true; + } else { + FieldSetEntity fs = fieldSetEntity.get(0); + companyUuid = fs.getString(CmnConst.ORG_LEVEL_UUID); + fse.setValue(CmnConst.FIELD_DEPT_UUID, fs.getString(CmnConst.FIELD_DEPT_UUID)); + } + // 鏍规嵁宀椾綅绛夌骇鍚嶇О鍙栧嚭鐩稿叧鏁版嵁 + List<FieldSetEntity> postGradeList = new ArrayList<>(); + for (String gradeName : gradeNames) { + if (!BaseUtil.dataTableIsEmpty(postGradeData) && postGradeData.getFieldSetEntity(gradeName) != null) { + postGradeList.addAll(postGradeData.getFieldSetEntity(gradeName)); + } + } + String error = "绗� %s 琛岋紝绗� %s 鍒楋紝宀椾綅绛夌骇涓嶅瓨鍦紝璇锋牳瀵� '%s' 鏁版嵁鍦ㄧ郴缁熶腑鏄惁瀛樺湪"; + // 鍒ゆ柇宀椾綅绛夌骇鏄惁瀛樺湪 榛樿涓嶆姏鍑洪敊璇� + if (postGradeList.size() < 1 && false) { + if (dataLocation == null) { + dataLocation = getDataLocation(fse); + } + error = String.format(error, dataLocation.getRowIndex(), dataLocation.getColIndex(CmnConst.FIELD_JOB_POST_GRADE), dataLocation.getColName(CmnConst.FIELD_JOB_POST_GRADE)); + errorEntity.addError(dataLocation.getRowIndex(), error); + errorFlag = true; + } else if (postGradeList.size() > 0) { + String gradeUuid = ""; + // 寰幆宀椾綅绛夌骇 + for (FieldSetEntity fs : postGradeList) { + // 鏌ユ壘宀椾綅绛夌骇涓庡叕鍙告槸鍚﹀尮閰� + if (companyUuid != null && companyUuid.equals(fs.getString(CmnConst.ORG_LEVEL_UUID))) { + if (!StringUtils.isEmpty(gradeUuid)) { + gradeUuid += ","; + } + gradeUuid += fs.getString("grade_uuid"); + } + } + // 娌℃湁鍖归厤鍒拌鍏徃涓嬫湁鐩稿簲鐨勫矖浣嶇瓑绾� + if (StringUtils.isEmpty(gradeUuid)) { + if (dataLocation == null) { + dataLocation = getDataLocation(fse); + } + error = "绗� %s 琛岋紝绗� %s 鍒楋紝宀椾綅绛夌骇鍦ㄤ笉瀛樺湪锛岃鏍稿 '%s' 鏁版嵁鍦ㄦ墍灞為儴闂ㄧ殑鍏徃涓槸鍚﹀瓨鍦�"; + error = String.format(error, dataLocation.getRowIndex(), dataLocation.getColIndex(CmnConst.FIELD_JOB_POST_GRADE), dataLocation.getColName(CmnConst.FIELD_JOB_POST_GRADE)); + errorEntity.addError(dataLocation.getRowIndex(), error); + errorFlag = true; + } else { + String[] gradeUuids = gradeUuid.split(","); + // 鍒涘缓宀椾綅涓庡矖浣嶇瓑绾х殑鏄犲皠琛� + DataTableEntity subGradeMapping = new DataTableEntity(); + for (String uuid : gradeUuids) { + FieldSetEntity gradeMappingFieldSet = new FieldSetEntity(); + gradeMappingFieldSet.setTableName(CmnConst.TABLE_PRODUCT_SYS_JOB_POSTS_GRADES_MAPPING); + gradeMappingFieldSet.setValue("job_grade_uuid", uuid); + BaseUtil.createCreatorAndCreationTime(gradeMappingFieldSet); + subGradeMapping.addFieldSetEntity(gradeMappingFieldSet); + } + fse.addSubDataTable(subGradeMapping); + fse.setValue(CmnConst.FIELD_JOB_POST_GRADE, null); + } + } + if (errorFlag) { + continue; + } + // 瀵煎叆鏁版嵁榛樿鍚敤 + fse.setValue(CmnConst.IS_USED, 1); + } + if (errorEntity.isError) { + errorEntity.newThrowBaseException(); + } else { + return dt; + } + } + errorEntity.newThrowBaseException("瀵煎叆宀椾綅绛夌骇澶辫触锛屾湭鎻愬彇鍒版暟鎹�"); + return null; + } + + /** + * 瀵煎叆鍛樺伐 涔嬪墠 鏁版嵁澶勭悊 + * + * @param fse + * @throws BaseException + */ + @Override + public DataTableEntity importStaffBefore(DataTableEntity fse) throws BaseException { + ImportStaffDataVo staffDataVo = new ImportStaffDataVo(fse); + staffDataVo.startImporting(); + return fse; + } + + + /** + * 鍛樺伐瀵煎叆鎿嶄綔绫� + */ + private class ImportStaffDataVo { + //瀵煎叆鐨勬墍鏈夋暟鎹� + private DataTableEntity dt; + /** + * 閿欒澶勭悊绫� + */ + private ImportErrorEntity errorEntity; + /** + * 绯荤粺涓笂绾ч瀵兼暟鎹� + */ + DataTableEntity directLeaderData; + /** + * 閮ㄩ棬鏁版嵁 + */ + DataTableEntity deptData; + /** + * 瑙掕壊鏁版嵁 + */ + DataTableEntity roleData; + /** + * 宀椾綅 & 宀椾綅绛夌骇鏁版嵁 + */ + DataTableEntity postData; + /** + * 鍛樺伐琛ㄥ巻鍙叉暟鎹� + */ + DataTableEntity systemData; + /** + * 瀵煎叆鏁版嵁鐨勬墍鏈夐瀵�(鍛樺伐缂栫爜锛� + */ + Set<String> direct_leader_codes; + /** + * 瀵煎叆鐨勬暟鎹寜閮ㄩ棬鍒嗙粍 + */ + Map<String, List<FieldSetEntity>> deptGroupMap; + /** + * 褰撳墠鐢ㄦ埛 + */ + SystemUser currentUser; + /** + * 褰撳墠瀹㈡埛 + */ + String client_uuid; + /** + * 瀵煎叆鐨勬暟鎹互鍛樺伐缂栫爜瀛樻斁锛堝憳宸ョ紪鐮佹槸鍞竴鐨勶級 + */ + Map<String, FieldSetEntity> staffCodeMap; + /** + * 瀵煎叆鏁版嵁绫诲瀷楠岃瘉 + */ + Map<String, String> fieldType; + /** + * 鍏徃杩囨护鏉′欢 + */ + String companyFilter; + /** + * 鍒嗛殧绗� + */ + String separator = ">"; + + StringBuilder sql; + /** + * 鍒濆瀵嗙爜 + * 鏉ユ簮浜� properties 涓殑鍒濆瀵嗙爜 濡備笉瀛樺湪榛樿涓� '123' + */ + String init_pwd; + /** + * 閮ㄩ棬鍏ㄧО瀛樻斁鐨勯儴闂ㄨ鎯呮暟鎹� + */ + private Map<String, FieldSetEntity> deptMap; + /** + * 鍛樺伐绠$悊service + * 瀹氫箟璇ユ搷浣滅被涓伩鍏嶆病蹇呰鐨勬敞鍏� 杩涘叆鏋勯�犳椂浼氬垵濮嬪寲瀵瑰簲bean + */ + private StaffManagerService staffManagerService; + + /** + * 鏋勯�犳柟娉� 鐢ㄤ簬clone 闈炲繀瑕佷笉瑕佽嚜琛岃皟鐢ㄦ鏂规硶 + * + * @param currentData + * @param currentDeptData + */ + ImportStaffDataVo(FieldSetEntity currentData, FieldSetEntity currentDeptData) throws BaseException { + // 璇ユ瀯閫犵敤浜� clone 鏂规硶 + // 闈瀋lone 鏂瑰紡璋冪敤浼氬嚭鐜版湭鐭ラ敊璇� + this.currentData = currentData; + this.currentDeptData = currentDeptData; + if (currentData == null || currentDeptData == null) { + try { + throw new RuntimeException("Constructor arguments cannot be null"); + } catch (RuntimeException e) { + throw new BaseException(e); + } + } + } + + /** + * 鏃犲弬鏋勯�� 鍒濆蹇呰鏁版嵁 + * + * @param dt + */ + public ImportStaffDataVo(DataTableEntity dt) throws BaseException { + errorEntity = new ImportErrorEntity(); + if (BaseUtil.dataTableIsEmpty(dt)) { + errorEntity.newThrowBaseException("瀵煎叆鍛樺伐澶辫触锛屾湭鎻愬彇鍒版暟鎹�"); + } + this.staffManagerService = SpringBeanUtil.getBean("staffManagerService", StaffManagerService.class); + direct_leader_codes = Sets.newHashSet(); + fieldType = Maps.newHashMap(); + currentUser = SpringMVCContextHolder.getCurrentUser(); + client_uuid = currentUser.getClient_uuid(); + staffCodeMap = Maps.newHashMap(); + deptGroupMap = Maps.newHashMap(); + init_pwd = Global.getSystemConfig("initial.pwd", "123"); + this.dt = dt; + //绠$悊鍛樻潈闄愰獙璇� + managerPermissionValidation(errorEntity, currentUser); + // 鍏徃杩囨护鏉′欢 + companyFilter = BaseUtil.buildQuestionMarkFilter(CmnConst.ORG_LEVEL_UUID, currentUser.getCurrentManager().getString(CmnConst.ORG_LEVEL_UUID).split(","), true); + fieldType.put("id_number", "id_card"); + fieldType.put("birth_date", "dateTime"); + fieldType.put("entry_datetime", "dateTime"); + fieldType.put("mobile_phone", "mobile_phone"); + fieldType.put("staff_email", "email"); + fieldType.put("age", "int"); + } + + /** + * 瀵煎叆鏁版嵁鍏ュ彛 + * 寮�濮嬪鍏� + */ + public void startImporting() throws BaseException { + // 鏁版嵁鏈夋晥鎬ч獙璇� 鏁版嵁蹇呭~楠岃瘉 & 鏁版嵁鏈夋晥鎬ч獙璇� & 鏁版嵁鍒嗙粍 + this.requiredValidation(); + // 鏌ヨ绯荤粺涓凡瀛樺湪鐨勫憳宸� + findExistStaff(); + // 鏁版嵁閲嶅楠岃瘉 + this.repeatValidation(); + this.throwError(); + // 鍒濆鍖栨墍闇�鏁版嵁 + this.initializeSystemData(); + // 寮�濮嬪鐞嗗鍏ユ暟鎹� + this.handleDataTable(); + } + + /** + * handleDataTable 閬嶅巻鏃剁殑鏁版嵁 + * 鍙兘鏄�氳繃 clone 瀵硅薄璧嬪�肩殑 娌℃湁閫氳繃 handleDataTable 鏂规硶 + */ + private FieldSetEntity currentData; + /** + * handleDataTable 閬嶅巻鏁版嵁瀵瑰簲鐨勯儴闂� + * 鍙兘鏄�氳繃 clone 瀵硅薄璧嬪�肩殑 娌℃湁閫氳繃 handleDataTable 鏂规硶 + */ + private FieldSetEntity currentDeptData; + + /** + * 涓婄骇棰嗗鏈壘鍒� + */ + private void superStaffNotExist() throws BaseException { + DataLocation dataLocation = getDataLocation(this.currentData); + String error = "绗� %s 琛岋紝绗� %s 鍒楋紝涓婄骇棰嗗鑾峰彇澶辫触锛岃妫�鏌� %s 濉啓鍊兼槸鍚︽纭紝璇ュ垪鍊煎簲濉啓 %s 鍒楀搴旂殑鍊�"; + error = String.format(error, dataLocation.getRowIndex(), dataLocation.getColIndex(CmnConst.FIELD_DIRECT_LEADER_CODE), dataLocation.getColName(CmnConst.FIELD_DIRECT_LEADER_CODE), dataLocation.getColName(CmnConst.FIELD_STAFF_CODE)); + errorEntity.addError(dataLocation.getRowIndex(), error); + } + + /** + * 澶勭悊鎵�鏈夎褰� + */ + private void handleDataTable() throws BaseException { + for (Map.Entry<String, List<FieldSetEntity>> fieldSets : this.deptGroupMap.entrySet()) { + String deptAllName = fieldSets.getKey(); + currentDeptData = this.getStaffDept(deptAllName); + List<FieldSetEntity> values = fieldSets.getValue(); + if (currentDeptData == null) { + for (int i = 0; i < values.size(); i++) { + this.currentData = values.get(i); + DataLocation dataLocation = getDataLocation(this.currentData); + String error = "绗� %s 琛岋紝绗� %s 鍒楋紝閮ㄩ棬鍦ㄧ郴缁熸垨绠$悊鐨勫叕鍙镐腑涓嶅瓨鍦紝璇锋鏌ュ垪 '%s' 鐨勫�� '%s' 鏄惁姝g‘"; + error = String.format(error, dataLocation.getRowIndex(), dataLocation.getColIndex(CmnConst.FIELD_DEPT_UUID), + dataLocation.getColName(CmnConst.FIELD_DEPT_UUID), deptAllName); + this.errorEntity.addError(dataLocation.getRowIndex(), error); + } + continue; + } + for (FieldSetEntity value : values) { + if (value.getBoolean("~processed~")) { + continue; + } + this.currentData = value; + this.handleFieldSet(); + } + } + throwError(); + } + + /** + * 澶勭悊鍗曟潯璁板綍 + */ + private void handleFieldSet() throws BaseException { + if (this.currentData.getBoolean("~processed~")) { + return; + } + String dept_uuid = this.currentDeptData.getString(CmnConst.UUID); + String org_level_uuid = this.currentDeptData.getString(CmnConst.ORG_LEVEL_UUID); + this.currentData.setValue("~processed~", 1); + this.currentData.setValue("~dept_uuid~", dept_uuid); + this.currentData.setValue(CmnConst.FIELD_STAFF_CODE, this.currentData.getString("~temp_staff_code~")); + this.currentData.setValue(CmnConst.FIELD_DEPT_UUID, currentDeptData.getString(CmnConst.FIELD_DEPT_UUID)); + this.currentData.setValue(CmnConst.ORG_LEVEL_UUID, org_level_uuid); + this.currentData.setValue("status", 1); + + //鍙栧嚭閰嶇疆涓处鎴峰垵濮嬪瘑鐮� + this.currentData.setValue(CmnConst.USER_PWD, this.init_pwd); + String sex = this.currentData.getString("sex"); + if (!StringUtils.isEmpty(sex)) { + // 鎬у埆涓嶄负绌烘椂 杞崲鍙傜収鏁版嵁 鎬у埆楠岃瘉宸插湪涓婁釜鏂规硶涓獙璇佽繃 + this.currentData.setValue("sex", sex.equals("鐢�") ? 0 : 1); + } + // 瀵煎叆鏁版嵁閰嶇疆涓� 浣跨敤 staff_avatar 瀛楁浣滀负鐢ㄦ埛鐧诲綍璐︽埛鐨勮浇浣� 鍦ㄦ澶勮浆鎹㈠洖鏉� + this.currentData.setValue(CmnConst.USER_ACCOUNT, this.currentData.getString("staff_avatar")); + // 鍒犻櫎杞戒綋鏁版嵁 + this.currentData.remove("staff_avatar"); + // 灏唖how_name 瀛楁锛堝憳宸ュ悕绉帮級 澶嶅埗鍒� user琛ㄥ瓧娈典笂 + this.currentData.setValue(CmnConst.USER_NAME, this.currentData.getString("show_name")); + String job_post_grade_uuid = this.currentData.getString(CmnConst.FIELD_JOB_POST_GRADE_UUID); + String job_post_name = this.currentData.getString("job_post_uuid"); + + // 宀椾綅 & 宀椾綅绛夌骇 + List<FieldSetEntity> postDataList = postData.getFieldSetEntity(this.currentData.getString("job_post_uuid")); + if (postDataList == null || postDataList.size() <= 0) { + // 娌℃湁宀椾綅 + postNotExist.method(this.currentData, "job_post_uuid"); + } else { + // 璁板綍鎵惧埌鐨勫矖浣嶇瓑绾uid 锛屽涓敤閫楀彿鍒嗛殧 + String grade_uuid = ""; + // 宀椾綅uuid + String post_uuid = null; + // 寰幆绯荤粺涓矖浣嶆暟鎹� + for (FieldSetEntity postFs : postDataList) { + // 鍒ゆ柇宀椾綅鏄惁鍦ㄩ儴闂ㄤ笅 & 宀椾綅鍚嶇О鍜屽鍏ユ暟鎹殑宀椾綅鍚嶇О鏄惁鐩稿悓 + if (currentDeptData.getString(CmnConst.FIELD_DEPT_UUID).equals(postFs.getString(CmnConst.FIELD_DEPT_UUID)) && job_post_name.equals(postFs.getUUID())) { + // 绯荤粺涓矖浣嶇殑uuid + String job_post_uuid = postFs.getString("job_post_uuid"); + // 宀椾綅uuid涓嶄负绌烘椂 鍒ゆ柇褰撳墠postFs 涓殑宀椾綅uuid鏄惁璺熷凡鎵惧埌鐨勫矖浣嶇浉鍚� + if (post_uuid != null && !post_uuid.equals(job_post_uuid)) { + continue; + } + if (post_uuid == null) { + // 璁板綍宀椾綅uuid + post_uuid = job_post_uuid; + } + // 鑾峰彇宀椾綅涓殑宀椾綅绛夌骇鍚嶇О + String job_grade_name = postFs.getString(CmnConst.FIELD_JOB_GRADE_NAME); + // 鎷嗗垎寰幆瀵煎叆宀椾綅绛夌骇鍚嶇О + if (!BaseUtil.strIsNull(job_post_grade_uuid)) { + for (String grade_name : job_post_grade_uuid.split(",")) { + // 鍒ゆ柇宀椾綅绛夌骇鍚嶇О鍜岀郴缁熶腑鐩稿悓 + if (job_grade_name.equals(grade_name)) { + if (!StringUtils.isEmpty(grade_uuid)) { + grade_uuid += ","; + } + grade_uuid += postFs.getString(CmnConst.FIELD_JOB_POST_GRADE); + } + } + } + } + + } + // 娌℃湁鎵惧埌宀椾綅 + if (StringUtils.isEmpty(post_uuid)) { + // 鎶涘嚭宀椾綅鏈壘鍒伴敊璇� + postNotExist.method(this.currentData, "job_post_uuid"); + } else { + // 鎵惧埌宀椾綅 + this.currentData.setValue("job_post_uuid", post_uuid); + } + // 娌℃湁鎵惧埌宀椾綅绛夌骇 + if (!StringUtils.isEmpty(grade_uuid)) { +// postNotExist.method(this.currentData, CmnConst.FIELD_JOB_POST_GRADE_UUID); +// } else { + this.currentData.setValue(CmnConst.FIELD_JOB_POST_GRADE_UUID, grade_uuid); + } + } + // 瀵煎叆鏁版嵁涓矖浣嶅悕绉� + String[] role_uuids = this.currentData.getString("role_uuids").split(","); + String roleUuid = ""; + // 瑙掕壊澶勭悊 + roleFor: + // 寰幆瑙掕壊鍚嶇О + for (String roleName : role_uuids) { + // 浣跨敤瑙掕壊鍚嶇О鑾峰彇绯荤粺鏁版嵁 + List<FieldSetEntity> roleList = roleData.getFieldSetEntity(roleName); + if (roleList != null && roleList.size() > 0) { + // 寰幆绯荤粺涓殑瑙掕壊 + for (FieldSetEntity roleFs : roleList) { + // 鍥犵郴缁熶腑瑙掕壊鎵�灞炲叕鍙稿彲澶氶�夛紝鍦ㄦ澶勫墠鍚庢嫾鎺ラ�楀彿 + String roleCompany = "," + roleFs.getString(CmnConst.ORG_LEVEL_UUID) + ","; + // 鍒ゆ柇瑙掕壊鏄惁鏈夊鍏ユ暟鎹殑鍏徃 + if (roleCompany.contains("," + org_level_uuid + ",")) { + String role_uuid = roleFs.getString("role_uuid"); + if (!StringUtils.isEmpty(roleUuid)) { + roleUuid += ","; + } + roleUuid += role_uuid; + continue roleFor; + } + } + } + + // 娌℃湁鎵惧埌瑙掕壊鏁版嵁 鎶涘嚭閿欒 + roleNotExist.method(this.currentData, roleName); + + } + this.currentData.setValue("role_uuids", roleUuid); + //瑁呰浇涓婄骇棰嗗code + this.loadingSuperCode(); + if (staffManagerService == null) { + staffManagerService = SpringBeanUtil.getBean("staffManagerService", StaffManagerService.class); + } + staffManagerService.saveStaffInfo(this.currentData); + } + + /** + * 鎶涘嚭閿欒 + * + * @throws BaseException + */ + void throwError() throws BaseException { + if (errorEntity.isError) { + errorEntity.newThrowBaseException(); + } + } + + /** + * 瑁呰浇涓婄骇棰嗗缂栫爜 + * + * @return + */ + private boolean loadingSuperCode() throws BaseException { + // 涓婄骇棰嗗锛堝憳宸ョ紪鐮侊級 + String direct_leader_code = this.currentData.getString(CmnConst.FIELD_DIRECT_LEADER_CODE); + String superCode = ""; + if (!StringUtils.isEmpty(direct_leader_code)) { + List<FieldSetEntity> fieldSetEntity = directLeaderData.getFieldSetEntity(direct_leader_code); + if (staffCodeMap.get(direct_leader_code) == null && (fieldSetEntity == null || fieldSetEntity.size() <= 0)) { + // 鏈壘鍒颁笂绾ч瀵� + this.superStaffNotExist(); + return false; + } else { + //涓婄骇棰嗗鍦ㄥ鍏ユ暟鎹� 鎴栫郴缁熶腑宸插瓨鍦� + // 鏍规嵁缂栫爜鑾峰彇涓婄骇锛堝鍏ユ暟鎹級 + FieldSetEntity superFs = staffCodeMap.get(direct_leader_code); + if (superFs == null && (fieldSetEntity == null || fieldSetEntity.size() <= 0)) { + // 鏈壘鍒颁笂绾ч瀵� + this.superStaffNotExist(); + return false; + } else if (superFs == null) { + // 鍦ㄧ郴缁熶腑鎷垮嚭涓婄骇棰嗗 + superFs = fieldSetEntity.get(0); + } + String user_id = superFs.getString(CmnConst.USER_ID); + if (StringUtils.isEmpty(user_id)) { + // user_id 涓嶅瓨鍦紝璇ヤ笂绾у湪瀵煎叆鏁版嵁涓湭淇濆瓨杩� + String deptAllName = superFs.getString(CmnConst.FIELD_DEPT_UUID); + if (superFs.getBoolean("~processed~")) { + deptAllName = superFs.getString("~" + CmnConst.FIELD_DEPT_UUID + "~"); + } + FieldSetEntity deptFs = getStaffDept(deptAllName); + if (deptFs == null) { + return false; + } + // 鍏嬮殕褰撳墠瀵硅薄 灏嗙埗绾х殑閮ㄩ棬 & 鍛樺伐琛ㄦ暟鎹斁鍏ュ厠闅嗗璞′腑 + ImportStaffDataVo clone = this.clone(deptFs, superFs); + // 鍏堣鐖剁骇鏁版嵁杩涜淇濆瓨鎿嶄綔 + // 杩欓噷浼氬嚭鐜伴�掑綊鎿嶄綔 鍥犱负 handleFieldSet 鏂规硶璋冪敤浜嗗綋鍓嶆柟娉� 鐖剁骇鐨勭埗绾ц繘鍏ヤ竴鑷寸殑鍒ゆ柇浼氫竴鐩撮�掑綊 clone骞朵繚瀛� + // 濡傛灉閫掑綊灞傛暟杩囧鍙兘浼氬嚭鐜� full gc + clone.handleFieldSet(); + } else { + //宸蹭繚瀛樿繃鐨勬暟鎹� 鍙栧嚭宸茬敓鎴愮殑tricode + superCode = superFs.getString(CmnConst.TRICODE); + } + } + } + this.currentData.setValue(CmnConst.FIELD_DIRECT_LEADER_CODE, superCode); + return true; + } + + /** + * 鍏嬮殕瀵硅薄 + * 鍏嬮殕鍚� sql 鎴愬憳鍙橀噺鏈垵濮嬪寲 + * + * @param currentDeptData + * @param currentData + * @return + */ + private ImportStaffDataVo clone(FieldSetEntity currentDeptData, FieldSetEntity currentData) throws BaseException { + ImportStaffDataVo clone = new ImportStaffDataVo(currentData, currentDeptData); + clone.deptData = this.deptData; + clone.postData = this.postData; + clone.roleData = this.roleData; + clone.deptGroupMap = this.deptGroupMap; + clone.errorEntity = this.errorEntity; + clone.direct_leader_codes = this.direct_leader_codes; + clone.deptMap = this.deptMap; + clone.dt = this.dt; + clone.systemData = this.systemData; + clone.directLeaderData = this.directLeaderData; + clone.staffCodeMap = this.staffCodeMap; + clone.companyFilter = this.companyFilter; + clone.currentUser = this.currentUser; + clone.fieldType = this.fieldType; + clone.init_pwd = this.init_pwd; + clone.client_uuid = this.client_uuid; + return clone; + } + + /** + * 鏍规嵁閮ㄩ棬鍏ㄧО鑾峰彇閮ㄩ棬璇︽儏 + * + * @param deptAllName + * @return + * @throws BaseException + */ + private FieldSetEntity getStaffDept(String deptAllName) throws BaseException { + if (deptMap == null) { + deptMap = Maps.newHashMap(); + } + if (deptMap.get(deptAllName) != null) { + return deptMap.get(deptAllName); + } + List<FieldSetEntity> deptDatList = deptData.getFieldSetEntity(deptAllName); + if (deptDatList == null || deptDatList.size() < 0) { + return null; + } + return deptDatList.get(0); + } + + /** + * 瑙掕壊鏈壘鍒伴敊璇洖璋� + */ + private CallBack<Object> roleNotExist = f -> { + FieldSetEntity fs = (FieldSetEntity) f[0]; + Object role_name = f[1]; + DataLocation dataLocation = getDataLocation(fs); + String error = "绗� %s 琛岋紝绗� %s 鍒楋紝%s 鍦ㄧ郴缁熶腑涓嶅瓨鍦紝璇锋鏌ュ垪鍊�%s 鏄惁姝g‘"; + error = String.format(error, dataLocation.getRowIndex(), dataLocation.getColIndex("role_uuids"), + dataLocation.getColName("role_uuids"), role_name); + errorEntity.addError(dataLocation.getRowIndex(), error); + }; + /** + * 宀椾綅 & 宀椾綅绛夌骇鏈壘鍒伴敊璇洖璋� + */ + private CallBack<Object> postNotExist = f -> { + FieldSetEntity fs = (FieldSetEntity) f[0]; + String fieldName = (String) f[1]; + DataLocation datLocation = getDataLocation(fs); + String error = "绗� %s 琛岋紝绗� %s 鍒楋紝'%s' 鏁版嵁鍦ㄧ郴缁熶腑涓嶅瓨鍦紝璇锋鏌� '%s' 鏄惁姝g‘"; + error = String.format(error, datLocation.getRowIndex(), datLocation.getColIndex(fieldName), + datLocation.getColName(fieldName), fs.getString(fieldName)); + errorEntity.addError(datLocation.getRowIndex(), error); + }; + + /** + * 鍒濆鍖栫郴缁熸暟鎹� + */ + private void initializeSystemData() throws BaseException { + //鏌ヨ涓婄骇棰嗗 + findDirectLeaderData(); + // 鏌ヨ绠$悊鍛樼鐞嗙殑(鍏徃涓嬬殑)閮ㄩ棬 + findDeptData(); + // 绠$悊鍛樼鐞嗙殑瑙掕壊 + findRoleData(); + // 绠$悊鍛樼鐞嗙殑宀椾綅 & 宀椾綅绛夌骇 + findPostData(); + this.throwError(); + } + + /** + * 鏌ヨ鎵�鏈夊矖浣� & 宀椾綅绛夌骇 + */ + private void findPostData() throws BaseException { + sql = new StringBuilder(); + sql.append(" select a.job_post_name uuid,a.uuid job_post_uuid,c.job_grade_name,c.uuid job_post_grades_uuid,a.dept_uuid FROM product_sys_job_posts a "); + sql.append(" LEFT join product_sys_job_posts_grades_mapping b on "); + sql.append(" a.dept_uuid in (select uuid FROM product_sys_org_levels where org_level_type=1 and "); + sql.append(companyFilter); + sql.append(" ) and a.uuid=b.job_post_uuid "); + sql.append(" LEFT join product_sys_job_post_grades c on b.job_grade_uuid=c.uuid "); + sql.append(" group by a.job_post_name,a.uuid ,c.job_grade_name,c.uuid,a.dept_uuid "); + // 鏌ヨ宀椾綅 & 宀椾綅绛夌骇 + postData = getBaseDao().listTable(sql.toString(), new Object[]{}); + if (BaseUtil.dataTableIsEmpty(roleData)) { + errorEntity.addError(0, "绯荤粺涓病鏈夊彲渚涢�夋嫨鐨勫矖浣嶆垨宀椾綅绛夌骇"); + } + } + + /** + * 鏌ヨ鎵�鏈夎鑹� + */ + private void findRoleData() throws BaseException { + sql = new StringBuilder(); + sql.append(" select role_name as uuid,uuid as role_uuid,org_level_uuid FROM product_sys_role "); + sql.append(" where is_used = 1 and "); + sql.append(companyFilter); + // 鏌ヨ瑙掕壊 + roleData = getBaseDao().listTable(sql.toString(), new Object[]{}); + if (BaseUtil.dataTableIsEmpty(roleData)) { + errorEntity.addError(0, "绯荤粺涓病鏈夊彲渚涢�夋嫨鐨勮鑹�"); + } + } + + /** + * 鏌ヨ鎵�鏈夐儴闂� + */ + private void findDeptData() throws BaseException { + // 鏌ヨ閮ㄩ棬 + sql = new StringBuilder(); + sql.append(" select org_level_all uuid,uuid as dept_uuid,org_level_uuid,org_level_code,org_level_code_parent FROM product_sys_org_levels "); + sql.append(" where org_level_type = 1 and "); + sql.append(BaseUtil.buildQuestionMarkFilter(CmnConst.FIELD_ORG_LEVEL_ALL, deptGroupMap.size(), true)); + sql.append(" and "); + sql.append(companyFilter); + // 鏌ヨ閮ㄩ棬 + deptData = getBaseDao().listTable(sql.toString(), deptGroupMap.keySet().toArray()); + if (BaseUtil.dataTableIsEmpty(deptData)) { + errorEntity.addError(0, "绯荤粺涓病鏈夊彲渚涢�夋嫨鐨勯儴闂�"); + } + } + + /** + * 鏌ヨ瀵煎叆鏁版嵁鎵�鏈夌殑涓婄骇棰嗗 + */ + private void findDirectLeaderData() throws BaseException { + sql = new StringBuilder(); + sql.append(" SELECT staff_code uuid,tricode,user_id FROM product_sys_staffs "); + sql.append(" where "); + sql.append(BaseUtil.buildQuestionMarkFilter(CmnConst.FIELD_STAFF_CODE, direct_leader_codes.size(), true)); + if (direct_leader_codes.size() > 0) { + sql.append(" and "); + } + sql.append(" org_level_uuid in (select uuid FROM product_sys_org_levels where org_level_type=0 and client_uuid=?) "); + // 鏆傛椂娉ㄩ噴涓嶇敤鍏徃鍋氶檺鍒� +// sql.append(" and "); +// sql.append(companyFilter); + // 鏌ヨ涓婄骇棰嗗 + List<String> params = Lists.newArrayList(direct_leader_codes.iterator()); + params.add(currentUser.getClient_uuid()); + directLeaderData = getBaseDao().listTable(sql.toString(), params.toArray()); + } + + /** + * 鏌ヨ鎵�鏈夊憳宸ョ紪鐮佷互鍙妘ser琛ㄤ腑鐨勮处鍙� + */ + private void findExistStaff() throws BaseException { + sql = new StringBuilder(126); + sql.append(" select concat(b.client_uuid,'>',staff_code) staff_code,a.user_account as staff_avatar "); + sql.append(" FROM product_sys_users a left join product_sys_staffs b on (b.client_uuid=? or b.uuid is null) and a.user_id=b.user_id "); + systemData = getBaseDao().listTable(sql.toString(), new Object[]{client_uuid}); + } + + /** + * 鏁版嵁鏍煎紡鏁堥獙 + */ + private void repeatValidation() throws BaseException { + // 娉� 锛歴taff_avatar 瀛楁涓� user琛ㄤ腑 user_account 鐨勮浇浣� + fieldRepeatValidation(errorEntity, dt, systemData, new String[]{CmnConst.FIELD_STAFF_CODE, "staff_avatar"}); + } + + /** + * 蹇呭~鏁堥獙 鏁版嵁澶勭悊 + */ + private void requiredValidation() throws BaseException { + errorEntity.mergeError(fieldRequiredValidation(dt, new String[]{"show_name", "staff_avatar", CmnConst.FIELD_STAFF_CODE, + CmnConst.FIELD_DEPT_UUID, "job_post_uuid", "role_uuids"}, fieldType, (FieldSetEntity[] f) -> { + FieldSetEntity fs = f[0]; + //涓婄骇棰嗗缂栫爜 + String direct_leader_code = fs.getString(CmnConst.FIELD_DIRECT_LEADER_CODE); + //宸ヤ綔閮ㄩ棬鍏ㄧО + String deptAllName = fs.getString(CmnConst.FIELD_DEPT_UUID); + String id_number = fs.getString("id_number"); + String age = fs.getString("age"); + Date birth_date = fs.getDate("birth_date"); + String sex = fs.getString("sex"); + String staff_code = fs.getString(CmnConst.FIELD_STAFF_CODE); + + if (!StringUtils.isEmpty(staff_code)) { + fs.setValue("~temp_staff_code~", staff_code); + fs.setValue(CmnConst.FIELD_STAFF_CODE, client_uuid + this.separator + staff_code); + staffCodeMap.put(staff_code, fs); + } + fs.setValue(CmnConst.CLIENT_UUID, client_uuid); + if (!StringUtils.isEmpty(direct_leader_code)) { + //灏嗕笂绾ч瀵肩紪鐮佺粺涓�鏀惧叆闆嗗悎涓� + // 涓婄骇棰嗗缂栫爜 = 鍛樺伐缂栫爜 + direct_leader_codes.add(direct_leader_code); + } + //鎸夐儴闂ㄥ垎缁勬暟鎹� + if (!StringUtils.isEmpty(deptAllName)) { + List<FieldSetEntity> fieldSets = deptGroupMap.get(deptAllName); + if (fieldSets == null) { + fieldSets = Lists.newArrayList(); + deptGroupMap.put(deptAllName, fieldSets); + } + fieldSets.add(fs); + } + if (!StringUtils.isEmpty(id_number)) { + try { + if (birth_date == null) { + // 鏍规嵁韬唤璇佸彇鍑虹敓鏃ユ湡 + fs.setValue("birth_date", BaseUtil.getBirthday(id_number)); + } + if (StringUtils.isEmpty(age)) { + // 鏍规嵁韬唤璇佸彇鍑哄勾榫� + fs.setValue("age", BaseUtil.getAge(id_number)); + } + if (StringUtils.isEmpty(sex)) { + // 鏍规嵁韬唤璇佸彇鍑烘�у埆 + fs.setValue("sex", BaseUtil.getSex(id_number)); + } + } catch (Exception e) { + + } + } + + + })); + + } + } + + + /** + * 閲嶈浇瀵煎叆鍛樺伐鏂规硶 + * 澶勭悊鍏徃銆侀儴闂ㄣ�佸矖浣嶃�佸矖浣嶇瓑绾с�佽处鍙� 鐩稿叧鏁版嵁 + * + * @param postData 绯荤粺宀椾綅&宀椾綅绛夌骇鏁版嵁 + * @param roleData 绯荤粺瑙掕壊鏁版嵁 + * @param roleNotExist 瑙掕壊涓嶅瓨鍦ㄩ敊璇洖璋� + * @param postNotExist 宀椾綅&宀椾綅绛夌骇涓嶅瓨鍦ㄩ敊璇洖璋� + * @param fs 瀵煎叆鏁版嵁 + * @param deptFieldSet 閮ㄩ棬鏁版嵁 + * @param deptAllName 閮ㄩ棬鍏ㄧО + * @throws BaseException + */ + private void importStaffBefore(DataTableEntity postData, DataTableEntity + roleData, CallBack<Object> roleNotExist, CallBack<Object> postNotExist, FieldSetEntity fs, FieldSetEntity deptFieldSet, String deptAllName) throws BaseException { + + String dept_uuid = fs.getString(CmnConst.UUID); + String org_level_uuid = fs.getString(CmnConst.ORG_LEVEL_UUID); + fs.setValue(CmnConst.FIELD_STAFF_CODE, fs.getString("~temp_staff_code~")); + fs.setValue(CmnConst.FIELD_DEPT_UUID, dept_uuid); + fs.setValue(CmnConst.ORG_LEVEL_UUID, org_level_uuid); + + String job_post_grade_uuid = fs.getString(CmnConst.FIELD_JOB_POST_GRADE); + String job_post_name = fs.getString("job_post_uuid"); + + // 宀椾綅 & 宀椾綅绛夌骇 + List<FieldSetEntity> postDataList = postData.getFieldSetEntity(deptAllName); + if (postDataList == null || postDataList.size() <= 0) { + // 娌℃湁宀椾綅 + postNotExist.method(fs, "job_post_uuid"); + } else { + // 璁板綍鎵惧埌鐨勫矖浣嶇瓑绾uid 锛屽涓敤閫楀彿鍒嗛殧 + String grade_uuid = ""; + // 宀椾綅uuid + String post_uuid = null; + // 寰幆绯荤粺涓矖浣嶆暟鎹� + for (FieldSetEntity postFs : postDataList) { + // 鍒ゆ柇宀椾綅鏄惁鍦ㄩ儴闂ㄤ笅 & 宀椾綅鍚嶇О鍜屽鍏ユ暟鎹殑宀椾綅鍚嶇О鏄惁鐩稿悓 + if (dept_uuid.equals(postFs.getString(CmnConst.FIELD_DEPT_UUID)) && job_post_name.equals(postFs.getString(CmnConst.FIELD_JOB_POST_NAME))) { + // 绯荤粺涓矖浣嶇殑uuid + String job_post_uuid = postFs.getString("job_post_uuid"); + // 宀椾綅uuid涓嶄负绌烘椂 鍒ゆ柇褰撳墠postFs 涓殑宀椾綅uuid鏄惁璺熷凡鎵惧埌鐨勫矖浣嶇浉鍚� + if (post_uuid != null && !post_uuid.equals(job_post_uuid)) { + continue; + } + if (post_uuid == null) { + // 璁板綍宀椾綅uuid + post_uuid = job_post_uuid; + } + // 鑾峰彇宀椾綅涓殑宀椾綅绛夌骇鍚嶇О + String job_grade_name = postFs.getString(CmnConst.FIELD_JOB_GRADE_NAME); + // 鎷嗗垎寰幆瀵煎叆宀椾綅绛夌骇鍚嶇О + for (String grade_name : job_post_grade_uuid.split(",")) { + // 鍒ゆ柇宀椾綅绛夌骇鍚嶇О鍜岀郴缁熶腑鐩稿悓 + if (job_grade_name.equals(grade_name)) { + if (!StringUtils.isEmpty(grade_uuid)) { + grade_uuid += ","; + } + grade_uuid += postFs.getString(CmnConst.FIELD_JOB_POST_GRADE); + } + } + } + // 娌℃湁鎵惧埌宀椾綅 + if (StringUtils.isEmpty(post_uuid)) { + // 鎶涘嚭宀椾綅鏈壘鍒伴敊璇� + postNotExist.method(fs, "job_post_uuid"); + } else { + // 鎵惧埌宀椾綅 + fs.setValue("job_post_uuid", post_uuid); + } + // 娌℃湁鎵惧埌宀椾綅绛夌骇 + if (StringUtils.isEmpty(grade_uuid)) { + postNotExist.method(fs, CmnConst.FIELD_JOB_POST_GRADE); + } else { + fs.setValue(CmnConst.FIELD_JOB_POST_GRADE, grade_uuid); + } + } + } + // 瀵煎叆鏁版嵁涓矖浣嶅悕绉� + String[] role_uuids = (String[]) fs.getObject("role_uuids"); + String roleUuid = ""; + // 瑙掕壊澶勭悊 + roleFor: + // 寰幆瑙掕壊鍚嶇О + for (String roleName : role_uuids) { + // 浣跨敤瑙掕壊鍚嶇О鑾峰彇绯荤粺鏁版嵁 + List<FieldSetEntity> roleList = roleData.getFieldSetEntity(roleName); + // 鍦ㄧ郴缁熶腑娌℃湁鎵惧埌瑙掕壊鍚嶇О涓�鑷寸殑鏁版嵁 + if (roleList == null || roleList.size() <= 0) { + roleNotExist.method(fs, roleName); + } else { + // 寰幆绯荤粺涓殑瑙掕壊 + for (FieldSetEntity roleFs : roleList) { + // 鍥犵郴缁熶腑瑙掕壊鎵�灞炲叕鍙稿彲澶氶�夛紝鍦ㄦ澶勫墠鍚庢嫾鎺ラ�楀彿 + String roleCompany = "," + roleFs.getString(CmnConst.ORG_LEVEL_UUID) + ","; + // 鍒ゆ柇瑙掕壊鏄惁鏈夊鍏ユ暟鎹殑鍏徃 + if (roleCompany.contains("," + org_level_uuid + ",")) { + String role_uuid = roleFs.getString("role_uuid"); + if (!StringUtils.isEmpty(roleUuid)) { + roleUuid += ","; + } + roleUuid += role_uuid; + continue roleFor; + } + } + // 娌℃湁鎵惧埌瑙掕壊鏁版嵁 鎶涘嚭閿欒 + roleNotExist.method(fs, roleName); + } + + } + } + + /** + * 鑾峰彇鏁版嵁浣嶇疆瀵硅薄 + * + * @param fse + * @return + */ + private DataLocation getDataLocation(FieldSetEntity fse) { + if (fse.getString("~dataLocation~") != null) { + return (DataLocation) fse.getObject("~dataLocation~"); + } else { + DataLocation dataLocation = new DataLocation(fse); + fse.setValue("~dataLocation~", dataLocation); + return dataLocation; + } + } + + /** + * 鍒濆鍖栨満鏋勬暟鎹� + * + * @param fse + * @param level_type + */ + public void initOrganizationFieldSet(FieldSetEntity fse, String client_uuid, String parentCode, + int level_type) { + fse.setValue(CmnConst.FIELD_ORG_LEVEL_CODE_PARENT, parentCode); + fse.setValue(CmnConst.FIELD_ORG_LEVEL_CODE, BaseUtil.createCode(fse, CmnConst.TABLE_PRODUCT_SYS_ORG_LEVELS, CmnConst.FIELD_ORG_LEVEL_CODE, parentCode)); + BaseUtil.createCreatorAndCreationTime(fse); + fse.remove(CmnConst.ORG_LEVEL_UUID); + fse.setValue(CmnConst.CLIENT_UUID, client_uuid); + fse.setValue(CmnConst.FIELD_ORG_LEVEL_STATUS, 0); + fse.setValue(CmnConst.FIELD_ORG_LEVEL_TYPE, level_type); + fse.setCodeFieldUpdateFlat(CmnConst.FIELD_ORG_LEVEL_CODE, false); + } + + public void managerPermissionValidation(ImportErrorEntity errorEntity, SystemUser user) throws + BaseException { + FieldSetEntity managerFieldSet = user.getCurrentManager(); + if (managerFieldSet == null || user.getUserType() != 2) { + errorEntity.newThrowBaseException("娌℃湁瀵煎叆姝ゆ暟鎹殑鏉冮檺锛岃鑱旂郴缁熺鐞嗗憳"); + } else if (StringUtils.isEmpty(managerFieldSet.getString(CmnConst.ORG_LEVEL_UUID))) { + errorEntity.newThrowBaseException("鍏徃鏉冮檺涓嶅瓨鍦紝璇疯仈绯荤粺绠$悊鍛�"); + } + } + + + /** + * 閿欒浣嶇疆 + */ + class DataLocation { + + //褰撳墠琛� + private Integer rowIndex; + //鍒楀悕 + private List<String> colNameList; + //瀛楁鍒楃储寮� + private Map<String, String> fieldIndex; + + DataLocation(FieldSetEntity fse) { + //褰撳墠琛� + this.rowIndex = fse.getInteger("~row~"); + //鍒楀悕 + this.colNameList = (List<String>) fse.getObject("~colName~"); + //瀛楁鍒楃储寮� + this.fieldIndex = (Map<String, String>) fse.getObject("~fieldIndex~"); + } + + /** + * 鑾峰彇褰撳墠琛岀储寮� + * + * @return + */ + public Integer getRowIndex() { + return rowIndex + 1; + } + + /** + * 鑾峰彇褰撳墠鍒楃储寮� + * + * @param fieldName + * @return + */ + public String getColIndex(String fieldName) { + if (fieldIndex == null || StringUtils.isEmpty(fieldName)) { + return null; + } + String colIndex = fieldIndex.get(fieldName); + return !StringUtils.isEmpty(colIndex) ? String.valueOf(Integer.valueOf(colIndex) + 1) : "鏈煡"; + } + + /** + * 鑾峰彇褰撳墠鍒楀悕绉� + * + * @param fieldName + * @return + */ + public String getColName(String fieldName) { + String colIndex = getColIndex(fieldName); + if (this.colNameList == null || colIndex == null || "鏈煡".equals(colIndex)) { + return "鏈煡鍒楀悕"; + } + return colNameList.get(Integer.valueOf(colIndex) - 1); + } + + + } + + + static class ImportErrorEntity { + + interface errorMsg { + errorMsg append(Object errorMsg); + } + + private Map<Integer, String> errorMap; + + private boolean isError = false; + + /** + * 鏂板閿欒 鑷姩鎹㈣ + * + * @param row + * @param errorMsg + * @return + */ + public errorMsg addError(int row, String errorMsg) { + if (errorMap == null) { + errorMap = Maps.newHashMap(); + } + isError = true; + String error = errorMap.get(row); + if (!StringUtils.isEmpty(error)) { + error += "\n"; + } else { + error = ""; + } + error += errorMsg; + errorMap.put(row, error); + return (emg) -> this.append(row, String.valueOf(emg)); + } + + /** + * 鍚堝苟閿欒 + * + * @param errorEntity + * @return + */ + public ImportErrorEntity mergeError(ImportErrorEntity errorEntity) { + Map<Integer, String> errorMap = errorEntity.errorMap; + if (errorEntity.isError) { + if (this.errorMap == null) { + this.errorMap = errorMap; + this.isError = true; + return this; + } else { + errorMap.forEach((k, v) -> { + String error = this.errorMap.get(k); + if (!StringUtils.isEmpty(error)) { + error += "\n"; + } else { + error = ""; + } + error += v; + this.isError = true; + this.errorMap.put(k, error); + }); + } + } + return this; + } + + /** + * 鎷兼帴閿欒 + * + * @param row + * @param errorMsg + * @return + */ + public errorMsg append(int row, String errorMsg) { + if (errorMap == null) { + errorMap = Maps.newHashMap(); + } + isError = true; + String error = errorMap.get(row); + if (StringUtils.isEmpty(error)) { + error = ""; + } + error += errorMsg; + errorMap.put(row, error); + return (emg) -> this.append(row, String.valueOf(emg)); + } + + public void newThrowBaseException() { + newThrowBaseException(null, null); + } + + public void newThrowBaseException(String msg, Exception exception) { + if (!StringUtils.isEmpty(msg)) { + throw new BaseException(CmnCode.UPLOAD_TEMPLATE_IMPORT_DATA_FAIL.getValue(), msg); + } else if (errorMap != null) { + List<Integer> es = Lists.newArrayList(errorMap.keySet().iterator()); + StringBuilder errorMsg = new StringBuilder(); + for (Integer e : es) { + String error = errorMap.get(e); + if (!StringUtils.isEmpty(error)) { + errorMsg.append(error).append("\n"); + } + } + if (errorMsg.length() > 0) { + if (exception != null) { + throw new BaseException(CmnCode.UPLOAD_TEMPLATE_IMPORT_DATA_FAIL.getValue(), errorMsg.toString(), exception); + } else { + throw new BaseException(CmnCode.UPLOAD_TEMPLATE_IMPORT_DATA_FAIL.getValue(), errorMsg.toString()); + } + } + throw new BaseException(CmnCode.UPLOAD_TEMPLATE_IMPORT_DATA_FAIL.getValue(), " 鏈煡閿欒锛岃鑱旂郴绠$悊鍛橈紝error message is empty for 'throwExportDataError' Method "); + } + if (exception != null) { + throw new BaseException(CmnCode.UPLOAD_TEMPLATE_IMPORT_DATA_FAIL.getValue(), " 鏈煡閿欒锛岃鑱旂郴绠$悊鍛橈紝error message is empty for 'throwExportDataError' Method ", exception); + } + throw new BaseException(CmnCode.UPLOAD_TEMPLATE_IMPORT_DATA_FAIL.getValue(), " 鏈煡閿欒锛岃鑱旂郴绠$悊鍛橈紝error message is empty for 'throwExportDataError' Method "); + } + + public void newThrowBaseException(String msg) { + newThrowBaseException(msg, null); + } + + } +} diff --git a/product-server-data-export-import/src/main/java/com/product/module/data/service/SystemDataExportService.java b/product-server-data-export-import/src/main/java/com/product/module/data/service/SystemDataExportService.java new file mode 100644 index 0000000..b1de6a9 --- /dev/null +++ b/product-server-data-export-import/src/main/java/com/product/module/data/service/SystemDataExportService.java @@ -0,0 +1,329 @@ +package com.product.module.data.service; + +import com.alibaba.excel.EasyExcel; +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONArray; +import com.alibaba.fastjson.JSONObject; +import com.google.common.collect.Lists; +import com.product.core.config.CoreConst; +import com.product.core.dao.BaseDao; +import com.product.core.entity.DataTableEntity; +import com.product.core.entity.FieldSetEntity; +import com.product.core.entity.RequestParameterEntity; +import com.product.core.exception.BaseException; +import com.product.core.service.support.AbstractBaseService; +import com.product.module.data.config.CmnCode; +import com.product.module.data.config.CmnConst; +import com.product.module.data.utli.*; +import org.apache.poi.ss.usermodel.*; +import org.apache.poi.xssf.usermodel.*; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import org.springframework.web.context.request.RequestContextHolder; +import org.springframework.web.context.request.ServletRequestAttributes; + +import javax.servlet.ServletOutputStream; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import java.io.*; +import java.net.URLEncoder; +import java.util.*; + +/** + * @Author cheng + * @Description 鏁版嵁瀵煎嚭service + * @Date 2021/6/10 15:02 + * @Version 1.0 + */ +@Service +public class SystemDataExportService extends AbstractBaseService { + @Autowired + SystemApiToMethods systemApiToMethods; + + @Override + public BaseDao getBaseDao() { + return super.getBaseDao(); + } + + public void reportDataExport(FieldSetEntity fse) throws BaseException { + //鎶ヨ〃uuid + String uuid = fse.getUUID(); + //鏄惁褰撳墠椤� + boolean exportCurrentPage = fse.getBoolean("exportCurrentPage"); + //褰撳墠椤靛彿 + int pageIndex = fse.getInteger(CmnConst.CPAGE); + + } + + /** + * 鏁版嵁鎶ヨ〃瀵煎嚭 + * + * @param reqp + * @return 杩斿洖Base64 EXCEL.XLSX + * @throws BaseException + * @throws IOException + */ + public String reportDataExport(RequestParameterEntity reqp) throws BaseException { + + FieldSetEntity formData = reqp.getFormData(); + //鎬诲垪鏁� + Integer totalColumn = formData.getInteger("totalColumn"); + //鎬昏鏁� + Integer totalRows = formData.getInteger("totalRows"); + //澶撮儴鍖哄煙琛屾暟 + Integer headCount = formData.getInteger("headCount"); + Map<String, File> files = reqp.getFiles(); + //鍥哄畾鏂囦欢鍚� + File portExcel = files.get("portExcel.xlsx"); + try (InputStream inputStream = new FileInputStream(portExcel); XSSFWorkbook wb = new XSSFWorkbook(inputStream)) { + XSSFSheet sheet = wb.getSheetAt(0); + //鑾峰彇澶撮儴鏍峰紡 + XSSFCellStyle headStyle = getReportStyle(wb, IndexedColors.BLACK.getIndex(), true, (short) 15, new java.awt.Color(191, 191, 191)); + //鑾峰彇鏁版嵁鍖烘牱寮� + XSSFCellStyle dataStyle = getReportStyle(wb, IndexedColors.BLACK.getIndex(), false, (short) 13, new java.awt.Color(255, 255, 255)); + //鎵�鏈夊悓鍒楁渶瀹� + Map<Integer, Integer> m = new HashMap<>(); + for (int i = 0; i < totalRows; i++) { + XSSFRow row = sheet.getRow(i); + XSSFCellStyle style = null; + if (i < headCount) { + //澶撮儴鍖哄煙鏍峰紡 + style = headStyle; + } else { + //鏁版嵁鍖烘牱寮� + style = dataStyle; + } + //閬嶅巻姣忎竴涓崟鍏冩牸 + for (int j = 0; j < totalColumn; j++) { + //鑾峰彇鍗曞厓鏍煎璞� + XSSFCell cell = row.getCell(j); + if (cell == null) { + //濉厖绌虹殑鍗曞厓鏍� + cell = row.createCell(j, CellType.STRING); + } + //璁剧疆鍗曞厓鏍兼牱寮� + cell.setCellStyle(style); + //鑾峰彇鍗曞厓鏍煎�� + String val = cell.getStringCellValue(); + if (val != null) { + //鏍规嵁瀛楄妭璁$畻澶ц嚧瀹藉害 + int i2 = val.getBytes().length * 256; + //瀹藉害涓嶈兘瓒呰繃 256*256 + if (i2 > 256 * 256) { + i2 = 256 * 255; + } + if (m.get(j) == null) { + m.put(j, i2); + } else { + //褰撳墠琛岀殑鍒楁槸鍚︽瘮鍏朵粬琛岀殑鍒楀 + Integer width = m.get(j); + if (width < i2) { + m.put(j, i2); + } + } + } + + } + } + //璁剧疆姣忓垪鐨勫搴� + for (Map.Entry<Integer, Integer> v : m.entrySet()) { + sheet.setColumnWidth(v.getKey(), v.getValue()); + } + //灏唚orkbook杞崲涓哄瓧鑺傛祦 + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + //灏唀xcel杈撳嚭鍒板瓧鑺傛祦 + wb.write(byteArrayOutputStream); + //灏嗗瓧鑺傛祦杞负瀛楄妭 + byte[] bytes = byteArrayOutputStream.toByteArray(); + //灏嗗瓧鑺傝浆鎹负Base64 + String encode = Base64.getEncoder().encodeToString(bytes); + //鍒犻櫎浼犲叆鐨勬枃浠� + if (portExcel != null && portExcel.exists()) { + portExcel.delete(); + } + //杩斿洖Base64瀛楃涓� 鎷兼帴XLSX鏂囦欢鏍煎紡鍓嶇紑 + return "data:application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;base64," + encode; + } catch (Exception e) { + throw new BaseException(CmnCode.EXPORT_REPORT_DATA_FIAL.getValue(), CmnCode.EXPORT_REPORT_DATA_FIAL.getValue() + e.getMessage()); + } + } + + /** + * 鍗曞厓鏍兼牱寮� + * + * @param workbook + * @param color 瀛椾綋棰滆壊 + * @param bold 鏄惁鍔犵矖 + * @param fontSize 瀛椾綋澶у皬 + * @param bgc 鑳屾櫙鑹� + * @return + */ + public XSSFCellStyle getReportStyle(XSSFWorkbook workbook, short color, boolean bold, short fontSize, java.awt.Color bgc) { + XSSFCellStyle cellStyle = workbook.createCellStyle(); + //宸﹀彸灞呬腑 + cellStyle.setAlignment(HorizontalAlignment.CENTER); + //涓婁笅灞呬腑 + cellStyle.setVerticalAlignment(VerticalAlignment.CENTER); + // 涓嬭竟妗� + cellStyle.setBorderBottom(BorderStyle.THIN); + // 宸﹁竟妗� + cellStyle.setBorderLeft(BorderStyle.THIN); + // 涓婅竟妗� + cellStyle.setBorderTop(BorderStyle.THIN); + // 鍙宠竟妗� + cellStyle.setBorderRight(BorderStyle.THIN); + //璁剧疆鑳屾櫙鑹� +// cellStyle.setFillForegroundColor(new XSSFColor()); + //濉厖妯″紡 + cellStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND); + XSSFFont font = workbook.createFont(); + //瀛椾綋棰滆壊 + font.setColor(color); + //鍔犵矖 + font.setBold(bold); + //瀛椾綋澶у皬 + font.setFontHeightInPoints(fontSize); + //瀛椾綋鏍峰紡 + font.setFontName("寰蒋闆呴粦"); + //鑷姩鎹㈣ + cellStyle.setWrapText(true); + cellStyle.setFont(font); + return cellStyle; + } + + + /** + * 閫氱敤鍒楄〃瀵煎嚭 + * + * @param fse + * @throws BaseException + */ + public void generalListDataExport(FieldSetEntity fse) throws BaseException { + //瀵煎嚭鏂囦欢鍚嶇О + String file_name = fse.getString(CmnConst.FILE_NAME); + //鏁版嵁鎺ュ彛 + String upload_api_url = fse.getString(CmnConst.UPLOAD_API_URL); + //鏁版嵁鎺ュ彛鎵�闇�鍙傛暟 + FieldSetEntity export_param = fse.getSubDataTable(CmnConst.EXPORT_PARAM).getFieldSetEntity(0); + HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest(); + RequestParameterEntity requestParameterEntity = (RequestParameterEntity) request.getAttribute(CoreConst.API_POST_REQUEST_DATA); + FieldSetEntity fs = new FieldSetEntity(); + fs.setTableName(fse.getString(CmnConst.TABLE_NAME)); + //寮�濮嬮〉 + int start_cpage = export_param.getInteger(CmnConst.START_CPAGE); + //缁撴潫椤� + int end_cpage = export_param.getInteger(CmnConst.END_CPAGE); + int pagesize = export_param.getInteger(CmnConst.PAGESIZE); + export_param.setValue(CmnConst.CPAGE, ((start_cpage) * pagesize) / pagesize); + export_param.setValue(CmnConst.PAGESIZE, pagesize * ((end_cpage - start_cpage) + 1)); + export_param.remove(CmnConst.START_CPAGE); + export_param.remove(CmnConst.END_CPAGE); + Map<Object, Object> values = export_param.getValues(); + for (Map.Entry<Object, Object> v : values.entrySet()) { + fs.setValue(v.getKey().toString(), v.getValue()); + } + requestParameterEntity.setFormData(fs); + String result = (String) systemApiToMethods.run(upload_api_url, 1); + + if (JSON.isValidObject(result)) { + JSONObject resultJson = JSON.parseObject(result); + if (200 == resultJson.getInteger("code")) { + //鑾峰彇鏁版嵁鎴愬姛 + Object data = resultJson.get("data"); + if (data instanceof JSONObject) { + } else if (data instanceof JSONArray) { + DataTableEntity export_field = export_param.getSubDataTable("export_field"); + try { + writeExcel((JSONArray) data, export_field, file_name); + } catch (Exception e) { + e.printStackTrace(); + } + } + } else { + throw new BaseException(resultJson.getString("code"), resultJson.getString("msg")); + } + } else { + System.out.println("鏈煡鐨勬暟鎹被鍨�"); + } + } + + /** + * 杈撳嚭excel + * + * @param data + * @param fieldInfo + * @param main_title + * @throws IOException + */ + public void writeExcel(JSONArray data, DataTableEntity fieldInfo, String main_title) throws IOException { + //鏍囬 + List<List<String>> headTitles = Lists.newArrayList(); + List<String> fields = Lists.newArrayList(); + //瀵煎嚭鐨勬暟鎹泦 + List<String> titles = Lists.newArrayList(); + List<String> titleTemplate = Lists.newArrayList(); + titleTemplate.add(main_title); + for (int i = 0; i < fieldInfo.getRows(); i++) { + titles.add(fieldInfo.getString(i, CmnConst.FIELD_DESC)); + fields.add(fieldInfo.getString(i, CmnConst.FIELD_NAME)); + } + List<List<Object>> lists = contentData(data, fields); + titles.forEach(title -> { + List<String> secondTitle = Lists.newArrayList(titleTemplate); + secondTitle.add(title); + headTitles.add(secondTitle); + }); + HttpServletResponse response = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getResponse(); + response.setContentType("multipart/form-data"); + response.setCharacterEncoding("utf-8"); + // 杩欓噷URLEncoder.encode鍙互闃叉涓枃涔辩爜 褰撶劧鍜宔asyexcel娌℃湁鍏崇郴 + writeExcel(headTitles, lists, main_title, response); + } + + /** + * 杈撳嚭excel + * + * @param excelHeaders excel琛ㄥご + * @param dataRows 鏁版嵁琛� + * @param sheetName sheet鍚嶇О + * @throws IOException + */ + public void writeExcel(List<List<String>> excelHeaders, List dataRows, String sheetName, HttpServletResponse response) throws IOException { + + response.setContentType("multipart/form-data"); + response.setCharacterEncoding("utf-8"); + //鍏佽璁块棶header涓殑鑷畾涔夊弬鏁� + response.setHeader("Access-Control-Expose-Headers", "Content-Disposition"); + //璁剧疆鏂囦欢鍚� + response.setHeader("Content-disposition", "attachment;filename=" + URLEncoder.encode(sheetName + System.currentTimeMillis() + ".xlsx", "UTF-8")); + // 杩欓噷URLEncoder.encode鍙互闃叉涓枃涔辩爜 褰撶劧鍜宔asyexcel娌℃湁鍏崇郴 + // 杩欓噷闇�瑕佽缃笉鍏抽棴娴� + try (ServletOutputStream outputStream = response.getOutputStream();) { + EasyExcel.write(outputStream). + registerWriteHandler(new Custemhandler()).head(excelHeaders).sheet(sheetName).doWrite(dataRows); + } + } + + + /** + * 缁勮鏁版嵁 + * + * @param dataArray + * @param fields + * @return + */ + private static List<List<Object>> contentData(JSONArray dataArray, List<String> fields) { + List<List<Object>> contentList = Lists.newArrayList(); + dataArray.forEach(data -> { + JSONObject dataJson = (JSONObject) data; + List<Object> content = Lists.newArrayList(); + fields.forEach(field -> { + content.add(dataJson.get(field)); + }); + contentList.add(content); + }); + return contentList; + } + + +} diff --git a/product-server-data-export-import/src/main/java/com/product/module/data/service/SystemDataUpLoadService.java b/product-server-data-export-import/src/main/java/com/product/module/data/service/SystemDataUpLoadService.java new file mode 100644 index 0000000..abf6013 --- /dev/null +++ b/product-server-data-export-import/src/main/java/com/product/module/data/service/SystemDataUpLoadService.java @@ -0,0 +1,882 @@ +package com.product.module.data.service; + + +import cn.hutool.core.util.NumberUtil; +import cn.hutool.core.util.ReflectUtil; +import cn.hutool.extra.spring.SpringUtil; +import com.alibaba.fastjson.JSONObject; +import com.google.common.collect.Lists; +import com.google.common.collect.Maps; +import com.google.common.collect.Sets; +import com.product.common.collect.SetUtils; +import com.product.common.excel.EasyExcelUtil; +import com.product.common.lang.StringUtils; +import com.product.core.cache.DataPoolCacheImpl; +import com.product.core.config.Global; +import com.product.core.dao.BaseDao; +import com.product.core.entity.DataTableEntity; +import com.product.core.entity.FieldMetaEntity; +import com.product.core.entity.FieldSetEntity; +import com.product.core.entity.RequestParameterEntity; +import com.product.core.exception.BaseException; +import com.product.core.permission.PermissionService; +import com.product.core.service.support.AbstractBaseService; +import com.product.core.service.support.QueryFilterService; +import com.product.core.spring.context.SpringMVCContextHolder; +import com.product.core.transfer.Transactional; +import com.product.file.service.FileManagerService; +import com.product.module.data.config.CmnCode; +import com.product.module.data.config.CmnConst; +import com.product.module.data.service.idel.ISystemDataUpLoadService; +import com.product.module.sys.entity.SystemUser; +import com.product.util.BaseUtil; +import com.product.util.SystemParamReplace; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import javax.servlet.http.HttpServletResponse; +import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; +import java.io.InputStream; +import java.lang.reflect.Method; +import java.lang.reflect.ParameterizedType; +import java.lang.reflect.Type; +import java.util.*; + +@Service +public class SystemDataUpLoadService extends AbstractBaseService implements ISystemDataUpLoadService { + @Autowired + private BaseDao baseDao; + @Autowired + private FileManagerService fileManagerService; + @Autowired + private QueryFilterService queryFilterService; + + @Autowired + private PermissionService permissionService; + + public List<Map<String, Object>> getPrompt() throws BaseException { + StringBuilder sql = new StringBuilder(); + sql.append(" select prompt_name `value` ,prompt_name `label` ,'prompt' type FROM product_sys_prompt "); + sql.append(" union all "); + sql.append(" select concat('銆�',dict_name,'銆�') dict_name,dict_name,'dict' type FROM product_sys_dict where is_used=1 group by dict_name "); + FieldSetEntity f = new FieldSetEntity(); + f.setTableName("x"); + f.setValue("desc", "楂樼骇鍙傜収锛屾櫘閫氬弬鐓�"); + DataTableEntity dt = baseDao.listTable(sql.toString(), new Object[]{}); + List<Map<String, Object>> result = Lists.newArrayList(); + if (!BaseUtil.dataTableIsEmpty(dt)) { + List<Map<String, Object>> promptList = Lists.newArrayList(); + List<Map<String, Object>> dictList = Lists.newArrayList(); + Map<String, Object> item; + for (int i = 0; i < dt.getRows(); i++) { + String type = dt.getString(i, "type"); + String value = dt.getString(i, "value"); + String label = dt.getString(i, "label"); + item = Maps.newHashMap(); + item.put("value", value); + item.put("label", label); + if ("prompt".equals(type)) { + promptList.add(item); + } else { + dictList.add(item); + } + } + item = Maps.newHashMap(); + item.put("label", "楂樼骇鍙傜収"); + item.put("children", promptList); + item.put("value", "~楂樼骇鍙傜収~"); + result.add(item); + item = Maps.newHashMap(); + item.put("label", "鏅�氬弬鐓�"); + item.put("children", dictList); + item.put("value", "~鏅�氬弬鐓"); + result.add(item); + } + return result; + } + + + /** + * 妯℃澘涓婁紶 + * + * @param rpe + * @return + */ + @Override + @Transactional + public JSONObject uploadTemplate(RequestParameterEntity rpe) { + FieldSetEntity paramFse = rpe.getFormData(); + String sourceFileName = paramFse.getString(CmnConst.FIELD_TEMPLATE_INFO); + if (StringUtils.isEmpty(sourceFileName) || !sourceFileName.endsWith(".xlsx")) { + throw new BaseException(CmnCode.UPLOAD_TEMPLATE_NOT_ALLOWED_FORMAT.getValue(), CmnCode.UPLOAD_TEMPLATE_NOT_ALLOWED_FORMAT.getText()); + } + + FieldSetEntity fse = fileManagerService.uploadFile(rpe); + JSONObject resultObj = new JSONObject(); + resultObj.put(CmnConst.FIELD_TEMPLATE_INFO, fse.getString(CmnConst.FIELD_TEMPLATE_INFO)); + return resultObj; + } + + /** + * 瑙f瀽妯℃澘锛岃幏鍙朎xcel琛ㄥご淇℃伅 + * + * @param fse + * @return + */ + public JSONObject analysisTemplate(FieldSetEntity fse) { + String attachmentUUID = fse.getString(CmnConst.FIELD_TEMPLATE_INFO); + DataTableEntity modelDte = null; + + String modelUUID = fse.getUUID(); + boolean needAnalysisFlag = true; + if (!StringUtils.isEmpty(modelUUID)) { + FieldSetEntity preModelFse = baseDao.getFieldSetEntity(CmnConst.TABLE_PRODUCT_SYS_DATA_UPLOAD_MODEL, modelUUID, true); + String preAttachmentUUID = preModelFse.getString(CmnConst.FIELD_TEMPLATE_INFO); + modelDte = baseDao.listTable(CmnConst.TABLE_PRODUCT_SYS_DATA_UPLOAD_MODEL, "upload_sign=?", new Object[]{preModelFse.getString(CmnConst.FIELD_UPLOAD_SIGN)}, null, null, Integer.MAX_VALUE, 1, true); + if (preAttachmentUUID.equals(attachmentUUID)) { + // 鍚屾牱鐨勬枃浠讹紝涓嶉渶瑕侀噸鏂拌В鏋� + needAnalysisFlag = false; + } + } + + FieldSetEntity attachmentFse = baseDao.getFieldSetEntity(CmnConst.TABLE_PRODUCT_SYS_ATTACHMENT, attachmentUUID, false); + if (needAnalysisFlag) { + // 闇�瑕侀噸鏂拌В鏋� + String relativePath = attachmentFse.getString(CmnConst.FIELD_ATTACHMENT_URL); + String templateName = attachmentFse.getString(CmnConst.FIELD_ATTACHMENT_TITLE); + String path = Global.getSystemConfig("local.dir", "") + File.separator + relativePath + File.separator + templateName; + File templateFile = new File(path); + // 鍒涘缓鏂囦欢娴佹搷浣滃璞� + try (InputStream inputStream = new FileInputStream(templateFile)) { + Map<String, List<List<String>>> map = EasyExcelUtil.readExcelByStringFromInputStream(inputStream, null); + DataTableEntity subDte; + Map<String, FieldSetEntity> subMap; + FieldSetEntity mainFse; + FieldSetEntity subFse; + List<List<String>> list; + int index = 0; + for (Map.Entry<String, List<List<String>>> entry : map.entrySet()) { + list = entry.getValue(); + if (list.isEmpty()) { + continue; + } + subDte = new DataTableEntity(); + mainFse = null; + for (String excelHeader : list.get(list.size() - 1)) { + if (StringUtils.isEmpty(excelHeader)) { + throw new BaseException(CmnCode.UPLOAD_TEMPLATE_EXISTS_EMPTY_COL.getValue(), CmnCode.UPLOAD_TEMPLATE_EXISTS_EMPTY_COL.getText()); + } + subFse = null; + if (modelDte != null && modelDte.getRows() > index) { + mainFse = modelDte.getFieldSetEntity(index); + subMap = dte2Map(mainFse.getSubDataTable(CmnConst.TABLE_PRODUCT_SYS_DATA_UPLOAD_MODEL_SUB), CmnConst.FIELD_EXCEL_HEADER); + if (subMap.containsKey(excelHeader)) { + // 鍘熸湁鐨勫瓧娈� + subFse = subMap.get(excelHeader); + } + } + if (subFse == null) { + // 鏈韩娌℃湁鐨勫瓧娈� + subFse = new FieldSetEntity(); + subFse.setTableName(CmnConst.TABLE_PRODUCT_SYS_DATA_UPLOAD_MODEL_SUB); + subFse.setValue(CmnConst.FIELD_EXCEL_HEADER, excelHeader); + } + subDte.addFieldSetEntity(subFse); + } + if (mainFse == null) { + mainFse = new FieldSetEntity(); + mainFse.setTableName(CmnConst.TABLE_PRODUCT_SYS_DATA_UPLOAD_MODEL); + if (modelDte == null) { + modelDte = new DataTableEntity(); + } + modelDte.addFieldSetEntity(mainFse); + } else { + mainFse.removeSubData(CmnConst.TABLE_PRODUCT_SYS_DATA_UPLOAD_MODEL_SUB); + } + mainFse.setValue("start_row_index", list.size() - 1); + mainFse.addSubDataTable(subDte); + index++; + } + } catch (Exception e) { + e.printStackTrace(); + throw new BaseException(CmnCode.UPLOAD_TEMPLATE_GET_INFO_FAIL.getValue(), CmnCode.UPLOAD_TEMPLATE_GET_INFO_FAIL.getText()); + } + } + + JSONObject resultObj = new JSONObject(); + resultObj.put("sheet_info", BaseUtil.dataTableEntityToJson(modelDte)); + resultObj.put(CmnConst.FIELD_UPLOAD_SIGN, SpringMVCContextHolder.getCurrentUser().getClient_uuid() + "_" + attachmentFse.getString(CmnConst.FIELD_ATTACHMENT_TITLE) + "_" + System.currentTimeMillis()); + return resultObj; + } + + /** + * 淇濆瓨 + * + * @param fse + */ + @Override + @Transactional + public void saveTemplate(FieldSetEntity fse) { + if (StringUtils.isEmpty(fse.getUUID())) { + addTemplate(fse); + } else { + updateTemplate(fse); + } + } + + /** + * 鏂板妯℃澘 + * + * @param fse + */ + private void addTemplate(FieldSetEntity fse) { + SystemUser curUser = SpringMVCContextHolder.getCurrentUser(); + String orgLevelUUID = curUser.getOrg_level_uuid(); + String clientUUID = curUser.getClient_uuid(); + String attachmentUUID = fse.getString(CmnConst.FIELD_TEMPLATE_INFO); + FieldSetEntity attachmentFse = baseDao.getFieldSetEntity(CmnConst.TABLE_PRODUCT_SYS_ATTACHMENT, attachmentUUID, false); + String uploadSign = clientUUID + "_" + attachmentFse.getString(CmnConst.FIELD_ATTACHMENT_TITLE) + "_" + System.currentTimeMillis(); + int sheetOrder = 1; + fse.setValue(CmnConst.FIELD_SHEET_ORDER, sheetOrder); + fse.setValue(CmnConst.FIELD_UPLOAD_SIGN, uploadSign); + // 淇濆瓨鏁版嵁瀵煎叆妯℃澘淇℃伅 + DataTableEntity modelDte = fse.getSubDataTable(CmnConst.TABLE_PRODUCT_SYS_DATA_UPLOAD_MODEL); + if (!BaseUtil.dataTableIsEmpty(modelDte)) { + FieldSetEntity tempFse; + for (int i = 0; i < modelDte.getRows(); i++) { + tempFse = modelDte.getFieldSetEntity(i); + tempFse.setValue(CmnConst.FIELD_UPLOAD_SIGN, uploadSign); + tempFse.setValue(CmnConst.FIELD_SHEET_ORDER, ++sheetOrder); + BaseUtil.addOrgLeveLUUID(tempFse, Collections.singletonList(CmnConst.TABLE_PRODUCT_SYS_DATA_UPLOAD_MODEL_SUB), orgLevelUUID, curUser); + baseDao.saveFieldSetEntity(tempFse); + } + fse.removeSubData(CmnConst.TABLE_PRODUCT_SYS_DATA_UPLOAD_MODEL); + } + BaseUtil.addOrgLeveLUUID(fse, Collections.singletonList(CmnConst.TABLE_PRODUCT_SYS_DATA_UPLOAD_MODEL_SUB), orgLevelUUID, curUser); + baseDao.saveFieldSetEntity(fse); + + String mvcUUID = fse.getString(CmnConst.FIELD_FUNCTION_UUID); + String buttonTitle = fse.getString(CmnConst.FILED_BUTTON_TITLE); + // todo 寰呮祴璇曪紝鍒涘缓mvc鐩稿叧鍐呭 + dealMvcInfo(mvcUUID, buttonTitle, uploadSign); + } + + /** + * 澶勭悊mvc涓鍏ラ厤缃俊鎭� + * + * @param mvcUUID + * @param buttonTitle + */ + private void dealMvcInfo(String mvcUUID, String buttonTitle, String uploadSign) { + FieldSetEntity firstPageFse = getFirstPageFse(mvcUUID); + if (firstPageFse == null) { + throw new BaseException(CmnCode.GET_MVC_FIRST_PAGE_INFO_FAIL.getValue(), CmnCode.GET_MVC_FIRST_PAGE_INFO_FAIL.getText()); + } + FieldSetEntity preImportButtonFse = getImportButtonFse(firstPageFse, mvcUUID); + + SystemUser curUser = SpringMVCContextHolder.getCurrentUser(); + if (preImportButtonFse == null) { + // 鏈韩娌℃湁瀵煎叆鎸夐挳锛岃嚜鍔ㄥ垱寤� todo + + // 鎸夐挳 + FieldSetEntity importButtonFse = new FieldSetEntity(); + importButtonFse.setTableName(CmnConst.TABLE_PRODUCT_SYS_BUTTONS); + importButtonFse.setValue(CmnConst.FILED_FUNCTION_UUID, mvcUUID); + importButtonFse.setValue(CmnConst.FILED_BUTTON_NAME, "default_import"); + importButtonFse.setValue(CmnConst.FILED_BUTTON_TITLE, buttonTitle); + importButtonFse.setValue(CmnConst.FILED_STATUS_UUID, 1); + importButtonFse.setValue(CmnConst.FILED_CATEGORY_UUID, "import"); + importButtonFse.setValue(CmnConst.FILED_CLIENT_TYPE_UUID, "Web"); + importButtonFse.setValue(CmnConst.FILED_ROUTE_NAME, BaseUtil.getPageCode()); + importButtonFse.setValue("params", "{\"upload_sign\":\"" + uploadSign + "\"}"); + importButtonFse.setValue("button_category_uuid", "import"); + importButtonFse.setValue("button_type", 2); + importButtonFse.setValue("is_main", 0); + BaseUtil.createCreatorAndCreationTime(curUser, importButtonFse); + baseDao.saveFieldSetEntity(importButtonFse); + +// // 椤甸潰 +// FieldSetEntity importPageFse = new FieldSetEntity(); +// importPageFse.setTableName(CmnConst.TABLE_PRODUCT_SYS_MVC_PAGE); +// importPageFse.setValue(CmnConst.FILED_FUNCTION_UUID, mvcUUID); +// importPageFse.setValue(CmnConst.FIELD_PAGE_NAME, "榛樿瀵煎叆椤甸潰"); +// importPageFse.setValue(CmnConst.FIELD_PAGE_TYPE, 2); +// importPageFse.setValue(CmnConst.FIELD_PAGE_TYPE, 2); +// BaseUtil.createCreatorAndCreationTime(curUser, importPageFse); +// baseDao.saveFieldSetEntity(importPageFse); + + // 杩炵嚎-鍒楄〃鐣岄潰-瀵煎叆鎸夐挳 + FieldSetEntity importLinkFse1 = new FieldSetEntity(); + importLinkFse1.setTableName(CmnConst.TABLE_PRODUCT_SYS_MVC_LINK); + importLinkFse1.setValue(CmnConst.FILED_FUNCTION_UUID, mvcUUID); + importLinkFse1.setValue(CmnConst.FIELD_LINK_TYPE, 0); + importLinkFse1.setValue(CmnConst.FIELD_LINE_FROM, firstPageFse.getUUID()); + importLinkFse1.setValue(CmnConst.FIELD_FROM_TYPE, 2); + importLinkFse1.setValue(CmnConst.FIELD_LINE_TO, importButtonFse.getUUID()); + importLinkFse1.setValue(CmnConst.FIELD_TO_TYPE, 1); + BaseUtil.createCreatorAndCreationTime(curUser, importLinkFse1); + baseDao.saveFieldSetEntity(importLinkFse1); +// // 杩炵嚎-瀵煎叆鎸夐挳-瀵煎叆椤甸潰 +// FieldSetEntity importLinkFse2 = new FieldSetEntity(); +// importLinkFse2.setTableName(CmnConst.TABLE_PRODUCT_SYS_MVC_LINK); +// importLinkFse2.setValue(CmnConst.FILED_FUNCTION_UUID, mvcUUID); +// importLinkFse2.setValue(CmnConst.FIELD_LINK_TYPE, 0); +// importLinkFse2.setValue(CmnConst.FIELD_LINE_FROM, importButtonFse.getUUID()); +// importLinkFse2.setValue(CmnConst.FIELD_FROM_TYPE, 1); +// importLinkFse2.setValue(CmnConst.FIELD_LINE_TO, importPageFse.getUUID()); +// importLinkFse2.setValue(CmnConst.FIELD_TO_TYPE, 2); +// BaseUtil.createCreatorAndCreationTime(curUser, importLinkFse2); +// baseDao.saveFieldSetEntity(importLinkFse2); + } else { + // 鏈韩瀛樺湪瀵煎叆鎸夐挳锛岀洿鎺ユ浛鎹㈢浉搴旂殑鏁版嵁 todo + preImportButtonFse.setValue("", ""); + BaseUtil.updatedRegeneratorAndUpdateTime(curUser, preImportButtonFse); + baseDao.saveFieldSetEntity(preImportButtonFse); + } + } + + /** + * 鎻愬彇鎸囧畾mvc涓�愬叆鍙c�戝悗绗竴涓〉闈� + * + * @param mvcUUID + * @return + */ + private FieldSetEntity getFirstPageFse(String mvcUUID) { + StringBuilder sql = new StringBuilder(256); + sql.append("select p.* from (") + .append("\n select * FROM product_sys_function_buttons where is_main=1 and function_uuid=?") + .append("\n) b") + .append("\ninner join product_sys_link l on b.uuid=l.line_from") + .append("\ninner join product_sys_mvc_page p on l.line_to=p.uuid"); + FieldSetEntity firstPageFse = baseDao.getFieldSetEntityBySQL(sql.toString(), new Object[]{mvcUUID}, false); + return firstPageFse; + } + + /** + * 鍏ュ彛鍚庣涓�涓〉闈箣鍚庣殑瀵煎叆 + * + * @param firstPageFse + * @param mvcUUID + * @return + */ + private FieldSetEntity getImportButtonFse(FieldSetEntity firstPageFse, String mvcUUID) { + StringBuilder sql = new StringBuilder(256); + sql.append("select b.* from (") + .append("\n select * FROM product_sys_mvc_page where uuid=?") + .append("\n) p") + .append("\ninner join product_sys_link l on p.uuid=l.line_to") + .append("\ninner join (") + .append("\n select * FROM product_sys_function_buttons where function_uuid=? and button_category_uuid='import'") + .append("\n) b on l.line_from=b.uuid"); + FieldSetEntity preImportButtonFse = baseDao.getFieldSetEntityBySQL(sql.toString(), new Object[]{firstPageFse.getUUID(), mvcUUID}, false); + return preImportButtonFse; + } + + /** + * 淇敼妯℃澘 + * + * @param fse + */ + private void updateTemplate(FieldSetEntity fse) { + SystemUser curUser = SpringMVCContextHolder.getCurrentUser(); + + // 淇濆瓨鏁版嵁瀵煎叆妯℃澘淇℃伅 + DataTableEntity modelDte = fse.getSubDataTable(CmnConst.TABLE_PRODUCT_SYS_DATA_UPLOAD_MODEL); + if (!BaseUtil.dataTableIsEmpty(modelDte)) { + FieldSetEntity tempFse; + for (int i = 0; i < modelDte.getRows(); i++) { + tempFse = modelDte.getFieldSetEntity(i); + BaseUtil.updatedRegeneratorAndUpdateTime(curUser, tempFse); + baseDao.saveFieldSetEntity(tempFse); + } + } + fse.removeSubData(CmnConst.TABLE_PRODUCT_SYS_DATA_UPLOAD_MODEL); + BaseUtil.updatedRegeneratorAndUpdateTime(curUser, fse); + baseDao.saveFieldSetEntity(fse); + } + + /** + * 鏌ヨ妯℃澘閰嶇疆璇︽儏 + * + * @param fse + * @return + */ + public FieldSetEntity findTemplate(FieldSetEntity fse) { + String uploadSign = fse.getString(CmnConst.FIELD_UPLOAD_SIGN); + DataTableEntity dt = baseDao.listTable(CmnConst.TABLE_PRODUCT_SYS_DATA_UPLOAD_MODEL, "upload_sign=?", new Object[]{uploadSign}, null, "sheet_order", Integer.MAX_VALUE, 1, true); + if (!BaseUtil.dataTableIsEmpty(dt)) { + FieldSetEntity fs = new FieldSetEntity(); + fs.setTableName(CmnConst.TABLE_PRODUCT_SYS_DATA_UPLOAD_MODEL); + DataTableEntity sub = new DataTableEntity(); + for (int i = 0; i < dt.getRows(); i++) { + if (i == 0) { + fs.setValue(CmnConst.FIELD_TITLE, dt.getString(0, CmnConst.FIELD_TITLE)); + fs.setValue(CmnConst.FIELD_FUNCTION_UUID, dt.getString(0, CmnConst.FIELD_FUNCTION_UUID)); + fs.setValue(CmnConst.FILED_BUTTON_TITLE, dt.getString(0, CmnConst.FILED_BUTTON_TITLE)); + fs.setValue(CmnConst.UUID, dt.getString(0, CmnConst.UUID)); + fs.setValue(CmnConst.FIELD_UPLOAD_SIGN, dt.getString(0, CmnConst.FIELD_UPLOAD_SIGN)); + fs.setValue(CmnConst.FIELD_TEMPLATE_INFO, dt.getString(0, CmnConst.FIELD_TEMPLATE_INFO)); + } + String before_func = dt.getString(i, CmnConst.FIELD_BEFORE_FUNC); + String after_func = dt.getString(i, CmnConst.FIELD_AFTER_FUNC); + String table_name = dt.getString(i, CmnConst.TABLE_NAME); + String startRowIndex = dt.getString(i, "start_row_index"); + FieldSetEntity f = new FieldSetEntity(); + f.setTableName("sheet_info"); + f.setValue(CmnConst.FIELD_BEFORE_FUNC, before_func); + f.setValue(CmnConst.FIELD_AFTER_FUNC, after_func); + f.setValue(CmnConst.UUID, dt.getString(i, CmnConst.UUID)); + f.setValue(CmnConst.TABLE_NAME, table_name); + f.setValue("start_row_index", startRowIndex); + f.setSubData(dt.getFieldSetEntity(i).getSubData()); + sub.addFieldSetEntity(f); + } + fs.addSubDataTable(sub); + return fs; + } + return null; + } + + /** + * 妯℃澘鍙拌处-宸﹁竟鏍戠粨鏋� + * + * @param fse + * @return + */ + public DataTableEntity listTemplate(FieldSetEntity fse) { + int pageSize = fse.getInteger(CmnConst.PAGESIZE) == null ? Integer.MAX_VALUE : fse.getInteger(CmnConst.PAGESIZE); + int curPage = fse.getInteger(CmnConst.CPAGE) == null ? 1 : fse.getInteger(CmnConst.CPAGE); + SystemUser user = SpringMVCContextHolder.getCurrentUser(); + StringBuilder filter = new StringBuilder(128); + filter.append("org_level_uuid=? and length(title)>0"); + String queryFilter = queryFilterService.getQueryFilter(fse); + if (!StringUtils.isEmpty(queryFilter)) { + filter.append(" and ").append(queryFilter); + } + List<Object> paramList = Lists.newArrayList(); + paramList.add(user.getOrg_level_uuid()); + String[] filterParamArr = !StringUtils.isEmpty(fse.getString("~select_params~")) ? fse.getString("~select_params~").split(",") : null; + if (filterParamArr != null) { + Collections.addAll(paramList, filterParamArr); + } + return baseDao.listTable(fse.getTableName(), filter.toString(), paramList.toArray(), null, fse.getString(""), pageSize, curPage); + } + + /** + * 鏁版嵁涓婁紶妯℃澘鍒犻櫎 + * + * @param fse + * @throws BaseException + */ + @Override + @Transactional + public void deleteModel(FieldSetEntity fse) throws BaseException { + String uploadSign = fse.getString(CmnConst.FIELD_UPLOAD_SIGN); + DataTableEntity modelDte = baseDao.listTable(CmnConst.TABLE_PRODUCT_SYS_DATA_UPLOAD_MODEL, "upload_sign=?", new Object[]{uploadSign}); + if (BaseUtil.dataTableIsEmpty(modelDte)) { + throw new BaseException(CmnCode.UPLOAD_TEMPLATE_DELETE_FAIL.getValue(), CmnCode.UPLOAD_TEMPLATE_DELETE_FAIL.getText()); + } + FieldSetEntity mainModelFse = null; + FieldSetEntity tempFse; + List<String> uuidParamList = Lists.newArrayList(); + for (int i = 0; i < modelDte.getRows(); i++) { + tempFse = modelDte.getFieldSetEntity(i); + uuidParamList.add(tempFse.getUUID()); + if (!StringUtils.isEmpty(tempFse.getString(CmnConst.FIELD_FUNCTION_UUID))) { + mainModelFse = tempFse; + } + } + if (mainModelFse == null) { + throw new BaseException(CmnCode.UPLOAD_TEMPLATE_GET_MAIN_INFO_FAIL.getValue(), CmnCode.UPLOAD_TEMPLATE_GET_MAIN_INFO_FAIL.getText()); + } + + // 鍒犻櫎mvc鐩稿叧鐨勮〃淇℃伅 + String mvcUUID = mainModelFse.getString(CmnConst.FIELD_FUNCTION_UUID); + FieldSetEntity firstPageFse = getFirstPageFse(mvcUUID); + // 瀵煎叆鎸夐挳 + FieldSetEntity importButtonFse = baseDao.getFieldSetEntityByFilter(CmnConst.TABLE_PRODUCT_SYS_BUTTONS, "function_uuid=? and button_name='default_import'", new Object[]{mvcUUID}, false); + if (importButtonFse != null) { + // 杩炵嚎-瀵煎叆鎸夐挳-瀵煎叆椤甸潰 +// FieldSetEntity secondLinkFse = baseDao.getFieldSetEntityByFilter(CmnConst.TABLE_PRODUCT_SYS_MVC_LINK, "function_uuid=? and link_type=0 and from_type=1 and line_from=?", new Object[]{mvcUUID, importButtonFse.getUUID()}, false); + // 鍒犻櫎-瀵煎叆椤甸潰 +// baseDao.delete(CmnConst.TABLE_PRODUCT_SYS_MVC_PAGE, new Object[]{secondLinkFse.getString(CmnConst.FIELD_LINE_TO)}); + // 鍒犻櫎-杩炵嚎-瀵煎叆鎸夐挳-瀵煎叆椤甸潰 +// baseDao.delete(CmnConst.TABLE_PRODUCT_SYS_MVC_LINK, "function_uuid=? and link_type=0 and from_type=1 and line_from=?", new Object[]{mvcUUID, importButtonFse.getUUID()}); + // 鍒犻櫎-杩炵嚎-鍒楄〃鐣岄潰-瀵煎叆鎸夐挳 + baseDao.delete(CmnConst.TABLE_PRODUCT_SYS_MVC_LINK, "function_uuid=? and link_type=0 and from_type=2 and to_type=1 and line_from=? and line_to=?", new Object[]{mvcUUID, firstPageFse.getUUID(), importButtonFse.getUUID()}); + // 鍒犻櫎-瀵煎叆鎸夐挳 + baseDao.delete(CmnConst.TABLE_PRODUCT_SYS_BUTTONS, new Object[]{importButtonFse.getUUID()}); + + } + // 鍒犻櫎闄勪欢 + FieldSetEntity attachmentFse = baseDao.getFieldSetEntity(CmnConst.TABLE_PRODUCT_SYS_ATTACHMENT, mainModelFse.getString(CmnConst.FIELD_TEMPLATE_INFO), false); + if (attachmentFse != null) { + String relativePath = attachmentFse.getString(CmnConst.FIELD_ATTACHMENT_URL); + String templateName = attachmentFse.getString(CmnConst.FIELD_ATTACHMENT_TITLE); + String path = Global.getSystemConfig("local.dir", "") + File.separator + relativePath + File.separator + templateName; + File templateFile = new File(path); + templateFile.delete(); + // 鍒犻櫎闄勪欢琛� + baseDao.delete(CmnConst.TABLE_PRODUCT_SYS_ATTACHMENT, new Object[]{attachmentFse.getUUID()}); + } + // 鍒犻櫎妯℃澘瀛愯〃 + String filter = BaseUtil.buildQuestionMarkFilter(CmnConst.FIELD_MODEL_UUID, uuidParamList.size(), true); + baseDao.delete(CmnConst.TABLE_PRODUCT_SYS_DATA_UPLOAD_MODEL_SUB, filter, uuidParamList.toArray()); + // 鍒犻櫎妯℃澘涓昏〃 + baseDao.delete(CmnConst.TABLE_PRODUCT_SYS_DATA_UPLOAD_MODEL, uuidParamList.toArray()); + } + + /** + * 妯℃澘涓嬭浇 + * + * @param fse + * @param response + * @throws IOException + */ + public void downloadTemplate(FieldSetEntity fse, HttpServletResponse response) throws IOException { + String upload_sign = fse.getString("upload_sign"); + FieldSetEntity templateFse = baseDao.getFieldSetEntityByFilter(CmnConst.TABLE_PRODUCT_SYS_DATA_UPLOAD_MODEL, "upload_sign=? AND length(title)>0", new Object[]{upload_sign}, false); + String attachmentUUID = templateFse.getString(CmnConst.FIELD_TEMPLATE_INFO); + fse.setValue(CmnConst.UUID, attachmentUUID); + fileManagerService.getFileContent(fse, response); + } + + /** + * 涓氬姟鍔熻兘瀵煎叆-涓婁紶鏂囦欢 + * + * @param rpe + * @return + */ + @Override + @Transactional + public String recordDataImport(RequestParameterEntity rpe) { + FieldSetEntity ff = fileManagerService.uploadFile(rpe); + FieldSetEntity fse = rpe.getFormData(); + fse.setValue(CmnConst.FIELD_IS_SUCCESS, 0); + SystemUser curUser = SpringMVCContextHolder.getCurrentUser(); + fse.setValue(CmnConst.FIELD_ORG_LEVEL_UUID, curUser.getOrg_level_uuid()); + BaseUtil.createCreatorAndCreationTime(curUser, fse); + fse.setValue("import_info", ff.getString("import_info")); + baseDao.saveFieldSetEntity(fse); + return fse.getUUID(); + } + + /** + * 涓氬姟鍔熻兘瀵煎叆-瑙f瀽骞朵繚瀛樺埌鏁版嵁搴� + * + * @param fse + * @return + */ + @Override + @Transactional + public void recordDataSave(FieldSetEntity fse) { + SystemUser curUser = SpringMVCContextHolder.getCurrentUser(); + + FieldSetEntity logFse = baseDao.getFieldSetEntity(CmnConst.TABLE_PRODUCT_SYS_DATA_UPLOAD_RECORD, fse.getUUID(), false); + if (logFse == null) { + throw new BaseException(CmnCode.UPLOAD_TEMPLATE_GET_UPLOAD_RECORD_FAIL.getValue(), CmnCode.UPLOAD_TEMPLATE_GET_UPLOAD_RECORD_FAIL.getText()); + } + + // 鑾峰彇妯℃澘淇℃伅 + DataTableEntity templateDte = baseDao.listTable(CmnConst.TABLE_PRODUCT_SYS_DATA_UPLOAD_MODEL, "upload_sign=?", new Object[]{logFse.getString(CmnConst.FIELD_UPLOAD_SIGN)}, null, "sheet_order", Integer.MAX_VALUE, 1, true); + + // 鑾峰彇瀵煎叆鏂囦欢淇℃伅 + FieldSetEntity attachmentFse = baseDao.getFieldSetEntity(CmnConst.TABLE_PRODUCT_SYS_ATTACHMENT, logFse.getString(CmnConst.FIELD_IMPORT_INFO), false); + String relativePath = attachmentFse.getString(CmnConst.FIELD_ATTACHMENT_URL); + String templateName = attachmentFse.getString(CmnConst.FIELD_ATTACHMENT_TITLE); + Map<String, List<List<String>>> dataMap = new HashMap<>(); + try { + String filePath = Global.getSystemConfig("local.dir", "") + File.separator + relativePath + File.separator + templateName; + dataMap = EasyExcelUtil.readExcelByString(filePath); + + if ("product_project_budget".equals(templateDte.getString(0, CmnConst.TABLE_NAME))) { + for (int i = 1; i < dataMap.size(); i++) { + templateDte.addFieldSetEntity(templateDte.getFieldSetEntity(0).clones()); + } + } + } catch (Exception e) { + e.printStackTrace(); + } + // 灏佽鍒癲te涓� + List<DataTableEntity> beforeSaveDataList = Lists.newArrayList(); + List<String> titleList; + List<List<String>> dataList; + List<String> rowList; + String singleValue;// 鍗曞厓鏍煎唴鐨勫�� + int index = 0; + FieldSetEntity curTemplateFse; + Map<String, FieldSetEntity> curSubMap; + List<List<List<String>>> headerDataList = Lists.newArrayList(); + List<Map<String, FieldSetEntity>> fieldInfoList = Lists.newArrayList(); + FieldSetEntity curFieldFse; + FieldSetEntity recordFse;// 涓氬姟琛╢se + DataTableEntity recordDte;// 涓氬姟琛╠te + for (Map.Entry<String, List<List<String>>> entry : dataMap.entrySet()) { + dataList = entry.getValue(); + if (dataList.isEmpty()) { + continue; + } + + recordDte = new DataTableEntity(); + curTemplateFse = templateDte.getFieldSetEntity(index); + curSubMap = dte2Map(curTemplateFse.getSubDataTable(CmnConst.TABLE_PRODUCT_SYS_DATA_UPLOAD_MODEL_SUB), CmnConst.FIELD_EXCEL_HEADER); + fieldInfoList.add(curSubMap); + // 瀛楁瀵瑰簲鐨別xcel 琛ㄥご绱㈠紩 + Map<String, String> fieldIndex = Maps.newHashMap(); + //琛ㄥご寮�濮嬭 cheng update 2023骞�6鏈�30鏃�15:48:22 澶氳澶存椂锛岃〃澶村紑濮嬭涓嶄竴瀹氭槸绗竴琛� + int startRowIndex = 1; + if (!StringUtils.isEmpty(curTemplateFse.getString("start_row_index")) && NumberUtil.isNumber(curTemplateFse.getString("start_row_index"))) { + startRowIndex = Integer.parseInt(curTemplateFse.getString("start_row_index")); + if (startRowIndex < 1) { + startRowIndex = 1; + } + } + + titleList = dataList.get(startRowIndex); + if (startRowIndex > 0) { + headerDataList.add(dataList.subList(0, startRowIndex)); + } else { + headerDataList.add(new ArrayList<>()); + } + for (int i = startRowIndex + 1; i < dataList.size(); i++) { + rowList = dataList.get(i); + recordFse = new FieldSetEntity(); + recordFse.setTableName(curTemplateFse.getString(CmnConst.FIELD_TABLE_NAME)); + //瀛楁瀵瑰簲鐨勫垪 + int j = 0; + for (; j < titleList.size(); j++) { + if (rowList.size() < (j + 1)) { + singleValue = null; + } else { + singleValue = rowList.get(j); + } + curFieldFse = curSubMap.get(titleList.get(j)); + recordFse.setValue(curFieldFse.getString(CmnConst.FIELD_FIELD_NAME), singleValue); + if (i == 1 || rowList.size() > fieldIndex.size()) { + fieldIndex.put(curFieldFse.getString(CmnConst.FIELD_FIELD_NAME), String.valueOf(j)); + } + } + recordFse.setValue("~colName~", titleList); + recordFse.setValue("~fieldIndex~", fieldIndex); + // fieldSet 瀵瑰簲鐨勮 + recordFse.setValue("~row~", i); + recordDte.addFieldSetEntity(recordFse); + } + beforeSaveDataList.add(recordDte); + index++; + } + + // 鏁版嵁瑙f瀽淇濆瓨 + String orgLevelUUID = curUser.getOrg_level_uuid(); + String actualValue; + FieldMetaEntity meta; + Object[] fieldArr; + DataTableEntity tempDte; + String fieldName; + for (int i = 0; i < beforeSaveDataList.size(); i++) { + tempDte = beforeSaveDataList.get(i); + + // 淇濆瓨鍓嶅鐞� + try { + tempDte = spDeal(templateDte.getFieldSetEntity(i).getString(CmnConst.FIELD_BEFORE_FUNC), tempDte, headerDataList.get(i)); + if (BaseUtil.dataTableIsEmpty(tempDte)) { + throw new BaseException(CmnCode.UPLOAD_TEMPLATE_BEFORE_FUNC_EXEC_NO_DATA.getValue(), CmnCode.UPLOAD_TEMPLATE_BEFORE_FUNC_EXEC_NO_DATA.getText()); + } + } catch (BaseException e) { + throw e; + } catch (Exception e) { + e.printStackTrace(); + throw new BaseException(CmnCode.UPLOAD_TEMPLATE_BEFORE_FUNC_EXEC_FAIL.getValue(), CmnCode.UPLOAD_TEMPLATE_BEFORE_FUNC_EXEC_FAIL.getText()); + } + + meta = tempDte.getMeta(); + fieldArr = meta.getFields(); + + curTemplateFse = templateDte.getFieldSetEntity(i); + curSubMap = dte2Map(curTemplateFse.getSubDataTable(CmnConst.TABLE_PRODUCT_SYS_DATA_UPLOAD_MODEL_SUB), CmnConst.FIELD_FIELD_NAME); + boolean isMultiFlag; + StringBuilder errorMsg = new StringBuilder(8); + for (int j = 0; j < tempDte.getRows(); j++) { + recordFse = tempDte.getFieldSetEntity(j); + for (Object fieldNameObj : fieldArr) { + if (fieldNameObj == null) { + continue; + } + fieldName = fieldNameObj.toString(); + singleValue = recordFse.getString(fieldName); + + curFieldFse = curSubMap.get(fieldName); + if (curFieldFse != null) { + // 鎻愬彇鐪熷疄鍊� + if (!StringUtils.isEmpty(curFieldFse.getString(CmnConst.FIELD_PROMPT_NAME))) { + isMultiFlag = curFieldFse.getString(CmnConst.FIELD_IS_MULTI) == null ? false : "1".equals(curFieldFse.getString(CmnConst.FIELD_IS_MULTI)); + // 鏍规嵁鍙傜収鍚嶇О锛屽弬鐓х被鍨嬶紝鏄剧ず鍩熺殑鍊硷紝鑾峰彇闅愯棌鍩熺殑鍊� + actualValue = getRealValue(curFieldFse.getString(CmnConst.FIELD_PROMPT_NAME), singleValue, isMultiFlag); + } else { + actualValue = singleValue; + } + recordFse.setValue(curFieldFse.getString(CmnConst.FIELD_FIELD_NAME), actualValue); + } + } + try { + BaseUtil.createCreatorAndCreationTime(curUser, recordFse); + baseDao.saveFieldSetEntity(recordFse); + } catch (BaseException e) { + e.printStackTrace(); +// errorMsg.append("瀵煎叆鏁版嵁閿欒锛歕n\t"); + errorMsg.append(String.format("绗�%s涓猻heet锛岀%s琛�,%s", i + 1, j + 1, e.getMessageInfo() != null ? e.getMessageInfo() : "")).append("\n"); +// throw new BaseException(CmnCode.UPLOAD_TEMPLATE_IMPORT_DATA_FAIL.getValue(), String.format("%s: 绗�%s涓猻heet锛岀%s琛�", CmnCode.UPLOAD_TEMPLATE_IMPORT_DATA_FAIL.getText(), i + 1, j + 1), e); + } catch (Exception e) { + errorMsg.append(String.format("绗�%s涓猻heet锛岀%s琛�,%s", i + 1, j + 1, e.getMessage() != null ? e.getMessage() : "")).append("\n"); +// throw new BaseException(CmnCode.UPLOAD_TEMPLATE_IMPORT_DATA_FAIL.getValue(), String.format("%s: 绗�%s涓猻heet锛岀%s琛�", CmnCode.UPLOAD_TEMPLATE_IMPORT_DATA_FAIL.getText(), i + 1, j + 1)); + } + } + if (errorMsg.length() > 0) { + throw new BaseException(CmnCode.UPLOAD_TEMPLATE_IMPORT_DATA_FAIL.getValue(), errorMsg.toString()); + } + + // 淇濆瓨鍚庡鐞� + try { + spDeal(templateDte.getFieldSetEntity(i).getString(CmnConst.FIELD_AFTER_FUNC), tempDte, headerDataList.get(i)); + } catch (BaseException e) { + SpringMVCContextHolder.getSystemLogger().error(e); + } catch (Exception e) { + throw new BaseException(CmnCode.UPLOAD_TEMPLATE_AFTER_FUNC_EXEC_FAIL.getValue(), CmnCode.UPLOAD_TEMPLATE_AFTER_FUNC_EXEC_FAIL.getText()); + } + } + + // 鏇存柊璁板綍琛ㄦ儏鍐� + logFse.setValue(CmnConst.FIELD_IS_SUCCESS, 1); + BaseUtil.updatedRegeneratorAndUpdateTime(curUser, fse); + baseDao.saveFieldSetEntity(logFse); + } + + /** + * dte鎸夌収鎸囧畾fse涓殑鍊间綔涓簁ey杞崲涓簃ap + * + * @param dte + * @param keyFieldName + * @return + */ + private Map<String, FieldSetEntity> dte2Map(DataTableEntity dte, String keyFieldName) { + Map<String, FieldSetEntity> resultMap = Maps.newHashMap(); + FieldSetEntity tempFse; + for (int i = 0; i < dte.getRows(); i++) { + tempFse = dte.getFieldSetEntity(i); + resultMap.put(tempFse.getString(keyFieldName), tempFse); + } + return resultMap; + } + + public static void main(String[] args) { + Class<?> a = DataTableEntity.class; + Class<DataTableEntity> b = DataTableEntity.class; + System.out.println(a.equals(b)); + } + + /** + * 浜嬩欢鍓嶆垨鑰呬簨浠跺悗璋冪敤閫昏緫鏂规硶鐨勭壒娈婂鐞� + * + * @param functionContent + * @param dte + * @param headerDataList + * @return + */ + private DataTableEntity spDeal(String functionContent, DataTableEntity dte, List<List<String>> headerDataList) throws BaseException { + if (functionContent == null) { + return dte; + } + functionContent = functionContent.trim(); + if (StringUtils.isEmpty(functionContent)) { + return dte; + } + String className = functionContent.substring(0, functionContent.indexOf(".")); + String methodName = functionContent.substring(functionContent.indexOf(".") + 1, functionContent.indexOf("(")); + //鏍规嵁className鑾峰彇绫� + Object bean = SpringUtil.getBean(className); + //浣跨敤huTool鐨勫弽灏勫伐鍏风被鑾峰彇鏂规硶锛屾柟娉曠殑鍙傛暟绫诲瀷涓篋ataTableEntity銆丩ist<List<String>> + Method method = ReflectUtil.getMethod(bean.getClass(), methodName, DataTableEntity.class, List.class); + if (method != null) { + Type genericReturnType = method.getGenericReturnType(); + //鍒ゆ柇method杩斿洖鍊间负DataTableEntity.class + boolean isBackDataTable = genericReturnType.getTypeName().equals("com.product.core.entity.DataTableEntity"); + //鍒ゆ柇绗簩涓弬鏁扮殑娉涘瀷绫诲瀷 + Type[] types = method.getGenericParameterTypes(); + Type type = types[1]; + //鍒ゆ柇绫诲瀷鏄惁涓篖ist<List<String>>锛屽鏋滄槸鍒欒皟鐢ㄦ柟娉� + if (isBackDataTable && type.getTypeName().equals("java.util.List<java.util.List<java.lang.String>>")) { + return ReflectUtil.invoke(bean, methodName, dte, headerDataList); + } + } + + return ReflectUtil.invoke(bean, methodName, dte); + } + + /** + * 鑾峰彇鐪熷疄鍊� + * + * @param promptName + * @param showValue + * @return + */ + private String getRealValue(String promptName, String showValue, boolean isMultiFlag) { + String realValue = showValue; + DataTableEntity promptDte; + FieldSetEntity promptFse; + if (promptName.startsWith("銆�")) { + // 鏅�氬弬鐓� + promptName = promptName.replace("銆�", "").replace("銆�", ""); + promptDte = DataPoolCacheImpl.getInstance().getCacheData(CmnConst.CACHE_COMMON_PROMPT, new String[]{promptName}); + if (!BaseUtil.dataTableIsEmpty(promptDte)) { + Set<String> showSet = SetUtils.string2Set(showValue, ","); + Set<String> realSet = Sets.newLinkedHashSet(); + for (int i = 0; i < promptDte.getRows(); i++) { + promptFse = promptDte.getFieldSetEntity(i); + if (isMultiFlag) { + if (showSet.contains(promptFse.getString(CmnConst.FIELD_DICT_LABEL))) { + realSet.add(promptFse.getString(CmnConst.FIELD_DICT_VALUE)); + } + } else { + if (showValue.equals(promptFse.getString(CmnConst.FIELD_DICT_LABEL))) { + realValue = promptFse.getString(CmnConst.FIELD_DICT_VALUE); + break; + } + } + } + if (!realSet.isEmpty()) { + realValue = SetUtils.set2String(realSet, ","); + } + } + } else { + // 楂樼骇鍙傜収 + promptFse = BaseUtil.getSingleInfoByCache(CmnConst.CACHE_ADVANCED_PROMPT, new String[]{promptName}); + String sourceTableName = promptFse.getString(CmnConst.FILED_SOURCE_TABLE); + String filter = promptFse.getString(CmnConst.FILED_FILTER); + String showFieldName = promptFse.getString(CmnConst.FILED_VIEW_FIELD); + Set<String> showSet = SetUtils.string2Set(showValue, ","); + String promptFilter = BaseUtil.buildQuestionMarkFilter(showFieldName, isMultiFlag ? showSet.size() : 1, true); + StringBuilder sql = new StringBuilder(256); + String realFieldName = promptFse.getString(CmnConst.FILED_VALUE_FIELD); + sql.append("select GROUP_CONCAT(").append(realFieldName).append(") real_value from ").append(sourceTableName).append(" where ").append(promptFilter); + if (!StringUtils.isEmpty(filter)) { + filter = SystemParamReplace.systemParamsReplace(filter); + sql.append(" and ").append(filter); + } + // 琛ュ厖鐗瑰畾瀛楁鏁版嵁杩囨护 + if (!StringUtils.isEmpty(promptFse.getString("org_filter_field")) || !StringUtils.isEmpty(promptFse.getString("user_filter_field"))) { + String dataFilter = permissionService.getDataFilter(sourceTableName, + promptFse.getString("user_filter_field"), promptFse.getString("org_filter_field")); + if (!StringUtils.isEmpty(dataFilter)) { + sql.append(" and ").append(dataFilter); + } + } + FieldSetEntity sourceFse = baseDao.getFieldSetEntityBySQL(sql.toString(), showSet.toArray(), false); + if (sourceFse != null) { + realValue = sourceFse.getString("real_value"); + } + } + return realValue; + } +} diff --git a/product-server-data-export-import/src/main/java/com/product/module/data/service/idel/IOrganizationImportService.java b/product-server-data-export-import/src/main/java/com/product/module/data/service/idel/IOrganizationImportService.java new file mode 100644 index 0000000..43ddce2 --- /dev/null +++ b/product-server-data-export-import/src/main/java/com/product/module/data/service/idel/IOrganizationImportService.java @@ -0,0 +1,53 @@ +package com.product.module.data.service.idel; + +import com.product.core.entity.DataTableEntity; +import com.product.core.exception.BaseException; + +/** + * @ClassName IOrganizationImportService + * @Description 缁勭粐鏈烘瀯瀵煎叆鏁版嵁澶勭悊 + * @Author cheng + * @Date 2021/12/2 16:09 + */ +public interface IOrganizationImportService { + /** + * 瀵煎叆鍏徃 涔嬪墠 鏁版嵁澶勭悊 + * + * @param fse + * @throws BaseException + */ + DataTableEntity importCompanyBefore(DataTableEntity fse) throws BaseException; + + /** + * 瀵煎叆閮ㄩ棬 涔嬪墠 鏁版嵁澶勭悊 + * + * @param fse + * @throws BaseException + */ + DataTableEntity importDeptBefore(DataTableEntity fse) throws BaseException; + + /** + * 瀵煎叆宀椾綅绛夌骇 涔嬪墠 鏁版嵁澶勭悊 + * + * @param fse + * @throws BaseException + */ + DataTableEntity importPostLevelBefore(DataTableEntity fse) throws BaseException; + + /** + * 瀵煎叆宀椾綅 涔嬪墠 鏁版嵁澶勭悊 + * + * @param fse + * @throws BaseException + */ + DataTableEntity importPostBefore(DataTableEntity fse) throws BaseException; + + /** + * 瀵煎叆鍛樺伐 涔嬪墠 鏁版嵁澶勭悊 + * + * @param fse + * @throws BaseException + */ + DataTableEntity importStaffBefore(DataTableEntity fse) throws BaseException; + +} diff --git a/product-server-data-export-import/src/main/java/com/product/module/data/service/idel/ISystemDataUpLoadService.java b/product-server-data-export-import/src/main/java/com/product/module/data/service/idel/ISystemDataUpLoadService.java new file mode 100644 index 0000000..cd78159 --- /dev/null +++ b/product-server-data-export-import/src/main/java/com/product/module/data/service/idel/ISystemDataUpLoadService.java @@ -0,0 +1,28 @@ +package com.product.module.data.service.idel; + +import com.alibaba.fastjson.JSONObject; +import com.product.core.entity.FieldSetEntity; +import com.product.core.entity.RequestParameterEntity; +import com.product.core.exception.BaseException; +import org.springframework.transaction.annotation.Transactional; + +import java.io.IOException; + +/** + * Copyright 漏 6c + * + * @Date: 2021-06-30 09:18 + * @Author: 6c + * @Description: + */ +public interface ISystemDataUpLoadService { + void deleteModel(FieldSetEntity fse) throws BaseException; + + JSONObject uploadTemplate(RequestParameterEntity rpe); + + void saveTemplate(FieldSetEntity fse); + + String recordDataImport(RequestParameterEntity rpe); + + void recordDataSave(FieldSetEntity fse); +} diff --git a/product-server-data-export-import/src/main/java/com/product/module/data/utli/Custemhandler.java b/product-server-data-export-import/src/main/java/com/product/module/data/utli/Custemhandler.java new file mode 100644 index 0000000..d7fd02b --- /dev/null +++ b/product-server-data-export-import/src/main/java/com/product/module/data/utli/Custemhandler.java @@ -0,0 +1,67 @@ +package com.product.module.data.utli; + +import com.alibaba.excel.enums.CellDataTypeEnum; +import com.alibaba.excel.metadata.Head; +import com.alibaba.excel.metadata.data.CellData; +import com.alibaba.excel.metadata.data.WriteCellData; +import com.alibaba.excel.write.metadata.holder.WriteSheetHolder; +import com.alibaba.excel.write.style.column.AbstractColumnWidthStyleStrategy; +import org.apache.commons.collections4.CollectionUtils; +import org.apache.poi.ss.usermodel.Cell; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +public class Custemhandler extends AbstractColumnWidthStyleStrategy { + private static final int MAX_COLUMN_WIDTH = 255; + + private Map<Integer, Map<Integer, Integer>> cache = new HashMap<Integer, Map<Integer, Integer>>(8); + + @Override + protected void setColumnWidth(WriteSheetHolder writeSheetHolder, List<WriteCellData<?>> cellDataList, Cell cell, Head head, + Integer relativeRowIndex, Boolean isHead) { + boolean needSetWidth = isHead || !CollectionUtils.isEmpty(cellDataList); + if (!needSetWidth) { + return; + } + Map<Integer, Integer> maxColumnWidthMap = cache.get(writeSheetHolder.getSheetNo()); + if (maxColumnWidthMap == null) { + maxColumnWidthMap = new HashMap<Integer, Integer>(16); + cache.put(writeSheetHolder.getSheetNo(), maxColumnWidthMap); + } + Integer columnWidth = dataLength(cellDataList, cell, isHead); + if (columnWidth < 0) { + return; + } + if (columnWidth > MAX_COLUMN_WIDTH) { + columnWidth = MAX_COLUMN_WIDTH; + } + Integer maxColumnWidth = maxColumnWidthMap.get(cell.getColumnIndex()); + if (maxColumnWidth == null || columnWidth > maxColumnWidth) { + maxColumnWidthMap.put(cell.getColumnIndex(), columnWidth); + writeSheetHolder.getSheet().setColumnWidth(cell.getColumnIndex(), columnWidth * 256); + } + } + + private Integer dataLength(List<WriteCellData<?>> cellDataList, Cell cell, Boolean isHead) { + if (isHead) { + return cell.getStringCellValue().getBytes().length; + } + CellData cellData = cellDataList.get(0); + CellDataTypeEnum type = cellData.getType(); + if (type == null) { + return -1; + } + switch (type) { + case STRING: + return cellData.getStringValue().getBytes().length; + case BOOLEAN: + return cellData.getBooleanValue().toString().getBytes().length; + case NUMBER: + return cellData.getNumberValue().toString().getBytes().length; + default: + return -1; + } + } +} diff --git a/product-server-data-export-import/src/main/java/com/product/module/data/utli/CustomMergeStrategy.java b/product-server-data-export-import/src/main/java/com/product/module/data/utli/CustomMergeStrategy.java new file mode 100644 index 0000000..084a682 --- /dev/null +++ b/product-server-data-export-import/src/main/java/com/product/module/data/utli/CustomMergeStrategy.java @@ -0,0 +1,98 @@ +package com.product.module.data.utli; + +import cn.hutool.core.collection.CollUtil; +import com.alibaba.excel.metadata.Head; +import com.alibaba.excel.write.merge.AbstractMergeStrategy; +import org.apache.poi.ss.usermodel.Cell; +import org.apache.poi.ss.usermodel.Sheet; +import org.apache.poi.ss.util.CellRangeAddress; + +import java.util.ArrayList; +import java.util.List; +import java.util.Optional; +import java.util.concurrent.atomic.AtomicInteger; + +public class CustomMergeStrategy extends AbstractMergeStrategy { + + /** + * 鍒嗙粍锛屾瘡鍑犺鍚堝苟涓�娆� + */ + private List<List<Integer>> mergeColDataGroupCountList; + + /** + * 鐩爣鍚堝苟鍒梚ndex + */ + private List<Integer> targetColumnIndex; + /** + * 闇�瑕佸紑濮嬪悎骞跺崟鍏冩牸鐨勯琛宨ndex + */ + private Integer rowIndex; + + /** + * mergeColDataList涓哄緟鍚堝苟鐩爣鍒楃殑鍊� + */ + public CustomMergeStrategy(List<List<String>> mergeColDataList, List<Integer> targetColumnIndex) { + this.mergeColDataGroupCountList = getGroupCountList(mergeColDataList); + this.targetColumnIndex = targetColumnIndex; + } + + + @Override + protected void merge(Sheet sheet, Cell cell, Head head, Integer relativeRowIndex) { + + if (null == rowIndex) { + rowIndex = cell.getRowIndex(); + } + // 浠呬粠棣栬浠ュ強鐩爣鍒楃殑鍗曞厓鏍煎紑濮嬪悎骞讹紝蹇界暐鍏朵粬 + if (cell.getRowIndex() == rowIndex && targetColumnIndex.contains(cell.getColumnIndex())) { + //鎵惧埌瀵瑰簲鐨勯渶瑕佸悎骞剁殑鍒� + AtomicInteger i = new AtomicInteger(0); + Optional<Integer> first = targetColumnIndex.stream().filter(col -> { + i.getAndIncrement(); + return col == cell.getColumnIndex(); + }).findFirst(); + mergeGroupColumn(sheet, first.get()); + } + } + + private void mergeGroupColumn(Sheet sheet, Integer index) { + int rowCount = rowIndex; + for (Integer count : mergeColDataGroupCountList.get(index)) { + if (count == 1) { + rowCount += count; + continue; + } + // 鍚堝苟鍗曞厓鏍� + CellRangeAddress cellRangeAddress = new CellRangeAddress(rowCount, rowCount + count - 1, + targetColumnIndex.get(index), targetColumnIndex.get(index)); + sheet.addMergedRegionUnsafe(cellRangeAddress); + rowCount += count; + } + } + + /** + * 璇ユ柟娉曞皢鐩爣鍒楁牴鎹�兼槸鍚︾浉鍚岃繛缁彲鍚堝苟锛屽瓨鍌ㄥ彲鍚堝苟鐨勮鏁� + */ + private List<List<Integer>> getGroupCountList(List<List<String>> exportDataList) { + if (CollUtil.isEmpty(exportDataList)) { + return new ArrayList<>(); + } + List<List<Integer>> groupCountListList = new ArrayList<>(); + exportDataList.forEach(dataList->{ + List<Integer> groupCountList = new ArrayList<>(); + int count = 1; + for (int i = 1; i < dataList.size(); i++) { + if (dataList.get(i).equals(dataList.get(i - 1))) { + count++; + } else { + groupCountList.add(count); + count = 1; + } + } + // 澶勭悊瀹屾渶鍚庝竴鏉″悗 + groupCountList.add(count); + groupCountListList.add(groupCountList); + }); + return groupCountListList; + } +} diff --git a/product-server-data-export-import/src/main/java/com/product/module/data/utli/SystemApiToMethods.java b/product-server-data-export-import/src/main/java/com/product/module/data/utli/SystemApiToMethods.java new file mode 100644 index 0000000..d359819 --- /dev/null +++ b/product-server-data-export-import/src/main/java/com/product/module/data/utli/SystemApiToMethods.java @@ -0,0 +1,243 @@ +package com.product.module.data.utli; + +import com.product.core.exception.BaseException; +import com.product.module.data.config.CmnCode; +import com.product.module.sys.version.ApiVersion; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.ConfigurableApplicationContext; +import org.springframework.stereotype.Component; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.context.request.RequestContextHolder; +import org.springframework.web.context.request.ServletRequestAttributes; + +import javax.annotation.PostConstruct; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import java.io.Serializable; +import java.lang.reflect.Method; +import java.lang.reflect.ParameterizedType; +import java.util.Collections; +import java.util.HashMap; +import java.util.Map; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +/** + * cheng + */ +@Component +public class SystemApiToMethods { + @Autowired + ConfigurableApplicationContext applicationContext; + /** + * 鍙map + */ + Map<String, Bean> beans; + + + public Boolean getBeanIsExist(String api) { + Bean bean = this.beans.get(api); + return bean != null; + } + + /** + * 閫氳繃api璋冪敤Controller灞傚叆鍙� + * + * @param api + * @return + * @throws BaseException + */ + public Object run(String api, Integer verion) throws BaseException { + if (api == null) { + return null; + } + if (api.indexOf("/") != 0) { + api = "/" + api; + } + //閫氳繃涓婁笅鏂囪幏鍙� request response + HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest(); + HttpServletResponse response = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getResponse(); + return run(request, response, api, verion); + } + + public boolean isVersion(String api) { + String str = api; + String pattern = ".*/v[0-9]*\\d$"; + Pattern r = Pattern.compile(pattern); + Matcher m = r.matcher(str); + return m.matches(); + } + + + public static void main(String args[]) { + + } + + /** + * 閫氳繃api璋冪敤Controller灞傚叆鍙� + * + * @param request + * @param response + * @param api + * @return + * @throws BaseException + */ + public Object run(HttpServletRequest request, HttpServletResponse response, String api, Integer version) throws BaseException { + if (beans == null || api == null) return null; + try { + if (api.indexOf("/") != 0) { + api = "/" + api; + } + api += version == null ? "" : !isVersion(api) ? "/v" + version : ""; + if (!getBeanIsExist(api)) { + throw new BaseException(CmnCode.EXPORT_GET_API_METHOD_FILA.getValue(), CmnCode.EXPORT_GET_API_METHOD_FILA.getText() + api); + } + Bean bean = this.beans.get(api); + if (bean != null) { + Class<?>[] parameterType = bean.getParameterType(); + if (parameterType != null) { + Object[] params = new Object[parameterType.length]; + for (int i = 0; i < parameterType.length; i++) { + Class<?> aClass = parameterType[i]; + Class<?> httpServletRequestClass = HttpServletRequest.class; + Class<?> HttpServletResponseClass = HttpServletResponse.class; + if (aClass == httpServletRequestClass) { + params[i] = request; + continue; + } + if (aClass == HttpServletResponseClass) { + params[i] = response; + continue; + } + params[i] = null; + } + return bean.method.invoke(bean.bean, params); + } + return bean.method.invoke(bean.bean); + } + return null; + } catch (Exception e) { + e.printStackTrace(); + throw new BaseException(e); + } + } + + /** + * 鍚姩鏃跺垵濮嬪寲鎷垮埌鎵�鏈夌殑璇锋眰鍦板潃 + */ + @PostConstruct + private void getAll() { + + //鑾峰彇restcontroller娉ㄨВ鐨勭被鍚� + String[] beanNamesForAnnotation = applicationContext.getBeanNamesForAnnotation(RestController.class); + Map<String, Bean> beanMap = new HashMap<>(); + //鑾峰彇绫诲璞� + for (String str : beanNamesForAnnotation) { + Object bean = applicationContext.getBean(str); + Class<?> forName = bean.getClass(); + //鑾峰彇requestmapping娉ㄨВ鐨勭被 + RequestMapping declaredAnnotation = forName.getAnnotation(RequestMapping.class); + if (declaredAnnotation != null) { + String[] value = (declaredAnnotation.value()); + for (Method method : forName.getDeclaredMethods()) { + ApiVersion version = method.getAnnotation(ApiVersion.class); + RequestMapping api_value = method.getAnnotation(RequestMapping.class); + PostMapping annotation = method.getAnnotation(PostMapping.class); + if (api_value != null) { + Bean bean1 = new Bean(); + String class_url = value[0] + api_value.value()[0].replace("{version}", "v" + (version == null ? "1" : String.valueOf(version.value()))); + bean1.apiUrl = class_url; + bean1.version = version == null ? 1 : version.value(); + bean1.bean = bean; + bean1.method = method; + beanMap.put(class_url, bean1); + } else if (annotation != null) { + Bean bean1 = new Bean(); + String class_url = value[0] + annotation.value()[0].replace("{version}", "v" + (version == null ? "1" : "" + version.value())); + bean1.apiUrl = class_url; + bean1.version = version == null ? 1 : version.value(); + bean1.bean = bean; + bean1.method = method; + beanMap.put(class_url, bean1); + } + } + } + PostMapping annotation = forName.getAnnotation(PostMapping.class); + if (annotation != null) { + String[] value = annotation.value(); + for (Method method : forName.getDeclaredMethods()) { + ApiVersion version = method.getAnnotation(ApiVersion.class); + PostMapping api_value = method.getAnnotation(PostMapping.class); + if (api_value != null) { + Bean bean1 = new Bean(); + String class_url = value[0] + api_value.value()[0].replace("{version}", "v" + (version == null ? "1" : "" + version.value())); + bean1.apiUrl = class_url; + bean1.version = version == null ? 1 : version.value(); + bean1.bean = bean; + bean1.method = method; + beanMap.put(class_url, bean1); + } + } + } + } + this.beans = Collections.unmodifiableMap(beanMap); + } + + private class Bean implements Serializable { + + + private String apiUrl; + + private int version; + + private Object bean; + + private Method method; + + private ParameterizedType parameterizedType; + + public Method getMethod() { + return method; + } + + public void setMethod(Method method) { + this.method = method; + } + + public String getApiUrl() { + return apiUrl; + } + + public void setApiUrl(String apiUrl) { + this.apiUrl = apiUrl; + } + + public int getVersion() { + return version; + } + + public void setVersion(int version) { + this.version = version; + } + + public Object getBean() { + return bean; + } + + public void setBean(Object bean) { + this.bean = bean; + } + + private Class<?>[] getParameterType() { + if (this.bean != null && this.method != null) { + return this.method.getParameterTypes(); + } + return null; + } + + + } + +} -- Gitblit v1.9.2