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

import java.util.List;
import java.util.Map;
import java.util.UUID;
import javax.annotation.Resource;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;
import com.jpsoft.shinestar.modules.base.dao.DistrictInfoDAO;
import com.jpsoft.shinestar.modules.base.entity.DistrictInfo;
import com.jpsoft.shinestar.modules.base.service.DistrictInfoService;
import com.github.pagehelper.Page;
import com.jpsoft.shinestar.modules.common.dto.Sort;
import com.github.pagehelper.PageHelper;

@Transactional
@Component(value="districtInfoService")
public class DistrictInfoServiceImpl implements DistrictInfoService {
	@Resource(name="districtInfoDAO")
	private DistrictInfoDAO districtInfoDAO;

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

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

		return districtInfoDAO.insert(model);
	}

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

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

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

		return count > 0 ? true : false;
	}

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

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

        return page;
	}

	@Override
	public DistrictInfo findByParent(String code){
		return districtInfoDAO.findByParent(code);
	}

	@Override
	public List<DistrictInfo> findTopRegion() {
		return districtInfoDAO.findTopRegion();
	}

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