<?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.SysHouseHoldInfoMapper">

  <resultMap id="sysHouseHoldInfoMap" type="com.yifu.cloud.plus.v1.yifu.social.entity.SysHouseHoldInfo">
    <id property="id" column="ID"/>
    <result property="organId" column="ORGAN_ID"/>
    <result property="name" column="NAME"/>
    <result property="createTime" column="CREATE_TIME"/>
    <result property="delFlag" column="DEL_FLAG"/>
    <result property="type" column="TYPE"/>
    <result property="province" column="PROVINCE"/>
    <result property="city" column="CITY"/>
    <result property="town" column="TOWN"/>
    <result property="rmark" column="RMARK"/>
    <result property="organName" column="ORGAN_NAME"/>
	<result property="auditUser" column="AUDIT_USER"/>
	<result property="auditUserName" column="AUDIT_USER_NAME"/>
	<result property="handleUser" column="HANDLE_USER"/>
	<result property="handleUserName" column="HANDLE_USER_NAME"/>
    <result property="createBy" column="CREATE_BY"/>
    <result property="updateBy" column="UPDATE_BY"/>
    <result property="createName" column="CREATE_NAME"/>
    <result property="createTime" column="CREATE_TIME"/>
    <result property="updateTime" column="UPDATE_TIME"/>
    <result property="houseType" column="HOUSE_TYPE"/>
    <result property="customerNo" column="CUSTOMER_NO"/>
    <result property="unitCreditCode" column="UNIT_CREDIT_CODE"/>
    <result property="fundBank" column="FUND_BANK"/>
    <result property="autoStatus" column="AUTO_STATUS"/>
    <result property="phone" column="PHONE"/>
    <result property="socialAccount" column="SOCIAL_ACCOUNT"/>
    <result property="mediclAccount" column="MEDICL_ACCOUNT"/>
    <result property="socialPassword" column="SOCIAL_PASSWORD"/>
    <result property="mediclPassword" column="MEDICL_PASSWORD"/>
    <result property="isSign" column="IS_SIGN"/>
    <result property="customerNoYsd" column="CUSTOMER_NO_YSD"/>
    <result property="isSingle" column="IS_SINGLE"/>
    <result property="isAutoLeaveDoc" column="IS_AUTO_LEAVE_DOC"/>

	<!-- MVPV1.7.15  户拆分 fxj  2025-09-11 -->
	<result property="autoStatusYsd" column="AUTO_STATUS_YSD"/>
	<result property="isSingleYsd" column="IS_SINGLE_YSD"/>
	<result property="rosterAutoFlagYgs" column="ROSTER_AUTO_FLAG_YGS"/>
	<result property="rosterAutoFlagYsd" column="ROSTER_AUTO_FLAG_YSD"/>
	<result property="dataFlagYgs" column="DATA_FLAG_YGS"/>
	<result property="dataFlagYsd" column="DATA_FLAG_YSD"/>
	<result property="addRosterTempYgs" column="ADD_ROSTER_TEMP_YGS"/>
	<result property="reduceRosterTempYgs" column="REDUCE_ROSTER_TEMP_YGS"/>
	<result property="addRosterTempYsd" column="ADD_ROSTER_TEMP_YSD"/>
	<result property="reduceRosterTempYsd" column="REDUCE_ROSTER_TEMP_YSD"/>
  </resultMap>

	<resultMap id="sysHouseHoldSingleInfoMap" type="com.yifu.cloud.plus.v1.yifu.social.entity.SysHouseHoldInfo">
		<id property="id" column="ID"/>
		<result property="name" column="NAME"/>
		<result property="type" column="TYPE"/>
		<result property="customerNo" column="CUSTOMER_NO"/>
		<result property="unitCreditCode" column="UNIT_CREDIT_CODE"/>
	</resultMap>

    <sql id="Base_Column_List">
                a.ID,
                a.ORGAN_ID,
                a.NAME,
                a.CREATE_TIME,
                a.DEL_FLAG,
                a.TYPE,
                a.PROVINCE,
                a.CITY,
                a.TOWN,
                a.RMARK,
                a.ORGAN_NAME,
                a.CREATE_BY,
                a.UPDATE_BY,
                a.CREATE_NAME,
                a.UPDATE_TIME,
				a.AUDIT_USER,
				a.AUDIT_USER_NAME,
				a.HANDLE_USER,
				a.HOUSE_TYPE,
				a.CUSTOMER_NO,
				a.UNIT_CREDIT_CODE,
				a.FUND_BANK,
				a.HANDLE_USER_NAME,
				a.AUTO_STATUS,
				a.PHONE,
				a.SOCIAL_ACCOUNT,
				a.MEDICL_ACCOUNT,
				a.SOCIAL_PASSWORD,
				a.MEDICL_PASSWORD,
				a.IS_SIGN,
				a.CUSTOMER_NO_YSD,
				a.IS_SINGLE,
				a.IS_AUTO_LEAVE_DOC,
				a.AUTO_STATUS_YSD,
				a.IS_SINGLE_YSD,
				a.ROSTER_AUTO_FLAG_YGS,
				a.ROSTER_AUTO_FLAG_YSD,
				a.DATA_FLAG_YGS,
				a.DATA_FLAG_YSD,
				a.ADD_ROSTER_TEMP_YGS,
				a.REDUCE_ROSTER_TEMP_YGS,
				a.ADD_ROSTER_TEMP_YSD,
				a.REDUCE_ROSTER_TEMP_YSD
    </sql>
    <sql id="sysHouseHoldInfo_where">
        <if test="sysHouseHoldInfo != null">
                    <if test="sysHouseHoldInfo.id != null and sysHouseHoldInfo.id.trim() != ''">
                        AND a.ID = #{sysHouseHoldInfo.id}
                    </if>
                    <if test="sysHouseHoldInfo.organId != null and sysHouseHoldInfo.organId.trim() != ''">
                        AND a.ORGAN_ID = #{sysHouseHoldInfo.organId}
                    </if>
                    <if test="sysHouseHoldInfo.name != null and sysHouseHoldInfo.name.trim() != ''">
						AND a.NAME like CONCAT('%',#{sysHouseHoldInfo.name},'%')
                    </if>
                    <if test="sysHouseHoldInfo.createTime != null">
                        AND a.CREATE_TIME = #{sysHouseHoldInfo.createTime}
                    </if>
                    <if test="sysHouseHoldInfo.delFlag != null and sysHouseHoldInfo.delFlag.trim() != ''">
                        AND a.DEL_FLAG = #{sysHouseHoldInfo.delFlag}
                    </if>
                    <if test="sysHouseHoldInfo.type != null and sysHouseHoldInfo.type.trim() != ''">
                        AND a.TYPE = #{sysHouseHoldInfo.type}
                    </if>
					<if test="sysHouseHoldInfo.houseType != null and sysHouseHoldInfo.houseType.trim() != ''">
						AND a.HOUSE_TYPE = #{sysHouseHoldInfo.houseType}
					</if>
                    <if test="sysHouseHoldInfo.province != null and sysHouseHoldInfo.province.trim() != ''">
                        AND a.PROVINCE = #{sysHouseHoldInfo.province}
                    </if>
                    <if test="sysHouseHoldInfo.city != null and sysHouseHoldInfo.city.trim() != ''">
                        AND a.CITY = #{sysHouseHoldInfo.city}
                    </if>
                    <if test="sysHouseHoldInfo.town != null and sysHouseHoldInfo.town.trim() != ''">
                        AND a.TOWN = #{sysHouseHoldInfo.town}
                    </if>
                    <if test="sysHouseHoldInfo.rmark != null and sysHouseHoldInfo.rmark.trim() != ''">
                        AND a.RMARK = #{sysHouseHoldInfo.rmark}
                    </if>
                    <if test="sysHouseHoldInfo.organName != null and sysHouseHoldInfo.organName.trim() != ''">
                        AND a.ORGAN_NAME = #{sysHouseHoldInfo.organName}
                    </if>
                    <if test="sysHouseHoldInfo.createBy != null and sysHouseHoldInfo.createBy.trim() != ''">
                        AND a.CREATE_BY = #{sysHouseHoldInfo.createBy}
                    </if>
                    <if test="sysHouseHoldInfo.updateBy != null and sysHouseHoldInfo.updateBy.trim() != ''">
                        AND a.UPDATE_BY = #{sysHouseHoldInfo.updateBy}
                    </if>
                    <if test="sysHouseHoldInfo.createName != null and sysHouseHoldInfo.createName.trim() != ''">
                        AND a.CREATE_NAME = #{sysHouseHoldInfo.createName}
                    </if>
					<if test="sysHouseHoldInfo.autoStatus != null and sysHouseHoldInfo.autoStatus.trim() != ''">
						AND a.AUTO_STATUS = #{sysHouseHoldInfo.autoStatus}
					</if>
					<if test="sysHouseHoldInfo.autoStatusYsd != null and sysHouseHoldInfo.autoStatusYsd.trim() != ''">
						AND a.AUTO_STATUS_YSD = #{sysHouseHoldInfo.autoStatusYsd}
					</if>
                    <if test="sysHouseHoldInfo.updateTime != null">
                        AND a.UPDATE_TIME = #{sysHouseHoldInfo.updateTime}
                    </if>
					<if test="sysHouseHoldInfo.isSign != null and sysHouseHoldInfo.isSign.trim() != ''">
						AND a.IS_SIGN = #{sysHouseHoldInfo.isSign}
					</if>
        </if>
    </sql>
    <!--sysHouseHoldInfo简单分页查询-->
    <select id="getSysHouseHoldInfoPage" resultMap="sysHouseHoldInfoMap">
        SELECT
        <include refid="Base_Column_List"/>
        FROM sys_house_hold_info a
        <where>
            1=1
            <include refid="sysHouseHoldInfo_where"/>
        </where>
		order by a.CREATE_TIME desc
    </select>

	<!--sysHouseHoldInfo简单分页查询-->
	<select id="getAllSingleSocailPage" resultMap="sysHouseHoldSingleInfoMap">
		SELECT
		a.ID,
		a.TYPE,
		a.CUSTOMER_NO,
		a.UNIT_CREDIT_CODE,
		a.NAME
		FROM sys_house_hold_info a
		where HOUSE_TYPE = '0'
		order by a.CREATE_TIME desc
	</select>

	<select id="selectExportCount" resultType="java.lang.Long">
		SELECT
		count(1)
		FROM sys_house_hold_info a
		<where>
			1=1
			<include refid="sysHouseHoldInfo_where"/>
		</where>
		order by a.CREATE_TIME desc
	</select>

	<select id="selectExportList" resultType="com.yifu.cloud.plus.v1.yifu.social.vo.TSocialHouseholdExportVo">
		SELECT
		if(a.TYPE = '0','社保户','公积金户') type,
		a.NAME,
		a1.AREA_NAME PROVINCE,
		a2.AREA_NAME CITY,
		ifnull(a3.AREA_NAME,'') TOWN,
		a.ORGAN_NAME organName,
		a.AUDIT_USER_NAME auditUserName,
		a.HANDLE_USER_NAME handleUserName,
		a.PHONE,
		if(a.HOUSE_TYPE = '0','独立户','自有户') houseType,
		a.CUSTOMER_NO customerNo,
		a.UNIT_CREDIT_CODE unitCreditCode,
		a.CUSTOMER_NO_YSD customerNoYsd,
		a.SOCIAL_ACCOUNT socialAccount,
		"" socialPassword,
		a.MEDICL_ACCOUNT mediclAccount,
		"" mediclPassword,
		if(a.IS_SIGN = '0','是','否') isSign,
		if(a.AUTO_STATUS = '0','启用','禁用') autoStatus,
		if(a.AUTO_STATUS_YSD = '0','启用','禁用') autoStatusYsd,
		case when a.IS_SINGLE = '0' then '批量' when a.IS_SINGLE = '1' then '单个' else '' end isSingle,
		case when a.IS_SINGLE_YSD = '0' then '批量' when a.IS_SINGLE_YSD = '1' then '单个' else '' end isSingleYsd,
		case when a.ROSTER_AUTO_FLAG_YGS = '0' then '否' when a.ROSTER_AUTO_FLAG_YGS = '1' then '是' else '' end rosterAutoFlagYgs,
		case when a.ROSTER_AUTO_FLAG_YSD = '0' then '否' when a.ROSTER_AUTO_FLAG_YSD = '1' then '是' else '' end rosterAutoFlagYsd,
		case when a.DATA_FLAG_YGS = '0' then '否' when a.DATA_FLAG_YGS = '1' then '是' else '' end dataFlagYgs,
		case when a.DATA_FLAG_YSD = '0' then '否' when a.DATA_FLAG_YSD = '1' then '是' else '' end dataFlagYsd,
		case when a.IS_AUTO_LEAVE_DOC = '0' then '否' when a.IS_AUTO_LEAVE_DOC = '1' then '是' else '' end isAutoLeaveDoc
		FROM sys_house_hold_info a
		LEFT JOIN sys_area a1 on a1.id=a.PROVINCE
		LEFT JOIN sys_area a2 on a2.id=a.CITY
		LEFT JOIN sys_area a3 on a3.id=a.TOWN
		<where>
			1 = 1
			<include refid="sysHouseHoldInfo_where"/>
		</where>
		order by a.CREATE_TIME desc
	</select>

	<!-- 获取自动生成解除劳动合同书的户与公章src -->
	<select id="getAttaSrcByAutoDoc" resultMap="sysHouseHoldSingleInfoMap" >
		SELECT h.NAME NAME,a.ATTA_SRC TYPE
		FROM t_atta_info a join sys_house_hold_info h on h.id=a.DOMAIN_ID
		where a.RELATION_TYPE = '1'
	</select>

	<select id="getHouseInfoAutoDoc" resultMap="sysHouseHoldInfoMap" >
		SELECT
		<include refid="Base_Column_List"/>
		,AREA_CODE
		FROM sys_house_hold_info a
		where a.AUTO_STATUS = '0' or a.AUTO_STATUS_YSD = '0'

	</select>
</mapper>
