<?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.patrol.business.dao.mapper.InputItemMapper">
	<update id="updateInputItem" parameterType="com.yeejoin.amos.patrol.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="inputClassify != null ">input_classify=#{inputClassify},</if>
			 <if test="unit != null ">unit=#{unit},</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.patrol.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" />
    </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 a.name like concat(concat("%",#{name}),"%")</if>
		<if test="itemNo!=null"> and a.item_no like concat(concat("%",#{itemNo}),"%")</if>
		<if test="isScore!=null"> and a.is_Score = #{isScore}</if>
		<if test="itemType!=null"> and a.item_Type = #{itemType} </if>
		<!-- <if test="level!=null"> and a.level = #{level} </if> -->
		<if test="orgCode!=null"> and a.org_Code = #{orgCode}</if>
		<if test="catalogIds !=null">
			and a.catalog_id in <foreach collection="catalogIds" item="catalogId" index="index" open="(" separator="," close=")" >#{catalogId}</foreach>
		</if>
		<choose>
             <when test="level == '-0' ">and a.level is null</when>
             <when test="level!=null and level != '-0'">and a.level = #{level}</when>
          </choose>
		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
		from
		p_input_item a left join p_catalog_tree b on a.catalog_id = b.id
		where a.is_delete = '0'
		and a.input_type!='1'
		<if test="name!=null"> and a.name like concat(concat("%",#{name}),"%")</if>
		<if test="itemNo!=null"> and a.item_no like concat(concat("%",#{itemNo}),"%")</if>
		<if test="isScore!=null"> and a.is_Score = #{isScore}</if>
		<if test="itemType!=null"> and a.item_Type = #{itemType} </if>
		<!-- <if test="level!=null"> and a.level = #{level} </if> -->
		<if test="orgCode!=null"> and a.org_Code = #{orgCode}</if>
		<if test="catalogIds !=null">
			and a.catalog_id in <foreach collection="catalogIds" item="catalogId" index="index" open="(" separator="," close=")" >#{catalogId}</foreach>
		</if>
		<choose>
             <when test="level == '-0' ">and a.level is null</when>
             <when test="level!=null and level != '-0'">and a.level = #{level}</when>
          </choose>
		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.patrol.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="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.patrol.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.patrol.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.patrol.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>
		<if test="orgCode!=null and orgCode !='' ">
			and org_Code = #{orgCode}
		</if>
	</select>
</mapper>