|
|
@@ -1,16 +1,20 @@
|
|
|
package com.izouma.nineth.web;
|
|
|
|
|
|
+import com.izouma.nineth.config.MetaConstants;
|
|
|
import com.izouma.nineth.domain.MetaLuckyDraw;
|
|
|
import com.izouma.nineth.domain.MetaLuckyDrawAwardModel;
|
|
|
+import com.izouma.nineth.dto.MetaRestResult;
|
|
|
import com.izouma.nineth.dto.PageQuery;
|
|
|
import com.izouma.nineth.enums.MetaAwardTypeEnum;
|
|
|
import com.izouma.nineth.exception.BusinessException;
|
|
|
import com.izouma.nineth.repo.MetaLuckyDrawRepo;
|
|
|
import com.izouma.nineth.service.MetaLuckyDrawService;
|
|
|
+import com.izouma.nineth.service.MetaParamsConfigService;
|
|
|
import com.izouma.nineth.utils.ObjUtils;
|
|
|
import com.izouma.nineth.utils.excel.ExcelUtils;
|
|
|
import lombok.AllArgsConstructor;
|
|
|
import org.apache.commons.collections.CollectionUtils;
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
import org.springframework.data.domain.Page;
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
@@ -28,6 +32,8 @@ public class MetaLuckyDrawController extends BaseController {
|
|
|
private MetaLuckyDrawService metaLuckyDrawService;
|
|
|
private MetaLuckyDrawRepo metaLuckyDrawRepo;
|
|
|
|
|
|
+ private MetaParamsConfigService metaParamsConfigService;
|
|
|
+
|
|
|
//@PreAuthorize("hasRole('ADMIN')")
|
|
|
@PostMapping("/save")
|
|
|
public MetaLuckyDraw save(@RequestBody MetaLuckyDraw record) {
|
|
|
@@ -55,11 +61,9 @@ public class MetaLuckyDrawController extends BaseController {
|
|
|
}
|
|
|
record.setMetaLuckDrawAwards(metaLuckDrawAwards);
|
|
|
}
|
|
|
- if (record.isPublish()) {
|
|
|
- MetaLuckyDraw metaLuckyDraw = metaLuckyDrawRepo.findByNameAndPublishAndDel(record.getName(), true, false);
|
|
|
- if (Objects.nonNull(metaLuckyDraw) && !Objects.equals(metaLuckyDraw.getId(), record.getId())) {
|
|
|
- throw new BusinessException("该活动名称已经存在!");
|
|
|
- }
|
|
|
+ MetaLuckyDraw metaLuckyDraw = metaLuckyDrawRepo.findByNameAndPublishAndDel(record.getName(), true, false);
|
|
|
+ if (Objects.nonNull(metaLuckyDraw) && !Objects.equals(metaLuckyDraw.getId(), record.getId())) {
|
|
|
+ throw new BusinessException("该活动名称已经存在!");
|
|
|
}
|
|
|
if (record.getId() != null) {
|
|
|
MetaLuckyDraw orig = metaLuckyDrawRepo.findById(record.getId()).orElseThrow(new BusinessException("无记录"));
|
|
|
@@ -92,5 +96,19 @@ public class MetaLuckyDrawController extends BaseController {
|
|
|
List<MetaLuckyDraw> data = all(pageQuery).getContent();
|
|
|
ExcelUtils.export(response, data);
|
|
|
}
|
|
|
+
|
|
|
+ @GetMapping("/findMetaLuckyDraw")
|
|
|
+ public MetaRestResult<MetaLuckyDraw> findMetaLuckyDraw() {
|
|
|
+ String idConfig = metaParamsConfigService.getString(MetaConstants.META_LUCKY_DRAW_ID);
|
|
|
+ if (StringUtils.isBlank(idConfig)) {
|
|
|
+ return MetaRestResult.returnError("抽奖活动id配置不存在!");
|
|
|
+ }
|
|
|
+ MetaLuckyDraw metaLuckyDraw = metaLuckyDrawRepo.findById(Long.parseLong(idConfig)).orElse(null);
|
|
|
+ if (Objects.isNull(metaLuckyDraw)) {
|
|
|
+ return MetaRestResult.returnError("抽奖活动不存在!");
|
|
|
+ }
|
|
|
+ return MetaRestResult.returnSuccess(metaLuckyDraw);
|
|
|
+ }
|
|
|
+
|
|
|
}
|
|
|
|