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 javax.annotation.Resource;
|
import java.math.BigDecimal;
|
import java.util.*;
|
|
/**
|
* @author hxh
|
* @title: ChannelAgentSharingRatioServiceImpl
|
* @description: TODO
|
* @date 2024/7/26 0:38
|
*/
|
@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) {
|
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) {
|
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() );
|
}
|
}
|