diff --git a/hiver-admin/test-output/test-report.html b/hiver-admin/test-output/test-report.html index 5bf4d372..24c41a7a 100644 --- a/hiver-admin/test-output/test-report.html +++ b/hiver-admin/test-output/test-report.html @@ -35,7 +35,7 @@ Hiver
  • -四月 23, 2026 18:21:01 +四月 25, 2026 17:38:11
  • @@ -84,7 +84,7 @@

    passTest

    -

    18:21:02 下午 / 0.015 secs

    +

    17:38:11 下午 / 0.017 secs

    @@ -92,9 +92,9 @@
    #test-id=1
    passTest
    -04.23.2026 18:21:02 -04.23.2026 18:21:02 -0.015 secs +04.25.2026 17:38:11 +04.25.2026 17:38:11 +0.017 secs
    @@ -104,7 +104,7 @@ Pass - 18:21:02 + 17:38:11 Test passed @@ -128,13 +128,13 @@

    Started

    -

    四月 23, 2026 18:21:01

    +

    四月 25, 2026 17:38:11

    Ended

    -

    四月 23, 2026 18:21:02

    +

    四月 25, 2026 17:38:11

    diff --git a/hiver-core/src/main/java/cc/hiver/core/serviceimpl/WorkerServiceImpl.java b/hiver-core/src/main/java/cc/hiver/core/serviceimpl/WorkerServiceImpl.java index 381ae03b..7d310f94 100644 --- a/hiver-core/src/main/java/cc/hiver/core/serviceimpl/WorkerServiceImpl.java +++ b/hiver-core/src/main/java/cc/hiver/core/serviceimpl/WorkerServiceImpl.java @@ -3,11 +3,9 @@ package cc.hiver.core.serviceimpl; import cc.hiver.core.common.constant.CommonConstant; import cc.hiver.core.common.constant.WorkerConstant; import cc.hiver.core.common.utils.PageUtil; -import cc.hiver.core.common.utils.SecurityUtil; import cc.hiver.core.common.vo.PageVo; import cc.hiver.core.dao.WorkerDao; import cc.hiver.core.entity.Worker; -import cc.hiver.core.service.OrderOfCoreService; import cc.hiver.core.service.WorkerService; import cc.hiver.core.vo.WorkerQueryVO; import cn.hutool.core.date.DateUtil; @@ -38,13 +36,6 @@ import java.util.List; public class WorkerServiceImpl implements WorkerService { @Autowired private WorkerDao workerDao; - - @Autowired - private SecurityUtil securityUtil; - - @Autowired - private OrderOfCoreService orderOfCoreService; - @Override public WorkerDao getRepository() { return workerDao; diff --git a/hiver-modules/hiver-base/src/main/java/cc/hiver/base/controller/manage/UserController.java b/hiver-modules/hiver-base/src/main/java/cc/hiver/base/controller/manage/UserController.java index c666e11c..3faf9e62 100644 --- a/hiver-modules/hiver-base/src/main/java/cc/hiver/base/controller/manage/UserController.java +++ b/hiver-modules/hiver-base/src/main/java/cc/hiver/base/controller/manage/UserController.java @@ -674,17 +674,19 @@ public class UserController { resultMap.put("user", wechatUser); List shop = shopService.getShopByUserid(wechatUser.getId()); - if(shop != null){ + if(!shop.isEmpty()){ List shopIds = shop.stream().map(Shop::getId).collect(Collectors.toList()); - List shopTakeaway = shopTakeawayService.selectListByshopId(shopIds); - if(shopTakeaway != null){ - shop.forEach(e -> { - for(ShopTakeaway shopTakeawa : shopTakeaway) { - if (e.getId().equals(shopTakeawa.getShopId())) { - e.setShopTakeaway(shopTakeawa); + if(!shopIds.isEmpty()){ + List shopTakeaway = shopTakeawayService.selectListByshopId(shopIds); + if(shopTakeaway != null){ + shop.forEach(e -> { + for(ShopTakeaway shopTakeawa : shopTakeaway) { + if (e.getId().equals(shopTakeawa.getShopId())) { + e.setShopTakeaway(shopTakeawa); + } } - } - }); + }); + } } resultMap.put("shop", shop); } diff --git a/hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/controller/CommentController.java b/hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/controller/CommentController.java index 1f07cdd8..c157cbae 100644 --- a/hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/controller/CommentController.java +++ b/hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/controller/CommentController.java @@ -26,8 +26,10 @@ import cc.hiver.mall.entity.Comment; import cc.hiver.mall.entity.Shop; import cc.hiver.mall.pojo.dto.ShopCacheDTO; import cc.hiver.mall.pojo.query.CommentQuery; +import cc.hiver.mall.pojo.vo.WorkerRedisVo; import cc.hiver.mall.service.CommentService; import cc.hiver.mall.service.ShopService; +import cc.hiver.mall.utils.WorkerRedisCacheUtil; import cn.hutool.json.JSONUtil; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import io.swagger.annotations.Api; @@ -57,6 +59,9 @@ public class CommentController { @Autowired private CommentService commentService; + @Autowired + WorkerRedisCacheUtil workerRedisCacheUtil; + @Autowired private ShopService shopService; @@ -98,6 +103,12 @@ public class CommentController { // 3. 淇濆瓨鏇存柊 workerServiceImpl.update(worker); + //鏇存柊缂撳瓨 + WorkerRedisVo workerRedisVo = workerRedisCacheUtil.get(worker.getRegion(), worker.getWorkerId()); + if(workerRedisVo != null){ + workerRedisVo.setWorker(worker); + workerRedisCacheUtil.update(worker.getRegion(), workerRedisVo); + } }else{ //鏇存柊搴楅摵璇勫垎 Shop shop = shopService.findById(e.getShopId()); diff --git a/hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/controller/MallDeliveryOrderController.java b/hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/controller/MallDeliveryOrderController.java index f63e4f2c..b03964e9 100644 --- a/hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/controller/MallDeliveryOrderController.java +++ b/hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/controller/MallDeliveryOrderController.java @@ -11,9 +11,11 @@ import cc.hiver.core.serviceimpl.JPushServiceImpl; import cc.hiver.mall.entity.MallDeliveryOrder; import cc.hiver.mall.entity.MallOrder; import cc.hiver.mall.pojo.query.MallDeliveryOrderPageQuery; +import cc.hiver.mall.pojo.vo.WorkerRedisVo; import cc.hiver.mall.service.mybatis.MallDeliveryOrderService; import cc.hiver.mall.utils.WaitOrderCacheUtil; import cc.hiver.mall.utils.WorkerOrderCacheUtil; +import cc.hiver.mall.utils.WorkerRedisCacheUtil; import cn.hutool.core.util.StrUtil; import com.baomidou.mybatisplus.core.metadata.IPage; import io.swagger.annotations.Api; @@ -47,6 +49,9 @@ public class MallDeliveryOrderController { @Autowired JPushServiceImpl jPushService; + @Autowired + WorkerRedisCacheUtil workerRedisCacheUtil; + @Autowired WorkerOrderCacheUtil workerOrderCacheUtil; @@ -166,17 +171,20 @@ public class MallDeliveryOrderController { //褰撳墠浜烘病鏈夋敞鍐屽吋鑱岋紝鍏堣祴浜堝吋鑱岃韩浠 final User user = securityUtil.getCurrUser(); Worker worker = new Worker(); - if(worker == null){ - worker.setWorkerName(user.getNickname()); - worker.setUserId(user.getId()); - worker.setAvgTime(BigDecimal.valueOf(30)); - worker.setMobile(user.getMobile()); - worker.setRegion(regionId); - worker.setIsOnLine(CommonConstant.ON_LINE); - worker.setScore(BigDecimal.valueOf(5)); - workerService.save(worker); - } - Integer result = mallDeliveryOrderService.workerAccept(user.getMobile(),deliveryId, workerId,workerName,groupId); + worker.setWorkerName(user.getNickname()); + worker.setUserId(user.getId()); + worker.setAvgTime(BigDecimal.valueOf(25)); + worker.setMobile(user.getMobile()); + worker.setRegion(regionId); + worker.setIsOnLine(CommonConstant.ON_LINE); + worker.setScore(BigDecimal.valueOf(5)); + workerService.save(worker); + //娣诲姞缂撳瓨 + WorkerRedisVo workerVO = new WorkerRedisVo(); + workerVO.setWorkerId(worker.getWorkerId()); + workerVO.setWorker(worker); + workerRedisCacheUtil.put(worker.getRegion(),workerVO); + Integer result = mallDeliveryOrderService.workerAccept(worker.getMobile(),deliveryId, worker.getWorkerId(),worker.getWorkerName(),groupId); if(result == 0){ return ResultUtil.success("閰嶉佸崟涓嶅瓨鍦"); }else if (result == 1){ @@ -194,6 +202,8 @@ public class MallDeliveryOrderController { return ResultUtil.success("閰嶉佸崟宸茶鎺ュ彇鎴栧凡鍙栨秷"); }else if(result == 2){ return ResultUtil.success("璇ュ崟宸叉寚瀹氬叾浠栭厤閫佸憳锛屾棤娉曟姠鍗"); + }else if(result == 5){ + return ResultUtil.success("宸茶绂佹鎺ュ崟锛屾棤娉曟姠鍗"); }else{ return ResultUtil.success("鎺ュ崟鎴愬姛"); } diff --git a/hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/controller/MallOrderController.java b/hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/controller/MallOrderController.java index 6d514db0..0b94fcbc 100644 --- a/hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/controller/MallOrderController.java +++ b/hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/controller/MallOrderController.java @@ -164,7 +164,7 @@ public class MallOrderController { */ @PostMapping("/shopMakeTime") @ApiOperation(value = "鍟嗗鍑洪") - public Result shopMakeTime(@ApiParam("璁㈠崟ID") @RequestParam String orderId) { + public Result shopMakeTime(@ApiParam("璁㈠崟ID") @RequestParam(value = "orderId") String orderId) { try { mallOrderService.shopMakeTime(orderId); return ResultUtil.success("鍑洪鎴愬姛"); diff --git a/hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/controller/ShopTakeawayController.java b/hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/controller/ShopTakeawayController.java index 774c9181..1f5988a0 100644 --- a/hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/controller/ShopTakeawayController.java +++ b/hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/controller/ShopTakeawayController.java @@ -18,9 +18,7 @@ package cc.hiver.mall.controller; import cc.hiver.core.common.utils.ResultUtil; import cc.hiver.core.common.vo.Result; import cc.hiver.mall.entity.ShopTakeaway; -import cc.hiver.mall.pojo.query.ShopTakeawayQuery; import cc.hiver.mall.service.ShopTakeawayService; -import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiParam; @@ -86,11 +84,4 @@ public class ShopTakeawayController { return ResultUtil.success("鍒犻櫎鎴愬姛"); } - @RequestMapping(value = "/getList", method = RequestMethod.POST) - @ApiOperation("鏍规嵁瀛︽牎id鑾峰彇澶栧崠涓氬姟閰嶇疆鍒楄〃") - public Result> getList( - @ApiParam("搴楅摵id鍒楄〃") @RequestBody ShopTakeawayQuery shopTakeawayQuery) { - final Page shopTakeawaysPage = shopTakeawayService.selectList(shopTakeawayQuery); - return ResultUtil.data(shopTakeawaysPage); - } } diff --git a/hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/controller/WorkerController.java b/hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/controller/WorkerController.java index 338cde7a..d83c0871 100644 --- a/hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/controller/WorkerController.java +++ b/hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/controller/WorkerController.java @@ -12,13 +12,21 @@ import cc.hiver.core.service.WorkerService; import cc.hiver.core.vo.WorkerAppVO; import cc.hiver.core.vo.WorkerQueryVO; import cc.hiver.mall.dao.mapper.WorkerRelaPriceMapper; +import cc.hiver.mall.entity.MallDeliveryOrder; import cc.hiver.mall.entity.Recharge; import cc.hiver.mall.entity.ShopArea; +import cc.hiver.mall.entity.WorkerRelaPrice; import cc.hiver.mall.pojo.vo.WorkerAreaOnlineCountVO; import cc.hiver.mall.pojo.vo.WorkerMatchVO; +import cc.hiver.mall.pojo.vo.WorkerRedisVo; import cc.hiver.mall.service.RechargeService; import cc.hiver.mall.service.ShopAreaService; +import cc.hiver.mall.service.mybatis.WorkerRelaPriceService; +import cc.hiver.mall.utils.WorkerOrderCacheUtil; +import cc.hiver.mall.utils.WorkerRedisCacheUtil; import cn.hutool.core.util.StrUtil; +import com.baomidou.mybatisplus.core.metadata.IPage; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiParam; @@ -26,13 +34,12 @@ import lombok.Data; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.cache.annotation.CacheConfig; -import org.springframework.data.domain.Page; import org.springframework.transaction.annotation.Transactional; import org.springframework.web.bind.annotation.*; import javax.validation.Valid; import java.math.BigDecimal; -import java.util.List; +import java.util.*; /** * 閰嶉佸憳绠$悊鎺ュ彛 @@ -53,6 +60,12 @@ public class WorkerController { @Autowired private RechargeService rechargeService; + @Autowired + WorkerRedisCacheUtil workerRedisCacheUtil; + + @Autowired + private WorkerRelaPriceService workerRelaPriceService; + @Autowired private ShopAreaService shopAreaService; @@ -65,7 +78,7 @@ public class WorkerController { @RequestMapping(value = "/getByCondition", method = RequestMethod.POST) @ApiOperation(value = "澶氭潯浠跺垎椤佃幏鍙栬鍗曞垪琛") public Result> getByCondition(@RequestBody WorkerQueryVO worker) { - Page page = workerService.findByCondition(worker); + Page page = (Page) workerService.findByCondition(worker); return new ResultUtil>().setData(page); } @@ -114,7 +127,7 @@ public class WorkerController { }else{ u.setWorkerName(user.getNickname()); u.setUserId(user.getId()); - u.setAvgTime(BigDecimal.valueOf(30)); + u.setAvgTime(BigDecimal.valueOf(25)); u.setMobile(user.getMobile()); u.setIsOnLine(CommonConstant.OFF_LINE); u.setScore(BigDecimal.valueOf(5)); @@ -138,6 +151,12 @@ public class WorkerController { u.setRegionTitle(""); } workerService.update(u); + Worker worker = workerService.findByWorkerId(u.getWorkerId()); + WorkerRedisVo workerRedisVo = workerRedisCacheUtil.get(worker.getRegion(), worker.getWorkerId()); + if(workerRedisVo != null){ + workerRedisVo.setWorker(worker); + } + workerRedisCacheUtil.update(worker.getRegion(), workerRedisVo); return ResultUtil.success("淇敼鎴愬姛"); } @@ -205,6 +224,14 @@ public class WorkerController { public Result onLine(@RequestParam("id") String id) { try { workerService.onLine(id); + //娣诲姞缂撳瓨 + Worker worker = workerService.get(id); + WorkerRedisVo workerVO = new WorkerRedisVo(); + workerVO.setWorkerId(worker.getWorkerId()); + workerVO.setWorker(worker); + List workerRelaPriceList = workerRelaPriceService.selectByWorkerId(worker.getWorkerId()); + workerVO.setWorkerRelaPriceList(workerRelaPriceList); + workerRedisCacheUtil.put(worker.getRegion(),workerVO); return ResultUtil.success("涓婄嚎鎴愬姛"); } catch (Exception e) { log.error(e.getMessage(), e); @@ -225,6 +252,8 @@ public class WorkerController { public Result offLine(@RequestParam("id")String id) { try { workerService.offLine(id); + //缂撳瓨鍘绘帀 + workerRedisCacheUtil.remove(workerService.get(id).getRegion(),id); return ResultUtil.success("涓嬬嚎鎴愬姛"); } catch (Exception e) { log.error(e.getMessage(), e); @@ -237,6 +266,8 @@ public class WorkerController { */ @Data public static class WorkerMatchDTO { + /** 瀛︽牎/鍖哄煙id锛堢敤浜庣紦瀛樻煡鎵撅紝瀵瑰簲 worker.region锛 */ + private String regionId; /** 鍙栬揣鍖哄煙id锛堝晢瀹舵墍鍦ㄥ尯鍩燂級 */ private String shopAreaId; /** 鎺ュ崟绫诲瀷 0澶栧崠 1蹇 */ @@ -256,17 +287,162 @@ public class WorkerController { * orderBkge -> 閰嶉佷剑閲戞搴 */ private String sortField; + /** 椤电爜锛堜粠1寮濮嬶級锛岄粯璁1 */ + private Integer pageNum = 1; + /** 姣忛〉鏉℃暟锛岄粯璁10 */ + private Integer pageSize = 10; } + @Autowired + private WorkerOrderCacheUtil workerOrderCacheUtil; + @RequestMapping(value = "/getMatchingWorkerList", method = RequestMethod.POST) @ApiOperation(value = "鍖归厤鎶㈠崟閰嶉佸憳鍒楄〃") - public Result> getMatchingWorkerList(@RequestBody WorkerMatchDTO dto) { - // 璁$畻鎺掑簭鏂瑰悜锛歛vgTime/orderBkge 榛樿 ASC锛宻core 榛樿 DESC + public Result> getMatchingWorkerList(@RequestBody WorkerMatchDTO dto) { + int pageNum = dto.getPageNum() != null && dto.getPageNum() > 0 ? dto.getPageNum() : 1; + int pageSize = dto.getPageSize() != null && dto.getPageSize() > 0 ? dto.getPageSize() : 10; + + // ============ 1. 浠庣紦瀛樿幏鍙栧綋鍓嶅尯鍩熸墍鏈夊湪绾块厤閫佸憳 ============ + List workerRedisVoList = null; + if (StrUtil.isNotBlank(dto.getRegionId())) { + workerRedisVoList = workerRedisCacheUtil.getAll(dto.getRegionId()); + } + + if (workerRedisVoList != null && !workerRedisVoList.isEmpty()) { + String keyword = StrUtil.isBlank(dto.getKeyword()) ? null : dto.getKeyword().trim().toLowerCase(); + List filteredList = new ArrayList<>(); + + for (WorkerRedisVo vo : workerRedisVoList) { + if (vo.getWorker() == null) continue; + Worker w = vo.getWorker(); + + // ---- 閰嶉佸憳鍩虹鐘舵佽繃婊わ細鍚敤(1) + 涓婄嚎(1) + 鎺ユ敹鎸囨淳(1) ---- + if (w.getWorkerStatus() == null || w.getWorkerStatus() != 1) continue; + if (w.getIsOnLine() == null || w.getIsOnLine() != 1) continue; + if (w.getGetPushOrder() == null || w.getGetPushOrder() != 1) continue; + + // ---- 浜ゆ槗淇濋殰杩囨护锛歳ebate_amount > 0 ---- + if (dto.getBaozhang() != null && dto.getBaozhang()) { + if (w.getRebateAmount() == null || w.getRebateAmount().compareTo(BigDecimal.ZERO) <= 0) { + continue; + } + } + + // ---- 鍏抽敭璇嶆ā绯婃悳绱細濮撳悕鎴栨墜鏈哄彿 ---- + if (keyword != null) { + boolean nameMatch = w.getWorkerName() != null && w.getWorkerName().toLowerCase().contains(keyword); + boolean mobileMatch = w.getMobile() != null && w.getMobile().contains(keyword); + if (!nameMatch && !mobileMatch) continue; + } + + // ---- 閰嶉佽鍒欏尮閰嶏細shopAreaId + putAreaId + orderType + getPushOrder ---- + if (vo.getWorkerRelaPriceList() == null || vo.getWorkerRelaPriceList().isEmpty()) continue; + + WorkerRelaPrice matchedRule = null; + for (WorkerRelaPrice rp : vo.getWorkerRelaPriceList()) { + // 瑙勫垯蹇呴』鎺ユ敹鎸囨淳 + if (rp.getGetPushOrder() == null || rp.getGetPushOrder() != 1) continue; + // 鍙栬揣鍖哄煙鍖归厤 + if (StrUtil.isNotBlank(dto.getShopAreaId()) && !dto.getShopAreaId().equals(rp.getGetAreaId())) continue; + // 閫佽揣鍖哄煙鍖归厤 + if (StrUtil.isNotBlank(dto.getPutAreaId()) && !dto.getPutAreaId().equals(rp.getPutAreaId())) continue; + // 璁㈠崟绫诲瀷鍖归厤 + if (dto.getOrderType() != null && !dto.getOrderType().equals(rp.getOrderType())) continue; + matchedRule = rp; + break; + } + if (matchedRule == null) continue; + + // ---- 浠庤鍗曠紦瀛樿幏鍙栬閰嶉佸憳鐨勫緟瀹屾垚璁㈠崟锛岀粺璁″悇鐘舵佹暟閲 ---- + List workerOrders = workerOrderCacheUtil.getAllAsList(w.getWorkerId()); + int orderWaitCount = 0; // status=0 寰呮帴鍗 + int orderGetCount = 0; // status=1 寰呭彇璐 + int orderPutCount = 0; // status=2 寰呴佽揪 + boolean hasSamePutArea = false; + + for (MallDeliveryOrder order : workerOrders) { + if (order.getStatus() == null) continue; + if (order.getStatus() == 0) orderWaitCount++; + else if (order.getStatus() == 1) orderGetCount++; + else if (order.getStatus() == 2) orderPutCount++; + + // 妫鏌ユ槸鍚︽湁鐩稿悓 putAreaId 鐨勮繘琛屼腑璁㈠崟 + if (StrUtil.isNotBlank(dto.getPutAreaId()) + && dto.getPutAreaId().equals(order.getPutAreaId()) + && order.getStatus() != null + && (order.getStatus() == 0 || order.getStatus() == 1 || order.getStatus() == 2)) { + hasSamePutArea = true; + } + } + + // ---- 鐩稿悓鍦板潃杩囨护 ---- + if (dto.getXiangtong() != null && dto.getXiangtong() && !hasSamePutArea) { + continue; + } + + // ---- 缁勮 WorkerMatchVO ---- + WorkerMatchVO matchVO = new WorkerMatchVO(); + matchVO.setWorkerId(w.getWorkerId()); + matchVO.setWorkerName(w.getWorkerName()); + matchVO.setMobile(w.getMobile()); + matchVO.setIcon(w.getIcon()); + matchVO.setGeolocation(w.getGeolocation()); + matchVO.setScore(w.getScore()); + matchVO.setAvgTime(w.getAvgTime()); + matchVO.setRebateAmount(w.getRebateAmount()); + matchVO.setHighFloorFee(w.getHighFloorFee()); + matchVO.setOrderBkge(matchedRule.getOrderBkge()); + matchVO.setOrderWaitCount(orderWaitCount); + matchVO.setOrderGetCount(orderGetCount); + matchVO.setOrderPutCount(orderPutCount); + filteredList.add(matchVO); + } + + // ============ 2. 鎺掑簭锛堜笌 SQL 涓鑷达級 ============ + Comparator comparator; + if ("score".equals(dto.getSortField())) { + comparator = Comparator.comparing(WorkerMatchVO::getScore, + Comparator.nullsLast(Comparator.reverseOrder())); + } else if ("orderBkge".equals(dto.getSortField())) { + comparator = Comparator.comparing(WorkerMatchVO::getOrderBkge, + Comparator.nullsLast(Comparator.naturalOrder())); + } else { + // 榛樿鎸 avgTime 姝e簭 + comparator = Comparator.comparing(WorkerMatchVO::getAvgTime, + Comparator.nullsLast(Comparator.naturalOrder())); + } + // 浜岀骇鎺掑簭锛歳ebateAmount 鍊掑簭 + comparator = comparator.thenComparing(WorkerMatchVO::getRebateAmount, + Comparator.nullsLast(Comparator.reverseOrder())); + filteredList.sort(comparator); + + // ============ 3. 鍐呭瓨鍒嗛〉 ============ + IPage page = new Page<>(pageNum, pageSize); + long total = filteredList.size(); + page.setTotal(total); + if (total > 0) { + int offset = (pageNum - 1) * pageSize; + if (offset >= total) { + page.setRecords(Collections.emptyList()); + } else { + int end = (int) Math.min(offset + pageSize, total); + page.setRecords(filteredList.subList(offset, end)); + } + } else { + page.setRecords(Collections.emptyList()); + } + + return new ResultUtil>().setData(page); + } + + // ============ 4. 缂撳瓨涓虹┖鏃跺洖閫鍒版暟鎹簱鏌ヨ锛堝甫鍒嗛〉锛 ============ String sortOrder = "DESC"; if ("avgTime".equals(dto.getSortField()) || "orderBkge".equals(dto.getSortField())) { sortOrder = "ASC"; } - List list = workerRelaPriceMapper.getMatchingWorkerList( + IPage pageParam = new Page<>(pageNum, pageSize); + IPage pageResult = workerRelaPriceMapper.getMatchingWorkerList( + pageParam, dto.getShopAreaId(), dto.getOrderType(), dto.getPutAreaId(), @@ -276,12 +452,51 @@ public class WorkerController { dto.getSortField(), sortOrder ); - return new ResultUtil>().setData(list); + return new ResultUtil>().setData(pageResult); } @RequestMapping(value = "/getOnlineWorkerByArea", method = RequestMethod.GET) @ApiOperation(value = "鏌ヨ鍚勯鍫傚尯鍩熷湪绾块厤閫佸憳鏁伴噺") public Result> getOnlineWorkerByArea(@RequestParam(value = "parentId")String parentId) { + //parentId灏辨槸regionId + List workerRedisVoList = workerRedisCacheUtil.getAll(parentId); + if (workerRedisVoList != null && !workerRedisVoList.isEmpty()) { + // 鎸 areaId 缁熻鍦ㄧ嚎涓旀帴鏀舵寚娲惧崟鐨勯厤閫佸憳鏁伴噺锛圫et 鍘婚噸 workerId锛 + // key=areaId, value={areaName, Set} + Map areaNameMap = new HashMap<>(); + Map> areaWorkerMap = new HashMap<>(); + + for (WorkerRedisVo vo : workerRedisVoList) { + if (vo.getWorker() == null) continue; + Worker w = vo.getWorker(); + // worker.getPushOrder == 1 浠h〃璇ラ厤閫佸憳鎺ユ敹鎸囨淳鍗 + if (w.getGetPushOrder() == null || w.getGetPushOrder() != 1) continue; + + // 閬嶅巻閰嶉佽鍒欙紝鎻愬彇 getPushOrder = 1 鐨勫彇璐у尯鍩 + if (vo.getWorkerRelaPriceList() != null) { + for (WorkerRelaPrice rp : vo.getWorkerRelaPriceList()) { + if (rp.getGetPushOrder() != null && rp.getGetPushOrder() == 1 && rp.getOrderType() == 0 + && StrUtil.isNotBlank(rp.getGetAreaId())) { + areaNameMap.putIfAbsent(rp.getGetAreaId(), rp.getGetAreaName()); + areaWorkerMap.computeIfAbsent(rp.getGetAreaId(), k -> new HashSet<>()) + .add(w.getWorkerId()); + } + } + } + } + + // 缁勮缁撴灉 + List result = new ArrayList<>(); + for (Map.Entry entry : areaNameMap.entrySet()) { + WorkerAreaOnlineCountVO countVO = new WorkerAreaOnlineCountVO(); + countVO.setAreaId(entry.getKey()); + countVO.setAreaName(entry.getValue()); + Set workers = areaWorkerMap.get(entry.getKey()); + countVO.setOnlineWorkerCount(workers != null ? workers.size() : 0); + result.add(countVO); + } + return new ResultUtil>().setData(result); + } List list = workerRelaPriceMapper.getOnlineWorkerCountByCanteenArea(parentId); return new ResultUtil>().setData(list); } diff --git a/hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/controller/WorkerRelaPriceController.java b/hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/controller/WorkerRelaPriceController.java index 2872caaf..7dee9071 100644 --- a/hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/controller/WorkerRelaPriceController.java +++ b/hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/controller/WorkerRelaPriceController.java @@ -23,7 +23,9 @@ import cc.hiver.core.service.UserService; import cc.hiver.core.service.WorkerService; import cc.hiver.mall.entity.WorkerRelaPrice; import cc.hiver.mall.pojo.vo.WorkerRealPriceVo; +import cc.hiver.mall.pojo.vo.WorkerRedisVo; import cc.hiver.mall.service.mybatis.WorkerRelaPriceService; +import cc.hiver.mall.utils.WorkerRedisCacheUtil; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import lombok.extern.slf4j.Slf4j; @@ -33,7 +35,7 @@ import org.springframework.web.bind.annotation.*; import java.util.List; /** - * 搴楅摵澶栧崠涓氬姟閰嶇疆鎺у埗鍣 + * 閰嶉佸憳浣i噾璁惧畾閰嶇疆鎺у埗鍣 * * @author cc */ @@ -46,6 +48,9 @@ public class WorkerRelaPriceController { @Autowired private WorkerRelaPriceService workerRelaPriceService; + @Autowired + WorkerRedisCacheUtil workerRedisCacheUtil; + @Autowired private WorkerService workerService; @@ -59,6 +64,8 @@ public class WorkerRelaPriceController { Worker worker = workerService.findByWorkerId(workerId); if(worker != null){ workerRealPriceVo.setWorkerName(worker.getWorkerName()); + workerRealPriceVo.setMobile(worker.getMobile()); + workerRealPriceVo.setGetPushOrder(worker.getGetPushOrder()); workerRealPriceVo.setCardPicture(worker.getCardPicture()); workerRealPriceVo.setHighFloorFee(worker.getHighFloorFee()); final List workerRelaPriceList = workerRelaPriceService.selectByWorkerId(workerId); @@ -72,23 +79,42 @@ public class WorkerRelaPriceController { public Result batchAdd(@RequestBody WorkerRealPriceVo workerRealPriceVo) { User user = userService.findById(workerRealPriceVo.getUserId()); Worker worker = workerService.findByUserId(workerRealPriceVo.getUserId()); - if(workerRealPriceVo != null){ - workerRelaPriceService.deleteByWorkerId(worker.getWorkerId()); - } + + List workerRelaPriceList = workerRelaPriceService.selectByWorkerId(worker.getWorkerId()); //鏇存柊閰嶉佸憳淇℃伅 worker.setWorkerName(workerRealPriceVo.getWorkerName()); worker.setCardPicture(workerRealPriceVo.getCardPicture()); + worker.setMobile(workerRealPriceVo.getMobile()); worker.setHighFloorFee(workerRealPriceVo.getHighFloorFee()); workerService.update(worker); // 鎵归噺鏂板閰嶉佽鍒 if(workerRealPriceVo.getWorkerRelaPriceList() != null){ workerRealPriceVo.getWorkerRelaPriceList().forEach(workerRelaPrice -> { - workerRelaPrice.setWorkerId(worker.getWorkerId()); workerRelaPrice.setGetPushOrder(0); + if(workerRelaPriceList != null){ + workerRelaPriceList.forEach(workerRelaPrice1 -> { + if(workerRelaPrice.getPutAreaId().equals(workerRelaPrice1.getPutAreaId()) && + workerRelaPrice.getGetAreaId().equals(workerRelaPrice1.getGetAreaId()) + && workerRelaPrice1.getGetPushOrder() == 1){ + workerRelaPrice.setGetPushOrder(1); + } + }); + } + workerRelaPrice.setWorkerId(worker.getWorkerId()); }); } + if(workerRealPriceVo != null){ + workerRelaPriceService.deleteByWorkerId(worker.getWorkerId()); + } final boolean b = workerRelaPriceService.saveBatch(workerRealPriceVo.getWorkerRelaPriceList()); if (b) { + //鏇存柊缂撳瓨 + WorkerRedisVo workerRedisVo = workerRedisCacheUtil.get(worker.getRegion(), worker.getWorkerId()); + if(workerRedisVo != null){ + workerRedisVo.setWorker(worker); + workerRedisVo.setWorkerRelaPriceList(workerRealPriceVo.getWorkerRelaPriceList()); + workerRedisCacheUtil.update(worker.getRegion(), workerRedisVo); + } return new ResultUtil().setData(user); } else { return ResultUtil.error("淇濆瓨澶辫触锛"); @@ -102,15 +128,27 @@ public class WorkerRelaPriceController { //鏇存柊閰嶉佸憳淇℃伅 鎺ュ彈鎸囨淳鍗 worker.setGetPushOrder(workerRealPriceVo.getGetPushOrder()); workerService.update(worker); - if(workerRealPriceVo.getGetPushOrder() != null && workerRealPriceVo.getGetPushOrder() == 1){ - // 鎵归噺鏇存柊閰嶉佽鍒 - final boolean b = workerRelaPriceService.saveOrUpdateBatch(workerRealPriceVo.getWorkerRelaPriceList()); - if (b) { - return ResultUtil.success("鏇存柊鎴愬姛锛"); - } else { - return ResultUtil.error("淇濆瓨澶辫触锛"); + // 鎵归噺鏇存柊閰嶉佽鍒 + final boolean b = workerRelaPriceService.saveOrUpdateBatch(workerRealPriceVo.getWorkerRelaPriceList()); + if (b) { + //鏇存柊缂撳瓨 + WorkerRedisVo workerRedisVo = workerRedisCacheUtil.get(worker.getRegion(), worker.getWorkerId()); + if(workerRedisVo != null){ + workerRedisVo.getWorker().setGetPushOrder(workerRealPriceVo.getGetPushOrder()); + if(workerRedisVo.getWorkerRelaPriceList() != null){ + workerRedisVo.getWorkerRelaPriceList().forEach(workerRelaPrice -> { + workerRealPriceVo.getWorkerRelaPriceList().forEach(workerRelaPrice1 -> { + if(workerRelaPrice.getId() !=null && workerRelaPrice.getId().equals(workerRelaPrice1.getId())){ + workerRelaPrice.setGetPushOrder(workerRelaPrice1.getGetPushOrder()); + } + }); + }); + } + workerRedisCacheUtil.update(worker.getRegion(), workerRedisVo); } + return ResultUtil.success("鏇存柊鎴愬姛锛"); + } else { + return ResultUtil.error("淇濆瓨澶辫触锛"); } - return ResultUtil.success("鏇存柊鎴愬姛锛"); } } diff --git a/hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/dao/mapper/ShopTakeawayMapper.java b/hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/dao/mapper/ShopTakeawayMapper.java index bd4563dd..37ff0f70 100644 --- a/hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/dao/mapper/ShopTakeawayMapper.java +++ b/hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/dao/mapper/ShopTakeawayMapper.java @@ -17,7 +17,6 @@ package cc.hiver.mall.dao.mapper; import cc.hiver.mall.entity.ShopTakeaway; import com.baomidou.mybatisplus.core.mapper.BaseMapper; -import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import org.apache.ibatis.annotations.Param; import org.springframework.stereotype.Repository; @@ -39,8 +38,6 @@ public interface ShopTakeawayMapper extends BaseMapper { void updateByPrimaryKeySelective(ShopTakeaway shopTakeaway); - Page selectList(Page page,@Param("regionId")String regionId); - List selectListByshopId(@Param("shopIdList")List shopIdList); } diff --git a/hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/dao/mapper/WorkerRelaPriceMapper.java b/hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/dao/mapper/WorkerRelaPriceMapper.java index e6f37b1a..5f6199a3 100644 --- a/hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/dao/mapper/WorkerRelaPriceMapper.java +++ b/hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/dao/mapper/WorkerRelaPriceMapper.java @@ -4,6 +4,7 @@ import cc.hiver.mall.entity.WorkerRelaPrice; import cc.hiver.mall.pojo.vo.WorkerAreaOnlineCountVO; import cc.hiver.mall.pojo.vo.WorkerMatchVO; import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.baomidou.mybatisplus.core.metadata.IPage; import org.apache.ibatis.annotations.Param; import org.springframework.stereotype.Repository; @@ -20,7 +21,9 @@ public interface WorkerRelaPriceMapper extends BaseMapper { /** * 鏌ヨ鍖归厤鏉′欢鐨勯厤閫佸憳鍒楄〃锛堣仈鏌 t_worker_rela_price銆乼_worker銆乵all_delivery_order锛 + *

    MyBatis-Plus 鍒嗛〉鎷︽埅鍣ㄤ細鏍规嵁 page 鍙傛暟鑷姩杩藉姞 COUNT 涓 LIMIT/OFFSET

    * + * @param page 鍒嗛〉鍙傛暟锛圡yBatis-Plus IPage锛 * @param shopAreaId 鍙栬揣鍖哄煙id锛堝墠鍙 shopAreaId锛 * @param putAreaId 閫佽揣鍖哄煙id * @param keyword 妯$硦鎼滅储濮撳悕鎴栨墜鏈哄彿锛堜负 null 鏃朵笉杩囨护锛 @@ -28,9 +31,10 @@ public interface WorkerRelaPriceMapper extends BaseMapper { * @param xiangtong 鐩稿悓鍦板潃锛歵rue 鍒欏彧鏌ユ墜涓婃湁鐩稿悓 putAreaId 璁㈠崟鐨勯厤閫佸憳 * @param sortField 鎺掑簭瀛楁锛歴core/avgTime/orderBkge锛堥粯璁 score锛 * @param sortOrder 鎺掑簭鏂瑰悜锛欴ESC/ASC - * @return 閰嶉佸憳鍖归厤 VO 鍒楄〃 + * @return 閰嶉佸憳鍖归厤 VO 鍒嗛〉缁撴灉 */ - List getMatchingWorkerList( + IPage getMatchingWorkerList( + IPage page, @Param("shopAreaId") String shopAreaId, @Param("orderType") Integer orderType, @Param("putAreaId") String putAreaId, diff --git a/hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/pojo/vo/WorkerMatchVO.java b/hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/pojo/vo/WorkerMatchVO.java index 9aadd79e..78afe87b 100644 --- a/hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/pojo/vo/WorkerMatchVO.java +++ b/hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/pojo/vo/WorkerMatchVO.java @@ -25,6 +25,9 @@ public class WorkerMatchVO { @ApiModelProperty("澶村儚") private String icon; + @ApiModelProperty("瀹氫綅") + private String geolocation; + @ApiModelProperty("璇勫垎") private BigDecimal score; diff --git a/hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/pojo/vo/WorkerRealPriceVo.java b/hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/pojo/vo/WorkerRealPriceVo.java index 6b3d3658..cd3d1af8 100644 --- a/hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/pojo/vo/WorkerRealPriceVo.java +++ b/hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/pojo/vo/WorkerRealPriceVo.java @@ -25,6 +25,9 @@ public class WorkerRealPriceVo implements Serializable { @ApiModelProperty(value = " 閰嶉佽鍒") private String workerName; + @ApiModelProperty(value = " 鐢佃瘽") + private String mobile; + @ApiModelProperty(value = " 閰嶉佽鍒") private String cardPicture; diff --git a/hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/pojo/vo/WorkerRedisVo.java b/hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/pojo/vo/WorkerRedisVo.java new file mode 100644 index 00000000..899b3677 --- /dev/null +++ b/hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/pojo/vo/WorkerRedisVo.java @@ -0,0 +1,28 @@ +package cc.hiver.mall.pojo.vo; + +import cc.hiver.core.entity.Worker; +import cc.hiver.mall.entity.WorkerRelaPrice; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import lombok.experimental.Accessors; + +import java.io.Serializable; +import java.util.List; + +/** + * 鍏艰亴缂撳瓨淇℃伅 + * @author 鐜嬪瘜搴 + */ +@Data +@Accessors(chain = true) +public class WorkerRedisVo implements Serializable { + + @ApiModelProperty(value = " 閰嶉佸憳ID") + private String workerId; + + @ApiModelProperty(value = " 閰嶉佸熀鏈俊鎭") + private Worker worker; + + @ApiModelProperty(value = " 閰嶉佽鍒") + private List workerRelaPriceList; +} diff --git a/hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/service/ShopTakeawayService.java b/hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/service/ShopTakeawayService.java index 0fc0a164..9e1c4552 100644 --- a/hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/service/ShopTakeawayService.java +++ b/hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/service/ShopTakeawayService.java @@ -16,8 +16,6 @@ limitations under the License. package cc.hiver.mall.service; import cc.hiver.mall.entity.ShopTakeaway; -import cc.hiver.mall.pojo.query.ShopTakeawayQuery; -import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.service.IService; import java.util.List; @@ -38,7 +36,5 @@ public interface ShopTakeawayService extends IService { void updateByPrimaryKeySelective(ShopTakeaway shopTakeaway); - Page selectList(ShopTakeawayQuery shopTakeawayQuery); - List selectListByshopId(List shopIdList); } diff --git a/hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/serviceimpl/ShopTakeawayServiceImpl.java b/hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/serviceimpl/ShopTakeawayServiceImpl.java index c1cf7e8d..f58b1c13 100644 --- a/hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/serviceimpl/ShopTakeawayServiceImpl.java +++ b/hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/serviceimpl/ShopTakeawayServiceImpl.java @@ -18,10 +18,8 @@ package cc.hiver.mall.serviceimpl; import cc.hiver.mall.dao.mapper.ShopTakeawayMapper; import cc.hiver.mall.entity.Shop; import cc.hiver.mall.entity.ShopTakeaway; -import cc.hiver.mall.pojo.query.ShopTakeawayQuery; import cc.hiver.mall.service.ShopService; import cc.hiver.mall.service.ShopTakeawayService; -import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; @@ -91,13 +89,6 @@ public class ShopTakeawayServiceImpl extends ServiceImpl selectList(ShopTakeawayQuery shopTakeawayQuery) { - final Page page = new Page<>(shopTakeawayQuery.getPageNum(), shopTakeawayQuery.getPageSize()); - final Page salePage = shopTakeawayMapper.selectList(page, shopTakeawayQuery.getRegionId()); - return salePage; - } - @Override public List selectListByshopId(List shopIdList) { return shopTakeawayMapper.selectListByshopId(shopIdList); diff --git a/hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/serviceimpl/mybatis/MallDeliveryOrderServiceImpl.java b/hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/serviceimpl/mybatis/MallDeliveryOrderServiceImpl.java index fd72285c..cc5cae3b 100644 --- a/hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/serviceimpl/mybatis/MallDeliveryOrderServiceImpl.java +++ b/hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/serviceimpl/mybatis/MallDeliveryOrderServiceImpl.java @@ -14,15 +14,13 @@ import cc.hiver.mall.mq.OrderAsyncProducer; import cc.hiver.mall.pojo.query.MallDeliveryOrderPageQuery; import cc.hiver.mall.pojo.query.MallRefundRecordPageQuery; import cc.hiver.mall.pojo.vo.MallOrderVO; +import cc.hiver.mall.pojo.vo.WorkerRedisVo; import cc.hiver.mall.service.ShopService; import cc.hiver.mall.service.mybatis.MallDeliveryOrderService; import cc.hiver.mall.service.mybatis.MallOrderService; import cc.hiver.mall.service.mybatis.MallRefundRecordService; import cc.hiver.mall.service.mybatis.MallUserCouponService; -import cc.hiver.mall.utils.MerchantOrderSeqUtil; -import cc.hiver.mall.utils.UserPendingOrderCacheUtil; -import cc.hiver.mall.utils.WaitOrderCacheUtil; -import cc.hiver.mall.utils.WorkerOrderCacheUtil; +import cc.hiver.mall.utils.*; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; import com.baomidou.mybatisplus.core.metadata.IPage; @@ -82,6 +80,9 @@ public class MallDeliveryOrderServiceImpl extends ServiceImpl qw = new LambdaQueryWrapper<>(); - qw.eq(cc.hiver.mall.entity.ShopTakeaway::getShopId, order.getShopId()); + LambdaQueryWrapper qw = new LambdaQueryWrapper<>(); + qw.eq(ShopTakeaway::getShopId, order.getShopId()); ShopTakeaway shopTakeaway = shopTakeawayMapper.selectOne(qw); if (shopTakeaway != null) { cookTimeMins = shopTakeaway.getCookingTime(); @@ -344,9 +349,11 @@ public class MallDeliveryOrderServiceImpl extends ServiceImpl gq = new LambdaQueryWrapper<>(); @@ -393,8 +400,10 @@ public class MallDeliveryOrderServiceImpl extends ServiceImpl qw = new LambdaQueryWrapper<>(); qw.eq(MallDeliveryOrder::getOrderId, order.getId()); @@ -1649,8 +1651,10 @@ public class MallOrderServiceImpl extends ServiceImpl duw = new LambdaUpdateWrapper<>(); diff --git a/hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/serviceimpl/mybatis/MallRefundRecordServiceImpl.java b/hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/serviceimpl/mybatis/MallRefundRecordServiceImpl.java index 7d62c59e..ff95fd27 100644 --- a/hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/serviceimpl/mybatis/MallRefundRecordServiceImpl.java +++ b/hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/serviceimpl/mybatis/MallRefundRecordServiceImpl.java @@ -252,8 +252,10 @@ public class MallRefundRecordServiceImpl extends ServiceImpl duw = new LambdaUpdateWrapper<>(); @@ -279,22 +285,28 @@ public class MallRefundRecordServiceImpl extends ServiceImpl duw = new LambdaUpdateWrapper<>(); @@ -346,8 +358,10 @@ public class MallRefundRecordServiceImpl extends ServiceImpl duw = new LambdaUpdateWrapper<>(); @@ -372,22 +390,28 @@ public class MallRefundRecordServiceImpl extends ServiceImpl duw = new LambdaUpdateWrapper<>(); @@ -396,8 +420,10 @@ public class MallRefundRecordServiceImpl extends ServiceImpl getAllAsList(String workerId) { + if (StringUtils.isBlank(workerId)) { + return Collections.emptyList(); + } + try { + String key = buildKey(workerId); + Map entries = redisTemplateHelper.hGetAll(key); + if (entries == null || entries.isEmpty()) { + return Collections.emptyList(); + } + List result = new ArrayList<>(entries.size()); + for (Object value : entries.values()) { + if (value != null) { + result.add(JSONUtil.toBean(value.toString(), MallDeliveryOrder.class)); + } + } + return result; + } catch (Exception e) { + log.error("鑾峰彇閰嶉佸憳鍏ㄩ儴璁㈠崟缂撳瓨澶辫触: workerId={}", workerId, e); + return Collections.emptyList(); + } + } + // ================================================================ // 鍐呴儴宸ュ叿 // ================================================================ diff --git a/hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/utils/WorkerRedisCacheUtil.java b/hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/utils/WorkerRedisCacheUtil.java new file mode 100644 index 00000000..46715b0e --- /dev/null +++ b/hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/utils/WorkerRedisCacheUtil.java @@ -0,0 +1,244 @@ +package cc.hiver.mall.utils; + +import cc.hiver.core.common.redis.RedisTemplateHelper; +import cc.hiver.mall.pojo.vo.WorkerRedisVo; +import cn.hutool.json.JSONUtil; +import lombok.extern.slf4j.Slf4j; +import org.apache.commons.lang3.StringUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +import java.util.ArrayList; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; + +/** + * 閰嶉佸憳淇℃伅缂撳瓨宸ュ叿绫 + *

    + * 搴曞眰浣跨敤 Redis Hash 缁撴瀯锛屼繚璇佹寜 regionId + workerId 缁村害鐨 O(1) 璇诲啓鏁堢巼銆 + *

    + *   Key   = WORKER_REDIS:{regionId}
    + *   Field = workerId
    + *   Value = WorkerRedisVo 鐨 JSON 搴忓垪鍖
    + * 
    + *

    + * 浣跨敤鍦烘櫙锛氱姸鎬佸彂鐢熷彉鍖栨椂锛堝垱寤恒佹洿鏂般佸彇娑堛佸畬鎴愮瓑锛夛紝 + * + * @author system + */ +@Slf4j +@Component +public class WorkerRedisCacheUtil { + + /** Redis Key 鍓嶇紑 */ + private static final String KEY_PREFIX = "WORKER_REDIS:"; + + @Autowired + private RedisTemplateHelper redisTemplateHelper; + + // ================================================================ + // Key 鏋勫缓 + // ================================================================ + + private String buildKey(String regionId) { + return KEY_PREFIX + regionId; + } + + // ================================================================ + // 瀛樻斁锛坧ut锛 + // ================================================================ + + /** + * 瀛樻斁鍗曚釜鍒扮紦瀛 + * + * @param regionId 鍖哄煙ID + * @param workerVO VO锛堝繀椤诲寘鍚湁鏁堢殑 id锛 + */ + public void put(String regionId, WorkerRedisVo workerVO) { + if (StringUtils.isBlank(regionId) || workerVO == null || StringUtils.isBlank(workerVO.getWorkerId())) { + log.info("WorkerRedisCacheUtil.put 鍙傛暟鏃犳晥, workerId={}, workerVO={}", regionId, workerVO); + return; + } + try { + String key = buildKey(regionId); + String json = JSONUtil.toJsonStr(workerVO); + redisTemplateHelper.hPut(key, workerVO.getWorkerId(), json); + log.info("缂撳瓨閰嶉佸憳: regionId={}, workerId={}", regionId, workerVO.getWorkerId()); + } catch (Exception e) { + log.info("缂撳瓨閰嶉佸憳澶辫触: regionId={}, workerId={}", regionId, workerVO.getWorkerId(), e); + } + } + + /** + * 鑾峰彇鍖哄煙鎵鏈夊湪绾块厤閫佸憳 + * + * @param regionId + * @return + */ + public List getAll(String regionId) { + if (StringUtils.isBlank(regionId)) { + return null; + } + try { + String key = buildKey(regionId); + Map entries = redisTemplateHelper.hGetAll(key); + if (entries == null || entries.isEmpty()) { + return null; + } + List result = new ArrayList<>(entries.size()); + for (Object value : entries.values()) { + if (value != null) { + result.add(JSONUtil.toBean(value.toString(), WorkerRedisVo.class)); + } + } + return result; + } catch (Exception e) { + log.info("鑾峰彇鍖哄煙鍦ㄧ嚎閰嶉佸憳缂撳瓨澶辫触: regionId={}", regionId, e); + return null; + } + } + + /** + * 鎵归噺瀛樻斁鍒扮紦瀛橈紙閫氬父鐢ㄤ簬缂撳瓨棰勭儹 / 棣栨鍔犺浇锛 + * + * @param regionId 鍖哄煙ID + * @param orders 鍒楄〃 + */ + public void putAll(String regionId, List orders) { + if (StringUtils.isBlank(regionId) || orders == null || orders.isEmpty()) { + return; + } + try { + String key = buildKey(regionId); + Map map = new LinkedHashMap<>(orders.size()); + for (WorkerRedisVo order : orders) { + if (order != null && StringUtils.isNotBlank(order.getWorkerId())) { + map.put(order.getWorkerId(), JSONUtil.toJsonStr(order)); + } + } + if (!map.isEmpty()) { + redisTemplateHelper.hPutAll(key, map); + log.info("鎵归噺缂撳瓨閰嶉佸憳: regionId={}, count={}", regionId, map.size()); + } + } catch (Exception e) { + log.info("鎵归噺缂撳瓨閰嶉佸憳澶辫触: regionId={}", regionId, e); + } + } + + // ================================================================ + // 鍒犻櫎锛坮emove锛 + // ================================================================ + + /** + * 鏍规嵁 regionId 鍜 workerId 浠庣紦瀛樹腑鍒犻櫎鎸囧畾 + * + * @param regionId 鍖哄煙ID + * @param workerId ID + */ + public void remove(String regionId, String workerId) { + if (StringUtils.isBlank(regionId) || StringUtils.isBlank(workerId)) { + log.info("UserPendingOrderCacheUtil.remove 鍙傛暟鏃犳晥, regionId={}, workerId={}", regionId, workerId); + return; + } + try { + String key = buildKey(regionId); + redisTemplateHelper.hDelete(key, workerId); + log.info("鍒犻櫎缂撳瓨: regionId={}, workerId={}", regionId, workerId); + } catch (Exception e) { + log.info("鍒犻櫎缂撳瓨澶辫触: regionId={}, workerId={}", regionId, workerId, e); + } + } + + /** + * 娓呴櫎鎸囧畾閰嶉佸憳鎵鏈夌紦瀛 + *

    + * 鍏稿瀷鍦烘櫙锛氶渶瑕佸己鍒跺埛鏂拌閰嶉佸憳缂撳瓨鏃惰皟鐢ㄣ + * + * @param regionId 鍖哄煙ID + */ + public void removeAll(String regionId) { + if (StringUtils.isBlank(regionId)) { + return; + } + try { + redisTemplateHelper.delete(buildKey(regionId)); + log.info("娓呴櫎閰嶉佸憳缂撳瓨: regionId={}", regionId); + } catch (Exception e) { + log.info("娓呴櫎閰嶉佸憳缂撳瓨澶辫触: regionId={}", regionId, e); + } + } + + // ================================================================ + // 鏇存柊锛坲pdate锛 + // ================================================================ + + /** + * 鏍规嵁 regionId 鍜 workerId 鏇存柊缂撳瓨涓殑淇℃伅 + *

    + * + * @param regionId 鍖哄煙ID + * @param workerVO 鏇存柊鍚庣殑VO + */ + public void update(String regionId, WorkerRedisVo workerVO) { + if (StringUtils.isBlank(regionId) || workerVO == null || StringUtils.isBlank(workerVO.getWorkerId())) { + log.warn("UserPendingOrderCacheUtil.update 鍙傛暟鏃犳晥, regionId={}, workerVO={}", regionId, workerVO); + return; + } + try { + // 濡傛灉鐘舵佸凡涓嶅睘浜庯紝鐩存帴鍒犻櫎 + /*if (!isTerminalStatus(workerVO.getStatus())) { + remove(regionId, workerVO.getWorkerId()); + log.debug("宸茬粓鎬侊紝浠庣紦瀛樼Щ闄: regionId={}, workerId={}, status={}", + regionId, workerVO.getWorkerId(), workerVO.getStatus()); + return; + }*/ + // 瑕嗙洊鏇存柊 + put(regionId, workerVO); + log.info("鏇存柊閰嶉佸憳缂撳瓨: regionId={}, workerId={}, status={}", + regionId, workerVO.getWorkerId()); + } catch (Exception e) { + log.info("鏇存柊鐢ㄦ埛淇℃伅缂撳瓨澶辫触: regionId={}, workerId={}", regionId, workerVO.getWorkerId(), e); + } + } + + /** + * 鑾峰彇閰嶉佸憳缂撳瓨鍗曚釜 + * + * @param regionId 鍖哄煙ID + * @param workerId ID + * @return 缂撳瓨鐨刅O锛屼笉瀛樺湪鏃惰繑鍥 null + */ + public WorkerRedisVo get(String regionId, String workerId) { + if (StringUtils.isBlank(regionId) || StringUtils.isBlank(workerId)) { + return null; + } + try { + String key = buildKey(regionId); + Object value = redisTemplateHelper.hGet(key, workerId); + if (value == null) { + return null; + } + return JSONUtil.toBean(value.toString(), WorkerRedisVo.class); + } catch (Exception e) { + log.info("鑾峰彇閰嶉佸憳鍗曚釜缂撳瓨澶辫触: regionId={}, workerId={}", regionId, workerId, e); + return null; + } + } + + /** + * 鍒ゆ柇璇ラ厤閫佸憳鐨勭紦瀛樻槸鍚﹀凡瀛樺湪 + * + * @param regionId 鍖哄煙ID + * @return true 琛ㄧず缂撳瓨瀛樺湪 + */ + public boolean exists(String regionId) { + if (StringUtils.isBlank(regionId)) { + return false; + } + Boolean hasKey = redisTemplateHelper.hasKey(buildKey(regionId)); + return hasKey != null && hasKey; + } + + +} diff --git a/hiver-modules/hiver-mall/src/main/resources/mapper/ShopTakeawayMapper.xml b/hiver-modules/hiver-mall/src/main/resources/mapper/ShopTakeawayMapper.xml index e57d6606..e402861b 100644 --- a/hiver-modules/hiver-mall/src/main/resources/mapper/ShopTakeawayMapper.xml +++ b/hiver-modules/hiver-mall/src/main/resources/mapper/ShopTakeawayMapper.xml @@ -34,7 +34,7 @@ where shop_id = #{shopId,jdbcType=VARCHAR} - select from t_shop_takeaway diff --git a/hiver-modules/hiver-mall/src/main/resources/mapper/WorkerRelaPriceMapper.xml b/hiver-modules/hiver-mall/src/main/resources/mapper/WorkerRelaPriceMapper.xml index c08221e4..4fa05c33 100644 --- a/hiver-modules/hiver-mall/src/main/resources/mapper/WorkerRelaPriceMapper.xml +++ b/hiver-modules/hiver-mall/src/main/resources/mapper/WorkerRelaPriceMapper.xml @@ -61,6 +61,7 @@ + @@ -71,6 +72,7 @@ diff --git a/hiver-modules/hiver-social/src/main/java/cc/hiver/social/controller/WechatController.java b/hiver-modules/hiver-social/src/main/java/cc/hiver/social/controller/WechatController.java index 4747b6c8..0ce25149 100644 --- a/hiver-modules/hiver-social/src/main/java/cc/hiver/social/controller/WechatController.java +++ b/hiver-modules/hiver-social/src/main/java/cc/hiver/social/controller/WechatController.java @@ -48,7 +48,9 @@ import java.io.UnsupportedEncodingException; import java.net.URLEncoder; import java.nio.charset.StandardCharsets; import java.util.ArrayList; +import java.util.HashMap; import java.util.List; +import java.util.Map; import java.util.concurrent.TimeUnit; /** @@ -147,16 +149,22 @@ public class WechatController { String phoneNumber = wechatPhoneService.getPhoneNumber(code); if (phoneNumber != null) { final User u = securityUtil.getCurrUser(); + String key = "username::" + u.getUsername(); u.setMobile(phoneNumber); u.setUsername(phoneNumber); userService.update(u); // 鍒犻櫎缂撳瓨 - redisTemplate.delete("username::" + u.getUsername()); - final String key = "username::" + u.getUsername(); + redisTemplate.delete(key); + User newUser = userService.findByMobile(phoneNumber); + final String keyNew = "username::" + newUser.getUsername(); // 缂撳瓨 final Gson gson = new GsonBuilder().setDateFormat("yyyy-MM-dd hh:mm:ss").create(); - redisTemplateHelper.set(key, gson.toJson(u), tokenProperties.getSaveLoginTime(), TimeUnit.DAYS); - return ResultUtil.data(phoneNumber); + redisTemplateHelper.set(keyNew, gson.toJson(newUser), tokenProperties.getSaveLoginTime(), TimeUnit.DAYS); + final String accessToken = securityUtil.getToken(userService.userToDTO(newUser), true); + Map map = new HashMap<>(); + map.put("mobile",phoneNumber); + map.put("accessToken",accessToken); + return ResultUtil.data(map); } else { return ResultUtil.error(401,"鑾峰彇鎵嬫満鍙峰け璐"); }