|
|
|
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.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("内容"));
|
|
|
|
}
|
|
|
|
//整合推送
|
|
|
|
@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("内容为空");
|
|
|
|
// }
|
|
|
|
// if (!map.containsKey("eventId")|| StringUtils.isBlank(map.get("eventId").toString())) {
|
|
|
|
// return AjaxResult.error("事件id为空");
|
|
|
|
// }
|
|
|
|
// if (map.get("content").toString().length()>=200){
|
|
|
|
// return AjaxResult.error("内容长度超长");
|
|
|
|
// }
|
|
|
|
// 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("参数错误");
|
|
|
|
}
|
|
|
|
if (map == null ||!map.containsKey("content")|| StringUtils.isBlank(map.get("content").toString())) {
|
|
|
|
return AjaxResult.error("内容为空");
|
|
|
|
}
|
|
|
|
if (!map.containsKey("eventId")|| StringUtils.isBlank(map.get("eventId").toString())) {
|
|
|
|
return AjaxResult.error("事件id为空");
|
|
|
|
}
|
|
|
|
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 = "微信推送失败"; // 初始化为成功状态
|
|
|
|
String message = "短信推送失败"; // 初始化为失败状态
|
|
|
|
for (String type : array) {
|
|
|
|
if ("1".equals(type)) { //短信
|
|
|
|
if (map == null || StringUtils.isBlank(map.get("phone").toString())) {
|
|
|
|
return AjaxResult.error("手机号为空");
|
|
|
|
}
|
|
|
|
String string = map.get("phone").toString();
|
|
|
|
send = msmService.send(string);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if ("2".equals(type)) { //微信
|
|
|
|
JSONArray objects = msmService.wenXinSend(content);
|
|
|
|
data = (Integer) objects.get(0);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (send==true){
|
|
|
|
message = "短信推送成功"; // 如果 send 为 true,则短信推送成功
|
|
|
|
}
|
|
|
|
if (data==0){
|
|
|
|
weiXin = "微信推送成功"; // 如果所有 dateValue 都为0,则微信推送成功
|
|
|
|
}
|
|
|
|
DcEventProcess dcEventProcess = new DcEventProcess();
|
|
|
|
dcEventProcess.setEventId(eventId);
|
|
|
|
dcEventProcess.setSource(1);
|
|
|
|
dcEventProcess.setProcessType(2);
|
|
|
|
String context = "出行信息发布:" + content;
|
|
|
|
dcEventProcess.setContext(context);
|
|
|
|
dcEventProcessService.insertDcEventProcess(dcEventProcess);
|
|
|
|
if ("短信推送成功".equals(message) &&"微信推送成功".equals(weiXin)) {
|
|
|
|
return AjaxResult.success(message +","+ weiXin);
|
|
|
|
} else {
|
|
|
|
return AjaxResult.error(message +","+ weiXin);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|