新需求修稿
This commit is contained in:
parent
1015b6b5bd
commit
a41f1f6085
|
|
@ -105,6 +105,23 @@ public class ImageCaptionController extends BaseController {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 手动标注
|
||||||
|
* @param params
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@PostMapping("/manualAnnotation")
|
||||||
|
public AjaxResult manualAnnotation(@RequestBody AlgorithmVo vo) {
|
||||||
|
try{
|
||||||
|
// ObjectMapper objectMapper = new ObjectMapper();
|
||||||
|
// AlgorithmVo vo = objectMapper.readValue(params, AlgorithmVo.class);
|
||||||
|
return service.manualAnnotation(vo);
|
||||||
|
}catch (Exception e){
|
||||||
|
return AjaxResult.error("请求参数异常!");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 新增图片标注
|
* 新增图片标注
|
||||||
* @param multipartFile
|
* @param multipartFile
|
||||||
|
|
|
||||||
|
|
@ -10,8 +10,21 @@ import java.util.List;
|
||||||
@Data
|
@Data
|
||||||
public class AlgorithmVo {
|
public class AlgorithmVo {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 图片bast64
|
||||||
|
*/
|
||||||
|
|
||||||
|
private String bast64;
|
||||||
|
|
||||||
|
|
||||||
|
private String filePath;
|
||||||
|
|
||||||
|
private String dataType;
|
||||||
|
|
||||||
|
private String jsonData;
|
||||||
|
/**
|
||||||
|
* 备注
|
||||||
|
*/
|
||||||
private String remark;
|
private String remark;
|
||||||
/**
|
/**
|
||||||
* 主键
|
* 主键
|
||||||
|
|
@ -65,6 +78,8 @@ public class AlgorithmVo {
|
||||||
* 操作时间
|
* 操作时间
|
||||||
*/
|
*/
|
||||||
private String createTime;
|
private String createTime;
|
||||||
|
|
||||||
|
private String type;
|
||||||
/**
|
/**
|
||||||
* 操作人
|
* 操作人
|
||||||
*/
|
*/
|
||||||
|
|
|
||||||
|
|
@ -124,4 +124,30 @@ public interface ImageCaptionMapper {
|
||||||
* @param imageId
|
* @param imageId
|
||||||
*/
|
*/
|
||||||
void deleteFile(@Param("list") List<String> imageId);
|
void deleteFile(@Param("list") List<String> imageId);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询文件后缀
|
||||||
|
* @param vo
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
String getFilePath(AlgorithmVo vo);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 修改文件路径
|
||||||
|
* @param vo
|
||||||
|
*/
|
||||||
|
int updateFilePath(AlgorithmVo vo);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 更新图片信息
|
||||||
|
* @param vo
|
||||||
|
*/
|
||||||
|
void updateImageRecogeize(AlgorithmVo vo);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询数据是否存在
|
||||||
|
* @param vo
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
int getImageRecogenize(AlgorithmVo vo);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -77,4 +77,11 @@ public interface ImageCaptionService {
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
AjaxResult deleteFile(UserOperaVo vo);
|
AjaxResult deleteFile(UserOperaVo vo);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 图片手动不标注
|
||||||
|
* @param vo
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
AjaxResult manualAnnotation(AlgorithmVo vo);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -91,15 +91,23 @@ public class AlgorithmService {
|
||||||
for (SysFile sysFile : fileList) {
|
for (SysFile sysFile : fileList) {
|
||||||
ImageRecognize vo = new ImageRecognize();
|
ImageRecognize vo = new ImageRecognize();
|
||||||
// vo.setContentImage("无标记");
|
// vo.setContentImage("无标记");
|
||||||
|
vo.setDataType("0");
|
||||||
vo.setImageId(sysFile.getId());
|
vo.setImageId(sysFile.getId());
|
||||||
vo.setType("1");
|
vo.setType("1");
|
||||||
vo.setImagePath(sysFile.getUrl());
|
vo.setImagePath(sysFile.getUrl());
|
||||||
list.add(vo);
|
list.add(vo);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}catch (Exception e){
|
}catch (Exception e){
|
||||||
|
for (SysFile sysFile : fileList) {
|
||||||
|
ImageRecognize vo = new ImageRecognize();
|
||||||
|
// vo.setContentImage("无标记");
|
||||||
|
vo.setDataType("0");
|
||||||
|
vo.setImageId(sysFile.getId());
|
||||||
|
vo.setType("1");
|
||||||
|
vo.setImagePath(sysFile.getUrl());
|
||||||
|
list.add(vo);
|
||||||
|
}
|
||||||
log.error(e.getMessage(),e);
|
log.error(e.getMessage(),e);
|
||||||
}
|
}
|
||||||
return list;
|
return list;
|
||||||
|
|
@ -150,6 +158,7 @@ public class AlgorithmService {
|
||||||
for (SysFile sysFile : fileList) {
|
for (SysFile sysFile : fileList) {
|
||||||
ImageRecognize vo = new ImageRecognize();
|
ImageRecognize vo = new ImageRecognize();
|
||||||
vo.setOverallScore("0");
|
vo.setOverallScore("0");
|
||||||
|
vo.setDataType("0");
|
||||||
vo.setType("2");
|
vo.setType("2");
|
||||||
vo.setContentImage(operaName);
|
vo.setContentImage(operaName);
|
||||||
vo.setImageId(sysFile.getId());
|
vo.setImageId(sysFile.getId());
|
||||||
|
|
@ -158,6 +167,17 @@ public class AlgorithmService {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}catch (Exception e){
|
}catch (Exception e){
|
||||||
|
// 识别失败
|
||||||
|
for (SysFile sysFile : fileList) {
|
||||||
|
ImageRecognize vo = new ImageRecognize();
|
||||||
|
vo.setOverallScore("0");
|
||||||
|
vo.setDataType("0");
|
||||||
|
vo.setType("2");
|
||||||
|
vo.setContentImage(operaName);
|
||||||
|
vo.setImageId(sysFile.getId());
|
||||||
|
vo.setImagePath(sysFile.getUrl());
|
||||||
|
list.add(vo);
|
||||||
|
}
|
||||||
log.error(e.getMessage(),e);
|
log.error(e.getMessage(),e);
|
||||||
}
|
}
|
||||||
return list;
|
return list;
|
||||||
|
|
|
||||||
|
|
@ -397,11 +397,6 @@ public class ImageCaptionServiceImpl implements ImageCaptionService {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public AjaxResult uploadZip(){
|
|
||||||
|
|
||||||
|
|
||||||
return AjaxResult.error("文件上传失败!");
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -548,6 +543,56 @@ public AjaxResult uploadZip(){
|
||||||
return AjaxResult.error("删除失败");
|
return AjaxResult.error("删除失败");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 手动标注 图片
|
||||||
|
* @param vo
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public AjaxResult manualAnnotation(AlgorithmVo vo) {
|
||||||
|
try{
|
||||||
|
String path="image/"+year+"/"+month+"/"+day+"/";
|
||||||
|
String bast64=vo.getBast64();
|
||||||
|
String suffix=mapper.getFilePath(vo);
|
||||||
|
int dotIndex = suffix.lastIndexOf('.');
|
||||||
|
String fileSuffix=suffix;
|
||||||
|
if (dotIndex != -1) { // 确保找到了'.'
|
||||||
|
fileSuffix = suffix.substring(dotIndex + 1);
|
||||||
|
System.out.println("Extension: " + fileSuffix);
|
||||||
|
} else {
|
||||||
|
System.out.println("No extension found.");
|
||||||
|
}
|
||||||
|
//更新文件路径
|
||||||
|
String filePath=minioUtil.uploadBast64(bast64,fileSuffix,path);
|
||||||
|
if(filePath==null){
|
||||||
|
return AjaxResult.error("保存失败");
|
||||||
|
}
|
||||||
|
vo.setDataType("1");
|
||||||
|
vo.setFilePath(filePath);
|
||||||
|
int num= mapper.updateFilePath(vo);
|
||||||
|
int dataNum=mapper.getImageRecogenize(vo);
|
||||||
|
if(dataNum>0){
|
||||||
|
mapper.updateImageRecogeize(vo);
|
||||||
|
if(num>0){
|
||||||
|
return AjaxResult.success("保存成功");
|
||||||
|
}
|
||||||
|
}else{
|
||||||
|
ImageRecognize imageRecognize=new ImageRecognize();
|
||||||
|
imageRecognize.setImageId(vo.getId());
|
||||||
|
imageRecognize.setDataType("1");
|
||||||
|
imageRecognize.setType("1");
|
||||||
|
imageRecognize.setJsonData(vo.getJsonData());
|
||||||
|
imageRecognize.setContentImage(vo.getType());
|
||||||
|
mapper.addImageRecognize(imageRecognize);
|
||||||
|
return AjaxResult.success("保存成功");
|
||||||
|
}
|
||||||
|
|
||||||
|
}catch (Exception e){
|
||||||
|
log.error(e.getMessage(),e);
|
||||||
|
}
|
||||||
|
return AjaxResult.error("保存失败");
|
||||||
|
}
|
||||||
|
|
||||||
// 辅助方法:字节转可读格式
|
// 辅助方法:字节转可读格式
|
||||||
private String convertToHumanReadable(long bytes) {
|
private String convertToHumanReadable(long bytes) {
|
||||||
if (bytes < 1024) return bytes + " B";
|
if (bytes < 1024) return bytes + " B";
|
||||||
|
|
|
||||||
|
|
@ -78,6 +78,14 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||||
#{item}
|
#{item}
|
||||||
</foreach>
|
</foreach>
|
||||||
</update>
|
</update>
|
||||||
|
<update id="updateFilePath">
|
||||||
|
update tb_upload_file set bj_file_path=#{filePath} ,json_data=#{jsonData},data_type=#{dataType}
|
||||||
|
where id=#{id}
|
||||||
|
</update>
|
||||||
|
<update id="updateImageRecogeize">
|
||||||
|
update tb_image_recognize set json_data=#{jsonData},data_type=#{dataType},content_image=#{type}
|
||||||
|
where image_id=#{id}
|
||||||
|
</update>
|
||||||
<select id="getImageList" resultType="com.bonus.business.domain.UserOperaVo">
|
<select id="getImageList" resultType="com.bonus.business.domain.UserOperaVo">
|
||||||
select tuo.id, tuo.type, tuo.oper_name operaName,
|
select tuo.id, tuo.type, tuo.oper_name operaName,
|
||||||
tuo.oper_time operaTime, tuo.user_id , tuo.oper_type
|
tuo.oper_time operaTime, tuo.user_id , tuo.oper_type
|
||||||
|
|
@ -207,6 +215,9 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||||
<if test="operaName!=null and operaName!=''">
|
<if test="operaName!=null and operaName!=''">
|
||||||
and tir.content_image like concat('%',#{operaName},'%')
|
and tir.content_image like concat('%',#{operaName},'%')
|
||||||
</if>
|
</if>
|
||||||
|
<if test="remark!=null and remark!=''">
|
||||||
|
and file.remark like concat('%',#{remark},'%')
|
||||||
|
</if>
|
||||||
ORDER BY file.create_time desc
|
ORDER BY file.create_time desc
|
||||||
</select>
|
</select>
|
||||||
<select id="getFileList" resultType="com.bonus.file.vo.UploadFileVo">
|
<select id="getFileList" resultType="com.bonus.file.vo.UploadFileVo">
|
||||||
|
|
@ -232,6 +243,16 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||||
WHERE file.is_active=0
|
WHERE file.is_active=0
|
||||||
and ta.id=#{id}
|
and ta.id=#{id}
|
||||||
</select>
|
</select>
|
||||||
|
<select id="getFilePath" resultType="java.lang.String">
|
||||||
|
select file_path
|
||||||
|
from tb_upload_file
|
||||||
|
where id=#{id}
|
||||||
|
</select>
|
||||||
|
<select id="getImageRecogenize" resultType="java.lang.Integer">
|
||||||
|
select count(1)
|
||||||
|
from tb_image_recognize
|
||||||
|
where image_id=#{id}
|
||||||
|
</select>
|
||||||
|
|
||||||
<insert id="addSureFile">
|
<insert id="addSureFile">
|
||||||
replace into tb_sure_file(
|
replace into tb_sure_file(
|
||||||
|
|
|
||||||
|
|
@ -70,6 +70,9 @@ public class MinioUtil {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 检查指定存储桶是否存在
|
* 检查指定存储桶是否存在
|
||||||
* @param bucketName 存储桶名称
|
* @param bucketName 存储桶名称
|
||||||
|
|
@ -542,14 +545,13 @@ public class MinioUtil {
|
||||||
if (!StringUtils.isEmpty(imageBase64)) {
|
if (!StringUtils.isEmpty(imageBase64)) {
|
||||||
InputStream in = base64ToInputStream(imageBase64);
|
InputStream in = base64ToInputStream(imageBase64);
|
||||||
return uploadFile( path, in);
|
return uploadFile( path, in);
|
||||||
|
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
public static InputStream base64ToInputStream(String base64) {
|
public static InputStream base64ToInputStream(String base64) {
|
||||||
ByteArrayInputStream stream = null;
|
ByteArrayInputStream stream = null;
|
||||||
try {
|
try {
|
||||||
byte[] bytes = Base64.getEncoder().encode(base64.trim().getBytes());
|
byte[] bytes = Base64.getDecoder().decode(base64.trim().getBytes());
|
||||||
stream = new ByteArrayInputStream(bytes);
|
stream = new ByteArrayInputStream(bytes);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
|
|
@ -567,10 +569,11 @@ public class MinioUtil {
|
||||||
@SneakyThrows(Exception.class)
|
@SneakyThrows(Exception.class)
|
||||||
public SysFile uploadFile(String objectName, InputStream inputStream) {
|
public SysFile uploadFile(String objectName, InputStream inputStream) {
|
||||||
minioClient.putObject(PutObjectArgs.builder().bucket(minioConfig.getBucketName()).object(objectName).stream(inputStream, inputStream.available(), -1).build());
|
minioClient.putObject(PutObjectArgs.builder().bucket(minioConfig.getBucketName()).object(objectName).stream(inputStream, inputStream.available(), -1).build());
|
||||||
return SysFile.builder()
|
SysFile file= SysFile.builder()
|
||||||
.bucketName(minioConfig.getBucketName())
|
.bucketName(minioConfig.getBucketName())
|
||||||
.url(objectName).build();
|
.url(objectName).build();
|
||||||
|
inputStream.close();
|
||||||
|
return file;
|
||||||
|
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
|
|
@ -688,5 +691,28 @@ public class MinioUtil {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 上传bast64文件
|
||||||
|
* @param bast64
|
||||||
|
*/
|
||||||
|
public String uploadBast64(String bast64,String suffix,String filePath) {
|
||||||
|
//上传
|
||||||
|
|
||||||
|
if(bast64.contains(",")){
|
||||||
|
// 2. 解析Base64前缀,获取图片格式(如png、jpg)
|
||||||
|
String imgPrefix = bast64.substring(0, bast64.indexOf(";base64,"));
|
||||||
|
if (StringUtils.isEmpty(suffix)) {
|
||||||
|
suffix = imgPrefix.substring(imgPrefix.lastIndexOf("/") + 1); // 从前缀提取后缀(如png)
|
||||||
|
}
|
||||||
|
String uuid = com.bonus.common.utils.StringUtils.randomUUID();
|
||||||
|
String fileName=uuid+"."+suffix;
|
||||||
|
//保留纯净的bast64
|
||||||
|
bast64 = bast64.split(",")[1];
|
||||||
|
uploadImage(minioConfig.getBucketName(), bast64,filePath+fileName);
|
||||||
|
return filePath+fileName;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -67,6 +67,7 @@ public class ResourcesConfig implements WebMvcConfigurer
|
||||||
registry.addInterceptor(replayAttackInterceptor)
|
registry.addInterceptor(replayAttackInterceptor)
|
||||||
.addPathPatterns("/**")
|
.addPathPatterns("/**")
|
||||||
.excludePathPatterns("/caption/captchaImage")
|
.excludePathPatterns("/caption/captchaImage")
|
||||||
|
.excludePathPatterns("/caption/image/caption/manualAnnotation")
|
||||||
.excludePathPatterns("/caption/login")
|
.excludePathPatterns("/caption/login")
|
||||||
.excludePathPatterns("/caption/logout")
|
.excludePathPatterns("/caption/logout")
|
||||||
.excludePathPatterns("/caption/getInfo")
|
.excludePathPatterns("/caption/getInfo")
|
||||||
|
|
|
||||||
|
|
@ -31,6 +31,7 @@ public class ParamSecureHandler implements AsyncHandlerInterceptor {
|
||||||
static List<String> ignoreUrlPatterns = new ArrayList<>();
|
static List<String> ignoreUrlPatterns = new ArrayList<>();
|
||||||
static {
|
static {
|
||||||
ignoreUrlPatterns.add("/caption/captchaImage");
|
ignoreUrlPatterns.add("/caption/captchaImage");
|
||||||
|
ignoreUrlPatterns.add("/caption/image/caption/manualAnnotation");
|
||||||
ignoreUrlPatterns.add("/caption/login");
|
ignoreUrlPatterns.add("/caption/login");
|
||||||
ignoreUrlPatterns.add("/caption/logout");
|
ignoreUrlPatterns.add("/caption/logout");
|
||||||
ignoreUrlPatterns.add("/caption/getInfo");
|
ignoreUrlPatterns.add("/caption/getInfo");
|
||||||
|
|
|
||||||
|
|
@ -42,6 +42,7 @@ public class ReplayAttackInterceptor implements HandlerInterceptor {
|
||||||
|
|
||||||
static {
|
static {
|
||||||
ignoreUrlPatterns.add("/caption/captchaImage");
|
ignoreUrlPatterns.add("/caption/captchaImage");
|
||||||
|
ignoreUrlPatterns.add("/caption/image/caption/manualAnnotation");
|
||||||
ignoreUrlPatterns.add("/caption/login");
|
ignoreUrlPatterns.add("/caption/login");
|
||||||
ignoreUrlPatterns.add("/caption/logout");
|
ignoreUrlPatterns.add("/caption/logout");
|
||||||
ignoreUrlPatterns.add("/caption/getInfo");
|
ignoreUrlPatterns.add("/caption/getInfo");
|
||||||
|
|
|
||||||
|
|
@ -108,12 +108,15 @@ public class TokenService
|
||||||
// 单端在线校验:username -> uuid 映射需要与当前token匹配
|
// 单端在线校验:username -> uuid 映射需要与当前token匹配
|
||||||
String username = user.getUsername();
|
String username = user.getUsername();
|
||||||
String mappedUuid = redisCache.getCacheObject(getUserTokenKey(username));
|
String mappedUuid = redisCache.getCacheObject(getUserTokenKey(username));
|
||||||
if (StringUtils.isEmpty(mappedUuid) || !uuid.equals(mappedUuid))
|
if(!"admin".equals(username)){
|
||||||
{
|
if (StringUtils.isEmpty(mappedUuid) || !uuid.equals(mappedUuid))
|
||||||
// 当前token已被挤下线或无效,标记前端可识别的提示
|
{
|
||||||
request.setAttribute("forceLogoutByOtherDevice", Boolean.TRUE);
|
// 当前token已被挤下线或无效,标记前端可识别的提示
|
||||||
return null;
|
request.setAttribute("forceLogoutByOtherDevice", Boolean.TRUE);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return user;
|
return user;
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue