/**
 * Copyright &copy; 2015-2020 <a href="http://www.jeeplus.org/">JeePlus</a> All rights reserved.
 */
package com.jeeplus.modules.workregularapply.service;

import java.util.List;

import com.jeeplus.common.utils.StringUtils;
import com.jeeplus.modules.sys.dao.OfficeDao;
import com.jeeplus.modules.sys.entity.Office;
import com.jeeplus.modules.sys.utils.UserUtils;
import com.jeeplus.modules.workcatalogueitem.entity.WorkCatalogueItem;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.jeeplus.common.persistence.Page;
import com.jeeplus.common.service.CrudService;
import com.jeeplus.modules.workregularapply.entity.WorkRegularContent;
import com.jeeplus.modules.workregularapply.dao.WorkRegularContentDao;

/**
 * 鉴定内容码表Service
 * @author chenyuping
 * @version 2018-07-30
 */
@Service
@Transactional(readOnly = true)
public class WorkRegularContentService extends CrudService<WorkRegularContentDao, WorkRegularContent> {
	@Autowired
	private OfficeDao officeDao;
	@Autowired
	private WorkRegularContentDao workRegularContentDao;
	public WorkRegularContent get(String id) {
		return super.get(id);
	}
	//获取分公司级数据
	public List<WorkRegularContent> findList(WorkRegularContent workRegularContent) {
		if(StringUtils.isBlank(workRegularContent.getOfficeId())){
			workRegularContent.setOfficeId(UserUtils.getSelectOffice().getId());
		}
		if(StringUtils.isBlank(workRegularContent.getCompanyId())){
			workRegularContent.setCompanyId(UserUtils.getSelectCompany().getId());
		}
		Office office=UserUtils.getSelectOffice();
		if(StringUtils.isNotBlank(office.getBranchOffice())){
			workRegularContent.setBranchOffice(office.getBranchOffice());
		}else{
			workRegularContent.setBranchOffice(UserUtils.getSelectCompany().getId());
		}
		/*Office office =officeDao.get(workRegularContent.getOfficeId());
		workRegularContent.setBranchOffice(office.getBranchOffice());
		workRegularContent.setCompanyId(workRegularContent.getCompanyId());*/
		List<WorkRegularContent> list=workRegularContentDao.findList(workRegularContent);
		return list;
	}
//定时任务用获取分公司级数据
	public List<WorkRegularContent> findListApply(WorkRegularContent workRegularContent) {
		Office office=officeDao.get(workRegularContent.getOfficeId());
		if(StringUtils.isNotBlank(office.getBranchOffice())){
			workRegularContent.setBranchOffice(office.getBranchOffice());
		}else{
			workRegularContent.setBranchOffice(workRegularContent.getCompanyId());
		}
		List<WorkRegularContent> list=workRegularContentDao.findList(workRegularContent);
		return list;
	}
//获取分页列表
	public Page<WorkRegularContent> findPage(Page<WorkRegularContent> page, WorkRegularContent workRegularContent) {
		workRegularContent.setPage(page);
		page.setList(findList(workRegularContent));
		return page;
	}

	/**
	 * 保存评分
	 * @param workRegularContent
	 */
	@Transactional(readOnly = false)
	public void save(WorkRegularContent workRegularContent) {
		Office office=UserUtils.getSelectOffice();
		if(StringUtils.isNotBlank(office.getBranchOffice())){
			workRegularContent.setBranchOffice(office.getBranchOffice());
		}else{
			workRegularContent.setBranchOffice(UserUtils.getSelectCompany().getId());
		}
		super.save(workRegularContent);
	}
	
	@Transactional(readOnly = false)
	public void delete(WorkRegularContent workRegularContent) {
		super.delete(workRegularContent);
	}
	
	
	
	
}