Commit 10740d80 authored by 李洪明's avatar 李洪明

Merge branch 'master' of https://app.bmetech.com/lihongming/bme-access-upload

# Conflicts:
#	src/main/java/com/bme/access/upload/Application.java
parents 6259760a 48b3bce3
package com.bme.access.upload;
import com.alibaba.druid.pool.DruidDataSource;
import com.alibaba.druid.spring.boot.autoconfigure.DruidDataSourceAutoConfigure;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
import org.springframework.boot.autoconfigure.jdbc.DataSourceTransactionManagerAutoConfiguration;
import org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
@SpringBootApplication
@SpringBootApplication()
@MapperScan("com.bme.access.upload.module.dao")
public class Application {
@ConfigurationProperties(prefix = "spring.datasource.original")
@Bean
public DruidDataSource dataSource() {
return new DruidDataSource();
}
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
......
......@@ -27,7 +27,7 @@ public class UploadDataNewTask {
/**
* 场内运输车辆信息-添加
*/
@Scheduled(cron = "0 0/15 * * * *")
@Scheduled(cron = "0 0/2 * * * *")
public void uploadInFactoryTransportVehicleInfo() {
try {
inFactoryTransportVehicleInfoService.getAndUploadInFactoryTransportVehicleInfo();
......@@ -39,7 +39,7 @@ public class UploadDataNewTask {
/**
* 车辆信息-添加
*/
@Scheduled(cron = "0 8/5 * * * ?")
// @Scheduled(cron = "0 8/5 * * * ?")
public void uploadTransportVehicleInfo() {
try {
transportVehicleInfoService.getAndUploadTransportVehicleInfoList(Boolean.TRUE);
......@@ -51,7 +51,7 @@ public class UploadDataNewTask {
/**
* 非道路移动机械信息-添加
*/
@Scheduled(cron = "0 0/15 * * * *")
// @Scheduled(cron = "0 0/15 * * * *")
public void uploadNoneRoadMovementInfo() {
try {
noneRoadMovementInfoService.getAndUploadTransportVehicleDate();
......
package com.bme.access.upload.module.dao;
import com.bme.access.upload.module.module.InFactoryTransportVehicleInfoUrl;
import org.apache.ibatis.annotations.Mapper;
import java.util.List;
/**
* 车辆电子运行台账
*
* @author yutyi
* @date 2020/07/28
*/
@Mapper
public interface InFactoryTransportVehicleInfoMapper {
List<InFactoryTransportVehicleInfoUrl> selectInFactoryTransportVehicleInfo(String uploadTime);
List<InFactoryTransportVehicleInfoUrl> selectInFactoryTransportVehicleInfo1();
Integer selectInFactoryTransportVehicleInfoCount();
}
\ No newline at end of file
package com.bme.access.upload.module.module;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
@Data
@AllArgsConstructor
@NoArgsConstructor
public class InFactoryTransportVehicleInfoUrl {
//车辆识 别代码 (VIN)
private String vin;
//发动机号码
private String numberPlate;
//注册登记日期
private String registrationDate;
//环保登记编码
private String environmentCode;
//生产日期
private String dtime;
//车辆类型
private String vehicleType;
//排放标准
private String vehicleEmissions;
//发动机号码
private String engineNumber;
//随车清单照片
private String onBoardList;
// 行驶证
private String drivingLicense;
// 发动机铭牌(图片URL地址)
private String engineImage;
// 燃料类型
private String fuelType;
// 车辆所有(单位)
private String owener;
// 重型柴油车辆排放阶段查询照片URL地址
private String vehicleLicenseVerificationImg;
// 车辆照片
private String vehicleImage;
// 机动车环保网查询照片URL地址
private String vinVerificationImg;
// 生产日期
private String productionDate;
// 在线状态
private String onlineStatus;
// 车辆品牌型号
private String model;
}
\ No newline at end of file
package com.bme.access.upload.module.module.upload;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
@Data
@AllArgsConstructor
@NoArgsConstructor
public class InFactoryTransportVehicleInfo {
// 车牌号码
private String carNo;
// 随车清单图片
private String vehicleListImg;
// 行驶证图片
private String drivingLicenseImg;
// 温度传感器或三元催化器图片
private String sensorCatalyticConverterImg;
// 机动车外观照片
private String carImg;
// 排放标准
private String emissionStandard;
// 燃料类型
private String fuelType;
// 环保登记编码
private String hbCarNo;
// 联网状态
private String internetStatus;
// 车辆所有人(单位)
private String owner;
// 生产日期
private String productionDate;
// 注册登记日期
private String registrationDate;
// 车辆识别代码
private String vin;
// 数据状态
private Integer netData;
// 车辆品牌
private String vehModel;
// 车辆型号
private String vehBrand;
}
\ No newline at end of file
package com.bme.access.upload.module.service;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.bme.access.upload.common.HttpUtils;
import com.bme.access.upload.module.dao.InFactoryTransportVehicleInfoMapper;
import com.bme.access.upload.module.module.InFactoryTransportVehicleInfoUrl;
import com.bme.access.upload.module.module.upload.InFactoryTransportVehicleInfo;
import com.bme.access.upload.module.utils.BeanConverter;
import lombok.extern.slf4j.Slf4j;
import org.apache.http.HttpResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import java.util.List;
@Service
@Slf4j
public class InFactoryTransportVehicleInfoService {
public void getAndUploadInFactoryTransportVehicleInfo() {
@Autowired
private BeanConverter beanConverter;
@Autowired
private InFactoryTransportVehicleInfoMapper inFactoryTransportVehicleInfoMapper;
@Autowired
private LoginService loginService;
private final static String IN_FACTORY_URL = "https://dctapi.soszyzg.com/dct/new/addTransPorVehicle";
public void getAndUploadInFactoryTransportVehicleInfo() throws Exception {
List<InFactoryTransportVehicleInfoUrl> inFactoryTransportVehicleInfoUrls = inFactoryTransportVehicleInfoMapper.selectInFactoryTransportVehicleInfo1();
List<InFactoryTransportVehicleInfo> inFactoryTransportVehicleInfos = beanConverter.convertInFactoryTransportVehicleInfo(inFactoryTransportVehicleInfoUrls);
if (!CollectionUtils.isEmpty(inFactoryTransportVehicleInfos)) {
try {
loginService.login();
} catch (Exception e) {
log.error("更新token失败:{}", e.getMessage());
}
}
for (InFactoryTransportVehicleInfo inFactoryTransportVehicleInfo : inFactoryTransportVehicleInfos) {
String bodyJson = JSONObject.toJSONString(inFactoryTransportVehicleInfo);
HttpUtils.sendPost(IN_FACTORY_URL, null, null, bodyJson);
Thread.sleep(50);
}
log.info("上传场内车辆{}条", inFactoryTransportVehicleInfoUrls.size());
}
}
package com.bme.access.upload.module.utils;
import net.coobird.thumbnailator.Thumbnails;
import org.springframework.util.StringUtils;
import java.io.*;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.Base64;
/**
* description:
* <p></p>
*
* @author huanghao
* @since 2021/5/6 19:49
* Copyright: 2021, BME (Shanghai) Co., Ltd. All Rights Reserved.
*/
public class Base64Utils {
/**
* 根据图片链接转为base64数据
*
* @param imageUrl
* @return
* @throws Exception
*/
public static String getBase64ByUrl(String imageUrl) {
// new一个URL对象
URL url = null;
try {
url = new URL(imageUrl);
// 打开链接
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
// 设置请求方式为"GET"
conn.setRequestMethod("GET");
// 超时响应时间为5秒
conn.setConnectTimeout(5 * 1000);
// 通过输入流获取图片数据
InputStream inStream = conn.getInputStream();
// 得到图片的二进制数据,以二进制封装得到数据,具有通用性
byte[] data = readInputStream(inStream);
return Base64.getEncoder().encodeToString(data);
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
/**
* 根据图片链接转为base64数据
*
* @param imageUrl
* @return
* @throws Exception
*/
public static byte[] getByteImgByUrl(String imageUrl) {
if (StringUtils.isEmpty(imageUrl)) {
return null;
}
// new一个URL对象
URL url = null;
try {
url = new URL(imageUrl);
// 打开链接
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
// 设置请求方式为"GET"
conn.setRequestMethod("GET");
// 超时响应时间为5秒
conn.setConnectTimeout(5 * 1000);
// 通过输入流获取图片数据
InputStream inStream = conn.getInputStream();
// 得到图片的二进制数据,以二进制封装得到数据,具有通用性
return readInputStream(inStream);
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
private static byte[] readInputStream(InputStream inStream) throws Exception {
ByteArrayOutputStream outStream = new ByteArrayOutputStream();
// 创建一个Buffer字符串
byte[] buffer = new byte[1024];
// 每次读取的字符串长度,如果为-1,代表全部读取完毕
int len = 0;
// 使用一个输入流从buffer里把数据读取出来
while ((len = inStream.read(buffer)) != -1) {
// 用输出流往buffer里写入数据,中间参数代表从哪个位置开始读,len代表读取的长度
outStream.write(buffer, 0, len);
}
// 关闭输入流
inStream.close();
// 把outStream里的数据写入内存
return outStream.toByteArray();
}
/**
* base64转文件
* @param base64sString
* @param filePath "E:/out.jpg" "/home/test.pdf"
*/
public static void base64StringToFile(String base64sString,String filePath){
BufferedInputStream bin = null;
FileOutputStream fout = null;
BufferedOutputStream bout = null;
try {
//将base64编码的字符串解码成字节数组
byte[] bytes = Base64.getDecoder().decode(base64sString);
//apache公司的API
//byte[] bytes = Base64.decodeBase64(base64sString);
//创建一个将bytes作为其缓冲区的ByteArrayInputStream对象
ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
//创建从底层输入流中读取数据的缓冲输入流对象
bin = new BufferedInputStream(bais);
//指定输出文件
//File file = new File("/home/test.pdf");
File file = new File(filePath);
//创建到指定文件的输出流
fout = new FileOutputStream(file);
//为文件输出流对接缓冲输出流对象
bout = new BufferedOutputStream(fout);
byte[] buffers = new byte[1024];
int len = bin.read(buffers);
while (len != -1) {
bout.write(buffers,0,len);
len = bin.read(buffers);
}
//刷新此输出流并强制写出所有缓冲的输出字节,必须这行代码,否则有可能有问题
bout.flush();
} catch (IOException e) {
e.printStackTrace();
}finally{
try {
bin.close();
fout.close();
bout.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
//转换
public static byte[] imageThumbnailsToBase64(String imageUrl) {
ByteArrayOutputStream bos = new ByteArrayOutputStream();;
try {
Thumbnails.of(new URL(imageUrl)).toOutputStream(bos);
// Thumbnails.of(imageUrl).size(600, 800).toOutputStream(bos);
byte[] bytes = bos.toByteArray();
return bytes;
} catch (Exception e) {
System.out.println("Thumbnails Upload failed:" + e);
}
return null;
}
public static void main(String[] args) {
byte[] bytes = getByteImgByUrl("https://q1.itc.cn/q_70/images03/20240430/59fe8596e4cb4824a6f27315328a3559.jpeg");
System.out.println(bytes);
}
}
\ No newline at end of file
package com.bme.access.upload.module.utils;
import com.bme.access.upload.module.module.InFactoryTransportVehicleInfoUrl;
import com.bme.access.upload.module.module.upload.InFactoryTransportVehicleInfo;
import com.google.common.collect.Lists;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Component;
import java.util.List;
import java.util.Objects;
@Component
@Slf4j
public class BeanConverter {
private final String owner = "四川罡宸不锈钢有限责任公司";
public List<InFactoryTransportVehicleInfo> convertInFactoryTransportVehicleInfo(List<InFactoryTransportVehicleInfoUrl> inFactoryTransportVehicleInfoUrls) {
List<InFactoryTransportVehicleInfo> list = Lists.newArrayList();
for (InFactoryTransportVehicleInfoUrl item : inFactoryTransportVehicleInfoUrls) {
InFactoryTransportVehicleInfo info = new InFactoryTransportVehicleInfo();
info.setCarNo(item.getNumberPlate());
if (StringUtils.isNotBlank(item.getOnBoardList())) {
info.setVehicleListImg(Base64Utils.getBase64ByUrl(item.getOnBoardList()));
}
if (StringUtils.isNotBlank(item.getDrivingLicense())) {
info.setDrivingLicenseImg(Base64Utils.getBase64ByUrl(item.getDrivingLicense()));
}
info.setSensorCatalyticConverterImg(null);
if (StringUtils.isNotBlank(item.getVehicleImage())) {
info.setCarImg(Base64Utils.getBase64ByUrl(item.getVehicleImage()));
}
if (item.getVehicleEmissions() == null) {
info.setEmissionStandard("X");
} else {
if (item.getVehicleEmissions().equals("99")) {
info.setEmissionStandard("D");
} else {
info.setEmissionStandard(item.getVehicleEmissions());
}
}
info.setFuelType(item.getFuelType());
info.setHbCarNo(item.getEnvironmentCode());
if (Objects.nonNull(item.getOnlineStatus())) {
// 联网状态 0—未联网,1—已联网
info.setInternetStatus(item.getOnlineStatus());
} else {
info.setInternetStatus("0");
}
if (StringUtils.isBlank(item.getOwener())) {
info.setOwner(owner);
} else {
info.setOwner(item.getOwener());
}
info.setProductionDate(item.getProductionDate());
info.setRegistrationDate(item.getRegistrationDate());
info.setVin(item.getVin());
info.setNetData(1);
info.setVehModel(item.getModel());
info.setVehBrand(item.getVehicleType());
list.add(info);
}
return list;
}
}
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.bme.access.upload.module.dao.InFactoryTransportVehicleInfoMapper">
<select id="selectInFactoryTransportVehicleInfo"
resultType="com.bme.access.upload.module.module.InFactoryTransportVehicleInfoUrl">
select
Number_plate numberPlate,
Registration_date registrationDate,
VIN vin,
Engine_number engineNumber,
vehicle_type vehicleType,
Vehicle_Emissions vehicleEmissions,
On_board_list onBoardList,
Driving_license drivingLicense,
DTime dtime,
vehicle_type vehicleType
from InFactory_Transport_Vehicle_Info where DTime > #{uploadTime}
</select>
<select id="selectInFactoryTransportVehicleInfo1"
resultType="com.bme.access.upload.module.module.InFactoryTransportVehicleInfoUrl">
select
Number_plate numberPlate,
Registration_date registrationDate,
VIN vin,
Engine_number engineNumber,
Vehicle_Emissions vehicleEmissions,
On_board_list onBoardList,
Driving_license drivingLicense,
DTime dtime,
Engine_image engineImage,
Fuel_Type fuelType,
vehicle_type vehicleType,
Owener owener,
VehicleLicense_Verification_Img vehicleLicenseVerificationImg,
Vehicle_Image vehicleImage,
VIN_Verification_Img vinVerificationImg,
production_date productionDate,
online_status onlineStatus,
model,
Environment_Code environmentCode
from InFactory_Transport_Vehicle_Info
</select>
<select id="selectInFactoryTransportVehicleInfoCount" resultType="java.lang.Integer">
select count(*) from InFactory_Transport_Vehicle_Info
</select>
</mapper>
\ No newline at end of file
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