package com.jpsoft.shinestar.modules.workflow.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.workflow.dao.TemplateDepartmentDAO;
import com.jpsoft.shinestar.modules.workflow.entity.TemplateDepartment;
import com.jpsoft.shinestar.modules.workflow.service.TemplateDepartmentService;
import com.github.pagehelper.Page;
import com.jpsoft.shinestar.modules.common.dto.Sort;
import com.github.pagehelper.PageHelper;

@Transactional
@Component(value="templateDepartmentService")
public class TemplateDepartmentServiceImpl implements TemplateDepartmentService {
	@Resource(name="templateDepartmentDAO")
	private TemplateDepartmentDAO templateDepartmentDAO;

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

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

		return templateDepartmentDAO.insert(model);
	}

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

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

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

		return count > 0 ? true : false;
	}

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

	@Override
	public List<TemplateDepartment> findByTemplateId(String templateId){
		return templateDepartmentDAO.findByTemplateId(templateId);
	}

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

        return page;
	}

	@Override
	public List<TemplateDepartment> findByFormIdDepartmentId(String formId, String companyId,String personRoleId) {
		return templateDepartmentDAO.findByFormIdDepartmentId(formId,companyId,personRoleId);
	}

	@Override
	public TemplateDepartment findByFormId(String formId) {
		return templateDepartmentDAO.findByFormId(formId);
	}
}