Commit 45558343 authored by 刘凡's avatar 刘凡

修改:修改气瓶同步消息

parent 2f1ffcea
...@@ -13,6 +13,7 @@ import io.swagger.annotations.ApiOperation; ...@@ -13,6 +13,7 @@ import io.swagger.annotations.ApiOperation;
import net.sf.json.JSONObject; import net.sf.json.JSONObject;
import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.Logger;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.ObjectUtils; import org.springframework.util.ObjectUtils;
import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.PostMapping;
...@@ -28,6 +29,7 @@ import org.typroject.tyboot.core.restful.exception.instance.BadRequest; ...@@ -28,6 +29,7 @@ import org.typroject.tyboot.core.restful.exception.instance.BadRequest;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.*; import java.util.*;
import java.util.stream.Collectors;
@RestController @RestController
@RequestMapping(value = "/cylinder") @RequestMapping(value = "/cylinder")
...@@ -53,6 +55,8 @@ public class CylinderController { ...@@ -53,6 +55,8 @@ public class CylinderController {
@Autowired @Autowired
private CylinderFillingDataValidationService cylinderFillingDataValidationService; private CylinderFillingDataValidationService cylinderFillingDataValidationService;
@Autowired @Autowired
CylinderFillingMessageService cylinderFillingMessageService;
@Autowired
private EmqKeeper emqKeeper; private EmqKeeper emqKeeper;
private SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); private SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
...@@ -113,31 +117,43 @@ public class CylinderController { ...@@ -113,31 +117,43 @@ public class CylinderController {
logger.error("液化气体气瓶充装信息上报,数据校验失败"); logger.error("液化气体气瓶充装信息上报,数据校验失败");
cylinderFillingMessage.setMessage(e.getMessage()); cylinderFillingMessage.setMessage(e.getMessage());
} }
if (!ObjectUtils.isEmpty(validateResult)) { if (!ObjectUtils.isEmpty(validateResult)) {
cylinderFillingMessage.setCylinderNumber(validateResult.getCylinderNumber()); cylinderFillingMessage.setCylinderNumber(validateResult.getCylinderNumber());
List<String> message = new ArrayList<>(); List<String> message = new ArrayList<>();
Boolean flag = true; Integer errorNumber = 0;
JSONObject error = new JSONObject();
if (!ObjectUtils.isEmpty(validateResult.getBeforeErrorData())) { if (!ObjectUtils.isEmpty(validateResult.getBeforeErrorData())) {
flag = false; errorNumber += validateResult.getBeforeErrorData().size();
message.add("充装前检查异常数:" + validateResult.getBeforeErrorData().size()); error.put("充装前检查错误数据:", validateResult.getBeforeErrorData());
message.add("充装前检查数据异常气瓶数:" + validateResult.getBeforeErrorCylinderNumber());
} }
if (!ObjectUtils.isEmpty(validateResult.getRecordErrorData())) { if (!ObjectUtils.isEmpty(validateResult.getRecordErrorData())) {
flag = false; errorNumber += validateResult.getRecordErrorData().size();
message.add("充装记录异常数:" + validateResult.getRecordErrorData().size()); error.put("充装填充错误数据:", validateResult.getRecordErrorData());
message.add("充装记录数据异常气瓶数:" + validateResult.getRecordErrorCylinderNumber());
} }
if (!ObjectUtils.isEmpty(validateResult.getAfterErrorData())) { if (!ObjectUtils.isEmpty(validateResult.getAfterErrorData())) {
flag = false; errorNumber += validateResult.getAfterErrorData().size();
message.add("充装后复查异常数:" + validateResult.getAfterErrorData().size()); error.put("充装后错误数据:", validateResult.getAfterErrorData());
message.add("充装后复查数据异常气瓶数:" + validateResult.getAfterErrorCylinderNumber());
} }
if (errorNumber <= 0) {
if (flag) { message.add("液化气体气瓶充装信息成功数:" + validateResult.getSuccessCylinderNumber() + "条");
message.add("液化气体气瓶充装信息上传成功"); } else {
cylinderFillingMessage.setMessage(String.join("条; ", message));
CylinderFillingMessageModel cylinderFillingMessageModel = new CylinderFillingMessageModel();
BeanUtils.copyProperties(cylinderFillingMessage, cylinderFillingMessageModel);
cylinderFillingMessageService.createWithModel(cylinderFillingMessageModel);
emqKeeper.getMqttClient().publish("openapi/cylinder/filling", JSONObject.fromObject(cylinderFillingMessage).toString().getBytes(), 2, false);
throw new BadRequest(error.toString());
} }
cylinderFillingMessage.setMessage(String.join(",", message));
} }
Map<String, Class> classMap = new HashMap<>(); Map<String, Class> classMap = new HashMap<>();
classMap.put("fillingBefore", TmCylinderFillingModel.class); classMap.put("fillingBefore", TmCylinderFillingModel.class);
classMap.put("filling", TmCylinderFillingRecordModel.class); classMap.put("filling", TmCylinderFillingRecordModel.class);
...@@ -155,7 +171,12 @@ public class CylinderController { ...@@ -155,7 +171,12 @@ public class CylinderController {
cylinderFillingRecordService.createCylinderFilling(fillingList); cylinderFillingRecordService.createCylinderFilling(fillingList);
cylinderFillingCheckService.createCylinderFillingAfter(fillingAfterList); cylinderFillingCheckService.createCylinderFillingAfter(fillingAfterList);
CylinderFillingMessageModel cylinderFillingMessageModel = new CylinderFillingMessageModel();
BeanUtils.copyProperties(cylinderFillingMessage, cylinderFillingMessageModel);
cylinderFillingMessageService.createWithModel(cylinderFillingMessageModel);
emqKeeper.getMqttClient().publish("openapi/cylinder/filling", JSONObject.fromObject(cylinderFillingMessage).toString().getBytes(), 2, false); emqKeeper.getMqttClient().publish("openapi/cylinder/filling", JSONObject.fromObject(cylinderFillingMessage).toString().getBytes(), 2, false);
return ResponseHelper.buildResponse("OK"); return ResponseHelper.buildResponse("OK");
} }
......
...@@ -7,6 +7,11 @@ import java.util.List; ...@@ -7,6 +7,11 @@ import java.util.List;
@Data @Data
public class CylinderFillingDataValidationResultModel { public class CylinderFillingDataValidationResultModel {
private Integer cylinderNumber; private Integer cylinderNumber;
private Integer beforeErrorCylinderNumber;
private Integer recordErrorCylinderNumber;
private Integer afterErrorCylinderNumber;
private Integer successCylinderNumber;
private List<String> beforeErrorData; private List<String> beforeErrorData;
private List<String> recordErrorData; private List<String> recordErrorData;
private List<String> afterErrorData; private List<String> afterErrorData;
......
package com.yeejoin.amos.api.openapi.face.model;
import lombok.Data;
import org.typroject.tyboot.core.rdbms.model.BaseModel;
@Data
public class CylinderFillingMessageModel extends BaseModel {
private String time;
private String fillingCompanyName;
private Integer cylinderNumber;
private String message;
}
package com.yeejoin.amos.api.openapi.face.orm.dao;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.yeejoin.amos.api.openapi.face.orm.entity.CylinderFillingMessageEntity;
import com.yeejoin.amos.api.openapi.face.orm.entity.OpenapiLog;
public interface CylinderFillingMessageMapper extends BaseMapper<CylinderFillingMessageEntity> {
}
package com.yeejoin.amos.api.openapi.face.orm.entity;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.typroject.tyboot.core.rdbms.orm.entity.BaseEntity;
@EqualsAndHashCode(callSuper = true)
@Data
@TableName("iot_cylinder_filling_logs")
public class CylinderFillingMessageEntity extends BaseEntity {
@TableField("filling_date")
private String time;
@TableField("filling_company_name")
private String fillingCompanyName;
@TableField("cylinder_number")
private Integer cylinderNumber;
@TableField("message")
private String message;
}
...@@ -187,6 +187,10 @@ public class CylinderFillingDataValidationService { ...@@ -187,6 +187,10 @@ public class CylinderFillingDataValidationService {
} }
Set<String> cylinderCodeSet = new ConcurrentHashSet<>(); Set<String> cylinderCodeSet = new ConcurrentHashSet<>();
Set<String> beforeErrorCylinderSet = new ConcurrentHashSet<>();
Set<String> recordErrorCylinderSet = new ConcurrentHashSet<>();
Set<String> afterErrorCylinderSet = new ConcurrentHashSet<>();
CompletableFuture<List<String>> beforeFuture = CompletableFuture.supplyAsync(() -> { CompletableFuture<List<String>> beforeFuture = CompletableFuture.supplyAsync(() -> {
// 异步校验检验前数据 // 异步校验检验前数据
JSONArray fillingBefore = jsonobject.getJSONArray("fillingBefore"); JSONArray fillingBefore = jsonobject.getJSONArray("fillingBefore");
...@@ -196,7 +200,7 @@ public class CylinderFillingDataValidationService { ...@@ -196,7 +200,7 @@ public class CylinderFillingDataValidationService {
cylinderCodeSet.add(row.getString("sequenceCode")); cylinderCodeSet.add(row.getString("sequenceCode"));
} }
} }
return validateFillingBeforeData(fillingBefore); return validateFillingBeforeData(fillingBefore, beforeErrorCylinderSet);
}); });
CompletableFuture<List<String>> recordFuture = CompletableFuture.supplyAsync(() -> { CompletableFuture<List<String>> recordFuture = CompletableFuture.supplyAsync(() -> {
// 异步校验检填充数据 // 异步校验检填充数据
...@@ -207,7 +211,7 @@ public class CylinderFillingDataValidationService { ...@@ -207,7 +211,7 @@ public class CylinderFillingDataValidationService {
cylinderCodeSet.add(row.getString("sequenceCode")); cylinderCodeSet.add(row.getString("sequenceCode"));
} }
} }
return validateFillingRecordData(filling); return validateFillingRecordData(filling, recordErrorCylinderSet);
}); });
CompletableFuture<List<String>> afterFuture = CompletableFuture.supplyAsync(() -> { CompletableFuture<List<String>> afterFuture = CompletableFuture.supplyAsync(() -> {
...@@ -219,7 +223,7 @@ public class CylinderFillingDataValidationService { ...@@ -219,7 +223,7 @@ public class CylinderFillingDataValidationService {
cylinderCodeSet.add(row.getString("sequenceCode")); cylinderCodeSet.add(row.getString("sequenceCode"));
} }
} }
return validateFillinAfterData(jsonobject.getJSONArray("fillingAfter")); return validateFillinAfterData(jsonobject.getJSONArray("fillingAfter"), afterErrorCylinderSet);
}); });
/** /**
...@@ -230,6 +234,14 @@ public class CylinderFillingDataValidationService { ...@@ -230,6 +234,14 @@ public class CylinderFillingDataValidationService {
result.setRecordErrorData(recordFuture.get()); result.setRecordErrorData(recordFuture.get());
result.setAfterErrorData(afterFuture.get()); result.setAfterErrorData(afterFuture.get());
result.setCylinderNumber(cylinderCodeSet.size()); result.setCylinderNumber(cylinderCodeSet.size());
result.setBeforeErrorCylinderNumber(beforeErrorCylinderSet.size());
result.setRecordErrorCylinderNumber(recordErrorCylinderSet.size());
result.setAfterErrorCylinderNumber(afterErrorCylinderSet.size());
cylinderCodeSet.removeAll(beforeErrorCylinderSet);
cylinderCodeSet.removeAll(recordErrorCylinderSet);
cylinderCodeSet.removeAll(afterErrorCylinderSet);
result.setSuccessCylinderNumber(cylinderCodeSet.size());
return result; return result;
} }
...@@ -239,15 +251,23 @@ public class CylinderFillingDataValidationService { ...@@ -239,15 +251,23 @@ public class CylinderFillingDataValidationService {
* @param jsonArray * @param jsonArray
* @return List 异常数据 * @return List 异常数据
*/ */
public List<String> validateFillingBeforeData(JSONArray jsonArray) { public List<String> validateFillingBeforeData(JSONArray jsonArray, Set<String> errorCylinderSet) {
// 1.必填校验 // 1.必填校验
List<String> errorRows = validateRequired(FillingBeforeFieldEnum.getAllRequireKeys(), jsonArray); List<String> errorRows = validateRequired(FillingBeforeFieldEnum.getAllRequireKeys(), jsonArray);
if (!ObjectUtils.isEmpty(errorRows)) { if (!ObjectUtils.isEmpty(errorRows)) {
errorRows.stream().forEach( json -> {
String sequenceCode = JSONObject.fromObject(json).getString("sequenceCode");
errorCylinderSet.add(sequenceCode);
});
return errorRows.stream().map(e -> "必填字段不能为空:" + e).collect(Collectors.toList()); return errorRows.stream().map(e -> "必填字段不能为空:" + e).collect(Collectors.toList());
} }
// 2.本次上传数据唯一性校验 // 2.本次上传数据唯一性校验
errorRows = validateUnique(FillingBeforeFieldEnum.getAllUniqueKeys(), jsonArray); errorRows = validateUnique(FillingBeforeFieldEnum.getAllUniqueKeys(), jsonArray);
if (!ObjectUtils.isEmpty(errorRows)) { if (!ObjectUtils.isEmpty(errorRows)) {
errorRows.stream().forEach( json -> {
String sequenceCode = JSONObject.fromObject(json).getString("sequenceCode");
errorCylinderSet.add(sequenceCode);
});
return errorRows.stream().map(e -> "上传数据重复:" + e).collect(Collectors.toList()); return errorRows.stream().map(e -> "上传数据重复:" + e).collect(Collectors.toList());
} }
// // 3.检查气瓶唯一标识码是否存在 // // 3.检查气瓶唯一标识码是否存在
...@@ -270,15 +290,23 @@ public class CylinderFillingDataValidationService { ...@@ -270,15 +290,23 @@ public class CylinderFillingDataValidationService {
* @param jsonArray * @param jsonArray
* @return List 异常数据 * @return List 异常数据
*/ */
public List<String> validateFillingRecordData(JSONArray jsonArray) { public List<String> validateFillingRecordData(JSONArray jsonArray, Set<String> errorCylinderSet) {
// 1.必填校验 // 1.必填校验
List<String> errorRows = validateRequired(FillingRecordFieldEnum.getAllRequireKeys(), jsonArray); List<String> errorRows = validateRequired(FillingRecordFieldEnum.getAllRequireKeys(), jsonArray);
if (!ObjectUtils.isEmpty(errorRows)) { if (!ObjectUtils.isEmpty(errorRows)) {
errorRows.stream().forEach( json -> {
String sequenceCode = JSONObject.fromObject(json).getString("sequenceCode");
errorCylinderSet.add(sequenceCode);
});
return errorRows.stream().map(e -> "必填字段不能为空::" + e).collect(Collectors.toList()); return errorRows.stream().map(e -> "必填字段不能为空::" + e).collect(Collectors.toList());
} }
// 2.本次上传数据唯一性校验 // 2.本次上传数据唯一性校验
errorRows = validateUnique(FillingRecordFieldEnum.getAllUniqueKeys(), jsonArray); errorRows = validateUnique(FillingRecordFieldEnum.getAllUniqueKeys(), jsonArray);
if (!ObjectUtils.isEmpty(errorRows)) { if (!ObjectUtils.isEmpty(errorRows)) {
errorRows.stream().forEach( json -> {
String sequenceCode = JSONObject.fromObject(json).getString("sequenceCode");
errorCylinderSet.add(sequenceCode);
});
return errorRows.stream().map(e -> "上传数据重复:" + e).collect(Collectors.toList()); return errorRows.stream().map(e -> "上传数据重复:" + e).collect(Collectors.toList());
} }
// // 3.检查气瓶唯一标识码是否存在 // // 3.检查气瓶唯一标识码是否存在
...@@ -301,16 +329,24 @@ public class CylinderFillingDataValidationService { ...@@ -301,16 +329,24 @@ public class CylinderFillingDataValidationService {
* @param jsonArray * @param jsonArray
* @return List 异常数据 * @return List 异常数据
*/ */
public List<String> validateFillinAfterData(JSONArray jsonArray) { public List<String> validateFillinAfterData(JSONArray jsonArray, Set<String> errorCylinderSet) {
// 1.必填校验 // 1.必填校验
List<String> errorRows = validateRequired(FillingAfterFieldEnum.getAllRequireKeys(), jsonArray); List<String> errorRows = validateRequired(FillingAfterFieldEnum.getAllRequireKeys(), jsonArray);
if (!ObjectUtils.isEmpty(errorRows)) { if (!ObjectUtils.isEmpty(errorRows)) {
errorRows.stream().forEach( json -> {
String sequenceCode = JSONObject.fromObject(json).getString("sequenceCode");
errorCylinderSet.add(sequenceCode);
});
return errorRows.stream().map(e -> "必填字段不能为空::" + e).collect(Collectors.toList()); return errorRows.stream().map(e -> "必填字段不能为空::" + e).collect(Collectors.toList());
} }
// 2.本次上传数据唯一性校验 // 2.本次上传数据唯一性校验
errorRows = validateUnique(FillingAfterFieldEnum.getAllUniqueKeys(), jsonArray); errorRows = validateUnique(FillingAfterFieldEnum.getAllUniqueKeys(), jsonArray);
if (!ObjectUtils.isEmpty(errorRows)) { if (!ObjectUtils.isEmpty(errorRows)) {
errorRows.stream().forEach( json -> {
String sequenceCode = JSONObject.fromObject(json).getString("sequenceCode");
errorCylinderSet.add(sequenceCode);
});
return errorRows.stream().map(e -> "上传数据重复:" + e).collect(Collectors.toList()); return errorRows.stream().map(e -> "上传数据重复:" + e).collect(Collectors.toList());
} }
// // 3.检查气瓶唯一标识码是否存在 // // 3.检查气瓶唯一标识码是否存在
......
package com.yeejoin.amos.api.openapi.face.service;
import com.yeejoin.amos.api.openapi.face.model.CylinderFillingMessageModel;
import com.yeejoin.amos.api.openapi.face.orm.dao.CylinderFillingMessageMapper;
import com.yeejoin.amos.api.openapi.face.orm.entity.CylinderFillingMessageEntity;
import org.springframework.stereotype.Component;
import org.typroject.tyboot.core.rdbms.service.BaseService;
@Component
public class CylinderFillingMessageService extends BaseService<CylinderFillingMessageModel, CylinderFillingMessageEntity, CylinderFillingMessageMapper> {
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment