From 56eba8e75bf073cd1c1a60514e35f896ef86faca Mon Sep 17 00:00:00 2001
From: wangsixiang <2970484253@qq.com>
Date: Fri, 12 Apr 2024 16:13:34 +0800
Subject: [PATCH] =?UTF-8?q?=E5=BE=AE=E4=BF=A1=E6=8E=A8=E9=80=81=EF=BC=8C?=
=?UTF-8?q?=E7=9F=AD=E4=BF=A1=E6=8E=A8=E9=80=81=EF=BC=8C=E4=BA=BA=E5=91=98?=
=?UTF-8?q?=E7=B1=BB=E5=9E=8B=EF=BC=8Chttp=E5=B7=A5=E5=85=B7=E7=B1=BB?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
zc-business/pom.xml | 12 ++
.../controller/DcWarningController.java | 24 ++-
.../zc/business/controller/MsmController.java | 38 ++++
.../com/zc/business/domain/DcEmployees.java | 2 +-
.../zc/business/mapper/DcWarningMapper.java | 12 ++
.../business/service/IDcWarningService.java | 2 +
.../com/zc/business/service/IMsmService.java | 21 ++
.../service/impl/DcWarningServiceImpl.java | 38 +++-
.../business/service/impl/MsmServiceImpl.java | 201 ++++++++++++++++++
.../java/com/zc/business/utils/HttpUtil.java | 83 ++++++++
.../mapper/business/DcEmployeesMapper.xml | 2 +-
.../mapper/business/DcWarningMapper.xml | 18 ++
12 files changed, 444 insertions(+), 9 deletions(-)
create mode 100644 zc-business/src/main/java/com/zc/business/controller/MsmController.java
create mode 100644 zc-business/src/main/java/com/zc/business/service/IMsmService.java
create mode 100644 zc-business/src/main/java/com/zc/business/service/impl/MsmServiceImpl.java
create mode 100644 zc-business/src/main/java/com/zc/business/utils/HttpUtil.java
diff --git a/zc-business/pom.xml b/zc-business/pom.xml
index 6b870a73..6f82f0b0 100644
--- a/zc-business/pom.xml
+++ b/zc-business/pom.xml
@@ -71,6 +71,18 @@
poi-tl
1.9.1
+
+
+ com.aliyun
+ aliyun-java-sdk-core
+ 4.6.3
+
+
+
+ com.aliyun
+ aliyun-java-sdk-dysmsapi
+ 2.2.1
+
com.zc
diff --git a/zc-business/src/main/java/com/zc/business/controller/DcWarningController.java b/zc-business/src/main/java/com/zc/business/controller/DcWarningController.java
index c1c34e59..a102cdca 100644
--- a/zc-business/src/main/java/com/zc/business/controller/DcWarningController.java
+++ b/zc-business/src/main/java/com/zc/business/controller/DcWarningController.java
@@ -1,5 +1,6 @@
package com.zc.business.controller;
+import com.ruoyi.common.utils.spring.SpringUtils;
import com.ruoyi.common.utils.uuid.IdUtils;
import com.zc.business.domain.DcWarningBatchConvert;
import com.zc.business.service.IDcWarningService;
@@ -10,12 +11,16 @@ import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.zc.business.domain.DcWarning;
+import com.zc.business.service.IDeviceService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.scheduling.annotation.EnableScheduling;
+import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.security.access.prepost.PreAuthorize;
+import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletResponse;
@@ -29,6 +34,7 @@ import java.util.List;
* @date 2024-01-26
*/
@Api(tags = "感知事件")
+@Component
@RestController
@RequestMapping("/business/warning")
public class DcWarningController extends BaseController
@@ -36,6 +42,11 @@ public class DcWarningController extends BaseController
@Autowired
private IDcWarningService dcWarningService;
+ //定时任务,定时结束部分事件
+ public void updateEndSection(){
+ IDcWarningService ben = SpringUtils.getBean(IDcWarningService.class);
+ ben.updateEndSection();
+ }
/**
* 查询预警信息列表
*/
@@ -136,9 +147,14 @@ public class DcWarningController extends BaseController
return dcWarningService.batchConvert(dcWarningBatchConvert);
}
- //定时任务,定时结束部分事件
- @PostMapping("/endSection")
- public AjaxResult updateEndSection(){
- return toAjax(dcWarningService.updateEndSection());
+
+ //指挥调度
+ @PostMapping("/commandAndDispatch")
+ public AjaxResult commandAndDispatch(@RequestBody DcWarning dcWarning){
+ if (StringUtils.isBlank(dcWarning.getStakeMark())){
+ return AjaxResult.error("参数错误");
+ }
+ return (dcWarningService.commandAndDispatch(dcWarning));
}
+
}
diff --git a/zc-business/src/main/java/com/zc/business/controller/MsmController.java b/zc-business/src/main/java/com/zc/business/controller/MsmController.java
new file mode 100644
index 00000000..128bd52f
--- /dev/null
+++ b/zc-business/src/main/java/com/zc/business/controller/MsmController.java
@@ -0,0 +1,38 @@
+package com.zc.business.controller;
+
+import com.ruoyi.common.core.controller.BaseController;
+import com.ruoyi.common.core.domain.AjaxResult;
+import com.zc.business.domain.DcWarning;
+import com.zc.business.service.IMsmService;
+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.HashMap;
+
+/**
+ * 王思祥
+ * 推送业务
+ */
+@RestController
+@RequestMapping("/business/sms")
+public class MsmController extends BaseController {
+ @Autowired
+ private IMsmService msmService;
+
+ /**
+ * 短信推送业务,阿里云短信业务
+ */
+ @PostMapping("/push")
+ public Boolean alibabaCloudSms()
+ {
+ return msmService.send("19806114248");
+ }
+ //调用微信推送
+ @PostMapping("/wenXinPush")
+ public AjaxResult commandAndDispatch(){
+ return AjaxResult.success(msmService.wenXinSend("wx9ee0e3babfd8d2af","de2ecb80b30d63135918ba3ae6ffb711"));
+ }
+}
\ No newline at end of file
diff --git a/zc-business/src/main/java/com/zc/business/domain/DcEmployees.java b/zc-business/src/main/java/com/zc/business/domain/DcEmployees.java
index ef714391..ef2635f2 100644
--- a/zc-business/src/main/java/com/zc/business/domain/DcEmployees.java
+++ b/zc-business/src/main/java/com/zc/business/domain/DcEmployees.java
@@ -50,7 +50,7 @@ public class DcEmployees extends BaseEntity
private Long parentId;
//人员类型1为路管人员2为应急人员
- @Excel(name = "人员类型 1-路管人员 2-应急人员")
+ @Excel(name = "人员类型 1-路管人员 2-交警人员")
private Long employeesType;
//类型参数
private String type;
diff --git a/zc-business/src/main/java/com/zc/business/mapper/DcWarningMapper.java b/zc-business/src/main/java/com/zc/business/mapper/DcWarningMapper.java
index 322a0dd7..174f24dd 100644
--- a/zc-business/src/main/java/com/zc/business/mapper/DcWarningMapper.java
+++ b/zc-business/src/main/java/com/zc/business/mapper/DcWarningMapper.java
@@ -5,9 +5,11 @@ import java.util.HashMap;
import java.util.List;
import cn.hutool.core.lang.hash.Hash;
+import com.zc.business.domain.DcRoadSection;
import com.zc.business.domain.DcWaringStrategy;
import com.zc.business.domain.DcWarning;
import org.apache.ibatis.annotations.Param;
+import org.springframework.security.core.parameters.P;
/**
* 预警信息Mapper接口
@@ -90,4 +92,14 @@ public interface DcWarningMapper
public Integer updateEndSection(@Param("dcWarningList") List dcWarningList);
//查询当天全部可以结束的事件
public List selectEndSection();
+ //依据桩号返回驻点id
+ public Long selectSectionId(@Param("stakeMark")String stakeMark,@Param("direction")String direction);
+ //依据桩号获取最近距离的驻点
+ public List> selectRecentlySection();
+ //查询某个机构的全部应急人员信息
+ public List> selectOrganizationEmployees(@Param("organizationId")Long organizationId);
+ //查询某个机构当天的值班信息
+ public List> selectShifts(@Param("station") Long station);
+ //查询某个机构的车辆信息
+ public List> selectVehicles(@Param("organizationId")Long organizationId);
}
diff --git a/zc-business/src/main/java/com/zc/business/service/IDcWarningService.java b/zc-business/src/main/java/com/zc/business/service/IDcWarningService.java
index 54c65999..33a68e4e 100644
--- a/zc-business/src/main/java/com/zc/business/service/IDcWarningService.java
+++ b/zc-business/src/main/java/com/zc/business/service/IDcWarningService.java
@@ -84,4 +84,6 @@ public interface IDcWarningService
//定时结束部分事件
Integer updateEndSection();
+ //指挥调度
+ AjaxResult commandAndDispatch(DcWarning dcWarning);
}
diff --git a/zc-business/src/main/java/com/zc/business/service/IMsmService.java b/zc-business/src/main/java/com/zc/business/service/IMsmService.java
new file mode 100644
index 00000000..5dc10cdf
--- /dev/null
+++ b/zc-business/src/main/java/com/zc/business/service/IMsmService.java
@@ -0,0 +1,21 @@
+package com.zc.business.service;
+
+import com.alibaba.fastjson.JSONArray;
+import com.ruoyi.common.core.domain.AjaxResult;
+
+public interface IMsmService {
+ /**
+ * 发送短信
+ *
+ * @param phone 手机号
+ * @return
+ */
+ public boolean send(String phone);
+ /**
+ * 微信推送
+ *
+ * @return
+ */
+ JSONArray wenXinSend(String appId, String appSecret);
+
+}
\ No newline at end of file
diff --git a/zc-business/src/main/java/com/zc/business/service/impl/DcWarningServiceImpl.java b/zc-business/src/main/java/com/zc/business/service/impl/DcWarningServiceImpl.java
index c2203f31..db0e0729 100644
--- a/zc-business/src/main/java/com/zc/business/service/impl/DcWarningServiceImpl.java
+++ b/zc-business/src/main/java/com/zc/business/service/impl/DcWarningServiceImpl.java
@@ -1,7 +1,6 @@
package com.zc.business.service.impl;
-
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.redis.RedisCache;
import com.ruoyi.common.utils.DateUtils;
@@ -16,19 +15,22 @@ import com.zc.business.mapper.DcEventMapper;
import com.zc.business.mapper.DcWarningMapper;
import com.zc.business.service.IDcEventService;
import com.zc.business.service.IDcWarningService;
+import com.zc.business.utils.StakeMarkUtils;
import org.apache.commons.lang3.StringUtils;
+import org.json.JSONArray;
+import org.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
import java.util.ArrayList;
+import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.TimeUnit;
-import org.json.JSONObject;
-import org.json.JSONArray;
+import java.util.stream.Collectors;
/**
* 预警信息Service业务层处理
*
@@ -543,4 +545,34 @@ public class DcWarningServiceImpl implements IDcWarningService
return dcWarningMapper.updateEndSection(dcWarnings);
}
+ @Override
+ public AjaxResult commandAndDispatch(DcWarning dcWarning) {
+ //逻辑,调用全部的机构信息,计算传入的桩号与机构桩号的距离作为排序使用,使用机构的id调出车辆,人员,值班等信息
+ List> mapList = dcWarningMapper.selectRecentlySection();//全部机构的桩号和名称
+ ArrayList> hashMaps = new ArrayList<>();
+ for (HashMap map:mapList){
+ if (StringUtils.isBlank(map.get("stakeMark").toString())){
+ continue;
+ }
+ String stakeMark = map.get("stakeMark").toString();
+ StakeMarkUtils stakeMarkUtils = new StakeMarkUtils();
+ Integer itselfStakeMark = stakeMarkUtils.stakeMarkToInt(stakeMark);//桩号本身的米数
+ Integer afferentStakeMark = stakeMarkUtils.stakeMarkToInt(dcWarning.getStakeMark());//传入的桩号米数
+ Integer difference =Math.abs(afferentStakeMark-itselfStakeMark); //计算距离绝对值
+ map.put("difference",difference/1000.0);//米转公里加入到map
+ Long id = (Long) map.get("id");//机构的id,用户获取人员、值班、车辆等信息
+ List> employeesMap = dcWarningMapper.selectOrganizationEmployees(id);//人员map
+ List> shiftsMap = dcWarningMapper.selectShifts(id);//值班map
+ List> vehiclesMap = dcWarningMapper.selectVehicles(id);//车辆map
+ map.put("employeesMap",employeesMap);
+ map.put("shiftsMap",shiftsMap);
+ map.put("vehiclesMap",vehiclesMap);
+ hashMaps.add(map);
+ }
+ List> sortedHashMaps = hashMaps.stream().sorted(Comparator.comparing(map -> {
+ return (Double) map.get("difference"); })).collect(Collectors.toList());
+ return AjaxResult.success(sortedHashMaps);
+ }
+
+
}
diff --git a/zc-business/src/main/java/com/zc/business/service/impl/MsmServiceImpl.java b/zc-business/src/main/java/com/zc/business/service/impl/MsmServiceImpl.java
new file mode 100644
index 00000000..fef5b2a4
--- /dev/null
+++ b/zc-business/src/main/java/com/zc/business/service/impl/MsmServiceImpl.java
@@ -0,0 +1,201 @@
+package com.zc.business.service.impl;
+
+import com.alibaba.fastjson.JSON;
+import com.alibaba.fastjson.JSONArray;
+import com.aliyuncs.DefaultAcsClient;
+import com.aliyuncs.IAcsClient;
+import com.aliyuncs.dysmsapi.model.v20170525.SendSmsRequest;
+import com.aliyuncs.dysmsapi.model.v20170525.SendSmsResponse;
+import com.aliyuncs.profile.DefaultProfile;
+import com.ruoyi.common.core.domain.AjaxResult;
+import com.ruoyi.common.core.redis.RedisCache;
+import com.ruoyi.common.utils.spring.SpringUtils;
+import com.zc.business.service.IMsmService;
+import com.zc.business.utils.HttpUtil;
+import org.apache.commons.lang3.StringUtils;
+import org.json.JSONObject;
+import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
+import org.springframework.stereotype.Service;
+
+import javax.annotation.Resource;
+import java.io.InputStream;
+
+import java.net.HttpURLConnection;
+import java.net.URL;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Random;
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.ThreadPoolExecutor;
+import java.util.concurrent.TimeUnit;
+
+/**
+ * 短信业务实现类
+ */
+@Service
+public class MsmServiceImpl implements IMsmService {
+ private static final String WEIXINTUISONTOKEN = "weixintuisontoken";//redis策略缓存的key
+
+ /**
+ * 发送短信
+ *
+ * @param phone 手机号
+ * @return
+ */
+ public boolean send(String phone) {
+ //地域节点、阿里云的id、秘钥
+ DefaultProfile profile = DefaultProfile.getProfile("cn-qingdao",
+ "LTAI5tENd3j1tP5t2fF4fxaX", "i86Yenj13XRd2aeZMtybpKxsqI1VRU");
+ IAcsClient client = new DefaultAcsClient(profile);
+ SendSmsRequest request = new SendSmsRequest();
+ request.setSysRegionId("cn-qingdao");//地域节点
+ request.putQueryParameter("PhoneNumbers", phone); //手机号,要填绑定测试的手机号码
+ request.putQueryParameter("SignName", "阿里云短信测试"); //阿里云签名名称
+ request.putQueryParameter("TemplateCode", "SMS_154950909"); //阿里云模板code
+ String code = String.format("%04d", new Random().nextInt(10000));//验证码
+ HashMap