|
|
@@ -7,21 +7,12 @@ import com.sckw.core.exception.SystemException;
|
|
|
import com.sckw.core.model.page.PageResult;
|
|
|
import com.sckw.core.web.constant.HttpStatus;
|
|
|
import com.sckw.core.web.context.LoginUserHolder;
|
|
|
-import com.sckw.system.model.KwsEnterprise;
|
|
|
-import com.sckw.system.model.KwsPrinter;
|
|
|
-import com.sckw.system.model.KwsWeighbridge;
|
|
|
-import com.sckw.system.model.KwsWeighbridgeDiffConfig;
|
|
|
-import com.sckw.system.model.vo.req.WeighbridgeDiffConfigReqVo;
|
|
|
-import com.sckw.system.model.vo.req.WeighbridgePageReqVo;
|
|
|
-import com.sckw.system.model.vo.req.WeighbridgeRestartReqVo;
|
|
|
-import com.sckw.system.model.vo.req.WeighbridgeSaveReqVo;
|
|
|
-import com.sckw.system.model.vo.req.WeighbridgeStatusReqVo;
|
|
|
-import com.sckw.system.model.vo.res.PlatformEnterpriseResVo;
|
|
|
-import com.sckw.system.model.vo.res.WeighbridgeDetailResVo;
|
|
|
-import com.sckw.system.model.vo.res.WeighbridgeDiffConfigResVo;
|
|
|
-import com.sckw.system.model.vo.res.WeighbridgePageResVo;
|
|
|
+import com.sckw.system.model.*;
|
|
|
+import com.sckw.system.model.vo.req.*;
|
|
|
+import com.sckw.system.model.vo.res.*;
|
|
|
import com.sckw.system.repository.KwsEnterpriseRepository;
|
|
|
import com.sckw.system.repository.KwsPrinterRepository;
|
|
|
+import com.sckw.system.repository.KwsWeighbridgeRecordRepository;
|
|
|
import com.sckw.system.repository.KwsWeighbridgeDiffConfigRepository;
|
|
|
import com.sckw.system.repository.KwsWeighbridgeRepository;
|
|
|
import lombok.RequiredArgsConstructor;
|
|
|
@@ -29,7 +20,9 @@ import lombok.extern.slf4j.Slf4j;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
+import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
+import java.io.IOException;
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.Collection;
|
|
|
import java.util.Collections;
|
|
|
@@ -66,6 +59,12 @@ public class KwsWeighbridgeManageService {
|
|
|
* 地磅误差配置数据访问层
|
|
|
*/
|
|
|
private final KwsWeighbridgeDiffConfigRepository kwsWeighbridgeDiffConfigRepository;
|
|
|
+ /**
|
|
|
+ * 地磅记录数据访问层
|
|
|
+ */
|
|
|
+ private final KwsWeighbridgeRecordRepository kwsWeighbridgeRecordRepository;
|
|
|
+
|
|
|
+ private final ValidateLicensePlateService validateLicensePlateService;
|
|
|
|
|
|
/**
|
|
|
* 分页查询地磅列表
|
|
|
@@ -640,4 +639,168 @@ public class KwsWeighbridgeManageService {
|
|
|
jsonObject.put("emptyLoadValue", reqVo.getEmptyLoadValue());
|
|
|
return jsonObject.toJSONString();
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 车牌验证
|
|
|
+ * @param request 地磅上报请求参数
|
|
|
+ * @return 是否保存成功
|
|
|
+ */
|
|
|
+ public LicensePlateValidateResponse handleValidateLicensePlate(LicensePlateValidateRequest request) {
|
|
|
+ log.info("车牌验证, 车牌:{}", request.getLicensePlate());
|
|
|
+ LicensePlateValidateResponse response = new LicensePlateValidateResponse();
|
|
|
+ ValidateLicensePlate validateLicensePlate;
|
|
|
+ //查询车牌是不存在
|
|
|
+ try {
|
|
|
+ validateLicensePlate = validateLicensePlateService.queryByLicensePlate(request.getLicensePlate(), request.getUuid());
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("车牌验证失败,请重新识别或联系管理员", e);
|
|
|
+ return getValidateLicensePlateError(response);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (validateLicensePlate != null) {
|
|
|
+ log.info("车牌验证成功");
|
|
|
+ response.setStatus(Boolean.TRUE);
|
|
|
+ response.setCode(200);
|
|
|
+ response.setMessage("车牌验证成功");
|
|
|
+
|
|
|
+ response.setData(new LicensePlateValidateResponse.Data());
|
|
|
+ response.getData().setTimestamp(System.currentTimeMillis() / 1000);
|
|
|
+ response.getData().setScreen_message("车牌验证成功");
|
|
|
+ response.getData().setVoice_message("车牌验证成功");
|
|
|
+ response.getData().setWarning(null);
|
|
|
+ return response;
|
|
|
+ } else {
|
|
|
+ return getValidateLicensePlateError(response);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ private LicensePlateValidateResponse getValidateLicensePlateError(LicensePlateValidateResponse response) {
|
|
|
+ log.info("车牌验证失败");
|
|
|
+ response.setStatus(Boolean.FALSE);
|
|
|
+ response.setCode(400);
|
|
|
+ response.setMessage("车牌验证异常");
|
|
|
+
|
|
|
+ response.setData(new LicensePlateValidateResponse.Data());
|
|
|
+ response.getData().setTimestamp(System.currentTimeMillis()/1000);
|
|
|
+ response.getData().setScreen_message("车牌验证失败");
|
|
|
+ response.getData().setVoice_message("车牌验证失败");
|
|
|
+ response.getData().setWarning(null);
|
|
|
+ return response;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 处理地磅过磅数据上报
|
|
|
+ * @param request 地磅上报请求参数
|
|
|
+ * @return 是否保存成功
|
|
|
+ */
|
|
|
+ public LicensePlateValidateResponse handleWeighbridgePush(WeighbridgePushRequest request) {
|
|
|
+ log.info("处理地磅数据上报 - 车牌:{}, 地磅编号:{}, 重量:{}, 时间戳:{}",
|
|
|
+ request.getLicensePlate(),
|
|
|
+ request.getWeighbridgeCode(),
|
|
|
+ request.getGrossWeight(),
|
|
|
+ request.getTimestamp());
|
|
|
+ LicensePlateValidateResponse licensePlateValidateResponse = new LicensePlateValidateResponse();
|
|
|
+ if (StringUtils.isAnyBlank(request.getLicensePlate(), request.getWeighbridgeCode()) || Objects.isNull(request.getGrossWeight()) || Objects.isNull(request.getTimestamp())) {
|
|
|
+ return getLicensePlateValidateResponse(request, licensePlateValidateResponse);
|
|
|
+ }
|
|
|
+ try {
|
|
|
+ KwsWeighbridge weighbridge = kwsWeighbridgeRepository.findByUniqueCode(request.getWeighbridgeCode().trim());
|
|
|
+ if (weighbridge == null || Objects.equals(weighbridge.getDelFlag(), 1)) {
|
|
|
+ log.error("地磅数据保存失败 - 地磅不存在, 地磅编号: {}", request.getWeighbridgeCode());
|
|
|
+ return getLicensePlateValidateResponse(request, licensePlateValidateResponse);
|
|
|
+ }
|
|
|
+
|
|
|
+ KwsWeighbridgeRecord record = buildWeighbridgeRecord(request, weighbridge.getId());
|
|
|
+ boolean saved = kwsWeighbridgeRecordRepository.save(record);
|
|
|
+ if (saved) {
|
|
|
+ // 异步处理图片上传
|
|
|
+ updateImageUrls(request, record);
|
|
|
+ licensePlateValidateResponse.setStatus(true);
|
|
|
+ licensePlateValidateResponse.setCode(200);
|
|
|
+ licensePlateValidateResponse.setMessage("数据上报成功");
|
|
|
+ LicensePlateValidateResponse.Data data = new LicensePlateValidateResponse.Data();
|
|
|
+ data.setTimestamp(resolveSecondTimestamp(request.getTimestamp()));
|
|
|
+ data.setScreen_message("数据上报成功");
|
|
|
+ data.setVoice_message("数据上报成功");
|
|
|
+ licensePlateValidateResponse.setData(data);
|
|
|
+ log.info("地磅数据保存成功 - ID: {}, 车牌: {}", record.getId(), record.getTruckNo());
|
|
|
+ return licensePlateValidateResponse;
|
|
|
+ } else {
|
|
|
+ log.error("地磅数据保存失败 - 车牌: {}", request.getLicensePlate());
|
|
|
+ return getLicensePlateValidateResponse(request, licensePlateValidateResponse);
|
|
|
+ }
|
|
|
+
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("地磅数据上报处理异常", e);
|
|
|
+ return getLicensePlateValidateResponse(request, licensePlateValidateResponse);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ private void updateImageUrls(WeighbridgePushRequest request, KwsWeighbridgeRecord record) {
|
|
|
+ MultipartFile[] images = request.getImages();
|
|
|
+ if (images == null || images.length == 0) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ int validImageCount = (int) java.util.Arrays.stream(images)
|
|
|
+ .filter(Objects::nonNull)
|
|
|
+ .count();
|
|
|
+ if (validImageCount == 0) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ // kws_weighbridge_record 当前没有图片URL字段,先只记录上传事实,避免保留无效的旧依赖代码。
|
|
|
+ log.info("地磅记录收到图片但当前未落库, recordId: {}, truckNo: {}, imageCount: {}",
|
|
|
+ record.getId(), request.getLicensePlate(), validImageCount);
|
|
|
+ }
|
|
|
+ private static LicensePlateValidateResponse getLicensePlateValidateResponse(WeighbridgePushRequest request, LicensePlateValidateResponse licensePlateValidateResponse) {
|
|
|
+
|
|
|
+ licensePlateValidateResponse.setStatus(false);
|
|
|
+ licensePlateValidateResponse.setCode(400);
|
|
|
+ licensePlateValidateResponse.setMessage("数据上报失败");
|
|
|
+ LicensePlateValidateResponse.Data data = new LicensePlateValidateResponse.Data();
|
|
|
+ String timestampStr = request.getTimestamp().toString();
|
|
|
+ if (timestampStr.length() == 10) {
|
|
|
+ // 秒级时间戳
|
|
|
+ data.setTimestamp(request.getTimestamp());
|
|
|
+ } else if (timestampStr.length() == 13) {
|
|
|
+ // 毫秒级时间戳
|
|
|
+ long l = request.getTimestamp() / 1000;
|
|
|
+ data.setTimestamp(l);
|
|
|
+ }
|
|
|
+
|
|
|
+ data.setVoice_message("数据上报失败");
|
|
|
+ licensePlateValidateResponse.setData(data);
|
|
|
+ return licensePlateValidateResponse;
|
|
|
+ }
|
|
|
+
|
|
|
+ private KwsWeighbridgeRecord buildWeighbridgeRecord(WeighbridgePushRequest request, Long weighbridgeId) {
|
|
|
+ Date now = new Date();
|
|
|
+ return new KwsWeighbridgeRecord()
|
|
|
+ .setWeighbridgeId(weighbridgeId)
|
|
|
+ .setTruckNo(request.getLicensePlate().trim())
|
|
|
+ .setWeight(request.getGrossWeight())
|
|
|
+ .setReceiveTime(resolveReceiveTime(request.getTimestamp()))
|
|
|
+ .setCreateBy(0L)
|
|
|
+ .setCreateTime(now)
|
|
|
+ .setUpdateBy(0L)
|
|
|
+ .setUpdateTime(now)
|
|
|
+ .setDelFlag(0);
|
|
|
+ }
|
|
|
+
|
|
|
+ private Date resolveReceiveTime(Long timestamp) {
|
|
|
+ long secondTimestamp = resolveSecondTimestamp(timestamp);
|
|
|
+ return new Date(secondTimestamp * 1000);
|
|
|
+ }
|
|
|
+
|
|
|
+ private long resolveSecondTimestamp(Long timestamp) {
|
|
|
+ if (timestamp == null) {
|
|
|
+ return System.currentTimeMillis() / 1000;
|
|
|
+ }
|
|
|
+ String timestampStr = timestamp.toString();
|
|
|
+ if (timestampStr.length() == 13) {
|
|
|
+ return timestamp / 1000;
|
|
|
+ }
|
|
|
+ return timestamp;
|
|
|
+ }
|
|
|
+
|
|
|
}
|