package com.hzs.system.config.provider;

import com.hzs.common.core.domain.R;
import com.hzs.system.config.IServiceChargeServiceApi;
import com.hzs.system.config.dto.ServiceChargeDTO;
import com.hzs.system.config.service.IBdServiceChargeService;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;

/**
 * 业务办理手续费dubbo服务类
 **/
@DubboService
public class ServiceChargeServiceProvider implements IServiceChargeServiceApi {

    @Autowired
    private IBdServiceChargeService serviceChargeService;

    @Override
    public R<ServiceChargeDTO> getServiceChargeByType(ServiceChargeDTO serviceChargeDTO) {
        ServiceChargeDTO dto = serviceChargeService.getServiceChargeByType(serviceChargeDTO);
        if (dto == null) {
            dto = ServiceChargeDTO.builder()
                    .pkAccount(0)
                    .cost(BigDecimal.ZERO)
                    .build();
        }
        return R.ok(dto);
    }

    @Override
    public R<List<ServiceChargeDTO>> getServiceChargeByType(List<ServiceChargeDTO> serviceChargeDTOList) {
        List<ServiceChargeDTO> resultList = new ArrayList<>();
        for (ServiceChargeDTO serviceChargeDTO : serviceChargeDTOList) {
            ServiceChargeDTO dto = serviceChargeService.getServiceChargeByType(serviceChargeDTO);
            if (null != dto) {
                resultList.add(dto);
            }
        }
        return R.ok(resultList);
    }

}
