xuhy
3 天以前 b8cebfa38ff8cd2065431a8f18c79e480d64ff10
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.ruoyi.system.mapper.TSysOrderMapper">
 
    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="com.ruoyi.system.model.TSysOrder">
        <id column="id" property="id" />
        <result column="app_user_id" property="appUserId" />
        <result column="inspection_id" property="inspectionId" />
        <result column="order_number" property="orderNumber" />
        <result column="total_money" property="totalMoney" />
        <result column="check_time" property="checkTime" />
        <result column="create_time" property="createTime" />
        <result column="update_time" property="updateTime" />
        <result column="create_by" property="createBy" />
        <result column="update_by" property="updateBy" />
        <result column="disabled" property="disabled" />
    </resultMap>
 
    <!-- 通用查询结果列 -->
    <sql id="Base_Column_List">
        id, app_user_id, inspection_id, order_number, total_money, check_time, create_time, update_time, create_by, update_by, disabled
    </sql>
    <select id="queryListByAppUserId" resultType="com.ruoyi.system.vo.TSysOrderVO">
        select
        <include refid="Base_Column_List"/>
            from t_sys_order
        where app_user_id = #{appUserId} and disabled = ${@com.ruoyi.common.enums.DisabledEnum@NO.getCode()}
        order by create_time desc
    </select>
 
 
    <select id="pageList" resultType="com.ruoyi.system.vo.TSysOrderPageVo">
        select t1.id,t1.create_time,t1.total_money,t2.nick_name as userName,t2.phone from t_sys_order t1
        left join t_sys_app_user t2 on t1.app_user_id = t2.id
        where t1.disabled = 0  and t1.clinic_id =#{query.clinicId}
        <if test="query.userName != null and query.userName != ''">
            and t2.nick_name like concat('%',#{query.userName},'%')
        </if>
        <if test="query.phone != null and query.phone != ''">
            and t2.phone like concat('%',#{query.phone},'%')
        </if>
        <if test="sTime != null and eTime != ''">
            and t1.create_time between #{sTime} and #{eTime}
        </if>
        order by t1.create_time desc
 
    </select>
    <select id="clinicSalesStatisticsCount" resultType="java.lang.Integer">
        select count(1)
        from t_sys_order tso
                 left join t_sys_order_goods tsog on tso.id = tsog.order_id
                 left join t_erp_goods teg on tsog.goods_id = teg.id
        where tso.disabled = ${@com.ruoyi.common.enums.DisabledEnum@NO.getCode()}
          and tso.clinic_id in <foreach collection="clinicIds" open="(" separator="," item="id" close=")">#{id}</foreach>
    </select>
    <select id="clinicSalesStatisticsTypeCount" resultType="java.lang.Integer">
        select count(1)
        from t_sys_order tso
                 left join t_sys_order_goods tsog on tso.id = tsog.order_id
                 left join t_erp_goods teg on tsog.goods_id = teg.id
        where tso.disabled = ${@com.ruoyi.common.enums.DisabledEnum@NO.getCode()}
          and tso.clinic_id in <foreach collection="clinicIds" open="(" separator="," item="id" close=")">#{id}</foreach>
        group by teg.type_id
    </select>
    <select id="clinicSalesStatisticsMoney" resultType="java.math.BigDecimal">
        select sum(total_money) from t_sys_order
        where disabled = ${@com.ruoyi.common.enums.DisabledEnum@NO.getCode()}
          and pay_time between #{startTime} and #{endTime}
          and clinic_id = #{clinicId}
    </select>
    <select id="clinicSalesStatisticsGoodsType"
            resultType="com.ruoyi.system.vo.ClinicSalesStatisticsGoodsTypeVO">
        select count(1), tegt.type_name
        from t_sys_order tso
                 left join t_sys_order_goods tsog on tso.id = tsog.order_id
                 left join t_erp_goods teg on tsog.goods_id = teg.id
                 left join t_erp_goods_type tegt on teg.type_id = tegt.id
        where tso.disabled = ${@com.ruoyi.common.enums.DisabledEnum@NO.getCode()}
          and tso.pay_time between #{startTime} and #{endTime}
          and tso.clinic_id = #{clinicId}
        group by teg.type_id
        order by count(1) desc
    </select>
    <select id="clinicSalesStatisticsGoodsCount"
            resultType="com.ruoyi.system.vo.ClinicSalesStatisticsGoodsCountVO">
        select
        date_format(t1.pay_time, '%m.%d') as `time`,
        date_format(t1.pay_time, '%Y-%m-%d') as payTime,
        sum(t2.sale_count) as goodsCount
        from t_sys_order t1
        left join t_sys_order_goods t2 on t1.id = t2.order_id
        where t1.disabled = ${@com.ruoyi.common.enums.DisabledEnum@NO.getCode()}
        and t1.pay_time between #{startTime} and #{endTime}
        and t1.clinic_id = #{clinicId}
        <if test="goodsName != null and goodsName != ''">
            and t2.goods_name like concat('%',#{goodsName},'%')
        </if>
        group by date_format(t1.pay_time, '%m.%d')
    </select>
    <select id="clinicSalesStatisticsGoodsCountMonth"
            resultType="com.ruoyi.system.vo.ClinicSalesStatisticsGoodsCountVO">
        select
        date_format(t1.pay_time, '%Y.%m') as `time`,
        sum(t2.sale_count) as goodsCount
        from t_sys_order t1
        left join t_sys_order_goods t2 on t1.id = t2.order_id
        where t1.disabled = ${@com.ruoyi.common.enums.DisabledEnum@NO.getCode()}
        and t1.pay_time between #{startTime} and #{endTime}
        and t1.clinic_id = #{clinicId}
        <if test="goodsName != null and goodsName != ''">
            and t2.goods_name like concat('%',#{goodsName},'%')
        </if>
        group by date_format(t1.pay_time, '%Y.%m')
    </select>
 
</mapper>