From 865f90ca2a7f5bfda3b82ae3ab02981adae143ae Mon Sep 17 00:00:00 2001 From: zc Date: Tue, 16 Dec 2025 09:38:31 +0800 Subject: [PATCH] =?UTF-8?q?=E5=85=B4=E5=AE=89=E4=BC=98=E5=8C=96=E8=BD=A6?= =?UTF-8?q?=E8=BE=86=E5=8C=85=E5=85=BC=E5=AE=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- dcsoft-auth/src/main/resources/bootstrap.yml | 4 +- .../src/main/resources/bootstrap.yml | 4 +- .../file/controller/SysFileController.java | 65 ++++---- .../file/utils/Base64MultipartFile.java | 77 +++++++++ .../file/utils/Base64ToMultipartFileUtil.java | 28 ++++ .../resources/mapper/job/SysJobLogMapper.xml | 1 + .../vehicle/controller/CarInfoController.java | 46 +++-- .../vehicle/controller/CarParkController.java | 11 ++ .../dcsoft/system/vehicle/domain/CarInfo.java | 3 +- .../dcsoft/system/vehicle/domain/CarPark.java | 33 ++++ .../system/vehicle/domain/CarParkItem.java | 13 ++ .../system/vehicle/mapper/CarParkMapper.java | 4 + .../vehicle/service/ICarParkService.java | 2 + .../service/impl/CarInfoServiceImpl.java | 157 +++++++++--------- .../service/impl/CarParkServiceImpl.java | 27 ++- .../mapper/vehicle/CarInfoMapper.xml | 2 +- .../mapper/vehicle/CarParkItemMapper.xml | 5 + .../mapper/vehicle/CarParkMapper.xml | 25 ++- .../mapper/vehicle/CarPassGatherMapper.xml | 2 +- .../mapper/vehicle/CarPassRecordMapper.xml | 2 +- 20 files changed, 373 insertions(+), 138 deletions(-) create mode 100644 dcsoft-modules/dcsoft-file/src/main/java/com/dcsoft/file/utils/Base64MultipartFile.java create mode 100644 dcsoft-modules/dcsoft-file/src/main/java/com/dcsoft/file/utils/Base64ToMultipartFileUtil.java diff --git a/dcsoft-auth/src/main/resources/bootstrap.yml b/dcsoft-auth/src/main/resources/bootstrap.yml index 48a5d5a..769605e 100644 --- a/dcsoft-auth/src/main/resources/bootstrap.yml +++ b/dcsoft-auth/src/main/resources/bootstrap.yml @@ -15,11 +15,11 @@ spring: discovery: # 服务注册地址 server-addr: 127.0.0.1:8848 -# namespace: xa + namespace: xa config: # 配置中心地址 server-addr: 127.0.0.1:8848 -# namespace: xa + namespace: xa # 配置文件格式 file-extension: yml # 共享配置 diff --git a/dcsoft-gateway/src/main/resources/bootstrap.yml b/dcsoft-gateway/src/main/resources/bootstrap.yml index 822e1e6..9b688ab 100644 --- a/dcsoft-gateway/src/main/resources/bootstrap.yml +++ b/dcsoft-gateway/src/main/resources/bootstrap.yml @@ -15,11 +15,11 @@ spring: discovery: # 服务注册地址 server-addr: 127.0.0.1:8848 -# namespace: xa + namespace: xa config: # 配置中心地址 server-addr: 127.0.0.1:8848 -# namespace: xa + namespace: xa # 配置文件格式 file-extension: yml # 共享配置 diff --git a/dcsoft-modules/dcsoft-file/src/main/java/com/dcsoft/file/controller/SysFileController.java b/dcsoft-modules/dcsoft-file/src/main/java/com/dcsoft/file/controller/SysFileController.java index 3fe1105..62ed798 100644 --- a/dcsoft-modules/dcsoft-file/src/main/java/com/dcsoft/file/controller/SysFileController.java +++ b/dcsoft-modules/dcsoft-file/src/main/java/com/dcsoft/file/controller/SysFileController.java @@ -13,24 +13,19 @@ import com.dcsoft.common.core.utils.file.FileUtils; import com.dcsoft.common.redis.service.RedisService; import com.dcsoft.file.service.IFaceService; import com.dcsoft.file.service.ISysFileService; -import com.dcsoft.file.utils.FileUploadUtils; -import com.dcsoft.file.utils.ImageToBase64Utils; -import com.dcsoft.file.utils.MinioUtil; -import com.dcsoft.file.utils.PictureUtils; +import com.dcsoft.file.utils.*; import com.dcsoft.system.api.domain.SysFile; import io.minio.MinioClient; import io.minio.RemoveObjectArgs; import net.coobird.thumbnailator.Thumbnails; +import net.coobird.thumbnailator.geometry.Positions; import org.apache.commons.codec.binary.Base64; import org.apache.commons.codec.digest.DigestUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.RequestParam; -import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.bind.annotation.*; import org.springframework.web.multipart.MultipartFile; import java.io.File; @@ -164,6 +159,27 @@ public class SysFileController { } } + @PostMapping("uploadMinioCarBase64") + public R uploadMinioCarBase64(@RequestBody JSONObject data) { + try { + String url = data.getString("url"); + if(StringUtils.isEmpty(url)){ + return R.fail("图片地址不能为空"); + } + MultipartFile file = Base64ToMultipartFileUtil.convertToMultipartFile(url); + + String fileNames = FileUploadUtils.uploadMinio(file, this.bucketName2, file.getName()); + SysFile sysFile = new SysFile(); + sysFile.setName(FileUtils.getName(fileNames)); + fileNames = fileNames.replace(miniourl, miniogwurl); + sysFile.setUrl(fileNames); + return R.ok(sysFile); + } catch (Exception e) { + log.error("上传文件失败", e); + return R.fail(e.getMessage()); + } + } + /** * 文件上传请求 @@ -293,29 +309,16 @@ public class SysFileController { @PostMapping("uploadMinio1") public R uploadMinio1(MultipartFile file, String fileName) { try { - //判断压缩图片 - if ((1024 * 1024 * 0.1) <= file.getSize()) { - // 小于 1M 的 - try { - String fileNames1 = file.getOriginalFilename(); - File newFile = new File(fileNames1); - if ((1024 * 1024 * 0.1) <= file.getSize() && file.getSize() <= (1024 * 1024)) { - Thumbnails.of(file.getInputStream()).scale(1f).outputQuality(0.4f).toFile(newFile); - } - // 1 - 2M 的 - else if ((1024 * 1024) < file.getSize() && file.getSize() <= (1024 * 1024 * 2)) { - Thumbnails.of(file.getInputStream()).scale(1f).outputQuality(0.2f).toFile(newFile); - } - // 2M 以上的 - else if ((1024 * 1024 * 2) < file.getSize()) { - Thumbnails.of(file.getInputStream()).scale(1f).outputQuality(0.1f).toFile(newFile); - } - // 转为 MultipartFile - file = PictureUtils.getMultipartFile(newFile); - newFile.delete(); - } catch (IOException e) { - throw new RuntimeException(e); - } + try { + // 裁剪图片为640*480 + String originalFilename = file.getOriginalFilename(); + File newFile = new File(originalFilename); + Thumbnails.of(file.getInputStream()).crop(Positions.CENTER).size(480, 640).toFile(newFile); + + file = PictureUtils.getMultipartFile(newFile); + newFile.delete(); + } catch (IOException e) { + throw new RuntimeException(e); } initFlowRules(); //上传前进行人脸检测 diff --git a/dcsoft-modules/dcsoft-file/src/main/java/com/dcsoft/file/utils/Base64MultipartFile.java b/dcsoft-modules/dcsoft-file/src/main/java/com/dcsoft/file/utils/Base64MultipartFile.java new file mode 100644 index 0000000..03140ff --- /dev/null +++ b/dcsoft-modules/dcsoft-file/src/main/java/com/dcsoft/file/utils/Base64MultipartFile.java @@ -0,0 +1,77 @@ +package com.dcsoft.file.utils; + +import org.springframework.web.multipart.MultipartFile; + +import java.io.*; +import java.util.Base64; + +public class Base64MultipartFile implements MultipartFile { + + private final byte[] fileContent; + private final String fileName; + private final String contentType; + + public Base64MultipartFile(String base64Data, String fileName) { + // 清理Base64数据 + String cleanedBase64 = base64Data.contains(",") + ? base64Data.substring(base64Data.indexOf(",") + 1) + : base64Data; + + this.fileContent = Base64.getDecoder().decode(cleanedBase64); + this.fileName = fileName; + this.contentType = extractContentType(base64Data); + } + + private String extractContentType(String base64Data) { + if (base64Data.startsWith("data:image/jpeg")) { + return "image/jpeg"; + } else if (base64Data.startsWith("data:image/png")) { + return "image/png"; + } else if (base64Data.startsWith("data:image/gif")) { + return "image/gif"; + } + return "application/octet-stream"; + } + + @Override + public String getName() { + return "file"; + } + + @Override + public String getOriginalFilename() { + return fileName; + } + + @Override + public String getContentType() { + return contentType; + } + + @Override + public boolean isEmpty() { + return fileContent == null || fileContent.length == 0; + } + + @Override + public long getSize() { + return fileContent.length; + } + + @Override + public byte[] getBytes() throws IOException { + return fileContent; + } + + @Override + public InputStream getInputStream() throws IOException { + return new ByteArrayInputStream(fileContent); + } + + @Override + public void transferTo(File dest) throws IOException, IllegalStateException { + try (FileOutputStream fos = new FileOutputStream(dest)) { + fos.write(fileContent); + } + } +} diff --git a/dcsoft-modules/dcsoft-file/src/main/java/com/dcsoft/file/utils/Base64ToMultipartFileUtil.java b/dcsoft-modules/dcsoft-file/src/main/java/com/dcsoft/file/utils/Base64ToMultipartFileUtil.java new file mode 100644 index 0000000..7149b5c --- /dev/null +++ b/dcsoft-modules/dcsoft-file/src/main/java/com/dcsoft/file/utils/Base64ToMultipartFileUtil.java @@ -0,0 +1,28 @@ +package com.dcsoft.file.utils; + +import org.springframework.web.multipart.MultipartFile; + +public class Base64ToMultipartFileUtil { + + public static MultipartFile convertToMultipartFile(String base64Data, String fileName) { + return new Base64MultipartFile(base64Data, fileName); + } + + /** + * 自动生成文件名 + */ + public static MultipartFile convertToMultipartFile(String base64Data) { + String fileName = generateFileName(base64Data); + return convertToMultipartFile(base64Data, fileName); + } + + private static String generateFileName(String base64Data) { + String extension = ".jpg"; + if (base64Data.startsWith("data:image/png")) { + extension = ".png"; + } else if (base64Data.startsWith("data:image/gif")) { + extension = ".gif"; + } + return "image_" + System.currentTimeMillis() + extension; + } +} diff --git a/dcsoft-modules/dcsoft-job/src/main/resources/mapper/job/SysJobLogMapper.xml b/dcsoft-modules/dcsoft-job/src/main/resources/mapper/job/SysJobLogMapper.xml index 20bb1fe..dcf95bb 100644 --- a/dcsoft-modules/dcsoft-job/src/main/resources/mapper/job/SysJobLogMapper.xml +++ b/dcsoft-modules/dcsoft-job/src/main/resources/mapper/job/SysJobLogMapper.xml @@ -42,6 +42,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" and date_format(create_time,'%y%m%d') <= date_format(#{params.endTime},'%y%m%d') + group by create_time desc diff --git a/dcsoft-modules/dcsoft-system/src/main/resources/mapper/vehicle/CarParkMapper.xml b/dcsoft-modules/dcsoft-system/src/main/resources/mapper/vehicle/CarParkMapper.xml index a377942..0237288 100644 --- a/dcsoft-modules/dcsoft-system/src/main/resources/mapper/vehicle/CarParkMapper.xml +++ b/dcsoft-modules/dcsoft-system/src/main/resources/mapper/vehicle/CarParkMapper.xml @@ -16,11 +16,13 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" + + select cp.id, cp.name, cp.space_id, cp.cars_num, cp.surplus_num, cp.remark, cp.create_by, cp.create_time, - cp.update_by, cp.update_time,ss.name space_name + cp.update_by, cp.update_time,ss.name space_name,cp.auto_lock,cp.parent_id from car_park cp left join sys_space ss on cp.space_id=ss.id @@ -51,6 +53,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" create_time, update_by, update_time, + parent_id, + auto_lock, #{id}, @@ -63,6 +67,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" #{createTime}, #{updateBy}, #{updateTime}, + #{parentId}, + #{autoLock}, @@ -78,6 +84,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" create_time = #{createTime}, update_by = #{updateBy}, update_time = #{updateTime}, + parent_id = #{parentId}, + auto_lock = #{autoLock}, where id = #{id} @@ -122,4 +130,19 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" where cp.name = #{name} + + + + diff --git a/dcsoft-modules/dcsoft-system/src/main/resources/mapper/vehicle/CarPassGatherMapper.xml b/dcsoft-modules/dcsoft-system/src/main/resources/mapper/vehicle/CarPassGatherMapper.xml index f5fd4ee..af9fc82 100644 --- a/dcsoft-modules/dcsoft-system/src/main/resources/mapper/vehicle/CarPassGatherMapper.xml +++ b/dcsoft-modules/dcsoft-system/src/main/resources/mapper/vehicle/CarPassGatherMapper.xml @@ -20,7 +20,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" select cpg.id, cpg.park_id, cpg.area, cpg.license, cpg.join_time, cpg.sn,cp.name park_name,se.name equipment_name,HOUR(TIMEDIFF(NOW(),cpg.join_time)) AS time_long from car_pass_gather cpg left join car_park cp on cp.id=cpg.park_id - left join sys_equipment se on se.sequence=cpg.sn + left join sys_equipment se on se.sequence=cpg.sn and se.product_id = 4