master
ljw 2025-11-05 11:44:54 +08:00
commit 1f6b6e78f9
14 changed files with 402 additions and 12 deletions

View File

@ -0,0 +1,23 @@
package com.njzscloud.supervisory.config;
import com.njzscloud.supervisory.hsoa.HsoaProperties;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Configuration;
@Slf4j
@Configuration
@EnableConfigurationProperties({HsoaProperties.class})
public class HsoaAutoConfiguration {
/* public HsoaAutoConfiguration(){
log.info("HsoaAutoConfiguration");
}
@Bean
@ConditionalOnBean(HttpClientDecorator.class)
public HsoaApi hsoaApi(HttpClientDecorator httpClientDecorator) {
return httpClientDecorator.decorate(HsoaApi.class);
} */
}

View File

@ -0,0 +1,88 @@
package com.njzscloud.supervisory.hsoa;
import cn.hutool.core.util.StrUtil;
import cn.hutool.extra.spring.SpringUtil;
import com.njzscloud.common.http.HttpClientDecorator;
import com.njzscloud.supervisory.config.AppProperties;
import com.njzscloud.supervisory.hsoa.pojo.param.LoginParam;
import com.njzscloud.supervisory.hsoa.pojo.param.PushVehicleTrajectoryParam;
import com.njzscloud.supervisory.hsoa.pojo.param.RefreshTokenParam;
import com.njzscloud.supervisory.hsoa.pojo.param.TokenParam;
import com.njzscloud.supervisory.hsoa.pojo.result.HsoaResult;
import com.njzscloud.supervisory.hsoa.pojo.result.LoginResult;
import lombok.extern.slf4j.Slf4j;
import java.util.concurrent.locks.ReentrantReadWriteLock;
@Slf4j
public class Hsoa {
public static final HsoaApi API;
private static final HsoaProperties hsoaProperties;
private static final ReentrantReadWriteLock rwLock = new ReentrantReadWriteLock();
private static final ReentrantReadWriteLock.ReadLock rlock = rwLock.readLock();
private static final ReentrantReadWriteLock.WriteLock wlock = rwLock.writeLock();
private static String refTnt = "";
private static String tnt = "";
private static long lastLoginTime = 0;
private static AppProperties appProperties;
static {
HttpClientDecorator httpClientDecorator = SpringUtil.getBean(HttpClientDecorator.class);
appProperties = SpringUtil.getBean(AppProperties.class);
API = httpClientDecorator.decorate(HsoaApi.class);
hsoaProperties = SpringUtil.getBean(HsoaProperties.class);
}
public static HsoaResult<?> pushVehicleTrajectory(PushVehicleTrajectoryParam param) {
login();
try {
rlock.lock();
AppProperties.DefaultPlace defaultPlace = appProperties.getDefaultPlace();
param.setCityCode(defaultPlace.getCity())
.setCityName(defaultPlace.getCityName())
;
return API.pushVehicleTrajectory(param, new TokenParam().setTnt(tnt).setRefTnt(refTnt));
} finally {
rlock.unlock();
}
}
public static void login() {
try {
wlock.lock();
long now = System.currentTimeMillis() / 1000;
if (StrUtil.isBlank(refTnt) || StrUtil.isBlank(tnt)) {
HsoaResult<LoginResult> loginResult = API.login(new LoginParam()
.setUserName(hsoaProperties.getUsername())
.setPassword(hsoaProperties.getPassword())
);
if (loginResult.isSuccess()) {
LoginResult data = loginResult.getData();
refTnt = data.getRefTnt();
tnt = data.getTnt();
lastLoginTime = now;
} else {
refTnt = "";
tnt = "";
}
} else if (now - lastLoginTime > hsoaProperties.getExpire() - 60) {
HsoaResult<LoginResult> loginResult = API.refreshToken(new RefreshTokenParam().setRefTnt(refTnt));
if (loginResult.isSuccess()) {
LoginResult data = loginResult.getData();
refTnt = data.getRefTnt();
tnt = data.getTnt();
lastLoginTime = now;
} else {
refTnt = "";
tnt = "";
}
}
} catch (Exception e) {
refTnt = "";
tnt = "";
log.error("政务平台登录失败", e);
} finally {
wlock.unlock();
}
}
}

View File

@ -0,0 +1,30 @@
package com.njzscloud.supervisory.hsoa;
import com.njzscloud.common.http.annotation.*;
import com.njzscloud.supervisory.hsoa.pojo.param.LoginParam;
import com.njzscloud.supervisory.hsoa.pojo.param.PushVehicleTrajectoryParam;
import com.njzscloud.supervisory.hsoa.pojo.param.RefreshTokenParam;
import com.njzscloud.supervisory.hsoa.pojo.param.TokenParam;
import com.njzscloud.supervisory.hsoa.pojo.result.HsoaResult;
import com.njzscloud.supervisory.hsoa.pojo.result.LoginResult;
@RemoteServer(value = "${hsoa.base-url}")
public interface HsoaApi {
/**
*
*/
@PostEndpoint("/garbage/mLoginApi/login")
HsoaResult<LoginResult> login(@FormBodyParam LoginParam apram);
/**
* TOKEN
*/
@GetEndpoint("/garbage/mLoginApi/refreshToken")
HsoaResult<LoginResult> refreshToken(@QueryParam RefreshTokenParam apram);
/**
*
*/
@PostEndpoint("/garbage/commonApi/pushVehicleTrajectory")
HsoaResult<Object> pushVehicleTrajectory(@JsonBodyParam PushVehicleTrajectoryParam apram, @QueryParam TokenParam tokenParam);
}

View File

@ -0,0 +1,19 @@
package com.njzscloud.supervisory.hsoa;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
import lombok.experimental.Accessors;
import org.springframework.boot.context.properties.ConfigurationProperties;
@Getter
@Setter
@ToString
@Accessors(chain = true)
@ConfigurationProperties(prefix = "hsoa")
public class HsoaProperties {
private String baseUrl;
private String username;
private String password;
private int expire = 72 * 24 * 3600;
}

View File

@ -0,0 +1,26 @@
package com.njzscloud.supervisory.hsoa.controller;
import com.njzscloud.common.core.utils.R;
import com.njzscloud.supervisory.hsoa.Hsoa;
import com.njzscloud.supervisory.hsoa.pojo.param.PushVehicleTrajectoryParam;
import com.njzscloud.supervisory.hsoa.pojo.result.HsoaResult;
import lombok.RequiredArgsConstructor;
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;
@RestController
@RequiredArgsConstructor
@RequestMapping("/hsoa")
public class HsoaController {
@PostMapping("/push")
public R<?> push(@RequestBody PushVehicleTrajectoryParam pushVehicleTrajectoryParam) {
HsoaResult<?> objectHsoaResult = Hsoa.pushVehicleTrajectory(pushVehicleTrajectoryParam);
if (objectHsoaResult.isSuccess()) {
return R.success(objectHsoaResult);
}
return R.failed();
}
}

View File

@ -0,0 +1,15 @@
package com.njzscloud.supervisory.hsoa.pojo.param;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
import lombok.experimental.Accessors;
@Getter
@Setter
@ToString
@Accessors(chain = true)
public class LoginParam {
private String userName;
private String password;
}

View File

@ -0,0 +1,83 @@
package com.njzscloud.supervisory.hsoa.pojo.param;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
import lombok.experimental.Accessors;
@Getter
@Setter
@ToString
@Accessors(chain = true)
public class PushVehicleTrajectoryParam {
@JsonProperty("cityCode")
private String cityCode;
@JsonProperty("cityName")
private String cityName;
@JsonProperty("districtCode")
private String districtCode;
@JsonProperty("districtName")
private String districtName;
@JsonProperty("companyName")
private String companyName;
@JsonProperty("transportLicense")
private String transportLicense;
@JsonProperty("plateNumber")
private String plateNumber;
@JsonProperty("vehicleType")
private String vehicleType;
@JsonProperty("longitude")
private String longitude;
@JsonProperty("latitude")
private String latitude;
@JsonProperty("speed")
private Double speed;
@JsonProperty("loadWeight")
private Double loadWeight;
@JsonProperty("loadStatus")
private String loadStatus;
@JsonProperty("sealedStatus")
private String sealedStatus;
@JsonProperty("liftStatus")
private String liftStatus;
@JsonProperty("direction")
private Double direction;
@JsonProperty("directionDesc")
private String directionDesc;
@JsonProperty("altitude")
private Double altitude;
@JsonProperty("locationDesc")
private String locationDesc;
@JsonProperty("address")
private String address;
@JsonProperty("gpsTime")
private String gpsTime;
@JsonProperty("receiveTime")
private String receiveTime;
@JsonProperty("accStatus")
private Integer accStatus;
@JsonProperty("onlineStatus")
private Integer onlineStatus;
@JsonProperty("locationMode")
private String locationMode;
@JsonProperty("stateType")
private String stateType;
@JsonProperty("alarmType")
private String alarmType;
@JsonProperty("alarmDesc")
private String alarmDesc;
@JsonProperty("todayMileage")
private Double todayMileage;
@JsonProperty("totalMileage")
private Double totalMileage;
@JsonProperty("temperature")
private String temperature;
@JsonProperty("humidity")
private String humidity;
@JsonProperty("oilValue")
private String oilValue;
@JsonProperty("voltage")
private String voltage;
}

View File

@ -0,0 +1,16 @@
package com.njzscloud.supervisory.hsoa.pojo.param;
import com.njzscloud.common.http.annotation.QueryParam;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
import lombok.experimental.Accessors;
@Getter
@Setter
@ToString
@Accessors(chain = true)
public class RefreshTokenParam {
@QueryParam("REF_TNT")
private String refTnt;
}

View File

@ -0,0 +1,18 @@
package com.njzscloud.supervisory.hsoa.pojo.param;
import com.njzscloud.common.http.annotation.QueryParam;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
import lombok.experimental.Accessors;
@Getter
@Setter
@ToString
@Accessors(chain = true)
public class TokenParam {
@QueryParam("REF_TNT")
private String refTnt;
@QueryParam("TNT")
private String tnt;
}

View File

@ -0,0 +1,18 @@
package com.njzscloud.supervisory.hsoa.pojo.result;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
import lombok.experimental.Accessors;
@Getter
@Setter
@ToString
@Accessors(chain = true)
public class HsoaResult<T> {
private String message;
private Integer code;
private boolean success;
private T data;
}

View File

@ -0,0 +1,18 @@
package com.njzscloud.supervisory.hsoa.pojo.result;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
import lombok.experimental.Accessors;
@Getter
@Setter
@ToString
@Accessors(chain = true)
public class LoginResult {
@JsonProperty("REF_TNT")
private String refTnt;
@JsonProperty("TNT")
private String tnt;
}

View File

@ -39,6 +39,9 @@ import com.njzscloud.supervisory.expense.contant.Scope;
import com.njzscloud.supervisory.expense.pojo.entity.ExpenseItemsConfigEntity;
import com.njzscloud.supervisory.expense.service.ExpenseItemsConfigService;
import com.njzscloud.supervisory.goods.contant.MoneyStrategy;
import com.njzscloud.supervisory.hsoa.Hsoa;
import com.njzscloud.supervisory.hsoa.pojo.param.PushVehicleTrajectoryParam;
import com.njzscloud.supervisory.hsoa.pojo.result.HsoaResult;
import com.njzscloud.supervisory.money.contant.MoneyChangeCategory;
import com.njzscloud.supervisory.money.pojo.entity.MoneyAccountEntity;
import com.njzscloud.supervisory.money.pojo.entity.MoneyChangeDetailEntity;
@ -1193,8 +1196,9 @@ public class OrderInfoService extends ServiceImpl<OrderInfoMapper, OrderInfoEnti
/**
*
* @param orderId ID
* @param items
*
* @param orderId ID
* @param items
*/
private void calculateItemsAndUpdateOrder(Long orderId, List<OrderExpenseItemsEntity> items) {
// 计算各付费项金额
@ -1457,16 +1461,19 @@ public class OrderInfoService extends ServiceImpl<OrderInfoMapper, OrderInfoEnti
private void startTrack(String gpsId, String licensePlate, Long orderInfoId, Long truckId) {
if (StrUtil.isBlank(gpsId)) return;
OrderPagingResult orderDetail = detail(orderInfoId);
CompletableFuture.runAsync(() -> {
Mqtt.subscribe(gpsId + "/track_location", (msg) -> {
RealtimeLocationResult realtimeLocationResult = msg.getMsg(RealtimeLocationResult.class);
if (realtimeLocationResult == null) {
return;
}
double speed = realtimeLocationResult.getSpeed();
if (realtimeLocationResult.isOverspeed()) {
bizWarnService.save(new BizWarnEntity()
.setWarnCategory(WarnCategory.SPEED.getVal())
.setWarnContent(StrUtil.format("{} 已超速,当前时速 {}km/h", licensePlate, realtimeLocationResult.getSpeed()))
.setWarnContent(StrUtil.format("{} 已超速,当前时速 {}km/h", licensePlate, speed))
.setOrderId(orderInfoId)
);
}
@ -1479,6 +1486,7 @@ public class OrderInfoService extends ServiceImpl<OrderInfoMapper, OrderInfoEnti
return;
}
int direction = realtimeLocationResult.getDirection();
TruckLocationTrackEntity entity = new TruckLocationTrackEntity()
.setOrderId(orderInfoId)
.setTruckId(truckId)
@ -1486,12 +1494,38 @@ public class OrderInfoService extends ServiceImpl<OrderInfoMapper, OrderInfoEnti
.setLatitude(latitude)
.setLongitude(longitude)
.setAltitude(realtimeLocationResult.getAltitude())
.setSpeed(realtimeLocationResult.getSpeed())
.setSpeed(speed)
.setLocationTime(DateUtil.parseLocalDateTime(time))
.setDirection(realtimeLocationResult.getDirection())
.setDirection(direction)
.setOverspeed(realtimeLocationResult.isOverspeed())
.setCompensate(realtimeLocationResult.getType() == 1);
truckLocationTrackService.save(entity);
try {
String transCompanyName = orderDetail.getTransCompanyName();
HsoaResult<?> result = Hsoa.pushVehicleTrajectory(new PushVehicleTrajectoryParam()
.setCompanyName(transCompanyName)
.setTransportLicense(orderDetail.getCertificateSn())
.setPlateNumber(licensePlate)
.setVehicleType(orderDetail.getTruckCategory())
.setLongitude(longitude + "")
.setLatitude(latitude + "")
.setSpeed(speed)
.setDirection(direction + 0.0)
.setStateType("正常行驶")
.setAlarmType("无")
.setLoadStatus("2")
.setSealedStatus("1")
.setLiftStatus("0")
.setAccStatus(1)
.setGpsTime(time)
.setLocationMode("WGS84")
);
if (result == null || !result.isSuccess()) {
log.error("推送定位数据失败数据Id{}", entity.getId());
}
} catch (Exception e) {
log.error("推送定位数据失败数据Id{}", entity.getId(), e);
}
});
/* Mqtt.publish("location/track", MapUtil.builder()
.put("terminalId", gpsId)

View File

@ -88,3 +88,8 @@ mqtt:
client-id: njzscloud-svr1
username: gps
password: TKG4TV3dF7CeazDnUdCF
hsoa:
base-url: http://60.173.195.121:9908
username: chuz_trajectory
password: e9t2YsgM5ug/kpIZpMdY9e9uXq60jyEQ30zQX+BzphI=

View File

@ -79,10 +79,7 @@ mqtt:
localizer:
enabled: false
# INSERT INTO greenfrog.sys_district (id, pid, province, city, area, town, district_name, tier, sort) VALUES ('341101', '341100', '340000', '341100', '341101', '', '市辖区', 3, 0);
# INSERT INTO greenfrog.sys_district (id, pid, province, city, area, town, district_name, tier, sort) VALUES ('341122', '341100', '340000', '341100', '341122', '', '来安县', 3, 0);
# INSERT INTO greenfrog.sys_district (id, pid, province, city, area, town, district_name, tier, sort) VALUES ('341124', '341100', '340000', '341100', '341124', '', '全椒县', 3, 0);
# INSERT INTO greenfrog.sys_district (id, pid, province, city, area, town, district_name, tier, sort) VALUES ('341125', '341100', '340000', '341100', '341125', '', '定远县', 3, 0);
# INSERT INTO greenfrog.sys_district (id, pid, province, city, area, town, district_name, tier, sort) VALUES ('341126', '341100', '340000', '341100', '341126', '', '凤阳县', 3, 0);
# INSERT INTO greenfrog.sys_district (id, pid, province, city, area, town, district_name, tier, sort) VALUES ('341181', '341100', '340000', '341100', '341181', '', '天长市', 3, 0);
# INSERT INTO greenfrog.sys_district (id, pid, province, city, area, town, district_name, tier, sort) VALUES ('341182', '341100', '340000', '341100', '341182', '', '明光市', 3, 0);
hsoa:
base-url: http://117.68.7.91:8088
username: chuz_trajectory
password: e9t2YsgM5ug/kpIZpMdY9e9uXq60jyEQ30zQX+BzphI=