feat: 增加短信发送功能接口
parent
0a90b90d0d
commit
c4bea3caa6
@ -0,0 +1,34 @@
|
|||||||
|
package com.shxy.xymanager_admin.controller;
|
||||||
|
|
||||||
|
import com.shxy.xymanager_common.annotation.Log;
|
||||||
|
import com.shxy.xymanager_common.base.BaseController;
|
||||||
|
import com.shxy.xymanager_common.base.ResponseReult;
|
||||||
|
import com.shxy.xymanager_common.model.SmsModel;
|
||||||
|
import com.shxy.xymanager_service.service.SmsService;
|
||||||
|
import io.swagger.annotations.Api;
|
||||||
|
import io.swagger.annotations.ApiOperation;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.validation.annotation.Validated;
|
||||||
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
|
import javax.annotation.Resource;
|
||||||
|
|
||||||
|
@RestController
|
||||||
|
@Api(tags = {"短信相关接口"})
|
||||||
|
@RequestMapping("sms")
|
||||||
|
@Slf4j
|
||||||
|
public class SmsController extends BaseController {
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
SmsService service;
|
||||||
|
|
||||||
|
@PostMapping("send")
|
||||||
|
@ApiOperation("发送短信")
|
||||||
|
@Log(title = "发送短信", type = "发送")
|
||||||
|
public ResponseReult<String> send(@Validated @RequestBody SmsModel model) {
|
||||||
|
service.sendSms(model);
|
||||||
|
return ResponseReult.success("OK");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,15 @@
|
|||||||
|
package com.shxy.xymanager_common.model;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import javax.validation.constraints.NotBlank;
|
||||||
|
import javax.validation.constraints.NotNull;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class SmsModel {
|
||||||
|
|
||||||
|
@NotNull(message = "termId不能为空")
|
||||||
|
private Integer termId;
|
||||||
|
@NotBlank(message = "content不能为空")
|
||||||
|
private String content;
|
||||||
|
}
|
@ -0,0 +1,24 @@
|
|||||||
|
package com.shxy.xymanager_common.sms;
|
||||||
|
|
||||||
|
import com.shxy.xymanager_common.constant.Constants;
|
||||||
|
import com.shxy.xymanager_common.sms.dahan.DahanApi;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import javax.annotation.Resource;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
@Slf4j
|
||||||
|
public class SmsAdapter {
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
DahanApi dahanApi;
|
||||||
|
|
||||||
|
public void sendSms(Integer type, String iccid, String content) {
|
||||||
|
if (Constants.NetType_Dahan.equals(type)) {
|
||||||
|
dahanApi.sendSms(iccid, content);
|
||||||
|
} else if (Constants.NetType_Rabchaser.equals(type)) {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -1,4 +1,4 @@
|
|||||||
package com.shxy.xymanager_framework.sms.dahan;
|
package com.shxy.xymanager_common.sms.dahan;
|
||||||
|
|
||||||
import com.shxy.xymanager_common.exception.ApiException;
|
import com.shxy.xymanager_common.exception.ApiException;
|
||||||
import com.shxy.xymanager_common.util.DigestUtils;
|
import com.shxy.xymanager_common.util.DigestUtils;
|
@ -1,19 +0,0 @@
|
|||||||
package com.shxy.xymanager_framework.sms;
|
|
||||||
|
|
||||||
import com.shxy.xymanager_framework.sms.dahan.DahanApi;
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
|
||||||
import org.springframework.stereotype.Service;
|
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
|
||||||
|
|
||||||
@Service
|
|
||||||
@Slf4j
|
|
||||||
public class SmsAdapter {
|
|
||||||
|
|
||||||
@Resource
|
|
||||||
DahanApi dahanApi;
|
|
||||||
|
|
||||||
public void sendSms(Integer type, String iccid, String content) {
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
@ -0,0 +1,43 @@
|
|||||||
|
package com.shxy.xymanager_service.impl;
|
||||||
|
|
||||||
|
import com.shxy.xymanager_common.constant.Constants;
|
||||||
|
import com.shxy.xymanager_common.entity.Terminals;
|
||||||
|
import com.shxy.xymanager_common.exception.ApiException;
|
||||||
|
import com.shxy.xymanager_common.model.SmsModel;
|
||||||
|
import com.shxy.xymanager_common.sms.SmsAdapter;
|
||||||
|
import com.shxy.xymanager_service.service.*;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
|
import javax.annotation.Resource;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
@Slf4j
|
||||||
|
@Transactional(rollbackFor = Exception.class)
|
||||||
|
public class SmsServiceImpl implements SmsService {
|
||||||
|
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
NewCacheService newCacheService;
|
||||||
|
@Resource
|
||||||
|
SmsAdapter smsAdapter;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void sendSms(SmsModel model) {
|
||||||
|
Terminals term = newCacheService.getTerminal(model.getTermId());
|
||||||
|
if (term == null) {
|
||||||
|
throw new ApiException("该装置不存在");
|
||||||
|
}
|
||||||
|
if (StringUtils.isBlank(term.getIccid())) {
|
||||||
|
throw new ApiException("该装置缺少iccid");
|
||||||
|
}
|
||||||
|
if (Constants.NetType_Dahan.equals(term.getNetType()) ||
|
||||||
|
Constants.NetType_Rabchaser.equals(term.getNetType())) {
|
||||||
|
smsAdapter.sendSms(term.getNetType(), term.getIccid(), model.getContent());
|
||||||
|
} else {
|
||||||
|
throw new ApiException("该装置的网络运营商类型不正确");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,9 @@
|
|||||||
|
package com.shxy.xymanager_service.service;
|
||||||
|
|
||||||
|
import com.shxy.xymanager_common.model.SmsModel;
|
||||||
|
|
||||||
|
|
||||||
|
public interface SmsService {
|
||||||
|
|
||||||
|
void sendSms(SmsModel model);
|
||||||
|
}
|
Loading…
Reference in New Issue