<?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.warehouse.profitwarehousing.mapper.ProfitWarehousingMapper">
    
	<sql id="profitWarehousingColumns">
		a.id AS "id",
		a.number AS "number",
		a.operator AS "operator.id",
		operator.name AS "operator.name",
		a.time AS "time",
		a.sum AS "sum",
		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"
	</sql>
	
	<sql id="profitWarehousingJoins">
		LEFT JOIN sys_user operator ON operator.id = a.operator
	</sql>
	
    
	<select id="get" resultType="ProfitWarehousing" >
		SELECT 
			<include refid="profitWarehousingColumns"/>
		FROM t_wh_profit_warehousing a
		<include refid="profitWarehousingJoins"/>
		WHERE a.id = #{id}
	</select>
	
	<select id="findList" resultType="ProfitWarehousing" >
		SELECT 
			<include refid="profitWarehousingColumns"/>
		FROM t_wh_profit_warehousing a
		<include refid="profitWarehousingJoins"/>
		<where>
			a.del_flag = #{DEL_FLAG_NORMAL}
			${dataScope}
			<if test="number != null and number != ''">
				AND a.number = #{number}
			</if>
			<if test="beginTime != null and beginTime != '' and endTime != ''  and endTime != null ">
				AND a.time BETWEEN #{beginTime} AND #{endTime}
			</if>
		</where>
		<choose>
			<when test="page !=null and page.orderBy != null and page.orderBy != ''">
				ORDER BY ${page.orderBy}
			</when>
			<otherwise>
				ORDER BY a.update_date DESC
			</otherwise>
		</choose>
	</select>
	
	<select id="findAllList" resultType="ProfitWarehousing" >
		SELECT 
			<include refid="profitWarehousingColumns"/>
		FROM t_wh_profit_warehousing a
		<include refid="profitWarehousingJoins"/>
		<where>
			a.del_flag = #{DEL_FLAG_NORMAL}
			${dataScope}
		</where>		
		<choose>
			<when test="page !=null and page.orderBy != null and page.orderBy != ''">
				ORDER BY ${page.orderBy}
			</when>
			<otherwise>
				ORDER BY a.update_date DESC
			</otherwise>
		</choose>
	</select>
	
	<insert id="insert">
		INSERT INTO t_wh_profit_warehousing(
			id,
			number,
			operator,
			time,
			sum,
			create_by,
			create_date,
			update_by,
			update_date,
			remarks,
			del_flag
		) VALUES (
			#{id},
			#{number},
			#{operator.id},
			#{time},
			#{sum},
			#{createBy.id},
			#{createDate},
			#{updateBy.id},
			#{updateDate},
			#{remarks},
			#{delFlag}
		)
	</insert>
	
	<update id="update">
		UPDATE t_wh_profit_warehousing SET 	
			number = #{number},
			operator = #{operator.id},
			time = #{time},
			sum = #{sum},
			update_by = #{updateBy.id},
			update_date = #{updateDate},
			remarks = #{remarks}
		WHERE id = #{id}
	</update>
	
	
	<!--物理删除-->
	<update id="delete">
		DELETE FROM t_wh_profit_warehousing
		WHERE id = #{id}
	</update>
	
	<!--逻辑删除-->
	<update id="deleteByLogic">
		UPDATE t_wh_profit_warehousing SET 
			del_flag = #{DEL_FLAG_DELETE}
		WHERE id = #{id}
	</update>
	
	
	<!-- 根据实体名称和字段名称和字段值获取唯一记录 -->
	<select id="findUniqueByProperty" resultType="ProfitWarehousing" statementType="STATEMENT">
		select * FROM t_wh_profit_warehousing  where ${propertyName} = '${value}'
	</select>
	
</mapper>