商品列表中增加分类名称,销量为真实销量,商品出库bug更改:增加出库类型判定
This commit is contained in:
@@ -40,4 +40,8 @@ public interface TbShopCategoryRepository extends JpaRepository<TbShopCategory,
|
|||||||
|
|
||||||
@Query(" SELECT category FROM TbShopCategory category where category.shopId = :shopId")
|
@Query(" SELECT category FROM TbShopCategory category where category.shopId = :shopId")
|
||||||
Page<TbShopCategory> findAllBy(@Param("shopId") String shopId,Pageable pageable);
|
Page<TbShopCategory> findAllBy(@Param("shopId") String shopId,Pageable pageable);
|
||||||
|
|
||||||
|
|
||||||
|
@Query("SELECT category FROM TbShopCategory category where category.id IN :ids ")
|
||||||
|
List<TbShopCategory> searchCategory(@Param("ids")List<Integer> ids);
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,27 @@
|
|||||||
|
package cn.ysk.cashier.repository.shop;
|
||||||
|
|
||||||
|
import javax.persistence.Tuple;
|
||||||
|
import cn.ysk.cashier.pojo.TbShopUserDutyDetail;
|
||||||
|
import org.apache.ibatis.annotations.Param;
|
||||||
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
|
import org.springframework.data.jpa.repository.Query;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author lyf
|
||||||
|
*/
|
||||||
|
public interface TbShopUserDutyDetailRepository extends JpaRepository<TbShopUserDutyDetail,Integer> {
|
||||||
|
|
||||||
|
|
||||||
|
@Query(value = "SELECT " +
|
||||||
|
"sum( num ), " +
|
||||||
|
"product_id " +
|
||||||
|
"FROM " +
|
||||||
|
"tb_shop_user_duty_detail " +
|
||||||
|
"WHERE " +
|
||||||
|
"product_id IN :ids " +
|
||||||
|
"GROUP BY " +
|
||||||
|
"product_id",nativeQuery = true)
|
||||||
|
List<Object[]> searchUUserDutyDetail(@Param("ids") List<Integer> ids);
|
||||||
|
}
|
||||||
@@ -21,16 +21,11 @@ import cn.ysk.cashier.dto.product.TbProductDto;
|
|||||||
import cn.ysk.cashier.dto.product.TbProductQueryCriteria;
|
import cn.ysk.cashier.dto.product.TbProductQueryCriteria;
|
||||||
import cn.ysk.cashier.exception.BadRequestException;
|
import cn.ysk.cashier.exception.BadRequestException;
|
||||||
import cn.ysk.cashier.mapper.product.TbProductMapper;
|
import cn.ysk.cashier.mapper.product.TbProductMapper;
|
||||||
import cn.ysk.cashier.pojo.product.TbProduct;
|
import cn.ysk.cashier.pojo.product.*;
|
||||||
import cn.ysk.cashier.pojo.product.TbProductSku;
|
|
||||||
import cn.ysk.cashier.pojo.product.TbProductSkuResult;
|
|
||||||
import cn.ysk.cashier.pojo.product.TbProductSpec;
|
|
||||||
import cn.ysk.cashier.pojo.shop.TbShopUnit;
|
import cn.ysk.cashier.pojo.shop.TbShopUnit;
|
||||||
import cn.ysk.cashier.repository.product.TbProductRepository;
|
import cn.ysk.cashier.repository.product.*;
|
||||||
import cn.ysk.cashier.repository.product.TbProductSkuRepository;
|
|
||||||
import cn.ysk.cashier.repository.product.TbProductSkuResultRepository;
|
|
||||||
import cn.ysk.cashier.repository.product.TbProductSpecRepository;
|
|
||||||
import cn.ysk.cashier.repository.shop.TbShopUnitRepository;
|
import cn.ysk.cashier.repository.shop.TbShopUnitRepository;
|
||||||
|
import cn.ysk.cashier.repository.shop.TbShopUserDutyDetailRepository;
|
||||||
import cn.ysk.cashier.service.product.TbProductService;
|
import cn.ysk.cashier.service.product.TbProductService;
|
||||||
import cn.ysk.cashier.utils.*;
|
import cn.ysk.cashier.utils.*;
|
||||||
import cn.ysk.cashier.vo.TbProductVo;
|
import cn.ysk.cashier.vo.TbProductVo;
|
||||||
@@ -49,6 +44,7 @@ import org.springframework.util.StringUtils;
|
|||||||
|
|
||||||
import javax.servlet.http.HttpServletResponse;
|
import javax.servlet.http.HttpServletResponse;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.math.BigDecimal;
|
||||||
import java.time.Instant;
|
import java.time.Instant;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.concurrent.CompletableFuture;
|
import java.util.concurrent.CompletableFuture;
|
||||||
@@ -71,6 +67,8 @@ public class TbProductServiceImpl implements TbProductService {
|
|||||||
private final TbShopUnitRepository tbShopUnitRepository;
|
private final TbShopUnitRepository tbShopUnitRepository;
|
||||||
private final TbProductSpecRepository tbProductSpecRepository;
|
private final TbProductSpecRepository tbProductSpecRepository;
|
||||||
private final TbProductSkuResultRepository tbProductSkuResultRepository;
|
private final TbProductSkuResultRepository tbProductSkuResultRepository;
|
||||||
|
private final TbShopCategoryRepository tbShopCategoryRepository;
|
||||||
|
private final TbShopUserDutyDetailRepository tbShopUserDutyDetailRe;
|
||||||
|
|
||||||
private final RedisUtils redisUtils;
|
private final RedisUtils redisUtils;
|
||||||
|
|
||||||
@@ -84,9 +82,12 @@ public class TbProductServiceImpl implements TbProductService {
|
|||||||
List<String> productId = new ArrayList<>();
|
List<String> productId = new ArrayList<>();
|
||||||
List<Integer> unitId = new ArrayList<>();
|
List<Integer> unitId = new ArrayList<>();
|
||||||
List<Integer> specId = new ArrayList<>();
|
List<Integer> specId = new ArrayList<>();
|
||||||
|
List<String> categoryId = new ArrayList<>();
|
||||||
|
List<Integer> productIdInt = new ArrayList<>();
|
||||||
for (TbProduct product : page.getContent()) {
|
for (TbProduct product : page.getContent()) {
|
||||||
//记录商品id
|
//记录商品id
|
||||||
productId.add(product.getId().toString());
|
productId.add(product.getId().toString());
|
||||||
|
productIdInt.add(product.getId());
|
||||||
//记录单位id
|
//记录单位id
|
||||||
if (product.getUnitId() != null) {
|
if (product.getUnitId() != null) {
|
||||||
if (!"".equals(product.getUnitId())) {
|
if (!"".equals(product.getUnitId())) {
|
||||||
@@ -95,6 +96,8 @@ public class TbProductServiceImpl implements TbProductService {
|
|||||||
}
|
}
|
||||||
//记录规格id
|
//记录规格id
|
||||||
specId.add(product.getSpecId());
|
specId.add(product.getSpecId());
|
||||||
|
//记录分类id
|
||||||
|
categoryId.add(product.getCategoryId());
|
||||||
}
|
}
|
||||||
//sku
|
//sku
|
||||||
List<TbProductSku> tbProductSkus = tbProductSkuRepository.searchSku(productId);
|
List<TbProductSku> tbProductSkus = tbProductSkuRepository.searchSku(productId);
|
||||||
@@ -108,23 +111,31 @@ public class TbProductServiceImpl implements TbProductService {
|
|||||||
if (!specId.isEmpty()) {
|
if (!specId.isEmpty()) {
|
||||||
tbProductSpecs = tbProductSpecRepository.searchSpec(specId);
|
tbProductSpecs = tbProductSpecRepository.searchSpec(specId);
|
||||||
}
|
}
|
||||||
|
//分类
|
||||||
|
List<TbShopCategory> tbShopCategory = new ArrayList<>();
|
||||||
|
if (!categoryId.isEmpty()){
|
||||||
|
List<Integer> categoryIdInt = ListUtil.stringChangeIntegerList(categoryId);
|
||||||
|
tbShopCategory = tbShopCategoryRepository.searchCategory(categoryIdInt);
|
||||||
|
}
|
||||||
|
//销量
|
||||||
|
List<Object[]> objects = new ArrayList<>();
|
||||||
|
if (!productIdInt.isEmpty()){
|
||||||
|
objects = tbShopUserDutyDetailRe.searchUUserDutyDetail(productIdInt);
|
||||||
|
}
|
||||||
//组装
|
//组装
|
||||||
List<TbProductVo> tbProductVoList = new ArrayList<>();
|
List<TbProductVo> tbProductVoList = new ArrayList<>();
|
||||||
for (TbProduct product : page.getContent()) {
|
for (TbProduct product : page.getContent()) {
|
||||||
List<TbProductSku> skuList = new ArrayList<>();
|
List<TbProductSku> skuList = new ArrayList<>();
|
||||||
TbProductVo tbProductVo = new TbProductVo();
|
TbProductVo tbProductVo = new TbProductVo();
|
||||||
//sku,并且计算销量以及库存
|
//sku,并且计算销量以及库存
|
||||||
Double realSalesNumber = 0.00;
|
|
||||||
Double stockNumber = 0.00;
|
Double stockNumber = 0.00;
|
||||||
for (TbProductSku sku : tbProductSkus) {
|
for (TbProductSku sku : tbProductSkus) {
|
||||||
//sku
|
//sku
|
||||||
if (sku.getProductId().equals(product.getId().toString())) {
|
if (sku.getProductId().equals(product.getId().toString())) {
|
||||||
skuList.add(sku);
|
skuList.add(sku);
|
||||||
realSalesNumber = realSalesNumber + (sku.getRealSalesNumber()==null?0:sku.getRealSalesNumber());
|
|
||||||
stockNumber = stockNumber + sku.getStockNumber();
|
stockNumber = stockNumber + sku.getStockNumber();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
tbProductVo.setRealSalesNumber(realSalesNumber);
|
|
||||||
tbProductVo.setStockNumber(stockNumber);
|
tbProductVo.setStockNumber(stockNumber);
|
||||||
tbProductVo.setSkuList(skuList);
|
tbProductVo.setSkuList(skuList);
|
||||||
//单位
|
//单位
|
||||||
@@ -149,7 +160,27 @@ public class TbProductServiceImpl implements TbProductService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
//分类
|
||||||
|
if (tbShopCategory.isEmpty()){
|
||||||
|
tbProductVo.setCategoryName("");
|
||||||
|
}else {
|
||||||
|
for (TbShopCategory shopCategory :tbShopCategory) {
|
||||||
|
if (shopCategory.getId().toString().equals(product.getCategoryId())){
|
||||||
|
tbProductVo.setCategoryName(shopCategory.getName());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//销量
|
||||||
|
if (objects.isEmpty()){
|
||||||
|
tbProductVo.setRealSalesNumber(0.00);
|
||||||
|
}else {
|
||||||
|
for (Object[] o :objects) {
|
||||||
|
if (((Integer) o[1]).equals(product.getId())){
|
||||||
|
BigDecimal bigDecimal = (BigDecimal) o[0];
|
||||||
|
tbProductVo.setRealSalesNumber(bigDecimal.doubleValue());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
BeanUtils.copyProperties(product, tbProductVo);
|
BeanUtils.copyProperties(product, tbProductVo);
|
||||||
tbProductVoList.add(tbProductVo);
|
tbProductVoList.add(tbProductVo);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -233,6 +233,10 @@ public class TbProductStockOperateServiceImpl implements TbProductStockOperateSe
|
|||||||
productStockDetail.setStockNumber((double) productListDto.getNumber());
|
productStockDetail.setStockNumber((double) productListDto.getNumber());
|
||||||
productStockDetail.setSubType(1);
|
productStockDetail.setSubType(1);
|
||||||
break;
|
break;
|
||||||
|
case "other-out":
|
||||||
|
productStockDetail.setStockNumber((double) -productListDto.getNumber());
|
||||||
|
productStockDetail.setSubType(-1);
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,14 @@
|
|||||||
|
package cn.ysk.cashier.vo;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author 12847
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
public class SalesNumberVO {
|
||||||
|
private Integer productId;
|
||||||
|
private BigDecimal salesNumber;
|
||||||
|
}
|
||||||
@@ -42,12 +42,12 @@ public class TbProductVo {
|
|||||||
|
|
||||||
private Integer unitId;
|
private Integer unitId;
|
||||||
|
|
||||||
|
|
||||||
private String coverImg;
|
private String coverImg;
|
||||||
|
|
||||||
@NotNull(message ="缺少商品类信息")
|
@NotNull(message ="缺少商品类信息")
|
||||||
private String categoryId;
|
private String categoryId;
|
||||||
|
|
||||||
|
private String categoryName;
|
||||||
|
|
||||||
private Integer specId;
|
private Integer specId;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user