|
|
@@ -521,58 +521,37 @@ public class KwfTruckReportService {
|
|
|
//有效上报信息
|
|
|
List<KwfTruckReportDto> effective = new ArrayList();
|
|
|
//已有运力/识别失败
|
|
|
- int haveCount = Global.NUMERICAL_ZERO, errorCount = Global.NUMERICAL_ZERO;
|
|
|
+ int haveCount = Global.NUMERICAL_ZERO, errorCount = Global.NUMERICAL_ZERO, rowIndex = Global.NUMERICAL_ZERO;
|
|
|
+ List<String> errorMsg = new ArrayList<>();
|
|
|
+ List<String> haveMsg = new ArrayList<>();
|
|
|
for (String str:params){
|
|
|
+ rowIndex ++;
|
|
|
/**识别上报数据**/
|
|
|
KwfTruckReportDto reportDto = analysis(str);
|
|
|
- if (reportDto == null) {
|
|
|
+ if (reportDto == null || StringUtils.isNotBlank(reportDto.getRemark())) {
|
|
|
errorCount ++;
|
|
|
+ errorMsg.add("第" + rowIndex + "行数据有误," + reportDto.getRemark());
|
|
|
continue;
|
|
|
}
|
|
|
|
|
|
- /**车辆信息**/
|
|
|
- //校验车辆档案是否存在
|
|
|
- List<KwfTruck> trucks = truckDao.findTruck(new HashMap<>(Global.NUMERICAL_SIXTEEN) {{put("truckNo", reportDto.getTruckNo());}});
|
|
|
- if (!CollectionUtils.isEmpty(trucks)) {
|
|
|
- //校验车辆是否已上报
|
|
|
- KwfTruck truck = trucks.get(Global.NUMERICAL_ZERO);
|
|
|
- List<Map<String, Object>> reports = truckReportDao.findList(new HashMap<>(Global.NUMERICAL_SIXTEEN) {{
|
|
|
- put("truckId", truck.getId());
|
|
|
- put("entId", LoginUserHolder.getEntId());
|
|
|
- }});
|
|
|
- if (!CollectionUtils.isEmpty(reports)) {
|
|
|
- haveCount ++;
|
|
|
- continue;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- /**档案信息**/
|
|
|
- //校验司机档案是否存在
|
|
|
- List<KwfDriver> drivers = driverDao.findDriver(new HashMap<>(Global.NUMERICAL_SIXTEEN) {{ put("phone", reportDto.getPhone()); }});
|
|
|
- if (!CollectionUtils.isEmpty(drivers)) {
|
|
|
- //校验司机是否已上报
|
|
|
- KwfDriver driver = drivers.get(Global.NUMERICAL_ZERO);
|
|
|
- List<Map<String, Object>> reports = truckReportDao.findList(new HashMap<>(Global.NUMERICAL_SIXTEEN) {{
|
|
|
- put("driverId", driver.getId());
|
|
|
- put("entId", LoginUserHolder.getEntId());
|
|
|
- }});
|
|
|
- if (!CollectionUtils.isEmpty(reports)) {
|
|
|
- haveCount ++;
|
|
|
- continue;
|
|
|
- }
|
|
|
+ /**校验车/司机是否已上报**/
|
|
|
+ String haveMessage = chenkHave(reportDto);
|
|
|
+ if (StringUtils.isNotBlank(haveMessage)) {
|
|
|
+ haveCount ++;
|
|
|
+ haveMsg.add("第" + rowIndex + "行数据," + haveMessage);
|
|
|
}
|
|
|
-
|
|
|
effective.add(reportDto);
|
|
|
}
|
|
|
|
|
|
/**返回数据**/
|
|
|
Map<String, Object> resultMap = new HashMap<>(Global.NUMERICAL_SIXTEEN);
|
|
|
resultMap.put("haveCount", haveCount);
|
|
|
+ resultMap.put("haveMsg", haveMsg);
|
|
|
resultMap.put("errorCount", errorCount);
|
|
|
+ resultMap.put("errorMsg", errorMsg);
|
|
|
resultMap.put("fail", haveCount + errorCount);
|
|
|
resultMap.put("success", effective.size());
|
|
|
resultMap.put("list", effective);
|
|
|
-
|
|
|
return HttpResult.ok(resultMap);
|
|
|
}
|
|
|
|
|
|
@@ -622,58 +601,125 @@ public class KwfTruckReportService {
|
|
|
* @date 2023/7/18
|
|
|
**/
|
|
|
public KwfTruckReportDto analysis(String str) {
|
|
|
+ StringBuilder msg = new StringBuilder();
|
|
|
/**识别上报数据**/
|
|
|
KwfTruckReportDto reportDto = new KwfTruckReportDto();
|
|
|
//非控校验
|
|
|
if (StringUtils.isBlank(str) || StringUtils.isBlank(str.trim())) {
|
|
|
- return null;
|
|
|
+ msg.append("数据为空!");
|
|
|
+ reportDto.setRemark(msg.toString());
|
|
|
+ return reportDto;
|
|
|
}
|
|
|
//字符截取-英文逗号/中文逗号
|
|
|
- String[] strArray = str.split(Global.COMMA1);
|
|
|
- strArray = (strArray == null || strArray.length <= 1) ? str.split(Global.COMMA) : strArray;
|
|
|
+ str = str.replaceAll(Global.COMMA1, Global.COMMA);
|
|
|
+ String[] strArray = str.split(Global.COMMA);
|
|
|
if (strArray == null || strArray.length <= 1 || strArray.length != 5 ) {
|
|
|
- return null;
|
|
|
+ msg.append("数据格式不正确!");
|
|
|
+ reportDto.setRemark(msg.toString());
|
|
|
+ return reportDto;
|
|
|
}
|
|
|
|
|
|
/**数据校验**/
|
|
|
//车牌号-非空/长度为7
|
|
|
String truckNo = strArray[0];
|
|
|
if (StringUtils.isBlank(truckNo) || truckNo.trim().length() != 7) {
|
|
|
- return null;
|
|
|
+ msg.append("车牌号格式不正确!");
|
|
|
}
|
|
|
|
|
|
//司机姓名-非空
|
|
|
String name = strArray[1];
|
|
|
if (StringUtils.isBlank(name) || name.trim().length() == 0) {
|
|
|
- return null;
|
|
|
+ msg.append("司机姓名不能为空!");
|
|
|
}
|
|
|
|
|
|
//司机电话-非空/手机号正则校验
|
|
|
String phone = strArray[2];
|
|
|
- if (StringUtils.isBlank(phone) || !RegularUtils.matchs(RegularUtils.PHONE_REG, phone)) {
|
|
|
- return null;
|
|
|
+ if (StringUtils.isBlank(phone) || !RegularUtils.matchs(RegularUtils.PHONE_REG, phone.trim())) {
|
|
|
+ msg.append("司机电话格式不正确!");
|
|
|
}
|
|
|
|
|
|
//身份证号-非空/身份证正则校验
|
|
|
String idcard = strArray[3];
|
|
|
- if (StringUtils.isBlank(idcard) || !RegularUtils.matchs(RegularUtils.IDCARD, idcard)) {
|
|
|
- return null;
|
|
|
+ if (StringUtils.isBlank(idcard) || !RegularUtils.matchs(RegularUtils.IDCARD, idcard.trim())) {
|
|
|
+ msg.append("身份证号格式不正确!");
|
|
|
}
|
|
|
|
|
|
//核定载量/吨-非空/数值正则校验
|
|
|
String actualWeight = strArray[4];
|
|
|
- if (StringUtils.isBlank(actualWeight) || !RegularUtils.matchs(RegularUtils.DECIMAL_REG, actualWeight)) {
|
|
|
- return null;
|
|
|
+ actualWeight = StringUtils.isNotBlank(actualWeight) ? actualWeight.replaceAll(Global.UNIT_TON, Global.EMPTY_STRING) : actualWeight;
|
|
|
+ if (StringUtils.isBlank(actualWeight) || !RegularUtils.matchs(RegularUtils.DECIMAL_REG, actualWeight.trim())) {
|
|
|
+ msg.append("核定载量格式不正确!");
|
|
|
}
|
|
|
|
|
|
- reportDto.setTruckNo(truckNo);
|
|
|
- reportDto.setName(name);
|
|
|
- reportDto.setPhone(phone);
|
|
|
- reportDto.setIdcard(idcard);
|
|
|
- reportDto.setActualWeight(new BigDecimal(actualWeight));
|
|
|
+ if (msg.length() > Global.NUMERICAL_ZERO) {
|
|
|
+ reportDto.setRemark(msg.toString());
|
|
|
+ return reportDto;
|
|
|
+ }
|
|
|
+ reportDto.setTruckNo(truckNo.trim());
|
|
|
+ reportDto.setName(name.trim());
|
|
|
+ reportDto.setPhone(phone.trim());
|
|
|
+ reportDto.setIdcard(idcard.trim());
|
|
|
+ reportDto.setActualWeight(new BigDecimal(actualWeight.trim()));
|
|
|
return reportDto;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * @param reportDto 上报对象
|
|
|
+ * @desc 校验车/司机是否已上报
|
|
|
+ * @author zk
|
|
|
+ * @date 2023/8/29
|
|
|
+ **/
|
|
|
+ public String chenkHave(KwfTruckReportDto reportDto){
|
|
|
+ /**车辆信息**/
|
|
|
+ //校验车辆档案是否存在
|
|
|
+ StringBuilder haveMsg = new StringBuilder();
|
|
|
+ List<KwfTruck> trucks = truckDao.findTruck(new HashMap<>(Global.NUMERICAL_SIXTEEN) {{put("truckNo", reportDto.getTruckNo());}});
|
|
|
+ if (!CollectionUtils.isEmpty(trucks)) {
|
|
|
+ //校验车辆是否已上报
|
|
|
+ KwfTruck truck = trucks.get(Global.NUMERICAL_ZERO);
|
|
|
+ List<Map<String, Object>> reports = truckReportDao.findList(new HashMap<>(Global.NUMERICAL_SIXTEEN) {{
|
|
|
+ put("truckId", truck.getId());
|
|
|
+ put("entId", LoginUserHolder.getEntId());
|
|
|
+ }});
|
|
|
+ if (!CollectionUtils.isEmpty(reports)) {
|
|
|
+ haveMsg.append(truck.getTruckNo() + "已上报!");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**档案信息**/
|
|
|
+ //校验司机档案是否存在
|
|
|
+ List<KwfDriver> drivers = driverDao.findDriver(new HashMap<>(Global.NUMERICAL_SIXTEEN) {{ put("phone", reportDto.getPhone()); }});
|
|
|
+ if (!CollectionUtils.isEmpty(drivers)) {
|
|
|
+ //校验司机是否已上报
|
|
|
+ KwfDriver driver = drivers.get(Global.NUMERICAL_ZERO);
|
|
|
+ List<Map<String, Object>> reports = truckReportDao.findList(new HashMap<>(Global.NUMERICAL_SIXTEEN) {{
|
|
|
+ put("driverId", driver.getId());
|
|
|
+ put("entId", LoginUserHolder.getEntId());
|
|
|
+ }});
|
|
|
+ if (!CollectionUtils.isEmpty(reports)) {
|
|
|
+ haveMsg.append(driver.getPhone() + "已上报!");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return haveMsg.toString();
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ public static void main(String[] args) {
|
|
|
+ String str = "川L0281D,王琳,18283808584,510623199909073568,30吨";
|
|
|
+ str = str.replaceAll(Global.COMMA1, Global.COMMA);
|
|
|
+ System.out.println(str);
|
|
|
+ //字符截取-英文逗号/中文逗号
|
|
|
+ String[] strArray = str.split(Global.COMMA);
|
|
|
+ if (strArray == null || strArray.length <= 1 || strArray.length != 5 ) {
|
|
|
+ System.out.println(strArray);
|
|
|
+ }
|
|
|
+ KwfTruckReportDto reportDto = new KwfTruckReportService().analysis(str);
|
|
|
+ System.out.println(com.alibaba.fastjson2.JSON.toJSON(reportDto));
|
|
|
+ //String errorMsg = "第" + rowIndex + "行数据有误," + validMsg;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
/**
|
|
|
* @param file 上传文件
|
|
|
* @desc 参数校验
|