From 0c9521d93a745de0ec71d83c094a6047c0222398 Mon Sep 17 00:00:00 2001
From: peng <peng.com>
Date: 星期三, 29 十月 2025 15:01:51 +0800
Subject: [PATCH] 调整
---
framework/src/main/java/cn/lili/modules/order/order/serviceimpl/OrderServiceImpl.java | 283 ++++++++++++++++++++++++++++++++++++++++++++++++++++----
1 files changed, 261 insertions(+), 22 deletions(-)
diff --git a/framework/src/main/java/cn/lili/modules/order/order/serviceimpl/OrderServiceImpl.java b/framework/src/main/java/cn/lili/modules/order/order/serviceimpl/OrderServiceImpl.java
index 3dfac11..38fc343 100644
--- a/framework/src/main/java/cn/lili/modules/order/order/serviceimpl/OrderServiceImpl.java
+++ b/framework/src/main/java/cn/lili/modules/order/order/serviceimpl/OrderServiceImpl.java
@@ -17,28 +17,25 @@
import cn.lili.common.event.TransactionCommitSendMQEvent;
import cn.lili.common.exception.ServiceException;
import cn.lili.common.properties.RocketmqCustomProperties;
-import cn.lili.common.security.AuthUser;
import cn.lili.common.security.OperationalJudgment;
import cn.lili.common.security.context.UserContext;
import cn.lili.common.security.enums.UserEnums;
import cn.lili.common.utils.CurrencyUtil;
import cn.lili.common.utils.SnowFlake;
import cn.lili.common.utils.StringUtils;
-import cn.lili.common.vo.ResultMessage;
import cn.lili.modules.goods.entity.dos.Goods;
import cn.lili.modules.goods.entity.dos.GoodsSku;
import cn.lili.modules.goods.entity.dto.GoodsCompleteMessage;
import cn.lili.modules.goods.service.GoodsService;
import cn.lili.modules.goods.service.GoodsSkuService;
import cn.lili.modules.lmk.domain.entity.CouponVirtual;
-import cn.lili.modules.lmk.domain.vo.OrderCountByDayAndHourVO;
import cn.lili.modules.lmk.domain.vo.OrderCountVO;
import cn.lili.modules.lmk.enums.general.AdminRoleEnum;
import cn.lili.modules.lmk.enums.general.VirtualGoodsTypeEnum;
import cn.lili.modules.lmk.mapper.LmkOrderSelectMapper;
import cn.lili.modules.lmk.service.CouponVirtualService;
-import cn.lili.modules.member.entity.dos.Member;
import cn.lili.modules.member.entity.dto.MemberAddressDTO;
+import cn.lili.modules.member.entity.dto.UpdateTracesDTO;
import cn.lili.modules.member.mapper.MemberMapper;
import cn.lili.modules.order.cart.entity.dto.TradeDTO;
import cn.lili.modules.order.cart.entity.enums.DeliveryMethodEnum;
@@ -52,9 +49,7 @@
import cn.lili.modules.order.trade.entity.dos.OrderLog;
import cn.lili.modules.order.trade.service.OrderLogService;
import cn.lili.modules.payment.entity.enums.PaymentMethodEnum;
-import cn.lili.modules.permission.entity.dos.AdminUser;
import cn.lili.modules.permission.service.AdminUserService;
-import cn.lili.modules.permission.service.RoleService;
import cn.lili.modules.promotion.entity.dos.Coupon;
import cn.lili.modules.promotion.entity.dos.Pintuan;
import cn.lili.modules.promotion.service.CouponService;
@@ -92,7 +87,6 @@
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
-import io.reactivex.rxjava3.core.Maybe;
import lombok.extern.slf4j.Slf4j;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Row;
@@ -117,13 +111,10 @@
import java.math.RoundingMode;
import java.net.URLEncoder;
import java.text.SimpleDateFormat;
-import java.time.LocalDate;
-import java.time.LocalDateTime;
-import java.time.LocalTime;
import java.util.*;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;
-import cn.lili.modules.permission.entity.dos.Role;
+
/**
* 瀛愯鍗曚笟鍔″眰瀹炵幇
*
@@ -284,6 +275,9 @@
String couponName = skuInfo.getCouponName();
orderItem.setCouponId(couponId);
orderItem.setCouponName(couponName);
+ }//璁㈠崟涓湁瀹氬埗鍟嗗搧灏嗚鍗曟敼涓哄畾鍒跺晢鍝�
+ else if (CustomizeFlagEnum.CUSTOMIZE.name().equals(skuInfo.getCustomizeFlag())) {
+ order.setCustomizeFlag(CustomizeFlagEnum.CUSTOMIZE.name());
}
}
orderItems.add(orderItem);
@@ -345,6 +339,23 @@
queryWrapper.groupBy("o.id");
queryWrapper.orderByDesc("o.id");
IPage<OrderSimpleVO> page = this.baseMapper.queryByParams(PageUtil.initPage(orderSearchParams), queryWrapper);
+ if (needHide){
+ if (!adminUserService.havePermissionRole(AdminRoleEnum.ORDER_INFO_PERMISSION)){
+ for (OrderSimpleVO vo : page.getRecords()){
+ vo.setConsigneeName(CommonUtil.maskName(vo.getConsigneeName()));
+ vo.setConsigneeMobile(CommonUtil.maskMobile(vo.getConsigneeMobile()));
+ }
+ }
+ }
+
+ return page;
+ }
+ @Override
+ public IPage<OrderSimpleVO> queryShareMineOrder(OrderSearchParams orderSearchParams,Boolean needHide) {
+ QueryWrapper queryWrapper = orderSearchParams.queryWrapper();
+ queryWrapper.groupBy("o.id");
+ queryWrapper.orderByDesc("o.id");
+ IPage<OrderSimpleVO> page = this.baseMapper.queryByShareParams(PageUtil.initPage(orderSearchParams), queryWrapper);
if (needHide){
if (!adminUserService.havePermissionRole(AdminRoleEnum.ORDER_INFO_PERMISSION)){
for (OrderSimpleVO vo : page.getRecords()){
@@ -497,6 +508,35 @@
@Override
public void queryExportOrder(HttpServletResponse response, OrderSearchParams orderSearchParams) {
List<OrderExportDTO> orderExportDTOS = this.baseMapper.queryExportOrder(orderSearchParams.queryWrapper());
+
+ if (!adminUserService.havePermissionRole(AdminRoleEnum.ORDER_INFO_PERMISSION)){
+ for (OrderExportDTO vo : orderExportDTOS){
+ vo.setConsigneeName(CommonUtil.maskName(vo.getConsigneeName()));
+ vo.setConsigneeMobile(CommonUtil.maskMobile(vo.getConsigneeMobile()));
+ }
+ }
+ XSSFWorkbook workbook = initOrderExportData(orderExportDTOS);
+ try {
+ // 璁剧疆鍝嶅簲澶�
+ String fileName = URLEncoder.encode("璁㈠崟鍒楄〃", "UTF-8");
+ response.setContentType("application/vnd.ms-excel;charset=UTF-8");
+ response.setHeader("Content-Disposition", "attachment;filename=" + fileName + ".xlsx");
+
+ ServletOutputStream out = response.getOutputStream();
+ workbook.write(out);
+ } catch (Exception e) {
+ e.printStackTrace();
+ } finally {
+ try {
+ workbook.close();
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+ }
+ @Override
+ public void queryShareExportOrder(HttpServletResponse response, OrderSearchParams orderSearchParams) {
+ List<OrderExportDTO> orderExportDTOS = this.baseMapper.queryShareExportOrder(orderSearchParams.queryWrapper());
if (!adminUserService.havePermissionRole(AdminRoleEnum.ORDER_INFO_PERMISSION)){
for (OrderExportDTO vo : orderExportDTOS){
@@ -820,6 +860,26 @@
}
@Override
+ public void updateTraces(UpdateTracesDTO updateTracesDTO) {
+ LambdaQueryWrapper<OrderPackage> eq = Wrappers.<OrderPackage>lambdaQuery()
+ .eq(OrderPackage::getOrderSn, updateTracesDTO.getOrderSn())
+ .eq(OrderPackage::getPackageNo, updateTracesDTO.getPackageNo());
+ OrderPackage one = orderPackageService.getOne(eq);
+ if (one == null) {
+ throw new ServiceException("褰撳墠鍖呰9涓嶅瓨鍦�");
+ }
+
+ String logisticsId = updateTracesDTO.getLogisticsId();
+ if (StringUtils.isNotBlank(logisticsId)) {
+ Logistics logic = logisticsService.getById(logisticsId);
+ one.setLogisticsNo(updateTracesDTO.getLogisticsNo());
+ one.setLogisticsCode(logic.getCode());
+ one.setLogisticsName(logic.getName());
+ orderPackageService.updateById(one);
+ }
+ }
+
+ @Override
public Traces getMapTraces(String orderSn) {
//鑾峰彇璁㈠崟淇℃伅
Order order = this.getBySn(orderSn);
@@ -1115,7 +1175,31 @@
checkBatchDeliver(orderBatchDeliverDTOList);
//璁㈠崟鎵归噺鍙戣揣
for (OrderBatchDeliverDTO orderBatchDeliverDTO : orderBatchDeliverDTOList) {
- this.delivery(orderBatchDeliverDTO.getOrderSn(), orderBatchDeliverDTO.getLogisticsNo(), orderBatchDeliverDTO.getLogisticsId());
+ String logisticsNo = orderBatchDeliverDTO.getLogisticsNo();
+ String[] split = logisticsNo.split(",");
+ //濡傛灉鐗╂祦鍗曞彿鍖呭惈澶氫釜锛屽垯杩涜鎷嗗崟
+ if (split.length > 1) {
+ for (int i = 0; i < split.length; i++) {
+ PartDeliveryParamsDTO partDeliveryParamsDTO = new PartDeliveryParamsDTO();
+ partDeliveryParamsDTO.setOrderSn(orderBatchDeliverDTO.getOrderSn());
+ partDeliveryParamsDTO.setLogisticsNo(split[i]);
+ partDeliveryParamsDTO.setLogisticsId(orderBatchDeliverDTO.getLogisticsId());
+ ArrayList<PartDeliveryDTO> partDeliveryDTOList = new ArrayList<>();
+ partDeliveryParamsDTO.setPartDeliveryDTOList(partDeliveryDTOList);
+ if (i == split.length - 1){
+ List<OrderItem> orderItemList = orderItemService.getByOrderSn(orderBatchDeliverDTO.getOrderSn());
+ for (OrderItem orderItem : orderItemList) {
+ if (RefundStatusEnum.NO_REFUND.name().equals(orderItem.getIsRefund())) {
+ PartDeliveryDTO partDeliveryDTO = new PartDeliveryDTO();
+ partDeliveryDTO.setDeliveryNum(orderItem.getNum());
+ partDeliveryDTO.setOrderItemId(orderItem.getId());
+ partDeliveryDTOList.add(partDeliveryDTO);
+ }
+ }
+ }
+ this.partDelivery(partDeliveryParamsDTO);
+ }
+ }
}
}
@@ -1406,7 +1490,7 @@
}
}
- List<Map<String, Object>> maps = lmkOrderSelectMapper.selectOrderCountByDay(startTime,endTime);
+ List<Map<String, Object>> maps = lmkOrderSelectMapper.selectOrderCountByDay(startTime,endTime,queryParam.getStoreId());
Map<String, Long> dayCountMap = maps.stream()
.collect(Collectors.toMap(
@@ -1501,32 +1585,184 @@
- List<Map<String, Object>> maps = lmkOrderSelectMapper.selectOrderTimePeriod(startTime,endTime);
- List<Map<String,Object>> countMap = lmkOrderSelectMapper.selectViewDataCount(startTime,endTime);
+ List<Map<String, Object>> maps = lmkOrderSelectMapper.selectOrderTimePeriod(startTime,endTime,queryParam.getStoreId());
+ List<String> goodsIds = new ArrayList<>();
+ //濡傛灉鏌ヨ鏉′欢甯︿簡搴楅摵 鏌ヨ搴楅摵鐨勫晢鍝�
+ if (StringUtils.isNotBlank(queryParam.getStoreId())){
+ List<Goods> list = new LambdaQueryChainWrapper<>(goodsService.getBaseMapper())
+ .eq(Goods::getDeleteFlag, Boolean.FALSE)
+ .eq(Goods::getStoreId, queryParam.getStoreId())
+ .list();
+ goodsIds = list.stream().map(Goods::getId).collect(Collectors.toList());
+ }
+
+
+ List<Map<String,Object>> countMap = lmkOrderSelectMapper.selectViewDataCount(startTime,endTime,queryParam.getStoreId(),goodsIds);
+
+
Map<String, Long> countByDayHour = maps.stream()
.collect(Collectors.toMap(
map -> map.get("hour").toString(),
map -> Long.valueOf(map.get("count").toString()),
Long::sum // 濡傛灉鏈夐噸澶嶏紝绱姞count
));
- System.out.println("鎵撳嵃璁板綍---------------------------------------");
- System.out.println(countMap);
- System.out.println("---------------------------------------");
+ Map<String, Long> viewDataCountByDayHour = countMap.stream()
+ .collect(Collectors.toMap(
+ map -> map.get("hour").toString(),
+ map -> Long.valueOf(map.get("count").toString()),
+ Long::sum
+ ));
// 閬嶅巻鏌ョ湅缁撴灉
List<Long> countList = new ArrayList<>();
+ List<Long> viewData = new ArrayList<>();
for (int i = 0; i < 24; i++) {
String hourKey = String.valueOf(i);
+ Long viewDataCount = viewDataCountByDayHour.getOrDefault(hourKey,0L);
Long count = countByDayHour.getOrDefault(hourKey, 0L);
countList.add(count);
+ viewData.add(viewDataCount);
}
Map<String,Object> map = new HashMap<>();
map.put("dateData",dateList);
map.put("countData",countList);
- //TODO 娴忚鏁版嵁鏈姞鍏�
-// map.put();
+ map.put("viewData",viewData);
return Result.ok().data(map);
+ }
+ @Override
+ public Result getPvUv(StatisticsQueryParam queryParam) {
+ Date startTime = null;
+ Date endTime = new Date(); // 缁撴潫鏃堕棿榛樿鏄綋鍓嶆椂闂�
+ List<String> dateList = new ArrayList<>();
+ Calendar calendar = Calendar.getInstance(); // 鐢ㄤ簬鏃ユ湡璁$畻鐨勬棩鍘嗗疄渚�
+ SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
+ int days = 0;
+ if (queryParam.getYear() != null && queryParam.getMonth() != null) {
+ Date[] dates =CommonUtil.getMonthStartAndEnd(queryParam.getYear(),queryParam.getMonth());
+ startTime = dates[0];
+ endTime = dates[1];
+ Calendar tempCalendar = Calendar.getInstance();
+ tempCalendar.setTime(startTime);
+ days = tempCalendar.getActualMaximum(Calendar.DAY_OF_MONTH);
+ for (int i = 0; i < days; i++) {
+ dateList.add(sdf.format(tempCalendar.getTime()));
+ tempCalendar.add(Calendar.DATE, 1); // 姣忓ぉ绱姞1澶�
+ }
+ }else{
+ switch (queryParam.getSearchType()) {
+ case "TODAY":
+ // 浠婂ぉ锛氫粠浠婂ぉ0鐐瑰埌鐜板湪
+ calendar.setTime(new Date()); // 閲嶇疆涓哄綋鍓嶆椂闂�
+ calendar.set(Calendar.HOUR_OF_DAY, 0); // 灏忔椂璁句负0锛�24灏忔椂鍒讹級
+ calendar.set(Calendar.MINUTE, 0); // 鍒嗛挓璁句负0
+ calendar.set(Calendar.SECOND, 0); // 绉掕涓�0
+ calendar.set(Calendar.MILLISECOND, 0); // 姣璁句负0
+ startTime = calendar.getTime(); // 寰楀埌浠婂ぉ0鐐圭殑Date瀵硅薄
+ dateList.add(sdf.format(startTime));
+ break;
+ case "YESTERDAY":
+ // 鏄ㄥぉ锛氫粠鏄ㄥぉ0鐐瑰埌鏄ㄥぉ23:59:59.999
+ calendar.setTime(new Date());
+ calendar.add(Calendar.DATE, -1); // 鏃ユ湡鍑�1澶╋紙鍙樹负鏄ㄥぉ锛�
+
+ // 璁剧疆鏄ㄥぉ0鐐�
+ calendar.set(Calendar.HOUR_OF_DAY, 0);
+ calendar.set(Calendar.MINUTE, 0);
+ calendar.set(Calendar.SECOND, 0);
+ calendar.set(Calendar.MILLISECOND, 0);
+ startTime = calendar.getTime();
+
+ // 璁剧疆鏄ㄥぉ23:59:59.999
+ calendar.set(Calendar.HOUR_OF_DAY, 23);
+ calendar.set(Calendar.MINUTE, 59);
+ calendar.set(Calendar.SECOND, 59);
+ calendar.set(Calendar.MILLISECOND, 999);
+ endTime = calendar.getTime();
+ dateList.add(sdf.format(startTime));
+ break;
+ case "LAST_SEVEN":
+ // 杩囧幓涓冨ぉ锛氫粠7澶╁墠0鐐瑰埌鐜板湪锛堝惈浠婂ぉ鍏�7澶╋級
+ calendar.setTime(new Date());
+ calendar.add(Calendar.DATE, -6); // 鏃ユ湡鍑�6澶╋紙7澶╁墠鐨勪粖澶╋級
+
+ // 璁剧疆7澶╁墠0鐐�
+ calendar.set(Calendar.HOUR_OF_DAY, 0);
+ calendar.set(Calendar.MINUTE, 0);
+ calendar.set(Calendar.SECOND, 0);
+ calendar.set(Calendar.MILLISECOND, 0);
+ startTime = calendar.getTime();
+ days = 7;
+ // 寰幆鐢熸垚7澶╃殑鏃ユ湡瀛楃涓�
+ Calendar tempCalendar = Calendar.getInstance();
+ tempCalendar.setTime(startTime);
+ for (int i = 0; i < days; i++) {
+ dateList.add(sdf.format(tempCalendar.getTime()));
+ tempCalendar.add(Calendar.DATE, 1); // 姣忓ぉ绱姞1澶�
+ }
+ break;
+ case "LAST_THIRTY":
+ // 杩囧幓30澶╋細浠�30澶╁墠0鐐瑰埌鐜板湪锛堝惈浠婂ぉ鍏�30澶╋級
+ calendar.setTime(new Date());
+ calendar.add(Calendar.DATE, -29); // 鏃ユ湡鍑�29澶╋紙30澶╁墠鐨勪粖澶╋級
+
+ // 璁剧疆30澶╁墠0鐐�
+ calendar.set(Calendar.HOUR_OF_DAY, 0);
+ calendar.set(Calendar.MINUTE, 0);
+ calendar.set(Calendar.SECOND, 0);
+ calendar.set(Calendar.MILLISECOND, 0);
+ startTime = calendar.getTime();
+ days = 30;
+ // 寰幆鐢熸垚30澶╃殑鏃ユ湡瀛楃涓�
+ Calendar tempCalendar30 = Calendar.getInstance();
+ tempCalendar30.setTime(startTime);
+ for (int i = 0; i < days; i++) {
+ dateList.add(sdf.format(tempCalendar30.getTime()));
+ tempCalendar30.add(Calendar.DATE, 1); // 姣忓ぉ绱姞1澶�
+ }
+ break;
+ default:
+ return Result.error("涓嶆敮鎸佺殑鏃堕棿鑼冨洿绫诲瀷");
+ }
+ }
+ List<String> goodsIds = new ArrayList<>();
+ //濡傛灉鏌ヨ鏉′欢甯︿簡搴楅摵 鏌ヨ搴楅摵鐨勫晢鍝�
+ if (StringUtils.isNotBlank(queryParam.getStoreId())){
+ List<Goods> list = new LambdaQueryChainWrapper<>(goodsService.getBaseMapper())
+ .eq(Goods::getDeleteFlag, Boolean.FALSE)
+ .eq(Goods::getStoreId, queryParam.getStoreId())
+ .list();
+ goodsIds = list.stream().map(Goods::getId).collect(Collectors.toList());
+ }
+ List<Map<String,Object>> maps = lmkOrderSelectMapper.selectPvUv(startTime,endTime,queryParam.getStoreId(),goodsIds);
+ Map<String, Long> pvDataMap = maps.stream()
+ .collect(Collectors.toMap(
+ map -> map.get("day").toString(),
+ map -> Long.valueOf(map.get("pvData").toString()),
+ Long::sum // 濡傛灉鏈夐噸澶嶏紝绱姞count
+ ));
+ Map<String, Long> uvDataMap = maps.stream()
+ .collect(Collectors.toMap(
+ map -> map.get("day").toString(),
+ map -> Long.valueOf(map.get("uvData").toString()),
+ Long::sum // 濡傛灉鏈夐噸澶嶏紝绱姞count
+ ));
+ List<Long> pvData = new ArrayList<>();
+ List<Long> uvData = new ArrayList<>();
+ for (String date: dateList){
+ String dayKey = String.valueOf(date);
+ Long pv = pvDataMap.getOrDefault(dayKey,0L);
+ Long uv = uvDataMap.getOrDefault(dayKey, 0L);
+ pvData.add(pv);
+ uvData.add(uv);
+ }
+
+ Map<String,Object> map = new HashMap<>();
+ map.put("dateData",dateList);
+ map.put("pvData",pvData);
+ map.put("uvData",uvData);
+ return Result.ok().data(map);
+
}
@Override
@@ -1600,7 +1836,7 @@
return Result.error("涓嶆敮鎸佺殑鏃堕棿鑼冨洿绫诲瀷");
}
}
- List<Map<String, Object>> maps = lmkOrderSelectMapper.selectProductRepurchase(startTime,endTime,queryParam.getCurrentLimit());
+ List<Map<String, Object>> maps = lmkOrderSelectMapper.selectProductRepurchase(startTime,endTime,queryParam.getCurrentLimit(),queryParam.getStoreId());
List<String> goodsData = new ArrayList<>();
List<BigDecimal> rateData = new ArrayList<>();
@@ -1609,7 +1845,10 @@
// 鎻愬彇鍟嗗搧鍚嶏紙娉ㄦ剰锛氶敭鏄痳esultMap涓畾涔夌殑property鍊�"goodsName"锛�
if (Objects.nonNull(map.get("goodsName"))) {
String goodsName = map.get("goodsName").toString();
- goodsData.add(goodsName);
+ String buyerCount = map.get("buyerCount").toString();
+ String repurchaseBuyerCount = map.get("repurchaseBuyerCount").toString();
+ String format = String.format("%s:璐拱浜烘暟 %s 澶嶈喘浜烘暟%s", goodsName, buyerCount, repurchaseBuyerCount);
+ goodsData.add(format);
}
// 鎻愬彇澶嶈喘鐜囷紙澶嶈喘鐜囬�氬父鏄暟瀛楃被鍨嬶紝杩欓噷鐢˙igDecimal鎺ユ敹锛�
--
Gitblit v1.8.0