<?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.njcn.device.pq.mapper.PqsLineWeightMapper">

    <select id="selectWeight" resultType="com.njcn.device.pq.pojo.vo.PqsLineWeightVo">
        SELECT
            sys.name AS areaName,
            gd.NAME AS gbName,
            sub.NAME AS subName,
            dev.NAME AS devName,
            line.NAME AS lineName,
            pd.Run_Flag AS runFlag,
            pld.Line_Grade AS lineGrade,
            line.id AS lineIndex,
            COMMUN_FEE_MARK,
            ASSET_BELONG,
            SERVICE_MARK,
            AGENT_MARK,
            COMPANY_MARK,
            USER_MARK,
            LINE_TYPE_MARK,
            BUSINESS_MARK
        FROM
            pq_line line
        INNER JOIN pq_line_detail pld ON line.Id = pld.Id
        INNER JOIN pq_line vol ON vol.Id = line.Pid
        INNER JOIN pq_line dev ON dev.Id = vol.Pid
        INNER JOIN pq_device pd ON pd.Id = dev.Id
        INNER JOIN pq_line sub ON sub.Id = dev.Pid
        INNER JOIN pq_line gd ON gd.Id = sub.Pid
        INNER JOIN pq_line area ON area.Id = gd.Pid
        INNER JOIN sys_area sys ON area.NAME = sys.id
        LEFT JOIN  pqs_line_weight plw ON line.Id = plw.LINE_INDEX
        <where>
            line.State = 1
            <if test="param.runFlag!=null">
                and pd.Run_Flag = #{param.runFlag}
            </if>
            <if test="param.lineGrade!=null and param.lineGrade!=''">
                and pld.line_grade = #{param.lineGrade}
            </if>
            <if test="param.searchValue!=null and param.searchValue!=''">
                and (
                area.name like CONCAT('%', #{param.searchValue}, '%')
                or gd.name like CONCAT('%', #{param.searchValue}, '%')
                or sub.name like CONCAT('%', #{param.searchValue}, '%')
                or dev.name like CONCAT('%', #{param.searchValue}, '%')
                or line.name like CONCAT('%', #{param.searchValue}, '%')
                )
            </if>
        </where>
        order by area.sort asc,gd.sort asc,sub.sort asc,dev.sort asc,line.sort asc
    </select>
    <select id="getLineID" resultType="java.lang.String">
        SELECT
            line.id
        FROM
            pq_line line
        INNER JOIN pq_line vol ON vol.Id = line.Pid
        INNER JOIN pq_line dev ON dev.Id = vol.Pid
        INNER JOIN pq_line sub ON sub.Id = dev.Pid
        INNER JOIN pq_line gd ON gd.Id = sub.Pid
        INNER JOIN pq_line area ON area.Id = gd.Pid
        where
            line.name = #{param.lineName}
           and dev.name = #{param.devName}
          and sub.name = #{param.subName}
          and  gd.name = #{param.gbName}
          and area.id = #{param.areaName}
    </select>
    <select id="selectWeights" resultType="com.njcn.device.pq.pojo.vo.PqsLineWeightVo$WeightExcel">
        SELECT
        sys.name AS areaName,
        gd.NAME AS gbName,
        sub.NAME AS subName,
        dev.NAME AS devName,
        line.NAME AS lineName,
        pd.Run_Flag AS runFlag,
        pld.Line_Grade AS lineGrade,
        line.id AS lineIndex,
        COMMUN_FEE_MARK,
        ASSET_BELONG,
        SERVICE_MARK,
        AGENT_MARK,
        COMPANY_MARK,
        USER_MARK,
        LINE_TYPE_MARK,
        BUSINESS_MARK
        FROM
        pq_line line
        INNER JOIN pq_line_detail pld ON line.Id = pld.Id
        INNER JOIN pq_line vol ON vol.Id = line.Pid
        INNER JOIN pq_line dev ON dev.Id = vol.Pid
        INNER JOIN pq_device pd ON pd.Id = dev.Id
        INNER JOIN pq_line sub ON sub.Id = dev.Pid
        INNER JOIN pq_line gd ON gd.Id = sub.Pid
        INNER JOIN pq_line area ON area.Id = gd.Pid
        INNER JOIN sys_area sys ON area.NAME = sys.id
        LEFT JOIN  pqs_line_weight plw ON line.Id = plw.LINE_INDEX
        <where>
            line.State = 1
            <if test="param.runFlag!=null">
                and pd.Run_Flag = #{param.runFlag}
            </if>
            <if test="param.lineGrade!=null and param.lineGrade!=''">
                and pld.line_grade = #{param.lineGrade}
            </if>
            <if test="param.searchValue!=null and param.searchValue!=''">
                and (
                area.name like CONCAT('%', #{param.searchValue}, '%')
                or gd.name like CONCAT('%', #{param.searchValue}, '%')
                or sub.name like CONCAT('%', #{param.searchValue}, '%')
                or dev.name like CONCAT('%', #{param.searchValue}, '%')
                or line.name like CONCAT('%', #{param.searchValue}, '%')
                )
            </if>
        </where>
        order by area.sort asc,gd.sort asc,sub.sort asc,dev.sort asc,line.sort asc
    </select>
</mapper>
