From a053811c774ac07340e46561f5d2ab4d892282a0 Mon Sep 17 00:00:00 2001 From: Administrator <1101184511@qq.com> Date: 星期一, 29 七月 2024 02:38:40 +0800 Subject: [PATCH] 渠道功能完善 --- src/main/java/com/taoke/autopay/service/impl/agent/ChannelAgentSharingRatioServiceImpl.java | 90 +++++++++++++++++++++++++++++++++++++++++++- 1 files changed, 87 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/taoke/autopay/service/impl/agent/ChannelAgentSharingRatioServiceImpl.java b/src/main/java/com/taoke/autopay/service/impl/agent/ChannelAgentSharingRatioServiceImpl.java index 518bd5e..c08d683 100644 --- a/src/main/java/com/taoke/autopay/service/impl/agent/ChannelAgentSharingRatioServiceImpl.java +++ b/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,95 @@ */ @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()); + } + 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 = 0; + 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() ); } } -- Gitblit v1.8.0