增加短信引擎配置功能
This commit is contained in:
parent
6cf24fc93e
commit
2c434f8c90
|
|
@ -1,7 +1,13 @@
|
||||||
package com.mdd.admin.controller.setting;
|
package com.mdd.admin.controller.setting;
|
||||||
|
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
import com.mdd.admin.config.aop.Log;
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
import com.mdd.admin.service.setting.ISettingSmsService;
|
||||||
|
import com.mdd.common.core.AjaxResult;
|
||||||
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
|
import javax.annotation.Resource;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 短信设置管理
|
* 短信设置管理
|
||||||
|
|
@ -10,16 +16,46 @@ import org.springframework.web.bind.annotation.RestController;
|
||||||
@RequestMapping("api/setting/sms")
|
@RequestMapping("api/setting/sms")
|
||||||
public class SmsController {
|
public class SmsController {
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
ISettingSmsService iSettingSmsService;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 短信引擎列表
|
||||||
|
*
|
||||||
|
* @author fzr
|
||||||
|
* @return Object
|
||||||
|
*/
|
||||||
|
@GetMapping("/list")
|
||||||
public Object list() {
|
public Object list() {
|
||||||
return null;
|
List<Map<String, Object>> list = iSettingSmsService.list();
|
||||||
|
return AjaxResult.success(list);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Object detail() {
|
/**
|
||||||
return null;
|
* 短信引擎详情
|
||||||
|
*
|
||||||
|
* @author fzr
|
||||||
|
* @param alias 别名
|
||||||
|
* @return Object
|
||||||
|
*/
|
||||||
|
@GetMapping("/detail")
|
||||||
|
public Object detail(String alias) {
|
||||||
|
Map<String, Object> map = iSettingSmsService.detail(alias);
|
||||||
|
return AjaxResult.success(map);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Object save() {
|
/**
|
||||||
return null;
|
* 短信引擎保存
|
||||||
|
*
|
||||||
|
* @author fzr
|
||||||
|
* @param params 参数
|
||||||
|
* @return Object
|
||||||
|
*/
|
||||||
|
@Log(title = "短信引擎保存")
|
||||||
|
@PostMapping("/save")
|
||||||
|
public Object save(@RequestBody Map<String, String> params) {
|
||||||
|
iSettingSmsService.save(params);
|
||||||
|
return AjaxResult.success();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,36 @@
|
||||||
package com.mdd.admin.service.setting;
|
package com.mdd.admin.service.setting;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 短信配置接口类
|
* 短信配置接口类
|
||||||
*/
|
*/
|
||||||
public interface ISettingSmsService {
|
public interface ISettingSmsService {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 短信引擎列表
|
||||||
|
*
|
||||||
|
* @author fzr
|
||||||
|
* @return List<Map<String, Object>>
|
||||||
|
*/
|
||||||
|
List<Map<String, Object>> list();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 短信引擎详情
|
||||||
|
*
|
||||||
|
* @author fzr
|
||||||
|
* @param alias 别名
|
||||||
|
* @return Map<String, Object>
|
||||||
|
*/
|
||||||
|
Map<String, Object> detail(String alias);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 短信引擎保存
|
||||||
|
*
|
||||||
|
* @author fzr
|
||||||
|
* @param params 参数
|
||||||
|
*/
|
||||||
|
void save(Map<String, String> params);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,11 +1,124 @@
|
||||||
package com.mdd.admin.service.setting.impl;
|
package com.mdd.admin.service.setting.impl;
|
||||||
|
|
||||||
|
import com.alibaba.fastjson.JSON;
|
||||||
import com.mdd.admin.service.setting.ISettingSmsService;
|
import com.mdd.admin.service.setting.ISettingSmsService;
|
||||||
|
import com.mdd.common.utils.ConfigUtil;
|
||||||
|
import com.mdd.common.utils.StringUtil;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import java.util.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 短信配置服务实现类
|
* 短信配置服务实现类
|
||||||
*/
|
*/
|
||||||
@Service
|
@Service
|
||||||
public class SettingSmsServiceImpl implements ISettingSmsService {
|
public class SettingSmsServiceImpl implements ISettingSmsService {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 短信引擎列表
|
||||||
|
*
|
||||||
|
* @author fzr
|
||||||
|
* @return List<Map<String, Object>>
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public List<Map<String, Object>> list() {
|
||||||
|
String engine = ConfigUtil.get("sms", "default", "aliyun");
|
||||||
|
List<Map<String, Object>> list = new LinkedList<>();
|
||||||
|
|
||||||
|
Map<String, Object> aliyun = new LinkedHashMap<>();
|
||||||
|
aliyun.put("name", "阿里云短信");
|
||||||
|
aliyun.put("alias", "aliyun");
|
||||||
|
aliyun.put("status", engine.equals("aliyun") ? 1 : 0);
|
||||||
|
list.add(aliyun);
|
||||||
|
|
||||||
|
Map<String, Object> tencent = new LinkedHashMap<>();
|
||||||
|
tencent.put("name", "腾讯云短信");
|
||||||
|
tencent.put("alias", "tencent");
|
||||||
|
tencent.put("status", engine.equals("tencent") ? 1 : 0);
|
||||||
|
list.add(tencent);
|
||||||
|
|
||||||
|
Map<String, Object> huawei = new LinkedHashMap<>();
|
||||||
|
huawei.put("name", "华为云短信");
|
||||||
|
huawei.put("alias", "huawei");
|
||||||
|
huawei.put("status", engine.equals("huawei") ? 1 : 0);
|
||||||
|
list.add(huawei);
|
||||||
|
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 短信引擎详情
|
||||||
|
*
|
||||||
|
* @author fzr
|
||||||
|
* @param alias 别名
|
||||||
|
* @return Map<String, Object>
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public Map<String, Object> detail(String alias) {
|
||||||
|
String engine = ConfigUtil.get("sms", "default", "local");
|
||||||
|
Map<String, String> config = ConfigUtil.getMap("sms", alias);
|
||||||
|
config = StringUtil.isNotNull(config) ? config : Collections.emptyMap();
|
||||||
|
|
||||||
|
Map<String, Object> map = new LinkedHashMap<>();
|
||||||
|
map.put("name", config.getOrDefault("name", ""));
|
||||||
|
map.put("status", engine.equals(alias) ? 1 : 0);
|
||||||
|
map.put("alias", alias);
|
||||||
|
map.put("sign", config.getOrDefault("sign", ""));
|
||||||
|
|
||||||
|
switch (alias) {
|
||||||
|
case "aliyun":
|
||||||
|
map.put("appKey", config.getOrDefault("appKey", ""));
|
||||||
|
map.put("secretKey", config.getOrDefault("secretKey", ""));
|
||||||
|
break;
|
||||||
|
case "tencent":
|
||||||
|
map.put("appId", config.getOrDefault("appId", ""));
|
||||||
|
map.put("secretId", config.getOrDefault("secretId", ""));
|
||||||
|
map.put("secretKey", config.getOrDefault("secretKey", ""));
|
||||||
|
break;
|
||||||
|
case "huawei":
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return map;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 短信引擎保存
|
||||||
|
*
|
||||||
|
* @author fzr
|
||||||
|
* @param params 参数
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void save(Map<String, String> params) {
|
||||||
|
Map<String, String> map = new LinkedHashMap<>();
|
||||||
|
|
||||||
|
switch (params.get("alias")) {
|
||||||
|
case "aliyun":
|
||||||
|
map.put("name", "阿里云短信");
|
||||||
|
map.put("alias", "aliyun");
|
||||||
|
map.put("sign", params.getOrDefault("sign", ""));
|
||||||
|
map.put("appKey", params.getOrDefault("appKey", ""));
|
||||||
|
map.put("secretKey", params.getOrDefault("secretKey", ""));
|
||||||
|
break;
|
||||||
|
case "tencent":
|
||||||
|
System.out.println("来了吗");
|
||||||
|
map.put("name", "腾讯云短信");
|
||||||
|
map.put("alias", "aliyun");
|
||||||
|
map.put("sign", params.getOrDefault("sign", ""));
|
||||||
|
map.put("appId", params.getOrDefault("appId", ""));
|
||||||
|
map.put("secretId", params.getOrDefault("secretId", ""));
|
||||||
|
map.put("secretKey", params.getOrDefault("secretKey", ""));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
ConfigUtil.set("sms", params.get("alias"), JSON.toJSONString(map));
|
||||||
|
|
||||||
|
String engine = ConfigUtil.get("sms", "default", "");
|
||||||
|
if (Integer.parseInt(params.get("status")) == 1) {
|
||||||
|
ConfigUtil.set("sms", "default", params.get("alias"));
|
||||||
|
} else if (engine.equals(params.get("alias")) && Integer.parseInt(params.get("status")) == 0) {
|
||||||
|
ConfigUtil.set("sms", "default", "");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@ import com.alibaba.fastjson.JSON;
|
||||||
import com.baomidou.mybatisplus.core.toolkit.Assert;
|
import com.baomidou.mybatisplus.core.toolkit.Assert;
|
||||||
import com.mdd.admin.service.setting.ISettingStorageService;
|
import com.mdd.admin.service.setting.ISettingStorageService;
|
||||||
import com.mdd.common.utils.ConfigUtil;
|
import com.mdd.common.utils.ConfigUtil;
|
||||||
|
import com.mdd.common.utils.StringUtil;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
@ -67,6 +68,7 @@ public class SettingStorageServiceImpl implements ISettingStorageService {
|
||||||
public Map<String, Object> detail(String alias) {
|
public Map<String, Object> detail(String alias) {
|
||||||
String engine = ConfigUtil.get("storage", "default", "local");
|
String engine = ConfigUtil.get("storage", "default", "local");
|
||||||
Map<String, String> config = ConfigUtil.getMap("storage", alias);
|
Map<String, String> config = ConfigUtil.getMap("storage", alias);
|
||||||
|
config = StringUtil.isNotNull(config) ? config : Collections.emptyMap();
|
||||||
|
|
||||||
Map<String, Object> map = new LinkedHashMap<>();
|
Map<String, Object> map = new LinkedHashMap<>();
|
||||||
map.put("name", config.getOrDefault("name", ""));
|
map.put("name", config.getOrDefault("name", ""));
|
||||||
|
|
@ -96,8 +98,7 @@ public class SettingStorageServiceImpl implements ISettingStorageService {
|
||||||
Assert.notNull(params.get("alias"), "alias参数缺失");
|
Assert.notNull(params.get("alias"), "alias参数缺失");
|
||||||
Assert.notNull(params.get("status"), "status参数缺失");
|
Assert.notNull(params.get("status"), "status参数缺失");
|
||||||
Map<String, String> map = new LinkedHashMap<>();
|
Map<String, String> map = new LinkedHashMap<>();
|
||||||
System.out.println("斤斤计较");
|
|
||||||
System.out.println(params);
|
|
||||||
map.put("name", "本地存储");
|
map.put("name", "本地存储");
|
||||||
if (!params.get("alias").equals("local")) {
|
if (!params.get("alias").equals("local")) {
|
||||||
map.put("bucket", params.getOrDefault("bucket", ""));
|
map.put("bucket", params.getOrDefault("bucket", ""));
|
||||||
|
|
@ -124,7 +125,7 @@ public class SettingStorageServiceImpl implements ISettingStorageService {
|
||||||
if (Integer.parseInt(params.get("status")) == 1) {
|
if (Integer.parseInt(params.get("status")) == 1) {
|
||||||
ConfigUtil.set("storage", "default", params.get("alias"));
|
ConfigUtil.set("storage", "default", params.get("alias"));
|
||||||
} else if (engine.equals(params.get("alias")) && Integer.parseInt(params.get("status")) == 0) {
|
} else if (engine.equals(params.get("alias")) && Integer.parseInt(params.get("status")) == 0) {
|
||||||
ConfigUtil.set("storage", "default", params.get(""));
|
ConfigUtil.set("storage", "default", "");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue