|
|
@@ -1,26 +1,31 @@
|
|
|
package com.izouma.nineth.web;
|
|
|
+
|
|
|
import com.izouma.nineth.domain.Coupon;
|
|
|
-import com.izouma.nineth.service.CouponService;
|
|
|
+import com.izouma.nineth.dto.GeneralDTO;
|
|
|
import com.izouma.nineth.dto.PageQuery;
|
|
|
import com.izouma.nineth.exception.BusinessException;
|
|
|
+import com.izouma.nineth.repo.CollectionRepo;
|
|
|
import com.izouma.nineth.repo.CouponRepo;
|
|
|
+import com.izouma.nineth.service.CouponService;
|
|
|
import com.izouma.nineth.utils.ObjUtils;
|
|
|
import com.izouma.nineth.utils.excel.ExcelUtils;
|
|
|
import lombok.AllArgsConstructor;
|
|
|
+import org.apache.commons.collections.CollectionUtils;
|
|
|
import org.springframework.data.domain.Page;
|
|
|
-import org.springframework.security.access.prepost.PreAuthorize;
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
import java.io.IOException;
|
|
|
import java.util.List;
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
@RestController
|
|
|
@RequestMapping("/coupon")
|
|
|
@AllArgsConstructor
|
|
|
public class CouponController extends BaseController {
|
|
|
- private CouponService couponService;
|
|
|
- private CouponRepo couponRepo;
|
|
|
+ private CouponService couponService;
|
|
|
+ private CouponRepo couponRepo;
|
|
|
+ private CollectionRepo collectionRepo;
|
|
|
|
|
|
//@PreAuthorize("hasRole('ADMIN')")
|
|
|
@PostMapping("/save")
|
|
|
@@ -42,7 +47,20 @@ public class CouponController extends BaseController {
|
|
|
|
|
|
@GetMapping("/get/{id}")
|
|
|
public Coupon get(@PathVariable Long id) {
|
|
|
- return couponRepo.findById(id).orElseThrow(new BusinessException("无记录"));
|
|
|
+ Coupon coupon = couponRepo.findById(id).orElseThrow(new BusinessException("无记录"));
|
|
|
+ if (CollectionUtils.isNotEmpty(coupon.getCollectionIds())) {
|
|
|
+ List<GeneralDTO> dtos = collectionRepo.findAllByIdIn(coupon.getCollectionIds())
|
|
|
+ .stream()
|
|
|
+ .map(collection -> {
|
|
|
+ GeneralDTO dto = new GeneralDTO();
|
|
|
+ dto.setId(collection.getId());
|
|
|
+ dto.setName(collection.getName());
|
|
|
+ return dto;
|
|
|
+ })
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ coupon.setCollections(dtos);
|
|
|
+ }
|
|
|
+ return coupon;
|
|
|
}
|
|
|
|
|
|
@PostMapping("/del/{id}")
|