<?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.yeejoin.amos.supervision.business.dao.mapper.InputItemMapper">
	<update id="updateInputItem" parameterType="com.yeejoin.amos.supervision.dao.entity.InputItem">
		UPDATE p_input_item
		 <trim prefix="set" suffixOverrides=",">
			<if test="catalogId != null">catalog_id=#{catalogId},</if>
			<if test="dataJson != null ">data_json=#{dataJson},</if>
			<if test="defaultValue != null">default_value=#{defaultValue},</if>
			<if test="inputJson != null">input_json=#{inputJson},</if>
			<if test="isMultiline != null">is_multiline=#{isMultiline},</if>
			<if test="isMust != null">is_must=#{isMust},</if>
			<if test="isScore != null ">is_score=#{isScore},</if>
			<if test="itemType != null ">item_type=#{itemType},</if>
			<if test="name !=null ">name=#{name},</if>
			<if test="orderNo > 0 ">order_no=#{orderNo},</if>
			<if test="orgCode != null ">org_code=#{orgCode},</if>
			<if test="pictureJson != null ">picture_json=#{pictureJson},</if>
			<if test="remark != null ">remark=#{remark},</if>
			<if test="level != null ">level=#{level},</if>
			<if test="itemNo != null ">item_no=#{itemNo},</if>
			<if test="riskDesc != null ">risk_desc=#{riskDesc},</if>
		 	<if test="checkMethod != null ">check_method=#{checkMethod},</if>
			 <if test="maintenanceContent != null ">maintenance_content=#{maintenanceContent},</if>
			 <if test="testRequirement != null ">test_requirement=#{testRequirement},</if>
			 <if test="inputClassify != null ">input_classify=#{inputClassify},</if>
			 <if test="unit != null ">unit=#{unit},</if>
			 <if test="checkType != null ">check_type=#{checkType},</if>
			 <if test="itemParent != null ">item_parent=#{itemParent},</if>
			 <if test="itemClassify != null ">item_classify=#{itemClassify},</if>
			 <if test="itemTypeClassify != null ">item_type_classify=#{itemTypeClassify},</if>
			 <if test="itemLevel != null ">item_level=#{itemLevel},</if>
			 <if test="itemTypeClassifyIds != null ">item_type_classify_ids=#{itemTypeClassifyIds},</if>
 		</trim>
 		WHERE id=#{id}
	</update>
	 <!-- 检查项查询 -->
    <select id="countByCatalogId" resultType="java.util.HashMap">
	    SELECT
		    id,name
		FROM
		   p_input_item
		<trim prefix="WHERE" prefixOverrides="AND ">
         <if test="is_delete!=null">and is_delete = #{is_delete}</if>
         <if test="catalog_id!=null"> and catalog_id = #{catalog_id}</if>
         </trim>
    </select>
    <resultMap id="inputItemMap" type="com.yeejoin.amos.supervision.business.vo.InputItemVo">
       <result property="orgCode" column="org_code" />
       <result property="orderNo" column="order_no" />
       <result property="itemType" column="item_Type" />
       <result property="isMust" column="is_Must" />
       <result property="defaultValue" column="default_Value" />
       <result property="isMultiline" column="is_multiline" />
       <result property="inputJson" column="input_json" />
       <result property="dataJson" column="data_json" />
       <result property="pictureJson" column="picture_json" />
       <result property="isScore" column="is_Score" />
       <result property="catalogName" column="catalog_Name" />
       <result property="catalogId" column="catalog_Id" />
       <result property="level" column="level" />
       <result property="itemNo" column="item_no" />
		<result property="riskDesc" column="risk_desc" />
		<result property="maintenanceContent" column="maintenance_content" />
		<result property="testRequirement" column="test_requirement" />
		<result property="checkMethod" column="check_method" />
		<result property="createDate" column="create_date" />
		<result property="inputClassify" column="input_classify" />
		<result property="checkTypeId" column="check_type_id" />
		<result property="checkType" column="check_type" />
		<result property="itemParent" column="item_parent" />
		<result property="itemClassify" column="item_classify" />
		<result property="itemTypeClassify" column="item_type_classify" />
		<result property="itemLevel" column="item_level" />
		<result property="itemStart" column="item_start" />
		<result property="ext" column="ext" />
    </resultMap>
	<!--统计 -->
	<select id="countInputItemInfoData" resultType="long">
		SELECT
		count(1) AS total_num
		FROM
		p_input_item a
		where a.is_delete = '0' and a.input_type != '1'
		<if test="name!=null and name!=''"> and a.name like concat(concat("%",#{name}),"%")</if>
		<if test="itemNo!=null"> and a.item_no like concat(concat("%",#{itemNo}),"%")</if>
		<if test="itemType!=null"> and a.item_Type = #{itemType} </if>
		<if test="checkTypeId!=null and checkTypeId!=''"> and a.check_type_id = #{checkTypeId} </if>
		<if test="itemStart!=null"> and a.item_start = #{itemStart} </if>
		<if test="orgCode!=null"> and a.org_Code = #{orgCode}</if>
		<if test="itemClassify != null"> and a.item_classify = #{itemClassify}</if>
		<if test="itemTypeClassifyIds != null"> and FIND_IN_SET(#{itemTypeClassifyIds}, a.item_type_classify_ids)</if>
		order by a.id desc
	</select>
	<!--查询 -->
	<select id="getInputItemInfo" resultMap="inputItemMap">
		SELECT
		a.id,
		a.NAME,
		a.item_no,
		a.item_type,
		a.is_must,
		a.default_value,
		a.is_score,
		b.NAME AS catalog_name,
		a.remark,
		a.LEVEL,
		a.risk_desc,
		a.maintenance_content,
		a.test_requirement,
		a.check_method,
		a.create_date,
		a.input_classify,
		a.check_type,
		a.item_parent,
		a.item_classify,
		a.item_type_classify,
		a.item_level,
		a.item_start,
		IF
		( i.input_item_id IS NULL, 0, 1 ) AS ext
		FROM
		p_input_item a
		LEFT JOIN p_catalog_tree b ON a.catalog_id = b.id
		LEFT JOIN p_route_point_item i ON a.id = i.input_item_id
		WHERE
		a.is_delete = '0'
		AND a.input_type != '1'
		<if test="name!=null and name!=''"> and a.name like concat(concat("%",#{name}),"%")</if>
		<if test="itemNo!=null"> and a.item_no like concat(concat("%",#{itemNo}),"%")</if>
		<if test="itemType!=null"> and a.item_Type = #{itemType} </if>
		<if test="checkTypeId!=null and checkTypeId!=''"> and a.check_type_id = #{checkTypeId} </if>
		<if test="itemStart!=null"> and a.item_start = #{itemStart} </if>
		<if test="orgCode!=null"> and a.org_Code = #{orgCode}</if>
		<if test="itemClassify != null"> and a.item_classify = #{itemClassify}</if>
		<if test="itemTypeClassifyIds != null"> and FIND_IN_SET(#{itemTypeClassifyIds}, a.item_type_classify_ids)</if>
		order by a.id desc
		<choose>
			<when test="pageSize==-1"></when>
			<when test="pageSize!=-1">limit #{offset},#{pageSize}</when>
		</choose>
	</select>

	<select id="getInputItemListByNames" resultMap="inputItemMap" parameterType="String">
		SELECT
			a.id,
			a.name,
			a.item_type,
			a.is_must,
			a.default_value,
			a.is_score,
			b.name as catalog_name,
			a.remark,
			a.level
		from
			p_input_item a left join p_catalog_tree b on a.catalog_id = b.id
			where a.is_delete = '0'
			<if test="orgCode!=null and orgCode !='' "> and a.org_Code = #{orgCode}</if>
			<if test="itemNames!=null and itemNames.length > 0">
				and a.name in <foreach collection="itemNames" item="name" index="index" open="(" close=")" separator=",">#{name}</foreach>
			</if>
	</select>
	<select id="queryCustomInputItem" resultType="com.yeejoin.amos.supervision.business.vo.PointInputItemVo">
		SELECT * FROM p_input_item
		where is_delete = '0' and input_type = 0
			<if test="orgCode!=null and orgCode !='' ">
				and org_Code = #{orgCode}
			</if>
			<if test="itemType!=null and itemType !='' ">
				and item_type = #{itemType}
			</if>
			<if test="inputClassify!=null and inputClassify !='' ">
				and input_classify like concat('%',#{inputClassify},'%')
			</if>
			<if test="nameOrItemNo!=null and nameOrItemNo !='' ">
				and (name like concat("%", #{nameOrItemNo}, "%") or item_no like concat("%", #{nameOrItemNo}, "%"))
			</if>
		ORDER BY create_date DESC
	</select>
	<select id="queryCustomInputItemByPointId" resultType="com.yeejoin.amos.supervision.business.vo.PointInputItemVo">
-- 		SELECT
-- 		pii.id,
-- 		pii.org_code,
-- 		pii.name,
-- 		ppi.order_no as  order_no,
-- 		pii.item_type ,
-- 		pii.is_must,
-- 		pii.input_json,
-- 		pii.catalog_id,
-- 		pii.is_delete,
-- 		pii.item_no,
-- 		pii.risk_desc,
-- 		pii.input_classify,
-- 		pii.picture_json,
-- 		pii.check_method,
-- 		pii.title,
-- 		pii.equipment_name,
-- 		pii.input_type,
-- 		pii.basis_json,
-- 		pii.level
-- 		FROM
-- 		p_point_classify ppc
-- 		LEFT JOIN p_point_inputitem ppi ON ppi.classify_ids = ppc.id
-- 		LEFT JOIN p_input_item pii ON pii.id = ppi.input_item_id
--
-- 		WHERE pii.is_delete = '0'
		SELECT
		pii.*,
		ppi.order_no as pOrderNo,
		ppi.id as pointItemId,
		ppc.name as classifyNames,
		ppc.id as classifyIds,
		prpi.id  as routePointItemId
		FROM
		p_point_classify ppc
		LEFT JOIN p_point_inputitem ppi ON ppi.classify_ids = ppc.id
		LEFT JOIN p_input_item pii ON pii.id = ppi.input_item_id
		lEFT JOIN p_route_point_item prpi ON prpi.point_input_item_id = pii.id
		WHERE pii.is_delete = '0'
		<if test="pointId!=null and pointId !='' "> AND ppc.point_id = #{pointId}</if>
		<if test="equipmentId!=null and equipmentId !='' "> AND ppc.equipment_id = #{equipmentId}</if>
	</select>
	<select id="getInputItemListByitemNos" resultType="com.yeejoin.amos.supervision.business.vo.InputItemVo">
		SELECT
		a.id,
		a.name,
		a.item_type,
		a.is_must,
		a.default_value,
		a.is_score,
		b.name as catalog_name,
		a.remark,
		a.level
		from
		p_input_item a left join p_catalog_tree b on a.catalog_id = b.id
		where a.is_delete = '0'
		<if test="itemNos!=null and itemNos.length > 0">
			and a.item_no in <foreach collection="itemNos" item="itemNo" index="index" open="(" close=")" separator=",">#{itemNo}</foreach>
		</if>
	</select>
	<select id="getInputItemByitemNo" resultType="com.yeejoin.amos.supervision.business.vo.PointInputItemVo">
		SELECT
		a.order_no
		from
		p_input_item
		where is_delete = '0' and input_type = 1
		<if test="orgCode!=null and orgCode !='' ">
			and org_Code = #{orgCode}
		</if>
	</select>

    <select id="getInputItemByEquipmentName" resultType="com.yeejoin.amos.supervision.dao.entity.InputItem">
        SELECT
        pii.id AS id,
        pii.order_no AS orderNo
        from
        p_input_item pii
        where is_delete = '0' and input_type = 1 and equipment_name=#{equipmentName}
<!--        <if test="orgCode!=null and orgCode !=''">-->
<!--            and org_Code = #{orgCode}-->
<!--        </if>-->
    </select>
    <insert id="insertList" parameterType="java.util.List">
        INSERT INTO p_input_item (
        `org_code`, `name`, `item_type`,
        `create_by`, `create_date`, `is_delete`, `item_no`, `input_classify`, `check_method`, `maintenance_content`,
        `test_requirement`, `input_type`, order_no, is_must, is_score, is_multiline, catalog_id, picture_json, data_json)
        VALUES
        <foreach collection="list" item="item" index="index" separator=",">
            (
            #{item.orgCode},
            #{item.name},
            #{item.itemType},
            #{item.createBy},
            #{item.createDate},
            #{item.isDelete},
            #{item.itemNo},
            #{item.inputClassify},
            #{item.checkMethod},
            #{item.maintenanceContent},
            #{item.testRequirement},
            #{item.inputType},
            #{item.orderNo},
            #{item.isMust},
            #{item.isScore},
            #{item.isMultiline},
            #{item.catalogId},
            #{item.pictureJson},
            #{item.dataJson}
            )
        </foreach>
    </insert>

	<select id="getInputItemParent" resultType="com.yeejoin.amos.supervision.business.vo.InputItemVo">
		SELECT
			pii.id AS id,
			pii.name AS name
		FROM
			p_input_item pii
		WHERE
		1=1
		<if test="id !=null and id !=''">
			AND pii.id != #{id}
		</if>
		AND pii.is_delete != 1
		ORDER BY create_date DESC;
	</select>

	<update id="updatePointById" parameterType="map">
		update p_input_item SET item_start = #{itemStart} WHERE id = #{id}
	</update>

	<select id="getIds" resultType="long">
		SELECT
			id
		FROM
			p_input_item
		WHERE
			is_delete = 0
	</select>
	<select id="findByIdIn" resultType="com.yeejoin.amos.supervision.dao.entity.InputItem">
		SELECT
			*
		FROM
			p_input_item
		<where>
			is_delete = 0
			<if test="list != null and list.size() >0">
				AND id IN
				<foreach collection="list" item="item" index="index" open="(" close=")" separator=",">
					#{item}
				</foreach>
			</if>
		</where>
	</select>
	<!--统计 -->
	<select id="queryPageCount" resultType="long">
		SELECT
		count(1) AS total_num
		FROM
		p_input_item a
		WHERE
		a.is_delete = '0'
		AND a.input_type != '1'
		<if test="name!=null and name!=''"> and a.name like concat(concat("%",#{name}),"%")</if>
		<if test="itemNo!=null"> and a.item_no like concat(concat("%",#{itemNo}),"%")</if>
		<if test="itemType!=null"> and a.item_Type = #{itemType} </if>
		<if test="checkTypeId!=null and checkTypeId!=''"> and a.check_type_id = #{checkTypeId} </if>
		<if test="itemStart!=null"> and a.item_start = #{itemStart} </if>
		<!--<if test="orgCode!=null"> and a.org_Code = #{orgCode}</if>-->
		<if test="itemClassify != null"> and a.item_classify = #{itemClassify}</if>
		<if test="itemTypeClassifyIds != null"> and FIND_IN_SET(#{itemTypeClassifyIds}, a.item_type_classify_ids)</if>
		<if test="planId != null">and a.id NOT IN ( SELECT p.input_item_id FROM p_route_point_item p WHERE p.plan_id = #{planId} )</if>
	</select>
	<!--查询 -->
	<select id="queryPage" resultType="com.yeejoin.amos.supervision.business.vo.InputItemVo">
		SELECT
		a.*
		FROM
		p_input_item a
		WHERE
		a.is_delete = '0'
		AND a.input_type != '1'
		<if test="name!=null and name!=''"> and a.name like concat(concat("%",#{name}),"%")</if>
		<if test="itemNo!=null"> and a.item_no like concat(concat("%",#{itemNo}),"%")</if>
		<if test="itemType!=null"> and a.item_Type = #{itemType} </if>
		<if test="checkTypeId!=null and checkTypeId!=''"> and a.check_type_id = #{checkTypeId} </if>
		<if test="itemStart!=null"> and a.item_start = #{itemStart} </if>
		<!--<if test="orgCode!=null"> and a.org_Code = #{orgCode}</if>-->
		<if test="itemClassify != null"> and a.item_classify = #{itemClassify}</if>
		<if test="itemTypeClassifyIds != null"> and FIND_IN_SET(#{itemTypeClassifyIds}, a.item_type_classify_ids)</if>
		<if test="planId != null">and a.id NOT IN ( SELECT p.input_item_id FROM p_route_point_item p WHERE p.plan_id = #{planId} )</if>
		order by a.id desc
		<choose>
			<when test="pageSize==-1"></when>
			<when test="pageSize!=-1">limit #{offset},#{pageSize}</when>
		</choose>
	</select>
</mapper>