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

	<resultMap id="tGzPushEntryMap" type="com.yifu.cloud.plus.v1.yifu.archives.vo.TGzPushEntrySearchVo">
		<id property="id" column="id"/>
		<result property="bizId" column="biz_id"/>
		<result property="taskType" column="task_type"/>
		<result property="pushStatus" column="push_status"/>
		<result property="pushTime" column="push_time"/>
		<result property="failReason" column="fail_reason"/>
		<result property="pushData" column="push_data"/>
		<result property="responseData" column="response_data"/>
		<result property="delFlag" column="del_flag"/>
		<result property="name" column="name"/>
		<result property="nationalId" column="national_id"/>
		<result property="createTime" column="create_time"/>
		<result property="createBy" column="create_by"/>
		<result property="createName" column="create_name"/>
		<result property="updateBy" column="update_by"/>
		<result property="updateTime" column="update_time"/>
	</resultMap>
	<sql id="Base_Column_List">
                a.id,
                a.biz_id,
                a.task_type,
                a.push_status,
                a.push_time,
                a.fail_reason,
                a.push_data,
                a.response_data,
                a.del_flag,
                a.name,
                a.national_id,
                a.create_time,
                a.create_by,
                a.create_name,
                a.update_by,
                a.update_time
    </sql>
	<sql id="tGzPushEntry_where">
		<if test="tGzPushEntry != null">
			<if test="tGzPushEntry.id != null and tGzPushEntry.id.trim() != ''">
				AND a.id = #{tGzPushEntry.id}
			</if>
			<if test="tGzPushEntry.bizId != null and tGzPushEntry.bizId.trim() != ''">
				AND a.biz_id = #{tGzPushEntry.bizId}
			</if>
			<if test="tGzPushEntry.taskType != null and tGzPushEntry.taskType.trim() != ''">
				AND a.task_type = #{tGzPushEntry.taskType}
			</if>
			<if test="tGzPushEntry.pushStatus != null and tGzPushEntry.pushStatus.trim() != ''">
				AND a.push_status = #{tGzPushEntry.pushStatus}
			</if>
			<if test="tGzPushEntry.pushStatusArray != null and tGzPushEntry.pushStatusArray.length > 0">
				AND a.push_status in
				<foreach item="item" index="index" collection="tGzPushEntry.pushStatusArray" open="(" separator="," close=")">
					'${item}'
				</foreach>
			</if>
			<if test="tGzPushEntry.pushTime != null">
				AND a.push_time = #{tGzPushEntry.pushTime}
			</if>
			<!--查询推送时间-->
			<if test="tGzPushEntry.createTimeStart != null ">
				AND a.push_time &gt;= #{tGzPushEntry.createTimeStart}
			</if>
			<if test="tGzPushEntry.createTimeEnd != null ">
				AND a.push_time &lt;= #{tGzPushEntry.createTimeEnd}
			</if>
			<if test="tGzPushEntry.failReason != null and tGzPushEntry.failReason.trim() != ''">
				AND a.fail_reason = #{tGzPushEntry.failReason}
			</if>
			<if test="tGzPushEntry.pushData != null and tGzPushEntry.pushData.trim() != ''">
				AND a.push_data = #{tGzPushEntry.pushData}
			</if>
			<if test="tGzPushEntry.responseData != null and tGzPushEntry.responseData.trim() != ''">
				AND a.response_data = #{tGzPushEntry.responseData}
			</if>
			<if test="tGzPushEntry.delFlag != null and tGzPushEntry.delFlag.trim() != ''">
				AND a.del_flag = #{tGzPushEntry.delFlag}
			</if>
			<if test="tGzPushEntry.name != null and tGzPushEntry.name.trim() != ''">
				AND a.name like concat('%',#{tGzPushEntry.name},'%')
			</if>
			<if test="tGzPushEntry.nationalId != null and tGzPushEntry.nationalId.trim() != ''">
				AND a.national_id like concat('%',#{tGzPushEntry.nationalId},'%')
			</if>
			<if test="tGzPushEntry.createTime != null">
				AND a.create_time = #{tGzPushEntry.createTime}
			</if>
			<if test="tGzPushEntry.createBy != null and tGzPushEntry.createBy.trim() != ''">
				AND a.create_by = #{tGzPushEntry.createBy}
			</if>
			<if test="tGzPushEntry.createName != null and tGzPushEntry.createName.trim() != ''">
				AND a.create_name = #{tGzPushEntry.createName}
			</if>
			<if test="tGzPushEntry.updateBy != null and tGzPushEntry.updateBy.trim() != ''">
				AND a.update_by = #{tGzPushEntry.updateBy}
			</if>
			<if test="tGzPushEntry.updateTime != null">
				AND a.update_time = #{tGzPushEntry.updateTime}
			</if>
		</if>
	</sql>
	<!--tGzPushEntry简单分页查询-->
	<select id="getTGzPushEntryPage" resultMap="tGzPushEntryMap">
		SELECT
		<include refid="Base_Column_List"/>
		FROM t_gz_push_entry a
		<where>
			a.del_flag = '0'
			<include refid="tGzPushEntry_where"/>
		</where>
		ORDER by a.biz_id asc,a.create_time asc,a.id asc
	</select>


	<!--取消OFFER，同步取消任务-->
	<select id="getTGzPushEntryListForStatus" resultType="java.lang.String">
		SELECT
			a.task_type
		FROM t_gz_push_entry a
		where a.del_flag = '0' and a.biz_id = #{bizId} and a.push_status != '0'
		ORDER by a.biz_id asc,a.create_time asc,a.id asc
	</select>

	<!--取消OFFER，同步取消任务-->
	<update id="deleteByBizId" >
		update t_gz_push_entry a
		set a.del_flag = '1'
		where a.del_flag = '0' and a.biz_id = #{bizId} and a.push_status != '0'
	</update>

</mapper>
