Browse Source

对接拼团数据1

master
wangfukang 2 days ago
parent
commit
f4145b49f4
  1. 16
      hiver-admin/test-output/test-report.html
  2. 9
      hiver-core/src/main/java/cc/hiver/core/serviceimpl/WorkerServiceImpl.java
  3. 4
      hiver-modules/hiver-base/src/main/java/cc/hiver/base/controller/manage/UserController.java
  4. 11
      hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/controller/CommentController.java
  5. 18
      hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/controller/MallDeliveryOrderController.java
  6. 2
      hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/controller/MallOrderController.java
  7. 9
      hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/controller/ShopTakeawayController.java
  8. 231
      hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/controller/WorkerController.java
  9. 54
      hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/controller/WorkerRelaPriceController.java
  10. 3
      hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/dao/mapper/ShopTakeawayMapper.java
  11. 8
      hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/dao/mapper/WorkerRelaPriceMapper.java
  12. 3
      hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/pojo/vo/WorkerMatchVO.java
  13. 3
      hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/pojo/vo/WorkerRealPriceVo.java
  14. 28
      hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/pojo/vo/WorkerRedisVo.java
  15. 4
      hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/service/ShopTakeawayService.java
  16. 9
      hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/serviceimpl/ShopTakeawayServiceImpl.java
  17. 29
      hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/serviceimpl/mybatis/MallDeliveryOrderServiceImpl.java
  18. 6
      hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/serviceimpl/mybatis/MallOrderServiceImpl.java
  19. 26
      hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/serviceimpl/mybatis/MallRefundRecordServiceImpl.java
  20. 29
      hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/utils/WorkerOrderCacheUtil.java
  21. 244
      hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/utils/WorkerRedisCacheUtil.java
  22. 2
      hiver-modules/hiver-mall/src/main/resources/mapper/ShopTakeawayMapper.xml
  23. 3
      hiver-modules/hiver-mall/src/main/resources/mapper/WorkerRelaPriceMapper.xml
  24. 16
      hiver-modules/hiver-social/src/main/java/cc/hiver/social/controller/WechatController.java

16
hiver-admin/test-output/test-report.html

@ -35,7 +35,7 @@
<a href="#"><span class="badge badge-primary">Hiver</span></a> <a href="#"><span class="badge badge-primary">Hiver</span></a>
</li> </li>
<li class="m-r-10"> <li class="m-r-10">
<a href="#"><span class="badge badge-primary">四月 23, 2026 18:21:01</span></a> <a href="#"><span class="badge badge-primary">四月 25, 2026 17:38:11</span></a>
</li> </li>
</ul> </ul>
</div> </div>
@ -84,7 +84,7 @@
<div class="test-detail"> <div class="test-detail">
<span class="meta text-white badge badge-sm"></span> <span class="meta text-white badge badge-sm"></span>
<p class="name">passTest</p> <p class="name">passTest</p>
<p class="text-sm"><span>18:21:02 下午</span> / <span>0.015 secs</span></p> <p class="text-sm"><span>17:38:11 下午</span> / <span>0.017 secs</span></p>
</div> </div>
<div class="test-contents d-none"> <div class="test-contents d-none">
<div class="detail-head"> <div class="detail-head">
@ -92,9 +92,9 @@
<div class="info"> <div class="info">
<div class='float-right'><span class='badge badge-default'>#test-id=1</span></div> <div class='float-right'><span class='badge badge-default'>#test-id=1</span></div>
<h5 class="test-status text-pass">passTest</h5> <h5 class="test-status text-pass">passTest</h5>
<span class='badge badge-success'>04.23.2026 18:21:02</span> <span class='badge badge-success'>04.25.2026 17:38:11</span>
<span class='badge badge-danger'>04.23.2026 18:21:02</span> <span class='badge badge-danger'>04.25.2026 17:38:11</span>
<span class='badge badge-default'>0.015 secs</span> <span class='badge badge-default'>0.017 secs</span>
</div> </div>
<div class="m-t-10 m-l-5"></div> <div class="m-t-10 m-l-5"></div>
</div> </div>
@ -104,7 +104,7 @@
<tbody> <tbody>
<tr class="event-row"> <tr class="event-row">
<td><span class="badge log pass-bg">Pass</span></td> <td><span class="badge log pass-bg">Pass</span></td>
<td>18:21:02</td> <td>17:38:11</td>
<td> <td>
Test passed Test passed
</td> </td>
@ -128,13 +128,13 @@
<div class="col-md-3"> <div class="col-md-3">
<div class="card"><div class="card-body"> <div class="card"><div class="card-body">
<p class="m-b-0">Started</p> <p class="m-b-0">Started</p>
<h3>四月 23, 2026 18:21:01</h3> <h3>四月 25, 2026 17:38:11</h3>
</div></div> </div></div>
</div> </div>
<div class="col-md-3"> <div class="col-md-3">
<div class="card"><div class="card-body"> <div class="card"><div class="card-body">
<p class="m-b-0">Ended</p> <p class="m-b-0">Ended</p>
<h3>四月 23, 2026 18:21:02</h3> <h3>四月 25, 2026 17:38:11</h3>
</div></div> </div></div>
</div> </div>
<div class="col-md-3"> <div class="col-md-3">

9
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.CommonConstant;
import cc.hiver.core.common.constant.WorkerConstant; import cc.hiver.core.common.constant.WorkerConstant;
import cc.hiver.core.common.utils.PageUtil; 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.common.vo.PageVo;
import cc.hiver.core.dao.WorkerDao; import cc.hiver.core.dao.WorkerDao;
import cc.hiver.core.entity.Worker; import cc.hiver.core.entity.Worker;
import cc.hiver.core.service.OrderOfCoreService;
import cc.hiver.core.service.WorkerService; import cc.hiver.core.service.WorkerService;
import cc.hiver.core.vo.WorkerQueryVO; import cc.hiver.core.vo.WorkerQueryVO;
import cn.hutool.core.date.DateUtil; import cn.hutool.core.date.DateUtil;
@ -38,13 +36,6 @@ import java.util.List;
public class WorkerServiceImpl implements WorkerService { public class WorkerServiceImpl implements WorkerService {
@Autowired @Autowired
private WorkerDao workerDao; private WorkerDao workerDao;
@Autowired
private SecurityUtil securityUtil;
@Autowired
private OrderOfCoreService orderOfCoreService;
@Override @Override
public WorkerDao getRepository() { public WorkerDao getRepository() {
return workerDao; return workerDao;

4
hiver-modules/hiver-base/src/main/java/cc/hiver/base/controller/manage/UserController.java

@ -674,8 +674,9 @@ public class UserController {
resultMap.put("user", wechatUser); resultMap.put("user", wechatUser);
List<Shop> shop = shopService.getShopByUserid(wechatUser.getId()); List<Shop> shop = shopService.getShopByUserid(wechatUser.getId());
if(shop != null){ if(!shop.isEmpty()){
List<String> shopIds = shop.stream().map(Shop::getId).collect(Collectors.toList()); List<String> shopIds = shop.stream().map(Shop::getId).collect(Collectors.toList());
if(!shopIds.isEmpty()){
List<ShopTakeaway> shopTakeaway = shopTakeawayService.selectListByshopId(shopIds); List<ShopTakeaway> shopTakeaway = shopTakeawayService.selectListByshopId(shopIds);
if(shopTakeaway != null){ if(shopTakeaway != null){
shop.forEach(e -> { shop.forEach(e -> {
@ -686,6 +687,7 @@ public class UserController {
} }
}); });
} }
}
resultMap.put("shop", shop); resultMap.put("shop", shop);
} }
Worker worker = workerService.findByUserId(wechatUser.getId()); Worker worker = workerService.findByUserId(wechatUser.getId());

11
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.entity.Shop;
import cc.hiver.mall.pojo.dto.ShopCacheDTO; import cc.hiver.mall.pojo.dto.ShopCacheDTO;
import cc.hiver.mall.pojo.query.CommentQuery; 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.CommentService;
import cc.hiver.mall.service.ShopService; import cc.hiver.mall.service.ShopService;
import cc.hiver.mall.utils.WorkerRedisCacheUtil;
import cn.hutool.json.JSONUtil; import cn.hutool.json.JSONUtil;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
@ -57,6 +59,9 @@ public class CommentController {
@Autowired @Autowired
private CommentService commentService; private CommentService commentService;
@Autowired
WorkerRedisCacheUtil workerRedisCacheUtil;
@Autowired @Autowired
private ShopService shopService; private ShopService shopService;
@ -98,6 +103,12 @@ public class CommentController {
// 3. 保存更新 // 3. 保存更新
workerServiceImpl.update(worker); workerServiceImpl.update(worker);
//更新缓存
WorkerRedisVo workerRedisVo = workerRedisCacheUtil.get(worker.getRegion(), worker.getWorkerId());
if(workerRedisVo != null){
workerRedisVo.setWorker(worker);
workerRedisCacheUtil.update(worker.getRegion(), workerRedisVo);
}
}else{ }else{
//更新店铺评分 //更新店铺评分
Shop shop = shopService.findById(e.getShopId()); Shop shop = shopService.findById(e.getShopId());

18
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.MallDeliveryOrder;
import cc.hiver.mall.entity.MallOrder; import cc.hiver.mall.entity.MallOrder;
import cc.hiver.mall.pojo.query.MallDeliveryOrderPageQuery; 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.service.mybatis.MallDeliveryOrderService;
import cc.hiver.mall.utils.WaitOrderCacheUtil; import cc.hiver.mall.utils.WaitOrderCacheUtil;
import cc.hiver.mall.utils.WorkerOrderCacheUtil; import cc.hiver.mall.utils.WorkerOrderCacheUtil;
import cc.hiver.mall.utils.WorkerRedisCacheUtil;
import cn.hutool.core.util.StrUtil; import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
@ -47,6 +49,9 @@ public class MallDeliveryOrderController {
@Autowired @Autowired
JPushServiceImpl jPushService; JPushServiceImpl jPushService;
@Autowired
WorkerRedisCacheUtil workerRedisCacheUtil;
@Autowired @Autowired
WorkerOrderCacheUtil workerOrderCacheUtil; WorkerOrderCacheUtil workerOrderCacheUtil;
@ -166,17 +171,20 @@ public class MallDeliveryOrderController {
//当前人没有注册兼职,先赋予兼职身份 //当前人没有注册兼职,先赋予兼职身份
final User user = securityUtil.getCurrUser(); final User user = securityUtil.getCurrUser();
Worker worker = new Worker(); Worker worker = new Worker();
if(worker == null){
worker.setWorkerName(user.getNickname()); worker.setWorkerName(user.getNickname());
worker.setUserId(user.getId()); worker.setUserId(user.getId());
worker.setAvgTime(BigDecimal.valueOf(30)); worker.setAvgTime(BigDecimal.valueOf(25));
worker.setMobile(user.getMobile()); worker.setMobile(user.getMobile());
worker.setRegion(regionId); worker.setRegion(regionId);
worker.setIsOnLine(CommonConstant.ON_LINE); worker.setIsOnLine(CommonConstant.ON_LINE);
worker.setScore(BigDecimal.valueOf(5)); worker.setScore(BigDecimal.valueOf(5));
workerService.save(worker); workerService.save(worker);
} //添加缓存
Integer result = mallDeliveryOrderService.workerAccept(user.getMobile(),deliveryId, workerId,workerName,groupId); 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){ if(result == 0){
return ResultUtil.success("配送单不存在"); return ResultUtil.success("配送单不存在");
}else if (result == 1){ }else if (result == 1){
@ -194,6 +202,8 @@ public class MallDeliveryOrderController {
return ResultUtil.success("配送单已被接取或已取消"); return ResultUtil.success("配送单已被接取或已取消");
}else if(result == 2){ }else if(result == 2){
return ResultUtil.success("该单已指定其他配送员,无法抢单"); return ResultUtil.success("该单已指定其他配送员,无法抢单");
}else if(result == 5){
return ResultUtil.success("已被禁止接单,无法抢单");
}else{ }else{
return ResultUtil.success("接单成功"); return ResultUtil.success("接单成功");
} }

2
hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/controller/MallOrderController.java

@ -164,7 +164,7 @@ public class MallOrderController {
*/ */
@PostMapping("/shopMakeTime") @PostMapping("/shopMakeTime")
@ApiOperation(value = "商家出餐") @ApiOperation(value = "商家出餐")
public Result shopMakeTime(@ApiParam("订单ID") @RequestParam String orderId) { public Result shopMakeTime(@ApiParam("订单ID") @RequestParam(value = "orderId") String orderId) {
try { try {
mallOrderService.shopMakeTime(orderId); mallOrderService.shopMakeTime(orderId);
return ResultUtil.success("出餐成功"); return ResultUtil.success("出餐成功");

9
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.utils.ResultUtil;
import cc.hiver.core.common.vo.Result; import cc.hiver.core.common.vo.Result;
import cc.hiver.mall.entity.ShopTakeaway; import cc.hiver.mall.entity.ShopTakeaway;
import cc.hiver.mall.pojo.query.ShopTakeawayQuery;
import cc.hiver.mall.service.ShopTakeawayService; import cc.hiver.mall.service.ShopTakeawayService;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam; import io.swagger.annotations.ApiParam;
@ -86,11 +84,4 @@ public class ShopTakeawayController {
return ResultUtil.success("删除成功"); return ResultUtil.success("删除成功");
} }
@RequestMapping(value = "/getList", method = RequestMethod.POST)
@ApiOperation("根据学校id获取外卖业务配置列表")
public Result<Page<ShopTakeaway>> getList(
@ApiParam("店铺id列表") @RequestBody ShopTakeawayQuery shopTakeawayQuery) {
final Page<ShopTakeaway> shopTakeawaysPage = shopTakeawayService.selectList(shopTakeawayQuery);
return ResultUtil.data(shopTakeawaysPage);
}
} }

231
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.WorkerAppVO;
import cc.hiver.core.vo.WorkerQueryVO; import cc.hiver.core.vo.WorkerQueryVO;
import cc.hiver.mall.dao.mapper.WorkerRelaPriceMapper; import cc.hiver.mall.dao.mapper.WorkerRelaPriceMapper;
import cc.hiver.mall.entity.MallDeliveryOrder;
import cc.hiver.mall.entity.Recharge; import cc.hiver.mall.entity.Recharge;
import cc.hiver.mall.entity.ShopArea; 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.WorkerAreaOnlineCountVO;
import cc.hiver.mall.pojo.vo.WorkerMatchVO; 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.RechargeService;
import cc.hiver.mall.service.ShopAreaService; 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 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.Api;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam; import io.swagger.annotations.ApiParam;
@ -26,13 +34,12 @@ import lombok.Data;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheConfig; import org.springframework.cache.annotation.CacheConfig;
import org.springframework.data.domain.Page;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import javax.validation.Valid; import javax.validation.Valid;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.util.List; import java.util.*;
/** /**
* 配送员管理接口 * 配送员管理接口
@ -53,6 +60,12 @@ public class WorkerController {
@Autowired @Autowired
private RechargeService rechargeService; private RechargeService rechargeService;
@Autowired
WorkerRedisCacheUtil workerRedisCacheUtil;
@Autowired
private WorkerRelaPriceService workerRelaPriceService;
@Autowired @Autowired
private ShopAreaService shopAreaService; private ShopAreaService shopAreaService;
@ -65,7 +78,7 @@ public class WorkerController {
@RequestMapping(value = "/getByCondition", method = RequestMethod.POST) @RequestMapping(value = "/getByCondition", method = RequestMethod.POST)
@ApiOperation(value = "多条件分页获取订单列表") @ApiOperation(value = "多条件分页获取订单列表")
public Result<Page<Worker>> getByCondition(@RequestBody WorkerQueryVO worker) { public Result<Page<Worker>> getByCondition(@RequestBody WorkerQueryVO worker) {
Page<Worker> page = workerService.findByCondition(worker); Page<Worker> page = (Page<Worker>) workerService.findByCondition(worker);
return new ResultUtil<Page<Worker>>().setData(page); return new ResultUtil<Page<Worker>>().setData(page);
} }
@ -114,7 +127,7 @@ public class WorkerController {
}else{ }else{
u.setWorkerName(user.getNickname()); u.setWorkerName(user.getNickname());
u.setUserId(user.getId()); u.setUserId(user.getId());
u.setAvgTime(BigDecimal.valueOf(30)); u.setAvgTime(BigDecimal.valueOf(25));
u.setMobile(user.getMobile()); u.setMobile(user.getMobile());
u.setIsOnLine(CommonConstant.OFF_LINE); u.setIsOnLine(CommonConstant.OFF_LINE);
u.setScore(BigDecimal.valueOf(5)); u.setScore(BigDecimal.valueOf(5));
@ -138,6 +151,12 @@ public class WorkerController {
u.setRegionTitle(""); u.setRegionTitle("");
} }
workerService.update(u); 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("修改成功"); return ResultUtil.success("修改成功");
} }
@ -205,6 +224,14 @@ public class WorkerController {
public Result<Object> onLine(@RequestParam("id") String id) { public Result<Object> onLine(@RequestParam("id") String id) {
try { try {
workerService.onLine(id); workerService.onLine(id);
//添加缓存
Worker worker = workerService.get(id);
WorkerRedisVo workerVO = new WorkerRedisVo();
workerVO.setWorkerId(worker.getWorkerId());
workerVO.setWorker(worker);
List<WorkerRelaPrice> workerRelaPriceList = workerRelaPriceService.selectByWorkerId(worker.getWorkerId());
workerVO.setWorkerRelaPriceList(workerRelaPriceList);
workerRedisCacheUtil.put(worker.getRegion(),workerVO);
return ResultUtil.success("上线成功"); return ResultUtil.success("上线成功");
} catch (Exception e) { } catch (Exception e) {
log.error(e.getMessage(), e); log.error(e.getMessage(), e);
@ -225,6 +252,8 @@ public class WorkerController {
public Result<Object> offLine(@RequestParam("id")String id) { public Result<Object> offLine(@RequestParam("id")String id) {
try { try {
workerService.offLine(id); workerService.offLine(id);
//缓存去掉
workerRedisCacheUtil.remove(workerService.get(id).getRegion(),id);
return ResultUtil.success("下线成功"); return ResultUtil.success("下线成功");
} catch (Exception e) { } catch (Exception e) {
log.error(e.getMessage(), e); log.error(e.getMessage(), e);
@ -237,6 +266,8 @@ public class WorkerController {
*/ */
@Data @Data
public static class WorkerMatchDTO { public static class WorkerMatchDTO {
/** 学校/区域id(用于缓存查找,对应 worker.region) */
private String regionId;
/** 取货区域id(商家所在区域) */ /** 取货区域id(商家所在区域) */
private String shopAreaId; private String shopAreaId;
/** 接单类型 0外卖 1快递 */ /** 接单类型 0外卖 1快递 */
@ -256,17 +287,162 @@ public class WorkerController {
* orderBkge -> 配送佣金正序 * orderBkge -> 配送佣金正序
*/ */
private String sortField; private String sortField;
/** 页码(从1开始),默认1 */
private Integer pageNum = 1;
/** 每页条数,默认10 */
private Integer pageSize = 10;
} }
@Autowired
private WorkerOrderCacheUtil workerOrderCacheUtil;
@RequestMapping(value = "/getMatchingWorkerList", method = RequestMethod.POST) @RequestMapping(value = "/getMatchingWorkerList", method = RequestMethod.POST)
@ApiOperation(value = "匹配抢单配送员列表") @ApiOperation(value = "匹配抢单配送员列表")
public Result<List<WorkerMatchVO>> getMatchingWorkerList(@RequestBody WorkerMatchDTO dto) { public Result<IPage<WorkerMatchVO>> getMatchingWorkerList(@RequestBody WorkerMatchDTO dto) {
// 计算排序方向:avgTime/orderBkge 默认 ASC,score 默认 DESC int pageNum = dto.getPageNum() != null && dto.getPageNum() > 0 ? dto.getPageNum() : 1;
int pageSize = dto.getPageSize() != null && dto.getPageSize() > 0 ? dto.getPageSize() : 10;
// ============ 1. 从缓存获取当前区域所有在线配送员 ============
List<WorkerRedisVo> 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<WorkerMatchVO> 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;
// ---- 交易保障过滤:rebate_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<MallDeliveryOrder> 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<WorkerMatchVO> 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 正序
comparator = Comparator.comparing(WorkerMatchVO::getAvgTime,
Comparator.nullsLast(Comparator.naturalOrder()));
}
// 二级排序:rebateAmount 倒序
comparator = comparator.thenComparing(WorkerMatchVO::getRebateAmount,
Comparator.nullsLast(Comparator.reverseOrder()));
filteredList.sort(comparator);
// ============ 3. 内存分页 ============
IPage<WorkerMatchVO> 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<IPage<WorkerMatchVO>>().setData(page);
}
// ============ 4. 缓存为空时回退到数据库查询(带分页) ============
String sortOrder = "DESC"; String sortOrder = "DESC";
if ("avgTime".equals(dto.getSortField()) || "orderBkge".equals(dto.getSortField())) { if ("avgTime".equals(dto.getSortField()) || "orderBkge".equals(dto.getSortField())) {
sortOrder = "ASC"; sortOrder = "ASC";
} }
List<WorkerMatchVO> list = workerRelaPriceMapper.getMatchingWorkerList( IPage<WorkerMatchVO> pageParam = new Page<>(pageNum, pageSize);
IPage<WorkerMatchVO> pageResult = workerRelaPriceMapper.getMatchingWorkerList(
pageParam,
dto.getShopAreaId(), dto.getShopAreaId(),
dto.getOrderType(), dto.getOrderType(),
dto.getPutAreaId(), dto.getPutAreaId(),
@ -276,12 +452,51 @@ public class WorkerController {
dto.getSortField(), dto.getSortField(),
sortOrder sortOrder
); );
return new ResultUtil<List<WorkerMatchVO>>().setData(list); return new ResultUtil<IPage<WorkerMatchVO>>().setData(pageResult);
} }
@RequestMapping(value = "/getOnlineWorkerByArea", method = RequestMethod.GET) @RequestMapping(value = "/getOnlineWorkerByArea", method = RequestMethod.GET)
@ApiOperation(value = "查询各食堂区域在线配送员数量") @ApiOperation(value = "查询各食堂区域在线配送员数量")
public Result<List<WorkerAreaOnlineCountVO>> getOnlineWorkerByArea(@RequestParam(value = "parentId")String parentId) { public Result<List<WorkerAreaOnlineCountVO>> getOnlineWorkerByArea(@RequestParam(value = "parentId")String parentId) {
//parentId就是regionId
List<WorkerRedisVo> workerRedisVoList = workerRedisCacheUtil.getAll(parentId);
if (workerRedisVoList != null && !workerRedisVoList.isEmpty()) {
// 按 areaId 统计在线且接收指派单的配送员数量(Set 去重 workerId)
// key=areaId, value={areaName, Set<workerId>}
Map<String, String> areaNameMap = new HashMap<>();
Map<String, Set<String>> areaWorkerMap = new HashMap<>();
for (WorkerRedisVo vo : workerRedisVoList) {
if (vo.getWorker() == null) continue;
Worker w = vo.getWorker();
// worker.getPushOrder == 1 代表该配送员接收指派单
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<WorkerAreaOnlineCountVO> result = new ArrayList<>();
for (Map.Entry<String, String> entry : areaNameMap.entrySet()) {
WorkerAreaOnlineCountVO countVO = new WorkerAreaOnlineCountVO();
countVO.setAreaId(entry.getKey());
countVO.setAreaName(entry.getValue());
Set<String> workers = areaWorkerMap.get(entry.getKey());
countVO.setOnlineWorkerCount(workers != null ? workers.size() : 0);
result.add(countVO);
}
return new ResultUtil<List<WorkerAreaOnlineCountVO>>().setData(result);
}
List<WorkerAreaOnlineCountVO> list = workerRelaPriceMapper.getOnlineWorkerCountByCanteenArea(parentId); List<WorkerAreaOnlineCountVO> list = workerRelaPriceMapper.getOnlineWorkerCountByCanteenArea(parentId);
return new ResultUtil<List<WorkerAreaOnlineCountVO>>().setData(list); return new ResultUtil<List<WorkerAreaOnlineCountVO>>().setData(list);
} }

54
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.core.service.WorkerService;
import cc.hiver.mall.entity.WorkerRelaPrice; import cc.hiver.mall.entity.WorkerRelaPrice;
import cc.hiver.mall.pojo.vo.WorkerRealPriceVo; 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.service.mybatis.WorkerRelaPriceService;
import cc.hiver.mall.utils.WorkerRedisCacheUtil;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
@ -33,7 +35,7 @@ import org.springframework.web.bind.annotation.*;
import java.util.List; import java.util.List;
/** /**
* 店铺外卖业务配置控制器 * 配送员佣金设定配置控制器
* *
* @author cc * @author cc
*/ */
@ -46,6 +48,9 @@ public class WorkerRelaPriceController {
@Autowired @Autowired
private WorkerRelaPriceService workerRelaPriceService; private WorkerRelaPriceService workerRelaPriceService;
@Autowired
WorkerRedisCacheUtil workerRedisCacheUtil;
@Autowired @Autowired
private WorkerService workerService; private WorkerService workerService;
@ -59,6 +64,8 @@ public class WorkerRelaPriceController {
Worker worker = workerService.findByWorkerId(workerId); Worker worker = workerService.findByWorkerId(workerId);
if(worker != null){ if(worker != null){
workerRealPriceVo.setWorkerName(worker.getWorkerName()); workerRealPriceVo.setWorkerName(worker.getWorkerName());
workerRealPriceVo.setMobile(worker.getMobile());
workerRealPriceVo.setGetPushOrder(worker.getGetPushOrder());
workerRealPriceVo.setCardPicture(worker.getCardPicture()); workerRealPriceVo.setCardPicture(worker.getCardPicture());
workerRealPriceVo.setHighFloorFee(worker.getHighFloorFee()); workerRealPriceVo.setHighFloorFee(worker.getHighFloorFee());
final List<WorkerRelaPrice> workerRelaPriceList = workerRelaPriceService.selectByWorkerId(workerId); final List<WorkerRelaPrice> workerRelaPriceList = workerRelaPriceService.selectByWorkerId(workerId);
@ -72,23 +79,42 @@ public class WorkerRelaPriceController {
public Result<User> batchAdd(@RequestBody WorkerRealPriceVo workerRealPriceVo) { public Result<User> batchAdd(@RequestBody WorkerRealPriceVo workerRealPriceVo) {
User user = userService.findById(workerRealPriceVo.getUserId()); User user = userService.findById(workerRealPriceVo.getUserId());
Worker worker = workerService.findByUserId(workerRealPriceVo.getUserId()); Worker worker = workerService.findByUserId(workerRealPriceVo.getUserId());
if(workerRealPriceVo != null){
workerRelaPriceService.deleteByWorkerId(worker.getWorkerId()); List<WorkerRelaPrice> workerRelaPriceList = workerRelaPriceService.selectByWorkerId(worker.getWorkerId());
}
//更新配送员信息 //更新配送员信息
worker.setWorkerName(workerRealPriceVo.getWorkerName()); worker.setWorkerName(workerRealPriceVo.getWorkerName());
worker.setCardPicture(workerRealPriceVo.getCardPicture()); worker.setCardPicture(workerRealPriceVo.getCardPicture());
worker.setMobile(workerRealPriceVo.getMobile());
worker.setHighFloorFee(workerRealPriceVo.getHighFloorFee()); worker.setHighFloorFee(workerRealPriceVo.getHighFloorFee());
workerService.update(worker); workerService.update(worker);
// 批量新增配送规则 // 批量新增配送规则
if(workerRealPriceVo.getWorkerRelaPriceList() != null){ if(workerRealPriceVo.getWorkerRelaPriceList() != null){
workerRealPriceVo.getWorkerRelaPriceList().forEach(workerRelaPrice -> { workerRealPriceVo.getWorkerRelaPriceList().forEach(workerRelaPrice -> {
workerRelaPrice.setWorkerId(worker.getWorkerId());
workerRelaPrice.setGetPushOrder(0); 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()); final boolean b = workerRelaPriceService.saveBatch(workerRealPriceVo.getWorkerRelaPriceList());
if (b) { 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<User>().setData(user); return new ResultUtil<User>().setData(user);
} else { } else {
return ResultUtil.error("保存失败!"); return ResultUtil.error("保存失败!");
@ -102,15 +128,27 @@ public class WorkerRelaPriceController {
//更新配送员信息 接受指派单 //更新配送员信息 接受指派单
worker.setGetPushOrder(workerRealPriceVo.getGetPushOrder()); worker.setGetPushOrder(workerRealPriceVo.getGetPushOrder());
workerService.update(worker); workerService.update(worker);
if(workerRealPriceVo.getGetPushOrder() != null && workerRealPriceVo.getGetPushOrder() == 1){
// 批量更新配送规则 // 批量更新配送规则
final boolean b = workerRelaPriceService.saveOrUpdateBatch(workerRealPriceVo.getWorkerRelaPriceList()); final boolean b = workerRelaPriceService.saveOrUpdateBatch(workerRealPriceVo.getWorkerRelaPriceList());
if (b) { 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("更新成功!"); return ResultUtil.success("更新成功!");
} else { } else {
return ResultUtil.error("保存失败!"); return ResultUtil.error("保存失败!");
} }
} }
return ResultUtil.success("更新成功!");
}
} }

3
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 cc.hiver.mall.entity.ShopTakeaway;
import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.apache.ibatis.annotations.Param; import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Repository; import org.springframework.stereotype.Repository;
@ -39,8 +38,6 @@ public interface ShopTakeawayMapper extends BaseMapper<ShopTakeaway> {
void updateByPrimaryKeySelective(ShopTakeaway shopTakeaway); void updateByPrimaryKeySelective(ShopTakeaway shopTakeaway);
Page<ShopTakeaway> selectList(Page<ShopTakeaway> page,@Param("regionId")String regionId);
List<ShopTakeaway> selectListByshopId(@Param("shopIdList")List<String> shopIdList); List<ShopTakeaway> selectListByshopId(@Param("shopIdList")List<String> shopIdList);
} }

8
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.WorkerAreaOnlineCountVO;
import cc.hiver.mall.pojo.vo.WorkerMatchVO; import cc.hiver.mall.pojo.vo.WorkerMatchVO;
import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.apache.ibatis.annotations.Param; import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Repository; import org.springframework.stereotype.Repository;
@ -20,7 +21,9 @@ public interface WorkerRelaPriceMapper extends BaseMapper<WorkerRelaPrice> {
/** /**
* 查询匹配条件的配送员列表联查 t_worker_rela_pricet_workermall_delivery_order * 查询匹配条件的配送员列表联查 t_worker_rela_pricet_workermall_delivery_order
* <p>MyBatis-Plus 分页拦截器会根据 page 参数自动追加 COUNT LIMIT/OFFSET</p>
* *
* @param page 分页参数MyBatis-Plus IPage
* @param shopAreaId 取货区域id前台 shopAreaId * @param shopAreaId 取货区域id前台 shopAreaId
* @param putAreaId 送货区域id * @param putAreaId 送货区域id
* @param keyword 模糊搜索姓名或手机号 null 时不过滤 * @param keyword 模糊搜索姓名或手机号 null 时不过滤
@ -28,9 +31,10 @@ public interface WorkerRelaPriceMapper extends BaseMapper<WorkerRelaPrice> {
* @param xiangtong 相同地址true 则只查手上有相同 putAreaId 订单的配送员 * @param xiangtong 相同地址true 则只查手上有相同 putAreaId 订单的配送员
* @param sortField 排序字段score/avgTime/orderBkge默认 score * @param sortField 排序字段score/avgTime/orderBkge默认 score
* @param sortOrder 排序方向DESC/ASC * @param sortOrder 排序方向DESC/ASC
* @return 配送员匹配 VO 列表 * @return 配送员匹配 VO 分页结果
*/ */
List<WorkerMatchVO> getMatchingWorkerList( IPage<WorkerMatchVO> getMatchingWorkerList(
IPage<WorkerMatchVO> page,
@Param("shopAreaId") String shopAreaId, @Param("shopAreaId") String shopAreaId,
@Param("orderType") Integer orderType, @Param("orderType") Integer orderType,
@Param("putAreaId") String putAreaId, @Param("putAreaId") String putAreaId,

3
hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/pojo/vo/WorkerMatchVO.java

@ -25,6 +25,9 @@ public class WorkerMatchVO {
@ApiModelProperty("头像") @ApiModelProperty("头像")
private String icon; private String icon;
@ApiModelProperty("定位")
private String geolocation;
@ApiModelProperty("评分") @ApiModelProperty("评分")
private BigDecimal score; private BigDecimal score;

3
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 = " 配送规则") @ApiModelProperty(value = " 配送规则")
private String workerName; private String workerName;
@ApiModelProperty(value = " 电话")
private String mobile;
@ApiModelProperty(value = " 配送规则") @ApiModelProperty(value = " 配送规则")
private String cardPicture; private String cardPicture;

28
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<WorkerRelaPrice> workerRelaPriceList;
}

4
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; package cc.hiver.mall.service;
import cc.hiver.mall.entity.ShopTakeaway; 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 com.baomidou.mybatisplus.extension.service.IService;
import java.util.List; import java.util.List;
@ -38,7 +36,5 @@ public interface ShopTakeawayService extends IService<ShopTakeaway> {
void updateByPrimaryKeySelective(ShopTakeaway shopTakeaway); void updateByPrimaryKeySelective(ShopTakeaway shopTakeaway);
Page<ShopTakeaway> selectList(ShopTakeawayQuery shopTakeawayQuery);
List<ShopTakeaway> selectListByshopId(List<String> shopIdList); List<ShopTakeaway> selectListByshopId(List<String> shopIdList);
} }

9
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.dao.mapper.ShopTakeawayMapper;
import cc.hiver.mall.entity.Shop; import cc.hiver.mall.entity.Shop;
import cc.hiver.mall.entity.ShopTakeaway; import cc.hiver.mall.entity.ShopTakeaway;
import cc.hiver.mall.pojo.query.ShopTakeawayQuery;
import cc.hiver.mall.service.ShopService; import cc.hiver.mall.service.ShopService;
import cc.hiver.mall.service.ShopTakeawayService; import cc.hiver.mall.service.ShopTakeawayService;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
@ -91,13 +89,6 @@ public class ShopTakeawayServiceImpl extends ServiceImpl<ShopTakeawayMapper, Sh
} }
} }
@Override
public Page<ShopTakeaway> selectList(ShopTakeawayQuery shopTakeawayQuery) {
final Page<ShopTakeaway> page = new Page<>(shopTakeawayQuery.getPageNum(), shopTakeawayQuery.getPageSize());
final Page<ShopTakeaway> salePage = shopTakeawayMapper.selectList(page, shopTakeawayQuery.getRegionId());
return salePage;
}
@Override @Override
public List<ShopTakeaway> selectListByshopId(List<String> shopIdList) { public List<ShopTakeaway> selectListByshopId(List<String> shopIdList) {
return shopTakeawayMapper.selectListByshopId(shopIdList); return shopTakeawayMapper.selectListByshopId(shopIdList);

29
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.MallDeliveryOrderPageQuery;
import cc.hiver.mall.pojo.query.MallRefundRecordPageQuery; import cc.hiver.mall.pojo.query.MallRefundRecordPageQuery;
import cc.hiver.mall.pojo.vo.MallOrderVO; 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.ShopService;
import cc.hiver.mall.service.mybatis.MallDeliveryOrderService; import cc.hiver.mall.service.mybatis.MallDeliveryOrderService;
import cc.hiver.mall.service.mybatis.MallOrderService; import cc.hiver.mall.service.mybatis.MallOrderService;
import cc.hiver.mall.service.mybatis.MallRefundRecordService; import cc.hiver.mall.service.mybatis.MallRefundRecordService;
import cc.hiver.mall.service.mybatis.MallUserCouponService; import cc.hiver.mall.service.mybatis.MallUserCouponService;
import cc.hiver.mall.utils.MerchantOrderSeqUtil; import cc.hiver.mall.utils.*;
import cc.hiver.mall.utils.UserPendingOrderCacheUtil;
import cc.hiver.mall.utils.WaitOrderCacheUtil;
import cc.hiver.mall.utils.WorkerOrderCacheUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.core.metadata.IPage;
@ -82,6 +80,9 @@ public class MallDeliveryOrderServiceImpl extends ServiceImpl<MallDeliveryOrderM
@Autowired @Autowired
private ShopTakeawayMapper shopTakeawayMapper; private ShopTakeawayMapper shopTakeawayMapper;
@Autowired
WorkerRedisCacheUtil workerRedisCacheUtil;
@Autowired @Autowired
WorkerOrderCacheUtil workerOrderCacheUtil; WorkerOrderCacheUtil workerOrderCacheUtil;
@ -149,6 +150,10 @@ public class MallDeliveryOrderServiceImpl extends ServiceImpl<MallDeliveryOrderM
@Override @Override
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
public Integer workerAccept(String workerPhone, String deliveryId, String workerId,String workerName, String groupId) { public Integer workerAccept(String workerPhone, String deliveryId, String workerId,String workerName, String groupId) {
Worker worker = workerServiceImpl.findByWorkerId(workerId);
if(worker != null && worker.getWorkerStatus() == 3){
return 5;
}
MallDeliveryOrder delivery = this.getById(deliveryId); MallDeliveryOrder delivery = this.getById(deliveryId);
if (delivery == null) return 0;//throw new RuntimeException("配送单不存在"); if (delivery == null) return 0;//throw new RuntimeException("配送单不存在");
if (delivery.getStatus() != STATUS_WAIT_ACCEPT) return 1;//throw new RuntimeException("配送单已被接取或已取消"); if (delivery.getStatus() != STATUS_WAIT_ACCEPT) return 1;//throw new RuntimeException("配送单已被接取或已取消");
@ -315,8 +320,8 @@ public class MallDeliveryOrderServiceImpl extends ServiceImpl<MallDeliveryOrderM
if (order != null) { if (order != null) {
long cookTimeMins = 10; // default long cookTimeMins = 10; // default
try { try {
LambdaQueryWrapper<cc.hiver.mall.entity.ShopTakeaway> qw = new LambdaQueryWrapper<>(); LambdaQueryWrapper<ShopTakeaway> qw = new LambdaQueryWrapper<>();
qw.eq(cc.hiver.mall.entity.ShopTakeaway::getShopId, order.getShopId()); qw.eq(ShopTakeaway::getShopId, order.getShopId());
ShopTakeaway shopTakeaway = shopTakeawayMapper.selectOne(qw); ShopTakeaway shopTakeaway = shopTakeawayMapper.selectOne(qw);
if (shopTakeaway != null) { if (shopTakeaway != null) {
cookTimeMins = shopTakeaway.getCookingTime(); cookTimeMins = shopTakeaway.getCookingTime();
@ -344,9 +349,11 @@ public class MallDeliveryOrderServiceImpl extends ServiceImpl<MallDeliveryOrderM
this.update(uw); this.update(uw);
//更新缓存 //更新缓存
MallDeliveryOrder delivery1 = workerOrderCacheUtil.get(workerId, deliveryId); MallDeliveryOrder delivery1 = workerOrderCacheUtil.get(workerId, deliveryId);
if(delivery1 != null){
delivery1.setStatus(STATUS_DELIVERING); delivery1.setStatus(STATUS_DELIVERING);
delivery1.setGetTime(new Date()); delivery1.setGetTime(new Date());
workerOrderCacheUtil.update(workerId,delivery1); workerOrderCacheUtil.update(workerId,delivery1);
}
//如果groupID有值 ,需要更新所有子订单状态 //如果groupID有值 ,需要更新所有子订单状态
if(delivery.getGroupId() != null){ if(delivery.getGroupId() != null){
LambdaQueryWrapper<MallOrderGroup> gq = new LambdaQueryWrapper<>(); LambdaQueryWrapper<MallOrderGroup> gq = new LambdaQueryWrapper<>();
@ -393,9 +400,11 @@ public class MallDeliveryOrderServiceImpl extends ServiceImpl<MallDeliveryOrderM
this.update(uw); this.update(uw);
//更新缓存 //更新缓存
MallDeliveryOrder delivery = workerOrderCacheUtil.get(workerId, deliveryId); MallDeliveryOrder delivery = workerOrderCacheUtil.get(workerId, deliveryId);
if(delivery != null){
delivery.setArriveTime(new Date()); delivery.setArriveTime(new Date());
workerOrderCacheUtil.update(workerId,delivery); workerOrderCacheUtil.update(workerId,delivery);
} }
}
/** /**
* 配送员送达状态配送中 -> 已送达 * 配送员送达状态配送中 -> 已送达
@ -473,6 +482,12 @@ public class MallDeliveryOrderServiceImpl extends ServiceImpl<MallDeliveryOrderM
workerServiceImpl.update(worker); workerServiceImpl.update(worker);
//更新缓存 //更新缓存
workerOrderCacheUtil.remove(workerId,deliveryId); workerOrderCacheUtil.remove(workerId,deliveryId);
//更新缓存
WorkerRedisVo workerRedisVo = workerRedisCacheUtil.get(worker.getRegion(), worker.getWorkerId());
if(workerRedisVo != null){
workerRedisVo.setWorker(worker);
workerRedisCacheUtil.update(worker.getRegion(), workerRedisVo);
}
} }
/** /**
@ -501,10 +516,12 @@ public class MallDeliveryOrderServiceImpl extends ServiceImpl<MallDeliveryOrderM
this.update(uw); this.update(uw);
//更新抢单大厅缓存 //更新抢单大厅缓存
MallDeliveryOrder delivery1 = waitOrderCacheUtil.get(delivery.getRegionId(), deliveryId); MallDeliveryOrder delivery1 = waitOrderCacheUtil.get(delivery.getRegionId(), deliveryId);
if(delivery1 != null){
delivery1.setWorkerId(null); delivery1.setWorkerId(null);
delivery1.setWorkerName(null); delivery1.setWorkerName(null);
delivery1.setWorkerPhone(null); delivery1.setWorkerPhone(null);
waitOrderCacheUtil.update(delivery1.getRegionId(), delivery1); waitOrderCacheUtil.update(delivery1.getRegionId(), delivery1);
}
//给用户发送短信通知被拒绝 //给用户发送短信通知被拒绝
smsUtil.sendCode(delivery.getReceiverPhone(), null, SettingConstant.SMS_TYPE.SMS_REJECT_ORDER.name()); smsUtil.sendCode(delivery.getReceiverPhone(), null, SettingConstant.SMS_TYPE.SMS_REJECT_ORDER.name());
} }

6
hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/serviceimpl/mybatis/MallOrderServiceImpl.java

@ -1640,8 +1640,10 @@ public class MallOrderServiceImpl extends ServiceImpl<MallOrderMapper, MallOrder
smsUtil.sendCode(delivery.getWorkerPhone(), null, SettingConstant.SMS_TYPE.SMS_ORDERRETURN.name()); smsUtil.sendCode(delivery.getWorkerPhone(), null, SettingConstant.SMS_TYPE.SMS_ORDERRETURN.name());
//更新缓存 //更新缓存
MallDeliveryOrder delivery1 = workerOrderCacheUtil.get(workerId,delivery.getId()); MallDeliveryOrder delivery1 = workerOrderCacheUtil.get(workerId,delivery.getId());
if(delivery1 != null){
delivery1.setIsReturn(IS_RETURN_EXPRESS); delivery1.setIsReturn(IS_RETURN_EXPRESS);
workerOrderCacheUtil.update(workerId,delivery1); workerOrderCacheUtil.update(workerId,delivery1);
}
}else{ }else{
LambdaQueryWrapper<MallDeliveryOrder> qw = new LambdaQueryWrapper<>(); LambdaQueryWrapper<MallDeliveryOrder> qw = new LambdaQueryWrapper<>();
qw.eq(MallDeliveryOrder::getOrderId, order.getId()); qw.eq(MallDeliveryOrder::getOrderId, order.getId());
@ -1649,10 +1651,12 @@ public class MallOrderServiceImpl extends ServiceImpl<MallOrderMapper, MallOrder
smsUtil.sendCode(delivery.getWorkerPhone(), null, SettingConstant.SMS_TYPE.SMS_ORDERRETURN.name()); smsUtil.sendCode(delivery.getWorkerPhone(), null, SettingConstant.SMS_TYPE.SMS_ORDERRETURN.name());
//更新缓存 //更新缓存
MallDeliveryOrder delivery1 = workerOrderCacheUtil.get(workerId,delivery.getId()); MallDeliveryOrder delivery1 = workerOrderCacheUtil.get(workerId,delivery.getId());
if(delivery1 != null){
delivery1.setIsReturn(IS_RETURN_EXPRESS); delivery1.setIsReturn(IS_RETURN_EXPRESS);
workerOrderCacheUtil.update(workerId,delivery1); workerOrderCacheUtil.update(workerId,delivery1);
} }
} }
}
List<MallOrderGoods> goodsList = mallOrderGoodsMapper.selectByOrderId(order.getId()); List<MallOrderGoods> goodsList = mallOrderGoodsMapper.selectByOrderId(order.getId());
if (goodsList == null || goodsList.isEmpty()) return; if (goodsList == null || goodsList.isEmpty()) return;
@ -1808,8 +1812,10 @@ public class MallOrderServiceImpl extends ServiceImpl<MallOrderMapper, MallOrder
updateOrderStatus(order.getId(), STATUS_WAIT_REFUND); updateOrderStatus(order.getId(), STATUS_WAIT_REFUND);
//更新缓存 //更新缓存
MallOrderVO vo = userPendingOrderCacheUtil.get(order.getUserId(), order.getId()); MallOrderVO vo = userPendingOrderCacheUtil.get(order.getUserId(), order.getId());
if(vo != null){
vo.setStatus(STATUS_WAIT_REFUND); vo.setStatus(STATUS_WAIT_REFUND);
userPendingOrderCacheUtil.update(order.getUserId(),vo); userPendingOrderCacheUtil.update(order.getUserId(),vo);
}
//如果是外卖,更新配送单状态 //如果是外卖,更新配送单状态
if(order.getDeliveryType() == DELIVERY_TYPE_EXPRESS){ if(order.getDeliveryType() == DELIVERY_TYPE_EXPRESS){
LambdaUpdateWrapper<MallDeliveryOrder> duw = new LambdaUpdateWrapper<>(); LambdaUpdateWrapper<MallDeliveryOrder> duw = new LambdaUpdateWrapper<>();

26
hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/serviceimpl/mybatis/MallRefundRecordServiceImpl.java

@ -252,8 +252,10 @@ public class MallRefundRecordServiceImpl extends ServiceImpl<MallRefundRecordMap
updateOrderStatusAndReturn(mallRefundRecord.getOrderId(), STATUS_WAIT_PICKUP); updateOrderStatusAndReturn(mallRefundRecord.getOrderId(), STATUS_WAIT_PICKUP);
//更新缓存 //更新缓存
MallOrderVO vo = userPendingOrderCacheUtil.get(order.getUserId(), order.getId()); MallOrderVO vo = userPendingOrderCacheUtil.get(order.getUserId(), order.getId());
if(vo != null){
vo.setStatus(STATUS_WAIT_PICKUP); vo.setStatus(STATUS_WAIT_PICKUP);
userPendingOrderCacheUtil.update(order.getUserId(),vo); userPendingOrderCacheUtil.update(order.getUserId(),vo);
}
}else{ }else{
//面对面拼团 //面对面拼团
if(mallRefundRecord.getOrderType() == STATUS_WAIT_PICKUP){ if(mallRefundRecord.getOrderType() == STATUS_WAIT_PICKUP){
@ -262,15 +264,19 @@ public class MallRefundRecordServiceImpl extends ServiceImpl<MallRefundRecordMap
updateOrderStatusAndReturn(mallRefundRecord.getOrderId(), STATUS_WAIT_PICKUP); updateOrderStatusAndReturn(mallRefundRecord.getOrderId(), STATUS_WAIT_PICKUP);
//更新缓存 //更新缓存
MallOrderVO vo = userPendingOrderCacheUtil.get(order.getUserId(), order.getId()); MallOrderVO vo = userPendingOrderCacheUtil.get(order.getUserId(), order.getId());
if(vo != null){
vo.setStatus(STATUS_WAIT_PICKUP); vo.setStatus(STATUS_WAIT_PICKUP);
userPendingOrderCacheUtil.update(order.getUserId(),vo); userPendingOrderCacheUtil.update(order.getUserId(),vo);
}
}else if(delivery.getStatus() == DELIVERY_TYPE_SELF){ }else if(delivery.getStatus() == DELIVERY_TYPE_SELF){
updateOrderStatusAndReturn(mallRefundRecord.getOrderId(), STATUS_DELIVERING); updateOrderStatusAndReturn(mallRefundRecord.getOrderId(), STATUS_DELIVERING);
//更新缓存 //更新缓存
MallOrderVO vo = userPendingOrderCacheUtil.get(order.getUserId(), order.getId()); MallOrderVO vo = userPendingOrderCacheUtil.get(order.getUserId(), order.getId());
if(vo != null){
vo.setStatus(STATUS_DELIVERING); vo.setStatus(STATUS_DELIVERING);
userPendingOrderCacheUtil.update(order.getUserId(),vo); userPendingOrderCacheUtil.update(order.getUserId(),vo);
} }
}
//更新配送单isReturn //更新配送单isReturn
LambdaUpdateWrapper<MallDeliveryOrder> duw = new LambdaUpdateWrapper<>(); LambdaUpdateWrapper<MallDeliveryOrder> duw = new LambdaUpdateWrapper<>();
duw.eq(MallDeliveryOrder::getOrderId, mallRefundRecord.getOrderId()) duw.eq(MallDeliveryOrder::getOrderId, mallRefundRecord.getOrderId())
@ -279,23 +285,29 @@ public class MallRefundRecordServiceImpl extends ServiceImpl<MallRefundRecordMap
//更新缓存 //更新缓存
MallDeliveryOrder delivery1 = workerOrderCacheUtil.get(delivery.getWorkerId(),delivery.getId()); MallDeliveryOrder delivery1 = workerOrderCacheUtil.get(delivery.getWorkerId(),delivery.getId());
if(delivery1 != null){
delivery1.setIsReturn(0); delivery1.setIsReturn(0);
workerOrderCacheUtil.update(delivery.getWorkerId(),delivery1); workerOrderCacheUtil.update(delivery.getWorkerId(),delivery1);
}
}else{ }else{
MallDeliveryOrder delivery = findDeliveryByOrderId(mallRefundRecord.getOrderId()); MallDeliveryOrder delivery = findDeliveryByOrderId(mallRefundRecord.getOrderId());
if(delivery.getStatus() == STATUS_WAIT_SHOP){ if(delivery.getStatus() == STATUS_WAIT_SHOP){
updateOrderStatusAndReturn(mallRefundRecord.getOrderId(), STATUS_WAIT_PICKUP); updateOrderStatusAndReturn(mallRefundRecord.getOrderId(), STATUS_WAIT_PICKUP);
//更新缓存 //更新缓存
MallOrderVO vo = userPendingOrderCacheUtil.get(order.getUserId(), order.getId()); MallOrderVO vo = userPendingOrderCacheUtil.get(order.getUserId(), order.getId());
if(vo != null){
vo.setStatus(STATUS_WAIT_PICKUP); vo.setStatus(STATUS_WAIT_PICKUP);
userPendingOrderCacheUtil.update(order.getUserId(),vo); userPendingOrderCacheUtil.update(order.getUserId(),vo);
}
}else if(delivery.getStatus() == DELIVERY_TYPE_SELF){ }else if(delivery.getStatus() == DELIVERY_TYPE_SELF){
updateOrderStatusAndReturn(mallRefundRecord.getOrderId(), STATUS_DELIVERING); updateOrderStatusAndReturn(mallRefundRecord.getOrderId(), STATUS_DELIVERING);
//更新缓存 //更新缓存
MallOrderVO vo = userPendingOrderCacheUtil.get(order.getUserId(), order.getId()); MallOrderVO vo = userPendingOrderCacheUtil.get(order.getUserId(), order.getId());
if(vo != null){
vo.setStatus(STATUS_DELIVERING); vo.setStatus(STATUS_DELIVERING);
userPendingOrderCacheUtil.update(order.getUserId(),vo); userPendingOrderCacheUtil.update(order.getUserId(),vo);
} }
}
//更新配送单isReturn //更新配送单isReturn
LambdaUpdateWrapper<MallDeliveryOrder> duw = new LambdaUpdateWrapper<>(); LambdaUpdateWrapper<MallDeliveryOrder> duw = new LambdaUpdateWrapper<>();
duw.eq(MallDeliveryOrder::getOrderId, mallRefundRecord.getOrderId()) duw.eq(MallDeliveryOrder::getOrderId, mallRefundRecord.getOrderId())
@ -346,8 +358,10 @@ public class MallRefundRecordServiceImpl extends ServiceImpl<MallRefundRecordMap
updateOrderStatusAndReturn(mallRefundRecord.getOrderId(), STATUS_WAIT_PICKUP); updateOrderStatusAndReturn(mallRefundRecord.getOrderId(), STATUS_WAIT_PICKUP);
//更新缓存 //更新缓存
MallOrderVO vo = userPendingOrderCacheUtil.get(order.getUserId(), order.getId()); MallOrderVO vo = userPendingOrderCacheUtil.get(order.getUserId(), order.getId());
if(vo != null){
vo.setStatus(STATUS_WAIT_PICKUP); vo.setStatus(STATUS_WAIT_PICKUP);
userPendingOrderCacheUtil.update(order.getUserId(),vo); userPendingOrderCacheUtil.update(order.getUserId(),vo);
}
}else{ }else{
//面对面拼团 //面对面拼团
if(mallRefundRecord.getOrderType() == STATUS_WAIT_PICKUP){ if(mallRefundRecord.getOrderType() == STATUS_WAIT_PICKUP){
@ -356,15 +370,19 @@ public class MallRefundRecordServiceImpl extends ServiceImpl<MallRefundRecordMap
updateOrderStatusAndReturn(mallRefundRecord.getOrderId(), STATUS_WAIT_PICKUP); updateOrderStatusAndReturn(mallRefundRecord.getOrderId(), STATUS_WAIT_PICKUP);
//更新缓存 //更新缓存
MallOrderVO vo = userPendingOrderCacheUtil.get(order.getUserId(), order.getId()); MallOrderVO vo = userPendingOrderCacheUtil.get(order.getUserId(), order.getId());
if(vo != null){
vo.setStatus(STATUS_WAIT_PICKUP); vo.setStatus(STATUS_WAIT_PICKUP);
userPendingOrderCacheUtil.update(order.getUserId(),vo); userPendingOrderCacheUtil.update(order.getUserId(),vo);
}
}else if(delivery.getStatus() == DELIVERY_TYPE_SELF){ }else if(delivery.getStatus() == DELIVERY_TYPE_SELF){
updateOrderStatusAndReturn(mallRefundRecord.getOrderId(), STATUS_DELIVERING); updateOrderStatusAndReturn(mallRefundRecord.getOrderId(), STATUS_DELIVERING);
//更新缓存 //更新缓存
MallOrderVO vo = userPendingOrderCacheUtil.get(order.getUserId(), order.getId()); MallOrderVO vo = userPendingOrderCacheUtil.get(order.getUserId(), order.getId());
if(vo != null){
vo.setStatus(STATUS_DELIVERING); vo.setStatus(STATUS_DELIVERING);
userPendingOrderCacheUtil.update(order.getUserId(),vo); userPendingOrderCacheUtil.update(order.getUserId(),vo);
} }
}
//更新配送单isReturn //更新配送单isReturn
LambdaUpdateWrapper<MallDeliveryOrder> duw = new LambdaUpdateWrapper<>(); LambdaUpdateWrapper<MallDeliveryOrder> duw = new LambdaUpdateWrapper<>();
duw.eq(MallDeliveryOrder::getOrderId, mallRefundRecord.getOrderId()) duw.eq(MallDeliveryOrder::getOrderId, mallRefundRecord.getOrderId())
@ -372,23 +390,29 @@ public class MallRefundRecordServiceImpl extends ServiceImpl<MallRefundRecordMap
mallDeliveryOrderMapper.update(null, duw); mallDeliveryOrderMapper.update(null, duw);
//更新缓存 //更新缓存
MallDeliveryOrder delivery1 = workerOrderCacheUtil.get(delivery.getWorkerId(),delivery.getId()); MallDeliveryOrder delivery1 = workerOrderCacheUtil.get(delivery.getWorkerId(),delivery.getId());
if(delivery1 != null){
delivery1.setIsReturn(0); delivery1.setIsReturn(0);
workerOrderCacheUtil.update(delivery.getWorkerId(),delivery1); workerOrderCacheUtil.update(delivery.getWorkerId(),delivery1);
}
}else{ }else{
MallDeliveryOrder delivery = findDeliveryByOrderId(mallRefundRecord.getOrderId()); MallDeliveryOrder delivery = findDeliveryByOrderId(mallRefundRecord.getOrderId());
if(delivery.getStatus() == STATUS_WAIT_SHOP){ if(delivery.getStatus() == STATUS_WAIT_SHOP){
updateOrderStatusAndReturn(mallRefundRecord.getOrderId(), STATUS_WAIT_PICKUP); updateOrderStatusAndReturn(mallRefundRecord.getOrderId(), STATUS_WAIT_PICKUP);
//更新缓存 //更新缓存
MallOrderVO vo = userPendingOrderCacheUtil.get(order.getUserId(), order.getId()); MallOrderVO vo = userPendingOrderCacheUtil.get(order.getUserId(), order.getId());
if(vo != null){
vo.setStatus(STATUS_WAIT_PICKUP); vo.setStatus(STATUS_WAIT_PICKUP);
userPendingOrderCacheUtil.update(order.getUserId(),vo); userPendingOrderCacheUtil.update(order.getUserId(),vo);
}
}else if(delivery.getStatus() == DELIVERY_TYPE_SELF){ }else if(delivery.getStatus() == DELIVERY_TYPE_SELF){
updateOrderStatusAndReturn(mallRefundRecord.getOrderId(), STATUS_DELIVERING); updateOrderStatusAndReturn(mallRefundRecord.getOrderId(), STATUS_DELIVERING);
//更新缓存 //更新缓存
MallOrderVO vo = userPendingOrderCacheUtil.get(order.getUserId(), order.getId()); MallOrderVO vo = userPendingOrderCacheUtil.get(order.getUserId(), order.getId());
if(vo != null){
vo.setStatus(STATUS_DELIVERING); vo.setStatus(STATUS_DELIVERING);
userPendingOrderCacheUtil.update(order.getUserId(),vo); userPendingOrderCacheUtil.update(order.getUserId(),vo);
} }
}
//更新配送单isReturn //更新配送单isReturn
LambdaUpdateWrapper<MallDeliveryOrder> duw = new LambdaUpdateWrapper<>(); LambdaUpdateWrapper<MallDeliveryOrder> duw = new LambdaUpdateWrapper<>();
duw.eq(MallDeliveryOrder::getOrderId, mallRefundRecord.getOrderId()) duw.eq(MallDeliveryOrder::getOrderId, mallRefundRecord.getOrderId())
@ -396,10 +420,12 @@ public class MallRefundRecordServiceImpl extends ServiceImpl<MallRefundRecordMap
mallDeliveryOrderMapper.update(null, duw); mallDeliveryOrderMapper.update(null, duw);
//更新缓存 //更新缓存
MallDeliveryOrder delivery1 = workerOrderCacheUtil.get(delivery.getWorkerId(),delivery.getId()); MallDeliveryOrder delivery1 = workerOrderCacheUtil.get(delivery.getWorkerId(),delivery.getId());
if(delivery1 != null){
delivery1.setIsReturn(0); delivery1.setIsReturn(0);
workerOrderCacheUtil.update(delivery.getWorkerId(),delivery1); workerOrderCacheUtil.update(delivery.getWorkerId(),delivery1);
} }
} }
}
}else{ }else{
//同意退款 //同意退款
MallOrder order = mallOrderService.getById(mallRefundRecord.getOrderId()); MallOrder order = mallOrderService.getById(mallRefundRecord.getOrderId());

29
hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/utils/WorkerOrderCacheUtil.java

@ -308,6 +308,35 @@ public class WorkerOrderCacheUtil {
return hasKey != null && hasKey; return hasKey != null && hasKey;
} }
/**
* 获取配送员所有待完成订单不分页不过滤
*
* @param workerId 配送员ID
* @return 该配送员所有缓存订单缓存不存在时返回空列表
*/
public List<MallDeliveryOrder> getAllAsList(String workerId) {
if (StringUtils.isBlank(workerId)) {
return Collections.emptyList();
}
try {
String key = buildKey(workerId);
Map<Object, Object> entries = redisTemplateHelper.hGetAll(key);
if (entries == null || entries.isEmpty()) {
return Collections.emptyList();
}
List<MallDeliveryOrder> 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();
}
}
// ================================================================ // ================================================================
// 内部工具 // 内部工具
// ================================================================ // ================================================================

244
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;
/**
* 配送员信息缓存工具类
* <p>
* 底层使用 Redis Hash 结构保证按 regionId + workerId 维度的 O(1) 读写效率
* <pre>
* Key = WORKER_REDIS:{regionId}
* Field = workerId
* Value = WorkerRedisVo JSON 序列化
* </pre>
* <p>
* 使用场景状态发生变化时创建更新取消完成等
*
* @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;
}
// ================================================================
// 存放(put)
// ================================================================
/**
* 存放单个到缓存
*
* @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<WorkerRedisVo> getAll(String regionId) {
if (StringUtils.isBlank(regionId)) {
return null;
}
try {
String key = buildKey(regionId);
Map<Object, Object> entries = redisTemplateHelper.hGetAll(key);
if (entries == null || entries.isEmpty()) {
return null;
}
List<WorkerRedisVo> 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<WorkerRedisVo> orders) {
if (StringUtils.isBlank(regionId) || orders == null || orders.isEmpty()) {
return;
}
try {
String key = buildKey(regionId);
Map<String, String> 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);
}
}
// ================================================================
// 删除(remove)
// ================================================================
/**
* 根据 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);
}
}
/**
* 清除指定配送员所有缓存
* <p>
* 典型场景需要强制刷新该配送员缓存时调用
*
* @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);
}
}
// ================================================================
// 更新(update)
// ================================================================
/**
* 根据 regionId workerId 更新缓存中的信息
* <p>
*
* @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 缓存的VO不存在时返回 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;
}
}

2
hiver-modules/hiver-mall/src/main/resources/mapper/ShopTakeawayMapper.xml

@ -34,7 +34,7 @@
where shop_id = #{shopId,jdbcType=VARCHAR} where shop_id = #{shopId,jdbcType=VARCHAR}
</select> </select>
<select id="selectList" resultMap="BaseResultMap" parameterType="java.lang.String" > <select id="selectListByRegionId" resultMap="BaseResultMap" parameterType="java.lang.String" >
select select
<include refid="Base_Column_List" /> <include refid="Base_Column_List" />
from t_shop_takeaway from t_shop_takeaway

3
hiver-modules/hiver-mall/src/main/resources/mapper/WorkerRelaPriceMapper.xml

@ -61,6 +61,7 @@
<result column="score" property="score"/> <result column="score" property="score"/>
<result column="avg_time" property="avgTime"/> <result column="avg_time" property="avgTime"/>
<result column="rebate_amount" property="rebateAmount"/> <result column="rebate_amount" property="rebateAmount"/>
<result column="geolocation" property="geolocation"/>
<result column="high_floor_fee" property="highFloorFee"/> <result column="high_floor_fee" property="highFloorFee"/>
<result column="order_bkge" property="orderBkge"/> <result column="order_bkge" property="orderBkge"/>
<result column="order_wait_count" property="orderWaitCount"/> <result column="order_wait_count" property="orderWaitCount"/>
@ -71,6 +72,7 @@
<select id="getMatchingWorkerList" resultMap="WorkerMatchVOMap"> <select id="getMatchingWorkerList" resultMap="WorkerMatchVOMap">
SELECT SELECT
w.worker_id, w.worker_id,
w.geolocation,
w.worker_name, w.worker_name,
w.mobile, w.mobile,
w.icon, w.icon,
@ -144,6 +146,7 @@
w.avg_time ASC w.avg_time ASC
</otherwise> </otherwise>
</choose> </choose>
, w.rebate_amount DESC
</select> </select>
<resultMap id="WorkerAreaOnlineCountVOMap" type="cc.hiver.mall.pojo.vo.WorkerAreaOnlineCountVO"> <resultMap id="WorkerAreaOnlineCountVOMap" type="cc.hiver.mall.pojo.vo.WorkerAreaOnlineCountVO">

16
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.net.URLEncoder;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
/** /**
@ -147,16 +149,22 @@ public class WechatController {
String phoneNumber = wechatPhoneService.getPhoneNumber(code); String phoneNumber = wechatPhoneService.getPhoneNumber(code);
if (phoneNumber != null) { if (phoneNumber != null) {
final User u = securityUtil.getCurrUser(); final User u = securityUtil.getCurrUser();
String key = "username::" + u.getUsername();
u.setMobile(phoneNumber); u.setMobile(phoneNumber);
u.setUsername(phoneNumber); u.setUsername(phoneNumber);
userService.update(u); userService.update(u);
// 删除缓存 // 删除缓存
redisTemplate.delete("username::" + u.getUsername()); redisTemplate.delete(key);
final String key = "username::" + u.getUsername(); User newUser = userService.findByMobile(phoneNumber);
final String keyNew = "username::" + newUser.getUsername();
// 缓存 // 缓存
final Gson gson = new GsonBuilder().setDateFormat("yyyy-MM-dd hh:mm:ss").create(); final Gson gson = new GsonBuilder().setDateFormat("yyyy-MM-dd hh:mm:ss").create();
redisTemplateHelper.set(key, gson.toJson(u), tokenProperties.getSaveLoginTime(), TimeUnit.DAYS); redisTemplateHelper.set(keyNew, gson.toJson(newUser), tokenProperties.getSaveLoginTime(), TimeUnit.DAYS);
return ResultUtil.data(phoneNumber); final String accessToken = securityUtil.getToken(userService.userToDTO(newUser), true);
Map<String,String> map = new HashMap<>();
map.put("mobile",phoneNumber);
map.put("accessToken",accessToken);
return ResultUtil.data(map);
} else { } else {
return ResultUtil.error(401,"获取手机号失败"); return ResultUtil.error(401,"获取手机号失败");
} }

Loading…
Cancel
Save