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