123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081 |
- package com.fdkankan.fusion.service.impl;
- import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
- import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
- import com.fdkankan.fusion.common.PageInfo;
- import com.fdkankan.fusion.common.ResultCode;
- import com.fdkankan.fusion.entity.Dict;
- import com.fdkankan.fusion.entity.DictFile;
- import com.fdkankan.fusion.exception.BusinessException;
- import com.fdkankan.fusion.mapper.IDictMapper;
- import com.fdkankan.fusion.request.DictParam;
- import com.fdkankan.fusion.service.IDictFileService;
- import com.fdkankan.fusion.service.IDictService;
- import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
- import org.apache.commons.lang3.StringUtils;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.stereotype.Service;
- import java.util.List;
- /**
- * <p>
- * 服务实现类
- * </p>
- *
- * @author
- * @since 2025-02-10
- */
- @Service
- public class DictServiceImpl extends ServiceImpl<IDictMapper, Dict> implements IDictService {
- @Autowired
- IDictFileService dictFileService;
- @Override
- public List<Dict> getByKey(String dictKey) {
- if(StringUtils.isBlank(dictKey)){
- throw new BusinessException(ResultCode.MISSING_REQUIRED_PARAMETERS);
- }
- LambdaQueryWrapper<Dict> wrapper = new LambdaQueryWrapper<>();
- wrapper.eq(Dict::getDictKey,dictKey);
- wrapper.orderByAsc(Dict::getSort);
- wrapper.orderByDesc(Dict::getId);
- return list(wrapper);
- }
- @Override
- public Object pageList(DictParam param) {
- if(StringUtils.isBlank(param.getDictKey())){
- throw new BusinessException(ResultCode.MISSING_REQUIRED_PARAMETERS);
- }
- LambdaQueryWrapper<Dict> wrapper = new LambdaQueryWrapper<>();
- wrapper.eq(Dict::getDictKey,param.getDictKey());
- if(StringUtils.isNotBlank(param.getDictName())){
- wrapper.like(Dict::getDictName,param.getDictName());
- }
- wrapper.orderByAsc(Dict::getSort);
- wrapper.orderByDesc(Dict::getId);
- Page<Dict> page = this.page(new Page<>(param.getPageNum(), param.getPageSize()), wrapper);
- return PageInfo.PageInfo(page);
- }
- @Override
- public void addOrUpdate(Dict dict) {
- if(StringUtils.isBlank(dict.getDictName()) || StringUtils.isBlank(dict.getDictKey())){
- throw new BusinessException(ResultCode.MISSING_REQUIRED_PARAMETERS);
- }
- this.saveOrUpdate(dict);
- }
- @Override
- public void del(Dict dict) {
- if(dict.getId() == null){
- throw new BusinessException(ResultCode.MISSING_REQUIRED_PARAMETERS);
- }
- dictFileService.updateDictId(dict.getId(),null);
- this.removeById(dict.getId());
- }
- }
|