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;

/**
 * @description: 业务办理手续费dubbo服务类
 * @author: zhang jing
 * @date: 2023/1/7 15:04
 * @param:
 * @return:
 **/
@DubboService
public class ServiceChargeServiceProvider implements IServiceChargeServiceApi {

    @Autowired
    private IBdServiceChargeService serviceChargeService;

    /**
     * @description: 根据业务类型查询扣款
     * @author: zhang jing
     * @date: 2023/1/7 15:13
     * @param: [serviceChargeDTO]
     * @return: com.hzs.common.core.domain.R<com.hzs.system.config.dto.ServiceChargeDTO>
     **/
    @Override
    public R<ServiceChargeDTO> getServiceChargeByType(ServiceChargeDTO serviceChargeDTO) {
        ServiceChargeDTO dto = serviceChargeService.getServiceChargeByType(serviceChargeDTO);
        if (null == dto) {
            // 如果没有配置业务办理手续费，给一个从现金币扣款为0的
            dto = ServiceChargeDTO.builder()
                    .cost(BigDecimal.ZERO)
                    .pkAccount(1)
                    .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);
    }

}
