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

import com.jeeplus.core.persistence.Page;
import com.jeeplus.core.service.CrudService;
import com.jeeplus.modules.sg.managementcenter.materialInventory.entity.MaterialInventory;
import com.jeeplus.modules.sg.picking.activiti.entity.*;
import com.jeeplus.modules.sg.picking.activiti.mapper.PickIngMapper;
import com.jeeplus.modules.sg.picking.activiti.mapper.ShowListMapper;
import org.activiti.engine.task.Task;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

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

/**
 * 模块显示Service
 *
 * @author
 * @version 2019-11-08
 */
@Service
@Transactional(readOnly = true)
public class ShowListService extends CrudService<ShowListMapper, ShowList> {
	@Autowired
	private ShowListMapper showListMapper;

	@Override
	public Page<ShowList> findPage(Page<ShowList> page, ShowList entity) {
		return super.findPage(page, entity);
	}

	public Page<ShowList> findNewPage(Page<ShowList> page, ShowList showList) {
		dataRuleFilter(showList);
		showList.setPage(page);
		page.setList(mapper.findNewList(showList));
		return page;
	}

	public Page<ShowList> findNewTemPage(Page<ShowList> page, ShowList showList) {
		dataRuleFilter(showList);
		showList.setPage(page);
		page.setList(mapper.findNewTemList(showList));
		return page;
	}

	public Page<ShowList> findRaisePage(Page<ShowList> page, ShowList showList) {
		dataRuleFilter(showList);
		showList.setPage(page);
		page.setList(mapper.findRaiseList(showList));
		return page;
	}

	//物资上报
	public Page<ShowList> findMaterialReport(Page<ShowList> page, ShowList showList) {
		dataRuleFilter(showList);
		showList.setPage(page);
		page.setList(mapper.findMaterialReport(showList));
		return page;
	}

	public List<ShowList> findNewTemList(ShowList showList) {
		return mapper.findNewTemList(showList);
	}


	public Page<Acquisition> acquisitionList(Page<Acquisition> page, Acquisition acquisition) {
		dataRuleFilter(acquisition);
		acquisition.setPage(page);
		page.setList(mapper.acquisitionList(acquisition));
		return page;
	}

	public Page<ShowList> inventoryComparisonData(Page<ShowList> page, ShowList showList, List<String> searchList) {
		dataRuleFilter(showList);
		showList.setPage(page);
		page.setList(mapper.inventoryComparisonData(searchList));
		return page;
	}

	/**
	 * 根据id查询领料清单中的需要修改的那条信息
	 */
	public ShowList findOneList(ShowList showList) {
		return showListMapper.findOneList(showList);
	}

	/**
	 * 根据id查询临时表中的需要修改的那条信息
	 * */
	public ShowList findOneTemList(ShowList showList){
		return showListMapper.findOneTemList(showList);
	}


/*	public Page<ShowList> findNewPage(Page<ShowList> page, ShowList entity) {
		dataRuleFilter(entity);
		entity.setPage(page);
		page.setList(mapper.findNewList(entity));
		return page;
	}*/


	public String findNumber(String projectId) {
		return showListMapper.findNumber(projectId);
	}

	/**
	 * 保存项目提前领料流程信息
	 */
	@Transactional(readOnly = false)
	public void newSave(PickApplication pickApplication) {
		pickApplication.preInsert();
		showListMapper.newSave(pickApplication);
	}

	/**
	 * 保存物资上报流程信息
	 */
	@Transactional(readOnly = false)
	public void materialReportSave(MaterialReport materialReport) {
		materialReport.preInsert();
		showListMapper.materialReportSave(materialReport);
	}

	/**
	 *将数据存入提资领料表
	 */
	@Transactional(readOnly = false)
	public void replaceData(List<ShowList> list) {
		for (ShowList s :
				list) {
			s.preInsert();
		}
		showListMapper.replaceData(list);
	}

	/**
	 * 修改总量
	 */
	@Transactional(readOnly = false)
	public void updateAmount(ShowList showList) {
		showListMapper.updateAmount(showList);
	}

	/**
	 * 修改总量-提资模块
	 */
	@Transactional(readOnly = false)
	public void raiseUpdate(ShowList showList) {
		showListMapper.raiseUpdate(showList);
	}

	/**
	 * 修改临时表总量
	 */
	@Transactional(readOnly = false)
	public void updateTemAmount(ShowList showList) {
		showListMapper.updateTemAmount(showList);
	}

	/**
	 * 修改项目信息状态
	 */
	@Transactional(readOnly = false)
	public void projectUpdate(PickApplication pickApplication) {
		showListMapper.projectUpdate(pickApplication);
	}

	;

	public String selectProjectId(String id) {
		return showListMapper.selectProjectId(id);
	}

	;

	public String itemQuery(String procInsId) {
		return showListMapper.itemQuery(procInsId);
	}

	@Transactional(readOnly = false)
	public void deleteData(String id) {
		showListMapper.deleteData(id);
	}

	@Transactional(readOnly = false)
	public void deleteRaiseAll(String id) {
		showListMapper.deleteRaiseAll(id);
	}


	@Transactional(readOnly = false)
	public void trunCate(String projectName) {
		showListMapper.trunCate(projectName);
	}

	@Transactional(readOnly = false)
	public void deleteTemData(String id) {
		showListMapper.deleteTemData(id);
	}

	/**
	 * 查询流程中物料的可用库存数量
	 */
	public List<MaterialInventory> inventoryQuery(List<ShowList> showLists) {
		return showListMapper.inventoryQuery(showLists);
	}

	public List<ShowList> processListQuery(List<String> list) {
		return showListMapper.processListQuery(list);
	}

	public void updateManagerTime(String procInsId) {
		showListMapper.updateManagerTime(procInsId);
	}

	public List<String> selectAllId() {
		return showListMapper.selectAllId();
	}

	@Transactional(readOnly = false)
	public void updateAcqStatus(String reserveProjectName) {
		showListMapper.updateAcqStatus(reserveProjectName);
	}

	public String findAcqStatus(String reserveProjectName) {
		return showListMapper.findAcqStatus(reserveProjectName);
	}

	public List<ExportListing> exportListing(List<String> list) {
		return showListMapper.exportListing(list);
	}



	public Page<PickIng> findNewImgPage(Page<PickIng> page, PickIng pickIng) {
		dataRuleFilter(pickIng);
		pickIng.setPage(page);
		page.setList(mapper.findMdImg(pickIng.getId()));
		return page;
	}

}