feat(订单和机柜): 添加用户租赁机柜查询和订单筛选功能

添加根据用户ID和企业ID查询租赁机柜的功能
在订单查询接口中增加hasReturn参数用于筛选已归还/未归还订单
在QywxMessageJob中添加支付状态检查逻辑
This commit is contained in:
dzq 2025-07-02 11:28:40 +08:00
parent a068d54493
commit e48735a463
8 changed files with 119 additions and 10 deletions

View File

@ -131,6 +131,10 @@ public class QywxMessageJob {
log.info("订单[{}]为租赁订单,无需发送逾期提醒", order.getOrderId());
return;
}
if (!order.getPayStatus().equals(2)) {
log.info("订单[{}]未支付,无需发送逾期提醒", order.getOrderId());
return;
}
// 6. 获取用户信息
List<QyUserEntity> userList = qyUserApplicationService.getUserByUserId(order.getUserid());
QyUserEntity user = null;

View File

@ -45,16 +45,36 @@ public class CabinetCellController {
private final CabinetMainboardModelFactory cabinetMainboardModelFactory;
private final CabinetCellApplicationService cabinetCellApplicationService;
/**
* 管理员获取机柜格口列表
* @param shopId
* @return
*/
@GetMapping("/detail")
public ResponseDTO<List<CabinetDetailDTO>> getCabinetDetail(@RequestParam Long shopId) {
return ResponseDTO.ok(smartCabinetApplicationService.getCabinetDetail(shopId));
}
/**
* 获取正在出租的机柜格口列表
* @param shopId
* @return
*/
@GetMapping("/detail/renting")
public ResponseDTO<List<RentingCabinetDetailDTO>> getRentingCabinetDetail(@RequestParam Long shopId) {
return ResponseDTO.ok(smartCabinetApplicationService.getRentingCabinetDetail(shopId));
}
/**
* 用户获取自己租用的机柜格口列表
* @param corpid
* @param ab98UserId
* @return
*/
@GetMapping("/detail/user")
public ResponseDTO<List<CabinetDetailDTO>> getCabinetDetail(@RequestParam String corpid, @RequestParam Long ab98UserId) {
return ResponseDTO.ok(smartCabinetApplicationService.getUserRentedCabinetList(corpid, ab98UserId));
}
@Operation(summary = "配置格口商品库存")
@PutMapping("/configureGoodsCellsStock/{cellId}/{goodsId}/{stock}")

View File

@ -84,8 +84,10 @@ public class OrderController extends BaseController {
* @return 包含订单列表的响应
*/
@GetMapping("/user/{openid}")
public ResponseDTO<GetOrdersByOpenIdDTO> getOrdersByOpenId(@PathVariable String openid, @RequestParam(required = false) String corpid) {
GetOrdersByOpenIdDTO result = orderApplicationService.getOrdersByOpenId(openid, corpid);
public ResponseDTO<GetOrdersByOpenIdDTO> getOrdersByOpenId(@PathVariable String openid,
@RequestParam(required = false) String corpid,
@RequestParam(required = false) Integer hasReturn) {
GetOrdersByOpenIdDTO result = orderApplicationService.getOrdersByOpenId(openid, corpid, hasReturn);
return ResponseDTO.ok(result);
}
@ -94,8 +96,9 @@ public class OrderController extends BaseController {
* @return 包含订单列表的响应
*/
@GetMapping("/user/qy/{qyUserId}")
public ResponseDTO<GetOrdersByOpenIdDTO> getOrdersByOpenId(@PathVariable Long qyUserId) {
GetOrdersByOpenIdDTO result = orderApplicationService.getOrdersByQyUserId(qyUserId);
public ResponseDTO<GetOrdersByOpenIdDTO> getOrdersByOpenId(@PathVariable Long qyUserId,
@RequestParam(required = false) Integer hasReturn) {
GetOrdersByOpenIdDTO result = orderApplicationService.getOrdersByQyUserId(qyUserId, hasReturn);
return ResponseDTO.ok(result);
}

View File

@ -111,4 +111,12 @@ public interface CabinetCellMapper extends BaseMapper<CabinetCellEntity> {
"LEFT JOIN ab98_user au ON so.name = au.name AND so.mobile = au.tel AND au.deleted = 0 " +
"${ew.customSqlSegment} ")
List<CabinetCellLatestOrderDTO> selectLatestOrderInfoByCell(@Param(Constants.WRAPPER) Wrapper<?> queryWrapper);
@Select("SELECT cc.* " +
"FROM cabinet_cell cc " +
"INNER JOIN shop_order_goods sog ON cc.cell_id = sog.cell_id AND sog.deleted = 0 " +
"INNER JOIN shop_order so ON sog.order_id = so.order_id AND so.deleted = 0 " +
"INNER JOIN ab98_user au ON so.name = au.name AND so.mobile = au.tel AND au.deleted = 0 " +
"${ew.customSqlSegment}")
List<CabinetCellEntity> selectRentedCellsByAb98UserIdAndCorpid(@Param(Constants.WRAPPER) Wrapper<?> queryWrapper);
}

View File

@ -40,4 +40,6 @@ public interface CabinetCellService extends IService<CabinetCellEntity> {
List<CabinetCellDO> selectCabinetCellDOList(Long cabinetId);
List<CabinetCellLatestOrderDTO> selectLatestOrderInfoByCell(List<Long> cellIds);
List<CabinetCellEntity> selectRentedCellsByAb98UserIdAndCorpid(Long ab98UserId, String corpid);
}

View File

@ -76,4 +76,19 @@ public class CabinetCellServiceImpl extends ServiceImpl<CabinetCellMapper, Cabin
.in("cc.cell_id", cellIds);
return baseMapper.selectLatestOrderInfoByCell(queryWrapper);
}
@Override
public List<CabinetCellEntity> selectRentedCellsByAb98UserIdAndCorpid(Long ab98UserId, String corpid) {
QueryWrapper<CabinetCellEntity> queryWrapper = new QueryWrapper<>();
queryWrapper.eq("cc.is_rented", 1)
.eq("cc.deleted", 0)
.eq("so.deleted", 0)
.eq("sog.deleted", 0)
.eq("sog.mode", 3)
.eq("sog.status", 1)
.eq("au.deleted", 0)
.eq("so.corpid", corpid)
.eq("au.ab98_user_id", ab98UserId);
return baseMapper.selectRentedCellsByAb98UserIdAndCorpid(queryWrapper);
}
}

View File

@ -323,4 +323,43 @@ public class SmartCabinetApplicationService {
public List<SmartCabinetDO> getConsumablesCabinetList() {
return smartCabinetService.selectSmartCabinetDOList();
}
public List<CabinetDetailDTO> getUserRentedCabinetList(String corpid, Long ab98UserId) {
List<CabinetCellEntity> cabinetCells = cabinetCellService.selectRentedCellsByAb98UserIdAndCorpid(ab98UserId, corpid);
// 获取所有智能柜单元格和商品的基础数据
QueryWrapper<SmartCabinetEntity> smartCabinetEntityQueryWrapper = new QueryWrapper<>();
smartCabinetEntityQueryWrapper.in("cabinet_id", cabinetCells.stream()
.map(CabinetCellEntity::getCabinetId).filter(Objects::nonNull).distinct().collect(Collectors.toList()))
.eq("deleted", false);
List<SmartCabinetEntity> smartCabinets = smartCabinetService.list(smartCabinetEntityQueryWrapper);
List<CabinetDetailDTO> result = new ArrayList<>();
// 遍历每个智能柜构建详细信息
for (SmartCabinetEntity cabinet : smartCabinets) {
CabinetDetailDTO cabinetDetailDTO = new CabinetDetailDTO();
// 设置柜体基础信息
cabinetDetailDTO.setCabinetId(cabinet.getCabinetId());
cabinetDetailDTO.setCabinetName(cabinet.getCabinetName());
cabinetDetailDTO.setLockControlNo(cabinet.getLockControlNo());
// 处理柜体下的所有单元格
List<CabinetDetailDTO.CellInfoDTO> cellInfoList = cabinetCells.stream()
.filter(cell -> cell.getCabinetId().equals(cabinet.getCabinetId()))
.map(cell -> {
CabinetDetailDTO.CellInfoDTO cellInfo = new CabinetDetailDTO.CellInfoDTO();
// 设置单元格基础信息
cellInfo.setCellId(cell.getCellId());
cellInfo.setCellNo(cell.getCellNo());
cellInfo.setPinNo(cell.getPinNo());
cellInfo.setStock(cell.getStock());
return cellInfo;
}).collect(Collectors.toList());
// 将单元格列表加入柜体信息
cabinetDetailDTO.setCells(cellInfoList);
result.add(cabinetDetailDTO);
}
return result;
}
}

View File

@ -54,10 +54,7 @@ import com.agileboot.domain.shop.paymentOperationLog.command.AddPaymentOperation
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Objects;
import java.util.*;
import java.util.stream.Collectors;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
@ -413,7 +410,7 @@ public class OrderApplicationService {
* @param corpid 企业微信 ID
* @return 包含订单列表订单商品列表和商品列表的 DTO 对象
*/
public GetOrdersByOpenIdDTO getOrdersByOpenId(String openid, String corpid) {
public GetOrdersByOpenIdDTO getOrdersByOpenId(String openid, String corpid, Integer hasReturn) {
// 根据 openid 获取 Ab98 用户信息
Ab98UserEntity ab98User = ab98UserService.getByOpenid(openid);
@ -440,15 +437,28 @@ public class OrderApplicationService {
}
}
// 根据查询条件获取订单列表
if (Integer.valueOf(1).equals(hasReturn)) {
orderQueryWrapper.eq("pay_status", 2);
}
List<ShopOrderEntity> orderList = orderService.list(orderQueryWrapper);
// 构建订单商品查询条件
QueryWrapper<ShopOrderGoodsEntity> orderGoodsQueryWrapper = new QueryWrapper<>();
// 添加订单 ID 作为查询条件查询属于这些订单的商品
orderGoodsQueryWrapper.in("order_id", orderList.stream().map(ShopOrderEntity::getOrderId).collect(Collectors.toList()));
if (Integer.valueOf(1).equals(hasReturn)) {
orderGoodsQueryWrapper.eq("status", 2);
} else if (Integer.valueOf(0).equals(hasReturn)) {
orderGoodsQueryWrapper.eq("status", 1);
}
// 根据查询条件获取订单商品列表
List<ShopOrderGoodsEntity> orderGoods = orderGoodsService.list(orderGoodsQueryWrapper);
Set<Long> orderIds = orderGoods.stream().map(ShopOrderGoodsEntity::getOrderId).collect(Collectors.toSet());
orderList = orderList.stream()
.filter(order -> orderIds.contains(order.getOrderId()))
.collect(Collectors.toList());
// 构建商品查询条件
QueryWrapper<ShopGoodsEntity> goodsQueryWrapper = new QueryWrapper<>();
// 添加商品 ID 作为查询条件查询这些商品信息
@ -466,7 +476,7 @@ public class OrderApplicationService {
* @param qyUserId 企业微信用户 ID
* @return 包含订单列表订单商品列表和商品列表的 DTO 对象
*/
public GetOrdersByOpenIdDTO getOrdersByQyUserId(Long qyUserId) {
public GetOrdersByOpenIdDTO getOrdersByQyUserId(Long qyUserId, Integer hasReturn) {
// 校验 qyUserId 是否为空为空则抛出异常
if (qyUserId == null) {
throw new ApiException(ErrorCode.Client.COMMON_REQUEST_PARAMETERS_INVALID, "qyUserId不能为空");
@ -497,6 +507,9 @@ public class OrderApplicationService {
}
}
// 根据查询条件获取订单列表
if (Integer.valueOf(1).equals(hasReturn)) {
orderQueryWrapper.eq("pay_status", 2);
}
List<ShopOrderEntity> orderList = orderService.list(orderQueryWrapper);
// 构建订单商品查询条件
@ -508,6 +521,11 @@ public class OrderApplicationService {
// 添加订单 ID 作为查询条件查询属于这些订单的商品
QueryWrapper<ShopOrderGoodsEntity> orderGoodsQueryWrapper = new QueryWrapper<>();
orderGoodsQueryWrapper.in("order_id", orderList.stream().map(ShopOrderEntity::getOrderId).collect(Collectors.toList()));
if (Integer.valueOf(1).equals(hasReturn)) {
orderGoodsQueryWrapper.eq("status", 2);
} else if (Integer.valueOf(0).equals(hasReturn)) {
orderGoodsQueryWrapper.eq("status", 1);
}
List<ShopOrderGoodsEntity> orderGoods = orderGoodsService.list(orderGoodsQueryWrapper);
QueryWrapper<ShopGoodsEntity> goodsQueryWrapper = new QueryWrapper<>();