12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697 |
- package com.fdkankan.manage.service.impl;
- import cn.dev33.satoken.stp.StpUtil;
- import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
- import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
- import com.fdkankan.manage.common.PageInfo;
- import com.fdkankan.manage.common.ResultCode;
- import com.fdkankan.manage.constant.FileTypeEnum;
- import com.fdkankan.manage.entity.CommonUpload;
- import com.fdkankan.manage.entity.DictFile;
- import com.fdkankan.manage.exception.BusinessException;
- import com.fdkankan.manage.mapper.IDictFileMapper;
- import com.fdkankan.manage.service.ICommonUploadService;
- import com.fdkankan.manage.service.IDictFileService;
- import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
- import com.fdkankan.manage.vo.request.DictFileParam;
- import com.fdkankan.manage.vo.response.DictFileVo;
- import org.apache.commons.lang3.StringUtils;
- import org.springframework.beans.BeanUtils;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.stereotype.Service;
- import java.util.ArrayList;
- import java.util.HashMap;
- import java.util.List;
- import java.util.stream.Collectors;
- /**
- * <p>
- * 服务实现类
- * </p>
- *
- * @author
- * @since 2024-12-02
- */
- @Service
- public class DictFileServiceImpl extends ServiceImpl<IDictFileMapper, DictFile> implements IDictFileService {
- @Autowired
- ICommonUploadService commonUploadService;
- @Override
- public Object pageList(DictFileParam param) {
- if(StringUtils.isBlank(param.getTypeKey())){
- throw new BusinessException(ResultCode.MISSING_REQUIRED_PARAMETERS);
- }
- LambdaQueryWrapper<DictFile> wrapper = new LambdaQueryWrapper<>();
- if(StringUtils.isNotBlank(param.getName())){
- wrapper.like(DictFile::getName,param.getName());
- }
- if(param.getDictId() != null){
- wrapper.eq(DictFile::getDictId,param.getDictId());
- }
- wrapper.eq(DictFile::getSysUserId, StpUtil.getLoginId());
- wrapper.orderByDesc(DictFile::getId);
- Page<DictFile> page = this.page(new Page<>(param.getPageNum(), param.getPageSize()), wrapper);
- List<Integer> uploadIds = page.getRecords().stream().map(DictFile::getUploadId).collect(Collectors.toList());
- HashMap<Integer,CommonUpload> map = new HashMap<>();
- if(!uploadIds.isEmpty()){
- List<CommonUpload> commonUploads = commonUploadService.listByIds(uploadIds);
- commonUploads.forEach(e -> map.put(e.getId(),e));
- }
- List<DictFileVo> voList = new ArrayList<>();
- for (DictFile record : page.getRecords()) {
- DictFileVo vo = new DictFileVo();
- BeanUtils.copyProperties(record,vo);
- CommonUpload upload = map.get(record.getUploadId());
- if(upload != null){
- BeanUtils.copyProperties(upload,vo);
- }
- voList.add(vo);
- }
- Page<DictFileVo> voPage = new Page<>(param.getPageNum(),param.getPageSize());
- voPage.setTotal(page.getTotal());
- voPage.setRecords(voList);
- return PageInfo.PageInfo(voPage);
- }
- @Override
- public void addOrUpdate(DictFile dictFile) {
- if(StringUtils.isBlank(dictFile.getName()) || StringUtils.isBlank(dictFile.getTypeKey())
- || dictFile.getDictId() == null ){
- throw new BusinessException(ResultCode.MISSING_REQUIRED_PARAMETERS);
- }
- this.saveOrUpdate(dictFile);
- }
- @Override
- public void del(DictFile dictFile) {
- if(dictFile.getId() == null){
- throw new BusinessException(ResultCode.MISSING_REQUIRED_PARAMETERS);
- }
- this.removeById(dictFile.getId());
- }
- }
|