123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683 |
- package com.qmth.teachcloud.common.contant;
- import com.qmth.boot.core.uid.service.UidService;
- import com.qmth.teachcloud.common.annotation.DBVerify;
- import com.qmth.teachcloud.common.bean.result.DBVerifyResult;
- import com.qmth.teachcloud.common.config.DictionaryConfig;
- import com.qmth.teachcloud.common.entity.BasicSchool;
- import com.qmth.teachcloud.common.entity.SysUser;
- import com.qmth.teachcloud.common.enums.ExceptionResultEnum;
- import com.qmth.teachcloud.common.enums.TFCustomTypeEnum;
- import com.qmth.teachcloud.common.service.CommonCacheService;
- import com.qmth.teachcloud.common.util.Base64Util;
- import com.qmth.teachcloud.common.util.ServletUtil;
- import org.apache.commons.io.IOUtils;
- import org.springframework.cglib.beans.BeanMap;
- import javax.annotation.Resource;
- import java.io.FileOutputStream;
- import java.io.IOException;
- import java.io.OutputStream;
- import java.io.UnsupportedEncodingException;
- import java.lang.reflect.Field;
- import java.math.BigDecimal;
- import java.net.URLEncoder;
- import java.nio.charset.Charset;
- import java.util.*;
- import java.util.stream.Collectors;
- /**
- * @Description: 系统常量
- * @Param:
- * @return:
- * @Author: wangliang
- * @Date: 2019/10/11
- */
- public class SystemConstant {
- @Resource
- DictionaryConfig dictionaryConfig;
- /**
- * 系统常量
- */
- public static final String CHARSET_NAME = "UTF-8";
- // public static final String CHARSET_GB2312 = "gb2312";
- public static final String CHARSET_GBK = "gbk";
- public static final Charset CHARSET = Charset.forName(CHARSET_NAME);
- public static final String MD5 = "MD5";
- public static final String SUCCESS = "success";
- public static final String EXTEND_COLUMN = "extendColumn";
- public static final String USER_DIR = "user.dir";
- public static final String PDF_TEMP = "pdf-temp";
- public static final String FILE_TEMP = "file-temp";
- public static final String SESSION = "session:";
- public static final String TASK = "task";
- public static final String TB_TASK_ID = "tbTaskId";
- public static final String TB_SYNC_TASK = "tbSyncTask";
- public static final String TB_SYNC_TASK_ID = "tbSyncTaskId";
- public static final String USER = "account";
- public static final String SCHOOL_ID = "schoolId";
- public static final String SCHOOL = "school";
- public static final String ORG = "org";
- public static final String ERROR = "/error";
- public static final String METHOD = "post";
- public static final String DEFAULT_PASSWORD = "MTIzNDU2";
- public static final String UPDATE_TIME = "updateTime";
- public static final String PATH = "path";
- public static final String PDF_PATH = "pdfPath";
- public static final String HTML_PATH = "htmlPath";
- public static final String TYPE = "type";
- public static final String LOCAL = "local";
- public static final String OSS = "oss";
- public static final String LOGO = "logo";
- public static final String UPLOAD_TYPE = "uploadType";
- public static final String ID = "id";
- public static final String MODEL = "model";
- public static final String VERSION = "version";
- public static final String FLOW_ENTITY_ID = "flowEntityId";
- public static final String CUSTOM_FLOW_ID = "customFlowId";
- public static final String ACT_FLOW_ID = "actFlowId";
- public static final String FLOW_PROCESS_VAR_MAP = "flowProcessVarMap";
- public static final String PROCESS_DEFINITION_ID = "processDefinitionId";
- public static final String FILE = "file";
- public static final String SIZE = "size";
- public static final String HTML_PREFIX = ".html";
- public static final String PDF_PREFIX = ".pdf";
- public static final String FTL_PREFIX = ".ftl";
- public static final String ZIP_PREFIX = ".zip";
- // public static final String JPG_PREFIX = ".jpg";
- public static final String DEFAULT_DATE_PATTERN = "yyyy-MM-dd HH:mm:ss";
- public static final int PAGE_NUMBER = 0;
- public static final int PAGE_SIZE = 10000000;
- public static final int PAGE_SIZE_MIN = 10;
- public static final int PAGE_SIZE_MAX = 500;
- public static final int PAGE_NUMBER_MIN = 1;
- public static final int IN_SIZE_MAX = 1000;
- public static final int ALL_CARD = -1;
- public static final String MANUAL = "manual";
- public static final String DELIMITER = ":";
- public static final String COMMA = ",";
- public static final int FINAL_SCALE = 1;
- public static final int CALCULATE_SCALE = 4;
- // public static final int OPER_SCALE = 8;
- public static final BigDecimal PERCENT = new BigDecimal(100);
- public static final String HYPHEN = "-";
- public static final String DEFAULT_SIGN = "#";
- public static final String PARENT_ORG = "教务处";
- public static final String SCHOOL_CODE = "wdfx";
- public static final String ADMIN_CODE = "admin";
- public static final String AUTH = "auth";//命题老师id
- // public static final int MAX_RETRY_CREATE_PDF_COUNT = 5;
- //英文字母、数字、中文括号、英文括号、下划线(_)、减号(-)、中文横线(—)
- public static final String REGULAR_EXPRESSION_OF_CODE = "[a-zA-Z0-9](\\w+)?-?(\\w+)?—?(\\w+)?(\\((\\w+)?-?(\\w+)?—?(\\w+)?\\))?(\\((\\w+)?-?(\\w+)?—?(\\w+)?\\))?(\\w+)?";
- public static final String REGULAR_EXPRESSION_OF_PHONE = "((\\d{3,4})|(\\(\\d{3,4}\\)-))?\\d{7,8}";
- public static final String REGULAR_EXPRESSION_OF_CODE_PRIMARY_DIMENSION = "[A-Z]";
- public static final String REGULAR_EXPRESSION_OF_CODE_SECOND_DIMENSION = "[A-Z][1-9][0-9]*";
- public static final String SYS_USER = "sysUser";
- public static final String DATA_COUNT = "dataCount";
- public static final List<Long> MENU_MANAGE = Arrays.asList(507L, 508L, 530L, 531L, 675L, 676L);
- public static final float PAPER_DEVIATION = 2;
- public static final String COMMA_OF_ENGLISH = ",";
- public static final String COMMA_OF_CHINESE = ",";
- public static final String PAUSE_SIGN = "、";
- public static final String ORG_SPLIT = "/";
- public static final String PUSH_OPERATE_NOTICE = "操作成功,请去基础配置 -> 系统设置 -> 同步管理中查看结果";
- public static final String EXCEL_PROTECT_KEY = "Qmth87863577";
- /**
- * oss url过期时间
- */
- // public static final int OSS_URL_EXPIRE = 5 * 60 * 1000;//过期时间5分钟
- /**
- * 缓存配置
- */
- public static final String USER_OAUTH_CACHE = "user:oauth:cache";
- public static final String USER_ACCOUNT_CACHE = "user:account:cache";
- public static final String USER_MENU_CACHE = "user:menu:cache";
- public static final String SCHOOL_CACHE = "school:cache";
- public static final String SCHOOL_CODE_CACHE = "school:code:cache";
- public static final String ORG_CACHE = "org:cache";
- public static final String PRIVILEGE_URL_CACHE = "privilege:url:cache";
- public static final String ROLE_PRIVILEGE_CACHE = "role:privilege:cache";
- public static final String USER_ROLE_PRIVILEGE_CACHE = "user:role:privilege:cache";
- public static final String ROLE_CACHE = "role:cache";
- public static final String AUTH_INFO_CACHE = "auth:info:cache";
- public static final String TXT_CHARSET_CACHE = "charset:txt:cache";
- /**
- * 报表缓存
- */
- public static final String EXAM_STUDENT_REPORT = "report:cache:examStudent";
- public static final String COLLEGE_DEAN_REPORT = "report:cache:collegeDean";
- public static final String COLLEGE_COURSE_REPORT = "report:cache:collegeCourse";
- public static final String SURVEY_TEACHER_VIEW_REPORT = "report:cache:surveyTeacherView";
- public static final String TEACHER_VIEW_REPORT = "report:cache:teacherView";
- public static final String TEACHER_ANSWER_VIEW_REPORT = "report:cache:teacherAnswerView";
- /**
- * 鉴权
- */
- public static final String HEADER_AUTHORIZATION = "Authorization";
- public static final String HEADER_TIME = "time";
- public static final String HEADER_PLATFORM = "platform";
- public static final String HEADER_DEVICE_ID = "deviceId";
- public static final String TOKEN = "token";
- public static final String SIGN = "sign";
- /**
- * redis
- */
- public static final int DEFAULT_SESSION_EXPIRE = 1;//过期时间1天
- public static final long REDIS_DEFAULT_EXPIRE_TIME = 24 * 60L * 60L;//过期时间24小时
- public static final long REDIS_THIRD_USER_AUTH_EXPIRE_TIME = 2 * 60L;//过期时间2分钟
- /**
- * redis mq
- */
- public static final String REDIS_LOCK_MQ_PREFIX = "redis:lock:mq:";
- public static final int REDIS_MQ_MAX_RECONSUME = 5;
- public static final String MQ_TOPIC_BUFFER_LIST = "mq:topic:buffer:list";
- public static final String REDIS_LOCK_BATCH_NO_PREFIX = "redis:lock:batchNo:";//
- public static final String REDIS_LOCK_GRADE_COURSE_DELETE_PREFIX = "redis:lock:courseInfo:";
- public static final String REDIS_LOCK_GRADE_EXAM_DELETE_PREFIX = "redis:lock:exam:";
- /**
- * redis lock
- */
- public static final int MAX_RETRY_COUNT = 30;
- public static final long REDIS_CACHE_TIME_OUT = 60L;
- public static final long REDIS_LOCK_MQ_TIME_OUT = 60L;
- public static final long REDIS_LOCK_BATCH_NO_TIME_OUT = 60L * 30;
- /**
- * aes相关
- */
- public static final String AES = "AES";
- public static final String AES_MODE_PKCS5 = "AES/CBC/PKCS5Padding";//用这个模式,规则必须为16位
- public static final String AES_MODE_PKCS7 = "AES/CBC/PKCS7Padding";//用这个模式,规则必须为16位
- public static final String AES_RULE = "1234567890123456";//aes密钥
- /**
- * 变量
- */
- // public static String TEMP_FILES_DIR;
- // public static String PDF_TEMP_FILES_DIR;
- /**
- * excel相关
- */
- public static final String XLSX = "xlsx";
- public static final String XLS = "xls";
- /**
- * 线程池配置
- */
- public static final String THREAD_POOL_NAME = "taskThreadPool";
- // public static final int THREAD_POOL_CORE_POOL_SIZE = 5;
- // public static final int THREAD_POOL_MAX_POOL_SIZE = 100;
- public static final int THREAD_POOL_KEEP_ALIVE_SECONDS = 10;
- public static final int THREAD_POOL_QUEUE_CAPACITY = 500;
- /**
- * mq消息
- */
- public static final int DELIVERED_ACK_TYPE = 0;//消息"已发出",但尚未处理结束
- public static final int POSION_ACK_TYPE = 1;//消息"错误",通常表示"抛弃"此消息,比如消息重发多次后,都无法正确处理时,消息将会被删除或者DLQ(死信队列)
- public static final int STANDARD_ACK_TYPE = 2;//"标准"类型,通常表示为消息"处理成功",broker端可以删除消息了
- public static final int REDELIVERED_ACK_TYPE = 3;//消息需"重发",比如consumer处理消息时抛出了异常,broker稍后会重新发送此消息
- public static final int INDIVIDUAL_ACK_TYPE = 4;//表示只确认"单条消息",无论在任何ACK_MODE下
- public static final int UNMATCHED_ACK_TYPE = 5;//BROKER间转发消息时,接收端"拒绝"消息
- public static final int UNSEND_ACK_TYPE = 6;//消息未发出
- /**
- * activiti
- */
- public static final String APPROVE_ID = "approveId";//审批id
- public static final String FLOW_SUBMIT = "flowSubmit";//命题提交申请
- public static final String FLOW_JOIN_TYPE = "flowJoinType";//流程关联类型
- public static final String OLD_FLOW_ID = "oldFlowId";//旧流程id
- public static final String FLOW_TYPE = "flowType";//流程类型
- public static final String FLOW_ID = "flowId";//流程id
- public static final String FLOW_TASK_ID = "flowTaskId";//流程任务id
- public static final String APPROVE = "approve";//流程审核变量
- public static final String AGGINESS_MAP = "agginessMap";//流程审批人变量
- public static final String APPROVE_PASS_MAP = "approvePassMap";//流程审批通过变量
- public static final String APPROVE_REJECT_MAP = "approveRejectMap";//流程审批驳回变量
- public static final String APPROVE_USER_IDS = "approveUserIds";//流程审批人列表
- public static final String SETUP_MAP = "setupMap";//流程步骤变量
- public static final String APPROVE_SETUP = "approveSetup";//流程节点
- public static final String APPROVE_OPERATION = "approveOperation";//流程操作
- public static final String FLOW_STATUS = "flowStatus";//流程状态
- public static final String APPROVE_REMARK = "approveRemark";//流程审批意见
- public static final String OBJECT_ID = "objectId";
- public static final String OBJECT_DATA = "objectData";
- public static final String APPROVE_TF_FLOW_LOG = "TFFlowLog";//流程院长自动审批
- public static final String PAPAER_ATTACHMENT_IDS = "paperAttachmentIds";//命题附件ids
- public static final String REDIS_LOCK_FLOW_TASK_PREFIX = "redis:lock:flow:task:";//流程节点锁
- public static final String REDIS_LOCK_EXAM_TASK_FLOW_PREFIX = "redis:lock:exam:task:flow:";//考试任务流程节点锁
- public static final long REDIS_LOCK_FLOW_TASK_TIME_OUT = 60L * 2;
- public static final long REDIS_LOCK_EXAM_TASK_FLOW_TIME_OUT = 60L * 2;
- public static final String REDIS_LOCK_FLOW_PREFIX = "redis:lock:flow:";//流程锁
- public static final long REDIS_LOCK_FLOW_TIME_OUT = 60L * 2;
- public static final String REDIS_LOCK_CUSTOM_FLOW_PREFIX = "redis:lock:custom:flow:";//自定义流程锁
- public static final long REDIS_LOCK_CUSTOM_FLOW_TIME_OUT = 60L * 2;
- public static final String REDIS_LOCK_CALCULATE_PREFIX = "redis:lock:calculate:";//计算锁
- public static final long REDIS_LOCK_CALCULATE_TIME_OUT = 60L * 60;
- /**
- * 机器心跳
- */
- public static final String CURRENT_TASK_MACHINE_ID = "current_task_machine_id";//当前机器id
- public static final String TASK_MACHINE_ID = "task_machine_id:";//任务机器id
- public static final String TASK_MACHINE_ID_LIKE = "task_machine_id*";//任务机器like
- public static final String LOG_ERROR = "请求出错:";
- /**
- * http设置
- */
- public static final int CONNECT_TIME_OUT = 1000 * 60 * 2;//请求超时
- public static final int SOCKET_CONNECT_TIME_OUT = 1000 * 60 * 30;//读取数据超时
- // /**
- // * 初始化附件文件路径
- // */
- // public static void initTempFiles() {
- // File fileTempDir = null, pdfTempDir = null;
- // DictionaryConfig dictionaryConfig = SpringContextHolder.getBean(DictionaryConfig.class);
- //
- // if (Objects.nonNull(dictionaryConfig.sysDomain().getFileTempPath()) && !Objects.equals("", dictionaryConfig.sysDomain().getFileTempPath())) {
- // fileTempDir = new File(dictionaryConfig.sysDomain().getFileTempPath().trim());
- // } else {
- // StringJoiner fileTempLocalPath = new StringJoiner("").add(System.getProperty(USER_DIR));
- // String mkdir = fileTempLocalPath.toString().substring(0, fileTempLocalPath.toString().lastIndexOf(File.separator));
- // fileTempDir = new File(new StringBuffer(mkdir).append(File.separator).append(FILE_TEMP).toString());
- // }
- // if (Objects.nonNull(fileTempDir) && !fileTempDir.exists()) {
- // fileTempDir.mkdirs();
- // }
- //
- // if (Objects.nonNull(dictionaryConfig.sysDomain().getPdfTempPath()) && !Objects.equals("", dictionaryConfig.sysDomain().getPdfTempPath())) {
- // pdfTempDir = new File(dictionaryConfig.sysDomain().getPdfTempPath().trim());
- // } else {
- // StringJoiner pdfTempLocalPath = new StringJoiner("").add(System.getProperty(USER_DIR));
- // String mkdir = pdfTempLocalPath.toString().substring(0, pdfTempLocalPath.toString().lastIndexOf(File.separator));
- // pdfTempDir = new File(new StringBuffer(mkdir).append(File.separator).append(PDF_TEMP).toString());
- // }
- // if (Objects.nonNull(pdfTempDir) && !pdfTempDir.exists()) {
- // pdfTempDir.mkdirs();
- // }
- // TEMP_FILES_DIR = fileTempDir.getPath();
- // PDF_TEMP_FILES_DIR = pdfTempDir.getPath();
- // }
- /**
- * id转换为long
- *
- * @return
- */
- public static Long convertIdToLong(String id) {
- return Objects.nonNull(id) && id.length() > 0 ? Long.parseLong(id) : null;
- }
- /**
- * id转换为Integer
- *
- * @return
- */
- public static Integer convertIdToInteger(String id) {
- return Objects.nonNull(id) && id.length() > 0 ? Integer.parseInt(id) : null;
- }
- /**
- * 获取全局uuid
- *
- * @return
- */
- public static String getUuid() {
- return String.valueOf(UUID.randomUUID()).replaceAll("-", "");
- }
- /**
- * 获取数据库uuid
- *
- * @return
- */
- public static Long getDbUuid() {
- UidService uidservice = SpringContextHolder.getBean(UidService.class);
- return uidservice.getId();
- }
- /**
- * enable转换
- *
- * @return
- */
- public static Boolean convertEnable(Boolean enable) {
- return Objects.nonNull(enable) ? enable : true;
- }
- /**
- * 试卷类型转换
- *
- * @param paperType
- * @return
- */
- public static String convertPaperType(String paperType) {
- paperType = paperType.toLowerCase();
- int ascii = (int) paperType.charAt(0);
- return String.valueOf(ascii + 704);
- }
- /**
- * 模糊查询时调用以去除符号"%","_"特殊字符对查询结果的影响
- *
- * @param param 要校验的参数
- * @return 转译后的参数
- */
- public static String translateSpecificSign(String param) {
- if (param == null) {
- return null;
- }
- if (param.contains("%")) {
- param = param.replaceAll("%", "\\\\%");
- }
- if (param.contains("_")) {
- param = param.replaceAll("_", "\\\\_");
- }
- return param;
- }
- public static void verifyLength(String str, int length, String name) {
- if (str == null || str.length() == 0 || str.equals("null")) {
- throw ExceptionResultEnum.ERROR.exception(name + "不能为空");
- }
- if (str.length() > length) {
- throw ExceptionResultEnum.ERROR.exception("[" + name + ":" + str + "]' 超过长度限制 : " + length);
- }
- }
- public static boolean strNotNull(String str) {
- return str != null && str.length() > 0 && !str.equals("null");
- }
- /**
- * Long 类型的参数不为空
- *
- * @param x 参数
- * @return true:不为空、false:为空
- */
- public static boolean longNotNull(Long x) {
- return x != null && x > 0;
- }
- public static Long getHeadOrUserSchoolId() {
- SysUser sysUser = (SysUser) ServletUtil.getRequestUser();
- Long schoolId;
- if (Objects.nonNull(ServletUtil.getRequestHeaderSchoolIdByNotVaild())) {
- schoolId = Long.parseLong(ServletUtil.getRequestHeaderSchoolIdByNotVaild().toString());
- } else {
- schoolId = sysUser.getSchoolId();
- }
- return schoolId;
- }
- /**
- * 检验字段
- *
- * @param obj 被检验的映射类对象
- * @param clazz 该对象的类
- * @return 检验结果(状态 、 信息)
- * @throws IllegalAccessException 异常
- */
- public static DBVerifyResult verifyDBFields(Object obj, Class<?> clazz) throws IllegalAccessException {
- Field[] fields = clazz.getDeclaredFields();
- for (Field field : fields) {
- field.setAccessible(true); // 解除封装
- String fieldValue = String.valueOf(field.get(obj));
- DBVerify dbVerify = field.getAnnotation(DBVerify.class);
- if (Objects.isNull(dbVerify)) {
- continue;
- }
- String value = dbVerify.value();
- boolean required = dbVerify.required();
- int min = dbVerify.min();
- int max = dbVerify.max();
- if (required) {
- if (fieldValue == null || fieldValue.length() == 0 || fieldValue.equals("null")) {
- return new DBVerifyResult(false, "[" + value + "]为必须字段,不能为空");
- }
- }
- if (fieldValue != null && min > 0) {
- if (fieldValue.length() < min) {
- return new DBVerifyResult(false, "[" + value + "]低于最小长度限制,最小限制[" + min + "]");
- }
- }
- if (fieldValue != null && max > 0) {
- if (fieldValue.length() > max) {
- return new DBVerifyResult(false, "[" + value + "]超过最大长度限制,最大限制[" + max + "]");
- }
- }
- }
- return new DBVerifyResult(true, "成功");
- }
- // /**
- // * 获取流程学校code
- // *
- // * @return
- // */
- // public static Map<String, List<String>> getFlowSchoolCodeMap() {
- // DictionaryConfig dictionaryConfig = SpringContextHolder.getBean(DictionaryConfig.class);
- // Map<String, List<String>> flowSchoolCodeMap = dictionaryConfig.sysDomain().getFlowSchoolCodeMap();
- // Optional.ofNullable(flowSchoolCodeMap).orElseThrow(() -> ExceptionResultEnum.ERROR.exception("未配置学校流程code"));
- // return flowSchoolCodeMap;
- // }
- /**
- * 验证参数任意一个为空
- *
- * @param objects 要非空校验的参数
- */
- public static boolean isOneNull(Object... objects) {
- boolean result = false;
- for (Object object : objects) {
- if (Objects.isNull(object)) {
- result = true;
- } else if (object instanceof String) {
- String param = String.valueOf(object);
- if (param.length() == 0 || param.equals("null")) {
- result = true;
- }
- } else if (object instanceof Long) {
- Long param = SystemConstant.convertIdToLong(String.valueOf(object));
- if (param == null || param == 0) {
- result = true;
- }
- } else if (object instanceof Integer) {
- int param = Integer.parseInt(String.valueOf(object));
- if (param == 0) {
- result = true;
- }
- }
- }
- return result;
- }
- /**
- * 构建流程变量
- *
- * @param objectId
- * @param o
- * @param tfCustomTypeEnum
- * @param approveId
- * @param flowSubmit
- * @return
- */
- public static Map<String, Object> buildFlowVar(Long objectId,
- Object o,
- TFCustomTypeEnum tfCustomTypeEnum,
- Long approveId,
- boolean flowSubmit) {
- Map<String, Object> map = new HashMap<>();
- map.computeIfAbsent(SystemConstant.OBJECT_ID, v -> objectId);
- map.computeIfAbsent(SystemConstant.OBJECT_DATA, v -> o);
- map.computeIfAbsent(SystemConstant.FLOW_TYPE, v -> tfCustomTypeEnum);
- map.computeIfAbsent(SystemConstant.APPROVE_ID, v -> approveId);
- map.computeIfAbsent(SystemConstant.FLOW_SUBMIT, v -> flowSubmit);
- return map;
- }
- /**
- * 跨步数组(将list集合按照数量拆分成多个集合)
- *
- * @param datasource 数据源(初始大数据集合)
- * @param step 跨步(多少个元素一个集合)
- * @param <T> 泛型
- * @return 拆分好地集合的集合
- */
- public static <T> List<List<T>> getStepList(List<T> datasource, int step) {
- List<List<T>> result = new ArrayList<>();
- int size = datasource.size();
- for (int i = 0; i < size; i = i + step) {
- List<T> cell = datasource.stream().skip(i).limit(step).collect(Collectors.toList());
- result.add(cell);
- }
- return result;
- }
- /**
- * 跨步数组(将list集合按照cpu核心数量拆分成多个集合)
- *
- * @param datasource 数据源
- * @param <T> 泛型
- * @return 拆分好地集合的集合
- */
- public static <T> List<List<T>> getStepList(List<T> datasource) {
- int cpuNum = Runtime.getRuntime().availableProcessors();
- int step = datasource.size() / cpuNum + 1;
- List<List<T>> result = new ArrayList<>();
- int size = datasource.size();
- for (int i = 0; i < size; i = i + step) {
- List<T> cell = datasource.stream().skip(i).limit(step).collect(Collectors.toList());
- result.add(cell);
- }
- return result;
- }
- /**
- * URL 编码, Encode默认为UTF-8.
- */
- public static String urlEncode(String part) {
- try {
- return URLEncoder.encode(part, SystemConstant.CHARSET_NAME);
- } catch (UnsupportedEncodingException e) {
- throw ExceptionResultEnum.ERROR.exception(e.getMessage());
- }
- }
- /**
- * 图片转换
- *
- * @param imgBase64
- * @param filePath
- * @throws IOException
- */
- public static void base64ToImage(String imgBase64, String filePath) throws IOException {
- OutputStream out = null;
- try {
- byte[] b = Base64Util.decode(imgBase64);
- out = new FileOutputStream(filePath);
- IOUtils.write(b, out);
- } catch (Exception e) {
- e.printStackTrace();
- } finally {
- if (Objects.nonNull(out)) {
- out.flush();
- out.close();
- }
- }
- }
- /**
- * 将对象装换为map
- *
- * @param bean
- * @return
- */
- public static Map<String, Object> beanToMap(Object bean) {
- Map map = new HashMap<>();
- if (bean != null) {
- BeanMap beanMap = BeanMap.create(bean);
- for (Object key : beanMap.keySet()) {
- map.put(String.valueOf(key), beanMap.get(key));
- }
- }
- return map;
- }
- /**
- * 将map装换为javabean对象
- *
- * @param map
- * @param bean
- * @return
- */
- public static Object mapToBean(Map<String, Object> map, Object bean) {
- BeanMap beanMap = BeanMap.create(bean);
- beanMap.putAll(map);
- return bean;
- }
- /**
- * 获取本地文件host
- *
- * @param hostUrl
- * @return
- */
- public static String getLocalFileHost(String hostUrl) {
- CommonCacheService commonCacheService = SpringContextHolder.getBean(CommonCacheService.class);
- if (hostUrl.contains("*")) {
- SysUser sysUser = (SysUser) ServletUtil.getRequestUser();
- BasicSchool basicSchool = commonCacheService.schoolCache(sysUser.getSchoolId());
- hostUrl = hostUrl.replace("*", basicSchool.getCode());
- }
- return hostUrl;
- }
- /**
- * 获取本地文件host
- *
- * @param hostUrl
- * @param userId
- * @return
- */
- public static String getLocalFileHostByUserId(String hostUrl, Long userId) {
- CommonCacheService commonCacheService = SpringContextHolder.getBean(CommonCacheService.class);
- if (hostUrl.contains("*")) {
- SysUser sysUser = commonCacheService.userCache(userId);
- BasicSchool basicSchool = commonCacheService.schoolCache(sysUser.getSchoolId());
- hostUrl = hostUrl.replace("*", basicSchool.getCode());
- }
- return hostUrl;
- }
- /**
- * 获取本地文件路径
- *
- * @param filePath
- * @return
- */
- public static String getLocalFilePath(String hostUrl, String filePath) {
- Optional.ofNullable(hostUrl).orElseThrow(() -> ExceptionResultEnum.ERROR.exception("未配置hostUrl"));
- String[] hostArray = hostUrl.split(":");
- if (hostArray.length == 2 && filePath.contains(SystemConstant.FILE_TEMP)) {
- filePath = filePath.substring(filePath.indexOf(SystemConstant.FILE_TEMP), filePath.length());
- } else if (hostArray.length == 2 && filePath.contains(SystemConstant.PDF_TEMP)) {
- filePath = filePath.substring(filePath.indexOf(SystemConstant.PDF_TEMP), filePath.length());
- }
- return filePath;
- }
- }
|