新需求修稿
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
|
||||
|
|
|
|||
|
|
@ -10,8 +10,21 @@ import java.util.List;
|
|||
@Data
|
||||
public class AlgorithmVo {
|
||||
|
||||
/**
|
||||
* 图片bast64
|
||||
*/
|
||||
|
||||
private String bast64;
|
||||
|
||||
|
||||
private String filePath;
|
||||
|
||||
private String dataType;
|
||||
|
||||
private String jsonData;
|
||||
/**
|
||||
* 备注
|
||||
*/
|
||||
private String remark;
|
||||
/**
|
||||
* 主键
|
||||
|
|
@ -65,6 +78,8 @@ public class AlgorithmVo {
|
|||
* 操作时间
|
||||
*/
|
||||
private String createTime;
|
||||
|
||||
private String type;
|
||||
/**
|
||||
* 操作人
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -124,4 +124,30 @@ public interface ImageCaptionMapper {
|
|||
* @param 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
|
||||
*/
|
||||
AjaxResult deleteFile(UserOperaVo vo);
|
||||
|
||||
/**
|
||||
* 图片手动不标注
|
||||
* @param vo
|
||||
* @return
|
||||
*/
|
||||
AjaxResult manualAnnotation(AlgorithmVo vo);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -91,15 +91,23 @@ public class AlgorithmService {
|
|||
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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}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);
|
||||
}
|
||||
return list;
|
||||
|
|
@ -150,6 +158,7 @@ public class AlgorithmService {
|
|||
for (SysFile sysFile : fileList) {
|
||||
ImageRecognize vo = new ImageRecognize();
|
||||
vo.setOverallScore("0");
|
||||
vo.setDataType("0");
|
||||
vo.setType("2");
|
||||
vo.setContentImage(operaName);
|
||||
vo.setImageId(sysFile.getId());
|
||||
|
|
@ -158,6 +167,17 @@ public class AlgorithmService {
|
|||
}
|
||||
}
|
||||
}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);
|
||||
}
|
||||
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("删除失败");
|
||||
}
|
||||
|
||||
/**
|
||||
* 手动标注 图片
|
||||
* @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) {
|
||||
if (bytes < 1024) return bytes + " B";
|
||||
|
|
|
|||
|
|
@ -78,6 +78,14 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||
#{item}
|
||||
</foreach>
|
||||
</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 tuo.id, tuo.type, tuo.oper_name operaName,
|
||||
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!=''">
|
||||
and tir.content_image like concat('%',#{operaName},'%')
|
||||
</if>
|
||||
<if test="remark!=null and remark!=''">
|
||||
and file.remark like concat('%',#{remark},'%')
|
||||
</if>
|
||||
ORDER BY file.create_time desc
|
||||
</select>
|
||||
<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
|
||||
and ta.id=#{id}
|
||||
</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">
|
||||
replace into tb_sure_file(
|
||||
|
|
|
|||
|
|
@ -70,6 +70,9 @@ public class MinioUtil {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 检查指定存储桶是否存在
|
||||
* @param bucketName 存储桶名称
|
||||
|
|
@ -542,14 +545,13 @@ public class MinioUtil {
|
|||
if (!StringUtils.isEmpty(imageBase64)) {
|
||||
InputStream in = base64ToInputStream(imageBase64);
|
||||
return uploadFile( path, in);
|
||||
|
||||
}
|
||||
return null;
|
||||
}
|
||||
public static InputStream base64ToInputStream(String base64) {
|
||||
ByteArrayInputStream stream = null;
|
||||
try {
|
||||
byte[] bytes = Base64.getEncoder().encode(base64.trim().getBytes());
|
||||
byte[] bytes = Base64.getDecoder().decode(base64.trim().getBytes());
|
||||
stream = new ByteArrayInputStream(bytes);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
|
|
@ -567,10 +569,11 @@ public class MinioUtil {
|
|||
@SneakyThrows(Exception.class)
|
||||
public SysFile uploadFile(String objectName, InputStream inputStream) {
|
||||
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())
|
||||
.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)
|
||||
.addPathPatterns("/**")
|
||||
.excludePathPatterns("/caption/captchaImage")
|
||||
.excludePathPatterns("/caption/image/caption/manualAnnotation")
|
||||
.excludePathPatterns("/caption/login")
|
||||
.excludePathPatterns("/caption/logout")
|
||||
.excludePathPatterns("/caption/getInfo")
|
||||
|
|
|
|||
|
|
@ -31,6 +31,7 @@ public class ParamSecureHandler implements AsyncHandlerInterceptor {
|
|||
static List<String> ignoreUrlPatterns = new ArrayList<>();
|
||||
static {
|
||||
ignoreUrlPatterns.add("/caption/captchaImage");
|
||||
ignoreUrlPatterns.add("/caption/image/caption/manualAnnotation");
|
||||
ignoreUrlPatterns.add("/caption/login");
|
||||
ignoreUrlPatterns.add("/caption/logout");
|
||||
ignoreUrlPatterns.add("/caption/getInfo");
|
||||
|
|
|
|||
|
|
@ -42,6 +42,7 @@ public class ReplayAttackInterceptor implements HandlerInterceptor {
|
|||
|
||||
static {
|
||||
ignoreUrlPatterns.add("/caption/captchaImage");
|
||||
ignoreUrlPatterns.add("/caption/image/caption/manualAnnotation");
|
||||
ignoreUrlPatterns.add("/caption/login");
|
||||
ignoreUrlPatterns.add("/caption/logout");
|
||||
ignoreUrlPatterns.add("/caption/getInfo");
|
||||
|
|
|
|||
|
|
@ -108,12 +108,15 @@ public class TokenService
|
|||
// 单端在线校验:username -> uuid 映射需要与当前token匹配
|
||||
String username = user.getUsername();
|
||||
String mappedUuid = redisCache.getCacheObject(getUserTokenKey(username));
|
||||
if (StringUtils.isEmpty(mappedUuid) || !uuid.equals(mappedUuid))
|
||||
{
|
||||
// 当前token已被挤下线或无效,标记前端可识别的提示
|
||||
request.setAttribute("forceLogoutByOtherDevice", Boolean.TRUE);
|
||||
return null;
|
||||
if(!"admin".equals(username)){
|
||||
if (StringUtils.isEmpty(mappedUuid) || !uuid.equals(mappedUuid))
|
||||
{
|
||||
// 当前token已被挤下线或无效,标记前端可识别的提示
|
||||
request.setAttribute("forceLogoutByOtherDevice", Boolean.TRUE);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
return user;
|
||||
}
|
||||
catch (Exception e)
|
||||
|
|
|
|||
Loading…
Reference in New Issue