From 4c48ff084d78e954d6659ebbebbf52f063c4b79a Mon Sep 17 00:00:00 2001 From: 81041 <81041@DESKTOP-025NVD9> Date: 星期二, 14 一月 2020 09:45:54 +0800 Subject: [PATCH] 加默认用户为1002 --- Device_Manage/src/com/fgkj/actions/ActionUtil.java | 1072 +++++++++++++++++++++++++++++----------------------------- 1 files changed, 538 insertions(+), 534 deletions(-) diff --git a/Device_Manage/src/com/fgkj/actions/ActionUtil.java b/Device_Manage/src/com/fgkj/actions/ActionUtil.java index edb0b51..52136c8 100644 --- a/Device_Manage/src/com/fgkj/actions/ActionUtil.java +++ b/Device_Manage/src/com/fgkj/actions/ActionUtil.java @@ -1,534 +1,538 @@ -package com.fgkj.actions; - -import java.io.File; -import java.io.FileInputStream; -import java.io.FileOutputStream; -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; -import java.io.PrintWriter; -import java.lang.reflect.Type; -import java.text.ParseException; -import java.text.SimpleDateFormat; -import java.util.Calendar; -import java.util.Date; - -import javax.servlet.ServletContext; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; -import javax.servlet.http.HttpSession; - -import org.apache.commons.codec.digest.DigestUtils; -import org.apache.struts2.ServletActionContext; - -import sun.java2d.loops.XORComposite; -import sun.misc.BASE64Decoder; -import sun.misc.BASE64Encoder; - -import com.google.gson.Gson; -import com.google.gson.GsonBuilder; -import com.google.gson.JsonSyntaxException; -import com.opensymphony.xwork2.ActionSupport; -import com.sun.org.apache.commons.digester.Digester; - -public class ActionUtil extends ActionSupport{ - public static String time_yyyyMMddHHmmss = "yyyy-MM-dd HH:mm:ss"; - - - - public String key; //璺ㄥ煙璇嗗埆鐮� - - /* - * 鑾峰彇HttpServletRequest - */ - public static HttpServletRequest getRequest(){ - return ServletActionContext.getRequest(); - } - - /* - * 鑾峰彇HttpServletResponse - */ - public static HttpServletResponse getResponse(){ - return ServletActionContext.getResponse(); - } - - /* - * 鑾峰彇HttpSession - */ - public static HttpSession getSession(){ - return ServletActionContext.getRequest().getSession(); - } - - /** - * - * @return 杩斿洖application - */ - public static ServletContext getApplication(){ - return ServletActionContext.getServletContext(); - } - //鑾峰彇application涓簰鏂ヤ笂浼犵殑鏍囧織浣峟lag - public static int getFlag(){ - ServletContext app=ServletActionContext.getServletContext(); - int flag=(Integer) app.getAttribute("flag"); - return flag; - } - ////缁檃pplication涓簰鏂ヤ笂浼犵殑鏍囧織浣峟lag璁剧疆鍊� - public static void setFlag(int flag){ - ServletContext app=ServletActionContext.getServletContext(); - app.setAttribute("flag", flag); - } - /* - * 鑾峰彇灏嗗璞¤浆鎹㈡垚json鏍煎紡 - */ - public static String tojson(Object obj){ - Gson gson = new GsonBuilder().setDateFormat("yyyy-MM-dd HH:mm:ss").create(); - return gson.toJson(obj); - } - - public static String chageDateToString(Date time,String type){ - String msg = ""; - SimpleDateFormat sdf = new SimpleDateFormat(type); - msg = sdf.format(time); - return msg; - } - - - /** - * - * @param datetype 闇�瑕佽В鏋愮殑鏃ユ湡鐨勬牸寮忓锛�"yyyy-MM-dd HH:mm:ss" - * @return 寰楀埌瀵瑰簲鐨刧son瀵硅薄 - */ - public static Gson getGson(String datetype){ - return new GsonBuilder().setDateFormat(datetype).create(); - } - - /** - * 鑾峰彇榛樿鐨刧son瀵硅薄 - * @return - */ - public static Gson getGson(){ - return new Gson(); - } - - - public static <T> T getObject(String jsonstring,Type listtype){ - Gson gson=new Gson(); - T t=null; - try { - t=gson.fromJson(jsonstring, listtype); - } catch (JsonSyntaxException e) { - e.printStackTrace(); - } - return t; - } - - /** - * - * @return 鑾峰彇杈撳嚭娴� - */ - public static PrintWriter getOut(){ - PrintWriter out =null; - try { - out=getResponse().getWriter(); - } catch (IOException e) { - e.printStackTrace(); - } - return out; - } - - /** - * - * @param time java.util鍖呬腑鐨勬椂闂� - * @return java.sql鏃堕棿 - */ - public static Date getSimpDate(Date time){ - //System.out.println(time); - return new java.sql.Date(time.getTime()); - } - - //浣跨敤MD5鍔犲瘑 - public static Object EncryptionMD5(Object obj){ - String md5=null; - if(obj!=null && obj.toString().length()>0){ - md5=DigestUtils.md5Hex(obj.toString()); - } - return md5; - } - - //浣跨敤Base64鍔犲瘑 - public static Object EncryptionBase64(Object obj){ - String base64=null; - if(obj!=null && obj.toString().length()>0){ - base64=new BASE64Encoder().encode(obj.toString().getBytes()); - base64 = base64.replaceAll("[\\s*\t\n\r]", ""); //鏇挎崲鍔犲瘑鍚庝笉鎹㈣ - } - return base64; - } - - //浣跨敤Base64瑙e瘑 - public static Object DecryptionBase64(Object obj){ - String base64=null; - if(obj!=null && obj.toString().length()>0){ - try { - base64 = new String(new BASE64Decoder().decodeBuffer(obj.toString())); - } catch (IOException e) { - e.printStackTrace(); - } - } - return base64; - } - - //鑾峰彇鎸囧畾骞存湀鐨勫ぉ鏁� - public static int getDaysByYearMonth(int year, int month) { - - Calendar a = Calendar.getInstance(); - a.set(Calendar.YEAR, year); - a.set(Calendar.MONTH, month - 1); - a.set(Calendar.DATE, 1); - a.roll(Calendar.DATE, -1); - int maxDate = a.get(Calendar.DATE); - return maxDate; - } - - /** - * - * @return 鑾峰彇褰撳墠session 涓殑鐢ㄦ埛瀵硅薄 - */ - public static Object getUser(){ - HttpSession session =getSession(); - return session.getAttribute("user"); - } - - //鑾峰彇鏌愬勾鏌愭湀鐨勮捣濮嬪拰缁撴潫鏃堕棿 - //闇�瑕佹敞鎰忕殑鏄細鏈堜唤鏄粠0寮�濮嬬殑锛屾瘮濡傝濡傛灉杈撳叆5鐨勮瘽锛屽疄闄呬笂鏄剧ず鐨勬槸4鏈堜唤鐨勬渶鍚庝竴澶╋紝鍗冧竾涓嶈鎼為敊浜嗗摝 - public static String getLastDayOfMonth(int year, int month) { - Calendar cal = Calendar.getInstance(); - cal.set(Calendar.YEAR, year); - cal.set(Calendar.MONTH, month); - cal.set(Calendar.DAY_OF_MONTH,cal.getActualMaximum(Calendar.DATE)); - return new SimpleDateFormat( "yyyy-MM-dd ").format(cal.getTime())+"23:59:59"; - } - - public static String getFirstDayOfMonth(int year, int month) { - Calendar cal = Calendar.getInstance(); - cal.set(Calendar.YEAR, year); - cal.set(Calendar.MONTH, month); - cal.set(Calendar.DAY_OF_MONTH,cal.getMinimum(Calendar.DATE)); - return new SimpleDateFormat( "yyyy-MM-dd ").format(cal.getTime())+"00:00:00"; - } - //鑾峰彇褰撳墠鏃堕棿鐨勫勾浠� - public static int getNowYear(){ - Calendar ca = Calendar.getInstance();//寰楀埌涓�涓狢alendar鐨勫疄渚� - ca.setTime(new Date()); //璁剧疆鏃堕棿涓哄綋鍓嶆椂闂� - int year = ca.get(Calendar.YEAR); - //System.out.println(month); - return year; - } - //鑾峰彇褰撳墠鏃堕棿鐨勬湀浠� - public static int getNowMonth(){ - Calendar ca = Calendar.getInstance();//寰楀埌涓�涓狢alendar鐨勫疄渚� - ca.setTime(new Date()); //璁剧疆鏃堕棿涓哄綋鍓嶆椂闂� - int month = ca.get(Calendar.MONTH) + 1; - //System.out.println(month); - return month; - } - //鑾峰彇褰撳墠鏃堕棿鐨勬棩鏈� - public static int getNowday(){ - Calendar ca = Calendar.getInstance();//寰楀埌涓�涓狢alendar鐨勫疄渚� - ca.setTime(new Date()); //璁剧疆鏃堕棿涓哄綋鍓嶆椂闂� - int day = ca.get(Calendar.DAY_OF_MONTH); - //System.out.println(month); - return day; - } - //褰撳墠鏃堕棿鍔犱笂x灏忔椂 - public static String getDateAdd(int minute){ - Date date = new Date(); - Calendar c = Calendar.getInstance(); - c.setTime(date); - c.add(Calendar.MINUTE, minute); - return new SimpleDateFormat( "yyyy-MM-dd HH:mm:ss").format(c.getTime()); - } - - - //鑾峰彇鏃堕棿鐨勫勾浠� - public static int getDateYear(Date date){ - Calendar ca = Calendar.getInstance();//寰楀埌涓�涓狢alendar鐨勫疄渚� - ca.setTime(date); //璁剧疆鏃堕棿涓哄綋鍓嶆椂闂� - int year = ca.get(Calendar.YEAR); - //System.out.println(month); - return year; - } - //鑾峰彇鏃堕棿鐨勬湀浠� - public static int getDateMonth(Date date){ - Calendar ca = Calendar.getInstance();//寰楀埌涓�涓狢alendar鐨勫疄渚� - ca.setTime(date); //璁剧疆鏃堕棿涓哄綋鍓嶆椂闂� - int month = ca.get(Calendar.MONTH) + 1; - //System.out.println(month); - return month; - } - //鑾峰彇鏃堕棿鐨勬棩鏈� - public static int getDateday(Date date){ - Calendar ca = Calendar.getInstance();//寰楀埌涓�涓狢alendar鐨勫疄渚� - ca.setTime(date); //璁剧疆鏃堕棿涓哄綋鍓嶆椂闂� - int day = ca.get(Calendar.DAY_OF_MONTH); - //System.out.println(month); - return day; - } - //褰撳墠鏃堕棿鍔犱笂x灏忔椂 - public static Date getDateAdd(Date date,int minute){ - Calendar c = Calendar.getInstance(); - c.setTime(date); - c.add(Calendar.MINUTE, minute); - return c.getTime(); - } - //缁欏畾鏃堕棿鍒ゆ柇涓庡綋鍓嶆椂闂寸浉姣旀槸鍚︿负鑰佺數姹�(numYear涓烘椂闂存湡闄愬嚑骞�) - public static int judgeBatt(Date inUseDate,Date date,int numYear){ - int judge=0; - inUseDate.setYear(ActionUtil.getDateYear(inUseDate)+numYear-1900); - //System.out.println("inUseDate: "+inUseDate); - if(inUseDate.after(date)){ - judge=1; - }else{ - judge=0; - } - return judge; - } - //鑾峰彇鏌愬勾鏌愭湀鏌愭棩鍐呯殑鏃堕棿<date涓烘墽琛屾椂闂寸殑鏃跺垎绉掕缃负鎻愰啋鏃堕棿娈电殑鏃跺垎绉�> - public static Date getWorkDay(Date date,Date noticeTime) { - Calendar cal = Calendar.getInstance(); - cal.setTime(date); //璁剧疆鏃堕棿涓烘墽琛屾棩鏈� - int year = cal.get(Calendar.YEAR);//骞� - int month = cal.get(Calendar.MONTH);//鏈� - int day = cal.get(Calendar.DAY_OF_MONTH);//鏃� - cal.setTime(noticeTime);//璁剧疆鏃堕棿涓烘彁閱掓椂闂存 - /*int hour=cal.get(Calendar.HOUR_OF_DAY);//鏃� - int minute=cal.get(Calendar.MINUTE);//鍒� - int second=cal.get(Calendar.SECOND);//绉�*/ - cal.set(Calendar.YEAR, year); - cal.set(Calendar.MONTH, month); - cal.set(Calendar.DAY_OF_MONTH,day); - return cal.getTime(); - } - //鑾峰彇鏌愬勾鏌愭湀鏌愭棩璧峰鏃堕棿/缁撴潫鏃堕棿 - public static String getDayTime(int year, int month,int day,int type) { - Calendar cal = Calendar.getInstance(); - cal.set(Calendar.YEAR, year); - cal.set(Calendar.MONTH, month); - cal.set(Calendar.DAY_OF_MONTH,day); - if(type==1){ - return new SimpleDateFormat( "yyyy-MM-dd ").format(cal.getTime())+"00:00:00"; - - } else if(type==2){ - return new SimpleDateFormat( "yyyy-MM-dd ").format(cal.getTime())+"09:00:00"; - }else if(type==3){ - return new SimpleDateFormat( "yyyy-MM-dd ").format(cal.getTime())+"17:00:00"; - }else if(type==4){ - return new SimpleDateFormat( "yyyy-MM-dd ").format(cal.getTime())+"23:59:59"; - } - return new SimpleDateFormat( "yyyy-MM-dd ").format(cal.getTime()); - } - - //璁$畻鐢垫睜浣跨敤浜嗗灏戜釜鏈� - public static int battInuseMonth(Date inUseDate){ - int useDay=0; - Date nowd=new Date();//褰撳墠鏃堕棿 - int inuseY=ActionUtil.getDateYear(inUseDate); - int inuseM=ActionUtil.getDateMonth(inUseDate); - int nowY=ActionUtil.getDateYear(nowd); - int nowM=ActionUtil.getDateMonth(nowd); - if(inuseY==nowY){ - useDay=nowM-inuseM; - }else{ - useDay=(nowY-inuseY)*12+nowM-inuseM; - } - return useDay; - - } - //璁$畻鏃ユ湡涔嬮棿鐩稿樊鐨勫ぉ鏁� - public static int daysBetween(Date smdate,Date bdate) - { - SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd"); - - try { - smdate=sdf.parse(sdf.format(smdate)); - bdate=sdf.parse(sdf.format(bdate)); - } catch (ParseException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - - Calendar cal = Calendar.getInstance(); - cal.setTime(smdate); - long time1 = cal.getTimeInMillis(); - cal.setTime(bdate); - long time2 = cal.getTimeInMillis(); - long between_days=(time2-time1)/(1000*3600*24); - - return Math.abs(Integer.parseInt(String.valueOf(between_days))); - } - //璁$畻鏃ユ湡涔嬮棿鐩稿樊鐨勫皬鏃� - public static int HoursBetween(Date smdate,Date bdate) - { - SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); - try { - smdate=sdf.parse(sdf.format(smdate)); - bdate=sdf.parse(sdf.format(bdate)); - } catch (ParseException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - Calendar cal = Calendar.getInstance(); - cal.setTime(smdate); - long time1 = cal.getTimeInMillis(); - cal.setTime(bdate); - long time2 = cal.getTimeInMillis(); - long between_hours=(time2-time1)/(1000*3600); - //System.out.println("between_hours:"+between_hours); - return (int) Math.abs(between_hours); - } - - //姣旇緝涓や釜鏃堕棿鐨勫ぇ灏� - public static int compareDate(Date d1,Date d2){ - if (d1.getTime() > d2.getTime()) { - return 1; - } else if (d1.getTime() < d2.getTime()) { - return -1; - } else {//鐩哥瓑 - return 0; - } - } - /** - * @Description: 鏍规嵁鍥剧墖鍦板潃杞崲涓篵ase64缂栫爜瀛楃涓� - * @Author: - * @CreateTime: - * @return - */ - public static String getImageStr(String imgFile) { - InputStream inputStream = null; - byte[] data = null; - try { - inputStream = new FileInputStream(imgFile); - data = new byte[inputStream.available()]; - inputStream.read(data); - inputStream.close(); - } catch (IOException e) { - e.printStackTrace(); - } - // 鍔犲瘑 - BASE64Encoder encoder = new BASE64Encoder(); - return encoder.encode(data); - } - - - /** - * @Description: 灏哹ase64缂栫爜瀛楃涓茶浆鎹负鍥剧墖 - * @Author: - * @CreateTime: - * @param imgStr base64缂栫爜瀛楃涓� - * @param path 鍥剧墖璺緞-鍏蜂綋鍒版枃浠� - * @return - */ - public static boolean generateImage(String imgStr, String path) { - if (imgStr == null) - return false; - BASE64Decoder decoder = new BASE64Decoder(); - try { - // 瑙e瘑 - byte[] b = decoder.decodeBuffer(imgStr); - // 澶勭悊鏁版嵁 - for (int i = 0; i < b.length; ++i) { - if (b[i] < 0) { - b[i] += 256; - } - } - OutputStream out = new FileOutputStream(path); - out.write(b); - out.flush(); - out.close(); - return true; - } catch (Exception e) { - return false; - } - } - - /** - * 灏嗚緭鍏ユ祦涓殑鏁版嵁璇诲埌瀛楄妭鏁扮粍涓� - * @param is - * @return - */ - public static byte[] IStoByteArr(InputStream is){ - byte[] b = null; - try { - b = new byte[is.available()]; - is.read(b); - } catch (IOException e) { - e.printStackTrace(); - } finally{ - if(is != null){ - try { - is.close(); - } catch (IOException e) { - e.printStackTrace(); - } - } - } - - return b; - } - - /** - * 鍏佽璺ㄥ煙璇锋眰 - */ - public static void isAllowHeaders(){ - HttpServletResponse res = getResponse(); - res.setHeader("Access-Control-Allow-Origin", "*"); //鍏佽璺ㄥ煙璁块棶 - res.setHeader("Access-Control-Allow-Headers", "X-Requested-With,content-type,token"); - res.setHeader("Access-Control-Allow-Methods", "GET, HEAD, POST, PUT, DELETE, TRACE, OPTIONS, PATCH"); - } - - - - public void setKey(String key) { - this.key = key; - } - - /** - * 鍒涘缓鎸囧畾鐨勬枃浠舵枃浠讹紝鑻ヤ笉瀛樺湪鍒欏厛鍒涘缓鎸囧畾鐨勬枃浠跺す鍐嶅垱寤烘寚瀹氱殑鏂囦欢 - * @param filePath - */ - public static void createFileRootIFNotExist(String filePath){ - File f = new File(filePath); - if(!f.exists()){ - if(!f.getParentFile().exists()){ - f.getParentFile().mkdirs(); - } - try { - f.createNewFile(); - } catch (IOException e) { - e.printStackTrace(); - } - } - } - - /** - * 鍒涘缓鎸囧畾鐨勬枃浠舵枃浠讹紝鑻ヤ笉瀛樺湪鍒欏厛鍒涘缓鎸囧畾鐨勬枃浠跺す鍐嶅垱寤烘寚瀹氱殑鏂囦欢 - * @param filePath - */ - public static void createFilefolderIFNotExist(String filePath){ - File f = new File(filePath); - if(!f.exists()){ - if(!f.getParentFile().exists()){ - f.getParentFile().mkdirs(); - } - } - } - - - public static void main(String[] args) { - String str = "绂忓厜鐢靛瓙"; - //System.out.println(EncryptionMD5(EncryptionMD5(str))); - - - createFilefolderIFNotExist("d:/aaaa/aaaa/aaaa/aaaa/ddd.txt"); - } -} +package com.fgkj.actions; + +import java.io.File; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.io.PrintWriter; +import java.lang.reflect.Type; +import java.text.ParseException; +import java.text.SimpleDateFormat; +import java.util.Calendar; +import java.util.Date; + +import javax.servlet.ServletContext; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import javax.servlet.http.HttpSession; + +import org.apache.commons.codec.digest.DigestUtils; +import org.apache.struts2.ServletActionContext; + +import sun.java2d.loops.XORComposite; +import sun.misc.BASE64Decoder; +import sun.misc.BASE64Encoder; + +import com.fgkj.dto.User_inf; +import com.google.gson.Gson; +import com.google.gson.GsonBuilder; +import com.google.gson.JsonSyntaxException; +import com.opensymphony.xwork2.ActionSupport; +import com.sun.org.apache.commons.digester.Digester; + +public class ActionUtil extends ActionSupport{ + public static String time_yyyyMMddHHmmss = "yyyy-MM-dd HH:mm:ss"; + + + + public String key; //璺ㄥ煙璇嗗埆鐮� + + /* + * 鑾峰彇HttpServletRequest + */ + public static HttpServletRequest getRequest(){ + return ServletActionContext.getRequest(); + } + + /* + * 鑾峰彇HttpServletResponse + */ + public static HttpServletResponse getResponse(){ + return ServletActionContext.getResponse(); + } + + /* + * 鑾峰彇HttpSession + */ + public static HttpSession getSession(){ + return ServletActionContext.getRequest().getSession(); + } + + /** + * + * @return 杩斿洖application + */ + public static ServletContext getApplication(){ + return ServletActionContext.getServletContext(); + } + //鑾峰彇application涓簰鏂ヤ笂浼犵殑鏍囧織浣峟lag + public static int getFlag(){ + ServletContext app=ServletActionContext.getServletContext(); + int flag=(Integer) app.getAttribute("flag"); + return flag; + } + ////缁檃pplication涓簰鏂ヤ笂浼犵殑鏍囧織浣峟lag璁剧疆鍊� + public static void setFlag(int flag){ + ServletContext app=ServletActionContext.getServletContext(); + app.setAttribute("flag", flag); + } + /* + * 鑾峰彇灏嗗璞¤浆鎹㈡垚json鏍煎紡 + */ + public static String tojson(Object obj){ + Gson gson = new GsonBuilder().setDateFormat("yyyy-MM-dd HH:mm:ss").create(); + return gson.toJson(obj); + } + + public static String chageDateToString(Date time,String type){ + String msg = ""; + SimpleDateFormat sdf = new SimpleDateFormat(type); + msg = sdf.format(time); + return msg; + } + + + /** + * + * @param datetype 闇�瑕佽В鏋愮殑鏃ユ湡鐨勬牸寮忓锛�"yyyy-MM-dd HH:mm:ss" + * @return 寰楀埌瀵瑰簲鐨刧son瀵硅薄 + */ + public static Gson getGson(String datetype){ + return new GsonBuilder().setDateFormat(datetype).create(); + } + + /** + * 鑾峰彇榛樿鐨刧son瀵硅薄 + * @return + */ + public static Gson getGson(){ + return new Gson(); + } + + + public static <T> T getObject(String jsonstring,Type listtype){ + Gson gson=new Gson(); + T t=null; + try { + t=gson.fromJson(jsonstring, listtype); + } catch (JsonSyntaxException e) { + e.printStackTrace(); + } + return t; + } + + /** + * + * @return 鑾峰彇杈撳嚭娴� + */ + public static PrintWriter getOut(){ + PrintWriter out =null; + try { + out=getResponse().getWriter(); + } catch (IOException e) { + e.printStackTrace(); + } + return out; + } + + /** + * + * @param time java.util鍖呬腑鐨勬椂闂� + * @return java.sql鏃堕棿 + */ + public static Date getSimpDate(Date time){ + //System.out.println(time); + return new java.sql.Date(time.getTime()); + } + + //浣跨敤MD5鍔犲瘑 + public static Object EncryptionMD5(Object obj){ + String md5=null; + if(obj!=null && obj.toString().length()>0){ + md5=DigestUtils.md5Hex(obj.toString()); + } + return md5; + } + + //浣跨敤Base64鍔犲瘑 + public static Object EncryptionBase64(Object obj){ + String base64=null; + if(obj!=null && obj.toString().length()>0){ + base64=new BASE64Encoder().encode(obj.toString().getBytes()); + base64 = base64.replaceAll("[\\s*\t\n\r]", ""); //鏇挎崲鍔犲瘑鍚庝笉鎹㈣ + } + return base64; + } + + //浣跨敤Base64瑙e瘑 + public static Object DecryptionBase64(Object obj){ + String base64=null; + if(obj!=null && obj.toString().length()>0){ + try { + base64 = new String(new BASE64Decoder().decodeBuffer(obj.toString())); + } catch (IOException e) { + e.printStackTrace(); + } + } + return base64; + } + + //鑾峰彇鎸囧畾骞存湀鐨勫ぉ鏁� + public static int getDaysByYearMonth(int year, int month) { + + Calendar a = Calendar.getInstance(); + a.set(Calendar.YEAR, year); + a.set(Calendar.MONTH, month - 1); + a.set(Calendar.DATE, 1); + a.roll(Calendar.DATE, -1); + int maxDate = a.get(Calendar.DATE); + return maxDate; + } + + /** + * + * @return 鑾峰彇褰撳墠session 涓殑鐢ㄦ埛瀵硅薄 + */ + public static Object getUser(){ + /*HttpSession session =getSession(); + return session.getAttribute("user");*/ + User_inf uinf=new User_inf(); + uinf.setUId(1002); + return uinf; + } + + //鑾峰彇鏌愬勾鏌愭湀鐨勮捣濮嬪拰缁撴潫鏃堕棿 + //闇�瑕佹敞鎰忕殑鏄細鏈堜唤鏄粠0寮�濮嬬殑锛屾瘮濡傝濡傛灉杈撳叆5鐨勮瘽锛屽疄闄呬笂鏄剧ず鐨勬槸4鏈堜唤鐨勬渶鍚庝竴澶╋紝鍗冧竾涓嶈鎼為敊浜嗗摝 + public static String getLastDayOfMonth(int year, int month) { + Calendar cal = Calendar.getInstance(); + cal.set(Calendar.YEAR, year); + cal.set(Calendar.MONTH, month); + cal.set(Calendar.DAY_OF_MONTH,cal.getActualMaximum(Calendar.DATE)); + return new SimpleDateFormat( "yyyy-MM-dd ").format(cal.getTime())+"23:59:59"; + } + + public static String getFirstDayOfMonth(int year, int month) { + Calendar cal = Calendar.getInstance(); + cal.set(Calendar.YEAR, year); + cal.set(Calendar.MONTH, month); + cal.set(Calendar.DAY_OF_MONTH,cal.getMinimum(Calendar.DATE)); + return new SimpleDateFormat( "yyyy-MM-dd ").format(cal.getTime())+"00:00:00"; + } + //鑾峰彇褰撳墠鏃堕棿鐨勫勾浠� + public static int getNowYear(){ + Calendar ca = Calendar.getInstance();//寰楀埌涓�涓狢alendar鐨勫疄渚� + ca.setTime(new Date()); //璁剧疆鏃堕棿涓哄綋鍓嶆椂闂� + int year = ca.get(Calendar.YEAR); + //System.out.println(month); + return year; + } + //鑾峰彇褰撳墠鏃堕棿鐨勬湀浠� + public static int getNowMonth(){ + Calendar ca = Calendar.getInstance();//寰楀埌涓�涓狢alendar鐨勫疄渚� + ca.setTime(new Date()); //璁剧疆鏃堕棿涓哄綋鍓嶆椂闂� + int month = ca.get(Calendar.MONTH) + 1; + //System.out.println(month); + return month; + } + //鑾峰彇褰撳墠鏃堕棿鐨勬棩鏈� + public static int getNowday(){ + Calendar ca = Calendar.getInstance();//寰楀埌涓�涓狢alendar鐨勫疄渚� + ca.setTime(new Date()); //璁剧疆鏃堕棿涓哄綋鍓嶆椂闂� + int day = ca.get(Calendar.DAY_OF_MONTH); + //System.out.println(month); + return day; + } + //褰撳墠鏃堕棿鍔犱笂x灏忔椂 + public static String getDateAdd(int minute){ + Date date = new Date(); + Calendar c = Calendar.getInstance(); + c.setTime(date); + c.add(Calendar.MINUTE, minute); + return new SimpleDateFormat( "yyyy-MM-dd HH:mm:ss").format(c.getTime()); + } + + + //鑾峰彇鏃堕棿鐨勫勾浠� + public static int getDateYear(Date date){ + Calendar ca = Calendar.getInstance();//寰楀埌涓�涓狢alendar鐨勫疄渚� + ca.setTime(date); //璁剧疆鏃堕棿涓哄綋鍓嶆椂闂� + int year = ca.get(Calendar.YEAR); + //System.out.println(month); + return year; + } + //鑾峰彇鏃堕棿鐨勬湀浠� + public static int getDateMonth(Date date){ + Calendar ca = Calendar.getInstance();//寰楀埌涓�涓狢alendar鐨勫疄渚� + ca.setTime(date); //璁剧疆鏃堕棿涓哄綋鍓嶆椂闂� + int month = ca.get(Calendar.MONTH) + 1; + //System.out.println(month); + return month; + } + //鑾峰彇鏃堕棿鐨勬棩鏈� + public static int getDateday(Date date){ + Calendar ca = Calendar.getInstance();//寰楀埌涓�涓狢alendar鐨勫疄渚� + ca.setTime(date); //璁剧疆鏃堕棿涓哄綋鍓嶆椂闂� + int day = ca.get(Calendar.DAY_OF_MONTH); + //System.out.println(month); + return day; + } + //褰撳墠鏃堕棿鍔犱笂x灏忔椂 + public static Date getDateAdd(Date date,int minute){ + Calendar c = Calendar.getInstance(); + c.setTime(date); + c.add(Calendar.MINUTE, minute); + return c.getTime(); + } + //缁欏畾鏃堕棿鍒ゆ柇涓庡綋鍓嶆椂闂寸浉姣旀槸鍚︿负鑰佺數姹�(numYear涓烘椂闂存湡闄愬嚑骞�) + public static int judgeBatt(Date inUseDate,Date date,int numYear){ + int judge=0; + inUseDate.setYear(ActionUtil.getDateYear(inUseDate)+numYear-1900); + //System.out.println("inUseDate: "+inUseDate); + if(inUseDate.after(date)){ + judge=1; + }else{ + judge=0; + } + return judge; + } + //鑾峰彇鏌愬勾鏌愭湀鏌愭棩鍐呯殑鏃堕棿<date涓烘墽琛屾椂闂寸殑鏃跺垎绉掕缃负鎻愰啋鏃堕棿娈电殑鏃跺垎绉�> + public static Date getWorkDay(Date date,Date noticeTime) { + Calendar cal = Calendar.getInstance(); + cal.setTime(date); //璁剧疆鏃堕棿涓烘墽琛屾棩鏈� + int year = cal.get(Calendar.YEAR);//骞� + int month = cal.get(Calendar.MONTH);//鏈� + int day = cal.get(Calendar.DAY_OF_MONTH);//鏃� + cal.setTime(noticeTime);//璁剧疆鏃堕棿涓烘彁閱掓椂闂存 + /*int hour=cal.get(Calendar.HOUR_OF_DAY);//鏃� + int minute=cal.get(Calendar.MINUTE);//鍒� + int second=cal.get(Calendar.SECOND);//绉�*/ + cal.set(Calendar.YEAR, year); + cal.set(Calendar.MONTH, month); + cal.set(Calendar.DAY_OF_MONTH,day); + return cal.getTime(); + } + //鑾峰彇鏌愬勾鏌愭湀鏌愭棩璧峰鏃堕棿/缁撴潫鏃堕棿 + public static String getDayTime(int year, int month,int day,int type) { + Calendar cal = Calendar.getInstance(); + cal.set(Calendar.YEAR, year); + cal.set(Calendar.MONTH, month); + cal.set(Calendar.DAY_OF_MONTH,day); + if(type==1){ + return new SimpleDateFormat( "yyyy-MM-dd ").format(cal.getTime())+"00:00:00"; + + } else if(type==2){ + return new SimpleDateFormat( "yyyy-MM-dd ").format(cal.getTime())+"09:00:00"; + }else if(type==3){ + return new SimpleDateFormat( "yyyy-MM-dd ").format(cal.getTime())+"17:00:00"; + }else if(type==4){ + return new SimpleDateFormat( "yyyy-MM-dd ").format(cal.getTime())+"23:59:59"; + } + return new SimpleDateFormat( "yyyy-MM-dd ").format(cal.getTime()); + } + + //璁$畻鐢垫睜浣跨敤浜嗗灏戜釜鏈� + public static int battInuseMonth(Date inUseDate){ + int useDay=0; + Date nowd=new Date();//褰撳墠鏃堕棿 + int inuseY=ActionUtil.getDateYear(inUseDate); + int inuseM=ActionUtil.getDateMonth(inUseDate); + int nowY=ActionUtil.getDateYear(nowd); + int nowM=ActionUtil.getDateMonth(nowd); + if(inuseY==nowY){ + useDay=nowM-inuseM; + }else{ + useDay=(nowY-inuseY)*12+nowM-inuseM; + } + return useDay; + + } + //璁$畻鏃ユ湡涔嬮棿鐩稿樊鐨勫ぉ鏁� + public static int daysBetween(Date smdate,Date bdate) + { + SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd"); + + try { + smdate=sdf.parse(sdf.format(smdate)); + bdate=sdf.parse(sdf.format(bdate)); + } catch (ParseException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + + Calendar cal = Calendar.getInstance(); + cal.setTime(smdate); + long time1 = cal.getTimeInMillis(); + cal.setTime(bdate); + long time2 = cal.getTimeInMillis(); + long between_days=(time2-time1)/(1000*3600*24); + + return Math.abs(Integer.parseInt(String.valueOf(between_days))); + } + //璁$畻鏃ユ湡涔嬮棿鐩稿樊鐨勫皬鏃� + public static int HoursBetween(Date smdate,Date bdate) + { + SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + try { + smdate=sdf.parse(sdf.format(smdate)); + bdate=sdf.parse(sdf.format(bdate)); + } catch (ParseException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + Calendar cal = Calendar.getInstance(); + cal.setTime(smdate); + long time1 = cal.getTimeInMillis(); + cal.setTime(bdate); + long time2 = cal.getTimeInMillis(); + long between_hours=(time2-time1)/(1000*3600); + //System.out.println("between_hours:"+between_hours); + return (int) Math.abs(between_hours); + } + + //姣旇緝涓や釜鏃堕棿鐨勫ぇ灏� + public static int compareDate(Date d1,Date d2){ + if (d1.getTime() > d2.getTime()) { + return 1; + } else if (d1.getTime() < d2.getTime()) { + return -1; + } else {//鐩哥瓑 + return 0; + } + } + /** + * @Description: 鏍规嵁鍥剧墖鍦板潃杞崲涓篵ase64缂栫爜瀛楃涓� + * @Author: + * @CreateTime: + * @return + */ + public static String getImageStr(String imgFile) { + InputStream inputStream = null; + byte[] data = null; + try { + inputStream = new FileInputStream(imgFile); + data = new byte[inputStream.available()]; + inputStream.read(data); + inputStream.close(); + } catch (IOException e) { + e.printStackTrace(); + } + // 鍔犲瘑 + BASE64Encoder encoder = new BASE64Encoder(); + return encoder.encode(data); + } + + + /** + * @Description: 灏哹ase64缂栫爜瀛楃涓茶浆鎹负鍥剧墖 + * @Author: + * @CreateTime: + * @param imgStr base64缂栫爜瀛楃涓� + * @param path 鍥剧墖璺緞-鍏蜂綋鍒版枃浠� + * @return + */ + public static boolean generateImage(String imgStr, String path) { + if (imgStr == null) + return false; + BASE64Decoder decoder = new BASE64Decoder(); + try { + // 瑙e瘑 + byte[] b = decoder.decodeBuffer(imgStr); + // 澶勭悊鏁版嵁 + for (int i = 0; i < b.length; ++i) { + if (b[i] < 0) { + b[i] += 256; + } + } + OutputStream out = new FileOutputStream(path); + out.write(b); + out.flush(); + out.close(); + return true; + } catch (Exception e) { + return false; + } + } + + /** + * 灏嗚緭鍏ユ祦涓殑鏁版嵁璇诲埌瀛楄妭鏁扮粍涓� + * @param is + * @return + */ + public static byte[] IStoByteArr(InputStream is){ + byte[] b = null; + try { + b = new byte[is.available()]; + is.read(b); + } catch (IOException e) { + e.printStackTrace(); + } finally{ + if(is != null){ + try { + is.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } + } + + return b; + } + + /** + * 鍏佽璺ㄥ煙璇锋眰 + */ + public static void isAllowHeaders(){ + HttpServletResponse res = getResponse(); + res.setHeader("Access-Control-Allow-Origin", "*"); //鍏佽璺ㄥ煙璁块棶 + res.setHeader("Access-Control-Allow-Headers", "X-Requested-With,content-type,token"); + res.setHeader("Access-Control-Allow-Methods", "GET, HEAD, POST, PUT, DELETE, TRACE, OPTIONS, PATCH"); + } + + + + public void setKey(String key) { + this.key = key; + } + + /** + * 鍒涘缓鎸囧畾鐨勬枃浠舵枃浠讹紝鑻ヤ笉瀛樺湪鍒欏厛鍒涘缓鎸囧畾鐨勬枃浠跺す鍐嶅垱寤烘寚瀹氱殑鏂囦欢 + * @param filePath + */ + public static void createFileRootIFNotExist(String filePath){ + File f = new File(filePath); + if(!f.exists()){ + if(!f.getParentFile().exists()){ + f.getParentFile().mkdirs(); + } + try { + f.createNewFile(); + } catch (IOException e) { + e.printStackTrace(); + } + } + } + + /** + * 鍒涘缓鎸囧畾鐨勬枃浠舵枃浠讹紝鑻ヤ笉瀛樺湪鍒欏厛鍒涘缓鎸囧畾鐨勬枃浠跺す鍐嶅垱寤烘寚瀹氱殑鏂囦欢 + * @param filePath + */ + public static void createFilefolderIFNotExist(String filePath){ + File f = new File(filePath); + if(!f.exists()){ + if(!f.getParentFile().exists()){ + f.getParentFile().mkdirs(); + } + } + } + + + public static void main(String[] args) { + String str = "绂忓厜鐢靛瓙"; + //System.out.println(EncryptionMD5(EncryptionMD5(str))); + + + createFilefolderIFNotExist("d:/aaaa/aaaa/aaaa/aaaa/ddd.txt"); + } +} -- Gitblit v1.9.1