| | |
| | | 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.framework.exception.CoolException; |
| | | 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 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 javax.servlet.http.HttpServletResponse; |
| | | import jakarta.servlet.http.HttpServletResponse; |
| | | import java.util.*; |
| | | |
| | | @RestController |
| | |
| | | public R page(@RequestBody Map<String, Object> map) { |
| | | BaseParam baseParam = buildParam(map, BaseParam.class); |
| | | PageParam<DictType, BaseParam> pageParam = new PageParam<>(baseParam, DictType.class); |
| | | return R.ok().add(dictTypeService.page(pageParam, pageParam.buildWrapper(true))); |
| | | return R.ok().add(buildPageRowsUtils.rowsMap(dictTypeService.page(pageParam, pageParam.buildWrapper(true)))); |
| | | } |
| | | |
| | | @PreAuthorize("hasAuthority('system:dictType:list')") |
| | | @PostMapping("/dictType/list") |
| | | public R list(@RequestBody Map<String, Object> map) { |
| | | return R.ok().add(dictTypeService.list()); |
| | | return R.ok().add(buildPageRowsUtils.rowsMap(dictTypeService.list())); |
| | | } |
| | | |
| | | @PreAuthorize("hasAuthority('system:dictType:list')") |
| | | @PostMapping({"/dictType/many/{ids}", "/dictTypes/many/{ids}"}) |
| | | public R many(@PathVariable Long[] ids) { |
| | | return R.ok().add(dictTypeService.listByIds(Arrays.asList(ids))); |
| | | return R.ok().add(buildPageRowsUtils.rowsMap(dictTypeService.listByIds(Arrays.asList(ids)))); |
| | | } |
| | | |
| | | @PreAuthorize("hasAuthority('system:dictType:list')") |
| | | @GetMapping("/dictType/{id}") |
| | | public R get(@PathVariable("id") Long id) { |
| | | return R.ok().add(dictTypeService.getById(id)); |
| | | return R.ok().add(buildPageRowsUtils.rowsMap(dictTypeService.getById(id))); |
| | | } |
| | | |
| | | @PreAuthorize("hasAuthority('system:dictType:save')") |
| | |
| | | @PostMapping("/dictType/save") |
| | | public R save(@RequestBody DictType dictType) { |
| | | dictType.setCreateBy(getLoginUserId()); |
| | | dictType.setCreateTime(new Date()); |
| | | dictType.setUpdateBy(getLoginUserId()); |
| | | dictType.setUpdateTime(new Date()); |
| | | if (Objects.isNull(dictType.getName())) { |
| | | throw new CoolException("字典名称不能为空!!"); |
| | | } |
| | | if (Objects.isNull(dictType.getCode())) { |
| | | throw new CoolException("字典编码不能为空!!"); |
| | | } |
| | | if (!dictTypeService.list(new LambdaQueryWrapper<DictType>().eq(DictType::getCode, dictType.getCode())).isEmpty()) { |
| | | throw new CoolException("编码不能重复!!"); |
| | | } |
| | | if (!dictTypeService.list(new LambdaQueryWrapper<DictType>().eq(DictType::getName, dictType.getName())).isEmpty()) { |
| | | throw new CoolException("名称不能重复!!"); |
| | | } |
| | | if (!dictTypeService.save(dictType)) { |
| | | return R.error("Save Fail"); |
| | | } |
| | | return R.ok("Save Success").add(dictType); |
| | | return R.ok("Save Success").add(buildPageRowsUtils.rowsMap(dictType)); |
| | | } |
| | | |
| | | @PreAuthorize("hasAuthority('system:dictType:update')") |
| | | @OperationLog("Update 数据字典") |
| | | @PostMapping("/dictType/update") |
| | | public R update(@RequestBody DictType dictType) { |
| | | if (Objects.isNull(dictType)) { |
| | | throw new CoolException("参数不能为空!!"); |
| | | } |
| | | dictType.setUpdateBy(getLoginUserId()); |
| | | dictType.setUpdateTime(new Date()); |
| | | if (!dictTypeService.updateById(dictType)) { |
| | | return R.error("Update Fail"); |
| | | } |
| | | return R.ok("Update Success").add(dictType); |
| | | return R.ok("Update Success").add(buildPageRowsUtils.rowsMap(dictType)); |
| | | } |
| | | |
| | | @PreAuthorize("hasAuthority('system:dictType:remove')") |
| | |
| | | if (!dictTypeService.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:dictType:list')") |
| | |
| | | dictTypeService.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:dictType:list')") |
| | | @PostMapping("/dictType/export") |
| | | public void export(@RequestBody Map<String, Object> map, HttpServletResponse response) throws Exception { |
| | | ExcelUtil.build(ExcelUtil.create(dictTypeService.list(), DictType.class), response); |
| | | ExcelUtil.build(ExcelUtil.create(buildPageRowsUtils.rowsMap(dictTypeService.list()), DictType.class), response); |
| | | } |
| | | |
| | | } |
| | | |