You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
124 lines
5.5 KiB
124 lines
5.5 KiB
package com.zc.business.controller;
|
|
|
|
import com.alibaba.fastjson.JSONArray;
|
|
import com.ruoyi.common.core.controller.BaseController;
|
|
import com.ruoyi.common.core.domain.AjaxResult;
|
|
import com.zc.business.domain.DcEventProcess;
|
|
import com.zc.business.enums.UniversalEnum;
|
|
import com.zc.business.service.IMsmService;
|
|
import com.zc.business.service.impl.DcEventProcessServiceImpl;
|
|
import org.apache.commons.lang3.StringUtils;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.web.bind.annotation.PostMapping;
|
|
import org.springframework.web.bind.annotation.RequestBody;
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
|
|
import java.util.ArrayList;
|
|
import java.util.HashMap;
|
|
|
|
/**
|
|
* 王思祥
|
|
* 推送业务
|
|
*/
|
|
@RestController
|
|
@RequestMapping("/business/sms")
|
|
public class MsmController extends BaseController {
|
|
@Autowired
|
|
private IMsmService msmService;
|
|
@Autowired
|
|
private DcEventProcessServiceImpl dcEventProcessService;
|
|
|
|
/**
|
|
* 短信推送业务,阿里云短信业务
|
|
*/
|
|
@PostMapping("/push")
|
|
public Boolean alibabaCloudSms(@RequestBody HashMap map)
|
|
{
|
|
String type = map.get("type").toString();
|
|
if (map==null|| StringUtils.isBlank(map.get("phone").toString())){
|
|
return false;
|
|
}
|
|
String string = map.get("phone").toString();
|
|
return msmService.send(string);
|
|
}
|
|
|
|
//调用微信推送
|
|
@PostMapping("/wenXinPush")
|
|
public AjaxResult commandAndDispatch(@RequestBody HashMap map){
|
|
return AjaxResult.success(msmService.wenXinSend(UniversalEnum.CONTENT.getValue()));
|
|
}
|
|
//整合推送
|
|
@PostMapping("/pushAll")
|
|
public AjaxResult pushAll(@RequestBody HashMap map){
|
|
// if (map == null || !map.containsKey("type")||StringUtils.isBlank(map.get("type").toString())) {
|
|
// return AjaxResult.error("参数错误");
|
|
// }
|
|
if (map == null ||!map.containsKey("content")|| StringUtils.isBlank(map.get("content").toString())) {
|
|
return AjaxResult.error(UniversalEnum.CONTENT_IS_EMPTY.getValue());
|
|
}
|
|
if (!map.containsKey("eventId")|| StringUtils.isBlank(map.get("eventId").toString())) {
|
|
return AjaxResult.error(UniversalEnum.THE_EVENT_ID_IS_NULL.getValue());
|
|
}
|
|
if (map.get("content").toString().length()>=UniversalEnum.TWO_HUNDRED.getNumber()){
|
|
return AjaxResult.error(UniversalEnum.THE_CONTENT_IS_TOO_LONG.getValue());
|
|
}
|
|
return msmService.putAll(map);
|
|
//return AjaxResult.error("功能开发中");
|
|
}
|
|
//整合推送(弃用)
|
|
@PostMapping("/pushAllText")
|
|
public AjaxResult pushAllText(@RequestBody HashMap map)
|
|
{
|
|
if (map == null || !map.containsKey("type")||StringUtils.isBlank(map.get("type").toString())) {
|
|
return AjaxResult.error(UniversalEnum.PARAMETER_ERROR.getValue());
|
|
}
|
|
if (map == null ||!map.containsKey("content")|| StringUtils.isBlank(map.get("content").toString())) {
|
|
return AjaxResult.error(UniversalEnum.CONTENT_IS_EMPTY.getValue());
|
|
}
|
|
if (!map.containsKey("eventId")|| StringUtils.isBlank(map.get("eventId").toString())) {
|
|
return AjaxResult.error(UniversalEnum.THE_EVENT_ID_IS_NULL.getValue());
|
|
}
|
|
String eventId = map.get("eventId").toString();//事件id
|
|
String content = map.get("content").toString();//信息内容
|
|
ArrayList<String> array = (ArrayList<String>) map.get("type");
|
|
Boolean send = null;
|
|
Integer data = null;
|
|
String weiXin = UniversalEnum.WECHAT_PUSH_FAILED.getValue(); // 初始化为成功状态
|
|
String message = UniversalEnum.SMS_PUSH_FAILURE.getValue(); // 初始化为失败状态
|
|
for (String type : array) {
|
|
if (UniversalEnum.ONE.getValue().equals(type)) { //短信
|
|
if (map == null || StringUtils.isBlank(map.get("phone").toString())) {
|
|
return AjaxResult.error(UniversalEnum.THE_PHONE_NUMBER_IS_EMPTY.getValue());
|
|
}
|
|
String string = map.get("phone").toString();
|
|
send = msmService.send(string);
|
|
continue;
|
|
}
|
|
if (UniversalEnum.TWO.getValue().equals(type)) { //微信
|
|
JSONArray objects = msmService.wenXinSend(content);
|
|
data = (Integer) objects.get(UniversalEnum.ZERO.getNumber());
|
|
continue;
|
|
}
|
|
}
|
|
if (send){
|
|
message = UniversalEnum.SMS_PUSH_SUCCESSFUL.getValue(); // 如果 send 为 true,则短信推送成功
|
|
}
|
|
if (data==UniversalEnum.ZERO.getNumber()){
|
|
weiXin = UniversalEnum.WECHAT_PUSH_SUCCEEDED.getValue(); // 如果所有 dateValue 都为0,则微信推送成功
|
|
}
|
|
DcEventProcess dcEventProcess = new DcEventProcess();
|
|
dcEventProcess.setEventId(eventId);
|
|
dcEventProcess.setSource(UniversalEnum.ONE.getNumber());
|
|
dcEventProcess.setProcessType(UniversalEnum.TWO.getNumber());
|
|
String context = UniversalEnum.TRAVEL_INFORMATION_RELEASE.getValue() + content;
|
|
dcEventProcess.setContext(context);
|
|
dcEventProcessService.insertDcEventProcess(dcEventProcess);
|
|
if (UniversalEnum.SMS_PUSH_SUCCESSFUL.getValue().equals(message) &&UniversalEnum.WECHAT_PUSH_SUCCEEDED.getValue().equals(weiXin)) {
|
|
return AjaxResult.success(message +UniversalEnum.COMMA.getValue()+ weiXin);
|
|
} else {
|
|
return AjaxResult.error(message +UniversalEnum.COMMA.getValue()+ weiXin);
|
|
}
|
|
}
|
|
|
|
}
|
|
|