Merge remote-tracking branch 'origin/master'
18 files modified
5 files added
| | |
| | | * 岗位id |
| | | */ |
| | | private String postId; |
| | | private String online_status; |
| | | |
| | | @TableField("work_status") |
| | | private String work_status; |
| | |
| | | <groupId>org.springblade</groupId> |
| | | <artifactId>blade-starter-oss-qiniu</artifactId> |
| | | </dependency> |
| | | <dependency> |
| | | <groupId>io.netty</groupId> |
| | | <artifactId>netty-all</artifactId> |
| | | </dependency> |
| | | </dependencies> |
| | | |
| | | </project> |
| | |
| | | import org.springblade.core.launch.BladeApplication; |
| | | import org.springblade.jfpt.nettyServer.Server; |
| | | import org.springblade.jfpt.nettyTcpServer.TcpServer; |
| | | import org.springblade.jfpt.webscoket.WebSocketServer; |
| | | import org.springframework.boot.CommandLineRunner; |
| | | import org.springframework.boot.autoconfigure.SpringBootApplication; |
| | | |
| | |
| | | public void run(String... args) throws Exception { |
| | | Server server=new Server(8088); |
| | | TcpServer tcpServer = new TcpServer(8099); |
| | | WebSocketServer webSocketServer= new WebSocketServer(9034); |
| | | //UdpServer udpServer=new UdpServer(8099); |
| | | } |
| | | |
| | | } |
| | | |
| | |
| | | /** |
| | | *开始时间 |
| | | */ |
| | | private Date begTime; |
| | | private String begTime; |
| | | |
| | | /** |
| | | * 结束时间 |
| | | */ |
| | | private Date endTime; |
| | | private String endTime; |
| | | |
| | | /** |
| | | * 状态 0: 当天时间统计数据 1: 本周内的数据统计 |
| | |
| | | if (status==0 && equipmentVOS.size()>0){ |
| | | for (EquipmentVO e:equipmentVOS) { |
| | | try { |
| | | hearbeat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(e.getHeartbeat()).getTime(); |
| | | if(null!=e.getHeartbeat()) { |
| | | hearbeat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(e.getHeartbeat()).getTime(); |
| | | } |
| | | } catch (ParseException parseException) { |
| | | parseException.printStackTrace(); |
| | | } |
| | |
| | | /** |
| | | *开始时间 |
| | | */ |
| | | private Date begTime; |
| | | private String begTime; |
| | | |
| | | /** |
| | | * 结束时间 |
| | | */ |
| | | private Date endTime; |
| | | private String endTime; |
| | | |
| | | /** |
| | | * 状态 0: 当天时间统计数据 1: 本周内的数据统计 |
| | |
| | | } else if (fqbm.equals("3")) { |
| | | alarm.setWaringType("系统故障"); |
| | | alarm.setContent("扩展模块故障"); |
| | | reason="扩展模块故障"; |
| | | serverHandler.equipmentService.updateExstate(state,reason,devId); |
| | | // reason="扩展模块故障"; |
| | | // serverHandler.equipmentService.updateExstate(state,reason,devId); |
| | | } else if (fqbm.equals("4")) { |
| | | alarm.setWaringType("系统故障"); |
| | | alarm.setContent("中继器故障"); |
| | | reason="中继器故障"; |
| | | serverHandler.equipmentService.updateExstate(state,reason,devId); |
| | | // reason="中继器故障"; |
| | | // serverHandler.equipmentService.updateExstate(state,reason,devId); |
| | | } else if (fqbm.equals("5")) { |
| | | alarm.setWaringType("系统故障"); |
| | | alarm.setContent("打印机缺纸"); |
| | | reason="打印机缺纸"; |
| | | serverHandler.equipmentService.updateExstate(state,reason,devId); |
| | | // reason="打印机缺纸"; |
| | | // serverHandler.equipmentService.updateExstate(state,reason,devId); |
| | | } else if (fqbm.equals("6")) { |
| | | alarm.setWaringType("系统故障"); |
| | | alarm.setContent("打印机故障"); |
| | | reason="打印机故障"; |
| | | serverHandler.equipmentService.updateExstate(state,reason,devId); |
| | | // reason="打印机故障"; |
| | | // serverHandler.equipmentService.updateExstate(state,reason,devId); |
| | | } else if (fqbm.equals("7")) { |
| | | alarm.setWaringType("系统故障"); |
| | | alarm.setContent("扩展模块无直流"); |
| | | reason="扩展模块无直流"; |
| | | serverHandler.equipmentService.updateExstate(state,reason,devId); |
| | | // reason="扩展模块无直流"; |
| | | // serverHandler.equipmentService.updateExstate(state,reason,devId); |
| | | } else if (fqbm.equals("8")) { |
| | | alarm.setWaringType("系统故障"); |
| | | alarm.setContent("扩展模块低电压"); |
| | |
| | | } else if (fqbm.equals("9")) { |
| | | alarm.setWaringType("系统故障"); |
| | | alarm.setContent("扩展模块复位"); |
| | | reason="扩展模块复位"; |
| | | serverHandler.equipmentService.updateExstate(state,reason,devId); |
| | | // reason="扩展模块复位"; |
| | | // serverHandler.equipmentService.updateExstate(state,reason,devId); |
| | | } |
| | | break; |
| | | case "34": |
| | | if (fqbm.equals("1")) { |
| | | alarm.setWaringType("系统故障"); |
| | | alarm.setContent("扩展模块防拆触发"); |
| | | reason="扩展模块防拆触发"; |
| | | serverHandler.equipmentService.updateExstate(state,reason,devId); |
| | | // reason="扩展模块防拆触发"; |
| | | // serverHandler.equipmentService.updateExstate(state,reason,devId); |
| | | } |
| | | break; |
| | | case "35": |
| | |
| | | } else if (fqbm.equals("2")) { |
| | | alarm.setWaringType("系统故障"); |
| | | alarm.setContent("电话接口2故障"); |
| | | reason="电话接口2故障"; |
| | | serverHandler.equipmentService.updateExstate(state,reason,devId); |
| | | // reason="电话接口2故障"; |
| | | // serverHandler.equipmentService.updateExstate(state,reason,devId); |
| | | } else if (fqbm.equals("3")) { |
| | | alarm.setWaringType("通讯故障"); |
| | | alarm.setContent("远距离无线通讯"); |
| | |
| | | if (fqbm.equals("0")) { |
| | | alarm.setWaringType("系统故障-恢复"); |
| | | alarm.setContent("电话线故障-通讯故障(转发)"); |
| | | reason=""; |
| | | serverHandler.equipmentService.updateExstate("",reason,devId); |
| | | } |
| | | else if (fqbm.equals("1")) { |
| | | alarm.setWaringType("系统故障"); |
| | | alarm.setContent("交流电故障-通讯故障(转发)"); |
| | | reason=""; |
| | | serverHandler.equipmentService.updateExstate("",reason,devId); |
| | | } |
| | | else if (fqbm.equals("2")) { |
| | | alarm.setWaringType("系统故障"); |
| | |
| | | else if (fqbm.equals("3")) { |
| | | alarm.setWaringType("系统故障"); |
| | | alarm.setContent("警号/继电器故障-通讯故障(转发)"); |
| | | |
| | | } |
| | | else if (fqbm.equals("4")) { |
| | | alarm.setWaringType("系统故障"); |
| | |
| | | else if (fqbm.equals("7")) { |
| | | alarm.setWaringType("系统故障-恢复"); |
| | | alarm.setContent("交流电故障恢复-通讯故障(转发)"); |
| | | reason=""; |
| | | serverHandler.equipmentService.updateExstate("",reason,devId); |
| | | } |
| | | else if (fqbm.equals("8")) { |
| | | alarm.setWaringType("系统故障-恢复"); |
| | |
| | | else if (fqbm.equals("A")) { |
| | | alarm.setWaringType("系统故障-恢复"); |
| | | alarm.setContent("电话线故障-通讯故障(转发)"); |
| | | reason=""; |
| | | serverHandler.equipmentService.updateExstate("",reason,devId); |
| | | } |
| | | else if (fqbm.equals("B")) { |
| | | alarm.setWaringType("系统故障-恢复"); |
| | | alarm.setContent("回路短路故障恢复-通讯故障(转发)"); |
| | | reason=""; |
| | | serverHandler.equipmentService.updateExstate("",reason,devId); |
| | | } |
| | | else if (fqbm.equals("C")) { |
| | | alarm.setWaringType("系统故障-恢复"); |
| | | alarm.setContent("无线监控恢复-通讯故障(转发)"); |
| | | reason=""; |
| | | serverHandler.equipmentService.updateExstate("",reason,devId); |
| | | } |
| | | else if (fqbm.equals("E")) { |
| | | alarm.setWaringType("系统故障"); |
| | |
| | | else if (fqbm.equals("F")) { |
| | | alarm.setWaringType("系统故障-恢复"); |
| | | alarm.setContent("无线监控故障恢复-通讯故障(转发)"); |
| | | reason=""; |
| | | serverHandler.equipmentService.updateExstate("",reason,devId); |
| | | } |
| | | break; |
| | | case "9B": |
| | |
| | | return R.data(parcelService.getParcelStatis(conditionVo)); |
| | | } |
| | | |
| | | /** |
| | | * 获取图片地址 |
| | | * @param imgUrl 图片url |
| | | * @param response |
| | | * @return |
| | | */ |
| | | @GetMapping("/getParcelPic") |
| | | public R getParcelPic(String imgUrl,HttpServletResponse response){ |
| | | response.setHeader("Access-Control-Allow-Origin", "*"); |
| | | response.setHeader("Access-Control-Allow-Methods", "POST, GET, OPTIONS, DELETE"); |
| | | response.setHeader("Access-Control-Allow-Credentials","true"); |
| | | return R.data(parcelService.getParcelPic(imgUrl)); |
| | | } |
| | | |
| | | /** |
| | | * 获取包裹明细分页数据,远程调用api获取数据 |
| | | * @param conditionVo 请求参数对象 |
| | | * @param response |
| | | * @return |
| | | */ |
| | | @GetMapping("/getParcelDetailPage") |
| | | public R getParcelDetailPage(ConditionVo conditionVo,HttpServletResponse response){ |
| | | response.setHeader("Access-Control-Allow-Origin", "*"); |
| | | response.setHeader("Access-Control-Allow-Methods", "POST, GET, OPTIONS, DELETE"); |
| | | response.setHeader("Access-Control-Allow-Credentials","true"); |
| | | return R.data(parcelService.getParcelDetailPage(conditionVo)); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 获取包裹违禁品明细分页数据,远程调用api获取数据 |
| | | * @param conditionVo 请求参数对象 |
| | | * @param response |
| | | * @return |
| | | */ |
| | | @GetMapping("/getParcelkindDetailPage") |
| | | public R getParcelkindDetailPage(ConditionVo conditionVo,HttpServletResponse response){ |
| | | response.setHeader("Access-Control-Allow-Origin", "*"); |
| | | response.setHeader("Access-Control-Allow-Methods", "POST, GET, OPTIONS, DELETE"); |
| | | response.setHeader("Access-Control-Allow-Credentials","true"); |
| | | return R.data(parcelService.getParcelkindDetailPage(conditionVo)); |
| | | } |
| | | |
| | | |
| | | } |
| | |
| | | * @return |
| | | */ |
| | | Map<String, Object> selectParcelData(); |
| | | |
| | | |
| | | /** |
| | | * 获取图片地址 |
| | | * @param imgUrl 图片Url |
| | | * @return |
| | | */ |
| | | Map<String, String> getParcelPic(String imgUrl); |
| | | |
| | | /** |
| | | * 获取包裹明细分页数据,远程调用api获取数据 |
| | | * @param conditionVo 请求参数对象 |
| | | * @return |
| | | */ |
| | | Object getParcelDetailPage(ConditionVo conditionVo); |
| | | |
| | | /** |
| | | * 获取包裹违禁品明细分页数据,远程调用api获取数据 |
| | | * @param conditionVo 请求参数对象 |
| | | * @return |
| | | */ |
| | | Object getParcelkindDetailPage(ConditionVo conditionVo); |
| | | } |
| | |
| | | package org.springblade.jfpt.parcel.service.impl; |
| | | |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.alibaba.fastjson.JSONArray; |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import io.swagger.models.auth.In; |
| | | import org.springblade.jfpt.parcel.service.ParcelService; |
| | | import org.springblade.jfpt.parcel.util.DateUtils; |
| | | import org.springblade.jfpt.parcel.util.HttpClientUtils; |
| | | import org.springblade.jfpt.parcel.util.JacksonUtil; |
| | | import org.springblade.jfpt.parcel.util.PageList; |
| | | import org.springblade.jfpt.parcel.vo.ConditionVo; |
| | | import org.springframework.beans.factory.annotation.Value; |
| | | import org.springframework.stereotype.Service; |
| | |
| | | |
| | | @Value("${PARCEL_URL}") |
| | | private String PARCEL_URL; |
| | | |
| | | @Value("${PARCEL_PICTURE_URL}") |
| | | private String PARCEL_PICTURE_URL; |
| | | |
| | | @Value("${PARCEL_DETAIL_RUL}") |
| | | private String PARCEL_DETAIL_RUL; |
| | | |
| | | |
| | | |
| | |
| | | public Object getParcelStatis(ConditionVo conditionVo) { |
| | | List<Object> list = new ArrayList<>();//返回 |
| | | //1.判空 |
| | | if (null!=conditionVo.getStatus()){ |
| | | if (null!=conditionVo.getStatus()) { |
| | | //2.获取数据 |
| | | List<Object> objectList = getParcelData(conditionVo,PARCEL_URL,PARCEL_KEY,PARCEL_SECRET); |
| | | System.out.println("objectList = " + objectList); |
| | | //3.创建时间集合,包裹集合数据 |
| | | List<String> listTime = new ArrayList<>(); |
| | | List<Map<String,Object>> parcelList = new ArrayList<>(); |
| | | if (conditionVo.getStatus() == 1) { |
| | | //3.获取今天之前的每一天数组 2021-3-12 arsn修改 |
| | | listTime = DateUtils.pastDay(new SimpleDateFormat("yyyy-MM-dd").format(new Date())); |
| | | List<String> percelTimeList = new ArrayList<>(); |
| | | for (Object object:objectList) { |
| | | //4.取出list里面的值转为map |
| | | Map<String, Object> objectMap = (Map<String, Object>) object; |
| | | //5.将远程时间数据存入集合 |
| | | percelTimeList.add(objectMap.get("dateStr").toString()); |
| | | } |
| | | for (String time:listTime) { |
| | | //6.创建map,用于存储包裹数据 |
| | | HashMap<String, Object> hashMap = new HashMap<>(); |
| | | //7.如果远程数据哪天数据没有,则为0 |
| | | if (!percelTimeList.contains(time)){ |
| | | hashMap.put("dateStr",time); |
| | | hashMap.put("checkCount",0); |
| | | hashMap.put("dangerCount",0); |
| | | parcelList.add(hashMap); |
| | | }else { |
| | | //8.遍历,分别取出数据 |
| | | for (Object object : objectList) { |
| | | //9.取出list里面的值转为map |
| | | Map<String, Object> objectMap = (Map<String, Object>) object; |
| | | String dateStr = objectMap.get("dateStr").toString(); //安检时间 |
| | | Integer checkCount = Integer.parseInt(objectMap.get("checkCount").toString()); //安检包裹数量 |
| | | Integer dangerCount = Integer.parseInt(objectMap.get("dangerCount").toString()); //违禁包裹数量 |
| | | //10.判断,存入数据 |
| | | if (time.equals(dateStr)) { |
| | | Set<Map.Entry<String, Object>> entries = objectMap.entrySet(); |
| | | for (Map.Entry<String, Object> m : entries) { |
| | | if (m.getKey().equals("checkCount")) { |
| | | hashMap.put("checkCount", checkCount); |
| | | hashMap.put("dateStr", dateStr); |
| | | } |
| | | if (m.getKey().equals("dangerCount")) { |
| | | hashMap.put("dangerCount", dangerCount); |
| | | List<Object> objectList = getParcelData(conditionVo, PARCEL_URL, PARCEL_KEY, PARCEL_SECRET); |
| | | if (null != objectList) { |
| | | //3.创建时间集合,包裹集合数据 |
| | | List<String> listTime = new ArrayList<>(); |
| | | List<Map<String, Object>> parcelList = new ArrayList<>(); |
| | | if (conditionVo.getStatus() == 1) { |
| | | //3.获取今天之前的每一天数组 2021-3-12 arsn修改 |
| | | listTime = DateUtils.pastDay(new SimpleDateFormat("yyyy-MM-dd").format(new Date())); |
| | | List<String> percelTimeList = new ArrayList<>(); |
| | | for (Object object : objectList) { |
| | | //4.取出list里面的值转为map |
| | | Map<String, Object> objectMap = (Map<String, Object>) object; |
| | | //5.将远程时间数据存入集合 |
| | | percelTimeList.add(objectMap.get("dateStr").toString()); |
| | | } |
| | | for (String time : listTime) { |
| | | //6.创建map,用于存储包裹数据 |
| | | HashMap<String, Object> hashMap = new HashMap<>(); |
| | | //7.如果远程数据哪天数据没有,则为0 |
| | | if (!percelTimeList.contains(time)) { |
| | | hashMap.put("dateStr", time); |
| | | hashMap.put("checkCount", 0); |
| | | hashMap.put("dangerCount", 0); |
| | | parcelList.add(hashMap); |
| | | } else { |
| | | //8.遍历,分别取出数据 |
| | | for (Object object : objectList) { |
| | | //9.取出list里面的值转为map |
| | | Map<String, Object> objectMap = (Map<String, Object>) object; |
| | | String dateStr = objectMap.get("dateStr").toString(); //安检时间 |
| | | Integer checkCount = Integer.parseInt(objectMap.get("checkCount").toString()); //安检包裹数量 |
| | | Integer dangerCount = Integer.parseInt(objectMap.get("dangerCount").toString()); //违禁包裹数量 |
| | | //10.判断,存入数据 |
| | | if (time.equals(dateStr)) { |
| | | Set<Map.Entry<String, Object>> entries = objectMap.entrySet(); |
| | | for (Map.Entry<String, Object> m : entries) { |
| | | if (m.getKey().equals("checkCount")) { |
| | | hashMap.put("checkCount", checkCount); |
| | | hashMap.put("dateStr", dateStr); |
| | | } |
| | | if (m.getKey().equals("dangerCount")) { |
| | | hashMap.put("dangerCount", dangerCount); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | //11.加入到集合中 |
| | | parcelList.add(hashMap); |
| | | } |
| | | //11.加入到集合中 |
| | | parcelList.add(hashMap); |
| | | } |
| | | } |
| | | //12.封装数据 |
| | | list.add(listTime); |
| | | list.add(parcelList); |
| | | list.add(getKindServenDataList()); |
| | | //13.返回 |
| | | return list; |
| | | } |
| | | //12.封装数据 |
| | | list.add(listTime); |
| | | list.add(parcelList); |
| | | list.add(getKindServenDataList()); |
| | | //13.返回 |
| | | return list; |
| | | } |
| | | return null; |
| | | } |
| | |
| | | */ |
| | | private List<Object> getParcelData(ConditionVo conditionVo, String url, String key, String secret) { |
| | | //1.创建map对象,用于存储请求接口的秘钥 |
| | | Map<String, String> map = new HashMap<>(); |
| | | Map<String, Object> map = new HashMap<>(); |
| | | String startDate = null; |
| | | String endDate = null; |
| | | //2.2查询本天的数据 |
| | |
| | | String params = HttpClientUtils.httpPost(url, key, secret, map); |
| | | //5.数据转换 |
| | | Map<String, Object> data = (Map<String, Object>) JSONObject.parse(params); |
| | | //System.out.println("data = " + data); |
| | | return JSON.parseArray(data.get("result").toString()); |
| | | if (data.get("succ").toString().equals("ok")){ |
| | | //6.返回数据 |
| | | return JSON.parseArray(data.get("result").toString()); |
| | | } |
| | | return null; |
| | | } |
| | | |
| | | |
| | |
| | | conditionVo.setStatus(status); |
| | | //获取包裹数据 |
| | | List<Object> parcelData = getParcelData(conditionVo, PARCEL_URL, PARCEL_KEY, PARCEL_SECRET); |
| | | //查询当天的包裹总数 |
| | | Integer dangerCount = null; |
| | | Integer contrabandCount = null; |
| | | if (status == 0) { |
| | | for (Object object : parcelData) { |
| | | //取出list里面的值转为map |
| | | Map<String, Object> objectMap = (Map<String, Object>) object; |
| | | dangerCount = Integer.parseInt(objectMap.get("dangerCount").toString()); //违禁包裹数量 |
| | | contrabandCount = Integer.parseInt(objectMap.get("contrabandCount").toString()); //违禁物品数量 |
| | | if (null!=parcelData) { |
| | | //查询当天的包裹总数 |
| | | Integer dangerCount = null; |
| | | Integer contrabandCount = null; |
| | | if (status == 0) { |
| | | for (Object object : parcelData) { |
| | | //取出list里面的值转为map |
| | | Map<String, Object> objectMap = (Map<String, Object>) object; |
| | | dangerCount = Integer.parseInt(objectMap.get("dangerCount").toString()); //违禁包裹数量 |
| | | contrabandCount = Integer.parseInt(objectMap.get("contrabandCount").toString()); //违禁物品数量 |
| | | } |
| | | } |
| | | //封装数据 |
| | | list.add(dangerCount); |
| | | list.add(contrabandCount); |
| | | //返回数据 |
| | | return list; |
| | | } |
| | | //封装数据 |
| | | list.add(dangerCount); |
| | | list.add(contrabandCount); |
| | | //返回数据 |
| | | return list; |
| | | return null; |
| | | } |
| | | |
| | | /** |
| | |
| | | conditionVo.setStatus(1);//近7天status 为 1 |
| | | //获取数据 |
| | | List<Object> objectList = getParcelData(conditionVo,PARCEL_CONTRABAND_URL,PARCEL_KEY,PARCEL_SECRET); |
| | | //遍历违禁编码map数据 |
| | | List<String> times = DateUtils.pastDay(new SimpleDateFormat("yyyy-MM-dd").format(new Date())); |
| | | List<Integer> list = new ArrayList<>(); |
| | | for (String time:times) { |
| | | Integer count = 0; |
| | | //遍历集合数据获取每一天的count |
| | | for (Object object : objectList) { |
| | | Map<String, Object> objectMap = (Map<String, Object>) object;//取出list里面的值转为map |
| | | //对比时间和objCode,危险品,刀具,枪支等 |
| | | if (time.equals(objectMap.get("dateStr").toString()) ){ |
| | | if (null!=objectList) { |
| | | //遍历违禁编码map数据 |
| | | List<String> times = DateUtils.pastDay(new SimpleDateFormat("yyyy-MM-dd").format(new Date())); |
| | | List<Integer> list = new ArrayList<>(); |
| | | for (String time : times) { |
| | | Integer count = 0; |
| | | //遍历集合数据获取每一天的count |
| | | for (Object object : objectList) { |
| | | Map<String, Object> objectMap = (Map<String, Object>) object;//取出list里面的值转为map |
| | | //对比时间和objCode,危险品,刀具,枪支等 |
| | | if (time.equals(objectMap.get("dateStr").toString())) { |
| | | // //枪支 |
| | | // if (objectMap.get("objCode").toString().equals("gan")) { |
| | | // count += Integer.parseInt(objectMap.get("objCount").toString()); |
| | |
| | | // if (objectMap.get("objCode").toString().equals("boomExplosive")) { |
| | | // count += Integer.parseInt(objectMap.get("objCount").toString()); |
| | | // } |
| | | //3-20 修改不筛选危险品,由第三方筛选好 |
| | | count += Integer.parseInt(objectMap.get("objCount").toString()); |
| | | //3-20 修改不筛选危险品,由第三方筛选好 |
| | | count += Integer.parseInt(objectMap.get("objCount").toString()); |
| | | } |
| | | } |
| | | list.add(count); |
| | | } |
| | | return list; |
| | | } |
| | | return null; |
| | | } |
| | | |
| | | /** |
| | | * 获取图片地址 |
| | | * @param imgUrl 图片Url |
| | | * @return |
| | | */ |
| | | @Override |
| | | public Map<String, String> getParcelPic(String imgUrl) { |
| | | //截取图片imgKey信息 |
| | | String[] imgKeys = imgUrl.split("=", imgUrl.length()); |
| | | String imgKey = imgKeys[1]; |
| | | //封装成map对象 |
| | | HashMap<String, String> map = new HashMap<>(); |
| | | map.put("imgKey",imgKey); |
| | | //执行http远程调用 |
| | | String s = HttpClientUtils.doGetHeaderPictureBase64(PARCEL_PICTURE_URL, PARCEL_KEY, PARCEL_SECRET, map); |
| | | map.put("imgBase64",s); |
| | | return map; |
| | | } |
| | | |
| | | /** |
| | | * 获取包裹明细分页数据,远程调用api获取数据 |
| | | * @param conditionVo 请求参数对象 |
| | | * @return |
| | | */ |
| | | @Override |
| | | public Object getParcelDetailPage(ConditionVo conditionVo) { |
| | | String result = getParcelDataPageList(conditionVo, PARCEL_DETAIL_RUL, PARCEL_KEY, PARCEL_SECRET).get("result").toString(); |
| | | if (null!=result) { |
| | | return JSONObject.parse(result); |
| | | } |
| | | return null; |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 获取包裹违禁品明细分页数据,远程调用api获取数据 |
| | | * @param conditionVo 请求参数对象 |
| | | * @return |
| | | */ |
| | | @Override |
| | | public Object getParcelkindDetailPage(ConditionVo conditionVo) { |
| | | conditionVo.setDecisioDiagramResult("contraband"); |
| | | Map<Object, Object> map = new HashMap<>(); |
| | | List<Object> list = new ArrayList<>(); |
| | | //获取违禁包裹数据 |
| | | Map<String,Object> result = (Map<String,Object>)getParcelDataPageList(conditionVo, PARCEL_DETAIL_RUL, PARCEL_KEY, PARCEL_SECRET).get("result"); |
| | | if (null!=result) { |
| | | //获取总违禁包裹数量 |
| | | Integer totalSize = Integer.parseInt(result.get("totalSize").toString()); |
| | | int total = totalSize/conditionVo.getCurrentPage() +1 ; |
| | | for (int i = 0;i<total;i++){ |
| | | conditionVo.setCurrentPage(i+1); |
| | | //获取违禁包裹数据 |
| | | Map<String,Object> resultData = (Map<String,Object>)getParcelDataPageList(conditionVo, PARCEL_DETAIL_RUL, PARCEL_KEY, PARCEL_SECRET).get("result"); |
| | | //提取违禁品数据 |
| | | List<Object> dataList = JSON.parseArray(resultData.get("data").toString()); |
| | | for (Object data : dataList) { |
| | | //取出list里面的值转为map |
| | | Map<String, Object> objectMap = (Map<String, Object>) data; |
| | | //获取违禁包裹名称,包裹Id,包裹图片,过机时间 |
| | | String checkMachineName = objectMap.get("checkMachineName").toString(); |
| | | String packageId = objectMap.get("packageId").toString(); |
| | | String imgUrl = objectMap.get("imgUrl").toString(); |
| | | String samplingTime = objectMap.get("samplingTime").toString(); |
| | | //获取违禁品集合数据 |
| | | List<Object> detailVoList = JSON.parseArray(objectMap.get("coordsDetailVoList").toString()); |
| | | //遍历违禁品集合数据 |
| | | for (Object detailVo : detailVoList) { |
| | | //封装违禁包裹信息 |
| | | Map<String, Object> detailVoMap = (Map<String, Object>) detailVo; |
| | | detailVoMap.put("checkMachineName", checkMachineName); |
| | | detailVoMap.put("packageId", packageId); |
| | | detailVoMap.put("imgUrl", imgUrl); |
| | | detailVoMap.put("samplingTime", samplingTime); |
| | | list.add(detailVoMap); |
| | | } |
| | | } |
| | | } |
| | | list.add(count); |
| | | //对组装好的违禁品集合数据排序,按时间 |
| | | //分页 |
| | | List<Object> listPaging = PageList.getListPaging(list, conditionVo.getCurrentPage(), conditionVo.getPageSize()); |
| | | //封装数据 |
| | | map.put("totalSize", list.size()); |
| | | map.put("data", listPaging); |
| | | map.put("currentPage", conditionVo.getCurrentPage()); |
| | | map.put("pageSize", conditionVo.getPageSize()); |
| | | //返回数据 |
| | | return map; |
| | | } |
| | | return list; |
| | | return null; |
| | | } |
| | | |
| | | /** |
| | | * 远程调用api 获取违禁品详细数据 |
| | | * @param conditionVo 条件 |
| | | * @param url 违禁品详细数据Url |
| | | * @param key key |
| | | * @param secret 秘钥 |
| | | * @return |
| | | */ |
| | | public Map<String,Object> getParcelDataPageList(ConditionVo conditionVo, String url, String key, String secret){ |
| | | //1.创建map对象存储数据 |
| | | HashMap<String, Object> map = new HashMap<>(); |
| | | //2.条件判断 |
| | | if (null!=conditionVo.getStartTime()){ |
| | | map.put("startTime", conditionVo.getStartTime()); |
| | | } |
| | | if (null!=conditionVo.getEndTime()){ |
| | | map.put("endTime", conditionVo.getEndTime()); |
| | | } |
| | | if (null!=conditionVo.getDecisioDiagramResult()){ |
| | | map.put("decisioDiagramResult", conditionVo.getDecisioDiagramResult()); |
| | | } |
| | | if (null!=conditionVo.getCurrentPage()){ |
| | | map.put("currentPage", conditionVo.getCurrentPage()); |
| | | } |
| | | if (null!=conditionVo.getPageSize()){ |
| | | map.put("pageSize", conditionVo.getPageSize()); |
| | | } |
| | | //3.远程调用api 获取数据 |
| | | String params = HttpClientUtils.httpPost(PARCEL_DETAIL_RUL, PARCEL_KEY, PARCEL_SECRET, map); |
| | | Map<String,Object> paramsMap = (Map<String, Object>) JSONObject.parse(params); |
| | | if (paramsMap.get("succ").toString().equals("ok")){ |
| | | //4返回数据 |
| | | return paramsMap; |
| | | } |
| | | //4返回数据 |
| | | return null; |
| | | } |
| | | |
| | | } |
| | |
| | | import org.apache.http.message.BasicNameValuePair; |
| | | import org.apache.http.ssl.SSLContextBuilder; |
| | | import org.apache.http.util.EntityUtils; |
| | | import sun.misc.BASE64Encoder; |
| | | |
| | | import javax.net.ssl.SSLContext; |
| | | |
| | |
| | | |
| | | HttpGet get = new HttpGet(builder.build()); |
| | | |
| | | |
| | | response = httpclient.execute(get); |
| | | |
| | | System.out.println(response.getStatusLine()); |
| | | |
| | | if (200 == response.getStatusLine().getStatusCode()) { |
| | | HttpEntity entity = response.getEntity(); |
| | | System.out.println(entity.toString()); |
| | | resultString = EntityUtils.toString(entity, "utf-8"); |
| | | System.out.println(resultString.toString()); |
| | | } |
| | | |
| | | } catch (Exception e) { |
| | |
| | | |
| | | return resultString; |
| | | } |
| | | |
| | | /** |
| | | * 执行有参GET请求,带请求头 |
| | | * |
| | | * @param url 请求url |
| | | * @param params 参数 |
| | | * @param key 请求头Key |
| | | * @param secretKey 秘钥 |
| | | * @return |
| | | */ |
| | | public static String doGetHeader(String url, String key, String secretKey,Map<String, String> params) { |
| | | |
| | | //获取httpclient客户端 |
| | | CloseableHttpClient httpclient = HttpClients.createDefault(); |
| | | |
| | | String resultString = ""; |
| | | |
| | | CloseableHttpResponse response = null; |
| | | |
| | | try { |
| | | URIBuilder builder = new URIBuilder(url); |
| | | |
| | | if (null != params) { |
| | | for (String keys : params.keySet()) { |
| | | builder.addParameter(keys,params.get(keys)); |
| | | //builder.setParameter(keys, params.get(keys)); |
| | | } |
| | | } |
| | | |
| | | HttpGet httpGet = new HttpGet(builder.build()); |
| | | |
| | | //设置请求头 |
| | | httpGet.addHeader(key,secretKey); |
| | | // 传输的类型 |
| | | httpGet.addHeader("Content-Type", "application/x-www-form-urlencoded"); |
| | | //执行Http请求调用 |
| | | response = httpclient.execute(httpGet); |
| | | //判断是否请求成功返回 |
| | | if (200 == response.getStatusLine().getStatusCode()) { |
| | | HttpEntity entity = response.getEntity(); |
| | | resultString = EntityUtils.toString(entity, "utf-8"); |
| | | } |
| | | |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } finally { |
| | | if (null != response) { |
| | | try { |
| | | response.close(); |
| | | } catch (IOException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | if (null != httpclient) { |
| | | try { |
| | | httpclient.close(); |
| | | } catch (IOException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | } |
| | | |
| | | return resultString; |
| | | } |
| | | |
| | | /** |
| | | * 执行有参GET请求,带请求头,接收图片流 |
| | | * |
| | | * @param url 请求url |
| | | * @param params 参数 |
| | | * @param key 请求头Key |
| | | * @param secretKey 秘钥 |
| | | * @return |
| | | */ |
| | | public static String doGetHeaderPictureBase64(String url, String key, String secretKey,Map<String, String> params) { |
| | | |
| | | //获取httpclient客户端 |
| | | CloseableHttpClient httpclient = HttpClients.createDefault(); |
| | | String resultString = ""; |
| | | CloseableHttpResponse response = null; |
| | | try { |
| | | URIBuilder builder = new URIBuilder(url); |
| | | if (null != params) { |
| | | for (String keys : params.keySet()) { |
| | | builder.addParameter(keys,params.get(keys)); |
| | | } |
| | | } |
| | | HttpGet httpGet = new HttpGet(builder.build()); |
| | | //设置请求头 |
| | | httpGet.addHeader(key,secretKey); |
| | | // 传输的类型 |
| | | httpGet.addHeader("Content-Type", "application/x-www-form-urlencoded"); |
| | | //执行Http请求调用 |
| | | response = httpclient.execute(httpGet); |
| | | // 将返回的图片或者文件转化成字节数组的形式 |
| | | byte[] data = EntityUtils.toByteArray(response.getEntity()); |
| | | BASE64Encoder encoder = new BASE64Encoder(); |
| | | //String imageBase64 = "data:image/png;base64," + encoder.encodeBuffer(data).trim(); |
| | | return encoder.encodeBuffer(data).trim().replaceAll("\n", "").replaceAll("\r", "").replaceAll(" ", "");//删除 \r\n |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } finally { |
| | | if (null != response) { |
| | | try { |
| | | response.close(); |
| | | } catch (IOException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | if (null != httpclient) { |
| | | try { |
| | | httpclient.close(); |
| | | } catch (IOException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | } |
| | | return resultString; |
| | | } |
| | | |
| | | /** |
| | | * 执行无参GET请求 |
| | |
| | | * @param map |
| | | * @return |
| | | */ |
| | | public static String httpPost(String url, String appKey, String appKeyValue, Map<String, String> map) { |
| | | public static String httpPost(String url, String appKey, String appKeyValue, Map<String, Object> map) { |
| | | // 返回body |
| | | String body = null; |
| | | // 获取连接客户端工具 |
| New file |
| | |
| | | package org.springblade.jfpt.parcel.util; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | | |
| | | public class PageList { |
| | | /** |
| | | * 分页 |
| | | * |
| | | * @param list 集合 |
| | | * @param pageNum 页码 |
| | | * @param pageSize 页码数量 |
| | | * @param <T> 泛型 |
| | | * @return 返回当前页数据 |
| | | */ |
| | | public static <T> List<T> getListPaging(List<T> list, int pageNum, int pageSize) { |
| | | if (list == null || list.size() <= 0) { |
| | | return new ArrayList<>(0); |
| | | } |
| | | //开始下标 |
| | | int startIndex = (pageNum - 1) * pageSize; |
| | | //结束下标 subList()方法不包含结束下标的元素 |
| | | int endIndex = pageNum * pageSize; |
| | | //list总条数 |
| | | int total = list.size(); |
| | | //总页数 |
| | | int pageCount = 0; |
| | | //通过取余决定是否给总页数加1 |
| | | int num = total % pageSize; |
| | | if (num == 0) { |
| | | pageCount = total / pageSize; |
| | | } else { |
| | | pageCount = total / pageSize + 1; |
| | | } |
| | | //如果当前页是最后一页的话 要包含集合的最后一条数据,因为sublist方法本身结束的下标是不包含当前元素的 |
| | | if (pageNum == pageCount) { |
| | | endIndex = total; |
| | | } |
| | | return list.subList(startIndex, endIndex); |
| | | } |
| | | } |
| | |
| | | private String endDate; |
| | | |
| | | /** |
| | | * 开始时间 |
| | | */ |
| | | private String startTime; |
| | | /** |
| | | * 结束时间 |
| | | */ |
| | | private String endTime; |
| | | |
| | | /** |
| | | * 状态码 0:本天 1:本周 2:本月 |
| | | */ |
| | | private Integer status; |
| | | |
| | | /** |
| | | * 是否为违禁品 contraband-违禁物品 normal-非违禁物品 |
| | | */ |
| | | private String decisioDiagramResult; |
| | | |
| | | /** |
| | | * 分页页码 |
| | | */ |
| | | private Integer currentPage; |
| | | |
| | | /** |
| | | * 分页记录数 |
| | | */ |
| | | private Integer pageSize; |
| | | } |
| | |
| | | List<SuserVOs> selectName(); |
| | | String selectNames(String ud); |
| | | void updateOne(Integer id, String ynumber, String yname, String phone, String address, String type, String dj, String information, String jd, String wd, String createtime, String addvcd); |
| | | void updateUser(String online_status,String account); |
| | | |
| | | void s(String ynumber, String yname, String phone, String address, String type, String dj, String information, String jd, String wd, String createtime, String addvcd); |
| | | |
| | | /** |
| | |
| | | select count(*) from sys_suser where is_delete=0 |
| | | </select> |
| | | |
| | | <update id="updateUser"> |
| | | update jfpth.blade_user SET online_status=#{online_status} where account=#{account} |
| | | </update> |
| | | |
| | | </mapper> |
| | |
| | | String selectNames(String ud); |
| | | void updateOne(Integer id, String ynumber, String yname, String phone, String address, String type, String dj, String information, String jd, String wd, String createtime, String addvcd); |
| | | void s(String ynumber, String yname, String phone, String address, String type, String dj, String information, String jd, String wd, String createtime, String addvcd); |
| | | |
| | | void updateUser(String online_status,String account); |
| | | /** |
| | | * 查询业主总数 |
| | | * @return |
| | |
| | | baseMapper.s(ynumber, yname, phone, address, type, dj, information, jd, wd,createtime,addvcd); |
| | | } |
| | | |
| | | @Override |
| | | public void updateUser(String online_status, String account) { |
| | | baseMapper.updateUser(online_status, account); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 查询业主总数 |
| | | * @return |
| New file |
| | |
| | | package org.springblade.jfpt.webscoket; |
| | | import io.netty.channel.Channel; |
| | | import io.netty.channel.ChannelId; |
| | | import io.netty.channel.group.ChannelGroup; |
| | | import io.netty.channel.group.DefaultChannelGroup; |
| | | import io.netty.handler.codec.http.websocketx.TextWebSocketFrame; |
| | | import io.netty.util.concurrent.GlobalEventExecutor; |
| | | |
| | | import java.util.HashMap; |
| | | import java.util.Map; |
| | | import java.util.concurrent.ConcurrentHashMap; |
| | | import java.util.concurrent.ConcurrentMap; |
| | | public class ChannelSupervise { |
| | | private static ChannelGroup GlobalGroup=new DefaultChannelGroup(GlobalEventExecutor.INSTANCE); |
| | | private static ConcurrentMap<String, ChannelId> ChannelMap=new ConcurrentHashMap(); |
| | | private static Map<String, String> map = new HashMap<String, String>();; |
| | | public static void addChannel(Channel channel,String name){ |
| | | GlobalGroup.add(channel); |
| | | ChannelMap.put(channel.id().asShortText(),channel.id()); |
| | | map.put(channel.id().asShortText(),name); |
| | | } |
| | | public static void removeChannel(Channel channel){ |
| | | GlobalGroup.remove(channel); |
| | | ChannelMap.remove(channel.id().asShortText()); |
| | | map.remove(channel.id().asShortText()); |
| | | } |
| | | public static Channel findChannel(String id){ |
| | | return GlobalGroup.find(ChannelMap.get(id)); |
| | | } |
| | | public static String findName(String id){ |
| | | return map.get(id); |
| | | } |
| | | public static void send2All(TextWebSocketFrame tws){ |
| | | GlobalGroup.writeAndFlush(tws); |
| | | } |
| | | |
| | | } |
| New file |
| | |
| | | package org.springblade.jfpt.webscoket; |
| | | |
| | | import io.netty.buffer.ByteBuf; |
| | | import io.netty.buffer.Unpooled; |
| | | import io.netty.channel.*; |
| | | import io.netty.handler.codec.http.DefaultFullHttpResponse; |
| | | import io.netty.handler.codec.http.FullHttpRequest; |
| | | import io.netty.handler.codec.http.HttpResponseStatus; |
| | | import io.netty.handler.codec.http.HttpVersion; |
| | | import io.netty.handler.codec.http.websocketx.CloseWebSocketFrame; |
| | | import io.netty.handler.codec.http.websocketx.PingWebSocketFrame; |
| | | import io.netty.handler.codec.http.websocketx.PongWebSocketFrame; |
| | | import io.netty.handler.codec.http.websocketx.TextWebSocketFrame; |
| | | import io.netty.handler.codec.http.websocketx.WebSocketFrame; |
| | | import io.netty.handler.codec.http.websocketx.WebSocketServerHandshaker; |
| | | import io.netty.handler.codec.http.websocketx.WebSocketServerHandshakerFactory; |
| | | import io.netty.util.CharsetUtil; |
| | | import java.util.Date; |
| | | |
| | | import org.springblade.jfpt.suser.service.ISuserService; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Component; |
| | | |
| | | import javax.annotation.PostConstruct; |
| | | |
| | | @Component |
| | | public class WebSocketHandler extends SimpleChannelInboundHandler<Object> { |
| | | |
| | | private WebSocketServerHandshaker handshaker; |
| | | |
| | | private String on=null; |
| | | |
| | | @Autowired |
| | | private ISuserService suserService; |
| | | |
| | | private static WebSocketHandler webSocketHandler; |
| | | |
| | | @PostConstruct |
| | | public void init() { |
| | | webSocketHandler = this; |
| | | } |
| | | |
| | | @Override |
| | | protected void channelRead0(ChannelHandlerContext ctx, Object msg) throws Exception { |
| | | if (msg instanceof FullHttpRequest) { |
| | | //以http请求形式接入,但是走的是websocket |
| | | handleHttpRequest(ctx, (FullHttpRequest) msg); |
| | | } else if (msg instanceof WebSocketFrame) { |
| | | //处理websocket客户端的消息 |
| | | handlerWebSocketFrame(ctx, (WebSocketFrame) msg); |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public void channelActive(ChannelHandlerContext ctx) throws Exception { |
| | | //添加连接 |
| | | System.out.println("客户端加入连接:" + ctx.channel()); |
| | | //ChannelSupervise.addChannel(ctx.channel()); |
| | | } |
| | | |
| | | @Override |
| | | public void channelInactive(ChannelHandlerContext ctx) throws Exception { |
| | | //断开连接 |
| | | System.out.println("客户端断开连接:" + ctx.channel()); |
| | | //用户离线状态 |
| | | String name = ChannelSupervise.findName(ctx.channel().id().asShortText()); |
| | | String num="0"; |
| | | webSocketHandler.suserService.updateUser(num,name); |
| | | ChannelSupervise.removeChannel(ctx.channel()); |
| | | } |
| | | |
| | | @Override |
| | | public void channelReadComplete(ChannelHandlerContext ctx) throws Exception { |
| | | ctx.flush(); |
| | | } |
| | | |
| | | private void handlerWebSocketFrame(ChannelHandlerContext ctx, WebSocketFrame frame) throws NumberFormatException, Exception { |
| | | // 判断是否关闭链路的指令 |
| | | if (frame instanceof CloseWebSocketFrame) { |
| | | handshaker.close(ctx.channel(), (CloseWebSocketFrame) frame.retain()); |
| | | return; |
| | | } |
| | | // 判断是否ping消息 |
| | | if (frame instanceof PingWebSocketFrame) { |
| | | ctx.channel().write( |
| | | new PongWebSocketFrame(frame.content().retain())); |
| | | return; |
| | | } |
| | | // 本例程仅支持文本消息,不支持二进制消息 |
| | | if (!(frame instanceof TextWebSocketFrame)) { |
| | | System.out.println("本例程仅支持文本消息,不支持二进制消息"); |
| | | throw new UnsupportedOperationException(String.format( |
| | | "%s frame types not supported", frame.getClass().getName())); |
| | | } |
| | | // 返回应答消息 |
| | | String request = ((TextWebSocketFrame) frame).text(); |
| | | //把用户信息添加到通道里 |
| | | ChannelSupervise.addChannel(ctx.channel(),request); |
| | | //用户在线状态 |
| | | this.on=request; |
| | | String num="1"; |
| | | webSocketHandler.suserService.updateUser(num,request); |
| | | TextWebSocketFrame tws = new TextWebSocketFrame(new Date().toString() |
| | | + ctx.channel().id() + ":" + ctx.channel()); |
| | | // 返回【谁发的发给谁】 |
| | | |
| | | ctx.channel().writeAndFlush(tws); |
| | | // 群发 |
| | | // ChannelSupervise.send2All(tws); |
| | | } |
| | | |
| | | /** |
| | | * 唯一的一次http请求,用于创建websocket |
| | | * |
| | | * @throws InterruptedException |
| | | */ |
| | | private void handleHttpRequest(final ChannelHandlerContext ctx, |
| | | FullHttpRequest req) throws InterruptedException { |
| | | //要求Upgrade为websocket,过滤掉get/Post |
| | | if (!req.decoderResult().isSuccess() || (!"websocket".equals(req.headers().get("Upgrade")))) { |
| | | //若不是websocket方式,则创建BAD_REQUEST的req,返回给客户端 |
| | | sendHttpResponse(ctx, req, new DefaultFullHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.BAD_REQUEST)); |
| | | return; |
| | | } |
| | | //握手 |
| | | WebSocketServerHandshakerFactory wsFactory = new WebSocketServerHandshakerFactory( |
| | | "ws://localhost:9034/websocket", null, false); |
| | | handshaker = wsFactory.newHandshaker(req); |
| | | if (handshaker == null) { |
| | | WebSocketServerHandshakerFactory |
| | | .sendUnsupportedVersionResponse(ctx.channel()); |
| | | } else { |
| | | handshaker.handshake(ctx.channel(), req); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 拒绝不合法的请求,并返回错误信息 |
| | | */ |
| | | private static void sendHttpResponse(ChannelHandlerContext ctx, |
| | | FullHttpRequest req, DefaultFullHttpResponse res) { |
| | | // 返回应答给客户端 |
| | | if (res.status().code() != 200) { |
| | | ByteBuf buf = Unpooled.copiedBuffer(res.status().toString(), |
| | | CharsetUtil.UTF_8); |
| | | res.content().writeBytes(buf); |
| | | buf.release(); |
| | | } |
| | | ChannelFuture f = ctx.channel().writeAndFlush(res); |
| | | // 如果是非Keep-Alive,关闭连接 |
| | | // if (!isKeepAlive(req) || res.status().code() != 200) { |
| | | // f.addListener(ChannelFutureListener.CLOSE); |
| | | // } |
| | | } |
| | | @Override |
| | | public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception { |
| | | cause.printStackTrace(); |
| | | ctx.close(); |
| | | } |
| | | |
| | | } |
| New file |
| | |
| | | package org.springblade.jfpt.webscoket; |
| | | import io.netty.bootstrap.ServerBootstrap; |
| | | import io.netty.channel.ChannelFuture; |
| | | import io.netty.channel.ChannelInitializer; |
| | | import io.netty.channel.ChannelOption; |
| | | import io.netty.channel.EventLoopGroup; |
| | | import io.netty.channel.nio.NioEventLoopGroup; |
| | | import io.netty.channel.socket.SocketChannel; |
| | | import io.netty.channel.socket.nio.NioServerSocketChannel; |
| | | import io.netty.handler.codec.http.HttpObjectAggregator; |
| | | import io.netty.handler.codec.http.HttpServerCodec; |
| | | import io.netty.handler.logging.LogLevel; |
| | | import io.netty.handler.logging.LoggingHandler; |
| | | import io.netty.handler.stream.ChunkedWriteHandler; |
| | | public class WebSocketServer { |
| | | private int port = 9034; |
| | | |
| | | public WebSocketServer(int port) { |
| | | bind(port); |
| | | } |
| | | |
| | | public void bind(int port) { |
| | | Thread thread = new Thread(new Runnable() { |
| | | @Override |
| | | public void run() { |
| | | EventLoopGroup bossGroup = new NioEventLoopGroup(); |
| | | EventLoopGroup workerGroup = new NioEventLoopGroup(); |
| | | try { |
| | | ServerBootstrap serverBootstrap = new ServerBootstrap(); |
| | | serverBootstrap.group(bossGroup, workerGroup).channel(NioServerSocketChannel.class) |
| | | .handler(new LoggingHandler(LogLevel.INFO)) |
| | | //保持连接 |
| | | .childOption(ChannelOption.SO_KEEPALIVE, true) |
| | | .childHandler(new ChannelInitializer<SocketChannel>() { |
| | | @Override |
| | | protected void initChannel(SocketChannel ch) { |
| | | // ch.pipeline().addLast("logging",new LoggingHandler("DEBUG"));//设置log监听器,并且日志级别为debug,方便观察运行流程 |
| | | ch.pipeline().addLast("http-codec", new HttpServerCodec());//设置解码器 |
| | | ch.pipeline().addLast("aggregator", new HttpObjectAggregator(65536));//聚合器,使用websocket会用到 |
| | | ch.pipeline().addLast("http-chunked", new ChunkedWriteHandler());//用于大数据的分区传输 |
| | | ch.pipeline().addLast("handler", new WebSocketHandler());//自定义的业务handler |
| | | } |
| | | }); |
| | | |
| | | ChannelFuture channelFuture = serverBootstrap.bind(port).sync(); |
| | | System.out.println("WebSocketServer启动成功"); |
| | | channelFuture.channel().closeFuture().sync(); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } finally { |
| | | bossGroup.shutdownGracefully(); |
| | | workerGroup.shutdownGracefully(); |
| | | } |
| | | } |
| | | }); |
| | | thread.start(); |
| | | } |
| | | } |
| New file |
| | |
| | | <html> |
| | | <head> |
| | | <meta http-equiv="Content-Type" content="text/html; charset = utf-8"/> |
| | | <title>WebSocket客户端</title> |
| | | <script type="text/javascript"> |
| | | var socket; |
| | | if(!window.WebSocket){ |
| | | window.WebSocket = window.MozWebSocket; |
| | | } |
| | | |
| | | if(window.WebSocket){ |
| | | socket = new WebSocket("ws://localhost:9034/websocket"); |
| | | socket.onmessage = function(event){ |
| | | var ta = document.getElementById('responseContent'); |
| | | ta.value += event.data + "\r\n"; |
| | | }; |
| | | |
| | | socket.onopen = function(event){ |
| | | var ta = document.getElementById('responseContent'); |
| | | ta.value = "你当前的浏览器支持WebSocket,请进行后续操作\r\n"; |
| | | }; |
| | | |
| | | socket.onclose = function(event){ |
| | | var ta = document.getElementById('responseContent'); |
| | | ta.value = ""; |
| | | |
| | | ta.value = "WebSocket连接已经关闭\r\n"; |
| | | }; |
| | | }else{ |
| | | alert("您的浏览器不支持WebSocket"); |
| | | } |
| | | |
| | | |
| | | |
| | | function send(message){ |
| | | if(!window.WebSocket){ |
| | | return; |
| | | } |
| | | if(socket.readyState == WebSocket.OPEN){ |
| | | socket.send(message); |
| | | }else{ |
| | | alert("WebSocket连接没有建立成功!!"); |
| | | } |
| | | } |
| | | </script> |
| | | </head> |
| | | <body> |
| | | <form onSubmit="return false;"> |
| | | <input type = "text" name = "message" value = ""/> |
| | | <br/><br/> |
| | | <input type = "button" value = "发送WebSocket请求消息" onClick = "send(this.form.message.value)"/> |
| | | <hr color="red"/> |
| | | <h2>客户端接收到服务端返回的应答消息</h2> |
| | | <textarea id = "responseContent" style = "width:1024px; height:300px"></textarea> |
| | | </form> |
| | | </body> |
| | | </html> |
| | |
| | | import springfox.documentation.annotations.ApiIgnore; |
| | | |
| | | import javax.validation.Valid; |
| | | import java.text.ParseException; |
| | | import java.text.SimpleDateFormat; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | |
| | | @ApiOperationSupport(order = 2) |
| | | @ApiOperation(value = "分页", notes = "传入tenant") |
| | | //@PreAuth(RoleConstant.HAS_ROLE_ADMIN) |
| | | public R<IPage<Tenant>> list(@ApiIgnore @RequestParam Map<String, Object> tenant, Query query, BladeUser bladeUser) { |
| | | public R<IPage<Tenant>> list(@ApiIgnore @RequestParam Map<String, Object> tenant, Query query, BladeUser bladeUser) throws ParseException { |
| | | QueryWrapper<Tenant> queryWrapper = Condition.getQueryWrapper(tenant, Tenant.class); |
| | | IPage<Tenant> pages = tenantService.page(Condition.getPage(query), (!bladeUser.getTenantId().equals(BladeConstant.ADMIN_TENANT_ID)) ? queryWrapper.lambda().eq(Tenant::getTenantId, bladeUser.getTenantId()) : queryWrapper); |
| | | return R.data(pages); |
| | |
| | | @ApiOperationSupport(order = 4) |
| | | @ApiOperation(value = "分页", notes = "传入tenant") |
| | | //@PreAuth(RoleConstant.HAS_ROLE_ADMIN) |
| | | public R<IPage<Tenant>> page(Tenant tenant, Query query) { |
| | | public R<IPage<Tenant>> page(Tenant tenant, Query query) throws ParseException { |
| | | IPage<Tenant> pages = tenantService.selectTenantPage(Condition.getPage(query), tenant); |
| | | return R.data(pages); |
| | | } |
| | |
| | | <result column="role_id" property="roleId"/> |
| | | <result column="dept_id" property="deptId"/> |
| | | <result column="post_id" property="postId"/> |
| | | <result column="online_status" property="online_status"/> |
| | | <result column="channlId" property="channlId"/> |
| | | </resultMap> |
| | | |
| | | <select id="selectUserPage" resultMap="userResultMap"> |