'完成微信登录、商户和门店配置'

dev-discount
199901012 4 years ago
parent 9cfe5e88d7
commit f60193a9b9
  1. 36
      hai-bweb/src/main/java/com/bweb/controller/HighMerchantController.java
  2. 51
      hai-bweb/src/main/java/com/bweb/controller/HighMerchantStoreController.java
  3. 43
      hai-bweb/src/main/java/com/bweb/controller/LoginController.java
  4. 3
      hai-bweb/src/main/resources/dev/config.properties
  5. 3
      hai-bweb/src/main/resources/prod/config.properties
  6. 53
      hai-cweb/src/main/java/com/cweb/config/SessionKeyCache.java
  7. 19
      hai-cweb/src/main/java/com/cweb/config/SysConfig.java
  8. 33
      hai-cweb/src/main/java/com/cweb/config/WxMaConfiguration.java
  9. 143
      hai-cweb/src/main/java/com/cweb/controller/LoginController.java
  10. 218
      hai-cweb/src/main/java/com/cweb/controller/WechatController.java
  11. 4
      hai-cweb/src/main/resources/dev/application.yml
  12. 2
      hai-cweb/src/main/resources/prod/application.yml
  13. 6
      hai-cweb/src/main/resources/prod/config.properties
  14. 5
      hai-service/pom.xml
  15. 4
      hai-service/src/main/java/com/hai/common/exception/ErrorCode.java
  16. 20
      hai-service/src/main/java/com/hai/common/security/UserCenter.java
  17. 8
      hai-service/src/main/java/com/hai/dao/HighUserMapper.java
  18. 8
      hai-service/src/main/java/com/hai/dao/HighUserSqlProvider.java
  19. 4
      hai-service/src/main/java/com/hai/entity/HighMerchant.java
  20. 4
      hai-service/src/main/java/com/hai/entity/HighMerchantStore.java
  21. 6
      hai-service/src/main/java/com/hai/entity/HighUser.java
  22. 30
      hai-service/src/main/java/com/hai/entity/HighUserExample.java
  23. 21
      hai-service/src/main/java/com/hai/model/HighMerchantModel.java
  24. 22
      hai-service/src/main/java/com/hai/model/HighMerchantStoreModel.java
  25. 22
      hai-service/src/main/java/com/hai/model/HighUserModel.java
  26. 27
      hai-service/src/main/java/com/hai/model/UserInfoModel.java
  27. 2
      hai-service/src/main/java/com/hai/service/HighMerchantService.java
  28. 9
      hai-service/src/main/java/com/hai/service/HighMerchantStoreService.java
  29. 15
      hai-service/src/main/java/com/hai/service/HighUserService.java
  30. 7
      hai-service/src/main/java/com/hai/service/SecUserService.java
  31. 23
      hai-service/src/main/java/com/hai/service/impl/HighMerchantServiceImpl.java
  32. 44
      hai-service/src/main/java/com/hai/service/impl/HighMerchantStoreServiceImpl.java
  33. 25
      hai-service/src/main/java/com/hai/service/impl/HighUserServiceImpl.java
  34. 7
      hai-service/src/main/java/com/hai/service/impl/SecUserServiceImpl.java

@ -10,12 +10,14 @@ import com.hai.common.security.AESEncodeUtil;
import com.hai.common.security.SessionObject; import com.hai.common.security.SessionObject;
import com.hai.common.security.UserCenter; import com.hai.common.security.UserCenter;
import com.hai.common.utils.MD5Util; import com.hai.common.utils.MD5Util;
import com.hai.common.utils.MemberValidateUtil;
import com.hai.common.utils.ResponseMsgUtil; import com.hai.common.utils.ResponseMsgUtil;
import com.hai.entity.*; import com.hai.entity.*;
import com.hai.model.MenuTreeModel; import com.hai.model.MenuTreeModel;
import com.hai.model.ResponseData; import com.hai.model.ResponseData;
import com.hai.model.UserInfoModel; import com.hai.model.UserInfoModel;
import com.hai.service.HighMerchantService; import com.hai.service.HighMerchantService;
import com.hai.service.SecUserService;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
@ -51,6 +53,9 @@ public class HighMerchantController {
@Resource @Resource
private HighMerchantService highMerchantService; private HighMerchantService highMerchantService;
@Resource
private SecUserService secUserService;
@RequestMapping(value="/editMerchant",method = RequestMethod.POST) @RequestMapping(value="/editMerchant",method = RequestMethod.POST)
@ResponseBody @ResponseBody
@ApiOperation(value = "编辑商户") @ApiOperation(value = "编辑商户")
@ -68,18 +73,37 @@ public class HighMerchantController {
throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR, ""); throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR, "");
} }
if (highMerchant.getId() != null) { // id为空 就是增加商户,需要校验账号是否填写
if (highMerchantService.getMerchantById(highMerchant.getId()) == null) { if (highMerchant.getId() == null) {
log.error("HighMerchantController -> editMerchant() error!","未找到商户"); if (StringUtils.isBlank(highMerchant.getSecUser().getPassword()) || StringUtils.isBlank(highMerchant.getSecUser().getTelephone())) {
throw ErrorHelp.genException(SysCode.System, ErrorCode.MERCHANT_NOF_FOUND, ""); log.error("HighMerchantController -> editMerchant() error!","参数错误");
throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR, "");
}
// 校验账户手机号
if (!MemberValidateUtil.validatePhone(highMerchant.getSecUser().getTelephone())) {
log.error("BsStudentController --> addStudent() error!", "请输入正确的电话号码");
throw ErrorHelp.genException(SysCode.System, ErrorCode.PHONE_NUM_IS_ERROR, "");
}
// 校验账号手机号是否存在
if (secUserService.findByPhone(highMerchant.getSecUser().getTelephone()) != null) {
log.error("BsStudentController --> addStudent() error!", "电话号码已被使用");
throw ErrorHelp.genException(SysCode.System, ErrorCode.PHONE_NUM_EXISTED, "");
} }
highMerchant.setStatus(1); // 状态:0:不可用,1:可用
highMerchant.setCreateTime(new Date());
highMerchant.setUpdateTime(new Date()); highMerchant.setUpdateTime(new Date());
} else { } else {
highMerchant.setCreateTime(new Date()); if (highMerchantService.getMerchantById(highMerchant.getId()) == null) {
log.error("HighMerchantController -> editMerchant() error!","未找到商户");
throw ErrorHelp.genException(SysCode.System, ErrorCode.MERCHANT_NOF_FOUND, "");
}
highMerchant.setUpdateTime(new Date()); highMerchant.setUpdateTime(new Date());
} }
highMerchant.setStatus(1); // 状态:0:不可用,1:可用
highMerchant.setOperatorId(userInfoModel.getSecUser().getId()); highMerchant.setOperatorId(userInfoModel.getSecUser().getId());
highMerchant.setOperatorName(userInfoModel.getSecUser().getUserName()); highMerchant.setOperatorName(userInfoModel.getSecUser().getUserName());
highMerchantService.editMerchant(highMerchant); highMerchantService.editMerchant(highMerchant);

@ -7,6 +7,7 @@ import com.hai.common.exception.ErrorHelp;
import com.hai.common.exception.SysCode; import com.hai.common.exception.SysCode;
import com.hai.common.security.SessionObject; import com.hai.common.security.SessionObject;
import com.hai.common.security.UserCenter; import com.hai.common.security.UserCenter;
import com.hai.common.utils.MemberValidateUtil;
import com.hai.common.utils.ResponseMsgUtil; import com.hai.common.utils.ResponseMsgUtil;
import com.hai.entity.HighMerchant; import com.hai.entity.HighMerchant;
import com.hai.entity.HighMerchantStore; import com.hai.entity.HighMerchantStore;
@ -14,6 +15,7 @@ import com.hai.model.ResponseData;
import com.hai.model.UserInfoModel; import com.hai.model.UserInfoModel;
import com.hai.service.HighMerchantService; import com.hai.service.HighMerchantService;
import com.hai.service.HighMerchantStoreService; import com.hai.service.HighMerchantStoreService;
import com.hai.service.SecUserService;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
@ -50,6 +52,9 @@ public class HighMerchantStoreController {
@Resource @Resource
private HighMerchantService highMerchantService; private HighMerchantService highMerchantService;
@Resource
private SecUserService secUserService;
@RequestMapping(value="/editHighMerchantStore",method = RequestMethod.POST) @RequestMapping(value="/editHighMerchantStore",method = RequestMethod.POST)
@ResponseBody @ResponseBody
@ApiOperation(value = "编辑商户门店") @ApiOperation(value = "编辑商户门店")
@ -67,21 +72,43 @@ public class HighMerchantStoreController {
log.error("HighMerchantStoreController -> editMerchantStore() error!","参数错误"); log.error("HighMerchantStoreController -> editMerchantStore() error!","参数错误");
throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR, ""); throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR, "");
} }
// 商户
HighMerchant merchant = highMerchantService.getMerchantById(highMerchantStore.getMerchantId());
if (merchant != null) {
log.error("HighMerchantStoreController -> editMerchantStore() error!","未找到商户"); // id为空 就是增加门店,需要校验账号是否填写
throw ErrorHelp.genException(SysCode.System, ErrorCode.MERCHANT_NOF_FOUND, ""); if (highMerchantStore.getId() == null) {
} if (StringUtils.isBlank(highMerchantStore.getSecUser().getPassword()) || StringUtils.isBlank(highMerchantStore.getSecUser().getTelephone())) {
if (highMerchantStore.getId() != null) { log.error("HighMerchantController -> editMerchant() error!","参数错误");
throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR, "");
}
// 校验账户手机号
if (!MemberValidateUtil.validatePhone(highMerchantStore.getSecUser().getTelephone())) {
log.error("BsStudentController --> addStudent() error!", "请输入正确的电话号码");
throw ErrorHelp.genException(SysCode.System, ErrorCode.PHONE_NUM_IS_ERROR, "");
}
// 校验账号手机号是否存在
if (secUserService.findByPhone(highMerchantStore.getSecUser().getTelephone()) != null) {
log.error("BsStudentController --> addStudent() error!", "电话号码已被使用");
throw ErrorHelp.genException(SysCode.System, ErrorCode.PHONE_NUM_EXISTED, "");
}
// 校验商户
HighMerchant merchant = highMerchantService.getMerchantById(highMerchantStore.getMerchantId());
if (merchant != null) {
log.error("HighMerchantStoreController -> editMerchantStore() error!","未找到商户");
throw ErrorHelp.genException(SysCode.System, ErrorCode.MERCHANT_NOF_FOUND, "");
}
highMerchantStore.setCompanyId(merchant.getCompanyId());
highMerchantStore.setCreateTime(new Date());
highMerchantStore.setUpdateTime(new Date()); highMerchantStore.setUpdateTime(new Date());
highMerchantStore.setStatus(1); // 状态:0:删除,1:正常
} else { } else {
highMerchantStore.setCreateTime(new Date());
highMerchantStore.setUpdateTime(new Date()); highMerchantStore.setUpdateTime(new Date());
} }
highMerchantStore.setCompanyId(merchant.getCompanyId());
highMerchantStore.setStatus(1); // 状态:0:删除,1:正常
highMerchantStore.setOperatorId(userInfoModel.getSecUser().getId()); highMerchantStore.setOperatorId(userInfoModel.getSecUser().getId());
highMerchantStore.setOperatorName(userInfoModel.getSecUser().getUserName()); highMerchantStore.setOperatorName(userInfoModel.getSecUser().getUserName());
highMerchantStoreService.editMerchantStore(highMerchantStore); highMerchantStoreService.editMerchantStore(highMerchantStore);
@ -104,9 +131,7 @@ public class HighMerchantStoreController {
log.error("HighMerchantStoreController -> deleteMerchantStore() error!","未找到商户门店"); log.error("HighMerchantStoreController -> deleteMerchantStore() error!","未找到商户门店");
throw ErrorHelp.genException(SysCode.System, ErrorCode.MERCHANT_STORE_NOF_FOUND, ""); throw ErrorHelp.genException(SysCode.System, ErrorCode.MERCHANT_STORE_NOF_FOUND, "");
} }
merchantStore.setStatus(0); highMerchantStoreService.deleteMerchantStore(id);
merchantStore.setUpdateTime(new Date());
highMerchantStoreService.editMerchantStore(merchantStore);
return ResponseMsgUtil.success("操作成功"); return ResponseMsgUtil.success("操作成功");

@ -48,6 +48,12 @@ public class LoginController {
@Resource @Resource
private BsCompanyService bsCompanyService; private BsCompanyService bsCompanyService;
@Resource
private HighMerchantService highMerchantService;
@Resource
private HighMerchantStoreService highMerchantStoreService;
@Resource @Resource
private BsOrganizationService bsOrganizationService; private BsOrganizationService bsOrganizationService;
@ -74,7 +80,7 @@ public class LoginController {
throw ErrorHelp.genException(SysCode.System, ErrorCode.PASSWORD_ERROR, ""); throw ErrorHelp.genException(SysCode.System, ErrorCode.PASSWORD_ERROR, "");
} }
UserInfoModel userInfoModel = new UserInfoModel(); UserInfoModel userInfoModel = new UserInfoModel();
secUser.setPassword(""); secUser.setPassword(null);
userInfoModel.setSecUser(secUser); //用户信息 userInfoModel.setSecUser(secUser); //用户信息
//查询用户角色 //查询用户角色
@ -98,7 +104,7 @@ public class LoginController {
userInfoModel.setButtonList(buttonList); userInfoModel.setButtonList(buttonList);
userInfoModel.setPermissionList(permissionList); userInfoModel.setPermissionList(permissionList);
// 根据用户来源返回登录数据 0:超级管理员 1:运营中心成员 // 根据用户来源返回登录数据 0:超级管理员 1:公司 2:商户 3:门店
if (secUser.getObjectType() == 0 || secUser.getObjectType() == 1) { if (secUser.getObjectType() == 0 || secUser.getObjectType() == 1) {
// 公司员工(超级管理员和单位员工) // 公司员工(超级管理员和单位员工)
//查询公司 //查询公司
@ -121,13 +127,42 @@ public class LoginController {
userInfoModel.setBsCompany(bsCompany); //公司信息 userInfoModel.setBsCompany(bsCompany); //公司信息
}else { } else if (secUser.getObjectType() == 2) {
// 查询商户
HighMerchant merchant = highMerchantService.getMerchantById(secUser.getObjectId());
if(merchant == null){
log.error("login error!","未找到商户");
throw ErrorHelp.genException(SysCode.System, ErrorCode.MERCHANT_NOF_FOUND, "");
}
if(merchant.getStatus() != 1) {
log.error("login error!","商户状态不正常,请联系管理员");
throw ErrorHelp.genException(SysCode.System, ErrorCode.MERCHANT_STATUS_ERROR, "");
}
userInfoModel.setMerchant(merchant);
} else if (secUser.getObjectType() == 3) {
// 查询门店
HighMerchantStore merchantStore = highMerchantStoreService.getMerchantStoreById(secUser.getObjectId());
if(merchantStore == null){
log.error("login error!","未找到商户门店");
throw ErrorHelp.genException(SysCode.System, ErrorCode.MERCHANT_STORE_NOF_FOUND, "");
}
if(merchantStore.getStatus() != 1) {
log.error("login error!","未找到商户门店");
throw ErrorHelp.genException(SysCode.System, ErrorCode.MERCHANT_STORE_NOF_FOUND, "");
}
userInfoModel.setMerchantStore(merchantStore);
} else {
log.error("login error!","用户信息错误"); log.error("login error!","用户信息错误");
throw ErrorHelp.genException(SysCode.System, ErrorCode.SEC_USER_EXPIRED, ""); throw ErrorHelp.genException(SysCode.System, ErrorCode.SEC_USER_EXPIRED, "");
} }
String aesStr = AESEncodeUtil.aesEncrypt(secUser.getId().toString()); String aesStr = AESEncodeUtil.aesEncrypt(secUser.getId().toString());
userInfoModel.setToken(aesStr); userInfoModel.setToken(aesStr);
SessionObject so = new SessionObject(aesStr, 3, userInfoModel); SessionObject so = new SessionObject(aesStr, secUser.getObjectType(), userInfoModel);
userCenter.save(request, response, so); userCenter.save(request, response, so);
return ResponseMsgUtil.success(so); return ResponseMsgUtil.success(so);
} catch (Exception e) { } catch (Exception e) {

@ -1,5 +1,2 @@
wxAppId=wx01898d5209357d68
wxAppSecret=5c52d0526fcdb425075f6d51381d5c03
fileUrl=F:/hurui_probject/filesystem fileUrl=F:/hurui_probject/filesystem
cmsPath=F:/hurui_probject/filesystem cmsPath=F:/hurui_probject/filesystem

@ -1 +1,2 @@
fileUrl=/home/filesystem fileUrl=F:/hurui_probject/filesystem
cmsPath=F:/hurui_probject/filesystem

@ -0,0 +1,53 @@
package com.cweb.config;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
public class SessionKeyCache {
private static Map<String, CacheData> CACHE_DATA = new ConcurrentHashMap<>();
public static <T> T getData(String key) {
CacheData<T> data = CACHE_DATA.get(key);
if (data != null){
if(data.getExpire() <= 0 || data.getSaveTime() >= System.currentTimeMillis()) {
return data.getData();
}else{
clear(key);
}
}
return null;
}
public static <T> void setData(String key, T data, int expire) {
CACHE_DATA.put(key, new CacheData(data, expire));
}
public static void clear(String key) {
CACHE_DATA.remove(key);
}
private static class CacheData<T> {
CacheData(T t, int expire) {
this.data = t;
this.expire = expire <= 0 ? 0 : expire*1000;
this.saveTime = System.currentTimeMillis() + this.expire;
}
private T data;
private long saveTime; // 存活时间
private long expire; // 过期时间 小于等于0标识永久存活
public T getData() {
return data;
}
public long getExpire() {
return expire;
}
public long getSaveTime() {
return saveTime;
}
}
}

@ -11,6 +11,9 @@ public class SysConfig {
private String fileUrl; private String fileUrl;
private String wxAppId;
private String wxAppSecret;
public String getFileUrl() { public String getFileUrl() {
return fileUrl; return fileUrl;
} }
@ -18,4 +21,20 @@ public class SysConfig {
public void setFileUrl(String fileUrl) { public void setFileUrl(String fileUrl) {
this.fileUrl = fileUrl; this.fileUrl = fileUrl;
} }
public String getWxAppId() {
return wxAppId;
}
public void setWxAppId(String wxAppId) {
this.wxAppId = wxAppId;
}
public String getWxAppSecret() {
return wxAppSecret;
}
public void setWxAppSecret(String wxAppSecret) {
this.wxAppSecret = wxAppSecret;
}
} }

@ -0,0 +1,33 @@
package com.cweb.config;
import cn.binarywang.wx.miniapp.api.WxMaService;
import cn.binarywang.wx.miniapp.api.impl.WxMaServiceImpl;
import cn.binarywang.wx.miniapp.config.impl.WxMaDefaultConfigImpl;
import org.springframework.context.annotation.Configuration;
import javax.annotation.PostConstruct;
@Configuration
public class WxMaConfiguration {
private static WxMaService maService;
public static WxMaService getMaService() {
if (maService == null) {
throw new IllegalArgumentException(String.format("未找到对应的配置,请核实!"));
}
return maService;
}
@PostConstruct
public void init() {
WxMaDefaultConfigImpl config = new WxMaDefaultConfigImpl();
config.setAppid(SysConst.getSysConfig().getWxAppId());
config.setSecret(SysConst.getSysConfig().getWxAppSecret());
maService = new WxMaServiceImpl();
maService.setWxMaConfig(config);
}
}

@ -1,143 +0,0 @@
package com.cweb.controller;
import com.alibaba.fastjson.JSONObject;
import com.hai.common.exception.ErrorCode;
import com.hai.common.exception.ErrorHelp;
import com.hai.common.exception.SysCode;
import com.hai.common.security.*;
import com.hai.common.utils.ResponseMsgUtil;
import com.hai.model.ResponseData;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Objects;
@Controller
@RequestMapping(value = "/login")
@Api(value = "登录")
public class LoginController {
private static Logger log = LoggerFactory.getLogger(LoginController.class);
@Resource
private UserCenter userCenter;
@RequestMapping(value="/userLogin",method = RequestMethod.POST)
@ResponseBody
@ApiOperation(value = "用户登录 {'phone':'','password':'','code':'','type':''}")
public ResponseData userLogin(@RequestBody String reqBody, HttpServletRequest request, HttpServletResponse response) {
try {
/* UserInfoModel userInfoModel = new UserInfoModel();
String aesStr = AESEncodeUtil.aesEncrypt(customer.getId().toString());
SessionObject so = new SessionObject(aesStr, 1,userInfoModel);
userCenter.save(request, response, so);*/
return ResponseMsgUtil.success(null);
} catch (Exception e) {
return ResponseMsgUtil.exception(e);
}
}
@RequestMapping(value="/logout",method = RequestMethod.POST)
@ResponseBody
@ApiOperation(value = "登出")
public ResponseData logout(HttpServletRequest request, HttpServletResponse response){
try {
userCenter.remove(request, response);
return ResponseMsgUtil.success("退出成功");
} catch (Exception e) {
log.error("login error!",e);
return ResponseMsgUtil.exception(e);
}
}
@RequestMapping(value="/checkVerifyCode",method = RequestMethod.POST)
@ResponseBody
@ApiOperation(value = "校验验证码 ({'phone':'','code':''})")
public ResponseData checkVerifyCode(@RequestBody String reqBody){
try {
if(StringUtils.isBlank(reqBody)) {
log.error("login error!","参数错误");
throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR, "");
}
JSONObject jsonObject = JSONObject.parseObject(reqBody);
String phone = jsonObject.getString("phone");
String code = jsonObject.getString("code");
if(StringUtils.isBlank(phone) || StringUtils.isBlank(code)) {
log.error("login error!","参数错误");
throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR, "");
}
VerifyCode verifyCode = VerifyCodeStorage.getDate(phone);
if (verifyCode == null) {
return ResponseMsgUtil.success(false);
}
// 校验验证码
if (Objects.equals(String.valueOf(verifyCode.getObject()),code)) {
// 清除记录,验证码只能验证一次
//2020-08-06暂不做清除处理
//VerifyCodeStorage.remove(phone);
return ResponseMsgUtil.success(true);
} else {
return ResponseMsgUtil.success(false);
}
} catch (Exception e) {
log.error("login error!",e);
return ResponseMsgUtil.exception(e);
}
}
@RequestMapping(value="/forgetPassword",method = RequestMethod.POST)
@ResponseBody
@ApiOperation(value = "忘记密码 ({'phone':'','code':'','password':'','sign':''})")
public ResponseData forgetPassword(@RequestBody String reqBody) {
try {
JSONObject jsonObject = JSONObject.parseObject(reqBody);
String phone = jsonObject.getString("phone"); //用户电话
String code = jsonObject.getString("code"); // 验证码
String password = jsonObject.getString("password");//新密码
if(StringUtils.isBlank(phone) || StringUtils.isBlank(code) ||
StringUtils.isBlank(password)) {
log.error("LoginController --> forgetPassword() error!","参数错误");
throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR, "");
}
VerifyCode verifyCode = VerifyCodeStorage.getDate(phone);
if (verifyCode == null) {
log.error("LoginController --> forgetPassword() error!","验证码错误");
throw ErrorHelp.genException(SysCode.System, ErrorCode.SMS_CODE_ERROR, "");
}
// 校验验证码
if (!Objects.equals(String.valueOf(verifyCode.getObject()),code)) {
log.error("LoginController --> forgetPassword() error!","验证码错误");
throw ErrorHelp.genException(SysCode.System, ErrorCode.SMS_CODE_ERROR, "");
}
return ResponseMsgUtil.success("密码设置成功");
} catch (Exception e) {
log.error("LoginController --> forgetPassword() error!",e);
return ResponseMsgUtil.exception(e);
}
}
}

@ -0,0 +1,218 @@
package com.cweb.controller;
import cn.binarywang.wx.miniapp.api.WxMaService;
import cn.binarywang.wx.miniapp.bean.WxMaJscode2SessionResult;
import cn.binarywang.wx.miniapp.bean.WxMaPhoneNumberInfo;
import cn.binarywang.wx.miniapp.bean.WxMaUserInfo;
import com.alibaba.fastjson.JSONObject;
import com.cweb.config.SessionKeyCache;
import com.cweb.config.WxMaConfiguration;
import com.hai.common.exception.ErrorCode;
import com.hai.common.exception.ErrorHelp;
import com.hai.common.exception.SysCode;
import com.hai.common.security.SessionObject;
import com.hai.common.security.UserCenter;
import com.hai.common.utils.ResponseMsgUtil;
import com.hai.entity.HighUser;
import com.hai.model.HighUserModel;
import com.hai.model.ResponseData;
import com.hai.service.HighUserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Date;
@Controller
@RequestMapping(value = "/wechat")
@Api(value = "微信授权")
public class WechatController {
private static final Logger log = LoggerFactory.getLogger(WechatController.class);
@Autowired
private UserCenter userCenter;
@Resource
private HighUserService highUserService;
@RequestMapping(value = "/handleCode", method = RequestMethod.GET)
@ResponseBody
@ApiOperation(value = "微信小程序code解析")
public ResponseData compairCode(@RequestParam(value = "code", required = true) String code,
HttpServletRequest request, HttpServletResponse response) {
try {
//校验code,openId不能同时为空
if (StringUtils.isEmpty(code)) {
throw ErrorHelp.genException(SysCode.MiniProgram, ErrorCode.REQ_PARAMS_ERROR, "");
}
//请求微信api,获取用户session_key以及openId
final WxMaService wxService = WxMaConfiguration.getMaService();
WxMaJscode2SessionResult session = wxService.jsCode2SessionInfo(code);
//保存小程序用户登录的openId及sessionKey信息
SessionKeyCache.setData(session.getOpenid(), session.getSessionKey(), -1);
JSONObject jo = new JSONObject();
jo.put("openId", session.getOpenid());
return ResponseMsgUtil.success(jo);
} catch (Exception e) {
return ResponseMsgUtil.exception(e);
}
}
@RequestMapping(value = "/login", method = RequestMethod.GET)
@ResponseBody
@ApiOperation(value = "微信小程序授权用户登录接口")
public ResponseData login(@RequestParam(value = "openId", required = true) String openId,
HttpServletRequest request, HttpServletResponse response) {
try {
//校验code,openId不能同时为空
if (StringUtils.isEmpty(openId)) {
throw ErrorHelp.genException(SysCode.MiniProgram, ErrorCode.REQ_PARAMS_ERROR, "");
}
HighUser highUser = highUserService.findByOpenId(openId);
if (highUser == null) {
log.error("login error!", "未找到用户");
throw ErrorHelp.genException(SysCode.System, ErrorCode.UN_MEMBER_ERROR, "");
}
// 定义个人所有数据
HighUserModel loginDataModel = new HighUserModel();
highUser.setPassword(null);
loginDataModel.setHighUser(highUser);
SessionObject so = new SessionObject(openId, 99 , loginDataModel);
userCenter.save(request, response, so);
return ResponseMsgUtil.success(so);
} catch (Exception e) {
return ResponseMsgUtil.exception(e);
}
}
@RequestMapping(value = "/getPhoneNumber", method = RequestMethod.GET)
@ResponseBody
@ApiOperation(value = "小程序获取用户手机号码")
public ResponseData getPhoneNumber(@RequestParam(value = "encryptedData", required = true) String encryptedData,
@RequestParam(value = "iv", required = true) String iv,
@RequestParam(value = "openId", required = true) String openId,
HttpServletRequest request, HttpServletResponse response) {
try {
log.error("origin encryptedData:" + encryptedData + ";iv:" + iv);
//校验openId不能为空
//encryptedData,iv与unionId不能同时为空
encryptedData = encryptedData.replace(" ", "+");
iv = iv.replace(" ", "+");
log.error("dest encryptedData:" + encryptedData + ";iv:" + iv);
if (StringUtils.isEmpty(openId)
|| StringUtils.isEmpty(encryptedData) || StringUtils.isEmpty(iv)) {
throw ErrorHelp.genException(SysCode.MiniProgram, ErrorCode.REQ_PARAMS_ERROR, "");
}
//请求微信api,获取用户session_key以及openId
String sessionKey = SessionKeyCache.getData(openId);
final WxMaService wxService = WxMaConfiguration.getMaService();
WxMaPhoneNumberInfo phoneNoInfo = wxService.getUserService().getPhoneNoInfo(sessionKey, encryptedData, iv);
if (phoneNoInfo == null || StringUtils.isEmpty(phoneNoInfo.getPurePhoneNumber())) {
throw ErrorHelp.genException(SysCode.MiniProgram, ErrorCode.WECHAT_DECRYPT_ERROR, "用户phoneNumber解析失败");
}
HighUser user = highUserService.findByPhone(phoneNoInfo.getPurePhoneNumber());
if (user == null) {
user = new HighUser();
user.setOpenId(openId);
user.setRegTime(new Date());
user.setStatus(1);
user.setPhone(phoneNoInfo.getPurePhoneNumber());
highUserService.insertUser(user);
} else {
user.setOpenId(openId);;
highUserService.updateUser(user);
}
// 定义个人所有数据
HighUserModel highUserModel = new HighUserModel();
user.setPassword(null);
highUserModel.setHighUser(user);
SessionObject so = new SessionObject(openId, 1 , highUserModel);
userCenter.save(request, response, so);
return ResponseMsgUtil.success(so);
} catch (Exception e) {
return ResponseMsgUtil.exception(e);
}
}
@RequestMapping(value = "/getUserInfo", method = RequestMethod.GET)
@ResponseBody
@ApiOperation(value = "小程序获取用户信息")
public ResponseData getUserInfo(@RequestParam(value = "encryptedData", required = true) String encryptedData,
@RequestParam(value = "iv", required = true) String iv,
@RequestParam(value = "openId", required = true) String openId,
HttpServletRequest request, HttpServletResponse response) {
try {
//校验openId不能为空
//encryptedData,iv与unionId不能同时为空
encryptedData = encryptedData.replace(" ", "+");
iv = iv.replace(" ", "+");
if (StringUtils.isEmpty(openId)
|| StringUtils.isEmpty(encryptedData) || StringUtils.isEmpty(iv)) {
throw ErrorHelp.genException(SysCode.MiniProgram, ErrorCode.REQ_PARAMS_ERROR, "");
}
//请求微信api,获取用户session_key以及openId
String sessionKey = SessionKeyCache.getData(openId);
final WxMaService wxService = WxMaConfiguration.getMaService();
WxMaUserInfo userInfo = wxService.getUserService().getUserInfo(sessionKey, encryptedData, iv);
System.out.println("");
if (userInfo == null) {
throw ErrorHelp.genException(SysCode.MiniProgram, ErrorCode.WECHAT_DECRYPT_ERROR, "用户phoneNumber解析失败");
}
HighUser user = highUserService.findByOpenId(openId);
if (user == null) {
user = new HighUser();
user.setOpenId(openId);
user.setRegTime(new Date());
user.setStatus(1);
user.setHeaderImg(userInfo.getAvatarUrl());
user.setName(userInfo.getNickName());
highUserService.insertUser(user);
} else {
user.setOpenId(openId);
user.setHeaderImg(userInfo.getAvatarUrl());
user.setName(userInfo.getNickName());
highUserService.updateUser(user);
}
// 定义个人所有数据
HighUserModel highUserModel = new HighUserModel();
user.setPassword(null);
highUserModel.setHighUser(user);
SessionObject so = new SessionObject(openId, 1 , highUserModel);
userCenter.save(request, response, so);
return ResponseMsgUtil.success(so);
} catch (Exception e) {
return ResponseMsgUtil.exception(e);
}
}
}

@ -1,7 +1,7 @@
server: server:
port: 9302 port: 9301
servlet: servlet:
context-path: /brest context-path: /crest
#配置是否为debug模式,debug模式下,不开启权限校验 #配置是否为debug模式,debug模式下,不开启权限校验
debug: true debug: true

@ -1,5 +1,5 @@
server: server:
port: 9302 port: 9301
servlet: servlet:
context-path: /crest context-path: /crest

@ -1 +1,5 @@
fileUrl=/home/filesystem wxAppId=wx01898d5209357d68
wxAppSecret=5c52d0526fcdb425075f6d51381d5c03
fileUrl=F:/hurui_probject/filesystem
cmsPath=F:/hurui_probject/filesystem

@ -266,6 +266,11 @@
<artifactId>xstream</artifactId> <artifactId>xstream</artifactId>
<version>1.4.11.1</version> <version>1.4.11.1</version>
</dependency> </dependency>
<dependency>
<groupId>com.github.binarywang</groupId>
<artifactId>weixin-java-miniapp</artifactId>
<version>3.8.0</version>
</dependency>
</dependencies> </dependencies>
</project> </project>

@ -76,6 +76,10 @@ public enum ErrorCode {
ID_CARD_NUM_IS_ERROR("2104","身份证号码错误"), ID_CARD_NUM_IS_ERROR("2104","身份证号码错误"),
MERCHANT_NOF_FOUND("2105","未找到商户"), MERCHANT_NOF_FOUND("2105","未找到商户"),
MERCHANT_STORE_NOF_FOUND("2106","未找到商户门店"), MERCHANT_STORE_NOF_FOUND("2106","未找到商户门店"),
PHONE_NUM_IS_ERROR("2107","请输入正确的电话号码"),
PHONE_NUM_EXISTED("2108","电话号码已被使用"),
MERCHANT_STATUS_ERROR("2109","商户状态不正常,请联系管理员"),
STATUS_ERROR("3000","状态错误"), STATUS_ERROR("3000","状态错误"),
ADD_DATA_ERROR("3001","增加数据失败"), ADD_DATA_ERROR("3001","增加数据失败"),

@ -88,26 +88,18 @@ public class UserCenter {
if(cookie == null){ if(cookie == null){
return null; return null;
} }
return cookie.getValue();
try{
return AESEncodeUtil.aesDecrypt(cookie.getValue());
}catch(JsonParseException e){
log.error("parse cookie json failed: " + cookie.getValue());
return null;
}
} }
public static SessionObject getSessionObject(HttpServletRequest request) throws Exception { public static SessionObject getSessionObject(HttpServletRequest request) throws Exception {
String token = request.getHeader("Authorization"); String token = request.getHeader("Authorization");
if (StringUtils.isBlank(token)) { if (StringUtils.isBlank(token)) {
throw ErrorHelp.genException(SysCode.System, ErrorCode.USE_VISIT_ILLEGAL, ""); if (StringUtils.isNotBlank(read(request))) {
} token = read(request);
if (LoginCache.getData(token) != null) { }
return LoginCache.getData(token);
} }
if (LoginCache.getData(token) == null) {
if (read(request) != null) { throw ErrorHelp.genException(SysCode.System, ErrorCode.USE_VISIT_ILLEGAL, "");
return LoginCache.getData(token);
} }
return LoginCache.getData(token); return LoginCache.getData(token);
} }

@ -46,7 +46,7 @@ public interface HighUserMapper extends HighUserMapperExt {
"ext_1, ext_2, ext_3, ", "ext_1, ext_2, ext_3, ",
"ext_4)", "ext_4)",
"values (#{headerImg,jdbcType=VARCHAR}, #{name,jdbcType=VARCHAR}, ", "values (#{headerImg,jdbcType=VARCHAR}, #{name,jdbcType=VARCHAR}, ",
"#{phone,jdbcType=BIGINT}, #{password,jdbcType=VARCHAR}, ", "#{phone,jdbcType=VARCHAR}, #{password,jdbcType=VARCHAR}, ",
"#{sex,jdbcType=VARCHAR}, #{birthdate,jdbcType=DATE}, #{regTime,jdbcType=TIMESTAMP}, ", "#{sex,jdbcType=VARCHAR}, #{birthdate,jdbcType=DATE}, #{regTime,jdbcType=TIMESTAMP}, ",
"#{gold,jdbcType=INTEGER}, #{status,jdbcType=INTEGER}, #{openId,jdbcType=VARCHAR}, ", "#{gold,jdbcType=INTEGER}, #{status,jdbcType=INTEGER}, #{openId,jdbcType=VARCHAR}, ",
"#{ext1,jdbcType=VARCHAR}, #{ext2,jdbcType=VARCHAR}, #{ext3,jdbcType=VARCHAR}, ", "#{ext1,jdbcType=VARCHAR}, #{ext2,jdbcType=VARCHAR}, #{ext3,jdbcType=VARCHAR}, ",
@ -64,7 +64,7 @@ public interface HighUserMapper extends HighUserMapperExt {
@Result(column="id", property="id", jdbcType=JdbcType.BIGINT, id=true), @Result(column="id", property="id", jdbcType=JdbcType.BIGINT, id=true),
@Result(column="header_img", property="headerImg", jdbcType=JdbcType.VARCHAR), @Result(column="header_img", property="headerImg", jdbcType=JdbcType.VARCHAR),
@Result(column="name", property="name", jdbcType=JdbcType.VARCHAR), @Result(column="name", property="name", jdbcType=JdbcType.VARCHAR),
@Result(column="phone", property="phone", jdbcType=JdbcType.BIGINT), @Result(column="phone", property="phone", jdbcType=JdbcType.VARCHAR),
@Result(column="password", property="password", jdbcType=JdbcType.VARCHAR), @Result(column="password", property="password", jdbcType=JdbcType.VARCHAR),
@Result(column="sex", property="sex", jdbcType=JdbcType.VARCHAR), @Result(column="sex", property="sex", jdbcType=JdbcType.VARCHAR),
@Result(column="birthdate", property="birthdate", jdbcType=JdbcType.DATE), @Result(column="birthdate", property="birthdate", jdbcType=JdbcType.DATE),
@ -90,7 +90,7 @@ public interface HighUserMapper extends HighUserMapperExt {
@Result(column="id", property="id", jdbcType=JdbcType.BIGINT, id=true), @Result(column="id", property="id", jdbcType=JdbcType.BIGINT, id=true),
@Result(column="header_img", property="headerImg", jdbcType=JdbcType.VARCHAR), @Result(column="header_img", property="headerImg", jdbcType=JdbcType.VARCHAR),
@Result(column="name", property="name", jdbcType=JdbcType.VARCHAR), @Result(column="name", property="name", jdbcType=JdbcType.VARCHAR),
@Result(column="phone", property="phone", jdbcType=JdbcType.BIGINT), @Result(column="phone", property="phone", jdbcType=JdbcType.VARCHAR),
@Result(column="password", property="password", jdbcType=JdbcType.VARCHAR), @Result(column="password", property="password", jdbcType=JdbcType.VARCHAR),
@Result(column="sex", property="sex", jdbcType=JdbcType.VARCHAR), @Result(column="sex", property="sex", jdbcType=JdbcType.VARCHAR),
@Result(column="birthdate", property="birthdate", jdbcType=JdbcType.DATE), @Result(column="birthdate", property="birthdate", jdbcType=JdbcType.DATE),
@ -118,7 +118,7 @@ public interface HighUserMapper extends HighUserMapperExt {
"update high_user", "update high_user",
"set header_img = #{headerImg,jdbcType=VARCHAR},", "set header_img = #{headerImg,jdbcType=VARCHAR},",
"`name` = #{name,jdbcType=VARCHAR},", "`name` = #{name,jdbcType=VARCHAR},",
"phone = #{phone,jdbcType=BIGINT},", "phone = #{phone,jdbcType=VARCHAR},",
"`password` = #{password,jdbcType=VARCHAR},", "`password` = #{password,jdbcType=VARCHAR},",
"sex = #{sex,jdbcType=VARCHAR},", "sex = #{sex,jdbcType=VARCHAR},",
"birthdate = #{birthdate,jdbcType=DATE},", "birthdate = #{birthdate,jdbcType=DATE},",

@ -37,7 +37,7 @@ public class HighUserSqlProvider {
} }
if (record.getPhone() != null) { if (record.getPhone() != null) {
sql.VALUES("phone", "#{phone,jdbcType=BIGINT}"); sql.VALUES("phone", "#{phone,jdbcType=VARCHAR}");
} }
if (record.getPassword() != null) { if (record.getPassword() != null) {
@ -138,7 +138,7 @@ public class HighUserSqlProvider {
} }
if (record.getPhone() != null) { if (record.getPhone() != null) {
sql.SET("phone = #{record.phone,jdbcType=BIGINT}"); sql.SET("phone = #{record.phone,jdbcType=VARCHAR}");
} }
if (record.getPassword() != null) { if (record.getPassword() != null) {
@ -196,7 +196,7 @@ public class HighUserSqlProvider {
sql.SET("id = #{record.id,jdbcType=BIGINT}"); sql.SET("id = #{record.id,jdbcType=BIGINT}");
sql.SET("header_img = #{record.headerImg,jdbcType=VARCHAR}"); sql.SET("header_img = #{record.headerImg,jdbcType=VARCHAR}");
sql.SET("`name` = #{record.name,jdbcType=VARCHAR}"); sql.SET("`name` = #{record.name,jdbcType=VARCHAR}");
sql.SET("phone = #{record.phone,jdbcType=BIGINT}"); sql.SET("phone = #{record.phone,jdbcType=VARCHAR}");
sql.SET("`password` = #{record.password,jdbcType=VARCHAR}"); sql.SET("`password` = #{record.password,jdbcType=VARCHAR}");
sql.SET("sex = #{record.sex,jdbcType=VARCHAR}"); sql.SET("sex = #{record.sex,jdbcType=VARCHAR}");
sql.SET("birthdate = #{record.birthdate,jdbcType=DATE}"); sql.SET("birthdate = #{record.birthdate,jdbcType=DATE}");
@ -227,7 +227,7 @@ public class HighUserSqlProvider {
} }
if (record.getPhone() != null) { if (record.getPhone() != null) {
sql.SET("phone = #{phone,jdbcType=BIGINT}"); sql.SET("phone = #{phone,jdbcType=VARCHAR}");
} }
if (record.getPassword() != null) { if (record.getPassword() != null) {

@ -1,5 +1,7 @@
package com.hai.entity; package com.hai.entity;
import com.hai.model.HighMerchantModel;
import java.io.Serializable; import java.io.Serializable;
import java.util.Date; import java.util.Date;
@ -12,7 +14,7 @@ import java.util.Date;
* 代码由工具生成 * 代码由工具生成
* *
**/ **/
public class HighMerchant implements Serializable { public class HighMerchant extends HighMerchantModel implements Serializable {
/** /**
* 主键 * 主键
*/ */

@ -1,5 +1,7 @@
package com.hai.entity; package com.hai.entity;
import com.hai.model.HighMerchantStoreModel;
import java.io.Serializable; import java.io.Serializable;
import java.util.Date; import java.util.Date;
@ -12,7 +14,7 @@ import java.util.Date;
* 代码由工具生成 * 代码由工具生成
* *
**/ **/
public class HighMerchantStore implements Serializable { public class HighMerchantStore extends HighMerchantStoreModel implements Serializable {
/** /**
* 主键 * 主键
*/ */

@ -31,7 +31,7 @@ public class HighUser implements Serializable {
/** /**
* 手机号码 * 手机号码
*/ */
private Long phone; private String phone;
/** /**
* 登录密码 * 登录密码
@ -99,11 +99,11 @@ public class HighUser implements Serializable {
this.name = name; this.name = name;
} }
public Long getPhone() { public String getPhone() {
return phone; return phone;
} }
public void setPhone(Long phone) { public void setPhone(String phone) {
this.phone = phone; this.phone = phone;
} }

@ -362,52 +362,62 @@ public class HighUserExample {
return (Criteria) this; return (Criteria) this;
} }
public Criteria andPhoneEqualTo(Long value) { public Criteria andPhoneEqualTo(String value) {
addCriterion("phone =", value, "phone"); addCriterion("phone =", value, "phone");
return (Criteria) this; return (Criteria) this;
} }
public Criteria andPhoneNotEqualTo(Long value) { public Criteria andPhoneNotEqualTo(String value) {
addCriterion("phone <>", value, "phone"); addCriterion("phone <>", value, "phone");
return (Criteria) this; return (Criteria) this;
} }
public Criteria andPhoneGreaterThan(Long value) { public Criteria andPhoneGreaterThan(String value) {
addCriterion("phone >", value, "phone"); addCriterion("phone >", value, "phone");
return (Criteria) this; return (Criteria) this;
} }
public Criteria andPhoneGreaterThanOrEqualTo(Long value) { public Criteria andPhoneGreaterThanOrEqualTo(String value) {
addCriterion("phone >=", value, "phone"); addCriterion("phone >=", value, "phone");
return (Criteria) this; return (Criteria) this;
} }
public Criteria andPhoneLessThan(Long value) { public Criteria andPhoneLessThan(String value) {
addCriterion("phone <", value, "phone"); addCriterion("phone <", value, "phone");
return (Criteria) this; return (Criteria) this;
} }
public Criteria andPhoneLessThanOrEqualTo(Long value) { public Criteria andPhoneLessThanOrEqualTo(String value) {
addCriterion("phone <=", value, "phone"); addCriterion("phone <=", value, "phone");
return (Criteria) this; return (Criteria) this;
} }
public Criteria andPhoneIn(List<Long> values) { public Criteria andPhoneLike(String value) {
addCriterion("phone like", value, "phone");
return (Criteria) this;
}
public Criteria andPhoneNotLike(String value) {
addCriterion("phone not like", value, "phone");
return (Criteria) this;
}
public Criteria andPhoneIn(List<String> values) {
addCriterion("phone in", values, "phone"); addCriterion("phone in", values, "phone");
return (Criteria) this; return (Criteria) this;
} }
public Criteria andPhoneNotIn(List<Long> values) { public Criteria andPhoneNotIn(List<String> values) {
addCriterion("phone not in", values, "phone"); addCriterion("phone not in", values, "phone");
return (Criteria) this; return (Criteria) this;
} }
public Criteria andPhoneBetween(Long value1, Long value2) { public Criteria andPhoneBetween(String value1, String value2) {
addCriterion("phone between", value1, value2, "phone"); addCriterion("phone between", value1, value2, "phone");
return (Criteria) this; return (Criteria) this;
} }
public Criteria andPhoneNotBetween(Long value1, Long value2) { public Criteria andPhoneNotBetween(String value1, String value2) {
addCriterion("phone not between", value1, value2, "phone"); addCriterion("phone not between", value1, value2, "phone");
return (Criteria) this; return (Criteria) this;
} }

@ -0,0 +1,21 @@
package com.hai.model;
import com.hai.entity.SecUser;
/**
* @Auther: 胡锐
* @Description:
* @Date: 2021/3/10 20:22
*/
public class HighMerchantModel {
private SecUser secUser;
public SecUser getSecUser() {
return secUser;
}
public void setSecUser(SecUser secUser) {
this.secUser = secUser;
}
}

@ -0,0 +1,22 @@
package com.hai.model;
import com.hai.entity.SecUser;
/**
* @Auther: 胡锐
* @Description:
* @Date: 2021/3/10 22:11
*/
public class HighMerchantStoreModel {
// 账号
private SecUser secUser;
public SecUser getSecUser() {
return secUser;
}
public void setSecUser(SecUser secUser) {
this.secUser = secUser;
}
}

@ -0,0 +1,22 @@
package com.hai.model;
import com.hai.entity.HighUser;
/**
* @Auther: 胡锐
* @Description:
* @Date: 2021/3/10 22:50
*/
public class HighUserModel {
// 用户
private HighUser highUser;
public HighUser getHighUser() {
return highUser;
}
public void setHighUser(HighUser highUser) {
this.highUser = highUser;
}
}

@ -26,6 +26,8 @@ public class UserInfoModel {
private BsCompany bsCompany; private BsCompany bsCompany;
// 商户 // 商户
private HighMerchant merchant; private HighMerchant merchant;
// 门店
private HighMerchantStore merchantStore;
// 权限列表 // 权限列表
private List<SecPermission> permissionList; private List<SecPermission> permissionList;
// 菜单权限列表 // 菜单权限列表
@ -35,14 +37,6 @@ public class UserInfoModel {
private String token; private String token;
public HighMerchant getMerchant() {
return merchant;
}
public void setMerchant(HighMerchant merchant) {
this.merchant = merchant;
}
public SecUser getSecUser() { public SecUser getSecUser() {
return secUser; return secUser;
} }
@ -75,6 +69,22 @@ public class UserInfoModel {
this.bsCompany = bsCompany; this.bsCompany = bsCompany;
} }
public HighMerchant getMerchant() {
return merchant;
}
public void setMerchant(HighMerchant merchant) {
this.merchant = merchant;
}
public HighMerchantStore getMerchantStore() {
return merchantStore;
}
public void setMerchantStore(HighMerchantStore merchantStore) {
this.merchantStore = merchantStore;
}
public List<SecPermission> getPermissionList() { public List<SecPermission> getPermissionList() {
return permissionList; return permissionList;
} }
@ -99,7 +109,6 @@ public class UserInfoModel {
this.buttonList = buttonList; this.buttonList = buttonList;
} }
public String getToken() { public String getToken() {
return token; return token;
} }

@ -13,7 +13,7 @@ public interface HighMerchantService {
/** /**
* 编辑 * 编辑
*/ */
void editMerchant(HighMerchant highMerchant); void editMerchant(HighMerchant highMerchant) throws Exception;
/** /**
* 根据id查询 * 根据id查询

@ -17,7 +17,14 @@ public interface HighMerchantStoreService {
* @Description 编辑门店 * @Description 编辑门店
* @Date 2021/3/9 20:26 * @Date 2021/3/9 20:26
**/ **/
void editMerchantStore(HighMerchantStore highMerchantStore); void editMerchantStore(HighMerchantStore highMerchantStore) throws Exception;
/**
* @Author 胡锐
* @Description 删除门店
* @Date 2021/3/10 22:24
**/
void deleteMerchantStore(Long id);
/** /**
* @Author 胡锐 * @Author 胡锐

@ -14,6 +14,7 @@ import java.util.Map;
*/ */
public interface HighUserService { public interface HighUserService {
/** /**
* *
* @Title: getListUser * @Title: getListUser
@ -38,6 +39,20 @@ public interface HighUserService {
*/ */
HighUser findByUserId(Long userId); HighUser findByUserId(Long userId);
/**
* @Author 胡锐
* @Description 根据微信openId 查询用户
* @Date 2021/3/10 22:44
**/
HighUser findByOpenId(String openId);
/**
* @Author 胡锐
* @Description 根据手机号 查询用户
* @Date 2021/3/10 22:55
**/
HighUser findByPhone(String phone);
/** /**
* *
* @Title: updateUser * @Title: updateUser

@ -200,4 +200,11 @@ public interface SecUserService {
* @throws * @throws
*/ */
UserTreeModel findAttendUserTree(Long companyId, BsOrganization organization); UserTreeModel findAttendUserTree(Long companyId, BsOrganization organization);
/**
* @Author 胡锐
* @Description 查询门店所有账号
* @Date 2021/3/10 22:35
**/
List<SecUser> getMerchantStoreUser(Long merchantStoreId);
} }

@ -1,14 +1,19 @@
package com.hai.service.impl; package com.hai.service.impl;
import com.hai.common.utils.MD5Util;
import com.hai.dao.HighMerchantMapper; import com.hai.dao.HighMerchantMapper;
import com.hai.entity.HighMerchant; import com.hai.entity.HighMerchant;
import com.hai.entity.HighMerchantExample; import com.hai.entity.HighMerchantExample;
import com.hai.entity.SecUser;
import com.hai.service.HighMerchantService; import com.hai.service.HighMerchantService;
import com.hai.service.SecUserService;
import org.apache.commons.collections4.MapUtils; import org.apache.commons.collections4.MapUtils;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.util.Date;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@ -18,10 +23,26 @@ public class HighMerchantServiceImpl implements HighMerchantService {
@Resource @Resource
private HighMerchantMapper highMerchantMapper; private HighMerchantMapper highMerchantMapper;
@Resource
private SecUserService secUserService;
@Override @Override
public void editMerchant(HighMerchant highMerchant) { @Transactional
public void editMerchant(HighMerchant highMerchant) throws Exception {
if (highMerchant.getId() == null) { if (highMerchant.getId() == null) {
highMerchantMapper.insert(highMerchant); highMerchantMapper.insert(highMerchant);
highMerchant.getSecUser().setUserName(highMerchant.getMerchantName());
highMerchant.getSecUser().setLoginName(highMerchant.getSecUser().getTelephone());
highMerchant.getSecUser().setPassword(MD5Util.encode(highMerchant.getSecUser().getPassword().getBytes()));
highMerchant.getSecUser().setStatus(1);
highMerchant.getSecUser().setRoleId(2L);
highMerchant.getSecUser().setObjectType(2);
highMerchant.getSecUser().setObjectId(highMerchant.getId());
highMerchant.getSecUser().setCreateTime(new Date());
highMerchant.getSecUser().setUpdateTime(new Date());
secUserService.addUser(highMerchant.getSecUser());
} else { } else {
highMerchantMapper.updateByPrimaryKey(highMerchant); highMerchantMapper.updateByPrimaryKey(highMerchant);
} }

@ -1,15 +1,23 @@
package com.hai.service.impl; package com.hai.service.impl;
import com.hai.common.exception.ErrorCode;
import com.hai.common.exception.ErrorHelp;
import com.hai.common.exception.SysCode;
import com.hai.common.utils.MD5Util;
import com.hai.dao.HighMerchantStoreMapper; import com.hai.dao.HighMerchantStoreMapper;
import com.hai.entity.HighMerchantStore; import com.hai.entity.HighMerchantStore;
import com.hai.entity.HighMerchantStoreExample; import com.hai.entity.HighMerchantStoreExample;
import com.hai.entity.SecUser;
import com.hai.service.HighMerchantStoreService; import com.hai.service.HighMerchantStoreService;
import com.hai.service.SecUserService;
import org.apache.commons.collections4.MapUtils; import org.apache.commons.collections4.MapUtils;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.util.Date;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@ -19,12 +27,46 @@ public class HighMerchantStoreServiceImpl implements HighMerchantStoreService {
@Resource @Resource
private HighMerchantStoreMapper highMerchantStoreMapper; private HighMerchantStoreMapper highMerchantStoreMapper;
@Resource
private SecUserService secUserService;
@Override @Override
public void editMerchantStore(HighMerchantStore highMerchantStore) { @Transactional
public void editMerchantStore(HighMerchantStore highMerchantStore) throws Exception {
if (highMerchantStore.getId() != null) { if (highMerchantStore.getId() != null) {
highMerchantStoreMapper.updateByPrimaryKey(highMerchantStore); highMerchantStoreMapper.updateByPrimaryKey(highMerchantStore);
} else { } else {
highMerchantStoreMapper.insert(highMerchantStore); highMerchantStoreMapper.insert(highMerchantStore);
highMerchantStore.getSecUser().setUserName(highMerchantStore.getStoreName());
highMerchantStore.getSecUser().setLoginName(highMerchantStore.getSecUser().getTelephone());
highMerchantStore.getSecUser().setPassword(MD5Util.encode(highMerchantStore.getSecUser().getPassword().getBytes()));
highMerchantStore.getSecUser().setStatus(1);
highMerchantStore.getSecUser().setRoleId(3L);
highMerchantStore.getSecUser().setObjectType(3);
highMerchantStore.getSecUser().setObjectId(highMerchantStore.getId());
highMerchantStore.getSecUser().setCreateTime(new Date());
highMerchantStore.getSecUser().setUpdateTime(new Date());
secUserService.addUser(highMerchantStore.getSecUser());
}
}
@Override
@Transactional
public void deleteMerchantStore(Long id) {
// 查询门店
HighMerchantStore store = highMerchantStoreMapper.selectByPrimaryKey(id);
if (store != null) {
throw ErrorHelp.genException(SysCode.System, ErrorCode.MERCHANT_STORE_NOF_FOUND, "");
}
store.setStatus(0);
store.setUpdateTime(new Date());
highMerchantStoreMapper.updateByPrimaryKey(store);
// 查询门店下的所有用户
List<SecUser> userList = secUserService.getMerchantStoreUser(store.getId());
for (SecUser user : userList) {
user.setStatus(0); // 删除
secUserService.updateUser(user);
} }
} }

@ -5,7 +5,6 @@ import com.hai.dao.HighUserMapper;
import com.hai.entity.HighUser; import com.hai.entity.HighUser;
import com.hai.entity.HighUserExample; import com.hai.entity.HighUserExample;
import com.hai.service.HighUserService; import com.hai.service.HighUserService;
import com.sun.xml.bind.v2.model.core.ID;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
@ -29,7 +28,7 @@ public class HighUserServiceImpl implements HighUserService {
HighUserExample.Criteria criteria = example.createCriteria(); HighUserExample.Criteria criteria = example.createCriteria();
if (StringUtils.isNotBlank(map.get("phone"))) { if (StringUtils.isNotBlank(map.get("phone"))) {
criteria.andPhoneEqualTo(Long.valueOf(map.get("phone"))); criteria.andPhoneEqualTo(map.get("phone"));
} }
if (StringUtils.isNotBlank(map.get("name"))) { if (StringUtils.isNotBlank(map.get("name"))) {
criteria.andNameLike("%" + map.get("name") + "%"); criteria.andNameLike("%" + map.get("name") + "%");
@ -52,6 +51,28 @@ public class HighUserServiceImpl implements HighUserService {
return highUserMapper.selectByPrimaryKey(userId); return highUserMapper.selectByPrimaryKey(userId);
} }
@Override
public HighUser findByOpenId(String openId) {
HighUserExample example = new HighUserExample();
example.createCriteria().andOpenIdEqualTo(openId);
List<HighUser> list = highUserMapper.selectByExample(example);
if (list != null && list.size() > 0) {
return list.get(0);
}
return null;
}
@Override
public HighUser findByPhone(String phone) {
HighUserExample example = new HighUserExample();
example.createCriteria().andPhoneEqualTo(phone);
List<HighUser> list = highUserMapper.selectByExample(example);
if (list != null && list.size() > 0) {
return list.get(0);
}
return null;
}
@Override @Override
public void updateUser(HighUser highUser) { public void updateUser(HighUser highUser) {
highUserMapper.updateByPrimaryKeySelective(highUser); highUserMapper.updateByPrimaryKeySelective(highUser);

@ -250,6 +250,13 @@ public class SecUserServiceImpl implements SecUserService {
return userTreeModel; return userTreeModel;
} }
@Override
public List<SecUser> getMerchantStoreUser(Long merchantStoreId) {
SecUserExample example = new SecUserExample();
example.createCriteria().andObjectTypeEqualTo(3).andObjectIdEqualTo(merchantStoreId).andStatusEqualTo(1);
return secUserMapper.selectByExample(example);
}
//构建考勤员工树 //构建考勤员工树
public void buildAttendUserTree(UserTreeModel parent, List<BsOrganization> organizations) { public void buildAttendUserTree(UserTreeModel parent, List<BsOrganization> organizations) {
// 查询部门下员工 // 查询部门下员工

Loading…
Cancel
Save