Browse Source

推送整合,调度联络,微博推送

develop
wangsixiang 7 months ago
parent
commit
cdec228fea
  1. 20
      zc-business/src/main/java/com/zc/business/controller/DcWarningController.java
  2. 29
      zc-business/src/main/java/com/zc/business/controller/MsmController.java
  3. 77
      zc-business/src/main/java/com/zc/business/controller/WeiboAuthExample.java
  4. 109
      zc-business/src/main/java/com/zc/business/controller/WeiboAuthUtil.java
  5. 10
      zc-business/src/main/java/com/zc/business/domain/DcDispatch.java
  6. 5
      zc-business/src/main/java/com/zc/business/domain/DcDispatchResource.java
  7. 20
      zc-business/src/main/java/com/zc/business/mapper/DcWarningMapper.java
  8. 6
      zc-business/src/main/java/com/zc/business/service/IDcWarningService.java
  9. 141
      zc-business/src/main/java/com/zc/business/service/impl/DcWarningServiceImpl.java
  10. 6
      zc-business/src/main/java/com/zc/business/service/impl/MsmServiceImpl.java
  11. 99
      zc-business/src/main/resources/mapper/business/DcWarningMapper.xml

20
zc-business/src/main/java/com/zc/business/controller/DcWarningController.java

@ -153,19 +153,25 @@ public class DcWarningController extends BaseController
//指挥调度
@PostMapping("/commandAndDispatch")
public AjaxResult commandAndDispatch(@RequestBody DcWarning dcWarning){
if (StringUtils.isBlank(dcWarning.getStakeMark())){
if (StringUtils.isBlank(dcWarning.getStakeMark())||StringUtils.isBlank(dcWarning.getId())){
return AjaxResult.error("参数错误");
}
return (dcWarningService.commandAndDispatch(dcWarning));
}
//指挥调度记录新增
@PostMapping("/insertDispatch")
//指挥调度记录修改
@PostMapping("/updateDispatch")
public AjaxResult insertDispatch(@RequestBody DcDispatch dcDispatch){
return AjaxResult.success(dcWarningService.insertDispatch(dcDispatch));
if (dcDispatch.getOrganizationId()==null){
return AjaxResult.error("参数错误");
}
return toAjax(dcWarningService.insertDispatch(dcDispatch));
}
//指挥调度资源新增
@PostMapping("/insertSource")
public AjaxResult insertDispatchSource(@RequestBody DcDispatchResource dcDispatchResource){
return toAjax(dcWarningService.insertDispatchSource(dcDispatchResource));
@PostMapping("/updateSource")
public AjaxResult insertDispatchSource(@RequestBody HashMap map){
if (map==null||!map.containsKey("dispatchId")){
return AjaxResult.error("参数错误");
}
return toAjax(dcWarningService.insertDispatchSource(map));
}
}

29
zc-business/src/main/java/com/zc/business/controller/MsmController.java

@ -3,24 +3,17 @@ 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.ruoyi.common.utils.SecurityUtils;
import com.zc.business.domain.DcEventProcess;
import com.zc.business.domain.DcWarning;
import com.zc.business.service.IMsmService;
import com.zc.business.service.impl.DcEventProcessServiceImpl;
import com.zc.business.utils.HttpUtil;
import org.apache.commons.lang3.StringUtils;
import org.omg.CORBA.INTERNAL;
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.lang.reflect.Array;
import java.rmi.MarshalledObject;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
/**
@ -89,17 +82,12 @@ public class MsmController extends BaseController {
continue;
}
}
if (send==null){
message=null;
}else if (send){
if (send==true){
message = "短信推送成功"; // 如果 send 为 true,则短信推送成功
}
if (data==null){
weiXin=null;
}else if (data==0){
if (data==0){
weiXin = "微信推送成功"; // 如果所有 dateValue 都为0,则微信推送成功
}
DcEventProcess dcEventProcess = new DcEventProcess();
dcEventProcess.setEventId(eventId);
dcEventProcess.setSource(1);
@ -107,18 +95,9 @@ public class MsmController extends BaseController {
String context = "出行信息发布:" + content;
dcEventProcess.setContext(context);
dcEventProcessService.insertDcEventProcess(dcEventProcess);
if (message!=null&&"短信推送成功".equals(message) &&weiXin!=null&&"微信推送成功".equals(weiXin)) {
if ("短信推送成功".equals(message) &&"微信推送成功".equals(weiXin)) {
return AjaxResult.success(message +","+ weiXin);
} else if (message==null&&weiXin!=null&&"微信推送成功".equals(weiXin)){
return AjaxResult.success(weiXin);
}else if (message!=null&&"短信推送成功".equals(message)&&weiXin==null){
return AjaxResult.success(message);
}else if (message!=null&&"短信推送失败".equals(message)&&weiXin==null){
return AjaxResult.error(message);
}else if (message==null&&"微信推送失败".equals(weiXin)){
return AjaxResult.error(weiXin);
}else {
} else {
return AjaxResult.error(message +","+ weiXin);
}
}

77
zc-business/src/main/java/com/zc/business/controller/WeiboAuthExample.java

@ -0,0 +1,77 @@
package com.zc.business.controller;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
import java.util.Map;
import java.util.HashMap;
//微博获取token的工具类
public class WeiboAuthExample {
private static final String APP_KEY = "1894516689";
private static final String APP_SECRET = "4e89660243b70328fb74ae10f9ed98e5";
private static final String REDIRECT_URI = "https://api.weibo.com/oauth2/default.html"; // 回调URL,需要URL编码
private static final String AUTHORIZE_URL = "https://api.weibo.com/oauth2/authorize?client_id="+APP_KEY+"&redirect_uri="+REDIRECT_URI+"&response_type=code";
public static void main(String[] args) throws IOException {
// 1. 引导用户到微博授权页面
System.out.println("Please visit the following URL to authorize your Weibo account:");
System.out.println(AUTHORIZE_URL);
System.out.println("After authorization, you will be redirected to the callback URL with an Authorization Code.");
// 在实际应用中,你应该设置一个HTTP服务器来处理回调,而不是从控制台读取输入。
// 这里为了简化示例,我们直接从控制台读取Authorization Code。
System.out.print("Enter the Authorization Code from the callback URL: ");
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
String code = reader.readLine();
// 2. 使用Authorization Code请求Access Token
String accessTokenUrl = "https://api.weibo.com/oauth2/access_token";
Map<String, String> params = new HashMap<>();
params.put("client_id", APP_KEY);
params.put("client_secret", APP_SECRET);
params.put("grant_type", "authorization_code");
params.put("code", code);
params.put("redirect_uri", REDIRECT_URI);
String accessTokenResponse = sendPostRequest(accessTokenUrl, params);
// 解析Access Token响应,实际应用中应该使用JSON库来解析
System.out.println("Access Token Response: " + accessTokenResponse);
}
private static String sendPostRequest(String url, Map<String, String> params) throws IOException {
URL obj = new URL(url);
HttpURLConnection con = (HttpURLConnection) obj.openConnection();
con.setRequestMethod("POST");
con.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
con.setRequestProperty("Accept", "application/json");
con.setDoOutput(true);
StringBuilder postData = new StringBuilder();
for (Map.Entry<String, String> param : params.entrySet()) {
if (postData.length() != 0) postData.append('&');
postData.append(URLEncoder.encode(param.getKey(), StandardCharsets.UTF_8.toString()));
postData.append('=');
postData.append(URLEncoder.encode(param.getValue(), StandardCharsets.UTF_8.toString()));
}
byte[] postDataBytes = postData.toString().getBytes(StandardCharsets.UTF_8);
try (OutputStream os = con.getOutputStream()) {
os.write(postDataBytes);
}
int responseCode = con.getResponseCode();
BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream()));
String inputLine;
StringBuffer response = new StringBuffer();
while ((inputLine = in.readLine()) != null) {
response.append(inputLine);
}
in.close();
return response.toString();
}
}

109
zc-business/src/main/java/com/zc/business/controller/WeiboAuthUtil.java

@ -1,20 +1,18 @@
package com.zc.business.controller;
import com.alibaba.fastjson.JSONObject;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.util.EntityUtils;
import java.io.IOException;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.List;
/**
* @author 王思祥
@ -22,75 +20,42 @@ import java.net.URLEncoder;
*/
public class WeiboAuthUtil {
//1.登录传入重定向的url,用户授权后返回授权的code,2.使用code取得认证权限token 3.调用接口参数
//1.登录获取用户的回调code
private static final String APP_KEY = "1894516689";
private static final String APP_SECRET = "4e89660243b70328fb74ae10f9ed98e5";
private static final String REDIRECT_URI = "https://api.weibo.com/oauth2/default.html";//授权回调地址
//获取授权后的code
public String tokenCode(){
String url="https://api.weibo.com/oauth2/authorize?client_id="+APP_KEY+"&redirect_uri="+REDIRECT_URI+"&response_type=code";
String accessToken=null;
com.alibaba.fastjson.JSONObject jsonObj = null;
private static final String ACCESS_TOKEN = "2.00oesadIn1MNEC0296dd00f87jmhaC";
private static final String WEIBO_API_URL = "https://api.weibo.com/2/statuses/update.json";
public static void main(String[] args) {
try {
URL urlGet = new URL(url);
HttpURLConnection http = (HttpURLConnection) urlGet.openConnection();
http.setRequestMethod("GET"); // 必须是get方式请求
http.setDoInput(true);
http.connect();
InputStream is = http.getInputStream();
int size = is.available();
byte[] jsonBytes = new byte[size];
is.read(jsonBytes);
accessToken = new String(jsonBytes, "UTF-8");
System.err.println(accessToken);
jsonObj = com.alibaba.fastjson.JSONObject.parseObject(accessToken);
is.close();
return jsonObj.get("code").toString();
}catch (Exception e){
String text = "这是一条通过Java和微博API推送的消息!"; // 你要推送的微博内容
postWeibo(text);
} catch (Exception e) {
e.printStackTrace();
}
return "";
}
//获取toke
public String token(String code)throws IOException {
HttpClient httpClient = HttpClients.createDefault();
String tokenUrl = REDIRECT_URI + "?client_id=" + APP_KEY
+ "&client_secret=" + APP_SECRET
+ "&grant_type=authorization_code"
+ "&code=" + code
+ "&redirect_uri=" + URLEncoder.encode(REDIRECT_URI, "UTF-8");
HttpGet httpGet = new HttpGet(tokenUrl);
HttpResponse response = httpClient.execute(httpGet);
private static void postWeibo(String status) throws Exception {
CloseableHttpClient httpClient = HttpClients.createDefault();
HttpPost httpPost = new HttpPost(WEIBO_API_URL);
// 设置请求头,包含Content-Type
httpPost.setHeader("Content-Type", "application/x-www-form-urlencoded;charset=UTF-8");
httpPost.setHeader("Authorization", "Bearer " + ACCESS_TOKEN);
// 构造POST请求参数列表
List<BasicNameValuePair> params = new ArrayList<>();
params.add(new BasicNameValuePair("access_token", ACCESS_TOKEN));
params.add(new BasicNameValuePair("status", status));
// 将参数列表转换为URL编码的字符串
StringEntity paramsEntity = new StringEntity(EntityUtils.toString(new UrlEncodedFormEntity(params, StandardCharsets.UTF_8)), StandardCharsets.UTF_8);
// 设置请求体内容
httpPost.setEntity(paramsEntity);
// 发送请求并获取响应
HttpResponse response = httpClient.execute(httpPost);
HttpEntity entity = response.getEntity();
if (entity != null) {
String responseBody = EntityUtils.toString(entity, "UTF-8");
org.json.JSONObject jsonObject = new org.json.JSONObject(responseBody);
return jsonObject.optString("access_token");
String responseString = EntityUtils.toString(entity, StandardCharsets.UTF_8);
System.out.println("Response: " + responseString);
}
return null;
// 关闭HttpClient连接
httpClient.close();
}
//执行调用推送api
public static void main(String[] args) throws Exception {
WeiboAuthUtil weiboAuthUtil = new WeiboAuthUtil();
String code = weiboAuthUtil.tokenCode();
String accessToken = weiboAuthUtil.token("1223e0dbc177fe5a20ba1cc2f3c444d5");//认证后的code放入,获取token
// 创建HttpClient实例
try (CloseableHttpClient httpClient = HttpClients.createDefault()) {
// 构建请求URL,这里以获取用户信息为例
String url = "https://api.weibo.com/2/users/show.json?access_token=" + accessToken + "&uid=用户UID";
// 创建HttpGet请求
HttpGet httpGet = new HttpGet(url);
// 执行请求并获取响应
try (CloseableHttpResponse response = httpClient.execute(httpGet)) {
HttpEntity entity = response.getEntity();
if (entity != null) {
// 读取响应内容
String responseString = EntityUtils.toString(entity, "UTF-8");
System.out.println(responseString);
}
}
}
}
}

10
zc-business/src/main/java/com/zc/business/domain/DcDispatch.java

@ -63,6 +63,16 @@ private String organizationName;
/** $column.columnComment */
@Excel(name = "调度记录id", readConverterExp = "$column.readConverterExp()")
private Long dispatchId;
//部门id
private Long deptId;
public Long getDeptId() {
return deptId;
}
public void setDeptId(Long deptId) {
this.deptId = deptId;
}
public Integer getDispatchType() {
return dispatchType;

5
zc-business/src/main/java/com/zc/business/domain/DcDispatchResource.java

@ -30,7 +30,10 @@ public class DcDispatchResource extends BaseEntity
@Excel(name = "${comment}", readConverterExp = "$column.readConverterExp()")
private Long dispatchId;
public void setId(Long id)
public void setId(Long id)
{
this.id = id;
}

20
zc-business/src/main/java/com/zc/business/mapper/DcWarningMapper.java

@ -108,4 +108,24 @@ public interface DcWarningMapper
public Integer insertDispatchResource(DcDispatchResource dcDispatchResource);
//新增调度记录信息
public Integer insertDcDispatch(DcDispatch dcDispatch);
//修改调度记录信息
public Integer updateDcDispatch(DcDispatch dcDispatch);
//查询调度资源信息
public HashMap<String,Object> selectDcDispatch(@Param("eventId") String eventId);
//查询记录信息
public List<HashMap<String,Object>> selectDispatchResource(@Param("dispatchId")Long dispatchId);
//查询查询值班的全部人员
public List<HashMap<String,Object>> selectShiftsEmployees();
//查询机构人员和调度关系
public List<HashMap<String,Object>> selectEmployeesDispatch(@Param("organizationId")Long organizationId,@Param("eventId") String eventId);
//查询机构车辆和调度关系
public List<HashMap<String,Object>> selectVehiclesDispatch(@Param("organizationId")Long organizationId,@Param("eventId") String eventId);
//取出运管中心
public HashMap<String,Object> selectOrganization();
//选中的人员信息
public List<HashMap<String,Object>> selectEmployeesChoice(@Param("dispatchId")Long dispatchId);
//选中的车辆信息
public List<HashMap<String,Object>> selectVehiclesChoice(@Param("dispatchId")Long dispatchId);
public Integer deleteDispatchResource(@Param("dispatchId")Long dispatchId);
}

6
zc-business/src/main/java/com/zc/business/service/IDcWarningService.java

@ -88,8 +88,8 @@ public interface IDcWarningService
Integer updateEndSection();
//指挥调度
AjaxResult commandAndDispatch(DcWarning dcWarning);
//修改指挥调度资源记录
public Integer insertDispatch(DcDispatch dcDispatch);
//新增指挥调度资源记录
public DcDispatch insertDispatch(DcDispatch dcDispatch);
//新增指挥调度资源记录
public Integer insertDispatchSource(DcDispatchResource dcDispatchResource);
public Integer insertDispatchSource(HashMap map);
}

141
zc-business/src/main/java/com/zc/business/service/impl/DcWarningServiceImpl.java

@ -29,6 +29,9 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.lang.reflect.Array;
import java.rmi.MarshalledObject;
import java.util.concurrent.ThreadLocalRandom;
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.Comparator;
@ -506,18 +509,45 @@ public class DcWarningServiceImpl implements IDcWarningService
}
List<HashMap<String, Object>> sortedHashMaps = hashMaps.stream().sorted(Comparator.comparing(map -> {
return (Double) map.get("difference"); })).collect(Collectors.toList());
HashMap<String, Object> map = sortedHashMaps.get(0);
Long id = (Long) map.get("id");//取出最近的机构id
if (id!=null){
DcDispatch dcDispatch = new DcDispatch();
dcDispatch.setEventId(dcWarning.getId());
dcDispatch.setOrganizationId(id);
dcWarningMapper.insertDcDispatch(dcDispatch);//事件绑定记录
if (!sortedHashMaps.isEmpty()) {
HashMap<String, Object> map = sortedHashMaps.get(0);
Long id = (Long) map.get("id");//取出最近的机构id
if (id != null) {
DcDispatch dcDispatch = new DcDispatch();
DcDispatchResource dcDispatchResource = new DcDispatchResource();
dcDispatch.setDeptId(SecurityUtils.getLoginUser().getDeptId());
dcDispatch.setEventId(dcWarning.getId());
dcWarningMapper.insertDcDispatch(dcDispatch);//事件绑定信息记录
Long dispatchId = dcDispatch.getId();//信息记录id
List<HashMap<String, Object>> employeesMap = dcWarningMapper.selectOrganizationEmployees(dispatchId);//人员map
if (employeesMap != null) {
// 生成一个随机索引,范围在0到列表长度减1之间
int randomIndex = ThreadLocalRandom.current().nextInt(employeesMap.size());
HashMap<String, Object> randomEmployee = employeesMap.get(randomIndex);
Long employeesId = (Long) randomEmployee.get("id");//随机人员id
dcDispatchResource.setResourceId(employeesId);//资源id
dcDispatchResource.setDispatchType(1);//资源类型
dcDispatchResource.setDispatchId(dispatchId);//信息记录id
dcWarningMapper.insertDispatchResource(dcDispatchResource);
}
List<HashMap<String, Object>> vehiclesMap = dcWarningMapper.selectVehicles(dispatchId);//车辆map
if (vehiclesMap != null) {
// 生成一个随机索引,范围在0到列表长度减1之间
int randomIndex = ThreadLocalRandom.current().nextInt(vehiclesMap.size());
HashMap<String, Object> randomEmployee = employeesMap.get(randomIndex);
Long vehiclesId = (Long) randomEmployee.get("id");//随机车辆id
dcDispatchResource.setResourceId(vehiclesId);//资源id
dcDispatchResource.setDispatchType(2);//资源类型
dcDispatchResource.setDispatchId(dispatchId);//信息记录id
dcWarningMapper.insertDispatchResource(dcDispatchResource);//绑定车辆信息
}
}
}
if (insertDcEvent==0){
return AjaxResult.error("操作失败");
}
return AjaxResult.success("操作成功");
}
@Override
@ -619,6 +649,7 @@ public class DcWarningServiceImpl implements IDcWarningService
//逻辑,调用全部的机构信息,计算传入的桩号与机构桩号的距离作为排序使用,使用机构的id调出车辆,人员,值班等信息
List<HashMap<String, Object>> mapList = dcWarningMapper.selectRecentlySection();//全部机构的桩号和名称
ArrayList<HashMap<String,Object>> hashMaps = new ArrayList<>();
Map<String, Object> mapAll = new HashMap<>();
for (HashMap<String,Object> map:mapList){
if (StringUtils.isBlank(map.get("stakeMark").toString())){
continue;
@ -630,57 +661,75 @@ public class DcWarningServiceImpl implements IDcWarningService
Integer difference =Math.abs(afferentStakeMark-itselfStakeMark); //计算距离绝对值
map.put("difference",difference/1000.0);//米转公里加入到map
Long id = (Long) map.get("id");//机构的id,用户获取人员、值班、车辆等信息
List<HashMap<String, Object>> employeesMap = dcWarningMapper.selectOrganizationEmployees(id);//人员map
List<HashMap<String, Object>> shiftsMap = dcWarningMapper.selectShifts(id);//值班map
List<HashMap<String, Object>> vehiclesMap = dcWarningMapper.selectVehicles(id);//车辆map
List<HashMap<String, Object>> employeesMap = dcWarningMapper.selectEmployeesDispatch(id,dcWarning.getId());//人员map
List<HashMap<String, Object>> vehiclesMap = dcWarningMapper.selectVehiclesDispatch(id,dcWarning.getId());//车辆map
map.put("employeesMap",employeesMap);
map.put("shiftsMap",shiftsMap);
map.put("vehiclesMap",vehiclesMap);
hashMaps.add(map);
}
List<HashMap<String, Object>> sortedHashMaps = hashMaps.stream().sorted(Comparator.comparing(map -> {
return (Double) map.get("difference"); })).collect(Collectors.toList());
return AjaxResult.success(sortedHashMaps);
mapAll.put("listData",sortedHashMaps);
HashMap<String, Object> map = dcWarningMapper.selectDcDispatch(dcWarning.getId());//获取机构id与资源id
if (map!=null){
HashMap<Object, Object> hashMap = new HashMap<>();
Long id = (Long) map.get("id");//调度记录id
Object deptName =map.get("deptName");//部门名称
List<HashMap<String, Object>> shifts = dcWarningMapper.selectShiftsEmployees();//值班为空把全部的人员信息作为值班人员信息
List<HashMap<String, Object>> resource = dcWarningMapper.selectDispatchResource(id);//全部资源信息
List<HashMap<String, Object>> employeesChoice = dcWarningMapper.selectEmployeesChoice(id);//选中人员信息
List<HashMap<String, Object>> vehiclesChoice = dcWarningMapper.selectVehiclesChoice(id);//选中车辆信息
hashMap.put("id",id);//调度记录id
hashMap.put("deptName",deptName);
hashMap.put("shifts",shifts);
hashMap.put("resource",resource);
mapAll.put("resource",hashMap);
mapAll.put("employeesChoice",employeesChoice);
mapAll.put("vehiclesChoice",vehiclesChoice);
}
return AjaxResult.success(mapAll);
}
@Override
public DcDispatch insertDispatch(DcDispatch dcDispatch) {
dcWarningMapper.insertDcDispatch(dcDispatch);
return dcDispatch;
public Integer insertDispatch(DcDispatch dcDispatch) {
if (dcDispatch.getId()==null){ //id为空说明新增
return dcWarningMapper.insertDcDispatch(dcDispatch);
}
return dcWarningMapper.updateDcDispatch(dcDispatch);
}
@Override
public Integer insertDispatchSource(DcDispatchResource dcDispatchResource) {
return dcWarningMapper.insertDispatchResource(dcDispatchResource);
@Transactional(rollbackFor = Exception.class)
public Integer insertDispatchSource(HashMap map) {
DcDispatchResource dcDispatchResource = new DcDispatchResource();
Integer pat = (Integer) map.get("dispatchId");
long dispatchId = pat.longValue();
dcWarningMapper.deleteDispatchResource(dispatchId);//删除全部属于该调度记录下的全部资源
ArrayList<Integer> employeesArray = (ArrayList<Integer>) map.get("employees");//取出人员
if (employeesArray!=null&&employeesArray.size()>0) {
for (Integer array : employeesArray) {
dcDispatchResource.setDispatchType(1);//类型
dcDispatchResource.setResourceId(array.longValue());//资源id
dcDispatchResource.setDispatchId(dispatchId);//关联调度记录
Integer integer = dcWarningMapper.insertDispatchResource(dcDispatchResource);
if (integer == 0) {
return 0;
}
}
}
ArrayList<Integer> vehicleArray = (ArrayList<Integer>) map.get("vehicle");////取出车辆
if (vehicleArray!=null&&vehicleArray.size()>0) {
for (Integer array : vehicleArray) {
dcDispatchResource.setDispatchType(2);
dcDispatchResource.setResourceId(array.longValue());
dcDispatchResource.setDispatchId(dispatchId);
Integer integer = dcWarningMapper.insertDispatchResource(dcDispatchResource);
if (integer == 0) {
return 0;
}
}
}
return 1;
}
//依据桩号计算出记录最近的机构id
public AjaxResult stake(DcWarning dcWarning){
String stakeMark = dcWarning.getStakeMark();
ArrayList<HashMap<String,Object>> hashMaps = new ArrayList<>();
List<HashMap<String, Object>> mapList = dcWarningMapper.selectRecentlySection();//全部机构的桩号和名称
for (HashMap<String,Object> map:mapList){
if (StringUtils.isBlank(map.get("stakeMark").toString())){
continue;
}
Long id = (Long) map.get("id");//机构的id
String stakeMarkNew = map.get("stakeMark").toString();//机构桩号
StakeMarkUtils stakeMarkUtils = new StakeMarkUtils();
Integer itselfStakeMark = stakeMarkUtils.stakeMarkToInt(stakeMarkNew);//机构本身的米数
Integer afferentStakeMark = stakeMarkUtils.stakeMarkToInt(stakeMark);//传入的桩号米数
Integer difference =Math.abs(afferentStakeMark-itselfStakeMark); //计算距离绝对值
map.put("difference",difference/1000.0);//米转公里加入到map
map.put("id",id);
hashMaps.add(map);
}
List<HashMap<String, Object>> sortedHashMaps = hashMaps.stream().sorted(Comparator.comparing(map -> {
return (Double) map.get("difference"); })).collect(Collectors.toList());
if (!sortedHashMaps.isEmpty()){
HashMap<String, Object> map = sortedHashMaps.get(0);
Long id = (Long) map.get("id");
return AjaxResult.success(id);
}
return null;
}
}

6
zc-business/src/main/java/com/zc/business/service/impl/MsmServiceImpl.java

@ -7,27 +7,21 @@ 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;

99
zc-business/src/main/resources/mapper/business/DcWarningMapper.xml

@ -172,6 +172,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="startTime != null">start_time,</if>
<if test="endTime != null">end_time,</if>
<if test="remark != null">remark,</if>
<if test="deptId != null">dept_id,</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="id != null">#{id},</if>
@ -182,6 +183,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="startTime != null">#{startTime},</if>
<if test="endTime != null">#{endTime},</if>
<if test="remark != null">#{remark},</if>
<if test="deptId != null">#{deptId},</if>
</trim>
</insert>
<update id="updateDcWarning" parameterType="DcWarning">
@ -231,6 +233,9 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
#{item.id}
</foreach>
</update>
<update id="updateDcDispatch">
update dc_dispatch set organization_id=#{organization_id} where id=#{id}
</update>
<delete id="deleteDcWarningById" parameterType="Integer">
delete from dc_warning where id = #{id}
</delete>
@ -250,6 +255,9 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
#{item.id}
</foreach>
</delete>
<delete id="deleteDispatchResource">
delete from dc_dispatch_resource where dispatch_id=#{dispatchId}
</delete>
<select id="selectCount" resultType="int">
SELECT COUNT(*)AS count FROM dc_warning
@ -289,7 +297,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
select id,organization_name organizationName,stake_mark stakeMark from dc_organization
</select>
<select id="selectOrganizationEmployees" resultType="java.util.HashMap">
select name,contact_number contactNumber from dc_employees where organization_id=#{organizationId} and employees_type=2
select id, name,contact_number contactNumber from dc_employees where organization_id=#{organizationId} and employees_type=2
</select>
<select id="selectShifts" resultType="java.util.HashMap">
select shifts.scheduling,employees.name shiftsName,employees.contact_number shiftsNumber from dc_shifts as shifts
@ -297,8 +305,95 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
where shifts.station=#{station} and DATE(date) = CURDATE();
</select>
<select id="selectVehicles" resultType="java.util.HashMap">
select vehicle_type vehicleType,vehicle_plate vehiclePlate from dc_vehicles
select id,vehicle_type vehicleType,vehicle_plate vehiclePlate from dc_vehicles
where vehicle_status=1 and organization_id=#{organizationId}
</select>
<select id="selectDcDispatch" resultType="java.util.HashMap">
select dc_dispatch.id id,sys_dept.dept_name deptName
from dc_dispatch
left join dc_organization on dc_dispatch.organization_id=dc_organization.id
LEFT JOIN sys_dept on sys_dept.dept_id=dc_dispatch.dept_id
where event_id=#{eventId}
</select>
<select id="selectDispatchResource" resultType="java.util.HashMap">
SELECT
dc_dispatch_resource.resource_id resourceId,
dc_dispatch_resource.dispatch_type dispatchType,
CASE
WHEN dc_dispatch_resource.dispatch_type = 1 THEN dc_employees.name
WHEN dc_dispatch_resource.dispatch_type = 2 THEN dc_vehicles.vehicle_type
ELSE NULL
END AS resourceName,
CASE
WHEN dc_dispatch_resource.dispatch_type = 1 THEN dc_employees.contact_number
WHEN dc_dispatch_resource.dispatch_type = 2 THEN dc_vehicles.vehicle_plate
ELSE NULL
END AS resourceValue
FROM
dc_dispatch_resource
LEFT JOIN dc_employees ON dc_dispatch_resource.resource_id = dc_employees.id AND dc_dispatch_resource.dispatch_type = 1
LEFT JOIN dc_vehicles ON dc_dispatch_resource.resource_id = dc_vehicles.id AND dc_dispatch_resource.dispatch_type = 2
where dc_dispatch_resource.dispatch_id=#{dispatchId}
</select>
<select id="selectShiftsEmployees" resultType="java.util.HashMap">
select shifts.name shiftsName,shifts.contact_number shiftsNumber
from dc_employees as shifts
</select>
<select id="selectEmployeesDispatch" resultType="java.util.HashMap">
SELECT dc_employees.id,
dc_employees.name,
dc_employees.contact_number AS contactNumber,
CASE
WHEN t.id IS NOT NULL THEN 1 -- 连接成立
ELSE 0 -- 连接不成立
END AS state
from dc_employees
LEFT JOIN(
select employees.id id, employees.name, employees.contact_number contactNumber
from dc_employees as employees
left JOIN dc_dispatch_resource as respurce on respurce.resource_id = employees.id
LEFT JOIN dc_dispatch as path on path.id = respurce.dispatch_id
where employees.organization_id = #{organizationId}
and employees.employees_type = 2
and respurce.dispatch_type = 1
and path.event_id = #{eventId}) as t on t.id = dc_employees.id
where organization_id = #{organizationId}
and employees_type = 2
</select>
<select id="selectVehiclesDispatch" resultType="java.util.HashMap">
select dc_vehicles.id,
dc_vehicles.vehicle_type vehicleType,
dc_vehicles.vehicle_plate vehiclePlate,
CASE
WHEN t.id IS NOT NULL THEN 1 -- 连接成立
ELSE 0 -- 连接不成立
END AS state
from dc_vehicles
LEFT JOIN(
select vehicles.id, vehicles.vehicle_type vehicleType, vehicles.vehicle_plate vehiclePlate
from dc_vehicles as vehicles
LEFT JOIN dc_dispatch_resource as resource on resource.resource_id = vehicles.id
LEFT JOIN dc_dispatch as path on path.id = resource.dispatch_id
where vehicles.organization_id = #{organizationId}
and vehicles.vehicle_status = 1
and resource.dispatch_type = 2
and path.event_id = #{eventId}) as t on t.id = dc_vehicles.id
where vehicle_status = 1
and organization_id = #{organizationId}
</select>
<select id="selectOrganization" resultType="java.util.HashMap">
select id from dc_organization where parent_id=0;
</select>
<select id="selectEmployeesChoice" resultType="java.util.HashMap">
select employees.id,employees.`name` from dc_dispatch_resource as resource
LEFT JOIN dc_employees as employees on resource.resource_id=employees.id
WHERE resource.dispatch_id=#{dispatchId} and resource.dispatch_type=1
</select>
<select id="selectVehiclesChoice" resultType="java.util.HashMap">
select vehicle.id,vehicle.vehicle_type vehicleType,vehicle.vehicle_plate vehiclePlate from dc_dispatch_resource as resource
LEFT JOIN dc_vehicles as vehicle on resource.resource_id=vehicle.id
WHERE resource.dispatch_id=1 and resource.dispatch_type=2
</select>
</mapper>

Loading…
Cancel
Save