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

  <resultMap id="tAutoMainRelMap" type="com.yifu.cloud.plus.v1.yifu.archives.entity.TAutoMainRel">
    <id property="id" column="ID"/>
    <result property="deptNo" column="DEPT_NO"/>
    <result property="deptId" column="DEPT_ID"/>
    <result property="ruleUpdateTime" column="RULE_UPDATE_TIME"/>
    <result property="ruleUpdatePerson" column="RULE_UPDATE_PERSON"/>
    <result property="createBy" column="CREATE_BY"/>
    <result property="createName" column="CREATE_NAME"/>
    <result property="createTime" column="CREATE_TIME"/>
    <result property="updateBy" column="UPDATE_BY"/>
    <result property="updateTime" column="UPDATE_TIME"/>
	<result property="postFlag" column="POST_FLAG"/>
	<result property="autoFlag" column="AUTO_FLAG"/>
  </resultMap>
    <sql id="Base_Column_List">
                a.ID,
                a.dept_NO,
                a.dept_ID,
                a.RULE_UPDATE_TIME,
                a.RULE_UPDATE_PERSON,
                a.CREATE_BY,
                a.CREATE_NAME,
                a.CREATE_TIME,
                a.UPDATE_BY,
                a.UPDATE_TIME,a.post_flag,a.AUTO_FLAG
    </sql>
    <sql id="tAutoMainRel_where">
        <if test="tAutoMainRel != null">
                    <if test="tAutoMainRel.id != null and tAutoMainRel.id.trim() != ''">
                        AND a.ID = #{tAutoMainRel.id}
                    </if>
					<if test="tAutoMainRel.autoFlag != null and tAutoMainRel.autoFlag.trim() != ''">
						AND a.AUTO_FLAG = #{tAutoMainRel.autoFlag}
					</if>
                    <if test="tAutoMainRel.deptNo != null and tAutoMainRel.deptNo.trim() != ''">
                        AND a.DEPT_NO =  #{tAutoMainRel.deptNo}
                    </if>
                    <if test="tAutoMainRel.deptId != null and tAutoMainRel.deptId.trim() != ''">
                        AND a.DEPT_ID = #{tAutoMainRel.deptId}
                    </if>
                    <if test="tAutoMainRel.ruleUpdateTime != null">
                        AND a.RULE_UPDATE_TIME = #{tAutoMainRel.ruleUpdateTime}
                    </if>
                    <if test="tAutoMainRel.ruleUpdatePerson != null and tAutoMainRel.ruleUpdatePerson.trim() != ''">
                        AND a.RULE_UPDATE_PERSON = #{tAutoMainRel.ruleUpdatePerson}
                    </if>
                    <if test="tAutoMainRel.createBy != null and tAutoMainRel.createBy.trim() != ''">
                        AND a.CREATE_BY = #{tAutoMainRel.createBy}
                    </if>
                    <if test="tAutoMainRel.createName != null and tAutoMainRel.createName.trim() != ''">
                        AND a.CREATE_NAME = #{tAutoMainRel.createName}
                    </if>
                    <if test="tAutoMainRel.createTime != null">
                        AND a.CREATE_TIME = #{tAutoMainRel.createTime}
                    </if>
                    <if test="tAutoMainRel.updateBy != null and tAutoMainRel.updateBy.trim() != ''">
                        AND a.UPDATE_BY = #{tAutoMainRel.updateBy}
                    </if>
                    <if test="tAutoMainRel.updateTime != null">
                        AND a.UPDATE_TIME = #{tAutoMainRel.updateTime}
                    </if>
					<if test="tAutoMainRel.authSql != null and tAutoMainRel.authSql.trim() != ''">
						${tAutoMainRel.authSql}
					</if>
        </if>
    </sql>
    <!--tAutoMainRel简单分页查询-->
    <select id="getTAutoMainRelPage" resultType="com.yifu.cloud.plus.v1.yifu.archives.entity.TAutoMainRel">
        SELECT
		a.ID,
		a.dept_ID,
		a.RULE_UPDATE_TIME,
		a.RULE_UPDATE_PERSON,
		a.CREATE_BY,
		a.CREATE_NAME,
		a.CREATE_TIME,
		a.UPDATE_BY,
		a.UPDATE_TIME,a.post_flag
        ,b.DEPART_NAME,IFNULL(b.cs_name,'') csUserName,b.DEPART_NO dept_NO,IF(b.STOP_FLAG='0','是','否') STOP_FLAG
        ,a.AUTO_FLAG
        FROM t_auto_main_rel a
        left join  t_settle_domain b on a.DEPT_ID = b.id
        <where>
            1=1
			<if test="tAutoMainRel != null">
				<if test="tAutoMainRel.departName != null and tAutoMainRel.departName.trim() != ''">
					AND b.DEPART_NAME  like concat('%',#{tAutoMainRel.departName} ,'%')
				</if>
				<if test="tAutoMainRel.csUserName != null and tAutoMainRel.csUserName.trim() != ''">
					AND b.cs_name  like concat('%',#{tAutoMainRel.csUserName} ,'%')
				</if>
			</if>
            <include refid="tAutoMainRel_where"/>
			order  by a.CREATE_TIME desc
        </where>
    </select>

	<!-- 获取全量自动化项目与商险续保周期 -->
    <select id="getAutoDeptMap" resultType="com.yifu.cloud.plus.v1.yifu.archives.entity.TAutoMainRel">
		SELECT
		       ifnull(r.RENEWAL_PERIOD,1) id,d.DEPT_NO deptNo,IFNULL(b.cs_name,'') csUserName,IFNULL(b.cs_login_name,'') csLoginName
		FROM t_auto_main_rel d
		left join t_auto_insur_rule_info r on r.MAIN_ID=d.id
		left join  t_settle_domain b on d.DEPT_ID = b.id
    </select>

	<!-- 获取全量自动化项目编码 -->
	<select id="getAutoDeptNo" resultType="java.lang.String">
		SELECT
			d.DEPT_NO
		FROM t_auto_main_rel d
	</select>


	<select id="noPageCountDiy" resultType="java.lang.Long">
		SELECT
		count(1)
		FROM t_auto_main_rel a
		left join  t_settle_domain b on a.DEPT_ID = b.id
		<where>
			1=1
			<if test="tAutoMainRel != null">
				<if test="tAutoMainRel.departName != null and tAutoMainRel.departName.trim() != ''">
					AND b.DEPART_NAME  like concat('%',#{tAutoMainRel.departName} ,'%')
				</if>
				<if test="tAutoMainRel.csUserName != null and tAutoMainRel.csUserName.trim() != ''">
					AND b.cs_name  like concat('%',#{tAutoMainRel.csUserName} ,'%')
				</if>
			</if>
			<include refid="tAutoMainRel_where"/>
		</where>
	</select>

	<select id="noPageDiy" resultType="com.yifu.cloud.plus.v1.yifu.archives.vo.TAutoMainRelExportVo">
		SELECT
		a.RULE_UPDATE_TIME,
		a.RULE_UPDATE_PERSON,
		b.DEPART_NAME,
		IFNULL(b.cs_name,'') csUserName,
		b.DEPART_NO dept_NO,
		IF(b.STOP_FLAG='0','是','否') STOP_FLAG
		FROM t_auto_main_rel a
		left join  t_settle_domain b on a.DEPT_ID = b.id
		<where>
			1=1
			<if test="tAutoMainRel != null">
				<if test="tAutoMainRel.departName != null and tAutoMainRel.departName.trim() != ''">
					AND b.DEPART_NAME  like concat('%',#{tAutoMainRel.departName} ,'%')
				</if>
				<if test="tAutoMainRel.csUserName != null and tAutoMainRel.csUserName.trim() != ''">
					AND b.cs_name  like concat('%',#{tAutoMainRel.csUserName} ,'%')
				</if>
			</if>
			<include refid="tAutoMainRel_where"/>
			order  by a.CREATE_TIME desc
		</where>
	</select>
</mapper>
