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

	<resultMap id="fddPersonAccountMap" type="com.yifu.cloud.plus.v1.yifu.archives.entity.FddPersonAccount">
		<id property="id" column="ID"/>
		<result property="moblie" column="MOBLIE"/>
		<result property="name" column="NAME"/>
		<result property="idCard" column="ID_CARD"/>
		<result property="unionid" column="UNIONID"/>
		<result property="authStatus" column="AUTH_STATUS"/>
		<result property="systemFlag" column="SYSTEM_FLAG"/>
		<result property="companyInfoId" column="COMPANY_INFO_ID"/>
		<result property="realStatus" column="REAL_STATUS"/>
		<result property="realMessageFlag" column="REAL_MESSAGE_FLAG"/>
		<result property="createBy" column="CREATE_BY"/>
		<result property="updateBy" column="UPDATE_BY"/>
		<result property="createTime" column="CREATE_TIME"/>
		<result property="updateTime" column="UPDATE_TIME"/>
		<result property="createName" column="CREATE_NAME"/>
	</resultMap>

	<sql id="Base_Column_List">
		a.ID,
        a.MOBLIE,
        a.NAME,
        a.ID_CARD,
        a.UNIONID,
        a.AUTH_STATUS,
        a.SYSTEM_FLAG,
        a.REAL_STATUS,
        a.COMPANY_INFO_ID,
		a.CREATE_BY,
        a.CREATE_NAME,
        a.CREATE_TIME,
        a.UPDATE_BY,
        a.UPDATE_TIME
	</sql>

	<sql id="fddPersonAccount_where">
		<if test="fddPersonAccount != null">
			<if test="fddPersonAccount.id != null and fddPersonAccount.id.trim() != ''">
				AND a.ID = #{fddPersonAccount.id}
			</if>
			<if test="fddPersonAccount.moblie != null and fddPersonAccount.moblie.trim() != ''">
				AND a.MOBLIE = #{fddPersonAccount.moblie}
			</if>
			<if test="fddPersonAccount.name != null and fddPersonAccount.name.trim() != ''">
				AND a.NAME = #{fddPersonAccount.name}
			</if>
			<if test="fddPersonAccount.idCard != null and fddPersonAccount.idCard.trim() != ''">
				AND a.ID_CARD = #{fddPersonAccount.idCard}
			</if>
			<if test="fddPersonAccount.unionid != null and fddPersonAccount.unionid.trim() != ''">
				AND a.UNIONID = #{fddPersonAccount.unionid}
			</if>
			<if test="fddPersonAccount.authStatus != null and fddPersonAccount.authStatus.trim() != ''">
				AND a.AUTH_STATUS = #{fddPersonAccount.authStatus}
			</if>
			<if test="fddPersonAccount.systemFlag != null and fddPersonAccount.systemFlag.trim() != ''">
				AND a.SYSTEM_FLAG = #{fddPersonAccount.systemFlag}
			</if>
			<if test="fddPersonAccount.realStatus != null and fddPersonAccount.realStatus.trim() != ''">
				AND a.REAL_STATUS = #{fddPersonAccount.realStatus}
			</if>
			<if test="fddPersonAccount.companyInfoId != null and fddPersonAccount.companyInfoId.trim() != ''">
				AND a.COMPANY_INFO_ID = #{fddPersonAccount.companyInfoId}
			</if>
			<if test="fddPersonAccount.createBy != null and fddPersonAccount.createBy.trim() != ''">
				AND a.CREATE_BY = #{fddPersonAccount.createBy}
			</if>
			<if test="fddPersonAccount.createName != null and fddPersonAccount.createName.trim() != ''">
				AND a.CREATE_NAME = #{fddPersonAccount.createName}
			</if>
			<if test="fddPersonAccount.createTime != null">
				AND a.CREATE_TIME = #{fddPersonAccount.createTime}
			</if>
			<if test="fddPersonAccount.updateBy != null and fddPersonAccount.updateBy.trim() != ''">
				AND a.UPDATE_BY = #{fddPersonAccount.updateBy}
			</if>
			<if test="fddPersonAccount.updateTime != null">
				AND a.UPDATE_TIME = #{fddPersonAccount.updateTime}
			</if>
		</if>
	</sql>
	<update id="delEmployee">
		update fdd_person_account set COMPANY_INFO_ID=#{unionIds} where id=#{id}
	</update>
	<!--fddPersonAccount简单分页查询-->
	<select id="getFddPersonAccountPage" resultMap="fddPersonAccountMap">
		SELECT
		<include refid="Base_Column_List"/>,GROUP_CONCAT(distinct c.COMPANY_NAME) as COMPANY_NAME,GROUP_CONCAT(distinct l.SEAL_NAME) as SEAL_NAME,GROUP_CONCAT(distinct l.id) as SEAL_ID
		FROM fdd_person_account a
		left join fdd_company_info c on FIND_IN_SET(c.ID,a.COMPANY_INFO_ID)
		left join fdd_seal_person_auth s on s.FDD_PERSON_ACCOUNT_ID=a.id
		left join fdd_seal_info l on l.SEAL_ID=s.SEAL_ID
		<where>
			1=1
			<include refid="fddPersonAccount_where"/>
		</where>
		GROUP BY a.ID_CARD,a.MOBLIE ORDER BY a.CREATE_TIME desc
	</select>
</mapper>
