<?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.goafanti.common.dao.PublicReleaseDetailsMapper">
  <resultMap id="BaseResultMap" type="com.goafanti.common.model.PublicReleaseDetails">
    <id column="id" jdbcType="INTEGER" property="id" />
    <result column="prid" jdbcType="INTEGER" property="prid" />
    <result column="uid" jdbcType="VARCHAR" property="uid" />
    <result column="ufid" jdbcType="VARCHAR" property="ufid" />
    <result column="new_user" jdbcType="INTEGER" property="newUser" />
    <result column="sign_sum" jdbcType="INTEGER" property="signSum" />
    <result column="longitude" jdbcType="VARCHAR" property="longitude" />
    <result column="latitude" jdbcType="VARCHAR" property="latitude" />
    <result column="clock_in" jdbcType="INTEGER" property="clockIn" />
    <result column="clock_in_time" jdbcType="TIMESTAMP" property="clockInTime" />
    <result column="photo_url" jdbcType="VARCHAR" property="photoUrl" />
    <result column="district_name" jdbcType="VARCHAR" property="districtName" />
    <result column="clock_in_remarks" jdbcType="VARCHAR" property="clockInRemarks" />
    <result column="duration" jdbcType="DOUBLE" property="duration" />
    <result column="main_status" jdbcType="INTEGER" property="mainStatus" />
    <result column="update_time" jdbcType="TIMESTAMP" property="updateTime" />
  </resultMap>
  <sql id="Base_Column_List">
    id, prid, `uid`, ufid, new_user, sign_sum, longitude, latitude, clock_in, clock_in_time,
    photo_url, district_name, clock_in_remarks, duration, main_status, update_time
  </sql>
  <select id="selectByPrimaryKey" parameterType="java.lang.Integer" resultMap="BaseResultMap">
    select
    <include refid="Base_Column_List" />
    from public_release_details
    where id = #{id,jdbcType=INTEGER}
  </select>
  <delete id="deleteByPrimaryKey" parameterType="java.lang.Integer">
    delete from public_release_details
    where id = #{id,jdbcType=INTEGER}
  </delete>
  <insert id="insert" keyColumn="id" keyProperty="id" parameterType="com.goafanti.common.model.PublicReleaseDetails" useGeneratedKeys="true">
    insert into public_release_details (prid, `uid`, ufid,
      new_user, sign_sum, longitude,
      latitude, clock_in, clock_in_time,
      photo_url, district_name, clock_in_remarks,
      duration, main_status, update_time
      )
    values (#{prid,jdbcType=INTEGER}, #{uid,jdbcType=VARCHAR}, #{ufid,jdbcType=VARCHAR},
      #{newUser,jdbcType=INTEGER}, #{signSum,jdbcType=INTEGER}, #{longitude,jdbcType=VARCHAR},
      #{latitude,jdbcType=VARCHAR}, #{clockIn,jdbcType=INTEGER}, #{clockInTime,jdbcType=TIMESTAMP},
      #{photoUrl,jdbcType=VARCHAR}, #{districtName,jdbcType=VARCHAR}, #{clockInRemarks,jdbcType=VARCHAR},
      #{duration,jdbcType=DOUBLE}, #{mainStatus,jdbcType=INTEGER}, #{updateTime,jdbcType=TIMESTAMP}
      )
  </insert>
  <insert id="insertSelective" keyColumn="id" keyProperty="id" parameterType="com.goafanti.common.model.PublicReleaseDetails" useGeneratedKeys="true">
    insert into public_release_details
    <trim prefix="(" suffix=")" suffixOverrides=",">
      <if test="prid != null">
        prid,
      </if>
      <if test="uid != null">
        `uid`,
      </if>
      <if test="ufid != null">
        ufid,
      </if>
      <if test="newUser != null">
        new_user,
      </if>
      <if test="signSum != null">
        sign_sum,
      </if>
      <if test="longitude != null">
        longitude,
      </if>
      <if test="latitude != null">
        latitude,
      </if>
      <if test="clockIn != null">
        clock_in,
      </if>
      <if test="clockInTime != null">
        clock_in_time,
      </if>
      <if test="photoUrl != null">
        photo_url,
      </if>
      <if test="districtName != null">
        district_name,
      </if>
      <if test="clockInRemarks != null">
        clock_in_remarks,
      </if>
      <if test="duration != null">
        duration,
      </if>
      <if test="mainStatus != null">
        main_status,
      </if>
      <if test="updateTime != null">
        update_time,
      </if>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides=",">
      <if test="prid != null">
        #{prid,jdbcType=INTEGER},
      </if>
      <if test="uid != null">
        #{uid,jdbcType=VARCHAR},
      </if>
      <if test="ufid != null">
        #{ufid,jdbcType=VARCHAR},
      </if>
      <if test="newUser != null">
        #{newUser,jdbcType=INTEGER},
      </if>
      <if test="signSum != null">
        #{signSum,jdbcType=INTEGER},
      </if>
      <if test="longitude != null">
        #{longitude,jdbcType=VARCHAR},
      </if>
      <if test="latitude != null">
        #{latitude,jdbcType=VARCHAR},
      </if>
      <if test="clockIn != null">
        #{clockIn,jdbcType=INTEGER},
      </if>
      <if test="clockInTime != null">
        #{clockInTime,jdbcType=TIMESTAMP},
      </if>
      <if test="photoUrl != null">
        #{photoUrl,jdbcType=VARCHAR},
      </if>
      <if test="districtName != null">
        #{districtName,jdbcType=VARCHAR},
      </if>
      <if test="clockInRemarks != null">
        #{clockInRemarks,jdbcType=VARCHAR},
      </if>
      <if test="duration != null">
        #{duration,jdbcType=DOUBLE},
      </if>
      <if test="mainStatus != null">
        #{mainStatus,jdbcType=INTEGER},
      </if>
      <if test="updateTime != null">
        #{updateTime,jdbcType=TIMESTAMP},
      </if>
    </trim>
  </insert>
  <update id="updateByPrimaryKeySelective" parameterType="com.goafanti.common.model.PublicReleaseDetails">
    update public_release_details
    <set>
      <if test="prid != null">
        prid = #{prid,jdbcType=INTEGER},
      </if>
      <if test="uid != null">
        `uid` = #{uid,jdbcType=VARCHAR},
      </if>
      <if test="ufid != null">
        ufid = #{ufid,jdbcType=VARCHAR},
      </if>
      <if test="newUser != null">
        new_user = #{newUser,jdbcType=INTEGER},
      </if>
      <if test="signSum != null">
        sign_sum = #{signSum,jdbcType=INTEGER},
      </if>
      <if test="longitude != null">
        longitude = #{longitude,jdbcType=VARCHAR},
      </if>
      <if test="latitude != null">
        latitude = #{latitude,jdbcType=VARCHAR},
      </if>
      <if test="clockIn != null">
        clock_in = #{clockIn,jdbcType=INTEGER},
      </if>
      <if test="clockInTime != null">
        clock_in_time = #{clockInTime,jdbcType=TIMESTAMP},
      </if>
      <if test="photoUrl != null">
        photo_url = #{photoUrl,jdbcType=VARCHAR},
      </if>
      <if test="districtName != null">
        district_name = #{districtName,jdbcType=VARCHAR},
      </if>
      <if test="clockInRemarks != null">
        clock_in_remarks = #{clockInRemarks,jdbcType=VARCHAR},
      </if>
      <if test="duration != null">
        duration = #{duration,jdbcType=DOUBLE},
      </if>
      <if test="mainStatus != null">
        main_status = #{mainStatus,jdbcType=INTEGER},
      </if>
      <if test="updateTime != null">
        update_time = #{updateTime,jdbcType=TIMESTAMP},
      </if>
    </set>
    where id = #{id,jdbcType=INTEGER}
  </update>
  <update id="updateByPrimaryKey" parameterType="com.goafanti.common.model.PublicReleaseDetails">
    update public_release_details
    set prid = #{prid,jdbcType=INTEGER},
      `uid` = #{uid,jdbcType=VARCHAR},
      ufid = #{ufid,jdbcType=VARCHAR},
      new_user = #{newUser,jdbcType=INTEGER},
      sign_sum = #{signSum,jdbcType=INTEGER},
      longitude = #{longitude,jdbcType=VARCHAR},
      latitude = #{latitude,jdbcType=VARCHAR},
      clock_in = #{clockIn,jdbcType=INTEGER},
      clock_in_time = #{clockInTime,jdbcType=TIMESTAMP},
      photo_url = #{photoUrl,jdbcType=VARCHAR},
      district_name = #{districtName,jdbcType=VARCHAR},
      clock_in_remarks = #{clockInRemarks,jdbcType=VARCHAR},
      duration = #{duration,jdbcType=DOUBLE},
      main_status = #{mainStatus,jdbcType=INTEGER},
      update_time = #{updateTime,jdbcType=TIMESTAMP}
    where id = #{id,jdbcType=INTEGER}
  </update>


  <select id="selectByPCid" resultType="com.goafanti.weChat.bo.OutPublicReleaseDetails">
    select
      a.id,a.prid, a.`uid`, a.ufid, a.new_user newUser,a.longitude,a.latitude,b.nickname userName,a.main_status mainStatus,
      a.district_name districtName ,a.clock_in clockIn,date_format(a.clock_in_time, '%Y-%m-%d %H:%i:%S')  clockInTimes,a.photo_url photoUrl
    from public_release_details a left join user b on a.uid=b.id
    where prid = #{id,jdbcType=INTEGER} order by a.update_time desc
  </select>

  <insert id="insertBatch">
    insert into public_release_details (prid, `uid`, ufid,
    new_user, sign_sum, longitude,
    latitude, clock_in, clock_in_time,
    photo_url, district_name,duration,main_status)
    values
    <foreach  collection="list" item="prd"  separator=",">
      (#{prd.prid,jdbcType=INTEGER}, #{prd.uid,jdbcType=VARCHAR}, #{prd.ufid,jdbcType=VARCHAR},
      #{prd.newUser,jdbcType=INTEGER}, #{prd.signSum,jdbcType=INTEGER}, #{prd.longitude,jdbcType=VARCHAR},
      #{prd.latitude,jdbcType=VARCHAR}, #{prd.clockIn,jdbcType=INTEGER}, #{prd.clockInTime,jdbcType=TIMESTAMP},
      #{prd.photoUrl,jdbcType=VARCHAR}, #{prd.districtName,jdbcType=VARCHAR},#{prd.duration,jdbcType=DOUBLE},
      #{prd.mainStatus,jdbcType=INTEGER})
    </foreach>
  </insert>

  <select id="getNamesByPrid" resultType="java.lang.String">
    select  GROUP_CONCAT(b.nickname)userNames
    from public_release_details a left join user b on a.uid =b.id
    where prid = #{id}
    group by prid
  </select>
  <select id="selectBypridAndUid" resultType="com.goafanti.weChat.bo.OutPublicReleaseDetails">
    select
      a.id,a.prid, a.`uid`, a.ufid, a.new_user newUser,a.longitude,a.latitude,b.nickname userName,
      a.district_name districtName ,a.clock_in clockIn,date_format(a.clock_in_time, '%Y-%m-%d %H:%i:%S')  clockInTimes,a.photo_url photoUrl
    from public_release_details a left join user b on a.uid=b.id
    where prid = #{id,jdbcType=INTEGER} and uid =#{uid}
  </select>

  <update id="updateDistrictByPrid">
    update public_release_details
    set longitude = #{longitude,jdbcType=VARCHAR},
        latitude = #{latitude,jdbcType=VARCHAR},
        district_name = #{districtName,jdbcType=VARCHAR}
    where prid =#{id}
  </update>
</mapper>
