Ver Fonte

正品联盟part7

Aslee há 4 anos atrás
pai
commit
0df98f0cd9

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

@@ -80,6 +80,7 @@ public class AuthProductApi {
      * @param productSaveDto {
      *                   productId              授权商品id
      *                   authId                 授权id
+     *                   brandId                品牌id
      *                   productName            商品名称
      *                   snCode                 商品SN码
      *                   productImage           商品图片

+ 94 - 29
src/main/java/com/caimei/controller/ShopApi.java

@@ -1,11 +1,11 @@
 package com.caimei.controller;
 
+import com.alibaba.fastjson.JSONObject;
 import com.caimei.model.ResponseJson;
+import com.caimei.model.dto.ShopInfoDto;
 import com.caimei.model.dto.ShopSaveDto;
-import com.caimei.model.vo.BrandVo;
-import com.caimei.model.vo.CountryVo;
-import com.caimei.model.vo.ShopFormVo;
-import com.caimei.model.vo.ShopListVo;
+import com.caimei.model.po.ShopInfoPo;
+import com.caimei.model.vo.*;
 import com.caimei.service.ShopService;
 import com.github.pagehelper.PageInfo;
 import io.swagger.annotations.Api;
@@ -14,9 +14,11 @@ import io.swagger.annotations.ApiImplicitParams;
 import io.swagger.annotations.ApiOperation;
 import lombok.RequiredArgsConstructor;
 import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.lang3.StringUtils;
 import org.springframework.web.bind.annotation.*;
 import org.springframework.web.multipart.MultipartFile;
 
+import java.util.ArrayList;
 import java.util.List;
 import java.util.Map;
 
@@ -71,28 +73,85 @@ public class ShopApi {
 
     /**
      * 添加供应商
-     * @param shopSaveDto {
-     *                   shopType           供应商类型:1代理商,2品牌方
-     *                   brandId            品牌id
-     *                   shopName           供应商名称
-     *                   mobile             手机号
-     *                   linkMan            联系人
-     *                   countryId          产地国家id
-     *                   brandAuthLogo      品牌授权logo
-     *                   shopStatus         供应商状态:0停用 1启用
-     *                   securityLink       官网认证链接
-     *                   statementType      代理声明类型:1弹窗 2链接 3图片 4文件(.doc .ppt .pdf)
-     *                   statementContent   声明弹窗内容
-     *                   statementLink      声明链接
-     *                   statementImage     声明图片
-     *                   statementFileId    声明文件id
-     *                   createBy           创建人用户id
-     * }
+     *
+     * @param params {
+     *                    authUserId         供应商用户id
+     *                    shopType           供应商类型:1代理商,2品牌方
+     *                    shopName           供应商名称
+     *                    mobile             手机号
+     *                    linkMan            联系人
+     *                    shopStatus         供应商状态:0停用 1启用
+     *                    createBy           创建人用户id
+     *                    shopInfo  [
+     *                                  {
+     *                                      brandId            品牌id
+     *                                      countryId          产地国家id
+     *                                      brandAuthLogo      品牌授权logo
+     *                                      securityLink       官网认证链接
+     *                                      statementType      代理声明类型:1弹窗 2链接 3图片 4文件(.doc .ppt .pdf)
+     *                                      statementContent   声明弹窗内容
+     *                                      statementLink      声明链接
+     *                                      statementImage     声明图片
+     *                                      statementFileId    声明文件id
+     *                                  }
+     *                              ]
+     *                    }
      */
     @ApiOperation("添加/编辑供应商")
+    @ApiImplicitParam(name = "params", value = "authUserId:供应商用户id;", required = true)
     @PostMapping("/save")
-    public ResponseJson saveShop(@RequestBody ShopSaveDto shopSaveDto) {
-        return shopService.saveShop(shopSaveDto);
+    public ResponseJson saveShop(@RequestBody String params) {
+        JSONObject paramsMap = JSONObject.parseObject(params);
+        Integer authUserId = paramsMap.getInteger("authUserId");
+        Integer shopType = paramsMap.getInteger("shopType");
+        if (null == shopType) {
+            return ResponseJson.error("请选择供应商类型", null);
+        }
+        String shopName = paramsMap.getString("shopName");
+        String mobile = paramsMap.getString("mobile");
+        if (StringUtils.isBlank(mobile)) {
+            return ResponseJson.error("参数异常,请输入手机号");
+        }
+        String linkMan = paramsMap.getString("linkMan");
+        if (StringUtils.isBlank(mobile)) {
+            return ResponseJson.error("参数异常,请输入联系人");
+        }
+        Integer shopStatus = paramsMap.getInteger("shopStatus");
+        if (null == shopStatus) {
+            return ResponseJson.error("参数异常,请输入供应商状态");
+        }
+        Integer createBy = paramsMap.getInteger("createBy");
+        List<Map<String, Object>> shopInfoData = (List<Map<String, Object>>) paramsMap.get("shopInfo");
+        if (null == shopInfoData || shopInfoData.size() <= 0) {
+            return ResponseJson.error("参数异常,请输入供应商信息");
+        }
+        List<ShopInfoDto> shopInfoList = new ArrayList<>();
+        for (Map<String, Object> infoMap : shopInfoData) {
+            Integer brandId = (Integer) infoMap.get("brandId");
+            Integer countryId = (Integer) infoMap.get("countryId");
+            String brandAuthLogo = (String) infoMap.get("brandAuthLogo");
+            String securityLink = (String) infoMap.get("securityLink");
+            Integer statementType = (Integer) infoMap.get("statementType");
+            String statementContent = (String) infoMap.get("statementContent");
+            String statementLink = (String) infoMap.get("statementLink");
+            String statementImage = (String) infoMap.get("statementImage");
+            Integer statementFileId = (Integer) infoMap.get("statementFileId");
+            if (null == brandId || null == countryId || StringUtils.isEmpty(brandAuthLogo) || null == statementType) {
+                return ResponseJson.error("参数异常,供应商信息数据异常");
+            }
+            ShopInfoDto shopInfo = new ShopInfoDto();
+            shopInfo.setBrandId(brandId);
+            shopInfo.setCountryId(countryId);
+            shopInfo.setBrandAuthLogo(brandAuthLogo);
+            shopInfo.setSecurityLink(securityLink);
+            shopInfo.setStatementType(statementType);
+            shopInfo.setStatementContent(statementContent);
+            shopInfo.setStatementLink(statementLink);
+            shopInfo.setStatementImage(statementImage);
+            shopInfo.setStatementFileId(statementFileId);
+            shopInfoList.add(shopInfo);
+        }
+        return shopService.saveShop(authUserId, shopType, shopName, mobile, linkMan, shopStatus, createBy, shopInfoList);
     }
 
     /**
@@ -123,29 +182,35 @@ public class ShopApi {
      * 代理声明文件上传
      *
      * @param authUserId:供应商用户id
+     * @param brandId:品牌id
      * @param file:代理声明文件
      * @return Integer
      */
     @ApiOperation("代理声明文件上传")
     @ApiImplicitParams({
             @ApiImplicitParam(name = "authUserId", required = false, value = "供应商用户id"),
+            @ApiImplicitParam(name = "brandId", required = false, value = "品牌id"),
             @ApiImplicitParam(name = "file", required = false, value = "代理声明文件"),
     })
     @PostMapping("/upload/file")
-    public ResponseJson<Integer> uploadFile(Integer authUserId, MultipartFile file) {
-        return shopService.uploadFile(authUserId, file);
+    public ResponseJson<Integer> uploadFile(Integer authUserId, Integer brandId, MultipartFile file) {
+        return shopService.uploadFile(authUserId, brandId, file);
     }
 
     /**
      * 品牌列表
-     * @param type 1品牌方品牌列表,2代理商品牌列表
+     *
+     * @param type 1品牌方可用品牌列表,2代理商可用品牌列表,3供应商可用品牌列表
      * @return AuthVo
      */
     @ApiOperation("品牌列表")
-    @ApiImplicitParam(name = "type", value = "1品牌方品牌列表,2代理商品牌列表", required = true)
+    @ApiImplicitParams({
+            @ApiImplicitParam(name = "type", value = "1品牌方品牌列表,2代理商品牌列表,3供应商可用品牌列表", required = true),
+            @ApiImplicitParam(name = "authUserId", value = "供应商用户id", required = false)
+    })
     @GetMapping("/brand/list")
-    public ResponseJson<List<BrandVo>> getBrandList(Integer type){
-        return shopService.getBrandList(type);
+    public ResponseJson<List<BrandVo>> getBrandList(Integer type, Integer authUserId) {
+        return shopService.getBrandList(type, authUserId);
     }
 
     /**

+ 13 - 10
src/main/java/com/caimei/mapper/ShopMapper.java

@@ -1,12 +1,9 @@
 package com.caimei.mapper;
 
+import com.caimei.model.dto.ShopInfoDto;
 import com.caimei.model.po.CmBrandAuthFilePo;
-import com.caimei.model.po.ShopInfoPo;
 import com.caimei.model.po.UserPo;
-import com.caimei.model.vo.BrandVo;
-import com.caimei.model.vo.CountryVo;
-import com.caimei.model.vo.ShopFormVo;
-import com.caimei.model.vo.ShopListVo;
+import com.caimei.model.vo.*;
 import org.apache.ibatis.annotations.Mapper;
 import org.apache.ibatis.annotations.Param;
 
@@ -41,17 +38,23 @@ public interface ShopMapper {
 
     void updateFileUserId(@Param("statementFileId") Integer statementFileId,@Param("authUserId") Integer authUserId);
 
-    void insertShopInfo(ShopInfoPo shopInfo);
+    void insertShopInfo(ShopInfoDto shopInfo);
 
     void updateShopByUserId(UserPo shop);
 
-    void updateShopInfoByUserId(ShopInfoPo shopInfo);
+    ShopFormVo getShopByUserId(Integer authUserId);
 
-    ShopFormVo getShopByAuthUserId(Integer authUserId);
-
-    List<BrandVo> getBrandList(Integer type);
+    List<BrandVo> getBrandList(@Param("type") Integer type,@Param("authUserId") Integer authUserId);
 
     List<CountryVo> getCountryList();
 
     Integer getUserIdByMobile(String mobile);
+
+    List<ShopBrandVo> getDbInfoBrandList(Integer authUserId);
+
+    void deleteShopInfoById(Integer infoId);
+
+    void updateShopInfo(ShopInfoDto shopInfoVo);
+
+    List<ShopInfoVo> getShopInfoByUserId(Integer authUserId);
 }

+ 4 - 0
src/main/java/com/caimei/model/dto/ProductSaveDto.java

@@ -25,6 +25,10 @@ public class ProductSaveDto {
     @ApiModelProperty("授权id")
     private Integer authId;
 
+    @NotNull(message = "品牌id不能为空")
+    @ApiModelProperty("品牌id")
+    private Integer brandId;
+
     @NotNull(message = "商品名称不能为空")
     @ApiModelProperty("商品名称")
     private String productName;

+ 62 - 0
src/main/java/com/caimei/model/dto/ShopInfoDto.java

@@ -0,0 +1,62 @@
+package com.caimei.model.dto;
+
+import lombok.Data;
+
+/**
+ * cm_brand_auth_shop_info
+ * @author 
+ */
+@Data
+public class ShopInfoDto {
+    private Integer id;
+
+    /**
+     * 用户Id
+     */
+    private Integer authUserId;
+
+    /**
+     * 所属品牌Id
+     */
+    private Integer brandId;
+
+    /**
+     * 品牌授权logo
+     */
+    private String brandAuthLogo;
+
+    /**
+     * 产地国家id
+     */
+    private Integer countryId;
+
+    /**
+     * 官网认证链接
+     */
+    private String securityLink;
+
+    /**
+     * 代理声明类型:1弹窗,2链接,3图片,4文件
+     */
+    private Integer statementType;
+
+    /**
+     * 声明弹窗内容
+     */
+    private String statementContent;
+
+    /**
+     * 声明链接
+     */
+    private String statementLink;
+
+    /**
+     * 声明图片
+     */
+    private String statementImage;
+
+    /**
+     * 声明文件id
+     */
+    private Integer statementFileId;
+}

+ 6 - 1
src/main/java/com/caimei/model/po/CmBrandAuthFilePo.java

@@ -14,10 +14,15 @@ import java.util.Date;
 public class CmBrandAuthFilePo {
     private Integer id;
     /**
-     * 对应cm_brand_auth_user表authUserId
+     * 供应商用户id
      */
     private Integer authUserId;
 
+    /**
+     * 品牌id
+     */
+    private Integer brandId;
+
     /**
      * 声明文件名称
      */

+ 5 - 0
src/main/java/com/caimei/model/po/ProductPo.java

@@ -22,6 +22,11 @@ public class ProductPo {
      */
     private Integer authId;
 
+    /**
+     * 品牌Id
+     */
+    private Integer brandId;
+
     /**
      * 商品名称
      */

+ 0 - 5
src/main/java/com/caimei/model/po/ShopInfoPo.java

@@ -16,11 +16,6 @@ public class ShopInfoPo{
      */
     private Integer authUserId;
 
-    /**
-     * 供应商类型:1品牌方,2代理商
-     */
-    private Integer type;
-
     /**
      * 所属品牌Id
      */

+ 5 - 0
src/main/java/com/caimei/model/po/UserPo.java

@@ -40,6 +40,11 @@ public class UserPo {
      */
     private Integer userIdentity;
 
+    /**
+     * 供应商类型:1品牌方,2代理商
+     */
+    private Integer shopType;
+
     /**
      * 创建时间
      */

+ 3 - 0
src/main/java/com/caimei/model/vo/ProductFormVo.java

@@ -20,6 +20,9 @@ public class ProductFormVo {
     @ApiModelProperty("授权id")
     private Integer authId;
 
+    @ApiModelProperty("品牌id")
+    private Integer brandId;
+
     @ApiModelProperty("商品名称")
     private String productName;
 

+ 17 - 0
src/main/java/com/caimei/model/vo/ShopBrandVo.java

@@ -0,0 +1,17 @@
+package com.caimei.model.vo;
+
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+
+/**
+ * @author Aslee
+ * @date 2021/5/17
+ */
+@Data
+public class ShopBrandVo {
+    @ApiModelProperty("供应商信息id")
+    private Integer id;
+
+    @ApiModelProperty("品牌id")
+    private Integer brandId;
+}

+ 5 - 52
src/main/java/com/caimei/model/vo/ShopFormVo.java

@@ -1,10 +1,12 @@
 package com.caimei.model.vo;
 
+import com.caimei.model.po.ShopInfoPo;
 import io.swagger.annotations.ApiModelProperty;
 import lombok.Data;
 
 import java.io.Serializable;
 import java.util.Date;
+import java.util.List;
 
 /**
  * Description
@@ -32,18 +34,6 @@ public class ShopFormVo implements Serializable {
     @ApiModelProperty("供应商类型")
     private Integer shopType;
 
-    /**
-     * 所属品牌Id
-     */
-    @ApiModelProperty("所属品牌Id")
-    private Integer brandId;
-
-    /**
-     * 所属品牌Logo
-     */
-    @ApiModelProperty("所属品牌Logo")
-    private String brandAuthLogo;
-
     /**
      * 手机号
      */
@@ -56,18 +46,6 @@ public class ShopFormVo implements Serializable {
     @ApiModelProperty("联系人")
     private String linkMan;
 
-    /**
-     * 产地国家Id
-     */
-    @ApiModelProperty("产地国家Id")
-    private Integer countryId;
-
-    /**
-     * 官网认证链接
-     */
-    @ApiModelProperty("官网认证链接")
-    private String securityLink;
-
     /**
      * 供应商状态:0停用 1启用
      */
@@ -75,33 +53,8 @@ public class ShopFormVo implements Serializable {
     private Integer shopStatus;
 
     /**
-     * 代理声明类型:1弹窗,2链接,3图片,4文件
+     * 供应商信息列表
      */
-    @ApiModelProperty("代理声明类型:1弹窗,2链接,3图片,4文件")
-    private Integer statementType;
-
-    /**
-     * 声明弹窗内容
-     */
-    @ApiModelProperty("声明弹窗内容")
-    private String statementContent;
-
-    /**
-     * 声明链接
-     */
-    @ApiModelProperty("声明链接")
-    private String statementLink;
-
-    /**
-     * 声明图片
-     */
-    @ApiModelProperty("声明图片")
-    private String statementImage;
-
-    /**
-     * 声明文件名称
-     */
-    @ApiModelProperty("声明文件名称")
-    private String statementFileName;
-
+    @ApiModelProperty("供应商信息列表")
+    private List<ShopInfoVo> shopInfo;
 }

+ 66 - 0
src/main/java/com/caimei/model/vo/ShopInfoVo.java

@@ -0,0 +1,66 @@
+package com.caimei.model.vo;
+
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+
+/**
+ * cm_brand_auth_shop_info
+ * @author 
+ */
+@Data
+public class ShopInfoVo {
+    /**
+     * 所属品牌Id
+     */
+    private Integer brandId;
+
+    /**
+     * 所属品牌名称
+     */
+    private String brandName;
+
+    /**
+     * 品牌授权logo
+     */
+    private String brandAuthLogo;
+
+    /**
+     * 产地国家id
+     */
+    private Integer countryId;
+
+    /**
+     * 官网认证链接
+     */
+    private String securityLink;
+
+    /**
+     * 代理声明类型:1弹窗,2链接,3图片,4文件
+     */
+    private Integer statementType;
+
+    /**
+     * 声明弹窗内容
+     */
+    private String statementContent;
+
+    /**
+     * 声明链接
+     */
+    private String statementLink;
+
+    /**
+     * 声明图片
+     */
+    private String statementImage;
+
+    /**
+     * 声明文件Id
+     */
+    private Integer statementFileId;
+
+    /**
+     * 声明文件名称
+     */
+    private String statementFileName;
+}

+ 1 - 1
src/main/java/com/caimei/model/vo/ShopListVo.java

@@ -32,7 +32,7 @@ public class ShopListVo implements Serializable {
      * 供应商类型:1代理商 2品牌方
      */
     @ApiModelProperty("供应商类型")
-    private Integer type;
+    private Integer shopType;
 
     /**
      * 所属品牌

+ 29 - 28
src/main/java/com/caimei/service/ShopService.java

@@ -1,11 +1,8 @@
 package com.caimei.service;
 
 import com.caimei.model.ResponseJson;
-import com.caimei.model.dto.ShopSaveDto;
-import com.caimei.model.vo.BrandVo;
-import com.caimei.model.vo.CountryVo;
-import com.caimei.model.vo.ShopFormVo;
-import com.caimei.model.vo.ShopListVo;
+import com.caimei.model.dto.ShopInfoDto;
+import com.caimei.model.vo.*;
 import com.github.pagehelper.PageInfo;
 import org.springframework.web.multipart.MultipartFile;
 
@@ -49,33 +46,36 @@ public interface ShopService {
 
     /**
      * 上传文件
-     * @param authUserId    供应商用户id
-     * @param file      上传文件
+     *
+     * @param authUserId 供应商用户id
+     * @param brandId:品牌id
+     * @param file       上传文件
      * @return
      */
-    ResponseJson<Integer> uploadFile(Integer authUserId, MultipartFile file);
+    ResponseJson<Integer> uploadFile(Integer authUserId, Integer brandId, MultipartFile file);
 
     /**
      * 添加供应商
-     * @param shopSaveDto {
-     *                   shopType           供应商类型:1代理商,2品牌方
-     *                   brandId            品牌id
-     *                   shopName           供应商名称
-     *                   mobile             手机号
-     *                   linkMan            联系人
-     *                   countryId          产地国家id
-     *                   brandAuthLogo      品牌授权logo
-     *                   shopStatus         供应商状态:0停用 1启用
-     *                   securityLink       官网认证链接
-     *                   statementType      代理声明类型:1弹窗 2链接 3图片 4文件(.doc .ppt .pdf)
-     *                   statementContent   声明弹窗内容
-     *                   statementLink      声明链接
-     *                   statementImage     声明图片
-     *                   statementFileId    声明文件id
-     *                   createBy           创建人用户id
-     * }
+     *  @param shopSaveDto {
+     *                    shopType           供应商类型:1代理商,2品牌方
+     *                    brandId            品牌id
+     *                    shopName           供应商名称
+     *                    mobile             手机号
+     *                    linkMan            联系人
+     *                    countryId          产地国家id
+     *                    brandAuthLogo      品牌授权logo
+     *                    shopStatus         供应商状态:0停用 1启用
+     *                    securityLink       官网认证链接
+     *                    statementType      代理声明类型:1弹窗 2链接 3图片 4文件(.doc .ppt .pdf)
+     *                    statementContent   声明弹窗内容
+     *                    statementLink      声明链接
+     *                    statementImage     声明图片
+     *                    statementFileId    声明文件id
+     *                    createBy           创建人用户id
+     *                    }
+     * @param shopInfoList
      */
-    ResponseJson saveShop(ShopSaveDto shopSaveDto);
+    ResponseJson saveShop(Integer authUserId, Integer shopType, String shopName, String mobile, String linkMan, Integer shopStatus, Integer createBy, List<ShopInfoDto> shopInfoList);
 
     /**
      * 获取供应商回显数据
@@ -87,14 +87,15 @@ public interface ShopService {
     /**
      * 根据供应商用户id删除代理声明文件
      */
-    void deleteFileByUserId(Integer authUserId);
+    void deleteFile(Integer authUserId,Integer brandId);
 
     /**
      * 品牌列表
      * @param type 1品牌方品牌列表,2代理商品牌列表
+     * @param authUserId    供应商用户id
      * @return AuthVo
      */
-    ResponseJson<List<BrandVo>> getBrandList(Integer type);
+    ResponseJson<List<BrandVo>> getBrandList(Integer type, Integer authUserId);
 
     /**
      * 产地国家列表

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

@@ -77,6 +77,7 @@ public class AuthProductServiceImpl implements AuthProductService {
     public ResponseJson saveProduct(ProductSaveDto productSaveDto) {
         Integer productId = productSaveDto.getProductId();
         Integer authId = productSaveDto.getAuthId();
+        Integer brandId = productSaveDto.getBrandId();
         String productName = productSaveDto.getProductName();
         String snCode = productSaveDto.getSnCode();
         String productImage = productSaveDto.getProductImage();
@@ -87,6 +88,9 @@ public class AuthProductServiceImpl implements AuthProductService {
         if (null == authId) {
             return ResponseJson.error("参数异常,请输入授权id", null);
         }
+        if (null == brandId) {
+            return ResponseJson.error("参数异常,请输入品牌id", null);
+        }
         if (StringUtils.isBlank(productName)) {
             return ResponseJson.error("参数异常,请输入商品名称", null);
         }
@@ -119,6 +123,8 @@ public class AuthProductServiceImpl implements AuthProductService {
         ProductPo product = new ProductPo();
         // 授权id
         product.setAuthId(authId);
+        // 品牌id
+        product.setBrandId(brandId);
         // 商品名称
         product.setProductName(productName);
         // sn码

+ 76 - 75
src/main/java/com/caimei/service/impl/ShopServiceImpl.java

@@ -3,30 +3,23 @@ package com.caimei.service.impl;
 import com.caimei.mapper.ShopMapper;
 import com.caimei.mapper.UserMapper;
 import com.caimei.model.ResponseJson;
-import com.caimei.model.dto.ShopSaveDto;
+import com.caimei.model.dto.ShopInfoDto;
 import com.caimei.model.po.CmBrandAuthFilePo;
-import com.caimei.model.po.ShopInfoPo;
 import com.caimei.model.po.UserPo;
-import com.caimei.model.vo.BrandVo;
-import com.caimei.model.vo.CountryVo;
-import com.caimei.model.vo.ShopFormVo;
-import com.caimei.model.vo.ShopListVo;
+import com.caimei.model.vo.*;
 import com.caimei.service.ShopService;
 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 java.io.File;
 import java.io.FileInputStream;
-import java.util.Date;
-import java.util.List;
-import java.util.UUID;
+import java.util.*;
 
 /**
  * Description
@@ -88,7 +81,7 @@ public class ShopServiceImpl implements ShopService {
     }
 
     @Override
-    public ResponseJson<Integer> uploadFile(Integer authUserId, MultipartFile file) {
+    public ResponseJson<Integer> uploadFile(Integer authUserId, Integer brandId, MultipartFile file) {
         authUserId = (null != authUserId && authUserId > 0) ? authUserId : null;
         String fileAllName = file.getOriginalFilename();
         String fileType = fileAllName.substring(fileAllName.lastIndexOf(".") + 1);
@@ -109,7 +102,7 @@ public class ShopServiceImpl implements ShopService {
             if (cmBrandAuthFile == null) {
                 log.info("默认路径>>>" + uploadFile.getAbsolutePath());
                 // 修改情况下,如果原来已经选择了文件代理声明,并且旧文件与新文件不同,需要将旧文件删除
-                deleteFileByUserId(authUserId);
+                deleteFile(authUserId, brandId);
                 //将新文件上传oss
                 OSSUtils.ossUpload(filePath, uploadFile, contentType);
                 //删除本地文件
@@ -117,6 +110,7 @@ public class ShopServiceImpl implements ShopService {
                 //保存关联关系
                 cmBrandAuthFile = new CmBrandAuthFilePo();
                 cmBrandAuthFile.setAuthUserId(authUserId);
+                cmBrandAuthFile.setBrandId(brandId);
                 cmBrandAuthFile.setName(fileName);
                 cmBrandAuthFile.setOssName(filePath);
                 cmBrandAuthFile.setMd5Hex(md5Hex);
@@ -134,9 +128,10 @@ public class ShopServiceImpl implements ShopService {
     }
 
     @Override
-    public void deleteFileByUserId(Integer authUserId) {
+    public void deleteFile(Integer authUserId, Integer brandId) {
         CmBrandAuthFilePo searchFile = new CmBrandAuthFilePo();
         searchFile.setAuthUserId(authUserId);
+        searchFile.setBrandId(brandId);
         CmBrandAuthFilePo oldFile = shopMapper.getStatementFile(searchFile);
         if (oldFile != null) {
             Integer num = shopMapper.getFileNumByMd5Hex(oldFile.getMd5Hex());
@@ -151,18 +146,9 @@ public class ShopServiceImpl implements ShopService {
     }
 
     @Override
-    public ResponseJson saveShop(ShopSaveDto shopSaveDto) {
-        Integer shopType = shopSaveDto.getShopType();
-        if (shopType == null) {
-            return ResponseJson.error("请选择供应商类型", null);
-        }
+    public ResponseJson saveShop(Integer authUserId, Integer shopType, String shopName, String mobile, String linkMan, Integer shopStatus, Integer createBy, List<ShopInfoDto> shopInfoList) {
         // 是否为添加操作
-        boolean insertFlag = null == shopSaveDto.getAuthUserId();
-        // 手机号
-        String mobile = shopSaveDto.getMobile();
-        if (StringUtils.isBlank(mobile)) {
-            return ResponseJson.error("参数异常,请输入手机号");
-        }
+        boolean insertFlag = null == authUserId;
         if (insertFlag) {
             // 添加时验证手机号是否已被使用
             Integer userIdByMobile = shopMapper.getUserIdByMobile(mobile);
@@ -171,41 +157,45 @@ public class ShopServiceImpl implements ShopService {
             }
         }
         // 更新品牌授权logo
-        shopMapper.updateBrandAuthLogo(shopSaveDto.getBrandId(),shopSaveDto.getBrandAuthLogo());
+        shopInfoList.forEach(shopInfo->{
+            shopMapper.updateBrandAuthLogo(shopInfo.getBrandId(), shopInfo.getBrandAuthLogo());
+        });
         /*
             组装供应商用户数据
          */
         UserPo shop = new UserPo();
         // 供应商名称
-        shop.setName(shopSaveDto.getShopName());
+        shop.setName(shopName);
         // 手机号
-        shop.setMobile(shopSaveDto.getMobile());
+        shop.setMobile(mobile);
         // 联系人
-        shop.setLinkMan(shopSaveDto.getLinkMan());
+        shop.setLinkMan(linkMan);
         // 供应商状态
-        shop.setStatus(shopSaveDto.getShopStatus());
+        shop.setStatus(shopStatus);
         if (insertFlag) {
             // 用户身份:1管理员,2供应商
             shop.setUserIdentity(2);
+            // 供应商类型
+            shop.setShopType(shopType);
             // 创建管理员id
-            shop.setCreateBy(shopSaveDto.getCreateBy());
+            shop.setCreateBy(createBy);
             // 创建时间
             shop.setCreateTime(new Date());
             // 设置随机8位密码
             String password = CodeUtil.generateCode(8);
             String md5Pwd = Md5Util.md5(password);
             shop.setPassword(md5Pwd);
+            // 插入供应商用户
+            shopMapper.insertShop(shop);
             // 发送短信
-            boolean smsFlag = AliyunSmsUtil.sendSms(shopSaveDto.getMobile(), 14, "{password:\"" + password + "\"}");
+            boolean smsFlag = AliyunSmsUtil.sendSms(mobile, 14, "{password:\"" + password + "\"}");
             if (!smsFlag) {
                 // 短信发送失败重试一次
-                AliyunSmsUtil.sendSms(shopSaveDto.getMobile(), 14, "{password:\"" + password + "\"}");
+                AliyunSmsUtil.sendSms(mobile, 14, "{password:\"" + password + "\"}");
             }
-            // 插入供应商用户
-            shopMapper.insertShop(shop);
             log.info("添加供应商,供应商用户id:" + shop.getAuthUserId());
         } else {
-            shop.setAuthUserId(shopSaveDto.getAuthUserId());
+            shop.setAuthUserId(authUserId);
             // 更新供应商用户
             shopMapper.updateShopByUserId(shop);
             log.info("更新供应商,供应商用户id:" + shop.getAuthUserId());
@@ -213,45 +203,50 @@ public class ShopServiceImpl implements ShopService {
         /*
             组装供应商信息数据
          */
-        ShopInfoPo shopInfo = new ShopInfoPo();
-        // 供应商用户id
-        shopInfo.setAuthUserId(shop.getAuthUserId());
-        // 供应商类型:1品牌方,2代理商
-        shopInfo.setType(shopSaveDto.getShopType());
-        // 品牌id
-        shopInfo.setBrandId(shopSaveDto.getBrandId());
-        // 国家id
-        shopInfo.setCountryId(shopSaveDto.getCountryId());
-        // 官网认证链接
-        shopInfo.setSecurityLink(shopSaveDto.getSecurityLink());
-        if (null != shopSaveDto.getStatementType()) {
-            shopInfo.setStatementType(shopSaveDto.getStatementType());
-            if (1 == shopSaveDto.getStatementType()) {
-                // 声明弹窗
-                shopInfo.setStatementContent(shopSaveDto.getStatementContent());
-            } else if (2 == shopSaveDto.getStatementType()) {
-                // 声明链接
-                shopInfo.setStatementLink(shopSaveDto.getStatementLink());
-            } else if (3 == shopSaveDto.getStatementType()) {
-                // 声明图片
-                shopInfo.setStatementImage(shopSaveDto.getStatementImage());
-            }
-            if (4 == shopSaveDto.getStatementType()) {
-                if (insertFlag){
-                    // 更新代理声明文件
-                    Integer statementFileId = shopSaveDto.getStatementFileId();
-                    shopMapper.updateFileUserId(statementFileId, shop.getAuthUserId());
-                }
-            } else if (!insertFlag){
-                // 没有选择文件代理声明的情况下,若存在原来的文件,删除代理声明文件
-                deleteFileByUserId(shop.getAuthUserId());
-            }
-        }
-        // 保存供应商信息
         if (insertFlag) {
-            shopMapper.insertShopInfo(shopInfo);
+            shopInfoList.forEach(shopInfo->{
+                shopInfo.setAuthUserId(shop.getAuthUserId());
+                // 插入供应商信息
+                shopMapper.insertShopInfo(shopInfo);
+                if (4 == shopInfo.getStatementType()) {
+                    shopMapper.updateFileUserId(shopInfo.getStatementFileId(), shop.getAuthUserId());
+                }
+            });
         } else {
-            shopMapper.updateShopInfoByUserId(shopInfo);
+            // 数据库中供应商信息数据
+            List<ShopBrandVo> dbInfoBrandList = shopMapper.getDbInfoBrandList(shop.getAuthUserId());
+            List<Integer> updateInfoBrandList = new ArrayList<>();
+            List<Integer> newInfoBrandList = new ArrayList<>();
+            // 编辑后的供应商品牌id
+            shopInfoList.forEach(shopInfo->{
+                newInfoBrandList.add(shopInfo.getBrandId());
+            });
+            for (ShopBrandVo shopBrand : dbInfoBrandList) {
+                if (!newInfoBrandList.contains(shopBrand.getBrandId())) {
+                    // 删除被删除的数据
+                    shopMapper.deleteShopInfoById(shopBrand.getId());
+                    // 删除文件
+                    deleteFile(authUserId, shopBrand.getBrandId());
+                } else {
+                    // 保存数据库已有且未被删除的供应商品牌id
+                    updateInfoBrandList.add(shopBrand.getBrandId());
+                }
+            }
+            shopInfoList.forEach(shopInfoVo -> {
+                shopInfoVo.setAuthUserId(shop.getAuthUserId());
+                // 保存供应商信息数据
+                if (updateInfoBrandList.contains(shopInfoVo.getBrandId())) {
+                    // 更新
+                    shopMapper.updateShopInfo(shopInfoVo);
+                    if (4 != shopInfoVo.getStatementType()) {
+                        // 没有选择文件代理声明的情况下,若存在原来的文件,删除代理声明文件
+                        deleteFile(shop.getAuthUserId(),shopInfoVo.getBrandId());
+                    }
+                } else {
+                    // 插入
+                    shopMapper.insertShopInfo(shopInfoVo);
+                }
+            });
         }
         return ResponseJson.success("保存供应商成功", null);
     }
@@ -261,16 +256,22 @@ public class ShopServiceImpl implements ShopService {
         if (null == authUserId) {
             return ResponseJson.error("参数异常,请输入供应商用户id", null);
         }
-        ShopFormVo shopForm = shopMapper.getShopByAuthUserId(authUserId);
+        ShopFormVo shopForm = shopMapper.getShopByUserId(authUserId);
         if (null == shopForm) {
             return ResponseJson.error("供应商不存在", null);
         }
+        List<ShopInfoVo> shopInfoList = shopMapper.getShopInfoByUserId(authUserId);
+        shopForm.setShopInfo(shopInfoList);
         return ResponseJson.success(shopForm);
     }
 
     @Override
-    public ResponseJson<List<BrandVo>> getBrandList(Integer type) {
-        List<BrandVo> brandList = shopMapper.getBrandList(type);
+    public ResponseJson<List<BrandVo>> getBrandList(Integer type, Integer authUserId) {
+        type = null == type ? 2 : type;
+        if (3 == type && null == authUserId) {
+            return ResponseJson.error("参数异常,请输入供应商用户id", null);
+        }
+        List<BrandVo> brandList = shopMapper.getBrandList(type, authUserId);
         return ResponseJson.success(brandList);
     }
 

+ 25 - 4
src/main/resources/backup.sql

@@ -5,6 +5,7 @@ CREATE TABLE `cm_brand_auth_user` (
                                                 `password` VARCHAR(100) NULL COMMENT '密码',
                                                 `linkMan` VARCHAR(30) NULL COMMENT '联系人',
                                                 `userIdentity` INT NULL COMMENT '用户身份:1管理员,2供应商',
+                                                `shopType` INT NULL COMMENT '供应商类型:1品牌方,2代理商',
                                                 `createTime` DATETIME NULL COMMENT '创建时间',
                                                 `createBy` INT NULL COMMENT '创建人Id',
                                                 `status` INT NULL COMMENT '状态:0停用,1启用',
@@ -12,10 +13,10 @@ CREATE TABLE `cm_brand_auth_user` (
     ENGINE = InnoDB
     DEFAULT CHARACTER SET = utf8
     COMMENT = '正品联盟后台管理员';
+
 CREATE TABLE `cm_brand_auth_shop_info` (
                                                    `id` INT NOT NULL AUTO_INCREMENT,
                                                    `authUserId` INT NULL COMMENT '用户Id',
-                                                   `type` INT NULL COMMENT '供应商类型:1品牌方,2代理商',
                                                    `brandId` INT NULL COMMENT '所属品牌Id',
                                                    `countryId` INT NULL COMMENT '产地国家id',
                                                    `securityLink` TEXT NULL COMMENT '官网认证链接',
@@ -28,10 +29,9 @@ CREATE TABLE `cm_brand_auth_shop_info` (
     DEFAULT CHARACTER SET = utf8
     COMMENT = '正品联盟供应商信息';
 
+
 INSERT INTO `cm_brand_auth_user` (`authUserId`, `name`, `password`, `userIdentity`, `status`) VALUES ('1', 'admin', '21D34CF4A2F21FDD791C4C1B67C3F954', '1', '1');
 
-ALTER TABLE `cm_brand_auth_file`
-    CHANGE COLUMN `brandAuthId` `authUserId` INT NULL DEFAULT NULL COMMENT '授权用户id' ;
 
 ALTER TABLE `cm_brand_auth`
     DROP COLUMN `statementImage`,
@@ -46,6 +46,27 @@ ALTER TABLE `cm_brand_auth`
     ADD COLUMN `authUserId` INT NULL COMMENT '供应商用户id' AFTER `id`,
     ADD COLUMN `status` INT NULL COMMENT '上架状态:0已下架,1已上架' AFTER `authParty`;
 
+
+
+
 ALTER TABLE `cm_brand_auth_product`
-    ADD COLUMN `status` INT NULL COMMENT '上架状态:0下架,1上架' AFTER `certificateImage`;
+    ADD COLUMN `status` INT NULL COMMENT '上架状态:0下架,1上架' AFTER `certificateImage`,
+    ADD COLUMN `brandId` INT NULL COMMENT '品牌id' AFTER `authId`;
+
+
+CREATE TABLE `cm_brand_auth_file` (
+                                      `id` INT NOT NULL AUTO_INCREMENT,
+                                      `authUserId` INT NULL COMMENT '授权用户id',
+                                      `brandId` INT NULL COMMENT '品牌id',
+                                      `name` VARCHAR(300) NULL COMMENT '文件名称',
+                                      `ossName` VARCHAR(300) NULL COMMENT 'oss存储名',
+                                      `md5Hex` VARCHAR(32) NULL COMMENT '文件唯一标识',
+                                      `uploadTime` DATETIME NULL COMMENT '上传时间',
+                                      PRIMARY KEY (`id`))
+    ENGINE = InnoDB
+    DEFAULT CHARACTER SET = utf8
+    COLLATE = utf8_bin
+    COMMENT = '品牌授权代理声明文件';
+
+
 

+ 5 - 3
src/main/resources/mapper/AuthProductMapper.xml

@@ -2,9 +2,9 @@
 <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
 <mapper namespace="com.caimei.mapper.AuthProductMapper">
     <insert id="insertProduct" keyColumn="id" keyProperty="productId" useGeneratedKeys="true" parameterType="com.caimei.model.po.ProductPo">
-        insert into cm_brand_auth_product(`authId`, `name`, `snCode`, `image`, `certificateImage`, `status`,
+        insert into cm_brand_auth_product(`authId`, `brandId`, `name`, `snCode`, `image`, `certificateImage`, `status`,
                                           `createTime`, `createBy`)
-        values (#{authId}, #{productName}, #{snCode}, #{productImage}, #{certificateImage}, #{status}, #{createTime},
+        values (#{authId}, #{brandId}, #{productName}, #{snCode}, #{productImage}, #{certificateImage}, #{status}, #{createTime},
                 #{createBy})
     </insert>
     <insert id="insertProductParam">
@@ -19,7 +19,8 @@
     </update>
     <update id="updateProductByProductId">
         update cm_brand_auth_product
-        set `name`             = #{productName},
+        set `brandId`          = #{brandId},
+            `name`             = #{productName},
             `snCode`           = #{snCode},
             `image`            = #{productImage},
             `certificateImage` = #{certificateImage},
@@ -50,6 +51,7 @@
     <select id="getProductFormByProductId" resultType="com.caimei.model.vo.ProductFormVo">
         select `id`    as productId,
                `authId`,
+               `brandId`,
                `name`  as productName,
                `snCode`,
                `image` as productImage,

+ 53 - 20
src/main/resources/mapper/ShopMapper.xml

@@ -2,18 +2,18 @@
 <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
 <mapper namespace="com.caimei.mapper.ShopMapper">
     <insert id="insertStatementFile" keyColumn="id" keyProperty="id" useGeneratedKeys="true" parameterType="com.caimei.model.po.CmBrandAuthFilePo">
-        insert into cm_brand_auth_file (`authUserId`, `name`, `ossName`, `md5Hex`, `uploadTime`)
-        values (#{authUserId}, #{name}, #{ossName}, #{md5Hex}, #{uploadTime})
+        insert into cm_brand_auth_file (`authUserId`, `brandId`, `name`, `ossName`, `md5Hex`, `uploadTime`)
+        values (#{authUserId}, #{brandId}, #{name}, #{ossName}, #{md5Hex}, #{uploadTime})
     </insert>
     <insert id="insertShop"  keyColumn="authUserId" keyProperty="authUserId" useGeneratedKeys="true" parameterType="com.caimei.model.po.UserPo">
-        insert into cm_brand_auth_user (`name`, `mobile`, `password`, `linkMan`, `userIdentity`, `createTime`,
+        insert into cm_brand_auth_user (`name`, `mobile`, `password`, `linkMan`, `userIdentity`, `shopType`, `createTime`,
                                         `createBy`,`status`)
-        values (#{name}, #{mobile}, #{password}, #{linkMan}, #{userIdentity}, #{createTime}, #{createBy}, #{status});
+        values (#{name}, #{mobile}, #{password}, #{linkMan}, #{userIdentity}, #{shopType}, #{createTime}, #{createBy}, #{status});
     </insert>
     <insert id="insertShopInfo">
         insert into cm_brand_auth_shop_info
         <trim prefix="(" suffix=")" suffixOverrides=",">
-            authUserId,type,brandId,countryId,securityLink,
+            authUserId,brandId,countryId,securityLink,
             <if test="statementType != null">
                 statementType,
             </if>
@@ -28,7 +28,7 @@
             </if>
         </trim>
         <trim prefix="values (" suffix=")" suffixOverrides=",">
-            #{authUserId},#{type},#{brandId},#{countryId},#{securityLink},
+            #{authUserId},#{brandId},#{countryId},#{securityLink},
             <if test="statementType != null">
                 #{statementType},
             </if>
@@ -65,10 +65,10 @@
             `status`  = #{status}
         where authUserId = #{authUserId}
     </update>
-    <update id="updateShopInfoByUserId">
+    <update id="updateShopInfo">
         update cm_brand_auth_shop_info
         <set>
-            brandId = #{brandId},countryId=#{countryId},securityLink = #{securityLink},
+            countryId=#{countryId},securityLink = #{securityLink},
             <if test="statementType != null">
                 statementType = #{statementType},
             </if>
@@ -82,13 +82,16 @@
                 statementImage = #{statementImage},
             </if>
         </set>
-        where authUserId = #{authUserId}
+        where authUserId = #{authUserId} and brandId = #{brandId}
     </update>
     <delete id="deleteStatementFile">
         delete from cm_brand_auth_file where id = #{id}
     </delete>
+    <delete id="deleteShopInfoById">
+        delete from cm_brand_auth_shop_info where id = #{infoId}
+    </delete>
     <select id="getShopList" resultType="com.caimei.model.vo.ShopListVo">
-        select u.authUserId,u.name,s.type,cb.name as brandName,u.mobile,u.linkMan,
+        select u.authUserId,u.name,u.shopType,group_concat(cb.name) as brandName,u.mobile,u.linkMan,
             u.status as shopStatus,u.createTime,
             (select au.name from cm_brand_auth_user au where au.authUserId = u.createBy) as createBy
             from cm_brand_auth_user u
@@ -99,7 +102,7 @@
             AND u.name like CONCAT('%',#{shopName},'%')
         </if>
         <if test="shopType != null ">
-            AND s.type = #{shopType}
+            AND u.shopType = #{shopType}
         </if>
         <if test="brandId != null">
             AND s.brandId = #{brandId}
@@ -110,6 +113,7 @@
         <if test="linkMan != null and linkMan !=''">
             AND u.linkMan like CONCAT('%',#{linkMan},'%')
         </if>
+        group by u.authUserId,u.createTime
         ORDER BY u.createTime DESC
     </select>
     <select id="getShopMobileByUserId" resultType="java.lang.String">
@@ -125,6 +129,9 @@
             <if test="authUserId != null">
                 and authUserId = #{authUserId}
             </if>
+            <if test="brandId != null">
+                and brandId = #{brandId}
+            </if>
             <if test="md5Hex != null and md5Hex != ''">
                 and md5Hex = #{md5Hex}
             </if>
@@ -134,20 +141,24 @@
     <select id="getFileNumByMd5Hex" resultType="java.lang.Integer">
         select count(*) from cm_brand_auth_file where md5Hex = #{md5Hex}
     </select>
-    <select id="getShopByAuthUserId" resultType="com.caimei.model.vo.ShopFormVo">
-        select u.authUserId,u.name as shopName,u.mobile,u.linkMan,u.status as shopStatus,s.type as shopType,s.brandId,s.countryId,s.securityLink,b.authLogo as brandAuthLogo,
-               s.statementType,s.statementContent,s.statementLink,s.statementImage,f.name as statementFileName
-               from cm_brand_auth_user u
-                   left join cm_brand_auth_shop_info s on u.authUserId = s.authUserId
-                   left join cm_brand_auth_file f on u.authUserId = f.authUserId
-                left join cm_brand b on s.brandId = b.id
-                where u.authUserId = #{authUserId}
+    <select id="getShopByUserId" resultType="com.caimei.model.vo.ShopFormVo">
+        select u.authUserId, u.name as shopName, u.mobile, u.linkMan, u.status as shopStatus, u.shopType as shopType
+        from cm_brand_auth_user u
+        where u.authUserId = #{authUserId};
     </select>
     <select id="getBrandList" resultType="com.caimei.model.vo.BrandVo">
         select id,name,authLogo from cm_brand
         <where>
             <if test="type == 1">
-                id not in (select brandId from cm_brand_auth_shop_info where type = 1 and brandId is not null)
+                id not in (select brandId
+                from cm_brand_auth_shop_info i
+                left join cm_brand_auth_user u on i.authUserId= u.authUserId
+                where u.shopType = 1 and i.brandId is not null);
+            </if>
+            <if test="type == 3">
+                id in (select brandId
+                from cm_brand_auth_shop_info
+                where authUserId = #{authUserId})
             </if>
         </where>
     </select>
@@ -159,4 +170,26 @@
     <select id="getUserIdByMobile" resultType="java.lang.Integer">
         select authUserId from cm_brand_auth_user where mobile = #{mobile} and userIdentity = 2
     </select>
+    <select id="getDbInfoBrandList" resultType="com.caimei.model.vo.ShopBrandVo">
+        select id,brandId
+        from cm_brand_auth_shop_info
+        where authUserId = #{authUserId}
+    </select>
+    <select id="getShopInfoByUserId" resultType="com.caimei.model.vo.ShopInfoVo">
+        select i.brandId,
+               i.countryId,
+               i.securityLink,
+               i.statementType,
+               i.statementContent,
+               i.statementLink,
+               i.statementImage,
+               f.id as statementFileId,
+               f.name as statementFileName,
+               b.name as brandName,
+               b.authLogo as brandAuthLogo
+        from cm_brand_auth_shop_info i
+                 left join cm_brand b on i.brandId = b.id
+                 left join cm_brand_auth_file f on i.authUserId = f.authUserId and i.brandId = f.brandId
+        where i.authUserId = #{authUserId}
+    </select>
 </mapper>