<?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.com.countrygarden.bi.main.dao.personnel.FenghuangCollectionrateMapper">
    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="cn.com.countrygarden.bi.main.model.dup.FenghuangCollectionrate">
                                    <id column="id" property="id" />
                                                <result column="user_id" property="userId" />
                                                <result column="user_name" property="userName" />
                                                <result column="collectionrate" property="collectionrate" />
                                                <result column="collectionrate_time" property="collectionrateTime" />
                        </resultMap>
                        
                        
      <select id="FenghuangCollectionratelist" resultType="cn.com.countrygarden.bi.main.dto.FenghuangCollectionrateDTO">

                  SELECT DISTINCT user_id as userId,user_name as userName,collectionrate as collectionrate,
                  collectionrate_time as collectionrateTime FROM fenghuang_collectionrate
                  WHERE collectionrate_time like concat('%',#{time},'%')
      </select>
    <select id="managerhousekeeper" resultType="cn.com.countrygarden.bi.main.dto.FenghuangCollectionrateDTO">

          SELECT DISTINCT f.id as id,m.name as userName
           FROM biapp.manager_housekeeper_cache m,biapp.fenghuang_manager_data f
           WHERE m.name=f.manager_name AND f.manager_name=#{userName} and f.begin_date like concat('%',#{time},'%')
      </select>
      
      <update id="updateFenghuangCollectionrate" parameterType="cn.com.countrygarden.bi.main.dto.FenghuangCollectionrateDTO">
            UPDATE biapp.fenghuang_manager_data SET
            collectionRate=#{collectionrate} 
            WHERE id=#{managerId};
      </update>

    <delete id="deleteColl">
         DELETE FROM biapp.fenghuang_collectionrate
         WHERE collectionrate_time like concat('%',#{time},'%')
        <if test="userIds != null and userIds.size()>0">
            AND user_id in
            <foreach collection="userIds" item="userId" open="(" separator="," close=")">
                #{userId}
            </foreach>
        </if>
    </delete>

    <select id="collnum" resultType="java.lang.Integer">
            SELECT COUNT(1) FROM biapp.fenghuang_collectionrate
             WHERE user_id=#{userId} and collectionrate_time like concat('%',#{time},'%')

    </select>
    <select id="selectNewCollectionRate" resultType="java.lang.Double">
        select ROUND(collectionrate*100,2)  FROM `fenghuang_collectionrate`
        WHERE collectionrate_time=date_format(DATE_ADD(NOW(),INTERVAL -1 MONTH),'%Y-%m')
        AND user_id =#{userId} limit 1
    </select>

    <update id="updatecoll" parameterType="cn.com.countrygarden.bi.main.model.dup.FenghuangCollectionrate">
          UPDATE biapp.fenghuang_collectionrate SET
          collectionrate = #{collectionrate},user_name=#{userName}
          WHERE user_id=#{userId} and collectionrate_time like concat('%',#{collectionrateTime},'%');
    </update>

    <select id="selectErrorRate" resultType="java.lang.String">
      SELECT user_id from fenghuang_collectionrate WHERE collectionrate_time=#{date} AND collectionrate='0';
    </select>

</mapper>