<?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="cn.pluss.platform.mapper.DeviceMapper">

	   	<insert id="saveDevice" parameterType="cn.pluss.platform.entity.Device">
        	insert into tb_pluss_device(name,type,introDesc,seq,status,createDt,matNo,venderName,venderModel,aisleModel,inventory,unitPrice,deviceLogo,venderCode,detail)VALUES(#{name},#{type},#{introDesc},#{seq},#{status},NOW(),#{matNo},#{venderName},#{venderModel},#{aisleModel},#{inventory},#{unitPrice},#{deviceLogo},#{venderCode},#{detail})
    	</insert>

	   	<insert id="saveDeviceBatch">
        	insert into tb_pluss_device(name,type,introDesc,seq,status,createDt) VALUES 
    			<foreach collection="list" item="item" index="index" separator=",">
			(#{name},#{type},#{introDesc},#{seq},#{status},#{createDt}		)
				</foreach>
    	</insert>

		<select id="queryDevice" parameterType="cn.pluss.platform.entity.Device" resultType="cn.pluss.platform.entity.Device">
			SELECT * from tb_pluss_device 
				<where> 
					<if test="id!= null"> 
					 	and id = #{id}
					 </if> 
					<if test="name!= null"> 
					 	and name = #{name}
					 </if> 
					<if test="type!= null"> 
					 	and type = #{type}
					 </if> 
					<if test="introDesc!= null"> 
					 	and introDesc = #{introDesc}
					 </if> 
					<if test="seq!= null"> 
					 	and seq = #{seq}
					 </if> 
					<if test="status!= null"> 
					 	and status = #{status}
					 </if> 
					<if test="createDt!= null"> 
					 	and createDt = #{createDt}
					 </if> 
					<if test="matNo!= null"> 
					 	and matNo = #{matNo}
					 </if> 
					 <if test="venderName!= null"> 
                        and venderName = #{venderName}
                     </if> 
                    <if test="venderModel!= null"> 
                        and venderModel = #{venderModel}
                     </if> 
                    <if test="aisleModel!= null"> 
                        and aisleModel = #{aisleModel}
                     </if> 
                    <if test="inventory!= null"> 
                        and inventory = #{inventory}
                     </if> 
                    <if test="unitPrice!= null"> 
                        and unitPrice = #{unitPrice}
                     </if> 
                    <if test="deviceLogo!= null"> 
                        and deviceLogo = #{deviceLogo}
                     </if> 
                    <if test="venderCode!= null"> 
                        and venderCode = #{venderCode}
                     </if> 
                    <if test="detail!= null"> 
                        and detail = #{detail}
                     </if> 
				 </where> 
		</select>

		<select id="queryDeviceList" parameterType="cn.pluss.platform.entity.Device" resultType="cn.pluss.platform.entity.Device">
			SELECT * from tb_pluss_device 
				<where> 
					<if test="id!= null"> 
					 and 	id = #{id}
					 </if> 
					<if test="name!= null"> 
					 and 	name = #{name}
					 </if> 
					<if test="type!= null"> 
					 and 	type = #{type}
					 </if> 
					<if test="introDesc!= null"> 
					 and 	introDesc = #{introDesc}
					 </if> 
					<if test="seq!= null"> 
					 and 	seq = #{seq}
					 </if> 
					<if test="status!= null"> 
					 and 	status = #{status}
					 </if> 
					<if test="createDt!= null"> 
					 and 	createDt = #{createDt}
					 </if> 
					 <if test="matNo!= null"> 
                        and matNo = #{matNo}
                     </if>
                      <if test="venderName!= null"> 
                        and venderName = #{venderName}
                     </if> 
                    <if test="venderModel!= null"> 
                        and venderModel = #{venderModel}
                     </if> 
                    <if test="aisleModel!= null"> 
                        and aisleModel = #{aisleModel}
                     </if> 
                    <if test="inventory!= null"> 
                        and inventory = #{inventory}
                     </if> 
                    <if test="unitPrice!= null"> 
                        and unitPrice = #{unitPrice}
                     </if> 
                      <if test="deviceLogo!= null"> 
                        and deviceLogo = #{deviceLogo}
                     </if>
                     <if test="venderCode!= null"> 
                        and venderCode = #{venderCode}
                     </if>
                     <if test="detail!= null"> 
                        and detail = #{detail}
                     </if> 
				 </where> 
		</select>

		<update id="updateDevice" parameterType="cn.pluss.platform.entity.Device" >
			update tb_pluss_device 
				  <set> 
					<if test="name!= null"> 
					 	name = #{name},
					 </if> 
					<if test="type!= null"> 
					 	type = #{type},
					 </if> 
					<if test="introDesc!= null"> 
					 	introDesc = #{introDesc},
					 </if> 
					<if test="seq!= null"> 
					 	seq = #{seq},
					 </if> 
					<if test="status!= null"> 
					 	status = #{status},
					 </if> 
					<if test="createDt!= null"> 
					 	createDt = #{createDt},
					 </if> 
					 <if test="matNo!= null"> 
                         matNo = #{matNo},
                     </if>
                      <if test="venderName!= null"> 
                         venderName = #{venderName},
                     </if> 
                    <if test="venderModel!= null"> 
                         venderModel = #{venderModel},
                     </if> 
                    <if test="aisleModel!= null"> 
                         aisleModel = #{aisleModel},
                     </if> 
                    <if test="inventory!= null"> 
                         inventory = #{inventory},
                     </if> 
                    <if test="unitPrice!= null"> 
                         unitPrice = #{unitPrice},
                     </if> 
                      <if test="deviceLogo!= null"> 
                         deviceLogo = #{deviceLogo},
                     </if>
                     <if test="venderCode!= null"> 
                         venderCode = #{venderCode},
                     </if>
                     <if test="detail!= null"> 
                         detail = #{detail}
                     </if> 
				</set>
			where id=#{id} 
		</update>

		<delete id="deleteDevice" parameterType="cn.pluss.platform.entity.Device" >
			DELETE FROM tb_pluss_device where id=#{id}
		</delete>

		<select id="queryDevicePage" parameterType="java.util.Map" resultType="cn.pluss.platform.entity.Device">
			SELECT * from tb_pluss_device 
				<where> 
					<if test="id!= null"> 
					and id = #{id}
					 </if> 
					<if test="name!= null and name!=''"> 
					and name LIKE CONCAT('%',#{name},'%')
					 </if> 
					<if test="type!= null"> 
					and type = #{type}
					 </if> 
					<if test="introDesc!= null"> 
					and introDesc = #{introDesc}
					 </if> 
					<if test="seq!= null"> 
					and seq = #{seq}
					 </if> 
					<if test="status!= null">
					and status = #{status}
					 </if> 
					<if test="createDt!= null"> 
					and createDt = #{createDt}
					 </if> 
					 <if test="matNo!= null"> 
                        and matNo = #{matNo}
                     </if>
                      <if test="venderName!= null and venderName!=''"> 
                        and venderName LIKE CONCAT('%',#{venderName},'%') 
                     </if> 
                    <if test="venderModel!= null and venderModel!=''"> 
                        and venderModel LIKE CONCAT('%',#{venderModel},'%') 
                     </if> 
                    <if test="aisleModel!= null"> 
                        and aisleModel = #{aisleModel}
                     </if> 
                    <if test="inventory!= null"> 
                        and inventory = #{inventory}
                     </if> 
                    <if test="unitPrice!= null"> 
                        and unitPrice = #{unitPrice}
                     </if> 
                     <if test="startTime!= null and startTime!=''"> 
                         <![CDATA[
                            and  DATE_FORMAT(createDt, '%Y-%m-%d %H:%i:%S')>=DATE_FORMAT(#{startTime}, '%Y-%m-%d %H:%i:%S')
                         ]]>
                     </if> 
                    <if test="endTime!= null and endTime!=''"> 
                         <![CDATA[
                            and  DATE_FORMAT(createDt, '%Y-%m-%d %H:%i:%S')<=DATE_FORMAT(#{endTime}, '%Y-%m-%d %H:%i:%S')
                         ]]>
                     </if> 
                      <if test="deviceLogo!= null"> 
                        and deviceLogo = #{deviceLogo}
                     </if>
                     <if test="venderCode!= null"> 
                        and venderCode = #{venderCode}
                     </if>
                     <if test="detail!= null"> 
                        and detail = #{detail}
                     </if> 
				 </where> 
			order by seq asc  limit #{pageSize}  offset  #{offset}  
		</select>

		<select id="queryDevicePageCount" parameterType="java.util.Map" resultType="java.lang.Integer">
			SELECT count(*) from tb_pluss_device 
					<where> 
					<if test="id!= null"> 
					 and id = #{id}
					 </if> 
					<if test="name!= null and name!=''.toString"> 
					 and name LIKE CONCAT('%',#{name},'%')
					 </if> 
					<if test="type!= null"> 
					 and type = #{type}
					 </if> 
					<if test="introDesc!= null"> 
					 and introDesc = #{introDesc}
					 </if> 
					<if test="seq!= null"> 
					 and seq = #{seq}
					 </if> 
					<if test="status!= null">
						and status = #{status}
					</if>
					 
					 <if test="startTime!= null and startTime!=''"> 
                         <![CDATA[
                            and  DATE_FORMAT(createDt, '%Y-%m-%d %H:%i:%S')>=DATE_FORMAT(#{startTime}, '%Y-%m-%d %H:%i:%S')
                         ]]>
                     </if> 
                    <if test="endTime!= null and endTime!=''"> 
                         <![CDATA[
                            and  DATE_FORMAT(createDt, '%Y-%m-%d %H:%i:%S')<=DATE_FORMAT(#{endTime}, '%Y-%m-%d %H:%i:%S')
                         ]]>
                     </if>  
					<if test="createDt!= null"> 
					 and createDt = #{createDt}
					 </if>
					 <if test="matNo!= null"> 
                        and matNo = #{matNo}
                     </if> 
                      <if test="venderName!= null and venderName!=''">
                        and venderName LIKE CONCAT('%',#{venderName},'%') 
                     </if> 
                    <if test="venderModel!= null and venderModel!='' "> 
                        and venderModel LIKE CONCAT('%',#{venderModel},'%') 
                     </if> 
                    <if test="aisleModel!= null"> 
                        and aisleModel = #{aisleModel}
                     </if> 
                    <if test="inventory!= null"> 
                        and inventory = #{inventory}
                     </if> 
                    <if test="unitPrice!= null"> 
                        and unitPrice = #{unitPrice}
                     </if> 
                      <if test="deviceLogo!= null"> 
                        and deviceLogo = #{deviceLogo}
                     </if>
                     <if test="venderCode!= null"> 
                        and venderCode = #{venderCode}
                     </if>
                     <if test="detail!= null"> 
                        and detail = #{detail}
                     </if> 
				</where>
		</select>

		<select id="pageDate" resultType="cn.pluss.platform.entity.Device">
				SELECT id,`name`,matNo,deviceLogo,`type`,introDesc,seq,`status`,
					createDt,venderName,venderCode,venderModel,aisleModel,inventory,unitPrice,detail
				FROM tb_pluss_device
				<where>
					<if test="device.id!= null">
						and id = #{device.id}
					</if>
					<if test="device.name != null  and device.name !=''.toString ">
						and name LIKE CONCAT('%',#{device.name},'%')
					</if>
					<if test="device.venderName!= null and device.venderName!=''">
						and venderName LIKE CONCAT('%',#{device.venderName},'%')
					</if>
					<if test="device.venderModel!= null and device.venderModel!='' ">
						and venderModel LIKE CONCAT('%',#{device.venderModel},'%')
					</if>
					<if test="device.status!= null">
						and status = #{device.status}
					</if>
					<if test="device.startTime != null">
						and createDt &gt;= #{device.startTime}
					</if>
					<if test="device.endTime!= null">
						and createDt &lt;= #{device.endTime}
					</if>
				</where>
		</select>

		<select id="getDeviceId" resultType="cn.pluss.platform.entity.Device">
			SELECT id,`name`,matNo,deviceLogo,`type`,introDesc,seq,`status`,
					createDt,venderName,venderCode,venderModel,aisleModel,inventory,unitPrice,detail
			FROM tb_pluss_device
			<where>
				<if test="id!= null">
					and id = #{id}
				</if>
			</where>
		</select>

</mapper>
