存酒接口
This commit is contained in:
parent
4067bc0b0b
commit
2b6345b7ce
|
|
@ -1,19 +1,78 @@
|
|||
package com.czg.controller.admin;
|
||||
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.czg.account.dto.storage.ShopStorageGoodDTO;
|
||||
import com.czg.account.entity.ShopStorageGood;
|
||||
import com.czg.account.service.ShopStorageGoodService;
|
||||
import com.czg.annotation.SaAdminCheckPermission;
|
||||
import com.czg.resp.CzgResult;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import com.czg.sa.StpKit;
|
||||
import com.czg.utils.PageUtil;
|
||||
import com.czg.validator.group.DefaultGroup;
|
||||
import com.czg.validator.group.InsertGroup;
|
||||
import com.czg.validator.group.UpdateGroup;
|
||||
import com.mybatisflex.core.paginate.Page;
|
||||
import com.mybatisflex.core.query.QueryWrapper;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
/**
|
||||
* 存酒管理
|
||||
* 存酒商品管理
|
||||
* @author Administrator
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping
|
||||
@RequestMapping("/admin/storageGood")
|
||||
public class ShopStorageGoodController {
|
||||
@Resource
|
||||
private ShopStorageGoodService shopStorageGoodService;
|
||||
|
||||
/**
|
||||
* 获取存酒商品列表
|
||||
* @param name 商品名
|
||||
* @return 列表
|
||||
*/
|
||||
@SaAdminCheckPermission(value = "storageGood:list", name = "获取存酒商品列表")
|
||||
@GetMapping
|
||||
public CzgResult<Page<ShopStorageGood>> list(String name) {
|
||||
QueryWrapper queryWrapper = new QueryWrapper().eq(ShopStorageGood::getShopId, StpKit.USER.getShopId());
|
||||
if (StrUtil.isNotBlank(name)) {
|
||||
queryWrapper.eq(ShopStorageGood::getName, name);
|
||||
}
|
||||
return CzgResult.success(shopStorageGoodService.page(PageUtil.buildPage(), queryWrapper));
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取存酒商品详情
|
||||
* @param id 商品id
|
||||
* @return 列表
|
||||
*/
|
||||
@SaAdminCheckPermission(value = "storageGood:detail", name = "获取存酒商品详情")
|
||||
@GetMapping("/detail")
|
||||
public CzgResult<ShopStorageGood> detail(@RequestParam Integer id) {
|
||||
return CzgResult.success(shopStorageGoodService.getOne(new QueryWrapper().eq(ShopStorageGood::getShopId, StpKit.USER.getShopId()).eq(ShopStorageGood::getId, id)));
|
||||
}
|
||||
|
||||
/**
|
||||
* 编辑存酒商品
|
||||
* @return 列表
|
||||
*/
|
||||
@SaAdminCheckPermission(value = "storageGood:edit", name = "存酒商品编辑")
|
||||
@PutMapping("/edit")
|
||||
public CzgResult<Boolean> edit(@RequestBody @Validated({UpdateGroup.class}) ShopStorageGoodDTO shopStorageGoodDTO) {
|
||||
return CzgResult.success(shopStorageGoodService.edit(StpKit.USER.getShopId(), shopStorageGoodDTO));
|
||||
}
|
||||
|
||||
/**
|
||||
* 编辑存酒商品
|
||||
* @return 列表
|
||||
*/
|
||||
@SaAdminCheckPermission(value = "storageGood:add", name = "存酒商品新增")
|
||||
@PutMapping("/add")
|
||||
public CzgResult<Boolean> add(@RequestBody @Validated({InsertGroup.class}) ShopStorageGoodDTO shopStorageGoodDTO) {
|
||||
return CzgResult.success(shopStorageGoodService.saveInfo(StpKit.USER.getShopId(), shopStorageGoodDTO));
|
||||
}
|
||||
|
||||
|
||||
// @SaAdminCheckPermission("")
|
||||
// public CzgResult<>
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,10 +1,14 @@
|
|||
|
||||
package com.czg.account.dto;
|
||||
package com.czg.account.dto.storage;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.time.LocalDateTime;
|
||||
import com.alibaba.fastjson2.annotation.JSONField;
|
||||
import java.io.Serial;
|
||||
|
||||
import com.czg.validator.group.UpdateGroup;
|
||||
import jakarta.validation.constraints.NotEmpty;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
|
|
@ -20,26 +24,27 @@ import lombok.NoArgsConstructor;
|
|||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class ShopStorageGoodDTO implements Serializable {
|
||||
|
||||
@Serial
|
||||
private static final long serialVersionUID = 1L;
|
||||
public class ShopStorageGoodDTO {
|
||||
|
||||
@NotNull(message = "id不为空", groups = UpdateGroup.class)
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* 酒品名
|
||||
*/
|
||||
@NotEmpty(message = "酒品名不为空")
|
||||
private String name;
|
||||
|
||||
/**
|
||||
* 图片地址
|
||||
*/
|
||||
@NotEmpty(message = "酒品名不为空")
|
||||
private String imgUrl;
|
||||
|
||||
/**
|
||||
* 单位
|
||||
*/
|
||||
@NotEmpty(message = "单位不为空")
|
||||
private String unit;
|
||||
|
||||
/**
|
||||
|
|
@ -47,22 +52,9 @@ public class ShopStorageGoodDTO implements Serializable {
|
|||
*/
|
||||
private Integer period;
|
||||
|
||||
/**
|
||||
* 0:未删除;1:已删除
|
||||
*/
|
||||
private Integer isDel;
|
||||
|
||||
@JSONField(format = "yyyy-MM-dd HH:mm:ss")
|
||||
private LocalDateTime createTime;
|
||||
|
||||
/**
|
||||
* 0:手动;1:商品;
|
||||
*/
|
||||
private Integer source;
|
||||
|
||||
/**
|
||||
* 商户Id
|
||||
*/
|
||||
private Long shopId;
|
||||
|
||||
}
|
||||
|
|
@ -1,5 +1,6 @@
|
|||
package com.czg.account.service;
|
||||
|
||||
import com.czg.account.dto.storage.ShopStorageGoodDTO;
|
||||
import com.mybatisflex.core.service.IService;
|
||||
import com.czg.account.entity.ShopStorageGood;
|
||||
|
||||
|
|
@ -11,4 +12,7 @@ import com.czg.account.entity.ShopStorageGood;
|
|||
*/
|
||||
public interface ShopStorageGoodService extends IService<ShopStorageGood> {
|
||||
|
||||
Boolean edit(Long shopId, ShopStorageGoodDTO shopStorageGoodDTO);
|
||||
|
||||
Boolean saveInfo(Long shopId, ShopStorageGoodDTO shopStorageGoodDTO);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,9 @@
|
|||
package com.czg.service.account.service.impl;
|
||||
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import com.czg.account.dto.storage.ShopStorageGoodDTO;
|
||||
import com.czg.exception.ApiNotPrintException;
|
||||
import com.mybatisflex.core.query.QueryWrapper;
|
||||
import com.mybatisflex.spring.service.impl.ServiceImpl;
|
||||
import com.czg.account.entity.ShopStorageGood;
|
||||
import com.czg.account.service.ShopStorageGoodService;
|
||||
|
|
@ -15,4 +19,22 @@ import org.springframework.stereotype.Service;
|
|||
@Service
|
||||
public class ShopStorageGoodServiceImpl extends ServiceImpl<ShopStorageGoodMapper, ShopStorageGood> implements ShopStorageGoodService{
|
||||
|
||||
@Override
|
||||
public Boolean edit(Long shopId, ShopStorageGoodDTO shopStorageGoodDTO) {
|
||||
ShopStorageGood storageGood = getOne(new QueryWrapper().eq(ShopStorageGood::getShopId, shopId).eq(ShopStorageGood::getId, shopStorageGoodDTO.getId()));
|
||||
if (storageGood == null) {
|
||||
throw new ApiNotPrintException("商品不存在");
|
||||
}
|
||||
|
||||
BeanUtil.copyProperties(shopStorageGoodDTO, storageGood);
|
||||
storageGood.setSource(null);
|
||||
return updateById(storageGood);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean saveInfo(Long shopId, ShopStorageGoodDTO shopStorageGoodDTO) {
|
||||
ShopStorageGood shopStorageGood = BeanUtil.copyProperties(shopStorageGoodDTO, ShopStorageGood.class);
|
||||
shopStorageGood.setShopId(shopId);
|
||||
return save(shopStorageGood);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue