diff --git a/hai-bweb/src/main/java/com/bweb/controller/HighMerchantController.java b/hai-bweb/src/main/java/com/bweb/controller/HighMerchantController.java index f74db933..7f0fb370 100644 --- a/hai-bweb/src/main/java/com/bweb/controller/HighMerchantController.java +++ b/hai-bweb/src/main/java/com/bweb/controller/HighMerchantController.java @@ -10,12 +10,14 @@ import com.hai.common.security.AESEncodeUtil; import com.hai.common.security.SessionObject; import com.hai.common.security.UserCenter; import com.hai.common.utils.MD5Util; +import com.hai.common.utils.MemberValidateUtil; import com.hai.common.utils.ResponseMsgUtil; import com.hai.entity.*; import com.hai.model.MenuTreeModel; import com.hai.model.ResponseData; import com.hai.model.UserInfoModel; import com.hai.service.HighMerchantService; +import com.hai.service.SecUserService; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import org.apache.commons.lang3.StringUtils; @@ -51,6 +53,9 @@ public class HighMerchantController { @Resource private HighMerchantService highMerchantService; + @Resource + private SecUserService secUserService; + @RequestMapping(value="/editMerchant",method = RequestMethod.POST) @ResponseBody @ApiOperation(value = "编辑商户") @@ -68,18 +73,37 @@ public class HighMerchantController { throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR, ""); } - if (highMerchant.getId() != null) { - if (highMerchantService.getMerchantById(highMerchant.getId()) == null) { - log.error("HighMerchantController -> editMerchant() error!","未找到商户"); - throw ErrorHelp.genException(SysCode.System, ErrorCode.MERCHANT_NOF_FOUND, ""); + // id为空 就是增加商户,需要校验账号是否填写 + if (highMerchant.getId() == null) { + if (StringUtils.isBlank(highMerchant.getSecUser().getPassword()) || StringUtils.isBlank(highMerchant.getSecUser().getTelephone())) { + 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()); } 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.setStatus(1); // 状态:0:不可用,1:可用 + highMerchant.setOperatorId(userInfoModel.getSecUser().getId()); highMerchant.setOperatorName(userInfoModel.getSecUser().getUserName()); highMerchantService.editMerchant(highMerchant); diff --git a/hai-bweb/src/main/java/com/bweb/controller/HighMerchantStoreController.java b/hai-bweb/src/main/java/com/bweb/controller/HighMerchantStoreController.java index 2d4f4768..7aba8005 100644 --- a/hai-bweb/src/main/java/com/bweb/controller/HighMerchantStoreController.java +++ b/hai-bweb/src/main/java/com/bweb/controller/HighMerchantStoreController.java @@ -7,6 +7,7 @@ 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.MemberValidateUtil; import com.hai.common.utils.ResponseMsgUtil; import com.hai.entity.HighMerchant; import com.hai.entity.HighMerchantStore; @@ -14,6 +15,7 @@ import com.hai.model.ResponseData; import com.hai.model.UserInfoModel; import com.hai.service.HighMerchantService; import com.hai.service.HighMerchantStoreService; +import com.hai.service.SecUserService; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import org.apache.commons.lang3.StringUtils; @@ -50,6 +52,9 @@ public class HighMerchantStoreController { @Resource private HighMerchantService highMerchantService; + @Resource + private SecUserService secUserService; + @RequestMapping(value="/editHighMerchantStore",method = RequestMethod.POST) @ResponseBody @ApiOperation(value = "编辑商户门店") @@ -67,21 +72,43 @@ public class HighMerchantStoreController { log.error("HighMerchantStoreController -> editMerchantStore() error!","参数错误"); throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR, ""); } - // 商户 - HighMerchant merchant = highMerchantService.getMerchantById(highMerchantStore.getMerchantId()); - if (merchant != null) { - log.error("HighMerchantStoreController -> editMerchantStore() error!","未找到商户"); - throw ErrorHelp.genException(SysCode.System, ErrorCode.MERCHANT_NOF_FOUND, ""); - } - if (highMerchantStore.getId() != null) { + + + + // id为空 就是增加门店,需要校验账号是否填写 + if (highMerchantStore.getId() == null) { + if (StringUtils.isBlank(highMerchantStore.getSecUser().getPassword()) || StringUtils.isBlank(highMerchantStore.getSecUser().getTelephone())) { + 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.setStatus(1); // 状态:0:删除,1:正常 + } else { - highMerchantStore.setCreateTime(new Date()); highMerchantStore.setUpdateTime(new Date()); } - highMerchantStore.setCompanyId(merchant.getCompanyId()); - highMerchantStore.setStatus(1); // 状态:0:删除,1:正常 highMerchantStore.setOperatorId(userInfoModel.getSecUser().getId()); highMerchantStore.setOperatorName(userInfoModel.getSecUser().getUserName()); highMerchantStoreService.editMerchantStore(highMerchantStore); @@ -104,9 +131,7 @@ public class HighMerchantStoreController { log.error("HighMerchantStoreController -> deleteMerchantStore() error!","未找到商户门店"); throw ErrorHelp.genException(SysCode.System, ErrorCode.MERCHANT_STORE_NOF_FOUND, ""); } - merchantStore.setStatus(0); - merchantStore.setUpdateTime(new Date()); - highMerchantStoreService.editMerchantStore(merchantStore); + highMerchantStoreService.deleteMerchantStore(id); return ResponseMsgUtil.success("操作成功"); diff --git a/hai-bweb/src/main/java/com/bweb/controller/LoginController.java b/hai-bweb/src/main/java/com/bweb/controller/LoginController.java index 0731b756..dc782524 100644 --- a/hai-bweb/src/main/java/com/bweb/controller/LoginController.java +++ b/hai-bweb/src/main/java/com/bweb/controller/LoginController.java @@ -48,6 +48,12 @@ public class LoginController { @Resource private BsCompanyService bsCompanyService; + @Resource + private HighMerchantService highMerchantService; + + @Resource + private HighMerchantStoreService highMerchantStoreService; + @Resource private BsOrganizationService bsOrganizationService; @@ -74,7 +80,7 @@ public class LoginController { throw ErrorHelp.genException(SysCode.System, ErrorCode.PASSWORD_ERROR, ""); } UserInfoModel userInfoModel = new UserInfoModel(); - secUser.setPassword(""); + secUser.setPassword(null); userInfoModel.setSecUser(secUser); //用户信息 //查询用户角色 @@ -98,7 +104,7 @@ public class LoginController { userInfoModel.setButtonList(buttonList); userInfoModel.setPermissionList(permissionList); - // 根据用户来源返回登录数据 0:超级管理员 1:运营中心成员 + // 根据用户来源返回登录数据 0:超级管理员 1:公司 2:商户 3:门店 if (secUser.getObjectType() == 0 || secUser.getObjectType() == 1) { // 公司员工(超级管理员和单位员工) //查询公司 @@ -121,13 +127,42 @@ public class LoginController { 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!","用户信息错误"); throw ErrorHelp.genException(SysCode.System, ErrorCode.SEC_USER_EXPIRED, ""); } String aesStr = AESEncodeUtil.aesEncrypt(secUser.getId().toString()); userInfoModel.setToken(aesStr); - SessionObject so = new SessionObject(aesStr, 3, userInfoModel); + SessionObject so = new SessionObject(aesStr, secUser.getObjectType(), userInfoModel); userCenter.save(request, response, so); return ResponseMsgUtil.success(so); } catch (Exception e) { diff --git a/hai-bweb/src/main/resources/dev/config.properties b/hai-bweb/src/main/resources/dev/config.properties index 669cf7ca..f0aa7b68 100644 --- a/hai-bweb/src/main/resources/dev/config.properties +++ b/hai-bweb/src/main/resources/dev/config.properties @@ -1,5 +1,2 @@ -wxAppId=wx01898d5209357d68 -wxAppSecret=5c52d0526fcdb425075f6d51381d5c03 - fileUrl=F:/hurui_probject/filesystem cmsPath=F:/hurui_probject/filesystem diff --git a/hai-bweb/src/main/resources/prod/config.properties b/hai-bweb/src/main/resources/prod/config.properties index 5034a9fd..f0aa7b68 100644 --- a/hai-bweb/src/main/resources/prod/config.properties +++ b/hai-bweb/src/main/resources/prod/config.properties @@ -1 +1,2 @@ -fileUrl=/home/filesystem +fileUrl=F:/hurui_probject/filesystem +cmsPath=F:/hurui_probject/filesystem diff --git a/hai-cweb/src/main/java/com/cweb/config/SessionKeyCache.java b/hai-cweb/src/main/java/com/cweb/config/SessionKeyCache.java new file mode 100644 index 00000000..fd8071b2 --- /dev/null +++ b/hai-cweb/src/main/java/com/cweb/config/SessionKeyCache.java @@ -0,0 +1,53 @@ +package com.cweb.config; + +import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; + +public class SessionKeyCache { + + private static Map CACHE_DATA = new ConcurrentHashMap<>(); + + public static T getData(String key) { + CacheData 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 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 { + 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; + } + } +} diff --git a/hai-cweb/src/main/java/com/cweb/config/SysConfig.java b/hai-cweb/src/main/java/com/cweb/config/SysConfig.java index 8816bed9..fdf16884 100644 --- a/hai-cweb/src/main/java/com/cweb/config/SysConfig.java +++ b/hai-cweb/src/main/java/com/cweb/config/SysConfig.java @@ -11,6 +11,9 @@ public class SysConfig { private String fileUrl; + private String wxAppId; + private String wxAppSecret; + public String getFileUrl() { return fileUrl; } @@ -18,4 +21,20 @@ public class SysConfig { public void setFileUrl(String 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; + } } diff --git a/hai-cweb/src/main/java/com/cweb/config/WxMaConfiguration.java b/hai-cweb/src/main/java/com/cweb/config/WxMaConfiguration.java new file mode 100644 index 00000000..11709bcf --- /dev/null +++ b/hai-cweb/src/main/java/com/cweb/config/WxMaConfiguration.java @@ -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); + } + +} diff --git a/hai-cweb/src/main/java/com/cweb/controller/LoginController.java b/hai-cweb/src/main/java/com/cweb/controller/LoginController.java deleted file mode 100644 index c9abe87e..00000000 --- a/hai-cweb/src/main/java/com/cweb/controller/LoginController.java +++ /dev/null @@ -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); - } - } - -} diff --git a/hai-cweb/src/main/java/com/cweb/controller/WechatController.java b/hai-cweb/src/main/java/com/cweb/controller/WechatController.java new file mode 100644 index 00000000..42413bd6 --- /dev/null +++ b/hai-cweb/src/main/java/com/cweb/controller/WechatController.java @@ -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); + } + } + + +} diff --git a/hai-cweb/src/main/resources/dev/application.yml b/hai-cweb/src/main/resources/dev/application.yml index 34903d32..78260bf2 100644 --- a/hai-cweb/src/main/resources/dev/application.yml +++ b/hai-cweb/src/main/resources/dev/application.yml @@ -1,7 +1,7 @@ server: - port: 9302 + port: 9301 servlet: - context-path: /brest + context-path: /crest #配置是否为debug模式,debug模式下,不开启权限校验 debug: true diff --git a/hai-cweb/src/main/resources/prod/application.yml b/hai-cweb/src/main/resources/prod/application.yml index 438274a1..03d8ec1f 100644 --- a/hai-cweb/src/main/resources/prod/application.yml +++ b/hai-cweb/src/main/resources/prod/application.yml @@ -1,5 +1,5 @@ server: - port: 9302 + port: 9301 servlet: context-path: /crest diff --git a/hai-cweb/src/main/resources/prod/config.properties b/hai-cweb/src/main/resources/prod/config.properties index 5034a9fd..669cf7ca 100644 --- a/hai-cweb/src/main/resources/prod/config.properties +++ b/hai-cweb/src/main/resources/prod/config.properties @@ -1 +1,5 @@ -fileUrl=/home/filesystem +wxAppId=wx01898d5209357d68 +wxAppSecret=5c52d0526fcdb425075f6d51381d5c03 + +fileUrl=F:/hurui_probject/filesystem +cmsPath=F:/hurui_probject/filesystem diff --git a/hai-service/pom.xml b/hai-service/pom.xml index 8f0002c7..59aa7cbd 100644 --- a/hai-service/pom.xml +++ b/hai-service/pom.xml @@ -267,8 +267,9 @@ 1.4.11.1 - org.springframework.boot - spring-boot-starter-aop + com.github.binarywang + weixin-java-miniapp + 3.8.0 diff --git a/hai-service/src/main/java/com/hai/common/exception/ErrorCode.java b/hai-service/src/main/java/com/hai/common/exception/ErrorCode.java index fc048b75..063bbdb1 100644 --- a/hai-service/src/main/java/com/hai/common/exception/ErrorCode.java +++ b/hai-service/src/main/java/com/hai/common/exception/ErrorCode.java @@ -76,6 +76,10 @@ public enum ErrorCode { ID_CARD_NUM_IS_ERROR("2104","身份证号码错误"), MERCHANT_NOF_FOUND("2105","未找到商户"), MERCHANT_STORE_NOF_FOUND("2106","未找到商户门店"), + PHONE_NUM_IS_ERROR("2107","请输入正确的电话号码"), + PHONE_NUM_EXISTED("2108","电话号码已被使用"), + MERCHANT_STATUS_ERROR("2109","商户状态不正常,请联系管理员"), + STATUS_ERROR("3000","状态错误"), ADD_DATA_ERROR("3001","增加数据失败"), diff --git a/hai-service/src/main/java/com/hai/common/security/UserCenter.java b/hai-service/src/main/java/com/hai/common/security/UserCenter.java index fb117a76..63044d0e 100644 --- a/hai-service/src/main/java/com/hai/common/security/UserCenter.java +++ b/hai-service/src/main/java/com/hai/common/security/UserCenter.java @@ -88,26 +88,18 @@ public class UserCenter { if(cookie == null){ return null; } - - try{ - return AESEncodeUtil.aesDecrypt(cookie.getValue()); - }catch(JsonParseException e){ - log.error("parse cookie json failed: " + cookie.getValue()); - return null; - } + return cookie.getValue(); } public static SessionObject getSessionObject(HttpServletRequest request) throws Exception { String token = request.getHeader("Authorization"); if (StringUtils.isBlank(token)) { - throw ErrorHelp.genException(SysCode.System, ErrorCode.USE_VISIT_ILLEGAL, ""); - } - if (LoginCache.getData(token) != null) { - return LoginCache.getData(token); + if (StringUtils.isNotBlank(read(request))) { + token = read(request); + } } - - if (read(request) != null) { - return LoginCache.getData(token); + if (LoginCache.getData(token) == null) { + throw ErrorHelp.genException(SysCode.System, ErrorCode.USE_VISIT_ILLEGAL, ""); } return LoginCache.getData(token); } diff --git a/hai-service/src/main/java/com/hai/dao/HighUserMapper.java b/hai-service/src/main/java/com/hai/dao/HighUserMapper.java index f22a7132..6a25c5e0 100644 --- a/hai-service/src/main/java/com/hai/dao/HighUserMapper.java +++ b/hai-service/src/main/java/com/hai/dao/HighUserMapper.java @@ -46,7 +46,7 @@ public interface HighUserMapper extends HighUserMapperExt { "ext_1, ext_2, ext_3, ", "ext_4)", "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}, ", "#{gold,jdbcType=INTEGER}, #{status,jdbcType=INTEGER}, #{openId,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="header_img", property="headerImg", 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="sex", property="sex", jdbcType=JdbcType.VARCHAR), @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="header_img", property="headerImg", 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="sex", property="sex", jdbcType=JdbcType.VARCHAR), @Result(column="birthdate", property="birthdate", jdbcType=JdbcType.DATE), @@ -118,7 +118,7 @@ public interface HighUserMapper extends HighUserMapperExt { "update high_user", "set header_img = #{headerImg,jdbcType=VARCHAR},", "`name` = #{name,jdbcType=VARCHAR},", - "phone = #{phone,jdbcType=BIGINT},", + "phone = #{phone,jdbcType=VARCHAR},", "`password` = #{password,jdbcType=VARCHAR},", "sex = #{sex,jdbcType=VARCHAR},", "birthdate = #{birthdate,jdbcType=DATE},", diff --git a/hai-service/src/main/java/com/hai/dao/HighUserSqlProvider.java b/hai-service/src/main/java/com/hai/dao/HighUserSqlProvider.java index cb3561b0..a89a4675 100644 --- a/hai-service/src/main/java/com/hai/dao/HighUserSqlProvider.java +++ b/hai-service/src/main/java/com/hai/dao/HighUserSqlProvider.java @@ -37,7 +37,7 @@ public class HighUserSqlProvider { } if (record.getPhone() != null) { - sql.VALUES("phone", "#{phone,jdbcType=BIGINT}"); + sql.VALUES("phone", "#{phone,jdbcType=VARCHAR}"); } if (record.getPassword() != null) { @@ -138,7 +138,7 @@ public class HighUserSqlProvider { } if (record.getPhone() != null) { - sql.SET("phone = #{record.phone,jdbcType=BIGINT}"); + sql.SET("phone = #{record.phone,jdbcType=VARCHAR}"); } if (record.getPassword() != null) { @@ -196,7 +196,7 @@ public class HighUserSqlProvider { sql.SET("id = #{record.id,jdbcType=BIGINT}"); sql.SET("header_img = #{record.headerImg,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("sex = #{record.sex,jdbcType=VARCHAR}"); sql.SET("birthdate = #{record.birthdate,jdbcType=DATE}"); @@ -227,7 +227,7 @@ public class HighUserSqlProvider { } if (record.getPhone() != null) { - sql.SET("phone = #{phone,jdbcType=BIGINT}"); + sql.SET("phone = #{phone,jdbcType=VARCHAR}"); } if (record.getPassword() != null) { diff --git a/hai-service/src/main/java/com/hai/entity/HighMerchant.java b/hai-service/src/main/java/com/hai/entity/HighMerchant.java index fc9cfa4b..1582b4c3 100644 --- a/hai-service/src/main/java/com/hai/entity/HighMerchant.java +++ b/hai-service/src/main/java/com/hai/entity/HighMerchant.java @@ -1,5 +1,7 @@ package com.hai.entity; +import com.hai.model.HighMerchantModel; + import java.io.Serializable; import java.util.Date; @@ -12,7 +14,7 @@ import java.util.Date; * 代码由工具生成 * **/ -public class HighMerchant implements Serializable { +public class HighMerchant extends HighMerchantModel implements Serializable { /** * 主键 */ @@ -341,4 +343,4 @@ public class HighMerchant implements Serializable { sb.append("]"); return sb.toString(); } -} \ No newline at end of file +} diff --git a/hai-service/src/main/java/com/hai/entity/HighMerchantStore.java b/hai-service/src/main/java/com/hai/entity/HighMerchantStore.java index aef4c02f..70f41dfa 100644 --- a/hai-service/src/main/java/com/hai/entity/HighMerchantStore.java +++ b/hai-service/src/main/java/com/hai/entity/HighMerchantStore.java @@ -1,5 +1,7 @@ package com.hai.entity; +import com.hai.model.HighMerchantStoreModel; + import java.io.Serializable; import java.util.Date; @@ -12,7 +14,7 @@ import java.util.Date; * 代码由工具生成 * **/ -public class HighMerchantStore implements Serializable { +public class HighMerchantStore extends HighMerchantStoreModel implements Serializable { /** * 主键 */ @@ -293,4 +295,4 @@ public class HighMerchantStore implements Serializable { sb.append("]"); return sb.toString(); } -} \ No newline at end of file +} diff --git a/hai-service/src/main/java/com/hai/entity/HighUser.java b/hai-service/src/main/java/com/hai/entity/HighUser.java index 885ed8a1..652345c4 100644 --- a/hai-service/src/main/java/com/hai/entity/HighUser.java +++ b/hai-service/src/main/java/com/hai/entity/HighUser.java @@ -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; } - public Long getPhone() { + public String getPhone() { return phone; } - public void setPhone(Long phone) { + public void setPhone(String phone) { this.phone = phone; } diff --git a/hai-service/src/main/java/com/hai/entity/HighUserExample.java b/hai-service/src/main/java/com/hai/entity/HighUserExample.java index ffe3f251..aa04d6a8 100644 --- a/hai-service/src/main/java/com/hai/entity/HighUserExample.java +++ b/hai-service/src/main/java/com/hai/entity/HighUserExample.java @@ -362,52 +362,62 @@ public class HighUserExample { return (Criteria) this; } - public Criteria andPhoneEqualTo(Long value) { + public Criteria andPhoneEqualTo(String value) { addCriterion("phone =", value, "phone"); return (Criteria) this; } - public Criteria andPhoneNotEqualTo(Long value) { + public Criteria andPhoneNotEqualTo(String value) { addCriterion("phone <>", value, "phone"); return (Criteria) this; } - public Criteria andPhoneGreaterThan(Long value) { + public Criteria andPhoneGreaterThan(String value) { addCriterion("phone >", value, "phone"); return (Criteria) this; } - public Criteria andPhoneGreaterThanOrEqualTo(Long value) { + public Criteria andPhoneGreaterThanOrEqualTo(String value) { addCriterion("phone >=", value, "phone"); return (Criteria) this; } - public Criteria andPhoneLessThan(Long value) { + public Criteria andPhoneLessThan(String value) { addCriterion("phone <", value, "phone"); return (Criteria) this; } - public Criteria andPhoneLessThanOrEqualTo(Long value) { + public Criteria andPhoneLessThanOrEqualTo(String value) { addCriterion("phone <=", value, "phone"); return (Criteria) this; } - public Criteria andPhoneIn(List 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 values) { addCriterion("phone in", values, "phone"); return (Criteria) this; } - public Criteria andPhoneNotIn(List values) { + public Criteria andPhoneNotIn(List values) { addCriterion("phone not in", values, "phone"); return (Criteria) this; } - public Criteria andPhoneBetween(Long value1, Long value2) { + public Criteria andPhoneBetween(String value1, String value2) { addCriterion("phone between", value1, value2, "phone"); return (Criteria) this; } - public Criteria andPhoneNotBetween(Long value1, Long value2) { + public Criteria andPhoneNotBetween(String value1, String value2) { addCriterion("phone not between", value1, value2, "phone"); return (Criteria) this; } diff --git a/hai-service/src/main/java/com/hai/model/HighMerchantModel.java b/hai-service/src/main/java/com/hai/model/HighMerchantModel.java new file mode 100644 index 00000000..17de7df4 --- /dev/null +++ b/hai-service/src/main/java/com/hai/model/HighMerchantModel.java @@ -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; + } +} diff --git a/hai-service/src/main/java/com/hai/model/HighMerchantStoreModel.java b/hai-service/src/main/java/com/hai/model/HighMerchantStoreModel.java new file mode 100644 index 00000000..efd93dc2 --- /dev/null +++ b/hai-service/src/main/java/com/hai/model/HighMerchantStoreModel.java @@ -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; + } +} diff --git a/hai-service/src/main/java/com/hai/model/HighUserModel.java b/hai-service/src/main/java/com/hai/model/HighUserModel.java new file mode 100644 index 00000000..d7d449b3 --- /dev/null +++ b/hai-service/src/main/java/com/hai/model/HighUserModel.java @@ -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; + } +} diff --git a/hai-service/src/main/java/com/hai/model/UserInfoModel.java b/hai-service/src/main/java/com/hai/model/UserInfoModel.java index 628d0f16..afcc0b94 100644 --- a/hai-service/src/main/java/com/hai/model/UserInfoModel.java +++ b/hai-service/src/main/java/com/hai/model/UserInfoModel.java @@ -26,6 +26,8 @@ public class UserInfoModel { private BsCompany bsCompany; // 商户 private HighMerchant merchant; + // 门店 + private HighMerchantStore merchantStore; // 权限列表 private List permissionList; // 菜单权限列表 @@ -35,14 +37,6 @@ public class UserInfoModel { private String token; - public HighMerchant getMerchant() { - return merchant; - } - - public void setMerchant(HighMerchant merchant) { - this.merchant = merchant; - } - public SecUser getSecUser() { return secUser; } @@ -75,6 +69,22 @@ public class UserInfoModel { 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 getPermissionList() { return permissionList; } @@ -99,7 +109,6 @@ public class UserInfoModel { this.buttonList = buttonList; } - public String getToken() { return token; } diff --git a/hai-service/src/main/java/com/hai/service/HighMerchantService.java b/hai-service/src/main/java/com/hai/service/HighMerchantService.java index 955494a1..340e3cfd 100644 --- a/hai-service/src/main/java/com/hai/service/HighMerchantService.java +++ b/hai-service/src/main/java/com/hai/service/HighMerchantService.java @@ -13,7 +13,7 @@ public interface HighMerchantService { /** * 编辑 */ - void editMerchant(HighMerchant highMerchant); + void editMerchant(HighMerchant highMerchant) throws Exception; /** * 根据id查询 diff --git a/hai-service/src/main/java/com/hai/service/HighMerchantStoreService.java b/hai-service/src/main/java/com/hai/service/HighMerchantStoreService.java index e83f4599..bc105f8f 100644 --- a/hai-service/src/main/java/com/hai/service/HighMerchantStoreService.java +++ b/hai-service/src/main/java/com/hai/service/HighMerchantStoreService.java @@ -17,7 +17,14 @@ public interface HighMerchantStoreService { * @Description 编辑门店 * @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 胡锐 diff --git a/hai-service/src/main/java/com/hai/service/HighUserService.java b/hai-service/src/main/java/com/hai/service/HighUserService.java index 79c29ce7..a4fceb05 100644 --- a/hai-service/src/main/java/com/hai/service/HighUserService.java +++ b/hai-service/src/main/java/com/hai/service/HighUserService.java @@ -14,6 +14,7 @@ import java.util.Map; */ public interface HighUserService { + /** * * @Title: getListUser @@ -38,6 +39,20 @@ public interface HighUserService { */ 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 diff --git a/hai-service/src/main/java/com/hai/service/SecUserService.java b/hai-service/src/main/java/com/hai/service/SecUserService.java index 769dfaab..12e9f4e0 100644 --- a/hai-service/src/main/java/com/hai/service/SecUserService.java +++ b/hai-service/src/main/java/com/hai/service/SecUserService.java @@ -200,4 +200,11 @@ public interface SecUserService { * @throws */ UserTreeModel findAttendUserTree(Long companyId, BsOrganization organization); + + /** + * @Author 胡锐 + * @Description 查询门店所有账号 + * @Date 2021/3/10 22:35 + **/ + List getMerchantStoreUser(Long merchantStoreId); } diff --git a/hai-service/src/main/java/com/hai/service/impl/HighMerchantServiceImpl.java b/hai-service/src/main/java/com/hai/service/impl/HighMerchantServiceImpl.java index 93fe1f8d..db2aa21b 100644 --- a/hai-service/src/main/java/com/hai/service/impl/HighMerchantServiceImpl.java +++ b/hai-service/src/main/java/com/hai/service/impl/HighMerchantServiceImpl.java @@ -1,14 +1,19 @@ package com.hai.service.impl; +import com.hai.common.utils.MD5Util; import com.hai.dao.HighMerchantMapper; import com.hai.entity.HighMerchant; import com.hai.entity.HighMerchantExample; +import com.hai.entity.SecUser; import com.hai.service.HighMerchantService; +import com.hai.service.SecUserService; import org.apache.commons.collections4.MapUtils; import org.apache.commons.lang3.StringUtils; import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; import javax.annotation.Resource; +import java.util.Date; import java.util.List; import java.util.Map; @@ -18,10 +23,26 @@ public class HighMerchantServiceImpl implements HighMerchantService { @Resource private HighMerchantMapper highMerchantMapper; + @Resource + private SecUserService secUserService; + @Override - public void editMerchant(HighMerchant highMerchant) { + @Transactional + public void editMerchant(HighMerchant highMerchant) throws Exception { if (highMerchant.getId() == null) { 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 { highMerchantMapper.updateByPrimaryKey(highMerchant); } diff --git a/hai-service/src/main/java/com/hai/service/impl/HighMerchantStoreServiceImpl.java b/hai-service/src/main/java/com/hai/service/impl/HighMerchantStoreServiceImpl.java index 28d8fccd..80df2aed 100644 --- a/hai-service/src/main/java/com/hai/service/impl/HighMerchantStoreServiceImpl.java +++ b/hai-service/src/main/java/com/hai/service/impl/HighMerchantStoreServiceImpl.java @@ -1,15 +1,23 @@ 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.entity.HighMerchantStore; import com.hai.entity.HighMerchantStoreExample; +import com.hai.entity.SecUser; import com.hai.service.HighMerchantStoreService; +import com.hai.service.SecUserService; import org.apache.commons.collections4.MapUtils; import org.apache.commons.lang3.StringUtils; import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; import javax.annotation.Resource; +import java.util.Date; import java.util.List; import java.util.Map; @@ -19,12 +27,46 @@ public class HighMerchantStoreServiceImpl implements HighMerchantStoreService { @Resource private HighMerchantStoreMapper highMerchantStoreMapper; + @Resource + private SecUserService secUserService; + @Override - public void editMerchantStore(HighMerchantStore highMerchantStore) { + @Transactional + public void editMerchantStore(HighMerchantStore highMerchantStore) throws Exception { if (highMerchantStore.getId() != null) { highMerchantStoreMapper.updateByPrimaryKey(highMerchantStore); } else { 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 userList = secUserService.getMerchantStoreUser(store.getId()); + for (SecUser user : userList) { + user.setStatus(0); // 删除 + secUserService.updateUser(user); } } diff --git a/hai-service/src/main/java/com/hai/service/impl/HighUserServiceImpl.java b/hai-service/src/main/java/com/hai/service/impl/HighUserServiceImpl.java index 08c6a3ff..a696c931 100644 --- a/hai-service/src/main/java/com/hai/service/impl/HighUserServiceImpl.java +++ b/hai-service/src/main/java/com/hai/service/impl/HighUserServiceImpl.java @@ -5,7 +5,6 @@ import com.hai.dao.HighUserMapper; import com.hai.entity.HighUser; import com.hai.entity.HighUserExample; import com.hai.service.HighUserService; -import com.sun.xml.bind.v2.model.core.ID; import org.apache.commons.lang3.StringUtils; import org.springframework.stereotype.Service; @@ -29,7 +28,7 @@ public class HighUserServiceImpl implements HighUserService { HighUserExample.Criteria criteria = example.createCriteria(); if (StringUtils.isNotBlank(map.get("phone"))) { - criteria.andPhoneEqualTo(Long.valueOf(map.get("phone"))); + criteria.andPhoneEqualTo(map.get("phone")); } if (StringUtils.isNotBlank(map.get("name"))) { criteria.andNameLike("%" + map.get("name") + "%"); @@ -52,6 +51,28 @@ public class HighUserServiceImpl implements HighUserService { return highUserMapper.selectByPrimaryKey(userId); } + @Override + public HighUser findByOpenId(String openId) { + HighUserExample example = new HighUserExample(); + example.createCriteria().andOpenIdEqualTo(openId); + List 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 list = highUserMapper.selectByExample(example); + if (list != null && list.size() > 0) { + return list.get(0); + } + return null; + } + @Override public void updateUser(HighUser highUser) { highUserMapper.updateByPrimaryKeySelective(highUser); diff --git a/hai-service/src/main/java/com/hai/service/impl/SecUserServiceImpl.java b/hai-service/src/main/java/com/hai/service/impl/SecUserServiceImpl.java index cbde1be3..dd10bf59 100644 --- a/hai-service/src/main/java/com/hai/service/impl/SecUserServiceImpl.java +++ b/hai-service/src/main/java/com/hai/service/impl/SecUserServiceImpl.java @@ -250,6 +250,13 @@ public class SecUserServiceImpl implements SecUserService { return userTreeModel; } + @Override + public List 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 organizations) { // 查询部门下员工