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> 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> 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; } } 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 = "é«çº§åç §é 置信æ¯"; } 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()); } // 夿忰æ¯å¦æ£å¸¸ 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()); } } } 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()); } } /** * æ ¹æ®å·²ç»ä¸ä¼ çexcelæä»¶,è§£æ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()); } } /** * ä¸å¡åè½å¯¼å ¥-è§£æå¹¶ä¿åå°æ°æ®åº * * @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()); } } } 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è¡ï¼ç¬¬ Nåï¼'表头åç§°' ('æ°æ®å¼') æ°æ®å第 %s è¡ï¼ç¬¬Nè¡ï¼ç¬¬ 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 ? "ï¼è¯·è¾å ¥æ£ç¡®ç '%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 'æ¯å¦æ£ç¡®ï¼' %s '"; error = String.format(error, dataLocation.getRowIndex(), dataLocation.getColName(CmnConst.ORG_LEVEL_UUID), companyAllName); errorEntity.addError(dataLocation.getRowIndex(), error); continue; } String error = "第 %s è¡ï¼ä¸çº§æºæè·å失败ï¼ä¸çº§é¨é¨ä¸åå¨ï¼è¯·æ£æ¥' %s 'æ¯å¦æ£ç¡®ï¼' %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; // ä¸çº§æºæçuuid 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; } // ååºä¸çº§é¨é¨çcodeä½ä¸ºä¸çº§ç¼ç code = deptFse.getString(CmnConst.FIELD_ORG_LEVEL_CODE); parentUuid = deptFse.getString(CmnConst.ORG_LEVEL_UUID); } else { // ååºä¸çº§å ¬å¸çcodeä½ä¸ºä¸çº§ç¼ç 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)); // æ ¹æ®ç¨æ·ä¸ä¼ çå ¬å¸å ¨ç§° & 该管çå管ççææå ¬å¸ è¿è¡æ¥è¯¢å ¬å¸çuuid 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) { // å°å ¬å¸uuidåå ¥æ¯æ¡æ°æ® 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 æ¹æ³ // éclone æ¹å¼è°ç¨ä¼åºç°æªç¥é误 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' æ¯å¦æ£ç¡®"; 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"); // å°show_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 { // è®°å½æ¾å°çå²ä½ç级uuid ï¼å¤ä¸ªç¨éå·åé 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 æ¯å¦æ£ç¡®"; 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' æ¯å¦æ£ç¡®"; 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()); } /** * æ¥è¯¢ææåå·¥ç¼ç 以åuser表ä¸çè´¦å· */ 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 { // 注 ï¼staff_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 { // è®°å½æ¾å°çå²ä½ç级uuid ï¼å¤ä¸ªç¨éå·åé 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); } } } 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()); } //å°workbook转æ¢ä¸ºåèæµ ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); //å°excelè¾åºå°åèæµ 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å¯ä»¥é²æ¢ä¸æä¹±ç å½ç¶åeasyexcel没æå ³ç³» 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å¯ä»¥é²æ¢ä¸æä¹±ç å½ç¶åeasyexcel没æå ³ç³» // è¿ééè¦è®¾ç½®ä¸å ³éæµ 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; } } 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; } /** * è§£ææ¨¡æ¿ï¼è·åExcelè¡¨å¤´ä¿¡æ¯ * * @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ä¸ãå ¥å£ãå第ä¸ä¸ªé¡µé¢ * * @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(); } /** * ä¸å¡åè½å¯¼å ¥-è§£æå¹¶ä¿åå°æ°æ®åº * * @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(); } // å°è£ å°dteä¸ 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;// ä¸å¡è¡¨fse DataTableEntity recordDte;// ä¸å¡è¡¨dte 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); // åæ®µå¯¹åºçexcel è¡¨å¤´ç´¢å¼ 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++; } // æ°æ®è§£æä¿å 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个sheetï¼ç¬¬%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个sheetï¼ç¬¬%sè¡", CmnCode.UPLOAD_TEMPLATE_IMPORT_DATA_FAIL.getText(), i + 1, j + 1), e); } catch (Exception e) { errorMsg.append(String.format("第%s个sheetï¼ç¬¬%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个sheetï¼ç¬¬%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ä¸çå¼ä½ä¸ºkey转æ¢ä¸ºmap * * @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çåå°å·¥å ·ç±»è·åæ¹æ³ï¼æ¹æ³çåæ°ç±»å为DataTableEntityãList<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]; //å¤æç±»åæ¯å¦ä¸ºList<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; } } 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; } 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); } 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; } } } 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; /** * ç®æ åå¹¶åindex */ private List<Integer> targetColumnIndex; /** * éè¦å¼å§åå¹¶åå æ ¼çé¦è¡index */ 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; } } 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; } } }