ParkingFeeSystemComponent.java 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. package com.template.component;
  2. import cn.hutool.core.map.MapUtil;
  3. import cn.hutool.core.util.StrUtil;
  4. import cn.hutool.http.HttpRequest;
  5. import com.alibaba.fastjson.JSON;
  6. import com.alibaba.fastjson.JSONObject;
  7. import com.template.common.exception.MyCustomException;
  8. import com.template.common.result.ResponseStatusEnum;
  9. import com.template.common.utils.CreateSign1;
  10. import com.template.component.bo.AddVisitorCarBO;
  11. import com.template.config.ParkingFeeSysOfMxhConfig;
  12. import lombok.RequiredArgsConstructor;
  13. import lombok.extern.slf4j.Slf4j;
  14. import org.springframework.stereotype.Component;
  15. import java.util.Map;
  16. /**
  17. * 停车场收费系统组件
  18. * @author codingliang
  19. * @date 2025-06-17
  20. */
  21. @Slf4j
  22. @Component
  23. @RequiredArgsConstructor
  24. public class ParkingFeeSystemComponent {
  25. private final ParkingFeeSysOfMxhConfig parkingFeeSysOfMxhConfig;
  26. /**
  27. * 墨轩湖小区新增访客车辆
  28. * @param addCarRecordBo 新增访客车辆bo
  29. */
  30. public void addVisitorCarOfMxh(AddVisitorCarBO addCarRecordBo) {
  31. String sign = CreateSign1.MD5(JSON.toJSONString(addCarRecordBo) + "key=" + parkingFeeSysOfMxhConfig.getKey()).toUpperCase();
  32. Map<String, Object> param = MapUtil.<String, Object>builder()
  33. .put("park_id", parkingFeeSysOfMxhConfig.getParkId())
  34. .put("service_name", parkingFeeSysOfMxhConfig.getServiceName())
  35. .put("sign", sign)
  36. .put("data", addCarRecordBo)
  37. .build();
  38. String result;
  39. try {
  40. result = HttpRequest.post(parkingFeeSysOfMxhConfig.getUrl()).body(JSON.toJSONString(param)).execute().body();
  41. } catch (Exception e) {
  42. log.error("调用第三方接口异常", e);
  43. throw new MyCustomException(ResponseStatusEnum.THIRD_API_ERROR);
  44. }
  45. JSONObject jsonObject = JSON.parseObject(result);
  46. String state = jsonObject.getString("state");
  47. // 1 表示新增成功
  48. if (!StrUtil.equals(state, "1")) {
  49. log.error("新增车牌失败,返回信息为:{}", result);
  50. throw new MyCustomException(ResponseStatusEnum.THIRD_API_ERROR);
  51. }
  52. }
  53. }