Просмотр исходного кода

生命礼赞订单,财务审核调整

wangxy 3 дней назад
Родитель
Сommit
1a77d3c8e0

+ 4 - 0
fs-admin/src/main/java/com/fs/his/controller/LifeSaluteOrderController.java

@@ -15,6 +15,7 @@ import com.fs.his.param.LifeSaluteOrderCreateParam;
 import com.fs.his.service.ILifeSaluteOrderService;
 import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.security.access.prepost.PreAuthorize;
 import org.springframework.web.bind.annotation.*;
 import org.springframework.web.multipart.MultipartFile;
 
@@ -36,6 +37,7 @@ public class LifeSaluteOrderController extends BaseController {
      * @param lifeSaluteOrder 查询条件
      * @return 分页列表数据
      */
+    @PreAuthorize("@ss.hasPermi('his:lifeSaluteOrder:list')")
     @GetMapping("/list")
     public TableDataInfo list(LifeSaluteOrder lifeSaluteOrder) {
         startPage();
@@ -62,6 +64,7 @@ public class LifeSaluteOrderController extends BaseController {
      * @return Excel文件
      */
     @Log(title = "生命礼赞订单", businessType = BusinessType.EXPORT)
+    @PreAuthorize("@ss.hasPermi('his:lifeSaluteOrder:export')")
     @GetMapping("/export")
     public AjaxResult export(LifeSaluteOrder lifeSaluteOrder) {
         List<LifeSaluteOrder> list = lifeSaluteOrderService.selectLifeSaluteOrderList(lifeSaluteOrder);
@@ -84,6 +87,7 @@ public class LifeSaluteOrderController extends BaseController {
      * 从Excel导入生命礼赞订单数据
      */
     @Log(title = "生命礼赞订单", businessType = BusinessType.IMPORT)
+    @PreAuthorize("@ss.hasPermi('his:lifeSaluteOrder:import')")
     @PostMapping("/importData")
     public AjaxResult importData(MultipartFile file, boolean updateSupport) throws Exception
     {

+ 85 - 0
fs-admin/src/main/java/com/fs/his/task/Task.java

@@ -91,6 +91,7 @@ import org.springframework.util.CollectionUtils;
 import java.text.ParseException;
 import java.time.LocalDate;
 import java.time.LocalDateTime;
+import java.util.Date;
 import java.time.ZoneId;
 import java.util.*;
 import java.util.concurrent.CompletableFuture;
@@ -165,6 +166,10 @@ public class Task {
     @Autowired
     CompanyUserMapper companyUserMapper;
     @Autowired
+    FsExternalOrderMapper fsExternalOrderMapper;
+    @Autowired
+    FsStoreOrderFinanceAuditMapper fsStoreOrderFinanceAuditMapper;
+    @Autowired
     FsInquiryOrderMapper fsInquiryOrderMapper;
     @Autowired
     FsCourseRedPacketLogMapper fsCourseRedPacketLogMapper;
@@ -2040,4 +2045,84 @@ public class Task {
         }
     }
 
+    /**
+     * 自动创建订单完成财务审核记录
+     * 每天凌晨1点执行,扫描fs_store_order和fs_external_order表,
+     * 将物流状态为正常签收(delivery_status=301)的订单写入财务审核表
+     */
+    public void autoCreateFinanceAuditForSignedOrders() {
+        log.info("开始自动创建订单完成财务审核记录");
+        int storeCount = 0;
+        int externalCount = 0;
+        try {
+            List<FsStoreOrder> storeOrders = fsStoreOrderMapper.selectSignedOrdersWithoutAudit();
+            if (storeOrders != null && !storeOrders.isEmpty()) {
+                for (FsStoreOrder order : storeOrders) {
+                    try {
+                        FsStoreOrderFinanceAudit audit = new FsStoreOrderFinanceAudit();
+                        audit.setOrderId(order.getOrderId());
+                        audit.setOrderCode(order.getOrderCode());
+                        audit.setAuditType(2);
+                        audit.setOriginalTotalPrice(order.getTotalPrice());
+                        audit.setOriginalPayPrice(order.getPayPrice());
+                        audit.setNewTotalPrice(order.getTotalPrice());
+                        audit.setNewPayPrice(order.getPayPrice());
+                        audit.setAuditStatus(0);
+                        audit.setApplyUserId(order.getCompanyUserId());
+                        audit.setOrderType(1);
+                        if (order.getCompanyUserId() != null) {
+                            CompanyUser salesUser = companyUserMapper.selectCompanyUserById(order.getCompanyUserId());
+                            if (salesUser != null) {
+                                audit.setApplyUserName(salesUser.getNickName());
+                            }
+                        }
+                        audit.setApplyTime(new Date());
+                        fsStoreOrderFinanceAuditMapper.insertFsStoreOrderFinanceAudit(audit);
+                        storeCount++;
+                    } catch (Exception e) {
+                        log.error("创建店铺订单财务审核记录失败, orderId={}: {}", order.getOrderId(), e.getMessage());
+                    }
+                }
+            }
+        } catch (Exception e) {
+            log.error("查询店铺订单失败: {}", e.getMessage(), e);
+        }
+
+        try {
+            List<FsExternalOrder> externalOrders = fsExternalOrderMapper.selectSignedOrdersWithoutAudit();
+            if (externalOrders != null && !externalOrders.isEmpty()) {
+                for (FsExternalOrder order : externalOrders) {
+                    try {
+                        FsStoreOrderFinanceAudit audit = new FsStoreOrderFinanceAudit();
+                        audit.setOrderId(order.getOrderId());
+                        audit.setOrderCode(order.getOrderCode());
+                        audit.setAuditType(2);
+                        audit.setOriginalTotalPrice(order.getTotalPrice());
+                        audit.setOriginalPayPrice(order.getPayPrice());
+                        audit.setNewTotalPrice(order.getTotalPrice());
+                        audit.setNewPayPrice(order.getPayPrice());
+                        audit.setAuditStatus(0);
+                        audit.setApplyUserId(order.getCompanyUserId());
+                        audit.setOrderType(0);
+                        if (order.getCompanyUserId() != null) {
+                            CompanyUser salesUser = companyUserMapper.selectCompanyUserById(order.getCompanyUserId());
+                            if (salesUser != null) {
+                                audit.setApplyUserName(salesUser.getNickName());
+                            }
+                        }
+                        audit.setApplyTime(new Date());
+                        fsStoreOrderFinanceAuditMapper.insertFsStoreOrderFinanceAudit(audit);
+                        externalCount++;
+                    } catch (Exception e) {
+                        log.error("创建外部订单财务审核记录失败, orderId={}: {}", order.getOrderId(), e.getMessage());
+                    }
+                }
+            }
+        } catch (Exception e) {
+            log.error("查询外部订单失败: {}", e.getMessage(), e);
+        }
+
+        log.info("自动创建订单完成财务审核记录完成,店铺订单: {},外部订单: {}", storeCount, externalCount);
+    }
+
 }

+ 1 - 1
fs-company/src/main/java/com/fs/company/controller/store/FsExternalOrderController.java

@@ -114,7 +114,7 @@ public class FsExternalOrderController extends BaseController {
                 param.getVoucherRemark(),
                 userId,
                 userName,
-                param.getOrderType()));
+                0));
     }
 
     @GetMapping(value = "/getExpress/{orderId}")

+ 2 - 0
fs-service/src/main/java/com/fs/his/mapper/FsExternalOrderMapper.java

@@ -37,4 +37,6 @@ public interface FsExternalOrderMapper {
 
     @Select("SELECT * FROM fs_external_order WHERE extend_order_id IS NOT NULL AND status IN (2, 3)")
     List<FsExternalOrder> selectSyncedOrders();
+
+    List<FsExternalOrder> selectSignedOrdersWithoutAudit();
 }

+ 2 - 0
fs-service/src/main/java/com/fs/his/mapper/FsStoreOrderFinanceAuditMapper.java

@@ -17,6 +17,8 @@ public interface FsStoreOrderFinanceAuditMapper {
 
     FsStoreOrderFinanceAudit selectByOrderId(@Param("orderId") Long orderId);
 
+    FsStoreOrderFinanceAudit selectByOrderIdAndOrderType(@Param("orderId") Long orderId, @Param("orderType") Integer orderType);
+
     int insertFsStoreOrderFinanceAudit(FsStoreOrderFinanceAudit fsStoreOrderFinanceAudit);
 
     int updateFsStoreOrderFinanceAudit(FsStoreOrderFinanceAudit fsStoreOrderFinanceAudit);

+ 2 - 0
fs-service/src/main/java/com/fs/his/mapper/FsStoreOrderMapper.java

@@ -1156,6 +1156,8 @@ public interface FsStoreOrderMapper
     @Select("select * from fs_store_order where extend_order_id  like 'SO%' and `status`=2 ")
     List<FsStoreOrder> selectOmsOrderdeliveryOp();
 
+    List<FsStoreOrder> selectSignedOrdersWithoutAudit();
+
     @Select("select * from fs_store_order_scrm where extend_order_id  is not null and `status`=1 ")
     List<FsStoreOrderScrm> selectOmsOrderdeliveryOpScrm();
     List<FsStoreOrder> selectFsStoreOrderByOrderIdIn(@Param("ids") List<Long> ids);

+ 8 - 0
fs-service/src/main/java/com/fs/his/mapper/LifeSaluteOrderMapper.java

@@ -42,6 +42,14 @@ public interface LifeSaluteOrderMapper {
      */
     public List<LifeSaluteOrder> selectLifeSaluteOrderByIds(@Param("ids") List<Long> ids);
 
+    /**
+     * 根据运单号查询生命礼赞订单
+     *
+     * @param waybillNo 运单号
+     * @return 生命礼赞订单集合
+     */
+    public List<LifeSaluteOrder> selectLifeSaluteOrderByWaybillNo(String waybillNo);
+
     /**
      * 新增生命礼赞订单
      *

+ 79 - 37
fs-service/src/main/java/com/fs/his/service/impl/FsStoreOrderFinanceAuditServiceImpl.java

@@ -1,9 +1,10 @@
 package com.fs.his.service.impl;
 
 import com.fs.common.exception.CustomException;
-import com.fs.common.utils.DateUtils;
+import com.fs.his.domain.FsExternalOrder;
 import com.fs.his.domain.FsStoreOrder;
 import com.fs.his.domain.FsStoreOrderFinanceAudit;
+import com.fs.his.mapper.FsExternalOrderMapper;
 import com.fs.his.mapper.FsStoreOrderFinanceAuditMapper;
 import com.fs.his.mapper.FsStoreOrderMapper;
 import com.fs.his.param.FsOrderFinanceAuditApplyParam;
@@ -25,6 +26,9 @@ public class FsStoreOrderFinanceAuditServiceImpl implements IFsStoreOrderFinance
     @Autowired
     private FsStoreOrderMapper fsStoreOrderMapper;
 
+    @Autowired
+    private FsExternalOrderMapper fsExternalOrderMapper;
+
     @Override
     public FsStoreOrderFinanceAudit selectFsStoreOrderFinanceAuditById(Long id) {
         return fsStoreOrderFinanceAuditMapper.selectFsStoreOrderFinanceAuditById(id);
@@ -54,33 +58,9 @@ public class FsStoreOrderFinanceAuditServiceImpl implements IFsStoreOrderFinance
     @Transactional(rollbackFor = Exception.class)
     public int applyFinanceAudit(FsOrderFinanceAuditApplyParam param, Long applyUserId, String applyUserName) {
         int count = 0;
+        Integer orderType = param.getOrderType() == null ? 1 : param.getOrderType();
         for (Long orderId : param.getOrderIds()) {
-            FsStoreOrder order = fsStoreOrderMapper.selectFsStoreOrderByOrderId(orderId);
-            if (order == null) {
-                throw new CustomException("订单不存在:" + orderId);
-            }
-
-            FsStoreOrderFinanceAudit existAudit = fsStoreOrderFinanceAuditMapper.selectByOrderId(orderId);
-            if (existAudit != null && existAudit.getAuditStatus() == 0) {
-                throw new CustomException("订单已存在待审核记录:" + order.getOrderCode());
-            }
-
-            FsStoreOrderFinanceAudit audit = new FsStoreOrderFinanceAudit();
-            audit.setOrderId(orderId);
-            audit.setOrderCode(order.getOrderCode());
-            audit.setAuditType(param.getAuditType());
-            audit.setOriginalTotalPrice(order.getTotalPrice());
-            audit.setOriginalPayPrice(order.getPayPrice());
-            audit.setNewTotalPrice(param.getNewTotalPrice());
-            audit.setNewPayPrice(param.getNewPayPrice());
-            audit.setPriceChangeReason(param.getPriceChangeReason());
-            audit.setVoucherImages(param.getVoucherImages());
-            audit.setVoucherRemark(param.getVoucherRemark());
-            audit.setAuditStatus(0);
-            audit.setApplyUserId(applyUserId);
-            audit.setApplyUserName(applyUserName);
-            audit.setApplyTime(new Date());
-
+            FsStoreOrderFinanceAudit audit = buildFinanceAudit(param, orderId, orderType, applyUserId, applyUserName);
             count += fsStoreOrderFinanceAuditMapper.insertFsStoreOrderFinanceAudit(audit);
         }
         return count;
@@ -107,19 +87,81 @@ public class FsStoreOrderFinanceAuditServiceImpl implements IFsStoreOrderFinance
         int result = fsStoreOrderFinanceAuditMapper.updateFsStoreOrderFinanceAudit(audit);
 
         if (param.getAuditStatus() == 1) {
-            FsStoreOrder order = new FsStoreOrder();
-            order.setOrderId(audit.getOrderId());
-
-            if (audit.getAuditType() == 1) {
-                order.setStatus(4);
-            } else if (audit.getAuditType() == 2) {
-                order.setTotalPrice(audit.getNewTotalPrice());
-                order.setPayPrice(audit.getNewPayPrice());
+            if (isExternalOrder(audit.getOrderType())) {
+                updateExternalOrderByAudit(audit);
+            } else {
+                updateStoreOrderByAudit(audit);
             }
-
-            fsStoreOrderMapper.updateFsStoreOrder(order);
         }
 
         return result;
     }
+
+    private FsStoreOrderFinanceAudit buildFinanceAudit(FsOrderFinanceAuditApplyParam param, Long orderId, Integer orderType, Long applyUserId, String applyUserName) {
+        FsStoreOrderFinanceAudit existAudit = fsStoreOrderFinanceAuditMapper.selectByOrderIdAndOrderType(orderId, orderType);
+        if (existAudit != null && existAudit.getAuditStatus() == 0) {
+            throw new CustomException("订单已存在待审核记录:" + existAudit.getOrderCode());
+        }
+
+        FsStoreOrderFinanceAudit audit = new FsStoreOrderFinanceAudit();
+        audit.setOrderId(orderId);
+        audit.setOrderType(orderType);
+        audit.setAuditType(param.getAuditType());
+        audit.setNewTotalPrice(param.getNewTotalPrice());
+        audit.setNewPayPrice(param.getNewPayPrice());
+        audit.setPriceChangeReason(param.getPriceChangeReason());
+        audit.setVoucherImages(param.getVoucherImages());
+        audit.setVoucherRemark(param.getVoucherRemark());
+        audit.setAuditStatus(0);
+        audit.setApplyUserId(applyUserId);
+        audit.setApplyUserName(applyUserName);
+        audit.setApplyTime(new Date());
+
+        if (isExternalOrder(orderType)) {
+            FsExternalOrder order = fsExternalOrderMapper.selectFsExternalOrderByOrderId(orderId);
+            if (order == null) {
+                throw new CustomException("外部订单不存在:" + orderId);
+            }
+            audit.setOrderCode(order.getOrderCode());
+            audit.setOriginalTotalPrice(order.getTotalPrice());
+            audit.setOriginalPayPrice(order.getPayPrice());
+        } else {
+            FsStoreOrder order = fsStoreOrderMapper.selectFsStoreOrderByOrderId(orderId);
+            if (order == null) {
+                throw new CustomException("订单不存在:" + orderId);
+            }
+            audit.setOrderCode(order.getOrderCode());
+            audit.setOriginalTotalPrice(order.getTotalPrice());
+            audit.setOriginalPayPrice(order.getPayPrice());
+        }
+        return audit;
+    }
+
+    private void updateStoreOrderByAudit(FsStoreOrderFinanceAudit audit) {
+        FsStoreOrder order = new FsStoreOrder();
+        order.setOrderId(audit.getOrderId());
+        if (audit.getAuditType() == 1) {
+            order.setStatus(4);
+        } else if (audit.getAuditType() == 2) {
+            order.setTotalPrice(audit.getNewTotalPrice());
+            order.setPayPrice(audit.getNewPayPrice());
+        }
+        fsStoreOrderMapper.updateFsStoreOrder(order);
+    }
+
+    private void updateExternalOrderByAudit(FsStoreOrderFinanceAudit audit) {
+        FsExternalOrder order = new FsExternalOrder();
+        order.setOrderId(audit.getOrderId());
+        if (audit.getAuditType() == 1) {
+            order.setStatus(4);
+        } else if (audit.getAuditType() == 2) {
+            order.setTotalPrice(audit.getNewTotalPrice());
+            order.setPayPrice(audit.getNewPayPrice());
+        }
+        fsExternalOrderMapper.updateFsExternalOrder(order);
+    }
+
+    private boolean isExternalOrder(Integer orderType) {
+        return orderType != null && orderType == 0;
+    }
 }

+ 82 - 23
fs-service/src/main/java/com/fs/his/service/impl/FsStoreOrderServiceImpl.java

@@ -157,6 +157,9 @@ public class FsStoreOrderServiceImpl implements IFsStoreOrderService {
     @Autowired
     private FsExternalOrderMapper fsExternalOrderMapper;
 
+    @Autowired
+    private LifeSaluteOrderMapper lifeSaluteOrderMapper;
+
     @Autowired
     private FsPatientMapper fsPatientMapper;
 
@@ -2482,6 +2485,7 @@ public class FsStoreOrderServiceImpl implements IFsStoreOrderService {
             }
             updateStoreOrderDelivery(dto);
             updateExternalOrderDelivery(dto);
+            updateLifeSaluteOrderDelivery(dto);
             if (!dto.isSuccess()) {
                 logger.info("物流状态异常:{}", dto);
             }
@@ -2574,6 +2578,28 @@ public class FsStoreOrderServiceImpl implements IFsStoreOrderService {
         }
     }
 
+    private void updateLifeSaluteOrderDelivery(ExpressInfoDTO dto) {
+        List<LifeSaluteOrder> orders = lifeSaluteOrderMapper.selectLifeSaluteOrderByWaybillNo(dto.getLogisticCode());
+        if (orders == null) {
+            return;
+        }
+        for (LifeSaluteOrder order : orders) {
+            logger.info("生命礼赞订单物流回调订单信息:{}", JSONUtil.toJsonStr(order));
+            if (order == null || (order.getDeliveryStatus() != null && order.getDeliveryStatus() == 3)) {
+                continue;
+            }
+            if (dto.getState() == null || dto.getStateEx() == null) {
+                continue;
+            }
+            LifeSaluteOrder update = new LifeSaluteOrder();
+            update.setId(order.getId());
+            update.setDeliveryStatus(Integer.parseInt(dto.getState()));
+            update.setDeliveryType(dto.getStateEx());
+            update.setDeliveryUpdateTime(DateUtils.getNowDate());
+            lifeSaluteOrderMapper.updateLifeSaluteOrder(update);
+        }
+    }
+
     private boolean isNormalSigned(ExpressInfoDTO dto) {
         return "3".equals(dto.getState())
                 && ("301".equals(dto.getStateEx())
@@ -4849,39 +4875,50 @@ public class FsStoreOrderServiceImpl implements IFsStoreOrderService {
 
     @Override
     @Transactional(rollbackFor = Exception.class)
-    public int applyFinanceAudit(List<Long> orderIds, Integer auditType, 
+    public int applyFinanceAudit(List<Long> orderIds, Integer auditType,
                                   BigDecimal newTotalPrice, BigDecimal newPayPrice,
                                   String priceChangeReason, String voucherImages, String voucherRemark,
                                   Long applyUserId, String applyUserName, Integer orderType) {
         int count = 0;
+        Integer realOrderType = orderType != null ? orderType : 1;
         for (Long orderId : orderIds) {
-            FsStoreOrder order = fsStoreOrderMapper.selectFsStoreOrderByOrderId(orderId);
-            if (order == null) {
-                throw new CustomException("订单不存在:" + orderId);
-            }
-
-            FsStoreOrderFinanceAudit existAudit = fsStoreOrderFinanceAuditMapper.selectByOrderId(orderId);
+            FsStoreOrderFinanceAudit existAudit = fsStoreOrderFinanceAuditMapper.selectByOrderIdAndOrderType(orderId, realOrderType);
             if (existAudit != null && existAudit.getAuditStatus() == 0) {
-                throw new CustomException("订单已存在待审核记录:" + order.getOrderCode());
+                throw new CustomException("订单已存在待审核记录:" + existAudit.getOrderCode());
             }
 
             FsStoreOrderFinanceAudit audit = new FsStoreOrderFinanceAudit();
             audit.setOrderId(orderId);
-            audit.setOrderCode(order.getOrderCode());
             audit.setAuditType(auditType);
-            audit.setOriginalTotalPrice(order.getTotalPrice());
-            audit.setOriginalPayPrice(order.getPayPrice());
             audit.setNewTotalPrice(newTotalPrice);
             audit.setNewPayPrice(newPayPrice);
             audit.setPriceChangeReason(priceChangeReason);
             audit.setVoucherImages(voucherImages);
             audit.setVoucherRemark(voucherRemark);
-            audit.setOrderType(orderType != null ? orderType : 1);
+            audit.setOrderType(realOrderType);
             audit.setAuditStatus(0);
             audit.setApplyUserId(applyUserId);
             audit.setApplyUserName(applyUserName);
             audit.setApplyTime(new Date());
 
+            if (isExternalFinanceAuditOrder(realOrderType)) {
+                FsExternalOrder order = fsExternalOrderMapper.selectFsExternalOrderByOrderId(orderId);
+                if (order == null) {
+                    throw new CustomException("外部订单不存在:" + orderId);
+                }
+                audit.setOrderCode(order.getOrderCode());
+                audit.setOriginalTotalPrice(order.getTotalPrice());
+                audit.setOriginalPayPrice(order.getPayPrice());
+            } else {
+                FsStoreOrder order = fsStoreOrderMapper.selectFsStoreOrderByOrderId(orderId);
+                if (order == null) {
+                    throw new CustomException("订单不存在:" + orderId);
+                }
+                audit.setOrderCode(order.getOrderCode());
+                audit.setOriginalTotalPrice(order.getTotalPrice());
+                audit.setOriginalPayPrice(order.getPayPrice());
+            }
+
             count += fsStoreOrderFinanceAuditMapper.insertFsStoreOrderFinanceAudit(audit);
         }
         return count;
@@ -4909,23 +4946,45 @@ public class FsStoreOrderServiceImpl implements IFsStoreOrderService {
         int result = fsStoreOrderFinanceAuditMapper.updateFsStoreOrderFinanceAudit(audit);
 
         if (auditStatus == 1) {
-            FsStoreOrder order = new FsStoreOrder();
-            order.setOrderId(audit.getOrderId());
-
-            if (audit.getAuditType() == 1) {
-                order.setTotalPrice(audit.getNewTotalPrice());
-                order.setPayPrice(audit.getNewPayPrice());
-                order.setPayMoney(audit.getNewPayPrice());
-            } else if (audit.getAuditType() == 2) {
-               order.setStatus(4);
+            if (isExternalFinanceAuditOrder(audit.getOrderType())) {
+                updateExternalOrderByFinanceAudit(audit);
+            } else {
+                updateStoreOrderByFinanceAudit(audit);
             }
-
-            fsStoreOrderMapper.updateFsStoreOrder(order);
         }
 
         return result;
     }
 
+    private void updateStoreOrderByFinanceAudit(FsStoreOrderFinanceAudit audit) {
+        FsStoreOrder order = new FsStoreOrder();
+        order.setOrderId(audit.getOrderId());
+        if (audit.getAuditType() == 1) {
+            order.setTotalPrice(audit.getNewTotalPrice());
+            order.setPayPrice(audit.getNewPayPrice());
+            order.setPayMoney(audit.getNewPayPrice());
+        } else if (audit.getAuditType() == 2) {
+            order.setStatus(4);
+        }
+        fsStoreOrderMapper.updateFsStoreOrder(order);
+    }
+
+    private void updateExternalOrderByFinanceAudit(FsStoreOrderFinanceAudit audit) {
+        FsExternalOrder order = new FsExternalOrder();
+        order.setOrderId(audit.getOrderId());
+        if (audit.getAuditType() == 1) {
+            order.setTotalPrice(audit.getNewTotalPrice());
+            order.setPayPrice(audit.getNewPayPrice());
+        } else if (audit.getAuditType() == 2) {
+            order.setStatus(4);
+        }
+        fsExternalOrderMapper.updateFsExternalOrder(order);
+    }
+
+    private boolean isExternalFinanceAuditOrder(Integer orderType) {
+        return orderType != null && orderType == 0;
+    }
+
     @Override
     public void createJSTOmsOrder(List<Long> orderIds) throws Exception {
         // 1. 检查 ERP 是否开启

+ 9 - 0
fs-service/src/main/resources/mapper/his/FsExternalOrderMapper.xml

@@ -286,4 +286,13 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
         LEFT JOIN company_user cu ON o.company_user_id = cu.user_id
         WHERE o.order_id = #{orderId}
     </select>
+
+    <select id="selectSignedOrdersWithoutAudit" resultMap="FsExternalOrderResult">
+        select * from fs_external_order o
+        where o.delivery_status = 3 and o.status !=-3
+        and not exists (
+            select 1 from fs_store_order_finance_audit fa
+            where fa.order_id = o.order_id and fa.audit_type = 2 and fa.order_type=0
+        )
+    </select>
 </mapper>

+ 8 - 0
fs-service/src/main/resources/mapper/his/FsStoreOrderFinanceAuditMapper.xml

@@ -62,6 +62,14 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
         limit 1
     </select>
 
+    <select id="selectByOrderIdAndOrderType" resultMap="FsStoreOrderFinanceAuditResult">
+        <include refid="selectFsStoreOrderFinanceAuditVo"/>
+        where order_id = #{orderId}
+          and order_type = #{orderType}
+        order by create_time desc
+        limit 1
+    </select>
+
     <insert id="insertFsStoreOrderFinanceAudit" parameterType="FsStoreOrderFinanceAudit" useGeneratedKeys="true" keyProperty="id">
         insert into fs_store_order_finance_audit
         <trim prefix="(" suffix=")" suffixOverrides=",">

+ 10 - 0
fs-service/src/main/resources/mapper/his/FsStoreOrderMapper.xml

@@ -2360,4 +2360,14 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
         </if>
     </select>
 
+    <select id="selectSignedOrdersWithoutAudit" resultMap="FsStoreOrderResult">
+        select * from fs_store_order so
+        where so.delivery_status = 3
+        and so.is_del = 0 and so.status !=-3
+        and not exists (
+            select 1 from fs_store_order_finance_audit fa
+            where fa.order_id = so.order_id and fa.audit_type = 2 and  fa.order_type=1
+        )
+    </select>
+
 </mapper>

+ 6 - 0
fs-service/src/main/resources/mapper/his/LifeSaluteOrderMapper.xml

@@ -126,6 +126,12 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
         where order_no = #{orderNo}
     </select>
 
+    <!-- 根据运单号查询生命礼赞订单 -->
+    <select id="selectLifeSaluteOrderByWaybillNo" parameterType="String" resultMap="LifeSaluteOrderResult">
+        <include refid="selectLifeSaluteOrderVo"/>
+        where waybill_no = #{waybillNo}
+    </select>
+
     <!-- 根据ID列表批量查询生命礼赞订单 -->
     <select id="selectLifeSaluteOrderByIds" resultMap="LifeSaluteOrderResult">
         <include refid="selectLifeSaluteOrderVo"/>