|
@@ -2,24 +2,29 @@ package com.fuint.module.backendApi.controller;
|
|
|
|
|
|
import com.fuint.common.Constants;
|
|
import com.fuint.common.Constants;
|
|
import com.fuint.common.dto.AccountInfo;
|
|
import com.fuint.common.dto.AccountInfo;
|
|
|
|
+import com.fuint.common.enums.SettingTypeEnum;
|
|
|
|
+import com.fuint.common.enums.SmsSettingEnum;
|
|
|
|
+import com.fuint.common.enums.YesOrNoEnum;
|
|
import com.fuint.common.service.SendSmsService;
|
|
import com.fuint.common.service.SendSmsService;
|
|
|
|
+import com.fuint.common.service.SettingService;
|
|
import com.fuint.common.util.TokenUtil;
|
|
import com.fuint.common.util.TokenUtil;
|
|
import com.fuint.framework.exception.BusinessCheckException;
|
|
import com.fuint.framework.exception.BusinessCheckException;
|
|
import com.fuint.framework.pagination.PaginationRequest;
|
|
import com.fuint.framework.pagination.PaginationRequest;
|
|
import com.fuint.framework.pagination.PaginationResponse;
|
|
import com.fuint.framework.pagination.PaginationResponse;
|
|
import com.fuint.framework.web.BaseController;
|
|
import com.fuint.framework.web.BaseController;
|
|
import com.fuint.framework.web.ResponseObject;
|
|
import com.fuint.framework.web.ResponseObject;
|
|
|
|
+import com.fuint.repository.model.MtSetting;
|
|
import com.fuint.repository.model.MtSmsSendedLog;
|
|
import com.fuint.repository.model.MtSmsSendedLog;
|
|
import com.fuint.utils.StringUtil;
|
|
import com.fuint.utils.StringUtil;
|
|
import io.swagger.annotations.Api;
|
|
import io.swagger.annotations.Api;
|
|
import io.swagger.annotations.ApiOperation;
|
|
import io.swagger.annotations.ApiOperation;
|
|
import lombok.AllArgsConstructor;
|
|
import lombok.AllArgsConstructor;
|
|
-import org.springframework.web.bind.annotation.CrossOrigin;
|
|
|
|
-import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
|
-import org.springframework.web.bind.annotation.RequestMethod;
|
|
|
|
-import org.springframework.web.bind.annotation.RestController;
|
|
|
|
|
|
+import org.springframework.security.access.prepost.PreAuthorize;
|
|
|
|
+import org.springframework.web.bind.annotation.*;
|
|
import javax.servlet.http.HttpServletRequest;
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
|
+import java.util.Date;
|
|
import java.util.HashMap;
|
|
import java.util.HashMap;
|
|
|
|
+import java.util.List;
|
|
import java.util.Map;
|
|
import java.util.Map;
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -39,6 +44,11 @@ public class BackendSmsController extends BaseController {
|
|
*/
|
|
*/
|
|
private SendSmsService sendSmsService;
|
|
private SendSmsService sendSmsService;
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
+ * 配置服务接口
|
|
|
|
+ * */
|
|
|
|
+ private SettingService settingService;
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* 查询已发短信列表
|
|
* 查询已发短信列表
|
|
*
|
|
*
|
|
@@ -81,4 +91,98 @@ public class BackendSmsController extends BaseController {
|
|
|
|
|
|
return getSuccessResult(result);
|
|
return getSuccessResult(result);
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 获取短信设置
|
|
|
|
+ *
|
|
|
|
+ * @param request
|
|
|
|
+ * @return
|
|
|
|
+ */
|
|
|
|
+ @ApiOperation(value = "获取短信设置")
|
|
|
|
+ @RequestMapping(value = "/setting", method = RequestMethod.GET)
|
|
|
|
+ @CrossOrigin
|
|
|
|
+ @PreAuthorize("@pms.hasPermission('smsTemplate:edit')")
|
|
|
|
+ public ResponseObject setting(HttpServletRequest request) throws BusinessCheckException {
|
|
|
|
+ String token = request.getHeader("Access-Token");
|
|
|
|
+ AccountInfo accountInfo = TokenUtil.getAccountInfoByToken(token);
|
|
|
|
+ if (accountInfo == null) {
|
|
|
|
+ return getFailureResult(1001, "请先登录");
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ List<MtSetting> settingList = settingService.getSettingList(accountInfo.getMerchantId(), SettingTypeEnum.SMS_CONFIG.getKey());
|
|
|
|
+
|
|
|
|
+ String isClose = "";
|
|
|
|
+ String accessKeyId = YesOrNoEnum.FALSE.getKey();
|
|
|
|
+ String accessKeySecret = YesOrNoEnum.FALSE.getKey();
|
|
|
|
+ String signName = YesOrNoEnum.FALSE.getKey();
|
|
|
|
+ for (MtSetting setting : settingList) {
|
|
|
|
+ if (StringUtil.isNotEmpty(setting.getValue())) {
|
|
|
|
+ if (setting.getName().equals(SmsSettingEnum.IS_CLOSE.getKey())) {
|
|
|
|
+ isClose = setting.getValue();
|
|
|
|
+ } else if (setting.getName().equals(SmsSettingEnum.ACCESS_KEY_ID.getKey())) {
|
|
|
|
+ accessKeyId = setting.getValue();
|
|
|
|
+ } else if (setting.getName().equals(SmsSettingEnum.ACCESS_KEY_SECRET.getKey())) {
|
|
|
|
+ accessKeySecret = setting.getValue();
|
|
|
|
+ } else if (setting.getName().equals(SmsSettingEnum.SIGN_NAME.getKey())) {
|
|
|
|
+ signName = setting.getValue();
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ Map<String, Object> result = new HashMap<>();
|
|
|
|
+ result.put("isClose", isClose);
|
|
|
|
+ result.put("accessKeyId", accessKeyId);
|
|
|
|
+ result.put("accessKeySecret", accessKeySecret);
|
|
|
|
+ result.put("signName", signName);
|
|
|
|
+
|
|
|
|
+ return getSuccessResult(result);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 保存短信设置
|
|
|
|
+ *
|
|
|
|
+ * @param request HttpServletRequest对象
|
|
|
|
+ * @return
|
|
|
|
+ */
|
|
|
|
+ @ApiOperation(value = "保存短信设置")
|
|
|
|
+ @RequestMapping(value = "/saveSetting", method = RequestMethod.POST)
|
|
|
|
+ @CrossOrigin
|
|
|
|
+ @PreAuthorize("@pms.hasPermission('smsTemplate:edit')")
|
|
|
|
+ public ResponseObject saveSetting(HttpServletRequest request, @RequestBody Map<String, Object> param) throws BusinessCheckException {
|
|
|
|
+ String token = request.getHeader("Access-Token");
|
|
|
|
+ String isClose = param.get("isClose") != null ? param.get("isClose").toString() : null;
|
|
|
|
+ String accessKeyId = param.get("accessKeyId") != null ? param.get("accessKeyId").toString() : null;
|
|
|
|
+ String accessKeySecret = param.get("accessKeySecret") != null ? param.get("accessKeySecret").toString() : null;
|
|
|
|
+ String signName = param.get("signName") != null ? param.get("signName").toString() : null;
|
|
|
|
+
|
|
|
|
+ AccountInfo accountInfo = TokenUtil.getAccountInfoByToken(token);
|
|
|
|
+ if (accountInfo == null) {
|
|
|
|
+ return getFailureResult(1001, "请先登录");
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ SmsSettingEnum[] settingList = SmsSettingEnum.values();
|
|
|
|
+ for (SmsSettingEnum setting : settingList) {
|
|
|
|
+ MtSetting mtSetting = new MtSetting();
|
|
|
|
+ mtSetting.setType(SettingTypeEnum.SMS_CONFIG.getKey());
|
|
|
|
+ mtSetting.setName(setting.getKey());
|
|
|
|
+ if (setting.getKey().equals(SmsSettingEnum.IS_CLOSE.getKey())) {
|
|
|
|
+ mtSetting.setValue(isClose);
|
|
|
|
+ } else if (setting.getKey().equals(SmsSettingEnum.ACCESS_KEY_ID.getKey())) {
|
|
|
|
+ mtSetting.setValue(accessKeyId);
|
|
|
|
+ } else if (setting.getKey().equals(SmsSettingEnum.ACCESS_KEY_SECRET.getKey())) {
|
|
|
|
+ mtSetting.setValue(accessKeySecret);
|
|
|
|
+ } else if (setting.getKey().equals(SmsSettingEnum.SIGN_NAME.getKey())) {
|
|
|
|
+ mtSetting.setValue(signName);
|
|
|
|
+ }
|
|
|
|
+ mtSetting.setDescription(setting.getValue());
|
|
|
|
+ mtSetting.setOperator(accountInfo.getAccountName());
|
|
|
|
+ mtSetting.setUpdateTime(new Date());
|
|
|
|
+ mtSetting.setMerchantId(accountInfo.getMerchantId());
|
|
|
|
+ mtSetting.setStoreId(0);
|
|
|
|
+ settingService.saveSetting(mtSetting);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return getSuccessResult(true);
|
|
|
|
+ }
|
|
|
|
+
|
|
}
|
|
}
|