<?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.os.ems.info.mapper.PowerEnergySparePartsRegistrationMapper" >
<resultMap type= "PowerEnergySparePartsRegistration" id= "PowerEnergySparePartsRegistrationResult" >
<result property= "objid" column= "objid" />
<result property= "date" column= "date" />
<result property= "sparePartsName" column= "spare_parts_name" />
<result property= "wasteQuantity" column= "waste_quantity" />
<result property= "storageLocation" column= "storage_location" />
<result property= "registrar" column= "registrar" />
<result property= "warehouseConfirmation" column= "warehouse_confirmation" />
<result property= "remarks" column= "remarks" />
<result property= "sparePartModel" column= "spare_part_model" />
</resultMap>
<sql id= "selectPowerEnergySparePartsRegistrationVo" >
select objid, date, spare_parts_name, waste_quantity, storage_location, registrar, warehouse_confirmation, remarks, spare_part_model from power_energy_spare_parts_registration
</sql>
<select id= "selectPowerEnergySparePartsRegistrationList" parameterType= "PowerEnergySparePartsRegistration" resultMap= "PowerEnergySparePartsRegistrationResult" >
<include refid= "selectPowerEnergySparePartsRegistrationVo" />
<where >
<!-- 日期查询:优先使用日期范围,如果没有范围则使用精确日期 -->
<choose >
<when test= "params != null and ((params.beginDate != null and params.beginDate != '') or (params.endDate != null and params.endDate != ''))" >
<!-- 日期范围查询 -->
<if test= "params.beginDate != null and params.beginDate != '' and params.endDate != null and params.endDate != ''" >
and STR_TO_DATE(date, '%Y/%m/%d') BETWEEN STR_TO_DATE(#{params.beginDate}, '%Y/%m/%d') AND STR_TO_DATE(#{params.endDate}, '%Y/%m/%d')
</if>
<if test= "params.beginDate != null and params.beginDate != '' and (params.endDate == null or params.endDate == '')" >
and STR_TO_DATE(date, '%Y/%m/%d') >= STR_TO_DATE(#{params.beginDate}, '%Y/%m/%d')
</if>
<if test= "params.endDate != null and params.endDate != '' and (params.beginDate == null or params.beginDate == '')" >
and STR_TO_DATE(date, '%Y/%m/%d') < = STR_TO_DATE(#{params.endDate}, '%Y/%m/%d')
</if>
</when>
<otherwise >
<!-- 精确日期查询 -->
<if test= "date != null and date != ''" >
and date = #{date}
</if>
</otherwise>
</choose>
<if test= "sparePartsName != null and sparePartsName != ''" > and spare_parts_name like concat('%', #{sparePartsName}, '%')</if>
<if test= "wasteQuantity != null " > and waste_quantity like concat('%', #{wasteQuantity}, '%')</if>
<if test= "storageLocation != null and storageLocation != ''" > and storage_location like concat('%', #{storageLocation}, '%')</if>
<if test= "registrar != null and registrar != ''" > and registrar like concat('%', #{registrar}, '%')</if>
<if test= "warehouseConfirmation != null and warehouseConfirmation != ''" > and warehouse_confirmation like concat('%', #{warehouseConfirmation}, '%')</if>
<if test= "remarks != null and remarks != ''" > and remarks = #{remarks}</if>
<if test= "sparePartModel != null and sparePartModel != ''" > and spare_part_model like concat('%', #{sparePartModel}, '%')</if>
</where>
order by STR_TO_DATE(date, '%Y/%m/%d') desc, objid desc
</select>
<select id= "selectPowerEnergySparePartsRegistrationByObjid" parameterType= "Long" resultMap= "PowerEnergySparePartsRegistrationResult" >
<include refid= "selectPowerEnergySparePartsRegistrationVo" />
where objid = #{objid}
</select>
<insert id= "insertPowerEnergySparePartsRegistration" parameterType= "PowerEnergySparePartsRegistration" useGeneratedKeys= "true" keyProperty= "objid" >
insert into power_energy_spare_parts_registration
<trim prefix= "(" suffix= ")" suffixOverrides= "," >
<if test= "date != null" > date,</if>
<if test= "sparePartsName != null" > spare_parts_name,</if>
<if test= "wasteQuantity != null" > waste_quantity,</if>
<if test= "storageLocation != null" > storage_location,</if>
<if test= "registrar != null" > registrar,</if>
<if test= "warehouseConfirmation != null" > warehouse_confirmation,</if>
<if test= "remarks != null" > remarks,</if>
<if test= "sparePartModel != null" > spare_part_model,</if>
</trim>
<trim prefix= "values (" suffix= ")" suffixOverrides= "," >
<if test= "date != null" > #{date},</if>
<if test= "sparePartsName != null" > #{sparePartsName},</if>
<if test= "wasteQuantity != null" > #{wasteQuantity},</if>
<if test= "storageLocation != null" > #{storageLocation},</if>
<if test= "registrar != null" > #{registrar},</if>
<if test= "warehouseConfirmation != null" > #{warehouseConfirmation},</if>
<if test= "remarks != null" > #{remarks},</if>
<if test= "sparePartModel != null" > #{sparePartModel},</if>
</trim>
</insert>
<update id= "updatePowerEnergySparePartsRegistration" parameterType= "PowerEnergySparePartsRegistration" >
update power_energy_spare_parts_registration
<trim prefix= "SET" suffixOverrides= "," >
<if test= "date != null" > date = #{date},</if>
<if test= "sparePartsName != null" > spare_parts_name = #{sparePartsName},</if>
<if test= "wasteQuantity != null" > waste_quantity = #{wasteQuantity},</if>
<if test= "storageLocation != null" > storage_location = #{storageLocation},</if>
<if test= "registrar != null" > registrar = #{registrar},</if>
<if test= "warehouseConfirmation != null" > warehouse_confirmation = #{warehouseConfirmation},</if>
<if test= "remarks != null" > remarks = #{remarks},</if>
<if test= "sparePartModel != null" > spare_part_model = #{sparePartModel},</if>
</trim>
where objid = #{objid}
</update>
<delete id= "deletePowerEnergySparePartsRegistrationByObjid" parameterType= "Long" >
delete from power_energy_spare_parts_registration where objid = #{objid}
</delete>
<delete id= "deletePowerEnergySparePartsRegistrationByObjids" parameterType= "String" >
delete from power_energy_spare_parts_registration where objid in
<foreach item= "objid" collection= "array" open= "(" separator= "," close= ")" >
#{objid}
</foreach>
</delete>
</mapper>