<?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="cn.iocoder.yudao.module.knowledge.mapper.TViolationMapper" >
  <resultMap id="BaseResultMap" type="cn.iocoder.yudao.module.knowledge.entity.TViolation" >
    <id property="id" column="id" jdbcType="BIGINT" />
    <result property="title" column="filename" jdbcType="VARCHAR" />
    <result property="type" column="type" jdbcType="VARCHAR" />
    <result property="violator" column="violator" jdbcType="VARCHAR" />
    <result property="descr" column="descr" jdbcType="VARCHAR" />
    <result property="code" column="violation_code" jdbcType="VARCHAR" />
    <result property="violationTime" column="violation_time" jdbcType="TIMESTAMP" />
    <result property="lastPushTime" column="last_push_time" jdbcType="TIMESTAMP" />

    <result property="violationB" column="file_url" jdbcType="VARCHAR" />
  </resultMap>

  <insert id="saveRelatedImgInfo" parameterType="List">
    INSERT INTO t_violation_image (
      filename,
      file_size,
      file_url,
      sort,
      violation_code,
    )
    VALUES
    <foreach collection="paramList" item="item" separator=",">
      (
      #{item.filename},
      #{item.fileSize},
      #{item.fileUrl},
      #{item.sort},
      #{item.violationCode}
      )
    </foreach>

  </insert>

  <select id="getListPage" resultType="cn.iocoder.yudao.module.knowledge.entity.TViolation">
    SELECT
      id AS id,
      CODE AS CODE,
      title AS title,
      type AS type,
      violator AS violator,
      descr AS descr,
      code AS code,
      violation_time AS violationTime,
      last_push_time AS lastPushTime,
      creator AS creator,
      violation_b AS violationB,
      dept_id AS deptId,
      identity_id AS identityId
    FROM t_violation
    WHERE
        deleted = 0
    <if test="dto.title != '' and dto.title != null">
      AND `title` LIKE CONCAT( '%',#{dto.title}, '%')
    </if>
    <if test=" dto.violationTime != null">
      AND DATE(violation_time) = #{dto.violationTime}
    </if>
    <if test="dto.bgnTime!=null">
      AND (violation_time >= date_format(#{dto.bgnTime},'%y-%m-%d 00:00:00') and violation_time <![CDATA[<=]]> date_format(#{dto.endTime},'%y-%m-%d 23:59:59'))
    </if>
    ORDER BY
        violation_time DESC
  </select>

  <select id="appFindAll" resultType="cn.iocoder.yudao.module.knowledge.entity.TViolation">
    SELECT
    id AS id,
    CODE AS CODE,
    title AS title,
    type AS type,
    violator AS violator,
    descr AS descr,
    code AS code,
    violation_time AS violationTime,
    last_push_time AS lastPushTime,
    creator AS creator,
    violation_b AS violationB,
    dept_id AS deptId,
    identity_id AS identityId
    FROM t_violation
    WHERE
    deleted = 0
    <if test="dto.title != '' and dto.title != null">
      AND `title` LIKE CONCAT( '%',#{dto.title}, '%')
    </if>
    <if test=" dto.violationTime != null">
      AND DATE(violation_time) = #{dto.violationTime}
    </if>
    <if test=" dto.violator != null">
      AND `violator` LIKE CONCAT( '%',#{dto.violator}, '%')
    </if>
    <if test="dto.bgnTime!=null">
      AND (violation_time >= date_format(#{dto.bgnTime},'%y-%m-%d 00:00:00') and violation_time <![CDATA[<=]]> date_format(#{dto.endTime},'%y-%m-%d 23:59:59'))
    </if>
    ORDER BY
    violation_time DESC
  </select>


</mapper>
