<?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.NonCoalCategoryMapper">
|
|
<resultMap type="NonCoalCategory" id="NonCoalCategoryResult">
|
<result property="id" column="id"/>
|
<result property="districtCode" column="district_code"/>
|
<result property="categoryType" column="category_type"/>
|
<result property="subjectName" column="subject_name"/>
|
<result property="operateTypeId" column="operate_type_id"/>
|
<result property="amount" column="amount"/>
|
<result property="businessCode" column="business_code"/>
|
<result property="companyCode" column="company_code"/>
|
<result property="drawer" column="drawer"/>
|
<result property="reviewer" column="reviewer"/>
|
<result property="invoicingCompanyCode" column="invoicing_company_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"/>
|
<result property="operateTypeName" column="operate_type_name"/>
|
<result property="districtName" column="district_name"/>
|
</resultMap>
|
|
<resultMap type="NonCoalCategory" id="NonCoalCategoryResultVO" extends="NonCoalCategoryResult">
|
<result property="operateTypeName" column="operate_type_name"/>
|
|
</resultMap>
|
|
<sql id="selectNonCoalCategoryVo">
|
select id,
|
district_code,
|
category_type,
|
subject_name,
|
operate_type_id,
|
amount,
|
business_code,
|
company_code,
|
drawer,
|
reviewer,
|
invoicing_company_code,
|
`describe`,
|
update_by,
|
update_time,
|
create_by,
|
create_time
|
from non_coal_category
|
</sql>
|
|
<select id="selectNonCoalCategoryList" parameterType="NonCoalCategory" resultMap="NonCoalCategoryResult">
|
select a.id,
|
a.district_code,
|
a.category_type,
|
a.subject_name,
|
a.operate_type_id,
|
a.amount,
|
a.business_code,
|
a.company_code,
|
a.drawer,
|
a.reviewer,
|
a.invoicing_company_code,
|
a.`describe`,
|
a.update_by,
|
a.update_time,
|
a.create_by,
|
a.create_time,
|
(SELECT GROUP_CONCAT(name SEPARATOR '/') FROM sys_operate_type
|
WHERE FIND_IN_SET(id, (SELECT ancestors FROM sys_operate_type WHERE id = a.operate_type_id)) or id =
|
a.operate_type_id ) operate_type_name,
|
b.name district_name
|
from non_coal_category a
|
left join sys_district b on a.district_code = b.code
|
<where>
|
and a.del_flag = 0
|
<if test="districtCode != null and districtCode != ''">and a.district_code = #{districtCode}</if>
|
<if test="categoryType != null ">and a.category_type = #{categoryType}</if>
|
<if test="subjectName != null and subjectName != ''">and a.subject_name like concat('%', #{subjectName},
|
'%')
|
</if>
|
<if test="operateTypeId != null ">and a.operate_type_id = #{operateTypeId}</if>
|
<if test="amount != null ">and a.amount = #{amount}</if>
|
<if test="businessCode != null and businessCode != ''">and a.business_code = #{businessCode}</if>
|
<if test="companyCode != null and companyCode != ''">and a.company_code = #{companyCode}</if>
|
<if test="drawer != null and drawer != ''">and a.drawer = #{drawer}</if>
|
<if test="reviewer != null and reviewer != ''">and a.reviewer = #{reviewer}</if>
|
<if test="invoicingCompanyCode != null and invoicingCompanyCode != ''">and a.invoicing_company_code =
|
#{invoicingCompanyCode}
|
</if>
|
<if test="describe != null and describe != ''">and a.`describe` = #{describe}</if>
|
</where>
|
order by create_time desc
|
</select>
|
|
<select id="selectNonCoalCategoryById" parameterType="Long" resultMap="NonCoalCategoryResult">
|
select a.id,
|
a.district_code,
|
a.category_type,
|
a.subject_name,
|
a.operate_type_id,
|
a.amount,
|
a.business_code,
|
a.company_code,
|
a.drawer,
|
a.reviewer,
|
a.invoicing_company_code,
|
a.`describe`,
|
a.update_by,
|
a.update_time,
|
a.create_by,
|
a.create_time,
|
(SELECT GROUP_CONCAT(name SEPARATOR '/')
|
FROM sys_operate_type
|
WHERE FIND_IN_SET(id, (SELECT ancestors FROM sys_operate_type WHERE id = a.operate_type_id))
|
or id =
|
a.operate_type_id) operate_type_name,
|
b.name district_name
|
from non_coal_category a
|
left join sys_district b on a.district_code = b.code
|
|
where a.id = #{id}
|
</select>
|
|
<insert id="insertNonCoalCategory" parameterType="NonCoalCategory" useGeneratedKeys="true" keyProperty="id">
|
insert into non_coal_category
|
<trim prefix="(" suffix=")" suffixOverrides=",">
|
<if test="districtCode != null and districtCode != ''">district_code,</if>
|
<if test="categoryType != null">category_type,</if>
|
<if test="subjectName != null and subjectName != ''">subject_name,</if>
|
<if test="operateTypeId != null">operate_type_id,</if>
|
<if test="amount != null">amount,</if>
|
<if test="businessCode != null and businessCode != ''">business_code,</if>
|
<if test="companyCode != null and companyCode != ''">company_code,</if>
|
<if test="drawer != null and drawer != ''">drawer,</if>
|
<if test="reviewer != null and reviewer != ''">reviewer,</if>
|
<if test="invoicingCompanyCode != null and invoicingCompanyCode != ''">invoicing_company_code,</if>
|
<if test="describe != null">`describe`,</if>
|
<if test="updateBy != null">update_by,</if>
|
<if test="updateTime != null">update_time,</if>
|
<if test="createBy != null">create_by,</if>
|
<if test="createTime != null">create_time,</if>
|
<if test="delFlag != null">del_flag,</if>
|
</trim>
|
<trim prefix="values (" suffix=")" suffixOverrides=",">
|
<if test="districtCode != null and districtCode != ''">#{districtCode},</if>
|
<if test="categoryType != null">#{categoryType},</if>
|
<if test="subjectName != null and subjectName != ''">#{subjectName},</if>
|
<if test="operateTypeId != null">#{operateTypeId},</if>
|
<if test="amount != null">#{amount},</if>
|
<if test="businessCode != null and businessCode != ''">#{businessCode},</if>
|
<if test="companyCode != null and companyCode != ''">#{companyCode},</if>
|
<if test="drawer != null and drawer != ''">#{drawer},</if>
|
<if test="reviewer != null and reviewer != ''">#{reviewer},</if>
|
<if test="invoicingCompanyCode != null and invoicingCompanyCode != ''">#{invoicingCompanyCode},</if>
|
<if test="describe != null">#{describe},</if>
|
<if test="updateBy != null">#{updateBy},</if>
|
<if test="updateTime != null">#{updateTime},</if>
|
<if test="createBy != null">#{createBy},</if>
|
<if test="createTime != null">#{createTime},</if>
|
<if test="delFlag != null">#{delFlag},</if>
|
</trim>
|
</insert>
|
|
<update id="updateNonCoalCategory" parameterType="NonCoalCategory">
|
update non_coal_category
|
<trim prefix="SET" suffixOverrides=",">
|
<if test="districtCode != null and districtCode != ''">district_code = #{districtCode},</if>
|
<if test="categoryType != null">category_type = #{categoryType},</if>
|
<if test="subjectName != null and subjectName != ''">subject_name = #{subjectName},</if>
|
<if test="operateTypeId != null">operate_type_id = #{operateTypeId},</if>
|
<if test="amount != null">amount = #{amount},</if>
|
<if test="businessCode != null and businessCode != ''">business_code = #{businessCode},</if>
|
<if test="companyCode != null and companyCode != ''">company_code = #{companyCode},</if>
|
<if test="drawer != null and drawer != ''">drawer = #{drawer},</if>
|
<if test="reviewer != null and reviewer != ''">reviewer = #{reviewer},</if>
|
<if test="invoicingCompanyCode != null and invoicingCompanyCode != ''">invoicing_company_code =
|
#{invoicingCompanyCode},
|
</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>
|
|
<select id="checkUnite" parameterType="NonCoalCategory" resultType="int">
|
select count(id)
|
from non_coal_category
|
where del_flag = 0
|
and district_code = #{districtCode}
|
and category_type = #{categoryType}
|
and subject_name = #{subjectName}
|
<if test="id != null ">and id != #{id}</if>
|
</select>
|
<select id="selectCountCategory" resultType="com.gkhy.exam.pay.dto.rep.NonCategoryCount">
|
SELECT
|
cc.id,
|
sot.name as subject_name,
|
cc.amount,
|
cc.category_type,
|
COUNT( cps.`name` ) num
|
FROM
|
non_coal_category cc
|
LEFT JOIN sys_operate_type sot on cc.operate_type_id = sot.id
|
LEFT JOIN non_coal_pay_category cpc ON cc.id = cpc.category_id
|
LEFT JOIN non_coal_pay cp ON cpc.non_coal_pay_id = cp.id
|
LEFT JOIN non_coal_pay_student cps ON cp.id = cps.non_coal_pay_id
|
WHERE cc.category_type = 2 and cc.del_flag = 0 and cps.del_flag =0 and cp.del_flag = 0 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="districtCode!=null and districtCode!='' and districtCode != 65">
|
and cc.district_code =#{districtCode}
|
</if>
|
<if test="deptId!=null">
|
and cp.dept_id =#{deptId}
|
</if>
|
GROUP BY
|
cc.id
|
</select>
|
<select id="selectCountTheory" resultType="com.gkhy.exam.pay.dto.rep.CateGoryTheory">
|
WITH filtered_data AS (
|
SELECT
|
cp.id AS pay_id,
|
cp.pay_type,
|
cpc.category_id AS category_id
|
FROM
|
non_coal_pay cp
|
LEFT JOIN non_coal_pay_category cpc ON cp.id = cpc.non_coal_pay_id
|
LEFT JOIN non_coal_category cc ON cpc.category_id = cc.id
|
WHERE
|
cc.category_type = 1
|
AND cp.del_flag = 0
|
<if test="year !=null and year!=''">
|
and cp.year = #{year}
|
</if>
|
<if test="quarter!=null">
|
and cp.quarter = #{quarter}
|
</if>
|
<if test="districtCode !=null and districtCode !='' and districtCode != 65 ">
|
and cp.district_code = #{districtCode}
|
</if>
|
<if test="deptId!=null">
|
and cp.dept_id =#{deptId}
|
</if>
|
),
|
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 non_coal_pay_student cps ON fd.pay_id = cps.non_coal_pay_id
|
LEFT JOIN non_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
|
FROM
|
pay_type_data
|
GROUP BY
|
pay_type_name
|
</select>
|
|
<update id="deleteNonCoalCategoryById" parameterType="Long">
|
update non_coal_category
|
set del_flag = 2
|
where id = #{id}
|
</update>
|
|
<update id="deleteNonCoalCategoryByIds" parameterType="String">
|
update non_coal_category set del_flag = 2 where id in
|
<foreach item="id" collection="array" open="(" separator="," close=")">
|
#{id}
|
</foreach>
|
</update>
|
</mapper>
|