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

import java.util.List;

import com.jeeplus.common.utils.MenuStatusEnum;
import com.jeeplus.common.utils.StringUtils;
import com.jeeplus.modules.sys.utils.UserUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.jeeplus.modules.workcontractinfo.entity.WorkContractInfo;
import com.jeeplus.common.persistence.Page;
import com.jeeplus.common.service.CrudService;
import com.jeeplus.modules.workproject.entity.WorkProject;
import com.jeeplus.modules.workproject.dao.WorkProjectDao;

/**
 * 总项目管理Service
 * @author liuw
 * @version 2017-11-29
 */
@Service
@Transactional(readOnly = true)
public class WorkProjectService extends CrudService<WorkProjectDao, WorkProject> {
	@Autowired
	private WorkProjectDao workProjectDao;
	public WorkProject get(String id) {
		return super.get(id);
	}

	@Transactional(readOnly = false)
	public void updateStatus(WorkProject workProject) {
		dao.updateStatus(workProject);
	}
	public List<WorkProject> getByCId(WorkContractInfo contractId) {
		return workProjectDao.getByCId(contractId);
	}
	public List<WorkProject> findList(WorkProject workProject) {
		return super.findList(workProject);
	}
	
	public Page<WorkProject> findPage(Page<WorkProject> page, WorkProject workProject) {
		workProject.getSqlMap().put("dsf", dataScopeFilter(workProject.getCurrentUser(), "o", "u","s", MenuStatusEnum.END.getValue()));
		return super.findPage(page, workProject);
	}
	
	@Transactional(readOnly = false)
	public void save(WorkProject workProject) {
		if (StringUtils.isBlank(workProject.getOfficeId())){
			workProject.setOfficeId(UserUtils.getSelectOffice().getId());
		}
		super.save(workProject);
	}

	@Transactional(readOnly = false)
	public void update(WorkProject workProject) {
		workProjectDao.update(workProject);
	}
	@Transactional(readOnly = false)
	public void delete(WorkProject workProject) {
		super.delete(workProject);
	}
	
	public Page<WorkContractInfo> findPageBycontractId(Page<WorkContractInfo> page, WorkContractInfo contractId) {
		contractId.setPage(page);
		page.setList(dao.findListBycontractId(contractId));
		return page;
	}
	
	
	
}