diff --git a/shapelight-admin/src/main/java/net/shapelight/modules/car/controller/CarOpenApi.java b/shapelight-admin/src/main/java/net/shapelight/modules/car/controller/CarOpenApi.java index 7fef292..73c244c 100644 --- a/shapelight-admin/src/main/java/net/shapelight/modules/car/controller/CarOpenApi.java +++ b/shapelight-admin/src/main/java/net/shapelight/modules/car/controller/CarOpenApi.java @@ -68,6 +68,9 @@ public class CarOpenApi { @Autowired private TenPackService tenPackService; + @Autowired + private TenPackChannalService tenPackChannalService; + @PostMapping({"/getMsg/{cellId}"}) @ApiOperation("获取MSG") @ApiImplicitParams({@ApiImplicitParam(name = "sn", value = "设备sn", paramType = "query", dataType = "String", required = true)}) @@ -122,68 +125,135 @@ public class CarOpenApi { return R.ok(); } - @PostMapping({"/pushEnterRecord"}) - @ApiOperation("第三方推送入场记录") - public Map pushEnterRecord(@RequestBody Object object) { - Map res = new HashMap<>(); - res.put("code", "401"); - res.put("msg", "签名结果不一致"); - JSONObject msgJson = (JSONObject) JSONObject.toJSON(object); - String sign = msgJson.getString("sign"); - String appKey = msgJson.getString("appKey"); - Long timestamp = msgJson.getLong("timestamp"); - JSONObject bizContent = msgJson.getJSONObject("bizContent"); - String parkCode = bizContent.getString("parkCode"); - String parkName = bizContent.getString("parkName"); - String orderNum = bizContent.getString("orderNum"); - String plateNum = bizContent.getString("plateNum"); - String channelName = bizContent.getString("channelName"); - long enterTimeLong = bizContent.getLongValue("enterTime"); - Date enterTime = new Date(enterTimeLong * 1000L); - int type = bizContent.getIntValue("type"); - int carType = bizContent.getIntValue("carType"); - String imgUrl = bizContent.getString("imgUrl"); - - //去掉 amp; - imgUrl = imgUrl.replace("amp;", ""); - - TenPackRecordEnterEntity enter = new TenPackRecordEnterEntity(); - enter.setParkCode(parkCode); - enter.setParkName(parkName); - enter.setOrderNumber(orderNum); - enter.setPlateNumber(plateNum); - enter.setChannelName(channelName); - enter.setType(Integer.valueOf(type)); - enter.setCarType(Integer.valueOf(carType)); - enter.setEnterTime(enterTime); - if (!StringUtils.isEmpty(imgUrl)) { - URL url = null; - InputStream is = null; - HttpURLConnection httpUrl = null; - try { - url = new URL(imgUrl); - - BufferedImage image = ImageIO.read(url); - //获取图片的宽、高 - System.out.println("Width: " + image.getWidth()); - System.out.println("Height: " + image.getHeight()); - int w = image.getWidth(); - int h = image.getHeight(); - //调整尺寸不能大于1024 - if(w>1024 || h>1024){ - image = ThumbnailsUtils.resizeImageOne(image,1024,1024); - } - - String fileName = "car/" + enter.getParkCode() + "/" + UUIDUtil.uuid() + ".jpg"; - - byte[] data = ImageUtils.imageToBytes(image); - is = new ByteArrayInputStream(data); - int rl = is.available(); - PutObjectOptions putObjectOptions = new PutObjectOptions(rl, -1L); - putObjectOptions.setContentType("image/jpeg"); - this.minioClient.putObject(this.minioConfig - .getBucketName(), fileName, is, putObjectOptions); - +// @PostMapping({"/pushEnterRecord"}) +// @ApiOperation("第三方推送入场记录") +// public Map pushEnterRecord(@RequestBody Object object) { +// Map res = new HashMap<>(); +// res.put("code", "401"); +// res.put("msg", "签名结果不一致"); +// JSONObject msgJson = (JSONObject) JSONObject.toJSON(object); +// String sign = msgJson.getString("sign"); +// String appKey = msgJson.getString("appKey"); +// Long timestamp = msgJson.getLong("timestamp"); +// JSONObject bizContent = msgJson.getJSONObject("bizContent"); +// String parkCode = bizContent.getString("parkCode"); +// String parkName = bizContent.getString("parkName"); +// String orderNum = bizContent.getString("orderNum"); +// String plateNum = bizContent.getString("plateNum"); +// String channelName = bizContent.getString("channelName"); +// long enterTimeLong = bizContent.getLongValue("enterTime"); +// Date enterTime = new Date(enterTimeLong * 1000L); +// int type = bizContent.getIntValue("type"); +// int carType = bizContent.getIntValue("carType"); +// String imgUrl = bizContent.getString("imgUrl"); +// +// //去掉 amp; +// imgUrl = imgUrl.replace("amp;", ""); +// +// TenPackRecordEnterEntity enter = new TenPackRecordEnterEntity(); +// enter.setParkCode(parkCode); +// enter.setParkName(parkName); +// enter.setOrderNumber(orderNum); +// enter.setPlateNumber(plateNum); +// enter.setChannelName(channelName); +// enter.setType(Integer.valueOf(type)); +// enter.setCarType(Integer.valueOf(carType)); +// enter.setEnterTime(enterTime); +// if (!StringUtils.isEmpty(imgUrl)) { +// URL url = null; +// InputStream is = null; +// HttpURLConnection httpUrl = null; +// try { +// url = new URL(imgUrl); +// +// BufferedImage image = ImageIO.read(url); +// //获取图片的宽、高 +// System.out.println("Width: " + image.getWidth()); +// System.out.println("Height: " + image.getHeight()); +// int w = image.getWidth(); +// int h = image.getHeight(); +// //调整尺寸不能大于1024 +// if(w>1024 || h>1024){ +// image = ThumbnailsUtils.resizeImageOne(image,1024,1024); +// } +// +// String fileName = "car/" + enter.getParkCode() + "/" + UUIDUtil.uuid() + ".jpg"; +// +// byte[] data = ImageUtils.imageToBytes(image); +// is = new ByteArrayInputStream(data); +// int rl = is.available(); +// PutObjectOptions putObjectOptions = new PutObjectOptions(rl, -1L); +// putObjectOptions.setContentType("image/jpeg"); +// this.minioClient.putObject(this.minioConfig +// .getBucketName(), fileName, is, putObjectOptions); +// +//// httpUrl = (HttpURLConnection) url.openConnection(); +//// httpUrl.connect(); +//// httpUrl.getInputStream(); +//// is = httpUrl.getInputStream(); +//// String fileName = "car/" + enter.getParkCode() + "/" + UUIDUtil.uuid() + ".jpg"; +//// PutObjectOptions putObjectOptions = new PutObjectOptions(is.available(), -1L); +//// putObjectOptions.setContentType("image/jpeg"); +//// this.minioClient.putObject(this.minioConfig +//// .getBucketName(), fileName, is, putObjectOptions); +// enter.setImage(fileName); +// } catch (Exception e) { +// e.printStackTrace(); +// } finally { +// if (is != null) +// try { +// is.close(); +// } catch (IOException e) { +// e.printStackTrace(); +// } +// if (httpUrl != null) +// httpUrl.disconnect(); +// } +// } +// this.tenPackRecordEnterService.save(enter); +// res.put("code", "200"); +// res.put("msg", "成功"); +// return res; +// } +// +// @PostMapping({"/pushExitRecord"}) +// @ApiOperation("第三方推送出场记录") +// public Map pushExitRecord(@RequestBody Object object) { +// Map res = new HashMap<>(); +// res.put("code", "401"); +// res.put("msg", "签名结果不一致"); +// JSONObject msgJson = (JSONObject) JSONObject.toJSON(object); +// String sign = msgJson.getString("sign"); +// String appKey = msgJson.getString("appKey"); +// Long timestamp = msgJson.getLong("timestamp"); +// JSONObject bizContent = msgJson.getJSONObject("bizContent"); +// String parkCode = bizContent.getString("parkCode"); +// String parkName = bizContent.getString("parkName"); +// String orderNum = bizContent.getString("orderNum"); +// String plateNum = bizContent.getString("plateNum"); +// String channelName = bizContent.getString("channelName"); +// long exitTimeLong = bizContent.getLongValue("exitTime"); +// Date exitTime = new Date(exitTimeLong * 1000L); +// int type = bizContent.getIntValue("type"); +// int carType = bizContent.getIntValue("carType"); +// long parkTime = bizContent.getLongValue("parkTime"); +// String imgUrl = bizContent.getString("imgUrl"); +// TenPackRecordExitEntity enter = new TenPackRecordExitEntity(); +// enter.setParkCode(parkCode); +// enter.setParkName(parkName); +// enter.setOrderNumber(orderNum); +// enter.setPlateNumber(plateNum); +// enter.setChannelName(channelName); +// enter.setType(Integer.valueOf(type)); +// enter.setCarType(Integer.valueOf(carType)); +// enter.setExitTime(exitTime); +// enter.setPackTime(Long.valueOf(parkTime)); +// if (!StringUtils.isEmpty(imgUrl)) { +// URL url = null; +// InputStream is = null; +// HttpURLConnection httpUrl = null; +// try { +// url = new URL(imgUrl); // httpUrl = (HttpURLConnection) url.openConnection(); // httpUrl.connect(); // httpUrl.getInputStream(); @@ -193,92 +263,25 @@ public class CarOpenApi { // putObjectOptions.setContentType("image/jpeg"); // this.minioClient.putObject(this.minioConfig // .getBucketName(), fileName, is, putObjectOptions); - enter.setImage(fileName); - } catch (Exception e) { - e.printStackTrace(); - } finally { - if (is != null) - try { - is.close(); - } catch (IOException e) { - e.printStackTrace(); - } - if (httpUrl != null) - httpUrl.disconnect(); - } - } - this.tenPackRecordEnterService.save(enter); - res.put("code", "200"); - res.put("msg", "成功"); - return res; - } - - @PostMapping({"/pushExitRecord"}) - @ApiOperation("第三方推送出场记录") - public Map pushExitRecord(@RequestBody Object object) { - Map res = new HashMap<>(); - res.put("code", "401"); - res.put("msg", "签名结果不一致"); - JSONObject msgJson = (JSONObject) JSONObject.toJSON(object); - String sign = msgJson.getString("sign"); - String appKey = msgJson.getString("appKey"); - Long timestamp = msgJson.getLong("timestamp"); - JSONObject bizContent = msgJson.getJSONObject("bizContent"); - String parkCode = bizContent.getString("parkCode"); - String parkName = bizContent.getString("parkName"); - String orderNum = bizContent.getString("orderNum"); - String plateNum = bizContent.getString("plateNum"); - String channelName = bizContent.getString("channelName"); - long exitTimeLong = bizContent.getLongValue("exitTime"); - Date exitTime = new Date(exitTimeLong * 1000L); - int type = bizContent.getIntValue("type"); - int carType = bizContent.getIntValue("carType"); - long parkTime = bizContent.getLongValue("parkTime"); - String imgUrl = bizContent.getString("imgUrl"); - TenPackRecordExitEntity enter = new TenPackRecordExitEntity(); - enter.setParkCode(parkCode); - enter.setParkName(parkName); - enter.setOrderNumber(orderNum); - enter.setPlateNumber(plateNum); - enter.setChannelName(channelName); - enter.setType(Integer.valueOf(type)); - enter.setCarType(Integer.valueOf(carType)); - enter.setExitTime(exitTime); - enter.setPackTime(Long.valueOf(parkTime)); - if (!StringUtils.isEmpty(imgUrl)) { - URL url = null; - InputStream is = null; - HttpURLConnection httpUrl = null; - try { - url = new URL(imgUrl); - httpUrl = (HttpURLConnection) url.openConnection(); - httpUrl.connect(); - httpUrl.getInputStream(); - is = httpUrl.getInputStream(); - String fileName = "car/" + enter.getParkCode() + "/" + UUIDUtil.uuid() + ".jpg"; - PutObjectOptions putObjectOptions = new PutObjectOptions(is.available(), -1L); - putObjectOptions.setContentType("image/jpeg"); - this.minioClient.putObject(this.minioConfig - .getBucketName(), fileName, is, putObjectOptions); - enter.setImage(fileName); - } catch (Exception e) { - e.printStackTrace(); - } finally { - if (is != null) - try { - is.close(); - } catch (IOException e) { - e.printStackTrace(); - } - if (httpUrl != null) - httpUrl.disconnect(); - } - } - this.tenPackRecordExitService.save(enter); - res.put("code", "200"); - res.put("msg", "成功"); - return res; - } +// enter.setImage(fileName); +// } catch (Exception e) { +// e.printStackTrace(); +// } finally { +// if (is != null) +// try { +// is.close(); +// } catch (IOException e) { +// e.printStackTrace(); +// } +// if (httpUrl != null) +// httpUrl.disconnect(); +// } +// } +// this.tenPackRecordExitService.save(enter); +// res.put("code", "200"); +// res.put("msg", "成功"); +// return res; +// } /* @@ -383,11 +386,22 @@ public class CarOpenApi { // Long cellId = null; Long tenantId = null; + String parkCodeXa = null; + String channalCodeXa = null; TenPackEntity packEntity = tenPackService.getOne(new QueryWrapper() .eq("park_code",parkCode)); if(packEntity!=null){ cellId = packEntity.getCellId(); tenantId = packEntity.getTenantId(); + parkCodeXa = packEntity.getParkCodeXa(); + TenPackChannalEntity channalEntity = tenPackChannalService.getOne( + new QueryWrapper() + .eq("channal_name",channelName) + .eq("pack_id",packEntity.getParkId()) + ); + if(channalEntity!=null){ + channalCodeXa = channalEntity.getChannalCodeXa(); + } } if (serviceName.equals("enter")) { long enterTimeLong = bizContent.getLongValue("enterTime"); @@ -403,6 +417,8 @@ public class CarOpenApi { enter.setEnterTime(enterTime); enter.setCellId(cellId); enter.setTenantId(tenantId); + enter.setParkCodeXa(parkCodeXa); + enter.setChannalCodeXa(channalCodeXa); if (fileName.length() > 0) enter.setImage(fileName); this.tenPackRecordEnterService.save(enter); diff --git a/shapelight-admin/src/main/java/net/shapelight/modules/job/task/XaImageTask.java b/shapelight-admin/src/main/java/net/shapelight/modules/job/task/XaImageTask.java index 55f817a..d1e4978 100644 --- a/shapelight-admin/src/main/java/net/shapelight/modules/job/task/XaImageTask.java +++ b/shapelight-admin/src/main/java/net/shapelight/modules/job/task/XaImageTask.java @@ -8,10 +8,7 @@ import io.minio.MinioClient; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.InputStream; -import java.util.ArrayList; -import java.util.Base64; -import java.util.Date; -import java.util.List; +import java.util.*; import lombok.extern.slf4j.Slf4j; import net.shapelight.common.config.MinioConfig; @@ -164,7 +161,7 @@ public class XaImageTask implements ITask { syncRecords.add(syncRecord); updateRecords.add(record); count++; - if (count >= 30) + if (count >= 10) break; } } @@ -185,71 +182,133 @@ public class XaImageTask implements ITask { String enJson = XaUtils.encryptStr(json.trim(), appSecret); - TenTranEntity tranEntity = tenTranService.saveApi(fwikUrl,"","RYJCZPXX", "RYJCZPXX", appId, appSecret); + List syncRecordsUpdates = jsonData.getDatas(); + for(XaRYJCZPXX xx: syncRecordsUpdates){ + xx.setLV_ZPZP(""); + } + + TenTranEntity tranEntity = tenTranService.saveApi(fwikUrl,jsonData,"RYJCZPXX", "RYJCZPXX", appId, appSecret); String tranId = String.format("%s%016d",DateUtils.format(tranEntity.getTranDate(),"yyyyMMddHHmmss"),tranEntity.getTranId()); String resJson = XaApi.httpPOSTJson(fwikUrl, enJson, "RYJCZPXX", "RYJCZPXX", appId, appSecret,tranId); // String resJson = "{\"sta\":{\"code\":\"0000\",\"des\":\"成功\",\"ErrorLineParameter\":\"empty\"},\"datas\":[{\"Result\":\"接收成功\"}],\"pages\":[{\"psize\":\"1\",\"tcount\":\"1\",\"pno\":\"1\",\"tsize\":\"0\"}]}"; // String resJson = "23232"; // System.out.println(s); - log.debug("上传人员识别记录返回数据:" + resJson); + log.debug("上传人员识别记录图片返回数据:" + resJson); tranEntity.setTranResult(resJson); tenTranService.updateById(tranEntity); //上传成功,修改sync状态 - if (resJson.contains("\"code\":\"0000\"")) { - for (TenRecordEntity recordEntity : updateRecords) { - recordEntity.setXaSyncImage(1); - tenRecordService.updateById(recordEntity); +// if (resJson.contains("\"code\":\"0000\"")) { +// for (TenRecordEntity recordEntity : updateRecords) { +// recordEntity.setXaSyncImage(1); +// tenRecordService.updateById(recordEntity); +// } +// } + if(resJson.contains("ErrorLineParameter")){ + JSONObject resJsonObject = JSONObject.parseObject(resJson); + String errLine = resJsonObject.getJSONObject("sta").getString("ErrorLineParameter").trim(); + if(errLine.equals("empty")){ + for (TenRecordEntity recordEntity : updateRecords) { + recordEntity.setXaSyncImage(1); + tenRecordService.updateById(recordEntity); + } + }else{ + String[] lines = errLine.split(","); + List lineList = Arrays.asList(lines); + for (int i = 0;i records = this.tenPackRecordEnterService.getNotSync(cellId); - List syncRecords = new ArrayList(); + List records = this.tenPackRecordEnterService.getNotSyncImage(cellId); + List syncRecords = new ArrayList(); List updateRecords = new ArrayList<>(); int count = 0; for (TenPackRecordEnterEntity record : records) { - XaTCCTCSBXX syncRecord = new XaTCCTCSBXX(); + XaTCCTCSBZPXX syncRecord = new XaTCCTCSBZPXX(); - TenPackEntity packEntity = tenPackService.getOne(new QueryWrapper() - .eq("park_code",record.getParkCode())); +// TenPackEntity packEntity = tenPackService.getOne(new QueryWrapper() +// .eq("park_code",record.getParkCode())); +// +// if(packEntity==null){ +// continue; +// } +// String packCodeXa = packEntity.getParkCodeXa(); +// if(packCodeXa==null || packCodeXa.length()==0){ +// continue; +// } +// +// TenPackChannalEntity channalEntity = tenPackChannalService.getOne(new QueryWrapper() +// .eq("channal_name",record.getChannelName())); +// if(channalEntity==null){ +// continue; +// } +// String channalCodeXa = channalEntity.getChannalCodeXa(); +// if(channalCodeXa==null || channalCodeXa.length()==0){ +// continue; +// } - if(packEntity==null){ + + syncRecord.setLV_TCCBH(record.getParkCodeXa()); + syncRecord.setLV_ZPSJ(DateUtils.format(record.getEnterTime(), "yyyyMMddHHmmss")); + + String base64Image = ""; + InputStream inStream = null; + ByteArrayOutputStream outStream = null; + + try { + minioClient.statObject(minioConfig.getBucketName(), record.getImage()); + + inStream = minioClient.getObject(minioConfig.getBucketName(), record.getImage()); + outStream = new ByteArrayOutputStream(); + byte[] buffer = new byte[1024]; + int length; + while ((length = inStream.read(buffer)) != -1) { + outStream.write(buffer, 0, length); + } + base64Image = Base64.getEncoder().encodeToString(outStream.toByteArray()); + } catch (Exception e) { + log.error("照片不存在:" + record.getImage()); + e.printStackTrace(); + } finally { + if (inStream != null) { + try { + inStream.close(); + } catch (IOException e) { + log.error("inputStream close IOException:" + e.getMessage()); + } + } + if (outStream != null) { + try { + outStream.close(); + } catch (IOException e) { + log.error("outStream close IOException:" + e.getMessage()); + } + } + } + if (base64Image.length() == 0) { continue; } - String packCodeXa = packEntity.getParkCodeXa(); - if(packCodeXa==null || packCodeXa.length()==0){ - continue; - } - - TenPackChannalEntity channalEntity = tenPackChannalService.getOne(new QueryWrapper() - .eq("channal_name",record.getChannelName())); - if(channalEntity==null){ - continue; - } - String channalCodeXa = channalEntity.getChannalCodeXa(); - if(channalCodeXa==null || channalCodeXa.length()==0){ - continue; - } - - - syncRecord.setLV_TCCBH(packCodeXa); - syncRecord.setLV_CPHM(record.getPlateNumber()); - syncRecord.setLV_CPLX("03");//01 大型汽车号牌 2 小型汽车号牌 03 使馆汽车号牌 04 领馆汽车号牌 - syncRecord.setLV_GCSJ(DateUtils.format(record.getEnterTime(), "yyyyMMddHHmmss")); - syncRecord.setLV_GCLX("1");//1进场2出场 - syncRecord.setLV_JKBM(record.getRecordEnterId()+""); - syncRecord.setLV_SBXT("10");//申报系统,默认10 - syncRecord.setLV_KKSBBH(channalCodeXa); - syncRecord.setLV_PROCMODE("PMINSERT"); + syncRecord.setLV_ZPZP(base64Image);//base64图片 syncRecords.add(syncRecord); updateRecords.add(record); count++; - if (count >= 30) + if (count >= 10) break; } + if(count == 0){ + return; + } XaData jsonData = new XaData(); jsonData.setDatas(syncRecords); @@ -264,19 +323,43 @@ public class XaImageTask implements ITask { String enJson = XaUtils.encryptStr(json.trim(), appSecret); - TenTranEntity tranEntity = tenTranService.saveApi(fwikUrl,"","TCCTCSBXX", "TCCTCSBXX", appId, appSecret); + List syncRecordsUpdates = jsonData.getDatas(); + for(XaTCCTCSBZPXX xx: syncRecordsUpdates){ + xx.setLV_ZPZP(""); + } + + + TenTranEntity tranEntity = tenTranService.saveApi(fwikUrl,jsonData,"TCCTCSBZPXX", "TCCTCSBZPXX", appId, appSecret); String tranId = String.format("%s%016d",DateUtils.format(tranEntity.getTranDate(),"yyyyMMddHHmmss"),tranEntity.getTranId()); - String resJson = XaApi.httpPOSTJson(fwikUrl, enJson, "TCCTCSBXX", "TCCTCSBXX", appId, appSecret,tranId); + String resJson = XaApi.httpPOSTJson(fwikUrl, enJson, "TCCTCSBZPXX", "TCCTCSBZPXX", appId, appSecret,tranId); // String resJson = "{\"sta\":{\"code\":\"0000\",\"des\":\"成功\",\"ErrorLineParameter\":\"empty\"},\"datas\":[{\"Result\":\"接收成功\"}],\"pages\":[{\"psize\":\"1\",\"tcount\":\"1\",\"pno\":\"1\",\"tsize\":\"0\"}]}"; // String resJson = "23232"; // System.out.println(s); - log.debug("上传车辆进场记录返回数据:" + resJson); + log.debug("上传车辆进场图片返回数据:" + resJson); + tranEntity.setTranResult(resJson); + tenTranService.updateById(tranEntity); //上传成功,修改sync状态 - if (resJson.contains("\"code\":\"0000\"")) { - for (TenPackRecordEnterEntity recordEntity : updateRecords) { - recordEntity.setXaSync(1); - tenPackRecordEnterService.updateById(recordEntity); + if(resJson.contains("ErrorLineParameter")){ + JSONObject resJsonObject = JSONObject.parseObject(resJson); + String errLine = resJsonObject.getJSONObject("sta").getString("ErrorLineParameter").trim(); + if(errLine.equals("empty")){ + for (TenPackRecordEnterEntity recordEntity : updateRecords) { + recordEntity.setXaSyncImage(1); + tenPackRecordEnterService.updateById(recordEntity); + } + }else{ + String[] lines = errLine.split(","); + List lineList = Arrays.asList(lines); + for (int i = 0;i records = this.tenPackRecordExitService.getNotSync(cellId); - List syncRecords = new ArrayList(); + List records = this.tenPackRecordExitService.getNotSyncImage(cellId); + List syncRecords = new ArrayList(); List updateRecords = new ArrayList<>(); int count = 0; for (TenPackRecordExitEntity record : records) { - XaTCCTCSBXXEXIT syncRecord = new XaTCCTCSBXXEXIT(); + XaTCCTCSBZPXX syncRecord = new XaTCCTCSBZPXX(); - TenPackEntity packEntity = tenPackService.getOne(new QueryWrapper() - .eq("park_code",record.getParkCode())); +// TenPackEntity packEntity = tenPackService.getOne(new QueryWrapper() +// .eq("park_code",record.getParkCode())); +// +// if(packEntity==null){ +// continue; +// } +// String packCodeXa = packEntity.getParkCodeXa(); +// if(packCodeXa==null || packCodeXa.length()==0){ +// continue; +// } +// +// TenPackChannalEntity channalEntity = tenPackChannalService.getOne(new QueryWrapper() +// .eq("channal_name",record.getChannelName())); +// if(channalEntity==null){ +// continue; +// } +// String channalCodeXa = channalEntity.getChannalCodeXa(); +// if(channalCodeXa==null || channalCodeXa.length()==0){ +// continue; +// } - if(packEntity==null){ + + syncRecord.setLV_TCCBH(record.getParkCodeXa()); + syncRecord.setLV_ZPSJ(DateUtils.format(record.getExitTime(), "yyyyMMddHHmmss")); + + String base64Image = ""; + InputStream inStream = null; + ByteArrayOutputStream outStream = null; + + try { + minioClient.statObject(minioConfig.getBucketName(), record.getImage()); + + inStream = minioClient.getObject(minioConfig.getBucketName(), record.getImage()); + outStream = new ByteArrayOutputStream(); + byte[] buffer = new byte[1024]; + int length; + while ((length = inStream.read(buffer)) != -1) { + outStream.write(buffer, 0, length); + } + base64Image = Base64.getEncoder().encodeToString(outStream.toByteArray()); + } catch (Exception e) { + log.error("照片不存在:" + record.getImage()); + e.printStackTrace(); + } finally { + if (inStream != null) { + try { + inStream.close(); + } catch (IOException e) { + log.error("inputStream close IOException:" + e.getMessage()); + } + } + if (outStream != null) { + try { + outStream.close(); + } catch (IOException e) { + log.error("outStream close IOException:" + e.getMessage()); + } + } + } + if (base64Image.length() == 0) { continue; } - String packCodeXa = packEntity.getParkCodeXa(); - if(packCodeXa==null || packCodeXa.length()==0){ - continue; - } - - TenPackChannalEntity channalEntity = tenPackChannalService.getOne(new QueryWrapper() - .eq("channal_name",record.getChannelName())); - if(channalEntity==null){ - continue; - } - String channalCodeXa = channalEntity.getChannalCodeXa(); - if(channalCodeXa==null || channalCodeXa.length()==0){ - continue; - } - - - syncRecord.setLV_TCCBH(packCodeXa); - syncRecord.setLV_CPHM(record.getPlateNumber()); - syncRecord.setLV_CPLX("03");//01 大型汽车号牌 2 小型汽车号牌 03 使馆汽车号牌 04 领馆汽车号牌 - syncRecord.setLV_GCSJ(DateUtils.format(record.getExitTime(), "yyyyMMddHHmmss")); - syncRecord.setLV_GCLX("1");//1进场2出场 - syncRecord.setLV_CKBM(record.getRecordExitId()+""); - syncRecord.setLV_SBXT("10");//申报系统,默认10 - syncRecord.setLV_KKSBBH(channalCodeXa); - syncRecord.setLV_PROCMODE("PMINSERT"); + syncRecord.setLV_ZPZP(base64Image);//base64图片 syncRecords.add(syncRecord); updateRecords.add(record); count++; - if (count >= 30) + if (count >= 10) break; } + if(count == 0){ + return; + } XaData jsonData = new XaData(); jsonData.setDatas(syncRecords); @@ -344,7 +462,12 @@ public class XaImageTask implements ITask { String enJson = XaUtils.encryptStr(json.trim(), appSecret); - TenTranEntity tranEntity = tenTranService.saveApi(fwikUrl,"","TCCTCSBXX", "TCCTCSBXX", appId, appSecret); + List syncRecordsUpdates = jsonData.getDatas(); + for(XaTCCTCSBZPXX xx: syncRecordsUpdates){ + xx.setLV_ZPZP(""); + } + + TenTranEntity tranEntity = tenTranService.saveApi(fwikUrl,jsonData,"TCCTCSBXX", "TCCTCSBXX", appId, appSecret); String tranId = String.format("%s%016d",DateUtils.format(tranEntity.getTranDate(),"yyyyMMddHHmmss"),tranEntity.getTranId()); @@ -352,12 +475,36 @@ public class XaImageTask implements ITask { // String resJson = "{\"sta\":{\"code\":\"0000\",\"des\":\"成功\",\"ErrorLineParameter\":\"empty\"},\"datas\":[{\"Result\":\"接收成功\"}],\"pages\":[{\"psize\":\"1\",\"tcount\":\"1\",\"pno\":\"1\",\"tsize\":\"0\"}]}"; // String resJson = "23232"; // System.out.println(s); - log.debug("上传车辆进场记录返回数据:" + resJson); + log.debug("上传车辆出场记录返回数据:" + resJson); + tranEntity.setTranResult(resJson); + tenTranService.updateById(tranEntity); //上传成功,修改sync状态 - if (resJson.contains("\"code\":\"0000\"")) { - for (TenPackRecordExitEntity recordEntity : updateRecords) { - recordEntity.setXaSync(1); - tenPackRecordExitService.updateById(recordEntity); +// if (resJson.contains("\"code\":\"0000\"")) { +// for (TenPackRecordExitEntity recordEntity : updateRecords) { +// recordEntity.setXaSync(1); +// tenPackRecordExitService.updateById(recordEntity); +// } +// } + if(resJson.contains("ErrorLineParameter")){ + JSONObject resJsonObject = JSONObject.parseObject(resJson); + String errLine = resJsonObject.getJSONObject("sta").getString("ErrorLineParameter").trim(); + if(errLine.equals("empty")){ + for (TenPackRecordExitEntity recordEntity : updateRecords) { + recordEntity.setXaSyncImage(1); + tenPackRecordExitService.updateById(recordEntity); + } + }else{ + String[] lines = errLine.split(","); + List lineList = Arrays.asList(lines); + for (int i = 0;i= 50) + if (count >= 10) break; } } @@ -446,21 +593,49 @@ public class XaImageTask implements ITask { String enJson = XaUtils.encryptStr(json.trim(), appSecret); - TenTranEntity tranEntity = tenTranService.saveApi(fwikUrl,"","SYRK", "SYRK", appId, appSecret); + List syncRecordsUpdates = jsonData.getDatas(); + for(XaTCCTCSBZPXX xx: syncRecordsUpdates){ + xx.setLV_ZPZP(""); + } + + + TenTranEntity tranEntity = tenTranService.saveApi(fwikUrl,jsonData,"RYRKPHOTO", "RYRKPHOTO", appId, appSecret); String tranId = String.format("%s%016d",DateUtils.format(tranEntity.getTranDate(),"yyyyMMddHHmmss"),tranEntity.getTranId()); - String resJson = XaApi.httpPOSTJson(fwikUrl, enJson, "SYRK", "SYRK", appId, appSecret,tranId); + String resJson = XaApi.httpPOSTJson(fwikUrl, enJson, "RYRKPHOTO", "RYRKPHOTO", appId, appSecret,tranId); // String resJson = "{\"sta\":{\"code\":\"0000\",\"des\":\"成功\",\"ErrorLineParameter\":\"empty\"},\"datas\":[{\"Result\":\"接收成功\"}],\"pages\":[{\"psize\":\"1\",\"tcount\":\"1\",\"pno\":\"1\",\"tsize\":\"0\"}]}"; // String resJson = "23232"; // System.out.println(s); - log.debug("processRealPersonImage:" + resJson); + log.debug("上传实有人口返回数据:" + resJson); tranEntity.setTranResult(resJson); tenTranService.updateById(tranEntity); //上传成功,修改sync状态 - if (resJson.contains("\"code\":\"0000\"")) { - for (TenPersonEntity personEntity : updatePersons) { - personEntity.setXaSyncImage(1); - tenPersonService.updateNonal(personEntity); +// if (resJson.contains("\"code\":\"0000\"")) { +// for (TenPersonEntity personEntity : updatePersons) { +// personEntity.setXaSyncImage(1); +// tenPersonService.updateNonal(personEntity); +// } +// } + if(resJson.contains("ErrorLineParameter")){ + JSONObject resJsonObject = JSONObject.parseObject(resJson); + String errLine = resJsonObject.getJSONObject("sta").getString("ErrorLineParameter").trim(); + if(errLine.equals("empty")){ + for (TenPersonEntity recordEntity : updatePersons) { + recordEntity.setXaSyncImage(1); + tenPersonService.updateById(recordEntity); + } + }else{ + String[] lines = errLine.split(","); + List lineList = Arrays.asList(lines); + for (int i = 0;i lineList = Arrays.asList(lines); + for (int i = 0;i lineList = Arrays.asList(lines); + for (int i = 0;i lineList = Arrays.asList(lines); + for (int i = 0;i lineList = Arrays.asList(lines); + for (int i = 0;i allCells = this.tenCellService.list((Wrapper)(new QueryWrapper()) .eq("tenant_id", sysTenUser.getTenantId())); @@ -138,10 +139,32 @@ public class XaRecordTask implements ITask { tranEntity.setTranResult(resJson); tenTranService.updateById(tranEntity); //上传成功,修改sync状态 - if (resJson.contains("\"code\":\"0000\"")) { - for (TenRecordEntity recordEntity : updateRecords) { - recordEntity.setXaSync(1); - tenRecordService.updateById(recordEntity); +// if (resJson.contains("\"code\":\"0000\"")) { +// for (TenRecordEntity recordEntity : updateRecords) { +// recordEntity.setXaSync(1); +// tenRecordService.updateById(recordEntity); +// } +// } + if(resJson.contains("ErrorLineParameter")){ + JSONObject resJsonObject = JSONObject.parseObject(resJson); + String errLine = resJsonObject.getJSONObject("sta").getString("ErrorLineParameter").trim(); + if(errLine.equals("empty")){ + for (TenRecordEntity recordEntity : updateRecords) { + recordEntity.setXaSync(1); + tenRecordService.updateById(recordEntity); + } + }else{ + String[] lines = errLine.split(","); + List lineList = Arrays.asList(lines); + for (int i = 0;i lineList = Arrays.asList(lines); + for (int i = 0;i lineList = Arrays.asList(lines); + for (int i = 0;i params) { List cellIds = new ArrayList<>(); // cellIds.add(709832651506188289L); - String cellId = (String)params.get("cellId"); - if (cellId!=null && !cellId.isEmpty()){ + String cellId = (String) params.get("cellId"); + if (cellId != null && !cellId.isEmpty()) { Long cellLong = Long.parseLong(cellId); cellIds.add(cellLong); - }else { + } else { List cells = tenCellService.queryAll(params); for (TenCellEntity cell : cells) { cellIds.add(cell.getCellId()); } } if (cellIds.size() == 0) { - return new PageUtils(new ArrayList<>(),0,0,0); + return new PageUtils(new ArrayList<>(), 0, 0, 0); } IPage page = this.page( new Query().getPage(params), new QueryWrapper() - .eq("tenant_id",params.get("tenantId")) - .in("cell_id",cellIds) + .eq("tenant_id", params.get("tenantId")) + .in("cell_id", cellIds) .orderByDesc("enter_time") ); - for(TenPackRecordEnterEntity entity: page.getRecords()){ + for (TenPackRecordEnterEntity entity : page.getRecords()) { TenCellEntity cell = tenCellService.getById(entity.getCellId()); entity.setCellName(cell.getName()); } return new PageUtils(page); } + @Override public List getNotSync(Long cellId) { // String todayString = DateUtils.format(new Date(),DateUtils.DATE_PATTERN); // String todayStart = todayString+" 00:00:00"; // String todayEnd = todayString+" 23:59:59"; return this.list(new QueryWrapper() - .eq("cell_id",cellId) - .eq("xa_sync",0) - .isNotNull("image") - .last(" and TO_DAYS(enter_time) = TO_DAYS(NOW())")); + .eq("cell_id", cellId) + .eq("xa_sync", 0) + .isNotNull("image") + .isNotNull("park_code_xa") + .isNotNull("channal_code_xa") + .last(" and TO_DAYS(enter_time) = TO_DAYS(NOW())")); } + @Override public List getNotSyncImage(Long cellId) { return this.list(new QueryWrapper() - .eq("cell_id",cellId) - .eq("xa_sync_image",0) + .eq("cell_id", cellId) + .eq("xa_sync_image", 0) .isNotNull("image") - .eq("xa_sync",1) + .isNotNull("park_code_xa") + .isNotNull("channal_code_xa") + .eq("xa_sync", 1) .last(" and TO_DAYS(enter_time) = TO_DAYS(NOW())")); } } \ No newline at end of file diff --git a/shapelight-admin/src/main/java/net/shapelight/modules/ten/service/impl/TenPackRecordExitServiceImpl.java b/shapelight-admin/src/main/java/net/shapelight/modules/ten/service/impl/TenPackRecordExitServiceImpl.java index 87bf0d7..87c5853 100644 --- a/shapelight-admin/src/main/java/net/shapelight/modules/ten/service/impl/TenPackRecordExitServiceImpl.java +++ b/shapelight-admin/src/main/java/net/shapelight/modules/ten/service/impl/TenPackRecordExitServiceImpl.java @@ -63,6 +63,9 @@ public class TenPackRecordExitServiceImpl extends ServiceImpl() .eq("cell_id",cellId) .eq("xa_sync",0) + .isNotNull("image") + .isNotNull("park_code_xa") + .isNotNull("channal_code_xa") .last(" and TO_DAYS(exit_time) = TO_DAYS(NOW())")); } @Override @@ -71,6 +74,9 @@ public class TenPackRecordExitServiceImpl extends ServiceImpl