From 522dc2d1ba421f64b3243f944ba94402177b90f4 Mon Sep 17 00:00:00 2001 From: gaoben Date: Fri, 25 Jun 2021 18:30:26 +0800 Subject: [PATCH] =?UTF-8?q?v2.0.12=201.=E4=BC=98=E5=8C=96=E5=90=8C?= =?UTF-8?q?=E6=AD=A5=E5=AE=9E=E6=9C=89=E6=88=BF=E5=B1=8B=E9=80=BB=E8=BE=91?= =?UTF-8?q?=EF=BC=8C=E5=A6=82=E6=9E=9C=E6=B2=A1=E6=9C=89=E4=B8=9A=E4=B8=BB?= =?UTF-8?q?=E6=89=BE=E5=AE=B6=E5=BA=AD=E6=88=90=E5=91=98=202.=E8=87=AA?= =?UTF-8?q?=E5=8A=A8=E5=8C=96=E5=A4=84=E7=90=86=E6=88=BF=E5=B1=8B=E5=9C=B0?= =?UTF-8?q?=E5=9D=80=E5=92=8C=E6=A0=87=E5=87=86=E5=9C=B0=E5=9D=80=E5=AF=B9?= =?UTF-8?q?=E5=BA=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pom.xml | 4 +- .../modules/car/controller/CarOpenApi.java | 176 ++++++++++++----- .../modules/job/task/XaImageTask.java | 1 + .../modules/job/task/XaRealDataTask.java | 19 +- .../modules/job/task/XaRecordTask.java | 92 ++++++--- .../ten/controller/TenCellController.java | 11 ++ .../modules/ten/dao/TenPersonDao.java | 3 + .../modules/ten/dao/TenRoomDao.java | 4 + .../modules/ten/service/TenCellService.java | 2 + .../modules/ten/service/TenPersonService.java | 2 + .../modules/ten/service/TenRoomService.java | 2 + .../ten/service/impl/TenCellServiceImpl.java | 6 + .../service/impl/TenPersonServiceImpl.java | 5 + .../ten/service/impl/TenRoomServiceImpl.java | 46 ++++- .../src/main/resources/application-dev.yml | 32 +-- .../resources/mapper/ten/TenPersonDao.xml | 16 +- .../main/resources/mapper/ten/TenRoomDao.xml | 11 ++ .../src/test/java/gb/CarImageTest.java | 187 +++++++++++++++--- 18 files changed, 480 insertions(+), 139 deletions(-) diff --git a/pom.xml b/pom.xml index 72a0c76..b356257 100644 --- a/pom.xml +++ b/pom.xml @@ -29,9 +29,9 @@ 1.8 4.12 2.9.0 - 1.1.13 + 1.1.18 3.1.2 - 8.0.19 + 8.0.25 4.0 11.2.0.3 2.6 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 fd820e2..edc7255 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 @@ -11,15 +11,13 @@ import io.swagger.annotations.ApiOperation; import java.awt.image.BufferedImage; import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.InputStream; import java.net.HttpURLConnection; import java.net.URL; import java.net.URLDecoder; -import java.util.Date; -import java.util.HashMap; -import java.util.List; -import java.util.Map; +import java.util.*; import net.shapelight.common.config.GlobalValue; @@ -335,6 +333,116 @@ public class CarOpenApi { } + String dateDir = DateUtils.format(new Date(),DateUtils.DATE_YEAR_MONTH); + String fileName = "car/" + dateDir + "/" +parkCode+"/"+UUIDUtil.uuid() + ".jpg"; + if (!StringUtils.isEmpty(imgUrl)) { + URL url = null; + InputStream is = null; + HttpURLConnection httpUrl = null; + try { + + //new一个URL对象 + url = new URL(imgUrl); + //打开链接 + HttpURLConnection conn = (HttpURLConnection)url.openConnection(); + //设置请求方式为"GET" + conn.setRequestMethod("GET"); + //超时响应时间为5秒 + conn.setConnectTimeout(5 * 1000); + //通过输入流获取图片数据 + InputStream inStream = conn.getInputStream(); + + ByteArrayOutputStream outStream = new ByteArrayOutputStream(); + //创建一个Buffer字符串 + byte[] buffer = new byte[1024000]; + //每次读取的字符串长度,如果为-1,代表全部读取完毕 + int len = 0; + //使用一个输入流从buffer里把数据读取出来 + while( (len=inStream.read(buffer)) != -1 ){ + //用输出流往buffer里写入数据,中间参数代表从哪个位置开始读,len代表读取的长度 + outStream.write(buffer, 0, len); + } + + //得到图片的二进制数据,以二进制封装得到数据,具有通用性 + byte[] dataImage = outStream.toByteArray(); + + //关闭输入流 + inStream.close(); + outStream.close(); + + ByteArrayInputStream bais = new ByteArrayInputStream(dataImage); + BufferedImage image = ImageIO.read(bais); + + //获取图片的宽、高 +// 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); + } + 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); + + + + +// 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); +// } +// 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(); +// PutObjectOptions putObjectOptions = new PutObjectOptions(is.available(), -1L); +// putObjectOptions.setContentType("image/jpeg"); +// this.minioClient.putObject(this.minioConfig +// .getBucketName(), fileName, is, putObjectOptions); + } catch (Exception e) { + e.printStackTrace(); + log.error("保存图片失败:"+imgUrl+"--------------------"+e); + fileName = ""; + } finally { + if (is != null) + try { + is.close(); + } catch (IOException e) { + e.printStackTrace(); + } + if (httpUrl != null) + httpUrl.disconnect(); + } + } + + + + + + //去重 if (serviceName.equals("enter")) { long enterTimeLong = bizContent.getLongValue("enterTime"); @@ -372,55 +480,6 @@ public class CarOpenApi { - String fileName = "car/" + parkCode + "/" + UUIDUtil.uuid() + ".jpg"; - 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); - } - 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(); -// PutObjectOptions putObjectOptions = new PutObjectOptions(is.available(), -1L); -// putObjectOptions.setContentType("image/jpeg"); -// this.minioClient.putObject(this.minioConfig -// .getBucketName(), fileName, is, putObjectOptions); - } catch (Exception e) { - e.printStackTrace(); - fileName = ""; - } finally { - if (is != null) - try { - is.close(); - } catch (IOException e) { - e.printStackTrace(); - } - if (httpUrl != null) - httpUrl.disconnect(); - } - } // Long cellId = null; @@ -461,8 +520,17 @@ public class CarOpenApi { enter.setParkCodeXa(parkCodeXa); enter.setChannalCodeXa(channalCodeXa); enter.setChannalCode(channalCode); - if (fileName.length() > 0) + if (fileName.length() > 0){ enter.setImage(fileName); +// try { +// minioClient.statObject(minioConfig.getBucketName(), fileName); +// enter.setImage(fileName); +// } catch (Exception e) { +// log.error("照片保存失败:" + fileName); +// e.printStackTrace(); +// } + } + this.tenPackRecordEnterService.saveTr(enter); } else if (serviceName.equals("exit")) { long exitTimeLong = bizContent.getLongValue("exitTime"); 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 7a93e65..b4015c4 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 @@ -619,6 +619,7 @@ public class XaImageTask implements ITask { // } // } if(resJson.contains("ErrorLineParameter")){ + resJson = resJson.replace("(\"T",""); JSONObject resJsonObject = JSONObject.parseObject(resJson); String errLine = resJsonObject.getJSONObject("sta").getString("ErrorLineParameter").trim(); if(errLine.equals("empty")){ diff --git a/shapelight-admin/src/main/java/net/shapelight/modules/job/task/XaRealDataTask.java b/shapelight-admin/src/main/java/net/shapelight/modules/job/task/XaRealDataTask.java index c8b9595..8f43d58 100644 --- a/shapelight-admin/src/main/java/net/shapelight/modules/job/task/XaRealDataTask.java +++ b/shapelight-admin/src/main/java/net/shapelight/modules/job/task/XaRealDataTask.java @@ -8,6 +8,7 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import java.util.*; import lombok.extern.slf4j.Slf4j; +import net.shapelight.common.utils.Constant; import net.shapelight.common.utils.DateUtils; import net.shapelight.modules.sys.entity.SysUserEntity; import net.shapelight.modules.sys.service.SysUserService; @@ -84,7 +85,23 @@ public class XaRealDataTask implements ITask { List updateRooms = new ArrayList<>(); int count = 0; for (TenRoomEntity room : rooms) { - TenPersonEntity owner = this.tenPersonService.getOwner(room.getRoomId()); + TenPersonEntity owner = null; + List roomPersons = tenPersonService.getByHaveMobilePersonByRoomId(room.getRoomId()); + for(TenPersonEntity personEntity:roomPersons){ + if(personEntity.getPersonType().intValue() == Constant.PERSON_TYPE_OWNER){ + owner = personEntity; + break; + } + } + if(owner==null){ + for(TenPersonEntity personEntity:roomPersons){ + if(personEntity.getPersonType().intValue() == Constant.PERSON_TYPE_MEMBER){ + owner = personEntity; + break; + } + } + } +// TenPersonEntity owner = this.tenPersonService.getOwner(room.getRoomId()); TenAddressEntity addressEntity = tenAddressService.getById(room.getPId()); if (owner != null && addressEntity != null) { XaSYFW xaSYFW = new XaSYFW(); diff --git a/shapelight-admin/src/main/java/net/shapelight/modules/job/task/XaRecordTask.java b/shapelight-admin/src/main/java/net/shapelight/modules/job/task/XaRecordTask.java index 8d9029e..ecb9576 100644 --- a/shapelight-admin/src/main/java/net/shapelight/modules/job/task/XaRecordTask.java +++ b/shapelight-admin/src/main/java/net/shapelight/modules/job/task/XaRecordTask.java @@ -250,26 +250,42 @@ public class XaRecordTask implements ITask { // } // } 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.setXaSync(1); - tenPackRecordEnterService.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 getNotSyncImage(@Param("cellId") Long paramLong); + List getByHaveMobilePersonByRoomId(@Param("roomId") Long roomId); + + } diff --git a/shapelight-admin/src/main/java/net/shapelight/modules/ten/dao/TenRoomDao.java b/shapelight-admin/src/main/java/net/shapelight/modules/ten/dao/TenRoomDao.java index 85a234d..2dc83d8 100644 --- a/shapelight-admin/src/main/java/net/shapelight/modules/ten/dao/TenRoomDao.java +++ b/shapelight-admin/src/main/java/net/shapelight/modules/ten/dao/TenRoomDao.java @@ -47,5 +47,9 @@ public interface TenRoomDao { List getNotSync(@Param("cellId") Long paramLong); + List getNotBindByCellId(@Param("cellId") Long paramLong); + + List getPicByCellId(@Param("pId") Long pId,@Param("cellId") Long paramLong); + } diff --git a/shapelight-admin/src/main/java/net/shapelight/modules/ten/service/TenCellService.java b/shapelight-admin/src/main/java/net/shapelight/modules/ten/service/TenCellService.java index 70cca97..0942a2b 100644 --- a/shapelight-admin/src/main/java/net/shapelight/modules/ten/service/TenCellService.java +++ b/shapelight-admin/src/main/java/net/shapelight/modules/ten/service/TenCellService.java @@ -30,5 +30,7 @@ public interface TenCellService extends IService { void updateByIdResis(TenCellEntity cell); + int syncRoomAddress(Long cellId); + } diff --git a/shapelight-admin/src/main/java/net/shapelight/modules/ten/service/TenPersonService.java b/shapelight-admin/src/main/java/net/shapelight/modules/ten/service/TenPersonService.java index c21fe2c..6dd6d83 100644 --- a/shapelight-admin/src/main/java/net/shapelight/modules/ten/service/TenPersonService.java +++ b/shapelight-admin/src/main/java/net/shapelight/modules/ten/service/TenPersonService.java @@ -120,6 +120,8 @@ public interface TenPersonService { List getNotSyncImage(Long paramLong); + List getByHaveMobilePersonByRoomId(Long roomId); + } diff --git a/shapelight-admin/src/main/java/net/shapelight/modules/ten/service/TenRoomService.java b/shapelight-admin/src/main/java/net/shapelight/modules/ten/service/TenRoomService.java index fa9cf18..dec702f 100644 --- a/shapelight-admin/src/main/java/net/shapelight/modules/ten/service/TenRoomService.java +++ b/shapelight-admin/src/main/java/net/shapelight/modules/ten/service/TenRoomService.java @@ -48,5 +48,7 @@ public interface TenRoomService { int getAllCount(Map params); List getNotSync(Long paramLong); + + int syncAddress(Long cellId); } diff --git a/shapelight-admin/src/main/java/net/shapelight/modules/ten/service/impl/TenCellServiceImpl.java b/shapelight-admin/src/main/java/net/shapelight/modules/ten/service/impl/TenCellServiceImpl.java index f0ec171..966d768 100644 --- a/shapelight-admin/src/main/java/net/shapelight/modules/ten/service/impl/TenCellServiceImpl.java +++ b/shapelight-admin/src/main/java/net/shapelight/modules/ten/service/impl/TenCellServiceImpl.java @@ -7,6 +7,7 @@ import net.shapelight.common.utils.SnowflakeIdWorker; import net.shapelight.modules.sys.entity.SysUserEntity; import net.shapelight.modules.sys.service.SysUserRoleService; import net.shapelight.modules.sys.service.SysUserService; +import net.shapelight.modules.ten.entity.TenRoomEntity; import net.shapelight.modules.ten.entity.TenUserScopeEntity; import net.shapelight.modules.ten.service.*; import org.springframework.beans.factory.annotation.Autowired; @@ -178,4 +179,9 @@ public class TenCellServiceImpl extends ServiceImpl i } return cellIdList; } + + @Override + public int syncRoomAddress(Long cellId) { + return tenRoomService.syncAddress(cellId); + } } diff --git a/shapelight-admin/src/main/java/net/shapelight/modules/ten/service/impl/TenPersonServiceImpl.java b/shapelight-admin/src/main/java/net/shapelight/modules/ten/service/impl/TenPersonServiceImpl.java index 7422c3c..ec0cbf0 100644 --- a/shapelight-admin/src/main/java/net/shapelight/modules/ten/service/impl/TenPersonServiceImpl.java +++ b/shapelight-admin/src/main/java/net/shapelight/modules/ten/service/impl/TenPersonServiceImpl.java @@ -2065,4 +2065,9 @@ public class TenPersonServiceImpl implements TenPersonService { public List getNotSyncImage(Long cellId) { return this.tenPersonDao.getNotSyncImage(cellId); } + + @Override + public List getByHaveMobilePersonByRoomId(Long roomId) { + return this.tenPersonDao.getByHaveMobilePersonByRoomId(roomId); + } } diff --git a/shapelight-admin/src/main/java/net/shapelight/modules/ten/service/impl/TenRoomServiceImpl.java b/shapelight-admin/src/main/java/net/shapelight/modules/ten/service/impl/TenRoomServiceImpl.java index 0aa619f..b06252c 100644 --- a/shapelight-admin/src/main/java/net/shapelight/modules/ten/service/impl/TenRoomServiceImpl.java +++ b/shapelight-admin/src/main/java/net/shapelight/modules/ten/service/impl/TenRoomServiceImpl.java @@ -2,10 +2,9 @@ package net.shapelight.modules.ten.service.impl; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import net.shapelight.modules.ten.entity.TenAddressEntity; +import net.shapelight.modules.ten.entity.TenBuildEntity; import net.shapelight.modules.ten.entity.TenCellEntity; -import net.shapelight.modules.ten.service.TenAddressService; -import net.shapelight.modules.ten.service.TenCellService; -import net.shapelight.modules.ten.service.TenPersonService; +import net.shapelight.modules.ten.service.*; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.cache.annotation.CacheEvict; import org.springframework.cache.annotation.Cacheable; @@ -22,7 +21,6 @@ import net.shapelight.common.utils.Query; import net.shapelight.modules.ten.dao.TenRoomDao; import net.shapelight.modules.ten.entity.TenRoomEntity; -import net.shapelight.modules.ten.service.TenRoomService; import org.springframework.transaction.annotation.Transactional; @@ -36,6 +34,8 @@ public class TenRoomServiceImpl implements TenRoomService { private TenPersonService tenPersonService; @Autowired private TenAddressService tenAddressService; + @Autowired + private TenBuildService tenBuildService; @Override public PageUtils queryPage(Map params) { @@ -203,5 +203,41 @@ public class TenRoomServiceImpl implements TenRoomService { return this.tenRoomDao.getNotSync(cellId); } - + @Override + @Transactional(rollbackFor = Exception.class) + public int syncAddress(Long cellId) { + List allRooms = tenRoomDao.getNotBindByCellId(cellId); + TenCellEntity cellEntity = tenCellService.getById(cellId); + int count = 0; + String xqid = cellEntity.getThirdId(); + if(xqid != null && !xqid.isEmpty()){ + for(TenRoomEntity roomEntity: allRooms){ + TenBuildEntity buildEntity = tenBuildService.getById(roomEntity.getBuildId(),roomEntity.getCellId()); + String buildNumber = buildEntity.getNumber(); + String unit = buildEntity.getUnit(); + String layer = roomEntity.getLayer().toString(); + String roomNumber = roomEntity.getRoomNumber().toString(); + String address = "号"+buildNumber+"栋"+unit+"单元"+layer+"层"+roomNumber+"号"; + //查询可以关联的标准地址 + List searchAddressList = tenAddressService.list(new QueryWrapper() + .eq("dzjb",14) + .eq("xqid",xqid) + .like("dzqc",address)); + //查询关联的是否已经绑定 + if(searchAddressList.size() == 1){ + TenAddressEntity addressEntity = searchAddressList.get(0); + List roomBind = tenRoomDao.getPicByCellId(addressEntity.getPId(),roomEntity.getCellId()); + //没有绑定 + if(roomBind.size() == 0){ + count++; + roomEntity.setPId(addressEntity.getPId()); + tenRoomDao.updateById(roomEntity); + }else{ + String roomName = roomEntity.getRoomName(); + } + } + } + } + return count; + } } diff --git a/shapelight-admin/src/main/resources/application-dev.yml b/shapelight-admin/src/main/resources/application-dev.yml index dc83234..b252feb 100644 --- a/shapelight-admin/src/main/resources/application-dev.yml +++ b/shapelight-admin/src/main/resources/application-dev.yml @@ -3,7 +3,7 @@ spring: type: com.alibaba.druid.pool.DruidDataSource druid: driver-class-name: com.mysql.cj.jdbc.Driver - url: jdbc:mysql://192.168.50.232:3306/cell_db_0511?useUnicode=true&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai&rewriteBatchedStatements=true + url: jdbc:mysql://192.168.50.232:3306/cell_db_0621?useUnicode=true&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai&useSSL=false&rewriteBatchedStatements=true username: user password: user@server001 initial-size: 10 @@ -19,23 +19,23 @@ spring: test-on-borrow: false test-on-return: false stat-view-servlet: - enabled: true + enabled: false url-pattern: /druid/* login-username: admin - login-password: admin - allow: 61.185.224.80 - web-stat-filter: - enabled: true - filter: - stat: - log-slow-sql: true - slow-sql-millis: 1000 - merge-sql: false - enabled: true - db-type: mysql - wall: - config: - multi-statement-allow: true + login-password: admin@A1 + allow: + web-stat-filter: + enabled: false + filter: + stat: + log-slow-sql: true + slow-sql-millis: 1000 + merge-sql: false + enabled: true + db-type: mysql + wall: + config: + multi-statement-allow: true #sharding.jdbc: diff --git a/shapelight-admin/src/main/resources/mapper/ten/TenPersonDao.xml b/shapelight-admin/src/main/resources/mapper/ten/TenPersonDao.xml index b3d8cee..87e5b51 100644 --- a/shapelight-admin/src/main/resources/mapper/ten/TenPersonDao.xml +++ b/shapelight-admin/src/main/resources/mapper/ten/TenPersonDao.xml @@ -919,10 +919,12 @@ + + + diff --git a/shapelight-admin/src/main/resources/mapper/ten/TenRoomDao.xml b/shapelight-admin/src/main/resources/mapper/ten/TenRoomDao.xml index 4b0aa98..bd354f7 100644 --- a/shapelight-admin/src/main/resources/mapper/ten/TenRoomDao.xml +++ b/shapelight-admin/src/main/resources/mapper/ten/TenRoomDao.xml @@ -421,6 +421,17 @@ and p_id is not null + + + + diff --git a/shapelight-admin/src/test/java/gb/CarImageTest.java b/shapelight-admin/src/test/java/gb/CarImageTest.java index 42f2f3f..266a25c 100644 --- a/shapelight-admin/src/test/java/gb/CarImageTest.java +++ b/shapelight-admin/src/test/java/gb/CarImageTest.java @@ -2,6 +2,7 @@ package gb; import io.minio.MinioClient; import io.minio.PutObjectOptions; +import lombok.extern.slf4j.Slf4j; import net.coobird.thumbnailator.Thumbnails; import net.shapelight.AdminApplication; import net.shapelight.common.config.MinioConfig; @@ -20,10 +21,12 @@ import java.awt.image.BufferedImage; import java.io.*; import java.net.HttpURLConnection; import java.net.URL; +import java.util.Date; @RunWith(SpringRunner.class) @SpringBootTest(classes = AdminApplication.class) +@Slf4j public class CarImageTest { @Autowired private MinioClient minioClient; @@ -33,9 +36,11 @@ public class CarImageTest { @Test public void ossTest() { - String imgUrl = "http://icecloud-prod.oss-cn-shenzhen.aliyuncs.com/P1610092525/image/202104/25/%E9%99%95A207AY_out_2_5802.jpg?Expires=1619330640&OSSAccessKeyId=LTAI4Furp7fmTGDMRhJ95jaX&Signature=2xS3T%2FlK9LMe%2FjAOotCEvIlCOmU%3D"; + String imgUrl = "http://icecloud-prod.oss-cn-shenzhen.aliyuncs.com/P1613901148/image/202106/17/%E9%99%95A3U32K_out_2_4472.jpg?Expires=1623895438&OSSAccessKeyId=LTAI4Furp7fmTGDMRhJ95jaX&Signature=iJ7H8%2FmOQz2Zs81APGk2SMrREGQ%3D"; imgUrl = imgUrl.replace("amp;", ""); String fileName = "car/" + 222 + "/" + UUIDUtil.uuid() + ".jpg"; + + if (!StringUtils.isEmpty(imgUrl)) { URL url = null; InputStream is = null; @@ -43,50 +48,26 @@ public class CarImageTest { try { url = new URL(imgUrl); - BufferedImage image = ImageIO.read(url); //获取图片的宽、高 System.out.println("Width: " + image.getWidth()); System.out.println("Height: " + image.getHeight()); - //调整图片大小为 400X400尺寸 -// BufferedImage newImage = ImageUtils.resizeImage(image,400,400); int w = image.getWidth(); int h = image.getHeight(); + //调整尺寸不能大于1024 if(w>1024 || h>1024){ image = ThumbnailsUtils.resizeImageOne(image,1024,1024); } - - -// BufferedImage resizeBuff = ThumbnailsUtils.resizeImageOne(image,1024,1024); - - -// ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); -// if (w > 1024 || h > 1024) { -// Thumbnails.of(image) -// .size(1024, 1024) -//// .outputFormat("JPEG") -//// .outputQuality(1) -// .toOutputStream(outputStream); -// } - byte[] data = ImageUtils.imageToBytes(image); -// ByteArrayInputStream is = new ByteArrayInputStream(data); int rl = is.available(); - - -// httpUrl = (HttpURLConnection) url.openConnection(); -// httpUrl.connect(); -//// httpUrl.getInputStream(); -// is = httpUrl.getInputStream(); -// int rl = httpUrl.getContentLength(); -// int l = is.available(); PutObjectOptions putObjectOptions = new PutObjectOptions(rl, -1L); putObjectOptions.setContentType("image/jpeg"); this.minioClient.putObject(this.minioConfig .getBucketName(), fileName, is, putObjectOptions); } catch (Exception e) { e.printStackTrace(); +// log.error("保存图片失败:"+imgUrl+":"+e.getMessage()); fileName = ""; } finally { if (is != null) @@ -99,5 +80,157 @@ public class CarImageTest { httpUrl.disconnect(); } } + + + + +// String imgUrl = "http://icecloud-prod.oss-cn-shenzhen.aliyuncs.com/P1610092525/image/202104/25/%E9%99%95A207AY_out_2_5802.jpg?Expires=1619330640&OSSAccessKeyId=LTAI4Furp7fmTGDMRhJ95jaX&Signature=2xS3T%2FlK9LMe%2FjAOotCEvIlCOmU%3D"; +// imgUrl = imgUrl.replace("amp;", ""); +// String fileName = "car/" + 222 + "/" + UUIDUtil.uuid() + ".jpg"; +// 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()); +// //调整图片大小为 400X400尺寸 +//// BufferedImage newImage = ImageUtils.resizeImage(image,400,400); +// int w = image.getWidth(); +// int h = image.getHeight(); +// if(w>1024 || h>1024){ +// image = ThumbnailsUtils.resizeImageOne(image,1024,1024); +// } +// +// +//// BufferedImage resizeBuff = ThumbnailsUtils.resizeImageOne(image,1024,1024); +// +// +//// ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); +//// if (w > 1024 || h > 1024) { +//// Thumbnails.of(image) +//// .size(1024, 1024) +////// .outputFormat("JPEG") +////// .outputQuality(1) +//// .toOutputStream(outputStream); +//// } +// +// byte[] data = ImageUtils.imageToBytes(image); +//// ByteArrayInputStream +// is = new ByteArrayInputStream(data); +// int rl = is.available(); +// +// +//// httpUrl = (HttpURLConnection) url.openConnection(); +//// httpUrl.connect(); +////// httpUrl.getInputStream(); +//// is = httpUrl.getInputStream(); +//// int rl = httpUrl.getContentLength(); +//// int l = is.available(); +// PutObjectOptions putObjectOptions = new PutObjectOptions(rl, -1L); +// putObjectOptions.setContentType("image/jpeg"); +// this.minioClient.putObject(this.minioConfig +// .getBucketName(), fileName, is, putObjectOptions); +// } catch (Exception e) { +// e.printStackTrace(); +// fileName = ""; +// } finally { +// if (is != null) +// try { +// is.close(); +// } catch (IOException e) { +// e.printStackTrace(); +// } +// if (httpUrl != null) +// httpUrl.disconnect(); +// } +// } + } + + + @Test + public void imageUrlTest() { + String imgUrl = "http://icecloud-prod.oss-cn-shenzhen.aliyuncs.com/P1613901148/image/202106/17/%E9%99%95AH345%E5%AD%A6_in_2_9660.jpg?Expires=1623901253&OSSAccessKeyId=LTAI4Furp7fmTGDMRhJ95jaX&Signature=ASDVTMGzPt8INggoslRbYBgyenc%3D"; + imgUrl = imgUrl.replace("amp;", ""); + String fileName = "car/" + 222 + "/" + UUIDUtil.uuid() + ".jpg"; + + log.error("开始执行"); + + if (!StringUtils.isEmpty(imgUrl)) { + URL url = null; + InputStream is = null; +// HttpURLConnection httpUrl = null; + try { + + //new一个URL对象 + url = new URL(imgUrl); + //打开链接 + HttpURLConnection conn = (HttpURLConnection)url.openConnection(); + //设置请求方式为"GET" + conn.setRequestMethod("GET"); + //超时响应时间为5秒 + conn.setConnectTimeout(5 * 1000); + //通过输入流获取图片数据 + InputStream inStream = conn.getInputStream(); + + ByteArrayOutputStream outStream = new ByteArrayOutputStream(); + //创建一个Buffer字符串 + byte[] buffer = new byte[1024000]; + //每次读取的字符串长度,如果为-1,代表全部读取完毕 + int len = 0; + //使用一个输入流从buffer里把数据读取出来 + while( (len=inStream.read(buffer)) != -1 ){ + //用输出流往buffer里写入数据,中间参数代表从哪个位置开始读,len代表读取的长度 + outStream.write(buffer, 0, len); + } + + //得到图片的二进制数据,以二进制封装得到数据,具有通用性 + byte[] dataImage = outStream.toByteArray(); + + //关闭输入流 + inStream.close(); + outStream.close(); + + ByteArrayInputStream bais = new ByteArrayInputStream(dataImage); + BufferedImage image = ImageIO.read(bais); + + //获取图片的宽、高 +// 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); + } + 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); + } catch (Exception e) { + e.printStackTrace(); + log.error("保存图片失败:"+imgUrl+"-----------------"+e.getMessage()); + fileName = ""; + } finally { + if (is != null) + try { + is.close(); + } catch (IOException e) { + e.printStackTrace(); + } +// if (httpUrl != null) +// httpUrl.disconnect(); + } + } + + log.error("结束执行"); } }