| | |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.security.access.prepost.PreAuthorize; |
| | | import org.springframework.web.bind.annotation.*; |
| | | import com.vincent.rsf.server.manager.utils.buildPageRowsUtils; |
| | | |
| | | import jakarta.servlet.http.HttpServletResponse; |
| | | import java.util.*; |
| | |
| | | public R page(@RequestBody Map<String, Object> map) { |
| | | BaseParam baseParam = buildParam(map, BaseParam.class); |
| | | PageParam<Host, BaseParam> pageParam = new PageParam<>(baseParam, Host.class); |
| | | return R.ok().add(hostService.page(pageParam, pageParam.buildWrapper(true))); |
| | | return R.ok().add(buildPageRowsUtils.rowsMap(hostService.page(pageParam, pageParam.buildWrapper(true)))); |
| | | } |
| | | |
| | | @PreAuthorize("hasAuthority('system:host:list')") |
| | | @PostMapping("/host/list") |
| | | public R list(@RequestBody Map<String, Object> map) { |
| | | return R.ok().add(hostService.list()); |
| | | return R.ok().add(buildPageRowsUtils.rowsMap(hostService.list())); |
| | | } |
| | | |
| | | @PreAuthorize("hasAuthority('system:host:list')") |
| | | @PostMapping({"/host/many/{ids}", "/hosts/many/{ids}"}) |
| | | public R many(@PathVariable Long[] ids) { |
| | | return R.ok().add(hostService.listByIds(Arrays.asList(ids))); |
| | | return R.ok().add(buildPageRowsUtils.rowsMap(hostService.listByIds(Arrays.asList(ids)))); |
| | | } |
| | | |
| | | @PreAuthorize("hasAuthority('system:host:list')") |
| | | @GetMapping("/host/{id}") |
| | | public R get(@PathVariable("id") Long id) { |
| | | return R.ok().add(hostService.getById(id)); |
| | | return R.ok().add(buildPageRowsUtils.rowsMap(hostService.getById(id))); |
| | | } |
| | | |
| | | @PreAuthorize("hasAuthority('system:host:save')") |
| | |
| | | if (!hostService.save(host)) { |
| | | return R.error("Save Fail"); |
| | | } |
| | | return R.ok("Save Success").add(host); |
| | | return R.ok("Save Success").add(buildPageRowsUtils.rowsMap(host)); |
| | | } |
| | | |
| | | @PreAuthorize("hasAuthority('system:host:update')") |
| | |
| | | if (!hostService.updateById(host)) { |
| | | return R.error("Update Fail"); |
| | | } |
| | | return R.ok("Update Success").add(host); |
| | | return R.ok("Update Success").add(buildPageRowsUtils.rowsMap(host)); |
| | | } |
| | | |
| | | @PreAuthorize("hasAuthority('system:host:remove')") |
| | |
| | | if (!hostService.removeByIds(Arrays.asList(ids))) { |
| | | return R.error("Delete Fail"); |
| | | } |
| | | return R.ok("Delete Success").add(ids); |
| | | return R.ok("Delete Success").add(buildPageRowsUtils.rowsMap(ids)); |
| | | } |
| | | |
| | | @PreAuthorize("hasAuthority('system:host:list')") |
| | |
| | | hostService.page(new Page<>(1, 30), wrapper).getRecords().forEach( |
| | | item -> vos.add(new KeyValVo(item.getId(), item.getName())) |
| | | ); |
| | | return R.ok().add(vos); |
| | | return R.ok().add(buildPageRowsUtils.rowsMap(vos)); |
| | | } |
| | | |
| | | @PreAuthorize("hasAuthority('system:host:list')") |
| | | @PostMapping("/host/export") |
| | | public void export(@RequestBody Map<String, Object> map, HttpServletResponse response) throws Exception { |
| | | ExcelUtil.build(ExcelUtil.create(hostService.list(), Host.class), response); |
| | | ExcelUtil.build(ExcelUtil.create(buildPageRowsUtils.rowsMap(hostService.list()), Host.class), response); |
| | | } |
| | | |
| | | } |