From 83fb0dd2a6e4126e6deae0f3053b5ebb3fb31219 Mon Sep 17 00:00:00 2001 From: dzc <2388224167@qq.com> Date: Sun, 9 Aug 2026 14:44:53 +0800 Subject: [PATCH] =?UTF-8?q?feat=EF=BC=9A=E6=9F=A5=E8=AF=A2=E4=BC=98?= =?UTF-8?q?=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../hard/mapper/order/HardOrderMapper.java | 20 ++- .../impl/order/HardOrderServiceImpl.java | 115 +++--------------- .../mapper/order/HardOrderMapper.xml | 44 ++++--- 3 files changed, 66 insertions(+), 113 deletions(-) diff --git a/pjcloud-hardware/pjcloud-hardware-biz/src/main/java/com/bsd/pjcloud/hard/mapper/order/HardOrderMapper.java b/pjcloud-hardware/pjcloud-hardware-biz/src/main/java/com/bsd/pjcloud/hard/mapper/order/HardOrderMapper.java index c2def6879..0c9e6cbe8 100644 --- a/pjcloud-hardware/pjcloud-hardware-biz/src/main/java/com/bsd/pjcloud/hard/mapper/order/HardOrderMapper.java +++ b/pjcloud-hardware/pjcloud-hardware-biz/src/main/java/com/bsd/pjcloud/hard/mapper/order/HardOrderMapper.java @@ -57,11 +57,25 @@ public interface HardOrderMapper extends PjcloudBaseMapper { } default Page pageJoin(Page page, HardOrderDto dto) { - MPJLambdaWrapper wrapper = new MPJLambdaWrapper() - .selectAll(HardOrderEntity.class) + MPJLambdaWrapper wrapper = new MPJLambdaWrapper("a") + .selectAll(HardOrderEntity.class, HardOrderEntity::getMerchantType) + .selectAs("coalesce(mch.types, a.merchant_type)", HardOrderVo::getMerchantType) .selectAs(HardManagerEntity::getName, HardOrderVo::getHardName) .selectAs(HardManagerEntity::getType, HardOrderVo::getHardType) + .selectAs("u.name", HardOrderVo::getUsername) + .selectAs("u.phone", HardOrderVo::getUserMobile) + .selectAs("u.avatar", HardOrderVo::getUserAvatar) + .selectAs("user_dept.name", HardOrderVo::getUserDeptName) + .selectAs("mch.name", HardOrderVo::getMerchantName) + .selectAs("mch.logo_pic", HardOrderVo::getLogoPic) + .selectAs("w_m.wallet_type_id", HardOrderVo::getWalletTypeId) + .selectAs("w_t.unique_code", HardOrderVo::getWalletTypeUniqueCode) .leftJoin(HardManagerEntity.class, HardManagerEntity::getId, HardOrderEntity::getHardId) + .leftJoin("pjcloudx.sys_user u ON u.user_id = a.user_id AND u.tenant_id = a.tenant_id AND u.del_flag = '0'") + .leftJoin("pjcloudx.sys_dept user_dept ON user_dept.dept_id = a.user_dept_id AND user_dept.tenant_id = a.tenant_id AND user_dept.del_flag = '0'") + .leftJoin("pjcloudx_wallet.mch_manage mch ON mch.id = a.merchant_id AND mch.tenant_id = a.tenant_id AND mch.del_flag = '0'") + .leftJoin("pjcloudx_wallet.wallet_manage w_m ON w_m.id = a.wallet_id AND w_m.tenant_id = a.tenant_id AND w_m.del_flag = '0'") + .leftJoin("pjcloudx_wallet.wallet_type w_t ON w_t.id = w_m.wallet_type_id AND w_t.tenant_id = a.tenant_id AND w_t.del_flag = '0'") .eqIfExists(HardOrderEntity::getMerchantId, dto.getMerchantId()) .eqIfExists(HardOrderEntity::getUserId, dto.getUserId()) .eqIfExists(HardOrderEntity::getDeptId, dto.getDeptId()) @@ -179,4 +193,4 @@ public interface HardOrderMapper extends PjcloudBaseMapper { List shopGroupByTimeAndHourType(@Param("dto") PanelProductDto dto); List shopGroupByProduct(@Param("dto") PanelProductDto dto); -} \ No newline at end of file +} diff --git a/pjcloud-hardware/pjcloud-hardware-biz/src/main/java/com/bsd/pjcloud/hard/service/impl/order/HardOrderServiceImpl.java b/pjcloud-hardware/pjcloud-hardware-biz/src/main/java/com/bsd/pjcloud/hard/service/impl/order/HardOrderServiceImpl.java index d563abfbc..65ad1aecd 100644 --- a/pjcloud-hardware/pjcloud-hardware-biz/src/main/java/com/bsd/pjcloud/hard/service/impl/order/HardOrderServiceImpl.java +++ b/pjcloud-hardware/pjcloud-hardware-biz/src/main/java/com/bsd/pjcloud/hard/service/impl/order/HardOrderServiceImpl.java @@ -10,9 +10,7 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.bsd.pjcloud.admin.api.dto.UserInfo; -import com.bsd.pjcloud.admin.api.entity.SysDept; import com.bsd.pjcloud.admin.api.entity.SysUser; -import com.bsd.pjcloud.admin.api.feign.RemoteDeptService; import com.bsd.pjcloud.admin.api.feign.RemoteUserService; import com.bsd.pjcloud.admin.api.utils.DataUtil; import com.bsd.pjcloud.admin.api.vo.UserVO; @@ -38,7 +36,6 @@ import com.bsd.pjcloud.hard.api.dto.ali.AliMicropayDto; import com.bsd.pjcloud.hard.api.dto.ali.AliReverseDto; import com.bsd.pjcloud.hard.api.dto.hard.HandCancelActCodeDto; import com.bsd.pjcloud.hard.api.dto.hard.HardDoneHardQrCodeScanOrderDto; -import com.bsd.pjcloud.hard.api.dto.manager.HardManagerDto; import com.bsd.pjcloud.hard.api.dto.hard.HandCancelCodeDto; import com.bsd.pjcloud.hard.api.dto.hard.HardCreateOrderDto; import com.bsd.pjcloud.hard.api.dto.order.HardCreateCarDto; @@ -56,7 +53,6 @@ import com.bsd.pjcloud.hard.api.entity.order.HardCarEntity; import com.bsd.pjcloud.hard.api.entity.order.HardOrderEntity; import com.bsd.pjcloud.hard.api.entity.order.HardParentCarEntity; import com.bsd.pjcloud.hard.api.entity.spu.HardSpuEntity; -import com.bsd.pjcloud.hard.api.utils.HardUtil; import com.bsd.pjcloud.hard.api.vo.HardDoorFlowVo; import com.bsd.pjcloud.hard.api.vo.manager.HardManagerVo; import com.bsd.pjcloud.hard.api.vo.order.HardCarVo; @@ -64,10 +60,8 @@ import com.bsd.pjcloud.hard.api.vo.order.HardCreateHardQrCodeScanOrderVo; import com.bsd.pjcloud.hard.api.vo.order.HardOrderVo; import com.bsd.pjcloud.hard.api.vo.wechat.WechatMicropayVo; import com.bsd.pjcloud.hard.mapper.HardThirdMiOrderMapper; -import com.bsd.pjcloud.hard.mapper.manager.HardManagerMapper; import com.bsd.pjcloud.hard.mapper.order.HardOrderMapper; import com.bsd.pjcloud.hard.service.*; -import com.bsd.pjcloud.hard.utils.RemoteBatchQueryUtil; import com.bsd.pjcloud.supermarket.api.feign.RemoteMallProductService; import com.bsd.pjcloud.supermarket.api.feign.RemoteShopSkuService; import com.bsd.pjcloud.supermarket.api.feign.RemoteSupermarketSpuService; @@ -107,8 +101,6 @@ import org.springframework.data.redis.core.StringRedisTemplate; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import org.springframework.validation.annotation.Validated; -import org.springframework.web.context.request.RequestAttributes; -import org.springframework.web.context.request.RequestContextHolder; import java.math.BigDecimal; import java.math.RoundingMode; @@ -117,6 +109,7 @@ import java.time.LocalTime; import java.util.*; import java.util.concurrent.CompletableFuture; import java.util.concurrent.TimeUnit; +import java.util.stream.Collectors; /** * 订单表 @@ -150,7 +143,6 @@ public class HardOrderServiceImpl extends ServiceImpl list, HardOrderDto dto) { if (ObjectUtil.isEmpty(list)) return; - RequestAttributes requestAttributes = RequestContextHolder.getRequestAttributes(); - // 用户部门 - CompletableFuture deptFuture = CompletableFuture.runAsync(() -> { - RequestContextHolder.setRequestAttributes(requestAttributes); - List userIds = list.stream().map(HardOrderVo::getUserId).filter(ObjectUtil::isNotEmpty).distinct().toList(); - if (ObjectUtil.isNotEmpty(userIds)) { - List userList = userService.getUserDeptByIds(userIds).getData(); - if (ObjectUtil.isNotEmpty(userList)) { - Map map = CollectionUtils.convertMap(userList, UserVO::getUserId); - for (HardOrderVo item : list) { - UserVO userVO = map.get(item.getUserId()); - if (ObjectUtil.isEmpty(userVO)) continue; - item.setUsername(userVO.getName()); - item.setUserMobile(userVO.getPhone()); - item.setUserAvatar(userVO.getAvatar()); - } - } - } - }); - // 当前部门 - CompletableFuture currentDeptFuture = CompletableFuture.runAsync(() -> { - RequestContextHolder.setRequestAttributes(requestAttributes); - List deptIds = list.stream().map(HardOrderVo::getUserDeptId).filter(ObjectUtil::isNotEmpty).distinct().toList(); - if (ObjectUtil.isNotEmpty(deptIds)) { - Map deptList = deptService.getDeptByDeptIds(deptIds).getData(); - if (ObjectUtil.isNotEmpty(deptList)) { - for (HardOrderVo item : list) { - SysDept dept = deptList.get(item.getUserDeptId()); - if (ObjectUtil.isEmpty(dept)) continue; - item.setUserDeptName(dept.getName()); - } - } - } - }); - // 商户 - CompletableFuture mchFuture = CompletableFuture.runAsync(() -> { - RequestContextHolder.setRequestAttributes(requestAttributes); - List mchIds = list.stream().map(HardOrderVo::getMerchantId).filter(ObjectUtil::isNotEmpty).distinct().toList(); - if (ObjectUtil.isNotEmpty(mchIds)) { - R> mchList = remoteMchService.getByIds(mchIds); - if (ObjectUtil.isNotEmpty(mchList.getData())) { - WalletDataUtil.convertMchList(list, CollectionUtils.convertMap(mchList.getData(), MchManageVo::getId)); - } - } - }); - // 设备 - CompletableFuture deviceFuture = CompletableFuture.runAsync(() -> { - RequestContextHolder.setRequestAttributes(requestAttributes); - List hardIds = list.stream().map(HardOrderVo::getHardId).filter(ObjectUtil::isNotEmpty).distinct().toList(); - if (ObjectUtil.isNotEmpty(hardIds)) { - HardManagerDto hardManagerDto = new HardManagerDto(); - hardManagerDto.setIds(hardIds); - List hardList = hardManagerMapper.list(hardManagerDto); - if (ObjectUtil.isNotEmpty(hardList)) { - HardUtil.convertHardList(list, CollectionUtils.convertMap(hardList, HardManagerEntity::getId)); - } - } - }); - // 钱包 - CompletableFuture walletFuture = CompletableFuture.runAsync(() -> { - RequestContextHolder.setRequestAttributes(requestAttributes); - List walletIds = list.stream().map(HardOrderVo::getWalletId).filter(ObjectUtil::isNotEmpty).distinct().toList(); - if (ObjectUtil.isNotEmpty(walletIds)) { - List walletList = getWalletListByIds(walletIds); - Map walletMap = CollectionUtils.convertMap(walletList, WalletManageVo::getId); - for (HardOrderVo v : list) { - WalletManageVo target = walletMap.get(v.getWalletId()); - if (ObjectUtil.isEmpty(target)) continue; - v.setWalletTypeUniqueCode(target.getWalletTypeUniqueCode()); - } - } - }); - // 购物车 - if (dto.getIsFindCarList()) { - for (HardOrderVo v : list) { - if (ObjectUtil.isEmpty(v.getParentCarId())) continue; - List carList = hardCarService.getByParentCarId(v.getParentCarId()); - List carVoList = BeanUtils.toBean(carList, HardCarVo.class); - v.setCarList(carVoList); - } - } - CompletableFuture.allOf(deptFuture, mchFuture, deviceFuture, currentDeptFuture, walletFuture).join(); - } + if (!Boolean.TRUE.equals(dto.getIsFindCarList())) return; - private List getWalletListByIds(List walletIds) { - return RemoteBatchQueryUtil.queryByIds(walletIds, ids -> remoteWalletService.getWalletByIds(ids).getData()); + List parentCarIds = list.stream() + .map(HardOrderVo::getParentCarId) + .filter(ObjectUtil::isNotEmpty) + .distinct() + .toList(); + if (ObjectUtil.isEmpty(parentCarIds)) return; + + List carList = BeanUtils.toBean( + hardCarService.list(new LambdaQueryWrapper() + .in(HardCarEntity::getParentCarId, parentCarIds)), + HardCarVo.class + ); + Map> carMap = carList.stream() + .collect(Collectors.groupingBy(HardCarVo::getParentCarId)); + for (HardOrderVo order : list) { + if (ObjectUtil.isEmpty(order.getParentCarId())) continue; + order.setCarList(carMap.getOrDefault(order.getParentCarId(), Collections.emptyList())); + } } } diff --git a/pjcloud-hardware/pjcloud-hardware-biz/src/main/resources/mapper/order/HardOrderMapper.xml b/pjcloud-hardware/pjcloud-hardware-biz/src/main/resources/mapper/order/HardOrderMapper.xml index 7bf128c69..1e9895222 100644 --- a/pjcloud-hardware/pjcloud-hardware-biz/src/main/resources/mapper/order/HardOrderMapper.xml +++ b/pjcloud-hardware/pjcloud-hardware-biz/src/main/resources/mapper/order/HardOrderMapper.xml @@ -203,7 +203,7 @@ a.user_id, a.user_dept_id, a.merchant_id, - a.merchant_type, + coalesce(mch.types, a.merchant_type) as merchant_type, a.merchant_dept_id, a.hard_id, a.dept_id, @@ -239,11 +239,36 @@ m.name as hardName, m.type as hardType, m.dept_id as hardTypeDeptId, + u.name as username, + u.phone as userMobile, + u.avatar as userAvatar, + user_dept.name as userDeptName, + mch.name as merchantName, + mch.logo_pic as logoPic, s.id as afterSaleId, s.no as afterSaleNo, - w_m.wallet_type_id as walletTypeId - from (select a.id + w_m.wallet_type_id as walletTypeId, + w_t.unique_code as walletTypeUniqueCode from hard_order a + left join hard_manager m + on m.id = a.hard_id and m.tenant_id = a.tenant_id and m.del_flag = '0' + left join pjcloudx.sys_user u + on u.user_id = a.user_id and u.tenant_id = a.tenant_id and u.del_flag = '0' + left join pjcloudx.sys_dept user_dept + on user_dept.dept_id = a.user_dept_id and user_dept.tenant_id = a.tenant_id and user_dept.del_flag = '0' + left join pjcloudx_wallet.mch_manage mch + on mch.id = a.merchant_id and mch.tenant_id = a.tenant_id and mch.del_flag = '0' + left join pjcloudx_wallet.wallet_manage w_m + on w_m.id = a.wallet_id and w_m.tenant_id = a.tenant_id and w_m.del_flag = '0' + left join pjcloudx_wallet.wallet_type w_t + on w_t.id = w_m.wallet_type_id and w_t.tenant_id = a.tenant_id and w_t.del_flag = '0' + left join (select tenant_id, order_id, max(id) as id + from hard_after_sale + where del_flag = '0' + group by tenant_id, order_id) sx + on sx.order_id = a.id and sx.tenant_id = a.tenant_id + left join hard_after_sale s + on s.id = sx.id and s.tenant_id = a.tenant_id and s.del_flag = '0' @@ -258,17 +283,6 @@ and s.no = #{dto.afterSaleNo} - - order by a.create_time desc, a.user_id desc) t - join hard_order a on a.id = t.id - left join hard_manager m on m.id = a.hard_id - left join pjcloudx_wallet.wallet_manage w_m on w_m.id = a.wallet_id - left join (select order_id, max(id) as id - from hard_after_sale - where tenant_id = 1 - group by order_id) sx on sx.order_id = a.id - left join hard_after_sale s on s.id = sx.id - and w_m.wallet_type_id = #{dto.walletTypeId} @@ -1086,4 +1100,4 @@ - \ No newline at end of file +