BaseClass.java 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  1. /**
  2. *
  3. */
  4. package com.cnd3b.common;
  5. import com.cnd3b.common.data.db.SQLiteJDBC;
  6. import com.cnd3b.common.parameter.parameter;
  7. import com.cnd3b.utility.Sms;
  8. import p2.p2server.P2Server;
  9. import p2.pao.PaoRemote;
  10. import p2.pao.PaoSetRemote;
  11. import p2.util.P2Exception;
  12. import java.text.SimpleDateFormat;
  13. import java.util.ArrayList;
  14. import java.util.Calendar;
  15. import java.util.Date;
  16. import java.util.HashMap;
  17. /**
  18. * @author Administrator
  19. *
  20. */
  21. public class BaseClass {
  22. public static SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  23. public static void printErrOut(String keyname, String msg) {
  24. msg = msg.replace("'", "''");
  25. new SQLiteJDBC().InsertLogMsg(keyname, msg, "err");
  26. System.err.println(keyname + ":" + msg);
  27. }
  28. public static void printInfoOut(String keyname, String msg, boolean notdebug) {
  29. if (notdebug || parameter.isdebug()) {
  30. msg = msg.replace("'", "''");
  31. new SQLiteJDBC().InsertLogMsg(keyname, msg, "info");
  32. System.err.println(keyname + ":" + msg);
  33. }
  34. }
  35. public static void printInfoOut(String keyname, String msg) {
  36. if (parameter.isdebug()) {
  37. msg = msg.replace("'", "''");
  38. new SQLiteJDBC().InsertLogMsg(keyname, msg, "info");
  39. System.err.println(keyname + ":" + msg);
  40. }
  41. }
  42. public String getWeekFirstDay() {
  43. Calendar calendar = Calendar.getInstance();
  44. SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
  45. calendar.set(Calendar.DAY_OF_WEEK, 1);
  46. calendar.set(Calendar.DATE, calendar.get(Calendar.DATE) + 1);
  47. return format.format(calendar.getTime());
  48. }
  49. public String getWeekLastDay() {
  50. Calendar calendar = Calendar.getInstance();
  51. SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
  52. calendar.set(Calendar.DAY_OF_WEEK, 7);
  53. calendar.set(Calendar.DATE, calendar.get(Calendar.DATE) + 1);
  54. return format.format(calendar.getTime());
  55. }
  56. public String getMonthFirstDay() {
  57. Calendar calendar = Calendar.getInstance();
  58. SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
  59. calendar.set(Calendar.DAY_OF_MONTH, 1);
  60. return format.format(calendar.getTime());
  61. }
  62. public String getMonthLastDay() {
  63. Calendar calendar = Calendar.getInstance();
  64. SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
  65. calendar.set(Calendar.DAY_OF_MONTH, calendar.getActualMaximum(Calendar.DAY_OF_MONTH));
  66. return format.format(calendar.getTime());
  67. }
  68. /**
  69. * 获取当前系统日期,格式为yyyy-MM-dd
  70. *
  71. * @return
  72. */
  73. public String getDate_Str() {
  74. Calendar calendar = Calendar.getInstance();
  75. SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
  76. return format.format(calendar.getTime());
  77. }
  78. public String getDate_Str(Date date) {
  79. SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
  80. return format.format(date.getTime());
  81. }
  82. public Date getDateTime() {
  83. return Calendar.getInstance().getTime();
  84. }
  85. /**
  86. * 获取当前系统时间,格式为yyyy-MM-dd HH:mm:ss
  87. *
  88. * @return
  89. */
  90. public String getDateTime_Str() {
  91. Calendar calendar = Calendar.getInstance();
  92. SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  93. return format.format(calendar.getTime());
  94. }
  95. public String getDateTime_Str(Date date) {
  96. SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  97. return format.format(date.getTime());
  98. }
  99. public String nullToStr(String str) {
  100. if (null == str || "null".equals(str)) {
  101. return "";
  102. } else {
  103. return str;
  104. }
  105. }
  106. ArrayList<PaoSetRemote> PaoSetRemoteList = new ArrayList<>();
  107. public PaoSetRemote getP2ServerPaoSet(String paosetname, String hrid, String where) throws P2Exception {
  108. PaoSetRemote paoSetRemote = getP2ServerPaoSet(paosetname, hrid);
  109. paoSetRemote.setWhere(where);
  110. paoSetRemote.reset();
  111. return paoSetRemote;
  112. }
  113. public PaoSetRemote getP2ServerPaoSet(String paosetname, String hrid, String where, String orderby) throws P2Exception {
  114. PaoSetRemote paoSetRemote = getP2ServerPaoSet(paosetname, hrid);
  115. paoSetRemote.setWhere(where);
  116. paoSetRemote.setOrderBy(orderby);
  117. paoSetRemote.reset();
  118. return paoSetRemote;
  119. }
  120. public PaoSetRemote getP2ServerPaoSet(String paosetname, String hrid) throws P2Exception {
  121. PaoSetRemote paoSetRemote = P2Server.getP2Server().getPaoSet(paosetname, P2Server.getP2Server().getUserInfo(hrid));
  122. PaoSetRemoteList.add(paoSetRemote);
  123. return paoSetRemote;
  124. }
  125. public PaoSetRemote getP2ServerSystemPaoSet(String paosetname, String where) throws P2Exception {
  126. PaoSetRemote paoSetRemote = getP2ServerSystemPaoSet(paosetname);
  127. paoSetRemote.setWhere(where);
  128. paoSetRemote.reset();
  129. return paoSetRemote;
  130. }
  131. public PaoSetRemote getP2ServerSystemPaoSet(String paosetname, String where, String orderby) throws P2Exception {
  132. PaoSetRemote paoSetRemote = getP2ServerSystemPaoSet(paosetname);
  133. paoSetRemote.setWhere(where);
  134. paoSetRemote.setOrderBy(orderby);
  135. paoSetRemote.reset();
  136. return paoSetRemote;
  137. }
  138. public PaoSetRemote getP2ServerSystemPaoSet(String paosetname) throws P2Exception {
  139. PaoSetRemote paoSetRemote = P2Server.getP2Server().getPaoSet(paosetname, P2Server.getP2Server().getSystemUserInfo());
  140. PaoSetRemoteList.add(paoSetRemote);
  141. return paoSetRemote;
  142. }
  143. public ArrayList<Object> getP2FieldValues(PaoSetRemote paoSetRemote, String fieldname) throws P2Exception {
  144. ArrayList<Object> list = new ArrayList<>();
  145. int i = 0;
  146. PaoRemote pao = null;
  147. while ((pao = paoSetRemote.getPao(i)) != null) {
  148. list.add(pao.getDatabaseValue(fieldname));
  149. i++;
  150. }
  151. return list;
  152. }
  153. public HashMap<String, PaoRemote> getPaoMap(PaoSetRemote paoSetRemote, String keyfieldname) throws P2Exception {
  154. HashMap<String, PaoRemote> map = new HashMap<>();
  155. int i = 0;
  156. while (paoSetRemote.getPao(i) != null) {
  157. map.put(paoSetRemote.getPao(i).getString(keyfieldname), paoSetRemote.getPao(i));
  158. i++;
  159. }
  160. return map;
  161. }
  162. private static HashMap<String, ArrayList<String>> monthsmap = new HashMap<>();
  163. public ArrayList<String> getSectionMonth(String fbegmonth, String fendmonth) {
  164. String key = fbegmonth + "+" + fendmonth;
  165. if (monthsmap.containsKey(key)) {
  166. return monthsmap.get(key);
  167. }
  168. ArrayList<String> list = new ArrayList<>();
  169. int startmonth = Integer.parseInt(fbegmonth.substring(0, 4)) * 12 + Integer.parseInt(fbegmonth.substring(5));
  170. int endmonth = Integer.parseInt(fendmonth.substring(0, 4)) * 12 + Integer.parseInt(fendmonth.substring(5));
  171. while (startmonth <= endmonth) {
  172. int year = startmonth / 12;
  173. int month = startmonth % 12;
  174. if (month == 0) {
  175. year = year - 1;
  176. month = 12;
  177. }
  178. list.add(year + "-" + (month < 10 ? ("0" + month) : ("" + month)));
  179. startmonth++;
  180. }
  181. monthsmap.put(key, list);
  182. return list;
  183. }
  184. /**
  185. * 短信发送
  186. * @param fphonenumber
  187. * @param msg
  188. */
  189. public void sendShortMsg(String fphonenumber, String msg) {
  190. /**
  191. * 发送短信提醒
  192. */
  193. if (!fphonenumber.equals("")) {
  194. Sms sms = new Sms();
  195. sms.sendOutMsg(fphonenumber, msg);
  196. }
  197. }
  198. }