<?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.StationInfoMapper">
  <resultMap id="BaseResultMap" type="com.platform.yijia.pojo.StationInfo">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
    -->
    <id column="dept_id" jdbcType="INTEGER" property="stationId" />
    <result column="dept_name" jdbcType="VARCHAR" property="stationName" />
    <result column="dept_address" jdbcType="VARCHAR" property="stationAddress" />
    <result column="oil_gun_num" jdbcType="INTEGER" property="oilGunNum" />
    <result column="leader" jdbcType="VARCHAR" property="contacts" />
    <result column="phone" jdbcType="VARCHAR" property="phone" />
    <result column="station_longitude" jdbcType="VARCHAR" property="stationLongitude" />
    <result column="station_latitude" jdbcType="VARCHAR" property="stationLatitude" />
    <result column="station_pic" jdbcType="VARCHAR" property="stationPic" />
    <result column="mno" jdbcType="INTEGER" property="mno" />
    <result column="app_id" jdbcType="VARCHAR" property="appId" />
    <result column="gzh_app_id" jdbcType="VARCHAR" property="gzhAppId" />
  </resultMap>
  <resultMap extends="BaseResultMap" id="ResultMapWithBLOBs" type="com.platform.yijia.pojo.StationInfo">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
    -->
    <result column="station_pic" jdbcType="LONGVARBINARY" property="stationPic" />
  </resultMap>
  <!--获取油站信息-->
  <select id="selectStationInfo" parameterType="com.platform.yijia.pojo.StationInfo" resultMap="BaseResultMap">
    SELECT
        dept_id,
        dept_name,
        dept_address,
        oil_gun_num,
        leader,
        station_longitude,
        station_latitude,
        station_pic,
        mno
    FROM
        sys_dept
    <where>
      <if test="stationId !='' and stationId != null" >
        dept_id = #{stationId}
      </if>
    </where>

  </select>


  <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">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
    -->
    dept_id, dept_name, dept_address, oil_gun_num, leader, phone,
    station_longitude, station_latitude, mno
  </sql>
  <sql id="Blob_Column_List">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
    -->
    station_pic
  </sql>
  <select id="selectByExampleWithBLOBs" parameterType="com.platform.yijia.pojo.StationInfoExample" resultMap="ResultMapWithBLOBs">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
    -->
    select
    <if test="distinct">
      distinct
    </if>
    <include refid="Base_Column_List" />
    ,
    <include refid="Blob_Column_List" />
    from sys_dept
    <if test="_parameter != null">
      <include refid="Example_Where_Clause" />
    </if>
    <if test="orderByClause != null">
      order by ${orderByClause}
    </if>
  </select>
  <select id="selectByExample" parameterType="com.platform.yijia.pojo.StationInfoExample" resultMap="BaseResultMap">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
    -->
    select
    <if test="distinct">
      distinct
    </if>
    <include refid="Base_Column_List" />
    ,
    <include refid="Blob_Column_List" />
    from sys_dept
    <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="ResultMapWithBLOBs">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
    -->
    select
    <include refid="Base_Column_List" />
    ,
    <include refid="Blob_Column_List" />
    from sys_dept
    where dept_id = #{stationId,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 sys_dept
    where dept_id = #{stationId,jdbcType=INTEGER}
  </delete>
  <delete id="deleteByExample" parameterType="com.platform.yijia.pojo.StationInfoExample">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
    -->
    delete from sys_dept
    <if test="_parameter != null">
      <include refid="Example_Where_Clause" />
    </if>
  </delete>
  <insert id="insert" parameterType="com.platform.yijia.pojo.StationInfo">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
    -->
    insert into sys_dept (dept_id, dept_name, dept_address,
    oil_gun_num, leader, phone, station_longitude,
    station_latitude, mno, station_pic
    )
    values (#{stationId,jdbcType=INTEGER}, #{stationName,jdbcType=VARCHAR}, #{stationAddress,jdbcType=VARCHAR},
    #{oilGunNum,jdbcType=INTEGER}, #{contacts,jdbcType=VARCHAR}, #{phone,jdbcType=VARCHAR},
    #{stationLongitude,jdbcType=VARCHAR},
    #{stationLatitude,jdbcType=VARCHAR}, #{mno,jdbcType=INTEGER}, #{stationPic,jdbcType=LONGVARBINARY}
    )
  </insert>
  <insert id="insertSelective" parameterType="com.platform.yijia.pojo.StationInfo">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
    -->
    insert into sys_dept
    <trim prefix="(" suffix=")" suffixOverrides=",">
      <if test="stationId != null">
        dept_id,
      </if>
      <if test="stationName != null">
        dept_name,
      </if>
      <if test="stationAddress != null">
        dept_address,
      </if>
      <if test="oilGunNum != null">
        oil_gun_num,
      </if>
      <if test="leader != null">
        leader,
      </if>
      <if test="phone != null">
        phone,
      </if>
      <if test="stationLongitude != null">
        station_longitude,
      </if>
      <if test="stationLatitude != null">
        station_latitude,
      </if>
      <if test="mno != null">
        mno,
      </if>
      <if test="stationPic != null">
        station_pic,
      </if>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides=",">
      <if test="stationId != null">
        #{stationId,jdbcType=INTEGER},
      </if>
      <if test="stationName != null">
        #{stationName,jdbcType=VARCHAR},
      </if>
      <if test="stationAddress != null">
        #{stationAddress,jdbcType=VARCHAR},
      </if>
      <if test="oilGunNum != null">
        #{oilGunNum,jdbcType=INTEGER},
      </if>
      <if test="contacts != null">
        #{contacts,jdbcType=VARCHAR},
      </if>
      <if test="phone != null">
        #{phone,jdbcType=VARCHAR},
      </if>
      <if test="stationLongitude != null">
        #{stationLongitude,jdbcType=VARCHAR},
      </if>
      <if test="stationLatitude != null">
        #{stationLatitude,jdbcType=VARCHAR},
      </if>
      <if test="mno != null">
        #{mno,jdbcType=INTEGER},
      </if>
      <if test="stationPic != null">
        #{stationPic,jdbcType=LONGVARBINARY},
      </if>
    </trim>
  </insert>
  <select id="countByExample" parameterType="com.platform.yijia.pojo.StationInfoExample" resultType="java.lang.Long">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
    -->
    select count(*) from sys_dept
    <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 sys_dept
    <set>
      <if test="record.stationId != null">
        dept_id = #{record.stationId,jdbcType=INTEGER},
      </if>
      <if test="record.stationName != null">
        dept_name = #{record.stationName,jdbcType=VARCHAR},
      </if>
      <if test="record.stationAddress != null">
        dept_address = #{record.stationAddress,jdbcType=VARCHAR},
      </if>
      <if test="record.oilGunNum != null">
        oil_gun_num = #{record.oilGunNum,jdbcType=INTEGER},
      </if>
      <if test="record.contacts != null">
        leader = #{record.contacts,jdbcType=VARCHAR},
      </if>
      <if test="record.phone != null">
        phone = #{record.phone,jdbcType=VARCHAR},
      </if>
      <if test="record.stationLongitude != null">
        station_longitude = #{record.stationLongitude,jdbcType=VARCHAR},
      </if>
      <if test="record.stationLatitude != null">
        station_latitude = #{record.stationLatitude,jdbcType=VARCHAR},
      </if>
      <if test="record.mno != null">
        mno = #{record.mno,jdbcType=INTEGER},
      </if>
      <if test="record.stationPic != null">
        station_pic = #{record.stationPic,jdbcType=LONGVARBINARY},
      </if>
    </set>
    <if test="_parameter != null">
      <include refid="Update_By_Example_Where_Clause" />
    </if>
  </update>
  <update id="updateByExampleWithBLOBs" parameterType="map">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
    -->
    update sys_dept
    set dept_id = #{record.stationId,jdbcType=INTEGER},
    dept_name = #{record.stationName,jdbcType=VARCHAR},
    dept_address = #{record.stationAddress,jdbcType=VARCHAR},
    oil_gun_num = #{record.oilGunNum,jdbcType=INTEGER},
    leader = #{record.contacts,jdbcType=VARCHAR},
    phone = #{record.phone,jdbcType=VARCHAR},
    station_longitude = #{record.stationLongitude,jdbcType=VARCHAR},
    station_latitude = #{record.stationLatitude,jdbcType=VARCHAR},
    mno = #{record.mno,jdbcType=INTEGER},
    station_pic = #{record.stationPic,jdbcType=LONGVARBINARY}
    <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 sys_dept
    set dept_id = #{record.stationId,jdbcType=INTEGER},
    dept_name = #{record.stationName,jdbcType=VARCHAR},
    dept_address = #{record.stationAddress,jdbcType=VARCHAR},
    oil_gun_num = #{record.oilGunNum,jdbcType=INTEGER},
    leader = #{record.contacts,jdbcType=VARCHAR},
    phone = #{record.phone,jdbcType=VARCHAR},
    station_longitude = #{record.stationLongitude,jdbcType=VARCHAR},
    station_latitude = #{record.stationLatitude,jdbcType=VARCHAR},
    mno = #{record.mno,jdbcType=INTEGER}
    <if test="_parameter != null">
      <include refid="Update_By_Example_Where_Clause" />
    </if>
  </update>
  <update id="updateByPrimaryKeySelective" parameterType="com.platform.yijia.pojo.StationInfo">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
    -->
    update sys_dept
    <set>
      <if test="stationName != null">
        dept_name = #{stationName,jdbcType=VARCHAR},
      </if>
      <if test="stationAddress != null">
        dept_address = #{stationAddress,jdbcType=VARCHAR},
      </if>
      <if test="oilGunNum != null">
        oil_gun_num = #{oilGunNum,jdbcType=INTEGER},
      </if>
      <if test="contacts != null">
        leader = #{contacts,jdbcType=VARCHAR},
      </if>
      <if test="phone != null">
        phone = #{phone,jdbcType=VARCHAR},
      </if>
      <if test="stationLongitude != null">
        station_longitude = #{stationLongitude,jdbcType=VARCHAR},
      </if>
      <if test="stationLatitude != null">
        station_latitude = #{stationLatitude,jdbcType=VARCHAR},
      </if>
      <if test="mno != null">
        mno = #{mno,jdbcType=INTEGER},
      </if>
      <if test="stationPic != null">
        station_pic = #{stationPic,jdbcType=LONGVARBINARY},
      </if>
    </set>
    where dept_id = #{stationId,jdbcType=INTEGER}
  </update>
  <update id="updateByPrimaryKeyWithBLOBs" parameterType="com.platform.yijia.pojo.StationInfo">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
    -->
    update sys_dept
    set dept_name = #{stationName,jdbcType=VARCHAR},
    dept_address = #{stationAddress,jdbcType=VARCHAR},
    oil_gun_num = #{oilGunNum,jdbcType=INTEGER},
    leader = #{contacts,jdbcType=VARCHAR},
    phone = #{phone,jdbcType=VARCHAR},
    station_longitude = #{stationLongitude,jdbcType=VARCHAR},
    station_latitude = #{stationLatitude,jdbcType=VARCHAR},
    mno = #{mno,jdbcType=INTEGER},
    station_pic = #{stationPic,jdbcType=LONGVARBINARY}
    where dept_id = #{stationId,jdbcType=INTEGER}
  </update>
  <update id="updateByPrimaryKey" parameterType="com.platform.yijia.pojo.StationInfo">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
    -->
    update sys_dept
    set dept_name = #{stationName,jdbcType=VARCHAR},
    dept_address = #{stationAddress,jdbcType=VARCHAR},
    oil_gun_num = #{oilGunNum,jdbcType=INTEGER},
    leader = #{contacts,jdbcType=VARCHAR},
    phone = #{phone,jdbcType=VARCHAR},
    station_longitude = #{stationLongitude,jdbcType=VARCHAR},
    station_latitude = #{stationLatitude,jdbcType=VARCHAR},
    mno = #{mno,jdbcType=INTEGER}
    where dept_id = #{stationId,jdbcType=INTEGER}
  </update>

  <!--查询油站的公告-->
  <select id="getStationNoticeInfo" parameterType="Integer" resultType="map">
    SELECT
        notice AS notice
    FROM
        station_pay
    <where>
      <if test="stationId !='' and stationId != null" >
        station_id = #{stationId}
      </if>
    </where>
  </select>

  <!--查询油站的优惠方式-->
  <select id="getStationDiscountWay" parameterType="String" resultType="String">
    SELECT
        discount_setting AS discountSetting
    FROM
        station_pay
    <where>
      <if test="stationId !='' and stationId != null" >
        station_id = #{stationId}
      </if>
    </where>
  </select>

  <!--查询油站小程序AppId和AppSecret-->
  <select id="getStationAppIdAndAppSecret" parameterType="Integer" resultType="Map">
    SELECT
      mno             AS mno,
      dept_name       AS stationName,
      app_id          AS appId,
      app_secret      AS appSecret,
      gzh_app_id      AS gzhAppId,
      gzh_app_secret  AS gzhAppSecret
    FROM
        sys_dept
    <where>
      <if test="stationId != null" >
        dept_id = #{stationId}
      </if>
    </where>
  </select>


  <!--油站轮播图片信息返回结果-->
  <resultMap id="StationPicResultMap" type="com.platform.yijia.pojo.StationPic">
    <id     column="id"                     jdbcType="INTEGER" property="id" />
    <result column="name"                   jdbcType="VARCHAR" property="name" />
    <result column="url"                    jdbcType="VARCHAR" property="url" />
    <result column="station_id"             jdbcType="INTEGER" property="stationId" />
    <result column="station_name"           jdbcType="VARCHAR" property="stationName" />
    <result column="parent_id"              jdbcType="VARCHAR" property="parentId" />

  </resultMap>

  <!--查询油站轮播图片信息-->
  <select id="getStationPicList" resultMap="StationPicResultMap" parameterType="com.platform.yijia.pojo.StationPic">
    SELECT
        id,
        name,
        url,
        station_id,
        station_name,
        parent_id
    FROM
        station_pic
    <where>
      <if test="stationId !=null and stationId !=''">
        AND station_id = #{stationId}
      </if>
    </where>
  </select>

  <!--根据油站Id油枪号获取打印机编号 -->
  <select id="getStationPrinterList" parameterType="Integer" resultType="Map">
    SELECT
        A.station_id                AS stationId,
        A.device_no                 AS printerSn,
        B.integral_print_flag       AS integralPrintFlag
    FROM  station_device_manage     AS A
        LEFT JOIN station_pay       AS B ON A.station_id = B.station_id
    <where>
      A.device_status = "1"
      <if test="stationId != null and stationId !=''">
        AND A.station_id = #{stationId}
      </if>
    </where>
  </select>


</mapper>
