TpPEqpSMapper.xml 14 KB
<?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.zteits.park.mapper.smapper.TpPEqpSMapper">
    <resultMap id="queryEqpTypeByPlIdsResult" type="java.util.HashMap">
        <result property="key" column="pl_no"/>
        <result property="value" column="eqpTypes"/>
    </resultMap>
    <!-- 统计设备数量Where 条件 -->
    <sql id="statisticEqpCountWhere">
   	WHERE
        lot.data_status = 1
        AND eqp.data_state = 1
        <if test="plNos != null and plNos.size>0">
            AND lot.pl_no in
            <foreach collection="plNos" index="index" item="plNo" open="(" separator="," close=")">#{plNo}</foreach>
        </if>
        <if test="factoryNos != null and factoryNos.size>0">
            AND eqp.factory_no in
            <foreach collection="factoryNos" index="index" item="factoryNo" open="(" separator="," close=")">#{factoryNo}</foreach>
        </if>
        <if test="berthNo != null and berthNo != ''">
            AND eqp.berth_no like concat('%',#{berthNo,jdbcType=VARCHAR},'%')
        </if>
        <if test="eqpNo != null and eqpNo!=''">
            AND eqp.eqp_no like concat('%',#{eqpNo,jdbcType=VARCHAR},'%')
        </if>
        <if test="eqpIsOnline != null and eqpIsOnline!=''">
            AND eqp.eqp_is_online =#{eqpIsOnline}
        </if>
        <if test="usedType != null">
            <if test="usedType == 20">
                AND eqp.used_type = #{usedType}
            </if>
            <if test="usedType == 10">
                AND (eqp.used_type != 20 or eqp.used_type is null)
            </if>
        </if>
        <if test="cityId!=null and cityId!=''">
            AND lot.pl_city_id = #{cityId}
        </if>
        <if test="eqpTypes!=null and eqpTypes.size>0">
            AND eqp.eqp_type in
            <foreach collection="eqpTypes" index="index" item="eqpType"
            open="(" separator="," close=")">#{eqpType}</foreach>
        </if>
        <if test="orgId!=null and orgId!=''">
            AND eqp.org_id = #{orgId}
        </if>
        <if test="heartbeatTime!=null ">
            AND (eqp.heartbeat_time &lt;= #{heartbeatTime} or eqp.heartbeat_time is null)
        </if>
        <if test="inOutTime!=null ">
            AND (eqp.in_out_time &lt;= #{inOutTime} or eqp.in_out_time is null)
        </if>
        <if test="modifyTimeBegin !=null and modifyTimeEnd != null ">
            AND (eqp.modify_time between #{modifyTimeBegin} and #{modifyTimeEnd})
        </if>
        <if test="berthsOccupyStatus !=null">
            AND eqp.berths_occupy_status = #{berthsOccupyStatus}
        </if>
    </sql>

    <!-- 统计设备数量-根据设备类型分组 -->
    <select id="statisticEqpCountGroupByEqpType" parameterType="com.zteits.clouds.api.dto.park.param.QueryEqpRequest"
            resultType="com.zteits.clouds.api.dto.park.dto.StatisticEqpCountByEqpTypeDTO">
        SELECT
			eqp.eqp_type AS eqpType,
            count(1) as allEqpNum,
            sum( CASE used_type WHEN 20 THEN 1 ELSE 0 END ) AS operateEqpNum,
            sum( CASE WHEN used_type=20 AND eqp_is_online = 0 THEN 1 ELSE 0 END ) AS operateOnLineEqpNum,
            sum( CASE WHEN used_type=20 AND eqp_is_online = 1 THEN 1 ELSE 0 END ) AS operateOffLineEqpNum,
            sum( CASE WHEN used_type=20 AND (eqp_is_online = 2 OR eqp_is_online IS NULL) THEN 1 ELSE 0 END ) AS operateFaultEqpNum,
            sum( CASE WHEN (used_type !=20 OR used_type IS NULL) THEN 1 ELSE 0 END ) AS debugEqpNum,
            sum( CASE eqp_is_online WHEN 0 THEN 1 ELSE 0 END ) AS onlineEqpNum,
            sum( CASE eqp_is_online WHEN 1 THEN 1 ELSE 0 END ) AS offLineEqpNum,
            sum( CASE WHEN (eqp_is_online = 2 OR eqp_is_online IS NULL) THEN 1 ELSE 0 END ) AS faultEqpNum
        FROM
        tp_p_eqp eqp
        JOIN parking_lot lot ON eqp.pl_no = lot.pl_no
        <include refid="statisticEqpCountWhere" />
       GROUP BY eqp.eqp_type;
    </select>
    <!-- 统计设备数量-根据停车场编号分组 -->
    <select id="statisticEqpCountGroupByPlNo" parameterType="com.zteits.clouds.api.dto.park.param.QueryEqpRequest"
            resultType="com.zteits.clouds.api.dto.park.dto.StatisticEqpCountByPlNoDTO">
        SELECT
        	lot.pl_no as plNo,
	        lot.pl_name as plName,
			eqp.eqp_type AS eqpType,
			count(1) as allEqpNum,
	        sum( CASE eqp_is_online WHEN 0 THEN 1 ELSE 0 END ) AS onlineEqpNum,
			sum( CASE eqp_is_online WHEN 1 THEN 1 ELSE 0 END ) AS offLineEqpNum,
			sum( CASE eqp_is_online WHEN 2 THEN 1 ELSE 0 END ) AS faultEqpNum
        FROM
        tp_p_eqp eqp
        JOIN parking_lot lot ON eqp.pl_no = lot.pl_no
        <include refid="statisticEqpCountWhere" />
       GROUP BY lot.pl_no,lot.pl_name,eqp.eqp_type;
    </select>

	<!-- 统计设备数量-根据区县分组 -->
    <select id="statisticEqpCountGroupByCountry" parameterType="com.zteits.clouds.api.dto.park.param.QueryEqpRequest"
            resultType="com.zteits.clouds.api.dto.park.dto.StatisticEqpCountByCountryDTO">
        SELECT
	        lot.pl_city_id as plCityId,
	        lot.pl_city_name as plCityName,
	        lot.pl_country_id as plCountryId,
	        lot.pl_country_name as plCountryName,
			eqp.eqp_type AS eqpType,
	        count(1) as allEqpNum,
	        sum( CASE eqp_is_online WHEN 0 THEN 1 ELSE 0 END ) AS onlineEqpNum,
			sum( CASE eqp_is_online WHEN 1 THEN 1 ELSE 0 END ) AS offLineEqpNum,
			sum( CASE eqp_is_online WHEN 2 THEN 1 ELSE 0 END ) AS faultEqpNum
        FROM
        tp_p_eqp eqp
        JOIN parking_lot lot ON eqp.pl_no = lot.pl_no
        <include refid="statisticEqpCountWhere" />
       GROUP BY lot.pl_city_id,lot.pl_city_name,lot.pl_country_id,lot.pl_country_name,eqp.eqp_type;
    </select>

    <select id="queryEqpTypeByPlNos" resultMap="queryEqpTypeByPlIdsResult">
        SELECT
        t.pl_no,
        group_concat(DISTINCT (t.eqp_type)) AS eqpTypes
        FROM (SELECT * from tp_p_eqp WHERE pl_no IN
        <foreach collection="plNos" item="plNo" close=")" open="(" separator="," index="index">
            #{plNo}
        </foreach>
        ) t
        GROUP BY t.pl_no, t.eqp_type;
    </select>
    <!--系统判断为离线日志记录 3倍心跳间隔时间没有上报数据-->
    <select id="insertHeartBeatData">
        INSERT INTO ${eqpLogTableName}
        ( pl_no, eqp_no, berth_no, event_type, factory_no, data_state, create_time, modify_time, eqp_type, eqp_is_online )
        SELECT
        pl_no,
        eqp_no,
        berth_no,
        '99',
        factory_no,
        1,
        now(),
        now(),
        eqp_type,
        '1'
        FROM
        tp_p_eqp
        WHERE 1=1
        and heartbeat_time &lt;= DATE_SUB(now(),INTERVAL 3*heartbeat_interval SECOND)
        AND eqp_is_online = 0
    </select>
    <!-- 根据心跳间隔更新设备为离线状态 -->
    <update id="updateEqpOnlineStateByHeartBeat">
    update
		tp_p_eqp
		<set>
		eqp_is_online = 1,
		modify_time = now(),
        error_type_remark = '长时未上报'
		</set>
		where 1=1
		and heartbeat_time &lt;= DATE_SUB(now(),INTERVAL 3*heartbeat_interval SECOND)
		AND eqp_is_online = 0
    </update>
    <!--系统判断为故障日志记录  一天没有上报数据-->
    <select id="insertHeartBeatDataForFault">
        INSERT INTO ${eqpLogTableName}
        ( pl_no, eqp_no, berth_no, event_type, factory_no, data_state, create_time, modify_time, eqp_type, eqp_is_online )
        SELECT
        pl_no,
        eqp_no,
        berth_no,
        '98',
        factory_no,
        1,
        now(),
        now(),
        eqp_type,
        '2'
        FROM
        tp_p_eqp
        WHERE 1=1
        and heartbeat_time &lt;= DATE_SUB(now(),INTERVAL 1 day)
        AND eqp_is_online = 1
    </select>
    <!-- 根据心跳间隔更新设备为故障状态 -->
    <update id="updateEqpOnlineStateForFaultByHeartBeat">
    update
		tp_p_eqp
		<set>
		eqp_is_online = 2,
		modify_time = now(),
        error_type_remark = '长时离线'
		</set>
		where 1=1
		and (heartbeat_time &lt;= DATE_SUB(now(),INTERVAL 1 day)
        OR heartbeat_time IS NULL)

		AND eqp_is_online = 1
    </update>
   <!-- 批量插入地磁信息-->
   <insert id="batchInsertEqp" parameterType="java.lang.Integer">
       <selectKey keyProperty="id" order="AFTER" resultType="java.lang.Long">
           SELECT LAST_INSERT_ID()
       </selectKey>
       <if test="tpPEqpList != null and tpPEqpList.size >0">
           insert into tp_p_eqp (pl_no, eqp_type, join_method,
           eqp_no, berth_no, eqp_name,
           eqp_model, eqp_is_online, maintain_opt,
           heartbeat_interval, heartbeat_time, factory_no,
           lon_id, lat_id, remark,
           data_state, create_time, create_op,
           modify_time, modify_op, opt_flg,
           electricity, lon_lat_type, voltag,
           install_time, used_time, used_type,
           device_id, verify_code, rssi,
           gateway_no, psk,org_id)
           values
           <foreach collection="tpPEqpList" item="tpPEqp" index="index" separator=",">
               (#{tpPEqp.plNo,jdbcType=VARCHAR}, #{tpPEqp.eqpType,jdbcType=INTEGER}, #{tpPEqp.joinMethod,jdbcType=INTEGER},
               #{tpPEqp.eqpNo,jdbcType=VARCHAR}, #{tpPEqp.berthNo,jdbcType=VARCHAR}, #{tpPEqp.eqpName,jdbcType=VARCHAR},
               #{tpPEqp.eqpModel,jdbcType=VARCHAR}, #{tpPEqp.eqpIsOnline,jdbcType=CHAR}, #{tpPEqp.maintainOpt,jdbcType=VARCHAR},
               #{tpPEqp.heartbeatInterval,jdbcType=INTEGER}, #{tpPEqp.heartbeatTime,jdbcType=TIMESTAMP}, #{tpPEqp.factoryNo,jdbcType=VARCHAR},
               #{tpPEqp.lonId,jdbcType=DECIMAL}, #{tpPEqp.latId,jdbcType=DECIMAL}, #{tpPEqp.remark,jdbcType=VARCHAR},
               #{tpPEqp.dataState,jdbcType=INTEGER}, #{tpPEqp.createTime,jdbcType=TIMESTAMP}, #{tpPEqp.createOp,jdbcType=BIGINT},
               #{tpPEqp.modifyTime,jdbcType=TIMESTAMP}, #{tpPEqp.modifyOp,jdbcType=BIGINT}, #{tpPEqp.optFlg,jdbcType=CHAR},
               #{tpPEqp.electricity,jdbcType=VARCHAR}, #{tpPEqp.lonLatType,jdbcType=INTEGER}, #{tpPEqp.voltag,jdbcType=VARCHAR},
               #{tpPEqp.installTime,jdbcType=TIMESTAMP}, #{tpPEqp.usedTime,jdbcType=TIMESTAMP}, #{tpPEqp.usedType,jdbcType=INTEGER},
               #{tpPEqp.deviceId,jdbcType=VARCHAR}, #{tpPEqp.verifyCode,jdbcType=VARCHAR}, #{tpPEqp.rssi,jdbcType=INTEGER},
               #{tpPEqp.gatewayNo,jdbcType=VARCHAR}, #{tpPEqp.psk,jdbcType=VARCHAR},#{tpPEqp.orgId,jdbcType=BIGINT})
           </foreach>

       </if>

   </insert>

	<!-- 分页查询地磁 -->
    <select id="queryEqpsForPage" parameterType="com.zteits.clouds.api.dto.park.param.QueryEqpRequest"
            resultType="com.zteits.park.domain.TpPEqp">
            select eqp.id as id,
        eqp.pl_no as plNo, eqp.eqp_type as eqpType, eqp.join_method as joinMethod,
           eqp_no as eqpNo, berth_no AS berthNo, eqp_name as eqpName,
           eqp_model as eqpModel, eqp_is_online as eqpIsOnline, maintain_opt AS maintainOpt,
           heartbeat_interval as heartbeatInterval, heartbeat_time as heartbeatTime, factory_no as factoryNo,
           lon_id as lonId, lat_id AS latId, eqp.remark AS remark,
           eqp.data_state AS dataState, eqp.create_time AS createTime, eqp.create_op AS createOp,
           eqp.modify_time AS modifyTime, eqp.modify_op AS modifyOp, opt_flg AS optFlg,
           electricity AS electricity, lon_lat_type AS lonLatType, voltag AS voltag,
           install_time AS installTime, used_time AS usedTime, used_type AS usedType,
           device_id AS deviceId, verify_code AS verifyCode, rssi AS rssi,
           gateway_no AS gatewayNo, psk AS psk,eqp.org_id AS orgId,eqp.in_out_time AS inOutTime,
            eqp.report_ip reportIp,
        eqp.versions versions,
        eqp.mac mac,
        eqp.gyroxstatus gyroxstatus,
        eqp.berths_occupy_status berthsOccupyStatus
        FROM
        tp_p_eqp eqp
        JOIN parking_lot lot ON eqp.pl_no = lot.pl_no
        <include refid="statisticEqpCountWhere" />
      order by eqp.create_time DESC
    </select>

    <!--泊位更换区间时,将地磁表的关联信息也更新了 zwg 20190305-->
    <update id="updateEqpAreaCode">
        update
        tp_p_eqp eqp
        JOIN tp_p_berths berths ON eqp.pl_no = berths.pl_no
        AND eqp.berth_no = berths.berth_no
        AND eqp.data_state = 1
        AND berths.data_state = 1
        set eqp.pl_no = #{plNo}
        where berths.id in
        <foreach collection="berthsIds" open="(" close=")" separator="," item="berthsId">
            #{berthsId}
        </foreach>
    </update>

    <!-- 根据泊位区间编号和停车场编号和泊位或者地磁编号查询地磁信息 -->
    <select id="queryEqpInfoByPlNoAndOther" resultType="com.zteits.clouds.api.dto.park.dto.BerthsDTO"
            parameterType="com.zteits.clouds.api.dto.pda.param.QueryEqpByPlNoAndOrtherRequest">
        SELECT
        tb.pl_no plNo,
        tb.park_area_code parkAreaCode,
        tb.berth_no berthNo,
        tb.car_no carNo,
        tb.is_occupy isOccupy,
        tb.road_position roadPosition,
        tb.direction direction,
        tb.park_type parkType,
        tb.berth_address berthAddress,
        tb.car_status carStatus,
        tb.order_id orderId,
        ifnull(te.eqp_no,'') eqpNo,
        case when ifnull(te.eqp_no,0)  then 1 else 0 end  eqpIsFixed,
        ifnull(te.eqp_is_online,-1) eqpIsOnline
        FROM
        tp_p_berths tb, tp_p_eqp te
        WHERE
        tb.data_state = 1 and  tb.pl_no = te.pl_no and tb.berth_no = te.berth_no and te.data_state = 1
        <if test="plNo != null and plNo != '' ">
            and tb.pl_no = #{plNo}
        </if>
        <if test="parkAreaCode != null and parkAreaCode != '' ">
            and tb.park_area_code = #{parkAreaCode}
        </if>
        <if test="berthNoOrEqpNo != null and berthNoOrEqpNo != '' ">
            and (tb.berth_no like concat('%',#{berthNoOrEqpNo,jdbcType=VARCHAR},'%')
            or te.eqp_no like concat('%',#{berthNoOrEqpNo,jdbcType=VARCHAR},'%') )
        </if>
        <if test="eqpIsOnline != null and eqpIsOnline != '-1' and eqpIsOnline != '' ">
            and te.eqp_is_online = #{eqpIsOnline}
        </if>
        order by tb.pl_no,tb.berth_no
    </select>

</mapper>