feat: 交易记录锁定功能 - 新增locked字段、lock接口、锁定后禁止修改

This commit is contained in:
OpenCode
2026-07-17 17:20:42 +08:00
parent 0591f2ae46
commit 17e74bb247
4 changed files with 27 additions and 0 deletions
@@ -32,6 +32,14 @@ public class AdminStockRecordController extends BaseController<StockRecordServic
return R.ok();
}
@Operation(summary = "锁定")
@PostMapping("/lock")
public R<Void> lock(@RequestBody JSONObject params) {
Long id = params.getLong("id");
service.lock(id, CoolSecurityUtil.getCurrentUserId());
return R.ok();
}
@Operation(summary = "恢复")
@PostMapping("/restore")
public R<Void> restore(@RequestBody JSONObject params) {
@@ -32,6 +32,9 @@ public class StockRecordEntity extends BaseEntity<StockRecordEntity> {
@ColumnDefine(comment = "卖出数量", defaultValue = "100")
private Integer sellQuantity;
@ColumnDefine(comment = "是否已锁定", defaultValue = "0")
private Boolean locked;
@ColumnDefine(comment = "是否已归档", defaultValue = "0")
private Boolean archived;
@@ -6,4 +6,5 @@ import com.cool.modules.stock.entity.StockRecordEntity;
public interface StockRecordService extends BaseService<StockRecordEntity> {
void archive(Long id, Long userId);
void restore(Long id, Long userId);
void lock(Long id, Long userId);
}
@@ -20,6 +20,21 @@ public class StockRecordServiceImpl extends BaseServiceImpl<StockRecordMapper, S
if (type == ModifyEnum.ADD) {
entity.setUserId(CoolSecurityUtil.getCurrentUserId());
}
if (type == ModifyEnum.UPDATE) {
StockRecordEntity existing = getById(entity.getId());
if (existing != null && Boolean.TRUE.equals(existing.getLocked())) {
throw new RuntimeException("记录已锁定,无法修改");
}
}
}
@Override
public void lock(Long id, Long userId) {
StockRecordEntity entity = getById(id);
if (entity != null && entity.getUserId().equals(userId)) {
entity.setLocked(true);
updateById(entity);
}
}
@Override