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

  <resultMap id="tWorkHandlerInfoMap" type="com.yifu.cloud.plus.v1.yifu.archives.entity.TWorkHandlerInfo">
    <id property="id" column="ID"/>
    <result property="departNo" column="DEPART_NO"/>
    <result property="departName" column="DEPART_NAME"/>
    <result property="empName" column="EMP_NAME"/>
    <result property="empIdcard" column="EMP_IDCARD"/>
    <result property="deleteFlag" column="DELETE_FLAG"/>
    <result property="infoFrom" column="INFO_FROM"/>
    <result property="operUser" column="OPER_USER"/>
    <result property="operTime" column="OPER_TIME"/>
    <result property="operResult" column="OPER_RESULT"/>
    <result property="operInfo" column="OPER_INFO"/>
    <result property="reason" column="REASON"/>
  </resultMap>

    <sql id="Base_Column_List">
                a.ID,
                a.DEPART_NO,
                a.DEPART_NAME,
                a.EMP_NAME,
                a.EMP_IDCARD,
                a.DELETE_FLAG,
                a.INFO_FROM,
                a.OPER_USER,
                a.OPER_TIME,
                a.OPER_RESULT,
                a.OPER_INFO,
                a.REASON
    </sql>
	<resultMap id="tWorkHandlerInfoVoMap" type="com.yifu.cloud.plus.v1.yifu.archives.vo.TWorkHandlerInfoVo">
		<result property="departNo" column="DEPART_NO"/>
		<result property="departName" column="DEPART_NAME"/>
		<result property="empName" column="EMP_NAME"/>
		<result property="empIdcard" column="EMP_IDCARD"/>
		<result property="infoFrom" column="INFO_FROM"/>
		<result property="operUser" column="OPER_USER"/>
		<result property="operTime" column="OPER_TIME"/>
		<result property="operResult" column="OPER_RESULT"/>
		<result property="operInfo" column="OPER_INFO"/>
		<result property="reason" column="REASON"/>
	</resultMap>
	<sql id="tWorkHandlerInfo_where">
        <if test="tWorkHandlerInfo != null">
                    <if test="tWorkHandlerInfo.departNo != null and tWorkHandlerInfo.departNo.trim() != ''">
                        AND a.DEPART_NO = #{tWorkHandlerInfo.departNo}
                    </if>
                    <if test="tWorkHandlerInfo.departName != null and tWorkHandlerInfo.departName.trim() != ''">
                        AND a.DEPART_NAME = #{tWorkHandlerInfo.departName}
                    </if>
                    <if test="tWorkHandlerInfo.empName != null and tWorkHandlerInfo.empName.trim() != ''">
                        AND a.EMP_NAME like concat('%', #{tWorkHandlerInfo.empName} ,'%')
                    </if>
                    <if test="tWorkHandlerInfo.empIdcard != null and tWorkHandlerInfo.empIdcard.trim() != ''">
                        AND a.EMP_IDCARD like concat('%', #{tWorkHandlerInfo.empIdcard} ,'%')
                    </if>
                    <if test="tWorkHandlerInfo.infoFrom != null and tWorkHandlerInfo.infoFrom.trim() != ''">
                        AND a.INFO_FROM = #{tWorkHandlerInfo.infoFrom}
                    </if>
                    <if test="tWorkHandlerInfo.operUser != null and tWorkHandlerInfo.operUser.trim() != ''">
                        AND a.OPER_USER like concat('%', #{tWorkHandlerInfo.operUser} ,'%')
                    </if>
					<if test="tWorkHandlerInfo.startTime != null and tWorkHandlerInfo.startTime.trim() != '' ">
						AND a.OPER_TIME   <![CDATA[ >= ]]>  concat(#{tWorkHandlerInfo.startTime}, ' 00:00:00')
					</if>
					<if test="tWorkHandlerInfo.endTime != null and tWorkHandlerInfo.endTime.trim() != '' ">
						AND a.OPER_TIME <![CDATA[ <= ]]> concat(#{tWorkHandlerInfo.endTime}, ' 23:59:59')
					</if>
                    <if test="tWorkHandlerInfo.operResult != null and tWorkHandlerInfo.operResult.trim() != ''">
                        AND a.OPER_RESULT = #{tWorkHandlerInfo.operResult}
                    </if>
        </if>
    </sql>
    <!--tWorkHandlerInfo简单分页查询-->
    <select id="getTWorkHandlerInfoPage" resultMap="tWorkHandlerInfoMap">
        SELECT
        <include refid="Base_Column_List"/>
        FROM t_work_handler_info a
        <where>
            1=1
            <include refid="tWorkHandlerInfo_where"/>
        </where>
		order by a.OPER_TIME desc
    </select>

	<select id="noPageCountDiy" resultType="java.lang.Integer">
		SELECT
		count(1)
		FROM t_work_handler_info a
		<where>
			1=1
			<include refid="tWorkHandlerInfo_where"/>
		</where>
	</select>

	<select id="noPageDiy" resultMap="tWorkHandlerInfoVoMap">
		SELECT
			a.DEPART_NO,
			a.DEPART_NAME,
			a.EMP_NAME,
			a.EMP_IDCARD,
			a.INFO_FROM,
			a.OPER_USER,
			a.OPER_TIME,
			CASE WHEN a.OPER_RESULT=0 THEN "未执行"
			WHEN a.OPER_RESULT =1 THEN "部分成功"
			WHEN a.OPER_RESULT =2 THEN "全部成功"
			ELSE a.OPER_RESULT END as "OPER_RESULT",
			a.OPER_INFO,
			a.REASON
		FROM t_work_handler_info a
		<where>
			1=1
			<include refid="tWorkHandlerInfo_where"/>
		</where>
		order by a.OPER_TIME desc
		limit #{tWorkHandlerInfo.limitStart},#{tWorkHandlerInfo.limitEnd}
	</select>
</mapper>