<?xml version="1.0" encoding="UTF-8"?>

<!--
  ~
  ~      Copyright (c) 2018-2025, lengleng All rights reserved.
  ~
  ~  Redistribution and use in source and binary forms, with or without
  ~  modification, are permitted provided that the following conditions are met:
  ~
  ~ Redistributions of source code must retain the above copyright notice,
  ~  this list of conditions and the following disclaimer.
  ~  Redistributions in binary form must reproduce the above copyright
  ~  notice, this list of conditions and the following disclaimer in the
  ~  documentation and/or other materials provided with the distribution.
  ~  Neither the name of the yifu4cloud.com developer nor the names of its
  ~  contributors may be used to endorse or promote products derived from
  ~  this software without specific prior written permission.
  ~  Author: lengleng (wangiegie@gmail.com)
  ~
  -->

<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">

<mapper namespace="com.yifu.cloud.plus.v1.yifu.salary.mapper.TSalaryAttaMapper">

  <resultMap id="tAttaMap" type="com.yifu.cloud.plus.v1.yifu.salary.entity.TSalaryAtta">
    <id property="id" column="ID"/>
    <result property="attaName" column="ATTA_NAME"/>
    <result property="attaSrc" column="ATTA_SRC"/>
    <result property="attaUrl" column="ATTA_URL"/>
    <result property="attaSize" column="ATTA_SIZE"/>
    <result property="attaType" column="ATTA_TYPE"/>
    <result property="linkId" column="LINK_ID"/>
    <result property="linkType" column="LINK_TYPE"/>
    <result property="engineerType" column="ENGINEER_TYPE"/>
    <result property="printRemark" column="print_remark"/>
    <result property="recordId" column="record_id"/>
    <result property="recordStatus" column="record_status"/>
	  <result property="createBy" column="CREATE_BY"/>
	  <result property="createName" column="CREATE_NAME"/>
	  <result property="createTime" column="CREATE_TIME"/>
	  <result property="updateBy" column="UPDATE_BY"/>
	  <result property="updateTime" column="UPDATE_TIME"/>
  </resultMap>
    <sql id="selectParams">
                a.ID,
                a.ATTA_NAME,
                a.ATTA_SRC,
                a.ATTA_URL,
                a.ATTA_SIZE,
                a.ATTA_TYPE,
                a.LINK_ID,
                a.LINK_TYPE,
                a.ENGINEER_TYPE,
                a.print_remark,
                a.record_id,
                a.record_status,
				a.CREATE_BY,
				a.CREATE_NAME,
				a.CREATE_TIME,
				a.UPDATE_BY,
				a.UPDATE_TIME
    </sql>
	<!-- 基础查询 -->
	<sql id="tSalaryAtta_where">
		<if test="tAtta != null">
			<if test="tAtta.id != null and tAtta.id.trim() != ''">
				AND ID = #{tAtta.id}
			</if>
			<if test="tAtta.attaName != null and tAtta.attaName.trim() != ''">
				AND ATTA_NAME = #{tAtta.attaName}
			</if>
			<if test="tAtta.attaSrc != null and tAtta.attaSrc.trim() != ''">
				AND ATTA_SRC = #{tAtta.attaSrc}
			</if>
			<if test="tAtta.attaUrl != null and tAtta.attaUrl.trim() != ''">
				AND ATTA_URL = #{tAtta.attaUrl}
			</if>
			<if test="tAtta.attaSize != null and tAtta.attaSize.trim() != ''">
				AND ATTA_SIZE = #{tAtta.attaSize}
			</if>
			<if test="tAtta.attaType != null and tAtta.attaType.trim() != ''">
				AND ATTA_TYPE = #{tAtta.attaType}
			</if>
			<if test="tAtta.linkId != null and tAtta.linkId.trim() != ''">
				AND LINK_ID = #{tAtta.linkId}
			</if>
			<if test="tAtta.linkType != null">
				<if test="tAtta.linkType != 230 and tAtta.linkType != 236">
					AND LINK_TYPE = #{tAtta.linkType}
				</if>
				/* 普通工资以及暂停发以及自定义暂停发流转 */
				<if test="tAtta.linkType == 230">
					AND LINK_TYPE in (2,3,0,8)
				</if>
				/* 非扣税以及自定义暂停发流转 */
				<if test="tAtta.linkType == 236">
					AND LINK_TYPE in (2,3,6)
				</if>
			</if>
			<if test="tAtta.engineerType != null">
				AND ENGINEER_TYPE = #{tAtta.engineerType}
			</if>
			<if test="tAtta.recordId != null and tAtta.recordId.trim() != ''">
				AND record_id = #{tAtta.recordId}
			</if>
			<if test="tAtta.recordStatus != null">
				AND record_status = #{tAtta.recordStatus}
			</if>
		</if>
	</sql>
	<!--tAtta简单分页查询-->
	<select id="getTAttaPage" resultMap="tAttaMap">
		SELECT
		<include refid="selectParams"/>
		FROM t_salary_atta a
		<where>
			1=1
			<include refid="tSalaryAtta_where"/>
		</where>
		order by CREATE_TIME
	</select>

	<!--tAtta简单分页查询-->
	<select id="getTAttaList" resultMap="tAttaMap">
		SELECT
		<include refid="selectParams"/>
		FROM t_salary_atta a
		<where>
			1=1
			<include refid="tSalaryAtta_where"/>
		</where>
		order by CREATE_TIME desc
	</select>

	<update id="updateLinkId">
		update t_salary_atta
		<trim prefix="set" suffixOverrides=",">
			LINK_ID=#{domainId}
		</trim>
		WHERE
		<if test="ids != null and ids.size() > 0">
			id in
			<foreach collection="ids" item="param" index="index" open="(" close=")" separator=",">
				#{param}
			</foreach>
		</if>
	</update>
</mapper>
