<?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.cool.store.mapper.PointAuditRecordMapper">
  <resultMap id="BaseResultMap" type="com.cool.store.entity.PointAuditRecordDO">
    <id column="id" jdbcType="BIGINT" property="id" />
    <result column="point_id" jdbcType="BIGINT" property="pointId" />
    <result column="node_no" jdbcType="INTEGER" property="nodeNo" />
    <result column="cycle_count" jdbcType="TINYINT" property="cycleCount" />
    <result column="action_remark" jdbcType="VARCHAR" property="actionRemark" />
    <result column="handler_user_id" jdbcType="VARCHAR" property="handlerUserId" />
    <result column="handler_user_ids" jdbcType="VARCHAR" property="handlerUserIds" />
    <result column="receive_task_time" jdbcType="TIMESTAMP" property="receiveTaskTime" />
    <result column="finish_task_time" jdbcType="TIMESTAMP" property="finishTaskTime" />
    <result column="audit_status" jdbcType="TINYINT" property="auditStatus" />
    <result column="sign_time" jdbcType="TIMESTAMP" property="signTime" />
    <result column="sign_address" jdbcType="VARCHAR" property="signAddress" />
    <result column="picture_url" jdbcType="VARCHAR" property="pictureUrl" />
    <result column="reason" jdbcType="VARCHAR" property="reason" />
    <result column="deleted" jdbcType="BIT" property="deleted" />
    <result column="create_time" jdbcType="TIMESTAMP" property="createTime" />
    <result column="update_time" jdbcType="TIMESTAMP" property="updateTime" />
  </resultMap>

  <insert id="batchInsertSelective">
    <foreach collection="addList" item="item" separator=";">
      insert into xfsg_point_audit_record
      <trim prefix="(" suffix=")" suffixOverrides=",">
        <if test="item.pointId != null">
          point_id,
        </if>
        <if test="item.nodeNo != null">
          node_no,
        </if>
        <if test="item.cycleCount != null">
          cycle_count,
        </if>
        <if test="item.actionRemark != null">
          action_remark,
        </if>
        <if test="item.handlerUserId != null">
          handler_user_id,
        </if>
        <if test="item.handlerUserIds != null">
          handler_user_ids,
        </if>
        <if test="item.receiveTaskTime != null">
          receive_task_time,
        </if>
        <if test="item.finishTaskTime != null">
          finish_task_time,
        </if>
        <if test="item.auditStatus != null">
          audit_status,
        </if>
        <if test="item.signTime != null">
          sign_time,
        </if>
        <if test="item.signAddress != null">
          sign_address,
        </if>
        <if test="item.pictureUrl != null">
          picture_url,
        </if>
        <if test="item.reason != null">
          reason,
        </if>
      </trim>
      <trim prefix="values (" suffix=")" suffixOverrides=",">
        <if test="item.pointId != null">
          #{item.pointId},
        </if>
        <if test="item.nodeNo != null">
          #{item.nodeNo},
        </if>
        <if test="item.cycleCount != null">
          #{item.cycleCount},
        </if>
        <if test="item.actionRemark != null">
          #{item.actionRemark},
        </if>
        <if test="item.handlerUserId != null">
          #{item.handlerUserId},
        </if>
        <if test="item.handlerUserIds != null">
          #{item.handlerUserIds},
        </if>
        <if test="item.receiveTaskTime != null">
          #{item.receiveTaskTime},
        </if>
        <if test="item.finishTaskTime != null">
          #{item.finishTaskTime},
        </if>
        <if test="item.auditStatus != null">
          #{item.auditStatus},
        </if>
        <if test="item.signTime != null">
          #{item.signTime},
        </if>
        <if test="item.signAddress != null">
          #{item.signAddress},
        </if>
        <if test="item.pictureUrl != null">
          #{item.pictureUrl},
        </if>
        <if test="item.reason != null">
          #{item.reason},
        </if>
      </trim>
    </foreach>
  </insert>

  <select id="getPointAuditRecord" resultMap="BaseResultMap">
    select
      id, point_id, node_no, cycle_count, action_remark, handler_user_id, handler_user_ids, receive_task_time, finish_task_time, audit_status, sign_time, sign_address, picture_url, reason
    from
      xfsg_point_audit_record
    where
      point_id = #{pointId} and deleted = 0
      <if test="cycleCount != null">
        and cycle_count = #{cycleCount}
      </if>
    order by node_no asc
  </select>
  <select id="getPointAllAuditRecord" resultMap="BaseResultMap">
    select
      id, point_id, node_no, cycle_count, action_remark, handler_user_id, handler_user_ids, receive_task_time, finish_task_time, audit_status, sign_time, sign_address, picture_url, reason
    from
      xfsg_point_audit_record
    where
      point_id = #{pointId} and deleted = 0
    order by cycle_count asc, node_no asc
  </select>

  <update id="deletePointAuditRecord">
    update xfsg_point_audit_record set deleted = 1 where point_id = #{pointId} and cycle_count = #{cycleCount} and audit_status = 0
  </update>

  <select id="getPointSubmitAuditTime" resultMap="BaseResultMap">
    select
      point_id, receive_task_time, finish_task_time
    from
      xfsg_point_audit_record
    where node_no = 0 and point_id in
    <foreach collection="pointIds" item="pointId" open="(" close=")" separator=",">
      #{pointId}
    </foreach>
  </select>

</mapper>