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;
/**
*
* 服务实现类
*
*
* @author
* @since 2025-02-10
*/
@Service
public class DictServiceImpl extends ServiceImpl implements IDictService {
@Autowired
IDictFileService dictFileService;
@Override
public List getByKey(String dictKey) {
if(StringUtils.isBlank(dictKey)){
throw new BusinessException(ResultCode.MISSING_REQUIRED_PARAMETERS);
}
LambdaQueryWrapper 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 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 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());
}
}