| | |
| | | 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 com.vincent.rsf.server.common.domain.PageParam; |
| | | import com.vincent.rsf.server.system.entity.DictData; |
| | | import com.vincent.rsf.server.system.service.DictDataService; |
| | | 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.*; |
| | |
| | | |
| | | @PreAuthorize("hasAuthority('system:dictData:list')") |
| | | @PostMapping({"/dictData/many/{ids}", "/dictDatas/many/{ids}"}) |
| | | public R many(@PathVariable Long[] ids) { |
| | | return R.ok().add(dictDataService.listByIds(Arrays.asList(ids))); |
| | | public R many(@PathVariable String[] ids) { |
| | | if (ids == null || ids.length == 0) { |
| | | return R.ok().add(Collections.emptyList()); |
| | | } |
| | | List<Long> idList = new ArrayList<>(); |
| | | List<String> valueList = new ArrayList<>(); |
| | | for (String raw : ids) { |
| | | if (raw == null) { |
| | | continue; |
| | | } |
| | | String item = raw.trim(); |
| | | if (item.isEmpty()) { |
| | | continue; |
| | | } |
| | | valueList.add(item); |
| | | if (item.matches("^\\d+$")) { |
| | | try { |
| | | idList.add(Long.parseLong(item)); |
| | | } catch (NumberFormatException ignored) { |
| | | } |
| | | } |
| | | } |
| | | if (valueList.isEmpty()) { |
| | | return R.ok().add(Collections.emptyList()); |
| | | } |
| | | LambdaQueryWrapper<DictData> wrapper = new LambdaQueryWrapper<>(); |
| | | wrapper.in(DictData::getValue, valueList); |
| | | if (!idList.isEmpty()) { |
| | | wrapper.or().in(DictData::getId, idList); |
| | | } |
| | | return R.ok().add(dictDataService.list(wrapper)); |
| | | } |
| | | |
| | | @PreAuthorize("hasAuthority('system:dictData:list')") |
| | | @GetMapping("/dictData/{id}") |
| | | public R get(@PathVariable("id") Long id) { |
| | | return R.ok().add(dictDataService.getById(id)); |
| | | public R get(@PathVariable("id") String id) { |
| | | if (id == null || id.trim().isEmpty()) { |
| | | return R.ok().add(null); |
| | | } |
| | | String key = id.trim(); |
| | | DictData data = null; |
| | | if (key.matches("^\\d+$")) { |
| | | try { |
| | | data = dictDataService.getById(Long.parseLong(key)); |
| | | } catch (NumberFormatException ignored) { |
| | | } |
| | | } |
| | | if (data == null) { |
| | | data = dictDataService.getOne(new LambdaQueryWrapper<DictData>().eq(DictData::getValue, key), false); |
| | | } |
| | | return R.ok().add(data); |
| | | } |
| | | |
| | | @PreAuthorize("hasAuthority('system:dictData:save')") |
| | | @OperationLog("Create 字典数据集") |
| | | @PostMapping("/dictData/save") |
| | | public R save(@RequestBody DictData dictData) { |
| | | if (Objects.isNull(dictData.getLabel())) { |
| | | throw new CoolException("别名不能为空!!"); |
| | | } |
| | | if (Objects.isNull(dictData.getValue())) { |
| | | throw new CoolException("值不能为空!!"); |
| | | } |
| | | if (Objects.isNull(dictData.getDictTypeCode())) { |
| | | throw new CoolException("编码不能为空!!"); |
| | | } |
| | | if (Objects.isNull(dictData.getDictTypeId())) { |
| | | throw new CoolException("主单ID不能为空!!"); |
| | | } |
| | | dictData.setCreateBy(getLoginUserId()); |
| | | dictData.setCreateTime(new Date()); |
| | | dictData.setUpdateBy(getLoginUserId()); |
| | | dictData.setUpdateTime(new Date()); |
| | | if (!dictDataService.save(dictData)) { |
| | | return R.error("Save Fail"); |
| | | } |
| | |
| | | @PreAuthorize("hasAuthority('system:dictData:remove')") |
| | | @OperationLog("Delete 字典数据集") |
| | | @PostMapping("/dictData/remove/{ids}") |
| | | public R remove(@PathVariable Long[] ids) { |
| | | if (!dictDataService.removeByIds(Arrays.asList(ids))) { |
| | | public R remove(@PathVariable String[] ids) { |
| | | if (ids == null || ids.length == 0) { |
| | | return R.ok("Delete Success").add(Collections.emptyList()); |
| | | } |
| | | List<Long> idList = new ArrayList<>(); |
| | | List<String> valueList = new ArrayList<>(); |
| | | for (String raw : ids) { |
| | | if (raw == null) { |
| | | continue; |
| | | } |
| | | String item = raw.trim(); |
| | | if (item.isEmpty()) { |
| | | continue; |
| | | } |
| | | valueList.add(item); |
| | | if (item.matches("^\\d+$")) { |
| | | try { |
| | | idList.add(Long.parseLong(item)); |
| | | } catch (NumberFormatException ignored) { |
| | | } |
| | | } |
| | | } |
| | | if (valueList.isEmpty()) { |
| | | return R.ok("Delete Success").add(Collections.emptyList()); |
| | | } |
| | | LambdaQueryWrapper<DictData> wrapper = new LambdaQueryWrapper<>(); |
| | | wrapper.in(DictData::getValue, valueList); |
| | | if (!idList.isEmpty()) { |
| | | wrapper.or().in(DictData::getId, idList); |
| | | } |
| | | List<DictData> rows = dictDataService.list(wrapper); |
| | | List<Long> removeIds = new ArrayList<>(); |
| | | for (DictData row : rows) { |
| | | if (row != null && row.getId() != null) { |
| | | removeIds.add(row.getId()); |
| | | } |
| | | } |
| | | if (!removeIds.isEmpty() && !dictDataService.removeByIds(removeIds)) { |
| | | return R.error("Delete Fail"); |
| | | } |
| | | return R.ok("Delete Success").add(ids); |