| @@ -10,9 +10,11 @@ import cn.binarywang.wx.miniapp.api.impl.WxMaServiceImpl; | |||||
| import cn.binarywang.wx.miniapp.config.WxMaInMemoryConfig; | import cn.binarywang.wx.miniapp.config.WxMaInMemoryConfig; | ||||
| import com.simple.domain.po.WxAppinfo; | import com.simple.domain.po.WxAppinfo; | ||||
| import com.simple.domain.po.WxCUser; | import com.simple.domain.po.WxCUser; | ||||
| import com.simple.domain.po.WxMerchantBUser; | |||||
| import com.simple.interceptor.AuthorizationInterceptor; | import com.simple.interceptor.AuthorizationInterceptor; | ||||
| import com.simple.service.WxAppinfoService; | import com.simple.service.WxAppinfoService; | ||||
| import com.simple.service.WxCUserService; | import com.simple.service.WxCUserService; | ||||
| import com.simple.service.WxMerchantBUserService; | |||||
| import org.springframework.beans.factory.annotation.Autowired; | import org.springframework.beans.factory.annotation.Autowired; | ||||
| import org.springframework.web.bind.WebDataBinder; | import org.springframework.web.bind.WebDataBinder; | ||||
| import org.springframework.web.bind.annotation.InitBinder; | import org.springframework.web.bind.annotation.InitBinder; | ||||
| @@ -25,7 +27,7 @@ import javax.servlet.http.HttpServletRequest; | |||||
| @RestController | @RestController | ||||
| public class BaseController { | public class BaseController { | ||||
| @Autowired | @Autowired | ||||
| private WxCUserService wxCUserService; | |||||
| private WxMerchantBUserService wxMerchantBUserService; | |||||
| @Autowired | @Autowired | ||||
| private WxAppinfoService wxAppinfoService; | private WxAppinfoService wxAppinfoService; | ||||
| @@ -53,17 +55,17 @@ public class BaseController { | |||||
| } | } | ||||
| public WxCUser getUser() { | |||||
| public WxMerchantBUser getUser() { | |||||
| HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest(); | HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest(); | ||||
| Long cUserId = (Long) request.getAttribute(AuthorizationInterceptor.LOGIN_USER_KEY); | Long cUserId = (Long) request.getAttribute(AuthorizationInterceptor.LOGIN_USER_KEY); | ||||
| WxCUser user = wxCUserService.getById(cUserId); | |||||
| WxMerchantBUser user = wxMerchantBUserService.getById(cUserId); | |||||
| return user; | return user; | ||||
| } | } | ||||
| public String getTenantId() { | public String getTenantId() { | ||||
| HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest(); | HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest(); | ||||
| Long cUserId = (Long) request.getAttribute(AuthorizationInterceptor.LOGIN_USER_KEY); | Long cUserId = (Long) request.getAttribute(AuthorizationInterceptor.LOGIN_USER_KEY); | ||||
| WxCUser user = wxCUserService.getById(cUserId); | |||||
| WxMerchantBUser user = wxMerchantBUserService.getById(cUserId); | |||||
| return user.getTenantId(); | return user.getTenantId(); | ||||
| } | } | ||||
| @@ -1,71 +0,0 @@ | |||||
| package com.simple.controller; | |||||
| import org.apache.log4j.Logger; | |||||
| import org.springframework.beans.factory.annotation.Autowired; | |||||
| import org.springframework.util.Assert; | |||||
| import org.springframework.web.bind.annotation.*; | |||||
| import com.github.pagehelper.PageInfo; | |||||
| import com.simple.common.Result; | |||||
| import com.simple.common.ResultData; | |||||
| import com.simple.domain.po.WxAppinfo; | |||||
| import com.simple.service.WxAppinfoService; | |||||
| import io.swagger.annotations.ApiImplicitParam; | |||||
| import io.swagger.annotations.ApiImplicitParams; | |||||
| import io.swagger.annotations.ApiOperation; | |||||
| @RestController | |||||
| @RequestMapping("wxAppinfo") | |||||
| public class WxAppinfoController extends BaseController | |||||
| { | |||||
| @Autowired | |||||
| private WxAppinfoService wxAppinfoService; | |||||
| private Logger logger = Logger.getLogger(WxAppinfoController.class); | |||||
| @ApiOperation("分页列表接口") | |||||
| @GetMapping("list") | |||||
| @ApiImplicitParams({ | |||||
| @ApiImplicitParam(name="pageNum",value="页数",dataType="int", paramType = "query",required=true), | |||||
| @ApiImplicitParam(name="pageSize",value="每页条数",dataType="int", paramType = "query",required=true)}) | |||||
| public ResultData list(@ModelAttribute WxAppinfo wxAppinfo,Integer pageNum, Integer pageSize) { | |||||
| if (null == wxAppinfo) wxAppinfo = new WxAppinfo(); | |||||
| final PageInfo<WxAppinfo> page = wxAppinfoService.listAsPage(wxAppinfo, pageNum, pageSize); | |||||
| return new ResultData(page); | |||||
| } | |||||
| @ApiOperation("新增接口") | |||||
| @PostMapping("add") | |||||
| public ResultData add(@RequestBody WxAppinfo wxAppinfo) { | |||||
| //Assert.notNull(wxAppinfo.getName(), "角色名不能为空"); | |||||
| //Assert.isTrue(!checkUnique(sysRole.getName(), null), "重复的角色名"); | |||||
| wxAppinfoService.saveOrUpdate(wxAppinfo); | |||||
| return new ResultData(); | |||||
| } | |||||
| @ApiOperation("根据id更新接口") | |||||
| @PostMapping("update") | |||||
| public ResultData update(@RequestBody WxAppinfo wxAppinfo) { | |||||
| wxAppinfoService.saveOrUpdate(wxAppinfo); | |||||
| return new ResultData(); | |||||
| } | |||||
| @ApiOperation("根据id删除接口") | |||||
| @GetMapping("/del") | |||||
| @ApiImplicitParam(name="id",value="id",dataType="Long", paramType = "query",required=true) | |||||
| public ResultData delete(Long id) { | |||||
| wxAppinfoService.deleteById(id); | |||||
| return new ResultData(Result.SUCCESS, "删除成功", null); | |||||
| } | |||||
| @ApiOperation("根据id查询接口") | |||||
| @GetMapping("/findById") | |||||
| @ApiImplicitParam(name="id",value="id",dataType="Long", paramType = "query",required=true) | |||||
| public ResultData findById(Long id) { | |||||
| return new ResultData(Result.SUCCESS,"查询成功",wxAppinfoService.getById(id)); | |||||
| } | |||||
| } | |||||
| @@ -1,5 +1,12 @@ | |||||
| package com.simple.controller; | package com.simple.controller; | ||||
| import cn.binarywang.wx.miniapp.api.WxMaService; | |||||
| import cn.binarywang.wx.miniapp.bean.WxMaJscode2SessionResult; | |||||
| import com.simple.annotation.AuthIgnore; | |||||
| import com.simple.common.ErrorCode; | |||||
| import com.simple.utils.IPUtil; | |||||
| import me.chanjar.weixin.common.error.WxErrorException; | |||||
| import org.apache.commons.lang3.StringUtils; | |||||
| import org.apache.log4j.Logger; | import org.apache.log4j.Logger; | ||||
| import org.springframework.beans.factory.annotation.Autowired; | import org.springframework.beans.factory.annotation.Autowired; | ||||
| import org.springframework.util.Assert; | import org.springframework.util.Assert; | ||||
| @@ -14,58 +21,79 @@ import com.simple.service.WxMerchantBUserService; | |||||
| import io.swagger.annotations.ApiImplicitParam; | import io.swagger.annotations.ApiImplicitParam; | ||||
| import io.swagger.annotations.ApiImplicitParams; | import io.swagger.annotations.ApiImplicitParams; | ||||
| import io.swagger.annotations.ApiOperation; | import io.swagger.annotations.ApiOperation; | ||||
| import org.springframework.web.context.request.RequestContextHolder; | |||||
| import org.springframework.web.context.request.ServletRequestAttributes; | |||||
| import javax.servlet.http.HttpServletRequest; | |||||
| import java.util.Date; | |||||
| import java.util.HashMap; | |||||
| import java.util.Map; | |||||
| @RestController | @RestController | ||||
| @RequestMapping("wxMerchantBUser") | @RequestMapping("wxMerchantBUser") | ||||
| public class WxMerchantBUserController extends BaseController | public class WxMerchantBUserController extends BaseController | ||||
| { | { | ||||
| private Logger logger = Logger.getLogger(WxMerchantBUserController.class); | |||||
| @Autowired | @Autowired | ||||
| private WxMerchantBUserService wxMerchantBUserService; | private WxMerchantBUserService wxMerchantBUserService; | ||||
| private Logger logger = Logger.getLogger(WxMerchantBUserController.class); | |||||
| @ApiOperation("分页列表接口") | |||||
| @GetMapping("list") | |||||
| @ApiImplicitParams({ | |||||
| @ApiImplicitParam(name="pageNum",value="页数",dataType="int", paramType = "query",required=true), | |||||
| @ApiImplicitParam(name="pageSize",value="每页条数",dataType="int", paramType = "query",required=true)}) | |||||
| public ResultData list(@ModelAttribute WxMerchantBUser wxMerchantBUser,Integer pageNum, Integer pageSize) { | |||||
| if (null == wxMerchantBUser) wxMerchantBUser = new WxMerchantBUser(); | |||||
| final PageInfo<WxMerchantBUser> page = wxMerchantBUserService.listAsPage(wxMerchantBUser, pageNum, pageSize); | |||||
| return new ResultData(page); | |||||
| } | |||||
| /** | |||||
| * 用户登录 | |||||
| * @param map | |||||
| * @return | |||||
| */ | |||||
| @AuthIgnore | |||||
| @PostMapping("/login") | |||||
| @ApiOperation(value="用户登录", notes="{\"appId\":\"string\",\"phone\":\"string\",\"password\":\"string\",\"scene\":\"string\",\"sceneAddress\":\"string\"}") | |||||
| public ResultData userLogin(@RequestBody Map<String, String> map) { | |||||
| logger.debug(map.toString()); | |||||
| @ApiOperation("新增接口") | |||||
| @PostMapping("add") | |||||
| public ResultData add(@RequestBody WxMerchantBUser wxMerchantBUser) { | |||||
| //Assert.notNull(wxMerchantBUser.getName(), "角色名不能为空"); | |||||
| //Assert.isTrue(!checkUnique(sysRole.getName(), null), "重复的角色名"); | |||||
| wxMerchantBUserService.saveOrUpdate(wxMerchantBUser); | |||||
| return new ResultData(); | |||||
| } | |||||
| Map resultMap = new HashMap(); | |||||
| @ApiOperation("根据id更新接口") | |||||
| @PostMapping("update") | |||||
| public ResultData update(@RequestBody WxMerchantBUser wxMerchantBUser) { | |||||
| wxMerchantBUserService.saveOrUpdate(wxMerchantBUser); | |||||
| return new ResultData(); | |||||
| } | |||||
| String appId = map.get("appId"); | |||||
| String phone = map.get("phone"); | |||||
| String password = map.get("password"); | |||||
| String scene = map.get("scene"); | |||||
| String sceneAddress = map.get("sceneAddress"); | |||||
| //登录凭证不能为空 | |||||
| if (StringUtils.isBlank(phone)) { | |||||
| return new ResultData(ErrorCode.PARAMETER_NOT_NULL.getCode(), "phone不能为空"); | |||||
| } | |||||
| if (StringUtils.isBlank(password)) { | |||||
| return new ResultData(ErrorCode.PARAMETER_NOT_NULL.getCode(), "password不能为空"); | |||||
| } | |||||
| @ApiOperation("根据id删除接口") | |||||
| @GetMapping("/del") | |||||
| @ApiImplicitParam(name="id",value="id",dataType="Long", paramType = "query",required=true) | |||||
| public ResultData delete(Long id) { | |||||
| wxMerchantBUserService.deleteById(id); | |||||
| return new ResultData(Result.SUCCESS, "删除成功", null); | |||||
| } | |||||
| @ApiOperation("根据id查询接口") | |||||
| @GetMapping("/findById") | |||||
| @ApiImplicitParam(name="id",value="id",dataType="Long", paramType = "query",required=true) | |||||
| public ResultData findById(Long id) { | |||||
| return new ResultData(Result.SUCCESS,"查询成功",wxMerchantBUserService.getById(id)); | |||||
| String token = null; | |||||
| String session_key = null; | |||||
| String openId = null; | |||||
| HttpServletRequest request = ((ServletRequestAttributes)RequestContextHolder.getRequestAttributes()).getRequest(); | |||||
| String ipaddress = IPUtil.getIpAddr(request); | |||||
| WxMerchantBUser user = new WxMerchantBUser(); | |||||
| user.setAppId(appId); | |||||
| user.setPhone(phone); | |||||
| user.setBUserPwd(password); | |||||
| try { | |||||
| WxMerchantBUser user1 = wxMerchantBUserService.getById(user.getId()); | |||||
| if (user1 != null) { | |||||
| user1.createToken(new Date()); | |||||
| token = user1.getToken(); | |||||
| wxMerchantBUserService.saveOrUpdate(user1); | |||||
| resultMap.put("token", token); | |||||
| } else { | |||||
| user.createToken(new Date()); | |||||
| token = user.getToken(); | |||||
| wxMerchantBUserService.saveOrUpdate(user); | |||||
| resultMap.put("token", token); | |||||
| } | |||||
| } catch (Exception e) { | |||||
| logger.error(e.getMessage()); | |||||
| return new ResultData(ErrorCode.DB_FAIL.getCode(), "wx_c_user数据库保存出错", resultMap); | |||||
| } | |||||
| return new ResultData(resultMap); | |||||
| } | } | ||||
| } | } | ||||
| @@ -4,8 +4,10 @@ package com.simple.interceptor; | |||||
| import com.simple.annotation.AuthIgnore; | import com.simple.annotation.AuthIgnore; | ||||
| import com.simple.common.ErrorCode; | import com.simple.common.ErrorCode; | ||||
| import com.simple.domain.po.WxCUser; | import com.simple.domain.po.WxCUser; | ||||
| import com.simple.domain.po.WxMerchantBUser; | |||||
| import com.simple.exception.MallinkException; | import com.simple.exception.MallinkException; | ||||
| import com.simple.service.WxCUserService; | import com.simple.service.WxCUserService; | ||||
| import com.simple.service.WxMerchantBUserService; | |||||
| import org.apache.commons.lang.StringUtils; | import org.apache.commons.lang.StringUtils; | ||||
| import org.springframework.beans.factory.annotation.Autowired; | import org.springframework.beans.factory.annotation.Autowired; | ||||
| import org.springframework.stereotype.Component; | import org.springframework.stereotype.Component; | ||||
| @@ -24,7 +26,7 @@ import javax.servlet.http.HttpServletResponse; | |||||
| @Component | @Component | ||||
| public class AuthorizationInterceptor extends HandlerInterceptorAdapter { | public class AuthorizationInterceptor extends HandlerInterceptorAdapter { | ||||
| @Autowired | @Autowired | ||||
| private WxCUserService wxCUserService; | |||||
| private WxMerchantBUserService wxMerchantBUserService; | |||||
| public static final String LOGIN_USER_KEY = "LOGIN_USER_KEY"; | public static final String LOGIN_USER_KEY = "LOGIN_USER_KEY"; | ||||
| @@ -56,13 +58,13 @@ public class AuthorizationInterceptor extends HandlerInterceptorAdapter { | |||||
| ///// TODO use b端用户表 | ///// TODO use b端用户表 | ||||
| // 查询token信息 | // 查询token信息 | ||||
| WxCUser wxCUser = wxCUserService.getByToken(token); | |||||
| if(wxCUser == null || wxCUser.getExpireTime().getTime() < System.currentTimeMillis()){ | |||||
| WxMerchantBUser wxMerchantBUser = wxMerchantBUserService.getByToken(token); | |||||
| if(wxMerchantBUser == null || wxMerchantBUser.getExpireTime().getTime() < System.currentTimeMillis()){ | |||||
| throw new MallinkException(ErrorCode.TOKEN_INVALID.getCode(), "URL:" + request.getRequestURL() + " token失效,请重新登录"); | throw new MallinkException(ErrorCode.TOKEN_INVALID.getCode(), "URL:" + request.getRequestURL() + " token失效,请重新登录"); | ||||
| } | } | ||||
| //设置userId到request里,后续根据userId,获取用户信息 | //设置userId到request里,后续根据userId,获取用户信息 | ||||
| request.setAttribute(LOGIN_USER_KEY, wxCUser.getId()); | |||||
| request.setAttribute(LOGIN_USER_KEY, wxMerchantBUser.getId()); | |||||
| return true; | return true; | ||||
| } | } | ||||
| @@ -2,8 +2,9 @@ package com.simple.resolver; | |||||
| import com.simple.annotation.LoginUser; | import com.simple.annotation.LoginUser; | ||||
| import com.simple.domain.po.WxCUser; | import com.simple.domain.po.WxCUser; | ||||
| import com.simple.domain.po.WxMerchantBUser; | |||||
| import com.simple.interceptor.AuthorizationInterceptor; | import com.simple.interceptor.AuthorizationInterceptor; | ||||
| import com.simple.service.WxCUserService; | |||||
| import com.simple.service.WxMerchantBUserService; | |||||
| import org.springframework.beans.factory.annotation.Autowired; | import org.springframework.beans.factory.annotation.Autowired; | ||||
| import org.springframework.core.MethodParameter; | import org.springframework.core.MethodParameter; | ||||
| import org.springframework.stereotype.Component; | import org.springframework.stereotype.Component; | ||||
| @@ -22,7 +23,7 @@ import org.springframework.web.method.support.ModelAndViewContainer; | |||||
| @Component | @Component | ||||
| public class LoginUserHandlerMethodArgumentResolver implements HandlerMethodArgumentResolver { | public class LoginUserHandlerMethodArgumentResolver implements HandlerMethodArgumentResolver { | ||||
| @Autowired | @Autowired | ||||
| private WxCUserService wxCUserService; | |||||
| private WxMerchantBUserService wxMerchantBUserService; | |||||
| @Override | @Override | ||||
| public boolean supportsParameter(MethodParameter parameter) { | public boolean supportsParameter(MethodParameter parameter) { | ||||
| @@ -39,7 +40,7 @@ public class LoginUserHandlerMethodArgumentResolver implements HandlerMethodArgu | |||||
| } | } | ||||
| //获取用户信息 | //获取用户信息 | ||||
| WxCUser user = wxCUserService.getByToken((String)object); | |||||
| WxMerchantBUser user = wxMerchantBUserService.getByToken((String)object); | |||||
| return user; | return user; | ||||
| } | } | ||||
| @@ -11,12 +11,14 @@ import java.io.Serializable; | |||||
| @Table(name = "wx_merchant_b_user") | @Table(name = "wx_merchant_b_user") | ||||
| public class WxMerchantBUser implements Serializable { | public class WxMerchantBUser implements Serializable { | ||||
| private static final long serialVersionUID = 1L; | private static final long serialVersionUID = 1L; | ||||
| //12小时后过期 | |||||
| private final static int EXPIRE = 3600 * 12; | |||||
| @Id | @Id | ||||
| protected Long id; | protected Long id; | ||||
| @Transient | @Transient | ||||
| protected List<String> ids; | |||||
| protected List<Long> ids; | |||||
| @Transient | @Transient | ||||
| protected String sortColumns; | protected String sortColumns; | ||||
| @@ -32,10 +34,11 @@ public class WxMerchantBUser implements Serializable { | |||||
| return sortColumns; | return sortColumns; | ||||
| } | } | ||||
| public List<String> getIds() { | |||||
| public List<Long> getIds() { | |||||
| return ids; | return ids; | ||||
| } | } | ||||
| public void setIds(List<String> ids) { | |||||
| public void setIds(List<Long> ids) { | |||||
| this.ids = ids; | this.ids = ids; | ||||
| } | } | ||||
| @@ -47,6 +50,9 @@ public class WxMerchantBUser implements Serializable { | |||||
| /*B端用户id**/ | /*B端用户id**/ | ||||
| @io.swagger.annotations.ApiModelProperty(value="B端用户id",name="bUserId") | @io.swagger.annotations.ApiModelProperty(value="B端用户id",name="bUserId") | ||||
| private Long bUserId; | private Long bUserId; | ||||
| /*B端用户手机号**/ | |||||
| @io.swagger.annotations.ApiModelProperty(value="B端用户手机号",name="phone") | |||||
| private String phone; | |||||
| /***/ | /***/ | ||||
| @io.swagger.annotations.ApiModelProperty(value="",name="bUserPwd") | @io.swagger.annotations.ApiModelProperty(value="",name="bUserPwd") | ||||
| private String bUserPwd; | private String bUserPwd; | ||||
| @@ -59,6 +65,15 @@ public class WxMerchantBUser implements Serializable { | |||||
| /*更新时间**/ | /*更新时间**/ | ||||
| @io.swagger.annotations.ApiModelProperty(value="更新时间",name="updateDate") | @io.swagger.annotations.ApiModelProperty(value="更新时间",name="updateDate") | ||||
| private Date updateDate; | private Date updateDate; | ||||
| /*小程序的appId**/ | |||||
| @io.swagger.annotations.ApiModelProperty(value="小程序的appId",name="appId") | |||||
| private String appId; | |||||
| /*用户登录用token**/ | |||||
| @io.swagger.annotations.ApiModelProperty(value="用户登录用token",name="token") | |||||
| private String token; | |||||
| /*用户过期时间**/ | |||||
| @io.swagger.annotations.ApiModelProperty(value="用户过期时间",name="expireTime") | |||||
| private Date expireTime; | |||||
| public String getTenantId() { | public String getTenantId() { | ||||
| return tenantId; | return tenantId; | ||||
| } | } | ||||
| @@ -71,6 +86,12 @@ public class WxMerchantBUser implements Serializable { | |||||
| public void setBUserId(Long _bUserId) { | public void setBUserId(Long _bUserId) { | ||||
| bUserId = _bUserId; | bUserId = _bUserId; | ||||
| } | } | ||||
| public String getPhone() { | |||||
| return phone; | |||||
| } | |||||
| public void setPhone(String _phone) { | |||||
| phone = _phone; | |||||
| } | |||||
| public String getBUserPwd() { | public String getBUserPwd() { | ||||
| return bUserPwd; | return bUserPwd; | ||||
| } | } | ||||
| @@ -95,6 +116,24 @@ public class WxMerchantBUser implements Serializable { | |||||
| public void setUpdateDate(Date _updateDate) { | public void setUpdateDate(Date _updateDate) { | ||||
| updateDate = _updateDate; | updateDate = _updateDate; | ||||
| } | } | ||||
| public String getAppId() { | |||||
| return appId; | |||||
| } | |||||
| public void setAppId(String _appId) { | |||||
| appId = _appId; | |||||
| } | |||||
| public String getToken() { | |||||
| return token; | |||||
| } | |||||
| public void setToken(String _token) { | |||||
| token = _token; | |||||
| } | |||||
| public Date getExpireTime() { | |||||
| return expireTime; | |||||
| } | |||||
| public void setExpireTime(Date _expireTime) { | |||||
| expireTime = _expireTime; | |||||
| } | |||||
| @@ -103,10 +142,14 @@ public class WxMerchantBUser implements Serializable { | |||||
| Id_ASC("`id` ASC"),Id_DESC("`id` DESC") | Id_ASC("`id` ASC"),Id_DESC("`id` DESC") | ||||
| ,TenantId_ASC("`tenantId` ASC"),TenantId_DESC("`tenantId` DESC") | ,TenantId_ASC("`tenantId` ASC"),TenantId_DESC("`tenantId` DESC") | ||||
| ,BUserId_ASC("`bUserId` ASC"),BUserId_DESC("`bUserId` DESC") | ,BUserId_ASC("`bUserId` ASC"),BUserId_DESC("`bUserId` DESC") | ||||
| ,Phone_ASC("`phone` ASC"),Phone_DESC("`phone` DESC") | |||||
| ,BUserPwd_ASC("`bUserPwd` ASC"),BUserPwd_DESC("`bUserPwd` DESC") | ,BUserPwd_ASC("`bUserPwd` ASC"),BUserPwd_DESC("`bUserPwd` DESC") | ||||
| ,MerchantId_ASC("`merchantId` ASC"),MerchantId_DESC("`merchantId` DESC") | ,MerchantId_ASC("`merchantId` ASC"),MerchantId_DESC("`merchantId` DESC") | ||||
| ,CreateDate_ASC("`createDate` ASC"),CreateDate_DESC("`createDate` DESC") | ,CreateDate_ASC("`createDate` ASC"),CreateDate_DESC("`createDate` DESC") | ||||
| ,UpdateDate_ASC("`updateDate` ASC"),UpdateDate_DESC("`updateDate` DESC") | ,UpdateDate_ASC("`updateDate` ASC"),UpdateDate_DESC("`updateDate` DESC") | ||||
| ,AppId_ASC("`appId` ASC"),AppId_DESC("`appId` DESC") | |||||
| ,Token_ASC("`token` ASC"),Token_DESC("`token` DESC") | |||||
| ,ExpireTime_ASC("`expireTime` ASC"),ExpireTime_DESC("`expireTime` DESC") | |||||
| ; | ; | ||||
| private String value; | private String value; | ||||
| Field(String value){ | Field(String value){ | ||||
| @@ -158,4 +201,16 @@ public class WxMerchantBUser implements Serializable { | |||||
| this.setSortColumns(Field.valueOf(sortColumns)); | this.setSortColumns(Field.valueOf(sortColumns)); | ||||
| } | } | ||||
| } | } | ||||
| public void createToken(Date currentDate) { | |||||
| if (expireTime == null || expireTime.getTime() < currentDate.getTime()) | |||||
| { | |||||
| //生成一个token | |||||
| String token = UUID.randomUUID().toString(); | |||||
| //过期时间 | |||||
| Date expireTime = new Date(currentDate.getTime() + EXPIRE * 1000); | |||||
| setToken(token); | |||||
| setExpireTime(expireTime); | |||||
| } | |||||
| } | |||||
| } | } | ||||
| @@ -5,12 +5,12 @@ import com.simple.common.CommonMapper; | |||||
| import org.apache.ibatis.annotations.Param; | import org.apache.ibatis.annotations.Param; | ||||
| import com.simple.domain.po.WxMerchantBUser; | import com.simple.domain.po.WxMerchantBUser; | ||||
| public interface WxMerchantBUserMapper extends CommonMapper<WxMerchantBUser, String> { | |||||
| public interface WxMerchantBUserMapper extends CommonMapper<WxMerchantBUser, Long> { | |||||
| List<WxMerchantBUser> findList(WxMerchantBUser wxMerchantBUser); | List<WxMerchantBUser> findList(WxMerchantBUser wxMerchantBUser); | ||||
| WxMerchantBUser findByToken(String token); | |||||
| @@ -10,8 +10,8 @@ public interface WxMerchantBUserService { | |||||
| * 根据实体查询分页列表 | * 根据实体查询分页列表 | ||||
| * | * | ||||
| * @param record | * @param record | ||||
| * @param offset | |||||
| * @param limit | |||||
| * @param pageIndex | |||||
| * @param pageSize | |||||
| * @return | * @return | ||||
| */ | */ | ||||
| PageInfo<WxMerchantBUser> listAsPage(WxMerchantBUser record, Integer pageIndex, Integer pageSize); | PageInfo<WxMerchantBUser> listAsPage(WxMerchantBUser record, Integer pageIndex, Integer pageSize); | ||||
| @@ -23,6 +23,14 @@ public interface WxMerchantBUserService { | |||||
| * @return | * @return | ||||
| */ | */ | ||||
| WxMerchantBUser getById(Long id); | WxMerchantBUser getById(Long id); | ||||
| /** | |||||
| * 根据token获得实体 | |||||
| * | |||||
| * @param token | |||||
| * @return | |||||
| */ | |||||
| WxMerchantBUser getByToken(String token); | |||||
| /** | /** | ||||
| * 保存或更新实体 | * 保存或更新实体 | ||||
| @@ -27,6 +27,11 @@ public class WxMerchantBUserServiceImpl implements WxMerchantBUserService { | |||||
| return wxMerchantBUserMapper.selectByPrimaryKey(id); | return wxMerchantBUserMapper.selectByPrimaryKey(id); | ||||
| } | } | ||||
| @Override | |||||
| public WxMerchantBUser getByToken(String token) { | |||||
| return wxMerchantBUserMapper.findByToken(token); | |||||
| } | |||||
| @Override | @Override | ||||
| public void saveOrUpdate(WxMerchantBUser record) { | public void saveOrUpdate(WxMerchantBUser record) { | ||||
| if (record.getId() == null) { | if (record.getId() == null) { | ||||
| @@ -5,14 +5,18 @@ | |||||
| <id column="id" jdbcType="BIGINT" property="id" /> | <id column="id" jdbcType="BIGINT" property="id" /> | ||||
| <result column="tenant_id" jdbcType="VARCHAR" property="tenantId" /> | <result column="tenant_id" jdbcType="VARCHAR" property="tenantId" /> | ||||
| <result column="b_user_id" jdbcType="BIGINT" property="bUserId" /> | <result column="b_user_id" jdbcType="BIGINT" property="bUserId" /> | ||||
| <result column="phone" jdbcType="VARCHAR" property="phone" /> | |||||
| <result column="b_user_pwd" jdbcType="VARCHAR" property="bUserPwd" /> | <result column="b_user_pwd" jdbcType="VARCHAR" property="bUserPwd" /> | ||||
| <result column="merchant_id" jdbcType="BIGINT" property="merchantId" /> | <result column="merchant_id" jdbcType="BIGINT" property="merchantId" /> | ||||
| <result column="create_date" jdbcType="TIMESTAMP" property="createDate" /> | <result column="create_date" jdbcType="TIMESTAMP" property="createDate" /> | ||||
| <result column="update_date" jdbcType="TIMESTAMP" property="updateDate" /> | <result column="update_date" jdbcType="TIMESTAMP" property="updateDate" /> | ||||
| <result column="app_id" jdbcType="VARCHAR" property="appId" /> | |||||
| <result column="token" jdbcType="VARCHAR" property="token" /> | |||||
| <result column="expire_time" jdbcType="TIMESTAMP" property="expireTime" /> | |||||
| </resultMap> | </resultMap> | ||||
| <sql id="allColumns"> | <sql id="allColumns"> | ||||
| `id`,`tenant_id`,`b_user_id`,`b_user_pwd`,`merchant_id`,`create_date`,`update_date` | |||||
| `id`,`tenant_id`,`b_user_id`,`phone`,`b_user_pwd`,`merchant_id`,`create_date`,`update_date`,`app_id`,`token`,`expire_time` | |||||
| </sql> | </sql> | ||||
| <sql id="dynamicWhereConditions"> | <sql id="dynamicWhereConditions"> | ||||
| @@ -33,6 +37,11 @@ | |||||
| </if> | </if> | ||||
| <if test=" null != phone "> | |||||
| and `phone` like concat('%', #{phone},'%') | |||||
| </if> | |||||
| <if test=" null != bUserPwd "> | <if test=" null != bUserPwd "> | ||||
| and `b_user_pwd` like concat('%', #{bUserPwd},'%') | and `b_user_pwd` like concat('%', #{bUserPwd},'%') | ||||
| @@ -51,6 +60,21 @@ | |||||
| <if test=" null != updateDate "> | <if test=" null != updateDate "> | ||||
| and `update_date` = #{updateDate} | and `update_date` = #{updateDate} | ||||
| </if> | |||||
| <if test=" null != appId "> | |||||
| and `app_id` like concat('%', #{appId},'%') | |||||
| </if> | |||||
| <if test=" null != token "> | |||||
| and `token` like concat('%', #{token},'%') | |||||
| </if> | |||||
| <if test=" null != expireTime "> | |||||
| and `expire_time` = #{expireTime} | |||||
| </if> | </if> | ||||
| <if test=" null != ids "> | <if test=" null != ids "> | ||||
| and id in | and id in | ||||
| @@ -65,8 +89,11 @@ | |||||
| select <include refid="allColumns" /> from wx_merchant_b_user | select <include refid="allColumns" /> from wx_merchant_b_user | ||||
| <include refid="dynamicWhereConditions" /> | <include refid="dynamicWhereConditions" /> | ||||
| </select> | </select> | ||||
| <select id="findByToken" resultMap="BaseResultMap"> | |||||
| select * from wx_merchant_b_user | |||||
| where `token` = #{token} | |||||
| </select> | |||||