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.ProjectInfoDAO;
import com.jpsoft.shinestar.modules.base.entity.ProjectInfo;
import com.jpsoft.shinestar.modules.base.service.ProjectInfoService;
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="projectInfoService")
public class ProjectInfoServiceImpl implements ProjectInfoService {
	@Resource(name="projectInfoDAO")
	private ProjectInfoDAO projectInfoDAO;

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

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

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

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

	@Override
	public boolean exist(String id) {
		// TODO Auto-generated method stub
		int count = projectInfoDAO.exist(id);
		
		return count > 0 ? true : false;
	}
	
	@Override
	public List<ProjectInfo> list() {
		// TODO Auto-generated method stub
		return projectInfoDAO.list();
	}
		
	@Override
	public Page<ProjectInfo> pageSearch(Map<String, Object> searchParams, int pageNumber, int pageSize,boolean count,List<Sort> sortList) {
        Page<ProjectInfo> page = PageHelper.startPage(pageNumber,pageSize,count).doSelectPage(()->{
            projectInfoDAO.search(searchParams,sortList);
        });
        
        return page;
	}

	@Override
	public ProjectInfo findOneByCompanyId(String companyId) {
		return projectInfoDAO.findOneByCompanyId(companyId);
	}

	@Override
	public ProjectInfo findOneByProjectCode(String projectCode) {
		return projectInfoDAO.findOneByProjectCode(projectCode);
	}
}