<?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.jeeplus.modules.projectreportnum.dao.ProjectReportNumDao">
    
	<sql id="infoColums">
		a.id AS "id",
		a.create_by AS "createBy.id",
		a.create_date AS "createDate",
		a.update_by AS "updateBy.id",
		a.update_date AS "updateDate",
		a.remarks AS "remarks",
		a.del_flag AS "delFlag",
		a.num AS "num",
		a.state AS "state"

	</sql>
	
    
	<select id="get" resultType="ReportNum" >
		SELECT 
			<include refid="infoColums"/>
		FROM report_num a
		WHERE a.id = #{id}
	</select>
	
	<select id="findList" resultType="ReportNum" >
		SELECT 
			<include refid="infoColums"/>
		FROM report_num a
		
		<where>
			a.del_flag = #{DEL_FLAG_NORMAL} and a.state = '0' and a.create_by = #{userId}
		</where>
		<choose>
			<when test="page !=null and page.orderBy != null and page.orderBy != ''">
				ORDER BY ${page.orderBy}
			</when>
			<otherwise>
				ORDER BY a.update_date
			</otherwise>
		</choose>
	</select>


	<select id="countNum" parameterType="String" resultType="Integer">
		select count(id)
		 from report_num
		<where>
			create_by = #{userId} and state = '0'
		</where>
	</select>
	
	
	
	<insert id="insert">
		INSERT INTO report_num(
			id,
			create_by,
			create_date,
			update_by,
			update_date,
			remarks,
			del_flag,
			num,
			state
		) VALUES (
			#{id},
			#{createBy.id},
			#{createDate},
			#{updateBy.id},
			#{updateDate},
			#{remarks},
			#{delFlag},
			#{num},
			#{state}
		)
	</insert>
	
	<update id="updateNum">
		UPDATE report_num SET
			state = '1'
		WHERE num = #{num}
	</update>
	
	
	<!--物理删除-->
	<update id="delete">
		DELETE FROM report_num
		WHERE id = #{id}
	</update>
	

	
	





</mapper>