商品库存

This commit is contained in:
seesaw
2024-11-04 11:05:37 +08:00
parent 8a65561970
commit 575f163e36
6 changed files with 75 additions and 10 deletions

View File

@ -130,6 +130,8 @@ public interface ErrorCodeConstants {
ErrorCode STORE_GOODS_INVENTORY_NOT_EXISTS = new ErrorCode(1_004_019_001, "商品库存不存在"); ErrorCode STORE_GOODS_INVENTORY_NOT_EXISTS = new ErrorCode(1_004_019_001, "商品库存不存在");
ErrorCode STORE_GOODS_INVENTORY_NOT_ENOUGH = new ErrorCode(1_004_019_001, "商品库存不足");
ErrorCode STORE_GOODS_INVENTORY_RECORD_NOT_EXISTS = new ErrorCode(1_004_020_001, "商品出入库记录不存在"); ErrorCode STORE_GOODS_INVENTORY_RECORD_NOT_EXISTS = new ErrorCode(1_004_020_001, "商品出入库记录不存在");
} }

View File

@ -39,7 +39,7 @@ public class StoreGoodsInventoryController {
private StoreGoodsInventoryService storeGoodsInventoryService; private StoreGoodsInventoryService storeGoodsInventoryService;
@PostMapping("/create") @PostMapping("/create")
@Operation(summary = "创建商品库存") @Operation(summary = "出入库")
@PreAuthorize("@ss.hasPermission('member:store-goods-inventory:create')") @PreAuthorize("@ss.hasPermission('member:store-goods-inventory:create')")
public CommonResult<Integer> createStoreGoodsInventory(@Valid @RequestBody StoreGoodsInventorySaveReqVO createReqVO) { public CommonResult<Integer> createStoreGoodsInventory(@Valid @RequestBody StoreGoodsInventorySaveReqVO createReqVO) {
return success(storeGoodsInventoryService.createStoreGoodsInventory(createReqVO)); return success(storeGoodsInventoryService.createStoreGoodsInventory(createReqVO));

View File

@ -24,4 +24,10 @@ public class StoreGoodsInventorySaveReqVO {
@Schema(description = "重量") @Schema(description = "重量")
private Double weight; private Double weight;
@Schema(description = "1-入库,2-出库")
private Integer type;
@Schema(description = "出库类型")
private Integer outType;
} }

View File

@ -0,0 +1,27 @@
package cn.iocoder.yudao.module.member.enums;
import lombok.AllArgsConstructor;
import lombok.Getter;
/**
* 代码生成的场景枚举
*
* @author 芋道源码
*/
@AllArgsConstructor
@Getter
public enum InventoryTypeEnum {
IN(1, "入库"),
OUT(2, "出库"),
;
/**
* 编码
*/
private final Integer code;
/**
* 类型
*/
private final String name;
}

View File

@ -1,5 +1,8 @@
package cn.iocoder.yudao.module.member.service.storegoodsinventory; package cn.iocoder.yudao.module.member.service.storegoodsinventory;
import cn.hutool.core.collection.CollectionUtil;
import cn.iocoder.yudao.module.member.enums.InventoryTypeEnum;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import javax.annotation.Resource; import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated; import org.springframework.validation.annotation.Validated;
@ -30,12 +33,38 @@ public class StoreGoodsInventoryServiceImpl implements StoreGoodsInventoryServic
private StoreGoodsInventoryMapper storeGoodsInventoryMapper; private StoreGoodsInventoryMapper storeGoodsInventoryMapper;
@Override @Override
public Integer createStoreGoodsInventory(StoreGoodsInventorySaveReqVO createReqVO) { public synchronized Integer createStoreGoodsInventory(StoreGoodsInventorySaveReqVO createReqVO) {
// 插入 Integer id = null;
StoreGoodsInventoryDO storeGoodsInventory = BeanUtils.toBean(createReqVO, StoreGoodsInventoryDO.class); // 入库
storeGoodsInventoryMapper.insert(storeGoodsInventory); LambdaQueryWrapper<StoreGoodsInventoryDO> wrapper = new LambdaQueryWrapper<>();
wrapper.eq(StoreGoodsInventoryDO::getGoodsId,createReqVO.getGoodsId())
.eq(StoreGoodsInventoryDO::getCarteenId,createReqVO.getCarteenId());
List<StoreGoodsInventoryDO> storeGoodsInventoryDOS = storeGoodsInventoryMapper.selectList(wrapper);
if(InventoryTypeEnum.IN.getCode().equals(createReqVO.getType())){
if(CollectionUtil.isNotEmpty(storeGoodsInventoryDOS)){
StoreGoodsInventoryDO storeGoodsInventoryDO = storeGoodsInventoryDOS.get(0);
storeGoodsInventoryDO.setNumber(storeGoodsInventoryDO.getNumber()+createReqVO.getNumber());
storeGoodsInventoryMapper.updateById(storeGoodsInventoryDO);
id= storeGoodsInventoryDO.getId();
}else {
StoreGoodsInventoryDO storeGoodsInventory = BeanUtils.toBean(createReqVO, StoreGoodsInventoryDO.class);
storeGoodsInventoryMapper.insert(storeGoodsInventory);
id = storeGoodsInventory.getId();
}
}else {// 出库
if(CollectionUtil.isEmpty(storeGoodsInventoryDOS)){
throw exception(STORE_GOODS_INVENTORY_NOT_EXISTS);
}
StoreGoodsInventoryDO storeGoodsInventoryDO = storeGoodsInventoryDOS.get(0);
if(storeGoodsInventoryDO.getNumber()<createReqVO.getNumber()){
throw exception(STORE_GOODS_INVENTORY_NOT_ENOUGH);
}
storeGoodsInventoryDO.setNumber(storeGoodsInventoryDO.getNumber()-createReqVO.getNumber());
storeGoodsInventoryMapper.updateById(storeGoodsInventoryDO);
id = storeGoodsInventoryDO.getId();
}
// 返回 // 返回
return storeGoodsInventory.getId(); return id;
} }
@Override @Override

View File

@ -204,12 +204,13 @@ public class StoreOrderServiceImpl implements StoreOrderService {
.mapToDouble(StoreGoodsDto::getTotalPrice) .mapToDouble(StoreGoodsDto::getTotalPrice)
.sum(); .sum();
BigDecimal totalMoney = BigDecimal.valueOf(sum); BigDecimal totalMoney = BigDecimal.valueOf(sum);
BigDecimal amount = amountService.getAmount(dto.getUserId()); // BigDecimal amount = amountService.getAmount(dto.getUserId());
if(amount.compareTo(totalMoney) < 0){
return "金额不足";
}
MemberUserDO user = userService.getUser(Long.valueOf(s)); MemberUserDO user = userService.getUser(Long.valueOf(s));
dto.setUserId(user.getId()); dto.setUserId(user.getId());
if(user.getMoney().compareTo(totalMoney) < 0){
return "金额不足";
}
StoreOrderDO order = createOrder(dto,StoreOrderStatusEnum.COMPLETE.getCode()); StoreOrderDO order = createOrder(dto,StoreOrderStatusEnum.COMPLETE.getCode());
Double totalPrice = order.getTotalPrice(); Double totalPrice = order.getTotalPrice();
BigDecimal total = BigDecimal.valueOf(totalPrice).setScale(2, RoundingMode.HALF_UP); BigDecimal total = BigDecimal.valueOf(totalPrice).setScale(2, RoundingMode.HALF_UP);