派生自 projectDept/qhighschool

Administrator
2022-11-18 b6a92bcd70d2edfb8bf2a2e784b37e1fcd036c10
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
package com.qxueyou.scc.base.util;
 
import java.math.BigDecimal;
import java.math.BigInteger;
import java.math.MathContext;
import java.text.DecimalFormat;
import java.util.Random;
import java.util.regex.Pattern;
 
import org.apache.commons.lang3.StringUtils;
import org.springframework.web.servlet.ModelAndView;
 
import com.qxueyou.scc.exercise.model.ExerciseItemAnswerU;
 
public class CommonUtils {
    /** Ò»Î»Ð¡Êý */
    public static final String PARTEN_ONE = "#.#";
    /** ¶þλСÊý */
    public static final String PARTEN_TWO = "#.##";
    
    //µØÇò°ë¾¶
    private static final double EARTH_RADIUS = 6378.137;
    
    /**
     * ´ð°¸ÏÔʾͼÐÎÑÕÉ« ×Ô¶¨Òå
     * @return
     */
    public static String[] getColors(){
        String[] colors = new String[]{"#4572a7","#aa4643","#89a54e","#80699b","#3d96ae","#a56f8f","#9f7961","#6f83a5"};
        
        return colors;
    }
    
    /**
     * ¿Î³Ì±íÏÔʾͼÐÎÑÕÉ« ×Ô¶¨Òå
     * @return
     */
    public static String[] getRGBColors(){
        String[] colors = new String[]{"21,199,165","130,191,173","155,238,222","178,235,202","210,210,174","205,186,117",
                "220,205,166","233,174,160","240,94,104","169,169,169"};
        
        return colors;
    }
    
    /**
     * »»ËãΪ2λСÊý
     * @return
     */
    public static String formatDecimalFormat(Object obj, String parten){
        DecimalFormat decimal = new DecimalFormat(parten);
        return decimal.format(obj);
    }
    
    /**
     * É¾³ý×Ö·û×îºóµÄ·ûºÅ
     * @return
     */
    public static String removeStrLastComma(String string){
        String str = string;
        if(StringUtils.isBlank(str)){
            return str;
        }
        String lastStr = str.substring(str.length()-1);
        
        if(lastStr.indexOf(',') > -1){
            str = str.substring(0, str.length()-1);
        }
        
        return str;
    }
    
    /**
     * ×ª»»´ð°¸Öµ 0,1,2
     * @param correct
     * @return
     */
    public static byte parseInteractCorrectValue(String correct){
        byte value;
        
        if("true".equals(correct)){
            value=ExerciseItemAnswerU.CORRECT_RIGHT;//ÕýÈ·
        }else if("false".equals(correct)){
            value=ExerciseItemAnswerU.CORRECT_ERROR;//´íÎó
        }else{
            value=7;//δ֪
        }
        
        return value;
    }
    
    /**
     *   // ½øÐмӷ¨ÔËËã
     * @param d1
     * @param d2
     * @return
     */
    public static double add(double d1, double d2){      
        BigDecimal b1 = new BigDecimal(String.valueOf(d1));
        BigDecimal b2 = new BigDecimal(String.valueOf(d2));
        
        return b1.add(b2).doubleValue();
    }
    
    /**
     * // ½øÐмõ·¨ÔËËã
     * @param d1
     * @param d2
     * @return
     */
    public static double subtract(double d1, double d2){   
        BigDecimal b1 = new BigDecimal(String.valueOf(d1));
        BigDecimal b2 = new BigDecimal(String.valueOf(d2));
        
        return b1.subtract(b2).doubleValue();
    }
    
    /**
     * // ½øÐг˷¨ÔËËã
     * @param d1
     * @param d2
     * @return
     */
    public static double multiply(double d1, double d2){        
        BigDecimal b1 = new BigDecimal(String.valueOf(d1));
        BigDecimal b2 = new BigDecimal(String.valueOf(d2));
        
        return b1.multiply(b2).doubleValue();
    }
    
     /**
     * // ½øÐгý·¨ÔËËã ËÄÉáÎåÈë
     * @param d1
     * @param d2
     * @return
     */
    public static double divide(double d1,double d2,int len) {// ½øÐгý·¨ÔËËã
        BigDecimal b1 = new BigDecimal(String.valueOf(d1));
        BigDecimal b2 = new BigDecimal(String.valueOf(d2));
        
        return b1.divide(b2,len,BigDecimal.ROUND_HALF_UP).doubleValue();
    }
    
     /**
     * // ½øÐгý·¨ÔËËã ËÄÉáÎåÈë
     * @param d1
     * @param d2
     * @return
     */
    public static double divide(String d1,String d2,int len) {// ½øÐгý·¨ÔËËã
        BigDecimal b1 = new BigDecimal(d1);
        BigDecimal b2 = new BigDecimal(d2);
        
        return b1.divide(b2,len,BigDecimal.ROUND_HALF_UP).doubleValue();
    }
    
    
     /**
     * // ½øÐгý·¨ÔËËã ËÄÉáÎåÈë
     * @param d1
     * @param d2
     * @return
     */
    public static BigDecimal divide(BigDecimal b1,BigDecimal b2,int len) {// ½øÐгý·¨ÔËËã
        
        return b1.divide(b2, new MathContext(len));
    }
    public CommonUtils() {
        // TODO Auto-generated constructor stub
    }
    /*
     * 
     * °´Ö¸¶¨³¤¶È½ØÈ¡Ô´×Ö·û´®£¬ÈôÔ´×Ö·û´®²»´óÓÚÖ¸¶¨³¤¶È£¬ÔòÔ­Ñù·µ»Ø
     */
    public static String cutString(String res, Integer length, String suffix) {
        if (StringUtils.isEmpty(res)) {
            return "";
        }
        if (res.length() <= length) {
            return res;
        }
        return res.substring(0, length) + (suffix == null ? "" : suffix);
    }
    
    /**
     * Éú³ÉÁ÷Ë®ºÅ £º  module+ʱ¼ä´Á + 5Î»Ëæ»úÊý£¬³¤¶È20λ
     */
    public static String generateNo(String module){
        
        Random rand = new Random();
        String random = String.valueOf(rand.nextInt(100000));
        int index = 0;
        while( random.length() < 5 && index < 5 ){
            index++;
            random = "0".concat(random);
        }
        
        return module + System.currentTimeMillis() + random ;
    }
    
    /**
     * ¼ÆË㵥λÊý×Ö
     * 
     * @param number
     * @return
     */
    public static String getNumberByUnit(BigInteger number){
        
        if(number == null){
            return "0";
        }
        
        if(number.compareTo(new BigInteger("10000")) < 0){// Ð¡ÓÚ1Íò
            return String.valueOf(number);
        }
        
        if(number.compareTo(new BigInteger("10000")) >= 0 
                && number.compareTo(new BigInteger("100000000")) < 0){// ´óÓÚ1Íò Ð¡ÓÚÒ»ÒÚ    Ç°½ø1λΪ1.2Íò
            
            return Math.ceil(number.doubleValue()/1000)/10 + "Íò";
            
        }
        
        if(number.compareTo(new BigInteger("100000000")) >= 0){// ´óÓÚÒ»ÒÚ    Ç°½ø1λΪ1.2ÒÚ
            
            return Math.ceil(number.doubleValue()/1000000)/10 + "ÒÚ";
        }
        
        return "0";
    }
    
    /**
     * ¸ñʽ»¯Îı¾
     * @param str
     * @return
     */
    public static String formatText(String str){
        String text = str;
        if (StringUtils.isNotBlank(str)) {
            text = text.replace("\n", "<br/>");
        }
        return text;
    }
    
    //
    private static double rad(double d){
        return d * Math.PI / 180.0;
    }
 
    //»ñÈ¡Á½¸ö×ø±ê¾àÀë
    public static double GetDistance(double long1, double lat1, double long2, double lat2) {
        double a, b, d, sa2, sb2;
        double latA = rad(lat1);
        double latB = rad(lat2);
        a = latA - latB;
        b = rad(long1 - long2);
 
        sa2 = Math.sin(a / 2.0);
        sb2 = Math.sin(b / 2.0);
        d = 2   * EARTH_RADIUS
                * Math.asin(Math.sqrt(sa2 * sa2 + Math.cos(latA)
                * Math.cos(latB) * sb2 * sb2));
        return d;
    }
    
    /**
     * ÒøÐп¨ÑéÖ¤
     * 
     * @param cardNo
     * @return
     */
    public static boolean isBankCard(String cardNo){
        return Pattern.matches("^\\d{8,27}$", cardNo);
    }
    
    /**
     * ftl-·µ»Ø´íÎóÐÅÏ¢Ò³Ãæ
     * @param mv
     * @param msg
     * @return
     */
    public static ModelAndView resultDeletePage(ModelAndView mv,String msg){
        mv =  new ModelAndView("/deletePage");
        mv.addObject("content", msg);
        return mv;
    }
    
    /** µÃµ½classId*/
    public static String getClassId(String classId){
        return StringUtils.isEmpty(classId)?(StringUtils.isEmpty(ClientUtils.getClassId())?StringUtils.EMPTY:ClientUtils.getClassId()):classId;
    }
}