package com.inspect.taskinfo.service.impl;


import com.inspect.taskinfo.domain.PatrolTaskInfo;
import com.inspect.taskinfo.mapper.PatrolTaskInfoMapper;
import com.inspect.taskinfo.service.IPatrolTaskInfoService;

import java.util.*;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class PatrolTaskInfoServiceImpl implements IPatrolTaskInfoService {
    private final PatrolTaskInfoMapper patrolTaskInfoMapper;

    public PatrolTaskInfoServiceImpl(PatrolTaskInfoMapper patrolTaskInfoMapper) {
        this.patrolTaskInfoMapper = patrolTaskInfoMapper;
    }

    public PatrolTaskInfo selectPatrolTaskInfoByLineId(Long lineId) {
        return this.patrolTaskInfoMapper.selectPatrolTaskInfoByLineId(lineId);
    }

    public PatrolTaskInfo selectTaskInfoByBaseId(String lineId) {
        return this.patrolTaskInfoMapper.selectTaskInfoByBaseId(lineId);
    }

    public List<PatrolTaskInfo> selectTaskInfoByBaseIds(List<String> baseIds) {
        return this.patrolTaskInfoMapper.selectTaskInfoByBaseIds(baseIds);
    }

    public String selectAlgSubtypeIdsByPatrolPointId(String patrolPointId) {
        return this.patrolTaskInfoMapper.selectAlgSubtypeIdsByPatrolPointId(patrolPointId);
    }

    public Map<String, String> selectVideoPosByPointId(String lineId) {
        return this.patrolTaskInfoMapper.selectVideoPosByPointId(lineId);
    }

    public List<Map<String, String>> selectVideoPosByPointIdByEqpbookIds(List<String> pointIds) {
        return this.patrolTaskInfoMapper.selectVideoPosByPointIdByEqpbookIds(pointIds);
    }

    public Map<String, String> selectPoseInfo(String devId, String eqBookId) {
        return this.patrolTaskInfoMapper.selectPoseInfo(devId, eqBookId);
    }

    public List<PatrolTaskInfo> selectPatrolTaskInfoList(PatrolTaskInfo patrolTaskInfo) {
        return patrolTaskInfoMapper.selectPatrolTaskInfoList(patrolTaskInfo);
    }

    public List<PatrolTaskInfo> selectPatrolTask(PatrolTaskInfo patrolTaskInfo) {
        return this.patrolTaskInfoMapper.selectPatrolTask(patrolTaskInfo);
    }

    public Map<String, List> selectPatrolTaskInfoListByMajorId(String taskId) {
        Map<String, List> map = new HashMap<>();
        List<String> list1 = new ArrayList<>();
        List<String> listFull = this.patrolTaskInfoMapper.selectPatrolTaskInfoListByMajorIdFull(taskId);
        if (listFull.size() > 0) {
            for (int i = 0; i < listFull.size(); i++) {
                String value = listFull.get(i);
                if (listFull.get(i).contains("|") && listFull.get(i).indexOf("|") < listFull.get(i).length()-1) {
                    value = value.substring(value.indexOf("|") + 1);
                } else if (listFull.get(i).contains("_") && listFull.get(i).indexOf("_") < listFull.get(i).length()-1) {
                    value = value.substring(value.indexOf("_") + 1);
                }
                list1.add(value);
            }
        }

        map.put("list" , list1);
        map.put("listFull", listFull);
        return map;
    }

    public List<PatrolTaskInfo> selectPatrolAbnormalTaskList(PatrolTaskInfo patrolTaskInfo) {
        return this.patrolTaskInfoMapper.selectPatrolAbnormalTaskList(patrolTaskInfo);
    }

    public int insertPatrolTaskInfo(PatrolTaskInfo patrolTaskInfo) {
        patrolTaskInfo.setCreateTime(new Date());
        return this.patrolTaskInfoMapper.insertPatrolTaskInfo(patrolTaskInfo);
    }

    public int batchInsertPatrolTaskInfo(List<PatrolTaskInfo> patrolTaskInfos) {
        return this.patrolTaskInfoMapper.batchInsertPatrolTaskInfo(patrolTaskInfos);
    }

    public int updatePatrolTaskInfo(PatrolTaskInfo patrolTaskInfo) {
        return this.patrolTaskInfoMapper.updatePatrolTaskInfo(patrolTaskInfo);
    }

    public int deletePatrolTaskInfoByLineIds(Long[] lineIds) {
        return this.patrolTaskInfoMapper.deletePatrolTaskInfoByLineIds(lineIds);
    }

    public int deletePatrolTaskInfoByLineId(Long lineId) {
        return this.patrolTaskInfoMapper.deletePatrolTaskInfoByLineId(lineId);
    }

    public int deletePatrolTaskInfoByMajorIds(Long[] majorIds) {
        return this.patrolTaskInfoMapper.deletePatrolTaskInfoByMajorIds(majorIds);
    }

    public List<Map<String, Object>> selectPatrolTaskInfoCount(List<String> taskInfoIds) {
        return this.patrolTaskInfoMapper.selectPatrolTaskInfoCount(taskInfoIds);
    }

    public int deletePatrolTaskInfoByMajorId(Long taskMajorId) {
        return this.patrolTaskInfoMapper.deletePatrolTaskInfoByMajorId(taskMajorId);
    }

    @Override
    public int countPatrolTaskInfoByMajorId(String taskMajorId) {
        return this.patrolTaskInfoMapper.countPatrolTaskInfoByMajorId(taskMajorId);
    }
}
