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

import com.jeeplus.core.persistence.Page;
import com.jeeplus.core.service.CrudService;
import com.jeeplus.modules.sg.managementcenter.materialProvided.entity.MaterialProvided;
import com.jeeplus.modules.sg.managementcenter.materialProvided.entity.MaterialProvidedVersion;
import com.jeeplus.modules.sg.managementcenter.materialProvided.mapper.MaterialProvidedMapper;
import com.jeeplus.modules.sg.managementcenter.materialProvided.mapper.MaterialProvidedVersionMapper;
import com.jeeplus.modules.test.one.dialog.entity.Leave1;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional(readOnly = true)
public class MaterialProvidedService extends CrudService<MaterialProvidedMapper, MaterialProvided> {
	@Autowired
	private MaterialProvidedMapper materialProvidedMapper;

	@Autowired
	private MaterialProvidedVersionMapper materialProvidedVersionMapper;

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

	@Transactional(readOnly = false)
	public void saveList(List<MaterialProvided> list,MaterialProvidedVersion materialProvidedVersion) {
		materialProvidedVersion.preInsert();
		materialProvidedVersionMapper.insert(materialProvidedVersion);//保存版本信息
		String id = materialProvidedVersion.getId();
		String name = materialProvidedVersion.getVersionName();
		for(MaterialProvided materialProvided : list){
			materialProvided.preInsert();
			materialProvided.setVersion(id);
			materialProvided.setVersionName(name);
		}
		materialProvidedMapper.insertList(list);
	}
}