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

import java.util.ArrayList;
import java.util.List;

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.workitem.entity.WorkItem;
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.workcatalogueitem.entity.WorkCatalogueItem;
import com.jeeplus.modules.workcatalogueitem.dao.WorkCatalogueItemDao;

/**
 * 物品目录Service
 * @author chenyuping
 * @version 2018-07-10
 */
@Service
@Transactional(readOnly = true)
public class WorkCatalogueItemService extends CrudService<WorkCatalogueItemDao, WorkCatalogueItem> {
	@Autowired
	private WorkCatalogueItemDao workCatalogueItemDao;
	@Autowired
	private OfficeDao officeDao;
	public WorkCatalogueItem get(String id) {
		return super.get(id);
	}
	
	public List<WorkCatalogueItem> findList(WorkCatalogueItem workCatalogueItem) {
		Office office =officeDao.get(UserUtils.getSelectOffice().getId());
		workCatalogueItem.setBranchOffice(office.getBranchOffice());
		workCatalogueItem.setCompanyId(UserUtils.getSelectCompany().getId());
		List<WorkCatalogueItem> list=workCatalogueItemDao.findList(workCatalogueItem);
		return list;

	}
	
	public Page<WorkCatalogueItem> findPage(Page<WorkCatalogueItem> page, WorkCatalogueItem workCatalogueItem) {
		workCatalogueItem.setPage(page);
		page.setList(findList(workCatalogueItem));
		return page;
	}
	
	@Transactional(readOnly = false)
	public void save(WorkCatalogueItem workCatalogueItem) {
		super.save(workCatalogueItem);
	}
	
	@Transactional(readOnly = false)
	public void delete(WorkCatalogueItem workCatalogueItem) {
		super.delete(workCatalogueItem);
	}

	@Transactional(readOnly = false)
	public void removeFlat(WorkCatalogueItem workCatalogueItem) {
		workCatalogueItemDao.removeFlat(workCatalogueItem);
	}


	public List<WorkCatalogueItem> findCatalogList(WorkCatalogueItem workCatalogueItem) {
		Office office =officeDao.get(UserUtils.getSelectOffice().getId());
		workCatalogueItem.setBranchOffice(office.getBranchOffice());
		workCatalogueItem.setCompanyId(UserUtils.getSelectCompany().getId());
		workCatalogueItem.setRemoveFlat("0");
		List<WorkCatalogueItem> list=workCatalogueItemDao.findList(workCatalogueItem);
		return list;
	}

	public Page<WorkCatalogueItem> findCatalogPage(Page<WorkCatalogueItem> page, WorkCatalogueItem workCatalogueItem) {
		workCatalogueItem.setPage(page);
		page.setList(findCatalogList(workCatalogueItem));
		return page;
	}
	
}