package cn.cecep.talroad.service.impl.analysis;

import cn.cecep.talroad.domain.analysis.BCoDischargePlan;
import cn.cecep.talroad.mapper.analysis.BCoDischargePlanMapper;
import cn.cecep.talroad.service.analysis.BCoDischargePlanService;
import cn.cecep.talroad.vo.analysis.CoPlanAllInfo;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.List;
@Service
public class BCoDischargePlanServiceImpl extends ServiceImpl<BCoDischargePlanMapper, BCoDischargePlan> implements BCoDischargePlanService{

    @Override
    public int batchInsert(List<BCoDischargePlan> list) {
        return baseMapper.batchInsert(list);
    }

    @Override
    public BCoDischargePlan newPlan(String factoryId) {
        return baseMapper.newPlanName(factoryId);
    }

    @Override
    public IPage<CoPlanAllInfo> selectCoAllInfoService(CoPlanAllInfo info) {
        Page<CoPlanAllInfo> p=new Page<>(info.getPageNum(),info.getPageSize());
        if(info.getStatus()!=null){
            String number = info.getStatus().equals("离线/异常") ? "0" : "1";
            info.setStatus(number);
        }
        IPage<CoPlanAllInfo> coAndMaintenancePlanAllInfoIPage = baseMapper.selectCoAllInfo(p, info);
        coAndMaintenancePlanAllInfoIPage.getRecords().forEach(c->{
            //0是离线，0代表空值
            if(!"0".equals(c.getStatusSourceMQ())){
                c.setStatus(c.getStatusSourceMQ());
            }else {
                c.setStatus("离线/异常");
            }
        });
        return coAndMaintenancePlanAllInfoIPage;
    }

    @Override
    public List<CoPlanAllInfo> selectCoAllInfoServiceList(CoPlanAllInfo info) {
        if(info.getStatus()!=null){
            String number = info.getStatus().equals("离线/异常") ? "0" : "1";
            info.setStatus(number);

        }
        List<CoPlanAllInfo> records = baseMapper.selectCoAllInfo(new Page<>(0,Integer.MAX_VALUE), info).getRecords();
        records.forEach(c->{
            if(!"0".equals(c.getStatusSourceMQ())){
                c.setStatus(c.getStatusSourceMQ());
            }else {
                c.setStatus("离线/异常");
            }
        });
        return records;
    }
}
