package com.zy.acs.manager.manager.controller; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.zy.acs.framework.common.Cools; import com.zy.acs.framework.common.R; import com.zy.acs.manager.common.utils.ExcelUtil; 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.manager.entity.Guarantee; import com.zy.acs.manager.manager.service.GuaranteeService; import com.zy.acs.manager.system.controller.BaseController; 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 GuaranteeController extends BaseController { @Autowired private GuaranteeService guaranteeService; @PreAuthorize("hasAuthority('manager:guarantee:list')") @PostMapping("/guarantee/page") public R page(@RequestBody Map map) { BaseParam baseParam = buildParam(map, BaseParam.class); PageParam pageParam = new PageParam<>(baseParam, Guarantee.class); return R.ok().add(guaranteeService.page(pageParam, pageParam.buildWrapper(true))); } @PreAuthorize("hasAuthority('manager:guarantee:list')") @PostMapping("/guarantee/list") public R list(@RequestBody Map map) { return R.ok().add(guaranteeService.list()); } @PreAuthorize("hasAuthority('manager:guarantee:list')") @PostMapping({"/guarantee/many/{ids}", "/guarantees/many/{ids}"}) public R many(@PathVariable Long[] ids) { return R.ok().add(guaranteeService.listByIds(Arrays.asList(ids))); } @PreAuthorize("hasAuthority('manager:guarantee:list')") @GetMapping("/guarantee/{id}") public R get(@PathVariable("id") Long id) { return R.ok().add(guaranteeService.getById(id)); } @PreAuthorize("hasAuthority('manager:guarantee:save')") @OperationLog("Create Guarantee") @PostMapping("/guarantee/save") public R save(@RequestBody Guarantee guarantee) { guarantee.setCreateBy(getLoginUserId()); guarantee.setCreateTime(new Date()); guarantee.setUpdateBy(getLoginUserId()); guarantee.setUpdateTime(new Date()); if (!guaranteeService.save(guarantee)) { return R.error("Save Fail"); } return R.ok("Save Success").add(guarantee); } @PreAuthorize("hasAuthority('manager:guarantee:update')") @OperationLog("Update Guarantee") @PostMapping("/guarantee/update") public R update(@RequestBody Guarantee guarantee) { guarantee.setUpdateBy(getLoginUserId()); guarantee.setUpdateTime(new Date()); if (!guaranteeService.updateById(guarantee)) { return R.error("Update Fail"); } return R.ok("Update Success").add(guarantee); } @PreAuthorize("hasAuthority('manager:guarantee:remove')") @OperationLog("Delete Guarantee") @PostMapping("/guarantee/remove/{ids}") public R remove(@PathVariable Long[] ids) { if (!guaranteeService.removeByIds(Arrays.asList(ids))) { return R.error("Delete Fail"); } return R.ok("Delete Success").add(ids); } @PreAuthorize("hasAuthority('manager:guarantee:list')") @PostMapping("/guarantee/query") public R query(@RequestParam(required = false) String condition) { List vos = new ArrayList<>(); LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>(); if (!Cools.isEmpty(condition)) { wrapper.like(Guarantee::getName, condition); } guaranteeService.page(new Page<>(1, 30), wrapper).getRecords().forEach( item -> vos.add(new KeyValVo(item.getId(), item.getName())) ); return R.ok().add(vos); } @PreAuthorize("hasAuthority('manager:guarantee:list')") @PostMapping("/guarantee/export") public void export(@RequestBody Map map, HttpServletResponse response) throws Exception { ExcelUtil.build(ExcelUtil.create(guaranteeService.list(), Guarantee.class), response); } }