| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166 |
- package com.mangoo.rating.recommend.dto;
- import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
- import com.mangoo.rating.recommend.exception.ServiceException;
- import com.mangoo.rating.recommend.utils.bean.DozerUtils;
- import lombok.Data;
- import lombok.extern.slf4j.Slf4j;
- import org.springframework.util.CollectionUtils;
- import org.springframework.util.StringUtils;
- import java.io.Serializable;
- import java.util.HashMap;
- import java.util.Map;
- /**
- * 接口入参
- */
- @Data
- @Slf4j
- @JsonIgnoreProperties(ignoreUnknown = true)
- public class InDto implements Serializable {
- private static final long serialVersionUID = 1L;
- //appid
- private String appid;
- //openid
- private String openid;
- //unionid
- private String unionid;
- //用户类型: WX_WEB (微信公众号) WX_APPLET (微信小程序) THIRD (第三方) WX_AUTH(微信授权登陆)
- private String userType;
- //userid
- private Integer userId;
- //账号
- private String username;
- //每页数据条数
- private Integer pageSize =10;
- //页码数
- private Integer pageNo=1;
- //其他数据
- private Map<String,Object> data;
- //部门id
- private Integer departId;
- private Integer offset;
- private long timestamp;
- private String version;
- // 极光id
- private String smsRegisterId;
- //签名
- private String sign;
- public Object get(String key){
- if(null != data && !data.isEmpty()){
- return this.data.get(key);
- }
- return null;
- }
- public Object getDefault(String key,Object value){
- if(null != data && !data.isEmpty()){
- try{
- return null == this.data.get(key) ? value : this.data.get(key);
- }catch (Exception e){
- }
- }
- return value;
- }
- public String getString(String key){
- if(null != data && !data.isEmpty()&&this.data.containsKey(key)){
- return null != this.data.get(key) ? String.valueOf(this.data.get(key)) : null;
- }
- return null;
- }
- public Boolean existKeyString(String key){
- if(null != data && !data.isEmpty()&&this.data.containsKey(key)){
- return true;
- }
- return false;
- }
- public Integer getIntegerParam(String key) {
- if (CollectionUtils.isEmpty(data)) {
- return null;
- }
- return (Integer) this.data.get(key);
- }
- public boolean getBooleanParam(String key) {
- if (CollectionUtils.isEmpty(data)) {
- return false;
- }
- Boolean b = (Boolean) this.data.get(key);
- return b != null && b;
- }
- public String getStringDefault(String key,String value){
- if(null != data && !data.isEmpty()){
- try {
- String ret = String.valueOf(this.data.get(key));
- return StringUtils.isEmpty(ret) ? value : ("null".equals(ret) ? value : ret);
- }catch (Exception e){}
- }
- return value;
- }
- public Integer getIntegerDefault(String key,Integer value){
- if(null != data && !data.isEmpty()){
- try {
- Integer ret = (Integer) this.data.get(key);
- return StringUtils.isEmpty(ret) ? value : ret;
- }catch (Exception e){
- }
- }
- return value;
- }
- public InDto put(String key ,Object value){
- if(null == this.data) this.data = new HashMap<>();
- this.data.put(key, value);
- return this;
- }
- public InDto remove(String key){
- if(null != this.data && !this.data.isEmpty()){
- this.data.remove(key);
- }
- return this;
- }
- public Integer getPageSize() {
- if(this.pageSize == null){
- return pageSize;
- }
- return this.pageSize>0? this.pageSize:10;
- }
- public Integer getPageNo() {
- if(this.pageNo == null){
- return pageNo;
- }
- return this.pageNo>0? this.pageNo:1;
- }
- public Integer getOffset(){
- if(this.pageNo==null||this.pageSize==null){
- return 0;
- }
- return((pageNo) - 1 ) * pageSize;
- }
- /**
- * 转换indto中data为指定参数
- *
- * @param param
- * @param <T>
- * @return
- */
- public <T> T buildParam( T param) {
- try {
- DozerUtils.copy(this.data,param);
- return param;
- } catch (Exception e) {
- log.error("参数转换失败:", e);
- }
- throw new ServiceException(500, "参数获取失败!");
- }
- }
|