|
@ -1,5 +1,6 @@ |
|
|
package com.jiagutech.service; |
|
|
package com.jiagutech.service; |
|
|
|
|
|
|
|
|
|
|
|
import cn.dev33.satoken.stp.StpUtil; |
|
|
import com.alibaba.excel.EasyExcel; |
|
|
import com.alibaba.excel.EasyExcel; |
|
|
import com.alibaba.excel.ExcelWriter; |
|
|
import com.alibaba.excel.ExcelWriter; |
|
|
import com.alibaba.excel.util.MapUtils; |
|
|
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.HorizontalCellStyleStrategy; |
|
|
import com.alibaba.excel.write.style.column.LongestMatchColumnWidthStyleStrategy; |
|
|
import com.alibaba.excel.write.style.column.LongestMatchColumnWidthStyleStrategy; |
|
|
import com.alibaba.fastjson2.JSON; |
|
|
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.conditions.query.QueryWrapper; |
|
|
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils; |
|
|
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils; |
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
|
|
import com.jiagutech.client.RecognitionModelClient; |
|
|
import com.jiagutech.client.RecognitionModelClient; |
|
|
import com.jiagutech.dto.*; |
|
|
import com.jiagutech.dto.*; |
|
|
|
|
|
import com.jiagutech.dto.common.LoginUser; |
|
|
import com.jiagutech.dto.common.PageRequest; |
|
|
import com.jiagutech.dto.common.PageRequest; |
|
|
import com.jiagutech.dto.common.PageResult; |
|
|
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.entity.RecordContentEntity; |
|
|
import com.jiagutech.handler.ExcelFillCellMergeStrategy; |
|
|
|
|
|
|
|
|
import com.jiagutech.entity.RecordEntity; |
|
|
import com.jiagutech.mapper.RecordContentMapper; |
|
|
import com.jiagutech.mapper.RecordContentMapper; |
|
|
import com.jiagutech.mapper.RecordMapper; |
|
|
import com.jiagutech.mapper.RecordMapper; |
|
|
import com.jiagutech.record.RecordTaskHandler; |
|
|
import com.jiagutech.record.RecordTaskHandler; |
|
|
import com.jiagutech.record.RecordTaskManager; |
|
|
import com.jiagutech.record.RecordTaskManager; |
|
|
import com.jiagutech.record.RecordTaskProcessor; |
|
|
import com.jiagutech.record.RecordTaskProcessor; |
|
|
import com.sun.xml.bind.v2.TODO; |
|
|
|
|
|
|
|
|
import com.jiagutech.utils.LoginUtil; |
|
|
import lombok.RequiredArgsConstructor; |
|
|
import lombok.RequiredArgsConstructor; |
|
|
import lombok.SneakyThrows; |
|
|
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
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.HorizontalAlignment; |
|
|
import org.apache.poi.ss.usermodel.VerticalAlignment; |
|
|
import org.apache.poi.ss.usermodel.VerticalAlignment; |
|
|
|
|
|
import org.springframework.beans.factory.annotation.Value; |
|
|
import org.springframework.stereotype.Service; |
|
|
import org.springframework.stereotype.Service; |
|
|
import org.springframework.transaction.annotation.Transactional; |
|
|
import org.springframework.transaction.annotation.Transactional; |
|
|
import org.springframework.validation.BindException; |
|
|
|
|
|
import org.springframework.web.multipart.MultipartFile; |
|
|
import org.springframework.web.multipart.MultipartFile; |
|
|
import org.springframework.web.servlet.mvc.method.annotation.SseEmitter; |
|
|
import org.springframework.web.servlet.mvc.method.annotation.SseEmitter; |
|
|
|
|
|
|
|
|
import javax.servlet.ServletOutputStream; |
|
|
import javax.servlet.ServletOutputStream; |
|
|
import javax.servlet.http.HttpServletResponse; |
|
|
import javax.servlet.http.HttpServletResponse; |
|
|
import java.io.IOException; |
|
|
import java.io.IOException; |
|
|
import java.io.UnsupportedEncodingException; |
|
|
|
|
|
import java.math.BigDecimal; |
|
|
import java.math.BigDecimal; |
|
|
import java.math.RoundingMode; |
|
|
import java.math.RoundingMode; |
|
|
import java.net.URLEncoder; |
|
|
import java.net.URLEncoder; |
|
|
import java.text.DecimalFormat; |
|
|
import java.text.DecimalFormat; |
|
|
|
|
|
import java.time.LocalDateTime; |
|
|
import java.util.*; |
|
|
import java.util.*; |
|
|
import java.util.concurrent.ThreadPoolExecutor; |
|
|
import java.util.concurrent.ThreadPoolExecutor; |
|
|
|
|
|
|
|
@ -62,6 +68,9 @@ public class RecordServiceImpl implements RecordService { |
|
|
private final RecordContentMapper recordContentMapper; |
|
|
private final RecordContentMapper recordContentMapper; |
|
|
private final RecognitionModelClient recognitionModelClient; |
|
|
private final RecognitionModelClient recognitionModelClient; |
|
|
|
|
|
|
|
|
|
|
|
@Value("${tmp.path}") |
|
|
|
|
|
private String tmpPath; |
|
|
|
|
|
|
|
|
@Override |
|
|
@Override |
|
|
public SseEmitter createRecord(MultipartFile[] files, String modelName, Float lou, Float conf) { |
|
|
public SseEmitter createRecord(MultipartFile[] files, String modelName, Float lou, Float conf) { |
|
|
return null; |
|
|
return null; |
|
@ -70,7 +79,7 @@ public class RecordServiceImpl implements RecordService { |
|
|
@Override |
|
|
@Override |
|
|
public String createRecordAsync(CreateRecordRequest request) { |
|
|
public String createRecordAsync(CreateRecordRequest request) { |
|
|
String taskId = UUID.randomUUID().toString(); |
|
|
String taskId = UUID.randomUUID().toString(); |
|
|
RecordTaskHandler recordTaskHandler = new RecordTaskHandler(customThreadPool, taskProcessor); |
|
|
|
|
|
|
|
|
RecordTaskHandler recordTaskHandler = new RecordTaskHandler(customThreadPool, taskProcessor, tmpPath); |
|
|
recordTaskHandler.createTask(request, taskId); |
|
|
recordTaskHandler.createTask(request, taskId); |
|
|
RecordTaskManager.addRecordTask(taskId, recordTaskHandler); |
|
|
RecordTaskManager.addRecordTask(taskId, recordTaskHandler); |
|
|
return taskId; |
|
|
return taskId; |
|
@ -272,7 +281,12 @@ public class RecordServiceImpl implements RecordService { |
|
|
@Override |
|
|
@Override |
|
|
public PageResult<RecordItem> getPages(PageRequest pageRequest) { |
|
|
public PageResult<RecordItem> getPages(PageRequest pageRequest) { |
|
|
Page<RecordItem> page = new Page(pageRequest.getPageNum(), pageRequest.getPageSize()); |
|
|
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()); |
|
|
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(); |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|