package com.inkasso.management.statistics.service.impl;

import com.inkasso.adapter.service.KafubaoServiceImpl;
import com.inkasso.adapter.util.BeanUtilsProxy;
import com.inkasso.management.statistics.dao.InterfaceStatisticsDAO;
import com.inkasso.management.statistics.entity.InterfaceStatisticsDO;
import com.inkasso.management.statistics.model.dto.InterfaceStatisticsDTO;
import com.inkasso.management.statistics.model.request.AddInterfaceStatisticsRequest;
import com.inkasso.management.statistics.model.request.EditInterfaceStatisticsRequest;
import com.inkasso.management.statistics.service.InterfaceStatisticsService;
import com.inkasso.adapter.exception.ServiceException;
import com.inkasso.adapter.exception.enums.ExceptionEnum;
import org.springframework.stereotype.Service;

/**
* @author 张超
* @date  2023-08-25
*/
@Service
public class InterfaceStatisticsServiceImpl extends KafubaoServiceImpl<InterfaceStatisticsDAO, InterfaceStatisticsDO,InterfaceStatisticsDTO > implements InterfaceStatisticsService {


    @Override
    public void addInterfaceStatistics(AddInterfaceStatisticsRequest addInterfaceStatisticsRequest) {
      InterfaceStatisticsDO interfaceStatistics = BeanUtilsProxy.copyPropertiesIgnoreNull(addInterfaceStatisticsRequest, InterfaceStatisticsDO.class);
      this.baseMapper.insert(interfaceStatistics);
    }

    @Override
    public void editInterfaceStatistics(EditInterfaceStatisticsRequest editInterfaceStatisticsRequest) {

      InterfaceStatisticsDO interfaceStatistics = super.getById(editInterfaceStatisticsRequest.getId());
      if (interfaceStatistics == null) {
          throw new ServiceException(400, ExceptionEnum.SYSTEM_DATE_ERROR);
      }
      BeanUtilsProxy.copyPropertiesNotIgnoreNull(editInterfaceStatisticsRequest,interfaceStatistics);
      this.updateById(interfaceStatistics);
    }

    @Override
    public InterfaceStatisticsDTO getInterfaceStatisticsDtoById(Long id) {
       InterfaceStatisticsDO interfaceStatistics = super.getById(id);
       InterfaceStatisticsDTO interfaceStatisticsDto = BeanUtilsProxy.copyProperties(interfaceStatistics,InterfaceStatisticsDTO.class);
       return interfaceStatisticsDto;
    }

    @Override
    public void deleteInterfaceStatistics(Long id) {

       this.removeById(id);
    }
}

