package com.dhcc.finance.main.service.impl;

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

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Service;

import com.dhcc.common.constant.SysConstants;
import com.dhcc.common.constant.SysStatusCode;
import com.dhcc.common.model.CurrencyMeta;
import com.dhcc.common.model.SysUserInfo;
import com.dhcc.common.model.response.RestfulResponse;
import com.dhcc.common.util.CacheDataUtil;
import com.dhcc.common.util.SnowflakeIdWorker;
import com.dhcc.finance.constant.FinanceDictConsts;
import com.dhcc.finance.main.dao.CwBdVouchtempFMapper;
import com.dhcc.finance.main.domain.CwBdVouchtempF;
import com.dhcc.finance.main.service.CwBdVouchtempFService;
import com.dhcc.finance.util.MetaDataUtil;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;

import brave.Tracer;

/**
 * 功能描述：凭证模板分录辅助配置实现类
 * @author dml
 * @date 2019年3月27日 下午2:59:18
 * @修改日志：
 */
@Service
public class CwBdVouchtempFServiceImpl implements CwBdVouchtempFService{
	
	@Autowired
	private Tracer tracer;
	
	@Autowired
	private StringRedisTemplate stringRedisTemplate;
	
	@Autowired
	CwBdVouchtempFMapper cwBdVouchtempFMapper;

	/*
	 * (非 Javadoc)  
	 * Title: searchCwBdVouchtempFAllData 
	 * Description:查询全部凭证模板分录辅助配置
	 * @param pageNum
	 * @param pageSize
	 * @param navigatePages
	 * @return  
	 * @see com.dhcc.finance.main.service.CwBdVouchtempFService#searchCwBdVouchtempFAllData(int, int, int)    
	 * @author dml
	 * @date 2019年3月27日 下午3:03:32
	 * @修改日志：
	 */
	@Override
	public RestfulResponse<PageInfo<CwBdVouchtempF>, CurrencyMeta> searchCwBdVouchtempFAllData(int pageNum,
			int pageSize, int navigatePages,String pkVouchtempB) {
		PageHelper.startPage(pageNum, pageSize,"ASSORDER");
		CwBdVouchtempF cwBdVouchtempF = new CwBdVouchtempF();
		cwBdVouchtempF.setPkVouchtempB(pkVouchtempB);
		List<CwBdVouchtempF> listCwBdVouchtempF = cwBdVouchtempFMapper.searchCwBdVouchtempF(cwBdVouchtempF);
		PageInfo<CwBdVouchtempF> pageInfo = new PageInfo<>(listCwBdVouchtempF, navigatePages);
		return new RestfulResponse<PageInfo<CwBdVouchtempF>, CurrencyMeta>(SysConstants.CODE.SUCCESS,SysConstants.DEFAULT_MESSAGE.OPERATION_SUCCESS,pageInfo,MetaDataUtil.getMeta(tracer,SysStatusCode.OPERATION_SUCCESS));
	}

	/*
	 * (非 Javadoc)  
	 * Title: addCwBdVouchtempF 
	 * Description:新增凭证模板分录辅助配置
	 * @param cwBdVouchtempF
	 * @return  
	 * @see com.dhcc.finance.main.service.CwBdVouchtempFService#addCwBdVouchtempF(com.dhcc.finance.main.domain.CwBdVouchtempF)    
	 * @author dml
	 * @date 2019年3月27日 下午3:03:37
	 * @修改日志：
	 */
	@Override
	public RestfulResponse<Object, CurrencyMeta> addCwBdVouchtempF(CwBdVouchtempF cwBdVouchtempF) {
		SysUserInfo sysUserInfo = CacheDataUtil.<SysUserInfo>getCacheBean(stringRedisTemplate, SysConstants.REDIS_KEY_PREFIX.SYS_USER_INFO, SysUserInfo.class);
		if (sysUserInfo != null) {
			cwBdVouchtempF.setCreateUser(sysUserInfo.getUserId());
		}
		cwBdVouchtempF.setCreateTime(new Date());
		cwBdVouchtempF.setUseState(FinanceDictConsts.Syzt.EFFECTIVE);
		cwBdVouchtempF.setPkVouchtempF(SnowflakeIdWorker.getInstance().nextIdString());
		cwBdVouchtempFMapper.insert(cwBdVouchtempF);
		return new RestfulResponse<Object, CurrencyMeta>(SysConstants.CODE.SUCCESS,SysConstants.DEFAULT_MESSAGE.OPERATION_SUCCESS,MetaDataUtil.getMeta(tracer,SysStatusCode.OPERATION_SUCCESS));
	}

	/*
	 * (非 Javadoc)  
	 * Title: updateCwBdVouchtempFByPk 
	 * Description:通过主键修改凭证模板分录辅助配置
	 * @param cwBdVouchtempF
	 * @return  
	 * @see com.dhcc.finance.main.service.CwBdVouchtempFService#updateCwBdVouchtempFByPk(com.dhcc.finance.main.domain.CwBdVouchtempF)    
	 * @author dml
	 * @date 2019年3月27日 下午3:03:40
	 * @修改日志：
	 */
	@Override
	public RestfulResponse<Object, CurrencyMeta> updateCwBdVouchtempFByPk(CwBdVouchtempF cwBdVouchtempF) {
		SysUserInfo sysUserInfo = CacheDataUtil.<SysUserInfo>getCacheBean(stringRedisTemplate, SysConstants.REDIS_KEY_PREFIX.SYS_USER_INFO, SysUserInfo.class);
		if (sysUserInfo != null) {
			cwBdVouchtempF.setUpdateUser(sysUserInfo.getUserId());
		}
		cwBdVouchtempF.setUpdateTime(new Date());
		cwBdVouchtempFMapper.updateByPrimaryKeySelective(cwBdVouchtempF);
		return new RestfulResponse<Object, CurrencyMeta>(SysConstants.CODE.SUCCESS,SysConstants.DEFAULT_MESSAGE.OPERATION_SUCCESS,MetaDataUtil.getMeta(tracer,SysStatusCode.OPERATION_SUCCESS));
	}

	/*
	 * (非 Javadoc)  
	 * Title: deleteCwBdVouchtempFByPk 
	 * Description:逻辑删除凭证模板分录辅助配置
	 * @param pkVouchtempF
	 * @return  
	 * @see com.dhcc.finance.main.service.CwBdVouchtempFService#deleteCwBdVouchtempFByPk(java.lang.String)    
	 * @author dml
	 * @date 2019年3月27日 下午3:03:44
	 * @修改日志：
	 */
	@Override
	public RestfulResponse<Object, CurrencyMeta> deleteCwBdVouchtempFByPk(String pkVouchtempF) {
		CwBdVouchtempF cwBdVouchtempF = new CwBdVouchtempF();
		SysUserInfo sysUserInfo = CacheDataUtil.<SysUserInfo>getCacheBean(stringRedisTemplate, SysConstants.REDIS_KEY_PREFIX.SYS_USER_INFO, SysUserInfo.class);
		if (sysUserInfo != null) {
			cwBdVouchtempF.setUpdateUser(sysUserInfo.getUserId());
		}
		cwBdVouchtempF.setUpdateTime(new Date());
		cwBdVouchtempF.setUseState(FinanceDictConsts.Syzt.INVALID);
		cwBdVouchtempF.setPkVouchtempF(pkVouchtempF);
		cwBdVouchtempFMapper.updateByPrimaryKeySelective(cwBdVouchtempF);
		return new RestfulResponse<Object, CurrencyMeta>(SysConstants.CODE.SUCCESS,SysConstants.DEFAULT_MESSAGE.OPERATION_SUCCESS,MetaDataUtil.getMeta(tracer,SysStatusCode.OPERATION_SUCCESS));
	}

}
