|
@@ -24,6 +24,8 @@ import shop.alien.store.service.StorePriceService;
|
|
|
import java.math.RoundingMode;
|
|
import java.math.RoundingMode;
|
|
|
import java.text.ParseException;
|
|
import java.text.ParseException;
|
|
|
import java.text.SimpleDateFormat;
|
|
import java.text.SimpleDateFormat;
|
|
|
|
|
+import java.math.BigDecimal;
|
|
|
|
|
+import java.math.RoundingMode;
|
|
|
import java.time.LocalDate;
|
|
import java.time.LocalDate;
|
|
|
import java.time.LocalDateTime;
|
|
import java.time.LocalDateTime;
|
|
|
import java.time.LocalTime;
|
|
import java.time.LocalTime;
|
|
@@ -93,9 +95,50 @@ public class StoreProductDiscountServiceImpl implements StoreProductDiscountServ
|
|
|
vo.setSlotCount(group.size());
|
|
vo.setSlotCount(group.size());
|
|
|
vo.setStatus(head.getStatus());
|
|
vo.setStatus(head.getStatus());
|
|
|
vo.setUpdatedTime(group.stream().map(StoreProductDiscountRule::getUpdatedTime).filter(Objects::nonNull).max(Date::compareTo).orElse(head.getUpdatedTime()));
|
|
vo.setUpdatedTime(group.stream().map(StoreProductDiscountRule::getUpdatedTime).filter(Objects::nonNull).max(Date::compareTo).orElse(head.getUpdatedTime()));
|
|
|
|
|
+ // 价格显示逻辑
|
|
|
|
|
+ BigDecimal origin = info == null || info.price == null ? BigDecimal.ZERO : info.price;
|
|
|
|
|
+ vo.setOriginalPrice(origin);
|
|
|
|
|
+ BigDecimal discount;
|
|
|
|
|
+ if (TYPE_FREE.equalsIgnoreCase(head.getDiscountType())) {
|
|
|
|
|
+ discount = BigDecimal.ZERO;
|
|
|
|
|
+ } else if (TYPE_DISCOUNT.equalsIgnoreCase(head.getDiscountType())) {
|
|
|
|
|
+ BigDecimal rate = head.getDiscountRate() == null ? BigDecimal.ZERO : head.getDiscountRate();
|
|
|
|
|
+ discount = origin.multiply(rate).divide(new BigDecimal("100"), 2, RoundingMode.HALF_UP);
|
|
|
|
|
+ } else {
|
|
|
|
|
+ discount = BigDecimal.ZERO;
|
|
|
|
|
+ }
|
|
|
|
|
+ vo.setDiscountPrice(discount);
|
|
|
records.add(vo);
|
|
records.add(vo);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ // 排序:
|
|
|
|
|
+ // 1) 先按“同名规则的最新更新时间”倒序(哪个名字刚创建/更新过,整组置顶)
|
|
|
|
|
+ // 2) 组内再按各自更新时间倒序
|
|
|
|
|
+ Map<String, Date> nameMaxUpdated = new HashMap<>();
|
|
|
|
|
+ for (StoreProductDiscountRuleListVo vo : records) {
|
|
|
|
|
+ String name = vo.getRuleName();
|
|
|
|
|
+ Date ts = vo.getUpdatedTime();
|
|
|
|
|
+ if (name == null) {
|
|
|
|
|
+ continue;
|
|
|
|
|
+ }
|
|
|
|
|
+ Date cur = nameMaxUpdated.get(name);
|
|
|
|
|
+ if (cur == null || (ts != null && ts.after(cur))) {
|
|
|
|
|
+ nameMaxUpdated.put(name, ts);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ records.sort((a, b) -> {
|
|
|
|
|
+ Date aGroup = nameMaxUpdated.get(a.getRuleName());
|
|
|
|
|
+ Date bGroup = nameMaxUpdated.get(b.getRuleName());
|
|
|
|
|
+ // 组层级:最新在前
|
|
|
|
|
+ int cmpGroup = Comparator.nullsLast(Date::compareTo).reversed().compare(aGroup, bGroup);
|
|
|
|
|
+ if (cmpGroup != 0) return cmpGroup;
|
|
|
|
|
+ // 组内:单条更新时间倒序
|
|
|
|
|
+ int cmpInner = Comparator.nullsLast(Date::compareTo).reversed().compare(a.getUpdatedTime(), b.getUpdatedTime());
|
|
|
|
|
+ if (cmpInner != 0) return cmpInner;
|
|
|
|
|
+ // 最后以名称稳定排序,保证同名相邻
|
|
|
|
|
+ return Comparator.nullsFirst(String::compareTo).compare(a.getRuleName(), b.getRuleName());
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
Page<StoreProductDiscountRuleListVo> result = new Page<>(pn, ps, grouped.size());
|
|
Page<StoreProductDiscountRuleListVo> result = new Page<>(pn, ps, grouped.size());
|
|
|
result.setRecords(records);
|
|
result.setRecords(records);
|
|
|
return R.data(result);
|
|
return R.data(result);
|
|
@@ -130,8 +173,8 @@ public class StoreProductDiscountServiceImpl implements StoreProductDiscountServ
|
|
|
.eq(StoreProductDiscountRule::getProductId, rule.getProductId())
|
|
.eq(StoreProductDiscountRule::getProductId, rule.getProductId())
|
|
|
.eq(StoreProductDiscountRule::getRuleName, rule.getRuleName())
|
|
.eq(StoreProductDiscountRule::getRuleName, rule.getRuleName())
|
|
|
.eq(StoreProductDiscountRule::getDiscountType, rule.getDiscountType())
|
|
.eq(StoreProductDiscountRule::getDiscountType, rule.getDiscountType())
|
|
|
- .eq(StoreProductDiscountRule::getDiscountRate, rule.getDiscountRate())
|
|
|
|
|
.eq(StoreProductDiscountRule::getEffectiveMode, rule.getEffectiveMode());
|
|
.eq(StoreProductDiscountRule::getEffectiveMode, rule.getEffectiveMode());
|
|
|
|
|
+ if (rule.getDiscountRate() == null) groupQw.isNull(StoreProductDiscountRule::getDiscountRate); else groupQw.eq(StoreProductDiscountRule::getDiscountRate, rule.getDiscountRate());
|
|
|
if (rule.getStartDate() == null) groupQw.isNull(StoreProductDiscountRule::getStartDate); else groupQw.eq(StoreProductDiscountRule::getStartDate, rule.getStartDate());
|
|
if (rule.getStartDate() == null) groupQw.isNull(StoreProductDiscountRule::getStartDate); else groupQw.eq(StoreProductDiscountRule::getStartDate, rule.getStartDate());
|
|
|
if (rule.getEndDate() == null) groupQw.isNull(StoreProductDiscountRule::getEndDate); else groupQw.eq(StoreProductDiscountRule::getEndDate, rule.getEndDate());
|
|
if (rule.getEndDate() == null) groupQw.isNull(StoreProductDiscountRule::getEndDate); else groupQw.eq(StoreProductDiscountRule::getEndDate, rule.getEndDate());
|
|
|
List<StoreProductDiscountRule> sameGroup = ruleMapper.selectList(groupQw);
|
|
List<StoreProductDiscountRule> sameGroup = ruleMapper.selectList(groupQw);
|
|
@@ -178,8 +221,8 @@ public class StoreProductDiscountServiceImpl implements StoreProductDiscountServ
|
|
|
.eq(StoreProductDiscountRule::getProductId, existing.getProductId())
|
|
.eq(StoreProductDiscountRule::getProductId, existing.getProductId())
|
|
|
.eq(StoreProductDiscountRule::getRuleName, existing.getRuleName())
|
|
.eq(StoreProductDiscountRule::getRuleName, existing.getRuleName())
|
|
|
.eq(StoreProductDiscountRule::getDiscountType, existing.getDiscountType())
|
|
.eq(StoreProductDiscountRule::getDiscountType, existing.getDiscountType())
|
|
|
- .eq(StoreProductDiscountRule::getDiscountRate, existing.getDiscountRate())
|
|
|
|
|
.eq(StoreProductDiscountRule::getEffectiveMode, existing.getEffectiveMode());
|
|
.eq(StoreProductDiscountRule::getEffectiveMode, existing.getEffectiveMode());
|
|
|
|
|
+ if (existing.getDiscountRate() == null) delQw.isNull(StoreProductDiscountRule::getDiscountRate); else delQw.eq(StoreProductDiscountRule::getDiscountRate, existing.getDiscountRate());
|
|
|
if (existing.getStartDate() == null) delQw.isNull(StoreProductDiscountRule::getStartDate); else delQw.eq(StoreProductDiscountRule::getStartDate, existing.getStartDate());
|
|
if (existing.getStartDate() == null) delQw.isNull(StoreProductDiscountRule::getStartDate); else delQw.eq(StoreProductDiscountRule::getStartDate, existing.getStartDate());
|
|
|
if (existing.getEndDate() == null) delQw.isNull(StoreProductDiscountRule::getEndDate); else delQw.eq(StoreProductDiscountRule::getEndDate, existing.getEndDate());
|
|
if (existing.getEndDate() == null) delQw.isNull(StoreProductDiscountRule::getEndDate); else delQw.eq(StoreProductDiscountRule::getEndDate, existing.getEndDate());
|
|
|
ruleMapper.delete(delQw);
|
|
ruleMapper.delete(delQw);
|
|
@@ -208,8 +251,8 @@ public class StoreProductDiscountServiceImpl implements StoreProductDiscountServ
|
|
|
.eq(StoreProductDiscountRule::getProductId, existing.getProductId())
|
|
.eq(StoreProductDiscountRule::getProductId, existing.getProductId())
|
|
|
.eq(StoreProductDiscountRule::getRuleName, existing.getRuleName())
|
|
.eq(StoreProductDiscountRule::getRuleName, existing.getRuleName())
|
|
|
.eq(StoreProductDiscountRule::getDiscountType, existing.getDiscountType())
|
|
.eq(StoreProductDiscountRule::getDiscountType, existing.getDiscountType())
|
|
|
- .eq(StoreProductDiscountRule::getDiscountRate, existing.getDiscountRate())
|
|
|
|
|
.eq(StoreProductDiscountRule::getEffectiveMode, existing.getEffectiveMode());
|
|
.eq(StoreProductDiscountRule::getEffectiveMode, existing.getEffectiveMode());
|
|
|
|
|
+ if (existing.getDiscountRate() == null) delQw.isNull(StoreProductDiscountRule::getDiscountRate); else delQw.eq(StoreProductDiscountRule::getDiscountRate, existing.getDiscountRate());
|
|
|
if (existing.getStartDate() == null) delQw.isNull(StoreProductDiscountRule::getStartDate); else delQw.eq(StoreProductDiscountRule::getStartDate, existing.getStartDate());
|
|
if (existing.getStartDate() == null) delQw.isNull(StoreProductDiscountRule::getStartDate); else delQw.eq(StoreProductDiscountRule::getStartDate, existing.getStartDate());
|
|
|
if (existing.getEndDate() == null) delQw.isNull(StoreProductDiscountRule::getEndDate); else delQw.eq(StoreProductDiscountRule::getEndDate, existing.getEndDate());
|
|
if (existing.getEndDate() == null) delQw.isNull(StoreProductDiscountRule::getEndDate); else delQw.eq(StoreProductDiscountRule::getEndDate, existing.getEndDate());
|
|
|
ruleMapper.delete(delQw);
|
|
ruleMapper.delete(delQw);
|
|
@@ -523,13 +566,6 @@ public class StoreProductDiscountServiceImpl implements StoreProductDiscountServ
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
- // 名称唯一(同店同菜品)
|
|
|
|
|
- LambdaQueryWrapper<StoreProductDiscountRule> nameQw = new LambdaQueryWrapper<>();
|
|
|
|
|
- nameQw.eq(StoreProductDiscountRule::getStoreId, dto.getStoreId())
|
|
|
|
|
- .eq(StoreProductDiscountRule::getProductId, dto.getProductId())
|
|
|
|
|
- .eq(StoreProductDiscountRule::getRuleName, dto.getRuleName().trim());
|
|
|
|
|
- if (excludeId != null) nameQw.ne(StoreProductDiscountRule::getId, excludeId);
|
|
|
|
|
- if (ruleMapper.selectCount(nameQw) > 0) return "该菜品优惠名称已存在";
|
|
|
|
|
|
|
|
|
|
// 开启状态才参与冲突校验
|
|
// 开启状态才参与冲突校验
|
|
|
if (dto.getStatus() != null && dto.getStatus() == 0) return null;
|
|
if (dto.getStatus() != null && dto.getStatus() == 0) return null;
|