yujian
2019-01-22 88b54772dbcf5ecab1e2316e4e4626ac901b8908
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
<?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.yeshi.fanli.dao.mybatis.order.LostOrderMapper">
    <resultMap id="BaseResultMap" type="com.yeshi.fanli.entity.bus.user.LostOrder">
        <id column="id" property="id" jdbcType="BIGINT" />
        <result column="orderId" property="orderId" jdbcType="VARCHAR" />
        <result column="type" property="type" jdbcType="INTEGER" />
        <result column="state" property="state" jdbcType="INTEGER" />
        <result column="createTime" property="createTime" jdbcType="BIGINT" />
        <result column="handleTime" property="handleTime" jdbcType="BIGINT" />
        <result column="remake" property="remake" jdbcType="VARCHAR" />
        <result column="judge" property="judge" jdbcType="VARCHAR" />
        <result column="result_code" property="resultCode" jdbcType="INTEGER" />
        <association property="userInfo" column="uid"
            javaType="com.yeshi.fanli.entity.bus.user.UserInfo">
            <id column="uid" property="id" jdbcType="BIGINT" />
        </association>
 
        <association property="order" column="oid"
            javaType="com.yeshi.fanli.entity.bus.user.Order">
            <id column="oid" property="id" jdbcType="BIGINT" />
        </association>
    </resultMap>
    
    <resultMap id="AllResultMap" type="com.yeshi.fanli.entity.bus.user.LostOrder">
        <id column="id" property="id" jdbcType="BIGINT" />
        <result column="orderId" property="orderId" jdbcType="VARCHAR" />
        <result column="type" property="type" jdbcType="INTEGER" />
        <result column="state" property="state" jdbcType="INTEGER" />
        <result column="createTime" property="createTime" jdbcType="BIGINT" />
        <result column="handleTime" property="handleTime" jdbcType="BIGINT" />
        <result column="remake" property="remake" jdbcType="VARCHAR" />
        <result column="judge" property="judge" jdbcType="VARCHAR" />
        <result column="result_code" property="resultCode" jdbcType="INTEGER" />
        <association property="userInfo" column="uid"
              select="com.yeshi.fanli.dao.mybatis.UserInfoMapper.selectByPKey"/>
     
        <association property="order" column="oid" 
                 select="com.yeshi.fanli.dao.mybatis.order.OrderMapper.selectByPrimaryKey"> 
        </association>
    </resultMap>
 
    <select id="selectByOrderId" resultMap="BaseResultMap"
        parameterType="java.lang.String">
        select * from yeshi_ec_lost_order where orderId=#{0}
    </select>
 
    <update id="updateByPrimaryKeySelective" parameterType="com.yeshi.fanli.entity.bus.user.LostOrder">
        update yeshi_ec_lost_order
        <set>
            <if test="orderId != null">orderId=#{orderId,jdbcType=VARCHAR},</if>
            <if test="type != null">type=#{type,jdbcType=INTEGER},</if>
            <if test="state != null">state=#{state,jdbcType=INTEGER},</if>
            <if test="createTime != null">createTime=#{createTime,jdbcType=BIGINT},</if>
            <if test="handleTime != null">handleTime=#{handleTime,jdbcType=BIGINT},</if>
            <if test="userInfo != null">uid=#{userInfo.id,jdbcType=BIGINT},</if>
            <if test="order != null">oid=#{order.id,jdbcType=BIGINT},</if>
            <if test="remake != null">remake=#{remake,jdbcType=VARCHAR},</if>
            <if test="judge != null">judge=#{judge,jdbcType=VARCHAR},</if>
            <if test="resultCode != null">result_code=#{resultCode,jdbcType=INTEGER},</if>
        </set>
        where id = #{id,jdbcType=BIGINT}
    </update>
    
    <select id="countByUid" resultType="java.util.HashMap">
       SELECT IFNULL(COUNT(id), 0) AS total,IFNULL(SUM(CASE WHEN state = 1 THEN 1 ELSE 0 END),0) AS totalPass,
               IFNULL(SUM(CASE WHEN state = 2 THEN 1 ELSE 0 END),0) AS totalReject
        FROM yeshi_ec_lost_order  WHERE  uid = #{uid};
    </select>
    
      <select id="listQuery" resultMap="AllResultMap">
        SELECT d.* FROM yeshi_ec_lost_order d
              left join  yeshi_ec_user u on d.uid = u.id
        WHERE 1=1
           <if test='key != null and key != ""'>
                  AND (d.orderId like '%${key}%' or d.uid like '%${key}%' or u.nick_name like '%${key}%') 
           </if>
           <if test='state != null'>
                  AND d.state = #{state}
           </if>
           <if test='handleType != null and handleType == 0'>
                  AND d.state = 0
           </if>
            <if test='handleType != null and handleType != 0'>
                  AND (d.state = 1 or d.state = 2)
           </if>
           
           ORDER BY d.createTime desc
        LIMIT ${start},${count}
   </select>
   
   <select id="countQuery" resultType="java.lang.Long">
        SELECT  IFNULL(count(d.id),0) FROM yeshi_ec_lost_order d
          left join  yeshi_ec_user u on d.uid = u.id
        WHERE 1=1
           <if test='key != null and key != ""'>
                  AND (d.orderId like '%${key}%' or d.uid like '%${key}%' or u.nick_name like '%${key}%') 
           </if>
           <if test='state != null'>
                  AND d.state = #{state}
           </if>
           <if test='handleType != null and handleType == 0'>
                  AND d.state = 0
           </if>
            <if test='handleType != null and handleType != 0'>
                  AND (d.state = 1 or d.state = 2)
           </if>
    </select>
      
      
      <select id="countLostNum" resultType="java.util.HashMap">
        SELECT COUNT(t.`id`) AS showValue, 
            <if test="dateType == 1">
                 FROM_UNIXTIME(t.`createTime`/1000,'%Y-%m-%d') AS 'showDate'
            </if>
            <if test="dateType == 2">
                 FROM_UNIXTIME(t.`createTime`/1000,'%m') AS 'showDate'
            </if>
            <if test="dateType == 3">
                 FROM_UNIXTIME(t.`createTime`/1000,'%Y') AS 'showDate'
            </if>
        FROM `yeshi_ec_lost_order` t
        WHERE t.`createTime`IS NOT NULL  
            <if test="startTime != null and startTime != '' ">
                 AND FROM_UNIXTIME(t.`createTime`/1000,'%Y-%m-%d')<![CDATA[ >= ]]>'${startTime}'
            </if>
            <if test="endTime != null and endTime != '' ">
                 AND FROM_UNIXTIME(t.`createTime`/1000,'%Y-%m-%d') <![CDATA[ <= ]]> '${endTime}'
            </if>
            <if test="year != null and year != '' ">
                 AND FROM_UNIXTIME(t.`createTime`/1000,'%Y') = '${year}'
            </if>
            
            <if test="resultCode != null and resultCode != 0 ">
                 AND t.`result_code` = ${resultCode}
            </if>
                
        <if test="dateType == 1">
            GROUP BY FROM_UNIXTIME(t.`createTime`/1000,'%Y-%m-%d') 
        </if>
        <if test="dateType == 2">
             GROUP BY FROM_UNIXTIME(t.`createTime`/1000,'%Y-%m') 
        </if>
        <if test="dateType == 3">
             GROUP BY FROM_UNIXTIME(t.`createTime`/1000,'%Y') 
        </if>        
        
        ORDER BY t.`createTime`
    </select>
    
    
    <select id="countAppealMoney" resultType="java.util.HashMap">
        SELECT CAST(SUM(v.`hb_money`)AS DECIMAL(19,2)) AS showValue,
            <if test="dateType == 1">
                 FROM_UNIXTIME(t.`createTime`/1000,'%Y-%m-%d') AS 'showDate'
            </if>
            <if test="dateType == 2">
                 FROM_UNIXTIME(t.`createTime`/1000,'%m') AS 'showDate'
            </if>
            <if test="dateType == 3">
                 FROM_UNIXTIME(t.`createTime`/1000,'%Y') AS 'showDate'
            </if>
        FROM `yeshi_ec_lost_order` t
        LEFT JOIN  `yeshi_ec_common_order` tc ON tc.`co_order_no` = t.`orderId`
        LEFT JOIN  `yeshi_ec_hongbao_order` h ON h.`ho_order_id` = tc.`co_id`
        LEFT JOIN `yeshi_ec_hongbao_v2`v ON h.`ho_hongbao_id` = v.`hb_id`
        WHERE t.`createTime`IS NOT NULL  AND t.`result_code` = 2 AND (v.`hb_type` =1 OR v.`hb_type` = 2)
            <if test="startTime != null and startTime != '' ">
                 AND FROM_UNIXTIME(t.`createTime`/1000,'%Y-%m-%d')<![CDATA[ >= ]]>'${startTime}'
            </if>
            <if test="endTime != null and endTime != '' ">
                 AND FROM_UNIXTIME(t.`createTime`/1000,'%Y-%m-%d') <![CDATA[ <= ]]> '${endTime}'
            </if>
            <if test="year != null and year != '' ">
                 AND FROM_UNIXTIME(t.`createTime`/1000,'%Y') = '${year}'
            </if>
            
        <if test="dateType == 1">
            GROUP BY FROM_UNIXTIME(t.`createTime`/1000,'%Y-%m-%d') 
        </if>
        <if test="dateType == 2">
             GROUP BY FROM_UNIXTIME(t.`createTime`/1000,'%Y-%m') 
        </if>
        <if test="dateType == 3">
             GROUP BY FROM_UNIXTIME(t.`createTime`/1000,'%Y') 
        </if>        
        
        ORDER BY t.`createTime`
    </select>
    
      
</mapper>