后端实现: - RecordController:添加分页和搜索参数支持 - DeductRecordService:新增findByUserIdWithSearch方法 - DeductRecordRepository:添加分页查询和关键词搜索方法 - 新增deleteBatch批量删除接口 前端实现: - 搜索栏:支持按姓名或事项搜索 - 分页功能:上一页/下一页按钮,显示页码信息 - 全选功能:复选框全选/取消全选 - 批量删除:选中多条记录后可批量删除 - 一键清空:清空所有测算记录 - UI优化:添加操作栏、复选框样式 API接口: - GET /api/records/list - 支持分页和搜索参数 - POST /api/records/deleteBatch - 批量删除记录 - POST /api/records/clear - 清空所有记录
77 lines
2.6 KiB
Java
77 lines
2.6 KiB
Java
package xuan.controller;
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.web.bind.annotation.*;
|
|
import xuan.entity.ShareRecord;
|
|
import xuan.repository.ShareRecordRepository;
|
|
|
|
import java.util.HashMap;
|
|
import java.util.Map;
|
|
import java.util.UUID;
|
|
|
|
@RestController
|
|
@RequestMapping("/api/share")
|
|
public class ShareController {
|
|
|
|
@Autowired
|
|
private ShareRecordRepository shareRecordRepository;
|
|
|
|
@PostMapping("/create")
|
|
public Map<String, Object> createShare(@RequestBody Map<String, Object> params) {
|
|
Map<String, Object> result = new HashMap<>();
|
|
|
|
try {
|
|
String type = (String) params.get("type");
|
|
String resultData = (String) params.get("resultData");
|
|
String name = (String) params.get("name");
|
|
|
|
ShareRecord shareRecord = new ShareRecord();
|
|
shareRecord.setShareId(UUID.randomUUID().toString().replace("-", "").substring(0, 16));
|
|
shareRecord.setType(type);
|
|
shareRecord.setResultData(resultData);
|
|
shareRecord.setName(name);
|
|
|
|
shareRecordRepository.save(shareRecord);
|
|
|
|
result.put("success", true);
|
|
result.put("shareId", shareRecord.getShareId());
|
|
result.put("message", "分享链接创建成功");
|
|
} catch (Exception e) {
|
|
result.put("success", false);
|
|
result.put("error", "创建分享链接失败:" + e.getMessage());
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
@GetMapping("/view/{shareId}")
|
|
public Map<String, Object> viewShare(@PathVariable String shareId) {
|
|
Map<String, Object> result = new HashMap<>();
|
|
|
|
try {
|
|
ShareRecord shareRecord = shareRecordRepository.findByShareId(shareId)
|
|
.orElse(null);
|
|
|
|
if (shareRecord == null) {
|
|
result.put("success", false);
|
|
result.put("error", "分享链接不存在或已过期");
|
|
return result;
|
|
}
|
|
|
|
if (shareRecord.getExpireTime() != null && shareRecord.getExpireTime().before(new java.util.Date())) {
|
|
result.put("success", false);
|
|
result.put("error", "分享链接已过期");
|
|
return result;
|
|
}
|
|
|
|
result.put("success", true);
|
|
result.put("data", shareRecord);
|
|
} catch (Exception e) {
|
|
result.put("success", false);
|
|
result.put("error", "获取分享数据失败:" + e.getMessage());
|
|
}
|
|
|
|
return result;
|
|
}
|
|
}
|