存酒接口

This commit is contained in:
张松 2025-02-27 13:58:04 +08:00
parent 250ce131d2
commit 2bce1acb69
27 changed files with 807 additions and 63 deletions

View File

@ -29,8 +29,8 @@ public class UShopUserController {
* @return 店铺会员信息 * @return 店铺会员信息
*/ */
@GetMapping @GetMapping
public CzgResult<ShopUser> get() { public CzgResult<ShopUser> get(Long shopId) {
return CzgResult.success(shopUserService.getShopUserInfo(StpKit.USER.getShopId(), StpKit.USER.getLoginIdAsLong())); return CzgResult.success(shopUserService.getShopUserInfo(shopId == null ? StpKit.USER.getShopId() : shopId, StpKit.USER.getLoginIdAsLong()));
} }
/** /**
@ -49,8 +49,8 @@ public class UShopUserController {
* @return 店铺会员信息列表 * @return 店铺会员信息列表
*/ */
@GetMapping("/code") @GetMapping("/code")
public CzgResult<String> code() { public CzgResult<String> code(Long shopId) {
return shopUserService.getCode(StpKit.USER.getLoginIdAsLong(), StpKit.USER.getShopId()); return shopUserService.getCode(StpKit.USER.getLoginIdAsLong(), shopId == null ? StpKit.USER.getShopId() : shopId);
} }
} }

View File

@ -38,7 +38,7 @@ public class UserAuthorizationController {
*/ */
@PostMapping("/test") @PostMapping("/test")
public CzgResult<String> login() { public CzgResult<String> login() {
// StpKit.USER.login(1L, null, MyStpLogic.LoginType.USER, false); StpKit.USER.login(1L, "2342", null, MyStpLogic.LoginType.USER, false);
return CzgResult.success(StpKit.USER.getTokenValue()); return CzgResult.success(StpKit.USER.getTokenValue());
} }
} }

View File

@ -0,0 +1,85 @@
package com.czg.controller.admin;
import com.czg.product.dto.storage.CountStorageDTO;
import com.czg.product.dto.storage.ShopStorageAddDTO;
import com.czg.product.dto.storage.ShopStorageEditDTO;
import com.czg.product.entity.ShopStorage;
import com.czg.product.entity.ShopStorageRecord;
import com.czg.annotation.SaAdminCheckPermission;
import com.czg.product.service.ShopStorageService;
import com.czg.resp.CzgResult;
import com.czg.sa.StpKit;
import com.mybatisflex.core.paginate.Page;
import jakarta.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import java.util.List;
/**
* 存酒记录管理
* @author Administrator
*/
@RestController
@RequestMapping("/admin/shopStorage")
public class ShopStorageController {
@Resource
private ShopStorageService shopStorageService;
/**
* 存酒记录
* @param key 酒名/用户昵称
* @param phone 手机号
* @param status 0已取完1未取完2已过期
* @return 分页数据
*/
@SaAdminCheckPermission(value = "shopStorage:list", name = "获取存酒记录列表")
@GetMapping
public CzgResult<Page<ShopStorage>> list(String key, String phone, Integer status) {
return CzgResult.success(shopStorageService.pageInfo(StpKit.USER.getShopId(), key, phone, status));
}
/**
* 存酒记录添加
* @return 分页数据
*/
@SaAdminCheckPermission(value = "shopStorage:add", name = "添加存酒")
@PostMapping
public CzgResult<Boolean> add(@RequestBody @Validated ShopStorageAddDTO shopStorageAddDTO) {
return CzgResult.success(shopStorageService.add(StpKit.USER.getShopId(), shopStorageAddDTO));
}
/**
* 存酒取酒
* @return 分页数据
*/
@SaAdminCheckPermission(value = "shopStorage:edit", name = "修改存酒数量")
@PutMapping
public CzgResult<Boolean> edit(@RequestBody @Validated ShopStorageEditDTO shopStorageEditDTO) {
if (shopStorageEditDTO.getNum() == 0) {
return CzgResult.failure("数量不为0");
}
return CzgResult.success(shopStorageService.edit(StpKit.USER.getShopId(), shopStorageEditDTO));
}
/**
* 查询存取酒记录
* @param id 存酒id
* @return 分页数据
*/
@SaAdminCheckPermission(value = "shopStorage:record", name = "查询存取酒记录")
@GetMapping("/record")
public CzgResult<List<ShopStorageRecord>> recordList(@RequestParam Integer id) {
return CzgResult.success(shopStorageService.getRecord(StpKit.USER.getShopId(), id));
}
/**
* 存酒统计
* @return 统计信息
*/
@SaAdminCheckPermission(value = "shopStorage:count", name = "存酒统计")
@GetMapping("/count")
public CzgResult<List<CountStorageDTO>> countRecord() {
return CzgResult.success(shopStorageService.countRecord(StpKit.USER.getShopId()));
}
}

View File

@ -1,14 +1,14 @@
package com.czg.controller.admin; package com.czg.controller.admin;
import cn.hutool.core.util.StrUtil; import cn.hutool.core.util.StrUtil;
import com.czg.account.dto.storage.ShopStorageGoodDTO; import com.czg.product.dto.storage.ShopStorageGoodDTO;
import com.czg.account.entity.ShopStorageGood; import com.czg.product.entity.ShopStorage;
import com.czg.account.service.ShopStorageGoodService; import com.czg.product.entity.ShopStorageGood;
import com.czg.product.service.ShopStorageGoodService;
import com.czg.annotation.SaAdminCheckPermission; import com.czg.annotation.SaAdminCheckPermission;
import com.czg.resp.CzgResult; import com.czg.resp.CzgResult;
import com.czg.sa.StpKit; import com.czg.sa.StpKit;
import com.czg.utils.PageUtil; import com.czg.utils.PageUtil;
import com.czg.validator.group.DefaultGroup;
import com.czg.validator.group.InsertGroup; import com.czg.validator.group.InsertGroup;
import com.czg.validator.group.UpdateGroup; import com.czg.validator.group.UpdateGroup;
import com.mybatisflex.core.paginate.Page; import com.mybatisflex.core.paginate.Page;
@ -39,6 +39,7 @@ public class ShopStorageGoodController {
if (StrUtil.isNotBlank(name)) { if (StrUtil.isNotBlank(name)) {
queryWrapper.eq(ShopStorageGood::getName, name); queryWrapper.eq(ShopStorageGood::getName, name);
} }
queryWrapper.orderBy(ShopStorageGood::getId, false);
return CzgResult.success(shopStorageGoodService.page(PageUtil.buildPage(), queryWrapper)); return CzgResult.success(shopStorageGoodService.page(PageUtil.buildPage(), queryWrapper));
} }
@ -64,15 +65,23 @@ public class ShopStorageGoodController {
} }
/** /**
* 编辑存酒商品 * 添加存酒商品
* @return 列表 * @return 列表
*/ */
@SaAdminCheckPermission(value = "storageGood:add", name = "存酒商品新增") @SaAdminCheckPermission(value = "storageGood:add", name = "存酒商品新增")
@PutMapping("/add") @PostMapping
public CzgResult<Boolean> add(@RequestBody @Validated({InsertGroup.class}) ShopStorageGoodDTO shopStorageGoodDTO) { public CzgResult<Boolean> add(@RequestBody @Validated({InsertGroup.class}) ShopStorageGoodDTO shopStorageGoodDTO) {
return CzgResult.success(shopStorageGoodService.saveInfo(StpKit.USER.getShopId(), shopStorageGoodDTO)); return CzgResult.success(shopStorageGoodService.saveInfo(StpKit.USER.getShopId(), shopStorageGoodDTO));
} }
/**
* 删除存酒商品
* @return 列表
*/
@SaAdminCheckPermission(value = "storageGood:del", name = "存酒商品删除")
@DeleteMapping
public CzgResult<Boolean> del(@RequestBody @Validated({UpdateGroup.class}) ShopStorageGoodDTO shopStorageGoodDTO) {
return CzgResult.success(shopStorageGoodService.remove(new QueryWrapper().eq(ShopStorageGood::getShopId, StpKit.USER.getShopId()).eq(ShopStorageGood::getId, shopStorageGoodDTO.getId())));
}
} }

View File

@ -0,0 +1,92 @@
package com.czg.account.dto;
import java.io.Serializable;
import java.time.LocalDateTime;
import com.alibaba.fastjson2.annotation.JSONField;
import java.io.Serial;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
/**
* 用户存酒 实体类
*
* @author zs
* @since 2025-02-27
*/
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class ShopStorageDTO implements Serializable {
@Serial
private static final long serialVersionUID = 1L;
private Integer id;
/**
* 酒品名
*/
private String name;
/**
* 酒品图
*/
private String imgUrl;
/**
* 单位
*/
private String unit;
/**
* 数量
*/
private Integer num;
/**
* 0已取完1未取完2已过期
*/
private Integer status;
/**
* 到期时间
*/
@JSONField(format = "yyyy-MM-dd HH:mm:ss")
private LocalDateTime expTime;
/**
* 存酒时间
*/
@JSONField(format = "yyyy-MM-dd HH:mm:ss")
private LocalDateTime savTime;
/**
* 用户Id
*/
private Integer userId;
/**
* 用户头像
*/
private String headImg;
/**
* 用户昵称
*/
private String nickName;
/**
* 用户电话
*/
private String telphone;
/**
* 店铺id
*/
private Integer shopId;
}

View File

@ -0,0 +1,46 @@
package com.czg.product.dto;
import java.io.Serializable;
import java.time.LocalDateTime;
import com.alibaba.fastjson2.annotation.JSONField;
import java.io.Serial;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
/**
* 存取酒记录表 实体类
*
* @author zs
* @since 2025-02-27
*/
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class ShopStorageRecordDTO implements Serializable {
@Serial
private static final long serialVersionUID = 1L;
private Integer id;
/**
* 存酒信息id
*/
private Integer storageId;
/**
* 记录
*/
private String content;
/**
* 操作时间
*/
@JSONField(format = "yyyy-MM-dd HH:mm:ss")
private LocalDateTime time;
}

View File

@ -0,0 +1,14 @@
package com.czg.product.dto.storage;
import lombok.Data;
/**
* @author Administrator
*/
@Data
public class CountStorageDTO {
private String name;
private String imgUrl;
private Long savNum;
private Long expNum;
}

View File

@ -0,0 +1,34 @@
package com.czg.product.dto.storage;
import jakarta.validation.constraints.Min;
import jakarta.validation.constraints.NotNull;
import lombok.Data;
/**
*
* @author Administrator
*/
@Data
public class ShopStorageAddDTO {
/**
* shopUser的userId不是主键id
*/
@NotNull(message = "用户id不为空")
private Long userId;
/**
* 酒品id
*/
@NotNull(message = "酒品id不为空")
private Long shopStorageGoodId;
/**
* 数量
*/
@NotNull(message = "数量不为空")
@Min(value = 1, message = "数量不能小于1")
private Integer num;
/**
* 多少天后过期默认一天
*/
private Integer expDay;
}

View File

@ -0,0 +1,25 @@
package com.czg.product.dto.storage;
import jakarta.validation.constraints.Min;
import jakarta.validation.constraints.NotNull;
import lombok.Data;
import javax.swing.*;
/**
*
* @author Administrator
*/
@Data
public class ShopStorageEditDTO {
/**
* 存酒id
*/
@NotNull(message = "存酒id不为空")
private Integer id;
/**
* 正数为存酒反之为取酒
*/
@NotNull(message = "数量不为空")
private Integer num;
}

View File

@ -1,11 +1,12 @@
package com.czg.account.dto.storage; package com.czg.product.dto.storage;
import java.io.Serializable; import java.io.Serializable;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import com.alibaba.fastjson2.annotation.JSONField; import com.alibaba.fastjson2.annotation.JSONField;
import java.io.Serial; import java.io.Serial;
import com.czg.validator.group.InsertGroup;
import com.czg.validator.group.UpdateGroup; import com.czg.validator.group.UpdateGroup;
import jakarta.validation.constraints.NotEmpty; import jakarta.validation.constraints.NotEmpty;
import jakarta.validation.constraints.NotNull; import jakarta.validation.constraints.NotNull;
@ -32,19 +33,19 @@ public class ShopStorageGoodDTO {
/** /**
* 酒品名 * 酒品名
*/ */
@NotEmpty(message = "酒品名不为空") @NotEmpty(message = "酒品名不为空", groups = {UpdateGroup.class, InsertGroup.class})
private String name; private String name;
/** /**
* 图片地址 * 图片地址
*/ */
@NotEmpty(message = "酒品名不为空") @NotEmpty(message = "酒品名不为空", groups = {UpdateGroup.class, InsertGroup.class})
private String imgUrl; private String imgUrl;
/** /**
* 单位 * 单位
*/ */
@NotEmpty(message = "单位不为空") @NotEmpty(message = "单位不为空", groups = {UpdateGroup.class, InsertGroup.class})
private String unit; private String unit;
/** /**
@ -57,4 +58,6 @@ public class ShopStorageGoodDTO {
*/ */
private Integer source; private Integer source;
private Long prodId;
} }

View File

@ -0,0 +1,97 @@
package com.czg.product.entity;
import com.mybatisflex.annotation.Id;
import com.mybatisflex.annotation.KeyType;
import com.mybatisflex.annotation.Table;
import java.io.Serializable;
import java.time.LocalDateTime;
import java.io.Serial;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;
/**
* 用户存酒 实体类
*
* @author zs
* @since 2025-02-27
*/
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@Table("tb_shop_storage")
@Accessors(chain = true)
public class ShopStorage implements Serializable {
@Serial
private static final long serialVersionUID = 1L;
@Id(keyType = KeyType.Auto)
private Long id;
/**
* 酒品名
*/
private String name;
/**
* 酒品图
*/
private String imgUrl;
/**
* 单位
*/
private String unit;
/**
* 数量
*/
private Integer num;
/**
* 0已取完1未取完2已过期
*/
private Integer status;
/**
* 到期时间
*/
private LocalDateTime expTime;
/**
* 存酒时间
*/
private LocalDateTime savTime;
/**
* 用户Id
*/
private Long userId;
/**
* 用户头像
*/
private String headImg;
/**
* 用户昵称
*/
private String nickName;
/**
* 用户电话
*/
private String phone;
/**
* 店铺id
*/
private Long shopId;
}

View File

@ -1,4 +1,4 @@
package com.czg.account.entity; package com.czg.product.entity;
import com.mybatisflex.annotation.Column; import com.mybatisflex.annotation.Column;
import com.mybatisflex.annotation.Id; import com.mybatisflex.annotation.Id;

View File

@ -0,0 +1,50 @@
package com.czg.product.entity;
import com.mybatisflex.annotation.Id;
import com.mybatisflex.annotation.KeyType;
import com.mybatisflex.annotation.Table;
import java.io.Serializable;
import java.time.LocalDateTime;
import java.io.Serial;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
/**
* 存取酒记录表 实体类
*
* @author zs
* @since 2025-02-27
*/
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@Table("tb_shop_storage_record")
public class ShopStorageRecord implements Serializable {
@Serial
private static final long serialVersionUID = 1L;
@Id(keyType = KeyType.Auto)
private Long id;
/**
* 存酒信息id
*/
private Long storageId;
/**
* 记录
*/
private String content;
/**
* 操作时间
*/
private LocalDateTime time;
}

View File

@ -1,8 +1,11 @@
package com.czg.account.service; package com.czg.product.service;
import com.czg.account.dto.storage.ShopStorageGoodDTO; import com.czg.product.dto.storage.ShopStorageAddDTO;
import com.czg.product.dto.storage.ShopStorageGoodDTO;
import com.czg.product.entity.ShopStorage;
import com.mybatisflex.core.paginate.Page;
import com.mybatisflex.core.service.IService; import com.mybatisflex.core.service.IService;
import com.czg.account.entity.ShopStorageGood; import com.czg.product.entity.ShopStorageGood;
/** /**
* 酒品表 服务层 * 酒品表 服务层
@ -15,4 +18,5 @@ public interface ShopStorageGoodService extends IService<ShopStorageGood> {
Boolean edit(Long shopId, ShopStorageGoodDTO shopStorageGoodDTO); Boolean edit(Long shopId, ShopStorageGoodDTO shopStorageGoodDTO);
Boolean saveInfo(Long shopId, ShopStorageGoodDTO shopStorageGoodDTO); Boolean saveInfo(Long shopId, ShopStorageGoodDTO shopStorageGoodDTO);
} }

View File

@ -0,0 +1,14 @@
package com.czg.product.service;
import com.mybatisflex.core.service.IService;
import com.czg.product.entity.ShopStorageRecord;
/**
* 存取酒记录表 服务层
*
* @author zs
* @since 2025-02-27
*/
public interface ShopStorageRecordService extends IService<ShopStorageRecord> {
}

View File

@ -0,0 +1,31 @@
package com.czg.product.service;
import com.czg.product.dto.storage.CountStorageDTO;
import com.czg.product.dto.storage.ShopStorageAddDTO;
import com.czg.product.dto.storage.ShopStorageEditDTO;
import com.czg.product.entity.ShopStorageRecord;
import com.mybatisflex.core.paginate.Page;
import com.mybatisflex.core.service.IService;
import com.czg.product.entity.ShopStorage;
import java.util.List;
/**
* 用户存酒 服务层
*
* @author zs
* @since 2025-02-27
*/
public interface ShopStorageService extends IService<ShopStorage> {
Page<ShopStorage> pageInfo(Long shopId, String key, String phone, Integer status);
Boolean add(Long shopId, ShopStorageAddDTO shopStorageAddDTO);
Boolean edit(Long shopId, ShopStorageEditDTO shopStorageEditDTO);
List<ShopStorageRecord> getRecord(Long shopId, Integer id);
List<CountStorageDTO> countRecord(Long shopId);
}

View File

@ -130,6 +130,8 @@ public class ShopInfoServiceImpl extends ServiceImpl<ShopInfoMapper, ShopInfo> i
if (!StpKit.USER.isAdmin() && !Objects.equals(StpKit.USER.getShopId(), shopInfo.getId())) { if (!StpKit.USER.isAdmin() && !Objects.equals(StpKit.USER.getShopId(), shopInfo.getId())) {
throw new ApiNotPrintException("店铺信息不存在"); throw new ApiNotPrintException("店铺信息不存在");
} }
SysUser sysUser = sysUserService.getById(shopInfo.getId());
return shopInfo; return shopInfo;
} }

View File

@ -1,40 +0,0 @@
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;
import com.czg.service.account.mapper.ShopStorageGoodMapper;
import org.springframework.stereotype.Service;
/**
* 酒品表 服务层实现
*
* @author zs
* @since 2025-02-26
*/
@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);
}
}

View File

@ -1,7 +1,7 @@
package com.czg.service.account.mapper; package com.czg.service.product.mapper;
import com.mybatisflex.core.BaseMapper; import com.mybatisflex.core.BaseMapper;
import com.czg.account.entity.ShopStorageGood; import com.czg.product.entity.ShopStorageGood;
/** /**
* 酒品表 映射层 * 酒品表 映射层

View File

@ -0,0 +1,20 @@
package com.czg.service.product.mapper;
import com.czg.product.dto.storage.CountStorageDTO;
import com.mybatisflex.core.BaseMapper;
import com.czg.product.entity.ShopStorage;
import org.apache.ibatis.annotations.Param;
import java.util.List;
/**
* 用户存酒 映射层
*
* @author zs
* @since 2025-02-27
*/
public interface ShopStorageMapper extends BaseMapper<ShopStorage> {
List<CountStorageDTO> countRecord(@Param("shopId") Long shopId);
}

View File

@ -0,0 +1,14 @@
package com.czg.service.product.mapper;
import com.mybatisflex.core.BaseMapper;
import com.czg.product.entity.ShopStorageRecord;
/**
* 存取酒记录表 映射层
*
* @author zs
* @since 2025-02-27
*/
public interface ShopStorageRecordMapper extends BaseMapper<ShopStorageRecord> {
}

View File

@ -0,0 +1,69 @@
package com.czg.service.product.service.impl;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.util.StrUtil;
import com.czg.product.dto.storage.ShopStorageGoodDTO;
import com.czg.product.entity.Product;
import com.czg.product.entity.ShopProdUnit;
import com.czg.product.entity.ShopStorage;
import com.czg.exception.ApiNotPrintException;
import com.czg.product.service.ProductService;
import com.czg.product.service.ShopProdUnitService;
import com.czg.sa.StpKit;
import com.czg.service.product.mapper.ShopStorageGoodMapper;
import com.czg.utils.PageUtil;
import com.mybatisflex.core.paginate.Page;
import com.mybatisflex.core.query.QueryWrapper;
import com.mybatisflex.spring.service.impl.ServiceImpl;
import com.czg.product.entity.ShopStorageGood;
import com.czg.product.service.ShopStorageGoodService;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;
import static com.mybatisflex.core.query.QueryMethods.column;
/**
* 酒品表 服务层实现
*
* @author zs
* @since 2025-02-26
*/
@Service
public class ShopStorageGoodServiceImpl extends ServiceImpl<ShopStorageGoodMapper, ShopStorageGood> implements ShopStorageGoodService{
@Resource
private ProductService productService;
@Resource
private ShopProdUnitService shopProdUnitService;
@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);
if (shopStorageGoodDTO.getSource() == 1) {
Product product = productService.getOne(new QueryWrapper().eq(Product::getShopId, shopId).eq(Product::getId, shopStorageGoodDTO.getId()));
if (product == null) {
throw new ApiNotPrintException("商品不存在");
}
shopStorageGood.setName(product.getName());
shopStorageGood.setImgUrl(product.getCoverImg());
ShopProdUnit unit = shopProdUnitService.getOne(new QueryWrapper().eq(ShopProdUnit::getShopId, shopId).eq(ShopProdUnit::getId, product.getId()));
shopStorageGood.setUnit(unit == null ? "" : unit.getName());
}
shopStorageGood.setShopId(shopId);
return save(shopStorageGood);
}
}

View File

@ -0,0 +1,18 @@
package com.czg.service.product.service.impl;
import com.mybatisflex.spring.service.impl.ServiceImpl;
import com.czg.product.entity.ShopStorageRecord;
import com.czg.product.service.ShopStorageRecordService;
import com.czg.service.product.mapper.ShopStorageRecordMapper;
import org.springframework.stereotype.Service;
/**
* 存取酒记录表 服务层实现
*
* @author zs
* @since 2025-02-27
*/
@Service
public class ShopStorageRecordServiceImpl extends ServiceImpl<ShopStorageRecordMapper, ShopStorageRecord> implements ShopStorageRecordService{
}

View File

@ -0,0 +1,133 @@
package com.czg.service.product.service.impl;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.StrUtil;
import com.czg.account.entity.ShopUser;
import com.czg.account.service.ShopUserService;
import com.czg.exception.ApiNotPrintException;
import com.czg.product.dto.storage.CountStorageDTO;
import com.czg.product.dto.storage.ShopStorageAddDTO;
import com.czg.product.dto.storage.ShopStorageEditDTO;
import com.czg.product.entity.ShopStorageGood;
import com.czg.product.entity.ShopStorageRecord;
import com.czg.product.service.ShopStorageGoodService;
import com.czg.product.service.ShopStorageRecordService;
import com.czg.service.product.mapper.ShopStorageMapper;
import com.czg.utils.PageUtil;
import com.mybatisflex.core.paginate.Page;
import com.mybatisflex.core.query.QueryWrapper;
import com.mybatisflex.spring.service.impl.ServiceImpl;
import com.czg.product.entity.ShopStorage;
import com.czg.product.service.ShopStorageService;
import jakarta.annotation.Resource;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.stereotype.Service;
import java.util.List;
import static com.mybatisflex.core.query.QueryMethods.column;
/**
* 用户存酒 服务层实现
*
* @author zs
* @since 2025-02-27
*/
@Service
public class ShopStorageServiceImpl extends ServiceImpl<ShopStorageMapper, ShopStorage> implements ShopStorageService{
@DubboReference
private ShopUserService shopUserService;
@Resource
private ShopStorageGoodService shopStorageGoodService;
@Resource
private ShopStorageRecordService storageRecordService;
@Override
public Page<ShopStorage> pageInfo(Long shopId, String key, String phone, Integer status) {
QueryWrapper queryWrapper = new QueryWrapper().eq(ShopStorage::getShopId, shopId).eq(ShopStorage::getStatus, status);
if (StrUtil.isNotBlank(key)) {
queryWrapper.and(column(ShopStorage::getName).like(key).or(column(ShopStorage::getNickName).like(key)));
}
if (StrUtil.isNotBlank(phone)) {
queryWrapper.eq(ShopStorage::getPhone, phone);
}
queryWrapper.orderBy(ShopStorage::getId, false);
return page(PageUtil.buildPage(), queryWrapper);
}
@Override
public Boolean add(Long shopId, ShopStorageAddDTO shopStorageAddDTO) {
ShopUser shopUser = shopUserService.getOne(new QueryWrapper().eq(ShopUser::getUserId, shopStorageAddDTO.getUserId()).eq(ShopUser::getShopId, shopId));
if (shopUser == null) {
throw new ApiNotPrintException("店铺用户不存在");
}
ShopStorageGood shopStorageGood = shopStorageGoodService.getOne(new QueryWrapper().eq(ShopStorageGood::getShopId, shopId).eq(ShopStorageGood::getId, shopStorageAddDTO.getShopStorageGoodId()));
if (shopStorageGood == null) {
throw new ApiNotPrintException("存酒商品不存在");
}
ShopStorage shopStorage = new ShopStorage().setName(shopStorageGood.getName())
.setImgUrl(shopStorageGood.getImgUrl())
.setUnit(shopStorageGood.getUnit())
.setNum(shopStorageAddDTO.getNum())
.setSavTime(DateUtil.date().toLocalDateTime())
.setExpTime(DateUtil.offsetDay(DateUtil.date(), shopStorageAddDTO.getExpDay()).toLocalDateTime())
.setShopId(shopId)
.setUserId(shopStorageAddDTO.getUserId())
.setHeadImg(shopUser.getHeadImg())
.setNickName(shopUser.getNickName())
.setPhone(shopUser.getPhone());
boolean save = save(shopStorage);
if (save) {
ShopStorageRecord record = new ShopStorageRecord();
record.setStorageId(shopStorage.getId());
record.setTime(DateUtil.date().toLocalDateTime());
record.setContent("存入"+ shopStorage.getNum() + shopStorage.getUnit() + shopStorage.getName());
return storageRecordService.save(record);
}
throw new ApiNotPrintException("保存失败");
}
@Override
public Boolean edit(Long shopId, ShopStorageEditDTO shopStorageEditDTO) {
ShopStorage shopStorage = getOne(new QueryWrapper().eq(ShopStorage::getShopId, shopId).eq(ShopStorage::getId, shopStorageEditDTO.getId()));
if (shopStorage == null) {
throw new ApiNotPrintException("存酒记录不存在");
}
if (shopStorageEditDTO.getNum() < 0 && shopStorage.getNum() + shopStorageEditDTO.getNum() < 0) {
throw new ApiNotPrintException("可取酒数量不足");
}
shopStorage.setNum(shopStorage.getNum() + shopStorageEditDTO.getNum());
boolean b = updateById(shopStorage);
if (b) {
ShopStorageRecord record = new ShopStorageRecord();
record.setStorageId(shopStorage.getId());
record.setTime(DateUtil.date().toLocalDateTime());
record.setContent(((shopStorageEditDTO.getNum() > 0) ? "存入" : "取出") + Math.abs(shopStorageEditDTO.getNum()) + shopStorage.getUnit() + shopStorage.getName());
return storageRecordService.save(record);
}
return false;
}
@Override
public List<ShopStorageRecord> getRecord(Long shopId, Integer id) {
ShopStorage shopStorage = getOne(new QueryWrapper().eq(ShopStorage::getShopId, shopId).eq(ShopStorage::getId, id));
if (shopStorage == null) {
throw new ApiNotPrintException("存酒记录不存在");
}
return storageRecordService.list(new QueryWrapper().eq(ShopStorageRecord::getStorageId, id));
}
@Override
public List<CountStorageDTO> countRecord(Long shopId) {
return mapper.countRecord(shopId);
}
}

View File

@ -2,6 +2,6 @@
<!DOCTYPE mapper <!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd"> "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.czg.service.account.mapper.ShopStorageGoodMapper"> <mapper namespace="com.czg.service.product.mapper.ShopStorageGoodMapper">
</mapper> </mapper>

View File

@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.czg.service.product.mapper.ShopStorageMapper">
<select id="countRecord" resultType="com.czg.product.dto.storage.CountStorageDTO">
SELECT name,
img_url AS imgUrl,
SUM(CASE WHEN status = 1 THEN num ELSE 0 END) as savNum,
SUM(CASE WHEN status = 2 THEN num ELSE 0 END) as expNum
FROM tb_shop_storage
WHERE shop_id=#{shopId}
GROUP BY name
ORDER BY SUM(CASE WHEN status = 1 THEN num ELSE 0 END) desc
</select>
</mapper>

View File

@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.czg.service.product.mapper.ShopStorageRecordMapper">
</mapper>