fix: 优化过鱼逻辑
This commit is contained in:
parent
5f04dae69c
commit
b8d401f662
@ -30,6 +30,7 @@ import jakarta.annotation.Resource;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.util.StringUtils;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
@ -112,16 +113,57 @@ public class FishDraftDataController {
|
||||
return result ? ResponseResult.success("保存成功") : ResponseResult.error("保存失败");
|
||||
}
|
||||
|
||||
// @PostMapping("/batchSaveDraft")
|
||||
// @Operation(summary = "批量保存草稿")
|
||||
// public ResponseResult saveDraft(@RequestBody List<FishDraftData> fishDraftDataList) {
|
||||
//
|
||||
// fishDraftDataList.forEach(fishDraftData -> {
|
||||
// fishDraftData.setStatus("DRAFT");
|
||||
// fishDraftData.setDeletedFlag(0);
|
||||
// fishDraftData.setLockFlag(0);
|
||||
// });
|
||||
// boolean result = fishDraftDataService.saveBatch(fishDraftDataList);
|
||||
// return result ? ResponseResult.success("保存成功") : ResponseResult.error("保存失败");
|
||||
// }
|
||||
|
||||
@PostMapping("/batchSaveDraft")
|
||||
@Operation(summary = "批量保存草稿")
|
||||
public ResponseResult saveDraft(@RequestBody List<FishDraftData> fishDraftDataList) {
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public ResponseResult saveDraft(@RequestBody FishImportRowRequest request) {
|
||||
String taskId = request.getTaskId();
|
||||
ImportTask importTask = importTaskService.getById(taskId);
|
||||
String resultJson = importTask.getResultJson();
|
||||
FishImportResult importResult = null;
|
||||
if (resultJson != null && !resultJson.isEmpty()) {
|
||||
try {
|
||||
importResult = objectMapper.readValue(resultJson, FishImportResult.class);
|
||||
ZipFileUtil.ZipContent content = new ZipFileUtil.ZipContent();
|
||||
content.images = importResult.getImageFiles();
|
||||
content.videos = importResult.getVideoFiles();
|
||||
fishImportService.processAttachments(importResult, content);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
// ignore parse error
|
||||
}
|
||||
}
|
||||
|
||||
fishDraftDataList.forEach(fishDraftData -> {
|
||||
fishDraftData.setStatus("DRAFT");
|
||||
fishDraftData.setDeletedFlag(0);
|
||||
fishDraftData.setLockFlag(0);
|
||||
});
|
||||
if (importResult == null || importResult.getRows() == null) {
|
||||
return ResponseResult.error("导入数据不存在");
|
||||
}
|
||||
Date date = new Date();
|
||||
List<FishDraftData> fishDraftDataList = new ArrayList<>();
|
||||
for (FishImportResult.FishImportRow row : importResult.getRows()) {
|
||||
FishDraftData data = row.getData();
|
||||
data.setRowIndex(row.getRowIndex());
|
||||
data.setStatus("DRAFT");
|
||||
data.setEnddt(data.getStrdt());
|
||||
data.setDeletedFlag(0);
|
||||
data.setLockFlag(0);
|
||||
data.setTm(date);
|
||||
fishDraftDataList.add(data);
|
||||
}
|
||||
boolean result = fishDraftDataService.saveBatch(fishDraftDataList);
|
||||
importTaskService.markSuccess(taskId);
|
||||
return result ? ResponseResult.success("保存成功") : ResponseResult.error("保存失败");
|
||||
}
|
||||
|
||||
@ -204,7 +246,7 @@ public class FishDraftDataController {
|
||||
@PostMapping("/submitDraftsAll")
|
||||
@Operation(summary = "批量提交当前用户全部草稿")
|
||||
public ResponseResult submitDraftsAll() {
|
||||
List<FishDraftData> draft = fishDraftDataService.list(new LambdaQueryWrapper<FishDraftData>().eq(FishDraftData::getDeletedFlag, 0).eq(FishDraftData::getCreatedBy, SecurityUtils.getUserId()).in(FishDraftData::getStatus,"REJECTED", "DRAFT").select(FishDraftData::getId));
|
||||
List<FishDraftData> draft = fishDraftDataService.list(new LambdaQueryWrapper<FishDraftData>().eq(FishDraftData::getDeletedFlag, 0).eq(FishDraftData::getCreatedBy, SecurityUtils.getUserId()).in(FishDraftData::getStatus, "REJECTED", "DRAFT").select(FishDraftData::getId));
|
||||
List<String> ids = draft.stream().map(FishDraftData::getId).toList();
|
||||
boolean result = fishDraftDataService.submitDrafts(ids);
|
||||
return result ? ResponseResult.success("提交成功") : ResponseResult.error("提交失败");
|
||||
@ -482,6 +524,7 @@ public class FishDraftDataController {
|
||||
writeErrorResponse(response, "预览失败: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@GetMapping("/deleteFile")
|
||||
@Operation(summary = "删除导入文件")
|
||||
public ResponseResult deleteFile(@RequestParam String taskId,
|
||||
@ -892,6 +935,57 @@ public class FishDraftDataController {
|
||||
}
|
||||
}
|
||||
|
||||
@PostMapping("/deleteRowById")
|
||||
@Operation(summary = "删除数据")
|
||||
public ResponseResult deleteRowById(@RequestBody FishImportRowRequest request) {
|
||||
String taskId = request.getTaskId();
|
||||
FishDraftData data = request.getData();
|
||||
|
||||
if (taskId == null || taskId.isEmpty()) {
|
||||
return ResponseResult.error("任务ID不能为空");
|
||||
}
|
||||
if (data == null || data.getId() == null || data.getId().isEmpty()) {
|
||||
return ResponseResult.error("数据对象或其ID不能为空");
|
||||
}
|
||||
|
||||
try {
|
||||
ImportTask task = importTaskService.getById(taskId);
|
||||
if (task == null) {
|
||||
return ResponseResult.error("任务不存在");
|
||||
}
|
||||
|
||||
String resultJson = task.getResultJson();
|
||||
if (resultJson == null || resultJson.isEmpty()) {
|
||||
return ResponseResult.error("任务结果为空");
|
||||
}
|
||||
|
||||
FishImportResult importResult = objectMapper.readValue(resultJson, FishImportResult.class);
|
||||
|
||||
FishImportResult.FishImportRow targetRow = null;
|
||||
int targetIndex = -1;
|
||||
for (int i = 0; i < importResult.getRows().size(); i++) {
|
||||
FishImportResult.FishImportRow row = importResult.getRows().get(i);
|
||||
if (row.getData() != null && data.getId().equals(row.getData().getId())) {
|
||||
targetRow = row;
|
||||
targetIndex = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (targetIndex == -1) {
|
||||
return ResponseResult.error("未找到对应的数据行");
|
||||
}
|
||||
importResult.getRows().remove(targetIndex);
|
||||
String updatedJson = objectMapper.writeValueAsString(importResult);
|
||||
importTaskService.saveResultJson(taskId, updatedJson);
|
||||
return ResponseResult.success();
|
||||
|
||||
} catch (Exception e) {
|
||||
log.error("删除数据失败: " + e.getMessage(), e);
|
||||
return ResponseResult.error("删除数据失败: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
private void validateAndNormalizeData(FishDraftData data, FishImportResult.FishImportRow importRow,
|
||||
List<String> warnings) {
|
||||
if (data.getStcd() == null || data.getStcd().isEmpty()) {
|
||||
|
||||
@ -156,6 +156,14 @@ public class FishDraftData implements Serializable {
|
||||
*/
|
||||
private Integer deletedFlag;
|
||||
|
||||
|
||||
/**
|
||||
* 行号
|
||||
*/
|
||||
private Integer rowIndex;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 删除人
|
||||
*/
|
||||
|
||||
@ -216,7 +216,7 @@ public class FishDraftDataVO implements Serializable {
|
||||
/**
|
||||
* 排序字段
|
||||
*/
|
||||
private Integer orderIndex;
|
||||
private Integer rowIndex;
|
||||
|
||||
/**
|
||||
* 创建人名称
|
||||
|
||||
@ -18,9 +18,12 @@ import com.yfd.platform.data.service.IApprovalLogService;
|
||||
import com.yfd.platform.data.service.IApprovalMainService;
|
||||
import com.yfd.platform.data.service.IFishDraftDataService;
|
||||
import com.yfd.platform.env.domain.SdEngInfoBH;
|
||||
import com.yfd.platform.env.domain.SdFpssR;
|
||||
import com.yfd.platform.env.domain.SdHbrvDic;
|
||||
import com.yfd.platform.env.mapper.SdEngInfoBHMapper;
|
||||
import com.yfd.platform.env.mapper.SdFpssRMapper;
|
||||
import com.yfd.platform.env.mapper.SdHbrvDicMapper;
|
||||
import com.yfd.platform.env.service.ISdFpssRService;
|
||||
import com.yfd.platform.system.domain.SysUser;
|
||||
import com.yfd.platform.system.mapper.SysUserMapper;
|
||||
import com.yfd.platform.utils.KendoUtil;
|
||||
@ -28,6 +31,8 @@ import com.yfd.platform.utils.QgcQueryWrapperUtil;
|
||||
import com.yfd.platform.utils.SecurityUtils;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import jakarta.annotation.Resource;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.ibatis.executor.BatchResult;
|
||||
import org.springframework.security.core.GrantedAuthority;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
@ -41,6 +46,7 @@ import java.util.*;
|
||||
* </p>
|
||||
*/
|
||||
@Service
|
||||
@Slf4j
|
||||
public class FishDraftDataServiceImpl extends ServiceImpl<FishDraftDataMapper, FishDraftData> implements IFishDraftDataService {
|
||||
|
||||
@Resource
|
||||
@ -70,9 +76,17 @@ public class FishDraftDataServiceImpl extends ServiceImpl<FishDraftDataMapper, F
|
||||
@Resource
|
||||
private SdHbrvDicMapper hbrvDicMapper;
|
||||
|
||||
@Resource
|
||||
private SdFpssRMapper sdFpssRMapper;
|
||||
|
||||
@Resource
|
||||
private ISdFpssRService sdFpssRService;
|
||||
|
||||
@Override
|
||||
public Page<FishDraftDataVO> queryPageList(DataSourceRequest dataSourceRequest) {
|
||||
Page<FishDraftDataVO> page = KendoUtil.getPage(dataSourceRequest);
|
||||
page.setSize(dataSourceRequest.getTake());
|
||||
page.setCurrent(dataSourceRequest.getSkip());
|
||||
DataSourceLoadOptionsBase loadOptions = dataSourceRequest.toDevRequest();
|
||||
String stcd = QgcQueryWrapperUtil.getFilterFieldValue(loadOptions, "stcd");
|
||||
String approvalId = QgcQueryWrapperUtil.getFilterFieldValue(loadOptions, "approvalId");
|
||||
@ -397,6 +411,7 @@ public class FishDraftDataServiceImpl extends ServiceImpl<FishDraftDataMapper, F
|
||||
List<FishDraftData> dataList = this.listByIds(ids);
|
||||
Set<String> processedApprovalIds = new HashSet<>();
|
||||
List<String> validIds = new ArrayList<>();
|
||||
List<SdFpssR> fpssRList = new ArrayList<>();
|
||||
|
||||
for (FishDraftData fishDraftData : dataList) {
|
||||
if ("PENDING".equals(fishDraftData.getStatus())) {
|
||||
@ -404,6 +419,8 @@ public class FishDraftDataServiceImpl extends ServiceImpl<FishDraftDataMapper, F
|
||||
if (fishDraftData.getApprovalId() != null) {
|
||||
processedApprovalIds.add(fishDraftData.getApprovalId());
|
||||
}
|
||||
SdFpssR fpssR = convertToSdFpssR(fishDraftData, operatorId);
|
||||
fpssRList.add(fpssR);
|
||||
}
|
||||
}
|
||||
|
||||
@ -414,6 +431,8 @@ public class FishDraftDataServiceImpl extends ServiceImpl<FishDraftDataMapper, F
|
||||
updateWrapper.set(FishDraftData::getApproveTime, now);
|
||||
updateWrapper.set(FishDraftData::getUpdatedBy, operatorId);
|
||||
this.update(updateWrapper);
|
||||
boolean b = sdFpssRService.saveOrUpdateBatch(fpssRList);
|
||||
log.info("=======================插入数据条数======================="+fpssRList.size());
|
||||
for (String approvalId : processedApprovalIds) {
|
||||
ApprovalMain approvalMain = approvalMainService.getById(approvalId);
|
||||
approvalLogService.logApprove(approvalId, SecurityUtils.getUserId(), approveComment);
|
||||
@ -430,6 +449,47 @@ public class FishDraftDataServiceImpl extends ServiceImpl<FishDraftDataMapper, F
|
||||
return true;
|
||||
}
|
||||
|
||||
private SdFpssR convertToSdFpssR(FishDraftData draft, String operatorId) {
|
||||
SdFpssR fpssR = new SdFpssR();
|
||||
fpssR.setId(draft.getId());
|
||||
fpssR.setStcd(draft.getStcd());
|
||||
fpssR.setTm(draft.getTm());
|
||||
fpssR.setFtp(draft.getFtp());
|
||||
fpssR.setFsz(draft.getFsz());
|
||||
fpssR.setIsfs(draft.getIsfs());
|
||||
fpssR.setFcnt(draft.getFcnt());
|
||||
fpssR.setFwet(draft.getFwet());
|
||||
fpssR.setStrdt(draft.getStrdt());
|
||||
fpssR.setEnddt(draft.getEnddt());
|
||||
fpssR.setDirection(convertDirection(draft.getDirection()));
|
||||
fpssR.setYr(draft.getYr());
|
||||
fpssR.setMouth(draft.getMouth() != null ? String.valueOf(draft.getMouth()) : null);
|
||||
fpssR.setVdpth(draft.getVdpth());
|
||||
fpssR.setPicpth(draft.getPicpth());
|
||||
fpssR.setRecordUser(operatorId);
|
||||
fpssR.setRecordTime(new Date());
|
||||
fpssR.setIsDeleted(0);
|
||||
return fpssR;
|
||||
}
|
||||
|
||||
private Integer convertDirection(String direction) {
|
||||
if (direction == null) {
|
||||
return null;
|
||||
}
|
||||
switch (direction.trim()) {
|
||||
case "上行", "0":
|
||||
return 0;
|
||||
case "下行", "1":
|
||||
return 1;
|
||||
case "上行折返", "2":
|
||||
return 2;
|
||||
case "下行折返", "3":
|
||||
return 3;
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public boolean batchReject(String id, String rejectReason) {
|
||||
|
||||
@ -84,12 +84,12 @@ public class SdFpssR implements Serializable {
|
||||
/**
|
||||
* 过鱼图片文件路径
|
||||
*/
|
||||
private String imgpath;
|
||||
private String picpth;
|
||||
|
||||
/**
|
||||
* 过鱼视频文件路径
|
||||
*/
|
||||
private String vdpath;
|
||||
private String vdpth;
|
||||
|
||||
/**
|
||||
* 年份:数据时间,精确到年
|
||||
@ -135,4 +135,10 @@ public class SdFpssR implements Serializable {
|
||||
* 删除时间
|
||||
*/
|
||||
private Date deleteTime;
|
||||
|
||||
/**
|
||||
* 是否鱼苗(0否 1是)
|
||||
*/
|
||||
private Integer isfs;
|
||||
|
||||
}
|
||||
@ -78,7 +78,7 @@
|
||||
<result column="RVCD" property="rvcd"/>
|
||||
<result column="LGTD" property="lgtd"/>
|
||||
<result column="LTTD" property="lttd"/>
|
||||
<result column="ORDER_INDEX" property="orderIndex"/>
|
||||
<result column="ROW_INDEX" property="rowIndex"/>
|
||||
</resultMap>
|
||||
|
||||
<sql id="joinColumns">
|
||||
@ -123,7 +123,8 @@
|
||||
E.RVCD,
|
||||
E.LGTD,
|
||||
E.LTTD,
|
||||
E.ORDER_INDEX
|
||||
E.ORDER_INDEX,
|
||||
D.ROW_INDEX
|
||||
</sql>
|
||||
|
||||
<select id="selectJoinPage" resultMap="JoinResultMap">
|
||||
@ -169,7 +170,7 @@
|
||||
<if test="endTime != null and endTime != ''">
|
||||
AND D.STRDT <= TO_DATE(#{endTime}, 'yyyy-mm-dd hh24:mi:ss')
|
||||
</if>
|
||||
ORDER BY D.CREATED_AT DESC
|
||||
ORDER BY D.TM DESC, D.ROW_INDEX ASC
|
||||
</select>
|
||||
|
||||
<select id="selectJoinList" resultMap="JoinResultMap">
|
||||
|
||||
Loading…
Reference in New Issue
Block a user