/**
 * Copyright 2008-2009. Chongqing Communications Industry Services Co.,Ltd Information Technology Branch. All rights reserved.
 * <a>http://www.crunii.com</a>
 */
package com.crunii.micro.service.sysmgr.service.impl;

import com.crunii.micro.common.constants.CommonConstants;
import com.crunii.micro.common.dto.PageReq;
import com.crunii.micro.common.dto.PageRsp;
import com.crunii.micro.domain.entity.main.TEncryptConfig;
import com.crunii.micro.domain.repo.main.TEncryptConfigRepo;
import com.crunii.micro.service.sysmgr.dto.enc.EncryptConfigC;
import com.crunii.micro.service.sysmgr.dto.enc.EncryptConfigReq;
import com.crunii.micro.service.sysmgr.dto.enc.EncryptConfigU;
import com.crunii.micro.service.sysmgr.jdbc.EncryptConfigJdbcDao;
import com.crunii.micro.service.sysmgr.service.EncryptConfigService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;

/**
 * @author 田平 create 2021/4/30 10:52
 */
@Service
public class EncryptConfigServiceImpl implements EncryptConfigService {

	@Autowired
	private EncryptConfigJdbcDao encryptConfigJdbcDao;

	@Autowired
	private TEncryptConfigRepo tEncryptConfigRepo;

	@Override
	public PageRsp<TEncryptConfig> pageEncryptConfig(PageReq<EncryptConfigReq> req) {
		return encryptConfigJdbcDao.pageEncryptConfig(req);
	}

	@Override
	public void updateEncryptConfig(EncryptConfigU encryptU) {
		TEncryptConfig config = tEncryptConfigRepo.getOne(encryptU.getId());
		BeanUtils.copyProperties(encryptU, config);
		config.setUpdateTime(new Date());
		tEncryptConfigRepo.saveAndFlush(config);
	}

	@Override
	public void createEncryptConfig(EncryptConfigC encryptC) {
		Date curr = new Date();
		TEncryptConfig config = new TEncryptConfig();
		BeanUtils.copyProperties(encryptC, config);
		config.setUpdateTime(curr);
		config.setUpdateTime(curr);
		config.setState(CommonConstants.STATE_VALID);
		tEncryptConfigRepo.saveAndFlush(config);
	}
}
