Ver Fonte

阶梯价格编辑-接口

home chao há 5 anos atrás
pai
commit
13f7583181

+ 6 - 1
pom.xml

@@ -38,6 +38,11 @@
             <artifactId>mybatis-spring-boot-starter</artifactId>
             <version>1.3.1</version>
         </dependency>
+        <dependency>
+            <groupId>org.projectlombok</groupId>
+            <artifactId>lombok</artifactId>
+            <optional>true</optional>
+        </dependency>
 
         <!-- mysql的依赖 -->
         <dependency>
@@ -200,4 +205,4 @@
             </plugin>
         </plugins>
     </build>
-</project>
+</project>

+ 14 - 4
src/main/java/com/caimei/modules/products/controller/CmMallOrganizeProductsController.java

@@ -8,7 +8,10 @@ import com.caimei.modules.products.entity.CmMallPageModules;
 import com.caimei.modules.products.entity.CmMallProductsClassify;
 import com.caimei.modules.products.service.CmMallOrganizeProductsService;
 import com.caimei.modules.products.service.CmMallProductsClassifyService;
+import com.caimei.modules.shiro.entity.CmMallAdminUser;
+import com.caimei.modules.shiro.service.ShiroService;
 import com.caimei.utils.JsonModel;
+import com.caimei.utils.TokenEncryptUtils;
 import com.github.pagehelper.PageHelper;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Controller;
@@ -18,6 +21,7 @@ import org.springframework.web.bind.annotation.RequestMethod;
 import org.springframework.web.bind.annotation.ResponseBody;
 import org.thymeleaf.util.StringUtils;
 
+import javax.servlet.http.HttpServletRequest;
 import java.util.Date;
 import java.util.HashMap;
 import java.util.List;
@@ -37,7 +41,8 @@ public class CmMallOrganizeProductsController {
     private CmMallOrganizeProductsService cmMallOrganizeProductsService;
     @Autowired
     private CmMallProductsClassifyService cmMallProductsClassifyService;
-
+    @Autowired
+    private ShiroService shiroService;
     /**
      * 去商品列表页面
      *
@@ -88,11 +93,16 @@ public class CmMallOrganizeProductsController {
      */
     @ResponseBody
     @RequestMapping(value = "saveEditProductInfo", method = RequestMethod.POST)
-    public JsonModel saveEditProductInfo(@RequestBody CmMallOrganizeProducts cmMallOrganizeProducts) {
+    public JsonModel saveEditProductInfo(@RequestBody CmMallOrganizeProducts cmMallOrganizeProducts, HttpServletRequest httpRequest) {
         JsonModel jsonModel = JsonModel.newInstance();
         try {
+            String token = httpRequest.getHeader("token");
+            String decoded = TokenEncryptUtils.decoded(token);
+            String[] tokens = decoded.split("#,#");
+            CmMallAdminUser user = shiroService.findByUserId(Integer.valueOf(tokens[1]));
+            Long userId = user.getId().longValue();
             cmMallOrganizeProducts.setUpdateTime(new Date());
-            cmMallOrganizeProductsService.updateProductInfo(cmMallOrganizeProducts);
+            cmMallOrganizeProductsService.updateProductInfo(cmMallOrganizeProducts, userId);
             return jsonModel.success("修改成功", "");
         } catch (Exception e) {
             return jsonModel.error("修改失败");
@@ -222,4 +232,4 @@ public class CmMallOrganizeProductsController {
         cmMallOrganizeProductsService.canncelPreferredProduct(cmMallOrganizeProducts);
         return JsonModel.newInstance().success();
     }
-}
+}

+ 27 - 0
src/main/java/com/caimei/modules/products/dao/CmMallProductLadderPriceDao.java

@@ -0,0 +1,27 @@
+package com.caimei.modules.products.dao;
+
+import com.caimei.modules.products.entity.CmMallProductLadderPrice;
+import org.apache.ibatis.annotations.Mapper;
+import org.apache.ibatis.annotations.Param;
+
+import java.util.List;
+
+@Mapper
+public interface CmMallProductLadderPriceDao {
+    int deleteByPrimaryKey(Long id);
+
+    int insert(CmMallProductLadderPrice record);
+
+    int insertSelective(CmMallProductLadderPrice record);
+
+    CmMallProductLadderPrice selectByPrimaryKey(Long id);
+
+    int updateByPrimaryKeySelective(CmMallProductLadderPrice record);
+
+    int updateByPrimaryKey(CmMallProductLadderPrice record);
+
+    List<CmMallProductLadderPrice> selectByProductId(Long productId);
+
+    Long selectIdByProductIdAndLadderNum(@Param("productId") Long productId, @Param("ladderNum") Long ladderNum);
+
+}

+ 26 - 1
src/main/java/com/caimei/modules/products/entity/CmMallOrganizeProducts.java

@@ -2,6 +2,7 @@ package com.caimei.modules.products.entity;
 
 import java.io.Serializable;
 import java.util.Date;
+import java.util.List;
 
 /**
  * 小程序商城商品Entity
@@ -18,6 +19,10 @@ public class CmMallOrganizeProducts implements Serializable {
     private String productID;        // 商品ID,具体对应product表
     private String normalPrice;        // 市场价
     private String costPrice;        // 成本价
+    /**
+     * '启用阶梯价格标识 0否 1是',
+     */
+    private String ladderPriceFlag;
     private String retailPrice;        // 售价
     private String minBuyNumber;        // 最小起订量
     private String preferredProduct;        // 是否是优选商品:0不是优选,1优选商品
@@ -30,6 +35,18 @@ public class CmMallOrganizeProducts implements Serializable {
     private Date addTime;        // 添加时间
     private Date updateTime;        // 更新时间
     private Integer modules;     //第几个模块
+    /**
+     * 阶梯价格
+     */
+    private List<CmMallProductLadderPrice> ladderPriceList;
+
+    public List<CmMallProductLadderPrice> getLadderPriceList() {
+        return ladderPriceList;
+    }
+
+    public void setLadderPriceList(List<CmMallProductLadderPrice> ladderPriceList) {
+        this.ladderPriceList = ladderPriceList;
+    }
 
     //非小程序商城商品信息
     private String mainImage;//商品图片
@@ -92,6 +109,14 @@ public class CmMallOrganizeProducts implements Serializable {
         this.costPrice = costPrice;
     }
 
+    public String getLadderPriceFlag() {
+        return ladderPriceFlag;
+    }
+
+    public void setLadderPriceFlag(String ladderPriceFlag) {
+        this.ladderPriceFlag = ladderPriceFlag;
+    }
+
     public String getRetailPrice() {
         return retailPrice;
     }
@@ -235,4 +260,4 @@ public class CmMallOrganizeProducts implements Serializable {
     public void setExistsFlag(String existsFlag) {
         this.existsFlag = existsFlag;
     }
-}
+}

+ 62 - 0
src/main/java/com/caimei/modules/products/entity/CmMallProductLadderPrice.java

@@ -0,0 +1,62 @@
+package com.caimei.modules.products.entity;
+
+import java.io.Serializable;
+import java.math.BigDecimal;
+import java.util.Date;
+import lombok.Data;
+
+/**
+ * cm_mall_product_ladder_price
+ * @author 
+ */
+@Data
+public class CmMallProductLadderPrice implements Serializable {
+    private Long id;
+
+    /**
+     * 商品id,具体对应cm_mall_organize_products表的ID
+     */
+    private Long productId;
+
+    /**
+     * 第几阶梯(最多可设置3阶梯)
+     */
+    private Long ladderNum;
+
+    /**
+     * 购买数量(起订量)
+     */
+    private Long buyNum;
+
+    /**
+     * 购买价格(对应起订量单价)
+     */
+    private BigDecimal buyPrice;
+
+    /**
+     * 创建人(cm_mall_admin_user表ID)
+     */
+    private Long createBy;
+
+    /**
+     * 创建时间
+     */
+    private Date createDate;
+
+    /**
+     * 最后更新人(cm_mall_admin_user表ID)
+     */
+    private Long updateBy;
+
+    /**
+     * 最后更新时间
+     */
+    private Date updateDate;
+
+    /**
+     * 删除标记  0 否,其余是
+     */
+    private String delFlag;
+
+    private static final long serialVersionUID = 1L;
+}

+ 2 - 2
src/main/java/com/caimei/modules/products/service/CmMallOrganizeProductsService.java

@@ -14,7 +14,7 @@ public interface CmMallOrganizeProductsService {
 
     List<CmMallPageModules> findAllModule(Integer organizeID);
 
-    void updateProductInfo(CmMallOrganizeProducts cmMallOrganizeProducts);
+    void updateProductInfo(CmMallOrganizeProducts cmMallOrganizeProducts, Long userId);
 
     CmMallOrganizeProducts get(Integer id);
 
@@ -27,4 +27,4 @@ public interface CmMallOrganizeProductsService {
     void updateProductInfo1(CmMallOrganizeProducts cop);
 
     void canncelPreferredProduct(CmMallOrganizeProducts cmMallOrganizeProducts);
-}
+}

+ 41 - 2
src/main/java/com/caimei/modules/products/service/impl/CmMallOrganizeProductsServiceImpl.java

@@ -2,8 +2,10 @@ package com.caimei.modules.products.service.impl;
 
 import com.caimei.modules.club.entity.Page;
 import com.caimei.modules.products.dao.CmMallOrganizeProductsDao;
+import com.caimei.modules.products.dao.CmMallProductLadderPriceDao;
 import com.caimei.modules.products.entity.CmMallOrganizeProducts;
 import com.caimei.modules.products.entity.CmMallPageModules;
+import com.caimei.modules.products.entity.CmMallProductLadderPrice;
 import com.caimei.modules.products.service.CmMallOrganizeProductsService;
 import com.caimei.utils.AppUtils;
 import com.github.pagehelper.PageHelper;
@@ -12,12 +14,16 @@ import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Value;
 import org.springframework.stereotype.Service;
 
+import javax.annotation.Resource;
+import java.util.Date;
 import java.util.List;
 
 @Service
 public class CmMallOrganizeProductsServiceImpl implements CmMallOrganizeProductsService {
-    @Autowired
+    @Resource
     private CmMallOrganizeProductsDao cmMallOrganizeProductsDao;
+    @Resource
+    private CmMallProductLadderPriceDao cmMallProductLadderPriceDao;
     @Value("${malladmin.domain}")
     private String domain;
 
@@ -33,6 +39,11 @@ public class CmMallOrganizeProductsServiceImpl implements CmMallOrganizeProducts
         if (CollectionUtils.isNotEmpty(organizeProductsDaoList)) {
             for (CmMallOrganizeProducts c : organizeProductsDaoList) {
                 c.setMainImage(AppUtils.getProductImageURL(c.getMainImage(), 0, domain));
+                if ("1".equals(c.getLadderPriceFlag())){
+                    Long productId = c.getId().longValue();
+                    List<CmMallProductLadderPrice> ladderPriceList = cmMallProductLadderPriceDao.selectByProductId(productId);
+                    c.setLadderPriceList(ladderPriceList);
+                }
             }
         }
         Page<CmMallOrganizeProducts> organizeProductsPage = new Page<>(organizeProductsDaoList);
@@ -45,8 +56,31 @@ public class CmMallOrganizeProductsServiceImpl implements CmMallOrganizeProducts
     }
 
     @Override
-    public void updateProductInfo(CmMallOrganizeProducts cmMallOrganizeProducts) {
+    public void updateProductInfo(CmMallOrganizeProducts cmMallOrganizeProducts, Long userId) {
         cmMallOrganizeProductsDao.updateProductInfo(cmMallOrganizeProducts);
+        if("1".equals(cmMallOrganizeProducts.getLadderPriceFlag())) {
+            List<CmMallProductLadderPrice> ladderPriceList = cmMallOrganizeProducts.getLadderPriceList();
+            Long productId = cmMallOrganizeProducts.getId().longValue();
+            CmMallProductLadderPrice ladderPrice = new CmMallProductLadderPrice();
+            ladderPrice.setProductId(productId);
+            ladderPrice.setUpdateBy(userId);
+            ladderPrice.setUpdateDate(new Date());
+            for (CmMallProductLadderPrice item: ladderPriceList) {
+                ladderPrice.setLadderNum(item.getLadderNum());
+                ladderPrice.setBuyNum(item.getBuyNum());
+                ladderPrice.setBuyPrice(item.getBuyPrice());
+                ladderPrice.setDelFlag(item.getDelFlag());
+                Long ladderPriceId = cmMallProductLadderPriceDao.selectIdByProductIdAndLadderNum(productId, item.getLadderNum());
+                if (null !=ladderPriceId && ladderPriceId > 0L){
+                    ladderPrice.setId(ladderPriceId);
+                    cmMallProductLadderPriceDao.updateByPrimaryKeySelective(ladderPrice);
+                }else{
+                    ladderPrice.setCreateBy(userId);
+                    ladderPrice.setCreateDate(new Date());
+                    cmMallProductLadderPriceDao.insertSelective(ladderPrice);
+                }
+            }
+        }
     }
 
     @Override
@@ -77,6 +111,11 @@ public class CmMallOrganizeProductsServiceImpl implements CmMallOrganizeProducts
                         c.setExistsFlag("1");
                     }
                 }
+                if ("1".equals(c.getLadderPriceFlag())){
+                    Long productId = c.getId().longValue();
+                    List<CmMallProductLadderPrice> ladderPriceList = cmMallProductLadderPriceDao.selectByProductId(productId);
+                    c.setLadderPriceList(ladderPriceList);
+                }
             }
         }
         return listBuyMall;

+ 9 - 1
src/main/resources/application.yml

@@ -1,3 +1,11 @@
 spring:
   profiles:
-    active: @activatedProperties@
+    active: @activatedProperties@
+
+# 开启logging myabtis语句打印
+# mybatis:
+#   configuration:
+#     log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
+logging:
+  level:
+    com.caimei.modules.products.dao: debug

+ 3 - 3
src/main/resources/dev/application-dev.yml

@@ -12,9 +12,9 @@ spring:
     #数据源连接--start
   datasource:
     driverClassName: com.mysql.jdbc.Driver
-    url: jdbc:mysql://192.168.1.11:3306/caimei@20180509?characterEncoding=UTF8
-    username: developer
-    password: 05bZ/OxTB:X+yd%1
+    url: jdbc:mysql://119.29.0.46:3306/caimei_dev?useUnicode=true&characterEncoding=utf-8
+    username: general
+    password: 6#xsI%b4o@5c3RoE
     #数据源连接--end
 
   #模板引擎配置

+ 3 - 1
src/main/resources/mapper/CmMallOrganizeProductsMapper.xml

@@ -10,6 +10,7 @@
 		a.productID AS "productID",
 		a.normalPrice AS "normalPrice",
 		a.costPrice AS "costPrice",
+        a.ladderPriceFlag AS "ladderPriceFlag",
 		a.retailPrice AS "retailPrice",
 		a.minBuyNumber AS "minBuyNumber",
 		a.preferredProduct AS "preferredProduct",
@@ -108,6 +109,7 @@
 		classifyID = #{classifyID},
 		normalPrice = #{normalPrice},
 		costPrice = #{costPrice},
+        ladderPriceFlag = #{ladderPriceFlag},
 		retailPrice = #{retailPrice},
 		minBuyNumber = #{minBuyNumber},
 		updateTime = #{updateTime}
@@ -239,4 +241,4 @@
 		updateTime = #{updateTime}
 		WHERE id = #{id}
 	</update>
-</mapper>
+</mapper>

+ 160 - 0
src/main/resources/mapper/CmMallProductLadderPriceMapper.xml

@@ -0,0 +1,160 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+<mapper namespace="com.caimei.modules.products.dao.CmMallProductLadderPriceDao">
+  <resultMap id="BaseResultMap" type="com.caimei.modules.products.entity.CmMallProductLadderPrice">
+    <id column="id" jdbcType="BIGINT" property="id" />
+    <result column="productId" jdbcType="BIGINT" property="productId" />
+    <result column="ladderNum" jdbcType="BIGINT" property="ladderNum" />
+    <result column="buyNum" jdbcType="BIGINT" property="buyNum" />
+    <result column="buyPrice" jdbcType="DECIMAL" property="buyPrice" />
+    <result column="createBy" jdbcType="BIGINT" property="createBy" />
+    <result column="createDate" jdbcType="TIMESTAMP" property="createDate" />
+    <result column="updateBy" jdbcType="BIGINT" property="updateBy" />
+    <result column="updateDate" jdbcType="TIMESTAMP" property="updateDate" />
+    <result column="delFlag" jdbcType="CHAR" property="delFlag" />
+  </resultMap>
+  <sql id="Base_Column_List">
+    id, productId, ladderNum, buyNum, buyPrice, createBy, createDate, updateBy, updateDate,
+    delFlag
+  </sql>
+  <select id="selectByPrimaryKey" parameterType="java.lang.Long" resultMap="BaseResultMap">
+    select
+    <include refid="Base_Column_List" />
+    from cm_mall_product_ladder_price
+    where id = #{id,jdbcType=BIGINT}
+  </select>
+  <select id="selectByProductId" parameterType="java.lang.Long" resultMap="BaseResultMap">
+    select
+    <include refid="Base_Column_List" />
+    from cm_mall_product_ladder_price
+    where productId = #{productId,jdbcType=BIGINT}
+    order by ladderNum
+  </select>
+  <select id="selectIdByProductIdAndLadderNum" parameterType="java.lang.Long" resultType="java.lang.Long">
+    select id
+    from cm_mall_product_ladder_price
+    where productId = #{productId,jdbcType=BIGINT}
+      and ladderNum = #{ladderNum,jdbcType=BIGINT}
+  </select>
+  <delete id="deleteByPrimaryKey" parameterType="java.lang.Long">
+    delete from cm_mall_product_ladder_price
+    where id = #{id,jdbcType=BIGINT}
+  </delete>
+  <insert id="insert" keyColumn="id" keyProperty="id" parameterType="com.caimei.modules.products.entity.CmMallProductLadderPrice" useGeneratedKeys="true">
+    insert into cm_mall_product_ladder_price (productId, ladderNum, buyNum,
+      buyPrice, createBy, createDate,
+      updateBy, updateDate, delFlag
+      )
+    values (#{productId,jdbcType=BIGINT}, #{ladderNum,jdbcType=BIGINT}, #{buyNum,jdbcType=BIGINT},
+      #{buyPrice,jdbcType=DECIMAL}, #{createBy,jdbcType=BIGINT}, #{createDate,jdbcType=TIMESTAMP},
+      #{updateBy,jdbcType=BIGINT}, #{updateDate,jdbcType=TIMESTAMP}, #{delFlag,jdbcType=CHAR}
+      )
+  </insert>
+  <insert id="insertSelective" keyColumn="id" keyProperty="id" parameterType="com.caimei.modules.products.entity.CmMallProductLadderPrice" useGeneratedKeys="true">
+    insert into cm_mall_product_ladder_price
+    <trim prefix="(" suffix=")" suffixOverrides=",">
+      <if test="productId != null">
+        productId,
+      </if>
+      <if test="ladderNum != null">
+        ladderNum,
+      </if>
+      <if test="buyNum != null">
+        buyNum,
+      </if>
+      <if test="buyPrice != null">
+        buyPrice,
+      </if>
+      <if test="createBy != null">
+        createBy,
+      </if>
+      <if test="createDate != null">
+        createDate,
+      </if>
+      <if test="updateBy != null">
+        updateBy,
+      </if>
+      <if test="updateDate != null">
+        updateDate,
+      </if>
+      <if test="delFlag != null">
+        delFlag,
+      </if>
+    </trim>
+    <trim prefix="values (" suffix=")" suffixOverrides=",">
+      <if test="productId != null">
+        #{productId,jdbcType=BIGINT},
+      </if>
+      <if test="ladderNum != null">
+        #{ladderNum,jdbcType=BIGINT},
+      </if>
+      <if test="buyNum != null">
+        #{buyNum,jdbcType=BIGINT},
+      </if>
+      <if test="buyPrice != null">
+        #{buyPrice,jdbcType=DECIMAL},
+      </if>
+      <if test="createBy != null">
+        #{createBy,jdbcType=BIGINT},
+      </if>
+      <if test="createDate != null">
+        #{createDate,jdbcType=TIMESTAMP},
+      </if>
+      <if test="updateBy != null">
+        #{updateBy,jdbcType=BIGINT},
+      </if>
+      <if test="updateDate != null">
+        #{updateDate,jdbcType=TIMESTAMP},
+      </if>
+      <if test="delFlag != null">
+        #{delFlag,jdbcType=CHAR},
+      </if>
+    </trim>
+  </insert>
+  <update id="updateByPrimaryKeySelective" parameterType="com.caimei.modules.products.entity.CmMallProductLadderPrice">
+    update cm_mall_product_ladder_price
+    <set>
+      <if test="productId != null">
+        productId = #{productId,jdbcType=BIGINT},
+      </if>
+      <if test="ladderNum != null">
+        ladderNum = #{ladderNum,jdbcType=BIGINT},
+      </if>
+      <if test="buyNum != null">
+        buyNum = #{buyNum,jdbcType=BIGINT},
+      </if>
+      <if test="buyPrice != null">
+        buyPrice = #{buyPrice,jdbcType=DECIMAL},
+      </if>
+      <if test="createBy != null">
+        createBy = #{createBy,jdbcType=BIGINT},
+      </if>
+      <if test="createDate != null">
+        createDate = #{createDate,jdbcType=TIMESTAMP},
+      </if>
+      <if test="updateBy != null">
+        updateBy = #{updateBy,jdbcType=BIGINT},
+      </if>
+      <if test="updateDate != null">
+        updateDate = #{updateDate,jdbcType=TIMESTAMP},
+      </if>
+      <if test="delFlag != null">
+        delFlag = #{delFlag,jdbcType=CHAR},
+      </if>
+    </set>
+    where id = #{id,jdbcType=BIGINT}
+  </update>
+  <update id="updateByPrimaryKey" parameterType="com.caimei.modules.products.entity.CmMallProductLadderPrice">
+    update cm_mall_product_ladder_price
+    set productId = #{productId,jdbcType=BIGINT},
+      ladderNum = #{ladderNum,jdbcType=BIGINT},
+      buyNum = #{buyNum,jdbcType=BIGINT},
+      buyPrice = #{buyPrice,jdbcType=DECIMAL},
+      createBy = #{createBy,jdbcType=BIGINT},
+      createDate = #{createDate,jdbcType=TIMESTAMP},
+      updateBy = #{updateBy,jdbcType=BIGINT},
+      updateDate = #{updateDate,jdbcType=TIMESTAMP},
+      delFlag = #{delFlag,jdbcType=CHAR}
+    where id = #{id,jdbcType=BIGINT}
+  </update>
+</mapper>

+ 36 - 0
src/test/java/com/caimei/TestDao.java

@@ -0,0 +1,36 @@
+package com.caimei;
+
+import com.caimei.modules.shiro.dao.UserDao;
+import com.caimei.modules.shiro.entity.CmMallAdminUser;
+import com.caimei.utils.MD5Util;
+import junit.framework.TestCase;
+import org.junit.Test;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.context.annotation.ComponentScan;
+
+import javax.annotation.Resource;
+import java.util.Date;
+
+/**
+ * Description
+ *
+ * @author : Charles
+ * @date : 2020/2/25
+ */
+@SpringBootTest
+public class TestDao {
+
+    @Test
+    public void testSign() {
+        CmMallAdminUser user = new CmMallAdminUser();
+        user.setAccount("chaooo");
+        user.setPassword("123456");
+        user.setSalt("55120f70");
+        user.setAccountName("超超");
+        user.setOrganizeID(1);
+        String md5Pass = MD5Util.md5(user.getPassword() + user.getSalt());
+        user.setPassword(md5Pass);
+        System.out.println(md5Pass);
+        TestCase.assertNotNull(user);
+    }
+}