| | |
| | | package com.fzzy.igds.utils; |
| | | |
| | | import com.fzzy.igds.camera.data.ydqly.YdQlyNode; |
| | | import com.fzzy.igds.constant.GrainFrequence; |
| | | import com.ruoyi.common.config.FrameworkConfig; |
| | | import com.ruoyi.common.core.domain.entity.SysUser; |
| | | import com.ruoyi.common.utils.ShiroUtils; |
| | |
| | | private static final AtomicLong sequence = new AtomicLong(0); |
| | | private static String lastTimestamp = ""; |
| | | |
| | | |
| | | //全局用户实时坐在部门 |
| | | public static Map<String, String> contextUserDept = new HashMap<>(); |
| | | |
| | | /** |
| | | * 全局用于存放SN与组织编码的关系,例如分机SN和组织编码关系 |
| | | */ |
| | | public static Map<String, String> contextSnCompanyIdMap = new HashMap<>(); |
| | | |
| | | /** |
| | | * 流媒体节点使用 |
| | | */ |
| | | public static List<YdQlyNode> nodeList = null; |
| | | |
| | | /** |
| | | * 生成顺序ID:年月日时分秒毫秒(17位) + 序列号(4位) = 21位 |
| | | */ |
| | | public static String generateId() { |
| | | String pattern = "yyyyMMddHHmmssSSS"; |
| | | return generateId(null, pattern); |
| | | } |
| | | |
| | | /** |
| | | * 生成单据编码, (格式: yyyyMMddHHmmss + 4位随机数) |
| | | * @param prefix |
| | | * @return |
| | | */ |
| | | public static String generateOrderId(String prefix) { |
| | | String pattern = "yyyyMMddHHmmss"; |
| | | return generateId(prefix, pattern); |
| | | } |
| | | |
| | | /** |
| | | * |
| | | * |
| | | * @return |
| | | */ |
| | | public static String generateId() { |
| | | String currentTimestamp = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyyMMddHHmmssSSS")); |
| | | private static String generateId(String prefix, String pattern) { |
| | | if (null == pattern) pattern = "yyyyMMddHHmmss"; |
| | | String currentTimestamp = LocalDateTime.now().format(DateTimeFormatter.ofPattern(pattern)); |
| | | long seq; |
| | | synchronized (ContextUtil.class) { |
| | | if (currentTimestamp.equals(lastTimestamp)) { |
| | |
| | | } else { |
| | | sequence.set(0); |
| | | seq = 0; |
| | | |
| | | lastTimestamp = currentTimestamp; |
| | | } |
| | | } |
| | | return String.format("%s%04d", currentTimestamp, seq); |
| | | |
| | | if (null == prefix) return String.format("%s%02d", currentTimestamp, seq); |
| | | return prefix + "_" + String.format("%s%02d", currentTimestamp, seq); |
| | | } |
| | | |
| | | |
| | | public static String UUID() { |
| | | return UUID.randomUUID().toString().replaceAll("-", ""); |
| | |
| | | public static String getCompanyId() { |
| | | |
| | | SysUser user = ShiroUtils.getSysUser(); |
| | | if(null != user) return user.getCompanyId(); |
| | | if (null != user) return user.getCompanyId(); |
| | | return FrameworkConfig.getCompanyId(); |
| | | } |
| | | |
| | | public static String getLoginUserName() { |
| | | SysUser user = ShiroUtils.getSysUser(); |
| | | return null == user ? "系统" : user.getUserName(); |
| | | } |
| | | |
| | | public static String getLoginName() { |
| | | SysUser user = ShiroUtils.getSysUser(); |
| | | return null == user ? "sys" : user.getLoginName(); |
| | | } |
| | | |
| | | public static SysUser getLoginUser() { |
| | |
| | | Integer index5 = 100001; |
| | | Integer index = 0; |
| | | String orderId = "001"; |
| | | if(StringUtils.isNotEmpty(oldOrderId)){ |
| | | if (StringUtils.isNotEmpty(oldOrderId)) { |
| | | index = Integer.valueOf(oldOrderId); |
| | | } |
| | | if(3 == num){ |
| | | if (3 == num) { |
| | | orderId = ((index3 + index) + "").substring(1); |
| | | } |
| | | if(4 == num){ |
| | | if (4 == num) { |
| | | orderId = ((index4 + index) + "").substring(1); |
| | | } |
| | | if(5 == num){ |
| | | if (5 == num) { |
| | | orderId = ((index5 + index) + "").substring(1); |
| | | } |
| | | return orderId; |
| | | } |
| | | |
| | | /** |
| | | * 存放SN与所属组织的关系 |
| | | * |
| | | * @param sn |
| | | * @param companyId |
| | | */ |
| | | public static void addSerCompany(String sn, String companyId) { |
| | | contextSnCompanyIdMap.put(sn, companyId); |
| | | } |
| | | |
| | | /** |
| | | * 通过SN获取当前SN所属的组织 |
| | | * |
| | | * @param sn |
| | | * @return |
| | | */ |
| | | public static String getCompanyIdBySn(String sn) { |
| | | return contextSnCompanyIdMap.get(sn); |
| | | } |
| | | |
| | | public static String getTimeId() { |
| | | return DateFormatUtils.format(new Date(), "yyyyMMddHHmmss"); |
| | | } |
| | | |
| | | public static String getTimeId(int start, int end) { |
| | | return DateFormatUtils.format(new Date(), "yyyyMMddHHmmss") + RandomUtils.nextInt(start, end); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 如果用户是库区用户,判断是否数据公司级别 |
| | | * |
| | | * @param userDeptId 当前用户部门ID |
| | | * @return 如果部门ID大于长度7说明是库区,否则就是公司级别 |
| | | */ |
| | | public static boolean isDepotUser(String userDeptId) { |
| | | if(StringUtils.isBlank(userDeptId)) return false; |
| | | return userDeptId.length() > 7; |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 根据系统配置的批次频率获取批次编号 |
| | | * |
| | | * @param freq |
| | | * @return |
| | | */ |
| | | public static String getBatchIdByFireq(String freq) { |
| | | // 一天一次 |
| | | if (GrainFrequence.FREQ_02.getCode().equals(freq)) { |
| | | return DateFormatUtils.format(new Date(), "yyyyMMdd") + "1801"; |
| | | } |
| | | |
| | | // 一天两次 |
| | | if (GrainFrequence.FREQ_03.getCode().equals(freq)) { |
| | | String hour = DateFormatUtils.format(new Date(), "HH"); |
| | | if (Integer.valueOf(hour) >= 0 && Integer.valueOf(hour) <= 12) { |
| | | return DateFormatUtils.format(new Date(), "yyyyMMdd") + "1301"; |
| | | } else { |
| | | return DateFormatUtils.format(new Date(), "yyyyMMdd") + "1802"; |
| | | } |
| | | } |
| | | return getDefaultBatchId(); |
| | | } |
| | | |
| | | public static String getDefaultBatchId() { |
| | | return DateFormatUtils.format(new Date(), "yyyyMMddHHmm"); |
| | | } |
| | | |
| | | public static void main(String[] args) { |
| | | for (int i = 0; i < 10; i++){ |
| | | String id = generateId(); |
| | | System.out.println(id); |
| | | } |
| | | } |
| | | } |