Prechádzať zdrojové kódy

设备参数列表和品牌迁移到设备分类中

Aslee 2 rokov pred
rodič
commit
ba907f8344

+ 23 - 12
src/main/java/com/caimei/controller/admin/auth/AuthProductApi.java

@@ -1,8 +1,11 @@
 package com.caimei.controller.admin.auth;
 
+import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
 import com.caimei.model.ResponseJson;
 import com.caimei.model.dto.ProductSaveDto;
+import com.caimei.model.po.ProductParamPo;
+import com.caimei.model.po.ProductTypePo;
 import com.caimei.model.vo.ProductFormVo;
 import com.caimei.model.vo.ProductListVo;
 import com.caimei.model.vo.ProductTypeListVo;
@@ -87,7 +90,6 @@ public class AuthProductApi {
      * @param productSaveDto {
      *                   productId              授权商品id
      *                   authId                 授权id
-     *                   brandId                品牌id
      *                   productTypeId          设备分类id
      *                   snCode                 商品SN码
      *                   productImage           商品图片
@@ -99,7 +101,6 @@ public class AuthProductApi {
      *                   status                 上线状态:0已下线,1已上线,2待上线
      *                   createBy               创建人id
      *                   source                 来源:1供应商保存,2机构保存
-     *                   paramList              商品参数列表
      * }
      */
     @ApiOperation("添加/编辑授权商品")
@@ -108,12 +109,6 @@ public class AuthProductApi {
         return authProductService.saveProduct(productSaveDto, false);
     }
 
-    /**
-     * 获取授权商品回显数据
-     *
-     * @param productId 授权商品id
-     * @return ProductFormVo
-     */
     @ApiOperation("授权商品回显数据")
     @ApiImplicitParam(name = "productId", required = true, value = "授权商品id")
     @GetMapping("/form/data")
@@ -130,9 +125,6 @@ public class AuthProductApi {
         return authProductService.updateAllWaterMark();
     }
 
-    /**
-     * 审核商品
-     */
     @ApiOperation("审核商品")
     @ApiImplicitParam(name = "params", value = "productId:授权商品id;auditStatus:审核状态:0审核未通过,1审核通过,2待审核;" +
             "invalidReason:审核不通过原因;auditBy:审核人用户id;source:来源:1管理员审核,2供应商审核", required = true)
@@ -147,6 +139,16 @@ public class AuthProductApi {
         return authProductService.auditProduct(productId, auditStatus, invalidReason, auditBy, source);
     }
 
+    @ApiOperation("设备分类回显数据")
+    @ApiImplicitParam(name = "productTypeId", required = true, value = "设备分类id")
+    @GetMapping("/type/form/data")
+    public ResponseJson<ProductTypePo> getProductTypeFormData(Integer productTypeId) {
+        if (null == productTypeId) {
+            return ResponseJson.error("设备分类id不能为空", null);
+        }
+        return authProductService.getProductTypeFromData(productTypeId);
+    }
+
     @ApiOperation("添加/编辑设备分类")
     @ApiImplicitParam(name = "params", value = "productTypeId:设备分类id;authUserId:供应商用户id;name:设备分类名称;image:图片;createBy:创建人用户id;", required = true)
     @PostMapping("/type/save")
@@ -154,19 +156,28 @@ public class AuthProductApi {
         JSONObject paramsMap = JSONObject.parseObject(params);
         Integer productTypeId = paramsMap.getInteger("productTypeId");
         Integer authUserId = paramsMap.getInteger("authUserId");
+        Integer brandId = paramsMap.getInteger("brandId");
         String name = paramsMap.getString("name");
         String image = paramsMap.getString("image");
         Integer createBy = paramsMap.getInteger("createBy");
+        String paramListStr = paramsMap.getString("paramList");
+        List<ProductParamPo> paramList = JSONArray.parseArray(paramListStr, ProductParamPo.class);
         if (null == authUserId) {
             return ResponseJson.error("参数异常,供应商用户id不能为空");
         }
+        if (null == brandId) {
+            return ResponseJson.error("参数异常,品牌id不能为空");
+        }
         if (StringUtils.isEmpty(name)) {
             return ResponseJson.error("参数异常,设备分类名称不能为空");
         }
         if (StringUtils.isEmpty(image)) {
             return ResponseJson.error("参数异常,图片不能为空");
         }
-        return authProductService.saveProductType(productTypeId, authUserId, name, image, createBy, 1);
+        if (null == paramList || paramList.size() <= 0) {
+            return ResponseJson.error("参数异常,参数列表不能为空", null);
+        }
+        return authProductService.saveProductType(productTypeId, authUserId, brandId, name, image, createBy, paramList, 1);
     }
 
     @ApiOperation("删除设备分类")

+ 6 - 0
src/main/java/com/caimei/mapper/cmMapper/AuthProductMapper.java

@@ -88,4 +88,10 @@ public interface AuthProductMapper {
     ProductPo getProductPo(Integer productId);
 
     Integer getAuthUserIdByProductId(Integer productId);
+
+    void deleteParamsByProductTypeId(Integer productTypeId);
+
+    void insertProductTypeParam(@Param("productTypeId") Integer productTypeId, @Param("paramName") String paramName, @Param("paramContent") String paramContent);
+
+    List<ProductParamPo> getProductTypeParamList(Integer productTypeId);
 }

+ 11 - 0
src/main/java/com/caimei/model/po/ProductTypePo.java

@@ -3,6 +3,7 @@ package com.caimei.model.po;
 import lombok.Data;
 
 import java.util.Date;
+import java.util.List;
 
 /**
  * cm_brand_auth_product
@@ -22,6 +23,11 @@ public class ProductTypePo {
      */
     private Integer authUserId;
 
+    /**
+     * 品牌id
+     */
+    private Integer brandId;
+
     /**
      * 设备分类名称
      */
@@ -76,4 +82,9 @@ public class ProductTypePo {
      * 审核时间
      */
     private Date auditTime;
+
+    /**
+     * 参数列表
+     */
+    private List<ProductParamPo> paramList;
 }

+ 7 - 1
src/main/java/com/caimei/service/auth/AuthProductService.java

@@ -2,6 +2,7 @@ package com.caimei.service.auth;
 
 import com.caimei.model.ResponseJson;
 import com.caimei.model.dto.ProductSaveDto;
+import com.caimei.model.po.ProductParamPo;
 import com.caimei.model.po.ProductTypePo;
 import com.caimei.model.vo.*;
 import com.github.pagehelper.PageInfo;
@@ -123,7 +124,7 @@ public interface AuthProductService {
     /**
      * 保存设备分类
      */
-    ResponseJson<ProductTypePo> saveProductType(Integer productTypeId, Integer authUserId, String name, String image, Integer createBy, Integer createSource) throws IOException;
+    ResponseJson<ProductTypePo> saveProductType(Integer productTypeId, Integer authUserId, Integer brandId, String name, String image, Integer createBy, List<ProductParamPo> paramList, Integer createSource) throws IOException;
 
     /**
      * 删除设备分类
@@ -155,6 +156,11 @@ public interface AuthProductService {
      */
     ResponseJson<PageInfo<WxProductTypeListVo>> getWxProductTypeList(Integer authUserId, String appId, String name, Integer pageNum, Integer pageSize);
 
+    /**
+     * 设备分类回显数据
+     * @return
+     */
+    ResponseJson<ProductTypePo> getProductTypeFromData(Integer productTypeId);
 }
 
 

+ 37 - 10
src/main/java/com/caimei/service/auth/impl/AuthProductServiceImpl.java

@@ -168,9 +168,9 @@ public class AuthProductServiceImpl implements AuthProductService {
                 return ResponseJson.error("参数异常,请选择二维码授权牌模板", null);
             }
         }
-        if (null == paramList || paramList.size() <= 0) {
+        /*if (null == paramList || paramList.size() <= 0) {
             return ResponseJson.error("参数异常,商品参数列表不能为空", null);
-        }
+        }*/
         // 是否为添加操作
         boolean insertFlag = null == productId;
         /*
@@ -324,11 +324,13 @@ public class AuthProductServiceImpl implements AuthProductService {
         // 删除商品参数
         authProductMapper.deleteParamsByProductId(product.getProductId());
         // 保存商品参数
-        paramList.forEach(param -> {
-            if (StringUtils.isNotBlank(param.getParamName()) && StringUtils.isNotBlank(param.getParamContent())) {
-                authProductMapper.insertProductParam(product.getProductId(), param.getParamName(), param.getParamContent());
-            }
-        });
+        if (paramList != null) {
+            paramList.forEach(param -> {
+                if (StringUtils.isNotBlank(param.getParamName()) && StringUtils.isNotBlank(param.getParamContent())) {
+                    authProductMapper.insertProductParam(product.getProductId(), param.getParamName(), param.getParamContent());
+                }
+            });
+        }
         return ResponseJson.success("保存授权商品成功");
     }
 
@@ -380,6 +382,9 @@ public class AuthProductServiceImpl implements AuthProductService {
             return ResponseJson.error("商品不存在", null);
         }
         List<ProductParamPo> paramList = authProductMapper.getParamsByProductId(productId);
+        if (null == paramList || paramList.size() == 0) {
+            paramList = authProductMapper.getProductTypeParamList(productForm.getProductTypeId());
+        }
         productForm.setParamList(paramList);
         return ResponseJson.success(productForm);
     }
@@ -443,8 +448,9 @@ public class AuthProductServiceImpl implements AuthProductService {
                 // 查询设备分类是否已存在
                 ProductTypePo productType = authProductMapper.getProductType(null, product.getName(), authUserId);
                 if (null == productType) {
+                    List<ProductParamPo> paramList = authProductMapper.getParamsByProductId(productId);
                     try {
-                        ResponseJson<ProductTypePo> result = saveProductType(null, authUserId, product.getName(), product.getImage(), product.getCreateBy(), 2);
+                        ResponseJson<ProductTypePo> result = saveProductType(null, authUserId, product.getBrandId(), product.getName(), product.getImage(), product.getCreateBy(), paramList, 2);
                         int code = result.getCode();
                         if (0 == code) {
                             productType = result.getData();
@@ -471,8 +477,9 @@ public class AuthProductServiceImpl implements AuthProductService {
                 // 查询设备分类是否已存在
                 ProductTypePo productType = authProductMapper.getProductType(null, product.getName(), authUserId);
                 if (null == productType) {
+                    List<ProductParamPo> paramList = authProductMapper.getParamsByProductId(productId);
                     try {
-                        ResponseJson<ProductTypePo> result = saveProductType(null, authUserId, product.getName(), product.getImage(), product.getCreateBy(), 2);
+                        ResponseJson<ProductTypePo> result = saveProductType(null, authUserId, product.getBrandId(), product.getName(), product.getImage(), product.getCreateBy(), paramList, 2);
                         int code = result.getCode();
                         if (0 == code) {
                             productType = result.getData();
@@ -527,7 +534,7 @@ public class AuthProductServiceImpl implements AuthProductService {
     }
 
     @Override
-    public ResponseJson<ProductTypePo> saveProductType(Integer productTypeId, Integer authUserId, String name, String image, Integer createBy, Integer createSource) throws IOException {
+    public ResponseJson<ProductTypePo> saveProductType(Integer productTypeId, Integer authUserId, Integer brandId, String name, String image, Integer createBy, List<ProductParamPo> paramList, Integer createSource) throws IOException {
         // 是否为添加操作
         boolean insertFlag = null == productTypeId;
         /*
@@ -535,6 +542,7 @@ public class AuthProductServiceImpl implements AuthProductService {
          */
         ProductTypePo productType = new ProductTypePo();
         productType.setAuthUserId(authUserId);
+        productType.setBrandId(brandId);
         productType.setName(name);
         productType.setImage(image);
         productType.setCreateBy(createBy);
@@ -574,6 +582,16 @@ public class AuthProductServiceImpl implements AuthProductService {
             // 更新设备分类
             authProductMapper.updateProductType(productType);
         }
+        // 删除设备分类参数
+        authProductMapper.deleteParamsByProductTypeId(productType.getProductTypeId());
+        // 保存商品参数
+        if (null != paramList) {
+            paramList.forEach(param -> {
+                if (StringUtils.isNotBlank(param.getParamName()) && StringUtils.isNotBlank(param.getParamContent())) {
+                    authProductMapper.insertProductTypeParam(productType.getProductTypeId(), param.getParamName(), param.getParamContent());
+                }
+            });
+        }
         return ResponseJson.success("保存设备分类成功", productType);
     }
 
@@ -584,6 +602,7 @@ public class AuthProductServiceImpl implements AuthProductService {
             return ResponseJson.error("该设备有绑定设备认证,暂时无法删除");
         }
         authProductMapper.deleteProductType(productTypeId);
+        authProductMapper.deleteParamsByProductTypeId(productTypeId);
         return ResponseJson.success("删除设备分类成功");
     }
 
@@ -634,4 +653,12 @@ public class AuthProductServiceImpl implements AuthProductService {
         return ResponseJson.success(pageData);
     }
 
+    @Override
+    public ResponseJson<ProductTypePo> getProductTypeFromData(Integer productTypeId) {
+        ProductTypePo productType = authProductMapper.getProductType(productTypeId, null, null);
+        List<ProductParamPo> paramList = authProductMapper.getProductTypeParamList(productTypeId);
+        productType.setParamList(paramList);
+        return ResponseJson.success(productType);
+    }
+
 }

+ 20 - 8
src/main/resources/mapper/AuthProductMapper.xml

@@ -18,8 +18,12 @@
         values (#{productId}, #{paramName}, #{paramContent})
     </insert>
     <insert id="insertProductType" keyColumn="id" keyProperty="productTypeId" useGeneratedKeys="true" parameterType="com.caimei.model.po.ProductTypePo">
-        insert into cm_brand_product_type (authUserId, name, image, pcImage, appletsImage, status, auditStatus, auditBy, auditTime, createBy, createSource, createTime, delFlag)
-        values (#{authUserId}, #{name}, #{image}, #{pcImage}, #{appletsImage}, #{status}, #{auditStatus}, #{auditBy}, #{auditTime}, #{createBy}, #{createSource}, #{createTime}, 0)
+        insert into cm_brand_product_type (authUserId, brandId, name, image, pcImage, appletsImage, status, auditStatus, auditBy, auditTime, createBy, createSource, createTime, delFlag)
+        values (#{authUserId}, #{brandId}, #{name}, #{image}, #{pcImage}, #{appletsImage}, #{status}, #{auditStatus}, #{auditBy}, #{auditTime}, #{createBy}, #{createSource}, #{createTime}, 0)
+    </insert>
+    <insert id="insertProductTypeParam">
+        insert into cm_brand_product_type_param (productTypeId, name, content)
+        values (#{productTypeId}, #{paramName}, #{paramContent})
     </insert>
 
     <update id="updateProductStatusByProductId">
@@ -94,6 +98,7 @@
     <update id="updateProductType">
         update cm_brand_product_type
         set name  = #{name},
+            brandId = #{brandId},
             <if test="pcImage != null and pcImage != ''">
                 pcImage = #{pcImage},
             </if>
@@ -125,6 +130,9 @@
     <delete id="deleteParamsByProductId">
         delete from cm_brand_product_param where productId = #{productId}
     </delete>
+    <delete id="deleteParamsByProductTypeId">
+        delete from cm_brand_product_type_param where productTypeId = #{productTypeId}
+    </delete>
     <update id="deleteProductType">
         update cm_brand_product_type set delFlag = 1 where id = #{productTypeId}
     </update>
@@ -196,7 +204,6 @@
     <select id="getProductFormByProductId" resultType="com.caimei.model.vo.ProductFormVo">
         select p.`id`    as productId,
                `authId`,
-               `brandId`,
                cb.name as brandName,
                p.productTypeId,
                if(p.productTypeId is null, p.name, t.name) as productName,
@@ -325,7 +332,7 @@
                  left join cm_brand_product_type t on p.productTypeId = t.id and t.delFlag = 0
                  left join cm_brand_auth a on p.authId = a.id
                  left join cm_brand_auth_user u on a.authUserId = u.authUserId
-                 left join cm_brand_auth_shop_info i on u.authUserId = i.authUserId and p.brandId = i.brandId
+                 left join cm_brand_auth_shop_info i on u.authUserId = i.authUserId and t.brandId = i.brandId
                  left join cm_brand b on i.brandId = b.id
                  left join country c on i.countryId = c.countryId
         where p.id = #{productId}
@@ -345,9 +352,9 @@
         limit 1
     </select>
     <select id="getAuthProductParams" resultType="com.caimei.model.po.ProductParamPo">
-        select name as paramName, content as paramContent
-        from cm_brand_product_param
-        where productId = #{productId}
+        select p.name as paramName, p.content as paramContent
+        from cm_brand_product_type_param p left join cm_brand_auth_product ap on p.productTypeId = ap.productTypeId
+        where ap.id = #{productId}
     </select>
     <select id="getClubProductList" resultType="com.caimei.model.vo.WxProductListVo">
         select p.id as productId, t.name as productName, p.snCode
@@ -396,7 +403,7 @@
         order by t.id desc
     </select>
     <select id="getProductType" resultType="com.caimei.model.po.ProductTypePo">
-        select id as productTypeId, name, image, pcImage, appletsImage
+        select id as productTypeId, brandId, name, image, pcImage, appletsImage, authUserId, createBy
         from cm_brand_product_type
         <where>
             <if test="productTypeId != null">
@@ -425,4 +432,9 @@
                  left join cm_brand_auth a on p.authId = a.id
         where p.id = #{productId}
     </select>
+    <select id="getProductTypeParamList" resultType="com.caimei.model.po.ProductParamPo">
+        select name as paramName, content as paramContent
+        from cm_brand_product_type_param
+        where productTypeId = #{productTypeId}
+    </select>
 </mapper>