<?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.social.mapper.TIncomeDetailMapper">

	<resultMap id="tIncomeDetailMap" type="com.yifu.cloud.plus.v1.yifu.social.entity.TIncomeDetail">
		<id property="id" column="ID"/>
		<result property="empName" column="EMP_NAME"/>
		<result property="empIdcard" column="EMP_IDCARD"/>
		<result property="unitId" column="UNIT_ID"/>
		<result property="unitName" column="UNIT_NAME"/>
		<result property="unitNo" column="UNIT_NO"/>
		<result property="deptId" column="DEPT_ID"/>
		<result property="deptName" column="DEPT_NAME"/>
		<result property="deptNo" column="DEPT_NO"/>
		<result property="feeType" column="FEE_TYPE"/>
		<result property="feeMode" column="FEE_MODE"/>
		<result property="charges" column="CHARGES"/>
		<result property="sourceType" column="SOURCE_TYPE"/>
		<result property="money" column="MONEY"/>
		<result property="createMonth" column="CREATE_MONTH"/>
		<result property="payMonth" column="PAY_MONTH"/>
		<result property="createTime" column="CREATE_TIME"/>
		<result property="dataCreateMonth" column="DATA_CREATE_MONTH"/>
		<result property="sourceId" column="SOURCE_ID"/>
		<result property="redData" column="RED_DATA"/>
		<result property="mrSettleType" column="MR_SETTLE_TYPE"/>
		<result property="applyNo" column="APPLY_NO"/>
	</resultMap>
	<sql id="Base_Column_List">
		a.ID,
		a.EMP_NAME,
		a.EMP_IDCARD,
		a.UNIT_ID,
		a.UNIT_NAME,
		a.UNIT_NO,
		a.DEPT_ID,
		a.DEPT_NAME,
		a.DEPT_NO,
		a.FEE_TYPE,
		a.FEE_MODE,
		a.CHARGES,
		a.SOURCE_TYPE,
		a.MONEY,
		a.CREATE_MONTH,
		a.PAY_MONTH,
		a.CREATE_TIME,
		a.DATA_CREATE_MONTH,
		a.SOURCE_ID,
		a.RED_DATA,
		a.MR_SETTLE_TYPE,
		a.APPLY_NO
	</sql>
	<sql id="tIncomeDetail_where">
		<if test="tIncomeDetail != null">
			<if test="tIncomeDetail.id != null and tIncomeDetail.id.trim() != ''">
				AND a.ID = #{tIncomeDetail.id}
			</if>
			<if test="tIncomeDetail.empName != null and tIncomeDetail.empName.trim() != ''">
				AND a.EMP_NAME = #{tIncomeDetail.empName}
			</if>
			<if test="tIncomeDetail.empIdcard != null and tIncomeDetail.empIdcard.trim() != ''">
				AND a.EMP_IDCARD = #{tIncomeDetail.empIdcard}
			</if>
			<if test="tIncomeDetail.unitId != null and tIncomeDetail.unitId.trim() != ''">
				AND a.UNIT_ID = #{tIncomeDetail.unitId}
			</if>
			<if test="tIncomeDetail.unitName != null and tIncomeDetail.unitName.trim() != ''">
				AND a.UNIT_NAME = #{tIncomeDetail.unitName}
			</if>
			<if test="tIncomeDetail.unitNo != null and tIncomeDetail.unitNo.trim() != ''">
				AND a.UNIT_NO = #{tIncomeDetail.unitNo}
			</if>
			<if test="tIncomeDetail.deptId != null and tIncomeDetail.deptId.trim() != ''">
				AND a.DEPT_ID = #{tIncomeDetail.deptId}
			</if>
			<if test="tIncomeDetail.deptName != null and tIncomeDetail.deptName.trim() != ''">
				AND a.DEPT_NAME = #{tIncomeDetail.deptName}
			</if>
			<if test="tIncomeDetail.deptNo != null and tIncomeDetail.deptNo.trim() != ''">
				AND a.DEPT_NO = #{tIncomeDetail.deptNo}
			</if>
			<if test="tIncomeDetail.feeType != null and tIncomeDetail.feeType.trim() != ''">
				AND a.FEE_TYPE = #{tIncomeDetail.feeType}
			</if>
			<if test="tIncomeDetail.feeMode != null and tIncomeDetail.feeMode.trim() != ''">
				AND a.FEE_MODE = #{tIncomeDetail.feeMode}
			</if>
			<if test="tIncomeDetail.charges != null and tIncomeDetail.charges.trim() != ''">
				AND a.CHARGES = #{tIncomeDetail.charges}
			</if>
			<if test="tIncomeDetail.sourceType != null and tIncomeDetail.sourceType.trim() != ''">
				AND a.SOURCE_TYPE = #{tIncomeDetail.sourceType}
			</if>
			<if test="tIncomeDetail.money != null">
				AND a.MONEY = #{tIncomeDetail.money}
			</if>
			<if test="tIncomeDetail.createMonth != null and tIncomeDetail.createMonth.trim() != ''">
				AND a.CREATE_MONTH = #{tIncomeDetail.createMonth}
			</if>
			<if test="tIncomeDetail.payMonth != null and tIncomeDetail.payMonth.trim() != ''">
				AND a.PAY_MONTH = #{tIncomeDetail.payMonth}
			</if>
			<if test="tIncomeDetail.createTime != null">
				AND a.CREATE_TIME = #{tIncomeDetail.createTime}
			</if>
			<if test="tIncomeDetail.dataCreateMonth != null and tIncomeDetail.dataCreateMonth.trim() != ''">
				AND a.DATA_CREATE_MONTH = #{tIncomeDetail.dataCreateMonth}
			</if>
			<if test="tIncomeDetail.sourceId != null and tIncomeDetail.sourceId.trim() != ''">
				AND a.SOURCE_ID = #{tIncomeDetail.sourceId}
			</if>
			<if test="tIncomeDetail.redData != null and tIncomeDetail.redData.trim() != ''">
				AND a.RED_DATA = #{tIncomeDetail.redData}
			</if>
			<if test="tIncomeDetail.applyNo != null and tIncomeDetail.applyNo.trim() != ''">
				AND a.APPLY_NO = #{tIncomeDetail.applyNo}
			</if>
			<if test="tIncomeDetail.idCardList != null and tIncomeDetail.idCardList.size() > 0">
				AND a.EMP_IDCARD in
				<foreach item="item" index="index" collection="tIncomeDetail.idCardList" open="(" separator="," close=")">
					#{item}
				</foreach>
			</if>
		</if>
	</sql>

	<!-- 列表 -->
	<select id="getTIncomeDetailList" resultMap="tIncomeDetailMap">
		SELECT
		<include refid="Base_Column_List"/>
		FROM t_income_detail a
		<where>
			1=1
			<include refid="tIncomeDetail_where"/>
		</where>
	</select>

	<!-- 获取重复性 -->
	<select id="getTIncomeDetailRepeat" resultType="java.lang.Integer">
		SELECT
			count(1)
		FROM t_income_detail a
		where	a.ID !=  #{tIncomeDetail.id}
				AND a.SOURCE_ID = #{tIncomeDetail.sourceId}
				AND a.MONEY = #{tIncomeDetail.money}
				AND a.RED_DATA = #{tIncomeDetail.redData}
				AND a.FEE_TYPE = #{tIncomeDetail.feeType}
	</select>

</mapper>
