<?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.fas.business.dao.mapper.CommonMapper">
	<select id="countPoint" resultType="long">
		SELECT
			count(p.id)
		FROM
			p_point p
		where   p.is_delete='0'
			<if test="orgCode!=null"> and p.org_code = #{orgCode} </if>
			<if test="departmentId!=null"> and p.charge_dept_id = #{departmentId} </if>
			<if test="pointNo!=null"> and p.point_no like concat(concat("%",#{pointNo}),"%") </if>
			<if test="pointId!=null"> and p.id = #{pointId} </if>
			<if test="pointName!=null"> and p.name like concat(concat("%",#{pointName}),"%")</if>
			<if test="bindingPointIds!=null"> and p.id not in
				<foreach collection="bindingPointIds" item="item" index="index" separator="," open="(" close=")">
					#{item}
				</foreach>
			</if>
	</select>
	<select id="getPointList" resultType="java.util.HashMap">
		SELECT
			p.id,
			p.`name`,
			p.point_no pointNo
		FROM
			p_point p
		where    p.is_delete='0'
			<if test="orgCode!=null"> and p.org_code = #{orgCode} </if>
			<if test="departmentId!=null"> and p.charge_dept_id = #{departmentId} </if>
			<if test="pointNo!=null"> and p.point_no like concat(concat("%",#{pointNo}),"%") </if>
			<if test="pointId!=null"> and p.id = #{pointId} </if>
			<if test="pointName!=null"> and p.name like concat(concat("%",#{pointName}),"%")</if>
			<if test="bindingPointIds!=null"> and p.id not in
				<foreach collection="bindingPointIds" item="item" index="index" separator="," open="(" close=")">
					#{item}
				</foreach>
			</if>
			order by p.point_no
		<choose>
	     <when test="pageSize==-1"></when>
	     <when test="pageSize!=-1">limit #{offset},#{pageSize}</when>  
	    </choose>
	</select>
	
	<select id="countPointInput" resultType="long">
		SELECT
			count(ppi.id)
		FROM
			`p_point_inputitem` ppi
		LEFT JOIN p_point pp ON pp.id = ppi.point_id
		LEFT JOIN p_input_item pii ON pii.id = ppi.input_item_id
		where 1=1
		<if test="pointId!=null"> and ppi.point_id = #{pointId} </if>
		<if test="inputType!=null"> and pii.item_type = #{inputType} </if>
	</select>
	<select id="getPointInputList" resultType="java.util.HashMap">
		SELECT
		    ppi.id as pointInputitemId,
			ppi.point_id pointId,
			pii.`name` inputName,
			pii.item_type inputType,
			pii.id inputId,
			(
				SELECT
					CASE
				WHEN count(1) > 0 THEN
					'bound'
				ELSE
					'noBound'
				END
				FROM
					f_fmea_point_inputitem se
				WHERE
					se.point_inputitem_id = ppi.id
				AND
					se.fmea_id = #{fmeaId}
			) isBound
		FROM
			`p_point_inputitem` ppi
		LEFT JOIN p_point pp ON pp.id = ppi.point_id
		LEFT JOIN p_input_item pii ON pii.id = ppi.input_item_id
		where 1=1
		<if test="pointId!=null"> and ppi.point_id = #{pointId} </if>
		<if test="inputType!=null"> and pii.item_type = #{inputType} </if>
		ORDER BY ppi.order_no 
		<choose>
	     <when test="pageSize==-1"></when>
	     <when test="pageSize!=-1">limit #{offset},#{pageSize}</when>  
	    </choose>
	</select>
</mapper>