<?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">
<!-- namespace必须指向DAO接口 -->
<mapper namespace="com.jpsoft.shinestar.modules.base.dao.CompanySuperviseDAO">
	<resultMap id="CompanySuperviseMap" type="com.jpsoft.shinestar.modules.base.entity.CompanySupervise">
		<id property="id" column="id_" />
			<result property="companyId" column="company_id" />
			<result property="totalNum" column="total_num" />
			<result property="totalCheckNum" column="total_check_num" />
			<result property="totalAbnormalNum" column="total_abnormal_num" />
			<result property="leaveNum" column="leave_num" />
			<result property="testRate" column="test_rate" />
			<result property="recordTime" column="record_time" />
			<result property="delFlag" column="del_flag" />
			<result property="createBy" column="create_by" />
			<result property="createTime" column="create_time" />
			<result property="updateBy" column="update_by" />
			<result property="updateTime" column="update_time" />
			<result property="atOutProvinceNum" column="at_out_province_num" />
			<result property="atProvinceNum" column="at_province_num" />
			</resultMap>
	<insert id="insert" parameterType="com.jpsoft.shinestar.modules.base.entity.CompanySupervise">
	<!--
	<selectKey resultType="java.lang.String" order="BEFORE" keyProperty="id">
		select sys_guid() from dual
	</selectKey>
	-->
	<![CDATA[
		insert into base_company_supervise
	    (id_,company_id,total_num,total_check_num,total_abnormal_num,leave_num,test_rate,record_time,del_flag,create_by,create_time,update_by,update_time,at_out_province_num,at_province_num)
		values
		(
#{id,jdbcType=VARCHAR}
,#{companyId,jdbcType=VARCHAR}
,#{totalNum,jdbcType= NUMERIC }
,#{totalCheckNum,jdbcType= NUMERIC }
,#{totalAbnormalNum,jdbcType= NUMERIC }
,#{leaveNum,jdbcType= NUMERIC }
,#{testRate,jdbcType=VARCHAR}
,#{recordTime,jdbcType=VARCHAR}
,#{delFlag,jdbcType= NUMERIC }
,#{createBy,jdbcType=VARCHAR}
,#{createTime,jdbcType= TIMESTAMP }
,#{updateBy,jdbcType=VARCHAR}
,#{updateTime,jdbcType= TIMESTAMP }
,#{atOutProvinceNum,jdbcType= NUMERIC }
,#{atProvinceNum,jdbcType= NUMERIC }
		)
	]]>
	</insert>
	<delete id="delete" parameterType="string">
		delete from base_company_supervise where id_=#{id,jdbcType=VARCHAR}
	</delete>
	<update id="update" parameterType="com.jpsoft.shinestar.modules.base.entity.CompanySupervise">
		update base_company_supervise
		<set>
				<if test="companyId!=null">
		company_id=#{companyId,jdbcType=VARCHAR},
		</if>
				<if test="totalNum!=null">
		total_num=#{totalNum,jdbcType= NUMERIC },
		</if>
				<if test="totalCheckNum!=null">
		total_check_num=#{totalCheckNum,jdbcType= NUMERIC },
		</if>
				<if test="totalAbnormalNum!=null">
		total_abnormal_num=#{totalAbnormalNum,jdbcType= NUMERIC },
		</if>
				<if test="leaveNum!=null">
		leave_num=#{leaveNum,jdbcType= NUMERIC },
		</if>
				<if test="testRate!=null">
		test_rate=#{testRate,jdbcType=VARCHAR},
		</if>
				<if test="recordTime!=null">
		record_time=#{recordTime,jdbcType=VARCHAR},
		</if>
				<if test="delFlag!=null">
		del_flag=#{delFlag,jdbcType= NUMERIC },
		</if>
				<if test="createBy!=null">
		create_by=#{createBy,jdbcType=VARCHAR},
		</if>
				<if test="createTime!=null">
		create_time=#{createTime,jdbcType= TIMESTAMP },
		</if>
				<if test="updateBy!=null">
		update_by=#{updateBy,jdbcType=VARCHAR},
		</if>
				<if test="updateTime!=null">
		update_time=#{updateTime,jdbcType= TIMESTAMP },
		</if>
			<if test="atOutProvinceNum!=null">
				at_out_province_num=#{atOutProvinceNum,jdbcType= NUMERIC },
			</if>
			<if test="atProvinceNum!=null">
				at_province_num=#{atProvinceNum,jdbcType= NUMERIC },
			</if>
		</set>
	where id_=#{id}
	</update>
	<select id="get" parameterType="string" resultMap="CompanySuperviseMap">
		select * from base_company_supervise where id_=#{0}
	</select>
	<select id="exist" parameterType="string" resultType="int">
		select count(*) from base_company_supervise where id_=#{0}
	</select>
	<select id="list" resultMap="CompanySuperviseMap">
		select * from base_company_supervise where del_flag = 0
	</select>
	<select id="search" parameterType="hashmap" resultMap="CompanySuperviseMap">
		<![CDATA[
			select * from base_company_supervise
		]]>
		<where>
			<if test="searchParams.id != null">
				and ID_ like #{searchParams.id}
			</if>
			<if test="searchParams.recordTime != null">
				and record_time = #{searchParams.recordTime}
			</if>
			<if test="searchParams.inCompanyId != null">
				<foreach collection="searchParams.inCompanyId" item="personSuperviseRelation" open="and company_id in(" separator="," close=")">
					#{personSuperviseRelation.companyId}
				</foreach>
			</if>
		</where>
		<foreach item="sort" collection="sortList"  open="order by" separator=",">
	        ${sort.name} ${sort.order}
	 	</foreach>
	</select>

	<select id="findByCompanyIdAndRecordDate" resultMap="CompanySuperviseMap">
		<![CDATA[
		select * from base_company_supervise
		where del_flag = 0
		and company_id = #{companyId}
		and record_time = #{recordTime}
        limit 1
		]]>
	</select>

	<select id="findTotalNumByCompanyIdAndDate" resultType="Integer">
		<![CDATA[
		select sum(total_num) from base_company_supervise
		where del_flag = 0
		and record_time = #{date}
		]]>
		<foreach collection="list" item="personSuperviseRelation" open="and company_id in(" separator="," close=")">
			#{personSuperviseRelation.companyId}
		</foreach>
	</select>

	<select id="findTotalCheckNumByCompanyIdAndDate" resultType="Integer">
		<![CDATA[
		select sum(total_check_num) from base_company_supervise
		where del_flag = 0
		and record_time = #{date}
		]]>
		<foreach collection="list" item="personSuperviseRelation" open="and company_id in(" separator="," close=")">
			#{personSuperviseRelation.companyId}
		</foreach>
	</select>

	<select id="findTotalAbnormalNumByCompanyIdAndDate" resultType="Integer">
		<![CDATA[
		select sum(total_abnormal_num) from base_company_supervise
		where del_flag = 0
		and record_time = #{date}
		]]>
		<foreach collection="list" item="personSuperviseRelation" open="and company_id in(" separator="," close=")">
			#{personSuperviseRelation.companyId}
		</foreach>
	</select>

	<select id="findLeaveNumByCompanyIdAndDate" resultType="Integer">
		<![CDATA[
		select sum(leave_num) from base_company_supervise
		where del_flag = 0
		and record_time = #{date}
		]]>
		<foreach collection="list" item="personSuperviseRelation" open="and company_id in(" separator="," close=")">
			#{personSuperviseRelation.companyId}
		</foreach>
	</select>

</mapper>