gongchunyi
5 天以前 235721b4a24fd6cc5037bba78c60723dcf200741
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
<?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.account.mapper.AccountIncomeMapper">
 
    <select id="accountIncomeListPage" resultType="com.ruoyi.account.pojo.AccountIncome">
        SELECT
        ai.id,
        ai.business_id,
        ai.business_type,
        ai.income_date,
        ai.income_type,
        ai.customer_name,
        ai.income_money,
        ai.income_described,
        ai.income_method,
        ai.invoice_number,
        ai.note,
        CASE
            WHEN TRIM(IFNULL(ai.input_user, '')) REGEXP '^[0-9]+$'
                THEN COALESCE(ui.nick_name, ai.input_user)
            ELSE ai.input_user
        END AS input_user,
        ai.input_time,
        ai.create_time,
        ai.create_user,
        ai.update_time,
        ai.update_user,
        ai.tenant_id
        FROM account_income ai
        LEFT JOIN sys_user ui ON TRIM(IFNULL(ai.input_user, '')) REGEXP '^[0-9]+$'
            AND ui.user_id = CAST(TRIM(ai.input_user) AS UNSIGNED)
            AND ui.del_flag = '0'
        where
        1=1
        <if test="accountIncome.entryDateStart != null and accountIncome.entryDateStart != '' ">
            AND ai.income_date &gt;= DATE_FORMAT(#{accountIncome.entryDateStart},'%Y-%m-%d')
        </if>
        <if test="accountIncome.entryDateEnd != null and accountIncome.entryDateEnd != '' ">
            AND ai.income_date &lt;= DATE_FORMAT(#{accountIncome.entryDateEnd},'%Y-%m-%d')
        </if>
        <if test="accountIncome.incomeType != null and accountIncome.incomeType != '' ">
            AND ai.income_type = #{accountIncome.incomeType}
        </if>
        <if test="accountIncome.incomeMethodLabel != null and accountIncome.incomeMethodLabel != ''">
            AND (
            (
            ai.business_type = 1
            AND ai.income_method in
            <foreach collection="accountIncome.receiptPaymentMethodList" item="method" open="(" separator="," close=")">
                #{method}
            </foreach>
            )
            OR
            (
            ai.business_type is null
            AND ai.income_method in
            <foreach collection="accountIncome.paymentMethodList" item="method" open="(" separator="," close=")">
                #{method}
            </foreach>
            )
            )
        </if>
        <if test="(accountIncome.incomeMethodLabel == null or accountIncome.incomeMethodLabel == '') and accountIncome.incomeMethod != null and accountIncome.incomeMethod != '' ">
            AND ai.income_method = #{accountIncome.incomeMethod}
        </if>
    </select>
    <select id="accountIncomeExport" resultType="com.ruoyi.account.pojo.AccountIncome">
        SELECT
        ai.id,
        ai.business_id,
        ai.business_type,
        ai.income_date,
        ai.income_type,
        ai.customer_name,
        ai.income_money,
        ai.income_described,
        ai.income_method,
        ai.invoice_number,
        ai.note,
        CASE
            WHEN TRIM(IFNULL(ai.input_user, '')) REGEXP '^[0-9]+$'
                THEN COALESCE(ui.nick_name, ai.input_user)
            ELSE ai.input_user
        END AS input_user,
        ai.input_time,
        ai.create_time,
        ai.create_user,
        ai.update_time,
        ai.update_user,
        ai.tenant_id
        FROM account_income ai
        LEFT JOIN sys_user ui ON TRIM(IFNULL(ai.input_user, '')) REGEXP '^[0-9]+$'
            AND ui.user_id = CAST(TRIM(ai.input_user) AS UNSIGNED)
            AND ui.del_flag = '0'
        where
        1=1
        <if test="accountIncome.entryDateStart != null and accountIncome.entryDateStart != '' ">
            AND ai.income_date &gt;= DATE_FORMAT(#{accountIncome.entryDateStart},'%Y-%m-%d')
        </if>
        <if test="accountIncome.entryDateEnd != null and accountIncome.entryDateEnd != '' ">
            AND ai.income_date &lt;= DATE_FORMAT(#{accountIncome.entryDateEnd},'%Y-%m-%d')
        </if>
        <if test="accountIncome.incomeType != null and accountIncome.incomeType != '' ">
            AND ai.income_type = #{accountIncome.incomeType}
        </if>
        <if test="accountIncome.incomeMethod != null and accountIncome.incomeMethod != '' ">
            AND ai.income_method = #{accountIncome.incomeMethod}
        </if>
    </select>
    <select id="report" resultType="com.ruoyi.account.dto.AccountDto2">
        SELECT
        sdd.dict_label typeName,
        ifnull(sum(income_money),0) account
        FROM account_income ai
        left join sys_dict_data sdd on ai.income_type = sdd.dict_value and  sdd.dict_type='income_types'
        where
        1=1
        <if test="dateQueryDto.entryDateStart != null and dateQueryDto.entryDateStart != '' ">
            AND income_date &gt;= DATE_FORMAT(#{dateQueryDto.entryDateStart},'%Y-%m-%d')
        </if>
        <if test="dateQueryDto.entryDateEnd != null and dateQueryDto.entryDateEnd != '' ">
            AND income_date &lt;= DATE_FORMAT(#{dateQueryDto.entryDateEnd},'%Y-%m-%d')
        </if>
        group by income_type
    </select>
    <select id="report1" resultType="java.math.BigDecimal">
        SELECT
        ifnull(sum(income_money),0) account
        FROM account_income ai
        where
        income_type=#{dictValue}
        <if test="dateQueryDto.entryDateStart != null and dateQueryDto.entryDateStart != '' ">
            AND income_date &gt;= DATE_FORMAT(#{dateQueryDto.entryDateStart},'%Y-%m-%d')
        </if>
        <if test="dateQueryDto.entryDateEnd != null and dateQueryDto.entryDateEnd != '' ">
            AND income_date &lt;= DATE_FORMAT(#{dateQueryDto.entryDateEnd},'%Y-%m-%d')
        </if>
    </select>
 
    <select id="selectIncomeStats"
            resultType="com.ruoyi.home.dto.IncomeExpenseAnalysisDto">
        SELECT DATE_FORMAT(income_date, #{dateFormat}) AS dateStr,
               IFNULL(SUM(income_money), 0)            AS amount
        FROM account_income
        WHERE income_date BETWEEN #{startDate} AND #{endDate}
#           AND business_type = 1
        GROUP BY dateStr
        ORDER BY dateStr
 
    </select>
 
    <update id="syncReceiptIncomeDatesFromReceiptPayment">
        UPDATE account_income ai
            INNER JOIN receipt_payment rp ON ai.business_id = rp.id AND ai.business_type = 1
        SET ai.income_date  = DATE(rp.receipt_payment_date),
            ai.input_time   = DATE(rp.receipt_payment_date),
            ai.create_time  = DATE(rp.receipt_payment_date),
            ai.update_time  = DATE(rp.receipt_payment_date)
        WHERE rp.receipt_payment_date IS NOT NULL
          AND ai.income_type = '3'
          AND ai.business_type = 1
    </update>
 
</mapper>