<?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.archives.mapper.TSettleDomainMapper">

	<resultMap id="tSettleDomainMap" type="com.yifu.cloud.plus.v1.yifu.archives.entity.TSettleDomain">
		<id property="id" column="ID"/>
		<result property="departNo" column="DEPART_NO"/>
		<result property="departName" column="DEPART_NAME"/>
		<result property="isNew" column="IS_NEW"/>
		<result property="newRemark" column="NEW_REMARK"/>
		<result property="deleteFlag" column="DELETE_FLAG"/>
		<result property="dpAuditFlag" column="DP_AUDIT_FLAG"/>
		<result property="oldId" column="OLD_ID"/>
		<result property="belongContract" column="BELONG_CONTRACT"/>
		<result property="dpAuditOpinion" column="DP_AUDIT_OPINION"/>
		<result property="dpAuditMan" column="DP_AUDIT_MAN"/>
		<result property="dpAuditManName" column="DP_AUDIT_MAN_NAME"/>
		<result property="lastAuditDate" column="LAST_AUDIT_DATE"/>
		<result property="serverItem" column="SERVER_ITEM"/>
		<result property="incomeBelong" column="INCOME_BELONG"/>
		<result property="incomeBelongSub" column="INCOME_BELONG_SUB"/>
		<result property="customerId" column="CUSTOMER_ID"/>
		<result property="createUserName" column="CREATE_USER_NAME"/>
		<result property="commitUser" column="COMMIT_USER"/>
		<result property="commitUserName" column="COMMIT_USER_NAME"/>
		<result property="balance" column="BALANCE"/>
		<result property="invoiceBalance" column="INVOICE_BALANCE"/>
		<result property="firstPassFlag" column="FIRST_PASS_FLAG"/>
		<result property="firstPassTime" column="FIRST_PASS_TIME"/>
		<result property="province" column="PROVINCE"/>
		<result property="city" column="CITY"/>
		<result property="town" column="TOWN"/>
		<result property="stopFlag" column="STOP_FLAG"/>
		<result property="employeeNum" column="employee_num"/>
		<result property="stopDate" column="STOP_DATE"/>
		<result property="stopReason" column="STOP_REASON"/>
		<result property="stopUser" column="STOP_USER"/>
		<result property="stopUserName" column="STOP_USER_NAME"/>
		<result property="type" column="TYPE"/>
		<result property="businessPrimaryType" column="BUSINESS_PRIMARY_TYPE"/>
		<result property="businessSecondType" column="BUSINESS_SECOND_TYPE"/>
		<result property="businessThirdType" column="BUSINESS_THIRD_TYPE"/>
		<result property="managerAuditOpinion" column="MANAGER_AUDIT_OPINION"/>
		<result property="managerAuditMan" column="MANAGER_AUDIT_MAN"/>
		<result property="managerAuditManName" column="MANAGER_AUDIT_MAN_NAME"/>
		<result property="auditTime" column="AUDIT_TIME"/>
		<result property="managerAuditTime" column="MANAGER_AUDIT_TIME"/>
		<result property="createType" column="CREATE_TYPE"/>
		<result property="relateFlag" column="RELATE_FLAG"/>
		<result property="exceptionRemark" column="EXCEPTION_REMARK"/>
		<result property="existAdvancePayment" column="EXIST_ADVANCE_PAYMENT"/>
		<result property="backPayCycle" column="BACK_PAY_CYCLE"/>
		<result property="socialType" column="SOCIAL_TYPE"/>
		<result property="fundType" column="FUND_TYPE"/>
		<result property="insuranceSettleType" column="INSURANCE_SETTLE_TYPE"/>
		<result property="invoiceTitleSalary" column="INVOICE_TITLE_SALARY"/>
		<result property="invoiceTitleInsurance" column="INVOICE_TITLE_INSURANCE"/>
		<result property="unitOfOurCompany" column="UNIT_OF_OUR_COMPANY"/>
		<result property="customerNo" column="CUSTOMER_NO"/>
		<result property="customerName" column="CUSTOMER_NAME"/>
		<result property="mrSettleType" column="MR_SETTLE_TYPE"/>
		<result property="managementTag" column="MANAGEMENT_TAG"/>
		<result property="managementFee" column="MANAGEMENT_FEE"/>
		<result property="managementType" column="MANAGEMENT_TYPE"/>
		<result property="riskFundTag" column="RISK_FUND_TAG"/>
		<result property="riskFundFee" column="RISK_FUND_FEE"/>
		<result property="riskFundType" column="RISK_FUND_TYPE"/>
		<result property="manageServerItem" column="MANAGE_SERVER_ITEM"/>
		<result property="riskServerItem" column="RISK_SERVER_ITEM"/>
		<result property="unitSeriousIllnessProp" column="UNIT_SERIOUS_ILLNESS_PROP"/>
		<result property="bpoFlag" column="BPO_FLAG"/>
	</resultMap>

	<sql id="Base_Column_List">
		a.ID,
		a.DEPART_NO,
		a.DEPART_NAME,
		a.IS_NEW,
		a.NEW_REMARK,
		a.DELETE_FLAG,
		a.DP_AUDIT_FLAG,
		a.OLD_ID,
		a.BELONG_CONTRACT,
		a.DP_AUDIT_OPINION,
		a.DP_AUDIT_MAN,
		a.DP_AUDIT_MAN_NAME,
		a.LAST_AUDIT_DATE,
		a.SERVER_ITEM,
		a.INCOME_BELONG,
		a.INCOME_BELONG_SUB,
		a.CUSTOMER_ID,
		a.CREATE_USER_NAME,
		a.COMMIT_USER,
		a.COMMIT_USER_NAME,
		a.BALANCE,
		a.INVOICE_BALANCE,
		a.FIRST_PASS_FLAG,
		a.FIRST_PASS_TIME,
		a.PROVINCE,
		a.CITY,
		a.TOWN,
		a.STOP_FLAG,
		a.employee_num,
		a.STOP_DATE,
		a.STOP_REASON,
		a.STOP_USER,
		a.STOP_USER_NAME,
		a.TYPE,
		a.BUSINESS_PRIMARY_TYPE,
		a.BUSINESS_SECOND_TYPE,
		a.BUSINESS_THIRD_TYPE,
		a.MANAGER_AUDIT_OPINION,
		a.MANAGER_AUDIT_MAN,
		a.MANAGER_AUDIT_MAN_NAME,
		a.AUDIT_TIME,
		a.MANAGER_AUDIT_TIME,
		a.CREATE_TYPE,
		a.RELATE_FLAG,
		a.EXCEPTION_REMARK,
		a.EXIST_ADVANCE_PAYMENT,
		a.BACK_PAY_CYCLE,
		a.CREATE_BY,
		a.CREATE_NAME,
		a.CREATE_TIME,
		a.UPDATE_BY,
		a.UPDATE_TIME,
		a.SOCIAL_TYPE,
		a.INSURANCE_SETTLE_TYPE,
		a.CUSTOMER_NO,
		a.CUSTOMER_NAME,
		a.UNIT_OF_OUR_COMPANY,
		a.INVOICE_TITLE_SALARY,
		a.INVOICE_TITLE_INSURANCE,
		a.FUND_TYPE,
		a.MR_SETTLE_TYPE,
		a.MANAGEMENT_TAG,
		a.MANAGEMENT_FEE,
		a.MANAGEMENT_TYPE,
		a.RISK_FUND_TAG,
		a.RISK_FUND_FEE,
		a.RISK_FUND_TYPE,
		a.MANAGE_SERVER_ITEM,
		a.RISK_SERVER_ITEM,
		a.UNIT_SERIOUS_ILLNESS_PROP,
		a.BPO_FLAG
	</sql>

	<resultMap id="tSettleDomainSelectVoMap" type="com.yifu.cloud.plus.v1.yifu.archives.vo.TSettleDomainSelectVo">
		<id property="id" column="ID"/>
		<result property="province" column="PROVINCE"/>
		<result property="city" column="CITY"/>
		<result property="town" column="TOWN"/>
		<result property="departNo" column="DEPART_NO"/>
		<result property="departName" column="DEPART_NAME"/>
		<result property="isNew" column="IS_NEW"/>
		<result property="newRemark" column="NEW_REMARK"/>
		<result property="createTime" column="CREATE_TIME"/>
		<result property="deleteFlag" column="DELETE_FLAG"/>
		<result property="dpAuditFlag" column="DP_AUDIT_FLAG"/>
		<result property="oldId" column="OLD_ID"/>
		<result property="belongContract" column="BELONG_CONTRACT"/>
		<result property="customerId" column="CUSTOMER_ID"/>
		<result property="customerName" column="customerName"/>
		<result property="customerCode" column="customerCode"/>
		<result property="dpAuditMan" column="DP_AUDIT_MAN"/>
		<result property="dpAuditOpinion" column="DP_AUDIT_OPINION"/>
		<result property="lastAuditDate" column="LAST_AUDIT_DATE"/>
		<result property="serverItem" column="SERVER_ITEM"/>
		<result property="incomeBelong" column="INCOME_BELONG"/>
		<result property="incomeBelongSub" column="INCOME_BELONG_SUB"/>
		<result property="createUserName" column="CREATE_USER_NAME"/>
		<result property="commitUser" column="COMMIT_USER"/>
		<result property="commitUserName" column="COMMIT_USER_NAME"/>
		<result property="stopFlag" column="STOP_FLAG"/>
		<result property="bpoFlag" column="BPO_FLAG"/>
	</resultMap>

	<select id="getPage" resultMap="tSettleDomainMap">
		SELECT
			<include refid="Base_Column_List"/>
		FROM t_settle_domain a
		WHERE 1=1
		<if test="tSettleDomain != null">
			<if test="tSettleDomain.departName != null and tSettleDomain.departName.trim() != ''">
				and a.DEPART_NAME like concat('%', #{tSettleDomain.departName} ,'%')
			</if>
			<if test="tSettleDomain.departNo != null and tSettleDomain.departNo.trim() != ''">
				and a.DEPART_NO = #{tSettleDomain.departNo}
			</if>
			<if test="tSettleDomain.deleteFlag != null and tSettleDomain.deleteFlag.trim() != ''">
				and a.DELETE_FLAG = #{tSettleDomain.deleteFlag}
			</if>
			<if test="tSettleDomain.stopFlag != null and tSettleDomain.stopFlag.trim() != ''">
				and a.STOP_FLAG = #{tSettleDomain.stopFlag}
			</if>
		</if>
	</select>

	<select id="getUnitPage" resultType="com.yifu.cloud.plus.v1.yifu.archives.vo.IdNameNoVo">
		SELECT
			a.CUSTOMER_ID as id,
			a.CUSTOMER_NAME as name,
			a.CUSTOMER_NO as no
		FROM t_settle_domain a
		WHERE 1=1
		<if test="idNameNoVo != null">
			<if test="idNameNoVo.name != null and idNameNoVo.name.trim() != ''">
				and a.CUSTOMER_NAME like concat('%', #{idNameNoVo.name} ,'%')
			</if>
			<if test="idNameNoVo.no != null and idNameNoVo.no.trim() != ''">
				and a.CUSTOMER_NO = #{idNameNoVo.no}
			</if>
		</if>
		group by a.CUSTOMER_ID
	</select>

	<select id="selectSettleDomainSelectVosById"
			resultType="com.yifu.cloud.plus.v1.yifu.archives.vo.TSettleDomainSelectVo">
		SELECT
		<include refid="Base_Column_List"/>,
		a.CUSTOMER_ID AS 'customerId',
		a.CUSTOMER_NAME as 'customerName',
		a.CUSTOMER_NO as 'customerCode',
		a.INVOICE_TITLE_SALARY as 'businessSubjectName'
		FROM
		t_settle_domain a
		WHERE a.DEPART_NO=#{departNo} GROUP BY a.DEPART_NO
	</select>

	<select id="getSettleDomainVoById"
			resultType="com.yifu.cloud.plus.v1.yifu.archives.vo.TSettleDomainSelectVo">
		SELECT
		<include refid="Base_Column_List"/>,
		a.CUSTOMER_ID AS 'customerId',
		a.CUSTOMER_NAME as 'customerName',
		a.CUSTOMER_NO as 'customerCode',
		a.INVOICE_TITLE_SALARY as 'businessSubjectName'
		FROM
		t_settle_domain a
		WHERE a.id=#{id} GROUP BY a.id
	</select>

	<select id="selectAllSettleDomainSelectVos" resultMap="tSettleDomainSelectVoMap">
		SELECT
		<include refid="Base_Column_List"/>,
		a.CUSTOMER_ID AS 'customerId',
		a.CUSTOMER_NAME as 'customerName',
		a.CUSTOMER_NO as 'customerCode'
		FROM
		t_settle_domain a
		where a.DELETE_FLAG = '0'
	</select>
	<select id="getSetInfoByCodes" resultType="com.yifu.cloud.plus.v1.yifu.archives.vo.ProjectSetInfoVo">
		SELECT a.ID,
		a.DEPART_NO,
		a.DEPART_NAME,
		a.INSURANCE_SETTLE_TYPE,
		a.CUSTOMER_ID AS 'customerId',
		a.CUSTOMER_NAME as 'customerName',
		a.CUSTOMER_NO as 'customerCode',
		a.BUSINESS_PRIMARY_TYPE,
		a.BUSINESS_SECOND_TYPE,
		a.BUSINESS_THIRD_TYPE,
		a.STOP_FLAG,
		a.INVOICE_TITLE_SALARY,
		a.INVOICE_TITLE_INSURANCE,
		a.BPO_FLAG
		FROM t_settle_domain a
		where 1=1
			and a.DELETE_FLAG = '0'
			<if test="codes != null and codes.size() > 0">
				and  a.DEPART_NO in
				<foreach collection="codes" item="param" index="index" open="(" close=")" separator=",">
					#{param}
				</foreach>
			</if>

	</select>
</mapper>
