From bf2bffc884f00fd2ed2f16667ab6b91328012b8a Mon Sep 17 00:00:00 2001
From: 陶杰 <1378534974@qq.com>
Date: 星期二, 01 十月 2024 11:37:34 +0800
Subject: [PATCH] 1.订单商品评论 2.订单报表sql优化
---
src/main/java/com/mzl/flower/service/payment/OrderService.java | 96 ++++++++++++++++++++++++++++++++++++++++++++++--
1 files changed, 92 insertions(+), 4 deletions(-)
diff --git a/src/main/java/com/mzl/flower/service/payment/OrderService.java b/src/main/java/com/mzl/flower/service/payment/OrderService.java
index 3ebd8d4..47f3acb 100644
--- a/src/main/java/com/mzl/flower/service/payment/OrderService.java
+++ b/src/main/java/com/mzl/flower/service/payment/OrderService.java
@@ -12,8 +12,10 @@
import com.mzl.flower.config.security.SecurityUtils;
import com.mzl.flower.constant.Constants;
import com.mzl.flower.dto.PriceDTO;
+import com.mzl.flower.dto.request.comment.QueryFlowerCommentDTO;
import com.mzl.flower.dto.request.menber.MemberGrowthRecordDTO;
import com.mzl.flower.dto.request.payment.*;
+import com.mzl.flower.dto.response.comment.FlowerCommentVO;
import com.mzl.flower.dto.response.coupon.CouponRecordVO;
import com.mzl.flower.dto.response.flower.FlowerCartListDTO;
import com.mzl.flower.dto.response.flower.FlowerCartListWrapDTO;
@@ -43,6 +45,7 @@
import com.mzl.flower.mapper.system.UserWechatMapper;
import com.mzl.flower.mapper.warehouse.WarehouseLocationMapper;
import com.mzl.flower.service.BaseService;
+import com.mzl.flower.service.comment.FlowerCommentService;
import com.mzl.flower.service.coupon.CouponRecordService;
import com.mzl.flower.service.flower.FlowerService;
import com.mzl.flower.service.menber.MemberGrowthRecordService;
@@ -51,6 +54,7 @@
import com.mzl.flower.service.system.CodeService;
import com.mzl.flower.service.system.WeChatService;
import com.mzl.flower.service.transport.TransportService;
+import com.mzl.flower.utils.ExcelExportUtil;
import com.mzl.flower.utils.UUIDGenerator;
import com.wechat.pay.java.core.util.GsonUtil;
import io.micrometer.core.instrument.util.StringUtils;
@@ -63,8 +67,10 @@
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.ObjectUtils;
+import javax.servlet.http.HttpServletResponse;
import java.math.BigDecimal;
import java.math.RoundingMode;
+import java.net.URLEncoder;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
@@ -161,6 +167,9 @@
@Autowired
private CouponRecordService couponRecordService;
+ @Autowired
+ private FlowerCommentService flowerCommentService;
+
public void changeFlower2Cart(CartSaveDTO dto) {
String userId = SecurityUtils.getUserId();
@@ -193,7 +202,7 @@
Integer completeNumToday=getFlowerCompleteNumToday(userId,c.getFlowerId());
Integer tmp=completeNumToday+c.getNum();
if(null!=tmp && null!=flowerDetail.getLimited()
- && tmp.compareTo(flowerDetail.getLimited())>0){
+ && tmp.compareTo(flowerDetail.getLimited())>0){
throw new ValidationException("当天的订单的花数量加上购物车的数量不能超过限售数量!");
}
@@ -205,7 +214,7 @@
// 限购 1.首先查看购物车中的数量是否已经超过限售数量
if(null!=c.getNum() && null!=flowerDetail.getLimited()
- && c.getNum().compareTo(flowerDetail.getLimited())>0){
+ && c.getNum().compareTo(flowerDetail.getLimited())>0){
throw new ValidationException("数量不能超过限售数量!");
}
@@ -213,7 +222,7 @@
Integer completeNumToday=getFlowerCompleteNumToday(userId,c.getFlowerId());
Integer tmp=completeNumToday+c.getNum();
if(null!=tmp && null!=flowerDetail.getLimited()
- && tmp.compareTo(flowerDetail.getLimited())>0){
+ && tmp.compareTo(flowerDetail.getLimited())>0){
throw new ValidationException("当天的订单的花数量加上购物车的数量不能超过限售数量!");
}
@@ -1132,6 +1141,7 @@
new QueryWrapper<OrderItem>().eq("order_id", id));
Map<Long, String> stationMap = prepareStationMap();
+ Map<String, FlowerCommentVO> commentMap=prepareCommentMap(id);
List<OrderItemListDTO> result = new ArrayList<>();
for (OrderItem oi : ls) {
@@ -1140,10 +1150,35 @@
dto.setStationName(stationMap.get(oi.getStationId()));
+ // 评论
+ final FlowerCommentVO flowerCommentVO = commentMap.get(oi.getId());
+ copyCommentInfo(dto,flowerCommentVO);
+
result.add(dto);
}
return result;
+ }
+
+ private Map<String, FlowerCommentVO> prepareCommentMap(String orderId) {
+ QueryFlowerCommentDTO queryFlowerCommentDTO = new QueryFlowerCommentDTO();
+ queryFlowerCommentDTO.setOrderId(orderId);
+ final List<FlowerCommentVO> list = flowerCommentService.getList(queryFlowerCommentDTO);
+ if (list == null || list.isEmpty()) {
+ return Collections.emptyMap();
+ }
+ // 将 List 转换为 Map,其中 key 为 FlowerCommentVO 的 id
+ return list.stream().collect(Collectors.toMap(FlowerCommentVO::getOrderItemId, item -> item));
+ }
+
+
+ private void copyCommentInfo(OrderItemListDTO dto,FlowerCommentVO flowerCommentVO){
+ if(null != dto && null!=flowerCommentVO){
+ dto.setCommentGrade(flowerCommentVO.getCommentGrade());
+ dto.setComment(flowerCommentVO.getComment());
+ dto.setCommentImages(flowerCommentVO.getCommentImages());
+ dto.setAnonymityFalg(flowerCommentVO.getAnonymityFalg());
+ }
}
public List<Order> autoReceive() {
@@ -1675,7 +1710,7 @@
// 新增
cartMapper.updateById(cart);
}else{
- // 更新
+ // 更新
cartMapper.insert(cart);
}
}
@@ -1705,4 +1740,57 @@
orderMapper.updateById(order);
}
+ private List<OrderListExportDTO> getOrderExportListBase(OrderQueryDTO dto) {
+ dto.setStartDate(parseLocalDateTime(dto.getStartDateStr(), true));
+ dto.setEndDate(parseLocalDateTime(dto.getEndDateStr(), false));
+ dto.setCreateStartDate(parseLocalDateTime(dto.getCreateStartDateStr(), 17, 0, 0, -1));
+ dto.setCreateEndDate(parseLocalDateTime(dto.getCreateEndDateStr(), 17, 0, 0, 0));
+ List<OrderListExportDTO> ls = orderMapper.selectOrderExportList(dto);
+ return ls;
+ }
+
+ public void exportOrderDetail(HttpServletResponse response, OrderQueryDTO dto) {
+ List<OrderListExportDTO> ls = getOrderExportListBase( dto);
+ String[] rowsName = new String[]{"序号","订单号", "用户账号", "收货人", "收货人电话", "收货地址", "订单金额"
+ , "底价", "订单状态", "下单时间", "合伙人", "库位", "特殊需求", "备注"};
+ List<Object[]> dataList = new ArrayList<>();
+ int sn = 1;
+ for (OrderListExportDTO o : ls) {
+ Object[] objs = new Object[rowsName.length];
+ int a = 0;
+ objs[a++] = sn;
+ objs[a++] = o.getOrderNo();
+ objs[a++] = o.getCreateName();
+ objs[a++] = o.getCustomer();
+ objs[a++] = o.getCustomerTel();
+ objs[a++] = o.getCustomerAddress();
+ objs[a++] = o.getTotalAmount();
+ objs[a++] = o.getSupplierAmount();
+ objs[a++] = o.getStatusBackendStr();
+ objs[a++] = o.getCreateTime();
+ objs[a++] = o.getPartnerName();
+ objs[a++] = o.getWarehouseLocationCode();
+ objs[a++] = o.getSpecialNeedsStr();
+ objs[a++] = o.getRemarks();
+ dataList.add(objs);
+
+ sn++;
+ }
+ ExcelExportUtil excelExportUtil = new ExcelExportUtil("订单列表", rowsName, dataList, response);
+ try {
+ response.addHeader("filename", URLEncoder.encode("订单列表.xls", "UTF-8"));
+ response.addHeader("Access-Control-Expose-Headers", "filename");
+ excelExportUtil.export();
+ } catch (Exception e) {
+ log.error(e.getMessage(), e);
+ }
+
+ }
+
+ public void exportPartnerOrderList(HttpServletResponse response, OrderQueryDTO dto) {
+ Partner p = getCurrentPartner();
+ dto.setPartnerId(p.getId());
+ exportOrderDetail(response, dto);
+ }
+
}
--
Gitblit v1.9.3