BaseClass.java 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. /**
  2. *
  3. */
  4. package openapi.base;
  5. import openapi.base.data.db.SQLiteJDBC;
  6. import p2.p2server.P2Server;
  7. import p2.pao.PaoRemote;
  8. import p2.pao.PaoSetRemote;
  9. import p2.util.P2Exception;
  10. import java.text.SimpleDateFormat;
  11. import java.util.Calendar;
  12. import java.util.Date;
  13. import java.util.HashMap;
  14. /**
  15. * @author Administrator
  16. *
  17. */
  18. public class BaseClass {
  19. public static SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  20. public static void printErrOut(String keyname, String msg, boolean onlydebug) {
  21. msg = msg.replace("'", "''");
  22. new SQLiteJDBC().InsertLogMsg(keyname, msg, "err", onlydebug);
  23. }
  24. public static void printInfoOut(String keyname, String msg, boolean onlydebug) {
  25. msg = msg.replace("'", "''");
  26. new SQLiteJDBC().InsertLogMsg(keyname, msg, "info", onlydebug);
  27. }
  28. public String getWeekFirstDay() {
  29. Calendar calendar = Calendar.getInstance();
  30. SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
  31. calendar.set(Calendar.DAY_OF_WEEK, 1);
  32. calendar.set(Calendar.DATE, calendar.get(Calendar.DATE) + 1);
  33. return format.format(calendar.getTime());
  34. }
  35. public String getWeekLastDay() {
  36. Calendar calendar = Calendar.getInstance();
  37. SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
  38. calendar.set(Calendar.DAY_OF_WEEK, 7);
  39. calendar.set(Calendar.DATE, calendar.get(Calendar.DATE) + 1);
  40. return format.format(calendar.getTime());
  41. }
  42. public String getMonthFirstDay() {
  43. Calendar calendar = Calendar.getInstance();
  44. SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
  45. calendar.set(Calendar.DAY_OF_MONTH, 1);
  46. return format.format(calendar.getTime());
  47. }
  48. public String getMonthLastDay() {
  49. Calendar calendar = Calendar.getInstance();
  50. SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
  51. calendar.set(Calendar.DAY_OF_MONTH, calendar.getActualMaximum(Calendar.DAY_OF_MONTH));
  52. return format.format(calendar.getTime());
  53. }
  54. /**
  55. * 获取当前系统日期,格式为yyyy-MM-dd
  56. *
  57. * @return
  58. */
  59. public String getDate_Str() {
  60. Calendar calendar = Calendar.getInstance();
  61. SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
  62. return format.format(calendar.getTime());
  63. }
  64. public String getDate_Str(Date date) {
  65. if(date==null){
  66. return "";
  67. }
  68. SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
  69. return format.format(date.getTime());
  70. }
  71. public Date getDate(String date) {
  72. try {
  73. Date a = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(date);
  74. return a;
  75. } catch (Exception e) {
  76. e.printStackTrace();
  77. }
  78. return null;
  79. }
  80. /**
  81. * 获取当前系统时间,格式为YYYY-MM-dd HH:mm:ss
  82. *
  83. * @return
  84. */
  85. public String getDateTime_Str() {
  86. Calendar calendar = Calendar.getInstance();
  87. SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  88. return format.format(calendar.getTime());
  89. }
  90. public String getDateTime_Str(Date date) {
  91. if(date==null){
  92. return "";
  93. }
  94. SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  95. return format.format(date.getTime());
  96. }
  97. public String nullToStr(String str) {
  98. if (null == str || "null".equalsIgnoreCase(str)) {
  99. return "";
  100. } else {
  101. return str;
  102. }
  103. }
  104. public PaoSetRemote getP2ServerPaoSet(String paosetname, String hrid, String where) throws P2Exception {
  105. PaoSetRemote paoSetRemote = getP2ServerPaoSet(paosetname, hrid);
  106. paoSetRemote.setWhere(where);
  107. paoSetRemote.reset();
  108. return paoSetRemote;
  109. }
  110. public PaoSetRemote getP2ServerPaoSet(String paosetname, String hrid) throws P2Exception {
  111. PaoSetRemote paoSetRemote = P2Server.getP2Server().getPaoSet(paosetname, P2Server.getP2Server().getUserInfo(hrid));
  112. return paoSetRemote;
  113. }
  114. public HashMap<String, PaoRemote> getPaoMap(PaoSetRemote paoSetRemote, String keyfieldname) throws P2Exception {
  115. HashMap<String, PaoRemote> map = new HashMap<>(16);
  116. int i = 0;
  117. while (paoSetRemote.getPao(i) != null) {
  118. map.put(paoSetRemote.getPao(i).getString(keyfieldname), paoSetRemote.getPao(i));
  119. i++;
  120. }
  121. return map;
  122. }
  123. }