package com.ruoyi.other.controller;
|
|
|
import com.ruoyi.account.api.model.AppUser;
|
import com.ruoyi.common.core.domain.R;
|
import com.ruoyi.other.api.domain.RedPackegeSet;
|
import com.ruoyi.other.dto.RedPackegeSetDto;
|
import com.ruoyi.other.service.RedPackegeSetService;
|
import io.swagger.annotations.ApiOperation;
|
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.web.bind.annotation.*;
|
|
import javax.annotation.Resource;
|
import java.math.BigDecimal;
|
import java.time.LocalDateTime;
|
import java.util.List;
|
|
/**
|
* <p>
|
* 前端控制器
|
* </p>
|
*
|
* @author luodangjia
|
* @since 2024-11-20
|
*/
|
@RestController
|
@RequestMapping("/red-packege-set")
|
public class RedPackegeSetController {
|
@Resource
|
private RedPackegeSetService redPackegeSetService;
|
//获取当前生效的红包设置
|
@ResponseBody
|
@GetMapping("/get")
|
public R<BigDecimal> get(){
|
LocalDateTime now = LocalDateTime.now();
|
RedPackegeSet one = redPackegeSetService.lambdaQuery().le(RedPackegeSet::getStartTime, now).ge(RedPackegeSet::getEndTime, now).one();
|
if (one!=null){
|
return R.ok(one.getPackegeAmount());
|
}else {
|
return R.ok(BigDecimal.ZERO);
|
|
}
|
}
|
|
|
/**
|
* 获取红包配置
|
*/
|
@ApiOperation(value = "获取红包配置", tags = {"管理后台-活动管理-签到红包"})
|
@GetMapping("/getRedPackegeSet")
|
public R<RedPackegeSetDto> getRedPackegeSet(){
|
List<RedPackegeSet> redPackegeSetList = redPackegeSetService.list();
|
RedPackegeSetDto redPackegeSetDto = new RedPackegeSetDto();
|
redPackegeSetDto.setRedPackegeSets(redPackegeSetList);
|
return R.ok(redPackegeSetDto);
|
}
|
|
|
/**
|
* 添加红包配置
|
*/
|
@ApiOperation(value = "添加红包配置", tags = {"管理后台-活动管理-签到红包"})
|
@PostMapping("/addRedPackegeSet")
|
@Transactional(rollbackFor = Exception.class)
|
public R<Void> addRedPackegeSet(@RequestBody RedPackegeSetDto redPackegeSets){
|
redPackegeSetService.remove(null);
|
List<RedPackegeSet> redPackegeSetList = redPackegeSets.getRedPackegeSets();
|
for (int i = 0; i < redPackegeSetList.size(); i++) {
|
RedPackegeSet redPackegeSet = redPackegeSetList.get(i);
|
LocalDateTime startTime = redPackegeSet.getStartTime();
|
LocalDateTime endTime = redPackegeSet.getEndTime();
|
for (RedPackegeSet redPackegeSet1 : redPackegeSetList) {
|
LocalDateTime startTime1 = redPackegeSet1.getStartTime();
|
LocalDateTime endTime1 = redPackegeSet1.getEndTime();
|
if (!(endTime.isBefore(startTime1) || startTime.isAfter(endTime1))) {
|
return R.fail("时间有重叠,请重新配置");
|
}
|
}
|
}
|
redPackegeSetService.saveBatch(redPackegeSetList);
|
return R.ok();
|
}
|
|
/**
|
* 删除红包配置
|
*/
|
@ApiOperation(value = "删除红包配置", tags = {"管理后台-活动管理-签到红包"})
|
@GetMapping("/delRedPackegeSet")
|
public R<Void> delRedPackegeSet(){
|
redPackegeSetService.removeById(1);
|
return R.ok();
|
}
|
|
}
|