From 69283b5a4559509187516355602e32e4bdac9d5d Mon Sep 17 00:00:00 2001
From: jiangping <jp@doumee.com>
Date: 星期五, 28 二月 2025 11:54:12 +0800
Subject: [PATCH] Merge remote-tracking branch 'origin/2.0.1' into 2.0.1

---
 server/services/src/main/java/com/doumee/service/business/impl/DiscountServiceImpl.java |   47 ++++++++++++++++++++++++++++++++++++++++-------
 1 files changed, 40 insertions(+), 7 deletions(-)

diff --git a/server/services/src/main/java/com/doumee/service/business/impl/DiscountServiceImpl.java b/server/services/src/main/java/com/doumee/service/business/impl/DiscountServiceImpl.java
index 6e6895b..a8c5a63 100644
--- a/server/services/src/main/java/com/doumee/service/business/impl/DiscountServiceImpl.java
+++ b/server/services/src/main/java/com/doumee/service/business/impl/DiscountServiceImpl.java
@@ -31,6 +31,7 @@
 import org.springframework.util.CollectionUtils;
 
 import java.math.BigDecimal;
+import java.text.ParseException;
 import java.util.Date;
 import java.util.List;
 import java.util.Objects;
@@ -60,6 +61,8 @@
         discount.setIsdeleted(Constants.ZERO);
         discount.setCreateDate(new Date());
         discount.setCreator(userInfo.getId());
+        discount.setEditDate(new Date());
+        discount.setEditor(userInfo.getId());
         if(Constants.equalsInteger(discount.getUseType(),Constants.ZERO)){
             discount.setUseDays((int) (DateUtil.getBetweenDays(DateUtil.dateToString(discount.getUseStartDate(),"yyyy-MM-dd"),DateUtil.dateToString(discount.getUseEndDate(),"yyyy-MM-dd"))));
         }
@@ -68,7 +71,7 @@
     }
 
 
-    public void vaildReq(Discount discount) {
+    public void vaildReq(Discount discount){
         if(Objects.isNull(discount)
                 || StringUtils.isBlank(discount.getName())
                 || Objects.isNull(discount.getType())
@@ -95,13 +98,21 @@
                 ( discount.getUseStartDate().getTime()>discount.getUseEndDate().getTime()) ){
             throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"浣跨敤鏃舵淇℃伅閿欒");
         }
-
         //鎸囧畾鏃ユ湡鐢熸晥
         if(Constants.equalsInteger(discount.getUseType(),Constants.TWO) &&
                 ( discount.getUseStartDate().getTime()<discount.getStartDate().getTime() ||
                         discount.getUseStartDate().getTime() > discount.getEndDate().getTime()
                 ) ){
             throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"浣跨敤鏃舵淇℃伅閿欒");
+        }
+        if(Objects.isNull(discount.getSaleDayLimit())){
+            discount.setSaleDayLimit(Constants.ZERO);
+        }
+        if(Objects.isNull(discount.getSaleLimit())){
+            discount.setSaleLimit(Constants.ZERO);
+        }
+        if(Constants.equalsInteger(discount.getUseType(),Constants.TWO)){
+            discount.setUseEndDate( DateUtil.StringToDateFormat(DateUtil.getXDaysAfter(discount.getUseStartDate(),discount.getUseDays()),"yyyy-MM-dd"));
         }
     }
 
@@ -146,6 +157,24 @@
 
     @Override
     public void updateById(Discount discount) {
+        LoginUserInfo userInfo = (LoginUserInfo) SecurityUtils.getSubject().getPrincipal();
+        if(Objects.isNull(discount)
+        || StringUtils.isBlank(discount.getId())){
+            throw new BusinessException(ResponseStatus.BAD_REQUEST);
+        }
+        Discount model = discountMapper.selectById(discount.getId());
+        if(Objects.isNull(model)){
+            throw new BusinessException(ResponseStatus.DATA_EMPTY);
+        }
+        if(!Constants.equalsInteger(model.getStatus(),Constants.ONE)){
+            throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"鏈鐢ㄦ棤娉曡繘琛屼慨鏀�");
+        }
+        this.vaildReq(discount);
+        discount.setEditDate(new Date());
+        discount.setEditor(userInfo.getId());
+        if(Constants.equalsInteger(discount.getUseType(),Constants.ZERO)){
+            discount.setUseDays((int) (DateUtil.getBetweenDays(DateUtil.dateToString(discount.getUseStartDate(),"yyyy-MM-dd"),DateUtil.dateToString(discount.getUseEndDate(),"yyyy-MM-dd"))));
+        }
         discountMapper.updateById(discount);
     }
 
@@ -162,9 +191,12 @@
     @Override
     public Discount findById(String id) {
         Discount discount = discountJoinMapper.selectOne(new MPJLambdaWrapper<Discount>()
-                        .selectAll(Discount.class)
+                .selectAll(Discount.class)
+                .select(" s1.realname ",Discount::getCreatorName)
+                .select(" s2.realname ",Discount::getEditorName)
                 .select(" (select count(1) from goodsorder g where g.obj_type = 0 and g.obj_id = t.id and g.pay_status = 1 ) ",Discount::getSaleNum)
-                .leftJoin(SystemUser.class,SystemUser::getId,Discount::getCreator)
+                .leftJoin(" system_user s1 on s1.id = t.creator")
+                .leftJoin(" system_user s2 on s2.id = t.editor")
                 .eq(Discount::getId,id)
         );
         if(Objects.isNull(discount)){
@@ -205,7 +237,9 @@
                 .eq(Objects.nonNull(modele.getBikeOrElec()) && Constants.equalsInteger(modele.getBikeOrElec(),Constants.ONE),Discount::getIsbike, Constants.ONE)
                 .eq(Objects.nonNull(modele.getBikeOrElec()) && Constants.equalsInteger(modele.getBikeOrElec(),Constants.TWO),Discount::getIselecbike, Constants.ONE)
                 .eq(Discount::getIsdeleted, Constants.ZERO)
-                .eq( pageWrap.getModel().getStatus() !=null,BikeRepair::getStatus,pageWrap.getModel().getStatus());
+                .eq( pageWrap.getModel().getStatus() !=null,BikeRepair::getStatus,pageWrap.getModel().getStatus())
+                .apply( Objects.nonNull(modele.getMinShow())," now() BETWEEN t.start_date and  ( t.end_date   + INTERVAL '1 day' ) ")
+        ;
                 queryWrapper.orderByDesc(Discount::getCreateDate);
         PageData<Discount> pageData = PageData.from(discountJoinMapper.selectJoinPage(page, Discount.class,queryWrapper));
         for (Discount discount:pageData.getRecords()) {
@@ -219,8 +253,7 @@
     @Override
     public void dealPrice(Discount discount){
         if(Objects.isNull(discount)
-            || Objects.isNull(discount.getUseEndDate())
-            || Objects.isNull(discount.getUseStartDate())
+            || Objects.isNull(discount.getUseDays())
             || Objects.isNull(discount.getPrice())
             || discount.getPrice().compareTo(BigDecimal.ZERO)==0
         ){

--
Gitblit v1.9.3