SystemConstant.java 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683
  1. package com.qmth.teachcloud.common.contant;
  2. import com.qmth.boot.core.uid.service.UidService;
  3. import com.qmth.teachcloud.common.annotation.DBVerify;
  4. import com.qmth.teachcloud.common.bean.result.DBVerifyResult;
  5. import com.qmth.teachcloud.common.config.DictionaryConfig;
  6. import com.qmth.teachcloud.common.entity.BasicSchool;
  7. import com.qmth.teachcloud.common.entity.SysUser;
  8. import com.qmth.teachcloud.common.enums.ExceptionResultEnum;
  9. import com.qmth.teachcloud.common.enums.TFCustomTypeEnum;
  10. import com.qmth.teachcloud.common.service.CommonCacheService;
  11. import com.qmth.teachcloud.common.util.Base64Util;
  12. import com.qmth.teachcloud.common.util.ServletUtil;
  13. import org.apache.commons.io.IOUtils;
  14. import org.springframework.cglib.beans.BeanMap;
  15. import javax.annotation.Resource;
  16. import java.io.FileOutputStream;
  17. import java.io.IOException;
  18. import java.io.OutputStream;
  19. import java.io.UnsupportedEncodingException;
  20. import java.lang.reflect.Field;
  21. import java.math.BigDecimal;
  22. import java.net.URLEncoder;
  23. import java.nio.charset.Charset;
  24. import java.util.*;
  25. import java.util.stream.Collectors;
  26. /**
  27. * @Description: 系统常量
  28. * @Param:
  29. * @return:
  30. * @Author: wangliang
  31. * @Date: 2019/10/11
  32. */
  33. public class SystemConstant {
  34. @Resource
  35. DictionaryConfig dictionaryConfig;
  36. /**
  37. * 系统常量
  38. */
  39. public static final String CHARSET_NAME = "UTF-8";
  40. // public static final String CHARSET_GB2312 = "gb2312";
  41. public static final String CHARSET_GBK = "gbk";
  42. public static final Charset CHARSET = Charset.forName(CHARSET_NAME);
  43. public static final String MD5 = "MD5";
  44. public static final String SUCCESS = "success";
  45. public static final String EXTEND_COLUMN = "extendColumn";
  46. public static final String USER_DIR = "user.dir";
  47. public static final String PDF_TEMP = "pdf-temp";
  48. public static final String FILE_TEMP = "file-temp";
  49. public static final String SESSION = "session:";
  50. public static final String TASK = "task";
  51. public static final String TB_TASK_ID = "tbTaskId";
  52. public static final String TB_SYNC_TASK = "tbSyncTask";
  53. public static final String TB_SYNC_TASK_ID = "tbSyncTaskId";
  54. public static final String USER = "account";
  55. public static final String SCHOOL_ID = "schoolId";
  56. public static final String SCHOOL = "school";
  57. public static final String ORG = "org";
  58. public static final String ERROR = "/error";
  59. public static final String METHOD = "post";
  60. public static final String DEFAULT_PASSWORD = "MTIzNDU2";
  61. public static final String UPDATE_TIME = "updateTime";
  62. public static final String PATH = "path";
  63. public static final String PDF_PATH = "pdfPath";
  64. public static final String HTML_PATH = "htmlPath";
  65. public static final String TYPE = "type";
  66. public static final String LOCAL = "local";
  67. public static final String OSS = "oss";
  68. public static final String LOGO = "logo";
  69. public static final String UPLOAD_TYPE = "uploadType";
  70. public static final String ID = "id";
  71. public static final String MODEL = "model";
  72. public static final String VERSION = "version";
  73. public static final String FLOW_ENTITY_ID = "flowEntityId";
  74. public static final String CUSTOM_FLOW_ID = "customFlowId";
  75. public static final String ACT_FLOW_ID = "actFlowId";
  76. public static final String FLOW_PROCESS_VAR_MAP = "flowProcessVarMap";
  77. public static final String PROCESS_DEFINITION_ID = "processDefinitionId";
  78. public static final String FILE = "file";
  79. public static final String SIZE = "size";
  80. public static final String HTML_PREFIX = ".html";
  81. public static final String PDF_PREFIX = ".pdf";
  82. public static final String FTL_PREFIX = ".ftl";
  83. public static final String ZIP_PREFIX = ".zip";
  84. // public static final String JPG_PREFIX = ".jpg";
  85. public static final String DEFAULT_DATE_PATTERN = "yyyy-MM-dd HH:mm:ss";
  86. public static final int PAGE_NUMBER = 0;
  87. public static final int PAGE_SIZE = 10000000;
  88. public static final int PAGE_SIZE_MIN = 10;
  89. public static final int PAGE_SIZE_MAX = 500;
  90. public static final int PAGE_NUMBER_MIN = 1;
  91. public static final int IN_SIZE_MAX = 1000;
  92. public static final int ALL_CARD = -1;
  93. public static final String MANUAL = "manual";
  94. public static final String DELIMITER = ":";
  95. public static final String COMMA = ",";
  96. public static final int FINAL_SCALE = 1;
  97. public static final int CALCULATE_SCALE = 4;
  98. // public static final int OPER_SCALE = 8;
  99. public static final BigDecimal PERCENT = new BigDecimal(100);
  100. public static final String HYPHEN = "-";
  101. public static final String DEFAULT_SIGN = "#";
  102. public static final String PARENT_ORG = "教务处";
  103. public static final String SCHOOL_CODE = "wdfx";
  104. public static final String ADMIN_CODE = "admin";
  105. public static final String AUTH = "auth";//命题老师id
  106. // public static final int MAX_RETRY_CREATE_PDF_COUNT = 5;
  107. //英文字母、数字、中文括号、英文括号、下划线(_)、减号(-)、中文横线(—)
  108. public static final String REGULAR_EXPRESSION_OF_CODE = "[a-zA-Z0-9](\\w+)?-?(\\w+)?—?(\\w+)?(\\((\\w+)?-?(\\w+)?—?(\\w+)?\\))?(\\((\\w+)?-?(\\w+)?—?(\\w+)?\\))?(\\w+)?";
  109. public static final String REGULAR_EXPRESSION_OF_PHONE = "((\\d{3,4})|(\\(\\d{3,4}\\)-))?\\d{7,8}";
  110. public static final String REGULAR_EXPRESSION_OF_CODE_PRIMARY_DIMENSION = "[A-Z]";
  111. public static final String REGULAR_EXPRESSION_OF_CODE_SECOND_DIMENSION = "[A-Z][1-9][0-9]*";
  112. public static final String SYS_USER = "sysUser";
  113. public static final String DATA_COUNT = "dataCount";
  114. public static final List<Long> MENU_MANAGE = Arrays.asList(507L, 508L, 530L, 531L, 675L, 676L);
  115. public static final float PAPER_DEVIATION = 2;
  116. public static final String COMMA_OF_ENGLISH = ",";
  117. public static final String COMMA_OF_CHINESE = ",";
  118. public static final String PAUSE_SIGN = "、";
  119. public static final String ORG_SPLIT = "/";
  120. public static final String PUSH_OPERATE_NOTICE = "操作成功,请去基础配置 -> 系统设置 -> 同步管理中查看结果";
  121. public static final String EXCEL_PROTECT_KEY = "Qmth87863577";
  122. /**
  123. * oss url过期时间
  124. */
  125. // public static final int OSS_URL_EXPIRE = 5 * 60 * 1000;//过期时间5分钟
  126. /**
  127. * 缓存配置
  128. */
  129. public static final String USER_OAUTH_CACHE = "user:oauth:cache";
  130. public static final String USER_ACCOUNT_CACHE = "user:account:cache";
  131. public static final String USER_MENU_CACHE = "user:menu:cache";
  132. public static final String SCHOOL_CACHE = "school:cache";
  133. public static final String SCHOOL_CODE_CACHE = "school:code:cache";
  134. public static final String ORG_CACHE = "org:cache";
  135. public static final String PRIVILEGE_URL_CACHE = "privilege:url:cache";
  136. public static final String ROLE_PRIVILEGE_CACHE = "role:privilege:cache";
  137. public static final String USER_ROLE_PRIVILEGE_CACHE = "user:role:privilege:cache";
  138. public static final String ROLE_CACHE = "role:cache";
  139. public static final String AUTH_INFO_CACHE = "auth:info:cache";
  140. public static final String TXT_CHARSET_CACHE = "charset:txt:cache";
  141. /**
  142. * 报表缓存
  143. */
  144. public static final String EXAM_STUDENT_REPORT = "report:cache:examStudent";
  145. public static final String COLLEGE_DEAN_REPORT = "report:cache:collegeDean";
  146. public static final String COLLEGE_COURSE_REPORT = "report:cache:collegeCourse";
  147. public static final String SURVEY_TEACHER_VIEW_REPORT = "report:cache:surveyTeacherView";
  148. public static final String TEACHER_VIEW_REPORT = "report:cache:teacherView";
  149. public static final String TEACHER_ANSWER_VIEW_REPORT = "report:cache:teacherAnswerView";
  150. /**
  151. * 鉴权
  152. */
  153. public static final String HEADER_AUTHORIZATION = "Authorization";
  154. public static final String HEADER_TIME = "time";
  155. public static final String HEADER_PLATFORM = "platform";
  156. public static final String HEADER_DEVICE_ID = "deviceId";
  157. public static final String TOKEN = "token";
  158. public static final String SIGN = "sign";
  159. /**
  160. * redis
  161. */
  162. public static final int DEFAULT_SESSION_EXPIRE = 1;//过期时间1天
  163. public static final long REDIS_DEFAULT_EXPIRE_TIME = 24 * 60L * 60L;//过期时间24小时
  164. public static final long REDIS_THIRD_USER_AUTH_EXPIRE_TIME = 2 * 60L;//过期时间2分钟
  165. /**
  166. * redis mq
  167. */
  168. public static final String REDIS_LOCK_MQ_PREFIX = "redis:lock:mq:";
  169. public static final int REDIS_MQ_MAX_RECONSUME = 5;
  170. public static final String MQ_TOPIC_BUFFER_LIST = "mq:topic:buffer:list";
  171. public static final String REDIS_LOCK_BATCH_NO_PREFIX = "redis:lock:batchNo:";//
  172. public static final String REDIS_LOCK_GRADE_COURSE_DELETE_PREFIX = "redis:lock:courseInfo:";
  173. public static final String REDIS_LOCK_GRADE_EXAM_DELETE_PREFIX = "redis:lock:exam:";
  174. /**
  175. * redis lock
  176. */
  177. public static final int MAX_RETRY_COUNT = 30;
  178. public static final long REDIS_CACHE_TIME_OUT = 60L;
  179. public static final long REDIS_LOCK_MQ_TIME_OUT = 60L;
  180. public static final long REDIS_LOCK_BATCH_NO_TIME_OUT = 60L * 30;
  181. /**
  182. * aes相关
  183. */
  184. public static final String AES = "AES";
  185. public static final String AES_MODE_PKCS5 = "AES/CBC/PKCS5Padding";//用这个模式,规则必须为16位
  186. public static final String AES_MODE_PKCS7 = "AES/CBC/PKCS7Padding";//用这个模式,规则必须为16位
  187. public static final String AES_RULE = "1234567890123456";//aes密钥
  188. /**
  189. * 变量
  190. */
  191. // public static String TEMP_FILES_DIR;
  192. // public static String PDF_TEMP_FILES_DIR;
  193. /**
  194. * excel相关
  195. */
  196. public static final String XLSX = "xlsx";
  197. public static final String XLS = "xls";
  198. /**
  199. * 线程池配置
  200. */
  201. public static final String THREAD_POOL_NAME = "taskThreadPool";
  202. // public static final int THREAD_POOL_CORE_POOL_SIZE = 5;
  203. // public static final int THREAD_POOL_MAX_POOL_SIZE = 100;
  204. public static final int THREAD_POOL_KEEP_ALIVE_SECONDS = 10;
  205. public static final int THREAD_POOL_QUEUE_CAPACITY = 500;
  206. /**
  207. * mq消息
  208. */
  209. public static final int DELIVERED_ACK_TYPE = 0;//消息"已发出",但尚未处理结束
  210. public static final int POSION_ACK_TYPE = 1;//消息"错误",通常表示"抛弃"此消息,比如消息重发多次后,都无法正确处理时,消息将会被删除或者DLQ(死信队列)
  211. public static final int STANDARD_ACK_TYPE = 2;//"标准"类型,通常表示为消息"处理成功",broker端可以删除消息了
  212. public static final int REDELIVERED_ACK_TYPE = 3;//消息需"重发",比如consumer处理消息时抛出了异常,broker稍后会重新发送此消息
  213. public static final int INDIVIDUAL_ACK_TYPE = 4;//表示只确认"单条消息",无论在任何ACK_MODE下
  214. public static final int UNMATCHED_ACK_TYPE = 5;//BROKER间转发消息时,接收端"拒绝"消息
  215. public static final int UNSEND_ACK_TYPE = 6;//消息未发出
  216. /**
  217. * activiti
  218. */
  219. public static final String APPROVE_ID = "approveId";//审批id
  220. public static final String FLOW_SUBMIT = "flowSubmit";//命题提交申请
  221. public static final String FLOW_JOIN_TYPE = "flowJoinType";//流程关联类型
  222. public static final String OLD_FLOW_ID = "oldFlowId";//旧流程id
  223. public static final String FLOW_TYPE = "flowType";//流程类型
  224. public static final String FLOW_ID = "flowId";//流程id
  225. public static final String FLOW_TASK_ID = "flowTaskId";//流程任务id
  226. public static final String APPROVE = "approve";//流程审核变量
  227. public static final String AGGINESS_MAP = "agginessMap";//流程审批人变量
  228. public static final String APPROVE_PASS_MAP = "approvePassMap";//流程审批通过变量
  229. public static final String APPROVE_REJECT_MAP = "approveRejectMap";//流程审批驳回变量
  230. public static final String APPROVE_USER_IDS = "approveUserIds";//流程审批人列表
  231. public static final String SETUP_MAP = "setupMap";//流程步骤变量
  232. public static final String APPROVE_SETUP = "approveSetup";//流程节点
  233. public static final String APPROVE_OPERATION = "approveOperation";//流程操作
  234. public static final String FLOW_STATUS = "flowStatus";//流程状态
  235. public static final String APPROVE_REMARK = "approveRemark";//流程审批意见
  236. public static final String OBJECT_ID = "objectId";
  237. public static final String OBJECT_DATA = "objectData";
  238. public static final String APPROVE_TF_FLOW_LOG = "TFFlowLog";//流程院长自动审批
  239. public static final String PAPAER_ATTACHMENT_IDS = "paperAttachmentIds";//命题附件ids
  240. public static final String REDIS_LOCK_FLOW_TASK_PREFIX = "redis:lock:flow:task:";//流程节点锁
  241. public static final String REDIS_LOCK_EXAM_TASK_FLOW_PREFIX = "redis:lock:exam:task:flow:";//考试任务流程节点锁
  242. public static final long REDIS_LOCK_FLOW_TASK_TIME_OUT = 60L * 2;
  243. public static final long REDIS_LOCK_EXAM_TASK_FLOW_TIME_OUT = 60L * 2;
  244. public static final String REDIS_LOCK_FLOW_PREFIX = "redis:lock:flow:";//流程锁
  245. public static final long REDIS_LOCK_FLOW_TIME_OUT = 60L * 2;
  246. public static final String REDIS_LOCK_CUSTOM_FLOW_PREFIX = "redis:lock:custom:flow:";//自定义流程锁
  247. public static final long REDIS_LOCK_CUSTOM_FLOW_TIME_OUT = 60L * 2;
  248. public static final String REDIS_LOCK_CALCULATE_PREFIX = "redis:lock:calculate:";//计算锁
  249. public static final long REDIS_LOCK_CALCULATE_TIME_OUT = 60L * 60;
  250. /**
  251. * 机器心跳
  252. */
  253. public static final String CURRENT_TASK_MACHINE_ID = "current_task_machine_id";//当前机器id
  254. public static final String TASK_MACHINE_ID = "task_machine_id:";//任务机器id
  255. public static final String TASK_MACHINE_ID_LIKE = "task_machine_id*";//任务机器like
  256. public static final String LOG_ERROR = "请求出错:";
  257. /**
  258. * http设置
  259. */
  260. public static final int CONNECT_TIME_OUT = 1000 * 60 * 2;//请求超时
  261. public static final int SOCKET_CONNECT_TIME_OUT = 1000 * 60 * 30;//读取数据超时
  262. // /**
  263. // * 初始化附件文件路径
  264. // */
  265. // public static void initTempFiles() {
  266. // File fileTempDir = null, pdfTempDir = null;
  267. // DictionaryConfig dictionaryConfig = SpringContextHolder.getBean(DictionaryConfig.class);
  268. //
  269. // if (Objects.nonNull(dictionaryConfig.sysDomain().getFileTempPath()) && !Objects.equals("", dictionaryConfig.sysDomain().getFileTempPath())) {
  270. // fileTempDir = new File(dictionaryConfig.sysDomain().getFileTempPath().trim());
  271. // } else {
  272. // StringJoiner fileTempLocalPath = new StringJoiner("").add(System.getProperty(USER_DIR));
  273. // String mkdir = fileTempLocalPath.toString().substring(0, fileTempLocalPath.toString().lastIndexOf(File.separator));
  274. // fileTempDir = new File(new StringBuffer(mkdir).append(File.separator).append(FILE_TEMP).toString());
  275. // }
  276. // if (Objects.nonNull(fileTempDir) && !fileTempDir.exists()) {
  277. // fileTempDir.mkdirs();
  278. // }
  279. //
  280. // if (Objects.nonNull(dictionaryConfig.sysDomain().getPdfTempPath()) && !Objects.equals("", dictionaryConfig.sysDomain().getPdfTempPath())) {
  281. // pdfTempDir = new File(dictionaryConfig.sysDomain().getPdfTempPath().trim());
  282. // } else {
  283. // StringJoiner pdfTempLocalPath = new StringJoiner("").add(System.getProperty(USER_DIR));
  284. // String mkdir = pdfTempLocalPath.toString().substring(0, pdfTempLocalPath.toString().lastIndexOf(File.separator));
  285. // pdfTempDir = new File(new StringBuffer(mkdir).append(File.separator).append(PDF_TEMP).toString());
  286. // }
  287. // if (Objects.nonNull(pdfTempDir) && !pdfTempDir.exists()) {
  288. // pdfTempDir.mkdirs();
  289. // }
  290. // TEMP_FILES_DIR = fileTempDir.getPath();
  291. // PDF_TEMP_FILES_DIR = pdfTempDir.getPath();
  292. // }
  293. /**
  294. * id转换为long
  295. *
  296. * @return
  297. */
  298. public static Long convertIdToLong(String id) {
  299. return Objects.nonNull(id) && id.length() > 0 ? Long.parseLong(id) : null;
  300. }
  301. /**
  302. * id转换为Integer
  303. *
  304. * @return
  305. */
  306. public static Integer convertIdToInteger(String id) {
  307. return Objects.nonNull(id) && id.length() > 0 ? Integer.parseInt(id) : null;
  308. }
  309. /**
  310. * 获取全局uuid
  311. *
  312. * @return
  313. */
  314. public static String getUuid() {
  315. return String.valueOf(UUID.randomUUID()).replaceAll("-", "");
  316. }
  317. /**
  318. * 获取数据库uuid
  319. *
  320. * @return
  321. */
  322. public static Long getDbUuid() {
  323. UidService uidservice = SpringContextHolder.getBean(UidService.class);
  324. return uidservice.getId();
  325. }
  326. /**
  327. * enable转换
  328. *
  329. * @return
  330. */
  331. public static Boolean convertEnable(Boolean enable) {
  332. return Objects.nonNull(enable) ? enable : true;
  333. }
  334. /**
  335. * 试卷类型转换
  336. *
  337. * @param paperType
  338. * @return
  339. */
  340. public static String convertPaperType(String paperType) {
  341. paperType = paperType.toLowerCase();
  342. int ascii = (int) paperType.charAt(0);
  343. return String.valueOf(ascii + 704);
  344. }
  345. /**
  346. * 模糊查询时调用以去除符号"%","_"特殊字符对查询结果的影响
  347. *
  348. * @param param 要校验的参数
  349. * @return 转译后的参数
  350. */
  351. public static String translateSpecificSign(String param) {
  352. if (param == null) {
  353. return null;
  354. }
  355. if (param.contains("%")) {
  356. param = param.replaceAll("%", "\\\\%");
  357. }
  358. if (param.contains("_")) {
  359. param = param.replaceAll("_", "\\\\_");
  360. }
  361. return param;
  362. }
  363. public static void verifyLength(String str, int length, String name) {
  364. if (str == null || str.length() == 0 || str.equals("null")) {
  365. throw ExceptionResultEnum.ERROR.exception(name + "不能为空");
  366. }
  367. if (str.length() > length) {
  368. throw ExceptionResultEnum.ERROR.exception("[" + name + ":" + str + "]' 超过长度限制 : " + length);
  369. }
  370. }
  371. public static boolean strNotNull(String str) {
  372. return str != null && str.length() > 0 && !str.equals("null");
  373. }
  374. /**
  375. * Long 类型的参数不为空
  376. *
  377. * @param x 参数
  378. * @return true:不为空、false:为空
  379. */
  380. public static boolean longNotNull(Long x) {
  381. return x != null && x > 0;
  382. }
  383. public static Long getHeadOrUserSchoolId() {
  384. SysUser sysUser = (SysUser) ServletUtil.getRequestUser();
  385. Long schoolId;
  386. if (Objects.nonNull(ServletUtil.getRequestHeaderSchoolIdByNotVaild())) {
  387. schoolId = Long.parseLong(ServletUtil.getRequestHeaderSchoolIdByNotVaild().toString());
  388. } else {
  389. schoolId = sysUser.getSchoolId();
  390. }
  391. return schoolId;
  392. }
  393. /**
  394. * 检验字段
  395. *
  396. * @param obj 被检验的映射类对象
  397. * @param clazz 该对象的类
  398. * @return 检验结果(状态 、 信息)
  399. * @throws IllegalAccessException 异常
  400. */
  401. public static DBVerifyResult verifyDBFields(Object obj, Class<?> clazz) throws IllegalAccessException {
  402. Field[] fields = clazz.getDeclaredFields();
  403. for (Field field : fields) {
  404. field.setAccessible(true); // 解除封装
  405. String fieldValue = String.valueOf(field.get(obj));
  406. DBVerify dbVerify = field.getAnnotation(DBVerify.class);
  407. if (Objects.isNull(dbVerify)) {
  408. continue;
  409. }
  410. String value = dbVerify.value();
  411. boolean required = dbVerify.required();
  412. int min = dbVerify.min();
  413. int max = dbVerify.max();
  414. if (required) {
  415. if (fieldValue == null || fieldValue.length() == 0 || fieldValue.equals("null")) {
  416. return new DBVerifyResult(false, "[" + value + "]为必须字段,不能为空");
  417. }
  418. }
  419. if (fieldValue != null && min > 0) {
  420. if (fieldValue.length() < min) {
  421. return new DBVerifyResult(false, "[" + value + "]低于最小长度限制,最小限制[" + min + "]");
  422. }
  423. }
  424. if (fieldValue != null && max > 0) {
  425. if (fieldValue.length() > max) {
  426. return new DBVerifyResult(false, "[" + value + "]超过最大长度限制,最大限制[" + max + "]");
  427. }
  428. }
  429. }
  430. return new DBVerifyResult(true, "成功");
  431. }
  432. // /**
  433. // * 获取流程学校code
  434. // *
  435. // * @return
  436. // */
  437. // public static Map<String, List<String>> getFlowSchoolCodeMap() {
  438. // DictionaryConfig dictionaryConfig = SpringContextHolder.getBean(DictionaryConfig.class);
  439. // Map<String, List<String>> flowSchoolCodeMap = dictionaryConfig.sysDomain().getFlowSchoolCodeMap();
  440. // Optional.ofNullable(flowSchoolCodeMap).orElseThrow(() -> ExceptionResultEnum.ERROR.exception("未配置学校流程code"));
  441. // return flowSchoolCodeMap;
  442. // }
  443. /**
  444. * 验证参数任意一个为空
  445. *
  446. * @param objects 要非空校验的参数
  447. */
  448. public static boolean isOneNull(Object... objects) {
  449. boolean result = false;
  450. for (Object object : objects) {
  451. if (Objects.isNull(object)) {
  452. result = true;
  453. } else if (object instanceof String) {
  454. String param = String.valueOf(object);
  455. if (param.length() == 0 || param.equals("null")) {
  456. result = true;
  457. }
  458. } else if (object instanceof Long) {
  459. Long param = SystemConstant.convertIdToLong(String.valueOf(object));
  460. if (param == null || param == 0) {
  461. result = true;
  462. }
  463. } else if (object instanceof Integer) {
  464. int param = Integer.parseInt(String.valueOf(object));
  465. if (param == 0) {
  466. result = true;
  467. }
  468. }
  469. }
  470. return result;
  471. }
  472. /**
  473. * 构建流程变量
  474. *
  475. * @param objectId
  476. * @param o
  477. * @param tfCustomTypeEnum
  478. * @param approveId
  479. * @param flowSubmit
  480. * @return
  481. */
  482. public static Map<String, Object> buildFlowVar(Long objectId,
  483. Object o,
  484. TFCustomTypeEnum tfCustomTypeEnum,
  485. Long approveId,
  486. boolean flowSubmit) {
  487. Map<String, Object> map = new HashMap<>();
  488. map.computeIfAbsent(SystemConstant.OBJECT_ID, v -> objectId);
  489. map.computeIfAbsent(SystemConstant.OBJECT_DATA, v -> o);
  490. map.computeIfAbsent(SystemConstant.FLOW_TYPE, v -> tfCustomTypeEnum);
  491. map.computeIfAbsent(SystemConstant.APPROVE_ID, v -> approveId);
  492. map.computeIfAbsent(SystemConstant.FLOW_SUBMIT, v -> flowSubmit);
  493. return map;
  494. }
  495. /**
  496. * 跨步数组(将list集合按照数量拆分成多个集合)
  497. *
  498. * @param datasource 数据源(初始大数据集合)
  499. * @param step 跨步(多少个元素一个集合)
  500. * @param <T> 泛型
  501. * @return 拆分好地集合的集合
  502. */
  503. public static <T> List<List<T>> getStepList(List<T> datasource, int step) {
  504. List<List<T>> result = new ArrayList<>();
  505. int size = datasource.size();
  506. for (int i = 0; i < size; i = i + step) {
  507. List<T> cell = datasource.stream().skip(i).limit(step).collect(Collectors.toList());
  508. result.add(cell);
  509. }
  510. return result;
  511. }
  512. /**
  513. * 跨步数组(将list集合按照cpu核心数量拆分成多个集合)
  514. *
  515. * @param datasource 数据源
  516. * @param <T> 泛型
  517. * @return 拆分好地集合的集合
  518. */
  519. public static <T> List<List<T>> getStepList(List<T> datasource) {
  520. int cpuNum = Runtime.getRuntime().availableProcessors();
  521. int step = datasource.size() / cpuNum + 1;
  522. List<List<T>> result = new ArrayList<>();
  523. int size = datasource.size();
  524. for (int i = 0; i < size; i = i + step) {
  525. List<T> cell = datasource.stream().skip(i).limit(step).collect(Collectors.toList());
  526. result.add(cell);
  527. }
  528. return result;
  529. }
  530. /**
  531. * URL 编码, Encode默认为UTF-8.
  532. */
  533. public static String urlEncode(String part) {
  534. try {
  535. return URLEncoder.encode(part, SystemConstant.CHARSET_NAME);
  536. } catch (UnsupportedEncodingException e) {
  537. throw ExceptionResultEnum.ERROR.exception(e.getMessage());
  538. }
  539. }
  540. /**
  541. * 图片转换
  542. *
  543. * @param imgBase64
  544. * @param filePath
  545. * @throws IOException
  546. */
  547. public static void base64ToImage(String imgBase64, String filePath) throws IOException {
  548. OutputStream out = null;
  549. try {
  550. byte[] b = Base64Util.decode(imgBase64);
  551. out = new FileOutputStream(filePath);
  552. IOUtils.write(b, out);
  553. } catch (Exception e) {
  554. e.printStackTrace();
  555. } finally {
  556. if (Objects.nonNull(out)) {
  557. out.flush();
  558. out.close();
  559. }
  560. }
  561. }
  562. /**
  563. * 将对象装换为map
  564. *
  565. * @param bean
  566. * @return
  567. */
  568. public static Map<String, Object> beanToMap(Object bean) {
  569. Map map = new HashMap<>();
  570. if (bean != null) {
  571. BeanMap beanMap = BeanMap.create(bean);
  572. for (Object key : beanMap.keySet()) {
  573. map.put(String.valueOf(key), beanMap.get(key));
  574. }
  575. }
  576. return map;
  577. }
  578. /**
  579. * 将map装换为javabean对象
  580. *
  581. * @param map
  582. * @param bean
  583. * @return
  584. */
  585. public static Object mapToBean(Map<String, Object> map, Object bean) {
  586. BeanMap beanMap = BeanMap.create(bean);
  587. beanMap.putAll(map);
  588. return bean;
  589. }
  590. /**
  591. * 获取本地文件host
  592. *
  593. * @param hostUrl
  594. * @return
  595. */
  596. public static String getLocalFileHost(String hostUrl) {
  597. CommonCacheService commonCacheService = SpringContextHolder.getBean(CommonCacheService.class);
  598. if (hostUrl.contains("*")) {
  599. SysUser sysUser = (SysUser) ServletUtil.getRequestUser();
  600. BasicSchool basicSchool = commonCacheService.schoolCache(sysUser.getSchoolId());
  601. hostUrl = hostUrl.replace("*", basicSchool.getCode());
  602. }
  603. return hostUrl;
  604. }
  605. /**
  606. * 获取本地文件host
  607. *
  608. * @param hostUrl
  609. * @param userId
  610. * @return
  611. */
  612. public static String getLocalFileHostByUserId(String hostUrl, Long userId) {
  613. CommonCacheService commonCacheService = SpringContextHolder.getBean(CommonCacheService.class);
  614. if (hostUrl.contains("*")) {
  615. SysUser sysUser = commonCacheService.userCache(userId);
  616. BasicSchool basicSchool = commonCacheService.schoolCache(sysUser.getSchoolId());
  617. hostUrl = hostUrl.replace("*", basicSchool.getCode());
  618. }
  619. return hostUrl;
  620. }
  621. /**
  622. * 获取本地文件路径
  623. *
  624. * @param filePath
  625. * @return
  626. */
  627. public static String getLocalFilePath(String hostUrl, String filePath) {
  628. Optional.ofNullable(hostUrl).orElseThrow(() -> ExceptionResultEnum.ERROR.exception("未配置hostUrl"));
  629. String[] hostArray = hostUrl.split(":");
  630. if (hostArray.length == 2 && filePath.contains(SystemConstant.FILE_TEMP)) {
  631. filePath = filePath.substring(filePath.indexOf(SystemConstant.FILE_TEMP), filePath.length());
  632. } else if (hostArray.length == 2 && filePath.contains(SystemConstant.PDF_TEMP)) {
  633. filePath = filePath.substring(filePath.indexOf(SystemConstant.PDF_TEMP), filePath.length());
  634. }
  635. return filePath;
  636. }
  637. }