| package com.zy.acs.manager.system.controller; | 
|   | 
| import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; | 
| import com.baomidou.mybatisplus.extension.plugins.pagination.Page; | 
| import com.zy.acs.manager.common.annotation.OperationLog; | 
| import com.zy.acs.manager.common.domain.BaseParam; | 
| import com.zy.acs.manager.common.domain.KeyValVo; | 
| import com.zy.acs.manager.common.domain.PageParam; | 
| import com.zy.acs.manager.common.utils.ExcelUtil; | 
| import com.zy.acs.manager.system.entity.Host; | 
| import com.zy.acs.manager.system.service.HostService; | 
| import com.zy.acs.framework.common.Cools; | 
| import com.zy.acs.framework.common.R; | 
| import org.springframework.beans.factory.annotation.Autowired; | 
| import org.springframework.security.access.prepost.PreAuthorize; | 
| import org.springframework.web.bind.annotation.*; | 
|   | 
| import javax.servlet.http.HttpServletResponse; | 
| import java.util.*; | 
|   | 
| @RestController | 
| @RequestMapping("/api") | 
| public class HostController extends BaseController { | 
|   | 
|     @Autowired | 
|     private HostService hostService; | 
|   | 
|     @PreAuthorize("hasAuthority('system:host:list')") | 
|     @PostMapping("/host/page") | 
|     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))); | 
|     } | 
|   | 
|     @PreAuthorize("hasAuthority('system:host:list')") | 
|     @PostMapping("/host/list") | 
|     public R list(@RequestBody Map<String, Object> map) { | 
|         return R.ok().add(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))); | 
|     } | 
|   | 
|     @PreAuthorize("hasAuthority('system:host:list')") | 
|     @GetMapping("/host/{id}") | 
|     public R get(@PathVariable("id") Long id) { | 
|         return R.ok().add(hostService.getById(id)); | 
|     } | 
|   | 
|     @PreAuthorize("hasAuthority('system:host:save')") | 
|     @OperationLog("Create Host") | 
|     @PostMapping("/host/save") | 
|     public R save(@RequestBody Host host) { | 
|         Date now = new Date(); | 
|         host.setCreateTime(now); | 
|         host.setUpdateTime(now); | 
|         if (!hostService.save(host)) { | 
|             return R.error("Save Fail"); | 
|         } | 
|         return R.ok("Save Success").add(host); | 
|     } | 
|   | 
|     @PreAuthorize("hasAuthority('system:host:update')") | 
|     @OperationLog("Update Host") | 
|     @PostMapping("/host/update") | 
|     public R update(@RequestBody Host host) { | 
|         host.setUpdateTime(new Date()); | 
|         if (!hostService.updateById(host)) { | 
|             return R.error("Update Fail"); | 
|         } | 
|         return R.ok("Update Success").add(host); | 
|     } | 
|   | 
|     @PreAuthorize("hasAuthority('system:host:remove')") | 
|     @OperationLog("Delete Host") | 
|     @PostMapping("/host/remove/{ids}") | 
|     public R remove(@PathVariable Long[] ids) { | 
|         if (!hostService.removeByIds(Arrays.asList(ids))) { | 
|             return R.error("Delete Fail"); | 
|         } | 
|         return R.ok("Delete Success").add(ids); | 
|     } | 
|   | 
|     @PreAuthorize("hasAuthority('system:host:list')") | 
|     @PostMapping("/host/query") | 
|     public R query(@RequestParam(required = false) String condition) { | 
|         List<KeyValVo> vos = new ArrayList<>(); | 
|         LambdaQueryWrapper<Host> wrapper = new LambdaQueryWrapper<>(); | 
|         if (!Cools.isEmpty(condition)) { | 
|             wrapper.like(Host::getName, condition); | 
|         } | 
|         hostService.page(new Page<>(1, 30), wrapper).getRecords().forEach( | 
|                 item -> vos.add(new KeyValVo(item.getId(), item.getName())) | 
|         ); | 
|         return R.ok().add(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); | 
|     } | 
|   | 
| } |