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

import java.util.List;

import com.jeeplus.common.utils.StringUtils;
import com.jeeplus.modules.sys.entity.Office;
import com.jeeplus.modules.sys.entity.Role;
import com.jeeplus.modules.sys.service.OfficeService;
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.common.persistence.Page;
import com.jeeplus.common.service.CrudService;
import com.jeeplus.modules.activityassignment.entity.ActivityAssignment;
import com.jeeplus.modules.activityassignment.dao.ActivityAssignmentDao;

/**
 * 工作流任务委托Service
 * @author 杨帆
 * @version 2018-04-27
 */
@Service
@Transactional(readOnly = true)
public class ActivityAssignmentService extends CrudService<ActivityAssignmentDao, ActivityAssignment> {
	@Autowired
	private OfficeService officeService;

	public ActivityAssignment get(String id) {
		return super.get(id);
	}
	
	public List<ActivityAssignment> findList(ActivityAssignment activityAssignment) {
		return super.findList(activityAssignment);
	}
	
	public Page<ActivityAssignment> findPage(Page<ActivityAssignment> page, ActivityAssignment activityAssignment) {
		activityAssignment.setCompanyId(UserUtils.getSelectCompany().getId());
		if (!UserUtils.isManager()){
			activityAssignment.setCreateBy(UserUtils.getUser());
		}else {
			List<Role> roles = UserUtils.getSelectRole();
			String branchOffice = "";
			for (Role role:roles){
				if (role.getEnname().equals("gly")){
					branchOffice = "";
					break;
				}else if (role.getEnname().equals("fgly")){
					Office office = officeService.get(role.getOffice());
					branchOffice += office.getBranchOffice()+",";
				}
			}
			activityAssignment.setBranchOffice(branchOffice);
			//activityAssignment.getSqlMap().put("dsf", dataScopeFilter(activityAssignment.getCurrentUser(), "o", "u","s"));
		}
		return super.findPage(page, activityAssignment);
	}
	
	@Transactional(readOnly = false)
	public void save(ActivityAssignment activityAssignment) {
		if (StringUtils.isBlank(activityAssignment.getCompanyId())){
			activityAssignment.setCompanyId(UserUtils.getSelectCompany().getId());
		}
		super.save(activityAssignment);
	}
	
	@Transactional(readOnly = false)
	public void delete(ActivityAssignment activityAssignment) {
		super.delete(activityAssignment);
	}
	
	
	
	
}