浏览代码

计算产品维护维多利亚生命周期

yzc 2 年之前
父节点
当前提交
fcf4619240

+ 5 - 0
hx-item/src/main/java/com/fjhx/item/entity/product/vo/ProductInfoVo.java

@@ -20,4 +20,9 @@ public class ProductInfoVo extends ProductInfo {
 
     private List<String> classifyNameGroup;
 
+    /**
+     * 生命周期 维多利亚
+     */
+    private Integer lifeCycle;
+
 }

+ 8 - 1
hx-item/src/main/java/com/fjhx/item/service/product/impl/ProductInfoServiceImpl.java

@@ -30,6 +30,7 @@ import org.springframework.stereotype.Service;
 import org.springframework.web.multipart.MultipartFile;
 
 import java.util.ArrayList;
+import java.util.Date;
 import java.util.List;
 import java.util.Map;
 import java.util.function.Function;
@@ -65,7 +66,8 @@ public class ProductInfoServiceImpl extends ServiceImpl<ProductInfoMapper, Produ
                 new SqlField("pi", ProductInfo::getCode),
                 new SqlField("pi", ProductInfo::getCustomCode)
         );
-        wrapper.eq("json_unquote(victoriatourist_json ->'$.lifeCycle')", dto.getLifeCycle());
+        //计算并根据生命周期过滤
+        wrapper.eq("IF(DATEDIFF(now(),json_unquote( victoriatourist_json -> '$.growUpDay' ))> 0,3,IF(DATEDIFF(now(), json_unquote(victoriatourist_json -> '$.newProductsDay' ))> 0, 2, 1 ))", dto.getLifeCycle());
         Page<ProductInfoVo> page = this.baseMapper.getPage(dto.getPage(), wrapper);
 
         List<ProductInfoVo> records = page.getRecords();
@@ -133,8 +135,13 @@ public class ProductInfoServiceImpl extends ServiceImpl<ProductInfoMapper, Produ
 
             JSONObject json = JSONObject.parseObject(victoriatouristJson);
             json.put("deptName", sysDeptMap.get(json.getLong("deptId")));
+
+            //生命周期计算(在sql里面计算了) 当前时间-创建时间=的天数>growUpDay成熟期,>newProductsDay就是成长期,要不然就是新品期
+            json.put("lifeCycle", record.getLifeCycle());
+
             record.setVictoriatouristJson(json.toJSONString());
         }
+
         return page;
     }
 

+ 17 - 14
hx-item/src/main/resources/mapper/product/ProductInfoMapper.xml

@@ -3,20 +3,23 @@
 <mapper namespace="com.fjhx.item.mapper.product.ProductInfoMapper">
 
     <select id="getPage" resultType="com.fjhx.item.entity.product.vo.ProductInfoVo">
-        select pi.id,
-               pi.product_classify_id,
-               pi.code,
-               pi.type,
-               pi.name,
-               pi.spec,
-               pi.unit,
-               pi.remark,
-               pi.create_user,
-               pi.create_time,
-               pi.update_user,
-               pi.update_time,
-               pi.victoriatourist_json
-        from product_info pi
+        SELECT
+            pi.id,
+            pi.product_classify_id,
+            pi.CODE,
+            pi.type,
+            pi.NAME,
+            pi.spec,
+            pi.unit,
+            pi.remark,
+            pi.create_user,
+            pi.create_time,
+            pi.update_user,
+            pi.update_time,
+            pi.victoriatourist_json,
+            IF(DATEDIFF(now(),json_unquote( victoriatourist_json -> '$.growUpDay' ))> 0,3,IF(DATEDIFF(now(), json_unquote(victoriatourist_json -> '$.newProductsDay' ))> 0, 2, 1 )) AS lifeCycle
+        FROM
+            product_info pi
             ${ew.customSqlSegment}
     </select>