<?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.shelves.mapper.ShelvesMapper">
    
	<sql id="shelvesColumns">
		a.id AS "id",
		a.name AS "name",
		a.number AS "number",
		a.warehouse_id AS "warehouse.id",
		a.remarks AS "remarks",
		a.create_by AS "createBy.id",
		a.create_date AS "createDate",
		a.update_by AS "updateBy.id",
		a.update_date AS "updateDate",
		a.del_flag AS "delFlag",
		warehouse.name AS "warehouse.name"
	</sql>
	
	<sql id="shelvesJoins">
		left join t_wh_warehouse warehouse on a.warehouse_id = warehouse.id
	</sql>
	
    
	<select id="get" resultType="Shelves" >
		SELECT 
			<include refid="shelvesColumns"/>
		FROM t_wh_shelves a
		<include refid="shelvesJoins"/>
		WHERE a.id = #{id}
	</select>
	
	<select id="findList" resultType="Shelves" >
		SELECT
		a.id AS "id",
		a.name AS "name",
		a.number AS "number",
		a.warehouse_id AS "warehouse.id",
		a.remarks AS "remarks",
		a.create_by AS "createBy.id",
		a.create_date AS "createDate",
		a.update_by AS "updateBy.id",
		a.update_date AS "updateDate",
		a.del_flag AS "delFlag",
		warehouse.name AS "warehouse.name"
		FROM t_wh_shelves a
		<include refid="shelvesJoins"/>
		<where>
			a.del_flag = #{DEL_FLAG_NORMAL}
			${dataScope}
			<if test="number != null and number != ''">
				AND a.number = #{number}
			</if>
			<if test="warehouse != null and warehouse.id != null and warehouse.id != ''">
				AND a.warehouse_id = #{warehouse.id}
			</if>
			<if test="name != null and name != ''">
				AND a.name LIKE
				<if test="dbName == 'oracle'">'%'||#{name}||'%'</if>
				<if test="dbName == 'mssql'">'%'+#{name}+'%'</if>
				<if test="dbName == 'mysql'">concat('%',#{name},'%')</if>
			</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="Shelves" >
		SELECT 
			<include refid="shelvesColumns"/>
		FROM t_wh_shelves a
		<include refid="shelvesJoins"/>
		<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_shelves(
			id,
			name,
			number,
			warehouse_id,
			remarks,
			create_by,
			create_date,
			update_by,
			update_date,
			del_flag
		) VALUES (
			#{id},
			#{name},
			#{number},
			#{warehouse.id},
			#{remarks},
			#{createBy.id},
			#{createDate},
			#{updateBy.id},
			#{updateDate},
			#{delFlag}
		)
	</insert>
	
	<update id="update">
		UPDATE t_wh_shelves SET 	
			name = #{name},
			number = #{number},
			warehouse_id = #{warehouse.id},
			remarks = #{remarks},
			update_by = #{updateBy.id},
			update_date = #{updateDate}
		WHERE id = #{id}
	</update>
	
	
	<!--物理删除-->
	<update id="delete">
		DELETE FROM t_wh_shelves
		WHERE id = #{id}
	</update>
	
	<!--逻辑删除-->
	<update id="deleteByLogic">
		UPDATE t_wh_shelves SET 
			del_flag = #{DEL_FLAG_DELETE}
		WHERE id = #{id}
	</update>
	
	
	<!-- 根据实体名称和字段名称和字段值获取唯一记录 -->
	<select id="findUniqueByProperty" resultType="Shelves" statementType="STATEMENT">
		select * FROM t_wh_shelves  where ${propertyName} = '${value}'
	</select>
	
</mapper>