InDto.java 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. package com.mangoo.rating.recommend.dto;
  2. import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
  3. import com.mangoo.rating.recommend.exception.ServiceException;
  4. import com.mangoo.rating.recommend.utils.bean.DozerUtils;
  5. import lombok.Data;
  6. import lombok.extern.slf4j.Slf4j;
  7. import org.springframework.util.CollectionUtils;
  8. import org.springframework.util.StringUtils;
  9. import java.io.Serializable;
  10. import java.util.HashMap;
  11. import java.util.Map;
  12. /**
  13. * 接口入参
  14. */
  15. @Data
  16. @Slf4j
  17. @JsonIgnoreProperties(ignoreUnknown = true)
  18. public class InDto implements Serializable {
  19. private static final long serialVersionUID = 1L;
  20. //appid
  21. private String appid;
  22. //openid
  23. private String openid;
  24. //unionid
  25. private String unionid;
  26. //用户类型: WX_WEB (微信公众号) WX_APPLET (微信小程序) THIRD (第三方) WX_AUTH(微信授权登陆)
  27. private String userType;
  28. //userid
  29. private Integer userId;
  30. //账号
  31. private String username;
  32. //每页数据条数
  33. private Integer pageSize =10;
  34. //页码数
  35. private Integer pageNo=1;
  36. //其他数据
  37. private Map<String,Object> data;
  38. //部门id
  39. private Integer departId;
  40. private Integer offset;
  41. private long timestamp;
  42. private String version;
  43. // 极光id
  44. private String smsRegisterId;
  45. //签名
  46. private String sign;
  47. public Object get(String key){
  48. if(null != data && !data.isEmpty()){
  49. return this.data.get(key);
  50. }
  51. return null;
  52. }
  53. public Object getDefault(String key,Object value){
  54. if(null != data && !data.isEmpty()){
  55. try{
  56. return null == this.data.get(key) ? value : this.data.get(key);
  57. }catch (Exception e){
  58. }
  59. }
  60. return value;
  61. }
  62. public String getString(String key){
  63. if(null != data && !data.isEmpty()&&this.data.containsKey(key)){
  64. return null != this.data.get(key) ? String.valueOf(this.data.get(key)) : null;
  65. }
  66. return null;
  67. }
  68. public Boolean existKeyString(String key){
  69. if(null != data && !data.isEmpty()&&this.data.containsKey(key)){
  70. return true;
  71. }
  72. return false;
  73. }
  74. public Integer getIntegerParam(String key) {
  75. if (CollectionUtils.isEmpty(data)) {
  76. return null;
  77. }
  78. return (Integer) this.data.get(key);
  79. }
  80. public boolean getBooleanParam(String key) {
  81. if (CollectionUtils.isEmpty(data)) {
  82. return false;
  83. }
  84. Boolean b = (Boolean) this.data.get(key);
  85. return b != null && b;
  86. }
  87. public String getStringDefault(String key,String value){
  88. if(null != data && !data.isEmpty()){
  89. try {
  90. String ret = String.valueOf(this.data.get(key));
  91. return StringUtils.isEmpty(ret) ? value : ("null".equals(ret) ? value : ret);
  92. }catch (Exception e){}
  93. }
  94. return value;
  95. }
  96. public Integer getIntegerDefault(String key,Integer value){
  97. if(null != data && !data.isEmpty()){
  98. try {
  99. Integer ret = (Integer) this.data.get(key);
  100. return StringUtils.isEmpty(ret) ? value : ret;
  101. }catch (Exception e){
  102. }
  103. }
  104. return value;
  105. }
  106. public InDto put(String key ,Object value){
  107. if(null == this.data) this.data = new HashMap<>();
  108. this.data.put(key, value);
  109. return this;
  110. }
  111. public InDto remove(String key){
  112. if(null != this.data && !this.data.isEmpty()){
  113. this.data.remove(key);
  114. }
  115. return this;
  116. }
  117. public Integer getPageSize() {
  118. if(this.pageSize == null){
  119. return pageSize;
  120. }
  121. return this.pageSize>0? this.pageSize:10;
  122. }
  123. public Integer getPageNo() {
  124. if(this.pageNo == null){
  125. return pageNo;
  126. }
  127. return this.pageNo>0? this.pageNo:1;
  128. }
  129. public Integer getOffset(){
  130. if(this.pageNo==null||this.pageSize==null){
  131. return 0;
  132. }
  133. return((pageNo) - 1 ) * pageSize;
  134. }
  135. /**
  136. * 转换indto中data为指定参数
  137. *
  138. * @param param
  139. * @param <T>
  140. * @return
  141. */
  142. public <T> T buildParam( T param) {
  143. try {
  144. DozerUtils.copy(this.data,param);
  145. return param;
  146. } catch (Exception e) {
  147. log.error("参数转换失败:", e);
  148. }
  149. throw new ServiceException(500, "参数获取失败!");
  150. }
  151. }