存酒接口
This commit is contained in:
@@ -130,6 +130,8 @@ public class ShopInfoServiceImpl extends ServiceImpl<ShopInfoMapper, ShopInfo> i
|
||||
if (!StpKit.USER.isAdmin() && !Objects.equals(StpKit.USER.getShopId(), shopInfo.getId())) {
|
||||
throw new ApiNotPrintException("店铺信息不存在");
|
||||
}
|
||||
|
||||
SysUser sysUser = sysUserService.getById(shopInfo.getId());
|
||||
return shopInfo;
|
||||
}
|
||||
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
package com.czg.service.account.mapper;
|
||||
package com.czg.service.product.mapper;
|
||||
|
||||
import com.mybatisflex.core.BaseMapper;
|
||||
import com.czg.account.entity.ShopStorageGood;
|
||||
import com.czg.product.entity.ShopStorageGood;
|
||||
|
||||
/**
|
||||
* 酒品表 映射层。
|
||||
@@ -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);
|
||||
}
|
||||
@@ -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> {
|
||||
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -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{
|
||||
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -2,6 +2,6 @@
|
||||
<!DOCTYPE mapper
|
||||
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
"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>
|
||||
@@ -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>
|
||||
@@ -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>
|
||||
Reference in New Issue
Block a user