120 lines
3.3 KiB
Java
120 lines
3.3 KiB
Java
package com.peanut.modules.book.controller;
|
|
|
|
import java.util.*;
|
|
|
|
import com.peanut.modules.book.service.CouponProductCategoryRelationService;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.web.bind.annotation.PathVariable;
|
|
import org.springframework.web.bind.annotation.RequestBody;
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
import org.springframework.web.bind.annotation.RequestParam;
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
|
|
import com.peanut.modules.common.entity.CouponEntity;
|
|
import com.peanut.modules.book.service.CouponService;
|
|
import com.peanut.common.utils.PageUtils;
|
|
import com.peanut.common.utils.R;
|
|
|
|
|
|
|
|
/**
|
|
*
|
|
*
|
|
* @author yl
|
|
* @email yl328572838@163.com
|
|
* @date 2022-10-28 17:38:29
|
|
*/
|
|
@Slf4j
|
|
@RestController
|
|
@RequestMapping("book/coupon")
|
|
public class CouponController {
|
|
@Autowired
|
|
private CouponService couponService;
|
|
@Autowired
|
|
private CouponProductCategoryRelationService couponProductCategoryRelationService;
|
|
|
|
|
|
/**
|
|
* 列表
|
|
*/
|
|
@RequestMapping("/list")
|
|
// @RequiresPermissions("book:coupon:list")
|
|
public R list(@RequestParam Map<String, Object> params){
|
|
PageUtils page = couponService.queryPage(params);
|
|
|
|
return R.ok().put("page", page);
|
|
}
|
|
|
|
|
|
/**
|
|
* 信息
|
|
*/
|
|
@RequestMapping("/info/{id}")
|
|
// @RequiresPermissions("book:coupon:info")
|
|
public R info(@PathVariable("id") Long id){
|
|
CouponEntity coupon = couponService.getById(id);
|
|
|
|
return R.ok().put("coupon", coupon);
|
|
}
|
|
|
|
/**
|
|
* 保存
|
|
*/
|
|
@RequestMapping("/save")
|
|
// @RequiresPermissions("book:coupon:save")
|
|
public R save(@RequestBody CouponEntity coupon){
|
|
|
|
if(0 == coupon.getTakeEffectType()){
|
|
coupon.setTakeEffectDate(new Date());
|
|
Calendar cal = Calendar.getInstance();
|
|
cal.add(Calendar.DATE,Integer.valueOf(coupon.getValidity()).intValue());
|
|
coupon.setExpirationDate(cal.getTime());
|
|
}else{
|
|
Calendar cal = Calendar.getInstance();
|
|
cal.setTime(coupon.getTakeEffectDate());
|
|
cal.add(Calendar.DATE,Integer.valueOf(coupon.getValidity()).intValue());
|
|
coupon.setExpirationDate(cal.getTime());
|
|
}
|
|
couponService.save(coupon);
|
|
|
|
return R.ok();
|
|
}
|
|
|
|
/**
|
|
* 修改
|
|
*/
|
|
@RequestMapping("/update")
|
|
// @RequiresPermissions("book:coupon:update")
|
|
public R update(@RequestBody CouponEntity coupon){
|
|
|
|
if(0 == coupon.getTakeEffectType()){
|
|
coupon.setTakeEffectDate(new Date());
|
|
Calendar cal = Calendar.getInstance();
|
|
cal.add(Calendar.DATE,Integer.valueOf(coupon.getValidity()).intValue());
|
|
coupon.setExpirationDate(cal.getTime());
|
|
}else{
|
|
Calendar cal = Calendar.getInstance();
|
|
cal.setTime(coupon.getTakeEffectDate());
|
|
cal.add(Calendar.DATE,Integer.valueOf(coupon.getValidity()).intValue());
|
|
coupon.setExpirationDate(cal.getTime());
|
|
}
|
|
couponService.updateById(coupon);
|
|
|
|
return R.ok();
|
|
}
|
|
|
|
/**
|
|
* 删除
|
|
*/
|
|
@RequestMapping("/delete")
|
|
// @RequiresPermissions("book:coupon:delete")
|
|
public R delete(@RequestBody Long[] ids){
|
|
couponService.removeByIds(Arrays.asList(ids));
|
|
|
|
return R.ok();
|
|
}
|
|
|
|
|
|
}
|