/** * */ package openapi.base; import openapi.base.data.db.SQLiteJDBC; import p2.p2server.P2Server; import p2.pao.PaoRemote; import p2.pao.PaoSetRemote; import p2.util.P2Exception; import java.text.SimpleDateFormat; import java.util.Calendar; import java.util.Date; import java.util.HashMap; /** * @author Administrator * */ public class BaseClass { public static SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); public static void printErrOut(String keyname, String msg, boolean onlydebug) { msg = msg.replace("'", "''"); new SQLiteJDBC().InsertLogMsg(keyname, msg, "err", onlydebug); } public static void printInfoOut(String keyname, String msg, boolean onlydebug) { msg = msg.replace("'", "''"); new SQLiteJDBC().InsertLogMsg(keyname, msg, "info", onlydebug); } public String getWeekFirstDay() { Calendar calendar = Calendar.getInstance(); SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd"); calendar.set(Calendar.DAY_OF_WEEK, 1); calendar.set(Calendar.DATE, calendar.get(Calendar.DATE) + 1); return format.format(calendar.getTime()); } public String getWeekLastDay() { Calendar calendar = Calendar.getInstance(); SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd"); calendar.set(Calendar.DAY_OF_WEEK, 7); calendar.set(Calendar.DATE, calendar.get(Calendar.DATE) + 1); return format.format(calendar.getTime()); } public String getMonthFirstDay() { Calendar calendar = Calendar.getInstance(); SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd"); calendar.set(Calendar.DAY_OF_MONTH, 1); return format.format(calendar.getTime()); } public String getMonthLastDay() { Calendar calendar = Calendar.getInstance(); SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd"); calendar.set(Calendar.DAY_OF_MONTH, calendar.getActualMaximum(Calendar.DAY_OF_MONTH)); return format.format(calendar.getTime()); } /** * 获取当前系统日期,格式为yyyy-MM-dd * * @return */ public String getDate_Str() { Calendar calendar = Calendar.getInstance(); SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd"); return format.format(calendar.getTime()); } public String getDate_Str(Date date) { if(date==null){ return ""; } SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd"); return format.format(date.getTime()); } public Date getDate(String date) { try { Date a = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(date); return a; } catch (Exception e) { e.printStackTrace(); } return null; } /** * 获取当前系统时间,格式为YYYY-MM-dd HH:mm:ss * * @return */ public String getDateTime_Str() { Calendar calendar = Calendar.getInstance(); SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); return format.format(calendar.getTime()); } public String getDateTime_Str(Date date) { if(date==null){ return ""; } SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); return format.format(date.getTime()); } public String nullToStr(String str) { if (null == str || "null".equalsIgnoreCase(str)) { return ""; } else { return str; } } public PaoSetRemote getP2ServerPaoSet(String paosetname, String hrid, String where) throws P2Exception { PaoSetRemote paoSetRemote = getP2ServerPaoSet(paosetname, hrid); paoSetRemote.setWhere(where); paoSetRemote.reset(); return paoSetRemote; } public PaoSetRemote getP2ServerPaoSet(String paosetname, String hrid) throws P2Exception { PaoSetRemote paoSetRemote = P2Server.getP2Server().getPaoSet(paosetname, P2Server.getP2Server().getUserInfo(hrid)); return paoSetRemote; } public HashMap getPaoMap(PaoSetRemote paoSetRemote, String keyfieldname) throws P2Exception { HashMap map = new HashMap<>(16); int i = 0; while (paoSetRemote.getPao(i) != null) { map.put(paoSetRemote.getPao(i).getString(keyfieldname), paoSetRemote.getPao(i)); i++; } return map; } }