From 14e3019fb5528f19ce70fade3008ab620e3f4762 Mon Sep 17 00:00:00 2001
From: rentaiming <806181062@qq.com>
Date: 星期三, 31 七月 2024 15:55:22 +0800
Subject: [PATCH] 修改bug
---
ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/CustomConfigServiceImpl.java | 86 +++++++++++++++++++++++++++++++++++++++++++
1 files changed, 86 insertions(+), 0 deletions(-)
diff --git a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/CustomConfigServiceImpl.java b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/CustomConfigServiceImpl.java
index ee30608..a8c1ab7 100644
--- a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/CustomConfigServiceImpl.java
+++ b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/CustomConfigServiceImpl.java
@@ -2,6 +2,8 @@
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.google.common.collect.Lists;
+import com.ruoyi.common.core.exception.ServiceException;
+import com.ruoyi.common.core.utils.StringUtils;
import com.ruoyi.common.core.utils.page.BeanUtils;
import com.ruoyi.system.api.constants.ConfigEnum;
import com.ruoyi.system.api.domain.CustomConfig;
@@ -11,8 +13,11 @@
import com.ruoyi.system.mapper.CustomConfigMapper;
import com.ruoyi.system.service.ICustomConfigService;
import java.math.BigDecimal;
+import java.time.LocalDateTime;
+import java.util.Arrays;
import java.util.List;
import java.util.Optional;
+import java.util.stream.Collectors;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
@@ -179,4 +184,85 @@
}
return dto;
}
+
+ /**
+ * 保存客服电话
+ *
+ * @param phone 客服电话
+ */
+ @Override
+ public void updateServicePhone(String phone) {
+ Optional<CustomConfig> customConfigByKey = getCustomConfigByKey(
+ ConfigEnum.PLATFORM_SERVICE_PHONE.getKey());
+ if (customConfigByKey.isPresent()) {
+ CustomConfig customConfig = customConfigByKey.get();
+ String[] split = customConfig.getConfigValue().split(",");
+ if (split.length > 1) {
+ throw new ServiceException("客户电话最多配置两个");
+ }
+ boolean flag = Arrays.asList(split).contains(phone);
+ if (flag) {
+ throw new ServiceException("客户电话已存在");
+ }
+
+ if (StringUtils.isBlank(customConfig.getConfigValue())) {
+ customConfig.setConfigValue(phone);
+ } else {
+ StringBuilder stringBuilder = new StringBuilder();
+ stringBuilder.append(customConfig.getConfigValue());
+ stringBuilder.append(",");
+ stringBuilder.append(phone);
+ customConfig.setConfigValue(stringBuilder.toString());
+ }
+ customConfig.setUpdateTime(LocalDateTime.now());
+ this.updateById(customConfig);
+ } else {
+ CustomConfig config = new CustomConfig();
+ config.setConfigKey(ConfigEnum.PLATFORM_SERVICE_PHONE.getKey());
+ config.setConfigType(ConfigEnum.PLATFORM_SERVICE_PHONE.getKeyType());
+ config.setConfigName(ConfigEnum.PLATFORM_SERVICE_PHONE.getKeyName());
+ config.setConfigValue(phone);
+ config.setCreateTime(LocalDateTime.now());
+ this.save(config);
+ }
+ }
+
+ /**
+ * 获取客服电话
+ *
+ * @return 客服电话
+ */
+ @Override
+ public String getServicePhone() {
+ Optional<CustomConfig> customConfigByKey = getCustomConfigByKey(
+ ConfigEnum.PLATFORM_SERVICE_PHONE.getKey());
+ return customConfigByKey.map(CustomConfig::getConfigValue).orElse(null);
+ }
+
+ /**
+ * 删除客户电话
+ *
+ * @param phone 客服电话
+ */
+ @Override
+ public void deleteServicePhone(String phone) {
+ Optional<CustomConfig> customConfigByKey = getCustomConfigByKey(
+ ConfigEnum.PLATFORM_SERVICE_PHONE.getKey());
+ if (customConfigByKey.isPresent()) {
+ CustomConfig customConfig = customConfigByKey.get();
+ String configValue = customConfig.getConfigValue();
+ if (StringUtils.isNotBlank(configValue)) {
+ String[] split = configValue.split(",");
+ // 判断当前phone是否存在
+ boolean flag = Arrays.asList(split).contains(phone);
+ if (flag) {
+ // 删除 split 中与phone相同的元素
+ configValue = Arrays.stream(split).filter(s -> !s.equals(phone))
+ .collect(Collectors.joining(","));
+ customConfig.setConfigValue(configValue);
+ this.updateById(customConfig);
+ }
+ }
+ }
+ }
}
--
Gitblit v1.7.1