From 4ab42970a3436f5a7a27c9a645ea93c35c080be5 Mon Sep 17 00:00:00 2001 From: XinWei <2718030729@qq.com> Date: Wed, 31 Jul 2024 11:55:23 +0800 Subject: [PATCH] =?UTF-8?q?=E5=81=9C=E8=BD=A6=E5=9C=BA-=E8=BF=81=E7=A7=BB?= =?UTF-8?q?=E9=BB=91=E5=90=8D=E5=8D=95=E4=B8=8B=E5=8F=91=E3=80=81=E5=88=A0?= =?UTF-8?q?=E9=99=A4=E3=80=81=E6=9F=A5=E8=AF=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BlacklistDeliveryController.java | 17 ++++- .../BlacklistDeliveryService.java | 23 ++++++ .../BlacklistDeliveryServiceImpl.java | 51 +++++++++++++ .../parking/util/BlueCarRequestUtil.java | 74 +++++++++++++++++++ .../src/main/resources/application.yaml | 16 ++++ 5 files changed, 180 insertions(+), 1 deletion(-) create mode 100644 ludu-module-parking/ludu-module-parking-biz/src/main/java/cn/iocoder/yudao/module/parking/util/BlueCarRequestUtil.java diff --git a/ludu-module-parking/ludu-module-parking-biz/src/main/java/cn/iocoder/yudao/module/parking/controller/admin/blacklistdelivery/BlacklistDeliveryController.java b/ludu-module-parking/ludu-module-parking-biz/src/main/java/cn/iocoder/yudao/module/parking/controller/admin/blacklistdelivery/BlacklistDeliveryController.java index 3162ab17c..55f8d9bc3 100644 --- a/ludu-module-parking/ludu-module-parking-biz/src/main/java/cn/iocoder/yudao/module/parking/controller/admin/blacklistdelivery/BlacklistDeliveryController.java +++ b/ludu-module-parking/ludu-module-parking-biz/src/main/java/cn/iocoder/yudao/module/parking/controller/admin/blacklistdelivery/BlacklistDeliveryController.java @@ -1,5 +1,6 @@ package cn.iocoder.yudao.module.parking.controller.admin.blacklistdelivery; +import cn.iocoder.yudao.module.parking.util.BlueCardResult; import org.springframework.web.bind.annotation.*; import javax.annotation.Resource; import org.springframework.validation.annotation.Validated; @@ -37,7 +38,21 @@ public class BlacklistDeliveryController { @Resource private BlacklistDeliveryService blacklistDeliveryService; - + //黑名单下发(新增或修改) + @PostMapping("/insertBlacklist") + public BlueCardResult insertBlacklist(@RequestBody BlacklistDeliverySaveReqVO blacklistDelivery){ + return blacklistDeliveryService.doBlacklistDelivery(blacklistDelivery); + } + //黑名单删除 + @PostMapping("/deleteBlacklist") + public BlueCardResult deleteBlacklist(@RequestBody BlacklistDeliverySaveReqVO deleteBlacklistVo){ + return blacklistDeliveryService.deleteBlacklistDelivery(deleteBlacklistVo); + } + //查询黑名单 + @PostMapping("/selectBlacklist") + public CommonResult selectBlacklist(@RequestBody BlacklistDeliverySaveReqVO selectWhitelistVo) { + return blacklistDeliveryService.findBlacklist(selectWhitelistVo); + } @PostMapping("/create") @Operation(summary = "创建黑名单配置") @PreAuthorize("@ss.hasPermission('parking:blacklist-delivery:create')") diff --git a/ludu-module-parking/ludu-module-parking-biz/src/main/java/cn/iocoder/yudao/module/parking/service/blacklistdelivery/BlacklistDeliveryService.java b/ludu-module-parking/ludu-module-parking-biz/src/main/java/cn/iocoder/yudao/module/parking/service/blacklistdelivery/BlacklistDeliveryService.java index c8df33317..dc0f02670 100644 --- a/ludu-module-parking/ludu-module-parking-biz/src/main/java/cn/iocoder/yudao/module/parking/service/blacklistdelivery/BlacklistDeliveryService.java +++ b/ludu-module-parking/ludu-module-parking-biz/src/main/java/cn/iocoder/yudao/module/parking/service/blacklistdelivery/BlacklistDeliveryService.java @@ -2,10 +2,13 @@ package cn.iocoder.yudao.module.parking.service.blacklistdelivery; import java.util.*; import javax.validation.*; + +import cn.iocoder.yudao.framework.common.pojo.CommonResult; import cn.iocoder.yudao.module.parking.controller.admin.blacklistdelivery.vo.*; import cn.iocoder.yudao.module.parking.dal.dataobject.blacklistdelivery.BlacklistDeliveryDO; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.common.pojo.PageParam; +import cn.iocoder.yudao.module.parking.util.BlueCardResult; /** * 黑名单配置 Service 接口 @@ -52,4 +55,24 @@ public interface BlacklistDeliveryService { */ PageResult getBlacklistDeliveryPage(BlacklistDeliveryPageReqVO pageReqVO); + /** + * 黑名单下发(新增或修改) + * @param blacklistDelivery + * @return cn.iocoder.yudao.module.parking.util.BlueCardResult + */ + BlueCardResult doBlacklistDelivery(BlacklistDeliverySaveReqVO blacklistDelivery); + + /** + * 黑名单删除 + * @param deleteBlacklistVo + * @return cn.iocoder.yudao.module.parking.util.BlueCardResult + */ + BlueCardResult deleteBlacklistDelivery(BlacklistDeliverySaveReqVO deleteBlacklistVo); + + /** + * 查询黑名单 + * @param selectWhitelistVo + * @return cn.iocoder.yudao.framework.common.pojo.CommonResult + */ + CommonResult findBlacklist(BlacklistDeliverySaveReqVO selectWhitelistVo); } \ No newline at end of file diff --git a/ludu-module-parking/ludu-module-parking-biz/src/main/java/cn/iocoder/yudao/module/parking/service/blacklistdelivery/BlacklistDeliveryServiceImpl.java b/ludu-module-parking/ludu-module-parking-biz/src/main/java/cn/iocoder/yudao/module/parking/service/blacklistdelivery/BlacklistDeliveryServiceImpl.java index 44b95caa9..d036fe47d 100644 --- a/ludu-module-parking/ludu-module-parking-biz/src/main/java/cn/iocoder/yudao/module/parking/service/blacklistdelivery/BlacklistDeliveryServiceImpl.java +++ b/ludu-module-parking/ludu-module-parking-biz/src/main/java/cn/iocoder/yudao/module/parking/service/blacklistdelivery/BlacklistDeliveryServiceImpl.java @@ -1,11 +1,18 @@ package cn.iocoder.yudao.module.parking.service.blacklistdelivery; +import cn.iocoder.yudao.framework.common.pojo.CommonResult; +import cn.iocoder.yudao.module.parking.util.BlueCarRequestUtil; +import cn.iocoder.yudao.module.parking.util.BlueCardResult; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; + import javax.annotation.Resource; + import org.springframework.validation.annotation.Validated; import org.springframework.transaction.annotation.Transactional; import java.util.*; + import cn.iocoder.yudao.module.parking.controller.admin.blacklistdelivery.vo.*; import cn.iocoder.yudao.module.parking.dal.dataobject.blacklistdelivery.BlacklistDeliveryDO; import cn.iocoder.yudao.framework.common.pojo.PageResult; @@ -28,6 +35,8 @@ public class BlacklistDeliveryServiceImpl implements BlacklistDeliveryService { @Resource private BlacklistDeliveryMapper blacklistDeliveryMapper; + @Resource + private BlueCarRequestUtil blueCarRequestUtil; @Override public Long createBlacklistDelivery(BlacklistDeliverySaveReqVO createReqVO) { @@ -71,4 +80,46 @@ public class BlacklistDeliveryServiceImpl implements BlacklistDeliveryService { return blacklistDeliveryMapper.selectPage(pageReqVO); } + @Override + public BlueCardResult doBlacklistDelivery(BlacklistDeliverySaveReqVO blacklistDelivery) { + this.createBlacklistDelivery(blacklistDelivery); + Map map = new HashMap<>(); + map.put("id", blacklistDelivery.getId()); + map.put("parkNumber", blacklistDelivery.getParkNumber()); + map.put("source", blacklistDelivery.getSource()); + map.put("size", blacklistDelivery.getSize()); + List> datasList = new ArrayList<>(); + Map datasMap = new HashMap<>(); + datasMap.put("plate", blacklistDelivery.getPlate()); + if (blacklistDelivery.getMemo() != null) { + datasMap.put("memo", blacklistDelivery.getMemo()); + } + datasList.add(datasMap); + map.put("datas", datasList); + blueCarRequestUtil.doBlueCarPost(map, "bcopenapi/out/synBlack"); + return BlueCardResult.success(); + } + + @Override + public BlueCardResult deleteBlacklistDelivery(BlacklistDeliverySaveReqVO deleteBlacklistVo) { + Map map = new HashMap<>(); + map.put("parkNumber", deleteBlacklistVo.getParkNumber()); + map.put("plate", deleteBlacklistVo.getPlate()); + blueCarRequestUtil.doBlueCarPost(map, "bcopenapi/out/delBlack"); + return BlueCardResult.success(); + } + + @Override + public CommonResult findBlacklist(BlacklistDeliverySaveReqVO selectWhitelistVo) { + Map map = new HashMap<>(); + map.put("parkNumber", selectWhitelistVo.getParkNumber()); + map.put("size", selectWhitelistVo.getSize()); + List> datasList = new ArrayList<>(); + Map datasMap = new HashMap<>(); + datasMap.put("plate", selectWhitelistVo.getPlate()); + datasList.add(datasMap); + map.put("datas", datasList); + return blueCarRequestUtil.doBlueCarPost(map, "bcopenapi/out/queryBlack"); + } + } \ No newline at end of file diff --git a/ludu-module-parking/ludu-module-parking-biz/src/main/java/cn/iocoder/yudao/module/parking/util/BlueCarRequestUtil.java b/ludu-module-parking/ludu-module-parking-biz/src/main/java/cn/iocoder/yudao/module/parking/util/BlueCarRequestUtil.java new file mode 100644 index 000000000..820569046 --- /dev/null +++ b/ludu-module-parking/ludu-module-parking-biz/src/main/java/cn/iocoder/yudao/module/parking/util/BlueCarRequestUtil.java @@ -0,0 +1,74 @@ +package cn.iocoder.yudao.module.parking.util; + + +import cn.hutool.core.util.CharsetUtil; +import cn.hutool.core.util.HexUtil; +import cn.hutool.http.HttpResponse; +import cn.hutool.http.HttpUtil; +import cn.hutool.json.JSONObject; +import cn.hutool.json.JSONUtil; +import cn.iocoder.yudao.framework.common.pojo.CommonResult; +import cn.iocoder.yudao.module.parking.controller.admin.blacklistdelivery.vo.BlacklistDeliverySaveReqVO; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.stereotype.Component; + +import java.security.MessageDigest; + +import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; + +/** + * 蓝卡post请求工具类 + */ +@Component +public class BlueCarRequestUtil { + @Value("${blueCar.key}") + private String key; + @Value("${blueCar.parkNumber}") + private String parkNumber; +// @Value("${blueCar.Request.host}") + private String host; +// @Value("${blueCar.Request.port}") + private String port; + @Value("${blueCar.Request.ip}") + private String ip; + + public CommonResult doBlueCarPost(Object t, String portAddress){ + //请求地址 + String url = "http://"+ip+"/"+portAddress; + System.out.println(url); + //请求参数 + JSONObject jsonData = JSONUtil.parseObj(t); + // 构建sign字符串 + String s = key+parkNumber; + // 对sign字符串进行MD5加密 + String sign = md5(s); + // 发送POST请求 + HttpResponse response = HttpUtil.createPost(url) + .header("sign", sign) // 添加sign请求头 + .body(JSONUtil.toJsonStr(jsonData), "application/json") + .charset("UTF-8") // 设置编码格式为UTF-8 + .execute(); + // 获取响应状态码 + int status = response.getStatus(); + System.out.println(sign); + System.out.println("Response Code: " + status); + // 获取响应内容 + String responseBody = response.body(); + System.out.println("Response Body: " + responseBody); + // 关闭连接 + response.close(); + return success(responseBody); + } + + // 对sign参数进行MD5加密 + private String md5(String data) { + try { + MessageDigest md = MessageDigest.getInstance("MD5"); + byte[] md5Bytes = md.digest(data.getBytes(CharsetUtil.CHARSET_UTF_8)); + return HexUtil.encodeHexStr(md5Bytes, true); // 小写格式 + } catch (Exception e) { + e.printStackTrace(); + return null; + } + } +} diff --git a/ludu-module-parking/ludu-module-parking-biz/src/main/resources/application.yaml b/ludu-module-parking/ludu-module-parking-biz/src/main/resources/application.yaml index 2ec999dd3..ff4c1ad94 100644 --- a/ludu-module-parking/ludu-module-parking-biz/src/main/resources/application.yaml +++ b/ludu-module-parking/ludu-module-parking-biz/src/main/resources/application.yaml @@ -118,3 +118,19 @@ lundu: basePath: /home/upload/bcinterface/Uplmage/ #Windows下的文件路径 imgPath: https://yyxh.ptzykjgs.com/api/img/ +#蓝卡 +blueCar: + key: 7h5bdg7k926s28lzb5fny8pcrbtr426m + parkNumber: p230613141235 + Request: + host: 127.0.0.1 + port: 8080 + ip: swapi.bluecardsoft.com/bcopenapi + parkName: 石家庄联调专用 + +#海康 +haiKang: + appKey: abcdefg + appSecret: hijklmn + host: 127.0.0.1 + port: 8088