package com.yn.bftl.thirdparty.modules.business.service.impl;

import com.yn.bftl.common.modules.configuration.entity.ErpLogger;
import com.yn.bftl.thirdparty.modules.business.dto.ErpLoggerCreateDTO;
import com.yn.bftl.thirdparty.modules.business.repository.ErpLoggerRepository;
import com.yn.bftl.thirdparty.modules.business.service.ErpLoggerService;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;

/**
 * ERP日志服务实现类
 *
 * @author huabiao
 * @create 2022/8/15  17:27
 **/
@Service
public class ErpLoggerServiceImpl implements ErpLoggerService {

    @Resource
    private ErpLoggerRepository erpLoggerRepository;

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void createErpLogger(ErpLoggerCreateDTO erpLoggerCreateDTO) {
        ErpLogger erpLogger = new ErpLogger();
        BeanUtils.copyProperties(erpLoggerCreateDTO, erpLogger);
        if (erpLoggerCreateDTO.getErpAccountSet() != null) {
            erpLogger.setCompany(erpLoggerCreateDTO.getErpAccountSet().getCompany());
            erpLogger.setErpParameters(erpLoggerCreateDTO.getErpAccountSet().toJson());
        }
        erpLoggerRepository.save(erpLogger);
    }
}
