manailin
2022-06-28 dc8cd332896e040079c523b4f91aac1da474bcac
Merge remote-tracking branch 'remotes/origin/master_bug'
2个文件已修改
169 ■■■■■ 已修改文件
springcloud_k8s_panzhihuazhihuishequ/shop_backstage/src/main/java/com/panzhihua/shop_backstage/api/LoginApi.java 68 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
springcloud_k8s_panzhihuazhihuishequ/shop_backstage/src/main/java/com/panzhihua/shop_backstage/api/MicroCommercialStreetApi.java 101 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
springcloud_k8s_panzhihuazhihuishequ/shop_backstage/src/main/java/com/panzhihua/shop_backstage/api/LoginApi.java
@@ -2,8 +2,6 @@
import com.alibaba.fastjson.JSONObject;
import com.panzhihua.common.controller.BaseController;
import com.panzhihua.common.exceptions.ServiceException;
import com.panzhihua.common.interfaces.ShopOperLog;
import com.panzhihua.common.model.vos.LoginReturnVO;
import com.panzhihua.common.model.vos.LoginUserInfoVO;
import com.panzhihua.common.model.vos.R;
@@ -13,67 +11,49 @@
import com.panzhihua.common.service.auth.TokenService;
import com.panzhihua.common.service.community.CommunityService;
import com.panzhihua.common.service.user.UserService;
import com.panzhihua.shop_backstage.config.MyAESUtil;
import com.panzhihua.common.interfaces.ShopOperLog;
import com.panzhihua.shop_backstage.model.vos.LoginBody;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.util.ObjectUtils;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.time.Duration;
@Slf4j
@RestController
@RequestMapping("/")
@Api(tags = {"登录"})
public class LoginApi extends BaseController {
    private static String LOGIN_FAIL = "LOGIN_FAIL_";
    @Resource
    private TokenService tokenService;
    @Resource
    private UserService userService;
    @Resource
    private CommunityService communityService;
    @Resource
    private RedisTemplate redisTemplate;
    @ApiOperation(value = "商家后台登录", response = LoginReturnVO.class)
    @ShopOperLog(operType = 1)
    @PostMapping("login")
    public R login(@RequestBody LoginBody loginBody) {
    public R login(@RequestBody LoginBody loginBody){
        String account = loginBody.getAccount();
        String password = loginBody.getPassword();
        boolean empty = ObjectUtils.isEmpty(account);
        boolean empty1 = ObjectUtils.isEmpty(password);
        if (empty || empty1) {
        if (empty||empty1) {
            return R.fail("账户密码不能为空");
        }
        log.info("登录用户信息【{}】", loginBody);
        try {
            password = MyAESUtil.Decrypt(password, "Ryo7M3n8loC5Abcd");
        } catch (Exception e) {
            return R.fail("账号或密码错误!");
        }
        boolean flag = redisTemplate.hasKey(LOGIN_FAIL + account);
        log.info("登录用户信息【{}】",loginBody);
        try {
            R<ShopStoreVO> storeR = communityService.getUserStoreInfoByAccount(account);
            if (R.isOk(storeR)) {
                ShopStoreVO shopStoreVO =
                        JSONObject.parseObject(JSONObject.toJSONString(storeR.getData()), ShopStoreVO.class);
            if(R.isOk(storeR)) {
                ShopStoreVO shopStoreVO = JSONObject.parseObject(JSONObject.toJSONString(storeR.getData()), ShopStoreVO.class);
                Boolean accountValid = shopStoreVO.getStatus() == 1;
                if (accountValid) {
                    if (flag) {
                        Integer time = (Integer) redisTemplate.opsForValue().get(LOGIN_FAIL + account);
                        if (time >= 5) {
                            redisTemplate.opsForValue().set(LOGIN_FAIL + account, 5, Duration.ofMinutes(5));
                            throw new ServiceException("登录错误超过限制,请五分钟后重试");
                        }
                    }
                    R r = tokenService.loginShopBackStage(account, password);
                    return r;
                } else {
@@ -81,30 +61,18 @@
                }
            }
            return R.fail(storeR.getMsg());
        } catch (Exception e) {
            lockLogin(flag, account);
            return R.fail("账号或密码错误!");
        }catch (Exception e){
            return R.fail("登陆失败了");
        }
    }
    private void lockLogin(Boolean flag, String userName) {
        if (flag) {
            Integer time = (Integer) redisTemplate.opsForValue().get(LOGIN_FAIL + userName);
            redisTemplate.opsForValue().set(LOGIN_FAIL + userName, time + 1, Duration.ofMinutes(5));
        } else {
            redisTemplate.opsForValue().set(LOGIN_FAIL + userName, 1, Duration.ofMinutes(5));
        }
    }
    @ApiOperation(value = "修改密码")
    @PutMapping("changepassword")
    @ShopOperLog(operType = 2)
    public R changePassword(@Validated @RequestBody ChangePasswordVO changePasswordVO) {
    public R changePassword(@Validated @RequestBody ChangePasswordVO changePasswordVO){
        Long userId = this.getUserId();
        String newPassword = changePasswordVO.getNewPassword();
        String oldPassword = changePasswordVO.getOldPassword();
        String oldPassword=changePasswordVO.getOldPassword();
        if (newPassword.equals(oldPassword)) {
            return R.fail("修改失败,新密码和原密码一致");
        }
@@ -112,26 +80,24 @@
        return userService.changePassword(changePasswordVO);
    }
    @ApiOperation(value = "当前登录用户信息", response = LoginStoreUserInfoVO.class)
    @ApiOperation(value = "当前登录用户信息",response = LoginStoreUserInfoVO.class)
    @GetMapping("user")
    public R detailUser() {
    public R detailUser(){
        Long userId = this.getUserId();
        R<LoginUserInfoVO> loginUserInfoVOR = userService.detailUser(userId);
        try {
            LoginUserInfoVO loginUserInfoVO =
                    JSONObject.parseObject(JSONObject.toJSONString(loginUserInfoVOR.getData()), LoginUserInfoVO.class);
            LoginUserInfoVO loginUserInfoVO = JSONObject.parseObject(JSONObject.toJSONString(loginUserInfoVOR.getData()), LoginUserInfoVO.class);
            loginUserInfoVO.setPassword("******");
            R<ShopStoreVO> storeR = communityService.getUserStoreInfo(userId);
            LoginStoreUserInfoVO loginStoreUserInfoVO = new LoginStoreUserInfoVO();
            BeanUtils.copyProperties(loginUserInfoVO, loginStoreUserInfoVO);
            if (R.isOk(storeR) && storeR.getData() != null) {
                ShopStoreVO shopStoreVO =
                        JSONObject.parseObject(JSONObject.toJSONString(storeR.getData()), ShopStoreVO.class);
            if (R.isOk(storeR)&& storeR.getData()!=null) {
                ShopStoreVO shopStoreVO = JSONObject.parseObject(JSONObject.toJSONString(storeR.getData()), ShopStoreVO.class);
                loginStoreUserInfoVO.setStoreInfo(shopStoreVO);
            }
            return R.ok(loginStoreUserInfoVO);
        } catch (Exception e) {
        }catch (Exception e){
            e.printStackTrace();
            return R.fail("获取登陆商家用户信息失败");
        }
springcloud_k8s_panzhihuazhihuishequ/shop_backstage/src/main/java/com/panzhihua/shop_backstage/api/MicroCommercialStreetApi.java
@@ -1,79 +1,41 @@
package com.panzhihua.shop_backstage.api;
import static java.util.Objects.isNull;
import static java.util.Objects.nonNull;
import java.util.regex.Pattern;
import javax.annotation.Resource;
import javax.validation.Valid;
import org.springframework.beans.BeanUtils;
import org.springframework.util.ObjectUtils;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import com.alibaba.fastjson.JSONObject;
import com.panzhihua.common.controller.BaseController;
import com.panzhihua.common.model.dtos.community.microCommercialStreet.BindUserPhoneDTO;
import com.panzhihua.common.model.dtos.community.microCommercialStreet.DeleteProductDTO;
import com.panzhihua.common.model.dtos.community.microCommercialStreet.LoginWithPhoneDTO;
import com.panzhihua.common.model.dtos.community.microCommercialStreet.McsEvaluateDTO;
import com.panzhihua.common.model.dtos.community.microCommercialStreet.McsGameDTO;
import com.panzhihua.common.model.dtos.community.microCommercialStreet.McsInfoDTO;
import com.panzhihua.common.model.dtos.community.microCommercialStreet.McsMerchantDTO;
import com.panzhihua.common.model.dtos.community.microCommercialStreet.McsProductDTO;
import com.panzhihua.common.model.dtos.community.microCommercialStreet.PageJoinGameListDTO;
import com.panzhihua.common.model.dtos.community.microCommercialStreet.PageMcsEvaluateDTO;
import com.panzhihua.common.model.dtos.community.microCommercialStreet.PageMcsGameDTO;
import com.panzhihua.common.model.dtos.community.microCommercialStreet.PageMcsInformationDTO;
import com.panzhihua.common.model.dtos.community.microCommercialStreet.PageMcsMerchantDTO;
import com.panzhihua.common.model.dtos.community.microCommercialStreet.PageMcsProductDTO;
import com.panzhihua.common.model.dtos.community.microCommercialStreet.PageVerifyRecordDTO;
import com.panzhihua.common.model.dtos.community.microCommercialStreet.PutUserInfoDTO;
import com.panzhihua.common.model.dtos.community.microCommercialStreet.SetShelfForGameDTO;
import com.panzhihua.common.model.dtos.community.microCommercialStreet.SetShelfForInfoDTO;
import com.panzhihua.common.model.dtos.community.microCommercialStreet.SetShelfForProductDTO;
import com.panzhihua.common.exceptions.ServiceException;
import com.panzhihua.common.model.dtos.community.microCommercialStreet.*;
import com.panzhihua.common.model.vos.LoginReturnVO;
import com.panzhihua.common.model.vos.LoginUserInfoVO;
import com.panzhihua.common.model.vos.R;
import com.panzhihua.common.model.vos.community.microCommercialStreet.GameStatisticsVO;
import com.panzhihua.common.model.vos.community.microCommercialStreet.IndexTopStatisticsVO;
import com.panzhihua.common.model.vos.community.microCommercialStreet.McsConfigVO;
import com.panzhihua.common.model.vos.community.microCommercialStreet.McsCouponVO;
import com.panzhihua.common.model.vos.community.microCommercialStreet.McsEvaluateVO;
import com.panzhihua.common.model.vos.community.microCommercialStreet.McsGameVO;
import com.panzhihua.common.model.vos.community.microCommercialStreet.McsInformationVO;
import com.panzhihua.common.model.vos.community.microCommercialStreet.McsLabelVO;
import com.panzhihua.common.model.vos.community.microCommercialStreet.McsLoginUserInfoVO;
import com.panzhihua.common.model.vos.community.microCommercialStreet.McsMerchantVO;
import com.panzhihua.common.model.vos.community.microCommercialStreet.McsProductVO;
import com.panzhihua.common.model.vos.community.microCommercialStreet.McsVerifyRecordVO;
import com.panzhihua.common.model.vos.community.microCommercialStreet.MyCouponVO;
import com.panzhihua.common.model.vos.community.microCommercialStreet.TopStatisticsVO;
import com.panzhihua.common.model.vos.community.microCommercialStreet.VerifiedReturnVO;
import com.panzhihua.common.model.vos.community.microCommercialStreet.*;
import com.panzhihua.common.service.auth.TokenService;
import com.panzhihua.common.service.community.CommunityService;
import com.panzhihua.common.service.user.UserService;
import com.panzhihua.common.validated.AddGroup;
import com.panzhihua.common.validated.PutGroup;
import com.panzhihua.shop_backstage.aop.CheckMcsMerchantExpiration;
import com.panzhihua.shop_backstage.config.MyAESUtil;
import com.panzhihua.shop_backstage.config.WxMaConfiguration;
import com.panzhihua.shop_backstage.model.request.LoginRequest;
import com.panzhihua.shop_backstage.model.vos.LoginBody;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.util.ObjectUtils;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import javax.validation.Valid;
import java.time.Duration;
import java.util.regex.Pattern;
import static java.util.Objects.isNull;
import static java.util.Objects.nonNull;
/**
 * @title: MicroCommercialStreetApi
@@ -88,6 +50,7 @@
@Slf4j
public class MicroCommercialStreetApi extends BaseController {
    private static String LOGIN_FAIL = "LOGIN_FAIL_";
    @Resource
    private CommunityService communityService;
    @Resource
@@ -96,6 +59,8 @@
    private UserService userService;
    @Resource
    private WxMaConfiguration wxMaConfiguration;
    @Resource
    private RedisTemplate redisTemplate;
    @ApiOperation(value = "H5授权登录", response = LoginReturnVO.class)
    @PostMapping("/auth/login")
@@ -159,7 +124,14 @@
    @PostMapping("/merchant/login")
    public R merchantLogin(@RequestBody @Valid LoginBody loginBody) {
        String account = loginBody.getAccount();
        String password = loginBody.getPassword();
        log.info("登录用户信息【{}】", loginBody);
        try {
            password = MyAESUtil.Decrypt(loginBody.getPassword(), "Ryo7M3n8loC5Abcd");
        } catch (Exception e) {
            return R.fail("账号或密码错误!");
        }
        boolean flag = redisTemplate.hasKey(LOGIN_FAIL + account);
        try {
            R r = communityService.getMcsMerchantByAccount(account);
            Boolean isValid = false;
@@ -167,7 +139,14 @@
                McsMerchantVO merchantVO = JSONObject.parseObject(JSONObject.toJSONString(r.getData()), McsMerchantVO.class);
                isValid = merchantVO.getAccountStatus() == 1;
                if (isValid) {
                    R result = tokenService.loginMcsUser(account, loginBody.getPassword());
                    if (flag) {
                        Integer time = (Integer) redisTemplate.opsForValue().get(LOGIN_FAIL + account);
                        if (time >= 5) {
                            redisTemplate.opsForValue().set(LOGIN_FAIL + account, 5, Duration.ofMinutes(5));
                            throw new ServiceException("登录错误超过限制,请五分钟后重试");
                        }
                    }
                    R result = tokenService.loginMcsUser(account, password);
                    return result;
                } else {
                    return R.fail("账号被禁用");
@@ -175,10 +154,20 @@
            }
            return R.fail(r.getMsg());
        } catch (Exception e) {
            lockLogin(flag, account);
            return R.fail("登陆失败了");
        }
    }
    private void lockLogin(Boolean flag, String userName) {
        if (flag) {
            Integer time = (Integer) redisTemplate.opsForValue().get(LOGIN_FAIL + userName);
            redisTemplate.opsForValue().set(LOGIN_FAIL + userName, time + 1, Duration.ofMinutes(5));
        } else {
            redisTemplate.opsForValue().set(LOGIN_FAIL + userName, 1, Duration.ofMinutes(5));
        }
    }
    @ApiOperation(value = "微商业街用户登录", response = LoginReturnVO.class)
    @PostMapping("/loginWithPhone")
    public R loginWithPhone(@RequestBody @Valid LoginWithPhoneDTO loginDTO) {