教育训练处考试制证系统后端
“djh”
2025-03-06 f5e3323be3ce83280c48cd1856bea88c6aed8ffa
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
205
206
207
208
209
210
211
212
213
214
<?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.gkhy.exam.pay.mapper.CoalCategoryMapper">
 
    <resultMap type="CoalCategory" id="CoalCategoryResult">
        <result property="id" column="id"/>
        <result property="categoryType" column="category_type"/>
        <result property="subjectName" column="subject_name"/>
        <result property="amount" column="amount"/>
        <result property="businessCode" column="business_code"/>
        <result property="describe" column="describe"/>
        <result property="updateBy" column="update_by"/>
        <result property="updateTime" column="update_time"/>
        <result property="createBy" column="create_by"/>
        <result property="createTime" column="create_time"/>
    </resultMap>
 
    <sql id="selectCoalCategoryVo">
        select id,
               category_type,
               subject_name,
               amount,
               business_code,
               `describe`, update_by, update_time, create_by, create_time
        from coal_category
    </sql>
    <insert id="insertCoalCategory">
        insert into coal_category
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="categoryType != null">category_type,</if>
            <if test="subjectName != null and subjectName != ''">subject_name,</if>
            <if test="amount != null">amount,</if>
            <if test="businessCode!=null">business_code,</if>
            <if test="describe != null">`describe`,</if>
            <if test="createBy != null">create_by,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateBy != null">update_by,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="delFlag != null">del_flag,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="categoryType != null">#{categoryType},</if>
            <if test="subjectName != null and subjectName != ''">#{subjectName},</if>
            <if test="amount != null">#{amount},</if>
            <if test="businessCode!=null">#{businessCode},</if>
            <if test="describe != null">#{describe},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateBy != null">#{updateBy},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="delFlag != null">#{delFlag},</if>
        </trim>
    </insert>
    <insert id="saveCoalTicket">
        INSERT INTO `swspkmas`.`coal_ticket`
        ( `ticket_company_name`, `ticket_company_code`, `drawer`, `check`, `company_code` )
        VALUES
            ( #{ticketCompanyName}, #{ticketCompanyCode}, #{drawer}, #{check}, #{companyCode} )
    </insert>
 
    <update id="updateBatchByIds">
        update coal_category set del_flag = 2 where id in
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </update>
    <update id="updateCategoryById">
        update coal_category
        <trim prefix="SET" suffixOverrides=",">
            <if test="categoryType != null">category_type = #{categoryType},</if>
            <if test="subjectName != null and subjectName != ''">subject_name = #{subjectName},</if>
            <if test="amount != null">amount = #{amount},</if>
            <if test="businessCode!=null">business_code = #{businessCode},</if>
            <if test="describe != null">`describe` = #{describe},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="createBy != null">create_by = #{createBy},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="delFlag != null">del_flag = #{delFlag},</if>
        </trim>
        where id = #{id}
    </update>
    <update id="updateCoalTicket">
        update coal_ticket
        <trim prefix="SET" suffixOverrides=",">
            <if test="ticketCompanyName != null">ticket_company_name = #{ticketCompanyName},</if>
            <if test="ticketCompanyCode != null and ticketCompanyCode != ''">ticket_company_code = #{ticketCompanyCode},</if>
            <if test="drawer != null">drawer = #{drawer},</if>
            <if test="check!=null">`check` = #{check},</if>
            <if test="companyCode != null">company_code = #{companyCode},</if>
        </trim>
    </update>
 
    <select id="selectCoalCategoryList" parameterType="CoalCategory" resultMap="CoalCategoryResult">
        <include refid="selectCoalCategoryVo"/>
        <where>
            <if test="categoryType != null ">and category_type = #{categoryType}</if>
            <if test="subjectName != null  and subjectName != ''">and subject_name like concat('%', #{subjectName},
                '%')
            </if>
            <if test="amount != null ">and amount = #{amount}</if>
            and del_flag = 0
            order by create_time desc
        </where>
    </select>
 
    <select id="selectByCoalCategory" resultType="java.lang.Integer">
        select count(id)
        from coal_category
        <where>
            del_flag = 0
            and category_type = #{categoryType}
            and subject_name = #{subjectName}
        <if test="id!=null and id!=''">
            and id != #{id}
        </if>
        </where>
 
    </select>
 
    <select id="selectByCoalPayId" resultMap="CoalCategoryResult">
        SELECT
            cc.id,
            cc.category_type,
            cc.subject_name,
            cc.amount,
            cc.business_code,
            cc.`describe`
        FROM
            coal_category cc
            LEFT JOIN coal_pay_category cpc ON cc.id = cpc.coal_category_id
        WHERE
            cpc.coal_pay_id = #{id} and cpc.del_flag = 0
    </select>
    <select id="selectCoalTicket" resultType="com.gkhy.exam.pay.entity.CoalTicket">
            select id , ticket_company_name,ticket_company_code,drawer,`check`,company_code  from coal_ticket
    </select>
    <select id="countCategory" resultType="com.gkhy.exam.pay.dto.rep.CategoryCount">
        SELECT
            cc.id,
            cc.subject_name,
            cc.amount,
            cc.category_type,
            COUNT(cps.`name`) num
        FROM
            coal_category cc
                LEFT JOIN coal_pay_category cpc ON cc.id = cpc.coal_category_id
                LEFT JOIN coal_pay cp ON cpc.coal_pay_id = cp.id
                LEFT JOIN coal_pay_student cps on cp.id = cps.coal_pay_id
        <where>
            cc.del_flag = 0 and cp.del_flag = 0 and cps.del_flag = 0 and cc.category_type = 2 and cps.pay_status =1
            <if test="year !=null and year != ''">
                and cp.year = #{year}
            </if>
            <if test="quarter!=null">
                and cp.quarter = #{quarter}
            </if>
            <if test="deptId !=null">
                and cp.dept_id = #{deptId}
            </if>
        </where>
        GROUP BY cc.id
    </select>
    <select id="countThroey" resultType="com.gkhy.exam.pay.dto.rep.CateGoryTheory">
        WITH filtered_data AS (
        SELECT
        cp.id AS pay_id,
        cp.pay_type,
        cpc.coal_category_id AS category_id
        FROM
        coal_pay cp
        LEFT JOIN coal_pay_category cpc ON cp.id = cpc.coal_pay_id
        LEFT JOIN coal_category cc ON cpc.coal_category_id = cc.id
        WHERE
        cc.category_type = 1
        <if test="year !=null and year != ''">
            and cp.year = #{year}
        </if>
        <if test="quarter!=null">
            and cp.quarter = #{quarter}
        </if>
          <if test="deptId!=null">
              and cp.dept_id =#{deptId}
          </if>
        AND cp.del_flag = 0
        ),
        pay_type_data AS (
        SELECT
        CASE
        WHEN fd.pay_type IN (1, 3) THEN '初训理论'
        ELSE '复训理论'
        END AS pay_type_name,
        cps.id AS student_id,
        cc.amount
        FROM
        filtered_data fd
        LEFT JOIN coal_pay_student cps ON fd.pay_id = cps.coal_pay_id
        LEFT JOIN coal_category cc ON fd.category_id = cc.id
        WHERE
        cps.del_flag = 0 and cps.pay_status = 1
        )
        SELECT
        pay_type_name,
        COUNT(student_id) AS num,
        MAX(amount) AS amount  -- 假设需要汇总 amount
        FROM
        pay_type_data
        GROUP BY
        pay_type_name
    </select>
 
</mapper>