<?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.PointMapper">
    <!-- 根据ID获取点的项信息 -->
    <select id="getPointInputItemById1" resultType="com.yeejoin.amos.supervision.business.vo.PointInputItemVo">
		SELECT
			pc.id classifyIds,
			pi.order_no pOrderNo,
			pi.id AS pointItemId,
			ii.*
		FROM
			p_point_inputitem pi
		LEFT JOIN p_input_item ii ON ii.id = pi.input_item_id
		LEFT JOIN p_point_classify pc ON pi.classify_ids REGEXP CONCAT(
			'^',
			pc.id,
			',|,',
			pc.id,
			',|,',
			pc.id,
			'$',
			'|^',
			pc.id,
			'$'
			)
		<where>
		<if test="pointId!=null">AND pi.point_id = #{pointId}</if>
		<if test="classifyId!=null"> AND pc.id =  #{classifyId}  </if>
		</where>
		ORDER BY
		    pi.order_no
    </select>

	<select id="getPointEquipInputItemById" resultType="com.yeejoin.amos.supervision.business.vo.PointInputItemNewVo">
		SELECT
		pc.id classifyIds,
		pi.order_no pOrderNo,
		pi.id AS pointItemId,
		ii.*
		FROM
		p_point_inputitem pi
		LEFT JOIN p_input_item ii ON ii.id = pi.input_item_id
		LEFT JOIN p_point_classify pc ON pi.classify_ids REGEXP CONCAT(
		'^',
		pc.id,
		',|,',
		pc.id,
		',|,',
		pc.id,
		'$',
		'|^',
		pc.id,
		'$'
		)
		<where>
			<if test="pointId!=null">AND pi.point_id = #{pointId}</if>
			<if test="classifyId!=null"> AND pc.id =  #{classifyId}  </if>
		</where>
		ORDER BY
		pi.order_no
	</select>
    <select id="getPointClassInputItemById" resultType="com.yeejoin.amos.supervision.business.vo.PointInputItemVo">
		SELECT
			pc.`name` classifyNames,
			pc.id classifyIds,
			pi.order_no pOrderNo,
			pi.id AS pointItemId,
			ii.*
		FROM
			p_point_inputitem pi
		LEFT JOIN p_input_item ii ON ii.id = pi.input_item_id
		LEFT JOIN p_point_classify pc ON FIND_IN_SET(pc.id, pi.classify_ids) > 0
		WHERE
		pi.point_id = #{pointId}
		ORDER BY
		    pi.order_no
    </select>

    <select id="getPointInputItemById" resultType="com.yeejoin.amos.supervision.business.vo.PointInputItemVo">
        SELECT
		    p.*, temp.id pointItemId, temp.order_no pOrderNo
		FROM
		    p_input_item p
		RIGHT JOIN (
		    SELECT DISTINCT
		        pi.input_item_id,
		        pi.id,
		        order_no
		    FROM
		        p_point_inputitem pi
		    <where>
		        <if test="pointId!=null">and pi.point_id = #{pointId}</if>
                <if test="classifyId!=null">and FIND_IN_SET(#{classifyId}, pi.classify_ids)</if>
            </where>
		) temp ON temp.input_item_id = p.id
		ORDER BY
		    temp.order_no;
    </select>

    <!-- 根据ID获取点图片信息 -->
    <select id="getPointPhotoByPointId" resultType="com.yeejoin.amos.supervision.dao.entity.PointPhoto">
        SELECT
            *
        FROM
            p_point_photo
        <where>
            <if test="pointId!=null">point_id = #{pointId}</if>
        </where>
    </select>
        <!-- 巡检点查询 -->
    <select id="countByCatalogId" resultType="java.util.HashMap">
	    SELECT
		    id,name
		FROM
		   p_point
	    <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>

    <select id="getPointCountByCondition" resultType="int">
		SELECT
			count(1) sum
		FROM
		p_point p
		<where>
			<if test="isFixed!=null"> and p.is_fixed = #{isFixed}</if>
			<if test="routeId!=null"> and	p.route_id REGEXP CONCAT(
				'^',
				#{routeId},
				',|,',
				#{routeId},
				',|,',
				#{routeId},
				'$',
				'|^',
				#{routeId},
				'$'
				)</if>
			AND p.is_delete = 0
			<if test="name!=null"> AND ( p.point_no LIKE CONCAT('%', #{name},'%')
				OR p.NAME LIKE CONCAT('%', #{name},'%'))   </if>
			<if test="query != null and query != ''">
				<choose>
					<when test="queryType != null and (queryType == 'point' || queryType == 'all') ">
						AND CONCAT(p. NAME, ',', p.point_no ) LIKE concat('%', #{query}, '%')
					</when>
					<otherwise>
						AND EXISTS (
						SELECT
						CONCAT( ii. NAME, ',', p. NAME, ',', p.point_no )
						FROM
						p_input_item ii
						LEFT JOIN p_point_inputitem pi ON pi.input_item_id = ii.id
						WHERE
						p.id = pi.point_id
						<if test="queryType == null or queryType == '' or queryType == 'all' ">
							AND CONCAT( ii. NAME, ',', p. NAME, ',', p.point_no ) LIKE concat('%', #{query}, '%')
						</if>
						<if test="queryType != null and queryType == 'inputItem' ">
							AND ii. NAME LIKE concat('%', #{query}, '%')
						</if>
						<if test="queryType != null and queryType == 'point' ">
							AND CONCAT(p. NAME, ',', p.point_no ) LIKE concat('%', #{query}, '%')
						</if>
						)
					</otherwise>
				</choose>
			</if>
			<if test="orgCode!=null "> and p.org_Code= #{orgCode} </if>
		</where>
    </select>

    <select id="getPointByCondition" resultType="com.yeejoin.amos.supervision.business.vo.PointVo">
		SELECT
			p.id, P.route_name routeName, p.point_no pointNo, p.name ,p.org_Code
		FROM
			p_point p
		<where>
			<if test="isFixed!=null"> and p.is_fixed = #{isFixed}</if>
			<if test="routeId!=null"> and	p.route_id REGEXP CONCAT(
					'^',
					#{routeId},
					',|,',
					#{routeId},
					',|,',
					#{routeId},
					'$',
					'|^',
					#{routeId},
					'$'
				)</if>
			AND p.is_delete = 0
			<if test="name!=null"> AND ( p.point_no LIKE CONCAT('%', #{name},'%')
			OR p.NAME LIKE CONCAT('%', #{name},'%'))   </if>
			<if test="query != null and query != ''">


			 <choose>
                <when test="queryType != null and (queryType == 'point'|| queryType == 'all')">
                    AND CONCAT(p. NAME, ',', p.point_no ) LIKE concat('%', #{query}, '%')
                </when>
                <otherwise>
                    AND EXISTS (
					SELECT
						CONCAT( ii. NAME, ',', p. NAME, ',', p.point_no )
					FROM
						p_input_item ii
					LEFT JOIN p_point_inputitem pi ON pi.input_item_id = ii.id
					WHERE
						p.id = pi.point_id
					<if test="queryType == null or queryType == '' or queryType == 'all' ">
						AND CONCAT( ii. NAME, ',', p. NAME, ',', p.point_no ) LIKE concat('%', #{query}, '%')
					</if>
					<if test="queryType != null and queryType == 'inputItem' ">
						AND ii. NAME LIKE concat('%', #{query}, '%')
					</if>
					<if test="queryType != null and queryType == 'point' ">
						AND CONCAT(p. NAME, ',', p.point_no ) LIKE concat('%', #{query}, '%')
					</if>
				)
                </otherwise>
            </choose>





				<!-- AND EXISTS (
					SELECT
						CONCAT( ii. NAME, ',', p. NAME, ',', p.point_no )
					FROM
						p_input_item ii
					LEFT JOIN p_point_inputitem pi ON pi.input_item_id = ii.id
					WHERE
						p.id = pi.point_id
					<if test="queryType == null or queryType == '' or queryType == 'all' ">
						AND CONCAT( ii. NAME, ',', p. NAME, ',', p.point_no ) LIKE concat('%', #{query}, '%')
					</if>
					<if test="queryType != null and queryType == 'inputItem' ">
						AND ii. NAME LIKE concat('%', #{query}, '%')
					</if>
					<if test="queryType != null and queryType == 'point' ">
						AND CONCAT(p. NAME, ',', p.point_no ) LIKE concat('%', #{query}, '%')
					</if>
				)	 -->

			</if>
			<if test="orgCode!=null "> and p.org_Code= #{orgCode} </if>
		</where>
		limit #{offset},#{pageSize};
    </select>

    <select id="getPointById" resultType="Map">
		SELECT
			p.id,
			P.route_name routeName,
			p.point_no pointNo,
			p.NAME pointName,
			(CASE p.is_fixed
				WHEN 1 THEN
					'固定点'
				ELSE
					'移动点'
			END) fixed,
		  p.charge_person_id userName,
			p.charge_dept_id depid,
			p.remark,
			p.offline
		FROM
			p_point p
		<!-- LEFT JOIN s_user u ON u.id = p.charge_person_id
		LEFT JOIN s_department d on u.department_id = d.id  -->
    	where p.id = #{pointId}
    </select>

    <select id="getPointInputItem"  resultType="Map">
		SELECT
			p.id pointId,
			it.NAME inputItenName,
			it.id inputItemNO
		FROM
			p_point p,
			p_point_inputitem pi,
			p_input_item it
		WHERE
			p.id = pi.point_id
		AND pi.input_item_id = it.id
		AND it.is_delete = 0
		AND p.id = #{pointId}
    </select>

     <select id="getPointInputItem1"  resultType="Map">
		SELECT
			p.id pointId,
			it.NAME inputItenName,
			it.id inputItemNO
		FROM
			p_point p,
			p_point_inputitem pi,
			p_input_item it
		WHERE
			p.id = pi.point_id
		AND pi.input_item_id = it.id
		AND it.is_delete = 0
		AND p.id = #{pointId}
		AND it.id = #{inputitemId}

    </select>

    <select id="getPointRoute"  resultType="Map">
		 SELECT
			p.id pointId,
			r. NAME routeName
		FROM
			p_point p,
			p_route_point rp,
			p_route r
		WHERE
			p.id = rp.point_id
		AND rp.route_id = r.id
		AND r.is_delete = 0
		AND p.id = #{pointId}
    </select>

    <select id="getPointClassify" resultType="Map">
		SELECT
			p.id pointId,
			c.name classifyName,
			c.id classifyId
		FROM
			p_point p,
			p_point_classify c
		where p.id = c.point_id
		AND p.id = #{pointId}
    </select>

     <select id="getPointInputClassifyInfo" resultType="Map">
		SELECT
			ppi.order_no pOrderNo,
			ppi.id pointItemId,
			ppc.`name` classifyNames,
			ppc.id classifyIds,
			pii.id,
			pii.`name`,
			pii.risk_desc riskDesc,
			pii.order_no orderNo,
			pii.item_type itemType,
			pii.is_must isMust,
			pii.is_score isScore,
			pii.default_value defaultValue,
			pii.is_multiline isMultiline,
			pii.catalog_id originalId,
			pii.input_json inputJson,
			pii.data_json dataJson,
			pii.remark,
			pii.picture_json pictureJson,
			pii.create_by createBy,
			pii.create_date createDate,
			pii.is_delete isDelete,
			pii.`level`,
			pii.item_no itemNo,
			pii.original_id originalId,
			pii.basis_json basisJson,
			pii.org_code orgCode
		FROM
			`p_point_inputitem` ppi
		LEFT JOIN p_input_item pii ON pii.id = ppi.input_item_id
		LEFT JOIN p_point_classify ppc ON FIND_IN_SET(ppc.id, ppi.classify_ids) > 0
		WHERE
			ppi.point_id = #{pointId}
		ORDER BY
		   ppi.order_no
    </select>


     <select id="queryPointClassifyByRouteIdAndPointId" resultType="Map">
		SELECT
			ppc.id,
			ppc.point_id pointId,
			ppc.`name`,
			ppc.order_no orderNo
		FROM
			`p_route_point_item` prpi
		LEFT JOIN p_route_point prp ON prp.id = prpi.route_point_id
		LEFT JOIN p_point_classify ppc ON ppc.id = prpi.point_classify_id
		WHERE
			prp.route_id = #{routeId}
		AND prp.point_id = #{pointId}
		GROUP BY
			ppc.id,
			ppc.point_id,
			ppc.`name`,
			ppc.order_no
    </select>

   <!-- 巡检点统计 -->
	<select id="getSumPtForAdmin" resultType="java.util.HashMap">
		SELECT RealTimeStatus as name,status,count(1) as value
		FROM
		(select
			case vp.status
			when '1' then '合格'
			when '2' then '不合格'
			when '3' then '漏检'
			else '未纳入巡检计划'
			end as realTimeStatus,
			vp.status
			from
			(select status ,id FROM  p_point
			where is_delete = 0
				<if test="orgCode!=null">
					and (org_code LIKE CONCAT( #{orgCode}, '-%' ) or org_code= #{orgCode} )
				 </if>
			) VP
		) tt group by tt.RealTimeStatus,tt.status order by status
	</select>
		<!-- 巡检点统计 -->
	<select id="getSumPtForDept"  resultType="java.util.HashMap">
		SELECT RealTimeStatus as name,status,count(1) as value
		FROM
		(select
			case vp.realTimeStatus
			when '1' then '合格'
			when '2' then '不合格'
			when '3' then '漏检'
			else '未纳入巡检计划'
			end as realTimeStatus,
			vp.realTimeStatus as status
			from
			(select DISTINCT is_ok as realTimeStatus ,point_id FROM  p_check
			<where>
				<if test="orgCode!=null">
					and (org_code LIKE CONCAT( #{orgCode}, '-%' ) or org_code= #{orgCode} )
				</if>
			</where>
		) VP
		) tt group by tt.RealTimeStatus,tt.status order by status
	</select>
	<!-- 风险点分页统计，业务屏使用 -->
	<select id="getCheckPointCount" resultType="long">
		SELECT
			count(1)
		FROM p_point
		where is_delete = 0
		    <if test="orgCode!=null"> and org_code like #{orgCode}</if>
		    <if test="level!=null"> and Level = #{level}</if>
			<if test="checkType!=null"> and catalog_id = #{checkType}</if>
			<if test="groupId!=null"> AND charge_dept_id = #{groupId}</if>
			<if test="userId!=null"> and charge_person_id = #{userId}</if>
			<if test="checkStatus!=null">and FIND_IN_SET(status,#{checkStatus})</if>
			<if test="name!=null"> and name like concat( '%',#{name},'%')</if>
	</select>
	<resultMap id="checkPtListResultMap" type="com.yeejoin.amos.supervision.business.entity.mybatis.CheckPtListBo">
		 <result property="pointID" column="id" />
		 <result property="no" column="point_no" />
		 <result property="realTimeStatus" column="status" />
		 <result property="groupName" column="department_name" />
		 <result property="realName" column="userName" />
	</resultMap>
	<!-- 风险点分页查询，业务屏使用 -->
	<select id="getCheckPointList" resultMap="checkPtListResultMap">
		       SELECT
					p. NAME,
					p.id,
					p.point_no,
					CASE p. LEVEL
				WHEN '1' THEN
					'一级'
				WHEN '2' THEN
					'二级'
				WHEN '3' THEN
					'三级'
				WHEN '4' THEN
					'四级'
				WHEN '5' THEN
					'五级'
				ELSE
					'一级'
				END LEVEL,
				 ct. NAME checkType,
				 p.charge_dept_id department_name,
				 p.charge_person_id userName,
				 CASE p. STATUS
				WHEN '0' THEN
					'未纳入巡检计划'
				WHEN '1' THEN
					'合格'
				WHEN '2' THEN
					'不合格'
				WHEN '3' THEN
					'漏检'
				ELSE
					'合格'
				END AS STATUS,
				DATE_FORMAT(
				P.check_Time,
				'%Y-%m-%d %H:%i:%s'
				) checkTime,
				 p.error errorMsg
			FROM p_point p
			LEFT JOIN p_Catalog_Tree ct ON ct.ID = p.Catalog_ID
			<!-- LEFT JOIN s_department sd ON sd.id = p.charge_dept_id
			LEFT JOIN s_user su ON su.id = p.charge_person_id -->
			where p.is_delete = 0
		    <if test="orgCode!=null"> and p.org_code like #{orgCode}</if>
		    <if test="level!=null"> and p.Level = #{level}</if>
			<if test="checkType!=null"> and p.catalog_id = #{checkType}</if>
			<if test="groupId!=null"> AND p.charge_dept_id = #{groupId}</if>
			<if test="userId!=null"> and p.charge_person_id = #{userId}</if>
			<if test="checkStatus!=null">and  FIND_IN_SET(p.status,#{checkStatus})</if>
			<if test="name!=null"> and (p.name like concat( '%',#{name},'%') or p.point_no like concat( '%',#{name},'%'))</if>
			order by checkTime DESC
		<choose>
	     <when test="pageSize==-1"></when>
	     <when test="pageSize!=-1">limit #{offset},#{pageSize}</when>
	    </choose>
	</select>

	<resultMap id="pointResultMap" type="com.yeejoin.amos.supervision.business.entity.mybatis.CheckPtListBo">
		 <result property="pointID" column="id" />
		 <result property="no" column="point_no" />
		 <result property="realTimeStatus" column="status" />
		 <result property="groupName" column="department_name" />
		 <result property="realName" column="userName" />
		 <result property="loginName" column="user_name" />
	</resultMap>
	<!-- 风险点明细查询，业务屏使用 -->
	<select id="getCheckPointById" resultMap="pointResultMap">
			SELECT
			p.Name,
			p.id,
			p.point_no,
			ct.name checkType,
				p.charge_dept_id department_name ,
			p.charge_person_id userName,
			<!-- IFNULL(case when su.mobile = '' or su.mobile is null then null else su.mobile END,su.telephone) as user_name, -->
			CASE p. STATUS
				WHEN '0' THEN
					'未纳入巡检计划'
				WHEN '1' THEN
					'合格'
				WHEN '2' THEN
					'不合格'
				WHEN '3' THEN
					'漏检'
				ELSE
					'合格'
				END AS STATUS
			FROM p_point p
			LEFT JOIN p_Catalog_Tree ct ON ct.ID = p.Catalog_ID
		<!-- 	LEFT JOIN s_department sd ON sd.id = p.charge_dept_id
			LEFT JOIN s_user su ON su.id = p.charge_person_id -->
		<trim prefix="WHERE" prefixOverrides="AND ">
			<if test="pointId!=null"> and p.id = #{pointId}</if>
		</trim>
	</select>


	<select id="queryPointPie" resultType="Map">
		SELECT
			sum(a.QUALIFIED) qualified,
			sum(a.UNPLAN) unplan,
			sum(a.UNQUALIFIED) unqualified,
			sum(a.OMISSION) omission
		FROM
			(
				SELECT
					pt.id,
					CASE pt.`status`
				WHEN '1' THEN
					1
				ELSE
					0
				END QUALIFIED,
				CASE pt.`status`
			WHEN '0' THEN
				1
			ELSE
				0
			END UNPLAN,
			CASE pt.`status`
		WHEN '2' THEN
			1
		ELSE
			0
		END UNQUALIFIED,
		 CASE pt.`status`
		WHEN '3' THEN
			1
		ELSE
			0
		END OMISSION
		FROM
			p_point pt
	<!-- 	LEFT JOIN s_user u ON u.id = pt.charge_person_id
		LEFT JOIN s_department d ON d.id = pt.charge_dept_id -->
		where pt.is_delete = 0
			<if test="userId != null and userId > 0">and pt.charge_person_id = #{userId}</if>
			<if test="department != null and department > 0">and pt.charge_dept_id = #{department}</if>
			<if test="orgCode != null and orgCode !='' ">and pt.org_code = #{orgCode}</if>

		) a
	</select>

		<select id="queryPointHistogram" resultType="Map">
			SELECT
				case when a.department_name = ''|| a.department_name is null then '其他' else a.department_name end departmentName,
				sum(a.QUALIFIED) qualified,
				sum(a.UNPLAN) unplan,
				sum(a.UNQUALIFIED) unqualified,
				sum(a.OMISSION) omission
			FROM
				(
					SELECT
						pt.id,
						pt.charge_dept_id,
						case when pt.charge_dept_id = ''|| pt.charge_dept_id is null then '其他' else pt.charge_dept_id end department_name,
						CASE pt.`status`
					WHEN '1' THEN
						1
					ELSE
						0
					END QUALIFIED,
					CASE pt.`status`
				WHEN '0' THEN
					1
				ELSE
					0
				END UNPLAN,
				CASE pt.`status`
			WHEN '2' THEN
				1
			ELSE
				0
			END UNQUALIFIED,
			 CASE pt.`status`
			WHEN '3' THEN
				1
			ELSE
				0
			END OMISSION
			FROM
				p_point pt
			<!-- LEFT JOIN s_user u ON u.id = pt.charge_person_id
			LEFT JOIN s_department d ON d.id = pt.charge_dept_id -->
			where pt.is_delete = 0
				<if test="userId != null and userId > 0">and pt.charge_person_id = #{userId}</if>
				<if test="department != null and department > 0">and pt.charge_dept_id = #{department}</if>
				<if test="orgCode != null and orgCode !='' ">and pt.org_code = #{orgCode}</if>
				 ) a GROUP BY a.department_name
	</select>

	<select id="getPointCountByOrgCode" resultType="Long">
		select count(1) total from p_point p where
		position( #{orgCode} in p.org_code)
		and  is_delete=0
	</select>

	 <select id="getPointInfoById"  resultType="Map">
		SELECT
            pp.id pointId,
            pp.floor,
            pp.is_indoor isIndoor,
            pp.`name` pointName,
            pp.coordinates,
            pp.`level` pointLevel,
            pp.`status`,
            pp.address,
            ppl.`name` pplName,
            ppl.user_id userName,
            ppl.user_id userId,
            pp.org_code orgCode,
            ppl.dept_id groupName,
            pp.is_delete,
           <!--  if(ur.org_code <![CDATA[<>]]>'', ur.org_code, pp.org_code) defaultOrgCode -->
            pp.org_code defaultOrgCode
        FROM
            (
		    SELECT
		            pp.route_id,
		            pp.id,
		            pp.name,
		            pp.dept_id,
		            SUBSTRING_INDEX(
		                SUBSTRING_INDEX(
		                    pp.user_id,
		                    ',',
		                    temp.help_topic_id + 1
		                ),
		                ',',
		                - 1
		            ) user_id
		        FROM
		            p_plan pp
		        JOIN mysql.help_topic temp ON temp.help_topic_id <![CDATA[ < ]]> (
		            LENGTH(pp.user_id) - LENGTH(REPLACE(pp.user_id, ',', '')) + 1
		        )
		) ppl
        LEFT JOIN p_route_point prp ON prp.route_id = ppl.route_id
      <!--   LEFT JOIN s_user u ON u.id = ppl.user_id -->
       <!--  LEFT JOIN s_department d ON d.id = u.department_id -->
        RIGHT JOIN p_point pp ON pp.id = prp.point_id
     <!--    LEFT JOIN s_user ur ON ur.id = pp.charge_person_id -->
        WHERE
			pp.id = #{pointId}
    </select>


    <resultMap type="com.yeejoin.amos.supervision.business.vo.LeavelMovePointVo" id="leavelPoint">
		<id column="id" property="pointId"/>
		<id column="pointName" property="pointName"/>
		<id column="pointNo" property="pointNo"/>
		<id column="status" property="status"/>
		<id column="offline" property="offline"/>
		<id column="level" property="level"/>
		<id column="isFiexed" property="isFiexed"/>
		<id column="shotMinNumber" property="shotMinNumber"/>
		<id column="shotMaxNumber" property="shotMaxNumber"/>
		<id column="fixedShot" property="fixedShot"/>
		<id column="usuallyShot" property="usuallyShot"/>
		<id column="routeName" property="routeName"/>
		<id column="chargePerson" property="chargePerson"/>
		<id column="departmentName" property="departmentName"/>
		<id column="remark" property="remark"/>
		<collection property="classify" ofType="Map" select="getPointClassify" column="{pointId=id}" >
		</collection>
		<collection property="inputItems" ofType="com.yeejoin.amos.supervision.business.vo.PointInputItemVo" select="getPointInputItemById1" column="{pointId=id}" >
		</collection>
	</resultMap>

    <select id="queryLeavelPoint" resultMap="leavelPoint">
		 SELECT
			p.id,
			p.`status`,
			p.offline,
			p.NAME pointName,
			point_no pointNo,
			p.LEVEL,
			p.is_fixed isFiexed,
			p.shot_min_number shotMinNumber,
			p.shot_max_number shotMaxNumber,
			p.fixed_shot fixedShot,
			p.usually_shot usuallyShot,
			p.route_name routeName,
			p.charge_person_id chargePerson,
			p.charge_dept_id departmentName,
			P.remark
		FROM
			p_point p
			<!-- LEFT JOIN s_user u ON u.id = p.charge_person_id
			LEFT JOIN s_department d on d.id = p.charge_dept_id -->
		WHERE p.is_delete = 0
		AND p.offline = 1
		<if test="orgCode != null and orgCode != ''">AND p.org_code = #{orgCode}</if>
		<if test="startTime !=null and startTime != ''">AND p.last_update_time <![CDATA[>= ]]> STR_TO_DATE(#{startTime}, '%Y-%m-%d')</if>
    </select>
    <select id="getPoints" resultType="Map">
		SELECT
			p.point_no pointNo,
			p.`name` pointName,
			CASE p.`status`
		WHEN '0' THEN
			'未纳入巡检'
		WHEN '1' THEN
			'合格'
		WHEN '2' THEN
			'不合格'
		ELSE
			'漏检'
		END status ,
			pct.`name` catalogName,
			p.address,
			sd.department_name depName,
			su. NAME username,
			IFNULL(case when su.mobile = '' or su.mobile is null then null else su.mobile END,Su.telephone) as telephone
		FROM
			p_point p
		LEFT JOIN p_catalog_tree pct ON pct.id = p.catalog_id
		LEFT JOIN s_department sd ON sd.id = p.charge_dept_id
		LEFT JOIN s_user su ON su.id = p.charge_person_id
		WHERE
			p.charge_person_id != 0
		AND p.charge_dept_id != 0
    </select>

    <resultMap id="pointConfigResultMap" type="com.yeejoin.amos.supervision.core.common.response.PointResponse">
		  <result property="pointId" column="pointId" />
		 <result property="status" column="status" />
		 <result property="pointName" column="pointName" />
		 <result property="pointNo" column="pointNo" />
		 <result property="isFixed" column="isFixed" />
		 <result property="address" column="address" />
		 <result property="chargePerson" column="chargePerson" />
		 <result property="phone" column="phone" />
		 <result property="chargeDept" column="chargeDept" />
		  <collection property="pointConfigs" ofType="com.yeejoin.amos.supervision.dao.entity.PointConfig"
			select="queryPointConfig" column="{pointId=pointId}" >
		</collection>
	</resultMap>
     <select id="getPointConfigDom" resultMap="pointConfigResultMap">
		 SELECT
		 	p.id pointId,
			p.`status` status,
			p.NAME pointName,
			p.point_no pointNo,
			p.is_fixed isFixed,
			p.address address,
			u.name chargePerson,
			IFNULL(case when u.mobile = '' or u.mobile is null then null else u.mobile END,u.telephone) as phone
			d.department_name chargeDept
		FROM
			p_point p
			LEFT JOIN s_user u ON u.id = p.charge_person_id
			LEFT JOIN s_department d on d.id = p.charge_dept_id
		WHERE p.is_delete = 0

    </select>

    <resultMap id="PointConfigMap" type="com.yeejoin.amos.supervision.dao.entity.PointConfig">
		 <result property="id" column="id" />
		 <result property="name" column="name" />
		 <result property="pointId" column="point_id" />
		 <result property="pointCode" column="point_code" />
		 <result property="infomationAddress" column="infomation_address" />
		 <result property="status" column="status" />
		 <result property="updateDate" column="update_date" />
		 <result property="isDelete" column="is_delete" />

	</resultMap>
	 <select id="queryPointConfig" resultMap="PointConfigMap">
		 SELECT
		 pc.id,
		 pc.name,
		 pc.point_id ,
		 pc.point_code,
		 pc.infomation_address,
		 pc.status,
		 pc.update_date ,
		 pc.is_delete
		FROM
			p_point_config pc
		WHERE pc.point_id = #{pointId}

    </select>


	<resultMap type="com.yeejoin.amos.supervision.business.vo.PointVo" id="pointVoList">
		<id column="id" property="id"/>
		<result column="pointNo" property="pointNo"/>
		<result column="name" property="name"/>
		<result column="isFixed" property="isFixed"/>
		<result column="shotNumber" property="shotNumber"/>
		<result column="routeName" property="routeName"/>
		<result column="classifyId" property="classifyId"/>
		<association property="inputItemName"  select="getPointInputNames" column="{classifyId=classifyId,pointId=id}" >
		</association>
	</resultMap>

	<select id="getPointInputNames"  resultType="String">
		SELECT
			GROUP_CONCAT(pii. NAME SEPARATOR ';') inputItemName
		FROM
			p_point_inputitem ppi,
			p_input_item pii
		WHERE
			ppi.input_item_id = pii.id

	        <if test="classifyId!=null and classifyId!= ''">
	         	AND find_in_set(#{classifyId}, ppi.classify_ids)
	        </if>
	          <if test="pointId!=null and pointId!= 0">
	          	AND ppi.point_id = #{pointId}
	        </if>

		GROUP BY
			ppi.point_id
    </select>

	<select id="getPointVoByIds"  resultMap="pointVoList">
		SELECT
			p.id,
			p.point_no pointNo,
			p.`name`,
			p.is_fixed isFixed,
			CONCAT(p.shot_min_number,'-',p.shot_max_number) shotNumber,
			p.route_name routeName,
			ppc.id classifyId,
			ppc.`name` classifyName
		FROM
			p_point p
		LEFT JOIN p_point_classify ppc ON ppc.point_id = p.id
		<where>
			p.is_delete = 0
			<if test="orgCode !=null and orgCode !=''">
			and p.org_code = #{orgCode}
			</if>
			<if test="pointNo !=null and pointNo !=''">
				and p.point_no like concat(concat("%",#{pointNo}),"%")
			</if>
			<if test="name !=null and name !=''">
				and p.name like concat(concat("%",#{name}),"%")
			</if>
			<if test="isFixed !=null and isFixed !=''">
				and p.is_fixed = #{isFixed}
			</if>
			<if test="pointIds !=null and pointIds.size()>0">
				and p.id in
	          <foreach item="item" index="index"  collection="pointIds" open="(" separator="," close=")">
	              #{item}
	          </foreach>
			</if>
		</where>
		ORDER BY
		    p.create_date desc,p.point_no
    </select>

     <select id="findPointList" resultType="java.util.HashMap">
	   SELECT
			p.id,
			p.name,
			p.point_no pointNo,
			(SELECT GROUP_CONCAT(name SEPARATOR ';')  FROM p_point_classify WHERE point_id = p.id GROUP BY point_id) classifyName
		FROM
		p_point p
		where p.is_delete = 0
		 <if test="orgCode!=null and orgCode !=''">and p.org_code= #{orgCode} </if>
          <if test="name!=null and name !=''">and p.name like concat(concat("%",#{name}),"%")</if>
          <if test="code !=null and code !=''"> and p.point_no like concat(concat("%",#{code}),"%")</if>
    </select>
    <select id="queryAllPointConfig" resultType="java.util.Map">
	   SELECT
			c.`name`,
			c.point_code pointCode
		FROM
			p_point_config c,
			p_point p
		WHERE
			p.id = c.point_id
		AND p.org_code = #{orgCode}
		AND c.is_delete = 0
    </select>
	<select id="queryEquipPointInputItem" resultType="java.util.Map">
<!--		SELECT-->
<!--		distinct cast(spec.id as char) AS equipmentId,-->
<!--		we.name AS name,-->
<!--		structure.source_id AS sourceId,-->
<!--		structure.source_code AS sourceCode,-->
<!--		spec.system_id AS systemId,-->
<!--		spec.code AS code,-->
<!--		cast(ppc.id as char) AS id,-->
<!--		category.NAME AS categoryName,-->
<!--		category.CODE AS categoryCode,-->
<!--		equipment_detail.area AS address,-->
<!--		structure.NAME AS acre,-->
<!--		we.inspection_spec as inspectionName,-->
<!--		ppc.order_no as orderNo-->
<!--		FROM-->
<!--		p_point_classify ppc-->
<!--		LEFT JOIN  wl_equipment_specific spec ON spec.id=ppc.equipment_id-->
<!--		LEFT JOIN wl_equipment_detail equipment_detail ON equipment_detail.id = spec.equipment_detail_id-->
<!--		LEFT JOIN wl_stock_detail detail ON detail.equipment_specific_id = spec.id-->
<!--		LEFT JOIN wl_warehouse_structure structure ON detail.warehouse_structure_id = structure.id-->
<!--		LEFT JOIN f_fire_fighting_system AS manage ON manage.id = spec.system_id-->
<!--		LEFT JOIN wl_equipment we ON we.id = equipment_detail.equipment_id-->
<!--		LEFT JOIN wl_equipment_category category ON category.id = we.category_id-->
<!--		WHERE-->
<!--		<if test = "pointId!=''" > ppc.point_id = #{pointId} </if>-->
	</select>

	<select id="queryPointCount4Route" parameterType="long" resultType="int">
<!--		SELECT-->
<!--			count(1)-->
<!--		FROM-->
<!--			p_point pp-->
<!--			LEFT JOIN wl_warehouse_structure wws-->
<!--				ON pp.risk_source_id = wws.source_id-->
<!--		<where>-->
<!--			<if test="structureIdList != null and structureIdList.size > 0">-->
<!--				AND pp.risk_source_id  in-->
<!--				<foreach collection="structureIdList" open="(" close=")" separator="," item="sid">-->
<!--					#{sid}-->
<!--				</foreach>-->
<!--			</if>-->
<!--			<if test="name != null and name.length > 0">-->
<!--				AND pp.name LIKE concat("%", #{name}, "%")-->
<!--			</if>-->
<!--			<if test="pointNo != null and pointNo.length > 0">-->
<!--				AND pp.point_no LIKE concat("%", #{pointNo}, "%")-->
<!--			</if>-->
<!--			<if test="nullRiskSourceId == true">-->
<!--				AND ( pp.risk_source_id is NULL OR trim(pp.risk_source_id)='')-->
<!--			</if>-->
<!--			AND pp.is_delete = 0-->
<!--		</where>-->
	</select>

	<select id="queryPointList4Route" parameterType="long" resultType="map">
<!--		SELECT-->
<!--			pp.id pointId-->
<!--			, pp.name pointName-->
<!--			, pp.point_no pointNo-->
<!--			, wws.name area-->
<!--			, pp.address pointAddress-->
<!--			, wws.full_name position-->
<!--		FROM-->
<!--			p_point pp-->
<!--			LEFT JOIN wl_warehouse_structure wws-->
<!--				ON pp.risk_source_id = wws.source_id-->
<!--		<where>-->
<!--			<if test="structureIdList != null and structureIdList.size > 0">-->
<!--				AND pp.risk_source_id  in-->
<!--				<foreach collection="structureIdList" open="(" close=")" separator="," item="sid">-->
<!--					#{sid}-->
<!--				</foreach>-->
<!--			</if>-->
<!--			<if test="name != null and name.length > 0">-->
<!--				AND pp.name LIKE concat("%", #{name}, "%")-->
<!--			</if>-->
<!--			<if test="pointNo != null and pointNo.length > 0">-->
<!--				AND pp.point_no LIKE concat("%", #{pointNo}, "%")-->
<!--			</if>-->
<!--			<if test="nullRiskSourceId == true">-->
<!--				AND ( pp.risk_source_id is NULL OR trim(pp.risk_source_id)='' )-->
<!--			</if>-->
<!--			AND pp.is_delete = 0-->
<!--		</where>-->
<!--		LIMIT #{offset}, #{size}-->
	</select>

	<select id="queryPointListByRouteId" parameterType="long" resultType="map">
		/*SELECT
			pp.id pointId
			, pp.name pointName
			, pp.point_no pointNo
			, wws.name area
			, wws.full_name position
			, prp.order_no orderNo
			, prp.id prpId
			, prp.exclude_items excludeItems
		FROM
			p_point pp
			LEFT JOIN wl_warehouse_structure wws
				ON pp.risk_source_id = wws.source_id
			LEFT JOIN p_route_point prp
				ON prp.point_id = pp.id
		WHERE prp.route_id = #{routeId}
		ORDER BY prp.order_no*/
	</select>

	<select id="queryEquipListByPointId" parameterType="long" resultType="map">
		SELECT
			ppc.id classifyId
			, ppc.equipment_id equipId
			, ppc.name equipName
		FROM
			 p_point_classify ppc
		WHERE
			ppc.point_id = #{pointId}
	</select>

	<select id="queryItemList4RoutePoint" parameterType="long" resultType="map">
		SELECT
			pii.id itemId
			, pii.name
			, pii.picture_json photo
			, pii.basis_json basis
			, pii.check_method method
			, pii.item_type type
			, pii.level
			, pii.risk_desc
			, pii.input_classify
		FROM
			p_input_item pii
		WHERE
			pii.id IN (
				SELECT
					DISTINCT ppi.input_item_id
				FROM
					p_point_inputitem ppi
				WHERE
					ppi.point_id = #{pointId}
					AND ppi.classify_ids = #{classifyId}
			)
	</select>

	<select id="getPointRefItem" parameterType="list" resultType="map">
		SELECT
			ppi.id
			, ppi.input_item_id itemId
			, ppi.point_id pointId
			, ppi.classify_ids classifyId
		FROM
			p_point_inputitem ppi
		WHERE
		 	ppi.point_id IN
				<foreach collection="list" open="(" close=")" separator="," item="pointId">
					#{pointId}
		 		</foreach>
	</select>

	<select id="getPointRouteList" parameterType="list" resultType="Long">
		SELECT
			ppi.id
		FROM
			p_point ppi
		WHERE
			ppi.original_id IN
		<foreach collection="list" open="(" close=")" separator="," item="routeId">
			#{routeId}
		</foreach>
	</select>


	<select id="getPointRouteItem" parameterType="list" resultType="com.yeejoin.amos.supervision.dao.entity.PointInputItem">
		SELECT
		ppi.id
		, ppi.input_item_id itemId
		, ppi.point_id pointId
		, ppi.classify_ids classifyId
		FROM
		p_point_inputitem ppi
		WHERE
		ppi.point_id IN
		<foreach collection="list" open="(" close=")" separator="," item="pointId">
			#{pointId}
		</foreach>
	</select>

	<select id="getPointoriginalidbyrouteid"  parameterType="long" resultType="Long">
		SELECT
			original_id
		FROM
			p_point as ppo
		LEFT JOIN p_route_point as prp ON
			ppo.id = prp.point_id
		WHERE
		 	prp.route_id = #{routeId}
	</select>

	<select id="queryItemsByPointId" resultType="map">
		SELECT
			COALESCE ( pci.id , 0 ) inputId,
			ppi.id,
			prp.point_id pointId,
			pii.name itemName,
			pii.item_type itemTyp,
			pii.data_json dataJson,
			pii.remark remark,
			pii.picture_json picJson,
			pci.user_id userId,
			pci.user_name userName,
			pii.id itemId,
			group_concat(pcs.photo_data) photoData,
			COALESCE (pci.input_value, '') selectValue,
			CASE pii.`input_type`
			WHEN 0 THEN
				'手动录入'
			ELSE
				'同步'
			END inputType
		FROM
			p_route_point prp
			LEFT JOIN p_route_point_item  ppi ON ppi.route_point_id = prp.id
			LEFT JOIN p_input_item pii ON ppi.input_item_id = pii.id
			LEFT JOIN p_check_input pci ON pci.route_point_item_id = ppi.id
			LEFT JOIN p_check_shot pcs ON pci.id = pcs.check_input_id
		WHERE
			prp.route_id = #{routeId} AND prp.point_id = #{pointId} AND pii.is_delete = 0 AND
			( pci.input_value is NULL OR pci.input_value <![CDATA[<>]]> 'pass')
			GROUP BY ppi.id
	</select>

	<select id="getPlanExecuteTeams" resultType="map">
		SELECT
		    original_id id,
        	`name`
        FROM
        	p_point
	</select>
	<select id="getPointByPlanId" resultType="com.yeejoin.amos.supervision.dao.entity.Point">
		   select
		   	*
		   from p_point po
			where EXISTS
			(SELECT
			DISTINCT rp.point_id FROM
			p_plan pl,
			p_route_point rp
			where pl.route_id = rp.route_id
			and pl.id = #{planId}
			and po.id = rp.point_id)
	</select>
    <select id="queryAllPointList" resultType="java.lang.Long">
		select original_id from p_point where is_delete = 0;
	</select>
</mapper>