停车场-进出记录图片-上传图片功能迁移

This commit is contained in:
XinWei 2024-07-30 17:04:51 +08:00
parent a8643e80d5
commit 938662d535
6 changed files with 112 additions and 1 deletions

View File

@ -1,5 +1,6 @@
package cn.iocoder.yudao.module.parking.controller.admin.accessrecordpicture; package cn.iocoder.yudao.module.parking.controller.admin.accessrecordpicture;
import cn.iocoder.yudao.module.parking.util.BlueCardResult;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource; import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated; import org.springframework.validation.annotation.Validated;
@ -38,6 +39,10 @@ public class AccessRecordPictureController {
@Resource @Resource
private AccessRecordPictureService accessRecordPictureService; private AccessRecordPictureService accessRecordPictureService;
@PostMapping("/bcinterface/UpImage")
public BlueCardResult insertAccessRecordPicture (@RequestBody AccessRecordPictureDO accessRecordPicture){
return accessRecordPictureService.uploadAccessRecordPicture(accessRecordPicture);
}
@PostMapping("/create") @PostMapping("/create")
@Operation(summary = "创建进出记录图片") @Operation(summary = "创建进出记录图片")
@PreAuthorize("@ss.hasPermission('parking:access-record-picture:create')") @PreAuthorize("@ss.hasPermission('parking:access-record-picture:create')")

View File

@ -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.module.parking.dal.dataobject.accessrecordpicture.AccessRecordPictureDO;
import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.pojo.PageParam; import cn.iocoder.yudao.framework.common.pojo.PageParam;
import cn.iocoder.yudao.module.parking.util.BlueCardResult;
/** /**
* 进出记录图片 Service 接口 * 进出记录图片 Service 接口
@ -52,4 +53,10 @@ public interface AccessRecordPictureService {
*/ */
PageResult<AccessRecordPictureDO> getAccessRecordPicturePage(AccessRecordPicturePageReqVO pageReqVO); PageResult<AccessRecordPictureDO> getAccessRecordPicturePage(AccessRecordPicturePageReqVO pageReqVO);
/**
* 上传进出记录图片
* @param accessRecordPicture
* @return cn.iocoder.yudao.module.parking.util.BlueCardResult
*/
BlueCardResult uploadAccessRecordPicture(AccessRecordPictureDO accessRecordPicture);
} }

View File

@ -1,5 +1,9 @@
package cn.iocoder.yudao.module.parking.service.accessrecordpicture; 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 org.springframework.stereotype.Service;
import javax.annotation.Resource; import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated; import org.springframework.validation.annotation.Validated;
@ -28,7 +32,10 @@ public class AccessRecordPictureServiceImpl implements AccessRecordPictureServic
@Resource @Resource
private AccessRecordPictureMapper accessRecordPictureMapper; private AccessRecordPictureMapper accessRecordPictureMapper;
@Resource
private Base64Util base64Util;
@Value("${lundu.imgPath}")
private String imgPath;
@Override @Override
public Long createAccessRecordPicture(AccessRecordPictureSaveReqVO createReqVO) { public Long createAccessRecordPicture(AccessRecordPictureSaveReqVO createReqVO) {
// 插入 // 插入
@ -71,4 +78,12 @@ public class AccessRecordPictureServiceImpl implements AccessRecordPictureServic
return accessRecordPictureMapper.selectPage(pageReqVO); 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();
}
} }

View File

@ -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 "";
}
}
}

View File

@ -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<String,String> datas;
public static BlueCardResult success(){
BlueCardResult blueCardResult = new BlueCardResult();
blueCardResult.setStatus("success");
Map<String, String> 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;
}
}

View File

@ -113,3 +113,8 @@ yudao:
ignore-tables: ignore-tables:
debug: false debug: false
lundu:
# Linux系统下文件路径
basePath: /home/upload/bcinterface/Uplmage/
#Windows下的文件路径
imgPath: https://yyxh.ptzykjgs.com/api/img/