package com.muyu.enterprise.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.yulichang.wrapper.MPJLambdaWrapper;
import com.muyu.enterprise.cache.FenceCahceService;
import com.muyu.enterprise.mapper.ElectMapper;
import com.muyu.enterprise.mapper.WarnLogsMapper;
import com.muyu.enterprise.service.ElectService;
import com.muyu.common.core.utils.StringUtils;
import com.muyu.domain.Fence;
import com.muyu.domain.LanType;
import com.muyu.domain.req.FenceReq;
import com.muyu.domain.resp.FenceResp;
import com.muyu.enterprise.service.VehicleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ElectServiceImpl
        extends ServiceImpl<ElectMapper,Fence>
        implements ElectService {

    @Autowired
    private ElectMapper electMapper;
    @Autowired
    private VehicleService service;


    @Autowired
    private FenceCahceService fenceCahceService;


    @Override
    public List<FenceResp> selectFenceList(FenceReq req) {

        MPJLambdaWrapper<Fence> wrapper = new MPJLambdaWrapper<>();

        wrapper.selectAll(Fence.class)
                .selectAs(LanType::getTypeName,FenceReq::getTypeName)
                .leftJoin(LanType.class,LanType::getTypeId,Fence::getTypeId)
                .like(
                        StringUtils.isNotEmpty(req.getFenceName()),
                        Fence::getFenceName,
                        req.getFenceName()
                );
        List<FenceResp> list = electMapper.selectJoinList(FenceResp.class, wrapper);

        String decode = fenceCahceService.decode(String.valueOf(list));

        //将获取到的数据存到Redis
//        fenceCahceService.put(String.valueOf(decode),d);
        return list;
    }

    @Override
    public void updateFenceOn(Long fenceId) {
        int i = electMapper.updateFenceOn(fenceId);
    }

    @Override
    public void updateFenceOff(Long fenceId) {
        int i = electMapper.updateFenceOff(fenceId);
    }

    @Override
    public List<Fence> mapShow(Long fenceId) {
        List<Fence> fences = electMapper.mapShow(fenceId);
        return fences;
    }


    @Override
    public List<Fence> showFenceBound(Long fenceGroupId) {
        List<Fence> fences = electMapper.showFenceBound(fenceGroupId);
        return fences;
    }


}
