mirror of
https://gitee.com/gz-yami/mall4j.git
synced 2026-03-22 09:17:16 +08:00
修改地区添加判断
This commit is contained in:
@@ -12,8 +12,10 @@ package com.yami.shop.admin.controller;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.yami.shop.common.util.PageParam;
|
||||
import com.yami.shop.bean.enums.AreaLevelEnum;
|
||||
import com.yami.shop.bean.model.Area;
|
||||
import com.yami.shop.common.exception.YamiShopBindException;
|
||||
import com.yami.shop.common.util.PageParam;
|
||||
import com.yami.shop.service.AreaService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
@@ -22,7 +24,7 @@ import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.validation.Valid;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* @author lgh on 2018/10/26.
|
||||
@@ -95,6 +97,15 @@ public class AreaController {
|
||||
@PutMapping
|
||||
@PreAuthorize("@pms.hasPermission('admin:area:update')")
|
||||
public ResponseEntity<Void> update(@Valid @RequestBody Area area) {
|
||||
Area areaDb = areaService.getById(area.getAreaId());
|
||||
// 判断当前省市区级别,如果是1级、2级则不能修改级别,不能修改成别人的下级
|
||||
if(Objects.equals(areaDb.getLevel(), AreaLevelEnum.FIRST_LEVEL.value()) && !Objects.equals(area.getLevel(),AreaLevelEnum.FIRST_LEVEL.value())){
|
||||
throw new YamiShopBindException("不能改变一级行政地区的级别");
|
||||
}
|
||||
if(Objects.equals(areaDb.getLevel(),AreaLevelEnum.SECOND_LEVEL.value()) && !Objects.equals(area.getLevel(),AreaLevelEnum.SECOND_LEVEL.value())){
|
||||
throw new YamiShopBindException("不能改变二级行政地区的级别");
|
||||
}
|
||||
hasSameName(area);
|
||||
areaService.updateById(area);
|
||||
areaService.removeAreaCacheByParentId(area.getParentId());
|
||||
return ResponseEntity.ok().build();
|
||||
@@ -112,4 +123,14 @@ public class AreaController {
|
||||
return ResponseEntity.ok().build();
|
||||
}
|
||||
|
||||
private void hasSameName(Area area) {
|
||||
int count = areaService.count(new LambdaQueryWrapper<Area>()
|
||||
.eq(Area::getParentId, area.getParentId())
|
||||
.eq(Area::getAreaName, area.getAreaName())
|
||||
.ne(Objects.nonNull(area.getAreaId()) && !Objects.equals(area.getAreaId(), 0L), Area::getAreaId, area.getAreaId())
|
||||
);
|
||||
if (count > 0) {
|
||||
throw new YamiShopBindException("该地区已存在");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,29 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2018-2999 广州市蓝海创新科技有限公司 All rights reserved.
|
||||
*
|
||||
* https://www.mall4j.com/
|
||||
*
|
||||
* 未经允许,不可做商业用途!
|
||||
*
|
||||
* 版权所有,侵权必究!
|
||||
*/
|
||||
|
||||
package com.yami.shop.admin.task;
|
||||
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Slf4j
|
||||
@Component
|
||||
public class TestTask {
|
||||
|
||||
public void test1(){
|
||||
System.out.println(DateUtil.now() + ": test1 running.................");
|
||||
|
||||
}
|
||||
|
||||
public void test2(String param){
|
||||
System.out.println(DateUtil.now() + ": test2 running.................");
|
||||
}
|
||||
}
|
||||
@@ -94,7 +94,6 @@ public class OrderController {
|
||||
double total = 0.0;
|
||||
int totalCount = 0;
|
||||
double orderReduce = 0.0;
|
||||
// List<CouponOrderDto> coupons = new ArrayList<>();
|
||||
for (ShopCartDto shopCart : shopCarts) {
|
||||
|
||||
// 每个店铺的订单信息
|
||||
|
||||
@@ -72,7 +72,7 @@ public class ProdController {
|
||||
|
||||
Product product = prodService.getProductByProdId(prodId);
|
||||
if (product == null) {
|
||||
return ResponseEntity.ok(null);
|
||||
return ResponseEntity.ok().build();
|
||||
}
|
||||
|
||||
List<Sku> skuList = skuService.listByProdId(prodId);
|
||||
|
||||
@@ -0,0 +1,55 @@
|
||||
/*
|
||||
* Copyright (c) 2018-2999 广州市蓝海创新科技有限公司 All rights reserved.
|
||||
*
|
||||
* https://www.mall4j.com/
|
||||
*
|
||||
* 未经允许,不可做商业用途!
|
||||
*
|
||||
* 版权所有,侵权必究!
|
||||
*/
|
||||
package com.yami.shop.bean.enums;
|
||||
|
||||
/**
|
||||
* 地区层级
|
||||
* @author cl
|
||||
*/
|
||||
public enum AreaLevelEnum {
|
||||
|
||||
|
||||
/**
|
||||
* 第一层
|
||||
*/
|
||||
FIRST_LEVEL(1),
|
||||
|
||||
/**
|
||||
* 第二层
|
||||
*/
|
||||
SECOND_LEVEL(2),
|
||||
|
||||
/**
|
||||
* 第三层
|
||||
*/
|
||||
THIRD_LEVEL(3)
|
||||
|
||||
;
|
||||
|
||||
private Integer num;
|
||||
|
||||
public Integer value() {
|
||||
return num;
|
||||
}
|
||||
|
||||
AreaLevelEnum(Integer num) {
|
||||
this.num = num;
|
||||
}
|
||||
|
||||
public static AreaLevelEnum instance(Integer value) {
|
||||
AreaLevelEnum[] enums = values();
|
||||
for (AreaLevelEnum statusEnum : enums) {
|
||||
if (statusEnum.value().equals(value)) {
|
||||
return statusEnum;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user