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.ParkingInfoDAO;
import com.jpsoft.shinestar.modules.base.entity.ParkingInfo;
import com.jpsoft.shinestar.modules.base.service.ParkingInfoService;
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;

@Transactional
@Component(value="parkingInfoService")
public class ParkingInfoServiceImpl implements ParkingInfoService {
	@Resource(name="parkingInfoDAO")
	private ParkingInfoDAO parkingInfoDAO;

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

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

		return parkingInfoDAO.insert(model);
	}

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

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

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

		return count > 0 ? true : false;
	}

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

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

        return page;
	}

	@Override
	public List<ParkingInfo> findByCompanyIdNotParentId(String id) {
		return parkingInfoDAO.findByCompanyIdNotParentId(id);
	}

	@Override
	public List<ParkingInfo> findByParentId(String parentId) {
		return parkingInfoDAO.findByParentId(parentId);
	}

	@Override
	public List<ParkingInfo> findHasPicUrl(String companyId) {
		return parkingInfoDAO.findHasPicUrl(companyId);
	}

	@Override
	public ParkingInfo findByParkId(Long parkId) {
		return parkingInfoDAO.findByParkId(parkId);
	}


}