This commit is contained in:
gzlv
2021-07-12 19:25:23 +08:00
parent 4a16a4273c
commit 3261b76127
2 changed files with 55 additions and 33 deletions

View File

@ -110,6 +110,7 @@ public class StoreSeckillController {
YxSystemGroupDataQueryCriteria queryCriteria = new YxSystemGroupDataQueryCriteria(); YxSystemGroupDataQueryCriteria queryCriteria = new YxSystemGroupDataQueryCriteria();
queryCriteria.setGroupName(ShopConstants.YSHOP_SECKILL_TIME); queryCriteria.setGroupName(ShopConstants.YSHOP_SECKILL_TIME);
queryCriteria.setStatus(1);
List<YxSystemGroupData> yxSystemGroupDataList = yxSystemGroupDataService.queryAll(queryCriteria); List<YxSystemGroupData> yxSystemGroupDataList = yxSystemGroupDataService.queryAll(queryCriteria);
List<SeckillTimeDto> list = new ArrayList<>(); List<SeckillTimeDto> list = new ArrayList<>();

View File

@ -1,12 +1,12 @@
/** /**
* Copyright (C) 2018-2021 * Copyright (C) 2018-2021
* All rights reserved, Designed By www.yixiang.co * All rights reserved, Designed By www.yixiang.co
*/ */
package co.yixiang.modules.shop.rest; package co.yixiang.modules.shop.rest;
import cn.hutool.core.util.ObjectUtil; import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil; import cn.hutool.core.util.StrUtil;
import cn.hutool.json.JSONUtil;
import co.yixiang.constant.ShopConstants; import co.yixiang.constant.ShopConstants;
import co.yixiang.exception.BadRequestException; import co.yixiang.exception.BadRequestException;
import co.yixiang.logging.aop.log.Log; import co.yixiang.logging.aop.log.Log;
@ -16,6 +16,7 @@ import co.yixiang.modules.shop.service.YxSystemGroupDataService;
import co.yixiang.modules.shop.service.dto.YxSystemGroupDataQueryCriteria; import co.yixiang.modules.shop.service.dto.YxSystemGroupDataQueryCriteria;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
import org.springframework.cache.annotation.CacheEvict; import org.springframework.cache.annotation.CacheEvict;
@ -25,19 +26,15 @@ import org.springframework.data.domain.Sort;
import org.springframework.http.HttpStatus; import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity; import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.DeleteMapping; import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable; import java.util.List;
import org.springframework.web.bind.annotation.PostMapping; import java.util.Map;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
/** /**
* @author hupeng * @author hupeng
* @date 2019-10-18 * @date 2019-10-18
*/ */
@Api(tags = "商城:数据配置管理") @Api(tags = "商城:数据配置管理")
@RestController @RestController
@RequestMapping("api") @RequestMapping("api")
@ -54,21 +51,21 @@ public class SystemGroupDataController {
@GetMapping(value = "/yxSystemGroupData") @GetMapping(value = "/yxSystemGroupData")
@PreAuthorize("hasAnyRole('admin','YXSYSTEMGROUPDATA_ALL','YXSYSTEMGROUPDATA_SELECT')") @PreAuthorize("hasAnyRole('admin','YXSYSTEMGROUPDATA_ALL','YXSYSTEMGROUPDATA_SELECT')")
public ResponseEntity getYxSystemGroupDatas(YxSystemGroupDataQueryCriteria criteria, public ResponseEntity getYxSystemGroupDatas(YxSystemGroupDataQueryCriteria criteria,
Pageable pageable){ Pageable pageable) {
Sort sort = Sort.by(Sort.Direction.DESC, "sort"); Sort sort = Sort.by(Sort.Direction.DESC, "sort");
Pageable pageableT = PageRequest.of(pageable.getPageNumber(), Pageable pageableT = PageRequest.of(pageable.getPageNumber(),
pageable.getPageSize(), pageable.getPageSize(),
sort); sort);
return new ResponseEntity<>(yxSystemGroupDataService.queryAll(criteria,pageableT),HttpStatus.OK); return new ResponseEntity<>(yxSystemGroupDataService.queryAll(criteria, pageableT), HttpStatus.OK);
} }
@ForbidSubmit @ForbidSubmit
@Log("新增数据配置") @Log("新增数据配置")
@ApiOperation(value = "新增数据配置") @ApiOperation(value = "新增数据配置")
@PostMapping(value = "/yxSystemGroupData") @PostMapping(value = "/yxSystemGroupData")
@CacheEvict(cacheNames = ShopConstants.YSHOP_REDIS_INDEX_KEY,allEntries = true) @CacheEvict(cacheNames = ShopConstants.YSHOP_REDIS_INDEX_KEY, allEntries = true)
@PreAuthorize("hasAnyRole('admin','YXSYSTEMGROUPDATA_ALL','YXSYSTEMGROUPDATA_CREATE')") @PreAuthorize("hasAnyRole('admin','YXSYSTEMGROUPDATA_ALL','YXSYSTEMGROUPDATA_CREATE')")
public ResponseEntity create(@RequestBody String jsonStr){ public ResponseEntity create(@RequestBody String jsonStr) {
JSONObject jsonObject = JSON.parseObject(jsonStr); JSONObject jsonObject = JSON.parseObject(jsonStr);
this.checkParam(jsonObject); this.checkParam(jsonObject);
@ -79,17 +76,27 @@ public class SystemGroupDataController {
yxSystemGroupData.setStatus(jsonObject.getInteger("status")); yxSystemGroupData.setStatus(jsonObject.getInteger("status"));
yxSystemGroupData.setSort(jsonObject.getInteger("sort")); yxSystemGroupData.setSort(jsonObject.getInteger("sort"));
List<YxSystemGroupData> yshop_seckill_time = yxSystemGroupDataService.list(Wrappers.<YxSystemGroupData>lambdaQuery()
.eq(YxSystemGroupData::getGroupName, "yshop_seckill_time"));
if (yxSystemGroupData.getStatus() == 1) {
yshop_seckill_time.forEach(item -> {
Map map = JSONUtil.toBean(item.getValue(), Map.class);
if (jsonObject.getInteger("time").equals(map.get("time"))) {
throw new BadRequestException("不能同时开启同一时间点");
}
});
}
return new ResponseEntity<>(yxSystemGroupDataService.save(yxSystemGroupData),HttpStatus.CREATED); return new ResponseEntity<>(yxSystemGroupDataService.save(yxSystemGroupData), HttpStatus.CREATED);
} }
@ForbidSubmit @ForbidSubmit
@Log("修改数据配置") @Log("修改数据配置")
@ApiOperation(value = "修改数据配置") @ApiOperation(value = "修改数据配置")
@PutMapping(value = "/yxSystemGroupData") @PutMapping(value = "/yxSystemGroupData")
@CacheEvict(cacheNames = ShopConstants.YSHOP_REDIS_INDEX_KEY,allEntries = true) @CacheEvict(cacheNames = ShopConstants.YSHOP_REDIS_INDEX_KEY, allEntries = true)
@PreAuthorize("hasAnyRole('admin','YXSYSTEMGROUPDATA_ALL','YXSYSTEMGROUPDATA_EDIT')") @PreAuthorize("hasAnyRole('admin','YXSYSTEMGROUPDATA_ALL','YXSYSTEMGROUPDATA_EDIT')")
public ResponseEntity update(@RequestBody String jsonStr){ public ResponseEntity update(@RequestBody String jsonStr) {
JSONObject jsonObject = JSON.parseObject(jsonStr); JSONObject jsonObject = JSON.parseObject(jsonStr);
this.checkParam(jsonObject); this.checkParam(jsonObject);
@ -98,15 +105,28 @@ public class SystemGroupDataController {
yxSystemGroupData.setGroupName(jsonObject.get("groupName").toString()); yxSystemGroupData.setGroupName(jsonObject.get("groupName").toString());
jsonObject.remove("groupName"); jsonObject.remove("groupName");
yxSystemGroupData.setValue(jsonObject.toJSONString()); yxSystemGroupData.setValue(jsonObject.toJSONString());
if(jsonObject.getInteger("status") == null){ yxSystemGroupData.setStatus(jsonObject.getInteger("status"));
List<YxSystemGroupData> yshop_seckill_time = yxSystemGroupDataService.list(Wrappers.<YxSystemGroupData>lambdaQuery()
.eq(YxSystemGroupData::getGroupName, "yshop_seckill_time"));
if (yxSystemGroupData.getStatus() == 1) {
yshop_seckill_time.forEach(item -> {
Map map = JSONUtil.toBean(item.getValue(), Map.class);
if (jsonObject.getInteger("time").equals(map.get("time"))) {
throw new BadRequestException("不能同时开启同一时间点");
}
});
}
if (jsonObject.getInteger("status") == null) {
yxSystemGroupData.setStatus(1); yxSystemGroupData.setStatus(1);
}else{ } else {
yxSystemGroupData.setStatus(jsonObject.getInteger("status")); yxSystemGroupData.setStatus(jsonObject.getInteger("status"));
} }
if(jsonObject.getInteger("sort") == null){ if (jsonObject.getInteger("sort") == null) {
yxSystemGroupData.setSort(0); yxSystemGroupData.setSort(0);
}else{ } else {
yxSystemGroupData.setSort(jsonObject.getInteger("sort")); yxSystemGroupData.setSort(jsonObject.getInteger("sort"));
} }
@ -121,37 +141,38 @@ public class SystemGroupDataController {
@ApiOperation(value = "删除数据配置") @ApiOperation(value = "删除数据配置")
@DeleteMapping(value = "/yxSystemGroupData/{id}") @DeleteMapping(value = "/yxSystemGroupData/{id}")
@PreAuthorize("hasAnyRole('admin','YXSYSTEMGROUPDATA_ALL','YXSYSTEMGROUPDATA_DELETE')") @PreAuthorize("hasAnyRole('admin','YXSYSTEMGROUPDATA_ALL','YXSYSTEMGROUPDATA_DELETE')")
public ResponseEntity delete(@PathVariable Integer id){ public ResponseEntity delete(@PathVariable Integer id) {
yxSystemGroupDataService.removeById(id); yxSystemGroupDataService.removeById(id);
return new ResponseEntity(HttpStatus.OK); return new ResponseEntity(HttpStatus.OK);
} }
/** /**
* 检测参数 * 检测参数
*
* @param jsonObject * @param jsonObject
*/ */
private void checkParam(JSONObject jsonObject){ private void checkParam(JSONObject jsonObject) {
if(ObjectUtil.isNotNull(jsonObject.get("name"))){ if (ObjectUtil.isNotNull(jsonObject.get("name"))) {
if(StrUtil.isEmpty(jsonObject.getString("name"))){ if (StrUtil.isEmpty(jsonObject.getString("name"))) {
throw new BadRequestException("名称必须填写"); throw new BadRequestException("名称必须填写");
} }
} }
if(ObjectUtil.isNotNull(jsonObject.get("title"))){ if (ObjectUtil.isNotNull(jsonObject.get("title"))) {
if(StrUtil.isEmpty(jsonObject.getString("title"))){ if (StrUtil.isEmpty(jsonObject.getString("title"))) {
throw new BadRequestException("标题必须填写"); throw new BadRequestException("标题必须填写");
} }
} }
if(ObjectUtil.isNotNull(jsonObject.get("pic"))){ if (ObjectUtil.isNotNull(jsonObject.get("pic"))) {
if(StrUtil.isEmpty(jsonObject.getString("pic"))){ if (StrUtil.isEmpty(jsonObject.getString("pic"))) {
throw new BadRequestException("图片必须上传"); throw new BadRequestException("图片必须上传");
} }
} }
if(ObjectUtil.isNotNull(jsonObject.get("info"))){ if (ObjectUtil.isNotNull(jsonObject.get("info"))) {
if(StrUtil.isEmpty(jsonObject.getString("info"))){ if (StrUtil.isEmpty(jsonObject.getString("info"))) {
throw new BadRequestException("简介必须填写"); throw new BadRequestException("简介必须填写");
} }
} }