PrintNumTask.java 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. package com.zskk.task;
  2. import java.text.ParseException;
  3. import java.text.SimpleDateFormat;
  4. import java.util.Date;
  5. import java.util.HashMap;
  6. import java.util.List;
  7. import java.util.Map;
  8. import com.alibaba.fastjson.JSON;
  9. import com.alibaba.fastjson.JSONArray;
  10. import com.alibaba.fastjson.JSONObject;
  11. import com.jfinal.kit.PropKit;
  12. import com.jfinal.plugin.activerecord.Db;
  13. import com.jfinal.plugin.activerecord.Record;
  14. import com.jfinal.plugin.cron4j.ITask;
  15. import com.zskk.service.DataService;
  16. import com.zskk.service.ServiceFactory;
  17. import com.zskk.service.ThreadPoolService;
  18. public class PrintNumTask implements ITask {
  19. @Override
  20. public void run() {
  21. // TODO Auto-generated method stub
  22. DataService dService = ServiceFactory.getService(DataService.class);
  23. List<Record> records = Db.use("print").find("select * from IMAGEVIEW where PRINTED=? and PRINTTIME >?", "true", parseStringToDate1());
  24. for (Record record : records) {
  25. try {
  26. if (record == null) {
  27. continue;
  28. }
  29. Map<String, String> annex_params = new HashMap<>();
  30. annex_params.put("institution_id", PropKit.get("institution_id"));
  31. annex_params.put("type", "3");
  32. annex_params.put("code", record.getStr("CHECKID"));
  33. annex_params.put("print_time", record.getStr("PRINTTIME"));
  34. ThreadPoolService tService = ServiceFactory.getService(ThreadPoolService.class);
  35. tService.execute(() -> {
  36. dService.savePrint(annex_params);
  37. });
  38. } catch (Exception e) {
  39. // TODO: handle exception
  40. continue;
  41. }
  42. }
  43. }
  44. @Override
  45. public void stop() {
  46. // TODO Auto-generated method stub
  47. }
  48. /**
  49. * 日期字符串格式转换
  50. * @param dateStr
  51. * @return
  52. */
  53. private String parseStringToDate(String dateStr) {
  54. if (dateStr == null) {
  55. return "";
  56. }
  57. SimpleDateFormat sdf= new SimpleDateFormat("yyyyMMdd");
  58. Date date = null;
  59. String timeString = null;
  60. try {
  61. date = sdf.parse(dateStr);
  62. SimpleDateFormat sdf2= new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  63. timeString = sdf2.format(date);
  64. } catch (ParseException e) {
  65. // TODO Auto-generated catch block
  66. e.printStackTrace();
  67. }
  68. return timeString;
  69. }
  70. /**
  71. * 日期字符串格式转换
  72. *
  73. * @param dateStr
  74. * @return
  75. */
  76. private String parseStringToDate1() {
  77. SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  78. Date date = new Date();
  79. String timeString = null;
  80. Long i = date.getTime();
  81. Long j = i - 54000000;
  82. Date newdate = new Date(j);
  83. timeString = sdf.format(newdate);
  84. return timeString;
  85. }
  86. }