Browse Source

角果识别后台

master
zhangyeguang 3 weeks ago
parent
commit
75d8928eef
  1. 5
      src/main/java/com/jiagutech/client/RecognitionModelClient.java
  2. 2
      src/main/java/com/jiagutech/common/exception/BizCode.java
  3. 3
      src/main/java/com/jiagutech/common/exception/BusinessException.java
  4. 2
      src/main/java/com/jiagutech/common/sa/SaPermissionImpl.java
  5. 8
      src/main/java/com/jiagutech/common/sa/SaTokenConfigure.java
  6. 29
      src/main/java/com/jiagutech/controller/RecordController.java
  7. 23
      src/main/java/com/jiagutech/controller/UserController.java
  8. 9
      src/main/java/com/jiagutech/dto/Scale.java
  9. 19
      src/main/java/com/jiagutech/dto/UpdateScaleRequest.java
  10. 15
      src/main/java/com/jiagutech/dto/common/LoginUser.java
  11. 6
      src/main/java/com/jiagutech/dto/common/R.java
  12. 20
      src/main/java/com/jiagutech/dto/mapping/UserMapping.java
  13. 2
      src/main/java/com/jiagutech/dto/request/CreateRecordRequest.java
  14. 2
      src/main/java/com/jiagutech/dto/request/LoginRequest.java
  15. 22
      src/main/java/com/jiagutech/dto/request/RecordUpdateRequest.java
  16. 20
      src/main/java/com/jiagutech/dto/request/UpdateScaleRequest.java
  17. 8
      src/main/java/com/jiagutech/dto/request/UserRequest.java
  18. 6
      src/main/java/com/jiagutech/dto/response/LoginResponse.java
  19. 2
      src/main/java/com/jiagutech/dto/response/ModelPredictData.java
  20. 4
      src/main/java/com/jiagutech/dto/response/ModelPredictResponse.java
  21. 2
      src/main/java/com/jiagutech/dto/response/RecordDetail.java
  22. 2
      src/main/java/com/jiagutech/dto/response/RecordItem.java
  23. 13
      src/main/java/com/jiagutech/dto/response/TaskItem.java
  24. 23
      src/main/java/com/jiagutech/dto/response/UserItem.java
  25. 14
      src/main/java/com/jiagutech/entity/RecordContentEntity.java
  26. 2
      src/main/java/com/jiagutech/entity/RecordEntity.java
  27. 2
      src/main/java/com/jiagutech/entity/UserEntity.java
  28. 2
      src/main/java/com/jiagutech/handler/ModelPredictResponseListTypeHandler.java
  29. 8
      src/main/java/com/jiagutech/mapper/RecordMapper.java
  30. 3
      src/main/java/com/jiagutech/mapper/UserMapper.java
  31. 17
      src/main/java/com/jiagutech/record/RecordTaskHandler.java
  32. 20
      src/main/java/com/jiagutech/record/RecordTaskManager.java
  33. 8
      src/main/java/com/jiagutech/record/RecordTaskProcessor.java
  34. 14
      src/main/java/com/jiagutech/service/RecordService.java
  35. 66
      src/main/java/com/jiagutech/service/RecordServiceImpl.java
  36. 11
      src/main/java/com/jiagutech/service/UserService.java
  37. 21
      src/main/java/com/jiagutech/service/UserServiceImpl.java
  38. 2
      src/main/java/com/jiagutech/utils/LoginUtil.java
  39. 2
      src/main/resources/application.yml
  40. 5
      src/main/resources/mapper/RecordMapper.xml
  41. 5
      src/main/resources/mapper/UserMapper.xml

5
src/main/java/com/jiagutech/client/RecognitionModelClient.java

@ -1,8 +1,7 @@
package com.jiagutech.client;
import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONObject;
import com.jiagutech.dto.ModelPredictResponse;
import com.jiagutech.dto.response.ModelPredictResponse;
import com.jiagutech.dto.RecordModel;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
@ -10,11 +9,9 @@ import org.springframework.beans.factory.annotation.Value;
import org.springframework.core.io.FileSystemResource;
import org.springframework.http.*;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
import org.springframework.web.client.RestTemplate;
import org.springframework.web.multipart.MultipartFile;
import java.io.File;
import java.util.Collections;

2
src/main/java/com/jiagutech/common/exception/BizCode.java

@ -3,7 +3,7 @@ package com.jiagutech.common.exception;
import lombok.Getter;
@Getter
public enum BizCode implements CodeInterface {
public enum BizCode {
General_Success(200, "接口调用成功"),
ServerError(10001, "服务器异常"),
General_Failure(10004, "接口调用失败"),

3
src/main/java/com/jiagutech/common/exception/BusinessException.java

@ -33,12 +33,13 @@ public class BusinessException extends RuntimeException {
this.message = message1;
}
public BusinessException(CodeInterface biz) {
public BusinessException(BizCode biz) {
super();
this.code = biz.getCode();
this.message = biz.getMsg();
}
public BusinessException(String message) {
super(message);
this.code= BizCode.General_ParameterInvalid.getCode();

2
src/main/java/com/jiagutech/common/sa/SaPermissionImpl.java

@ -1,7 +1,7 @@
package com.jiagutech.common.sa;
import cn.dev33.satoken.stp.StpInterface;
import com.jiagutech.dto.LoginUser;
import com.jiagutech.dto.common.LoginUser;
import com.jiagutech.utils.LoginUtil;
import java.util.ArrayList;

8
src/main/java/com/jiagutech/common/sa/SaTokenConfigure.java

@ -16,18 +16,18 @@ public class SaTokenConfigure implements WebMvcConfigurer {
public void addInterceptors(InterceptorRegistry registry) {
// 注册 Sa-Token 拦截器,打开注解式鉴权功能
registry.addInterceptor(new SaInterceptor(handle -> {
String url = SaHolder.getRequest().getRequestPath();
try {
log.info("-------- 前端访问path:" + SaHolder.getRequest().getRequestPath());
log.info("request url :{}:", url);
StpUtil.checkLogin();
log.info("-------- 此 path 校验成功:" + SaHolder.getRequest().getRequestPath());
} catch (Exception e) {
log.info("-------- 此 path 校验失败:" + SaHolder.getRequest().getRequestPath());
log.info("url:{} --- 校验失败:", url);
throw e;
}
}))
.addPathPatterns("/**")
.excludePathPatterns("/user/login", "user/logout",
"/user/register", "/record/export/**", "/favicon.ico","/error",
"/user/register", "/record/export/**", "/favicon.ico", "/error",
"/swagger-ui/**", "/swagger-resources/**", "/v2/api-docs/**", "/doc.html/**", "/webjars/**"
);
}

29
src/main/java/com/jiagutech/controller/RecordController.java

@ -5,6 +5,12 @@ import com.jiagutech.dto.*;
import com.jiagutech.dto.common.PageRequest;
import com.jiagutech.dto.common.PageResult;
import com.jiagutech.dto.common.R;
import com.jiagutech.dto.request.CreateRecordRequest;
import com.jiagutech.dto.request.RecordUpdateRequest;
import com.jiagutech.dto.request.UpdateScaleRequest;
import com.jiagutech.dto.response.RecordDetail;
import com.jiagutech.dto.response.RecordItem;
import com.jiagutech.dto.response.TaskItem;
import com.jiagutech.entity.RecordContentEntity;
import com.jiagutech.service.RecordService;
import io.swagger.annotations.Api;
@ -12,6 +18,7 @@ import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.MediaType;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletResponse;
@ -73,8 +80,28 @@ public class RecordController {
@ApiOperation(value = "比例尺设置")
@PutMapping("/scale")
public void updateScale( @RequestBody UpdateScaleRequest request) {
public void updateScale(@RequestBody UpdateScaleRequest request) {
recordService.updateScale(request);
}
@ApiOperation(value = "删除记录")
@DeleteMapping(value = "/delete/{recordId}")
public R<Void> deleteRecord(Long recordId) {
boolean res = recordService.deleteRecord(recordId);
return res ? R.ok() : R.fail();
}
@ApiOperation(value = "更新记录")
@PutMapping(value = "/update")
public R<Void> updateRecord(@Validated @RequestBody RecordUpdateRequest updateRequest) {
boolean res = recordService.updateRecord(updateRequest);
return res ? R.ok() : R.fail("更新失败或记录不存在");
}
@ApiOperation(value = "获取任务列表")
@GetMapping(value = "/tasks")
public R<List<TaskItem>> getTasks() {
return R.ok(recordService.getTasks());
}
}

23
src/main/java/com/jiagutech/controller/UserController.java

@ -1,11 +1,14 @@
package com.jiagutech.controller;
import cn.dev33.satoken.stp.StpUtil;
import com.jiagutech.dto.LoginRequest;
import com.jiagutech.dto.LoginResponse;
import com.jiagutech.dto.common.LoginUser;
import com.jiagutech.dto.common.R;
import com.jiagutech.dto.UserRequest;
import com.jiagutech.dto.request.LoginRequest;
import com.jiagutech.dto.request.UserRequest;
import com.jiagutech.dto.response.LoginResponse;
import com.jiagutech.dto.response.UserItem;
import com.jiagutech.service.UserService;
import com.jiagutech.utils.LoginUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
@ -13,6 +16,8 @@ import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import java.util.List;
@Api(tags = "用户")
@Slf4j
@RestController
@ -58,4 +63,16 @@ public class UserController {
return R.ok();
}
@ApiOperation(value = "用户信息")
@GetMapping(value = "/userInfo")
public R<LoginUser> getUserInfo() {
return R.ok(LoginUtil.getLoginUser());
}
@ApiOperation(value = "待审核用户列表")
@GetMapping(value = "/userList")
public R<List<UserItem>> approvalUserList() {
return R.ok(userService.approvalUserList());
}
}

9
src/main/java/com/jiagutech/dto/Scale.java

@ -1,10 +1,19 @@
package com.jiagutech.dto;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import javax.validation.constraints.Size;
@Data
@ApiModel(description = "缩放比例")
public class Scale {
@ApiModelProperty(value = "缩放比例", required = true)
private int scale;
@ApiModelProperty(value = "实际大小", required = true)
private float size;
@ApiModelProperty(value = "坐标", required = true)
@Size(min = 2, max = 2, message = "坐标必须是2个")
private int[][] points;
}

19
src/main/java/com/jiagutech/dto/UpdateScaleRequest.java

@ -1,19 +0,0 @@
package com.jiagutech.dto;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
@Data
@ApiModel("更新比例尺")
public class UpdateScaleRequest {
@ApiModelProperty("记录id")
private long recordId;
@ApiModelProperty("记录内容id")
private long recordContentId;
@ApiModelProperty("比例尺类型,1=统一、2=自用、3=延用")
private int scaleType;
@ApiModelProperty("比例尺")
private Scale scale;
}

15
src/main/java/com/jiagutech/dto/LoginUser.java → src/main/java/com/jiagutech/dto/common/LoginUser.java

@ -1,14 +1,15 @@
package com.jiagutech.dto;
package com.jiagutech.dto.common;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.io.Serializable;
import java.time.LocalDateTime;
import java.util.List;
/**
* @ClassName LoginUser
@ -19,6 +20,7 @@ import java.util.List;
**/
@Data
@NoArgsConstructor
@ApiModel("登陆用户")
public class LoginUser implements Serializable {
private static final long serialVersionUID = 1L;
@ -33,6 +35,7 @@ public class LoginUser implements Serializable {
/**
* 部门
*/
@ApiModelProperty("部门")
private String unitName;
/**
@ -44,6 +47,7 @@ public class LoginUser implements Serializable {
/**
* 登录时间
*/
@ApiModelProperty("登录时间")
private Long loginTime;
/**
@ -60,15 +64,18 @@ public class LoginUser implements Serializable {
/**
* 用户名
*/
@ApiModelProperty("用户名")
private String username;
/**
* 用户昵称
* 用户姓名
*/
@ApiModelProperty("用户姓名")
private String realName;
/**
* 手机号
*/
@ApiModelProperty("手机号")
private String phone;
@JsonIgnore
private String password;
@ -83,4 +90,6 @@ public class LoginUser implements Serializable {
private Integer status;
private int role;
}

6
src/main/java/com/jiagutech/dto/common/R.java

@ -1,10 +1,10 @@
package com.jiagutech.dto.common;
import com.jiagutech.common.HttpStatus;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.io.Serializable;
/**
@ -31,7 +31,7 @@ public class R<T> implements Serializable {
private int code;
private String msg;
private String description;
private T data;
@ -96,7 +96,7 @@ public class R<T> implements Serializable {
R<T> r = new R<>();
r.setCode(code);
r.setData(data);
r.setMsg(msg);
r.setDescription(msg);
return r;
}

20
src/main/java/com/jiagutech/dto/mapping/UserMapping.java

@ -0,0 +1,20 @@
package com.jiagutech.dto.mapping;
import com.jiagutech.dto.response.UserItem;
import com.jiagutech.entity.UserEntity;
import org.mapstruct.Mapper;
import org.mapstruct.factory.Mappers;
import java.util.List;
@Mapper
public interface UserMapping {
UserMapping INSTANCE = Mappers.getMapper(UserMapping.class);
UserItem convertToUserItem(UserEntity userEntity);
List<UserItem> convertToUserItems(List<UserEntity> userEntities);
}

2
src/main/java/com/jiagutech/dto/CreateRecordRequest.java → src/main/java/com/jiagutech/dto/request/CreateRecordRequest.java

@ -1,4 +1,4 @@
package com.jiagutech.dto;
package com.jiagutech.dto.request;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;

2
src/main/java/com/jiagutech/dto/LoginRequest.java → src/main/java/com/jiagutech/dto/request/LoginRequest.java

@ -1,4 +1,4 @@
package com.jiagutech.dto;
package com.jiagutech.dto.request;
import com.jiagutech.common.UserConstants;

22
src/main/java/com/jiagutech/dto/request/RecordUpdateRequest.java

@ -0,0 +1,22 @@
package com.jiagutech.dto.request;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.hibernate.validator.constraints.Length;
import javax.validation.constraints.NotNull;
@Data
@ApiModel(value = "记录更新请求", description = "记录更新请求")
public class RecordUpdateRequest {
@NotNull
@ApiModelProperty(value = "记录ID", required = true)
private Long recordId;
@NotNull
@Length(min = 2, max = 100, message = "记录名称长度在2-100个字符之间")
@ApiModelProperty(value = "记录名称", required = true)
private String recordName;
}

20
src/main/java/com/jiagutech/dto/request/UpdateScaleRequest.java

@ -0,0 +1,20 @@
package com.jiagutech.dto.request;
import com.jiagutech.dto.Scale;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
@Data
@ApiModel("更新比例尺")
public class UpdateScaleRequest {
@ApiModelProperty(value = "记录id", required = true)
private long recordId;
@ApiModelProperty(value = "记录内容id", required = true)
private long recordContentId;
@ApiModelProperty(value = "比例尺类型,1=统一、2=自用、3=延用", required = true)
private int scaleType;
@ApiModelProperty(value = "比例尺")
private Scale scale;
}

8
src/main/java/com/jiagutech/dto/UserRequest.java → src/main/java/com/jiagutech/dto/request/UserRequest.java

@ -1,11 +1,12 @@
package com.jiagutech.dto;
package com.jiagutech.dto.request;
import com.jiagutech.common.UserConstants;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.hibernate.validator.constraints.Length;
import javax.validation.constraints.Pattern;
import javax.validation.constraints.Size;
/**
* @ClassName UserRequest
@ -21,7 +22,7 @@ public class UserRequest {
/**
* 用户昵称
*/
@Size(min = 2, max = 30, message = "用户姓名长度不能超过{max}个字符")
@Length(min = UserConstants.USERNAME_MIN_LENGTH, max = UserConstants.USERNAME_MAX_LENGTH, message = "姓名长度必须在2-20个字之间")
private String realName;
/**
@ -34,6 +35,7 @@ public class UserRequest {
/**
* 密码
*/
@Length(min = UserConstants.PASSWORD_MIN_LENGTH, max = UserConstants.PASSWORD_MAX_LENGTH, message = "密码长度必须在5-20位之间")
private String password;

6
src/main/java/com/jiagutech/dto/LoginResponse.java → src/main/java/com/jiagutech/dto/response/LoginResponse.java

@ -1,4 +1,4 @@
package com.jiagutech.dto;
package com.jiagutech.dto.response;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Data;
@ -12,13 +12,13 @@ public class LoginResponse {
/**
* 授权令牌
*/
@JsonProperty("access_token")
@JsonProperty("accessToken")
private String accessToken;
/**
* 刷新令牌
*/
@JsonProperty("refresh_token")
@JsonProperty("refreshToken")
private String refreshToken;
/**

2
src/main/java/com/jiagutech/dto/ModelPredictData.java → src/main/java/com/jiagutech/dto/response/ModelPredictData.java

@ -1,4 +1,4 @@
package com.jiagutech.dto;
package com.jiagutech.dto.response;
import lombok.Data;

4
src/main/java/com/jiagutech/dto/ModelPredictResponse.java → src/main/java/com/jiagutech/dto/response/ModelPredictResponse.java

@ -1,9 +1,7 @@
package com.jiagutech.dto;
package com.jiagutech.dto.response;
import lombok.Data;
import java.util.List;
@Data
public class ModelPredictResponse {
private Integer classify;

2
src/main/java/com/jiagutech/dto/RecordDetail.java → src/main/java/com/jiagutech/dto/response/RecordDetail.java

@ -1,4 +1,4 @@
package com.jiagutech.dto;
package com.jiagutech.dto.response;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.jiagutech.entity.RecordContentEntity;

2
src/main/java/com/jiagutech/dto/RecordItem.java → src/main/java/com/jiagutech/dto/response/RecordItem.java

@ -1,4 +1,4 @@
package com.jiagutech.dto;
package com.jiagutech.dto.response;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Data;

13
src/main/java/com/jiagutech/dto/response/TaskItem.java

@ -0,0 +1,13 @@
package com.jiagutech.dto.response;
import lombok.Data;
@Data
public class TaskItem {
private String taskId;
private String taskName;
private Float progress;
}

23
src/main/java/com/jiagutech/dto/response/UserItem.java

@ -0,0 +1,23 @@
package com.jiagutech.dto.response;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Data;
import java.time.LocalDateTime;
@Data
public class UserItem {
private Long id;
private String phone;
private String realName;
private String unitName;
private int status;
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
private LocalDateTime createTime;
}

14
src/main/java/com/jiagutech/entity/RecordContentEntity.java

@ -5,7 +5,7 @@ import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.baomidou.mybatisplus.extension.handlers.JacksonTypeHandler;
import com.jiagutech.dto.ModelPredictResponse;
import com.jiagutech.dto.response.ModelPredictResponse;
import com.jiagutech.dto.Scale;
import lombok.Data;
import lombok.experimental.Accessors;
@ -27,18 +27,18 @@ public class RecordContentEntity {
@TableField(typeHandler = JacksonTypeHandler.class)
private List<ModelPredictResponse> recognitionData;
private int siliquaNum;
private Integer siliquaNum;
private int handleNum;
private Integer handleNum;
private int beakNum;
private Integer beakNum;
//比例尺类型 ,1=统一/2=自用/3=延用/0=无
private int scaleType;
private Integer scaleType;
//比例
@TableField(typeHandler = JacksonTypeHandler.class)
private Scale scale;
private float conf;
private Float conf;
private float iou;
private Float iou;
}

2
src/main/java/com/jiagutech/entity/RecordEntity.java

@ -20,7 +20,7 @@ public class RecordEntity {
private Long userId;
private int imageNum;
private Integer imageNum;
private LocalDateTime createTime;

2
src/main/java/com/jiagutech/entity/UserEntity.java

@ -24,5 +24,7 @@ public class UserEntity {
private int status;
private int role;
}

2
src/main/java/com/jiagutech/handler/ModelPredictResponseListTypeHandler.java

@ -2,7 +2,7 @@ package com.jiagutech.handler;
import com.baomidou.mybatisplus.extension.handlers.JacksonTypeHandler;
import com.fasterxml.jackson.core.type.TypeReference;
import com.jiagutech.dto.ModelPredictResponse;
import com.jiagutech.dto.response.ModelPredictResponse;
import com.fasterxml.jackson.databind.ObjectMapper;
import java.sql.ResultSet;

8
src/main/java/com/jiagutech/mapper/RecordMapper.java

@ -1,14 +1,16 @@
package com.jiagutech.mapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.jiagutech.dto.RecordDetail;
import com.jiagutech.dto.RecordItem;
import com.jiagutech.dto.response.RecordDetail;
import com.jiagutech.dto.response.RecordItem;
import com.jiagutech.entity.RecordEntity;
import org.apache.ibatis.annotations.Param;
public interface RecordMapper extends BaseMapper<RecordEntity> {
RecordDetail getRecordDetail(long id);
Page<RecordItem> pageList(Page<RecordItem> page, Object o);
Page<RecordItem> pageList(Page<RecordItem> page, @Param("ew") QueryWrapper<RecordItem> queryWrapper);
}

3
src/main/java/com/jiagutech/mapper/UserMapper.java

@ -1,8 +1,7 @@
package com.jiagutech.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.jiagutech.dto.LoginUser;
import com.jiagutech.entity.RecordContentEntity;
import com.jiagutech.dto.common.LoginUser;
import com.jiagutech.entity.UserEntity;
public interface UserMapper extends BaseMapper<UserEntity> {

17
src/main/java/com/jiagutech/record/RecordTaskHandler.java

@ -1,8 +1,9 @@
package com.jiagutech.record;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.jiagutech.common.thread.MonitoredRunnable;
import com.jiagutech.dto.CreateRecordRequest;
import com.jiagutech.dto.LoginUser;
import com.jiagutech.dto.request.CreateRecordRequest;
import com.jiagutech.dto.common.LoginUser;
import com.jiagutech.utils.LoginUtil;
import lombok.Data;
import lombok.SneakyThrows;
@ -23,11 +24,13 @@ public class RecordTaskHandler {
private ThreadPoolExecutor theadPoolExecutor;
private RecordTaskProcessor processor;
private final String tmpPath;
public RecordTaskHandler(ThreadPoolExecutor threadPoolExecutor, RecordTaskProcessor processor) {
public RecordTaskHandler(ThreadPoolExecutor threadPoolExecutor, RecordTaskProcessor processor, String tmpPath) {
this.theadPoolExecutor = threadPoolExecutor;
this.processor = processor;
this.tmpPath = tmpPath;
}
protected void processTask() {
@ -52,9 +55,15 @@ public class RecordTaskHandler {
@SneakyThrows
public void createTask(CreateRecordRequest request, String taskId) {
log.info("用户【{}】创建识别任务,任务ID:{},", LoginUtil.getLoginUser().getRealName(), taskId);
URL resource = RecordTaskHandler.class.getClassLoader().getResource("");
assert resource != null;
String path = resource.getPath();
String path;
if (StringUtils.isEmpty(tmpPath)) {
path = resource.getPath();
} else {
path = tmpPath;
}
File[] files = new File[request.getFiles().length];
for (int i = 0; i < request.getFiles().length; i++) {
MultipartFile file = request.getFiles()[i];

20
src/main/java/com/jiagutech/record/RecordTaskManager.java

@ -1,5 +1,10 @@
package com.jiagutech.record;
import com.jiagutech.dto.response.TaskItem;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.concurrent.ConcurrentHashMap;
public class RecordTaskManager {
@ -18,4 +23,19 @@ public class RecordTaskManager {
recordTasks.remove(taskId);
}
public static List<TaskItem> getTasks(Long userId) {
List<TaskItem> taskItems = new ArrayList<>();
for (RecordTaskHandler recordTaskHandler : recordTasks.values()) {
RecordTaskHandler.RecordTask recordTask = recordTaskHandler.getRecordTask();
if (recordTask != null && recordTask.getProgress() < 100 && Objects.equals(recordTask.getLoginUser().getUserId(), userId)) {
TaskItem taskItem = new TaskItem();
taskItem.setTaskId(recordTask.getTaskId());
taskItem.setProgress(recordTask.getProgress());
taskItem.setTaskName(recordTask.getTaskName());
taskItems.add(taskItem);
}
}
return taskItems;
}
}

8
src/main/java/com/jiagutech/record/RecordTaskProcessor.java

@ -1,7 +1,7 @@
package com.jiagutech.record;
import com.jiagutech.client.RecognitionModelClient;
import com.jiagutech.dto.ModelPredictResponse;
import com.jiagutech.dto.response.ModelPredictResponse;
import com.jiagutech.entity.RecordContentEntity;
import com.jiagutech.entity.RecordEntity;
import com.jiagutech.mapper.RecordContentMapper;
@ -44,6 +44,7 @@ public class RecordTaskProcessor {
recordMapper.insert(recordEntity);
recordTask.setProgress(progress);
for (File file : recordTask.getFiles()) {
log.info("调用模型进行分析,file:{}", file.getName());
List<ModelPredictResponse> predict = modelClient.predict(file, recordTask.getModelName(), recordTask.getIou(), recordTask.getConf());
int handleNum = 0;
int rapeNum = 0;
@ -66,7 +67,9 @@ public class RecordTaskProcessor {
if (!CollectionUtils.isEmpty(predict)) {
String imageUrl;
try {
imageUrl = huaweiObs.uploadFile(file);
log.info("存储图片到oss,file:{}", file.getName());
// imageUrl = huaweiObs.uploadFile(file);
imageUrl = "";
progress += 2f;
} catch (Exception e) {
throw new RuntimeException(e);
@ -83,6 +86,7 @@ public class RecordTaskProcessor {
.setBeakNum(beakNum)
.setSiliquaNum(rapeNum);
recordContentMapper.insert(recordContentEntity);
log.info("保存处理结果,file:{}", file.getName());
progress += 3f;
}

14
src/main/java/com/jiagutech/service/RecordService.java

@ -3,11 +3,18 @@ package com.jiagutech.service;
import com.jiagutech.dto.*;
import com.jiagutech.dto.common.PageRequest;
import com.jiagutech.dto.common.PageResult;
import com.jiagutech.dto.request.CreateRecordRequest;
import com.jiagutech.dto.request.RecordUpdateRequest;
import com.jiagutech.dto.request.UpdateScaleRequest;
import com.jiagutech.dto.response.RecordDetail;
import com.jiagutech.dto.response.RecordItem;
import com.jiagutech.dto.response.TaskItem;
import com.jiagutech.entity.RecordContentEntity;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.servlet.mvc.method.annotation.SseEmitter;
import javax.servlet.http.HttpServletResponse;
import java.util.List;
public interface RecordService {
@ -28,4 +35,11 @@ public interface RecordService {
RecordModel getModels();
void updateScale(UpdateScaleRequest request);
boolean deleteRecord(Long recordId);
boolean updateRecord(RecordUpdateRequest updateRequest);
List<TaskItem> getTasks();
}

66
src/main/java/com/jiagutech/service/RecordServiceImpl.java

@ -1,5 +1,6 @@
package com.jiagutech.service;
import cn.dev33.satoken.stp.StpUtil;
import com.alibaba.excel.EasyExcel;
import com.alibaba.excel.ExcelWriter;
import com.alibaba.excel.util.MapUtils;
@ -10,43 +11,48 @@ import com.alibaba.excel.write.metadata.style.WriteCellStyle;
import com.alibaba.excel.write.style.HorizontalCellStyleStrategy;
import com.alibaba.excel.write.style.column.LongestMatchColumnWidthStyleStrategy;
import com.alibaba.fastjson2.JSON;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.jiagutech.client.RecognitionModelClient;
import com.jiagutech.dto.*;
import com.jiagutech.dto.common.LoginUser;
import com.jiagutech.dto.common.PageRequest;
import com.jiagutech.dto.common.PageResult;
import com.jiagutech.dto.request.CreateRecordRequest;
import com.jiagutech.dto.request.RecordUpdateRequest;
import com.jiagutech.dto.request.UpdateScaleRequest;
import com.jiagutech.dto.response.ModelPredictResponse;
import com.jiagutech.dto.response.RecordDetail;
import com.jiagutech.dto.response.RecordItem;
import com.jiagutech.dto.response.TaskItem;
import com.jiagutech.entity.RecordContentEntity;
import com.jiagutech.handler.ExcelFillCellMergeStrategy;
import com.jiagutech.entity.RecordEntity;
import com.jiagutech.mapper.RecordContentMapper;
import com.jiagutech.mapper.RecordMapper;
import com.jiagutech.record.RecordTaskHandler;
import com.jiagutech.record.RecordTaskManager;
import com.jiagutech.record.RecordTaskProcessor;
import com.sun.xml.bind.v2.TODO;
import com.jiagutech.utils.LoginUtil;
import lombok.RequiredArgsConstructor;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.math3.analysis.function.Max;
import org.apache.poi.ss.usermodel.HorizontalAlignment;
import org.apache.poi.ss.usermodel.VerticalAlignment;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.validation.BindException;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.servlet.mvc.method.annotation.SseEmitter;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.net.URLEncoder;
import java.text.DecimalFormat;
import java.time.LocalDateTime;
import java.util.*;
import java.util.concurrent.ThreadPoolExecutor;
@ -62,6 +68,9 @@ public class RecordServiceImpl implements RecordService {
private final RecordContentMapper recordContentMapper;
private final RecognitionModelClient recognitionModelClient;
@Value("${tmp.path}")
private String tmpPath;
@Override
public SseEmitter createRecord(MultipartFile[] files, String modelName, Float lou, Float conf) {
return null;
@ -70,7 +79,7 @@ public class RecordServiceImpl implements RecordService {
@Override
public String createRecordAsync(CreateRecordRequest request) {
String taskId = UUID.randomUUID().toString();
RecordTaskHandler recordTaskHandler = new RecordTaskHandler(customThreadPool, taskProcessor);
RecordTaskHandler recordTaskHandler = new RecordTaskHandler(customThreadPool, taskProcessor, tmpPath);
recordTaskHandler.createTask(request, taskId);
RecordTaskManager.addRecordTask(taskId, recordTaskHandler);
return taskId;
@ -272,7 +281,12 @@ public class RecordServiceImpl implements RecordService {
@Override
public PageResult<RecordItem> getPages(PageRequest pageRequest) {
Page<RecordItem> page = new Page(pageRequest.getPageNum(), pageRequest.getPageSize());
Page<RecordItem> result = recordMapper.pageList(page, null);
LoginUser loginUser = LoginUtil.getLoginUser();
QueryWrapper<RecordItem> queryWrapper = Wrappers.query();
if (loginUser.getRole() == 1) {
queryWrapper.eq("r.user_id", loginUser.getUserId());
}
Page<RecordItem> result = recordMapper.pageList(page, queryWrapper);
return PageResult.of((int) result.getTotal(), (int) result.getSize(), (int) result.getCurrent(), result.getRecords());
}
@ -332,4 +346,38 @@ public class RecordServiceImpl implements RecordService {
}
}
@Transactional
@Override
public boolean deleteRecord(Long recordId) {
int row = recordMapper.deleteById(recordId);
QueryWrapper<RecordContentEntity> queryWrapper = Wrappers.query();
queryWrapper.eq("record_id", recordId);
recordContentMapper.delete(queryWrapper);
return row > 0;
}
@Transactional
@Override
public boolean updateRecord(RecordUpdateRequest updateRequest) {
RecordEntity recordEntity = new RecordEntity();
recordEntity.setId(updateRequest.getRecordId());
recordEntity.setName(updateRequest.getRecordName());
recordEntity.setUpdateTime(LocalDateTime.now());
return recordMapper.updateById(recordEntity) > 0;
}
@Override
public List<TaskItem> getTasks() {
try {
return RecordTaskManager.getTasks(StpUtil.getLoginIdAsLong());
} catch (Exception e) {
log.error("获取任务失败", e);
}
return Collections.emptyList();
}
}

11
src/main/java/com/jiagutech/service/UserService.java

@ -1,8 +1,11 @@
package com.jiagutech.service;
import com.jiagutech.dto.LoginRequest;
import com.jiagutech.dto.LoginResponse;
import com.jiagutech.dto.UserRequest;
import com.jiagutech.dto.request.LoginRequest;
import com.jiagutech.dto.response.LoginResponse;
import com.jiagutech.dto.response.UserItem;
import com.jiagutech.dto.request.UserRequest;
import java.util.List;
public interface UserService {
LoginResponse login(LoginRequest loginBody);
@ -10,4 +13,6 @@ public interface UserService {
void register(UserRequest user);
void approval(Long userId);
List<UserItem> approvalUserList();
}

21
src/main/java/com/jiagutech/service/UserServiceImpl.java

@ -2,13 +2,17 @@ package com.jiagutech.service;
import cn.dev33.satoken.secure.BCrypt;
import cn.dev33.satoken.stp.StpUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.jiagutech.common.UserConstants;
import com.jiagutech.common.exception.BizCode;
import com.jiagutech.common.exception.BusinessException;
import com.jiagutech.dto.LoginRequest;
import com.jiagutech.dto.LoginResponse;
import com.jiagutech.dto.LoginUser;
import com.jiagutech.dto.UserRequest;
import com.jiagutech.dto.common.LoginUser;
import com.jiagutech.dto.mapping.UserMapping;
import com.jiagutech.dto.request.LoginRequest;
import com.jiagutech.dto.request.UserRequest;
import com.jiagutech.dto.response.LoginResponse;
import com.jiagutech.dto.response.UserItem;
import com.jiagutech.entity.UserEntity;
import com.jiagutech.mapper.UserMapper;
import com.jiagutech.utils.EmailUtil;
@ -16,6 +20,7 @@ import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import java.time.LocalDateTime;
import java.util.List;
@Service
@RequiredArgsConstructor
@ -68,4 +73,12 @@ public class UserServiceImpl implements UserService {
userEntity.setStatus(1);
userMapper.updateById(userEntity);
}
@Override
public List<UserItem> approvalUserList() {
QueryWrapper<UserEntity> wrapper = Wrappers.query();
wrapper.eq("status", 2);
List<UserEntity> userEntities = userMapper.selectList(wrapper);
return UserMapping.INSTANCE.convertToUserItems(userEntities);
}
}

2
src/main/java/com/jiagutech/utils/LoginUtil.java

@ -2,7 +2,7 @@ package com.jiagutech.utils;
import cn.dev33.satoken.stp.StpUtil;
import com.jiagutech.common.UserConstants;
import com.jiagutech.dto.LoginUser;
import com.jiagutech.dto.common.LoginUser;
public class LoginUtil {

2
src/main/resources/application.yml

@ -102,3 +102,5 @@ logging:
level:
com.jiagutech.mapper: debug
root: info
tmp:
path: /tmp/

5
src/main/resources/mapper/RecordMapper.xml

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.jiagutech.mapper.RecordMapper">
<resultMap id="RecordDetailMap" type="com.jiagutech.dto.RecordDetail">
<resultMap id="RecordDetailMap" type="com.jiagutech.dto.response.RecordDetail">
<id property="id" column="id"/>
<collection property="content" javaType="java.util.List" column="id"
select="com.jiagutech.mapper.RecordContentMapper.selectListByRecordId"/>
@ -13,7 +13,7 @@
from record_info
where id = #{id}
</select>
<select id="pageList" resultType="com.jiagutech.dto.RecordItem">
<select id="pageList" resultType="com.jiagutech.dto.response.RecordItem">
select r.id as recordId,
r.name as recordName,
r.user_id,
@ -24,6 +24,7 @@
u.phone
from record_info r
left join siliqua_user u on r.user_id = u.id
${ew.getCustomSqlSegment}
order by r.create_time desc
</select>

5
src/main/resources/mapper/UserMapper.xml

@ -3,14 +3,15 @@
<mapper namespace="com.jiagutech.mapper.UserMapper">
<select id="selectLoginUserByPhone" resultType="com.jiagutech.dto.LoginUser">
<select id="selectLoginUserByPhone" resultType="com.jiagutech.dto.common.LoginUser">
select id as user_id,
real_name,
phone,
create_time,
password,
unit_name,
status
status,
role
from siliqua_user
where phone = #{phone}
and status != 0

Loading…
Cancel
Save