From 262cdc113a44bbd51f98a56ce91966dc7b2ea938 Mon Sep 17 00:00:00 2001 From: puhanshu <a9236326> Date: 星期六, 08 一月 2022 17:55:25 +0800 Subject: [PATCH] 数字商业街代码提交 --- springcloud_k8s_panzhihuazhihuishequ/service_user/src/main/java/com/panzhihua/service_user/service/impl/UserServiceImpl.java | 76 +++++++++++++++++++++++++++++++++++-- 1 files changed, 71 insertions(+), 5 deletions(-) diff --git a/springcloud_k8s_panzhihuazhihuishequ/service_user/src/main/java/com/panzhihua/service_user/service/impl/UserServiceImpl.java b/springcloud_k8s_panzhihuazhihuishequ/service_user/src/main/java/com/panzhihua/service_user/service/impl/UserServiceImpl.java index dfed62b..29f7924 100644 --- a/springcloud_k8s_panzhihuazhihuishequ/service_user/src/main/java/com/panzhihua/service_user/service/impl/UserServiceImpl.java +++ b/springcloud_k8s_panzhihuazhihuishequ/service_user/src/main/java/com/panzhihua/service_user/service/impl/UserServiceImpl.java @@ -10,13 +10,14 @@ import java.util.HashSet; import java.util.List; import java.util.Map; +import java.util.Random; import java.util.Set; +import java.util.concurrent.TimeUnit; import java.util.stream.Collectors; import javax.annotation.Resource; -import javax.validation.constraints.NotBlank; -import com.panzhihua.common.model.dtos.community.microCommercialStreet.McsMerchantDTO; +import com.panzhihua.common.model.vos.community.microCommercialStreet.McsLoginUserInfoVO; import org.apache.commons.lang.time.DateFormatUtils; import org.apache.commons.lang.time.DateUtils; import org.springframework.beans.BeanUtils; @@ -41,6 +42,7 @@ import com.panzhihua.common.model.dtos.community.NoticeReadDTO; import com.panzhihua.common.model.dtos.community.convenient.ConvenientMerchantDTO; import com.panzhihua.common.model.dtos.community.convenient.DisableOrEnableConvenientMerchantDTO; +import com.panzhihua.common.model.dtos.community.microCommercialStreet.McsMerchantDTO; import com.panzhihua.common.model.dtos.grid.EventGridMemberAddDTO; import com.panzhihua.common.model.dtos.grid.EventGridMemberEditAdminDTO; import com.panzhihua.common.model.dtos.grid.EventGridMemberEditStatusDTO; @@ -84,6 +86,7 @@ import com.panzhihua.common.model.vos.user.UserPhoneVO; import com.panzhihua.common.utlis.IdCard; import com.panzhihua.common.utlis.SensitiveUtil; +import com.panzhihua.common.utlis.SmsUtil; import com.panzhihua.common.utlis.Snowflake; import com.panzhihua.common.utlis.StringUtils; import com.panzhihua.common.utlis.WxUtil; @@ -2827,14 +2830,25 @@ sysUserDO.setStatus(mcsMerchantDTO.getAccountStatus()); sysUserDO.setPhone(mcsMerchantDTO.getPhone()); sysUserDO.setPassword(encode); + sysUserDO.setPlaintextPassword(mcsMerchantDTO.getPassword()); try { userDao.insert(sysUserDO); - return R.ok(sysUserDO.getUserId()); + McsLoginUserInfoVO loginUserInfoVO = new McsLoginUserInfoVO(); + BeanUtils.copyProperties(sysUserDO, loginUserInfoVO); + return R.ok(loginUserInfoVO); } catch (Exception e) { e.printStackTrace(); - log.error("新增后台用户报错【{}】", e.getMessage()); + log.error("修改数字商业街商家用户报错【{}】", e.getMessage()); + if (e.getMessage().contains("union_phone_type")) { + return R.fail("手机号已存在"); + } else if (e.getMessage().contains("union_account_type")) { + return R.fail("账户已经存在"); + }else if(e.getMessage().contains("23000")){ + return R.fail("手机号已存在"); + } else { + return R.fail("账户或手机号已存在,请重新填写尝试"); + } } - return R.fail("新增商户发生错误"); } /** @@ -2892,4 +2906,56 @@ } return true; } + + /** + * 根据手机号、用户类型查询用户 + * @param phone + * @param type + * @return + */ + @Override + public R getSysUserByPhone(String phone, Integer type) { + SysUserDO sysUserDO = userDao.selectOne(new QueryWrapper<SysUserDO>().lambda().eq(SysUserDO::getPhone, phone).eq(SysUserDO::getType, type)); + McsLoginUserInfoVO loginUserInfoVO = null; + if (nonNull(sysUserDO)) { + loginUserInfoVO = new McsLoginUserInfoVO(); + BeanUtils.copyProperties(sysUserDO, loginUserInfoVO); + } + return R.ok(loginUserInfoVO); + } + + /** + * 发送验证码登录 + * @param phone 手机号 + * @param clientIP 用户ip + * @param prefixKey redis Key 前缀 + * @param limit 获取次数限制 + * @param timeout 超次数获取时间等待 + * @return + */ + @Override + public R sendMessageCodeForLogin(String phone, String clientIP, String prefixKey, Integer limit, Integer timeout) { + ValueOperations<String, String> opsForValue = stringRedisTemplate.opsForValue(); + if (isNotBlank(clientIP)) { + String redisKey = String.join("::", prefixKey, clientIP); + Long increment = opsForValue.increment(redisKey, 1); + if (increment > limit) { + return R.fail("请求频繁,请稍后再试"); + } + stringRedisTemplate.expire(redisKey, timeout, TimeUnit.SECONDS); + } + Random r = new Random(); + StringBuilder rs = new StringBuilder(); + for (int i = 0; i < 5; i++) { + rs.append(r.nextInt(10)); + } + String code = rs.toString(); + int result = SmsUtil.sendCode(phone, code); + if (result == 1) { + String codeKey = String.join("::", phone, code); + opsForValue.set(codeKey, code, timeout, TimeUnit.SECONDS); + return R.ok(); + } + return R.fail(); + } } -- Gitblit v1.7.1