日售出销量统计 前一天的
This commit is contained in:
parent
a23ab97ebf
commit
bb6226efab
|
|
@ -35,6 +35,7 @@ public class DateUtil {
|
|||
public static final DateTimeFormatter DFY_MD = DateTimeFormatter.ofPattern("yyyy-MM-dd");
|
||||
|
||||
private final static SimpleDateFormat sdfTime = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
||||
private final static SimpleDateFormat ymdTime = new SimpleDateFormat("yyyy-MM-dd");
|
||||
|
||||
/**
|
||||
* LocalDateTime 转时间戳
|
||||
|
|
@ -50,6 +51,10 @@ public class DateUtil {
|
|||
return sdfTime.format(date);
|
||||
}
|
||||
|
||||
public static String getYMDTime(Date date) {
|
||||
return ymdTime.format(date);
|
||||
}
|
||||
|
||||
/**
|
||||
* 将Date对象转换为时间戳(毫秒)
|
||||
* @param date 要转换的Date对象
|
||||
|
|
@ -313,6 +318,22 @@ public class DateUtil {
|
|||
return getDayEndTime(cal.getTime());
|
||||
}
|
||||
|
||||
public static Date getBeginDayOfYesterday() {
|
||||
Calendar cal = new GregorianCalendar();
|
||||
cal.setTime(getDayBegin());
|
||||
cal.add(Calendar.DAY_OF_MONTH, -1);
|
||||
|
||||
return cal.getTime();
|
||||
}
|
||||
|
||||
// 获取明天的结束时间
|
||||
public static Date getEndDayOfYesterday() {
|
||||
Calendar cal = new GregorianCalendar();
|
||||
cal.setTime(getDayEnd());
|
||||
cal.add(Calendar.DAY_OF_MONTH, -1);
|
||||
return cal.getTime();
|
||||
}
|
||||
|
||||
// 获取明天的开始时间
|
||||
public static Date getBeginDayOfTomorrow() {
|
||||
Calendar cal = new GregorianCalendar();
|
||||
|
|
|
|||
|
|
@ -0,0 +1,19 @@
|
|||
package cn.ysk.cashier.dto.product;
|
||||
|
||||
import lombok.Data;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.Id;
|
||||
|
||||
@Data
|
||||
@Entity
|
||||
public class StockCountDTO {
|
||||
private String shopId;
|
||||
@Id
|
||||
private Long proId;
|
||||
private String proName;
|
||||
private Integer isStock;
|
||||
private String skuName;
|
||||
private String unitName;
|
||||
private Integer stockCount;
|
||||
private Integer stockNumber;
|
||||
}
|
||||
|
|
@ -1,18 +1,3 @@
|
|||
/*
|
||||
* Copyright 2019-2020 Zheng Jie
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package cn.ysk.cashier.quartz.rest;
|
||||
|
||||
import io.swagger.annotations.Api;
|
||||
|
|
|
|||
|
|
@ -1,19 +1,23 @@
|
|||
package cn.ysk.cashier.quartz.task;
|
||||
|
||||
import cn.ysk.cashier.dto.product.StockCountDTO;
|
||||
import cn.ysk.cashier.pojo.order.TbCashierCart;
|
||||
import cn.ysk.cashier.pojo.product.TbProductStockDetail;
|
||||
import cn.ysk.cashier.repository.order.StockCountRepository;
|
||||
import cn.ysk.cashier.repository.order.TbCashierCartRepository;
|
||||
import cn.ysk.cashier.repository.product.TbProductSkuRepository;
|
||||
import cn.ysk.cashier.service.order.TbCashierCartService;
|
||||
import cn.ysk.cashier.service.shop.TbShopStorageService;
|
||||
import cn.ysk.cashier.utils.CacheKey;
|
||||
import cn.ysk.cashier.utils.DateUtil;
|
||||
import cn.ysk.cashier.utils.QueryHelp;
|
||||
import cn.ysk.cashier.utils.RedisUtils;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.scheduling.annotation.Scheduled;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import javax.persistence.EntityManager;
|
||||
import javax.persistence.criteria.Predicate;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
|
|
@ -32,12 +36,15 @@ public class TestTask {
|
|||
private TbShopStorageService storageService;
|
||||
@Autowired
|
||||
private TbCashierCartRepository cartService;
|
||||
@Autowired
|
||||
private StockCountRepository stockCountRepository;
|
||||
|
||||
@Autowired
|
||||
private TbProductSkuRepository skuRepository;
|
||||
@Autowired
|
||||
private RedisUtils redisUtils;
|
||||
|
||||
@Autowired
|
||||
private EntityManager entityManager;
|
||||
private final TbCashierCartService tbCashierCartService;
|
||||
|
||||
public TestTask(TbCashierCartService tbCashierCartService) {
|
||||
|
|
@ -87,4 +94,32 @@ public class TestTask {
|
|||
redisUtils.del(keysArray);
|
||||
log.info("购物车清楚记录开始结束");
|
||||
}
|
||||
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void countStock(){
|
||||
log.info("记录当日库存损耗开始");
|
||||
List<StockCountDTO> stockCountDTOS = stockCountRepository.countStock(DateUtil.getStrTime(DateUtil.getBeginDayOfYesterday()), DateUtil.getStrTime(DateUtil.getEndDayOfYesterday()));
|
||||
System.out.println(stockCountDTOS);
|
||||
stockCountDTOS.forEach(s->{
|
||||
TbProductStockDetail productStockDetail = new TbProductStockDetail();
|
||||
productStockDetail.setCreatedAt(System.currentTimeMillis());
|
||||
productStockDetail.setUpdatedAt(System.currentTimeMillis());
|
||||
productStockDetail.setShopId(s.getShopId().toString());
|
||||
productStockDetail.setProductId(s.getProId().toString());
|
||||
productStockDetail.setProductName(s.getProName());
|
||||
// productStockDetail.setSkuId(s.getSkuId().toString());
|
||||
productStockDetail.setIsStock(s.getIsStock());//是否开启库存
|
||||
productStockDetail.setLeftNumber(s.getStockNumber()+s.getStockCount());//原库存
|
||||
// productStockDetail.setSpecSnap(s.getSkuName());
|
||||
productStockDetail.setUnitName(s.getUnitName());
|
||||
productStockDetail.setStockNumber(-Double.valueOf(s.getStockCount()));
|
||||
productStockDetail.setSourcePath("NORMAL");
|
||||
productStockDetail.setType("other-out");
|
||||
productStockDetail.setRemark(DateUtil.getYMDTime(DateUtil.getBeginDayOfYesterday())+"日统计库存");
|
||||
productStockDetail.setSubType(-1);
|
||||
productStockDetail.setType(DateUtil.getYMDTime(DateUtil.getBeginDayOfYesterday())+"日售出记录");
|
||||
entityManager.persist(productStockDetail);
|
||||
});
|
||||
log.info("记录当日库存损耗结束");
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,35 @@
|
|||
package cn.ysk.cashier.repository.order;
|
||||
|
||||
import cn.ysk.cashier.dto.product.StockCountDTO;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.data.jpa.repository.Query;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @website https://eladmin.vip
|
||||
* @author lyf
|
||||
* @date 2024-03-02
|
||||
**/
|
||||
public interface StockCountRepository extends JpaRepository<StockCountDTO, Integer> {
|
||||
|
||||
@Query(value = "SELECT pro.shop_id as shop_id, pro.id as pro_id, info.product_name as pro_name,pro.stock_number, pro.is_stock," +
|
||||
" info.product_sku_name as sku_name, unit.NAME as unit_name ," +
|
||||
"SUM( CASE WHEN orders.order_type != 'return' THEN info.num ELSE 0 END )- SUM( CASE WHEN orders.order_type = 'return' THEN info.num ELSE 0 END ) as stock_count," +
|
||||
"CASE WHEN pro.is_distribute = '1' THEN sum(sku.stock_number) ELSE pro.stock_number END as stock_number " +
|
||||
"FROM " +
|
||||
"tb_order_info orders " +
|
||||
"LEFT JOIN tb_order_detail info ON orders.id = info.order_id " +
|
||||
"LEFT JOIN tb_product pro ON info.product_id = pro.id " +
|
||||
"LEFT JOIN tb_product_sku sku ON info.product_id = sku.product_id " +
|
||||
"LEFT JOIN tb_shop_unit unit ON unit.id = pro.unit_id " +
|
||||
"WHERE " +
|
||||
"info.create_time > :startTime " +
|
||||
"AND info.create_time < :endTime " +
|
||||
"AND ( info.STATUS = 'closed' OR info.STATUS = 'refund' ) " +
|
||||
"GROUP BY " +
|
||||
"info.product_id ",nativeQuery = true)
|
||||
List<StockCountDTO> countStock( @Param("startTime") String startTime, @Param("endTime") String endTime);
|
||||
|
||||
}
|
||||
|
|
@ -1,5 +1,6 @@
|
|||
package cn.ysk.cashier.repository.order;
|
||||
|
||||
import cn.ysk.cashier.dto.product.StockCountDTO;
|
||||
import cn.ysk.cashier.pojo.order.TbOrderDetail;
|
||||
import cn.ysk.cashier.vo.TbOrderPayCountVo;
|
||||
import cn.ysk.cashier.vo.TbOrderSalesCountByDayVo;
|
||||
|
|
@ -56,6 +57,23 @@ public interface TbOrderDetailRepository extends JpaRepository<TbOrderDetail, In
|
|||
"ORDER BY salesNum DESC")
|
||||
Page<TbOrderSalesCountByDayVo> queryTbOrderSalesCountByDay(@Param("shopId") Integer shopId,@Param("cateId")String cateId,@Param("proName")String proName, @Param("startTime") Date startTime, @Param("endTime") Date endTime, Pageable pageable);
|
||||
|
||||
@Query(value = "SELECT pro.shop_id as shop_id, pro.id as pro_id, info.product_name as pro_name, info.product_sku_id as sku_id, pro.is_stock as is_stock," +
|
||||
" info.product_sku_name as sku_name, unit.NAME as unit_name ," +
|
||||
"SUM( CASE WHEN orders.order_type != 'return' THEN info.num ELSE 0 END )- SUM( CASE WHEN orders.order_type = 'return' THEN info.num ELSE 0 END ) as stock_count " +
|
||||
"FROM " +
|
||||
"tb_order_info orders " +
|
||||
"LEFT JOIN tb_order_detail info ON orders.id = info.order_id " +
|
||||
"LEFT JOIN tb_product pro ON info.product_id = pro.id " +
|
||||
"LEFT JOIN tb_shop_unit unit ON unit.id = pro.unit_id " +
|
||||
"WHERE " +
|
||||
"info.create_time > :startTime " +
|
||||
"AND info.create_time < :endTime " +
|
||||
"AND ( info.STATUS = 'closed' OR info.STATUS = 'refund' ) " +
|
||||
"GROUP BY " +
|
||||
"info.product_id, " +
|
||||
"info.product_sku_id ",nativeQuery = true)
|
||||
List<StockCountDTO> countStock(@Param("startTime") String startTime, @Param("endTime") String endTime);
|
||||
|
||||
|
||||
|
||||
@Query("SELECT new cn.ysk.cashier.vo.TbOrderSalesCountByDayVo(" +
|
||||
|
|
@ -80,8 +98,8 @@ public interface TbOrderDetailRepository extends JpaRepository<TbOrderDetail, In
|
|||
List<TbOrderSalesCountByDayVo> queryTbOrderSalesCountByDay(@Param("shopId") Integer shopId,@Param("cateId")String cateId,@Param("proName")String proName, @Param("startTime") Date startTime, @Param("endTime") Date endTime);
|
||||
|
||||
@Query("SELECT new cn.ysk.cashier.vo.TbOrderSalesCountByDayVo(" +
|
||||
"SUM(CASE WHEN orders.orderType!='return' THEN info.num ELSE 0 END), " +
|
||||
"SUM(CASE WHEN orders.orderType='return' THEN info.num ELSE 0 END))" +
|
||||
"COALESCE(CAST(SUM(CASE WHEN orders.orderType!='return' THEN info.num ELSE 0 END) as long),0), " +
|
||||
"COALESCE(CAST(SUM(CASE WHEN orders.orderType='return' THEN info.num ELSE 0 END) as long),0))" +
|
||||
"FROM TbOrderInfo orders " +
|
||||
"LEFT JOIN TbOrderDetail info on orders.id=info.orderId " +
|
||||
"WHERE info.shopId = :shopId " +
|
||||
|
|
|
|||
|
|
@ -237,7 +237,7 @@ public class TbProductStockOperateServiceImpl implements TbProductStockOperateSe
|
|||
productStockDetail.setShopId(resources.getShopId());
|
||||
productStockDetail.setSkuId(productListDto.getId().toString());
|
||||
productStockDetail.setSourcePath("NORMAL");
|
||||
productStockDetail.setStockSnap(productListDto.getSpecSnap());
|
||||
productStockDetail.setSpecSnap(productListDto.getSpecSnap());
|
||||
productListDto.setNumber(productListDto.getNumber() != null ? productListDto.getNumber() : 0);
|
||||
tbProductSku.setCostPrice(productListDto.getCostPrice());
|
||||
// 总成本价
|
||||
|
|
|
|||
Loading…
Reference in New Issue