diff --git a/ludu-module-parking/ludu-module-parking-biz/src/main/java/cn/iocoder/yudao/module/parking/controller/admin/accessrecordpicture/AccessRecordPictureController.java b/ludu-module-parking/ludu-module-parking-biz/src/main/java/cn/iocoder/yudao/module/parking/controller/admin/accessrecordpicture/AccessRecordPictureController.java index 815b3cee1..d10a93ef0 100644 --- a/ludu-module-parking/ludu-module-parking-biz/src/main/java/cn/iocoder/yudao/module/parking/controller/admin/accessrecordpicture/AccessRecordPictureController.java +++ b/ludu-module-parking/ludu-module-parking-biz/src/main/java/cn/iocoder/yudao/module/parking/controller/admin/accessrecordpicture/AccessRecordPictureController.java @@ -1,5 +1,6 @@ package cn.iocoder.yudao.module.parking.controller.admin.accessrecordpicture; +import cn.iocoder.yudao.module.parking.util.BlueCardResult; import org.springframework.web.bind.annotation.*; import javax.annotation.Resource; import org.springframework.validation.annotation.Validated; @@ -38,6 +39,10 @@ public class AccessRecordPictureController { @Resource private AccessRecordPictureService accessRecordPictureService; + @PostMapping("/bcinterface/UpImage") + public BlueCardResult insertAccessRecordPicture (@RequestBody AccessRecordPictureDO accessRecordPicture){ + return accessRecordPictureService.uploadAccessRecordPicture(accessRecordPicture); + } @PostMapping("/create") @Operation(summary = "创建进出记录图片") @PreAuthorize("@ss.hasPermission('parking:access-record-picture:create')") diff --git a/ludu-module-parking/ludu-module-parking-biz/src/main/java/cn/iocoder/yudao/module/parking/service/accessrecordpicture/AccessRecordPictureService.java b/ludu-module-parking/ludu-module-parking-biz/src/main/java/cn/iocoder/yudao/module/parking/service/accessrecordpicture/AccessRecordPictureService.java index 68f77fb7f..1a31869ee 100644 --- a/ludu-module-parking/ludu-module-parking-biz/src/main/java/cn/iocoder/yudao/module/parking/service/accessrecordpicture/AccessRecordPictureService.java +++ b/ludu-module-parking/ludu-module-parking-biz/src/main/java/cn/iocoder/yudao/module/parking/service/accessrecordpicture/AccessRecordPictureService.java @@ -6,6 +6,7 @@ import cn.iocoder.yudao.module.parking.controller.admin.accessrecordpicture.vo.* import cn.iocoder.yudao.module.parking.dal.dataobject.accessrecordpicture.AccessRecordPictureDO; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.common.pojo.PageParam; +import cn.iocoder.yudao.module.parking.util.BlueCardResult; /** * 进出记录图片 Service 接口 @@ -52,4 +53,10 @@ public interface AccessRecordPictureService { */ PageResult getAccessRecordPicturePage(AccessRecordPicturePageReqVO pageReqVO); + /** + * 上传进出记录图片 + * @param accessRecordPicture + * @return cn.iocoder.yudao.module.parking.util.BlueCardResult + */ + BlueCardResult uploadAccessRecordPicture(AccessRecordPictureDO accessRecordPicture); } \ No newline at end of file diff --git a/ludu-module-parking/ludu-module-parking-biz/src/main/java/cn/iocoder/yudao/module/parking/service/accessrecordpicture/AccessRecordPictureServiceImpl.java b/ludu-module-parking/ludu-module-parking-biz/src/main/java/cn/iocoder/yudao/module/parking/service/accessrecordpicture/AccessRecordPictureServiceImpl.java index c0ad32e83..4d2cd2807 100644 --- a/ludu-module-parking/ludu-module-parking-biz/src/main/java/cn/iocoder/yudao/module/parking/service/accessrecordpicture/AccessRecordPictureServiceImpl.java +++ b/ludu-module-parking/ludu-module-parking-biz/src/main/java/cn/iocoder/yudao/module/parking/service/accessrecordpicture/AccessRecordPictureServiceImpl.java @@ -1,5 +1,9 @@ package cn.iocoder.yudao.module.parking.service.accessrecordpicture; +import cn.iocoder.yudao.module.parking.util.Base64Util; +import cn.iocoder.yudao.module.parking.util.BlueCardResult; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Service; import javax.annotation.Resource; import org.springframework.validation.annotation.Validated; @@ -28,7 +32,10 @@ public class AccessRecordPictureServiceImpl implements AccessRecordPictureServic @Resource private AccessRecordPictureMapper accessRecordPictureMapper; - + @Resource + private Base64Util base64Util; + @Value("${lundu.imgPath}") + private String imgPath; @Override public Long createAccessRecordPicture(AccessRecordPictureSaveReqVO createReqVO) { // 插入 @@ -71,4 +78,12 @@ public class AccessRecordPictureServiceImpl implements AccessRecordPictureServic return accessRecordPictureMapper.selectPage(pageReqVO); } + @Override + public BlueCardResult uploadAccessRecordPicture(AccessRecordPictureDO accessRecordPicture) { + base64Util.GenerateImage(accessRecordPicture.getImage(), accessRecordPicture.getImageName());//图片解密 + accessRecordPicture.setImgAddress(imgPath+accessRecordPicture.getImageName()); + accessRecordPictureMapper.insert(accessRecordPicture); + return BlueCardResult.success(); + } + } \ No newline at end of file diff --git a/ludu-module-parking/ludu-module-parking-biz/src/main/java/cn/iocoder/yudao/module/parking/util/Base64Util.java b/ludu-module-parking/ludu-module-parking-biz/src/main/java/cn/iocoder/yudao/module/parking/util/Base64Util.java new file mode 100644 index 000000000..36f3fd47c --- /dev/null +++ b/ludu-module-parking/ludu-module-parking-biz/src/main/java/cn/iocoder/yudao/module/parking/util/Base64Util.java @@ -0,0 +1,47 @@ +package cn.iocoder.yudao.module.parking.util; + +import org.apache.tomcat.util.codec.binary.Base64; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.stereotype.Component; + +import java.io.FileOutputStream; +import java.io.OutputStream; + +/** + * @Description 解析base64图片工具类 + */ +@Component +public class Base64Util { + + @Value("${lundu.basePath}") + private String uploadURL; + + public String GenerateImage(String imgStr, String fileName){ // 对字节数组字符串进行Base64解码并生成图片 + if (imgStr == null) { + // 图像数据为空 + return ""; + } + try {// Base64解码 + // byte[] b = decoder.decodeBuffer(imgStr); + String replace = imgStr.replace(" ", "+"); + byte[] b = Base64.decodeBase64(replace); + for (int i = 0; i < b.length; ++i) { + if (b[i] < 0) {// 调整异常数据 + b[i] += 256; + } + } + // 创建输出流 + String imgAddress = uploadURL+fileName; + System.out.println(imgAddress); + OutputStream out = new FileOutputStream(imgAddress); + out.write(b); + out.flush(); + out.close(); + return imgAddress; + } catch (Exception e) { + e.printStackTrace(); + return ""; + } + } + +} diff --git a/ludu-module-parking/ludu-module-parking-biz/src/main/java/cn/iocoder/yudao/module/parking/util/BlueCardResult.java b/ludu-module-parking/ludu-module-parking-biz/src/main/java/cn/iocoder/yudao/module/parking/util/BlueCardResult.java new file mode 100644 index 000000000..57d9281f6 --- /dev/null +++ b/ludu-module-parking/ludu-module-parking-biz/src/main/java/cn/iocoder/yudao/module/parking/util/BlueCardResult.java @@ -0,0 +1,32 @@ +package cn.iocoder.yudao.module.parking.util; + +import lombok.Data; + +import java.util.HashMap; +import java.util.Map; + +/** + * @Description 蓝卡返回数据 + */ +@Data +public class BlueCardResult { + private String status; + private String errorCode; + private Map datas; + + public static BlueCardResult success(){ + BlueCardResult blueCardResult = new BlueCardResult(); + blueCardResult.setStatus("success"); + Map map = new HashMap<>(); + map.put("timeStamp",String.valueOf(System.currentTimeMillis())); + blueCardResult.setDatas(map); + return blueCardResult; + } + + public static BlueCardResult error(String e){ + BlueCardResult blueCardResult = new BlueCardResult(); + blueCardResult.setStatus("fail"); + blueCardResult.setErrorCode(e); + return blueCardResult; + } +} diff --git a/ludu-module-parking/ludu-module-parking-biz/src/main/resources/application.yaml b/ludu-module-parking/ludu-module-parking-biz/src/main/resources/application.yaml index 4092591e8..2ec999dd3 100644 --- a/ludu-module-parking/ludu-module-parking-biz/src/main/resources/application.yaml +++ b/ludu-module-parking/ludu-module-parking-biz/src/main/resources/application.yaml @@ -113,3 +113,8 @@ yudao: ignore-tables: debug: false +lundu: + # Linux系统下文件路径 + basePath: /home/upload/bcinterface/Uplmage/ + #Windows下的文件路径 + imgPath: https://yyxh.ptzykjgs.com/api/img/