<?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.platform.yijia.dao.StationOilGunMapper">
  <resultMap id="BaseResultMap" type="com.platform.yijia.pojo.StationOilGun">
    <id column="oil_gun_id" jdbcType="INTEGER" property="oilGunId" />
    <result column="oil_gun_no" jdbcType="VARCHAR" property="oilGunNo" />
    <result column="oil_name" jdbcType="VARCHAR" property="oilName" />
    <result column="oil_price" jdbcType="DECIMAL" property="oilPrice" />
    <result column="station_id" jdbcType="INTEGER" property="stationId" />
    <result column="date" jdbcType="TIMESTAMP" property="date" />
  </resultMap>
  <sql id="Example_Where_Clause">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
    -->
    <where>
      <foreach collection="oredCriteria" item="criteria" separator="or">
        <if test="criteria.valid">
          <trim prefix="(" prefixOverrides="and" suffix=")">
            <foreach collection="criteria.criteria" item="criterion">
              <choose>
                <when test="criterion.noValue">
                  and ${criterion.condition}
                </when>
                <when test="criterion.singleValue">
                  and ${criterion.condition} #{criterion.value}
                </when>
                <when test="criterion.betweenValue">
                  and ${criterion.condition} #{criterion.value} and #{criterion.secondValue}
                </when>
                <when test="criterion.listValue">
                  and ${criterion.condition}
                  <foreach close=")" collection="criterion.value" item="listItem" open="(" separator=",">
                    #{listItem}
                  </foreach>
                </when>
              </choose>
            </foreach>
          </trim>
        </if>
      </foreach>
    </where>
  </sql>
  <sql id="Update_By_Example_Where_Clause">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
    -->
    <where>
      <foreach collection="example.oredCriteria" item="criteria" separator="or">
        <if test="criteria.valid">
          <trim prefix="(" prefixOverrides="and" suffix=")">
            <foreach collection="criteria.criteria" item="criterion">
              <choose>
                <when test="criterion.noValue">
                  and ${criterion.condition}
                </when>
                <when test="criterion.singleValue">
                  and ${criterion.condition} #{criterion.value}
                </when>
                <when test="criterion.betweenValue">
                  and ${criterion.condition} #{criterion.value} and #{criterion.secondValue}
                </when>
                <when test="criterion.listValue">
                  and ${criterion.condition}
                  <foreach close=")" collection="criterion.value" item="listItem" open="(" separator=",">
                    #{listItem}
                  </foreach>
                </when>
              </choose>
            </foreach>
          </trim>
        </if>
      </foreach>
    </where>
  </sql>
  <sql id="Base_Column_List">
    oil_gun_id, oil_gun_no, oil_name, oil_price, station_id, date
  </sql>
  <select id="selectByExample" parameterType="com.platform.yijia.pojo.StationOilGunExample" resultMap="BaseResultMap">
    select
    <if test="distinct">
      distinct
    </if>
    <include refid="Base_Column_List" />
    from station_oil_gun
    <if test="_parameter != null">
      <include refid="Example_Where_Clause" />
    </if>
    <if test="orderByClause != null">
      order by ${orderByClause}
    </if>
  </select>
  <select id="selectByPrimaryKey" parameterType="java.lang.Integer" resultMap="BaseResultMap">
    select
    <include refid="Base_Column_List" />
    from station_oil_gun
    where oil_gun_id = #{oilGunId,jdbcType=INTEGER}
  </select>
  <delete id="deleteByPrimaryKey" parameterType="java.lang.Integer">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
    -->
    delete from station_oil_gun
    where oil_gun_id = #{oilGunId,jdbcType=INTEGER}
  </delete>
  <delete id="deleteByExample" parameterType="com.platform.yijia.pojo.StationOilGunExample">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
    -->
    delete from station_oil_gun
    <if test="_parameter != null">
      <include refid="Example_Where_Clause" />
    </if>
  </delete>
  <insert id="insert" parameterType="com.platform.yijia.pojo.StationOilGun">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
    -->
    insert into station_oil_gun (oil_gun_id, oil_gun_no, oil_name,
      oil_price, station_id,
      date)
    values (#{oilGunId,jdbcType=INTEGER}, #{oilGunNo,jdbcType=VARCHAR}, #{oilName,jdbcType=VARCHAR},
      #{oilPrice,jdbcType=DECIMAL}, #{stationId,jdbcType=INTEGER},
      #{date,jdbcType=TIMESTAMP})
  </insert>
  <insert id="insertSelective" parameterType="com.platform.yijia.pojo.StationOilGun">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
    -->
    insert into station_oil_gun
    <trim prefix="(" suffix=")" suffixOverrides=",">
      <if test="oilGunId != null">
        oil_gun_id,
      </if>
      <if test="oilGunNo != null">
        oil_gun_no,
      </if>
      <if test="oilName != null">
        oil_name,
      </if>
      <if test="oilPrice != null">
        oil_price,
      </if>
      <if test="stationId != null">
        station_id,
      </if>

      <if test="date != null">
        date,
      </if>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides=",">
      <if test="oilGunId != null">
        #{oilGunId,jdbcType=INTEGER},
      </if>
      <if test="oilGunNo != null">
        #{oilGunNo,jdbcType=VARCHAR},
      </if>
      <if test="oilName != null">
        #{oilName,jdbcType=VARCHAR},
      </if>
      <if test="oilPrice != null">
        #{oilPrice,jdbcType=DECIMAL},
      </if>
      <if test="stationId != null">
        #{stationId,jdbcType=INTEGER},
      </if>
      <if test="date != null">
        #{date,jdbcType=TIMESTAMP},
      </if>
    </trim>
  </insert>
  <select id="countByExample" parameterType="com.platform.yijia.pojo.StationOilGunExample" resultType="java.lang.Long">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
    -->
    select count(*) from station_oil_gun
    <if test="_parameter != null">
      <include refid="Example_Where_Clause" />
    </if>
  </select>
  <update id="updateByExampleSelective" parameterType="map">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
    -->
    update station_oil_gun
    <set>
      <if test="record.oilGunId != null">
        oil_gun_id = #{record.oilGunId,jdbcType=INTEGER},
      </if>
      <if test="record.oilGunNo != null">
        oil_gun_no = #{record.oilGunNo,jdbcType=VARCHAR},
      </if>
      <if test="record.oilName != null">
        oil_name = #{record.oilName,jdbcType=VARCHAR},
      </if>
      <if test="record.oilPrice != null">
        oil_price = #{record.oilPrice,jdbcType=DECIMAL},
      </if>
      <if test="record.stationId != null">
        station_id = #{record.stationId,jdbcType=INTEGER},
      </if>
      <if test="record.date != null">
        date = #{record.date,jdbcType=TIMESTAMP},
      </if>
    </set>
    <if test="_parameter != null">
      <include refid="Update_By_Example_Where_Clause" />
    </if>
  </update>
  <update id="updateByExample" parameterType="map">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
    -->
    update station_oil_gun
    set oil_gun_id = #{record.oilGunId,jdbcType=INTEGER},
      oil_gun_no = #{record.oilGunNo,jdbcType=VARCHAR},
      oil_name = #{record.oilName,jdbcType=VARCHAR},
      oil_price = #{record.oilPrice,jdbcType=DECIMAL},
      station_id = #{record.stationId,jdbcType=INTEGER},
      date = #{record.date,jdbcType=TIMESTAMP}
    <if test="_parameter != null">
      <include refid="Update_By_Example_Where_Clause" />
    </if>
  </update>
  <update id="updateByPrimaryKeySelective" parameterType="com.platform.yijia.pojo.StationOilGun">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
    -->
    update station_oil_gun
    <set>
      <if test="oilGunNo != null">
        oil_gun_no = #{oilGunNo,jdbcType=VARCHAR},
      </if>
      <if test="oilName != null">
        oil_name = #{oilName,jdbcType=VARCHAR},
      </if>
      <if test="oilPrice != null">
        oil_price = #{oilPrice,jdbcType=DECIMAL},
      </if>
      <if test="stationId != null">
        station_id = #{stationId,jdbcType=INTEGER},
      </if>
      <if test="date != null">
        date = #{date,jdbcType=TIMESTAMP},
      </if>
    </set>
    where oil_gun_id = #{oilGunId,jdbcType=INTEGER}
  </update>
  <update id="updateByPrimaryKey" parameterType="com.platform.yijia.pojo.StationOilGun">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
    -->
    update station_oil_gun
    set oil_gun_no = #{oilGunNo,jdbcType=VARCHAR},
      oil_name = #{oilName,jdbcType=VARCHAR},
      oil_price = #{oilPrice,jdbcType=DECIMAL},
      station_id = #{stationId,jdbcType=INTEGER},
      date = #{date,jdbcType=TIMESTAMP}
    where oil_gun_id = #{oilGunId,jdbcType=INTEGER}
  </update>

  <!--根据油站Id油枪号获取打印机编号 -->
  <select id="getPrinterSnByStationIdAndOilGunNo" parameterType="map" resultType="map">
    SELECT
        A.gun_no            AS oilGunNo,
        A.station_id        AS stationId,
        A.device_no         AS printerSn,
        B.print_setting     AS printSetting
    FROM  station_device_manage     AS A
        LEFT JOIN sys_dept          AS B ON A.station_id = B.dept_id
    <where>
        <if test="stationId != null and stationId !=''">
          A.station_id = #{stationId}
        </if>
        <if test="oilGunNo != null and oilGunNo !=''">
          AND FIND_IN_SET(#{oilGunNo}, A.gun_no)
        </if>
        <if test="deviceType != null and deviceType !=''">
          AND A.device_type = #{deviceType}
        </if>

    </where>

  </select>

  <!--根据加油员id查询油枪-->
  <select id="selectOilGunByPersonalId" parameterType="map" resultType="map">
        SELECT
            T1.personnel_id             AS personnelId,
            T1.personnel_name           AS personnelName,
            T2.station_id               AS stationId,
            T2.oil_gun_id               AS oilGunId,
            T2.oil_gun_no               AS oilGunNo,
            T2.oil_name                 AS oilName,
            T2.oil_price                AS oilPrice,
            T2.date                     AS date
        FROM        station_personnel    AS T1
        LEFT JOIN   station_oil_gun      AS T2 ON FIND_IN_SET(T2.oil_gun_no, T1.gun_no) AND T1.station_id = T2.station_id
        <where>
          T1.del_flag = "0"
          <if test="personnelId != null and personnelId !=''">
            AND T1.personnel_id = #{personnelId}
          </if>
          <if test="stationId != null">
            AND T1.station_id = #{stationId}
          </if>
        </where>
  </select>

  <!--根据油站Id油枪号获取打印机编号 -->
  <select id="getPrinterSnByStationIdAndOilGunNoList" parameterType="map" resultType="map">
    SELECT
        A.gun_no            AS oilGunNo,
        A.station_id        AS stationId,
        A.device_no         AS printerSn,
        A.device_type       AS deviceType,
        B.print_setting     AS printSetting
    FROM  station_device_manage     AS A
        LEFT JOIN sys_dept          AS B ON A.station_id = B.dept_id
    <where>
      <if test="stationId != null and stationId !=''">
        A.station_id = #{stationId}
      </if>
      <if test="oilGunNo != null and oilGunNo !=''">
        AND FIND_IN_SET(#{oilGunNo}, A.gun_no)
      </if>
      <if test="deviceType != null and deviceType !=''">
        AND A.device_type = #{deviceType}
      </if>
    </where>
  </select>

</mapper>
