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

import com.jeeplus.common.utils.StringUtils;
import com.jeeplus.common.utils.excel.ImportExcel;
import com.jeeplus.core.persistence.Page;
import com.jeeplus.core.service.CrudService;
import com.jeeplus.modules.sg.managementcenter.materialinfo.entity.MaterialStandard;
import com.jeeplus.modules.sg.managementcenter.materialinfo.entity.MaterialVersion;
import com.jeeplus.modules.sg.managementcenter.materialinfo.mapper.MaterialVersionMapper;
import com.jeeplus.modules.sg.managementcenter.materialproject.entity.MaterialProject;
import com.jeeplus.modules.sg.managementcenter.materialproject.service.MaterialProjectService;
import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
import org.apache.poi.ss.usermodel.Row;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;


@Service
@Transactional(readOnly = true)
public class MaterialVersionService extends CrudService<MaterialVersionMapper, MaterialVersion> {

	@Autowired
	private MaterialVersionMapper materialVersionMapper;

	public MaterialVersion get(String id) {
		return super.get(id);
	}
	
	public List<MaterialVersion> findList(MaterialVersion materialVersion) {
		return super.findList(materialVersion);
	}
	
	
	public Page<MaterialVersion> findPage(Page<MaterialVersion> page, MaterialVersion materialVersion) {
		return super.findPage(page, materialVersion);
	}
	
	@Transactional(readOnly = false)
	public void save(MaterialVersion materialVersion) {
		super.save(materialVersion);
	}

	/**
	 *物料保存
	 */
	@Transactional(readOnly = false)
	public void saveList(List<MaterialStandard> list,String batch) {
		MaterialVersion materialVersion = new MaterialVersion();
		materialVersion.setBatch(batch);
        List<MaterialVersion> list1 = materialVersionMapper.findList(materialVersion);
        if(list1 != null && list1.size()>0){
        	materialVersionMapper.deleteByBatch(batch);
        	materialVersionMapper.deleteData(batch);
		}
        save(materialVersion);
		materialVersionMapper.insertList(list);
	}

	/**
	 *删除物料信息
	 */
	@Transactional(readOnly = false)
	public void delete(MaterialVersion materialVersion) {
		super.delete(materialVersion);
		deleteByPro(materialVersion.getBatch());
	}

	/**
	 * 更加批次号删除物料信息
	 */
	@Transactional(readOnly = false)
	public void deleteByPro(String batch) {
		materialVersionMapper.deleteByBatch(batch);
	}










	
}