| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124 | 
							- <?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">
 
- <!-- 命名,每一个映射对象不一样
 
- 	namespace:必须与对应的接口全类名一致
 
-  -->
 
- <mapper namespace="com.iamberry.app.mapper.MachineMapper">
 
- 	<sql id="allMachineField">
 
- 		ID,
 
- 		OWNER,
 
- 		MACHINE_NAME,
 
- 		MACHINE_MAC,
 
- 		MACHINE_INFO,
 
- 		STATUS_,
 
- 		LOCATION,
 
- 		CREATED_ON
 
- 	</sql>
 
- 	
 
- 	<!--通过<resultMap>映射实体类属性名和表的字段名对应关系 -->
 
-     <resultMap type="Machine" id="machineMap">
 
-         <!-- 用id属性来映射主键字段 -->
 
-         <id property="id" column="id"/>
 
-         <!-- 用result属性来映射非主键字段 -->
 
-         <result property="owner" column="owner"/>
 
-         <result property="machine_name" column="machine_name"/>
 
-         <result property="machine_mac" column="machine_mac"/>
 
-         <result property="machine_info" column="machine_info"/>
 
-         <result property="status_" column="status_"/>
 
-         <result property="location" column="location"/>
 
-         <result property="created_on" column="created_on"/>
 
-     </resultMap>
 
-     
 
-     
 
- 	<!-- 添加一台机器 -->
 
- 	<insert id="insertMachine" parameterType="Machine"
 
- 		useGeneratedKeys="true" keyProperty="id">
 
- 		INSERT INTO MACHINE 
 
- 			(MACHINE_NAME,MACHINE_MAC,MACHINE_INFO,OWNER,STATUS_,LOCATION,CREATED_ON)
 
- 		VALUES
 
- 			(
 
- 				#{machine_name},#{machine_mac},#{machine_info},#{owner}
 
- 				,#{status_},#{location},#{created_on}
 
- 			)
 
- 	</insert>
 
- 	<!-- 根据id 修改一台机器信息  -->
 
- 	<update id="updateMachine" parameterType="Machine">
 
- 		UPDATE MACHINE
 
- 		<set>
 
- 			<if test="owner != null and owner != ''">
 
- 				OWNER=#{owner},
 
- 			</if>
 
- 			<if test="machine_name != null and machine_name != ''">
 
- 				MACHINE_NAME=#{machine_name},
 
- 			</if>
 
- 			<if test="machine_mac != null and machine_mac != ''">
 
- 				MACHINE_MAC=#{machine_mac},
 
- 			</if>
 
- 			<if test="machine_info != null and machine_info != ''">
 
- 				MACHINE_INFO=#{machine_info},
 
- 			</if>
 
- 			<if test="status_ != null and status_ != ''">
 
- 				STATUS_=#{status_},
 
- 			</if>
 
- 			<if test="location != null and location != ''">
 
- 				LOCATION=#{location},
 
- 			</if>
 
- 			<if test="created_on != null and created_on != ''">
 
- 				CREATED_ON=#{created_on},
 
- 			</if>
 
- 		</set>
 
- 		WHERE ID=#{id}
 
- 	</update>
 
- 	
 
- 	<!-- 根据id 修改一台机器的状态-->
 
- 	<update id="updateMachineStatus" parameterType="Machine">
 
- 		UPDATE MACHINE 
 
- 		SET STATUS_ = #{0},CREATED_ON = NOW() 
 
- 		WHERE ID = #{1}
 
- 	</update>
 
- 	
 
- 	<!-- 根据机器码 修改一台机器的状态-->
 
- 	<update id="updateStatusByMac">
 
- 		UPDATE MACHINE 
 
- 		SET STATUS_ = #{1},CREATED_ON = NOW() 
 
- 		WHERE machine_mac = #{0}
 
- 	</update>
 
- 	
 
- 	<!-- 根据id 修改一台机器的位置信息-->
 
- 	<update id="updateMachineLocation" parameterType="Machine">
 
- 		UPDATE MACHINE 
 
- 		SET LOCATION = #{0} 
 
- 		WHERE ID = #{1}
 
- 	</update>
 
- 	
 
- 	<!-- 按用户,查询所有机器 -->
 
- 	<select id="selectMachineByOwner" parameterType="long" resultMap="machineMap">
 
- 		SELECT 
 
- 			<include refid="allMachineField"></include>
 
- 		FROM MACHINE WHERE OWNER = #{owner}
 
- 	</select>
 
- 	
 
- 	<!-- 根据id 查询一台机器 -->
 
- 	<select id="selectMachineById" parameterType="long" resultMap="machineMap">
 
- 		SELECT 
 
- 			<include refid="allMachineField"></include>
 
- 		FROM MACHINE WHERE ID = #{id}
 
- 	</select>
 
- 	
 
- 	<!-- 根据机器码和所属用户 查一台机器id -->
 
- 	<select id="isDevUserPairExist" resultType="Long">
 
- 		SELECT ID
 
- 		FROM MACHINE WHERE  MACHINE_MAC = #{0} AND OWNER = #{1}
 
- 	</select>
 
- 	
 
- 	<!-- 根据机器的ID,查询最近的一个用户ID -->
 
- 	<select id="selectUserIDByDevId" parameterType="String" resultType="Long">
 
- 		SELECT OWNER 
 
- 		FROM MACHINE 
 
- 		WHERE MACHINE_MAC = #{devid} ORDER BY id DESC LIMIT 0, 1
 
- 	</select>
 
- </mapper>
 
 
  |