package com.cxyxiaomo.epp.access.service;

import com.cxyxiaomo.epp.access.dao.GateDao;
import com.cxyxiaomo.epp.common.pojo.Gate;
import com.cxyxiaomo.epp.common.utils.SnowflakeManager;
import com.cxyxiaomo.epp.common.vo.GateVO;
import org.springframework.stereotype.Service;

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

@Service
public class GateService {

    @Resource
    GateDao gateDao;


    public Gate getGateById(Long id) {
        if (id == null) {
            return null;
        }
        return gateDao.getGateById(id);
    }

    public List<Gate> getGateList(GateVO gateVO) {
        return gateDao.getGateList(gateVO);
    }

    public boolean addGate(Gate gate) throws Exception {
        // 创建大门编号
        SnowflakeManager snowflakeManager = new SnowflakeManager(1L, 1L);
        long orderId = snowflakeManager.nextValue();
        gate.setId(orderId);
        return gateDao.addGate(gate);
    }

    public boolean updateGate(Gate gate) {
        return gateDao.updateGate(gate);
    }

    public boolean deleteGate(Long gateId) {
        return gateDao.deleteGateById(gateId);
    }
}
