admin
2024-09-27 17caebabf7a6a529b7039c71e21e5a324e31ea20
src/main/java/com/taoke/autopay/service/impl/agent/ChannelAgentSharingRatioServiceImpl.java
@@ -1,11 +1,18 @@
package com.taoke.autopay.service.impl.agent;
import com.taoke.autopay.dao.agent.ChannelAgentSharingRatioMapper;
import com.taoke.autopay.entity.OrderChannelEnum;
import com.taoke.autopay.entity.SystemConfigKeyEnum;
import com.taoke.autopay.entity.agent.ChannelAgentSharingRatio;
import com.taoke.autopay.service.SystemConfigService;
import com.taoke.autopay.service.agent.ChannelAgentSharingRatioService;
import com.taoke.autopay.utils.StringUtil;
import net.sf.json.JSONObject;
import org.springframework.stereotype.Service;
import java.util.List;
import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.*;
/**
 * @author hxh
@@ -15,18 +22,96 @@
 */
@Service
public class ChannelAgentSharingRatioServiceImpl implements ChannelAgentSharingRatioService {
    @Resource
    private SystemConfigService systemConfigService;
    @Resource
    private ChannelAgentSharingRatioMapper channelAgentSharingRatioMapper;
    @Override
    public void setShareRatio(ChannelAgentSharingRatio shareRatio) {
        ChannelAgentSharingRatio old = getShareRatio(shareRatio.getAgengId(), shareRatio.getOrderChannel());
        if (old != null) {
            if (shareRatio.getUpdateTime() != null) {
                shareRatio.setUpdateTime(new Date());
            }
            shareRatio.setId(old.getId());
            channelAgentSharingRatioMapper.updateByPrimaryKeySelective(shareRatio);
        } else {
            if (shareRatio.getCreateTime() == null) {
                shareRatio.setCreateTime(new Date());
            }
            channelAgentSharingRatioMapper.insertSelective(shareRatio);
        }
    }
    @Override
    public ChannelAgentSharingRatio getShareRatio(Long agengId, OrderChannelEnum orderChannel) {
        return null;
        ChannelAgentSharingRatioMapper.DaoQuery daoQuery = new ChannelAgentSharingRatioMapper.DaoQuery();
        daoQuery.agengId = agengId;
        daoQuery.orderChannel = orderChannel;
        daoQuery.count = 1;
        List<ChannelAgentSharingRatio> list = channelAgentSharingRatioMapper.list(daoQuery);
        if (list.isEmpty()) {
            return null;
        }
        return list.get(0);
    }
    @Override
    public List<ChannelAgentSharingRatio> getShareRatios(Long agengId) {
        return null;
        ChannelAgentSharingRatioMapper.DaoQuery daoQuery = new ChannelAgentSharingRatioMapper.DaoQuery();
        daoQuery.agengId = agengId;
        daoQuery.count = 1000;
        return channelAgentSharingRatioMapper.list(daoQuery);
    }
    @Override
    public Map<OrderChannelEnum, BigDecimal> getDefaultShareRatio() {
        String value = systemConfigService.getValueCache(SystemConfigKeyEnum.AGENT_ORDER_CHANNEL_SHARE_RATIO);
        if (StringUtil.isNullOrEmpty(value)) {
            return new HashMap<>();
        }
        Map<OrderChannelEnum, BigDecimal> map = new HashMap<>();
        JSONObject data = JSONObject.fromObject(value);
        for (OrderChannelEnum channel : OrderChannelEnum.values()) {
            if (data.optString(channel.name()) != null) {
                map.put(channel, new BigDecimal(data.optString(channel.name())));
            }
        }
        return map;
    }
    @Override
    public Map<OrderChannelEnum, BigDecimal> getShareMoneyMap(Long agengId) {
        List<ChannelAgentSharingRatio> list = getShareRatios(agengId);
        Map<OrderChannelEnum, ChannelAgentSharingRatio> listMap = new HashMap<>();
        for (ChannelAgentSharingRatio c : list) {
            listMap.put(c.getOrderChannel(), c);
        }
        Map<OrderChannelEnum, BigDecimal> defaultMap = getDefaultShareRatio();
        Map<OrderChannelEnum, BigDecimal> map = new HashMap<>();
        for (OrderChannelEnum channel : OrderChannelEnum.values()) {
            if (listMap.containsKey(channel)) {
                map.put(channel, listMap.get(channel).getShareValue());
            } else {
                map.put(channel, defaultMap.getOrDefault(channel, null));
            }
        }
        return map;
    }
    @Override
    public void setDefaultShareRatio(Map<OrderChannelEnum, BigDecimal> defaultShareRatio) {
        JSONObject data = new JSONObject();
        for (OrderChannelEnum key : defaultShareRatio.keySet()) {
            if (defaultShareRatio.get(key) != null) {
                data.put(key.name(), defaultShareRatio.get(key));
            }
        }
        systemConfigService.setValue(SystemConfigKeyEnum.AGENT_ORDER_CHANNEL_SHARE_RATIO,data.toString() );
    }
}