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.ParkingApplyDAO;
import com.jpsoft.shinestar.modules.base.dao.ParkingAuthorizeDAO;
import com.jpsoft.shinestar.modules.base.entity.ParkingAuthorize;
import com.jpsoft.shinestar.modules.base.service.ParkingAuthorizeService;
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-10-22 14:03
 */
@Transactional
@Component(value="parkingAuthorizeService")
public class ParkingAuthorizeServiceImpl implements ParkingAuthorizeService {

    @Resource(name="parkingAuthorizeDAO")
    private ParkingAuthorizeDAO parkingAuthorizeDAO;

    @Override
    public ParkingAuthorize get(String id) {
        // TODO Auto-generated method stub
        return parkingAuthorizeDAO.get(id);
    }

    @Override
    public int insert(ParkingAuthorize model) {
        // TODO Auto-generated method stub
        //model.setId(UUID.randomUUID().toString());

        return parkingAuthorizeDAO.insert(model);
    }

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

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

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

        return count > 0 ? true : false;
    }

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

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

        return page;
    }

    @Override
    public ParkingAuthorize findByAuthorizedCompanyId(String companyId) {
        return parkingAuthorizeDAO.findByAuthorizedCompanyId(companyId);
    }
}
