Condition.java 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. package com.fjhx.base;
  2. import cn.hutool.core.convert.Convert;
  3. import cn.hutool.core.date.DateUtil;
  4. import cn.hutool.core.util.ObjectUtil;
  5. import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
  6. import com.fjhx.utils.Assert;
  7. import com.fjhx.utils.PageUtil;
  8. import org.springblade.core.log.exception.ServiceException;
  9. import java.util.Date;
  10. import java.util.HashMap;
  11. /**
  12. * 条件实体
  13. */
  14. public class Condition extends HashMap<String, Object> {
  15. /**
  16. * 开始时间
  17. */
  18. public Date getBeginTime() {
  19. Object beginTimeObj = this.get("beginTime");
  20. Assert.notEmpty(beginTimeObj, "开始时间不能为空");
  21. Date beginTime;
  22. try {
  23. beginTime = DateUtil.beginOfDay(DateUtil.parse(beginTimeObj.toString()));
  24. } catch (Exception e) {
  25. throw new ServiceException("开始时间格式错误");
  26. }
  27. return beginTime;
  28. }
  29. /**
  30. * 结束时间
  31. */
  32. public Date getEndTime() {
  33. Object endTimeObj = this.get("endTime");
  34. Assert.notEmpty(endTimeObj, "结束时间不能为空");
  35. Date endTime;
  36. try {
  37. endTime = DateUtil.endOfDay(DateUtil.parse(endTimeObj.toString()));
  38. } catch (Exception e) {
  39. throw new ServiceException("结束时间格式错误");
  40. }
  41. return endTime;
  42. }
  43. /**
  44. * 关键字
  45. */
  46. public String getKeyword() {
  47. return getStr("keyword");
  48. }
  49. /**
  50. * 审批状态
  51. */
  52. public Integer getFlowStatus() {
  53. return getInt("flowStatus");
  54. }
  55. /**
  56. * 类型
  57. */
  58. public Integer getType() {
  59. return getInt("type");
  60. }
  61. /**
  62. * 状态
  63. */
  64. public Integer getStatus() {
  65. return getInt("status");
  66. }
  67. /**
  68. * 获取字符串
  69. */
  70. public String getStr(String str) {
  71. Object value = super.get(str);
  72. if (ObjectUtil.isEmpty(value)) {
  73. return null;
  74. }
  75. return value.toString();
  76. }
  77. /**
  78. * 获取字符串
  79. */
  80. public String getStr(String str, String error) {
  81. Object value = super.get(str);
  82. Assert.notEmpty(value, error);
  83. return value.toString();
  84. }
  85. /**
  86. * 获取int
  87. */
  88. public Integer getInt(String str) {
  89. return Convert.toInt(get(str));
  90. }
  91. public Page<Object> getPage() {
  92. return new Page<>(PageUtil.getCurrent(this), PageUtil.getSize(this));
  93. }
  94. }