<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.hzya.frame.sysnew.user.dao.impl.SysUserDaoImpl">

    <resultMap id="get-SysUserEntity-result" type="com.hzya.frame.sysnew.user.entity.SysUserEntity">
        <result property="id" column="id" jdbcType="VARCHAR"/>
        <result property="personId" column="person_id" jdbcType="VARCHAR"/>
        <result property="loginCode" column="login_code" jdbcType="VARCHAR"/>
        <result property="password" column="password" jdbcType="VARCHAR"/>
        <result property="salt" column="salt" jdbcType="VARCHAR"/>
        <result property="lastLoginTime" column="last_login_time" jdbcType="TIMESTAMP"/>
        <result property="lastConnectionTime" column="last_connection_time" jdbcType="TIMESTAMP"/>
        <result property="lastLoginIp" column="last_login_ip" jdbcType="VARCHAR"/>
        <result property="state" column="state" jdbcType="VARCHAR"/>
        <result property="remark" column="remark" jdbcType="VARCHAR"/>
        <result property="sorts" column="sorts" jdbcType="INTEGER"/>
        <result property="create_user_id" column="create_user_id" jdbcType="VARCHAR"/>
        <result property="create_time" column="create_time" jdbcType="TIMESTAMP"/>
        <result property="modify_user_id" column="modify_user_id" jdbcType="VARCHAR"/>
        <result property="modify_time" column="modify_time" jdbcType="TIMESTAMP"/>
        <result property="sts" column="sts" jdbcType="VARCHAR"/>
        <result property="org_id" column="org_id" jdbcType="VARCHAR"/>
        <result property="companyId" column="company_id" jdbcType="VARCHAR"/>
        <result property="personName" column="person_Name" jdbcType="VARCHAR"/>
        <result property="organName" column="organ_name" jdbcType="VARCHAR"/>
        <result property="mobilePhone" column="mobile_phone" jdbcType="VARCHAR"/>
        <result property="ddUserId" column="dd_user_id" jdbcType="VARCHAR"/>
        <result property="wxUserId" column="wx_user_id" jdbcType="VARCHAR"/>
    </resultMap>
    <!-- 查询的字段-->
    <sql id="SysUserEntity_Base_Column_List">
        id
       ,person_id 
        ,login_code 
        ,password 
        ,salt 
        ,last_login_time 
        ,last_connection_time 
        ,last_login_ip 
        ,state 
        ,remark 
        ,sorts 
        ,create_user_id 
        ,create_time 
        ,modify_user_id 
        ,modify_time 
        ,sts 
        ,org_id 
        ,company_id
        ,dd_user_id
        ,wx_user_id
     </sql>
    <!--通过ID获取数据 -->
    <select id="entity_get" resultMap="get-SysUserEntity-result">
        select
        a.id
        ,a.person_id
        ,a.login_code
        ,a.password
        ,a.salt
        ,a.last_login_time
        ,a.last_connection_time
        ,a.last_login_ip
        ,a.state
        ,a.remark
        ,a.sorts
        ,a.create_user_id
        ,a.create_time
        ,a.modify_user_id
        ,a.modify_time
        ,a.sts
        ,a.org_id
        ,a.company_id
        ,p.person_Name
        ,a.wx_user_id
        ,a.dd_user_id
        from
        sys_user a
        LEFT JOIN sys_person p on p.id =  a.person_id and p.sts = 'Y'
        where a.id = #{ id } and a.sts='Y'
    </select>
    <!-- 查询 采用==查询 -->
    <select id="entity_list_base" resultMap="get-SysUserEntity-result"
            parameterType="com.hzya.frame.sysnew.user.entity.SysUserEntity">
        select
        <include refid="SysUserEntity_Base_Column_List"/>
        from sys_user
        <trim prefix="where" prefixOverrides="and">
            <if test="id != null and id != ''">and id = #{id}</if>
            <if test="personId != null and personId != ''">and person_id = #{personId}</if>
            <if test="loginCode != null and loginCode != ''">and login_code = #{loginCode}</if>
            <if test="password != null and password != ''">and password = #{password}</if>
            <if test="salt != null and salt != ''">and salt = #{salt}</if>
            <if test="lastLoginTime != null">and last_login_time = #{lastLoginTime}</if>
            <if test="lastConnectionTime != null">and last_connection_time = #{lastConnectionTime}</if>
            <if test="lastLoginIp != null and lastLoginIp != ''">and last_login_ip = #{lastLoginIp}</if>
            <if test="state != null and state != ''">and state = #{state}</if>
            <if test="remark != null and remark != ''">and remark = #{remark}</if>
            <if test="sorts != null">and sorts = #{sorts}</if>
            <if test="create_user_id != null and create_user_id != ''">and create_user_id = #{create_user_id}</if>
            <if test="create_time != null">and create_time = #{create_time}</if>
            <if test="modify_user_id != null and modify_user_id != ''">and modify_user_id = #{modify_user_id}</if>
            <if test="modify_time != null">and modify_time = #{modify_time}</if>
            <if test="sts != null and sts != ''">and sts = #{sts}</if>
            <if test="org_id != null and org_id != ''">and org_id = #{org_id}</if>
            <if test="companyId != null and companyId != ''">and company_id = #{companyId}</if>
            <if test="ddUserId != null and ddUserId != ''">and dd_user_id = #{ddUserId}</if>
            <if test="wxUserId != null and wxUserId != ''">and wx_user_id = #{wxUserId}</if>
            and sts='Y'
        </trim>
        <if test=" sort == null or sort == ''.toString() ">order by sorts asc</if>
        <if test=" sort !='' and sort!=null and order !='' and order!=null ">order by ${sort} ${order}</if>
    </select>

    <!-- 查询符合条件的数量 -->
    <select id="entity_count" resultType="Integer" parameterType="com.hzya.frame.sysnew.user.entity.SysUserEntity">
        select count(1) from sys_user
        <trim prefix="where" prefixOverrides="and">
            <if test="id != null and id != ''">and id = #{id}</if>
            <if test="personId != null and personId != ''">and person_id = #{personId}</if>
            <if test="loginCode != null and loginCode != ''">and login_code = #{loginCode}</if>
            <if test="password != null and password != ''">and password = #{password}</if>
            <if test="salt != null and salt != ''">and salt = #{salt}</if>
            <if test="lastLoginTime != null">and last_login_time = #{lastLoginTime}</if>
            <if test="lastConnectionTime != null">and last_connection_time = #{lastConnectionTime}</if>
            <if test="lastLoginIp != null and lastLoginIp != ''">and last_login_ip = #{lastLoginIp}</if>
            <if test="state != null and state != ''">and state = #{state}</if>
            <if test="remark != null and remark != ''">and remark = #{remark}</if>
            <if test="sorts != null">and sorts = #{sorts}</if>
            <if test="create_user_id != null and create_user_id != ''">and create_user_id = #{create_user_id}</if>
            <if test="create_time != null">and create_time = #{create_time}</if>
            <if test="modify_user_id != null and modify_user_id != ''">and modify_user_id = #{modify_user_id}</if>
            <if test="modify_time != null">and modify_time = #{modify_time}</if>
            <if test="sts != null and sts != ''">and sts = #{sts}</if>
            <if test="org_id != null and org_id != ''">and org_id = #{org_id}</if>
            <if test="companyId != null and companyId != ''">and company_id = #{companyId}</if>
            and sts='Y'
        </trim>
    </select>

    <!-- 分页查询列表 采用like格式 -->
    <select id="entity_list_like" resultMap="get-SysUserEntity-result"
            parameterType="com.hzya.frame.sysnew.user.entity.SysUserEntity">
        select
        <include refid="SysUserEntity_Base_Column_List"/>
        from sys_user
        <trim prefix="where" prefixOverrides="and">
            <if test="id != null and id != ''">and id like concat('%',#{id},'%')</if>
            <if test="personId != null and personId != ''">and person_id like concat('%',#{personId},'%')</if>
            <if test="loginCode != null and loginCode != ''">and login_code like concat('%',#{loginCode},'%')</if>
            <if test="password != null and password != ''">and password like concat('%',#{password},'%')</if>
            <if test="salt != null and salt != ''">and salt like concat('%',#{salt},'%')</if>
            <if test="lastLoginTime != null">and last_login_time like concat('%',#{lastLoginTime},'%')</if>
            <if test="lastConnectionTime != null">and last_connection_time like concat('%',#{lastConnectionTime},'%')
            </if>
            <if test="lastLoginIp != null and lastLoginIp != ''">and last_login_ip like concat('%',#{lastLoginIp},'%')
            </if>
            <if test="state != null and state != ''">and state like concat('%',#{state},'%')</if>

            <if test="remark != null and remark != ''">and remark like concat('%',#{remark},'%')</if>
            <if test="sorts != null">and sorts like concat('%',#{sorts},'%')</if>
            <if test="create_user_id != null and create_user_id != ''">and create_user_id like
                concat('%',#{create_user_id},'%')
            </if>
            <if test="create_time != null">and create_time like concat('%',#{create_time},'%')</if>
            <if test="modify_user_id != null and modify_user_id != ''">and modify_user_id like
                concat('%',#{modify_user_id},'%')
            </if>
            <if test="modify_time != null">and modify_time like concat('%',#{modify_time},'%')</if>
            <if test="sts != null and sts != ''">and sts like concat('%',#{sts},'%')</if>
            <if test="org_id != null and org_id != ''">and org_id like concat('%',#{org_id},'%')</if>
            <if test="companyId != null and companyId != ''">and company_id like concat('%',#{companyId},'%')</if>
            and sts='Y'
        </trim>
        <if test=" sort == null or sort == ''.toString() ">order by sorts asc</if>
        <if test=" sort !='' and sort!=null and order !='' and order!=null ">order by ${sort} ${order}</if>
    </select>
    <select id="queryByLikePerson" resultMap="get-SysUserEntity-result"
            parameterType="com.hzya.frame.sysnew.user.entity.SysUserEntity">
        select
        a.id
        ,a.person_id
        ,a.login_code
        ,a.password
        ,a.salt
        ,a.last_login_time
        ,a.last_connection_time
        ,a.last_login_ip
        ,a.state
        ,a.remark
        ,a.sorts
        ,a.create_user_id
        ,a.create_time
        ,a.modify_user_id
        ,a.modify_time
        ,a.sts
        ,a.org_id
        ,a.company_id
        ,p.person_Name
        ,p.mobile_phone
        ,o.organ_name
        from
        sys_user a
        LEFT JOIN sys_person p on p.id =  a.person_id and p.sts = 'Y'
        LEFT JOIN sys_organ o on o.id =  p.organ_id and o.sts = 'Y'
        <trim prefix="where" prefixOverrides="and">
            <if test="id != null and id != ''">and a.id like concat('%',#{id},'%')</if>
            <if test="personId != null and personId != ''">and a.person_id like concat('%',#{personId},'%')</if>
            <if test="loginCode != null and loginCode != ''">and a.login_code like concat('%',#{loginCode},'%')</if>
            <if test="password != null and password != ''">and a.password like concat('%',#{password},'%')</if>
            <if test="salt != null and salt != ''">and a.salt like concat('%',#{salt},'%')</if>
            <if test="lastLoginTime != null">and a.last_login_time like concat('%',#{lastLoginTime},'%')</if>
            <if test="lastConnectionTime != null">and a.last_connection_time like concat('%',#{lastConnectionTime},'%')
            </if>
            <if test="lastLoginIp != null and lastLoginIp != ''">and a.last_login_ip like concat('%',#{lastLoginIp},'%')
            </if>
            <if test="state != null and state != ''">and a.state like concat('%',#{state},'%')</if>
            <if test="remark != null and remark != ''">and a.remark like concat('%',#{remark},'%')</if>
            <if test="sorts != null">and a.sorts like concat('%',#{sorts},'%')</if>
            <if test="create_user_id != null and create_user_id != ''">and a.create_user_id like
                concat('%',#{create_user_id},'%')
            </if>
            <if test="create_time != null">and a.create_time like concat('%',#{create_time},'%')</if>
            <if test="modify_user_id != null and modify_user_id != ''">and a.modify_user_id like
                concat('%',#{modify_user_id},'%')
            </if>
            <if test="modify_time != null">and a.modify_time like concat('%',#{modify_time},'%')</if>
            <if test="sts != null and sts != ''">and a.sts like concat('%',#{sts},'%')</if>
            <if test="org_id != null and org_id != ''">and a.org_id like concat('%',#{org_id},'%')</if>
            <if test="companyId != null and companyId != ''">and a.company_id like concat('%',#{companyId},'%')</if>
            <if test="organId != null and organId != ''">and p.organ_id  = #{organId}</if>
            and a.sts='Y'
        </trim>
        <if test=" sort == null or sort == ''.toString() ">order by a.sorts asc</if>
        <if test=" sort !='' and sort!=null and order !='' and order!=null ">order by ${sort} ${order}</if>
    </select>

    <!-- 查询列表 字段采用or格式 -->
    <select id="SysUserentity_list_or" resultMap="get-SysUserEntity-result"
            parameterType="com.hzya.frame.sysnew.user.entity.SysUserEntity">
        select
        <include refid="SysUserEntity_Base_Column_List"/>
        from sys_user
        <trim prefix="where" prefixOverrides="and">
            <if test="id != null and id != ''">or id = #{id}</if>
            <if test="personId != null and personId != ''">or person_id = #{personId}</if>
            <if test="loginCode != null and loginCode != ''">or login_code = #{loginCode}</if>
            <if test="password != null and password != ''">or password = #{password}</if>
            <if test="salt != null and salt != ''">or salt = #{salt}</if>
            <if test="lastLoginTime != null">or last_login_time = #{lastLoginTime}</if>
            <if test="lastConnectionTime != null">or last_connection_time = #{lastConnectionTime}</if>
            <if test="lastLoginIp != null and lastLoginIp != ''">or last_login_ip = #{lastLoginIp}</if>
            <if test="state != null and state != ''">or state = #{state}</if>
            <if test="remark != null and remark != ''">or remark = #{remark}</if>
            <if test="sorts != null">or sorts = #{sorts}</if>
            <if test="create_user_id != null and create_user_id != ''">or create_user_id = #{create_user_id}</if>
            <if test="create_time != null">or create_time = #{create_time}</if>
            <if test="modify_user_id != null and modify_user_id != ''">or modify_user_id = #{modify_user_id}</if>
            <if test="modify_time != null">or modify_time = #{modify_time}</if>
            <if test="sts != null and sts != ''">or sts = #{sts}</if>
            <if test="org_id != null and org_id != ''">or org_id = #{org_id}</if>
            <if test="companyId != null and companyId != ''">or company_id = #{companyId}</if>
            and sts='Y'
        </trim>
        <if test=" sort == null or sort == ''.toString()  ">order by sorts asc</if>
        <if test=" sort !='' and sort!=null and order !='' and order!=null ">order by ${sort} ${order}</if>
    </select>

    <!--新增所有列-->
    <insert id="entity_insert" parameterType="com.hzya.frame.sysnew.user.entity.SysUserEntity"
            >
        insert into sys_user(
        <trim suffix="" suffixOverrides=",">
            <if test="id != null and id != ''">id ,</if>
            <if test="personId != null and personId != ''">person_id ,</if>
            <if test="loginCode != null and loginCode != ''">login_code ,</if>
            <if test="password != null and password != ''">password ,</if>
            <if test="salt != null and salt != ''">salt ,</if>
            <if test="lastLoginTime != null">last_login_time ,</if>
            <if test="lastConnectionTime != null">last_connection_time ,</if>
            <if test="lastLoginIp != null and lastLoginIp != ''">last_login_ip ,</if>
            <if test="state != null and state != ''">state ,</if>
            <if test="remark != null and remark != ''">remark ,</if>
            <if test="sorts != null">sorts ,</if>
            <if test="create_user_id != null and create_user_id != ''">create_user_id ,</if>
            <if test="create_time != null">create_time ,</if>
            <if test="modify_user_id != null and modify_user_id != ''">modify_user_id ,</if>
            <if test="modify_time != null">modify_time ,</if>
            <if test="sts != null and sts != ''">sts ,</if>
            <if test="org_id != null and org_id != ''">org_id ,</if>
            <if test="companyId != null and companyId != ''">company_id ,</if>
            <if test="sts == null ">sts,</if>
        </trim>
        )values(
        <trim suffix="" suffixOverrides=",">
            <if test="id != null and id != ''">#{id} ,</if>
            <if test="personId != null and personId != ''">#{personId} ,</if>
            <if test="loginCode != null and loginCode != ''">#{loginCode} ,</if>
            <if test="password != null and password != ''">#{password} ,</if>
            <if test="salt != null and salt != ''">#{salt} ,</if>
            <if test="lastLoginTime != null">#{lastLoginTime} ,</if>
            <if test="lastConnectionTime != null">#{lastConnectionTime} ,</if>
            <if test="lastLoginIp != null and lastLoginIp != ''">#{lastLoginIp} ,</if>
            <if test="state != null and state != ''">#{state} ,</if>
            <if test="remark != null and remark != ''">#{remark} ,</if>
            <if test="sorts != null">#{sorts} ,</if>
            <if test="create_user_id != null and create_user_id != ''">#{create_user_id} ,</if>
            <if test="create_time != null">#{create_time} ,</if>
            <if test="modify_user_id != null and modify_user_id != ''">#{modify_user_id} ,</if>
            <if test="modify_time != null">#{modify_time} ,</if>
            <if test="sts != null and sts != ''">#{sts} ,</if>
            <if test="org_id != null and org_id != ''">#{org_id} ,</if>
            <if test="companyId != null and companyId != ''">#{companyId} ,</if>
            <if test="sts == null ">'Y',</if>
        </trim>
        )
    </insert>
    <!-- 批量新增 -->
    <insert id="entityInsertBatch"  >
        insert into sys_user(person_id, login_code, password, salt, last_login_time, last_connection_time,
        last_login_ip, state, remark, sorts, create_user_id, create_time, modify_user_id, modify_time, sts, org_id,
        company_id, sts)
        values
        <foreach collection="entities" item="entity" separator=",">
            (#{entity.personId},#{entity.loginCode},#{entity.password},#{entity.salt},#{entity.lastLoginTime},#{entity.lastConnectionTime},#{entity.lastLoginIp},#{entity.state},#{entity.remark},#{entity.sorts},#{entity.create_user_id},#{entity.create_time},#{entity.modify_user_id},#{entity.modify_time},#{entity.sts},#{entity.org_id},#{entity.companyId},
            'Y')
        </foreach>
    </insert>
    <!-- 批量新增或者修改-->
    <insert id="entityInsertOrUpdateBatch"  >
        insert into sys_user(person_id, login_code, password, salt, last_login_time, last_connection_time,
        last_login_ip, state, remark, sorts, create_user_id, create_time, modify_user_id, modify_time, sts, org_id,
        company_id)
        values
        <foreach collection="entities" item="entity" separator=",">
            (#{entity.personId},#{entity.loginCode},#{entity.password},#{entity.salt},#{entity.lastLoginTime},#{entity.lastConnectionTime},#{entity.lastLoginIp},#{entity.state},#{entity.remark},#{entity.sorts},#{entity.create_user_id},#{entity.create_time},#{entity.modify_user_id},#{entity.modify_time},#{entity.sts},#{entity.org_id},#{entity.companyId})
        </foreach>
        on duplicate key update
        person_id = values(person_id),
        login_code = values(login_code),
        password = values(password),
        salt = values(salt),
        last_login_time = values(last_login_time),
        last_connection_time = values(last_connection_time),
        last_login_ip = values(last_login_ip),
        state = values(state),
        remark = values(remark),
        sorts = values(sorts),
        create_user_id = values(create_user_id),
        create_time = values(create_time),
        modify_user_id = values(modify_user_id),
        modify_time = values(modify_time),
        sts = values(sts),
        org_id = values(org_id),
        company_id = values(company_id)
    </insert>
    <!--通过主键修改方法-->
    <update id="entity_update" parameterType="com.hzya.frame.sysnew.user.entity.SysUserEntity">
        update sys_user set
        <trim suffix="" suffixOverrides=",">
            <if test="personId != null and personId != ''">person_id = #{personId},</if>
            <if test="loginCode != null and loginCode != ''">login_code = #{loginCode},</if>
            <if test="password != null and password != ''">password = #{password},</if>
            <if test="salt != null and salt != ''">salt = #{salt},</if>
            <if test="lastLoginTime != null">last_login_time = #{lastLoginTime},</if>
            <if test="lastConnectionTime != null">last_connection_time = #{lastConnectionTime},</if>
            <if test="lastLoginIp != null and lastLoginIp != ''">last_login_ip = #{lastLoginIp},</if>
            <if test="state != null and state != ''">state = #{state},</if>
            <if test="remark != null and remark != ''">remark = #{remark},</if>
            <if test="sorts != null">sorts = #{sorts},</if>
            <if test="create_user_id != null and create_user_id != ''">create_user_id = #{create_user_id},</if>
            <if test="create_time != null">create_time = #{create_time},</if>
            <if test="modify_user_id != null and modify_user_id != ''">modify_user_id = #{modify_user_id},</if>
            <if test="modify_time != null">modify_time = #{modify_time},</if>
            <if test="sts != null and sts != ''">sts = #{sts},</if>
            <if test="org_id != null and org_id != ''">org_id = #{org_id},</if>
            <if test="companyId != null and companyId != ''">company_id = #{companyId},</if>
            <if test="ddUserId != null and ddUserId != ''">dd_user_id = #{ddUserId},</if>
            <if test="wxUserId != null and wxUserId != ''">wx_user_id = #{wxUserId},</if>
        </trim>
        where id = #{id}
    </update>
    <!-- 逻辑删除 -->
    <update id="entity_logicDelete" parameterType="com.hzya.frame.sysnew.user.entity.SysUserEntity">
update sys_user  set sts= 'N' ,modify_time = #{modify_time},modify_user_id = #{modify_user_id}
where id = #{id}
</update>
    <!-- 多条件逻辑删除 -->
    <update id="entity_logicDelete_Multi_Condition" parameterType="com.hzya.frame.sysnew.user.entity.SysUserEntity">
        update sys_user set sts= 'N' ,modify_time = #{modify_time},modify_user_id = #{modify_user_id}
        <trim prefix="where" prefixOverrides="and">
            <if test="id != null and id != ''">and id = #{id}</if>
            <if test="personId != null and personId != ''">and person_id = #{personId}</if>
            <if test="loginCode != null and loginCode != ''">and login_code = #{loginCode}</if>
            <if test="password != null and password != ''">and password = #{password}</if>
            <if test="salt != null and salt != ''">and salt = #{salt}</if>
            <if test="lastLoginTime != null">and last_login_time = #{lastLoginTime}</if>
            <if test="lastConnectionTime != null">and last_connection_time = #{lastConnectionTime}</if>
            <if test="lastLoginIp != null and lastLoginIp != ''">and last_login_ip = #{lastLoginIp}</if>
            <if test="state != null and state != ''">and state = #{state}</if>
            <if test="remark != null and remark != ''">and remark = #{remark}</if>
            <if test="sorts != null">and sorts = #{sorts}</if>
            <if test="sts != null and sts != ''">and sts = #{sts}</if>
            <if test="companyId != null and companyId != ''">and company_id = #{companyId}</if>
            and sts='Y'
        </trim>
    </update>
    <!--通过主键删除-->
    <delete id="entity_delete">
    delete from sys_user where id = #{id}
</delete>

</mapper>

