<?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.ym.mec.biz.dal.dao.ReplacementInstrumentDao">
	
	<resultMap type="com.ym.mec.biz.dal.entity.ReplacementInstrument" id="ReplacementInstrument">
		<result column="id_" property="id" />
		<result column="subject_id_" property="subjectId" />
		<result column="brand_" property="brand" />
		<result column="specification_" property="specification" />
		<result column="param_" property="param" />
		<result column="market_price_" property="marketPrice" />
		<result column="discount_price_" property="discountPrice" />
		<result column="depreciation_price_" property="depreciationPrice" />
		<result column="sale_price_" property="salePrice" />
		<result column="create_time_" property="createTime" />
		<result column="update_time_" property="updateTime" />
	</resultMap>

	<!-- 根据主键查询一条记录 -->
	<select id="get" resultMap="ReplacementInstrument" >
		SELECT * FROM replacement_instrument WHERE id_ = #{id}
	</select>
	
	
	<!-- 全查询 -->
	<select id="findAll" resultMap="ReplacementInstrument">
		SELECT * FROM replacement_instrument
	</select>
	
	<!-- 向数据库增加一条记录 -->
	<insert id="insert" parameterType="com.ym.mec.biz.dal.entity.ReplacementInstrument" useGeneratedKeys="true" keyColumn="id" keyProperty="id">
		INSERT INTO replacement_instrument (subject_id_,brand_,specification_,param_,market_price_,discount_price_,depreciation_price_,sale_price_,create_time_,update_time_)
		VALUES(#{subjectId},#{brand},#{specification},#{param},#{marketPrice},#{discountPrice},#{depreciationPrice},#{salePrice},NOW(),NOW())
	</insert>

	<update id="update" parameterType="com.ym.mec.biz.dal.entity.ReplacementInstrument">
		UPDATE replacement_instrument <set>
		<if test="subjectId != null">
			subject_id_ = #{subjectId},
		</if>
		<if test="brand != null">
			brand_ = #{brand},
		</if>
		<if test="specification != null">
			specification_ = #{specification},
		</if>
		<if test="param != null">
			param_ = #{param},
		</if>
		<if test="marketPrice != null">
			market_price_ = #{marketPrice},
		</if>
		<if test="discountPrice != null">
			discount_price_ = #{discountPrice},
		</if>
		<if test="depreciationPrice != null">
			depreciation_price_ = #{depreciationPrice},
		</if>
		<if test="salePrice != null">
			sale_price_ = #{salePrice},
		</if>
		<if test="updateTime != null">
			update_time_ = #{updateTime},
		</if>
	</set> WHERE id_ = #{id}
	</update>

	<!-- 根据主键删除一条记录 -->
	<delete id="delete" >
		DELETE FROM replacement_instrument_activity WHERE id_ = #{id}
	</delete>

	<!-- 分页查询 -->
	<select id="queryPage" resultMap="ReplacementInstrument" parameterType="map">
		SELECT * FROM replacement_instrument
		<include refid="queryPageSql"/>
		ORDER BY id_
		<include refid="global.limit"/>
	</select>
	<sql id="queryPageSql">
		<where>
			<if test="subjectId != null">
				AND subject_id_ = #{subjectId}
			</if>
			<if test="brand != null">
				AND brand_ = #{brand}
			</if>
			<if test="specification != null">
				AND specification_ = #{specification}
			</if>
		</where>
	</sql>
	
	<!-- 查询当前表的总记录数 -->
	<select id="queryCount" resultType="int">
		SELECT COUNT(id_) FROM replacement_instrument
		<include refid="queryPageSql"/>
	</select>
</mapper>
