<?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.prolog.cs.base.gsp.dao.GspUpkeepCheckPlanMapper">

	<sql id="Base_Column_List">
		ID, CODE, ENTERPRISE_ID, DC_ID, WAREHOUSE_ID, CARGO_OWNER_ID, STATUS, SOURCE, GMT_CREATE, CREATOR, CREATOR_NAME, GMT_MODIFIED, MODIFIER, MODIFIER_NAME, REMARK, PRINT_COUNT, BLDG_ID, IS_PROTECTED, UPKEEP_TYPE
	</sql>

	<select id="findList" resultMap="map">
		SELECT
		<include refid="Base_Column_List" />
		FROM
			GSP_UPKEEP_CHECK_PLAN p
		WHERE
			EXISTS (
				SELECT
				1
				FROM
				GSP_UPKEEP_CHECK c
				WHERE
				p.id = c.plan_id
				<if test='type != null and type =="1"'>
					and c.STATUS = 0
				</if>
				<if test='type != null and type =="2"'>
					and c.conclusion = 2 and status &lt;&gt; 6
				</if>
				<if test="upkeepType != null  and upkeepType !=''">
					and c.UPKEEP_TYPE = #{upkeepType}
				</if>	  
				<if test="enterpriseId != null  and enterpriseId !=''">
					and c.enterprise_id = #{enterpriseId}
				</if>
				<if test="warehouseId != null  and warehouseId !=''">
					and c.warehouse_id = #{warehouseId}
				</if>
				<if test="cargoOwnerId != null  and cargoOwnerId !=''">
					and c.CARGO_OWNER_ID = #{cargoOwnerId}
				</if>
				<if test="itemHealthCategory != null  and itemHealthCategory !=''">
					and c.ITEM_HEALTH_CATEGORY = #{itemHealthCategory}
				</if>
				<if test="itemId != null  and itemId !=''">
					and c.ITEM_ID = #{itemId}
				</if>
				<!-- 根据执行时间来做 -->
				<if test="startTime != null ">
					and c.PLAN_UPKEEP_DATE  &gt;= #{startTime}
				</if>
				<if test="endTime != null ">
					and c.PLAN_UPKEEP_DATE &lt; #{endTime}
				</if>
				)
		order by p.GMT_CREATE desc
	</select>

	<update id="updateGspYHPrintCount" >
		UPDATE GSP_UPKEEP_CHECK_PLAN set PRINT_COUNT = PRINT_COUNT+1  WHERE id = #{id}
	</update>

</mapper>
