店铺区域接口

This commit is contained in:
张松 2025-02-19 11:00:39 +08:00
parent 019fada4b9
commit 0d2efef2a1
6 changed files with 99 additions and 18 deletions

View File

@ -1,31 +1,31 @@
package com.czg.controller.admin;
import com.czg.account.dto.area.ShopAreaAddDTO;
import com.czg.account.dto.area.ShopAreaEditDTO;
import com.czg.account.entity.ShopTableArea;
import com.czg.account.service.ShopTableAreaService;
import com.czg.annotation.SaAdminCheckPermission;
import com.czg.resp.CzgResult;
import com.czg.sa.StpKit;
import com.mybatisflex.core.paginate.Page;
import com.mybatisflex.core.query.QueryWrapper;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
/**
* 区域管理
* @author Administrator
*/
@RestController
@RequestMapping("/shopArea")
@RequestMapping("/admin/shopArea")
public class ShopTableAreaController {
@Resource
private ShopTableAreaService shopTableAreaService;
/**
* 区域添加
* 区域获取
* 权限标识: shopArea:add
* @param name 区域名称
* @return 是否成功
*/
@ -37,12 +37,34 @@ public class ShopTableAreaController {
/**
* 区域修改
* @param name 区域名称
* 权限标识: shopArea:edit
* @return 是否成功
*/
@SaAdminCheckPermission("shopArea:edit")
@PutMapping
public CzgResult<Page<ShopTableArea>> edit(String name) {
return CzgResult.success(shopTableAreaService.pageInfo(StpKit.USER.getShopId(), name));
public CzgResult<Boolean> edit(@RequestBody @Validated ShopAreaEditDTO shopAreaEditDTO) {
return CzgResult.success(shopTableAreaService.edit(StpKit.USER.getShopId(), shopAreaEditDTO));
}
/**
* 区域删除
* 权限标识: shopArea:del
* @return 是否成功
*/
@SaAdminCheckPermission("shopArea:del")
@DeleteMapping
public CzgResult<Boolean> remove(@RequestBody @Validated ShopAreaEditDTO shopAreaEditDTO) {
return CzgResult.success(shopTableAreaService.remove(new QueryWrapper().eq(ShopTableArea::getShopId, StpKit.USER.getShopId()).eq(ShopTableArea::getId, shopAreaEditDTO.getId())));
}
/**
* 区域新增
* 权限标识: shopArea:add
* @return 是否成功
*/
@SaAdminCheckPermission("shopArea:add")
@PostMapping
public CzgResult<Boolean> add(@RequestBody @Validated ShopAreaAddDTO shopAreaAddDTO) {
return CzgResult.success(shopTableAreaService.add(shopAreaAddDTO));
}
}

View File

@ -0,0 +1,34 @@
package com.czg.account.dto.area;
import jakarta.validation.constraints.NotEmpty;
import jakarta.validation.constraints.NotNull;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.io.Serializable;
/**
* 店铺区域 实体类
*
* @author zs
* @since 2025-02-18
*/
@Data
public class ShopAreaAddDTO implements Serializable {
/**
* 排序
*/
private Integer sort;
/**
* 区域名称
*/
@NotEmpty(message = "店铺名称不为空")
private String name;
}

View File

@ -28,11 +28,6 @@ public class ShopAreaEditDTO implements Serializable {
@NotNull
private Integer id;
/**
* 店铺Id
*/
private Integer shopId;
/**
* 排序
*/

View File

@ -39,7 +39,7 @@ public class ShopTableArea implements Serializable {
/**
* 店铺Id
*/
private Integer shopId;
private Long shopId;
/**
* 排序
@ -55,6 +55,6 @@ public class ShopTableArea implements Serializable {
private LocalDateTime createdTime;
@Column(onInsertValue = "now()", onUpdateValue = "now()")
private Long updatedTime;
private LocalDateTime updatedTime;
}

View File

@ -1,5 +1,7 @@
package com.czg.account.service;
import com.czg.account.dto.area.ShopAreaAddDTO;
import com.czg.account.dto.area.ShopAreaEditDTO;
import com.mybatisflex.core.paginate.Page;
import com.mybatisflex.core.service.IService;
import com.czg.account.entity.ShopTableArea;
@ -13,4 +15,9 @@ import com.czg.account.entity.ShopTableArea;
public interface ShopTableAreaService extends IService<ShopTableArea> {
Page<ShopTableArea> pageInfo(Long shopId, String name);
boolean edit(Long shopId, ShopAreaEditDTO shopAreaEditDTO);
Boolean add(ShopAreaAddDTO shopAreaAddDTO);
}

View File

@ -1,6 +1,11 @@
package com.czg.service.account.service.impl;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.util.StrUtil;
import com.czg.account.dto.area.ShopAreaAddDTO;
import com.czg.account.dto.area.ShopAreaEditDTO;
import com.czg.exception.ApiNotPrintException;
import com.czg.sa.StpKit;
import com.czg.utils.PageUtil;
import com.mybatisflex.core.paginate.Page;
import com.mybatisflex.core.query.QueryWrapper;
@ -28,4 +33,22 @@ public class ShopTableAreaServiceImpl extends ServiceImpl<ShopAreaMapper, ShopTa
}
return page(PageUtil.buildPage(), queryWrapper);
}
@Override
public boolean edit(Long shopId, ShopAreaEditDTO shopAreaEditDTO) {
ShopTableArea tableArea = queryChain().eq(ShopTableArea::getShopId, shopId).eq(ShopTableArea::getId, shopAreaEditDTO.getId()).one();
if (tableArea == null) {
throw new ApiNotPrintException("区域不存在");
}
BeanUtil.copyProperties(shopAreaEditDTO, tableArea);
return updateById(tableArea);
}
@Override
public Boolean add(ShopAreaAddDTO shopAreaAddDTO) {
ShopTableArea shopTableArea = BeanUtil.copyProperties(shopAreaAddDTO, ShopTableArea.class);
shopTableArea.setShopId(StpKit.USER.getShopId());
return save(shopTableArea);
}
}