<?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.ProfitWarehousingInfoMapper">
    
	<sql id="profitWarehousingInfoColumns">
		a.id AS "id",
		a.profit_warehousing_id AS "profitWarehousing.id",
		profitWarehousing.number AS "profitWarehousing.number",
		a.name AS "name",
		a.type AS "type.id",
		a.marking AS "marking",
		a.shelves_id AS "shelves.id",
		a.warehouse_id AS "warehouse.id",
		warehouse.name AS "warehouse.name",
		a.qr_id AS "qrCode.id",
		a.amount AS "amount",
		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="profitWarehousingInfoJoins">
		LEFT JOIN t_wh_material_type type ON type.id = a.type
		LEFT JOIN t_wh_warehouse warehouse ON warehouse.id = a.warehouse_id
		LEFT JOIN t_profit_warehousing profitWarehousing ON profitWarehousing.id = a.profit_warehousing_id
	</sql>
	
    
	<select id="get" resultType="ProfitWarehousingInfo" >
		SELECT 
			<include refid="profitWarehousingInfoColumns"/>
		FROM t_wh_profit_warehousing_info a
		<include refid="profitWarehousingInfoJoins"/>
		WHERE a.id = #{id}
	</select>
	
	<select id="findList" resultType="ProfitWarehousingInfo" >
		SELECT 
			<include refid="profitWarehousingInfoColumns"/>
		FROM t_wh_profit_warehousing_info a
		<include refid="profitWarehousingInfoJoins"/>
		<where>
			a.del_flag = #{DEL_FLAG_NORMAL}
			${dataScope}
			<if test="profitWarehousing != null and profitWarehousing.id != null and profitWarehousing.id != ''">
				AND a.profit_warehousing_id = #{profitWarehousing.id}
			</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="ProfitWarehousingInfo" >
		SELECT 
			<include refid="profitWarehousingInfoColumns"/>
		FROM t_wh_profit_warehousing_info a
		<include refid="profitWarehousingInfoJoins"/>
		<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_info(
			id,
			profit_warehousing_id,
			name,
			type,
			marking,
			shelves_id,
			warehouse_id,
			qr_id,
			amount,
			create_by,
			create_date,
			update_by,
			update_date,
			remarks,
			del_flag
		) VALUES (
			#{id},
			#{profitWarehousing.id},
			#{name},
			#{type.id},
			#{marking},
			#{shelves.id},
			#{warehouse.id},
			#{qrCode.id},
			#{amount},
			#{createBy.id},
			#{createDate},
			#{updateBy.id},
			#{updateDate},
			#{remarks},
			#{delFlag}
		)
	</insert>
	
	<update id="update">
		UPDATE t_wh_profit_warehousing_info SET 	
			profit_warehousing_id = #{profitWarehousing.id},
			name = #{name},
			type = #{type},
			marking = #{marking},
			shelves_id = #{shelves.id},
			qr_id = #{qrCode.id},
			warehouse_id = #{warehouse.id},
			amount = #{amount},
			update_by = #{updateBy.id},
			update_date = #{updateDate},
			remarks = #{remarks}
		WHERE id = #{id}
	</update>
	
	
	<!--物理删除-->
	<update id="delete">
		DELETE FROM t_wh_profit_warehousing_info
		WHERE id = #{id}
	</update>
	
	<!--逻辑删除-->
	<update id="deleteByLogic">
		UPDATE t_wh_profit_warehousing_info SET 
			del_flag = #{DEL_FLAG_DELETE}
		WHERE id = #{id}
	</update>
	
	
	<!-- 根据实体名称和字段名称和字段值获取唯一记录 -->
	<select id="findUniqueByProperty" resultType="ProfitWarehousingInfo" statementType="STATEMENT">
		select * FROM t_wh_profit_warehousing_info  where ${propertyName} = '${value}'
	</select>
	
</mapper>