商品列表中增加分类名称,销量为真实销量,商品出库bug更改:增加出库类型判定
This commit is contained in:
parent
ca2bcdf4a0
commit
5e4b1859f5
|
|
@ -40,4 +40,8 @@ public interface TbShopCategoryRepository extends JpaRepository<TbShopCategory,
|
|||
|
||||
@Query(" SELECT category FROM TbShopCategory category where category.shopId = :shopId")
|
||||
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.exception.BadRequestException;
|
||||
import cn.ysk.cashier.mapper.product.TbProductMapper;
|
||||
import cn.ysk.cashier.pojo.product.TbProduct;
|
||||
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.product.*;
|
||||
import cn.ysk.cashier.pojo.shop.TbShopUnit;
|
||||
import cn.ysk.cashier.repository.product.TbProductRepository;
|
||||
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.product.*;
|
||||
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.utils.*;
|
||||
import cn.ysk.cashier.vo.TbProductVo;
|
||||
|
|
@ -49,6 +44,7 @@ import org.springframework.util.StringUtils;
|
|||
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.IOException;
|
||||
import java.math.BigDecimal;
|
||||
import java.time.Instant;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
|
@ -71,6 +67,8 @@ public class TbProductServiceImpl implements TbProductService {
|
|||
private final TbShopUnitRepository tbShopUnitRepository;
|
||||
private final TbProductSpecRepository tbProductSpecRepository;
|
||||
private final TbProductSkuResultRepository tbProductSkuResultRepository;
|
||||
private final TbShopCategoryRepository tbShopCategoryRepository;
|
||||
private final TbShopUserDutyDetailRepository tbShopUserDutyDetailRe;
|
||||
|
||||
private final RedisUtils redisUtils;
|
||||
|
||||
|
|
@ -84,9 +82,12 @@ public class TbProductServiceImpl implements TbProductService {
|
|||
List<String> productId = new ArrayList<>();
|
||||
List<Integer> unitId = new ArrayList<>();
|
||||
List<Integer> specId = new ArrayList<>();
|
||||
List<String> categoryId = new ArrayList<>();
|
||||
List<Integer> productIdInt = new ArrayList<>();
|
||||
for (TbProduct product : page.getContent()) {
|
||||
//记录商品id
|
||||
productId.add(product.getId().toString());
|
||||
productIdInt.add(product.getId());
|
||||
//记录单位id
|
||||
if (product.getUnitId() != null) {
|
||||
if (!"".equals(product.getUnitId())) {
|
||||
|
|
@ -95,6 +96,8 @@ public class TbProductServiceImpl implements TbProductService {
|
|||
}
|
||||
//记录规格id
|
||||
specId.add(product.getSpecId());
|
||||
//记录分类id
|
||||
categoryId.add(product.getCategoryId());
|
||||
}
|
||||
//sku
|
||||
List<TbProductSku> tbProductSkus = tbProductSkuRepository.searchSku(productId);
|
||||
|
|
@ -108,23 +111,31 @@ public class TbProductServiceImpl implements TbProductService {
|
|||
if (!specId.isEmpty()) {
|
||||
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<>();
|
||||
for (TbProduct product : page.getContent()) {
|
||||
List<TbProductSku> skuList = new ArrayList<>();
|
||||
TbProductVo tbProductVo = new TbProductVo();
|
||||
//sku,并且计算销量以及库存
|
||||
Double realSalesNumber = 0.00;
|
||||
Double stockNumber = 0.00;
|
||||
for (TbProductSku sku : tbProductSkus) {
|
||||
//sku
|
||||
if (sku.getProductId().equals(product.getId().toString())) {
|
||||
skuList.add(sku);
|
||||
realSalesNumber = realSalesNumber + (sku.getRealSalesNumber()==null?0:sku.getRealSalesNumber());
|
||||
stockNumber = stockNumber + sku.getStockNumber();
|
||||
}
|
||||
}
|
||||
tbProductVo.setRealSalesNumber(realSalesNumber);
|
||||
tbProductVo.setStockNumber(stockNumber);
|
||||
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);
|
||||
tbProductVoList.add(tbProductVo);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -233,6 +233,10 @@ public class TbProductStockOperateServiceImpl implements TbProductStockOperateSe
|
|||
productStockDetail.setStockNumber((double) productListDto.getNumber());
|
||||
productStockDetail.setSubType(1);
|
||||
break;
|
||||
case "other-out":
|
||||
productStockDetail.setStockNumber((double) -productListDto.getNumber());
|
||||
productStockDetail.setSubType(-1);
|
||||
break;
|
||||
default:
|
||||
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 String coverImg;
|
||||
|
||||
@NotNull(message ="缺少商品类信息")
|
||||
private String categoryId;
|
||||
|
||||
private String categoryName;
|
||||
|
||||
private Integer specId;
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue