mitao
2025-02-21 31573d6180d15ef65ed0df9c2732495f40b12663
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
<?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.panzhihua.service_community.dao.ComActWarehouseDonatesDao">
 
    <resultMap type="com.panzhihua.service_community.entity.ComActWarehouseDonates"
               id="ComActWarehouseDonatesBaseResultMap">
        <result property="id" column="id"/>
        <result property="userId" column="user_id"/>
        <result property="name" column="name"/>
        <result property="phone" column="phone"/>
        <result property="item" column="item"/>
        <result property="image" column="image"/>
        <result property="quantity" column="quantity"/>
        <result property="surplusQuantity" column="surplus_quantity"/>
        <result property="isAnonymous" column="is_anonymous"/>
        <result property="message" column="message"/>
        <result property="registerAt" column="register_at"/>
        <result property="signingAt" column="signing_at"/>
        <result property="status" column="status"/>
        <result property="communityId" column="community_id"/>
        <result property="registerBy" column="register_by"/>
        <result property="signingBy" column="signing_by"/>
    </resultMap>
    <insert id="batchInsertDonates" parameterType="java.util.List" useGeneratedKeys="true" keyProperty="id">
        INSERT INTO `com_act_warehouse_donates`(`name`,phone,item,quantity,surplus_quantity,
        is_anonymous,message,register_at,signing_at,status,community_id,register_by,signing_by)
        VALUES
        <foreach collection="donateList" item="item" index="index" separator="," >
            (#{item.name}, #{item.phone}, #{item.item}, #{item.quantity}, #{item.surplusQuantity},#{item.isAnonymous},
            #{item.message}, #{item.registerAt}, #{item.signingAt}, #{item.status}, #{item.communityId}, #{item.registerBy}, #{item.signingBy})
        </foreach>
    </insert>
    <select id="exportDonatesByIds"
            resultType="com.panzhihua.common.model.vos.community.warehouse.ExportDonatesVO">
        SELECT * FROM com_act_warehouse_donates
        WHERE id IN
            <foreach collection="needExportIds" open="(" separator="," close=")" index="index" item="item">
                #{item}
            </foreach>
    </select>
    <select id="exportDonatesBySearch"
            resultType="com.panzhihua.common.model.vos.community.warehouse.ExportDonatesVO">
        SELECT * FROM com_act_warehouse_donates
        WHERE community_id = ${exportDonatesDTO.communityId}
        <if test="exportDonatesDTO.status != null">
            AND status = #{exportDonatesDTO.status}
        </if>
        <if test="exportDonatesDTO.isAnonymous != null">
            AND is_anonymous = #{exportDonatesDTO.isAnonymous}
        </if>
        <if test="exportDonatesDTO.signingAtBegin != null">
            AND signing_at &gt;= #{exportDonatesDTO.signingAtBegin}
        </if>
        <if test="exportDonatesDTO.signingAtEnd != null">
            AND signing_at &lt;= #{exportDonatesDTO.signingAtEnd}
        </if>
        <if test="exportDonatesDTO.keyword != null and exportDonatesDTO.keyword != &quot;&quot;">
            AND (
                `name` LIKE CONCAT('%', #{exportDonatesDTO.keyword}, '%')
                OR phone LIKE CONCAT('%', #{exportDonatesDTO.keyword}, '%')
                OR item LIKE CONCAT('%', #{exportDonatesDTO.keyword}, '%')
            )
        </if>
        ORDER BY id DESC
    </select>
    <select id="pageDonates"
            resultType="com.panzhihua.common.model.vos.community.warehouse.ComActWarehouseDonatesVO">
        SELECT * FROM com_act_warehouse_donates
        WHERE community_id = ${pageDonatesDTO.communityId}
        <if test="pageDonatesDTO.isWhich != null and pageDonatesDTO.isWhich == 1">
            AND user_id = #{pageDonatesDTO.userId}
        </if>
        <if test="pageDonatesDTO.status != null">
            AND status = #{pageDonatesDTO.status}
        </if>
        <if test="pageDonatesDTO.isAnonymous != null">
            AND is_anonymous = #{pageDonatesDTO.isAnonymous}
        </if>
        <if test="pageDonatesDTO.signingAtBegin != null">
            AND signing_at &gt;= #{pageDonatesDTO.signingAtBegin}
        </if>
        <if test="pageDonatesDTO.signingAtEnd != null">
            AND signing_at &lt;= #{pageDonatesDTO.signingAtEnd}
        </if>
        <if test="pageDonatesDTO.keyword != null and pageDonatesDTO.keyword != &quot;&quot;">
            <if test="pageDonatesDTO.isWhich != null">
                AND status = 2
                AND item LIKE CONCAT('%', #{pageDonatesDTO.keyword}, '%')
            </if>
            <if test="pageDonatesDTO.isWhich == null">
                AND (
                `name` LIKE CONCAT('%', #{pageDonatesDTO.keyword}, '%')
                OR phone LIKE CONCAT('%', #{pageDonatesDTO.keyword}, '%')
                OR item LIKE CONCAT('%', #{pageDonatesDTO.keyword}, '%')
                )
            </if>
        </if>
        ORDER BY id DESC
    </select>
    <select id="selectDetailById"
            resultType="com.panzhihua.common.model.vos.community.warehouse.ComActWarehouseDonatesVO">
        SELECT temp.*,IF(su.name IS NULL, su.nick_name, su.name) AS signingBy FROM (
            SELECT * FROM com_act_warehouse_donates WHERE id = #{donatesId}
        ) temp LEFT JOIN sys_user su ON temp.signing_by = su.user_id
    </select>
    <select id="selectDonatesStatistics"
            resultType="com.panzhihua.common.model.vos.community.warehouse.DonatesStatisticsVO">
        SELECT
            (SELECT IF(SUM(quantity) IS NULL,0,SUM(quantity)) FROM com_act_warehouse_donates WHERE community_id = ${communityId} AND `status` = 2) as totalInc ,
            (SELECT IF(SUM(surplus_quantity) IS NULL,0,SUM(surplus_quantity)) FROM com_act_warehouse_donates WHERE community_id = ${communityId} AND `status` = 2) as surplus,
            (SELECT IF(SUM(quantity) IS NULL,0,SUM(quantity)) FROM com_act_warehouse_donates WHERE community_id = ${communityId} AND `status` = 2 AND signing_at LIKE #{currentYear}) as yearInc,
            (SELECT IF(SUM(quantity) IS NULL,0,SUM(quantity)) FROM com_act_warehouse_donates WHERE community_id = ${communityId} AND `status` = 2 AND signing_at LIKE #{currentMonth}) as mothInc,
            (SELECT IF(SUM(quantity) IS NULL,0,SUM(quantity)) FROM com_act_warehouse_donates WHERE community_id = ${communityId} AND `status` = 2 AND signing_at LIKE #{today}) as dayInc,
            (SELECT IF(SUM(goods_num) IS NULL,0,SUM(goods_num)) FROM com_act_warehouse_apply WHERE community_id = ${communityId} AND `status` = 3 AND actual_time LIKE #{currentYear}) as yearDec,
            (SELECT IF(SUM(goods_num) IS NULL,0,SUM(goods_num)) FROM com_act_warehouse_apply WHERE community_id = ${communityId} AND `status` = 3 AND actual_time LIKE #{currentMonth}) as mothDec,
            (SELECT IF(SUM(goods_num) IS NULL,0,SUM(goods_num)) FROM com_act_warehouse_apply WHERE community_id = ${communityId} AND `status` = 3 AND actual_time LIKE #{today}) as dayDec
    </select>
    <select id="getWarehouseDonateRecords" resultType="java.lang.String">
        SELECT CONCAT('收到爱心人士捐赠的',item,'x', quantity)
        FROM com_act_warehouse_donates WHERE community_id = ${communityId} AND `status` = 2 ORDER BY signing_at DESC limit #{pageSize}
    </select>
    <select id="getWarehouseLoveTransfer" resultType="java.lang.String">
        SELECT t1.content FROM com_act_warehouse_operation t1
        LEFT JOIN com_act_warehouse_donates t2 ON t1.goods_id = t2.id
        WHERE t2.community_id = ${communityId} AND t1.`type` = 2 ORDER BY create_time DESC limit #{pageSize}
    </select>
    <select id="getWarehouseImages" resultType="java.lang.String">
        SELECT image FROM com_act_warehouse_donates
        WHERE community_id = ${communityId} AND `status` = 2 AND image IS NOT NULL AND image != '' ORDER BY signing_at DESC limit #{pageSize}
    </select>
 
</mapper>