Pārlūkot izejas kodu

财务审核合计行

wangxy 1 dienu atpakaļ
vecāks
revīzija
bd779abf09

+ 12 - 0
fs-common/src/main/java/com/fs/common/core/controller/BaseController.java

@@ -3,6 +3,7 @@ package com.fs.common.core.controller;
 import java.beans.PropertyEditorSupport;
 import java.util.Date;
 import java.util.List;
+import java.util.Map;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.web.bind.WebDataBinder;
@@ -89,6 +90,17 @@ public class BaseController
         return rspData;
     }
 
+    /**
+     * 响应请求分页数据(带合计行)
+     */
+    @SuppressWarnings({ "rawtypes", "unchecked" })
+    protected TableDataInfo getDataTable(List<?> list, Map<String, Object> summary)
+    {
+        TableDataInfo rspData = getDataTable(list);
+        rspData.setSummary(summary);
+        return rspData;
+    }
+
     /**
      * 返回成功
      */

+ 15 - 1
fs-common/src/main/java/com/fs/common/core/page/TableDataInfo.java

@@ -2,10 +2,11 @@ package com.fs.common.core.page;
 
 import java.io.Serializable;
 import java.util.List;
+import java.util.Map;
 
 /**
  * 表格分页数据对象
- * 
+ *
 
  */
 public class TableDataInfo implements Serializable
@@ -24,6 +25,9 @@ public class TableDataInfo implements Serializable
     /** 消息内容 */
     private String msg;
 
+    /** 合计行(整个数据集的汇总,非当前页) */
+    private Map<String, Object> summary;
+
     private long totalRecordCount;
 
     private long successRecordCount;
@@ -112,4 +116,14 @@ public class TableDataInfo implements Serializable
     {
         this.msg = msg;
     }
+
+    public Map<String, Object> getSummary()
+    {
+        return summary;
+    }
+
+    public void setSummary(Map<String, Object> summary)
+    {
+        this.summary = summary;
+    }
 }

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

@@ -52,7 +52,8 @@ public class FsExternalOrderController extends BaseController {
             fsExternalOrder.setMemberPhone(PhoneUtil.encryptPhone(fsExternalOrder.getMemberPhone()));
         }
         List<FsExternalOrderListVO> list = fsExternalOrderService.selectExternalOrderListVO(fsExternalOrder);
-        return getDataTable(list);
+        java.util.Map<String, Object> summary = fsExternalOrderService.selectExternalOrderListVOSum(fsExternalOrder);
+        return getDataTable(list, summary);
     }
 
     @GetMapping(value = "/{orderId}")

+ 4 - 3
fs-company/src/main/java/com/fs/company/controller/store/FsFinanceOrderController.java

@@ -40,7 +40,8 @@ public class FsFinanceOrderController extends BaseController {
         LoginUser loginUser = SecurityUtils.getLoginUser();
         fsExternalOrder.setCompanyId(loginUser.getCompany().getCompanyId());
         List<FsFinanceOrderListVO> list = fsExternalOrderMapper.selectFinanceOrderListVO(fsExternalOrder);
-        return getDataTable(list);
+        java.util.Map<String, Object> summary = fsExternalOrderMapper.selectFinanceOrderListVOSum(fsExternalOrder);
+        return getDataTable(list, summary);
     }
 
     @Log(title = "导出财务外部订单", businessType = BusinessType.EXPORT)
@@ -144,8 +145,8 @@ public class FsFinanceOrderController extends BaseController {
         if (dto.getReturnPrice() == null) {
             return "回款金额不能为空";
         }
-        if (dto.getReturnPrice().compareTo(BigDecimal.ZERO) <= 0) {
-            return "回款金额必须大于0";
+        if (dto.getReturnPrice().compareTo(BigDecimal.ZERO) <0) {
+            return "回款金额必须大于等于0";
         }
         return null;
     }

+ 8 - 2
fs-company/src/main/java/com/fs/company/controller/store/FsRejectNoReturnController.java

@@ -12,6 +12,7 @@ import com.fs.framework.security.SecurityUtils;
 import com.fs.his.domain.FsExternalOrder;
 import com.fs.his.domain.vo.FsRejectNoReturnReportVO;
 import com.fs.his.mapper.FsStoreOrderMapper;
+import com.fs.his.mapper.FsExternalOrderMapper;
 import com.fs.his.param.FsStoreOrderParam;
 import com.fs.his.service.IFsExternalOrderService;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -35,6 +36,9 @@ public class FsRejectNoReturnController extends BaseController {
     @Autowired
     private FsStoreOrderMapper fsStoreOrderMapper;
 
+    @Autowired
+    private FsExternalOrderMapper fsExternalOrderMapper;
+
     /**
      * 拒收未还货列表
      */
@@ -46,7 +50,8 @@ public class FsRejectNoReturnController extends BaseController {
         LoginUser loginUser = SecurityUtils.getLoginUser();
         fsExternalOrder.setCompanyId(loginUser.getCompany().getCompanyId());
         List<FsRejectNoReturnReportVO> list = fsExternalOrderService.selectRejectNoReturnReport(fsExternalOrder);
-        return getDataTable(list);
+        java.util.Map<String, Object> summary = fsExternalOrderMapper.selectRejectNoReturnReportSum(fsExternalOrder);
+        return getDataTable(list, summary);
     }
 
     /**
@@ -74,7 +79,8 @@ public class FsRejectNoReturnController extends BaseController {
         LoginUser loginUser = SecurityUtils.getLoginUser();
         param.setCompanyId(loginUser.getCompany().getCompanyId());
         List<FsRejectNoReturnReportVO> list = fsStoreOrderMapper.selectStoreRejectNoReturnReport(param);
-        return getDataTable(list);
+        java.util.Map<String, Object> summary = fsStoreOrderMapper.selectStoreRejectNoReturnReportSum(param);
+        return getDataTable(list, summary);
     }
 
     /**

+ 12 - 4
fs-company/src/main/java/com/fs/company/controller/store/FsRejectReportController.java

@@ -13,6 +13,7 @@ import com.fs.his.domain.FsExternalOrder;
 import com.fs.his.domain.vo.FsRejectOrderReportVO;
 import com.fs.his.domain.vo.FsRejectProductReportVO;
 import com.fs.his.mapper.FsStoreOrderMapper;
+import com.fs.his.mapper.FsExternalOrderMapper;
 import com.fs.his.param.FsStoreOrderParam;
 import com.fs.his.service.IFsExternalOrderService;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -36,6 +37,9 @@ public class FsRejectReportController extends BaseController {
     @Autowired
     private FsStoreOrderMapper fsStoreOrderMapper;
 
+    @Autowired
+    private FsExternalOrderMapper fsExternalOrderMapper;
+
     /**
      * 拒收明细 - 订单维度列表
      */
@@ -47,7 +51,8 @@ public class FsRejectReportController extends BaseController {
         LoginUser loginUser = SecurityUtils.getLoginUser();
         fsExternalOrder.setCompanyId(loginUser.getCompany().getCompanyId());
         List<FsRejectOrderReportVO> list = fsExternalOrderService.selectRejectOrderReport(fsExternalOrder);
-        return getDataTable(list);
+        java.util.Map<String, Object> summary = fsExternalOrderMapper.selectRejectOrderReportSum(fsExternalOrder);
+        return getDataTable(list, summary);
     }
 
     /**
@@ -75,7 +80,8 @@ public class FsRejectReportController extends BaseController {
         LoginUser loginUser = SecurityUtils.getLoginUser();
         fsExternalOrder.setCompanyId(loginUser.getCompany().getCompanyId());
         List<FsRejectProductReportVO> list = fsExternalOrderService.selectRejectProductReport(fsExternalOrder);
-        return getDataTable(list);
+        java.util.Map<String, Object> summary = fsExternalOrderMapper.selectRejectProductReportSum(fsExternalOrder);
+        return getDataTable(list, summary);
     }
 
     /**
@@ -103,7 +109,8 @@ public class FsRejectReportController extends BaseController {
         LoginUser loginUser = SecurityUtils.getLoginUser();
         param.setCompanyId(loginUser.getCompany().getCompanyId());
         List<FsRejectOrderReportVO> list = fsStoreOrderMapper.selectStoreRejectOrderReport(param);
-        return getDataTable(list);
+        java.util.Map<String, Object> summary = fsStoreOrderMapper.selectStoreRejectOrderReportSum(param);
+        return getDataTable(list, summary);
     }
 
     /**
@@ -131,7 +138,8 @@ public class FsRejectReportController extends BaseController {
         LoginUser loginUser = SecurityUtils.getLoginUser();
         param.setCompanyId(loginUser.getCompany().getCompanyId());
         List<FsRejectProductReportVO> list = fsStoreOrderMapper.selectStoreRejectProductReport(param);
-        return getDataTable(list);
+        java.util.Map<String, Object> summary = fsStoreOrderMapper.selectStoreRejectProductReportSum(param);
+        return getDataTable(list, summary);
     }
 
     /**

+ 8 - 4
fs-company/src/main/java/com/fs/company/controller/store/FsReturnReportController.java

@@ -47,7 +47,8 @@ public class FsReturnReportController extends BaseController {
         LoginUser loginUser = SecurityUtils.getLoginUser();
         fsExternalOrder.setCompanyId(loginUser.getCompany().getCompanyId());
         List<FsReturnOrderReportVO> list = fsExternalOrderMapper.selectReturnOrderReport(fsExternalOrder);
-        return getDataTable(list);
+        java.util.Map<String, Object> summary = fsExternalOrderMapper.selectReturnOrderReportSum(fsExternalOrder);
+        return getDataTable(list, summary);
     }
 
     /**
@@ -75,7 +76,8 @@ public class FsReturnReportController extends BaseController {
         LoginUser loginUser = SecurityUtils.getLoginUser();
         fsExternalOrder.setCompanyId(loginUser.getCompany().getCompanyId());
         List<FsReturnProductReportVO> list = fsExternalOrderMapper.selectReturnProductReport(fsExternalOrder);
-        return getDataTable(list);
+        java.util.Map<String, Object> summary = fsExternalOrderMapper.selectReturnProductReportSum(fsExternalOrder);
+        return getDataTable(list, summary);
     }
 
     /**
@@ -103,7 +105,8 @@ public class FsReturnReportController extends BaseController {
         LoginUser loginUser = SecurityUtils.getLoginUser();
         param.setCompanyId(loginUser.getCompany().getCompanyId());
         List<FsReturnOrderReportVO> list = fsStoreOrderMapper.selectStoreReturnOrderReport(param);
-        return getDataTable(list);
+        java.util.Map<String, Object> summary = fsStoreOrderMapper.selectStoreReturnOrderReportSum(param);
+        return getDataTable(list, summary);
     }
 
     /**
@@ -131,7 +134,8 @@ public class FsReturnReportController extends BaseController {
         LoginUser loginUser = SecurityUtils.getLoginUser();
         param.setCompanyId(loginUser.getCompany().getCompanyId());
         List<FsReturnProductReportVO> list = fsStoreOrderMapper.selectStoreReturnProductReport(param);
-        return getDataTable(list);
+        java.util.Map<String, Object> summary = fsStoreOrderMapper.selectStoreReturnProductReportSum(param);
+        return getDataTable(list, summary);
     }
 
     /**

+ 8 - 2
fs-company/src/main/java/com/fs/company/controller/store/FsSignReportController.java

@@ -12,6 +12,7 @@ import com.fs.framework.security.SecurityUtils;
 import com.fs.his.domain.FsExternalOrder;
 import com.fs.his.domain.vo.FsSignOrderReportVO;
 import com.fs.his.mapper.FsStoreOrderMapper;
+import com.fs.his.mapper.FsExternalOrderMapper;
 import com.fs.his.param.FsStoreOrderParam;
 import com.fs.his.service.IFsExternalOrderService;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -35,6 +36,9 @@ public class FsSignReportController extends BaseController {
     @Autowired
     private FsStoreOrderMapper fsStoreOrderMapper;
 
+    @Autowired
+    private FsExternalOrderMapper fsExternalOrderMapper;
+
     /**
      * 签收未回款列表
      */
@@ -46,7 +50,8 @@ public class FsSignReportController extends BaseController {
         LoginUser loginUser = SecurityUtils.getLoginUser();
         fsExternalOrder.setCompanyId(loginUser.getCompany().getCompanyId());
         List<FsSignOrderReportVO> list = fsExternalOrderService.selectSignOrderReport(fsExternalOrder);
-        return getDataTable(list);
+        java.util.Map<String, Object> summary = fsExternalOrderMapper.selectSignOrderReportSum(fsExternalOrder);
+        return getDataTable(list, summary);
     }
 
     /**
@@ -74,7 +79,8 @@ public class FsSignReportController extends BaseController {
         LoginUser loginUser = SecurityUtils.getLoginUser();
         param.setCompanyId(loginUser.getCompany().getCompanyId());
         List<FsSignOrderReportVO> list = fsStoreOrderMapper.selectStoreSignOrderReport(param);
-        return getDataTable(list);
+        java.util.Map<String, Object> summary = fsStoreOrderMapper.selectStoreSignOrderReportSum(param);
+        return getDataTable(list, summary);
     }
 
     /**

+ 37 - 19
fs-company/src/main/java/com/fs/company/controller/store/FsStoreFinanceOrderController.java

@@ -79,7 +79,7 @@ public class FsStoreFinanceOrderController extends BaseController {
     }
 
     /**
-     * 导入回款数据(以订单编号匹配)
+     * 导入回款数据(以快递单号匹配)
      */
     @Log(title = "财务店铺订单回款导入", businessType = BusinessType.IMPORT)
     @PreAuthorize("@ss.hasPermi('store:storeFinanceOrder:import')")
@@ -94,31 +94,28 @@ public class FsStoreFinanceOrderController extends BaseController {
         List<FsFinanceOrderImportFailDTO> failList = new ArrayList<>();
 
         for (FsFinanceOrderImportDTO dto : importList) {
-            // 根据订单编号匹配 fs_store_order
-            FsStoreOrder order = matchStoreOrder(dto);
-            if (order == null) {
+            // 字段校验
+            String validateMsg = validateImportDto(dto);
+            if (validateMsg != null) {
                 failList.add(new FsFinanceOrderImportFailDTO(
-                        dto.getOrderCode(), dto.getDeliverySn(), null, null, dto.getReturnPrice(), "订单不存在"));
+                        dto.getOrderCode(), dto.getDeliverySn(), null, null, dto.getReturnPrice(), validateMsg));
                 continue;
             }
 
-            BigDecimal totalPrice = order.getTotalPrice() != null ? order.getTotalPrice() : BigDecimal.ZERO;
-            BigDecimal collectionPrice = order.getCollectionPrice();
-            BigDecimal importReturnPrice = dto.getReturnPrice() != null ? dto.getReturnPrice() : BigDecimal.ZERO;
-
-            // 回款金额与代收金额一致性校验
-            if (collectionPrice != null && collectionPrice.compareTo(importReturnPrice) != 0) {
+            // 匹配订单(按快递单号)
+            FsStoreOrder order = matchStoreOrder(dto);
+            if (order == null) {
                 failList.add(new FsFinanceOrderImportFailDTO(
-                        order.getOrderCode(), order.getDeliverySn(),
-                        totalPrice, collectionPrice, importReturnPrice,
-                        "回款金额与代收金额不一致"));
+                        dto.getOrderCode(), dto.getDeliverySn(), null, null, dto.getReturnPrice(),
+                        "快递单号未匹配到订单"));
                 continue;
             }
 
             // 更新回款信息
             FsStoreOrder update = new FsStoreOrder();
             update.setOrderId(order.getOrderId());
-            update.setReturnPrice(importReturnPrice);
+            update.setReturnPrice(dto.getReturnPrice() != null ? dto.getReturnPrice() : BigDecimal.ZERO);
+            update.setDeliverySn(dto.getDeliverySn());
             update.setUpdateBy(updateBy);
             if (dto.getReturnTime() != null) {
                 update.setDepositReturnTime(dto.getReturnTime());
@@ -140,11 +137,32 @@ public class FsStoreFinanceOrderController extends BaseController {
         return AjaxResult.success("导入成功 " + successCount + " 条,失败 0 条");
     }
 
-    /** 根据订单编号匹配店铺订单 */
-    private FsStoreOrder matchStoreOrder(FsFinanceOrderImportDTO dto) {
-        if (dto.getOrderCode() != null && !dto.getOrderCode().isEmpty()) {
-            return fsStoreOrderMapper.selectFsStoreOrderByOrderCode(dto.getOrderCode());
+    /** 导入字段校验,返回 null 表示通过,否则返回失败原因 */
+    private String validateImportDto(FsFinanceOrderImportDTO dto) {
+        if (dto.getDeliverySn() == null || dto.getDeliverySn().trim().isEmpty()) {
+            return "快递单号不能为空";
+        }
+        if (dto.getReturnPrice() == null) {
+            return "回款金额不能为空";
+        }
+        if (dto.getReturnPrice().compareTo(BigDecimal.ZERO) < 0) {
+            return "回款金额必须大于等于0";
         }
         return null;
     }
+
+    /** 根据快递单号匹配订单 */
+    private FsStoreOrder matchStoreOrder(FsFinanceOrderImportDTO dto) {
+        if (dto.getDeliverySn() == null || dto.getDeliverySn().isEmpty()) {
+            return null;
+        }
+        List<FsStoreOrder> list = fsStoreOrderMapper.selectFsStoreOrderListByDeliverySn(dto.getDeliverySn());
+        if (list == null || list.isEmpty()) {
+            return null;
+        }
+        if (list.size() > 1) {
+            logger.warn("快递单号 {} 对应多条订单,取第一条", dto.getDeliverySn());
+        }
+        return list.get(0);
+    }
 }

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

@@ -1,6 +1,7 @@
 package com.fs.his.mapper;
 
 import java.util.List;
+import java.util.Map;
 
 import com.fs.his.domain.FsExternalOrder;
 import com.fs.his.domain.vo.FsExternalOrderListVO;
@@ -63,4 +64,20 @@ public interface FsExternalOrderMapper {
     List<FsRejectNoReturnReportVO> selectRejectNoReturnReport(FsExternalOrder fsExternalOrder);
 
     List<FsSignDetailReportVO> selectSignDetailReport(FsExternalOrder fsExternalOrder);
+
+    Map<String, Object> selectExternalOrderListVOSum(FsExternalOrder fsExternalOrder);
+
+    Map<String, Object> selectFinanceOrderListVOSum(FsExternalOrder fsExternalOrder);
+
+    Map<String, Object> selectRejectNoReturnReportSum(FsExternalOrder fsExternalOrder);
+
+    Map<String, Object> selectRejectOrderReportSum(FsExternalOrder fsExternalOrder);
+
+    Map<String, Object> selectRejectProductReportSum(FsExternalOrder fsExternalOrder);
+
+    Map<String, Object> selectReturnOrderReportSum(FsExternalOrder fsExternalOrder);
+
+    Map<String, Object> selectReturnProductReportSum(FsExternalOrder fsExternalOrder);
+
+    Map<String, Object> selectSignOrderReportSum(FsExternalOrder fsExternalOrder);
 }

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

@@ -716,6 +716,18 @@ public interface FsStoreOrderMapper
      */
     List<FsRejectNoReturnReportVO> selectStoreRejectNoReturnReport(FsStoreOrderParam param);
 
+    Map<String, Object> selectStoreRejectNoReturnReportSum(FsStoreOrderParam param);
+
+    Map<String, Object> selectStoreRejectOrderReportSum(FsStoreOrderParam param);
+
+    Map<String, Object> selectStoreRejectProductReportSum(FsStoreOrderParam param);
+
+    Map<String, Object> selectStoreReturnOrderReportSum(FsStoreOrderParam param);
+
+    Map<String, Object> selectStoreReturnProductReportSum(FsStoreOrderParam param);
+
+    Map<String, Object> selectStoreSignOrderReportSum(FsStoreOrderParam param);
+
     @Select("select * from fs_store_order o where o.delivery_sn=#{deliverySn}")
     List<FsStoreOrder> selectFsStoreOrderListByDeliverySn( @Param("deliverySn") String deliverySn);
 

+ 3 - 0
fs-service/src/main/java/com/fs/his/service/IFsExternalOrderService.java

@@ -1,6 +1,7 @@
 package com.fs.his.service;
 
 import java.util.List;
+import java.util.Map;
 
 import com.fs.common.core.domain.R;
 import com.fs.his.domain.FsExternalOrder;
@@ -19,6 +20,8 @@ public interface IFsExternalOrderService {
 
     public List<FsExternalOrderListVO> selectExternalOrderListVO(FsExternalOrder fsExternalOrder);
 
+    public Map<String, Object> selectExternalOrderListVOSum(FsExternalOrder fsExternalOrder);
+
     public FsExternalOrderDetailVO selectExternalOrderDetailVO(Long orderId);
 
     public int insertFsExternalOrder(FsExternalOrder fsExternalOrder);

+ 6 - 0
fs-service/src/main/java/com/fs/his/service/impl/FsExternalOrderServiceImpl.java

@@ -153,6 +153,12 @@ public class FsExternalOrderServiceImpl implements IFsExternalOrderService {
         return list;
     }
 
+    @Override
+    @DataScope(deptAlias = "cu",userAlias = "cu")
+    public Map<String, Object> selectExternalOrderListVOSum(FsExternalOrder fsExternalOrder) {
+        return fsExternalOrderMapper.selectExternalOrderListVOSum(fsExternalOrder);
+    }
+
     @Override
     public FsExternalOrderDetailVO selectExternalOrderDetailVO(Long orderId) {
         FsExternalOrderDetailVO detailVO = fsExternalOrderMapper.selectExternalOrderDetailVO(orderId);

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

@@ -323,6 +323,7 @@
                 WHEN 2  THEN '审核通过'
                 WHEN 3  THEN '已发货'
                 WHEN 4  THEN '已回款'
+                WHEN -4 THEN '订单拒收'
                 WHEN -3 THEN '已取消'
                 ELSE '未知'
             END AS statusDesc,
@@ -830,5 +831,338 @@
         ORDER BY t.company_name, t.dept_name, t.order_type
     </select>
 
+    <!-- ========== 合计行查询(整个数据集汇总,非当前页) ========== -->
+
+    <select id="selectExternalOrderListVOSum" parameterType="FsExternalOrder" resultType="java.util.Map">
+        SELECT
+            SUM(t.totalPrice) AS totalPrice,
+            SUM(t.receivablePrice) AS receivablePrice,
+            SUM(t.payPrice) AS payPrice,
+            SUM(t.collectionPrice) AS collectionPrice,
+            SUM(t.refundPrice) AS refundPrice,
+            SUM(t.memberBuyCount) AS memberBuyCount
+        FROM (
+            SELECT
+                o.total_price AS totalPrice,
+                IFNULL(o.total_price, SUM(oi.price * oi.num)) AS receivablePrice,
+                o.pay_price AS payPrice,
+                o.collection_price AS collectionPrice,
+                o.refund_price AS refundPrice,
+                (SELECT COUNT(DISTINCT o2.order_id) FROM fs_external_order o2
+                 WHERE o2.user_id = o.user_id AND o2.company_id = o.company_id AND o2.status != -3) AS memberBuyCount
+            FROM fs_external_order o
+            LEFT JOIN company c                       ON o.company_id      = c.company_id
+            LEFT JOIN company_user cu                 ON o.company_user_id = cu.user_id
+            LEFT JOIN company_dept d                  ON cu.dept_id        = d.dept_id
+            LEFT JOIN fs_external_order_item oi       ON o.order_id        = oi.order_id
+            LEFT JOIN fs_store_order_finance_audit fa ON fa.order_id = o.order_id AND fa.order_type = 0 AND fa.audit_status = 0
+            LEFT JOIN fs_user u                       ON o.user_id         = u.user_id
+            LEFT JOIN fs_user_address ua              ON ua.address_id = (
+                SELECT ua2.address_id
+                FROM fs_user_address ua2
+                WHERE ua2.user_id = o.user_id AND IFNULL(ua2.is_del, 0) = 0
+                ORDER BY ua2.is_default DESC, ua2.update_time DESC, ua2.create_time DESC, ua2.address_id DESC
+                LIMIT 1
+            )
+            <where>
+                <if test="orderCode != null and orderCode != ''"> AND o.order_code = #{orderCode}</if>
+                <if test="userId != null"> AND o.user_id = #{userId}</if>
+                <if test="companyUserId != null"> AND o.company_user_id = #{companyUserId}</if>
+                <if test="companyUserName != null and companyUserName != ''"> AND cu.user_name LIKE CONCAT('%', #{companyUserName}, '%')</if>
+                <if test="deptId != null"> AND cu.dept_id = #{deptId}</if>
+                <if test="userName != null and userName != ''"> AND o.user_name LIKE CONCAT('%', #{userName}, '%')</if>
+                <if test="userPhone != null and userPhone != ''"> AND o.user_phone = #{userPhone}</if>
+                <if test="memberPhone != null and memberPhone != ''"> AND u.phone = #{memberPhone}</if>
+                <if test="memberName != null and memberName != ''"> AND u.nick_name LIKE CONCAT('%', #{memberName}, '%')</if>
+                <if test="memberSex != null"> AND u.sex = #{memberSex}</if>
+                <if test="memberAge != null"> AND TIMESTAMPDIFF(YEAR, FROM_UNIXTIME(u.birthday), CURDATE()) = #{memberAge}</if>
+                <if test="isPay != null"> AND o.is_pay = #{isPay}</if>
+                <if test="status != null"> AND o.status = #{status}</if>
+                <if test="deliveryStatus != null"> AND o.delivery_status = #{deliveryStatus}</if>
+                <if test="companyId != null"> AND o.company_id = #{companyId}</if>
+                <if test="isSync != null"> AND o.is_sync = #{isSync}</if>
+                <if test="sTime != null and sTime != ''"> AND o.external_create_time &gt;= #{sTime}</if>
+                <if test="eTime != null and eTime != ''"> AND o.external_create_time &lt;= CONCAT(#{eTime},' 23:59:59')</if>
+                <if test="address != null and address != ''"> AND (ua.province LIKE CONCAT('%', #{address}, '%') OR ua.city LIKE CONCAT('%', #{address}, '%') OR ua.district LIKE CONCAT('%', #{address}, '%') OR ua.detail LIKE CONCAT('%', #{address}, '%'))</if>
+                <if test="province != null and province != ''"> AND ua.province = #{province}</if>
+                <if test="city != null and city != ''"> AND ua.city = #{city}</if>
+                <if test="district != null and district != ''"> AND ua.district = #{district}</if>
+                <if test="township != null and township != ''"> AND ua.town_ship = #{township}</if>
+                <if test="productName != null and productName != ''"> AND oi.product_name LIKE CONCAT('%', #{productName}, '%')</if>
+                <if test="payPrice != null"> AND o.pay_price = #{payPrice}</if>
+                <if test="totalPrice != null"> AND o.total_price = #{totalPrice}</if>
+                <if test="collectionPrice != null"> AND o.collection_price = #{collectionPrice}</if>
+                <if test="refundPrice != null"> AND o.refund_price = #{refundPrice}</if>
+                <if test="remark != null and remark != ''"> AND o.remark LIKE CONCAT('%', #{remark}, '%')</if>
+                <if test="deliverySn != null and deliverySn != ''"> AND o.delivery_sn = #{deliverySn}</if>
+                <if test="deliveryCode != null and deliveryCode != ''"> AND o.delivery_code = #{deliveryCode}</if>
+                <if test="deliveryName != null and deliveryName != ''"> AND o.delivery_name LIKE CONCAT('%', #{deliveryName}, '%')</if>
+                <if test="deliveryStartTime != null and deliveryStartTime != ''"> AND o.delivery_time &gt;= #{deliveryStartTime}</if>
+                <if test="deliveryEndTime != null and deliveryEndTime != ''"> AND o.delivery_time &lt;= CONCAT(#{deliveryEndTime},' 23:59:59')</if>
+                <if test="depositReturnTimeStart != null and depositReturnTimeStart != ''"> AND o.update_time &gt;= #{depositReturnTimeStart}</if>
+                <if test="depositReturnTimeEnd != null and depositReturnTimeEnd != ''"> AND o.update_time &lt;= CONCAT(#{depositReturnTimeEnd},' 23:59:59')</if>
+                <if test="followTimeStart != null and followTimeStart != ''"> AND o.follow_time &gt;= #{followTimeStart}</if>
+                <if test="followTimeEnd != null and followTimeEnd != ''"> AND o.follow_time &lt;= CONCAT(#{followTimeEnd},' 23:59:59')</if>
+                <if test="refundTimeStart != null and refundTimeStart != ''"> AND o.refund_time &gt;= #{refundTimeStart}</if>
+                <if test="refundTimeEnd != null and refundTimeEnd != ''"> AND o.refund_time &lt;= CONCAT(#{refundTimeEnd},' 23:59:59')</if>
+                <if test="auditor != null and auditor != ''"> AND o.auditor LIKE CONCAT('%', #{auditor}, '%')</if>
+                <if test="auditTimeStart != null and auditTimeStart != ''"> AND o.audit_time &gt;= #{auditTimeStart}</if>
+                <if test="auditTimeEnd != null and auditTimeEnd != ''"> AND o.audit_time &lt;= CONCAT(#{auditTimeEnd},' 23:59:59')</if>
+                <if test="diseaseName != null and diseaseName != ''"> AND o.disease_name LIKE CONCAT('%', #{diseaseName}, '%')</if>
+                <if test="memberBuyCountMin != null">
+                    AND (SELECT COUNT(DISTINCT o2.order_id) FROM fs_external_order o2 WHERE o2.user_id = o.user_id AND o2.company_id = o.company_id AND o2.status != -3) &gt;= #{memberBuyCountMin}
+                </if>
+                <if test="memberBuyCount != null">
+                    AND (SELECT COUNT(DISTINCT o2.order_id) FROM fs_external_order o2 WHERE o2.user_id = o.user_id AND o2.company_id = o.company_id AND o2.status != -3) = #{memberBuyCount}
+                </if>
+                ${params.dataScope}
+            </where>
+            GROUP BY o.order_id
+            <if test="receivablePrice != null">
+                HAVING IFNULL(o.total_price, SUM(oi.price * oi.num)) = #{receivablePrice}
+            </if>
+        ) t
+    </select>
+
+    <select id="selectFinanceOrderListVOSum" parameterType="FsExternalOrder" resultType="java.util.Map">
+        SELECT
+            SUM(t.totalPrice) AS totalPrice,
+            SUM(t.collectionPrice) AS collectionPrice,
+            SUM(t.returnPrice) AS returnPrice
+        FROM (
+            SELECT
+                o.total_price AS totalPrice,
+                o.collection_price AS collectionPrice,
+                o.return_price AS returnPrice
+            FROM fs_external_order o
+            LEFT JOIN company c ON o.company_id = c.company_id
+            LEFT JOIN company_user cu ON o.company_user_id = cu.user_id
+            LEFT JOIN company_dept d ON cu.dept_id = d.dept_id
+            LEFT JOIN fs_external_order_item oi ON o.order_id = oi.order_id
+            <where>
+                 o.delivery_sn is not null and  o.delivery_sn !=''
+                <if test="orderCode != null and orderCode != ''"> AND o.order_code = #{orderCode}</if>
+                <if test="userName != null and userName != ''"> AND o.user_name LIKE CONCAT('%', #{userName}, '%')</if>
+                <if test="userPhone != null and userPhone != ''"> AND o.user_phone LIKE CONCAT('%', #{userPhone}, '%')</if>
+                <if test="deliverySn != null and deliverySn != ''"> AND o.delivery_sn = #{deliverySn}</if>
+                <if test="deliveryName != null and deliveryName != ''"> AND o.delivery_name LIKE CONCAT('%', #{deliveryName}, '%')</if>
+                <if test="status != null"> AND o.status = #{status}</if>
+                <if test="companyId != null"> AND o.company_id = #{companyId}</if>
+                <if test="returnStatus != null">
+                    <if test="returnStatus == 1"> AND o.status = 4</if>
+                    <if test="returnStatus == 0"> AND o.status != 4</if>
+                </if>
+                <if test="returnUser != null and returnUser != ''"> AND o.update_by LIKE CONCAT('%', #{returnUser}, '%')</if>
+                <if test="returnTimeStart != null and returnTimeStart != ''"> AND o.update_time >= #{returnTimeStart}</if>
+                <if test="returnTimeEnd != null and returnTimeEnd != ''"> AND o.update_time &lt;= #{returnTimeEnd}</if>
+                <if test="totalPrice != null"> AND o.total_price = #{totalPrice}</if>
+                <if test="collectionPrice != null"> AND o.collection_price = #{collectionPrice}</if>
+                <if test="receiverPhone != null and receiverPhone != ''"> AND o.receiver_phone LIKE CONCAT('%', #{receiverPhone}, '%')</if>
+                <if test="remark != null and remark != ''"> AND o.remark LIKE CONCAT('%', #{remark}, '%')</if>
+                <if test="payType != null"> AND o.pay_type = #{payType}</if>
+                <if test="companyUserName != null and companyUserName != ''"> AND cu.user_name LIKE CONCAT('%', #{companyUserName}, '%')</if>
+                <if test="deptId != null"> AND cu.dept_id = #{deptId}</if>
+                <if test="sTime != null and sTime != ''"> AND o.external_create_time >= #{sTime}</if>
+                <if test="eTime != null and eTime != ''"> AND o.external_create_time &lt;= #{eTime}</if>
+                <if test="deliveryStartTime != null and deliveryStartTime != ''"> AND o.delivery_time >= #{deliveryStartTime}</if>
+                <if test="deliveryEndTime != null and deliveryEndTime != ''"> AND o.delivery_time &lt;= #{deliveryEndTime}</if>
+                <if test="memberBuyCount != null">
+                    AND (SELECT COUNT(DISTINCT o2.order_id) FROM fs_external_order o2 WHERE o2.user_id = o.user_id AND o2.company_id = o.company_id AND o2.status != -3) = #{memberBuyCount}
+                </if>
+            </where>
+            GROUP BY o.order_id
+            <if test="productName != null and productName != '' or receivablePrice != null">
+                HAVING 1=1
+                <if test="productName != null and productName != ''"> AND GROUP_CONCAT(oi.product_name SEPARATOR ',') LIKE CONCAT('%', #{productName}, '%')</if>
+                <if test="receivablePrice != null"> AND IFNULL(o.total_price, SUM(oi.price * oi.num)) = #{receivablePrice}</if>
+            </if>
+        ) t
+    </select>
+
+    <select id="selectRejectNoReturnReportSum" parameterType="FsExternalOrder" resultType="java.util.Map">
+        SELECT
+            SUM(o.total_price) AS totalPrice
+        FROM fs_external_order o
+        LEFT JOIN company c ON o.company_id = c.company_id
+        LEFT JOIN company_user cu ON o.company_user_id = cu.user_id
+        LEFT JOIN company_dept d ON cu.dept_id = d.dept_id
+        <where>
+            o.delivery_status = 4 AND (o.is_return_goods IS NULL OR o.is_return_goods = 2)
+            <if test="orderCode != null and orderCode != ''"> AND o.order_code = #{orderCode}</if>
+            <if test="deliverySn != null and deliverySn != ''"> AND o.delivery_sn = #{deliverySn}</if>
+            <if test="userName != null and userName != ''"> AND o.user_name LIKE CONCAT('%', #{userName}, '%')</if>
+            <if test="userAddress != null and userAddress != ''"> AND o.user_address LIKE CONCAT('%', #{userAddress}, '%')</if>
+            <if test="totalPrice != null"> AND o.total_price = #{totalPrice}</if>
+            <if test="followTimeStart != null and followTimeStart != ''"> AND o.follow_time &gt;= #{followTimeStart}</if>
+            <if test="followTimeEnd != null and followTimeEnd != ''"> AND o.follow_time &lt;= #{followTimeEnd}</if>
+            <if test="deliveryName != null and deliveryName != ''"> AND o.delivery_name LIKE CONCAT('%', #{deliveryName}, '%')</if>
+            <if test="deliveryStartTime != null and deliveryStartTime != ''"> AND o.delivery_time &gt;= #{deliveryStartTime}</if>
+            <if test="deliveryEndTime != null and deliveryEndTime != ''"> AND o.delivery_time &lt;= #{deliveryEndTime}</if>
+            <if test="companyId != null"> AND o.company_id = #{companyId}</if>
+        </where>
+    </select>
+
+    <select id="selectRejectOrderReportSum" parameterType="FsExternalOrder" resultType="java.util.Map">
+        SELECT
+            SUM(t.totalPrice) AS totalPrice
+        FROM (
+            SELECT
+                o.total_price AS totalPrice
+            FROM fs_external_order o
+            LEFT JOIN company c ON o.company_id = c.company_id
+            LEFT JOIN company_user cu ON o.company_user_id = cu.user_id
+            LEFT JOIN company_dept d ON cu.dept_id = d.dept_id
+            LEFT JOIN fs_external_order_item oi ON o.order_id = oi.order_id
+            LEFT JOIN fs_user u ON o.user_id = u.user_id
+            <where>
+                o.delivery_status IN (4, 5, 6)
+                <if test="orderCode != null and orderCode != ''"> AND o.order_code = #{orderCode}</if>
+                <if test="deliverySn != null and deliverySn != ''"> AND o.delivery_sn = #{deliverySn}</if>
+                <if test="userName != null and userName != ''"> AND o.user_name LIKE CONCAT('%', #{userName}, '%')</if>
+                <if test="userAddress != null and userAddress != ''"> AND o.user_address LIKE CONCAT('%', #{userAddress}, '%')</if>
+                <if test="sTime != null and sTime != ''"> AND o.create_time >= #{sTime}</if>
+                <if test="eTime != null and eTime != ''"> AND o.create_time &lt;= #{eTime}</if>
+                <if test="totalPrice != null"> AND o.total_price = #{totalPrice}</if>
+                <if test="deliveryName != null and deliveryName != ''"> AND o.delivery_name LIKE CONCAT('%', #{deliveryName}, '%')</if>
+                <if test="rejectReturnTimeStart != null and rejectReturnTimeStart != ''"> AND o.reject_return_time >= #{rejectReturnTimeStart}</if>
+                <if test="rejectReturnTimeEnd != null and rejectReturnTimeEnd != ''"> AND o.reject_return_time &lt;= #{rejectReturnTimeEnd}</if>
+                <if test="returnUser != null and returnUser != ''"> AND o.update_by LIKE CONCAT('%', #{returnUser}, '%')</if>
+                <if test="userPhone != null and userPhone != ''"> AND o.user_phone LIKE CONCAT('%', #{userPhone}, '%')</if>
+                <if test="memberPhone != null and memberPhone != ''"> AND o.receiver_phone LIKE CONCAT('%', #{memberPhone}, '%')</if>
+                <if test="companyUserName != null and companyUserName != ''"> AND cu.user_name LIKE CONCAT('%', #{companyUserName}, '%')</if>
+                <if test="deliveryStartTime != null and deliveryStartTime != ''"> AND o.delivery_time >= #{deliveryStartTime}</if>
+                <if test="deliveryEndTime != null and deliveryEndTime != ''"> AND o.delivery_time &lt;= #{deliveryEndTime}</if>
+                <if test="companyId != null"> AND o.company_id = #{companyId}</if>
+            </where>
+            GROUP BY o.order_id, o.reject_return_time
+            <if test="productName != null and productName != ''">
+                HAVING GROUP_CONCAT(oi.product_name SEPARATOR ',') LIKE CONCAT('%', #{productName}, '%')
+            </if>
+        ) t
+    </select>
+
+    <select id="selectRejectProductReportSum" parameterType="FsExternalOrder" resultType="java.util.Map">
+        SELECT
+            SUM(t.num) AS num,
+            SUM(t.totalPrice) AS totalPrice
+        FROM (
+            SELECT
+                SUM(oi.num) AS num,
+                SUM(oi.price * oi.num) AS totalPrice
+            FROM fs_external_order o
+            LEFT JOIN company_user cu ON o.company_user_id = cu.user_id
+            LEFT JOIN company_dept d ON cu.dept_id = d.dept_id
+            INNER JOIN fs_external_order_item oi ON o.order_id = oi.order_id
+            <where>
+                o.delivery_status IN (4, 5, 6)
+                <if test="productName != null and productName != ''"> AND oi.product_name LIKE CONCAT('%', #{productName}, '%')</if>
+                <if test="deliveryName != null and deliveryName != ''"> AND o.delivery_name LIKE CONCAT('%', #{deliveryName}, '%')</if>
+                <if test="companyId != null"> AND o.company_id = #{companyId}</if>
+            </where>
+            GROUP BY o.delivery_name, oi.product_id, oi.product_name
+            <if test="totalNum != null or totalPrice != null">
+                HAVING 1=1
+                <if test="totalNum != null"> AND SUM(oi.num) = #{totalNum}</if>
+                <if test="totalPrice != null"> AND SUM(oi.price * oi.num) = #{totalPrice}</if>
+            </if>
+        ) t
+    </select>
+
+    <select id="selectReturnOrderReportSum" parameterType="FsExternalOrder" resultType="java.util.Map">
+        SELECT
+            SUM(t.payPrice) AS payPrice,
+            SUM(t.totalPrice) AS totalPrice
+        FROM (
+            SELECT
+                o.pay_price AS payPrice,
+                o.total_price AS totalPrice
+            FROM fs_external_order o
+            LEFT JOIN company c ON o.company_id = c.company_id
+            LEFT JOIN company_user cu ON o.company_user_id = cu.user_id
+            LEFT JOIN company_dept d ON cu.dept_id = d.dept_id
+            LEFT JOIN fs_external_order_item oi ON o.order_id = oi.order_id
+            LEFT JOIN fs_user u ON o.user_id = u.user_id
+            <where>
+                o.status = 4
+                <if test="orderCode != null and orderCode != ''"> AND o.order_code = #{orderCode}</if>
+                <if test="deliverySn != null and deliverySn != ''"> AND o.delivery_sn = #{deliverySn}</if>
+                <if test="userName != null and userName != ''"> AND o.user_name LIKE CONCAT('%', #{userName}, '%')</if>
+                <if test="userAddress != null and userAddress != ''"> AND o.user_address LIKE CONCAT('%', #{userAddress}, '%')</if>
+                <if test="sTime != null and sTime != ''"> AND o.create_time >= #{sTime}</if>
+                <if test="eTime != null and eTime != ''"> AND o.create_time &lt;= #{eTime}</if>
+                <if test="payPrice != null"> AND o.pay_price = #{payPrice}</if>
+                <if test="totalPrice != null"> AND o.total_price = #{totalPrice}</if>
+                <if test="deliveryName != null and deliveryName != ''"> AND o.delivery_name LIKE CONCAT('%', #{deliveryName}, '%')</if>
+                <if test="returnUser != null and returnUser != ''"> AND o.update_by LIKE CONCAT('%', #{returnUser}, '%')</if>
+                <if test="returnTimeStart != null and returnTimeStart != ''"> AND o.update_time >= #{returnTimeStart}</if>
+                <if test="returnTimeEnd != null and returnTimeEnd != ''"> AND o.update_time &lt;= #{returnTimeEnd}</if>
+                <if test="userPhone != null and userPhone != ''"> AND o.user_phone LIKE CONCAT('%', #{userPhone}, '%')</if>
+                <if test="memberPhone != null and memberPhone != ''"> AND o.receiver_phone LIKE CONCAT('%', #{memberPhone}, '%')</if>
+                <if test="companyUserName != null and companyUserName != ''"> AND cu.user_name LIKE CONCAT('%', #{companyUserName}, '%')</if>
+                <if test="deptId != null"> AND cu.dept_id = #{deptId}</if>
+                <if test="deliveryStartTime != null and deliveryStartTime != ''"> AND o.delivery_time >= #{deliveryStartTime}</if>
+                <if test="deliveryEndTime != null and deliveryEndTime != ''"> AND o.delivery_time &lt;= #{deliveryEndTime}</if>
+                <if test="companyId != null"> AND o.company_id = #{companyId}</if>
+            </where>
+            GROUP BY o.order_id, o.update_time
+            <if test="productName != null and productName != ''">
+                HAVING GROUP_CONCAT(oi.product_name SEPARATOR ',') LIKE CONCAT('%', #{productName}, '%')
+            </if>
+        ) t
+    </select>
+
+    <select id="selectReturnProductReportSum" parameterType="FsExternalOrder" resultType="java.util.Map">
+        SELECT
+            SUM(t.num) AS num,
+            SUM(t.totalPrice) AS totalPrice
+        FROM (
+            SELECT
+                SUM(oi.num) AS num,
+                SUM(oi.price * oi.num) AS totalPrice
+            FROM fs_external_order o
+            LEFT JOIN company_user cu ON o.company_user_id = cu.user_id
+            LEFT JOIN company_dept d ON cu.dept_id = d.dept_id
+            INNER JOIN fs_external_order_item oi ON o.order_id = oi.order_id
+            <where>
+                o.status = 4
+                <if test="productName != null and productName != ''"> AND oi.product_name LIKE CONCAT('%', #{productName}, '%')</if>
+                <if test="deliveryName != null and deliveryName != ''"> AND o.delivery_name LIKE CONCAT('%', #{deliveryName}, '%')</if>
+                <if test="deptId != null"> AND cu.dept_id = #{deptId}</if>
+                <if test="returnTimeStart != null and returnTimeStart != ''"> AND o.update_time >= #{returnTimeStart}</if>
+                <if test="returnTimeEnd != null and returnTimeEnd != ''"> AND o.update_time &lt;= #{returnTimeEnd}</if>
+                <if test="companyId != null"> AND o.company_id = #{companyId}</if>
+            </where>
+            GROUP BY d.dept_name, o.delivery_name, oi.product_id, oi.product_name
+        ) t
+    </select>
+
+    <select id="selectSignOrderReportSum" parameterType="FsExternalOrder" resultType="java.util.Map">
+        SELECT
+            SUM(o.pay_price) AS payPrice,
+            SUM(o.collection_price) AS collectionPrice,
+            SUM(o.total_price) AS totalPrice
+        FROM fs_external_order o
+        LEFT JOIN company c ON o.company_id = c.company_id
+        LEFT JOIN company_user cu ON o.company_user_id = cu.user_id
+        LEFT JOIN company_dept d ON cu.dept_id = d.dept_id
+        <where>
+            o.delivery_status = 3 AND o.status != 4
+            <if test="orderCode != null and orderCode != ''"> AND o.order_code = #{orderCode}</if>
+            <if test="deliverySn != null and deliverySn != ''"> AND o.delivery_sn = #{deliverySn}</if>
+            <if test="userName != null and userName != ''"> AND o.user_name LIKE CONCAT('%', #{userName}, '%')</if>
+            <if test="userAddress != null and userAddress != ''"> AND o.user_address LIKE CONCAT('%', #{userAddress}, '%')</if>
+            <if test="payPrice != null"> AND o.pay_price = #{payPrice}</if>
+            <if test="collectionPrice != null"> AND o.collection_price = #{collectionPrice}</if>
+            <if test="totalPrice != null"> AND o.total_price = #{totalPrice}</if>
+            <if test="followTimeStart != null and followTimeStart != ''"> AND o.follow_time &gt;= #{followTimeStart}</if>
+            <if test="followTimeEnd != null and followTimeEnd != ''"> AND o.follow_time &lt;= #{followTimeEnd}</if>
+            <if test="deliveryName != null and deliveryName != ''"> AND o.delivery_name LIKE CONCAT('%', #{deliveryName}, '%')</if>
+            <if test="deptId != null"> AND cu.dept_id = #{deptId}</if>
+            <if test="deliveryStartTime != null and deliveryStartTime != ''"> AND o.delivery_time &gt;= #{deliveryStartTime}</if>
+            <if test="deliveryEndTime != null and deliveryEndTime != ''"> AND o.delivery_time &lt;= #{deliveryEndTime}</if>
+            <if test="companyId != null"> AND o.company_id = #{companyId}</if>
+        </where>
+    </select>
+
 </mapper>
 

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

@@ -2970,4 +2970,185 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
         ORDER BY t.company_name, t.dept_name
     </select>
 
+    <!-- ========== 合计行查询(整个数据集汇总,非当前页) ========== -->
+
+    <select id="selectStoreRejectNoReturnReportSum" parameterType="com.fs.his.param.FsStoreOrderParam" resultType="java.util.Map">
+        SELECT
+            SUM(so.total_price) AS totalPrice
+        FROM fs_store_order so
+        LEFT JOIN company c ON so.company_id = c.company_id
+        LEFT JOIN company_user cu ON so.company_user_id = cu.user_id
+        LEFT JOIN company_dept d ON cu.dept_id = d.dept_id
+        <where>
+            so.delivery_status = 4 AND (so.is_return_goods IS NULL OR so.is_return_goods = 2)
+            <if test="orderCode != null and orderCode != ''"> AND so.order_code = #{orderCode}</if>
+            <if test="deliverySn != null and deliverySn != ''"> AND so.delivery_sn = #{deliverySn}</if>
+            <if test="userName != null and userName != ''"> AND so.user_name LIKE CONCAT('%', #{userName}, '%')</if>
+            <if test="userAddress != null and userAddress != ''"> AND so.user_address LIKE CONCAT('%', #{userAddress}, '%')</if>
+            <if test="totalPrice != null"> AND so.total_price = #{totalPrice}</if>
+            <if test="followTimeStart != null and followTimeStart != ''"> AND so.follow_time &gt;= #{followTimeStart}</if>
+            <if test="followTimeEnd != null and followTimeEnd != ''"> AND so.follow_time &lt;= #{followTimeEnd}</if>
+            <if test="deliveryName != null and deliveryName != ''"> AND so.delivery_name LIKE CONCAT('%', #{deliveryName}, '%')</if>
+            <if test="deliveryStartTime != null"> AND so.delivery_time &gt;= #{deliveryStartTime}</if>
+            <if test="deliveryEndTime != null"> AND so.delivery_time &lt;= #{deliveryEndTime}</if>
+            <if test="companyId != null"> AND so.company_id = #{companyId}</if>
+        </where>
+    </select>
+
+    <select id="selectStoreRejectOrderReportSum" parameterType="com.fs.his.param.FsStoreOrderParam" resultType="java.util.Map">
+        SELECT
+            SUM(t.totalPrice) AS totalPrice
+        FROM (
+            SELECT
+                so.total_price AS totalPrice
+            FROM fs_store_order so
+            LEFT JOIN company c ON so.company_id = c.company_id
+            LEFT JOIN company_user cu ON so.company_user_id = cu.user_id
+            LEFT JOIN company_dept d ON cu.dept_id = d.dept_id
+            LEFT JOIN fs_store_order_item soi ON so.order_id = soi.order_id
+            <where>
+                so.delivery_status IN (4, 5, 6)
+                <if test="orderCode != null and orderCode != ''"> AND so.order_code = #{orderCode}</if>
+                <if test="deliverySn != null and deliverySn != ''"> AND so.delivery_sn = #{deliverySn}</if>
+                <if test="userName != null and userName != ''"> AND so.user_name LIKE CONCAT('%', #{userName}, '%')</if>
+                <if test="userAddress != null and userAddress != ''"> AND so.user_address LIKE CONCAT('%', #{userAddress}, '%')</if>
+                <if test="sTime != null"> AND so.create_time &gt;= #{sTime}</if>
+                <if test="eTime != null"> AND so.create_time &lt;= #{eTime}</if>
+                <if test="totalPrice != null"> AND so.total_price = #{totalPrice}</if>
+                <if test="deliveryName != null and deliveryName != ''"> AND so.delivery_name LIKE CONCAT('%', #{deliveryName}, '%')</if>
+                <if test="rejectReturnTimeStart != null and rejectReturnTimeStart != ''"> AND so.reject_return_time &gt;= #{rejectReturnTimeStart}</if>
+                <if test="rejectReturnTimeEnd != null and rejectReturnTimeEnd != ''"> AND so.reject_return_time &lt;= #{rejectReturnTimeEnd}</if>
+                <if test="returnUser != null and returnUser != ''"> AND so.delivery_status_update_by LIKE CONCAT('%', #{returnUser}, '%')</if>
+                <if test="userPhone != null and userPhone != ''"> AND so.user_phone LIKE CONCAT('%', #{userPhone}, '%')</if>
+                <if test="receiverPhone != null and receiverPhone != ''"> AND so.receiver_phone LIKE CONCAT('%', #{receiverPhone}, '%')</if>
+                <if test="companyUserName != null and companyUserName != ''"> AND cu.user_name LIKE CONCAT('%', #{companyUserName}, '%')</if>
+                <if test="deliveryStartTime != null"> AND so.delivery_time &gt;= #{deliveryStartTime}</if>
+                <if test="deliveryEndTime != null"> AND so.delivery_time &lt;= #{deliveryEndTime}</if>
+                <if test="companyId != null"> AND so.company_id = #{companyId}</if>
+            </where>
+            GROUP BY so.order_id
+            <if test="productName != null and productName != ''">
+                HAVING GROUP_CONCAT(soi.json_info->>'$.productName' SEPARATOR ',') LIKE CONCAT('%', #{productName}, '%')
+            </if>
+        ) t
+    </select>
+
+    <select id="selectStoreRejectProductReportSum" parameterType="com.fs.his.param.FsStoreOrderParam" resultType="java.util.Map">
+        SELECT
+            SUM(t.num) AS num,
+            SUM(t.totalPrice) AS totalPrice
+        FROM (
+            SELECT
+                SUM(CAST(soi.json_info->>'$.num' AS DECIMAL(10,0))) AS num,
+                SUM(CAST(soi.json_info->>'$.price' AS DECIMAL(10,2)) * CAST(soi.json_info->>'$.num' AS DECIMAL(10,0))) AS totalPrice
+            FROM fs_store_order so
+            LEFT JOIN company_user cu ON so.company_user_id = cu.user_id
+            LEFT JOIN company_dept d ON cu.dept_id = d.dept_id
+            INNER JOIN fs_store_order_item soi ON so.order_id = soi.order_id
+            <where>
+                so.delivery_status IN (4, 5, 6)
+                <if test="productName != null and productName != ''"> AND soi.json_info->>'$.productName' LIKE CONCAT('%', #{productName}, '%')</if>
+                <if test="deliveryName != null and deliveryName != ''"> AND so.delivery_name LIKE CONCAT('%', #{deliveryName}, '%')</if>
+                <if test="companyId != null"> AND so.company_id = #{companyId}</if>
+            </where>
+            GROUP BY so.delivery_name, soi.json_info->>'$.productName'
+            <if test="totalNum != null or totalPrice != null">
+                HAVING 1=1
+                <if test="totalNum != null"> AND SUM(CAST(soi.json_info->>'$.num' AS DECIMAL(10,0))) = #{totalNum}</if>
+                <if test="totalPrice != null"> AND SUM(CAST(soi.json_info->>'$.price' AS DECIMAL(10,2)) * CAST(soi.json_info->>'$.num' AS DECIMAL(10,0))) = #{totalPrice}</if>
+            </if>
+        ) t
+    </select>
+
+    <select id="selectStoreReturnOrderReportSum" parameterType="com.fs.his.param.FsStoreOrderParam" resultType="java.util.Map">
+        SELECT
+            SUM(t.payPrice) AS payPrice,
+            SUM(t.totalPrice) AS totalPrice
+        FROM (
+            SELECT
+                so.pay_money AS payPrice,
+                so.total_price AS totalPrice
+            FROM fs_store_order so
+            LEFT JOIN company c ON so.company_id = c.company_id
+            LEFT JOIN company_user cu ON so.company_user_id = cu.user_id
+            LEFT JOIN company_dept d ON cu.dept_id = d.dept_id
+            LEFT JOIN fs_store_order_item soi ON so.order_id = soi.order_id
+            WHERE so.status = 4
+            <if test="orderCode != null and orderCode != ''"> AND so.order_code = #{orderCode}</if>
+            <if test="deliverySn != null and deliverySn != ''"> AND so.delivery_sn = #{deliverySn}</if>
+            <if test="userName != null and userName != ''"> AND so.user_name LIKE CONCAT('%', #{userName}, '%')</if>
+            <if test="userAddress != null and userAddress != ''"> AND so.user_address LIKE CONCAT('%', #{userAddress}, '%')</if>
+            <if test="sTime != null"> AND so.create_time &gt;= #{sTime}</if>
+            <if test="eTime != null"> AND so.create_time &lt;= #{eTime}</if>
+            <if test="payPrice != null"> AND so.pay_money = #{payPrice}</if>
+            <if test="totalPrice != null"> AND so.total_price = #{totalPrice}</if>
+            <if test="deliveryName != null and deliveryName != ''"> AND so.delivery_name LIKE CONCAT('%', #{deliveryName}, '%')</if>
+            <if test="returnUser != null and returnUser != ''"> AND so.update_by LIKE CONCAT('%', #{returnUser}, '%')</if>
+            <if test="returnTimeStart != null and returnTimeStart != ''"> AND so.deposit_return_time &gt;= #{returnTimeStart}</if>
+            <if test="returnTimeEnd != null and returnTimeEnd != ''"> AND so.deposit_return_time &lt;= #{returnTimeEnd}</if>
+            <if test="userPhone != null and userPhone != ''"> AND so.user_phone LIKE CONCAT('%', #{userPhone}, '%')</if>
+            <if test="receiverPhone != null and receiverPhone != ''"> AND so.user_phone LIKE CONCAT('%', #{receiverPhone}, '%')</if>
+            <if test="companyUserName != null and companyUserName != ''"> AND cu.user_name LIKE CONCAT('%', #{companyUserName}, '%')</if>
+            <if test="deptId != null"> AND cu.dept_id = #{deptId}</if>
+            <if test="deliveryStartTime != null"> AND so.delivery_time &gt;= #{deliveryStartTime}</if>
+            <if test="deliveryEndTime != null"> AND so.delivery_time &lt;= #{deliveryEndTime}</if>
+            <if test="companyId != null"> AND so.company_id = #{companyId}</if>
+            GROUP BY so.order_id
+            <if test="productName != null and productName != ''">
+                HAVING GROUP_CONCAT(soi.json_info->>'$.productName' SEPARATOR ',') LIKE CONCAT('%', #{productName}, '%')
+            </if>
+        ) t
+    </select>
+
+    <select id="selectStoreReturnProductReportSum" parameterType="com.fs.his.param.FsStoreOrderParam" resultType="java.util.Map">
+        SELECT
+            SUM(t.num) AS num,
+            SUM(t.totalPrice) AS totalPrice
+        FROM (
+            SELECT
+                SUM(CAST(soi.json_info->>'$.num' AS DECIMAL(10,0))) AS num,
+                SUM(CAST(soi.json_info->>'$.price' AS DECIMAL(10,2)) * CAST(soi.json_info->>'$.num' AS DECIMAL(10,0))) AS totalPrice
+            FROM fs_store_order so
+            LEFT JOIN company_user cu ON so.company_user_id = cu.user_id
+            LEFT JOIN company_dept d ON cu.dept_id = d.dept_id
+            INNER JOIN fs_store_order_item soi ON so.order_id = soi.order_id
+            WHERE so.status = 4
+            <if test="productName != null and productName != ''"> AND soi.json_info->>'$.productName' LIKE CONCAT('%', #{productName}, '%')</if>
+            <if test="deliveryName != null and deliveryName != ''"> AND so.delivery_name LIKE CONCAT('%', #{deliveryName}, '%')</if>
+            <if test="deptId != null"> AND cu.dept_id = #{deptId}</if>
+            <if test="returnTimeStart != null and returnTimeStart != ''"> AND so.deposit_return_time &gt;= #{returnTimeStart}</if>
+            <if test="returnTimeEnd != null and returnTimeEnd != ''"> AND so.deposit_return_time &lt;= #{returnTimeEnd}</if>
+            <if test="companyId != null"> AND so.company_id = #{companyId}</if>
+            GROUP BY d.dept_name, so.delivery_name, soi.product_id, soi.json_info->>'$.productName'
+        ) t
+    </select>
+
+    <select id="selectStoreSignOrderReportSum" parameterType="com.fs.his.param.FsStoreOrderParam" resultType="java.util.Map">
+        SELECT
+            SUM(so.pay_money) AS payPrice,
+            SUM(so.collection_price) AS collectionPrice,
+            SUM(so.total_price) AS totalPrice
+        FROM fs_store_order so
+        LEFT JOIN company c ON so.company_id = c.company_id
+        LEFT JOIN company_user cu ON so.company_user_id = cu.user_id
+        LEFT JOIN company_dept d ON cu.dept_id = d.dept_id
+        <where>
+            so.delivery_status = 3 AND so.status != 4
+            <if test="orderCode != null and orderCode != ''"> AND so.order_code = #{orderCode}</if>
+            <if test="deliverySn != null and deliverySn != ''"> AND so.delivery_sn = #{deliverySn}</if>
+            <if test="userName != null and userName != ''"> AND so.user_name LIKE CONCAT('%', #{userName}, '%')</if>
+            <if test="userAddress != null and userAddress != ''"> AND so.user_address LIKE CONCAT('%', #{userAddress}, '%')</if>
+            <if test="payPrice != null"> AND so.pay_money = #{payPrice}</if>
+            <if test="collectionPrice != null"> AND so.collection_price = #{collectionPrice}</if>
+            <if test="totalPrice != null"> AND so.total_price = #{totalPrice}</if>
+            <if test="followTimeStart != null and followTimeStart != ''"> AND so.follow_time &gt;= #{followTimeStart}</if>
+            <if test="followTimeEnd != null and followTimeEnd != ''"> AND so.follow_time &lt;= #{followTimeEnd}</if>
+            <if test="deliveryName != null and deliveryName != ''"> AND so.delivery_name LIKE CONCAT('%', #{deliveryName}, '%')</if>
+            <if test="deptId != null"> AND cu.dept_id = #{deptId}</if>
+            <if test="deliveryStartTime != null"> AND so.delivery_time &gt;= #{deliveryStartTime}</if>
+            <if test="deliveryEndTime != null"> AND so.delivery_time &lt;= #{deliveryEndTime}</if>
+            <if test="companyId != null"> AND so.company_id = #{companyId}</if>
+        </where>
+    </select>
+
 </mapper>

+ 17 - 14
fs-service/src/main/resources/mapper/his/FsUserMapper.xml

@@ -2477,24 +2477,27 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
         limit 10
     </select>
     <select id="findUsersByParam" resultType="com.fs.his.dto.FindUsersByDTO">
-        SELECT user_id as id, 0 as type,
-        CONCAT(user_id, '_', IFNULL(nick_name, '')) as name
-        FROM fs_user
-        WHERE user_id = #{keywords}
-        UNION
-        <!-- fs_user 按nick_name前缀搜索 -->
-        SELECT user_id as id, 0 as type,
-        CONCAT(user_id, '_', IFNULL(nick_name, '')) as name
-        FROM fs_user
-        WHERE nick_name LIKE CONCAT(#{keywords}, '%')
-        UNION
-        <!-- fs_user 按phone精确搜索(仅当keywords是数字时) -->
-        <if test="keywords.matches('\\d+')">
+        <!-- 客户搜索时 onlySales=true,仅返回销售信息,不查客户 -->
+        <if test="onlySales == null or onlySales == false">
+            SELECT user_id as id, 0 as type,
+            CONCAT(user_id, '_', IFNULL(nick_name, '')) as name
+            FROM fs_user
+            WHERE user_id = #{keywords}
+            UNION
+            <!-- fs_user 按nick_name前缀搜索 -->
             SELECT user_id as id, 0 as type,
             CONCAT(user_id, '_', IFNULL(nick_name, '')) as name
             FROM fs_user
-            WHERE phone = #{keywords}
+            WHERE nick_name LIKE CONCAT(#{keywords}, '%')
             UNION
+            <!-- fs_user 按phone精确搜索(仅当keywords是数字时) -->
+            <if test="keywords.matches('\\d+')">
+                SELECT user_id as id, 0 as type,
+                CONCAT(user_id, '_', IFNULL(nick_name, '')) as name
+                FROM fs_user
+                WHERE phone = #{keywords}
+                UNION
+            </if>
         </if>
         <!-- company_user相关查询 -->
         SELECT user_id as id, 1 as type,