| @@ -117,6 +117,8 @@ public class ShiroConfig { | |||
| filterChainDefinitionMap.put("/swagger-resources/**","anon"); | |||
| filterChainDefinitionMap.put("/webjars/**","anon"); | |||
| filterChainDefinitionMap.put("/wxMsgCallback/**","anon"); | |||
| filterChainDefinitionMap.put("/user/sendvalidationcode","anon"); | |||
| filterChainDefinitionMap.put("/user/updatepwd","anon"); | |||
| filterChainDefinitionMap.put("/carCallback/**","anon"); | |||
| filterChainDefinitionMap.put("/wxMallApply/add","anon"); | |||
| filterChainDefinitionMap.put("/wxMallApply/sendvalidationcode","anon"); | |||
| @@ -2,13 +2,18 @@ package com.iformall.controller; | |||
| import com.github.pagehelper.PageInfo; | |||
| import com.iformall.common.ErrorCode; | |||
| import com.iformall.common.Result; | |||
| import com.iformall.common.ResultData; | |||
| import com.iformall.domain.po.*; | |||
| import com.iformall.enums.EnumMallUserStatus; | |||
| import com.iformall.service.*; | |||
| import com.iformall.shiro.PasswordHelper; | |||
| import com.iformall.shiro.UserSession; | |||
| import io.swagger.annotations.Api; | |||
| import io.swagger.annotations.ApiImplicitParam; | |||
| import io.swagger.annotations.ApiImplicitParams; | |||
| import io.swagger.annotations.ApiOperation; | |||
| import org.apache.commons.lang3.StringUtils; | |||
| import org.apache.shiro.SecurityUtils; | |||
| import org.slf4j.Logger; | |||
| import org.slf4j.LoggerFactory; | |||
| @@ -48,6 +53,9 @@ public class MallUserInfoController extends BaseController { | |||
| @Autowired | |||
| MallRolePermissionService mallRolePermissionService; | |||
| @Autowired | |||
| WxMsgValidationcodeService wxMsgValidationcodeService; | |||
| @ApiOperation(value = "用户分页接口", response = String.class) | |||
| @GetMapping("lists") | |||
| public ResultData listAsPage(MallUserInfo userInfo, Integer pageNum, Integer pageSize) { | |||
| @@ -211,7 +219,6 @@ public class MallUserInfoController extends BaseController { | |||
| } | |||
| info.setMenus(menus); | |||
| } else { | |||
| // System.out.println("id:"+ SecurityUtils.getSubject().getSession().getId()); | |||
| MallUserRole ur = new MallUserRole(); | |||
| ur.setUid(info.getId()); | |||
| PageInfo<MallUserRole> page = mallUserRoleService.listAsPage(ur, 1, 1); | |||
| @@ -233,4 +240,75 @@ public class MallUserInfoController extends BaseController { | |||
| } | |||
| return new ResultData(info); | |||
| } | |||
| @GetMapping("sendvalidationcode") | |||
| @ApiImplicitParams({ | |||
| @ApiImplicitParam(name = "userName", value = "手机号", dataType = "String", paramType = "query", required = true), | |||
| @ApiImplicitParam(name = "type", value = "场景(1:登录)", dataType = "Integer", paramType = "query", required = true)}) | |||
| public ResultData sendvalidationcode(String userName, Integer type) { | |||
| MallUserInfo userQ = new MallUserInfo(); | |||
| userQ.setUsername(userName); | |||
| MallUserInfo user = userInfoService.getByUsername(userName); | |||
| if (user==null) { | |||
| logger.error("用户不存在, userName: " + userName); | |||
| return new ResultData(ErrorCode.USER_IS_EMPTY); | |||
| } | |||
| if(user.getStatus() == EnumMallUserStatus.NOT_VALID.getCode()){ | |||
| logger.error("用户已停用, userName: " + userName); | |||
| return new ResultData(ErrorCode.USER_IS_LOCKED); | |||
| } | |||
| if (StringUtils.isBlank(user.getPhone())) { | |||
| logger.error("用户手机号为空, userName: " + userName); | |||
| return new ResultData(ErrorCode.USER_PHONE_IS_NOT_FOUND); | |||
| } | |||
| WxMsgValidationcode wxMsgValidationcode = new WxMsgValidationcode(); | |||
| wxMsgValidationcode.setTenantId(user.getTenantId()); | |||
| wxMsgValidationcode.setPhone(user.getPhone()); | |||
| wxMsgValidationcode.setType(type); | |||
| return wxMsgValidationcodeService.sendvalidationcode(wxMsgValidationcode); | |||
| } | |||
| @ApiOperation(value = "修改密码", notes = "{\"userName\",\"string\",\"code\",\"string\",\"pwd\",\"string\"}") | |||
| @PostMapping("/updatepwd") | |||
| public ResultData updatepwd(@RequestBody Map<String, String> params) { | |||
| // String phone,String code,String pwd | |||
| String userName = params.get("userName"); | |||
| String code = params.get("code"); | |||
| String pwd = params.get("pwd"); | |||
| if (StringUtils.isBlank(userName)) { | |||
| return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), "userName不能为空"); | |||
| } | |||
| if (StringUtils.isBlank(code)) { | |||
| return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), "验证码不能为空"); | |||
| } | |||
| if (StringUtils.isBlank(pwd)) { | |||
| return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), "密码不能为空"); | |||
| } | |||
| MallUserInfo userQ = new MallUserInfo(); | |||
| userQ.setUsername(userName); | |||
| MallUserInfo user = userInfoService.getByUsername(userName); | |||
| if (user==null) { | |||
| logger.error("用户不存在, userName: " + userName); | |||
| return new ResultData(ErrorCode.USER_IS_EMPTY); | |||
| } | |||
| user.setPassword(pwd); | |||
| PasswordHelper passwordHelper = new PasswordHelper(); | |||
| passwordHelper.encryptPassword(user); | |||
| try { | |||
| return userInfoService.updatepwd(user, code); | |||
| } catch (Exception e) { | |||
| return new ResultData(Result.ERROR, e.getMessage()); | |||
| } | |||
| } | |||
| } | |||
| @@ -48,6 +48,7 @@ public enum ErrorCode{ | |||
| /** | |||
| * 用户2000-2099 | |||
| */ | |||
| USER_PHONE_IS_NOT_FOUND(1990,"手机号不存在"), | |||
| USER_IS_EMPTY(2000, "用户不存在"), | |||
| PASSWORD_ERROR(2001, "密码错误"), | |||
| LOGIN_USER_OR_PWD_ERROR(2002, "用户名或密码错误"), | |||
| @@ -59,6 +60,7 @@ public enum ErrorCode{ | |||
| USER_NAME_IS_FOUND(2008,"用户名已存在"), | |||
| USER_PHONE_IS_FOUND(2009,"手机号已存在"), | |||
| /** | |||
| * 商场/商户 | |||
| */ | |||
| @@ -0,0 +1,36 @@ | |||
| package com.iformall.enums; | |||
| /** | |||
| * Created by Stormeye on 2018/08/09. | |||
| */ | |||
| public enum EnumMallUserStatus { | |||
| VALID(1, "有效"), | |||
| NOT_VALID(0, "无效") | |||
| ; | |||
| public static EnumMallUserStatus getEnum(Integer code) { | |||
| for (EnumMallUserStatus value : values()) { | |||
| if (value.getCode().equals(code)) { | |||
| return value; | |||
| } | |||
| } | |||
| return null; | |||
| } | |||
| private Integer code; | |||
| private String message; | |||
| EnumMallUserStatus(Integer code, String message) { | |||
| this.code = code; | |||
| this.message = message; | |||
| } | |||
| public Integer getCode() { | |||
| return code; | |||
| } | |||
| public String getMessage() { | |||
| return message; | |||
| } | |||
| } | |||
| @@ -1,6 +1,7 @@ | |||
| package com.iformall.service; | |||
| import com.github.pagehelper.PageInfo; | |||
| import com.iformall.common.ResultData; | |||
| import com.iformall.domain.po.MallUserInfo; | |||
| public interface MallUserInfoService { | |||
| @@ -73,4 +74,6 @@ public interface MallUserInfoService { | |||
| boolean cntByUserPhone(String phone, Long id); | |||
| ResultData updatepwd(MallUserInfo user, String code); | |||
| } | |||
| @@ -2,27 +2,43 @@ package com.iformall.service.impl; | |||
| import com.github.pagehelper.PageHelper; | |||
| import com.github.pagehelper.PageInfo; | |||
| import com.iformall.common.ErrorCode; | |||
| import com.iformall.common.IdWorker; | |||
| import com.iformall.common.Result; | |||
| import com.iformall.common.ResultData; | |||
| import com.iformall.domain.po.MallUserInfo; | |||
| import com.iformall.domain.po.MallUserRole; | |||
| import com.iformall.domain.po.WxMsgValidationcode; | |||
| import com.iformall.exception.MallinkException; | |||
| import com.iformall.mapper.MallUserInfoMapper; | |||
| import com.iformall.mapper.MallUserRoleMapper; | |||
| import com.iformall.mapper.WxMsgValidationcodeMapper; | |||
| import com.iformall.service.MallUserInfoService; | |||
| import org.slf4j.Logger; | |||
| import org.slf4j.LoggerFactory; | |||
| import org.springframework.beans.factory.annotation.Autowired; | |||
| import org.springframework.stereotype.Service; | |||
| import org.springframework.transaction.annotation.Transactional; | |||
| import java.util.Date; | |||
| import java.util.HashMap; | |||
| import java.util.List; | |||
| import java.util.Map; | |||
| import java.util.stream.Collectors; | |||
| @Service | |||
| public class MallUserInfoServiceImpl implements MallUserInfoService { | |||
| @Autowired | |||
| private final Logger logger = LoggerFactory.getLogger(this.getClass()); | |||
| @Autowired | |||
| MallUserInfoMapper mallUserInfoMapper; | |||
| @Autowired | |||
| @Autowired | |||
| MallUserRoleMapper userRoleMapper; | |||
| @Autowired | |||
| WxMsgValidationcodeMapper wxMsgValidationcodeMapper; | |||
| @Override | |||
| public PageInfo<MallUserInfo> listAsPage(MallUserInfo record, Integer pageIndex, Integer pageSize) { | |||
| @@ -39,7 +55,7 @@ public class MallUserInfoServiceImpl implements MallUserInfoService { | |||
| if (record.getId() == null) { | |||
| //record.setId(UUID.randomUUID().toString().replaceAll("-", "")); | |||
| final IdWorker idWorker = IdWorker.get(); | |||
| record.setId(idWorker.nextId()); | |||
| record.setId(idWorker.nextId()); | |||
| mallUserInfoMapper.insertSelective(record); | |||
| } else { | |||
| mallUserInfoMapper.updateByPrimaryKeySelective(record); | |||
| @@ -50,18 +66,14 @@ public class MallUserInfoServiceImpl implements MallUserInfoService { | |||
| public void deleteById(Long id) { | |||
| mallUserInfoMapper.deleteByPrimaryKey(id); | |||
| } | |||
| @Override | |||
| public MallUserInfo getByUsername(String username) { | |||
| MallUserInfo userInfo = new MallUserInfo(); | |||
| userInfo.setUsername(username); | |||
| return mallUserInfoMapper.selectOne(userInfo); | |||
| } | |||
| @Override | |||
| public long cntByUserName(String username) { | |||
| MallUserInfo userInfo = new MallUserInfo(); | |||
| @@ -85,18 +97,41 @@ public class MallUserInfoServiceImpl implements MallUserInfoService { | |||
| @Override | |||
| public boolean cntByUserName(String username, Long id) { | |||
| Map<String,Object> params=new HashMap<>(); | |||
| params.put("username",username); | |||
| params.put("id",id); | |||
| return mallUserInfoMapper.cntByUserName(params)>0?true:false; | |||
| Map<String, Object> params = new HashMap<>(); | |||
| params.put("username", username); | |||
| params.put("id", id); | |||
| return mallUserInfoMapper.cntByUserName(params) > 0 ? true : false; | |||
| } | |||
| @Override | |||
| public boolean cntByUserPhone(String phone, Long id) { | |||
| Map<String,Object> params=new HashMap<>(); | |||
| params.put("phone",phone); | |||
| params.put("id",id); | |||
| return mallUserInfoMapper.cntByUserName(params)>0?true:false; | |||
| Map<String, Object> params = new HashMap<>(); | |||
| params.put("phone", phone); | |||
| params.put("id", id); | |||
| return mallUserInfoMapper.cntByUserName(params) > 0 ? true : false; | |||
| } | |||
| @Override | |||
| public ResultData updatepwd(MallUserInfo user, String code) { | |||
| WxMsgValidationcode wxMsgValidationcode = new WxMsgValidationcode(); | |||
| wxMsgValidationcode.setTenantId(user.getTenantId()); | |||
| wxMsgValidationcode.setPhone(user.getPhone()); | |||
| wxMsgValidationcode.setCode(code); | |||
| List<WxMsgValidationcode> wxmsgvalidationcodelist = wxMsgValidationcodeMapper.findList(wxMsgValidationcode); | |||
| Date currentdate = new Date(); | |||
| wxmsgvalidationcodelist = wxmsgvalidationcodelist.stream().filter(validationcode -> | |||
| validationcode.getExpiretime().after(currentdate)).collect(Collectors.toList()); | |||
| if (wxmsgvalidationcodelist.size() > 0) { | |||
| try { | |||
| mallUserInfoMapper.updateByPrimaryKey(user); | |||
| } catch (Exception e) { | |||
| logger.error("db failed: 用户-" + user.getUsername() + ", e:" + e.getMessage()); | |||
| throw new MallinkException(ErrorCode.DB_FAIL.getCode(), "DB FAILD " + e.getMessage()); | |||
| } | |||
| } else { | |||
| return new ResultData(Result.ERROR,"验证码不存在或过期",false); | |||
| } | |||
| return new ResultData(); | |||
| } | |||
| } | |||
| @@ -99,6 +99,7 @@ public class WxMerchantBUserServiceImpl implements WxMerchantBUserService { | |||
| public ResultData updatepwd(String appId, String phone, String code, String pwd) { | |||
| WxAppinfo appinfo = wxAppinfoMapper.findByAppId(appId); | |||
| WxMsgValidationcode wxMsgValidationcode = new WxMsgValidationcode(); | |||
| wxMsgValidationcode.setTenantId(appinfo.getTenantId()); | |||
| wxMsgValidationcode.setPhone(phone); | |||
| wxMsgValidationcode.setCode(code); | |||
| List<WxMsgValidationcode> wxmsgvalidationcodelist = wxMsgValidationcodeMapper.findList(wxMsgValidationcode); | |||