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.ApprovalConfigDAO;
import com.jpsoft.shinestar.modules.base.entity.ApprovalConfig;
import com.jpsoft.shinestar.modules.base.service.ApprovalConfigService;
import com.github.pagehelper.Page;
import com.jpsoft.shinestar.modules.common.dto.Sort;
import com.github.pagehelper.PageHelper;

@Transactional
@Component(value="approvalConfigService")
public class ApprovalConfigServiceImpl implements ApprovalConfigService {
	@Resource(name="approvalConfigDAO")
	private ApprovalConfigDAO approvalConfigDAO;

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

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

		return approvalConfigDAO.insert(model);
	}

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

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

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

		return count > 0 ? true : false;
	}

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

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

        return page;
	}

	@Override
	public ApprovalConfig findByCompanyIdAndType(String companyId, String type) {
		return approvalConfigDAO.findByCompanyIdAndType(companyId,type);
	}
}