package com.jkcredit.invoice.hub.service.needCharge;

import com.jkcredit.invoice.hub.mapper.NeedChargeMapper;
import com.jkcredit.invoice.hub.model.dto.needCharge.NeedChargeDto;
import com.jkcredit.invoice.hub.model.po.needCharge.NeedChargePo;
import com.jkcredit.invoice.hub.service.base.BaseService;
import com.jkcredit.invoice.hub.spi.lang.exception.ServiceException;
import com.jkcredit.invoice.hub.util.BeanUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Date;

/**
 * @description:
 * @author: xusonglin
 * @create: 2020/1/18 22:21
 * @version: V1.0
 **/
@Slf4j
@Service
public class NeedChargeServiceImpl extends BaseService implements NeedChargeService {
    @Resource
    NeedChargeMapper mapper;

    @Override
    public void saveNeedCharge(NeedChargeDto dto) {
        try {
            NeedChargePo po = new NeedChargePo();
            BeanUtil.copyProperties(po, dto);
            po.setCreateTime(new Date());
            mapper.insert(po);
        } catch (Exception e) {
            log.error("新增需要计费数据失败，失败原因：{}", e.getMessage());
            throw new ServiceException("新增需要计费数据失败");
        }
    }
}
