From e5926e82fd491b53bccae476e1f36bef9902c4e8 Mon Sep 17 00:00:00 2001 From: wenshijun Date: Mon, 26 Jan 2026 17:01:42 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8A=9F=E8=83=BD=E9=87=8D=E6=9E=84=E5=BC=80?= =?UTF-8?q?=E5=8F=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../zg/project/wisdom/domain/RkRecord.java | 4 +- .../zg/project/wisdom/mapper/GysJhMapper.java | 10 + .../service/impl/RkBillServiceImpl.java | 34 ++-- .../service/impl/RkRecordServiceImpl.java | 179 ++++++++++-------- .../resources/mybatis/wisdom/GysJhMapper.xml | 7 + .../mybatis/wisdom/RkRecordMapper.xml | 138 +++++++++----- 6 files changed, 233 insertions(+), 139 deletions(-) diff --git a/src/main/java/com/zg/project/wisdom/domain/RkRecord.java b/src/main/java/com/zg/project/wisdom/domain/RkRecord.java index 717de35..e62dd3b 100644 --- a/src/main/java/com/zg/project/wisdom/domain/RkRecord.java +++ b/src/main/java/com/zg/project/wisdom/domain/RkRecord.java @@ -188,12 +188,12 @@ public class RkRecord extends BaseEntity private String entityId; /** 借用时间 */ - @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") + @JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8") // @Excel(name = "借用时间", width = 30, dateFormat = "yyyy-MM-dd HH:mm:ss") private Date borrowTime; /** 归还时间 */ - @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") + @JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8") // @Excel(name = "归还时间", width = 30, dateFormat = "yyyy-MM-dd HH:mm:ss") private Date returnTime; diff --git a/src/main/java/com/zg/project/wisdom/mapper/GysJhMapper.java b/src/main/java/com/zg/project/wisdom/mapper/GysJhMapper.java index eb549ba..2a0279e 100644 --- a/src/main/java/com/zg/project/wisdom/mapper/GysJhMapper.java +++ b/src/main/java/com/zg/project/wisdom/mapper/GysJhMapper.java @@ -169,4 +169,14 @@ public interface GysJhMapper */ int updateRealQtyById(@Param("gysJhId") Long gysJhId, @Param("realQty") BigDecimal realQty); + + /** + * 回退实际入库数量(累减) + * + * @param rollbackQty 回退数量 + * @param gysJhId 供应计划ID + * @return 影响行数 + */ + int decreaseRealQtyById(@Param("rollbackQty") BigDecimal rollbackQty, + @Param("gysJhId") Long gysJhId); } diff --git a/src/main/java/com/zg/project/wisdom/service/impl/RkBillServiceImpl.java b/src/main/java/com/zg/project/wisdom/service/impl/RkBillServiceImpl.java index 2acc835..1d4b1a1 100644 --- a/src/main/java/com/zg/project/wisdom/service/impl/RkBillServiceImpl.java +++ b/src/main/java/com/zg/project/wisdom/service/impl/RkBillServiceImpl.java @@ -106,7 +106,7 @@ public class RkBillServiceImpl implements IRkBillService List rkInfoList = dto.getRkInfoList(); - /* ================== 0️⃣ 入库前:供应计划【批量】校验 ================== */ + /* ================== 0️⃣ 入库前:供应计划【批量】校验(预入库也要校验) ================== */ checkGysJhQtyBeforeInStockBatch(rkInfoList); /* ================== 1️⃣ 主单 rk_bill ================== */ @@ -117,8 +117,6 @@ public class RkBillServiceImpl implements IRkBillService bill.setBillNo(billNo); bill.setBizType("0"); // 入库 - bill.setExecStatus(bill.getExecStatus()); - bill.setOperationTime(dto.getRkBill().getOperationTime()); bill.setCreateTime(now); bill.setCreateBy(userId); bill.setIsDelete("0"); @@ -129,12 +127,12 @@ public class RkBillServiceImpl implements IRkBillService rkBillMapper.insertRkBill(bill); - /* ================== 2️⃣ 明细 & 事件 ================== */ + /* ================== 2️⃣ 明细 & 入库记录 ================== */ for (RkInfo info : rkInfoList) { info.setExecStatus(bill.getExecStatus()); - // 库位编码 + // 库位校验 if (StringUtils.isNotBlank(info.getPcode())) { PcdeDetail pcde = pcdeDetailMapper.selectByPcode(info.getPcode()); if (pcde == null) { @@ -170,8 +168,10 @@ public class RkBillServiceImpl implements IRkBillService rkRecordMapper.insertRkRecord(record); } - /* ================== 3️⃣ 入库后:供应计划【批量】更新 ================== */ - handleGysJhAfterInStockBatch(rkInfoList); + /* ================== 3️⃣ 入库完成后:更新供应计划(❗仅完成入库) ================== */ + if ("1".equals(bill.getExecStatus())) { + handleGysJhAfterInStockBatch(rkInfoList); + } return 1; } @@ -335,7 +335,7 @@ public class RkBillServiceImpl implements IRkBillService execStatus = bill.getExecStatus(); } - // 🚩 标记:本次是否包含预入库 + // 标记:本次是否包含预入库 boolean hasPreIn = false; List rkInfoList = dto.getRkInfoList(); @@ -346,7 +346,7 @@ public class RkBillServiceImpl implements IRkBillService /* ================== 4️⃣ 插入明细 & 事件 ================== */ for (RkInfo info : rkInfoList) { - /* ===== 4.1 库位校验 ===== */ + /* 4.1 库位校验 */ if (StringUtils.isNotBlank(info.getPcode())) { PcdeDetail pcde = pcdeDetailMapper.selectByPcode(info.getPcode()); if (pcde == null) { @@ -355,7 +355,7 @@ public class RkBillServiceImpl implements IRkBillService info.setPcodeId(pcde.getEncodedId()); } - /* ===== 4.2 继承主单字段 ===== */ + /* 4.2 继承主单字段 */ info.setBillNo(bill.getBillNo()); info.setOperationType(bill.getOperationType()); info.setBizType(bill.getBizType()); @@ -374,21 +374,21 @@ public class RkBillServiceImpl implements IRkBillService info.setHasMoved("0"); info.setIsBorrowed("0"); - /* ===== 4.3 备注兜底 ===== */ + /* 4.3 备注兜底 */ String finalRemark = StringUtils.isNotBlank(info.getRemark()) ? info.getRemark() : bill.getRemark(); info.setRemark(finalRemark); - /* ===== 4.4 审计字段 ===== */ + /* 4.4 审计字段 */ info.setCreateTime(now); info.setCreateBy(bill.getCreateBy()); info.setIsDelete("0"); - /* ===== 4.5 插入 rk_info ===== */ + /* 4.5 插入 rk_info */ rkInfoMapper.insertRkInfo(info); - /* ===== 4.6 插入 rk_record ===== */ + /* 4.6 插入 rk_record */ RkRecord record = buildInRkRecord(bill, info, now); record.setExecStatus(execStatus); record.setRkInfoId(info.getId()); @@ -398,8 +398,10 @@ public class RkBillServiceImpl implements IRkBillService rkRecordMapper.insertRkRecord(record); } - /* ================== 5️⃣ 追加后:供应计划【批量】更新 ================== */ - handleGysJhAfterInStockBatch(rkInfoList); + /* ================== 5️⃣ 追加后:供应计划【仅完成入库】 ================== */ + if ("1".equals(execStatus)) { + handleGysJhAfterInStockBatch(rkInfoList); + } /* ================== 6️⃣ 同步回退主单状态 ================== */ if (hasPreIn && !"0".equals(bill.getExecStatus())) { diff --git a/src/main/java/com/zg/project/wisdom/service/impl/RkRecordServiceImpl.java b/src/main/java/com/zg/project/wisdom/service/impl/RkRecordServiceImpl.java index ed9a882..f0f88be 100644 --- a/src/main/java/com/zg/project/wisdom/service/impl/RkRecordServiceImpl.java +++ b/src/main/java/com/zg/project/wisdom/service/impl/RkRecordServiceImpl.java @@ -263,13 +263,6 @@ public class RkRecordServiceImpl implements IRkRecordService return rows; } - - /** - * 批量删除出入库记录 - * - * @param ids 需要删除的出入库记录主键 - * @return 结果 - */ @Override @Transactional(rollbackFor = Exception.class) public int deleteRkRecordByIds(Long[] ids) { @@ -278,55 +271,27 @@ public class RkRecordServiceImpl implements IRkRecordService return 0; } - // ================== 1. 查询 record ================== + /* ================== 1️⃣ 查询 record ================== */ List records = rkRecordMapper.selectRkRecordByIds(Arrays.asList(ids)); if (records == null || records.isEmpty()) { return 0; } - // ================== 2. 校验 record 必须全部是预入库 ================== + /* ================== 2️⃣ 校验:必须全部是【预入库 / 预出库】 ================== */ boolean hasFinishedRecord = records.stream() .anyMatch(r -> r.getExecStatus() == null || !"0".equals(r.getExecStatus())); if (hasFinishedRecord) { throw new ServiceException("仅允许删除预入库/预出库的出入库记录"); } - // ================== 3. 回滚供应计划已入库数量 + 状态 ================== - Map rollbackMap = records.stream() - .filter(r -> r.getGysJhId() != null && r.getRealQty() != null) - .collect(Collectors.groupingBy( - RkRecord::getGysJhId, - Collectors.mapping( - RkRecord::getRealQty, - Collectors.reducing(BigDecimal.ZERO, BigDecimal::add) - ) - )); - - for (Map.Entry entry : rollbackMap.entrySet()) { - - Long jhId = entry.getKey(); - BigDecimal rollbackQty = entry.getValue(); - - // 1️⃣ 回滚数量 - gysJhMapper.rollbackInQty(jhId, rollbackQty); - - // 2️⃣ 判断回滚后数量是否为 0 - BigDecimal remainQty = gysJhMapper.selectRealQtyById(jhId); - - if (remainQty == null || remainQty.compareTo(BigDecimal.ZERO) == 0) { - // 3️⃣ 已入库数量为 0,回退状态 - gysJhMapper.updateStatus(jhId, "0"); // 0=未入库 - } - } - - // ================== 4. 收集 rkInfoId ================== + /* ================== 3️⃣ 收集 rkInfoId ================== */ List rkInfoIds = records.stream() .map(RkRecord::getRkInfoId) .filter(Objects::nonNull) .distinct() .collect(Collectors.toList()); - // ================== 5. 校验 info 也必须是预入库 ================== + /* ================== 4️⃣ 校验 info 也必须是预入库 ================== */ if (!rkInfoIds.isEmpty()) { int invalidCount = rkInfoMapper.countNotPreByIds(rkInfoIds); if (invalidCount > 0) { @@ -337,10 +302,10 @@ public class RkRecordServiceImpl implements IRkRecordService rkInfoMapper.deleteRkInfoByIds(rkInfoIds.toArray(new Long[0])); } - // ================== 6. 删除 record ================== + /* ================== 5️⃣ 删除 record ================== */ int deleteCount = rkRecordMapper.deleteRkRecordByIds(ids); - // ================== 7. 判断是否需要更新 bill 状态 ================== + /* ================== 6️⃣ 判断是否需要更新 bill 状态 ================== */ Set billNos = records.stream() .map(RkRecord::getBillNo) .filter(StringUtils::isNotBlank) @@ -383,8 +348,17 @@ public class RkRecordServiceImpl implements IRkRecordService throw new ServiceException("入库记录不存在"); } - /* ====================== 2️⃣ 校验是否发生过移库 ====================== */ - List rkInfoIds = recordList.stream() + /* ====================== 2️⃣ 仅处理【已完成入库】记录 ====================== */ + List finishedList = recordList.stream() + .filter(r -> "1".equals(r.getExecStatus())) + .collect(Collectors.toList()); + + if (finishedList.isEmpty()) { + throw new ServiceException("所选记录均为预入库状态,无需撤销"); + } + + /* ====================== 3️⃣ 校验是否发生过移库 ====================== */ + List rkInfoIds = finishedList.stream() .map(RkRecord::getRkInfoId) .filter(Objects::nonNull) .distinct() @@ -392,10 +366,8 @@ public class RkRecordServiceImpl implements IRkRecordService if (!rkInfoIds.isEmpty()) { - // 查询对应库存 List infoList = rkInfoMapper.selectRkInfoByIds(rkInfoIds); - // 只要有一条 has_moved = 1,直接禁止撤销 boolean hasMoved = infoList.stream() .anyMatch(info -> "1".equals(info.getHasMoved())); @@ -404,26 +376,74 @@ public class RkRecordServiceImpl implements IRkRecordService } } - /* ====================== 3️⃣ rk_record 回退为预入库 ====================== */ - rkRecordMapper.updateExecStatusByIds(recordIds, "0"); + /* ====================== 4️⃣ 汇总需回退的供应计划数量 ====================== */ + Map rollbackQtyMap = finishedList.stream() + .filter(r -> r.getGysJhId() != null && r.getRealQty() != null) + .collect(Collectors.groupingBy( + RkRecord::getGysJhId, + Collectors.mapping( + RkRecord::getRealQty, + Collectors.reducing(BigDecimal.ZERO, BigDecimal::add) + ) + )); - /* ====================== 4️⃣ rk_info 回退为预入库 ====================== */ + /* ====================== 5️⃣ 状态回退 ====================== */ + + // ① rk_record.exec_status = 0 + List finishedRecordIds = finishedList.stream() + .map(RkRecord::getId) + .collect(Collectors.toList()); + + rkRecordMapper.updateExecStatusByIds(finishedRecordIds, "0"); + + // ② rk_info.exec_status = 0 if (!rkInfoIds.isEmpty()) { rkInfoMapper.updateExecStatusByIds(rkInfoIds, "0"); } - /* ====================== 5️⃣ rk_bill 回退为预入库 ====================== */ - List billNos = recordList.stream() + // ③ rk_bill.exec_status = 0 + Set billNoSet = finishedList.stream() .map(RkRecord::getBillNo) .filter(StringUtils::isNotBlank) - .distinct() - .collect(Collectors.toList()); + .collect(Collectors.toSet()); - for (String billNo : billNos) { + for (String billNo : billNoSet) { rkBillMapper.updateExecStatusByBillNo(billNo, "0"); } - return recordIds.size(); + /* ====================== 6️⃣ 回退供应计划(关键补充) ====================== */ + for (Map.Entry entry : rollbackQtyMap.entrySet()) { + + Long gysJhId = entry.getKey(); + BigDecimal rollbackQty = entry.getValue(); + + // ① 实际入库数量回退(累减) + gysJhMapper.decreaseRealQtyById(rollbackQty, gysJhId); + + // ② 重算状态 + GysJh gysJh = gysJhMapper.selectGysJhById(gysJhId); + if (gysJh == null) { + continue; + } + + BigDecimal planQty = gysJh.getJhQty(); + BigDecimal realQty = gysJh.getRealQty() == null + ? BigDecimal.ZERO + : gysJh.getRealQty(); + + String status; + if (realQty.compareTo(BigDecimal.ZERO) == 0) { + status = "0"; // 未到货 + } else if (planQty != null && realQty.compareTo(planQty) >= 0) { + status = "1"; // 已入库 + } else { + status = "2"; // 部分入库 + } + + gysJhMapper.updateStatusById(gysJhId, status); + } + + return finishedRecordIds.size(); } @@ -435,22 +455,22 @@ public class RkRecordServiceImpl implements IRkRecordService throw new ServiceException("入库记录ID不能为空"); } - /* ================== 1. 查询 rk_record ================== */ + /* ================== 1️⃣ 查询 rk_record ================== */ List recordList = rkRecordMapper.selectRkRecordByIds(recordIds); if (recordList == null || recordList.isEmpty()) { throw new ServiceException("入库记录不存在"); } - /* ================== 2. 仅处理「预入库」记录 ================== */ + /* ================== 2️⃣ 仅处理【预入库】记录 ================== */ List preRecordList = recordList.stream() - .filter(r -> "0".equals(r.getExecStatus())) // 预入库 + .filter(r -> "0".equals(r.getExecStatus())) // 0 = 预入库 .collect(Collectors.toList()); if (preRecordList.isEmpty()) { throw new ServiceException("所选入库记录均已完成,无需重复入库"); } - /* ================== 3. 校验:完成入库数量 ≤ 计划交货数量 ================== */ + /* ================== 3️⃣ 校验:已入库 + 本次完成 ≤ 计划数量 ================== */ Map finishQtyMap = new HashMap<>(); for (RkRecord record : preRecordList) { @@ -475,16 +495,21 @@ public class RkRecordServiceImpl implements IRkRecordService } BigDecimal planQty = gysJh.getJhQty(); - if (planQty != null && finishQty.compareTo(planQty) > 0) { + BigDecimal alreadyQty = gysJh.getRealQty() == null + ? BigDecimal.ZERO + : gysJh.getRealQty(); + + if (planQty != null && alreadyQty.add(finishQty).compareTo(planQty) > 0) { throw new ServiceException( "一键入库数量超出供应计划数量,物料号:" + gysJh.getWlNo() + ",计划数量:" + planQty - + ",本次完成入库:" + finishQty + + ",已入库:" + alreadyQty + + ",本次完成:" + finishQty ); } } - /* ================== 4. 状态推进 ================== */ + /* ================== 4️⃣ 状态推进 ================== */ // ① rk_record.exec_status = 1 List preRecordIds = preRecordList.stream() @@ -493,7 +518,7 @@ public class RkRecordServiceImpl implements IRkRecordService rkRecordMapper.updateExecStatusByIds(preRecordIds, "1"); - // ② rk_info.exec_status = 1(只推进本次涉及的库存) + // ② rk_info.exec_status = 1(仅本次涉及的库存) List rkInfoIds = preRecordList.stream() .map(RkRecord::getRkInfoId) .filter(Objects::nonNull) @@ -504,54 +529,56 @@ public class RkRecordServiceImpl implements IRkRecordService rkInfoMapper.updateExecStatusByIds(rkInfoIds, "1"); } - // ③ rk_bill.exec_status = 1(✅ 只有当 bill 下所有 record 均完成) + // ③ rk_bill.exec_status = 1(只有 bill 下所有 record 均完成) Set billNoSet = preRecordList.stream() .map(RkRecord::getBillNo) .filter(StringUtils::isNotBlank) .collect(Collectors.toSet()); for (String billNo : billNoSet) { - - // 查询该 bill 下是否仍存在 预入库 record int unFinishedCount = rkRecordMapper.countPreInRecordByBillNo(billNo); - - // 只有当不存在任何预入库 record 时,才推进 bill 状态 if (unFinishedCount == 0) { rkBillMapper.updateExecStatusByBillNo(billNo, "1"); } } - /* ================== 5. 同步修正供应计划 ================== */ + /* ================== 5️⃣ 累加更新供应计划(关键修复点) ================== */ for (Map.Entry entry : finishQtyMap.entrySet()) { Long gysJhId = entry.getKey(); BigDecimal finishQty = entry.getValue(); - // ① 修正实收数量 - gysJhMapper.updateRealQtyById(gysJhId, finishQty); + // ✅ 改为【累加】而不是覆盖 + gysJhMapper.increaseRealQtyById(finishQty, gysJhId); - // ② 修正状态 + // 重新计算状态 GysJh gysJh = gysJhMapper.selectGysJhById(gysJhId); if (gysJh == null) { continue; } BigDecimal planQty = gysJh.getJhQty(); - BigDecimal realQty = gysJh.getRealQty(); + BigDecimal realQty = gysJh.getRealQty() == null + ? BigDecimal.ZERO + : gysJh.getRealQty(); - if (realQty == null || realQty.compareTo(BigDecimal.ZERO) == 0) { - gysJhMapper.updateStatusById(gysJhId, "0"); // 未到货 + String status; + if (realQty.compareTo(BigDecimal.ZERO) == 0) { + status = "0"; // 未到货 } else if (planQty != null && realQty.compareTo(planQty) >= 0) { - gysJhMapper.updateStatusById(gysJhId, "1"); // 已入库 + status = "1"; // 已入库 } else { - gysJhMapper.updateStatusById(gysJhId, "2"); // 部分入库 + status = "2"; // 部分入库 } + + gysJhMapper.updateStatusById(gysJhId, status); } return preRecordIds.size(); } + @Override @Transactional(rollbackFor = Exception.class) public int rollbackOut(List recordIds) { diff --git a/src/main/resources/mybatis/wisdom/GysJhMapper.xml b/src/main/resources/mybatis/wisdom/GysJhMapper.xml index d1b2b2d..2dea022 100644 --- a/src/main/resources/mybatis/wisdom/GysJhMapper.xml +++ b/src/main/resources/mybatis/wisdom/GysJhMapper.xml @@ -311,4 +311,11 @@ WHERE id = #{gysJhId} + + UPDATE gys_jh + SET real_qty = IFNULL(real_qty, 0) - #{rollbackQty} + WHERE id = #{gysJhId} + AND IFNULL(real_qty, 0) >= #{rollbackQty} + + diff --git a/src/main/resources/mybatis/wisdom/RkRecordMapper.xml b/src/main/resources/mybatis/wisdom/RkRecordMapper.xml index e3a9cb2..2286569 100644 --- a/src/main/resources/mybatis/wisdom/RkRecordMapper.xml +++ b/src/main/resources/mybatis/wisdom/RkRecordMapper.xml @@ -5,20 +5,18 @@ - + - - + - - + @@ -60,6 +58,7 @@ + @@ -85,52 +84,58 @@ - + SELECT rr.*, - /* 理货员姓名 */ su.nick_name AS operator_name, - - /* 物资类型名称 */ mt.type_name AS wl_type_name, - - /* 出入库类型名称:入库 / 出库 二选一 */ COALESCE(sit.type_name, sot.type_name) AS operation_type_name, - /* 仓库信息:小仓/大仓 */ - wh.warehouse_name, - wh.parent_warehouse_code, - wh.parent_warehouse_name, + -- 小仓 + wh.warehouse_name AS warehouse_name, + + -- 大仓 + pwh.warehouse_code AS parent_warehouse_code, + pwh.warehouse_name AS parent_warehouse_name, + ct.team_name AS team_name + FROM rk_record rr - LEFT JOIN sys_user su - ON rr.operator = su.user_id - LEFT JOIN material_type mt - ON rr.wl_type = mt.type_code - LEFT JOIN stock_in_type sit - ON rr.operation_type = sit.type_code - LEFT JOIN stock_out_type sot - ON rr.operation_type = sot.type_code - LEFT JOIN warehouse_info wh - ON rr.cangku = wh.warehouse_code + LEFT JOIN sys_user su ON rr.operator = su.user_id + LEFT JOIN material_type mt ON rr.wl_type = mt.type_code + LEFT JOIN stock_in_type sit ON rr.operation_type = sit.type_code + LEFT JOIN stock_out_type sot ON rr.operation_type = sot.type_code + + -- 小仓 + LEFT JOIN warehouse_info wh ON rr.cangku = wh.warehouse_code + + -- 大仓 + LEFT JOIN warehouse_info pwh ON wh.parent_warehouse_code = pwh.warehouse_code + LEFT JOIN construction_team ct ON rr.team_code = ct.team_code AND ct.is_delete = '0' - + + AND rr.exec_status = '1' + AND rr.operation_type = #{operationType} + - AND rb.biz_type IN + AND rr.biz_type IN + AND rr.biz_type = #{bizType} + AND rr.pcode = #{pcode} + AND rr.wl_type = #{wlType} + AND rr.cangku = #{cangku} + AND rr.operator = #{operator} + AND rr.is_chuku = #{isChuku} + AND rr.status = #{status} + AND rr.exec_status = #{execStatus} + AND rr.bill_no = #{billNo} + AND rr.is_delivery = #{isDelivery} - + + AND rr.xm_no LIKE concat('%', #{xmNo}, '%') @@ -177,50 +193,81 @@ AND rr.xm_ms LIKE concat('%', #{xmMs}, '%') - + AND rr.sap_no LIKE concat('%', #{sapNo}, '%') - + AND rr.gys_mc LIKE concat('%', #{gysMc}, '%') - - - AND rr.cangku = #{cangku} - AND rr.wl_no LIKE concat('%', #{wlNo}, '%') - + AND rr.wl_ms LIKE concat('%', #{wlMs}, '%') + AND rr.is_borrowed = #{isBorrowed} - + + AND (rr.is_delete = '0' OR rr.is_delete = 0 OR rr.is_delete IS NULL) - AND rr.is_delete = #{isDelete} - - - AND rr.operation_time >= #{startDate} - - - AND rr.operation_time <= #{endDate} + + + + AND ( + + ( + rr.biz_type IN ('0','1') + + AND rr.operation_time >= #{startDate} + + + AND rr.operation_time <= #{endDate} + + ) + OR + + ( + rr.biz_type = '2' + + AND rr.borrow_time >= DATE(#{startDate}) + + + AND rr.borrow_time < DATE_ADD(DATE(#{endDate}), INTERVAL 1 DAY) + + ) + OR + + ( + rr.biz_type = '3' + + AND rr.return_time >= DATE(#{startDate}) + + + AND rr.return_time < DATE_ADD(DATE(#{endDate}), INTERVAL 1 DAY) + + ) + ) - ORDER BY rr.exec_status = '0' DESC, rr.operation_time DESC + + ORDER BY rr.exec_status = '0' DESC, + rr.operation_time DESC +