java110 5 anni fa
parent
commit
0fe7faa439

+ 9 - 0
java110-bean/src/main/java/com/java110/dto/productSpecValue/ProductSpecValueDto.java

@@ -18,6 +18,7 @@ import java.util.List;
 public class ProductSpecValueDto extends PageDto implements Serializable {
 
     private String specId;
+    private String specName;
     private String valueId;
     private String productId;
     private String[] productIds;
@@ -149,4 +150,12 @@ public class ProductSpecValueDto extends PageDto implements Serializable {
     public void setProductSpecDetails(List<ProductSpecDetailDto> productSpecDetails) {
         this.productSpecDetails = productSpecDetails;
     }
+
+    public String getSpecName() {
+        return specName;
+    }
+
+    public void setSpecName(String specName) {
+        this.specName = specName;
+    }
 }

+ 21 - 0
java110-db/src/main/resources/mapper/common/FileRelServiceDaoImplMapper.xml

@@ -89,6 +89,27 @@
         )
     </insert>
 
+    <insert id="deleteFileRel" parameterType="Map">
+        update file_rel t set t.status_cd = '1'
+        where 1=1
+        <if test="relTypeCd !=null and relTypeCd != ''">
+            and t.rel_type_cd= #{relTypeCd}
+        </if>
+        <if test="fileRealName !=null and fileRealName != ''">
+            and t.file_real_name= #{fileRealName}
+        </if>
+        <if test="objId !=null and objId != ''">
+            and t.obj_id= #{objId}
+        </if>
+        <if test="fileSaveName !=null and fileSaveName != ''">
+            and t.file_save_name= #{fileSaveName}
+        </if>
+        <if test="fileRelId !=null and fileRelId != ''">
+            and t.file_rel_id= #{fileRelId}
+        </if>
+
+    </insert>
+
 
     <!-- 查询文件存放信息 add by wuxw 2018-07-03 -->
     <select id="getFileRelInfo" parameterType="Map" resultType="Map">

+ 65 - 68
java110-db/src/main/resources/mapper/goods/ProductDetailServiceDaoImplMapper.xml

@@ -5,93 +5,90 @@
 <mapper namespace="productDetailServiceDaoImpl">
 
 
-
-
-
     <!-- 保存产品属性信息 add by wuxw 2018-07-03 -->
     <insert id="saveProductDetailInfo" parameterType="Map">
         insert into product_detail(
-product_id,detail_id,store_id,content
-) values (
-#{productId},#{detailId},#{storeId},#{content}
-)
+        product_id,detail_id,store_id,content
+        ) values (
+        #{productId},#{detailId},#{storeId},#{content}
+        )
     </insert>
 
 
-
     <!-- 查询产品属性信息 add by wuxw 2018-07-03 -->
     <select id="getProductDetailInfo" parameterType="Map" resultType="Map">
-        select  t.product_id,t.product_id productId,t.detail_id,t.detail_id detailId,t.status_cd,t.status_cd statusCd,t.store_id,t.store_id storeId,t.content 
-from product_detail t 
-where 1 =1 
-<if test="productId !=null and productId != ''">
-   and t.product_id= #{productId}
-</if> 
-<if test="detailId !=null and detailId != ''">
-   and t.detail_id= #{detailId}
-</if> 
-<if test="statusCd !=null and statusCd != ''">
-   and t.status_cd= #{statusCd}
-</if> 
-<if test="storeId !=null and storeId != ''">
-   and t.store_id= #{storeId}
-</if> 
-<if test="content !=null and content != ''">
-   and t.content= #{content}
-</if> 
-order by t.create_time desc
-<if test="page != -1 and page != null ">
-   limit #{page}, #{row}
-</if> 
+        select t.product_id,t.product_id productId,t.detail_id,t.detail_id detailId,t.status_cd,t.status_cd
+        statusCd,t.store_id,t.store_id storeId,t.content
+        from product_detail t
+        where 1 =1
+        <if test="productId !=null and productId != ''">
+            and t.product_id= #{productId}
+        </if>
+        <if test="detailId !=null and detailId != ''">
+            and t.detail_id= #{detailId}
+        </if>
+        <if test="statusCd !=null and statusCd != ''">
+            and t.status_cd= #{statusCd}
+        </if>
+        <if test="storeId !=null and storeId != ''">
+            and t.store_id= #{storeId}
+        </if>
+        <if test="content !=null and content != ''">
+            and t.content= #{content}
+        </if>
+        order by t.create_time desc
+        <if test="page != -1 and page != null ">
+            limit #{page}, #{row}
+        </if>
 
     </select>
 
 
-
-
     <!-- 修改产品属性信息 add by wuxw 2018-07-03 -->
     <update id="updateProductDetailInfo" parameterType="Map">
-        update  product_detail t set t.status_cd = #{statusCd}
-<if test="newBId != null and newBId != ''">
-,t.b_id = #{newBId}
-</if> 
-<if test="productId !=null and productId != ''">
-, t.product_id= #{productId}
-</if> 
-<if test="storeId !=null and storeId != ''">
-, t.store_id= #{storeId}
-</if> 
-<if test="content !=null and content != ''">
-, t.content= #{content}
-</if> 
- where 1=1 <if test="detailId !=null and detailId != ''">
-and t.detail_id= #{detailId}
-</if> 
+        update product_detail t set t.status_cd = #{statusCd}
+        <if test="newBId != null and newBId != ''">
+            ,t.b_id = #{newBId}
+        </if>
+
+        <if test="content !=null and content != ''">
+            , t.content= #{content}
+        </if>
+        where 1=1
+        <if test="detailId !=null and detailId != ''">
+            and t.detail_id= #{detailId}
+        </if>
+        <if test="productId !=null and productId != ''">
+            and t.product_id= #{productId}
+        </if>
+        <if test="storeId !=null and storeId != ''">
+            and t.store_id= #{storeId}
+        </if>
 
     </update>
 
     <!-- 查询产品属性数量 add by wuxw 2018-07-03 -->
-     <select id="queryProductDetailsCount" parameterType="Map" resultType="Map">
-        select  count(1) count 
-from product_detail t 
-where 1 =1 
-<if test="productId !=null and productId != ''">
-   and t.product_id= #{productId}
-</if> 
-<if test="detailId !=null and detailId != ''">
-   and t.detail_id= #{detailId}
-</if> 
-<if test="statusCd !=null and statusCd != ''">
-   and t.status_cd= #{statusCd}
-</if> 
-<if test="storeId !=null and storeId != ''">
-   and t.store_id= #{storeId}
-</if> 
-<if test="content !=null and content != ''">
-   and t.content= #{content}
-</if> 
+    <select id="queryProductDetailsCount" parameterType="Map" resultType="Map">
+        select count(1) count
+        from product_detail t
+        where 1 =1
+        <if test="productId !=null and productId != ''">
+            and t.product_id= #{productId}
+        </if>
+        <if test="detailId !=null and detailId != ''">
+            and t.detail_id= #{detailId}
+        </if>
+        <if test="statusCd !=null and statusCd != ''">
+            and t.status_cd= #{statusCd}
+        </if>
+        <if test="storeId !=null and storeId != ''">
+            and t.store_id= #{storeId}
+        </if>
+        <if test="content !=null and content != ''">
+            and t.content= #{content}
+        </if>
 
 
-     </select>
+    </select>
 
 </mapper>

+ 6 - 4
java110-db/src/main/resources/mapper/goods/ProductSpecValueServiceDaoImplMapper.xml

@@ -19,8 +19,9 @@
     <select id="getProductSpecValueInfo" parameterType="Map" resultType="Map">
         select t.spec_id,t.spec_id specId,t.value_id,t.value_id valueId,t.product_id,t.product_id
         productId,t.price,t.ot_price,t.ot_price otPrice,t.cost_price,t.cost_price costPrice,t.vip_price,t.vip_price
-        vipPrice,t.status_cd,t.status_cd statusCd,t.store_id,t.store_id storeId,t.stock,t.sales
+        vipPrice,t.status_cd,t.status_cd statusCd,t.store_id,t.store_id storeId,t.stock,t.sales,ps.spec_name specName
         from product_spec_value t
+        left join product_spec ps on t.spec_id = ps.spec_id and ps.store_id = t.store_id and ps.status_cd = '0'
         where 1 =1
         <if test="specId !=null and specId != ''">
             and t.spec_id= #{specId}
@@ -93,9 +94,7 @@
         <if test="specId !=null and specId != ''">
             , t.spec_id= #{specId}
         </if>
-        <if test="productId !=null and productId != ''">
-            , t.product_id= #{productId}
-        </if>
+
         <if test="price !=null and price != ''">
             , t.price= #{price}
         </if>
@@ -121,6 +120,9 @@
         <if test="valueId !=null and valueId != ''">
             and t.value_id= #{valueId}
         </if>
+        <if test="productId !=null and productId != ''">
+            and t.product_id= #{productId}
+        </if>
 
     </update>
 

+ 3 - 0
java110-interface/src/main/java/com/java110/intf/common/IFileRelInnerServiceSMO.java

@@ -35,6 +35,9 @@ public interface IFileRelInnerServiceSMO {
     @RequestMapping(value = "/saveFileRel", method = RequestMethod.POST)
     public int saveFileRel(@RequestBody FileRelPo fileRelPo);
 
+    @RequestMapping(value = "/deleteFileRel", method = RequestMethod.POST)
+    public int deleteFileRel(@RequestBody FileRelPo fileRelPo);
+
     /**
      * 查询<p>小区楼</p>总记录数
      *

+ 8 - 12
service-common/src/main/java/com/java110/common/dao/IFileRelServiceDao.java

@@ -1,13 +1,7 @@
 package com.java110.common.dao;
 
 
-import com.java110.po.file.FileRelPo;
 import com.java110.utils.exception.DAOException;
-import com.java110.entity.merchant.BoMerchant;
-import com.java110.entity.merchant.BoMerchantAttr;
-import com.java110.entity.merchant.Merchant;
-import com.java110.entity.merchant.MerchantAttr;
-
 
 import java.util.List;
 import java.util.Map;
@@ -16,23 +10,24 @@ import java.util.Map;
  * 文件存放组件内部之间使用,没有给外围系统提供服务能力
  * 文件存放服务接口类,要求全部以字符串传输,方便微服务化
  * 新建客户,修改客户,删除客户,查询客户等功能
- *
+ * <p>
  * Created by wuxw on 2016/12/27.
  */
 public interface IFileRelServiceDao {
 
     /**
      * 保存 文件存放信息
+     *
      * @param businessFileRelInfo 文件存放信息 封装
      * @throws DAOException 操作数据库异常
      */
     void saveBusinessFileRelInfo(Map businessFileRelInfo) throws DAOException;
 
 
-
     /**
      * 查询文件存放信息(business过程)
      * 根据bId 查询文件存放信息
+     *
      * @param info bId 信息
      * @return 文件存放信息
      * @throws DAOException DAO异常
@@ -40,10 +35,9 @@ public interface IFileRelServiceDao {
     List<Map> getBusinessFileRelInfo(Map info) throws DAOException;
 
 
-
-
     /**
      * 保存 文件存放信息 Business数据到 Instance中
+     *
      * @param info
      * @throws DAOException DAO异常
      */
@@ -52,17 +46,19 @@ public interface IFileRelServiceDao {
 
     /**
      * 保存文件管理
+     *
      * @param info
      * @return
      */
     int saveFileRel(Map info);
 
-
+    int deleteFileRel(Map info);
 
 
     /**
      * 查询文件存放信息(instance过程)
      * 根据bId 查询文件存放信息
+     *
      * @param info bId 信息
      * @return 文件存放信息
      * @throws DAOException DAO异常
@@ -70,9 +66,9 @@ public interface IFileRelServiceDao {
     List<Map> getFileRelInfo(Map info) throws DAOException;
 
 
-
     /**
      * 修改文件存放信息
+     *
      * @param info 修改信息
      * @throws DAOException DAO异常
      */

+ 11 - 0
service-common/src/main/java/com/java110/common/dao/impl/FileRelServiceDaoImpl.java

@@ -88,6 +88,17 @@ public class FileRelServiceDaoImpl extends BaseServiceDao implements IFileRelSer
         return saveFlag;
     }
 
+    @Override
+    public int deleteFileRel(Map info) {
+        int deleteFlag = sqlSessionTemplate.insert("fileRelServiceDaoImpl.deleteFileRel", info);
+
+        if (deleteFlag < 1) {
+            throw new DAOException(ResponseConstant.RESULT_PARAM_ERROR, "删除文件存放信息Instance数据失败:" + JSONObject.toJSONString(info));
+        }
+
+        return deleteFlag;
+    }
+
 
     /**
      * 查询文件存放信息(instance)

+ 4 - 0
service-common/src/main/java/com/java110/common/smo/impl/FileRelInnerServiceSMOImpl.java

@@ -59,6 +59,10 @@ public class FileRelInnerServiceSMOImpl extends BaseServiceSMO implements IFileR
         return fileRelServiceDaoImpl.saveFileRel(BeanConvertUtil.beanCovertMap(fileRelPo));
     }
 
+    public int deleteFileRel(@RequestBody FileRelPo fileRelPo){
+        return fileRelServiceDaoImpl.deleteFileRel(BeanConvertUtil.beanCovertMap(fileRelPo));
+    }
+
 
     @Override
     public int queryFileRelsCount(@RequestBody FileRelDto fileRelDto) {

+ 24 - 1
service-goods/src/main/java/com/java110/goods/api/ProductApi.java

@@ -191,10 +191,33 @@ public class ProductApi {
         Assert.hasKeyAndValue(reqJson, "isPostage", "请求报文中未包含isPostage");
         Assert.hasKeyAndValue(reqJson, "productId", "productId不能为空");
 
+        String coverPhoto = reqJson.containsKey("coverPhoto") ? reqJson.getString("coverPhoto") : "";
+        JSONArray carouselFigurePhoto = reqJson.containsKey("carouselFigurePhoto") ? reqJson.getJSONArray("carouselFigurePhoto") : null;
+
+        JSONArray productSpecs = reqJson.containsKey("productSpecs") ? reqJson.getJSONArray("productSpecs") : null;
+
+        JSONObject spec = null;
+        List<ProductSpecValuePo> productSpecValuePos = null;;
+        if (productSpecs != null) {
+            productSpecValuePos = new ArrayList<>();
+            for (int specIndex = 0; specIndex < productSpecs.size(); specIndex++) {
+                spec = productSpecs.getJSONObject(specIndex);
+                productSpecValuePos.add(BeanConvertUtil.covertBean(spec, ProductSpecValuePo.class));
+            }
+        }
 
         ProductPo productPo = BeanConvertUtil.covertBean(reqJson, ProductPo.class);
         productPo.setStoreId(storeId);
-        return updateProductBMOImpl.update(productPo);
+
+
+        ProductDetailPo productDetailPo = null;
+        if(reqJson.containsKey("content")) {
+            productDetailPo = new ProductDetailPo();
+            productDetailPo.setStoreId(storeId);
+            productDetailPo.setContent(reqJson.getString("content"));
+        }
+
+        return updateProductBMOImpl.update(productPo, coverPhoto, carouselFigurePhoto, productSpecValuePos, productDetailPo);
     }
 
     /**

+ 7 - 1
service-goods/src/main/java/com/java110/goods/bmo/product/IUpdateProductBMO.java

@@ -1,7 +1,12 @@
 package com.java110.goods.bmo.product;
+import com.alibaba.fastjson.JSONArray;
 import com.java110.po.product.ProductPo;
+import com.java110.po.productDetail.ProductDetailPo;
+import com.java110.po.productSpecValue.ProductSpecValuePo;
 import org.springframework.http.ResponseEntity;
 
+import java.util.List;
+
 public interface IUpdateProductBMO {
 
 
@@ -11,7 +16,8 @@ public interface IUpdateProductBMO {
      * @param productPo
      * @return
      */
-    ResponseEntity<String> update(ProductPo productPo);
+    ResponseEntity<String> update(ProductPo productPo, String coverPhoto, JSONArray carouselFigurePhoto,
+                                  List<ProductSpecValuePo> productSpecValuePos, ProductDetailPo productDetailPo);
 
 
 }

+ 115 - 3
service-goods/src/main/java/com/java110/goods/bmo/product/impl/UpdateProductBMOImpl.java

@@ -1,34 +1,146 @@
 package com.java110.goods.bmo.product.impl;
 
+import com.alibaba.fastjson.JSONArray;
 import com.java110.core.annotation.Java110Transactional;
+import com.java110.core.factory.GenerateCodeFactory;
+import com.java110.dto.file.FileDto;
+import com.java110.dto.file.FileRelDto;
+import com.java110.dto.productDetail.ProductDetailDto;
 import com.java110.goods.bmo.product.IUpdateProductBMO;
+import com.java110.intf.IProductDetailInnerServiceSMO;
+import com.java110.intf.IProductSpecValueInnerServiceSMO;
+import com.java110.intf.common.IFileInnerServiceSMO;
+import com.java110.intf.common.IFileRelInnerServiceSMO;
 import com.java110.intf.goods.IProductInnerServiceSMO;
+import com.java110.po.file.FileRelPo;
 import com.java110.po.product.ProductPo;
+import com.java110.po.productDetail.ProductDetailPo;
+import com.java110.po.productSpecValue.ProductSpecValuePo;
+import com.java110.utils.util.StringUtil;
 import com.java110.vo.ResultVo;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.http.ResponseEntity;
 import org.springframework.stereotype.Service;
 
+import java.util.List;
+
 @Service("updateProductBMOImpl")
 public class UpdateProductBMOImpl implements IUpdateProductBMO {
 
     @Autowired
     private IProductInnerServiceSMO productInnerServiceSMOImpl;
+    @Autowired
+    private IFileRelInnerServiceSMO fileRelInnerServiceSMOImpl;
+    @Autowired
+    private IFileInnerServiceSMO fileInnerServiceSMOImpl;
+
+    @Autowired
+    private IProductSpecValueInnerServiceSMO productSpecValueInnerServiceSMOImpl;
+
+    @Autowired
+    private IProductDetailInnerServiceSMO productDetailInnerServiceSMOImpl;
 
     /**
      * @param productPo
      * @return 订单服务能够接受的报文
      */
     @Java110Transactional
-    public ResponseEntity<String> update(ProductPo productPo) {
+    public ResponseEntity<String> update(ProductPo productPo, String coverPhoto, JSONArray carouselFigurePhoto,
+                                         List<ProductSpecValuePo> productSpecValuePos, ProductDetailPo productDetailPo) {
 
         int flag = productInnerServiceSMOImpl.updateProduct(productPo);
 
-        if (flag > 0) {
+//保存商品封面
+        doSavaRentingFile(coverPhoto, productPo, FileRelDto.REL_TYPE_CD_GOODS_COVER);
+
+        if (carouselFigurePhoto != null) {
+            for (int carouselIndex = 0; carouselIndex < carouselFigurePhoto.size(); carouselIndex++) {
+                doSavaRentingFile(carouselFigurePhoto.getString(carouselIndex), productPo, FileRelDto.REL_TYPE_CD_GOODS_CAROUSEL_FIGURE);
+            }
+        }
+        if (productSpecValuePos != null) {
+            //删除所有 规格
+            ProductSpecValuePo deleteProductSpecValuePo = new ProductSpecValuePo();
+            deleteProductSpecValuePo.setStoreId(productPo.getStoreId());
+            deleteProductSpecValuePo.setProductId(productPo.getProductId());
+            productSpecValueInnerServiceSMOImpl.deleteProductSpecValue(deleteProductSpecValuePo);
+            for (ProductSpecValuePo productSpecValuePo : productSpecValuePos) {
+                productSpecValuePo.setStoreId(productPo.getStoreId());
+                productSpecValuePo.setProductId(productPo.getProductId());
+                productSpecValuePo.setValueId(GenerateCodeFactory.getGeneratorId(GenerateCodeFactory.CODE_PREFIX_valueId));
+                flag = productSpecValueInnerServiceSMOImpl.saveProductSpecValue(productSpecValuePo);
+
+                if (flag < 1) {
+                    throw new IllegalArgumentException("保存规格失败");
+                }
+            }
+        }
+
+        if (productDetailPo == null) {
             return ResultVo.createResponseEntity(ResultVo.CODE_OK, "保存成功");
         }
+        ProductDetailDto productDetailDto = new ProductDetailDto();
+        productDetailDto.setProductId(productPo.getProductId());
+        productDetailDto.setStoreId(productPo.getStoreId());
+        List<ProductDetailDto> productDetailDtos = productDetailInnerServiceSMOImpl.queryProductDetails(productDetailDto);
+
+        if (productDetailDtos == null || productDetailDtos.size() < 1) {
+            productDetailPo.setProductId(productPo.getProductId());
+            productDetailPo.setDetailId(GenerateCodeFactory.getGeneratorId(GenerateCodeFactory.CODE_PREFIX_detailId));
+            flag = productDetailInnerServiceSMOImpl.saveProductDetail(productDetailPo);
+        }else{
+            productDetailPo.setProductId(productPo.getProductId());
+            flag = productDetailInnerServiceSMOImpl.updateProductDetail(productDetailPo);
+
+        }
+        if (flag < 1) {
+            throw new IllegalArgumentException("保存规格失败");
+        }
 
-        return ResultVo.createResponseEntity(ResultVo.CODE_ERROR, "保存失败");
+
+        return ResultVo.createResponseEntity(ResultVo.CODE_OK, "保存成功");
+    }
+
+
+    /**
+     * 保存房屋租赁 图片
+     *
+     * @param photo
+     * @param productPo
+     */
+    private void doSavaRentingFile(String photo, ProductPo productPo, String fileTypeCd) {
+
+        if (StringUtil.isEmpty(photo)) {
+            return;
+        }
+
+        //删除 图片
+        FileRelPo fileRelPo = new FileRelPo();
+        fileRelPo.setObjId(productPo.getProductId());
+        fileRelPo.setRelTypeCd(fileTypeCd);
+        fileRelInnerServiceSMOImpl.deleteFileRel(fileRelPo);
+
+        FileDto fileDto = new FileDto();
+        fileDto.setCommunityId("-1");
+        fileDto.setContext(photo);
+        fileDto.setFileId(GenerateCodeFactory.getGeneratorId(GenerateCodeFactory.CODE_PREFIX_file_id));
+        fileDto.setFileName(fileDto.getFileId());
+
+        fileDto.setSuffix("jpeg");
+        String fileName = fileInnerServiceSMOImpl.saveFile(fileDto);
+
+        fileRelPo = new FileRelPo();
+        fileRelPo.setObjId(productPo.getProductId());
+        fileRelPo.setRelTypeCd(fileTypeCd);
+        fileRelPo.setFileRelId(GenerateCodeFactory.getGeneratorId(GenerateCodeFactory.CODE_PREFIX_relId));
+        fileRelPo.setFileRealName(fileName);
+        fileRelPo.setFileSaveName(fileName);
+        fileRelPo.setSaveWay(FileRelDto.SAVE_WAY_FTP);
+        int save = fileRelInnerServiceSMOImpl.saveFileRel(fileRelPo);
+
+        if (save < 1) {
+            throw new IllegalArgumentException("保存文件失败");
+        }
     }
 
 }