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

import java.util.ArrayList;
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 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.workitem.entity.WorkItem;
import com.jeeplus.modules.workitem.dao.WorkItemDao;

/**
 * 物品一览表Service
 * @author chenyuping
 * @version 2018-07-13
 */
@Service
@Transactional(readOnly = true)
public class WorkItemService extends CrudService<WorkItemDao, WorkItem> {
	@Autowired
    private WorkItemDao workItemDao;
	@Autowired
	private OfficeDao officeDao;

	public WorkItem get(String id) {
		return super.get(id);
	}
	
	public List<WorkItem> findList(WorkItem workItem) {
		Office office =officeDao.get(UserUtils.getSelectOffice().getId());
		if(StringUtils.isNotBlank(office.getBranchOffice())){
			workItem.setBranchOffice(office.getBranchOffice());
		}else{
			workItem.setCompanyId(UserUtils.getSelectCompany().getId());
		}
		List<WorkItem> list=workItemDao.findListBybranch(workItem);
		return list;
	}
	
	public Page<WorkItem> findPage(Page<WorkItem> page, WorkItem workItem) {
		workItem.setPage(page);
		page.setList(findList(workItem));
		return page;
	}

	public Page<WorkItem> findItemPage(Page<WorkItem> page, WorkItem workItem) {
		workItem.setPage(page);
		page.setList(findItemList(workItem));
		return page;
	}
	public List<WorkItem> findItemList(WorkItem workItem) {
		List<WorkItem> list=new ArrayList<>();
		workItem.setState("1");
		workItem.setIsAssets("1");
		Office office =officeDao.get(UserUtils.getSelectOffice().getId());
		if(StringUtils.isNotBlank(office.getBranchOffice())){
			workItem.setBranchOffice(office.getBranchOffice());
			list=workItemDao.findListByCompanyId(workItem);
		}else{
			workItem.setCompanyId(UserUtils.getSelectCompany().getId());
			list=workItemDao.findListByCompanyId(workItem);
		}
		return list;
	}
	//报废管理选物品
	public Page<WorkItem> findScrapPage(Page<WorkItem> page, WorkItem workItem) {
		workItem.setPage(page);
		page.setList(findScrapItemList(workItem));
		return page;
	}
	public List<WorkItem> findScrapItemList(WorkItem workItem) {
		List<WorkItem> list=new ArrayList<>();
		Office office =officeDao.get(UserUtils.getSelectOffice().getId());
		if(StringUtils.isNotBlank(office.getBranchOffice())){
			workItem.setBranchOffice(office.getBranchOffice());
			list=workItemDao.findScrapList(workItem);
		}else{
			workItem.setCompanyId(UserUtils.getSelectCompany().getId());
			list=workItemDao.findScrapList(workItem);
		}
		return list;
	}

	@Transactional(readOnly = false)
	public void save(WorkItem workItem) {
		super.save(workItem);
	}
	
	@Transactional(readOnly = false)
	public void delete(WorkItem workItem) {
		super.delete(workItem);
	}
	
	
	
	
}