package com.xhpc.charging.station.service;

import cn.hutool.core.date.DateUtil;
import com.xhpc.charging.station.mapper.XhpcBarrierGateMapper;
import com.xhpc.common.core.domain.R;
import com.xhpc.common.core.web.service.BaseService;
import com.xhpc.common.domain.XhpcBarrierGate;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;
import java.util.Map;

@Service
public class XhpcBarrierGateServiceImpl extends BaseService implements IXhpcBarrierGateService{

    @Resource
    private XhpcBarrierGateMapper xhpcBarrierGateMapper;
    @Override
    public R getBarrierGateList() {
        return R.ok(xhpcBarrierGateMapper.getBarrierGateList());
    }

    @Override
    public List<Map<String, Object>> getLsit(String barrierGateCompany,String chargingStationNumber) {
        return xhpcBarrierGateMapper.getLsit(barrierGateCompany,chargingStationNumber);
    }

    @Override
    public R insertBarrierGate(XhpcBarrierGate xhpcBarrierGate) {
        if(xhpcBarrierGate.getBarrierGateId() !=null){
            xhpcBarrierGateMapper.updateBarrierGate(xhpcBarrierGate);
        }else {
            xhpcBarrierGateMapper.insertBarrierGate(xhpcBarrierGate);
        }

        return R.ok(null,"保存成功");
    }

    @Override
    public R updateBarrierGate(XhpcBarrierGate xhpcBarrierGate) {
        return null;
    }

    @Override
    public R deleteBarrierGateById(Long barrierGateId) {
        xhpcBarrierGateMapper.deleteBarrierGateById(barrierGateId);

        return R.ok(null,"删除成功");
    }

    @Override
    public Map<String, Object> getXhpcBarrierGateById(Long barrierGateId) {
        return xhpcBarrierGateMapper.getXhpcBarrierGateById(barrierGateId);
    }

    @Override
    public void getEndTimeExpire() {
        List<Long> barrierGateEndTime = xhpcBarrierGateMapper.getBarrierGateEndTime(DateUtil.now());
        for (int i = 0; i <barrierGateEndTime.size() ; i++) {
            xhpcBarrierGateMapper.updateBarrierGateStatus(barrierGateEndTime.get(i));
        }
    }
}
