
package com.tmerclub.cloud.platform.feign;

import com.tmerclub.cloud.api.payment.vo.PaySettlementConfigVO;
import com.tmerclub.cloud.api.platform.feign.ConfigFeignClient;
import com.tmerclub.cloud.api.platform.vo.SysConfigApiVO;
import com.tmerclub.cloud.common.constant.Constant;
import com.tmerclub.cloud.common.response.ServerResponseEntity;
import com.tmerclub.cloud.common.util.BeanUtil;
import com.tmerclub.cloud.common.util.Json;
import com.tmerclub.cloud.platform.model.SysConfig;
import com.tmerclub.cloud.platform.service.SysConfigService;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * @author tmerclub
 * @date 2020/12/30
 */
@DubboService
public class ConfigFeignController implements ConfigFeignClient {

    @Autowired
    private SysConfigService sysConfigService;


    @Override
    public ServerResponseEntity<String> getConfig(String key) {
        return ServerResponseEntity.success(sysConfigService.getValue(key));
    }

    @Override
    public ServerResponseEntity<Integer> getPaySysType() {
        String value = sysConfigService.getValue(Constant.PAY_SETTLEMENT_CONFIG);
        PaySettlementConfigVO paySettlementConfigVO = Json.parseObject(value, PaySettlementConfigVO.class);
        return ServerResponseEntity.success(paySettlementConfigVO.getPaySettlementType());
    }

    @Override
    public void saveOrUpdateSysConfig(SysConfigApiVO sysConfigApiVO) {
        SysConfig sysConfig = BeanUtil.map(sysConfigApiVO, SysConfig.class);
        sysConfigService.saveOrUpdateSysConfig(sysConfig);
    }
}
