package com.vincent.rsf.server.system.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.system.entity.SerialRule; import com.vincent.rsf.server.system.service.SerialRuleService; 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 SerialRuleController extends BaseController { @Autowired private SerialRuleService serialRuleService; @PreAuthorize("hasAuthority('system:serialRule:list')") @PostMapping("/serialRule/page") public R page(@RequestBody Map map) { BaseParam baseParam = buildParam(map, BaseParam.class); PageParam pageParam = new PageParam<>(baseParam, SerialRule.class); return R.ok().add(serialRuleService.page(pageParam, pageParam.buildWrapper(true))); } @PreAuthorize("hasAuthority('system:serialRule:list')") @PostMapping("/serialRule/list") public R list(@RequestBody Map map) { return R.ok().add(serialRuleService.list()); } @PreAuthorize("hasAuthority('system:serialRule:list')") @PostMapping({"/serialRule/many/{ids}", "/serialRules/many/{ids}"}) public R many(@PathVariable Long[] ids) { return R.ok().add(serialRuleService.listByIds(Arrays.asList(ids))); } @PreAuthorize("hasAuthority('system:serialRule:list')") @GetMapping("/serialRule/{id}") public R get(@PathVariable("id") Long id) { return R.ok().add(serialRuleService.getById(id)); } @PreAuthorize("hasAuthority('system:serialRule:save')") @OperationLog("Create 字典数据集") @PostMapping("/serialRule/save") public R save(@RequestBody SerialRule serialRule) { serialRule.setCreateBy(getLoginUserId()); serialRule.setCreateTime(new Date()); serialRule.setUpdateBy(getLoginUserId()); serialRule.setUpdateTime(new Date()); if (!serialRuleService.save(serialRule)) { return R.error("Save Fail"); } return R.ok("Save Success").add(serialRule); } @PreAuthorize("hasAuthority('system:serialRule:update')") @OperationLog("Update 字典数据集") @PostMapping("/serialRule/update") public R update(@RequestBody SerialRule serialRule) { serialRule.setUpdateBy(getLoginUserId()); serialRule.setUpdateTime(new Date()); if (!serialRuleService.updateById(serialRule)) { return R.error("Update Fail"); } return R.ok("Update Success").add(serialRule); } @PreAuthorize("hasAuthority('system:serialRule:remove')") @OperationLog("Delete 字典数据集") @PostMapping("/serialRule/remove/{ids}") public R remove(@PathVariable Long[] ids) { if (!serialRuleService.removeByIds(Arrays.asList(ids))) { return R.error("Delete Fail"); } return R.ok("Delete Success").add(ids); } @PreAuthorize("hasAuthority('system:serialRule:list')") @PostMapping("/serialRule/query") public R query(@RequestParam(required = false) String condition) { List vos = new ArrayList<>(); LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>(); if (!Cools.isEmpty(condition)) { wrapper.like(SerialRule::getCode, condition); } serialRuleService.page(new Page<>(1, 30), wrapper).getRecords().forEach( item -> vos.add(new KeyValVo(item.getId(), item.getCode())) ); return R.ok().add(vos); } @PreAuthorize("hasAuthority('system:serialRule:list')") @PostMapping("/serialRule/export") public void export(@RequestBody Map map, HttpServletResponse response) throws Exception { ExcelUtil.build(ExcelUtil.create(serialRuleService.list(), SerialRule.class), response); } }