weaver-hrm-salary/src/com/engine/salary/mapper/datacollection/OtherDeductionMapper.xml

683 lines
24 KiB
XML
Raw Normal View History

2022-03-10 17:57:46 +08:00
<?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.engine.salary.mapper.datacollection.OtherDeductionMapper">
<resultMap id="BaseResultMap" type="com.engine.salary.entity.datacollection.po.OtherDeductionPO">
<result column="id" property="id"/>
<result column="employee_id" property="employeeId"/>
<result column="tax_agent_id" property="taxAgentId"/>
<result column="declare_month" property="declareMonth"/>
<result column="business_healthy_insurance" property="businessHealthyInsurance"/>
<result column="tax_delay_endowment_insurance" property="taxDelayEndowmentInsurance"/>
<result column="other_deduction" property="otherDeduction"/>
<result column="deduction_allowed_donation" property="deductionAllowedDonation"/>
<result column="create_time" property="createTime"/>
<result column="update_time" property="updateTime"/>
<result column="creator" property="creator"/>
<result column="delete_type" property="deleteType"/>
<result column="tenant_key" property="tenantKey"/>
</resultMap>
<!-- 表字段 -->
<sql id="baseColumns">
t
.
id
, t.employee_id
, t.tax_agent_id
, t.declare_month
, t.business_healthy_insurance
, t.tax_delay_endowment_insurance
, t.other_deduction
, t.deduction_allowed_donation
, t.create_time
, t.update_time
, t.creator
, t.delete_type
, t.tenant_key
</sql>
<!-- 查询全部 -->
<select id="listAll" resultMap="BaseResultMap">
SELECT
<include refid="baseColumns"/>
FROM hrsa_other_deduction t
WHERE delete_type = 0
</select>
<!-- 根据主键获取单条记录 -->
<select id="getById" resultMap="BaseResultMap" parameterType="Long">
SELECT
<include refid="baseColumns"/>
FROM hrsa_other_deduction t
WHERE id = #{id} AND delete_type = 0
</select>
<!-- 插入不为NULL的字段 -->
<insert id="insertIgnoreNull" parameterType="com.engine.salary.entity.datacollection.po.OtherDeductionPO"
keyProperty="id" keyColumn="id" useGeneratedKeys="true"
>
INSERT INTO hrsa_other_deduction
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="id != null">
id,
</if>
<if test="employeeId != null">
employee_id,
</if>
<if test="taxAgentId != null">
tax_agent_id,
</if>
<if test="declareMonth != null">
declare_month,
</if>
<if test="businessHealthyInsurance != null">
2022-05-27 15:01:44 +08:00
business_healthy_insurance,
</if>
<if test="taxDelayEndowmentInsurance != null">
tax_delay_endowment_insurance,
</if>
<if test="otherDeduction != null">
other_deduction,
</if>
<if test="deductionAllowedDonation != null">
deduction_allowed_donation,
</if>
<if test="createTime != null">
create_time,
</if>
<if test="updateTime != null">
update_time,
</if>
<if test="creator != null">
creator,
</if>
<if test="deleteType != null">
delete_type,
</if>
<if test="tenantKey != null">
tenant_key,
</if>
</trim>
<trim prefix="VALUES (" suffix=")" suffixOverrides=",">
<if test="id != null">
#{id},
</if>
<if test="employeeId != null">
#{employeeId},
</if>
<if test="taxAgentId != null">
#{taxAgentId},
</if>
<if test="declareMonth != null">
#{declareMonth},
</if>
<if test="businessHealthyInsurance != null">
#{businessHealthyInsurance},
</if>
<if test="taxDelayEndowmentInsurance != null">
#{taxDelayEndowmentInsurance},
</if>
<if test="otherDeduction != null">
#{otherDeduction},
</if>
<if test="deductionAllowedDonation != null">
#{deductionAllowedDonation},
</if>
<if test="createTime != null">
#{createTime},
</if>
<if test="updateTime != null">
#{updateTime},
</if>
<if test="creator != null">
#{creator},
</if>
<if test="deleteType != null">
#{deleteType},
</if>
<if test="tenantKey != null">
#{tenantKey},
</if>
</trim>
</insert>
<insert id="insertIgnoreNull" parameterType="com.engine.salary.entity.datacollection.po.OtherDeductionPO" databaseId="oracle"
>
2022-05-30 09:14:12 +08:00
<selectKey keyProperty="id" resultType="long" order="BEFORE">
2022-05-27 15:01:44 +08:00
select hrsa_other_deduction_id.nextval from dual
</selectKey>
INSERT INTO hrsa_other_deduction
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="id != null">
id,
</if>
<if test="employeeId != null">
employee_id,
</if>
<if test="taxAgentId != null">
tax_agent_id,
</if>
<if test="declareMonth != null">
declare_month,
</if>
<if test="businessHealthyInsurance != null">
2022-03-10 17:57:46 +08:00
business_healthy_insurance,
</if>
<if test="taxDelayEndowmentInsurance != null">
tax_delay_endowment_insurance,
</if>
<if test="otherDeduction != null">
other_deduction,
</if>
<if test="deductionAllowedDonation != null">
deduction_allowed_donation,
</if>
<if test="createTime != null">
create_time,
</if>
<if test="updateTime != null">
update_time,
</if>
<if test="creator != null">
creator,
</if>
<if test="deleteType != null">
delete_type,
</if>
<if test="tenantKey != null">
tenant_key,
</if>
</trim>
<trim prefix="VALUES (" suffix=")" suffixOverrides=",">
<if test="id != null">
#{id},
</if>
<if test="employeeId != null">
#{employeeId},
</if>
<if test="taxAgentId != null">
#{taxAgentId},
</if>
<if test="declareMonth != null">
#{declareMonth},
</if>
<if test="businessHealthyInsurance != null">
#{businessHealthyInsurance},
</if>
<if test="taxDelayEndowmentInsurance != null">
#{taxDelayEndowmentInsurance},
</if>
<if test="otherDeduction != null">
#{otherDeduction},
</if>
<if test="deductionAllowedDonation != null">
#{deductionAllowedDonation},
</if>
<if test="createTime != null">
#{createTime},
</if>
<if test="updateTime != null">
#{updateTime},
</if>
<if test="creator != null">
#{creator},
</if>
<if test="deleteType != null">
#{deleteType},
</if>
<if test="tenantKey != null">
#{tenantKey},
</if>
</trim>
</insert>
<!-- 更新,更新全部字段 -->
<update id="update" parameterType="com.engine.salary.entity.datacollection.po.OtherDeductionPO">
UPDATE hrsa_other_deduction
<set>
employee_id=#{employeeId},
tax_agent_id=#{taxAgentId},
declare_month=#{declareMonth},
business_healthy_insurance=#{businessHealthyInsurance},
tax_delay_endowment_insurance=#{taxDelayEndowmentInsurance},
other_deduction=#{otherDeduction},
deduction_allowed_donation=#{deductionAllowedDonation},
create_time=#{createTime},
update_time=#{updateTime},
creator=#{creator},
delete_type=#{deleteType},
tenant_key=#{tenantKey},
</set>
WHERE id = #{id} AND delete_type = 0
</update>
<!-- 更新不为NULL的字段 -->
<update id="updateIgnoreNull" parameterType="com.engine.salary.entity.datacollection.po.OtherDeductionPO">
UPDATE hrsa_other_deduction
<set>
<if test="employeeId != null">
employee_id=#{employeeId},
</if>
<if test="taxAgentId != null">
tax_agent_id=#{taxAgentId},
</if>
<if test="declareMonth != null">
declare_month=#{declareMonth},
</if>
<if test="businessHealthyInsurance != null">
business_healthy_insurance=#{businessHealthyInsurance},
</if>
<if test="taxDelayEndowmentInsurance != null">
tax_delay_endowment_insurance=#{taxDelayEndowmentInsurance},
</if>
<if test="otherDeduction != null">
other_deduction=#{otherDeduction},
</if>
<if test="deductionAllowedDonation != null">
deduction_allowed_donation=#{deductionAllowedDonation},
</if>
<if test="createTime != null">
create_time=#{createTime},
</if>
<if test="updateTime != null">
update_time=#{updateTime},
</if>
<if test="creator != null">
creator=#{creator},
</if>
<if test="deleteType != null">
delete_type=#{deleteType},
</if>
<if test="tenantKey != null">
tenant_key=#{tenantKey},
</if>
</set>
WHERE id = #{id} AND delete_type = 0
</update>
<!-- 根据主键删除记录 -->
<delete id="delete" parameterType="com.engine.salary.entity.datacollection.po.OtherDeductionPO">
UPDATE hrsa_other_deduction
SET delete_type=1
WHERE id = #{id}
AND delete_type = 0
</delete>
<sql id="otherDeductionColumn">
t1
.
id
,
t1.declare_month,
t1.employee_id,
t2.name AS tax_agent_name,
e.lastname as username,
d.departmentname AS departmentName,
e.mobile,
e.workcode as job_num,
e.companystartdate as hiredate,
t1.business_healthy_insurance,
t1.tax_delay_endowment_insurance,
t1.other_deduction,
t1.deduction_allowed_donation
</sql>
<sql id="paramSql">
<if test="param.ids != null and param.ids.size()>0">
AND t1.id IN
<foreach collection="param.ids" open="(" item="id" separator="," close=")">
#{id}
</foreach>
</if>
<if test="param.employeeId != null">
AND t1.employee_id = #{param.employeeId}
</if>
<!-- 关键字(姓名、部门、工号 -->
<if test="param.keyword != null and param.keyword != ''">
AND
(
e.lastname like CONCAT('%',#{param.keyword},'%')
OR d.departmentname like CONCAT('%',#{param.keyword},'%')
OR e.workcode like CONCAT('%',#{param.keyword},'%')
)
</if>
<!-- 申报月份 -->
<if test="param.declareMonth != null">
<if test="param.declareMonth.size() == 1">
AND t1.declare_month = #{param.declareMonth[0]}
</if>
<if test="param.declareMonth.size() == 2">
AND (t1.declare_month BETWEEN #{param.declareMonth[0]} AND #{param.declareMonth[1]})
</if>
</if>
<!-- 姓名 -->
<if test="param.username != null and param.username != ''">
AND e.lastname like CONCAT('%',#{param.username},'%')
</if>
<!-- 个税扣缴义务人 -->
<if test="param.taxAgentId != null">
AND t1.tax_agent_id = #{param.taxAgentId}
</if>
<!-- 部门 -->
<if test="param.departmentIds != null and param.departmentIds.size()>0">
AND d.id IN
<foreach collection="param.departmentIds" open="(" item="id" separator="," close=")">
#{id}
</foreach>
</if>
<!-- 工号 -->
<if test="param.jobNum != null and param.jobNum != ''">
AND e.workcode like CONCAT('%',#{param.jobNum},'%')
</if>
<!-- 入职日期 -->
<if test="param.hiredate != null and param.hiredate.size() == 2">
AND (e.companystartdate BETWEEN #{param.hiredate[0]} AND #{param.hiredate[1]})
</if>
<!-- 手机号 -->
<if test="param.mobile != null and param.mobile != ''">
AND e.mobile like CONCAT('%',#{param.mobile},'%')
</if>
</sql>
<sql id="paramSql" databaseId="oracle">
<if test="param.ids != null and param.ids.size()>0">
AND t1.id IN
<foreach collection="param.ids" open="(" item="id" separator="," close=")">
#{id}
</foreach>
</if>
<if test="param.employeeId != null">
AND t1.employee_id = #{param.employeeId}
</if>
<if test="param.keyword != null and param.keyword != ''">
AND
(
e.lastname like '%'||#{param.keyword}||'%'
OR d.departmentname like '%'||#{param.keyword}||'%'
OR e.workcode like '%'||#{param.keyword}||'%'
)
</if>
<if test="param.declareMonth != null">
<if test="param.declareMonth.size() == 1">
AND t1.declare_month = #{param.declareMonth[0]}
</if>
<if test="param.declareMonth.size() == 2">
AND (t1.declare_month BETWEEN #{param.declareMonth[0]} AND #{param.declareMonth[1]})
</if>
</if>
<if test="param.username != null and param.username != ''">
AND e.lastname like '%'||#{param.username}||'%'
</if>
<if test="param.taxAgentId != null">
AND t1.tax_agent_id = #{param.taxAgentId}
</if>
<if test="param.departmentIds != null and param.departmentIds.size()>0">
AND d.id IN
<foreach collection="param.departmentIds" open="(" item="id" separator="," close=")">
#{id}
</foreach>
</if>
<if test="param.jobNum != null and param.jobNum != ''">
AND e.workcode like '%'||#{param.jobNum}||'%'
</if>
<if test="param.hiredate != null and param.hiredate.size() == 2">
AND (e.companystartdate BETWEEN #{param.hiredate[0]} AND #{param.hiredate[1]})
</if>
<if test="param.mobile != null and param.mobile != ''">
AND e.mobile like '%'||#{param.mobile}||'%'
</if>
</sql>
<sql id="paramSql" databaseId="sqlserver">
<if test="param.ids != null and param.ids.size()>0">
AND t1.id IN
<foreach collection="param.ids" open="(" item="id" separator="," close=")">
#{id}
</foreach>
</if>
<if test="param.employeeId != null">
AND t1.employee_id = #{param.employeeId}
</if>
<if test="param.keyword != null and param.keyword != ''">
AND
(
e.lastname like '%'+#{param.keyword}+'%'
OR d.departmentname like '%'+#{param.keyword}+'%'
OR e.workcode like '%'+#{param.keyword}+'%'
)
</if>
<if test="param.declareMonth != null">
<if test="param.declareMonth.size() == 1">
AND t1.declare_month = #{param.declareMonth[0]}
</if>
<if test="param.declareMonth.size() == 2">
AND (t1.declare_month BETWEEN #{param.declareMonth[0]} AND #{param.declareMonth[1]})
</if>
</if>
<if test="param.username != null and param.username != ''">
AND e.lastname like '%'+#{param.username}+'%'
</if>
<if test="param.taxAgentId != null">
AND t1.tax_agent_id = #{param.taxAgentId}
</if>
<if test="param.departmentIds != null and param.departmentIds.size()>0">
AND d.id IN
<foreach collection="param.departmentIds" open="(" item="id" separator="," close=")">
#{id}
</foreach>
</if>
<if test="param.jobNum != null and param.jobNum != ''">
AND e.workcode like '%'+#{param.jobNum}+'%'
</if>
<if test="param.hiredate != null and param.hiredate.size() == 2">
AND (e.companystartdate BETWEEN #{param.hiredate[0]} AND #{param.hiredate[1]})
</if>
<if test="param.mobile != null and param.mobile != ''">
AND e.mobile like '%'+#{param.mobile}+'%'
</if>
</sql>
<select id="list" resultType="com.engine.salary.entity.datacollection.dto.OtherDeductionListDTO">
SELECT
<include refid="otherDeductionColumn"/>
FROM
hrsa_other_deduction t1
LEFT JOIN hrsa_tax_agent t2 ON t1.tax_agent_id = t2.id
LEFT JOIN hrmresource e ON e.id = t1.employee_id
LEFT JOIN hrmdepartment d ON d.id = e.departmentid
WHERE
t1.delete_type = 0 AND t2.delete_type = 0
<include refid="paramSql"/>
ORDER BY t1.id DESC
</select>
<select id="recordList" resultType="com.engine.salary.entity.datacollection.dto.OtherDeductionRecordDTO">
SELECT
<include refid="otherDeductionColumn"/>
FROM
hrsa_other_deduction t1
LEFT JOIN hrsa_tax_agent t2 ON t1.tax_agent_id = t2.id
LEFT JOIN hrmresource e ON e.id = t1.employee_id
LEFT JOIN hrmdepartment d ON d.id = e.departmentid
WHERE
t1.delete_type = 0 AND t2.delete_type = 0
<include refid="paramSql"/>
ORDER BY t1.declare_month DESC
</select>
<select id="listSome" resultMap="BaseResultMap">
SELECT
<include refid="baseColumns"/>
FROM hrsa_other_deduction t
WHERE delete_type = 0
<if test="param.declareMonth != null">
and declare_month = #{param.declareMonth}
</if>
<if test="param.employeeIds != null and param.employeeIds.size()>0">
2022-04-12 19:25:19 +08:00
AND t.employee_id IN
2022-03-10 17:57:46 +08:00
<foreach collection="param.employeeIds" open="(" item="employeeId" separator="," close=")">
#{employeeId}
</foreach>
</if>
2022-04-21 14:15:56 +08:00
<if test="param.taxAgentIds != null and param.taxAgentIds.size()>0">
AND t.tax_agent_id IN
<foreach collection="param.taxAgentIds" open="(" item="taxAgentId" separator="," close=")">
#{taxAgentId}
</foreach>
</if>
2022-03-10 17:57:46 +08:00
</select>
<insert id="insertData">
INSERT INTO hrsa_other_deduction(
employee_id,
tax_agent_id,
declare_month,
business_healthy_insurance,
tax_delay_endowment_insurance,
other_deduction,
deduction_allowed_donation,
create_time,
update_time,
creator,
tenant_key
)
VALUES
<foreach collection="collection" item="item" separator=",">
(
#{item.employeeId},
#{item.taxAgentId},
#{item.declareMonth},
#{item.businessHealthyInsurance},
#{item.taxDelayEndowmentInsurance},
#{item.otherDeduction},
#{item.deductionAllowedDonation},
#{item.createTime},
#{item.updateTime},
#{item.creator},
#{item.tenantKey}
)
</foreach>
</insert>
<insert id="insertData" databaseId="oracle">
INSERT INTO hrsa_other_deduction(
employee_id,
tax_agent_id,
declare_month,
business_healthy_insurance,
tax_delay_endowment_insurance,
other_deduction,
deduction_allowed_donation,
create_time,
update_time,
creator,
tenant_key
)
<foreach collection="collection" item="item" separator="union all">
select
#{item.employeeId},
#{item.taxAgentId},
#{item.declareMonth},
#{item.businessHealthyInsurance},
#{item.taxDelayEndowmentInsurance},
#{item.otherDeduction},
#{item.deductionAllowedDonation},
#{item.createTime},
#{item.updateTime},
#{item.creator},
#{item.tenantKey}
from dual
</foreach>
</insert>
<insert id="insertData" databaseId="sqlserver">
2022-04-22 18:00:35 +08:00
<foreach collection="collection" item="item" separator=";">
2022-03-10 17:57:46 +08:00
INSERT INTO hrsa_other_deduction(
employee_id,
tax_agent_id,
declare_month,
business_healthy_insurance,
tax_delay_endowment_insurance,
other_deduction,
deduction_allowed_donation,
create_time,
update_time,
creator,
tenant_key
)
VALUES
(
#{item.employeeId},
#{item.taxAgentId},
#{item.declareMonth},
#{item.businessHealthyInsurance},
#{item.taxDelayEndowmentInsurance},
#{item.otherDeduction},
#{item.deductionAllowedDonation},
#{item.createTime},
#{item.updateTime},
#{item.creator},
#{item.tenantKey}
)
</foreach>
</insert>
<update id="updateData" parameterType="java.util.List">
update hrsa_other_deduction
<trim prefix="set" suffixOverrides=",">
<trim prefix="business_healthy_insurance =case" suffix="end,">
<foreach collection="collection" item="item" index="index">
<if test="item.businessHealthyInsurance!=null">
when id=#{item.id} then #{item.businessHealthyInsurance}
</if>
</foreach>
</trim>
<trim prefix="tax_delay_endowment_insurance =case" suffix="end,">
<foreach collection="collection" item="item" index="index">
<if test="item.taxDelayEndowmentInsurance!=null">
when id=#{item.id} then #{item.taxDelayEndowmentInsurance}
</if>
</foreach>
</trim>
<trim prefix="other_deduction =case" suffix="end,">
<foreach collection="collection" item="item" index="index">
<if test="item.otherDeduction!=null">
when id=#{item.id} then #{item.otherDeduction}
</if>
</foreach>
</trim>
<trim prefix="deduction_allowed_donation =case" suffix="end,">
<foreach collection="collection" item="item" index="index">
<if test="item.deductionAllowedDonation!=null">
when id=#{item.id} then #{item.deductionAllowedDonation}
</if>
</foreach>
</trim>
</trim>
where
id in
<foreach collection="collection" item="item" index="index" separator="," open="(" close=")">
#{item.id}
</foreach>
</update>
</mapper>