<?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.maintenance.business.dao.mapper.InputItemMapper">
	<update id="updateInputItem" parameterType="com.yeejoin.amos.maintenance.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="companyId != null ">company_id=#{companyId},</if>
			 <if test="companyName != null ">company_name=#{companyName}</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.maintenance.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" />
    </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="inputClassify != null"> and a.input_classify = #{inputClassify}</if>
		<if test="itemType!=null"> and a.item_Type = #{itemType} </if>
		<if test="orgCode!=null"> and a.org_Code = #{orgCode}</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
		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="itemType!=null"> and a.item_Type = #{itemType} </if>
		<if test="orgCode!=null"> and a.org_Code = #{orgCode}</if>
		<if test="inputClassify != null"> and a.input_classify = #{inputClassify}</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.maintenance.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.maintenance.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.maintenance.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.maintenance.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.maintenance.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>
    <select id="queryInputItemInRountPoint" resultType="java.util.Map">
		SELECT
			pii.id,
			pii.`name` inputName,
			pii.item_type itemType,
			pii.test_requirement testRequirement,
			pii.data_json dataJson,
			pii.basis_json as basisJson,
			pii.default_value as defaultValue,
			pii.is_must isMust,
			pii.picture_json pictureJson,
			pii.order_no orderNo,
			prpi.id as routePointItemId
		FROM
			p_route_point_item prpi
				LEFT JOIN p_point_inputitem ppii ON ppii.id = prpi.point_input_item_id
				LEFT JOIN p_input_item pii ON pii.id = ppii.input_item_id
		WHERE
			prpi.route_point_id = #{routePointId}
		ORDER BY
			prpi.order_no
	</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>
</mapper>