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.ProcinstActivityDAO;
import com.jpsoft.shinestar.modules.workflow.entity.ProcinstActivity;
import com.jpsoft.shinestar.modules.workflow.service.ProcinstActivityService;
import com.github.pagehelper.Page;
import com.jpsoft.shinestar.modules.common.dto.Sort;
import com.github.pagehelper.PageHelper;

@Transactional
@Component(value="procinstActivityService")
public class ProcinstActivityServiceImpl implements ProcinstActivityService {
	@Resource(name="procinstActivityDAO")
	private ProcinstActivityDAO procinstActivityDAO;

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

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

		return procinstActivityDAO.insert(model);
	}

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

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

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

		return count > 0 ? true : false;
	}

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

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

        return page;
	}

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

		return page;
	}




	@Override
	public List<ProcinstActivity> findByProcinstId(String procinstId) {
		return procinstActivityDAO.findByProcinstId(procinstId);
	}

	@Override
	public ProcinstActivity findByActivityIndexAndActivityId(int activityIndex, String activityId) {
		return procinstActivityDAO.findByActivityIndexAndActivityId(activityIndex,activityId);
	}

	@Override
	public List<ProcinstActivity> findProcinstIdAndAction(String procinstId, String action) {
		return procinstActivityDAO.findProcinstIdAndAction(procinstId,action);
	}

	@Override
	public ProcinstActivity findByActivityIndexAndProcinstId(int activityIndex, String procinstId) {
		return procinstActivityDAO.findByActivityIndexAndProcinstId(activityIndex,procinstId);
	}

	@Override
	public ProcinstActivity findProcinstIdAndStatus(String procinstId, String status) {
		return procinstActivityDAO.findProcinstIdAndStatus(procinstId,status);
	}
}