提交 5e4662ba authored 作者: 吴德鹏's avatar 吴德鹏

update activity

上级 38c47dff
......@@ -53,16 +53,14 @@ public class ActivityController {
//查询商品活动
@GetMapping("item/{itemId}")
public Result getItemActivity(@PathVariable("itemId") String itemId) throws ParseException, ExecutionException, InterruptedException {
public Result getItemActivity(@PathVariable("itemId") String itemId) throws ParseException {
Result result = new Result();
Activity activity = null;
DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
//全场活动
if (activityRepository.existsByUseType(1)) {
Optional<Activity> fullAct = activityRepository.findFirstByUseType(1);
if (fullAct.isPresent()) {
activity = fullAct.get();
}
List<Activity> fullList = activityRepository.findAllByUseType(1);
activity = fullList.get(0);
}
//商品分类活动
......
......@@ -344,23 +344,21 @@ public class TbCfOrder {
*/
boolean fullAct = activityRepository.existsByUseType(1);
if (this.open && fullAct) {
Optional<Activity> allAct = activityRepository.findFirstByUseType(1);
if (allAct.isPresent()) {
Activity activity = allAct.get();
String type = String.valueOf(activity.getType());
if ("1".equals(type)) {
reduceAmount = caculateActFee(false, false, activity, itemsPrice, null);
System.out.println("减免金额:" + reduceAmount);
} else if ("2".equals(type)) {
BigDecimal rate = caculateActFee(false, true, activity, itemsPrice, null);
System.out.println("折扣比例:" + rate);
itemsPrice = rate.multiply(itemsPrice);
} else if ("3".equals(type)) {
BigDecimal rate = caculateActFee(true, true, activity, itemsPrice, itemSum);
System.out.println("购买件数:" + itemSum);
System.out.println("折扣比例:" + rate);
itemsPrice = rate.multiply(itemsPrice);
}
Activity activity = activityRepository.findAllByUseType(1).get(0);
String type = String.valueOf(activity.getType());
if ("1".equals(type)) {
reduceAmount = caculateActFee(false, false, activity, itemsPrice, null);
System.out.println("减免金额:" + reduceAmount);
} else if ("2".equals(type)) {
BigDecimal rate = caculateActFee(false, true, activity, itemsPrice, null);
System.out.println("折扣比例:" + rate);
itemsPrice = rate.multiply(itemsPrice);
} else if ("3".equals(type)) {
BigDecimal rate = caculateActFee(true, true, activity, itemsPrice, itemSum);
System.out.println("购买件数:" + itemSum);
System.out.println("折扣比例:" + rate);
itemsPrice = rate.multiply(itemsPrice);
}
}
......
......@@ -24,10 +24,10 @@ public interface ActivityRepository extends JpaRepository<Activity, String> {
boolean existsByUseType(Integer useType);
@Query(value = "select * from Activity a where CURRENT_TIMESTAMP between a.start_time and a.end_time and a.status=1 and use_type=:useType order by a.create_time desc limit 1", nativeQuery = true)
Optional<Activity> findFirstByUseType(Integer useType);
// @Query(value = "select * from Activity a where CURRENT_TIMESTAMP between a.start_time and a.end_time and a.status=1 and use_type=:useType order by a.create_time desc limit 1", nativeQuery = true)
// Optional<Activity> findFirstByUseType(Integer useType);
@Query(value = "select * from Activity a where CURRENT_TIMESTAMP between a.start_time and a.end_time and a.status=1 and use_type=:useType", nativeQuery = true)
@Query(value = "select * from Activity a where CURRENT_TIMESTAMP between a.start_time and a.end_time and a.status=1 and a.use_type=:useType order by a.create_time desc ", nativeQuery = true)
List<Activity> findAllByUseType(Integer useType);
}
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论