/*
 * Author: wangjian
 * 生成ServiceImpl
 */
package com.tofly.gpsboot.service.paln.task.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import com.tofly.gpsboot.mapper.plan.PlanInspectGroupMapper;
import com.tofly.gpsboot.service.paln.task.PlanInspectGroupService;
import com.tofly.gpsboot.service.config.InspectgroupService;
import com.tofly.pojo.plan.Inspectgroup;
import com.tofly.pojo.plan.PlanInspectGroup;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;


/**
 * 计划与巡检组关联表
 *
 * @author admin
 * @date Tue Mar 30 00:00:00 CST 2021
 */
@Service("planInspectGroupService")
public class PlanInspectGroupServiceImpl extends ServiceImpl<PlanInspectGroupMapper, PlanInspectGroup> implements PlanInspectGroupService {

    @Autowired
    private InspectgroupService inspectgroupService;

    @Override
    public String getInspectGroupName(Long planId){
        List<PlanInspectGroup> one = this.list(new QueryWrapper<PlanInspectGroup>().lambda().eq(PlanInspectGroup::getPlanId, planId));
        if(null != one && one.size()>0){
            PlanInspectGroup inspectGroup = one.get(0);
            Long inspectGroupId = inspectGroup.getInspectGroupId();
            if (null!=inspectGroupId){
                Inspectgroup byId = inspectgroupService.getById(inspectGroupId);
                if (null!=byId){
                    return byId.getName();
                }

            }
        }
        return "";
    }

    @Override
    public Long getInspectGroupId(Long planId) {
        List<PlanInspectGroup> one = this.list(new QueryWrapper<PlanInspectGroup>().lambda().eq(PlanInspectGroup::getPlanId, planId));
        if(null != one && one.size()>0){
            PlanInspectGroup inspectGroup = one.get(0);
            Long inspectGroupId = inspectGroup.getInspectGroupId();
            if(null!=inspectGroupId && inspectGroupId!=0){
                Inspectgroup byId = inspectgroupService.getById(inspectGroupId);
                if (null!=byId){
                    return byId.getId();
                }
            }

        }
        return 0L;
    }
}
