Browse Source

新增查询库存接口

cangku
chencheng 3 years ago
parent
commit
9d2636bf00
  1. 4
      hiver-modules/hiver-base/src/main/java/cc/hiver/base/controller/manage/UserController.java
  2. 41
      hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/controller/StockController.java
  3. 6
      hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/service/ShopUserService.java
  4. 25
      hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/serviceimpl/mybatis/StockServiceImpl.java

4
hiver-modules/hiver-base/src/main/java/cc/hiver/base/controller/manage/UserController.java

@ -17,7 +17,6 @@ import cc.hiver.core.service.*;
import cc.hiver.core.service.mybatis.IUserRoleService; import cc.hiver.core.service.mybatis.IUserRoleService;
import cc.hiver.core.vo.RoleDTO; import cc.hiver.core.vo.RoleDTO;
import cc.hiver.mall.entity.ShopUser; import cc.hiver.mall.entity.ShopUser;
import cc.hiver.mall.service.ShopService;
import cc.hiver.mall.service.ShopUserService; import cc.hiver.mall.service.ShopUserService;
import cn.hutool.core.util.StrUtil; import cn.hutool.core.util.StrUtil;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
@ -86,9 +85,6 @@ public class UserController {
@Autowired @Autowired
private SecurityUtil securityUtil; private SecurityUtil securityUtil;
@Autowired
private ShopService shopService;
@Autowired @Autowired
private ShopUserService shopUserService; private ShopUserService shopUserService;

41
hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/controller/StockController.java

@ -1,20 +1,23 @@
package cc.hiver.mall.controller; package cc.hiver.mall.controller;
import cc.hiver.core.common.utils.ResultUtil;
import cc.hiver.core.common.vo.Result; import cc.hiver.core.common.vo.Result;
import cc.hiver.mall.entity.Stock;
import cc.hiver.mall.pojo.vo.PurchaseVo; import cc.hiver.mall.pojo.vo.PurchaseVo;
import cc.hiver.mall.service.mybatis.PurchaseDetailService;
import cc.hiver.mall.service.mybatis.PurchaseService;
import cc.hiver.mall.service.mybatis.StockLogService;
import cc.hiver.mall.service.mybatis.StockService; import cc.hiver.mall.service.mybatis.StockService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
import java.util.List;
@Slf4j @Slf4j
@RestController @RestController
@Api(tags = "库存接口") @Api(tags = "库存接口")
@ -22,22 +25,34 @@ import org.springframework.web.bind.annotation.RestController;
@Transactional @Transactional
public class StockController { public class StockController {
@Autowired
private PurchaseService purchaseService;
@Autowired
private PurchaseDetailService purchaseDetailService;
@Autowired @Autowired
private StockService stockService; private StockService stockService;
@Autowired
private StockLogService stockLogService;
@RequestMapping(value = "/putIn", method = RequestMethod.POST) @RequestMapping(value = "/putIn", method = RequestMethod.POST)
@ApiOperation(value = "入库") @ApiOperation(value = "入库")
public Result putIn(PurchaseVo purchaseVo) { public Result putIn(@RequestBody PurchaseVo purchaseVo) {
return stockService.putIn(purchaseVo); return stockService.putIn(purchaseVo);
} }
@RequestMapping(value = "/getStockInfoByCondition", method = RequestMethod.GET)
@ApiOperation(value = "根据店铺信息获取库存信息")
public Result<List<Stock>> getStockInfoByCondition(Stock stock) {
QueryWrapper<Stock> queryWrapper = new QueryWrapper<>();
if(stock.getShopId()!= null){
queryWrapper.eq("shop_id",stock.getShopId());
}
if(stock.getProductName()!= null){
queryWrapper.eq("product_name",stock.getProductName());
}
if(stock.getProductName()!= null){
queryWrapper.eq("barcode",stock.getBarcode());
}
List<Stock> list = stockService.list(queryWrapper);
return new ResultUtil<List<Stock>>().setData(list);
}
} }

6
hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/service/ShopUserService.java

@ -2,10 +2,10 @@ package cc.hiver.mall.service;
import cc.hiver.core.base.HiverBaseService; import cc.hiver.core.base.HiverBaseService;
import cc.hiver.mall.entity.ShopUser; import cc.hiver.mall.entity.ShopUser;
import org.springframework.stereotype.Service;
@Service
public interface public interface ShopUserService extends HiverBaseService<ShopUser, String> {
ShopUserService extends HiverBaseService<ShopUser, String> {
void deleteAllByShopId(String shopId); void deleteAllByShopId(String shopId);
ShopUser selectByUserIdAndShopId(String userId,String shopId); ShopUser selectByUserIdAndShopId(String userId,String shopId);

25
hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/serviceimpl/mybatis/StockServiceImpl.java

@ -34,25 +34,45 @@ public class StockServiceImpl extends ServiceImpl<StockMapper, Stock> implements
@Autowired @Autowired
private StockLogService stockLogService; private StockLogService stockLogService;
@Autowired
private ProductService productService;
@Transactional @Transactional
@Override @Override
public Result putIn(PurchaseVo purchaseVo) { public Result putIn(PurchaseVo purchaseVo) {
Boolean result = false; Boolean result = false;
//1.判断入库的货品是否有库存,有则修改库存数量,没有则新建库存数据 //1.判断入库的货品是否有库存,有则修改库存数量,没有则新建库存数据
Purchase purchase = purchaseVo.getPurchase(); Purchase purchase = purchaseVo.getPurchase();
Product product;
List<PurchaseDetail> purchaseDetailList = purchaseVo.getPurchaseDetails(); List<PurchaseDetail> purchaseDetailList = purchaseVo.getPurchaseDetails();
List<PurchaseDetail> purchaseDetailList2 = new ArrayList<PurchaseDetail>();
for (PurchaseDetail purchaseDetail:purchaseDetailList){ for (PurchaseDetail purchaseDetail:purchaseDetailList){
String productId = purchaseDetail.getProductId(); String productId = purchaseDetail.getProductId();
product =productService.getById(productId);
String attributeList = purchaseDetail.getAttributeList(); String attributeList = purchaseDetail.getAttributeList();
QueryWrapper<Stock> stockQueryWrapper = new QueryWrapper<>(); QueryWrapper<Stock> stockQueryWrapper = new QueryWrapper<>();
stockQueryWrapper.eq("product_id",productId); stockQueryWrapper.eq("product_id",productId);
stockQueryWrapper.eq("attribute_list",attributeList); stockQueryWrapper.eq("attribute_list",attributeList);
List<Stock> originList = this.list(stockQueryWrapper); List<Stock> originList = this.list(stockQueryWrapper);
Integer stockCount = 0; Integer stockCount = 0;
purchaseDetail.setProductName(product.getProductName());
purchaseDetail.setUnit(product.getUnit());
purchaseDetail.setShopId(purchase.getShopId());
purchaseDetail.setCategoryId(product.getCategoryId());
purchaseDetail.setSupplierId(product.getSupplierId());
purchaseDetail.setProductSn(product.getProductSn());
purchaseDetail.setBarcode(product.getBarcode());
purchaseDetail.setProductVideo(product.getProductVideo());
purchaseDetail.setProductIntro(product.getProductIntro());
purchaseDetail.setSalesWeek(product.getSalesWeek());
purchaseDetail.setPrintBarcode(product.getPrintBarcode());
purchaseDetailList2.add(purchaseDetail);
if(originList.size() > 0){ if(originList.size() > 0){
//存在库存则修改库存数量 //存在库存则修改库存数量
Stock origin = originList.get(0); Stock origin = originList.get(0);
stockCount = origin.getStockCount(); stockCount = origin.getStockCount()!=null?origin.getStockCount():0;
UpdateWrapper<Stock> updateWrapper = new UpdateWrapper<>(); UpdateWrapper<Stock> updateWrapper = new UpdateWrapper<>();
updateWrapper.eq("id",origin.getId()); updateWrapper.eq("id",origin.getId());
updateWrapper.set("stock_count",stockCount + purchaseDetail.getProductCount()); updateWrapper.set("stock_count",stockCount + purchaseDetail.getProductCount());
@ -61,7 +81,6 @@ public class StockServiceImpl extends ServiceImpl<StockMapper, Stock> implements
//没有则新建库存数据 //没有则新建库存数据
Stock stock = new Stock(); Stock stock = new Stock();
BeanUtils.copyBeanProp(stock,purchaseDetail); BeanUtils.copyBeanProp(stock,purchaseDetail);
stock.setStockCount(purchaseDetail.getProductCount());
save(stock); save(stock);
} }
@ -81,7 +100,7 @@ public class StockServiceImpl extends ServiceImpl<StockMapper, Stock> implements
//3.登记采购单主表和采购单明细表 //3.登记采购单主表和采购单明细表
if(purchaseService.save(purchase)){ if(purchaseService.save(purchase)){
result = purchaseDetailService.saveBatch(purchaseDetailList); result = purchaseDetailService.saveBatch(purchaseDetailList2);
}; };
if(result) { if(result) {

Loading…
Cancel
Save