Merge branch 'test' into dev
This commit is contained in:
commit
1cfc94b22a
|
|
@ -13,6 +13,10 @@ public class RabbitConfig {
|
||||||
public static final String EXCHANGE_STOCK_RECORD = "exchange.stock.record";
|
public static final String EXCHANGE_STOCK_RECORD = "exchange.stock.record";
|
||||||
public static final String ROUTING_STOCK_RECORD_SALE = "routing.stock.record.sale";
|
public static final String ROUTING_STOCK_RECORD_SALE = "routing.stock.record.sale";
|
||||||
|
|
||||||
|
public static final String QUEUE_STOCK_RECORD = "queue.stock.record";
|
||||||
|
public static final String ROUTING_STOCK_RECORD= "routing.stock.record";
|
||||||
|
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
Queue stockRecordSaleQueue() {
|
Queue stockRecordSaleQueue() {
|
||||||
return new Queue(QUEUE_STOCK_RECORD_SALE);
|
return new Queue(QUEUE_STOCK_RECORD_SALE);
|
||||||
|
|
@ -27,4 +31,14 @@ public class RabbitConfig {
|
||||||
Binding binding(Queue stockRecordSaleQueue, DirectExchange stockRecordExchange) {
|
Binding binding(Queue stockRecordSaleQueue, DirectExchange stockRecordExchange) {
|
||||||
return BindingBuilder.bind(stockRecordSaleQueue).to(stockRecordExchange).with(ROUTING_STOCK_RECORD_SALE);
|
return BindingBuilder.bind(stockRecordSaleQueue).to(stockRecordExchange).with(ROUTING_STOCK_RECORD_SALE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
Queue stockRecordSaleQueue2() {
|
||||||
|
return new Queue(QUEUE_STOCK_RECORD);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
Binding binding2(Queue stockRecordSaleQueue2, DirectExchange stockRecordExchange) {
|
||||||
|
return BindingBuilder.bind(stockRecordSaleQueue2).to(stockRecordExchange).with(ROUTING_STOCK_RECORD);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -7,4 +7,16 @@ public interface RabbitConstants {
|
||||||
|
|
||||||
String CONS_MSG_COLLECT_PUT = "cons_msg_collect_put";
|
String CONS_MSG_COLLECT_PUT = "cons_msg_collect_put";
|
||||||
String CONS_MSG_COLLECT_ROUTINGKEY_PUT = "cons_msg_collect_routingkey_put";
|
String CONS_MSG_COLLECT_ROUTINGKEY_PUT = "cons_msg_collect_routingkey_put";
|
||||||
|
|
||||||
|
String CART_ORDER_COLLECT_PUT = "cart_order_collect_put";
|
||||||
|
String CART_ORDER_COLLECT_ROUTINGKEY_PUT = "cart_order_collect_routingkey_put";
|
||||||
|
|
||||||
|
// 打印
|
||||||
|
String PRINT_MECHINE_COLLECT_PUT="print_mechine_collect_put";
|
||||||
|
String PRINT_MECHINE_COLLECT_QUEUE_PUT = "print_mechine_collect_queue_put";
|
||||||
|
String PRINT_MECHINE_COLLECT_ROUTINGKEY_PUT = "print_mechine_collect_routingkey_put";
|
||||||
|
|
||||||
|
// 售出记录
|
||||||
|
String EXCHANGE_STOCK_RECORD = "exchange.stock.record";
|
||||||
|
String ROUTING_STOCK_RECORD_SALE = "routing.stock.record.sale";
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -125,4 +125,49 @@ public class TbPlaceController {
|
||||||
return ResponseEntity.ok(tbShopTableService.createOrder(createOrderDTO));
|
return ResponseEntity.ok(tbShopTableService.createOrder(createOrderDTO));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@AnonymousAccess
|
||||||
|
|
||||||
|
@PostMapping("/pending")
|
||||||
|
@Log("代客下单 查询购物车")
|
||||||
|
@ApiOperation("代客下单 查询购物车 /shop/table")
|
||||||
|
public ResponseEntity<Object> pending(
|
||||||
|
@RequestBody PendingDTO pendingDTO
|
||||||
|
) {
|
||||||
|
return ResponseEntity.ok(tbShopTableService.pending(pendingDTO));
|
||||||
|
}
|
||||||
|
|
||||||
|
@AnonymousAccess
|
||||||
|
|
||||||
|
@GetMapping("/car")
|
||||||
|
@Log("代客下单 查询购物车")
|
||||||
|
@ApiOperation("代客下单 查询购物车 /shop/table")
|
||||||
|
public ResponseEntity<Object> getCar(
|
||||||
|
@RequestParam Integer shopId
|
||||||
|
) {
|
||||||
|
return ResponseEntity.ok(tbShopTableService.getCar(shopId));
|
||||||
|
}
|
||||||
|
|
||||||
|
@AnonymousAccess
|
||||||
|
|
||||||
|
@GetMapping("/payType")
|
||||||
|
@Log("代客下单 查询购物车")
|
||||||
|
@ApiOperation("代客下单 查询购物车 /shop/table")
|
||||||
|
public ResponseEntity<Object> getPayType(
|
||||||
|
@RequestParam Integer shopId
|
||||||
|
) {
|
||||||
|
return ResponseEntity.ok(tbShopTableService.getPayType(shopId));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@AnonymousAccess
|
||||||
|
|
||||||
|
@PutMapping("/pay")
|
||||||
|
@Log("代客下单 查询购物车")
|
||||||
|
@ApiOperation("代客下单 查询购物车 /shop/table")
|
||||||
|
public ResponseEntity<Object> pay(
|
||||||
|
@Validated @RequestBody PayDTO payDTO
|
||||||
|
) {
|
||||||
|
return ResponseEntity.ok(tbShopTableService.pay(payDTO));
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -42,10 +42,8 @@ public class SummaryByDayController {
|
||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping(value = "count")
|
@GetMapping(value = "count")
|
||||||
public List<TbOrderPayCountVo> summaryCount(ShopSummaryDto summaryDto,
|
public List<TbOrderPayCountVo> summaryCount(ShopSummaryDto summaryDto) {
|
||||||
@RequestParam(required = false) @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") Date startTime,
|
return summaryService.summaryCount(summaryDto);
|
||||||
@RequestParam(required = false) @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") Date endTime) {
|
|
||||||
return summaryService.summaryCount(summaryDto, startTime, endTime);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,13 @@
|
||||||
|
package cn.ysk.cashier.dto.rabbit;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class StockRecordMsg {
|
||||||
|
private Integer shopId;
|
||||||
|
private Integer skuId;
|
||||||
|
private Integer productId;
|
||||||
|
private String type;
|
||||||
|
private Integer subType;
|
||||||
|
private Integer number;
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,11 @@
|
||||||
|
package cn.ysk.cashier.dto.shoptable;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import javax.validation.constraints.NotNull;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class CarDTO {
|
||||||
|
@NotNull
|
||||||
|
private Integer shopId;
|
||||||
|
}
|
||||||
|
|
@ -13,6 +13,6 @@ public class CreateOrderDTO {
|
||||||
@NotNull
|
@NotNull
|
||||||
private Integer shopId;
|
private Integer shopId;
|
||||||
@NotEmpty
|
@NotEmpty
|
||||||
private String tableId;
|
private Long tableId;
|
||||||
private String note;
|
private String note;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,16 @@
|
||||||
|
package cn.ysk.cashier.dto.shoptable;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import javax.validation.constraints.NotEmpty;
|
||||||
|
import javax.validation.constraints.NotNull;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class PayDTO {
|
||||||
|
@NotNull
|
||||||
|
private Integer shopId;
|
||||||
|
@NotNull
|
||||||
|
private Integer orderId;
|
||||||
|
@NotEmpty
|
||||||
|
private String payType;
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,20 @@
|
||||||
|
package cn.ysk.cashier.dto.shoptable;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
import org.bouncycastle.asn1.cmc.PendInfo;
|
||||||
|
|
||||||
|
import javax.validation.constraints.NotEmpty;
|
||||||
|
import javax.validation.constraints.NotNull;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class PendingDTO {
|
||||||
|
@NotEmpty
|
||||||
|
private String masterId;
|
||||||
|
@NotNull
|
||||||
|
private Integer shopId;
|
||||||
|
@NotNull
|
||||||
|
private Long tableId;
|
||||||
|
private Integer vipUserId;
|
||||||
|
@NotNull
|
||||||
|
private Boolean isPending;
|
||||||
|
}
|
||||||
|
|
@ -23,4 +23,6 @@ public class Activate extends Model<Activate> {
|
||||||
private String handselType;
|
private String handselType;
|
||||||
private String isDel;
|
private String isDel;
|
||||||
private String isUser;
|
private String isUser;
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,9 +2,20 @@ package cn.ysk.cashier.mybatis.mapper;
|
||||||
|
|
||||||
import cn.ysk.cashier.mybatis.entity.Activate;
|
import cn.ysk.cashier.mybatis.entity.Activate;
|
||||||
import cn.ysk.cashier.pojo.order.TbCashierCart;
|
import cn.ysk.cashier.pojo.order.TbCashierCart;
|
||||||
|
import cn.ysk.cashier.vo.CarVO;
|
||||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||||
|
import org.apache.ibatis.annotations.Param;
|
||||||
|
import org.apache.ibatis.annotations.Select;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
public interface TbCashierCartMapper extends BaseMapper<TbCashierCart> {
|
public interface TbCashierCartMapper extends BaseMapper<TbCashierCart> {
|
||||||
|
|
||||||
|
|
||||||
|
@Select("select table_id tableId,user_id userId, shop_Id as shopId,master_id as masterId,uuid,\n" +
|
||||||
|
" TRIM(TRAILING ', ' FROM GROUP_CONCAT(name ORDER BY id SEPARATOR ', ')) AS productName,\n" +
|
||||||
|
" pending_at as pendingAt,\n" +
|
||||||
|
" ifnull(sum(total_amount),0) as totalAmount\n" +
|
||||||
|
" from tb_cashier_cart where table_id is not null and shop_id = #{shopId} and status = 'refund' group by shop_Id, master_id order by trade_day desc")
|
||||||
|
List<CarVO> selectCar(@Param("shopId") Integer shopId);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,10 @@
|
||||||
package cn.ysk.cashier.rabbit;
|
package cn.ysk.cashier.rabbit;
|
||||||
|
|
||||||
|
import cn.hutool.core.util.StrUtil;
|
||||||
import cn.ysk.cashier.config.RabbitConfig;
|
import cn.ysk.cashier.config.RabbitConfig;
|
||||||
|
import cn.ysk.cashier.dto.rabbit.StockRecordMsg;
|
||||||
import cn.ysk.cashier.pojo.product.TbProductStockDetail;
|
import cn.ysk.cashier.pojo.product.TbProductStockDetail;
|
||||||
|
import cn.ysk.cashier.service.TbProductStockOperateService;
|
||||||
import cn.ysk.cashier.service.product.TbProductStockDetailService;
|
import cn.ysk.cashier.service.product.TbProductStockDetailService;
|
||||||
import com.alibaba.fastjson.JSONObject;
|
import com.alibaba.fastjson.JSONObject;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
|
@ -15,8 +18,11 @@ public class StockListener {
|
||||||
|
|
||||||
private final TbProductStockDetailService productStockDetailService;
|
private final TbProductStockDetailService productStockDetailService;
|
||||||
|
|
||||||
public StockListener(TbProductStockDetailService productStockDetailService) {
|
private final TbProductStockOperateService productStockOperateService;
|
||||||
|
|
||||||
|
public StockListener(TbProductStockDetailService productStockDetailService, TbProductStockOperateService productStockOperateService) {
|
||||||
this.productStockDetailService = productStockDetailService;
|
this.productStockDetailService = productStockDetailService;
|
||||||
|
this.productStockOperateService = productStockOperateService;
|
||||||
}
|
}
|
||||||
|
|
||||||
@RabbitListener(queues = RabbitConfig.QUEUE_STOCK_RECORD_SALE)
|
@RabbitListener(queues = RabbitConfig.QUEUE_STOCK_RECORD_SALE)
|
||||||
|
|
@ -33,4 +39,19 @@ public class StockListener {
|
||||||
log.error("执行保存库存mq失败", e);
|
log.error("执行保存库存mq失败", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@RabbitListener(queues = RabbitConfig.QUEUE_STOCK_RECORD)
|
||||||
|
public void recordStockHandler(String message) {
|
||||||
|
log.info("接收到下单保存库存信息mq消息,消息内容: {}", message);
|
||||||
|
if (StrUtil.isBlank(message)) {
|
||||||
|
log.warn("错误消息体");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
StockRecordMsg stockRecordMsg = JSONObject.parseObject(message, StockRecordMsg.class);
|
||||||
|
try {
|
||||||
|
productStockOperateService.addStockRecord(stockRecordMsg);
|
||||||
|
}catch (Exception e) {
|
||||||
|
log.error("执行保存库存mq失败", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -22,6 +22,8 @@ import org.springframework.data.jpa.repository.Modifying;
|
||||||
import org.springframework.data.jpa.repository.Query;
|
import org.springframework.data.jpa.repository.Query;
|
||||||
import org.springframework.data.repository.query.Param;
|
import org.springframework.data.repository.query.Param;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @website https://eladmin.vip
|
* @website https://eladmin.vip
|
||||||
* @author lyf
|
* @author lyf
|
||||||
|
|
@ -67,4 +69,7 @@ public interface TbShopPayTypeRepository extends JpaRepository<TbShopPayType, In
|
||||||
|
|
||||||
@Query("select t from TbShopPayType t where t.payType=:payType and t.shopId=:shopId")
|
@Query("select t from TbShopPayType t where t.payType=:payType and t.shopId=:shopId")
|
||||||
TbShopPayType findByPayType(@Param("payType")String payType,@Param("shopId") String shopId);
|
TbShopPayType findByPayType(@Param("payType")String payType,@Param("shopId") String shopId);
|
||||||
|
|
||||||
|
@Query("select t from TbShopPayType t where t.shopId=:s")
|
||||||
|
List<TbShopPayType> findByShopId(String s);
|
||||||
}
|
}
|
||||||
|
|
@ -37,7 +37,7 @@ public interface SummaryService {
|
||||||
*/
|
*/
|
||||||
void download(ShopSummaryDto summaryDto, HttpServletResponse response) throws IOException;
|
void download(ShopSummaryDto summaryDto, HttpServletResponse response) throws IOException;
|
||||||
|
|
||||||
List<TbOrderPayCountVo> summaryCount(ShopSummaryDto summaryDto, Date startTime, Date endTime);
|
List<TbOrderPayCountVo> summaryCount(ShopSummaryDto summaryDto);
|
||||||
|
|
||||||
List<ShopTableSaleInfoVo> selectSummaryTable(Integer shopId, Date startTime, Date endTime);
|
List<ShopTableSaleInfoVo> selectSummaryTable(Integer shopId, Date startTime, Date endTime);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
package cn.ysk.cashier.service;
|
package cn.ysk.cashier.service;
|
||||||
|
|
||||||
|
import cn.ysk.cashier.dto.rabbit.StockRecordMsg;
|
||||||
import cn.ysk.cashier.pojo.product.TbProductStockOperate;
|
import cn.ysk.cashier.pojo.product.TbProductStockOperate;
|
||||||
import cn.ysk.cashier.vo.ProductStockOperateVO;
|
import cn.ysk.cashier.vo.ProductStockOperateVO;
|
||||||
import cn.ysk.cashier.dto.product.OutAndOnDto;
|
import cn.ysk.cashier.dto.product.OutAndOnDto;
|
||||||
|
|
@ -74,4 +75,6 @@ public interface TbProductStockOperateService {
|
||||||
* @throws IOException /
|
* @throws IOException /
|
||||||
*/
|
*/
|
||||||
void download(List<TbProductStockOperate> all, HttpServletResponse response) throws IOException;
|
void download(List<TbProductStockOperate> all, HttpServletResponse response) throws IOException;
|
||||||
|
|
||||||
|
void addStockRecord(StockRecordMsg stockRecordMsg);
|
||||||
}
|
}
|
||||||
|
|
@ -15,6 +15,7 @@ import cn.ysk.cashier.service.SummaryService;
|
||||||
import cn.ysk.cashier.utils.DateUtil;
|
import cn.ysk.cashier.utils.DateUtil;
|
||||||
import cn.ysk.cashier.utils.FileUtil;
|
import cn.ysk.cashier.utils.FileUtil;
|
||||||
import cn.ysk.cashier.vo.*;
|
import cn.ysk.cashier.vo.*;
|
||||||
|
import com.alibaba.fastjson.JSONObject;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
|
@ -450,16 +451,16 @@ public class SummaryServiceImpl implements SummaryService {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<TbOrderPayCountVo> summaryCount(ShopSummaryDto summaryDto, Date startTime, Date endTime) {
|
public List<TbOrderPayCountVo> summaryCount(ShopSummaryDto summaryDto) {
|
||||||
List<TbOrderPayCountVo> list = new ArrayList<>();
|
List<TbOrderPayCountVo> list = new ArrayList<>();
|
||||||
Long start = 1704038400000L;
|
Long start = 1704038400000L;
|
||||||
Long end = Instant.now().toEpochMilli();
|
Long end = Instant.now().toEpochMilli();
|
||||||
if (startTime != null || endTime != null) {
|
if (summaryDto.getStartTime() != null || summaryDto.getEndTime() != null) {
|
||||||
start = startTime.getTime();
|
start = summaryDto.getStartTime().getTime();
|
||||||
end = endTime.getTime();
|
end = summaryDto.getEndTime().getTime();
|
||||||
} else {
|
} else {
|
||||||
startTime = DateUtil.toDate(DateUtil.fromTimeStamp(1704038400L));
|
summaryDto.setStartTime(DateUtil.toDate(DateUtil.fromTimeStamp(1704038400L)));
|
||||||
endTime = new Date();
|
summaryDto.setEndTime(new Date());
|
||||||
}
|
}
|
||||||
if (summaryDto.getType() != null && summaryDto.getType() == 1) {
|
if (summaryDto.getType() != null && summaryDto.getType() == 1) {
|
||||||
TbOrderPayCountVo payCount = tbOrderInfoRepository.queryOrderPayCount(summaryDto.getShopId(), start, end);
|
TbOrderPayCountVo payCount = tbOrderInfoRepository.queryOrderPayCount(summaryDto.getShopId(), start, end);
|
||||||
|
|
@ -474,7 +475,7 @@ public class SummaryServiceImpl implements SummaryService {
|
||||||
refCount.setIcon("el-icon-money");
|
refCount.setIcon("el-icon-money");
|
||||||
list.add(refCount);
|
list.add(refCount);
|
||||||
|
|
||||||
TbOrderSalesCountByDayVo numCount = detailRepository.queryTbOrderSalesCount(Integer.valueOf(summaryDto.getShopId()), startTime, endTime);
|
TbOrderSalesCountByDayVo numCount = detailRepository.queryTbOrderSalesCount(Integer.valueOf(summaryDto.getShopId()), summaryDto.getStartTime(), summaryDto.getEndTime());
|
||||||
TbOrderPayCountVo salesNum =new TbOrderPayCountVo("el-icon-goods","销售量","0",numCount.getSalesNum()-numCount.getRefNum());
|
TbOrderPayCountVo salesNum =new TbOrderPayCountVo("el-icon-goods","销售量","0",numCount.getSalesNum()-numCount.getRefNum());
|
||||||
TbOrderPayCountVo refNum =new TbOrderPayCountVo("el-icon-goods","退单量","0",numCount.getRefNum());
|
TbOrderPayCountVo refNum =new TbOrderPayCountVo("el-icon-goods","退单量","0",numCount.getRefNum());
|
||||||
list.add(salesNum);
|
list.add(salesNum);
|
||||||
|
|
|
||||||
|
|
@ -17,6 +17,7 @@ package cn.ysk.cashier.service.impl.productimpl;
|
||||||
|
|
||||||
import cn.hutool.core.util.StrUtil;
|
import cn.hutool.core.util.StrUtil;
|
||||||
import cn.ysk.cashier.dto.product.StockCountDTO;
|
import cn.ysk.cashier.dto.product.StockCountDTO;
|
||||||
|
import cn.ysk.cashier.dto.rabbit.StockRecordMsg;
|
||||||
import cn.ysk.cashier.pojo.order.TbOrderInfo;
|
import cn.ysk.cashier.pojo.order.TbOrderInfo;
|
||||||
import cn.ysk.cashier.pojo.product.TbProductStockDetail;
|
import cn.ysk.cashier.pojo.product.TbProductStockDetail;
|
||||||
import cn.ysk.cashier.repository.order.StockCountRepository;
|
import cn.ysk.cashier.repository.order.StockCountRepository;
|
||||||
|
|
@ -205,4 +206,5 @@ public class TbProductStockDetailServiceImpl implements TbProductStockDetailServ
|
||||||
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,15 @@
|
||||||
package cn.ysk.cashier.service.impl.productimpl;
|
package cn.ysk.cashier.service.impl.productimpl;
|
||||||
|
|
||||||
|
import cn.ysk.cashier.dto.rabbit.StockRecordMsg;
|
||||||
|
import cn.ysk.cashier.mybatis.mapper.TbProducSkutMapper;
|
||||||
|
import cn.ysk.cashier.mybatis.mapper.TbProductMapper;
|
||||||
import cn.ysk.cashier.pojo.product.TbProduct;
|
import cn.ysk.cashier.pojo.product.TbProduct;
|
||||||
import cn.ysk.cashier.pojo.shop.TbShopPurveyor;
|
import cn.ysk.cashier.pojo.shop.TbShopPurveyor;
|
||||||
|
import cn.ysk.cashier.pojo.shop.TbShopUnit;
|
||||||
import cn.ysk.cashier.repository.product.TbProductRepository;
|
import cn.ysk.cashier.repository.product.TbProductRepository;
|
||||||
|
import cn.ysk.cashier.repository.product.TbProductStockDetailRepository;
|
||||||
import cn.ysk.cashier.repository.shop.TbShopPurveyorRepository;
|
import cn.ysk.cashier.repository.shop.TbShopPurveyorRepository;
|
||||||
|
import cn.ysk.cashier.repository.shop.TbShopUnitRepository;
|
||||||
import cn.ysk.cashier.utils.*;
|
import cn.ysk.cashier.utils.*;
|
||||||
import com.alibaba.fastjson.JSON;
|
import com.alibaba.fastjson.JSON;
|
||||||
import com.alibaba.fastjson.JSONArray;
|
import com.alibaba.fastjson.JSONArray;
|
||||||
|
|
@ -23,12 +29,14 @@ import cn.ysk.cashier.repository.shop.TbShopInfoRepository;
|
||||||
import cn.ysk.cashier.pojo.shop.TbShopPurveyorTransact;
|
import cn.ysk.cashier.pojo.shop.TbShopPurveyorTransact;
|
||||||
import cn.ysk.cashier.repository.shop.TbShopPurveyorTransactRepository;
|
import cn.ysk.cashier.repository.shop.TbShopPurveyorTransactRepository;
|
||||||
import com.alipay.api.domain.Product;
|
import com.alipay.api.domain.Product;
|
||||||
|
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import cn.ysk.cashier.repository.product.TbProductStockOperateRepository;
|
import cn.ysk.cashier.repository.product.TbProductStockOperateRepository;
|
||||||
import cn.ysk.cashier.service.TbProductStockOperateService;
|
import cn.ysk.cashier.service.TbProductStockOperateService;
|
||||||
import cn.ysk.cashier.dto.product.TbProductStockOperateDto;
|
import cn.ysk.cashier.dto.product.TbProductStockOperateDto;
|
||||||
import cn.ysk.cashier.dto.product.TbProductStockOperateQueryCriteria;
|
import cn.ysk.cashier.dto.product.TbProductStockOperateQueryCriteria;
|
||||||
import cn.ysk.cashier.mapper.product.TbProductStockOperateMapper;
|
import cn.ysk.cashier.mapper.product.TbProductStockOperateMapper;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.beans.BeanUtils;
|
import org.springframework.beans.BeanUtils;
|
||||||
import org.springframework.data.domain.PageRequest;
|
import org.springframework.data.domain.PageRequest;
|
||||||
import org.springframework.data.domain.Sort;
|
import org.springframework.data.domain.Sort;
|
||||||
|
|
@ -53,6 +61,7 @@ import javax.servlet.http.HttpServletResponse;
|
||||||
**/
|
**/
|
||||||
@Service
|
@Service
|
||||||
@RequiredArgsConstructor
|
@RequiredArgsConstructor
|
||||||
|
@Slf4j
|
||||||
public class TbProductStockOperateServiceImpl implements TbProductStockOperateService {
|
public class TbProductStockOperateServiceImpl implements TbProductStockOperateService {
|
||||||
|
|
||||||
private final TbProductStockOperateRepository tbProductStockOperateRepository;
|
private final TbProductStockOperateRepository tbProductStockOperateRepository;
|
||||||
|
|
@ -429,4 +438,87 @@ public class TbProductStockOperateServiceImpl implements TbProductStockOperateSe
|
||||||
}
|
}
|
||||||
FileUtil.downloadExcel(list, response);
|
FileUtil.downloadExcel(list, response);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private final TbProductMapper productMapper;
|
||||||
|
private final TbProducSkutMapper producSkutMapper;
|
||||||
|
private final TbShopUnitRepository shopUnitRepository;
|
||||||
|
private final TbProductStockOperateRepository productStockOperateRepository;
|
||||||
|
private final TbProductStockDetailRepository productStockDetailRepository;
|
||||||
|
@Override
|
||||||
|
public void addStockRecord(StockRecordMsg stockRecordMsg) {
|
||||||
|
TbShopInfo byId = shopInfoRepository.findById(stockRecordMsg.getShopId()).orElseGet(TbShopInfo::new);
|
||||||
|
if (byId.getId() == null) {
|
||||||
|
throw new BadRequestException("商户号有误");
|
||||||
|
}
|
||||||
|
|
||||||
|
TbProduct product = productMapper.selectOne(new LambdaUpdateWrapper<TbProduct>()
|
||||||
|
.eq(TbProduct::getShopId, stockRecordMsg.getShopId())
|
||||||
|
.eq(TbProduct::getId, stockRecordMsg.getProductId())
|
||||||
|
.eq(TbProduct::getIsDel, 0));
|
||||||
|
|
||||||
|
TbProductSku productSku = producSkutMapper.selectOne(new LambdaUpdateWrapper<TbProductSku>()
|
||||||
|
.eq(TbProductSku::getShopId, stockRecordMsg.getShopId())
|
||||||
|
.eq(TbProductSku::getId, stockRecordMsg.getSkuId())
|
||||||
|
.eq(TbProductSku::getIsDel, 0));
|
||||||
|
if (product == null || productSku == null) {
|
||||||
|
log.info("商品或sku不存在");
|
||||||
|
throw new BadRequestException("商品或sku不存在");
|
||||||
|
}
|
||||||
|
|
||||||
|
TbShopUnit tbShopUnit = shopUnitRepository.findById(product.getUnitId()).orElse(null);
|
||||||
|
|
||||||
|
//增加操作日志
|
||||||
|
long times = Instant.now().toEpochMilli();
|
||||||
|
HashMap<String, Object> snapItem = new HashMap<>();
|
||||||
|
snapItem.put("stockNumber", product.getIsDistribute().equals(1) ? product.getStockNumber() - stockRecordMsg.getNumber() :
|
||||||
|
productSku.getStockNumber() - stockRecordMsg.getNumber());
|
||||||
|
snapItem.put("number", stockRecordMsg.getSubType() == -1 ? -stockRecordMsg.getNumber() : stockRecordMsg.getNumber());
|
||||||
|
snapItem.put("coverImg", product.getCoverImg());
|
||||||
|
snapItem.put("productId", product.getId());
|
||||||
|
snapItem.put("name", product.getName());
|
||||||
|
snapItem.put("unitName", tbShopUnit == null ? "" : tbShopUnit.getName());
|
||||||
|
|
||||||
|
ArrayList<HashMap<String, Object>> stockSnap = new ArrayList<>();
|
||||||
|
stockSnap.add(snapItem);
|
||||||
|
|
||||||
|
TbProductStockOperate stockOperate = new TbProductStockOperate();
|
||||||
|
stockOperate.setShopId(String.valueOf(stockRecordMsg.getShopId()));
|
||||||
|
stockOperate.setStockSnap(JSONObject.toJSONString(stockSnap));
|
||||||
|
stockOperate.setType(stockRecordMsg.getType());
|
||||||
|
|
||||||
|
Map<String, String> operatorSnapMap = new HashMap<>();
|
||||||
|
operatorSnapMap.put("name", byId.getShopName());
|
||||||
|
operatorSnapMap.put("account", byId.getAccount());
|
||||||
|
|
||||||
|
stockOperate.setOperatorSnap(JSON.toJSONString(operatorSnapMap));
|
||||||
|
stockOperate.setStockTime(times);
|
||||||
|
stockOperate.setCreatedAt(times);
|
||||||
|
stockOperate.setUpdatedAt(times);
|
||||||
|
stockOperate.setStatus("normal");
|
||||||
|
productStockOperateRepository.save(stockOperate);
|
||||||
|
|
||||||
|
|
||||||
|
TbProductStockDetail productStockDetail = new TbProductStockDetail();
|
||||||
|
productStockDetail.setCreatedAt(times);
|
||||||
|
productStockDetail.setUpdatedAt(times);
|
||||||
|
productStockDetail.setIsStock(1);
|
||||||
|
productStockDetail.setProductId(String.valueOf(product.getId()));
|
||||||
|
productStockDetail.setProductName(product.getName());
|
||||||
|
productStockDetail.setUnitName(tbShopUnit == null ? null : tbShopUnit.getName());
|
||||||
|
productStockDetail.setShopId(String.valueOf(stockRecordMsg.getShopId()));
|
||||||
|
productStockDetail.setSkuId(String.valueOf(stockRecordMsg.getSkuId()));
|
||||||
|
productStockDetail.setSubType(stockRecordMsg.getSubType());
|
||||||
|
productStockDetail.setType(stockRecordMsg.getType());
|
||||||
|
productStockDetail.setSpecSnap(productSku.getSpecSnap());
|
||||||
|
productStockDetail.setStockNumber(Double.valueOf(stockRecordMsg.getNumber()));
|
||||||
|
productStockDetail.setCostAmount(productSku.getSalePrice().multiply(BigDecimal.valueOf(Math.abs(stockRecordMsg.getNumber()))));
|
||||||
|
productStockDetail.setLeftNumber(product.getIsDistribute().equals(1) ? product.getStockNumber() - stockRecordMsg.getNumber()
|
||||||
|
: productSku.getStockNumber().intValue() - stockRecordMsg.getNumber());
|
||||||
|
productStockDetail.setRecordId(stockOperate.getId().toString());
|
||||||
|
productStockDetail.setStockSnap(JSONObject.toJSONString(snapItem));
|
||||||
|
productStockDetail.setSourcePath("NORMAL");
|
||||||
|
productStockDetailRepository.save(productStockDetail);
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -18,6 +18,7 @@ package cn.ysk.cashier.service.impl.shopimpl;
|
||||||
import cn.hutool.core.bean.BeanUtil;
|
import cn.hutool.core.bean.BeanUtil;
|
||||||
import cn.hutool.core.date.DateUtil;
|
import cn.hutool.core.date.DateUtil;
|
||||||
import cn.hutool.core.thread.ThreadUtil;
|
import cn.hutool.core.thread.ThreadUtil;
|
||||||
|
import cn.hutool.core.util.ObjectUtil;
|
||||||
import cn.ysk.cashier.config.security.security.TokenProvider;
|
import cn.ysk.cashier.config.security.security.TokenProvider;
|
||||||
import cn.ysk.cashier.cons.RedisConstant;
|
import cn.ysk.cashier.cons.RedisConstant;
|
||||||
import cn.ysk.cashier.cons.rabbit.RabbitConstants;
|
import cn.ysk.cashier.cons.rabbit.RabbitConstants;
|
||||||
|
|
@ -34,6 +35,7 @@ import cn.ysk.cashier.pojo.product.TbProductSku;
|
||||||
import cn.ysk.cashier.pojo.shop.TbMerchantAccount;
|
import cn.ysk.cashier.pojo.shop.TbMerchantAccount;
|
||||||
import cn.ysk.cashier.pojo.shop.TbShopInfo;
|
import cn.ysk.cashier.pojo.shop.TbShopInfo;
|
||||||
import cn.ysk.cashier.pojo.shop.TbShopTable;
|
import cn.ysk.cashier.pojo.shop.TbShopTable;
|
||||||
|
import cn.ysk.cashier.repository.TbShopPayTypeRepository;
|
||||||
import cn.ysk.cashier.repository.order.TbCashierCartRepository;
|
import cn.ysk.cashier.repository.order.TbCashierCartRepository;
|
||||||
import cn.ysk.cashier.repository.product.TbProductRepository;
|
import cn.ysk.cashier.repository.product.TbProductRepository;
|
||||||
import cn.ysk.cashier.repository.product.TbProductSkuRepository;
|
import cn.ysk.cashier.repository.product.TbProductSkuRepository;
|
||||||
|
|
@ -41,6 +43,7 @@ import cn.ysk.cashier.repository.shop.TbShopInfoRepository;
|
||||||
import cn.ysk.cashier.utils.*;
|
import cn.ysk.cashier.utils.*;
|
||||||
import com.alibaba.fastjson.JSONObject;
|
import com.alibaba.fastjson.JSONObject;
|
||||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
|
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
||||||
import com.dianguang.cloud.ossservice.model.DateUtils;
|
import com.dianguang.cloud.ossservice.model.DateUtils;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import cn.ysk.cashier.repository.shop.TbShopTableRepository;
|
import cn.ysk.cashier.repository.shop.TbShopTableRepository;
|
||||||
|
|
@ -95,6 +98,7 @@ public class TbShopTableServiceImpl implements TbShopTableService {
|
||||||
private final TbShopOpenIdMapper shopOpenIdMapper;
|
private final TbShopOpenIdMapper shopOpenIdMapper;
|
||||||
private final WxAccountUtil wxAccountUtil;
|
private final WxAccountUtil wxAccountUtil;
|
||||||
private final WxMsgUtils wxMsgUtils;
|
private final WxMsgUtils wxMsgUtils;
|
||||||
|
private final TbShopPayTypeRepository payTypeRepository;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 桌码前缀
|
* 桌码前缀
|
||||||
|
|
@ -290,11 +294,15 @@ public class TbShopTableServiceImpl implements TbShopTableService {
|
||||||
throw new BadRequestException("桌码不存在,桌码" + addCartDTO.getTableId());
|
throw new BadRequestException("桌码不存在,桌码" + addCartDTO.getTableId());
|
||||||
}
|
}
|
||||||
|
|
||||||
LambdaQueryWrapper<TbCashierCart> query = new LambdaQueryWrapper<TbCashierCart>().eq(TbCashierCart::getShopId, addCartDTO.getShopId())
|
LambdaQueryWrapper<TbCashierCart> query = new LambdaQueryWrapper<TbCashierCart>()
|
||||||
|
.eq(TbCashierCart::getShopId, addCartDTO.getShopId())
|
||||||
|
.eq(TbCashierCart::getSkuId, addCartDTO.getSkuId())
|
||||||
|
.eq(TbCashierCart::getProductId, addCartDTO.getProductId())
|
||||||
.eq(TbCashierCart::getTableId, addCartDTO.getTableId());
|
.eq(TbCashierCart::getTableId, addCartDTO.getTableId());
|
||||||
if (addCartDTO.getVipUserId() != null) {
|
if (addCartDTO.getVipUserId() != null) {
|
||||||
query.eq(TbCashierCart::getUserId, addCartDTO.getVipUserId());
|
query.eq(TbCashierCart::getUserId, addCartDTO.getVipUserId());
|
||||||
} else {
|
} else {
|
||||||
|
query.eq(TbCashierCart::getMasterId, addCartDTO.getMasterId());
|
||||||
query.isNull(TbCashierCart::getUserId);
|
query.isNull(TbCashierCart::getUserId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -455,138 +463,6 @@ public class TbShopTableServiceImpl implements TbShopTableService {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public Object createOrder(CreateOrderDTO createOrderDTO) {
|
|
||||||
String day = DateUtils.getDay();
|
|
||||||
LambdaQueryWrapper<TbCashierCart> queryWrapper = new LambdaQueryWrapper<TbCashierCart>()
|
|
||||||
.eq(TbCashierCart::getShopId, createOrderDTO.getShopId())
|
|
||||||
.eq(TbCashierCart::getTableId, createOrderDTO.getTableId())
|
|
||||||
.eq(TbCashierCart::getStatus, "create");
|
|
||||||
if (createOrderDTO.getVipUserId() != null) {
|
|
||||||
queryWrapper.eq(TbCashierCart::getUserId, createOrderDTO.getVipUserId());
|
|
||||||
}else {
|
|
||||||
queryWrapper.eq(TbCashierCart::getMasterId, createOrderDTO.getMasterId())
|
|
||||||
.isNull(TbCashierCart::getUserId);
|
|
||||||
}
|
|
||||||
List<TbCashierCart> cashierCarts = cashierCartMapper
|
|
||||||
.selectList(queryWrapper);
|
|
||||||
if (cashierCarts.isEmpty()) {
|
|
||||||
throw new BadRequestException("购物车为空,请先添加商品");
|
|
||||||
}
|
|
||||||
|
|
||||||
BigDecimal totalAmount = BigDecimal.ZERO;
|
|
||||||
BigDecimal packAMount = BigDecimal.ZERO;
|
|
||||||
BigDecimal feeAmount = BigDecimal.ZERO;
|
|
||||||
BigDecimal saleAmount = BigDecimal.ZERO;
|
|
||||||
List<TbOrderDetail> orderDetails = new ArrayList<>();
|
|
||||||
Integer orderId = null;
|
|
||||||
for (TbCashierCart cashierCart : cashierCarts) {
|
|
||||||
totalAmount = totalAmount.add(cashierCart.getTotalAmount());
|
|
||||||
packAMount = packAMount.add(cashierCart.getPackFee());
|
|
||||||
feeAmount = cashierCart.getPackFee();
|
|
||||||
TbProductSku productSku = productSkuRepository.findById(Integer.valueOf(cashierCart.getSkuId())).orElse(null);
|
|
||||||
TbOrderDetail orderDetail = new TbOrderDetail();
|
|
||||||
|
|
||||||
if (Objects.nonNull(productSku)) {
|
|
||||||
saleAmount = saleAmount.add(productSku.getSalePrice());
|
|
||||||
orderDetail.setProductSkuName(productSku.getSpecSnap());
|
|
||||||
}
|
|
||||||
|
|
||||||
orderDetail.setCreateTime(DateUtil.date().toTimestamp());
|
|
||||||
orderDetail.setNum(cashierCart.getNumber());
|
|
||||||
orderDetail.setPrice(cashierCart.getSalePrice());
|
|
||||||
orderDetail.setPriceAmount(cashierCart.getTotalAmount());
|
|
||||||
orderDetail.setProductId(Integer.valueOf(cashierCart.getProductId()));
|
|
||||||
orderDetail.setProductSkuId(Integer.valueOf(cashierCart.getSkuId()));
|
|
||||||
orderDetail.setProductName(cashierCart.getName());
|
|
||||||
orderDetail.setShopId(Integer.valueOf(cashierCart.getShopId()));
|
|
||||||
orderDetail.setPackAmount(cashierCart.getPackFee());
|
|
||||||
orderDetail.setStatus("unpaid");
|
|
||||||
orderDetail.setProductImg(cashierCart.getCoverImg());
|
|
||||||
orderDetails.add(orderDetail);
|
|
||||||
if (cashierCart.getOrderId() != null) {
|
|
||||||
orderId = cashierCart.getOrderId();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
TbOrderInfo orderInfo = null;
|
|
||||||
if (orderId != null) {
|
|
||||||
orderInfo = orderInfoMapper.selectById(orderId);
|
|
||||||
}
|
|
||||||
|
|
||||||
// 修改订单信息
|
|
||||||
if (orderInfo != null) {
|
|
||||||
// 删除历史订单
|
|
||||||
orderDetailMapper.delete(new LambdaQueryWrapper<TbOrderDetail>().eq(TbOrderDetail::getOrderId, orderId));
|
|
||||||
orderInfo.setUpdatedAt(System.currentTimeMillis());
|
|
||||||
orderInfo.setSettlementAmount(totalAmount);
|
|
||||||
orderInfo.setAmount(totalAmount);
|
|
||||||
orderInfo.setOriginAmount(totalAmount);
|
|
||||||
orderInfo.setStatus("unpaid");
|
|
||||||
orderInfo.setOrderAmount(totalAmount);
|
|
||||||
orderInfo.setRemark(createOrderDTO.getNote());
|
|
||||||
orderInfo.setFreightAmount(feeAmount);
|
|
||||||
orderInfo.setProductAmount(saleAmount);
|
|
||||||
orderInfo.setTradeDay(DateUtils.getDay());
|
|
||||||
orderInfoMapper.updateById(orderInfo);
|
|
||||||
}else {
|
|
||||||
String orderNo = generateOrderNumber();
|
|
||||||
orderInfo = new TbOrderInfo();
|
|
||||||
orderInfo.setOrderNo(orderNo);
|
|
||||||
orderInfo.setAmount(totalAmount);
|
|
||||||
orderInfo.setPackFee(packAMount);
|
|
||||||
orderInfo.setSettlementAmount(totalAmount);
|
|
||||||
orderInfo.setOriginAmount(totalAmount);
|
|
||||||
orderInfo.setProductAmount(saleAmount);
|
|
||||||
orderInfo.setOrderAmount(totalAmount);
|
|
||||||
orderInfo.setFreightAmount(feeAmount);
|
|
||||||
orderInfo.setTableId(createOrderDTO.getTableId());
|
|
||||||
orderInfo.setSendType("table");
|
|
||||||
orderInfo.setOrderType("cash");
|
|
||||||
orderInfo.setShopId(createOrderDTO.getShopId().toString());
|
|
||||||
orderInfo.setRefundAble(1);
|
|
||||||
orderInfo.setTradeDay(day);
|
|
||||||
orderInfo.setMasterId(createOrderDTO.getMasterId());
|
|
||||||
orderInfo.setRemark(createOrderDTO.getNote());
|
|
||||||
}
|
|
||||||
|
|
||||||
// 更新取餐号
|
|
||||||
orderInfo.setOutNumber(updateOutNumber(String.valueOf(createOrderDTO.getShopId())).toString());
|
|
||||||
orderInfoMapper.insert(orderInfo);
|
|
||||||
|
|
||||||
// 添加订单详细数据
|
|
||||||
orderId = orderInfo.getId();
|
|
||||||
for (TbOrderDetail orderDetail : orderDetails) {
|
|
||||||
orderDetail.setOrderId(orderId);
|
|
||||||
orderDetailMapper.insert(orderDetail);
|
|
||||||
}
|
|
||||||
|
|
||||||
// 更新购物车记录的orderId
|
|
||||||
// 是否是第一次添加的商品
|
|
||||||
boolean isFirst = true;
|
|
||||||
for (TbCashierCart cashierCart : cashierCarts) {
|
|
||||||
TbProduct product = productMapper.selectById(cashierCart.getProductId());
|
|
||||||
TbProductSku productSku = productSkuRepository.findById(Integer.valueOf(cashierCart.getSkuId())).orElse(null);
|
|
||||||
|
|
||||||
log.info("下单,开始校验库存预警,购物车id:{}", cashierCart.getId());
|
|
||||||
CompletableFuture.runAsync(() -> checkWarnLineAndSendMsg(productSku, product, Integer.valueOf(cashierCart.getShopId()), cashierCart.getNumber()));
|
|
||||||
|
|
||||||
// 已经添加的商品,修改数量
|
|
||||||
isFirst = updateStock(cashierCart);
|
|
||||||
cashierCart.setOrderId(orderId);
|
|
||||||
cashierCart.setUpdatedAt(System.currentTimeMillis());
|
|
||||||
cashierCartMapper.updateById(cashierCart);
|
|
||||||
}
|
|
||||||
if (isFirst) {
|
|
||||||
redisTemplate.delete("SHOP:CODE:USER:pc:" + createOrderDTO.getShopId() + ":"
|
|
||||||
+ day + ":" + createOrderDTO.getTableId() + ":" + (createOrderDTO.getVipUserId() == null ? "" : createOrderDTO.getVipUserId()));
|
|
||||||
}
|
|
||||||
|
|
||||||
// 推送耗材信息
|
|
||||||
pushConsMsg(orderInfo, cashierCarts);
|
|
||||||
return orderInfo;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 增加库存
|
* 增加库存
|
||||||
|
|
@ -754,18 +630,18 @@ public class TbShopTableServiceImpl implements TbShopTableService {
|
||||||
String date = DateUtils.getSdfTimes();
|
String date = DateUtils.getSdfTimes();
|
||||||
Random random = new Random();
|
Random random = new Random();
|
||||||
int randomNum = random.nextInt(900) + 100;
|
int randomNum = random.nextInt(900) + 100;
|
||||||
return "DD" + date + randomNum;
|
return "DDPL" + date + randomNum;
|
||||||
}
|
}
|
||||||
|
|
||||||
public synchronized String generateOrderCode(String day, String clientType, String shopId) {
|
public synchronized String generateOrderCode(String day, String clientType, String shopId) {
|
||||||
String code = redisUtils.get("SHOP:CODE:" + clientType + ":" + shopId + ":" + day) + "";
|
String code = redisTemplate.opsForValue().get("SHOP:CODE:" + clientType + ":" + shopId + ":" + day);
|
||||||
// 使用顺序递增的计数器生成取餐码
|
// 使用顺序递增的计数器生成取餐码
|
||||||
String orderCode = "";
|
String orderCode = "";
|
||||||
if (StringUtils.isEmpty(code) || "null".equals(code)) {
|
if (StringUtils.isEmpty(code) || "null".equals(code)) {
|
||||||
orderCode = "1";
|
orderCode = "1";
|
||||||
redisTemplate.opsForValue().set("SHOP:CODE:" + clientType + ":" + shopId + ":" + day, "1");
|
redisTemplate.opsForValue().set("SHOP:CODE:" + clientType + ":" + shopId + ":" + day, "1");
|
||||||
} else {
|
} else {
|
||||||
orderCode = String.valueOf(Integer.parseInt(code) + 1);
|
orderCode = String.valueOf(Integer.parseInt(code.replace("#", "")) + 1);
|
||||||
}
|
}
|
||||||
redisTemplate.opsForValue().set("SHOP:CODE:" + clientType + ":" + shopId + ":" + day, "#" + Integer.parseInt(code.replace("#", "")) + 2);
|
redisTemplate.opsForValue().set("SHOP:CODE:" + clientType + ":" + shopId + ":" + day, "#" + Integer.parseInt(code.replace("#", "")) + 2);
|
||||||
boolean flag = Boolean.TRUE.equals(redisTemplate.opsForValue().setIfAbsent("SHOP:CODE:SET" + clientType + ":" + shopId + ":" + day, orderCode));
|
boolean flag = Boolean.TRUE.equals(redisTemplate.opsForValue().setIfAbsent("SHOP:CODE:SET" + clientType + ":" + shopId + ":" + day, orderCode));
|
||||||
|
|
@ -777,6 +653,7 @@ public class TbShopTableServiceImpl implements TbShopTableService {
|
||||||
return orderCode;
|
return orderCode;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private final StringRedisTemplate redisTemplate;
|
private final StringRedisTemplate redisTemplate;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
@ -802,4 +679,258 @@ public class TbShopTableServiceImpl implements TbShopTableService {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public TbOrderInfo createOrder(CreateOrderDTO createOrderDTO) {
|
||||||
|
String day = DateUtils.getDay();
|
||||||
|
LambdaQueryWrapper<TbCashierCart> queryWrapper = new LambdaQueryWrapper<TbCashierCart>()
|
||||||
|
.eq(TbCashierCart::getShopId, createOrderDTO.getShopId())
|
||||||
|
.eq(TbCashierCart::getTableId, createOrderDTO.getTableId())
|
||||||
|
.eq(TbCashierCart::getStatus, "create");
|
||||||
|
if (createOrderDTO.getVipUserId() != null) {
|
||||||
|
queryWrapper.eq(TbCashierCart::getUserId, createOrderDTO.getVipUserId());
|
||||||
|
}else {
|
||||||
|
queryWrapper.eq(TbCashierCart::getMasterId, createOrderDTO.getMasterId())
|
||||||
|
.isNull(TbCashierCart::getUserId);
|
||||||
|
}
|
||||||
|
List<TbCashierCart> cashierCarts = cashierCartMapper
|
||||||
|
.selectList(queryWrapper);
|
||||||
|
if (cashierCarts.isEmpty()) {
|
||||||
|
throw new BadRequestException("购物车为空,请先添加商品");
|
||||||
|
}
|
||||||
|
|
||||||
|
BigDecimal totalAmount = BigDecimal.ZERO;
|
||||||
|
BigDecimal packAMount = BigDecimal.ZERO;
|
||||||
|
BigDecimal feeAmount = BigDecimal.ZERO;
|
||||||
|
BigDecimal saleAmount = BigDecimal.ZERO;
|
||||||
|
List<TbOrderDetail> orderDetails = new ArrayList<>();
|
||||||
|
Integer orderId = null;
|
||||||
|
for (TbCashierCart cashierCart : cashierCarts) {
|
||||||
|
totalAmount = totalAmount.add(cashierCart.getTotalAmount());
|
||||||
|
packAMount = packAMount.add(cashierCart.getPackFee());
|
||||||
|
feeAmount = cashierCart.getPackFee();
|
||||||
|
TbProductSku productSku = productSkuRepository.findById(Integer.valueOf(cashierCart.getSkuId())).orElse(null);
|
||||||
|
TbOrderDetail orderDetail = new TbOrderDetail();
|
||||||
|
|
||||||
|
if (Objects.nonNull(productSku)) {
|
||||||
|
saleAmount = saleAmount.add(productSku.getSalePrice());
|
||||||
|
orderDetail.setProductSkuName(productSku.getSpecSnap());
|
||||||
|
}
|
||||||
|
|
||||||
|
orderDetail.setCreateTime(DateUtil.date().toTimestamp());
|
||||||
|
orderDetail.setNum(cashierCart.getNumber());
|
||||||
|
orderDetail.setPrice(cashierCart.getSalePrice());
|
||||||
|
orderDetail.setPriceAmount(cashierCart.getTotalAmount());
|
||||||
|
orderDetail.setProductId(Integer.valueOf(cashierCart.getProductId()));
|
||||||
|
orderDetail.setProductSkuId(Integer.valueOf(cashierCart.getSkuId()));
|
||||||
|
orderDetail.setProductName(cashierCart.getName());
|
||||||
|
orderDetail.setShopId(Integer.valueOf(cashierCart.getShopId()));
|
||||||
|
orderDetail.setPackAmount(cashierCart.getPackFee());
|
||||||
|
orderDetail.setStatus("unpaid");
|
||||||
|
orderDetail.setProductImg(cashierCart.getCoverImg());
|
||||||
|
orderDetails.add(orderDetail);
|
||||||
|
if (cashierCart.getOrderId() != null) {
|
||||||
|
orderId = cashierCart.getOrderId();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
TbOrderInfo orderInfo = null;
|
||||||
|
if (orderId != null) {
|
||||||
|
orderInfo = orderInfoMapper.selectById(orderId);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 修改订单信息
|
||||||
|
if (orderInfo != null) {
|
||||||
|
// 删除历史订单
|
||||||
|
// 更新取餐号
|
||||||
|
orderInfo.setOutNumber(updateOutNumber(String.valueOf(createOrderDTO.getShopId())).toString());
|
||||||
|
orderDetailMapper.delete(new LambdaQueryWrapper<TbOrderDetail>().eq(TbOrderDetail::getOrderId, orderId));
|
||||||
|
orderInfo.setUpdatedAt(System.currentTimeMillis());
|
||||||
|
orderInfo.setSettlementAmount(totalAmount);
|
||||||
|
orderInfo.setAmount(totalAmount);
|
||||||
|
orderInfo.setOriginAmount(totalAmount);
|
||||||
|
orderInfo.setStatus("unpaid");
|
||||||
|
orderInfo.setOrderAmount(totalAmount);
|
||||||
|
orderInfo.setRemark(createOrderDTO.getNote());
|
||||||
|
orderInfo.setFreightAmount(feeAmount);
|
||||||
|
orderInfo.setProductAmount(saleAmount);
|
||||||
|
orderInfo.setTradeDay(DateUtils.getDay());
|
||||||
|
orderInfoMapper.updateById(orderInfo);
|
||||||
|
|
||||||
|
}else {
|
||||||
|
String orderNo = generateOrderNumber();
|
||||||
|
orderInfo = new TbOrderInfo();
|
||||||
|
orderInfo.setOrderNo(orderNo);
|
||||||
|
orderInfo.setAmount(totalAmount);
|
||||||
|
orderInfo.setPackFee(packAMount);
|
||||||
|
orderInfo.setSettlementAmount(totalAmount);
|
||||||
|
orderInfo.setOriginAmount(totalAmount);
|
||||||
|
orderInfo.setProductAmount(saleAmount);
|
||||||
|
orderInfo.setOrderAmount(totalAmount);
|
||||||
|
orderInfo.setFreightAmount(feeAmount);
|
||||||
|
orderInfo.setTableId(String.valueOf(createOrderDTO.getTableId()));
|
||||||
|
orderInfo.setSendType("table");
|
||||||
|
orderInfo.setOrderType("cash");
|
||||||
|
orderInfo.setShopId(createOrderDTO.getShopId().toString());
|
||||||
|
orderInfo.setRefundAble(1);
|
||||||
|
orderInfo.setTradeDay(day);
|
||||||
|
orderInfo.setMasterId(createOrderDTO.getMasterId());
|
||||||
|
orderInfo.setRemark(createOrderDTO.getNote());
|
||||||
|
orderInfoMapper.insert(orderInfo);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// 添加订单详细数据
|
||||||
|
orderId = orderInfo.getId();
|
||||||
|
for (TbOrderDetail orderDetail : orderDetails) {
|
||||||
|
orderDetail.setOrderId(orderId);
|
||||||
|
orderDetailMapper.insert(orderDetail);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 更新购物车记录的orderId
|
||||||
|
// 是否是第一次添加的商品
|
||||||
|
boolean isFirst = true;
|
||||||
|
for (TbCashierCart cashierCart : cashierCarts) {
|
||||||
|
TbProduct product = productMapper.selectById(cashierCart.getProductId());
|
||||||
|
TbProductSku productSku = productSkuRepository.findById(Integer.valueOf(cashierCart.getSkuId())).orElse(null);
|
||||||
|
|
||||||
|
log.info("下单,开始校验库存预警,购物车id:{}", cashierCart.getId());
|
||||||
|
CompletableFuture.runAsync(() -> checkWarnLineAndSendMsg(productSku, product, Integer.valueOf(cashierCart.getShopId()), cashierCart.getNumber()));
|
||||||
|
|
||||||
|
// 已经添加的商品,修改数量
|
||||||
|
isFirst = updateStock(cashierCart);
|
||||||
|
cashierCart.setOrderId(orderId);
|
||||||
|
cashierCart.setUpdatedAt(System.currentTimeMillis());
|
||||||
|
cashierCartMapper.updateById(cashierCart);
|
||||||
|
}
|
||||||
|
if (isFirst) {
|
||||||
|
redisTemplate.delete("SHOP:CODE:USER:pc:" + createOrderDTO.getShopId() + ":"
|
||||||
|
+ day + ":" + createOrderDTO.getTableId() + ":" + (createOrderDTO.getVipUserId() == null ? "" : createOrderDTO.getVipUserId()));
|
||||||
|
}
|
||||||
|
|
||||||
|
// 推送耗材信息
|
||||||
|
pushConsMsg(orderInfo, cashierCarts);
|
||||||
|
return orderInfo;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Object pending(PendingDTO pendingDTO) {
|
||||||
|
LambdaQueryWrapper<TbCashierCart> queryWrapper = new LambdaQueryWrapper<TbCashierCart>()
|
||||||
|
.eq(TbCashierCart::getShopId, pendingDTO.getShopId())
|
||||||
|
.eq(TbCashierCart::getTableId, pendingDTO.getTableId())
|
||||||
|
.eq(TbCashierCart::getStatus, "create");
|
||||||
|
if (pendingDTO.getVipUserId() != null) {
|
||||||
|
queryWrapper.eq(TbCashierCart::getUserId, pendingDTO.getVipUserId());
|
||||||
|
}else {
|
||||||
|
queryWrapper.eq(TbCashierCart::getMasterId, pendingDTO.getMasterId())
|
||||||
|
.isNull(TbCashierCart::getUserId);
|
||||||
|
}
|
||||||
|
List<TbCashierCart> cashierCarts = cashierCartMapper
|
||||||
|
.selectList(queryWrapper);
|
||||||
|
|
||||||
|
Integer orderId = null;
|
||||||
|
for (TbCashierCart item : cashierCarts) {
|
||||||
|
if (item.getOrderId() == null) {
|
||||||
|
orderId = null;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
orderId = item.getOrderId();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (orderId == null) {
|
||||||
|
CreateOrderDTO createOrderDTO = new CreateOrderDTO();
|
||||||
|
createOrderDTO.setTableId(pendingDTO.getTableId());
|
||||||
|
createOrderDTO.setShopId(pendingDTO.getShopId());
|
||||||
|
createOrderDTO.setMasterId(pendingDTO.getMasterId());
|
||||||
|
createOrderDTO.setVipUserId(pendingDTO.getVipUserId());
|
||||||
|
orderId = createOrder(createOrderDTO).getId();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
TbOrderDetail orderDetail = new TbOrderDetail();
|
||||||
|
orderDetail.setStatus(pendingDTO.getIsPending() ? "pending" : "cancelled");
|
||||||
|
orderDetailMapper.update(orderDetail, new LambdaUpdateWrapper<TbOrderDetail>()
|
||||||
|
.eq(TbOrderDetail::getShopId, pendingDTO.getIsPending())
|
||||||
|
.eq(TbOrderDetail::getOrderId, orderId));
|
||||||
|
|
||||||
|
TbOrderInfo orderInfo = new TbOrderInfo();
|
||||||
|
orderInfo.setId(orderId);
|
||||||
|
orderInfo.setStatus(pendingDTO.getIsPending() ? "pending" : "cancelled");
|
||||||
|
orderInfoMapper.updateById(orderInfo);
|
||||||
|
|
||||||
|
TbCashierCart cashierCart = new TbCashierCart();
|
||||||
|
cashierCart.setStatus(pendingDTO.getIsPending() ? "refund" : "create");
|
||||||
|
cashierCartMapper.update(cashierCart, new LambdaUpdateWrapper<TbCashierCart>()
|
||||||
|
.eq(TbCashierCart::getOrderId, orderId));
|
||||||
|
return orderInfo;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Object getCar(Integer shopId) {
|
||||||
|
return cashierCartMapper.selectCar(shopId);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Object getPayType(Integer shopId) {
|
||||||
|
return payTypeRepository.findByShopId(String.valueOf(shopId));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Object pay(PayDTO payDTO) {
|
||||||
|
TbOrderInfo orderInfo = orderInfoMapper.selectOne(new LambdaUpdateWrapper<TbOrderInfo>()
|
||||||
|
.eq(TbOrderInfo::getId, payDTO.getOrderId())
|
||||||
|
.eq(TbOrderInfo::getShopId, payDTO.getShopId()));
|
||||||
|
|
||||||
|
if (orderInfo == null) {
|
||||||
|
throw new BadRequestException("订单信息不存在");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!"unpaid".equals(orderInfo.getStatus())) {
|
||||||
|
return new BadRequestException("此订单不处于未支付状态");
|
||||||
|
}
|
||||||
|
|
||||||
|
// int count = shopInfoRepository.countSelectByShopIdAndPayType(orderInfo.getShopId(), "cash");
|
||||||
|
// if (count < 1) {
|
||||||
|
// return Result.fail(CodeEnum.PAYTYPENOEXIST);
|
||||||
|
// }
|
||||||
|
|
||||||
|
orderInfo.setPayAmount(orderInfo.getOrderAmount());
|
||||||
|
orderInfo.setPayType("cash");
|
||||||
|
orderInfo.setStatus("closed");
|
||||||
|
orderInfo.setPayOrderNo("cash".concat(SnowFlakeUtil.generateOrderNo()));
|
||||||
|
orderInfoMapper.updateById(orderInfo);
|
||||||
|
|
||||||
|
//更新购物车状态
|
||||||
|
TbCashierCart cashierCart = new TbCashierCart();
|
||||||
|
cashierCart.setStatus("final");
|
||||||
|
int cartCount = cashierCartMapper.update(cashierCart, new LambdaUpdateWrapper<TbCashierCart>()
|
||||||
|
.eq(TbCashierCart::getOrderId, payDTO.getOrderId()));
|
||||||
|
|
||||||
|
TbOrderDetail orderDetail = new TbOrderDetail();
|
||||||
|
orderDetail.setStatus("closed");
|
||||||
|
orderDetailMapper.update(orderDetail, new LambdaUpdateWrapper<TbOrderDetail>()
|
||||||
|
.eq(TbOrderDetail::getOrderId, payDTO.getOrderId()));
|
||||||
|
|
||||||
|
log.info("更新购物车:{}", cartCount);
|
||||||
|
|
||||||
|
JSONObject jsonObject = new JSONObject();
|
||||||
|
jsonObject.put("type", "create");
|
||||||
|
jsonObject.put("orderId", payDTO.getOrderId());
|
||||||
|
rabbitTemplate.convertAndSend(RabbitConstants.CART_ORDER_COLLECT_PUT, RabbitConstants.CART_ORDER_COLLECT_ROUTINGKEY_PUT, jsonObject.toJSONString(), new CorrelationData(UUID.randomUUID().toString()));
|
||||||
|
|
||||||
|
// 打印消息
|
||||||
|
rabbitTemplate.convertAndSend(RabbitConstants.PRINT_MECHINE_COLLECT_PUT, RabbitConstants.PRINT_MECHINE_COLLECT_ROUTINGKEY_PUT, payDTO.getOrderId().toString(), new CorrelationData(UUID.randomUUID().toString()));
|
||||||
|
|
||||||
|
// 发送库存记录mq消息
|
||||||
|
JSONObject mqData = new JSONObject();
|
||||||
|
mqData.put("orderId", payDTO.getOrderId());
|
||||||
|
mqData.put("type", "pc");
|
||||||
|
rabbitTemplate.convertAndSend(RabbitConstants.EXCHANGE_STOCK_RECORD, RabbitConstants.ROUTING_STOCK_RECORD_SALE, mqData.toJSONString(), new CorrelationData(UUID.randomUUID().toString()));
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -15,6 +15,7 @@
|
||||||
*/
|
*/
|
||||||
package cn.ysk.cashier.service.product;
|
package cn.ysk.cashier.service.product;
|
||||||
|
|
||||||
|
import cn.ysk.cashier.dto.rabbit.StockRecordMsg;
|
||||||
import cn.ysk.cashier.pojo.product.TbProductStockDetail;
|
import cn.ysk.cashier.pojo.product.TbProductStockDetail;
|
||||||
import cn.ysk.cashier.dto.product.TbProductStockDetailDto;
|
import cn.ysk.cashier.dto.product.TbProductStockDetailDto;
|
||||||
import cn.ysk.cashier.dto.product.TbProductStockDetailQueryCriteria;
|
import cn.ysk.cashier.dto.product.TbProductStockDetailQueryCriteria;
|
||||||
|
|
@ -88,4 +89,5 @@ public interface TbProductStockDetailService {
|
||||||
void download(List<TbProductStockDetailDto> all, HttpServletResponse response) throws IOException;
|
void download(List<TbProductStockDetailDto> all, HttpServletResponse response) throws IOException;
|
||||||
|
|
||||||
void addSaleRecord(Integer orderId);
|
void addSaleRecord(Integer orderId);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -111,4 +111,12 @@ public interface TbShopTableService {
|
||||||
Object createOrder(CreateOrderDTO createOrderDTO);
|
Object createOrder(CreateOrderDTO createOrderDTO);
|
||||||
|
|
||||||
Object getMasterId(Integer shopId, Long tableId, Integer vipUserId);
|
Object getMasterId(Integer shopId, Long tableId, Integer vipUserId);
|
||||||
|
|
||||||
|
Object pending(PendingDTO pendingDTO);
|
||||||
|
|
||||||
|
Object getCar(Integer shopId);
|
||||||
|
|
||||||
|
Object getPayType(Integer shopId);
|
||||||
|
|
||||||
|
Object pay(PayDTO payDTO);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,48 @@
|
||||||
|
package cn.ysk.cashier.utils;
|
||||||
|
|
||||||
|
import cn.hutool.core.lang.Snowflake;
|
||||||
|
import cn.hutool.core.util.IdUtil;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
|
||||||
|
import java.text.SimpleDateFormat;
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.Random;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Exrickx
|
||||||
|
*/
|
||||||
|
@Slf4j
|
||||||
|
public class SnowFlakeUtil {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 派号器workid:0~31
|
||||||
|
* 机房datacenterid:0~31
|
||||||
|
*/
|
||||||
|
private static Snowflake snowflake = IdUtil.createSnowflake(1, 1);
|
||||||
|
|
||||||
|
public static Long nextId() {
|
||||||
|
return snowflake.nextId();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
public static String generateOrderNo(){
|
||||||
|
String dateFormat="yyyyMMddHHmmssSSS";
|
||||||
|
SimpleDateFormat sm=new SimpleDateFormat(dateFormat);
|
||||||
|
|
||||||
|
String currentDate=sm.format(new Date());
|
||||||
|
|
||||||
|
Random rm=new Random();
|
||||||
|
int suffix=rm.nextInt(9999999);
|
||||||
|
|
||||||
|
return currentDate.concat(String.format("%07d",suffix));
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void main(String[] args){
|
||||||
|
for(int i=0;i<10;i++){
|
||||||
|
System.out.println(SnowFlakeUtil.generateOrderNo());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,17 @@
|
||||||
|
package cn.ysk.cashier.vo;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class CarVO {
|
||||||
|
private String masterId;
|
||||||
|
private String productName;
|
||||||
|
private String uuid;
|
||||||
|
private Integer shopId;
|
||||||
|
private String tableId;
|
||||||
|
private Integer userId;
|
||||||
|
private Long pendingAt;
|
||||||
|
private BigDecimal totalAmount;
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue