You can not select more than 25 topics
			Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
		
		
		
		
			
				
					69 lines
				
				1.9 KiB
			
		
		
			
		
	
	
					69 lines
				
				1.9 KiB
			| 
								 
											3 years ago
										 
									 | 
							
								package com.ynxbd.common.helper.common;
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								import org.apache.commons.codec.digest.DigestUtils;
							 | 
						||
| 
								 | 
							
								import org.apache.commons.lang3.ObjectUtils;
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								import java.util.Arrays;
							 | 
						||
| 
								 | 
							
								import java.util.Collections;
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/**
							 | 
						||
| 
								 | 
							
								 * @Author wsq
							 | 
						||
| 
								 | 
							
								 * @Date 2021/5/31 11:30
							 | 
						||
| 
								 | 
							
								 * @Copyright @ 2020 云南新八达科技有限公司 All rights reserved.
							 | 
						||
| 
								 | 
							
								 */
							 | 
						||
| 
								 | 
							
								public class NumHelper {
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								    /**
							 | 
						||
| 
								 | 
							
								     * 数字排序算法
							 | 
						||
| 
								 | 
							
								     *
							 | 
						||
| 
								 | 
							
								     * @param num    被排序数字
							 | 
						||
| 
								 | 
							
								     * @param isDesc 是否倒序
							 | 
						||
| 
								 | 
							
								     */
							 | 
						||
| 
								 | 
							
								    public static String numOrder(Integer num, boolean isDesc) {
							 | 
						||
| 
								 | 
							
								        String str;
							 | 
						||
| 
								 | 
							
								        try {
							 | 
						||
| 
								 | 
							
								            str = String.valueOf(num);
							 | 
						||
| 
								 | 
							
								        } catch (Exception e) {
							 | 
						||
| 
								 | 
							
								            ErrorHelper.println(e);
							 | 
						||
| 
								 | 
							
								            return null;
							 | 
						||
| 
								 | 
							
								        }
							 | 
						||
| 
								 | 
							
								        Integer[] arrays = new Integer[str.length()];
							 | 
						||
| 
								 | 
							
								        for (int i = 0; i < str.length(); i++) {
							 | 
						||
| 
								 | 
							
								            arrays[i] = Integer.parseInt(str.charAt(i) + "");
							 | 
						||
| 
								 | 
							
								        }
							 | 
						||
| 
								 | 
							
								        Arrays.sort(arrays, isDesc ? Collections.reverseOrder() : null);
							 | 
						||
| 
								 | 
							
								        StringBuilder sb = new StringBuilder();
							 | 
						||
| 
								 | 
							
								        for (Integer array : arrays) {
							 | 
						||
| 
								 | 
							
								            sb.append(array);
							 | 
						||
| 
								 | 
							
								        }
							 | 
						||
| 
								 | 
							
								        return sb.toString();
							 | 
						||
| 
								 | 
							
								    }
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								    /**
							 | 
						||
| 
								 | 
							
								     * 数字倒序排列
							 | 
						||
| 
								 | 
							
								     *
							 | 
						||
| 
								 | 
							
								     * @param num 被排序数字
							 | 
						||
| 
								 | 
							
								     */
							 | 
						||
| 
								 | 
							
								    public static String numDesc(String num) {
							 | 
						||
| 
								 | 
							
								        StringBuilder sb = new StringBuilder();
							 | 
						||
| 
								 | 
							
								        if (ObjectUtils.isEmpty(num)) {
							 | 
						||
| 
								 | 
							
								            return null;
							 | 
						||
| 
								 | 
							
								        }
							 | 
						||
| 
								 | 
							
								        for (int i = num.length() - 1; i >= 0; i--) {
							 | 
						||
| 
								 | 
							
								            sb.append(num.charAt(i));
							 | 
						||
| 
								 | 
							
								        }
							 | 
						||
| 
								 | 
							
								        return sb.toString();
							 | 
						||
| 
								 | 
							
								    }
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								    public static void main(String[] args) {
							 | 
						||
| 
								 | 
							
								        String reportId;
							 | 
						||
| 
								 | 
							
								        reportId = NumHelper.numDesc("527109");
							 | 
						||
| 
								 | 
							
								        System.out.println(reportId);
							 | 
						||
| 
								 | 
							
								        reportId = Base64Helper.encode(reportId);
							 | 
						||
| 
								 | 
							
								        System.out.println(reportId);
							 | 
						||
| 
								 | 
							
								        reportId = DigestUtils.md5Hex(reportId);
							 | 
						||
| 
								 | 
							
								        System.out.println(reportId);
							 | 
						||
| 
								 | 
							
								    }
							 | 
						||
| 
								 | 
							
								}
							 |