1.数据报表导出cpu拉高问题修复

2.代客下单相关接口
This commit is contained in:
2024-08-13 14:39:32 +08:00
parent e53037232f
commit a7de11423f
8 changed files with 192 additions and 14 deletions

View File

@@ -257,6 +257,15 @@ public class RedisUtils {
}
}
public boolean setNx(String key, Object value) {
try {
return redisTemplate.opsForValue().setIfAbsent(key, value);
} catch (Exception e) {
log.error(e.getMessage(), e);
return false;
}
}
/**
* 普通缓存放入并设置时间
*

View File

@@ -2,10 +2,7 @@ package cn.ysk.cashier.controller.product;
import cn.ysk.cashier.annotation.AnonymousAccess;
import cn.ysk.cashier.annotation.Log;
import cn.ysk.cashier.dto.shoptable.AddCartDTO;
import cn.ysk.cashier.dto.shoptable.ClearCartDTO;
import cn.ysk.cashier.dto.shoptable.RemoveCartDTO;
import cn.ysk.cashier.dto.shoptable.UpdateCartDTO;
import cn.ysk.cashier.dto.shoptable.*;
import cn.ysk.cashier.pojo.order.TbCashierCart;
import cn.ysk.cashier.service.product.TbProductService;
import cn.ysk.cashier.service.shop.TbShopTableService;
@@ -63,6 +60,14 @@ public class TbPlaceController {
return ResponseEntity.ok(tbShopTableService.updateCart(updateCartDTO));
}
@AnonymousAccess
@PutMapping("/pack")
@Log("代客下单")
@ApiOperation("代客下单/shop/table")
public ResponseEntity<TbCashierCart> pack(@Valid @RequestBody PackCartDTO packCartDTO) {
tbShopTableService.pack(packCartDTO);
return ResponseEntity.ok(null);
}
@AnonymousAccess
@DeleteMapping("/removeCart")
@@ -95,4 +100,27 @@ public class TbPlaceController {
return ResponseEntity.ok(tbShopTableService.getCart(tableId, page, size, shopId));
}
@AnonymousAccess
@GetMapping("/masterId")
@Log("代客下单 查询购物车")
@ApiOperation("代客下单 ")
public ResponseEntity<Object> getMasterId(
@RequestParam Long tableId,
@RequestParam Integer shopId
) {
return ResponseEntity.ok(tbShopTableService.getMasterId(tableId, shopId));
}
@AnonymousAccess
@PostMapping("/order")
@Log("代客下单 查询购物车")
@ApiOperation("代客下单 查询购物车 /shop/table")
public ResponseEntity<Object> createOrder(
@RequestBody CreateOrderDTO createOrderDTO
) {
return ResponseEntity.ok(tbShopTableService.createOrder(createOrderDTO));
}
}

View File

@@ -0,0 +1,15 @@
package cn.ysk.cashier.dto.shoptable;
import lombok.Data;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
@Data
public class CreateOrderDTO {
@NotNull
private Integer shopId;
@NotEmpty
private String tableId;
private String note;
}

View File

@@ -0,0 +1,18 @@
package cn.ysk.cashier.dto.shoptable;
import lombok.Data;
import org.hibernate.validator.constraints.Range;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
@Data
public class PackCartDTO {
@NotNull
private Integer shopId;
@NotEmpty
private String tableId;
@NotNull
@Range(min = 0, max = 1)
private Integer state;
}

View File

@@ -37,6 +37,19 @@ public interface TbOrderDetailRepository extends JpaRepository<TbOrderDetail, In
@Query("SELECT cart FROM TbOrderDetail cart WHERE cart.orderId in :ids")
List<TbOrderDetail> searchDetailByOrderIds(@Param("ids")List<Integer> ids);
@Query(value = "SELECT " +
"new cn.ysk.cashier.vo.TbOrderSaleVO(oi.orderNo, od.num, od.price, od.status, 0)\n" +
"FROM\n" +
"TbOrderInfo oi\n" +
"LEFT JOIN TbOrderDetail od ON oi.id = od.orderId \n" +
"WHERE\n" +
"od.shopId = :shopId \n" +
"AND ( od.status = 'closed' OR od.status = 'refund' ) \n" +
"AND od.createTime > :startTime \n" +
"AND od.createTime < :endTime \n" +
"AND (:productId is null or od.productId = :productId)\n" +
"AND (:productId is null or od.productSkuId = :productSkuId)")
List<TbOrderSaleVO> querySaleOrderInfo(@Param("startTime") Timestamp startTime, @Param("endTime") Timestamp endTime, @Param("productId") Integer productId, @Param("productSkuId") Integer productSkuId, @Param("shopId") Integer shopId);
@Query("SELECT new cn.ysk.cashier.vo.TbOrderSalesCountByDayVo(" +

View File

@@ -465,11 +465,14 @@ public class SummaryServiceImpl implements SummaryService {
}
}
tbOrderSalesCountByDayVos.parallelStream().forEach(all -> {
tbOrderSalesCountByDayVos.forEach(all -> {
List<TbOrderSaleVO> tbOrderSaleVOS = saleOrderMap.get(all.getProductSkuId().toString());
if (tbOrderSaleVOS == null) {
return;
}
// List<TbOrderSaleVO> tbOrderSaleVOS = detailRepository.querySaleOrderInfo(new Timestamp(summaryDto.getStartTime().getTime()),
// new Timestamp(summaryDto.getEndTime().getTime()), all.getProductId(), all.getProductSkuId(), Integer.valueOf(summaryDto.getShopId()));
for (TbOrderSaleVO tbOrderSaleVO : tbOrderSaleVOS) {
Map<String, Object> map = new LinkedHashMap<>();
map.put("商品分类", all.getCateName());

View File

@@ -17,10 +17,7 @@ package cn.ysk.cashier.service.impl.shopimpl;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.date.DateUtil;
import cn.ysk.cashier.dto.shoptable.AddCartDTO;
import cn.ysk.cashier.dto.shoptable.ClearCartDTO;
import cn.ysk.cashier.dto.shoptable.RemoveCartDTO;
import cn.ysk.cashier.dto.shoptable.UpdateCartDTO;
import cn.ysk.cashier.dto.shoptable.*;
import cn.ysk.cashier.exception.BadRequestException;
import cn.ysk.cashier.mybatis.mapper.TbCashierCartMapper;
import cn.ysk.cashier.mybatis.mapper.TbProductMapper;
@@ -31,8 +28,10 @@ import cn.ysk.cashier.pojo.shop.TbShopTable;
import cn.ysk.cashier.repository.order.TbCashierCartRepository;
import cn.ysk.cashier.repository.product.TbProductRepository;
import cn.ysk.cashier.repository.product.TbProductSkuRepository;
import cn.ysk.cashier.utils.RedisUtils;
import cn.ysk.cashier.utils.ValidationUtil;
import cn.ysk.cashier.utils.FileUtil;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.dianguang.cloud.ossservice.model.DateUtils;
import lombok.RequiredArgsConstructor;
@@ -42,6 +41,7 @@ import cn.ysk.cashier.dto.shop.TbShopTableDto;
import cn.ysk.cashier.dto.shop.TbShopTableQueryCriteria;
import cn.ysk.cashier.mapper.shop.TbShopTableMapper;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.data.domain.PageRequest;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@@ -73,6 +73,7 @@ public class TbShopTableServiceImpl implements TbShopTableService {
private final TbCashierCartRepository cashierCartRepository;
private final TbProductMapper productMapper;
private final TbCashierCartMapper cashierCartMapper;
private final RedisUtils redisUtils;
/**
*桌码前缀
@@ -302,6 +303,22 @@ public class TbShopTableServiceImpl implements TbShopTableService {
tbCashierCart.setCategoryId(product.getCategoryId());
cashierCartRepository.save(tbCashierCart);
}else {
tbCashierCart.setTotalAmount(new BigDecimal(addCartDTO.getNum()).multiply(productSku.getSalePrice()));
if (!addCartDTO.isPack()){
tbCashierCart.setPackFee(BigDecimal.ZERO);
}else {
tbCashierCart.setPackFee(new BigDecimal(addCartDTO.getNum()).multiply(product.getPackFee()));
tbCashierCart.setTotalAmount(tbCashierCart.getTotalAmount().add(tbCashierCart.getPackFee()));
}
if (addCartDTO.isGift()) {
tbCashierCart.setTotalAmount(BigDecimal.ZERO);
}
tbCashierCart.setIsPack(String.valueOf(addCartDTO.isPack()));
tbCashierCart.setIsGift(String.valueOf(addCartDTO.isGift()));
tbCashierCart.setTotalNumber(addCartDTO.getNum());
tbCashierCart.setNumber(addCartDTO.getNum());
// 数量0删除
@@ -310,7 +327,6 @@ public class TbShopTableServiceImpl implements TbShopTableService {
return null;
}
tbCashierCart.setUpdatedAt(DateUtil.current());
tbCashierCart.setTotalAmount(new BigDecimal(addCartDTO.getNum()).multiply(productSku.getSalePrice()));
cashierCartRepository.save(tbCashierCart);
}
@@ -359,4 +375,77 @@ public class TbShopTableServiceImpl implements TbShopTableService {
}
return cartPage;
}
@Override
public void pack(PackCartDTO packCartDTO) {
List<TbCashierCart> tbCashierCarts = cashierCartMapper.selectList(new LambdaQueryWrapper<TbCashierCart>().eq(TbCashierCart::getTableId, packCartDTO.getTableId())
.eq(TbCashierCart::getShopId, packCartDTO.getShopId())
.eq(TbCashierCart::getStatus, "create"));
tbCashierCarts.forEach(item -> {
if (packCartDTO.getState().equals(0) && item.getIsPack().equals("true")) {
item.setIsPack("false");
item.setTotalAmount(item.getTotalAmount().subtract(item.getPackFee()));
}else {
item.setIsPack("true");
item.setTotalAmount(item.getTotalAmount().add(item.getPackFee()));
}
cashierCartMapper.updateById(item);
});
}
@Override
public Object createOrder(CreateOrderDTO createOrderDTO) {
// 生成取餐码
String day = DateUtils.getDay();
return null;
}
public synchronized String generateOrderCode(String day, String clientType, String shopId) {
String code = redisUtils.get("SHOP:CODE:" + clientType + ":" + shopId + ":" + day)+"";
// 使用顺序递增的计数器生成取餐码
String orderCode = "";
if (StringUtils.isEmpty(code) || "null".equals(code)) {
orderCode = "1";
redisUtils.set("SHOP:CODE:" + clientType + ":" + shopId + ":" + day,"1");
} else {
orderCode =String.valueOf(Integer.parseInt(code)+1);
}
redisUtils.set("SHOP:CODE:" + clientType + ":" + shopId + ":" + day, "#" + Integer.parseInt(code.replace("#", "")) + 2);
boolean flag = redisUtils.setNx("SHOP:CODE:SET" + clientType + ":" + shopId + ":" + day, orderCode);
if (flag){
return generateOrderCode(day,clientType,shopId);
}
// 增加计数器
return orderCode;
}
// @Override
// public Object getMasterId(Long tableId, Integer shopId) {
// String day = DateUtils.getDay();
// JSONObject jsonObject = new JSONObject();
// String key="SHOP:CODE:USER:pc" + ":" + shopId + ":" + day + userId;
// String userCode = redisUtils.get(key)+"";
// if ("1".equals(type)) {
// String code = "#" + generateOrderCode(day, clientType, shopId);
// redisUtil.saveMessage(key, code);
// jsonObject.put("code", code);
// } else {
// if (StringUtils.isEmpty(userCode)||"null".equals(userCode)||"#null".equals(userCode)) {
// String code = "#" + generateOrderCode(day, clientType, shopId);
// redisUtil.saveMessage(key, code);
// jsonObject.put("code", code);
// } else {
// jsonObject.put("code", userCode);
// }
// }
// }
@Override
public Object getMasterId(Long tableId, Integer shopId) {
return null;
}
}

View File

@@ -15,10 +15,7 @@
*/
package cn.ysk.cashier.service.shop;
import cn.ysk.cashier.dto.shoptable.AddCartDTO;
import cn.ysk.cashier.dto.shoptable.ClearCartDTO;
import cn.ysk.cashier.dto.shoptable.RemoveCartDTO;
import cn.ysk.cashier.dto.shoptable.UpdateCartDTO;
import cn.ysk.cashier.dto.shoptable.*;
import cn.ysk.cashier.pojo.order.TbCashierCart;
import cn.ysk.cashier.pojo.shop.TbShopTable;
import cn.ysk.cashier.dto.shop.TbShopTableDto;
@@ -108,4 +105,10 @@ public interface TbShopTableService {
Page<TbCashierCart> getCart(Long tableId, Integer page, Integer size, Integer shopId);
TbCashierCart updateCart(UpdateCartDTO updateCartDTO);
void pack(PackCartDTO packCartDTO);
Object createOrder(CreateOrderDTO createOrderDTO);
Object getMasterId(Long tableId, Integer shopId);
}