package com.jpsoft.shinestar.modules.base.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.jpsoft.shinestar.modules.base.dao.ParkingDeviceDAO;
import com.jpsoft.shinestar.modules.base.entity.ParkingDevice;
import com.jpsoft.shinestar.modules.base.service.ParkingDeviceService;
import com.jpsoft.shinestar.modules.common.dto.Sort;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

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

/**
 * @author 墨鱼_mo
 * @date 2020-5-22 16:43
 */
@Transactional
@Component(value="parkingDeviceService")
public class ParkingDeviceServiceImpl implements ParkingDeviceService {

    @Resource(name="parkingDeviceDAO")
    private ParkingDeviceDAO parkingDeviceDAO;



    @Override
    public ParkingDevice get(Long id) {
        // TODO Auto-generated method stub
        return parkingDeviceDAO.get(id);
    }

    @Override
    public int insert(ParkingDevice model) {
        // TODO Auto-generated method stub
        //model.set${PkFieldName}(UUID.randomUUID().toString());

        return parkingDeviceDAO.insert(model);
    }

    @Override
    public int update(ParkingDevice model) {
        // TODO Auto-generated method stub
        return parkingDeviceDAO.update(model);
    }

    @Override
    public int delete(Long id) {
        // TODO Auto-generated method stub
        return parkingDeviceDAO.delete(id);
    }

    @Override
    public boolean exist(Long id) {
        // TODO Auto-generated method stub
        int count = parkingDeviceDAO.exist(id);

        return count > 0 ? true : false;
    }

    @Override
    public List<ParkingDevice> list() {
        // TODO Auto-generated method stub
        return parkingDeviceDAO.list();
    }

    @Override
    public Page<ParkingDevice> pageSearch(Map<String, Object> searchParams, int pageNumber, int pageSize, boolean count, List<Sort> sortList) {
        Page<ParkingDevice> page = PageHelper.startPage(pageNumber,pageSize,count).doSelectPage(()->{
            parkingDeviceDAO.search(searchParams,sortList);
        });

        return page;
    }

    @Override
    public ParkingDevice findByParkDeviceNo(String deviceCode) {
        return parkingDeviceDAO.findByParkDeviceNo(deviceCode);
    }

}
