|
|
@@ -1,6 +1,7 @@
|
|
|
package com.izouma.dingdong.web;
|
|
|
|
|
|
-import com.izouma.dingdong.web.BaseController;
|
|
|
+import com.izouma.dingdong.service.merchant.MerchantService;
|
|
|
+import com.izouma.dingdong.utils.SecurityUtils;
|
|
|
import com.izouma.dingdong.domain.Coupon;
|
|
|
import com.izouma.dingdong.service.CouponService;
|
|
|
import com.izouma.dingdong.dto.PageQuery;
|
|
|
@@ -11,12 +12,13 @@ import com.izouma.dingdong.utils.excel.ExcelUtils;
|
|
|
|
|
|
import lombok.AllArgsConstructor;
|
|
|
import org.springframework.data.domain.Page;
|
|
|
+import org.springframework.data.domain.PageImpl;
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
import java.io.IOException;
|
|
|
-import java.math.BigDecimal;
|
|
|
import java.util.List;
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
@RestController
|
|
|
@RequestMapping("/coupon")
|
|
|
@@ -24,6 +26,7 @@ import java.util.List;
|
|
|
public class CouponController extends BaseController {
|
|
|
private CouponService couponService;
|
|
|
private CouponRepo couponRepo;
|
|
|
+ private MerchantService merchantService;
|
|
|
|
|
|
//@PreAuthorize("hasRole('ADMIN')")
|
|
|
@PostMapping("/save")
|
|
|
@@ -40,7 +43,9 @@ public class CouponController extends BaseController {
|
|
|
//@PreAuthorize("hasRole('ADMIN')")
|
|
|
@GetMapping("/all")
|
|
|
public Page<Coupon> all(PageQuery pageQuery) {
|
|
|
- return couponRepo.findAll(toSpecification(pageQuery,Coupon.class), toPageRequest(pageQuery));
|
|
|
+ //return couponRepo.findAll(toSpecification(pageQuery,Coupon.class),toPageRequest(pageQuery));
|
|
|
+ List<Coupon> collect = couponRepo.findAll(toSpecification(pageQuery, Coupon.class)).stream().filter(Coupon::getEnabled).collect(Collectors.toList());
|
|
|
+ return new PageImpl<>(collect,toPageRequest(pageQuery),pageQuery.getSize());
|
|
|
}
|
|
|
|
|
|
@GetMapping("/get/{id}")
|
|
|
@@ -59,5 +64,11 @@ public class CouponController extends BaseController {
|
|
|
List<Coupon> data = all(pageQuery).getContent();
|
|
|
ExcelUtils.export(response, data);
|
|
|
}
|
|
|
+
|
|
|
+ @GetMapping("/my")
|
|
|
+ public List<Coupon> my(){
|
|
|
+ Long merchantId = merchantService.findMerchantId(SecurityUtils.getAuthenticatedUser().getId());
|
|
|
+ return couponRepo.findAllByMerchantIdAndEnabledTrue(merchantId);
|
|
|
+ }
|
|
|
}
|
|
|
|