WarehouseDao.xml 2.5 KB
<?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.thinkgem.jeesite.modules.yard.dao.WarehouseDao">
    
	<sql id="warehouseColumns">
		a.*,
		b.id AS "yard.id",
		b.name AS "yard.name",
		b.customs_code AS "yard.customsCode"
	</sql>
	
	<sql id="warehouseJoins">
			JOIN yard b ON b.id = a.yard_id
	</sql>
    
	<select id="get" resultType="Warehouse">
		SELECT 
			<include refid="warehouseColumns"/>
		FROM warehouse a
		<include refid="warehouseJoins"/>
		WHERE a.id = #{id}
	</select>
	
	<select id="findList" resultType="Warehouse">
		SELECT 
			<include refid="warehouseColumns"/>
		FROM warehouse a
		<include refid="warehouseJoins"/>
		<where>
			a.del_flag = #{DEL_FLAG_NORMAL}
			<if test="yard != null and yard != ''">
				AND b.name LIKE
					<if test="dbName == 'oracle'">'%'||#{yard.name}||'%'</if>
					<if test="dbName == 'mssql'">'%'+#{yard.name}+'%'</if>
					<if test="dbName == 'mysql'">concat('%',#{yard.name},'%')</if>
			</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="Warehouse">
		SELECT 
			<include refid="warehouseColumns"/>
		FROM warehouse a
		<include refid="warehouseJoins"/>
		<where>
			a.del_flag = #{DEL_FLAG_NORMAL}
		</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 warehouse(
			id,
			yard_id,
			name,
			create_by,
			create_date,
			update_by,
			update_date,
			remarks,
			del_flag
		) VALUES (
			#{id},
			#{yardId},
			#{name},
			#{createBy.id},
			#{createDate},
			#{updateBy.id},
			#{updateDate},
			#{remarks},
			#{delFlag}
		)
	</insert>
	
	<update id="update">
		UPDATE warehouse SET 	
			yard_id = #{yardId},
			name = #{name},
			remarks = #{remarks}
		WHERE id = #{id}
	</update>
	
	<update id="delete">
		UPDATE warehouse SET 
			del_flag = #{DEL_FLAG_DELETE}
		WHERE id = #{id}
	</update>
	
</mapper>