package com.ssj.service.sys.award.service.impl;

import java.util.Date;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.repository.PagingAndSortingRepository;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.ssj.bean.sys.award.domain.AwardMaterial;
import com.ssj.dao.sys.award.dao.AwardMaterialDao;
import com.ssj.dao.sys.award.dao.AwardQueryDao;
import com.ssj.framework.core.common.service.BaseServiceImpl;
import com.ssj.service.sys.award.service.AwardMaterialService;
import com.ssj.service.sys.award.service.AwardSncodeService;

@Service
@Transactional
public class AwardMaterialServiceImpl extends BaseServiceImpl<AwardMaterial, String> implements AwardMaterialService {
	
	@Autowired
	private AwardMaterialDao  awardMaterialDao;

	@Autowired
	private AwardQueryDao  queryDao;

	@Autowired
	private AwardSncodeService  awardSncodeService;

	@Override
	public PagingAndSortingRepository<AwardMaterial, String> getDao() {
		return awardMaterialDao;
	}

	@Override
	public Page<Map<String, Object>> findAwardMaterialBylist(Map<String, Object> searchParams, Pageable pageable) {
		return queryDao.findAwardMaterialBylist(searchParams, pageable);
	}

	@Override
	public List<AwardMaterial> findAwardMaterialByLevel(Integer level) {
		return awardMaterialDao.findAwardMaterialByLevel(level);
	}

	@Override
	public AwardMaterial getAwardMaterialById(String id) {
		return awardMaterialDao.getAwardMaterialById(id);
	}

	@Override
	@Transactional
	public AwardMaterial addNumberAndSnCode(String id, Integer number) {
		AwardMaterial awardMaterial = this.getById(id);
		awardMaterial.setStockNumber((awardMaterial.getStockNumber()==null?0:awardMaterial.getStockNumber())+number);
		awardMaterial.setUpdateTime(new Date());
		this.save(awardMaterial);
		
		awardSncodeService.createAwardSncodeByCode(awardMaterial,number);
		
		return awardMaterial;
	}

	
}
