package com.pcloud.book.book.biz.impl;

import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import com.google.common.collect.Maps;
import com.pcloud.appcenter.base.exception.AppBizException;
import com.pcloud.book.base.exception.BookBizException;
import com.pcloud.book.book.biz.BookAssistTempletBiz;
import com.pcloud.book.book.dao.BookAssistTempletDao;
import com.pcloud.book.book.entity.BookAssistTemplet;
import com.pcloud.common.exceptions.BizException;
import com.pcloud.common.utils.ListUtils;
import com.pcloud.common.utils.UUIDUitl;
/**
 * 书刊模板分类BIZ实现类
 * @author MICHAEL
 * @date : 2018年5月3日
 */
@Component("bookAssistTempletBiz")
public class BookAssistTempletBizImpl implements BookAssistTempletBiz {

	private static final Logger LOGGER = LoggerFactory.getLogger(BookAssistTempletBizImpl.class);
	@Autowired
	private BookAssistTempletDao bookAssistTempletDao;
	
	/**
	 * 新增
	 */
	/*@Transactional(rollbackFor=Exception.class)
	@Override
	public void insert(BookAssistTemplet bookAssistTemplet, Long partyId) throws BizException {
		LOGGER.info("【书刊模板分类】新增,<START>.[bookAssistTemplet]=" + bookAssistTemplet+",[partyId]:"+partyId);
		bookAssistTemplet.setTypeCode(UUIDUitl.generateAllString(12));
		bookAssistTemplet.setCreatedUser(partyId);
		try {
			bookAssistTempletDao.insert(bookAssistTemplet);
		} catch (Exception e) {
			LOGGER.error("【书刊模板分类】新增出现异常，信息为:"+e.getMessage());
			throw new BookBizException(BookBizException.DB_DML_FAIL, "系统出现异常，请稍后重试!");
		}
		LOGGER.info("【书刊模板分类】 新增,<END>");
	}*/
	/**
	 * 根据ID删除
	 */
	/*@Transactional(rollbackFor=Exception.class)
	@Override
	public void deleteById(Long assistTempletId, Long partyId) throws BizException {
		LOGGER.info("【书刊模板分类】根据ID删除,<START>.[assistTempletId]=" + assistTempletId+",[partyId]:"+partyId);
		checkTempletId(assistTempletId);
		try {
			bookAssistTempletDao.deleteById(assistTempletId);
		} catch (Exception e) {
			LOGGER.error("【书刊模板分类】根据ID删除出现异常，信息为:"+e.getMessage());
			throw new BookBizException(BookBizException.DB_DML_FAIL, "系统出现异常，请稍后重试!");
		}
		LOGGER.info("【书刊模板分类】根据ID删除,<END>.");
	}*/
	/**
	 * 修改
	 */
	/*@Transactional(rollbackFor=Exception.class)
	@Override
	public void update(BookAssistTemplet bookAssistTemplet, Long partyId) throws BizException {
		LOGGER.info("【书刊模板分类】修改,<START>.[bookAssistTemplet]=" + bookAssistTemplet+",[partyId]:"+partyId);
		Long assistTempletId = bookAssistTemplet.getAssistTempletId();
		checkTempletId(assistTempletId);
		bookAssistTemplet.setLastModifiedUser(partyId);
		try {
			bookAssistTempletDao.update(bookAssistTemplet);
		} catch (Exception e) {
			LOGGER.error("【书刊模板分类】修改出现异常，信息为:"+e.getMessage());
			throw new BookBizException(BookBizException.DB_DML_FAIL, "系统出现异常，请稍后重试!");
		}
		LOGGER.info("【书刊模板分类】 修改,<END>");

	}*/
	/**
	 * 根据ID查询
	 */
	/*@Override
	public BookAssistTemplet getById(Long assistTempletId) throws BizException {
		LOGGER.info("【书刊模板分类】根据ID查询,<START>.[assistTempletId]=" + assistTempletId);
		checkTempletId(assistTempletId);
		BookAssistTemplet bookAssistTemplet = null;
		try {
			bookAssistTempletDao.getById(assistTempletId);
		} catch (Exception e) {
			LOGGER.error("【书刊模板分类】根据ID查询出现异常，信息为:"+e.getMessage());
			throw new BookBizException(BookBizException.DB_DML_FAIL, "系统出现异常，请稍后重试!");
		}
		LOGGER.info("【书刊模板分类】 根据ID查询,<END>");
		return bookAssistTemplet;
	}*/
	/**
	 * 获取所有
	 */
	/*@Override
	public List<BookAssistTemplet> list(List<Long> assistTempletIds) throws BizException {
		LOGGER.info("【书刊模板分类】获取所有,<START>.");
		List<BookAssistTemplet> bookAssistTemplets = null;
		try {
			Map<String, Object> paramMap = Maps.newHashMap();
			if(!ListUtils.isEmpty(assistTempletIds)){
				paramMap.put("assistTempletIds!=null", assistTempletIds);
			}
			bookAssistTemplets = bookAssistTempletDao.listBy(paramMap);
		} catch (Exception e) {
			LOGGER.error("【书刊模板分类】获取所有出现异常，信息为:"+e.getMessage());
			throw new BookBizException(BookBizException.DB_DML_FAIL, "系统出现异常，请稍后重试!");
		}
		LOGGER.info("【书刊模板分类】 获取所有,<END>");
		return bookAssistTemplets;
	}*/
	
	/*public void checkTempletId(Long templetId) throws BizException {
		if (templetId == null || templetId < 1) {
			throw new AppBizException(AppBizException.PARAM_IS_NULL, "模板标识不能为空");
		}
	}
	@Override
	public Map<Long, BookAssistTemplet> mapByIds(List<Long> assistTempletIds) throws BizException {
		List<BookAssistTemplet> bookAssistTemplets = list(assistTempletIds);
		if(ListUtils.isEmpty(bookAssistTemplets)){
			return null;
		}
		Map<Long, BookAssistTemplet> result = bookAssistTemplets.stream()
				.collect(Collectors.toMap(BookAssistTemplet::getAssistTempletId, bookAssistTemplet -> bookAssistTemplet));
		return result;
	}
*/
}
