<?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"/>
	</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
	</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"/>
	</resultMap>

	<select id="selectSettleDomainSelectVosById"
			resultType="com.yifu.cloud.plus.v1.yifu.archives.vo.TSettleDomainSelectVo">
		SELECT
		<include refid="Base_Column_List"/>,
		c.customerId,
		c.CUSTOMER_NAME as 'customerName',
		c.CUSTOMER_CODE as 'customerCode',
		c.INDUSTRY_BELONG as 'industryBelong'
		FROM
		t_settle_domain a
		LEFT JOIN (
		select ID AS 'customerId',
		CUSTOMER_NAME,
		INDUSTRY_BELONG,
		CUSTOMER_CODE from t_customer_info
		) c ON a.CUSTOMER_ID = c.customerId
		WHERE a.id=#{id} GROUP BY a.id
	</select>

	<select id="selectAllSettleDomainSelectVos" resultMap="tSettleDomainSelectVoMap">
		SELECT
		<include refid="Base_Column_List"/>,
		c.ID AS 'customerId',
		c.CUSTOMER_NAME as 'customerName',
		c.CUSTOMER_CODE as 'customerCode',
		c.customer_type as 'customerTypeName'
		FROM
		t_settle_domain a
		LEFT JOIN t_customer_info c ON a.CUSTOMER_ID = c.ID
		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,
			   c.ID AS 'customerId',
			   c.CUSTOMER_NAME as 'customerName',
			   c.CUSTOMER_CODE as 'customerCode'
		FROM t_settle_domain a
				 LEFT JOIN t_customer_info c ON a.CUSTOMER_ID = c.ID
		where 1=1
			<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>