<?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"/>
		<result property="bpoEnable" column="BPO_ENABLE"/>
		<result property="buBelong" column="BU_BELONG"/>
		<result property="firstIndicatorBelong" column="FIRST_INDICATOR_BELONG"/>
		<result property="secondIndicatorBelong" column="SECOND_INDICATOR_BELONG"/>
		<result property="lineType" column="LINE_TYPE"/>

		<!-- 2025-01-10 FXJ V1.7.5 -->
		<result property="hasContainRisks" column="HAS_CONTAIN_RISKS"/>
		<result property="newLine" column="NEW_LINE"/>
		<result property="division" column="DIVISION"/>

		<result property="issueStatus" column="ISSUE_STATUS"/>

		<result property="csName" column="cs_name"/>
		<result property="csPhone" column="cs_phone"/>
		<result property="csLoginName" column="cs_login_name"/>
		<!-- 2025-03-31 FXJ V1.7.9 -->
		<result property="projectManager" column="PROJECT_MANAGER"/>

	</resultMap>

	<resultMap id="tSettleDomainTwoMap" type="com.yifu.cloud.plus.v1.yifu.archives.vo.SecondBelongVo">
		<result property="departNo" column="DEPART_NO"/>
		<result property="secondIndicatorBelong" column="SECOND_INDICATOR_BELONG"/>
	</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,
		a.BPO_ENABLE,
		a.BU_BELONG,
		a.ISSUE_STATUS,
		a.FIRST_INDICATOR_BELONG,
		a.SECOND_INDICATOR_BELONG,
		a.LINE_TYPE,
		a.HAS_CONTAIN_RISKS,
		a.NEW_LINE,
		a.DIVISION,
		a.cs_name,
		a.cs_phone,
		a.cs_login_name,
		a.PROJECT_MANAGER
	</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"/>
		<result property="bpoEnable" column="BPO_ENABLE"/>

		<!-- 2025-01-10 FXJ V1.7.5 -->
		<result property="hasContainRisks" column="HAS_CONTAIN_RISKS"/>
		<result property="newLine" column="NEW_LINE"/>
		<result property="division" column="DIVISION"/>

		<result property="csName" column="cs_name"/>
		<result property="csPhone" column="cs_phone"/>
		<result property="csLoginName" column="cs_login_name"/>

		<!-- 2025-03-31 FXJ V1.7.9 -->
		<result property="projectManager" column="PROJECT_MANAGER"/>
	</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.serverItem != null and tSettleDomain.serverItem.trim() != ''">
				and a.SERVER_ITEM  like concat('%',#{tSettleDomain.serverItem},'%')
			</if>
			<if test="tSettleDomain.hasContainRisks != null and tSettleDomain.hasContainRisks.trim() != ''">
				and a.HAS_CONTAIN_RISKS  = #{tSettleDomain.hasContainRisks}
			</if>
			<if test="tSettleDomain.newLine != null and tSettleDomain.newLine.trim() != ''">
				and a.NEW_LINE  like concat('%',#{tSettleDomain.newLine},'%')
			</if>
			<if test="tSettleDomain.division != null and tSettleDomain.division.trim() != ''">
				and a.DIVISION  like concat('%',#{tSettleDomain.division},'%')
			</if>
			<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 tSettleDomain.stopFlag == 0">
				and a.STOP_FLAG = '0'
			</if>
			<if test="tSettleDomain.stopFlag != null and tSettleDomain.stopFlag.trim() != '' and tSettleDomain.stopFlag == 1">
				and (a.STOP_FLAG = '1' or a.STOP_FLAG = '2')
			</if>
			<if test="tSettleDomain.lineType != null and tSettleDomain.lineType.trim() != ''">
				and a.LINE_TYPE =  #{tSettleDomain.lineType}
			</if>
			<if test="tSettleDomain.buBelong != null and tSettleDomain.buBelong.trim() != ''">
				and a.BU_BELONG = #{tSettleDomain.buBelong}
			</if>
			<if test="tSettleDomain.buBelong != null and tSettleDomain.buBelong.trim() != ''">
				and a.BU_BELONG = #{tSettleDomain.buBelong}
			</if>
			<if test="tSettleDomain.issueStatus != null">
				and a.ISSUE_STATUS = #{tSettleDomain.issueStatus}
			</if>
			<if test="tSettleDomain.authSql != null and tSettleDomain.authSql.trim() != ''">
				${tSettleDomain.authSql}
			</if>
		</if>
		order by CREATE_TIME desc
	</select>

	<select id="getInvoiceTitleSalaryPage" resultType="com.yifu.cloud.plus.v1.yifu.archives.vo.IdNameNoVo">
		SELECT
			distinct a.INVOICE_TITLE_SALARY as name
		FROM t_settle_domain a
		WHERE a.DELETE_FLAG = '0' and a.INVOICE_TITLE_SALARY is not null
		<if test="invoiceTitleSalary != null and invoiceTitleSalary.trim() != ''">
			and a.INVOICE_TITLE_SALARY like concat('%',#{invoiceTitleSalary},'%')
		</if>
		order by CASE WHEN a.INVOICE_TITLE_SALARY = '安徽皖信人力资源管理有限公司' THEN 0 ELSE 1 END,CREATE_TIME desc
	</select>

	<select id="getTwoBlongPage" resultMap="tSettleDomainTwoMap">
		SELECT
		a.DEPART_NO,
		a.SECOND_INDICATOR_BELONG
		FROM t_settle_domain a
		WHERE a.DELETE_FLAG = '0' and a.SECOND_INDICATOR_BELONG is not null
		<if test="tSettleDomain != null">
			<if test="tSettleDomain.departNo != null and tSettleDomain.departNo.trim() != ''">
				and a.DEPART_NO = #{tSettleDomain.departNo}
			</if>
			<if test="tSettleDomain.secondIndicatorBelong != null and tSettleDomain.secondIndicatorBelong.trim() != ''">
				and a.SECOND_INDICATOR_BELONG like concat('%', #{tSettleDomain.secondIndicatorBelong} ,'%')
			</if>
		</if>
		group by a.SECOND_INDICATOR_BELONG
		order by CREATE_TIME desc
	</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} ,'%') or a.CUSTOMER_NO 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}  limit 1
	</select>

	<select id="getSettleDomainVoByNo"
			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 = #{deptNo}  limit 1
	</select>


	<select id="getPagePerMission" resultMap="tSettleDomainMap">
		SELECT
		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,
		a.BPO_ENABLE,
		a.BU_BELONG,
		a.ISSUE_STATUS,
		a.FIRST_INDICATOR_BELONG,
		a.SECOND_INDICATOR_BELONG,
		a.LINE_TYPE,
		if(a.HAS_CONTAIN_RISKS = '是','0',if(a.HAS_CONTAIN_RISKS = '否','1','')) HAS_CONTAIN_RISKS,
		a.NEW_LINE,
		a.DIVISION,
		a.cs_name,
		a.cs_phone,
		a.cs_login_name,a.PROJECT_MANAGER
		FROM
			t_settle_domain a
			<if test="userId != null and userId.trim() != '-999'">
				LEFT JOIN t_cutsomer_data_permisson b ON b.SETTLE_DOMAIN_NO = a.DEPART_NO and b.STATUS = '0'
			</if>
		WHERE a.DELETE_FLAG = '0'
		/* 2023-6-12 11:12:15 hgw根据 */
		<if test="userId != null and userId.trim() != '-999'">
			AND b.USER_ID = #{userId}
		</if>
		<if test="departName != null and departName.trim() != ''">
			and a.DEPART_NAME like concat("%",#{departName},"%")
		</if>
		<if test="nameOrNo != null and nameOrNo.trim() != ''">
			and (a.DEPART_NAME like concat("%",#{nameOrNo},"%") or a.DEPART_NO like concat("%",#{nameOrNo},"%"))
		</if>
		<if test="customerId != null and customerId.trim() != ''">
			and a.CUSTOMER_ID =#{customerId}
		</if>
		<if test="flag != null">
			and a.STOP_FLAG='0'
		</if>
		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,
		a.BPO_ENABLE,
		a.SERVER_ITEM
		FROM t_settle_domain a
		where 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>

	<select id="getSettleInfoByCodes" resultMap="tSettleDomainMap">
		SELECT
		<include refid="Base_Column_List"/>
		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>

	<select id="getOwnSettleDomainNoPage" resultMap="tSettleDomainMap">
		SELECT
		<include refid="Base_Column_List"/>
		FROM
		t_settle_domain a
		where
		1=1
		<if test="name != null and name.trim() != ''">
			and a.DEPART_NAME like concat("%",#{name},"%")
		</if>
		and a.id in (select b.settle_id from m_setttle_customer_user b where b.user_id = #{userId}) and  a.DELETE_FLAG = '0'
	</select>

	<select id="getOwnSettleDomain" resultMap="tSettleDomainMap">
		SELECT
		<include refid="Base_Column_List"/>
		FROM
		t_settle_domain a
		where
		1=1
		<if test="name != null and name.trim() != ''">
			and a.DEPART_NAME like concat("%",#{name},"%")
		</if>
		and a.id in (select b.settle_id from m_setttle_customer_user b where b.user_id = #{userId}) and  a.DELETE_FLAG = '0'
	</select>

	<select id="getTCustomerInfoPageForB" resultType="com.yifu.cloud.plus.v1.yifu.archives.entity.TCustomerInfo">
		SELECT
		a.CUSTOMER_ID AS 'id',
		a.CUSTOMER_NAME as 'customerName',
		a.CUSTOMER_NO as 'customerCode'
		FROM t_settle_domain a
		WHERE a.DELETE_FLAG='0'
		<if test="tSettleDomain != null">
			<if test="tSettleDomain.customerName != null and tSettleDomain.customerName.trim() != ''">
				and a.CUSTOMER_NAME like concat('%', #{tSettleDomain.customerName} ,'%')
			</if>
			<if test="tSettleDomain.customerCode != null and tSettleDomain.customerCode.trim() != ''">
				and a.CUSTOMER_NO = #{tSettleDomain.customerCode}
			</if>
			<if test="tSettleDomain.customerIds != null and tSettleDomain.customerIds.size() > 0">
				and  a.CUSTOMER_ID in
				<foreach collection="tSettleDomain.customerIds" item="param" index="index" open="(" close=")" separator=",">
					#{param}
				</foreach>
			</if>
		</if>
		group  by a.CUSTOMER_NO order by CREATE_TIME desc
	</select>

	<select id="getTSettleDomainPageB" resultMap="tSettleDomainMap">
		SELECT
		<include refid="Base_Column_List"/>
		FROM
		t_settle_domain a
		where
		1=1
		<if test="tSettleDomain.customerName != null and tSettleDomain.customerName.trim() != ''">
			AND a.CUSTOMER_NAME like  CONCAT('%',#{tSettleDomain.customerName,jdbcType=VARCHAR},'%')
		</if>
		<if test="tSettleDomain.customerCode != null and tSettleDomain.customerCode.trim() != ''">
			AND a.CUSTOMER_CODE like  CONCAT('%',#{tSettleDomain.customerCode,jdbcType=VARCHAR},'%')
		</if>
		<if test="tSettleDomain.departNo != null and tSettleDomain.departNo.trim() != ''">
			AND a.DEPART_NO like  CONCAT('%',#{tSettleDomain.departNo,jdbcType=VARCHAR},'%')
		</if>
		<if test="tSettleDomain.departName != null and tSettleDomain.departName.trim() != ''">
			AND a.DEPART_NAME like CONCAT('%',#{tSettleDomain.departName,jdbcType=VARCHAR},'%')
		</if>
		<if test="tSettleDomain.settleDomainIds != null and tSettleDomain.settleDomainIds.size >0">
			AND a.id in
			<foreach item="item" index="index" collection="tSettleDomain.settleDomainIds" open="(" separator="," close=")">
				#{item}
			</foreach>
		</if>
	</select>

	<select id="getTCustomerInfoForB" resultType="com.yifu.cloud.plus.v1.yifu.archives.entity.TCustomerInfo">
		SELECT
		a.CUSTOMER_ID AS 'id',
		a.CUSTOMER_NAME as 'customerName',
		a.CUSTOMER_NO as 'customerCode'
		FROM t_settle_domain a
		WHERE a.DELETE_FLAG='0'
		<if test="ids != null and ids.size() > 0">
			and  a.CUSTOMER_ID in
			<foreach collection="ids" item="param" index="index" open="(" close=")" separator=",">
				#{param}
			</foreach>
		</if>
		group  by a.CUSTOMER_NO order by CREATE_TIME desc
	</select>

	<select id="getCustomerOwnerPage" resultType="com.yifu.cloud.plus.v1.yifu.archives.vo.CustomerOwnerSelectVo">
		SELECT
		a.CUSTOMER_ID AS 'customerId',
		a.CUSTOMER_NAME as 'customerName',
		a.CUSTOMER_NO as 'customerCode'
		FROM
		t_settle_domain a
		where
		1=1
		<if test="customerName != null and customerName.trim() != ''">
			AND a.CUSTOMER_NAME like  CONCAT('%',#{customerName},'%')
		</if>
		<if test="settleIdList != null and settleIdList.size >0">
			AND a.id in
			<foreach item="item" index="index" collection="settleIdList" open="(" separator="," close=")">
				#{item}
			</foreach>
		</if>
		and a.id in (select b.settle_id from m_setttle_customer_user b where b.user_id = #{userId}) and  a.DELETE_FLAG = '0'
		group  by a.CUSTOMER_NO order by CREATE_TIME desc
	</select>

	<update id="changeIssueStatus">
		update 	t_settle_domain a
		set a.ISSUE_STATUS=#{changeIssueStatusVo.issueStatus}
		WHERE  a.ID=#{changeIssueStatusVo.id}
	</update>
	<select id="getAllInfoMap" resultMap="tSettleDomainMap">
		SELECT
		<include refid="Base_Column_List"/>
		FROM
		t_settle_domain a
		where  a.DELETE_FLAG = '0'
	</select>

	<select id="getAllDeptByCustomerLoginName" resultType="java.lang.String">
		SELECT
			distinct(a.DEPART_NO) as DEPART_NO
		FROM
		t_settle_domain a
		where a.DELETE_FLAG = '0' and a.CS_LOGIN_NAME = #{userLoginName}
	</select>

	<select id="getServiceInfoByCodes" resultType="com.yifu.cloud.plus.v1.yifu.archives.vo.ProjectCustomerServiceVo">
		SELECT
		a.DEPART_NO as 'departNo',
		a.DEPART_NAME as 'departName',
		a.cs_login_name as 'csLoginName'
		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>
