| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960 |
- package com.template.component;
- import cn.hutool.core.map.MapUtil;
- import cn.hutool.core.util.StrUtil;
- import cn.hutool.http.HttpRequest;
- import com.alibaba.fastjson.JSON;
- import com.alibaba.fastjson.JSONObject;
- import com.template.common.exception.MyCustomException;
- import com.template.common.result.ResponseStatusEnum;
- import com.template.common.utils.CreateSign1;
- import com.template.component.bo.AddVisitorCarBO;
- import com.template.config.ParkingFeeSysOfMxhConfig;
- import lombok.RequiredArgsConstructor;
- import lombok.extern.slf4j.Slf4j;
- import org.springframework.stereotype.Component;
- import java.util.Map;
- /**
- * 停车场收费系统组件
- * @author codingliang
- * @date 2025-06-17
- */
- @Slf4j
- @Component
- @RequiredArgsConstructor
- public class ParkingFeeSystemComponent {
- private final ParkingFeeSysOfMxhConfig parkingFeeSysOfMxhConfig;
- /**
- * 墨轩湖小区新增访客车辆
- * @param addCarRecordBo 新增访客车辆bo
- */
- public void addVisitorCarOfMxh(AddVisitorCarBO addCarRecordBo) {
- String sign = CreateSign1.MD5(JSON.toJSONString(addCarRecordBo) + "key=" + parkingFeeSysOfMxhConfig.getKey()).toUpperCase();
- Map<String, Object> param = MapUtil.<String, Object>builder()
- .put("park_id", parkingFeeSysOfMxhConfig.getParkId())
- .put("service_name", parkingFeeSysOfMxhConfig.getServiceName())
- .put("sign", sign)
- .put("data", addCarRecordBo)
- .build();
- String result;
- try {
- result = HttpRequest.post(parkingFeeSysOfMxhConfig.getUrl()).body(JSON.toJSONString(param)).execute().body();
- } catch (Exception e) {
- log.error("调用第三方接口异常", e);
- throw new MyCustomException(ResponseStatusEnum.THIRD_API_ERROR);
- }
- JSONObject jsonObject = JSON.parseObject(result);
- String state = jsonObject.getString("state");
- // 1 表示新增成功
- if (!StrUtil.equals(state, "1")) {
- log.error("新增车牌失败,返回信息为:{}", result);
- throw new MyCustomException(ResponseStatusEnum.THIRD_API_ERROR);
- }
- }
- }
|