fix(app): 导航栏编辑SQL报错

This commit is contained in:
冷冷 committed 2024-09-08 16:35:19 +08:00
1 parent 39e7ab3372
commit ebf053ab30
1 file changed
+28 -19
@@ -27,26 +27,35 @@ import java.util.stream.Collectors;
@SecurityRequirement(name = HttpHeaders.AUTHORIZATION)
public class AppTabbarController {
private final AppTabbarService tabbarService;
private final AppTabbarService tabbarService;
/**
* 查询导航列表
* @return R
*/
@Operation(summary = "查询导航列表", description = "查询导航列表")
@GetMapping("/list")
public R list() {
return R.ok(tabbarService.list());
}
/**
* 查询导航列表
*
* @return R
*/
@Operation(summary = "查询导航列表", description = "查询导航列表")
@GetMapping("/list")
public R list() {
return R.ok(tabbarService.list());
}
@Operation(summary = "更新导航", description = "更新导航")
@PutMapping
public R update(@RequestBody List<AppTabbarEntity> tabbarEntityList) {
// 删除不在新增范围的导航菜单
List<Long> idList = tabbarService.list().stream().map(AppTabbarEntity::getId).collect(Collectors.toList());
List<Long> newIdList = tabbarEntityList.stream().map(AppTabbarEntity::getId).collect(Collectors.toList());
tabbarService.removeBatchByIds(CollUtil.subtractToList(idList, newIdList));
return R.ok(tabbarService.saveOrUpdateBatch(tabbarEntityList));
}
@Operation(summary = "更新导航", description = "更新导航")
@PutMapping
public R update(@RequestBody List<AppTabbarEntity> tabbarEntityList) {
// 删除不在新增范围的导航菜单
List<Long> idList = tabbarService.list().stream().map(AppTabbarEntity::getId).collect(Collectors.toList());
List<Long> newIdList = tabbarEntityList.stream().map(AppTabbarEntity::getId).collect(Collectors.toList());
// 计算需要删除的 ID 列表
List<Long> idsToRemove = CollUtil.subtractToList(idList, newIdList);
// 如果有需要删除的菜单,则批量删除
if (CollUtil.isNotEmpty(idsToRemove)) {
tabbarService.removeBatchByIds(idsToRemove);
}
return R.ok(tabbarService.saveOrUpdateBatch(tabbarEntityList));
}
}