Browse Source

正品联盟后台part5

Aslee 4 years ago
parent
commit
0b0ab56b7a

+ 5 - 14
src/main/java/com/caimei/controller/DefaultApi.java

@@ -2,6 +2,8 @@ package com.caimei.controller;
 
 import com.caimei.module.base.entity.bo.JsonModel;
 import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiModelProperty;
+import io.swagger.annotations.ApiOperation;
 import org.springframework.web.bind.annotation.GetMapping;
 import org.springframework.web.bind.annotation.PostMapping;
 import org.springframework.web.bind.annotation.RestController;
@@ -16,30 +18,19 @@ import org.springframework.web.bind.annotation.RestController;
 @Api(tags = "默认API")
 public class DefaultApi {
     @GetMapping("/")
+    @ApiOperation("欢迎页")
     public String welcome(){
-        //return "欢迎使用!《采美365网》! <br><a href='swagger-ui.html'>swagger接口文档入口</a>";
         return "欢迎使用!《正品联盟后台》!";
     }
-    /**
-     * 刷新token, 供旧系统调用
-     */
-    @PostMapping("/token/refresh")
-    public String tokenRefresh() {
-        return "刷新Token成功!";
-    }
 
-    /**
-     * Token失效
-     */
     @GetMapping("/unauthorized")
+    @ApiOperation("Token失效")
     public JsonModel unauthorized() {
         return new JsonModel().error(-99, "Token失效请重新登录!");
     }
 
-    /**
-     * 处理非法请求
-     */
     @GetMapping("/error")
+    @ApiOperation("处理非法请求")
     public JsonModel error() {
         return new JsonModel().error(-100, "非法的请求!");
     }

+ 1 - 1
src/main/java/com/caimei/controller/ShopApi.java

@@ -124,7 +124,7 @@ public class ShopApi {
      *
      * @param authUserId:供应商用户id
      * @param file:代理声明文件
-     * @return
+     * @return Integer
      */
     @ApiOperation("代理声明文件上传")
     @ApiImplicitParams({

+ 0 - 1
src/main/java/com/caimei/controller/UserApi.java

@@ -6,7 +6,6 @@ import com.caimei.model.vo.UserLoginVo;
 import com.caimei.service.UserService;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiImplicitParam;
-import io.swagger.annotations.ApiImplicitParams;
 import io.swagger.annotations.ApiOperation;
 import lombok.RequiredArgsConstructor;
 import org.springframework.web.bind.annotation.*;

+ 2 - 0
src/main/java/com/caimei/mapper/ShopMapper.java

@@ -52,4 +52,6 @@ public interface ShopMapper {
     List<BrandVo> getBrandList(Integer type);
 
     List<CountryVo> getCountryList();
+
+    Integer getUserIdByMobile(String mobile);
 }

+ 4 - 4
src/main/java/com/caimei/service/impl/AuthProductServiceImpl.java

@@ -87,20 +87,20 @@ public class AuthProductServiceImpl implements AuthProductService {
         if (null == authId) {
             return ResponseJson.error("参数异常,请输入授权id", null);
         }
-        if (StringUtils.isEmpty(productName)) {
+        if (StringUtils.isBlank(productName)) {
             return ResponseJson.error("参数异常,请输入商品名称", null);
         }
-        if (StringUtils.isEmpty(snCode)) {
+        if (StringUtils.isBlank(snCode)) {
             return ResponseJson.error("参数异常,请输入商品SN码", null);
         }
         Integer productIdBySnCode = authProductMapper.getProductIdBySnCode(snCode);
         if (null != productIdBySnCode && !productIdBySnCode.equals(productId)) {
             return ResponseJson.error("参数异常,该商品SN码已存在,请重新输入", null);
         }
-        if (StringUtils.isEmpty(productImage)) {
+        if (StringUtils.isBlank(productImage)) {
             return ResponseJson.error("参数异常,请上传商品图片", null);
         }
-        if (StringUtils.isEmpty(certificateImage)) {
+        if (StringUtils.isBlank(certificateImage)) {
             return ResponseJson.error("参数异常,请上传授权牌照", null);
         }
         if (null == status) {

+ 1 - 1
src/main/java/com/caimei/service/impl/AuthServiceImpl.java

@@ -89,7 +89,7 @@ public class AuthServiceImpl implements AuthService {
         if (null == authUserId) {
             return ResponseJson.error("参数异常,请输入供应商用户id");
         }
-        if (StringUtils.isEmpty(authParty)) {
+        if (StringUtils.isBlank(authParty)) {
             return ResponseJson.error("参数异常,请输入授权机构名称");
         }
         if (null == status) {

+ 23 - 10
src/main/java/com/caimei/service/impl/ShopServiceImpl.java

@@ -1,5 +1,6 @@
 package com.caimei.service.impl;
 
+import com.caimei.components.RedisService;
 import com.caimei.mapper.ShopMapper;
 import com.caimei.mapper.UserMapper;
 import com.caimei.model.ResponseJson;
@@ -12,18 +13,17 @@ import com.caimei.model.vo.CountryVo;
 import com.caimei.model.vo.ShopFormVo;
 import com.caimei.model.vo.ShopListVo;
 import com.caimei.service.ShopService;
-import com.caimei.utils.AliyunSmsUtil;
-import com.caimei.utils.CodeUtil;
-import com.caimei.utils.Md5Util;
-import com.caimei.utils.OSSUtils;
+import com.caimei.utils.*;
 import com.github.pagehelper.PageHelper;
 import com.github.pagehelper.PageInfo;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.codec.digest.DigestUtils;
+import org.apache.commons.lang3.StringUtils;
 import org.springframework.stereotype.Service;
 import org.springframework.web.multipart.MultipartFile;
 
 import javax.annotation.Resource;
+import javax.servlet.http.HttpServletRequest;
 import java.io.File;
 import java.io.FileInputStream;
 import java.util.Date;
@@ -80,10 +80,10 @@ public class ShopServiceImpl implements ShopService {
         String md5Password = Md5Util.md5(newPassword);
         userMapper.updatePasswordByUserId(authUserId, md5Password);
         String mobile = shopMapper.getShopMobileByUserId(authUserId);
-        boolean smsFlag = AliyunSmsUtil.sendSms(mobile, 14, "{code:" + newPassword + "}");
+        boolean smsFlag = AliyunSmsUtil.sendSms(mobile, 14, "{password:\"" + newPassword + "\"}");
         if (!smsFlag) {
             // 短信发送失败重试一次
-            AliyunSmsUtil.sendSms(mobile, 14, "{code:" + newPassword + "}");
+            AliyunSmsUtil.sendSms(mobile, 14, "{password:\"" + newPassword + "\"}");
         }
         log.info("正品联盟后台供应商重置密码,用户id:" + authUserId + ",新密码:" + newPassword);
         return ResponseJson.success("密码重置成功");
@@ -157,6 +157,18 @@ public class ShopServiceImpl implements ShopService {
         }
         // 是否为添加操作
         boolean insertFlag = null == shopSaveDto.getAuthUserId();
+        // 手机号
+        String mobile = shopSaveDto.getMobile();
+        if (StringUtils.isBlank(mobile)) {
+            return ResponseJson.error("参数异常,请输入手机号");
+        }
+        if (insertFlag) {
+            // 添加时验证手机号是否已被使用
+            Integer userIdByMobile = shopMapper.getUserIdByMobile(mobile);
+            if (null != userIdByMobile) {
+                return ResponseJson.error("该手机号已被使用,请重新输入", null);
+            }
+        }
         // 更新品牌授权logo
         shopMapper.updateBrandAuthLogo(shopSaveDto.getBrandId(),shopSaveDto.getBrandAuthLogo());
         /*
@@ -179,13 +191,14 @@ public class ShopServiceImpl implements ShopService {
             // 创建时间
             shop.setCreateTime(new Date());
             // 设置随机8位密码
-            String password = Md5Util.md5(CodeUtil.generateCode(8));
-            shop.setPassword(password);
+            String password = CodeUtil.generateCode(8);
+            String md5Pwd = Md5Util.md5(password);
+            shop.setPassword(md5Pwd);
             // 发送短信
-            boolean smsFlag = AliyunSmsUtil.sendSms(shopSaveDto.getMobile(), 14, "{code:" + password + "}");
+            boolean smsFlag = AliyunSmsUtil.sendSms(shopSaveDto.getMobile(), 14, "{password:\"" + password + "\"}");
             if (!smsFlag) {
                 // 短信发送失败重试一次
-                AliyunSmsUtil.sendSms(shopSaveDto.getMobile(), 14, "{code:" + password + "}");
+                AliyunSmsUtil.sendSms(shopSaveDto.getMobile(), 14, "{password:\"" + password + "\"}");
             }
             // 插入供应商用户
             shopMapper.insertShop(shop);

+ 19 - 5
src/main/java/com/caimei/service/impl/UserServiceImpl.java

@@ -11,8 +11,11 @@ import com.caimei.utils.Md5Util;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.lang3.StringUtils;
 import org.springframework.stereotype.Service;
+import org.springframework.web.context.request.RequestContextHolder;
+import org.springframework.web.context.request.ServletRequestAttributes;
 
 import javax.annotation.Resource;
+import javax.servlet.http.HttpServletRequest;
 
 /**
  * Description
@@ -37,10 +40,10 @@ public class UserServiceImpl implements UserService {
      */
     @Override
     public ResponseJson<UserLoginVo> passwordLogin(String mobileOrName, String password) {
-        if (StringUtils.isEmpty(mobileOrName)) {
+        if (StringUtils.isBlank(mobileOrName)) {
             return ResponseJson.error("请填写账户名", null);
         }
-        if (StringUtils.isEmpty(password)) {
+        if (StringUtils.isBlank(password)) {
             return ResponseJson.error("请填写密码", null);
         }
         // 根据账户名和手机号获取管理员账号和供应商账号
@@ -77,17 +80,26 @@ public class UserServiceImpl implements UserService {
         String oldPassword = passwordDto.getOldPassword();
         String newPassword = passwordDto.getNewPassword();
         String confirmPwd = passwordDto.getConfirmPwd();
+        // 获取登录用户的用户id
+        ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
+        HttpServletRequest request = attributes.getRequest();
+        String token = request.getHeader("X-Token");
+        String cacheToken = null!=token ? String.valueOf(redisService.get(token)) : null;
+        int loginUserId = JwtUtil.parseTokenUid(cacheToken);
+        if (loginUserId != authUserId) {
+            return ResponseJson.error("修改失败,只能修改自己账户的密码!");
+        }
         // 参数校验
         if (authUserId == null) {
             return ResponseJson.error("用户id不能为空");
         }
-        if (StringUtils.isEmpty(oldPassword)) {
+        if (StringUtils.isBlank(oldPassword)) {
             return ResponseJson.error("请输入旧密码");
         }
-        if (StringUtils.isEmpty(newPassword)) {
+        if (StringUtils.isBlank(newPassword)) {
             return ResponseJson.error("请输入新密码");
         }
-        if (StringUtils.isEmpty(confirmPwd)) {
+        if (StringUtils.isBlank(confirmPwd)) {
             return ResponseJson.error("请确认密码");
         }
         if (!newPassword.equals(confirmPwd)) {
@@ -102,6 +114,8 @@ public class UserServiceImpl implements UserService {
         // 更新密码
         newPassword = Md5Util.md5(newPassword);
         userMapper.updatePasswordByUserId(authUserId, newPassword);
+        // 清除token
+        // redisService.remove();
         return ResponseJson.success("密码修改成功");
     }
 

+ 1 - 1
src/main/java/com/caimei/utils/AliyunSmsUtil.java

@@ -77,7 +77,7 @@ public class AliyunSmsUtil {
             // 模版内容: 您正在更换联系人手机号,您的验证码为:${code}。
             templateCode = "SMS_205435893";
         } else if (type == 14) {
-            // 模版内容: 您正品联盟管理系统登录密码为:${code}。
+            // 模版内容: 您正品联盟登录密码为:${password}。
             templateCode = "SMS_217145278";
         }
         try {

+ 3 - 0
src/main/resources/mapper/ShopMapper.xml

@@ -156,4 +156,7 @@
         from country
         where validFlag = 1
     </select>
+    <select id="getUserIdByMobile" resultType="java.lang.Integer">
+        select authUserId from cm_brand_auth_user where mobile = #{mobile} and userIdentity = 2
+    </select>
 </mapper>