From cdec228fea8db380ac356c9aca0554e0a84160e2 Mon Sep 17 00:00:00 2001 From: wangsixiang <2970484253@qq.com> Date: Fri, 19 Apr 2024 10:58:13 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8E=A8=E9=80=81=E6=95=B4=E5=90=88=EF=BC=8C?= =?UTF-8?q?=E8=B0=83=E5=BA=A6=E8=81=94=E7=BB=9C=EF=BC=8C=E5=BE=AE=E5=8D=9A?= =?UTF-8?q?=E6=8E=A8=E9=80=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/DcWarningController.java | 20 ++- .../zc/business/controller/MsmController.java | 29 +--- .../business/controller/WeiboAuthExample.java | 77 ++++++++++ .../zc/business/controller/WeiboAuthUtil.java | 109 +++++--------- .../com/zc/business/domain/DcDispatch.java | 10 ++ .../business/domain/DcDispatchResource.java | 5 +- .../zc/business/mapper/DcWarningMapper.java | 20 +++ .../business/service/IDcWarningService.java | 6 +- .../service/impl/DcWarningServiceImpl.java | 141 ++++++++++++------ .../business/service/impl/MsmServiceImpl.java | 6 - .../mapper/business/DcWarningMapper.xml | 99 +++++++++++- 11 files changed, 360 insertions(+), 162 deletions(-) create mode 100644 zc-business/src/main/java/com/zc/business/controller/WeiboAuthExample.java 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 aa45c5f4..1cb74c8c 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 @@ -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)); } } 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 index efc8929e..5b9d83b6 100644 --- a/zc-business/src/main/java/com/zc/business/controller/MsmController.java +++ b/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); } } diff --git a/zc-business/src/main/java/com/zc/business/controller/WeiboAuthExample.java b/zc-business/src/main/java/com/zc/business/controller/WeiboAuthExample.java new file mode 100644 index 00000000..054b44a2 --- /dev/null +++ b/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 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 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 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(); + } +} \ No newline at end of file diff --git a/zc-business/src/main/java/com/zc/business/controller/WeiboAuthUtil.java b/zc-business/src/main/java/com/zc/business/controller/WeiboAuthUtil.java index 2076aa7c..584a37f7 100644 --- a/zc-business/src/main/java/com/zc/business/controller/WeiboAuthUtil.java +++ b/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 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); - } - } - } - } } \ No newline at end of file diff --git a/zc-business/src/main/java/com/zc/business/domain/DcDispatch.java b/zc-business/src/main/java/com/zc/business/domain/DcDispatch.java index 6a2e9ed8..6cf17542 100644 --- a/zc-business/src/main/java/com/zc/business/domain/DcDispatch.java +++ b/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; diff --git a/zc-business/src/main/java/com/zc/business/domain/DcDispatchResource.java b/zc-business/src/main/java/com/zc/business/domain/DcDispatchResource.java index 7f9f318d..90a79098 100644 --- a/zc-business/src/main/java/com/zc/business/domain/DcDispatchResource.java +++ b/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; } 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 f1ddd947..e866bcd2 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 @@ -108,4 +108,24 @@ public interface DcWarningMapper public Integer insertDispatchResource(DcDispatchResource dcDispatchResource); //新增调度记录信息 public Integer insertDcDispatch(DcDispatch dcDispatch); + //修改调度记录信息 + public Integer updateDcDispatch(DcDispatch dcDispatch); + //查询调度资源信息 + public HashMap selectDcDispatch(@Param("eventId") String eventId); + //查询记录信息 + public List> selectDispatchResource(@Param("dispatchId")Long dispatchId); + //查询查询值班的全部人员 + public List> selectShiftsEmployees(); + //查询机构人员和调度关系 + public List> selectEmployeesDispatch(@Param("organizationId")Long organizationId,@Param("eventId") String eventId); + //查询机构车辆和调度关系 + public List> selectVehiclesDispatch(@Param("organizationId")Long organizationId,@Param("eventId") String eventId); + //取出运管中心 + public HashMap selectOrganization(); + //选中的人员信息 + public List> selectEmployeesChoice(@Param("dispatchId")Long dispatchId); + //选中的车辆信息 + public List> selectVehiclesChoice(@Param("dispatchId")Long dispatchId); + public Integer deleteDispatchResource(@Param("dispatchId")Long dispatchId); + } 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 c406e471..93af5845 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 @@ -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); } 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 536b8d0c..ac34bbc6 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 @@ -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> sortedHashMaps = hashMaps.stream().sorted(Comparator.comparing(map -> { return (Double) map.get("difference"); })).collect(Collectors.toList()); - HashMap 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 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> employeesMap = dcWarningMapper.selectOrganizationEmployees(dispatchId);//人员map + if (employeesMap != null) { + // 生成一个随机索引,范围在0到列表长度减1之间 + int randomIndex = ThreadLocalRandom.current().nextInt(employeesMap.size()); + HashMap 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> vehiclesMap = dcWarningMapper.selectVehicles(dispatchId);//车辆map + if (vehiclesMap != null) { + // 生成一个随机索引,范围在0到列表长度减1之间 + int randomIndex = ThreadLocalRandom.current().nextInt(vehiclesMap.size()); + HashMap 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> mapList = dcWarningMapper.selectRecentlySection();//全部机构的桩号和名称 ArrayList> hashMaps = new ArrayList<>(); + Map mapAll = new HashMap<>(); for (HashMap 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> employeesMap = dcWarningMapper.selectOrganizationEmployees(id);//人员map - List> shiftsMap = dcWarningMapper.selectShifts(id);//值班map - List> vehiclesMap = dcWarningMapper.selectVehicles(id);//车辆map + List> employeesMap = dcWarningMapper.selectEmployeesDispatch(id,dcWarning.getId());//人员map + List> vehiclesMap = dcWarningMapper.selectVehiclesDispatch(id,dcWarning.getId());//车辆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); + mapAll.put("listData",sortedHashMaps); + HashMap map = dcWarningMapper.selectDcDispatch(dcWarning.getId());//获取机构id与资源id + if (map!=null){ + HashMap hashMap = new HashMap<>(); + Long id = (Long) map.get("id");//调度记录id + Object deptName =map.get("deptName");//部门名称 + List> shifts = dcWarningMapper.selectShiftsEmployees();//值班为空把全部的人员信息作为值班人员信息 + List> resource = dcWarningMapper.selectDispatchResource(id);//全部资源信息 + List> employeesChoice = dcWarningMapper.selectEmployeesChoice(id);//选中人员信息 + List> 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 employeesArray = (ArrayList) 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 vehicleArray = (ArrayList) 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> hashMaps = new ArrayList<>(); - List> mapList = dcWarningMapper.selectRecentlySection();//全部机构的桩号和名称 - for (HashMap 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> sortedHashMaps = hashMaps.stream().sorted(Comparator.comparing(map -> { - return (Double) map.get("difference"); })).collect(Collectors.toList()); - if (!sortedHashMaps.isEmpty()){ - HashMap map = sortedHashMaps.get(0); - Long id = (Long) map.get("id"); - return AjaxResult.success(id); - } - return null; - } } 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 index dff802d2..8937a43e 100644 --- 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 @@ -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; diff --git a/zc-business/src/main/resources/mapper/business/DcWarningMapper.xml b/zc-business/src/main/resources/mapper/business/DcWarningMapper.xml index 7a2d46e2..c854231f 100644 --- a/zc-business/src/main/resources/mapper/business/DcWarningMapper.xml +++ b/zc-business/src/main/resources/mapper/business/DcWarningMapper.xml @@ -172,6 +172,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" start_time, end_time, remark, + dept_id, #{id}, @@ -182,6 +183,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" #{startTime}, #{endTime}, #{remark}, + #{deptId}, @@ -231,6 +233,9 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" #{item.id} + + update dc_dispatch set organization_id=#{organization_id} where id=#{id} + delete from dc_warning where id = #{id} @@ -250,6 +255,9 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" #{item.id} + + delete from dc_dispatch_resource where dispatch_id=#{dispatchId} + + + + + + + + +