forked from kidgrow-microservices-platform

dougang
2020-12-03 189cb9a1b925fbdfde02c175b2d84f4fe00dbaa7
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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
<?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.kidgrow.oprationcenter.mapper.ProductOrderMapper">
    <!--定义查询列-->
    <sql id="Column_List">
      DISTINCT *
    </sql>
 
    <!--sql查询片段-->
    <sql id="where">
        <where>
            <include refid="where_condition"></include>
        </where>
    </sql>
    <sql id="where_condition">
        <if test="p.id != null and p.id !=''">
            and id = #{p.id}
        </if>
        <if test="p.hospitalId != null and p.hospitalId !=''">
            and hospital_id = #{p.hospitalId}
        </if>
        <if test="p.hospitalName != null and p.hospitalName !=''">
            and hospital_name like concat('%',#{p.hospitalName},'%')
        </if>
        <if test="p.departmentId != null and p.departmentId !=''">
            and department_id = #{p.departmentId}
        </if>
        <if test="p.departmentName != null and p.departmentName !=''">
            and department_name = #{p.departmentName}
        </if>
        <if test="p.contractNo != null and p.contractNo !=''">
            and contract_no = #{p.contractNo}
        </if>
        <if test="p.contractTitle != null and p.contractTitle !=''">
            and contract_title = #{p.contractTitle}
        </if>
        <if test="p.contractBeginTime != null and p.contractBeginTime !=''">
            and contract_begin_time = #{p.contractBeginTime}
        </if>
        <if test="p.contractEndTime != null and p.contractEndTime !=''">
            and contract_end_time = #{p.contractEndTime}
        </if>
        <if test="p.contractTime != null and p.contractTime !=''">
            and contract_time = #{p.contractTime}
        </if>
        <if test="p.isDel != null and p.isDel !=''">
            and is_del = #{p.isDel}
        </if>
        <if test="p.enabled != null and p.enabled !=''">
            and enabled = #{p.enabled}
        </if>
        <if test="p.updateTime != null and p.updateTime !=''">
            and update_time = #{p.updateTime}
        </if>
        <if test="p.createUserId != null and p.createUserId !=''">
            and create_user_id = #{p.createUserId}
        </if>
        <if test="p.createUserName != null and p.createUserName !=''">
            and create_user_name = #{p.createUserName}
        </if>
        <if test="p.updateUserId != null and p.updateUserId !=''">
            and update_user_id = #{p.updateUserId}
        </if>
        <if test="p.updateUserName != null and p.updateUserName !=''">
            and update_user_name = #{p.updateUserName}
        </if>
        <if test="p.createTime != null and p.createTime !=''">
            and create_time = #{p.createTime}
        </if>
    </sql>
    <!--定义数据权限的查询-->
    <sql id="Role_Organization">
        <if test="p.roleOrg != null and p.roleOrg.size>0">
            <foreach item="item" collection="p.roleOrg" index="">
                <foreach item="itemto" collection="item" index="inx">
                    <choose>
                        <when test="inx == 1">
                            <if test="itemto.flag">
 
                            </if>
                            <if test="!itemto.flag">
                                or ( is_del = 0 and enabled=1) <include refid="where_condition"></include>
                            </if>
                        </when>
                        <when test="inx==2">
                            <if test="itemto.flag">
                                AND
                                <foreach item="itemtoto" collection="itemto.object" separator="or" open="(" close=")"
                                         index="">
                                    create_user_org_code = #{itemtoto.orgCode}
                                </foreach>
                            </if>
                            <if test="!itemto.flag">
                                or (
                                <foreach item="itemtoto" collection="itemto.object" separator="or" open="(" close=")"
                                         index="">
                                    create_user_org_code = #{itemtoto.orgCode}
                                </foreach>
                                and is_del = 0 and enabled=1  <include refid="where_condition"></include>
                                )
                            </if>
                        </when>
                        <when test="inx == 3">
                            <if test="itemto.flag">
                                AND
                                create_user_org_code = #{itemto.object}
                            </if>
                            <if test="!itemto.flag">
                                or (create_user_org_code = #{itemto.object} and is_del = 0 and enabled=1) <include refid="where_condition"></include>
                            </if>
                        </when>
                        <when test="inx == 4">
                            <if test="itemto.flag">
                                AND
                                create_user_org_code like '${itemto.object}%'
                            </if>
                            <if test="!itemto.flag">
                                or (create_user_org_code like '${itemto.object}%' and is_del = 0 and enabled=1) <include refid="where_condition"></include>
                            </if>
                        </when>
                        <when test="inx == 5">
                            <if test="itemto.flag">
                                AND
                                create_user_id = #{itemto.object}
                            </if>
                            <if test="!itemto.flag">
                                or (create_user_id = #{itemto.object} and is_del = 0 and enabled=1) <include refid="where_condition"></include>
                            </if>
                        </when>
                        <otherwise>
                            AND id is null
                        </otherwise>
                    </choose>
                </foreach>
            </foreach>
        </if>
    </sql>
    <!--sql查询片段-->
    <sql id="where_role">
        <where>
            <!--查询条件自行添加-->
            is_del=0
            <include refid="where_condition"></include>
            <include refid="Role_Organization"></include>
        </where>
    </sql>
    <!--定义根据-ProductOrder当作查询条件返回对象-->
    <select id="findByObject" resultType="com.kidgrow.oprationcenter.model.ProductOrder">
        select
        <include refid="Column_List"/>
        from product_order
        <include refid="where"/>
        order by id desc
        limit 1
    </select>
 
    <!--定义根据-ProductOrder当作查询条件返回对象集合-->
    <select id="findList" resultType="com.kidgrow.oprationcenter.model.ProductOrder">
        select
        <include refid="Column_List"/>
        from product_order
        <include refid="where_role"/>
        order by id desc
    </select>
    <update id="delProductDetail">
        UPDATE  product_order_record SET is_del=1,update_time=now() WHERE order_id= #{orderId};
        UPDATE  product_order_detail SET is_del=1,update_time=now() WHERE order_id= #{orderId};
    </update>
    <select id="getStatus" parameterType="com.kidgrow.oprationcenter.model.ProductOrder" resultType="int">
        SELECT
    SUM(total)
        FROM
            (
                SELECT
                    count(*) total
                FROM
                    `product_order` order_order
                LEFT JOIN product_order_record record ON order_order.id = record.order_id
                WHERE
                    order_order.hospital_id = #{hospitalId}
                AND order_order.department_id = #{departmentId}
                AND record.pro_type = 1
                AND order_order.enabled = 1
                AND order_order.is_del = 0
                AND record.enabled = 1
                AND record.is_del = 0
                UNION ALL
                    SELECT
                        count(*) total
                    FROM
                        `product_order` order_order
                    LEFT JOIN product_order_record record ON order_order.id = record.order_id
                    WHERE
                        order_order.hospital_id = #{hospitalId}
                    AND record.pro_type = 1
                    AND record.is_share = 1
                    AND order_order.enabled = 1
                    AND order_order.is_del = 0
                    AND record.enabled = 1
                    AND record.is_del = 0
            ) cc
    </select>
</mapper>