/*
 * Author: wangjian
 * 生成ServiceImpl
 */
package com.tofly.xrtymis.custom.service.impl;

import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.tofly.api.CodeClient;
import com.tofly.api.message.MessageClient;
import com.tofly.api.message.MessageStateClient;
import com.tofly.common.core.entity.ResultRespone;
import com.tofly.common.core.util.DateUtil;
import com.tofly.common.oauth.exception.ToflyDeniedException;
import com.tofly.common.oauth.util.SecurityUtils;
import com.tofly.pojo.Syschildcode;
import com.tofly.pojo.message.Messagepush;
import com.tofly.pojo.message.Messagerecipient;
import com.tofly.xrtymis.custom.commons.CommonConstants;
import com.tofly.xrtymis.custom.commons.Constate;
import com.tofly.xrtymis.custom.dto.TfYwpnGatherrecorDataDTO;
import com.tofly.xrtymis.custom.service.TfYwpnGatherrecordService;
import com.tofly.xrtymis.custom.vo.GatherRecordVO;
import com.tofly.xrtymis.custom.vo.TfYwpnGatherrecordVO;
import com.tofly.xrtymis.entity.*;
import com.tofly.xrtymis.mapper.*;
import org.apache.commons.lang3.ObjectUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.*;

/**
 * 数据采集记录表：TF_YWPN_GATHERRECORD_W
 *
 * @author fcl
 * @date Fri Apr 16 00:00:00 CST 2021
 */
@Service("tfYwpnGatherrecordService")
public class TfYwpnGatherrecordServiceImpl extends ServiceImpl<TfYwpnGatherrecordMapper, TfYwpnGatherrecord> implements TfYwpnGatherrecordService {

    @Autowired
    private MessageClient messageClient;
    @Autowired
    private CodeClient codeClient;
    @Autowired
    private TfYwpnWaterRepMapper repMapper;
    @Autowired
    private TfYwpnHydrantMapper hydrantMapper;
    @Autowired
    private TfYwpnManholeMapper manholeMapper;
    @Autowired
    private TfYwpnNonvalveMapper nonvalveMapper;
    @Autowired
    private TfYwpnPipeMapper pipeMapper;
    @Autowired
    private TfYwpnStationMapper stationMapper;
    @Autowired
    private TfYwpnValveMapper valveMapper;
    @Autowired
    private TfYwpnPipenodeMapper nodeMapper;
    @Autowired
    private MessageStateClient messageStateClient;

    @Override
    @Transactional(rollbackFor = Exception.class)
    public boolean submitRecord(String ids,String reviewId) {
        if (StringUtils.isBlank(ids)){
            return false;
        }

        StringBuilder builder = null;
        List<String> idList = Arrays.asList(ids.split(Constate.CSV));
        // 记录管点数据 去重
        Set<TfYwpnPipenode> set = new HashSet<>();
        if (idList.size() > 0) {
            for (String id : idList) {
                // 获取待提交记录信息 判断状态
                TfYwpnGatherrecord tfYwpnGatherrecord = this.getById(id);
                if (tfYwpnGatherrecord != null && Constate.NO.equals(tfYwpnGatherrecord.getState()) ) {
                    // 采集水表不推送消息
                    if (CommonConstants.WATERREP_RECORD_TABLE_NAME.equals(tfYwpnGatherrecord.getTableName())) {
                        updateStateSubmit(tfYwpnGatherrecord,null);
                        continue;
                    } else {
                        if (StringUtils.isBlank(reviewId)) {
                            throw new ToflyDeniedException("请选择审核人");
                        } else{
                            if (CommonConstants.PIPE_RECORD_TABLE_NAME.equals(tfYwpnGatherrecord.getTableName())) {
                                // 获取管线数据 找到管点关联情况
                                TfYwpnPipe tfYwpnPipe = pipeMapper.selectById(tfYwpnGatherrecord.getGatherId());
                                if (messagePush(tfYwpnGatherrecord, reviewId)) {
                                    updateStateSubmit(tfYwpnGatherrecord,reviewId);
                                    // 加入起、止点查询非空校验 测试时发现脏数据，管线关联管点数据，但是该管点已被删除，导致空指针问题
                                    // 查询起点 加入集合
                                    TfYwpnPipenode startNode = nodeMapper.selectOne(Wrappers.<TfYwpnPipenode>lambdaQuery()
                                            .eq(TfYwpnPipenode::getSid, tfYwpnPipe.getStartsid()));
                                    if (ObjectUtils.isNotEmpty(startNode)) {
                                        set.add(startNode);
                                    }
                                    // 查询终点 加入集合
                                    TfYwpnPipenode endtNode = nodeMapper.selectOne(Wrappers.<TfYwpnPipenode>lambdaQuery()
                                            .eq(TfYwpnPipenode::getSid, tfYwpnPipe.getEndsid()));
                                    if (ObjectUtils.isNotEmpty(endtNode)) {
                                        set.add(endtNode);
                                    }
                                }
                                continue;
                            } else if (!CommonConstants.NODE_RECORD_TABLE_NAME
                                    .equals(tfYwpnGatherrecord.getTableName())) {
                                if (messagePush(tfYwpnGatherrecord, reviewId)) {
                                    updateStateSubmit(tfYwpnGatherrecord,reviewId);
                                }
                                continue;
                            }
                        }
                    }
                }
                throw new ToflyDeniedException("采集信息数据异常");
            }
            // 如果管点集合有数据 遍历提交审核
            if (set.size() > 0) {
                for (TfYwpnPipenode node : set) {
                    TfYwpnGatherrecord tfYwpnGatherrecord = this.getOne(Wrappers.<TfYwpnGatherrecord>lambdaQuery()
                            .eq(TfYwpnGatherrecord::getTableName,CommonConstants.NODE_RECORD_TABLE_NAME)
                            .eq(TfYwpnGatherrecord::getGatherId, node.getId()));
                    // 存在管点已发发布后 做为起点或终点情况 判断状态未发布才推送消息并修改状态
                    if ("0".equals(tfYwpnGatherrecord.getState())) {
                        if(messagePush(tfYwpnGatherrecord,reviewId)){
                            updateStateSubmit(tfYwpnGatherrecord,reviewId);
                        }
                    }
                }
            }
        }
        return true;
    }

    // 增加修改审核人id 修改采集记录
    private boolean updateStateSubmit(TfYwpnGatherrecord record , String reviewId) {
        LambdaUpdateWrapper<TfYwpnGatherrecord> updateWrapper = Wrappers.<TfYwpnGatherrecord>lambdaUpdate()
                .eq(TfYwpnGatherrecord::getId, record.getId())
                .set(TfYwpnGatherrecord::getState, CommonConstants.GATHER_RECORD_STATE_PUSHED);
        if (StringUtils.isNotBlank(reviewId)) {
            updateWrapper.set(TfYwpnGatherrecord::getAuditUser,reviewId);
        }
        return update(null,updateWrapper);
    }

    private boolean messagePush(TfYwpnGatherrecord tfYwpnGatherrecord,String reviewId) {
        String getname = getGatherTypeName(tfYwpnGatherrecord.getGatherType());

        // 消息推送
        Messagepush messagepush = new Messagepush();
        messagepush.setTopic(getname + "信息采集审核");
        StringBuilder builder = new StringBuilder();
        builder.append(tfYwpnGatherrecord.getCreateTime().toString()).append(Constate.CSV)
                .append(tfYwpnGatherrecord.getCreateUserName())
                .append(",").append(messagepush.getTopic());
        messagepush.setMessage(builder.toString());
//        messagepush.setTableName(tfYwpnGatherrecord.getTableName());
//        messagepush.setTableId(tfYwpnGatherrecord.getGatherId());
        // 与管网数据管理中心约定 修改table 及tableId填入
        messagepush.setTableName(CommonConstants.GATHER_RECORD_TABLE_NAME);
        messagepush.setTableId(tfYwpnGatherrecord.getId());
        // 0102 一体化采集推送消息code
        messagepush.setType("0102");
//        messagepush.setType("0002");
        Long messagePushId = messageClient.save(messagepush).getResult();

        Messagerecipient messagerecipient = new Messagerecipient();
        messagerecipient.setMessageId(messagePushId);
        messagerecipient.setRecipient(Long.valueOf(reviewId));
        messagerecipient.setFlag(Constate.NO);
        return messageStateClient.save(messagerecipient).getResult();
    }

    @Override
    public boolean ispublished(String tableName, Long gatherId) {
        TfYwpnGatherrecord gatherrecord = getOne(Wrappers.<TfYwpnGatherrecord>lambdaQuery()
                .eq(TfYwpnGatherrecord::getTableName, tableName)
                .eq(TfYwpnGatherrecord::getGatherId, gatherId));
        if (gatherrecord != null) {
            return CommonConstants.GATHER_RECORD_STATE_PUSHED.equals(gatherrecord.getState());
        }
        return false;
    }

    @Override
    public Page<TfYwpnGatherrecordVO> getPageVO(Page page, TfYwpnGatherrecorDataDTO dto) {
        LambdaQueryWrapper<TfYwpnGatherrecord> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(TfYwpnGatherrecord::getCreateUser,SecurityUtils.getUserId());
        if (dto != null ) {
            if (dto.getState() != null) {
                queryWrapper.eq(TfYwpnGatherrecord::getState, dto.getState());
            }
            if (dto.getGatherEndTime() != null && dto.getGatherStartTime() != null) {
                Date start = DateUtil.parseDate(DateUtil.parseDateToStr(DateUtil.DATETIME_DEFAULT_FORMAT, dto.getGatherStartTime()));

                Date end = DateUtil.parseDate(DateUtil.parseDateToStr(DateUtil.DATE_DEFAULT_FORMAT, dto.getGatherEndTime()) + " 23:59:59");
                queryWrapper.between(TfYwpnGatherrecord::getCreateTime,start, end);
            }
            if (dto.getGatherType() != null) {
                List<String> list = Arrays.asList(dto.getGatherType().split(Constate.CSV));
                queryWrapper.in(TfYwpnGatherrecord::getGatherType, list);
            }
            queryWrapper.orderByDesc(TfYwpnGatherrecord::getCreateTime);
        }
        Page res = this.getBaseMapper().getPage(page, queryWrapper);
        List<TfYwpnGatherrecordVO> records = res.getRecords();
        if (records != null && records.size() > 0) {
            for (TfYwpnGatherrecordVO record : records) {
                String typeName = getGatherTypeName(record.getGatherType());
                if (StringUtils.isNotBlank(typeName)) {
                    record.setGatherTypeName(typeName);
                }
            }
        }
        return res;
    }

    private String getGatherTypeName(String gatherType) {
        Syschildcode syschildcode = new Syschildcode();
        syschildcode.setId(Long.valueOf(gatherType));
        Object result = codeClient.getChild(syschildcode).getResult();
        if (ObjectUtils.isNotEmpty(result)) {
            String str = JSON.toJSONString(result);
            String json = str.substring(1, str.length() - 1);
            return JSON.parseObject(json, Syschildcode.class).getCname();
        }
        return "";
    }

    @Override
    public List<GatherRecordVO> getNoAudit(String types) {
        List<GatherRecordVO> result = new ArrayList<>();
        List<String> typelist = null;
        GatherRecordVO recordVO = null;
        if (StringUtils.isBlank(types)) {
            return result;
        } else {
            typelist = Arrays.asList(types.split(Constate.CSV));
            for (String type : typelist) {

                LambdaQueryWrapper<TfYwpnGatherrecord> query = Wrappers.<TfYwpnGatherrecord>lambdaQuery()
                        .eq(TfYwpnGatherrecord::getGatherType, type)
                        .eq(TfYwpnGatherrecord::getState, Constate.NO)
                        .eq(TfYwpnGatherrecord::getCreateUser,SecurityUtils.getUserId())
                        .orderByAsc(TfYwpnGatherrecord::getCreateTime);

                List<TfYwpnGatherrecord> recordList = this.getBaseMapper().selectList(query);
                if (recordList != null && recordList.size() > 0 ) {
                    for (TfYwpnGatherrecord record : recordList) {
                        recordVO = new GatherRecordVO();
                        BeanUtils.copyProperties(record,recordVO);

                        switch (record.getTableName()) {
                            case CommonConstants.PIPE_RECORD_TABLE_NAME :
                                TfYwpnPipe tfYwpnPipe = pipeMapper.selectById(record.getGatherId());
                                if (tfYwpnPipe != null) {
                                    recordVO.setAddress(tfYwpnPipe.getAddress());
                                    recordVO.setSid(tfYwpnPipe.getSid());
                                    GatherRecordVO startVO = null;
                                    GatherRecordVO endVO = null;

                                    TfYwpnPipenode start = nodeMapper.selectOne(Wrappers.<TfYwpnPipenode>lambdaQuery()
                                            .eq(TfYwpnPipenode::getSid, tfYwpnPipe.getStartsid()));
                                    if (start != null) {
                                        startVO = new GatherRecordVO();
                                        startVO.setGatherId(start.getId());
                                        startVO.setSid(start.getSid());
                                        startVO.setY(start.getY());
                                        startVO.setX(start.getX());
                                        startVO.setAddress(start.getAddress());
//                                        startVO.setGatherType("629");
                                        recordVO.setStartNode(startVO);
                                    }

                                    TfYwpnPipenode end = nodeMapper.selectOne(Wrappers.<TfYwpnPipenode>lambdaQuery()
                                            .eq(TfYwpnPipenode::getSid, tfYwpnPipe.getEndsid()));
                                    if (end != null) {
                                        endVO = new GatherRecordVO();
                                        endVO.setGatherId(end.getId());
                                        endVO.setSid(end.getSid());
                                        endVO.setY(end.getY());
                                        endVO.setX(end.getX());
                                        endVO.setAddress(end.getAddress());
//                                        endVO.setGatherType("629");
                                        recordVO.setEndNode(endVO);
                                    }
                                    result.add(recordVO);
                                }
                                break;
                            case CommonConstants.WATERREP_RECORD_TABLE_NAME :
                                TfYwpnWaterRep waterRep = repMapper.selectById(record.getGatherId());
                                if (waterRep != null ) {
                                    recordVO.setX(waterRep.getX());
                                    recordVO.setY(waterRep.getY());
                                    recordVO.setSid(waterRep.getSid());
                                    recordVO.setAddress(waterRep.getAddress());
                                    recordVO.setWaterRep(waterRep);
                                    result.add(recordVO);
                                }
                                break;
                            case CommonConstants.STATION_RECORD_TABLE_NAME :
                                TfYwpnStation tfYwpnStation = stationMapper.selectById(record.getGatherId());
                                if (tfYwpnStation != null ) {
                                    recordVO.setX(tfYwpnStation.getX());
                                    recordVO.setY(tfYwpnStation.getY());
                                    recordVO.setSid(tfYwpnStation.getSid());
                                    recordVO.setAddress(tfYwpnStation.getAddress());
                                    result.add(recordVO);
                                }
                                break;
                            case CommonConstants.VALVE_RECORD_TABLE_NAME :
                                TfYwpnValve tfYwpnValve = valveMapper.selectById(record.getGatherId());
                                if (tfYwpnValve != null) {
                                    recordVO.setX(tfYwpnValve.getX());
                                    recordVO.setY(tfYwpnValve.getY());
                                    recordVO.setSid(tfYwpnValve.getSid());
                                    recordVO.setAddress(tfYwpnValve.getAddress());
                                    result.add(recordVO);
                                }
                                break;
                            case CommonConstants.NONVALVE_RECORD_TABLE_NAME :
                                TfYwpnNonvalve tfYwpnNonvalve = nonvalveMapper.selectById(record.getGatherId());
                                if (tfYwpnNonvalve != null) {
                                    recordVO.setX(tfYwpnNonvalve.getX());
                                    recordVO.setY(tfYwpnNonvalve.getY());
                                    recordVO.setSid(tfYwpnNonvalve.getSid());
                                    recordVO.setAddress(tfYwpnNonvalve.getAddress());
                                    result.add(recordVO);
                                }
                                break;
                            case CommonConstants.HYDRANT_RECORD_TABLE_NAME :
                                TfYwpnHydrant tfYwpnHydrant = hydrantMapper.selectById(record.getGatherId());
                                if(tfYwpnHydrant != null ){
                                    recordVO.setX(tfYwpnHydrant.getX());
                                    recordVO.setY(tfYwpnHydrant.getY());
                                    recordVO.setSid(tfYwpnHydrant.getSid());
                                    recordVO.setAddress(tfYwpnHydrant.getAddress());
                                    result.add(recordVO);

                                }
                                break;
                            case CommonConstants.MANHOLE_RECORD_TABLE_NAME :
                                TfYwpnManhole tfYwpnManhole = manholeMapper.selectById(record.getGatherId());
                                if (tfYwpnManhole != null ) {
                                    recordVO.setX(tfYwpnManhole.getX());
                                    recordVO.setY(tfYwpnManhole.getY());
                                    recordVO.setSid(tfYwpnManhole.getSid());
                                    recordVO.setAddress(tfYwpnManhole.getAddress());
                                    result.add(recordVO);
                                }
                                break;
                            case CommonConstants.NODE_RECORD_TABLE_NAME :
                                TfYwpnPipenode node = nodeMapper.selectById(record.getGatherId());
                                if (node != null ) {
                                    recordVO.setX(node.getX());
                                    recordVO.setY(node.getY());
                                    recordVO.setSid(node.getSid());
                                    recordVO.setAddress(node.getAddress());
                                    result.add(recordVO);
                                }
                                break;
                        }

//                        switch (record.getGatherType()) {
//                            case "609" :
//                                TfYwpnPipe tfYwpnPipe = pipeMapper.selectById(record.getGatherId());
//                                if (tfYwpnPipe != null) {
//                                    recordVO.setAddress(tfYwpnPipe.getAddress());
//                                    recordVO.setSid(tfYwpnPipe.getSid());
//                                    GatherRecordVO startVO = null;
//                                    GatherRecordVO endVO = null;
//
//                                    TfYwpnPipenode start = nodeMapper.selectOne(Wrappers.<TfYwpnPipenode>lambdaQuery()
//                                            .eq(TfYwpnPipenode::getSid, tfYwpnPipe.getStartsid()));
//                                    if (start != null) {
//                                        startVO = new GatherRecordVO();
//                                        startVO.setGatherId(start.getId());
//                                        startVO.setSid(start.getSid());
//                                        startVO.setY(start.getY());
//                                        startVO.setX(start.getX());
//                                        startVO.setAddress(start.getAddress());
//                                        startVO.setGatherType("629");
//                                        recordVO.setStartNode(startVO);
//                                    }
//
//                                    TfYwpnPipenode end = nodeMapper.selectOne(Wrappers.<TfYwpnPipenode>lambdaQuery()
//                                            .eq(TfYwpnPipenode::getSid, tfYwpnPipe.getEndsid()));
//                                    if (end != null) {
//                                        endVO = new GatherRecordVO();
//                                        endVO.setGatherId(end.getId());
//                                        endVO.setSid(end.getSid());
//                                        endVO.setY(end.getY());
//                                        endVO.setX(end.getX());
//                                        endVO.setAddress(end.getAddress());
//                                        endVO.setGatherType("629");
//                                        recordVO.setEndNode(endVO);
//                                    }
//                                    result.add(recordVO);
//                                }
//                                break;
//                            case "610" :
//                                TfYwpnWaterRep waterRep = repMapper.selectById(record.getGatherId());
//                                if (waterRep != null ) {
//                                    recordVO.setX(waterRep.getX());
//                                    recordVO.setY(waterRep.getY());
//                                    recordVO.setSid(waterRep.getSid());
//                                    recordVO.setAddress(waterRep.getAddress());
//                                    recordVO.setWaterRep(waterRep);
//                                    result.add(recordVO);
//                                }
//                                break;
//                            case "611" :
//                                TfYwpnStation tfYwpnStation = stationMapper.selectById(record.getGatherId());
//                                if (tfYwpnStation != null ) {
//                                    recordVO.setX(tfYwpnStation.getX());
//                                    recordVO.setY(tfYwpnStation.getY());
//                                    recordVO.setSid(tfYwpnStation.getSid());
//                                    recordVO.setAddress(tfYwpnStation.getAddress());
//                                    result.add(recordVO);
//                                }
//                                break;
//                            case "612" :
//                                TfYwpnValve tfYwpnValve = valveMapper.selectById(record.getGatherId());
//                                if (tfYwpnValve != null) {
//                                    recordVO.setX(tfYwpnValve.getX());
//                                    recordVO.setY(tfYwpnValve.getY());
//                                    recordVO.setSid(tfYwpnValve.getSid());
//                                    recordVO.setAddress(tfYwpnValve.getAddress());
//                                    result.add(recordVO);
//                                }
//                                break;
//                            case "613" :
//                                TfYwpnNonvalve tfYwpnNonvalve = nonvalveMapper.selectById(record.getGatherId());
//                                if (tfYwpnNonvalve != null) {
//                                    recordVO.setX(tfYwpnNonvalve.getX());
//                                    recordVO.setY(tfYwpnNonvalve.getY());
//                                    recordVO.setSid(tfYwpnNonvalve.getSid());
//                                    recordVO.setAddress(tfYwpnNonvalve.getAddress());
//                                    result.add(recordVO);
//                                }
//                                break;
//                            case "614" :
//                                TfYwpnHydrant tfYwpnHydrant = hydrantMapper.selectById(record.getGatherId());
//                                if(tfYwpnHydrant != null ){
//                                    recordVO.setX(tfYwpnHydrant.getX());
//                                    recordVO.setY(tfYwpnHydrant.getY());
//                                    recordVO.setSid(tfYwpnHydrant.getSid());
//                                    recordVO.setAddress(tfYwpnHydrant.getAddress());
//                                    result.add(recordVO);
//
//                                }
//                                break;
//                            case "615" :
//                                TfYwpnManhole tfYwpnManhole = manholeMapper.selectById(record.getGatherId());
//                                if (tfYwpnManhole != null ) {
//                                    recordVO.setX(tfYwpnManhole.getX());
//                                    recordVO.setY(tfYwpnManhole.getY());
//                                    recordVO.setSid(tfYwpnManhole.getSid());
//                                    recordVO.setAddress(tfYwpnManhole.getAddress());
//                                    result.add(recordVO);
//                                }
//                                break;
//                            case "629" :
//                                TfYwpnPipenode node = nodeMapper.selectById(record.getGatherId());
//                                if (node != null ) {
//                                    recordVO.setX(node.getX());
//                                    recordVO.setY(node.getY());
//                                    recordVO.setSid(node.getSid());
//                                    recordVO.setAddress(node.getAddress());
//                                    result.add(recordVO);
//                                }
//                                break;
//                        }
                    }
                }
            }
        }
        return result;
    }

    @Override
    public boolean deleteByTableNameAndGatherId(String tableName, Long gatherId) {
        boolean ispublished = this.ispublished(tableName, gatherId);
        if (!ispublished) {
            return this.remove(Wrappers.<TfYwpnGatherrecord>lambdaQuery()
                    .eq(TfYwpnGatherrecord::getTableName, tableName)
                    .eq(TfYwpnGatherrecord::getGatherId, gatherId));
        } else {
            return false;
        }
    }

    @Override
    public String getGlobalSid(String gatherTypeId, Long id) {
        StringBuilder sid = new StringBuilder("JS");
        String format = LocalDate.now().format(DateTimeFormatter.BASIC_ISO_DATE);
        String str = null;
        if (id <= 9999) {
            str = String.format("%04d", id);
        } else {
            str = String.format("%06d", id);
        }
        return sid.append(gatherTypeId).append(format).append(str).toString();
    }

    @Override
    public ResultRespone deleteById(Long id) {
        TfYwpnGatherrecord record = this.getById(id);
        if (record != null && Integer.parseInt(record.getState()) <= 1 ) {
            switch (record.getTableName()) {
                case CommonConstants.PIPE_RECORD_TABLE_NAME :
                    TfYwpnPipe pipe = pipeMapper.selectById(record.getGatherId());
                    if (pipe != null) {
                        TfYwpnPipenode start = nodeMapper.selectOne(Wrappers.<TfYwpnPipenode>lambdaQuery().eq(TfYwpnPipenode::getSid, pipe.getStartsid()));
                        TfYwpnPipenode end = nodeMapper.selectOne(Wrappers.<TfYwpnPipenode>lambdaQuery().eq(TfYwpnPipenode::getSid, pipe.getEndsid()));
                        remove(Wrappers.<TfYwpnGatherrecord>lambdaQuery().eq(TfYwpnGatherrecord::getTableName,CommonConstants.NODE_RECORD_TABLE_NAME)
                                .eq(TfYwpnGatherrecord::getGatherId, start.getId()));
                        remove(Wrappers.<TfYwpnGatherrecord>lambdaQuery().eq(TfYwpnGatherrecord::getTableName,CommonConstants.NODE_RECORD_TABLE_NAME)
                                .eq(TfYwpnGatherrecord::getGatherId, end.getId()));
                        nodeMapper.deleteById(start.getId());
                        nodeMapper.deleteById(end.getId());
                    }
                    pipeMapper.deleteById(record.getGatherId());
                    removeById(id);
                    break;
                case CommonConstants.WATERREP_RECORD_TABLE_NAME :
                    repMapper.deleteById(record.getGatherId());
                    removeById(id);
                    break;
                case CommonConstants.STATION_RECORD_TABLE_NAME :
                    stationMapper.deleteById(record.getGatherId());
                    removeById(id);
                    break;
                case CommonConstants.VALVE_RECORD_TABLE_NAME :
                    valveMapper.deleteById(record.getGatherId());
                    removeById(id);
                    break;
                case CommonConstants.NONVALVE_RECORD_TABLE_NAME :
                    nonvalveMapper.deleteById(record.getGatherId());
                    removeById(id);
                    break;
                case CommonConstants.HYDRANT_RECORD_TABLE_NAME :
                    hydrantMapper.deleteById(record.getGatherId());
                    removeById(id);
                    break;
                case CommonConstants.MANHOLE_RECORD_TABLE_NAME :
                    manholeMapper.deleteById(record.getGatherId());
                    removeById(id);
                    break;
                case CommonConstants.NODE_RECORD_TABLE_NAME :
                    nodeMapper.deleteById(record.getGatherId());
                    removeById(id);
                    break;
            }
        }
        return ResultRespone.failed("删除失败，采集记录已提交");
    }

}
