123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245 |
- package com.ruoyi.system.service.impl;
- import cn.hutool.core.util.StrUtil;
- import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
- import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
- import com.ruoyi.common.config.RuoYiConfig;
- import com.ruoyi.common.enums.CommentType;
- import com.ruoyi.common.exception.BaseException;
- import com.ruoyi.common.utils.DateUtils;
- import com.ruoyi.common.utils.SecurityUtils;
- import com.ruoyi.common.utils.bean.BeanUtils;
- import com.ruoyi.system.domain.ZbFile;
- import com.ruoyi.system.domain.grallery.ZbGallery;
- import com.ruoyi.system.domain.grallery.ZbGalleryCategory;
- import com.ruoyi.system.domain.grallery.ZbGalleryImg;
- import com.ruoyi.system.dto.GalleryCategoryDto;
- import com.ruoyi.system.dto.GalleryDto;
- import com.ruoyi.system.dto.GalleryImgDto;
- import com.ruoyi.system.mapper.ZbGalleryMapper;
- import com.ruoyi.system.service.IZbCommentService;
- import com.ruoyi.system.service.IZbGalleryCategoryService;
- import com.ruoyi.system.service.IZbGalleryImgService;
- import com.ruoyi.system.service.IZbGalleryService;
- import lombok.RequiredArgsConstructor;
- import org.springframework.stereotype.Service;
- import org.springframework.transaction.annotation.Transactional;
- import java.util.*;
- import java.util.stream.Collectors;
- /**
- * 【请填写功能名称】Service业务层处理
- *
- * @author ruoyi
- * @date 2020-11-20
- */
- @Service
- @RequiredArgsConstructor
- public class ZbGalleryServiceImpl extends ServiceImpl<ZbGalleryMapper, ZbGallery> implements IZbGalleryService {
- private final IZbGalleryImgService galleryImgService;
- private final RuoYiConfig ruoYiConfig;
- private final IZbCommentService commentService;
- private final IZbGalleryCategoryService galleryCategoryService;
- private final ZbFileServiceImpl zbFileService;
- /**
- * 查询【请填写功能名称】列表
- *
- * @param zbGallery 【请填写功能名称】
- * @return 【请填写功能名称】
- */
- @Override
- public List<GalleryDto> selectZbGalleryList(ZbGallery zbGallery, Page<ZbGallery> page) {
- return baseMapper.selectZbGalleryList(zbGallery, page);
- }
- /**
- * 新增【请填写功能名称】
- *
- * @param zbGallery 【请填写功能名称】
- * @return 结果
- */
- @Override
- @Transactional(rollbackFor = Exception.class)
- public boolean insertZbGallery(GalleryDto zbGallery) {
- ZbGallery gallery = new ZbGallery();
- BeanUtils.copyBeanProp(gallery, zbGallery);
- Date nowDate = DateUtils.getNowDate();
- gallery.setCreateTime(nowDate);
- String createBy = SecurityUtils.getUserId().toString();
- gallery.setCreateBy(createBy);
- int insert = baseMapper.insert(gallery);
- if (insert <= 0) {
- throw new BaseException("图库保存失败");
- }
- //判断是否新增图库时,新增了图片
- if (zbGallery.getImgInfos().size() > 0) {
- List<ZbGalleryImg> imgList = zbGallery.getImgInfos().stream().filter(e -> e.getId() != null).map(x -> {
- ZbGalleryImg galleryImg = new ZbGalleryImg();
- galleryImg.setAuthor(x.getAuthor());
- galleryImg.setLocation(x.getLocation());
- galleryImg.setGallertId(gallery.getId());
- galleryImg.setQrCodeId(x.getQrCode());
- galleryImg.setThumbId(x.getId());
- galleryImg.setWatermarkType(x.getWatermarkType());
- galleryImg.setWatermarkColor(x.getWatermarkColor());
- galleryImg.setCreateBy(createBy);
- galleryImg.setCreateTime(nowDate);
- galleryImg.setAuthorConcat(x.getConcat());
- galleryImg.setRemark(x.getRemark());
- return galleryImg;
- }).collect(Collectors.toList());
- if (imgList.size() > 0) {
- galleryImgService.saveBatch(imgList);
- }
- }
- return true;
- }
- /**
- * 修改【请填写功能名称】
- *
- * @param zbGallery 【请填写功能名称】
- * @return 结果
- */
- @Override
- @Transactional(rollbackFor = Exception.class)
- public boolean updateZbGallery(GalleryDto zbGallery) {
- ZbGallery gallery = new ZbGallery();
- BeanUtils.copyBeanProp(gallery, zbGallery);
- gallery.setCategoryId(zbGallery.getCategoryId());
- Date nowDate = DateUtils.getNowDate();
- gallery.setCreateTime(nowDate);
- String createBy = SecurityUtils.getUserId().toString();
- gallery.setCreateBy(createBy);
- int insert = baseMapper.updateById(gallery);
- if (insert <= 0) {
- throw new BaseException("图库保存失败");
- }
- Long galleryId = gallery.getId();
- //对应图片信息删除
- galleryImgService.removeByGalleryId(galleryId);
- //判断是否修改图库时,是否包含图片
- if (zbGallery.getImgInfos().size() > 0) {
- List<ZbGalleryImg> imgList = zbGallery.getImgInfos().stream().filter(e -> e.getId() != null).map(x -> {
- ZbGalleryImg galleryImg = new ZbGalleryImg();
- galleryImg.setAuthor(x.getAuthor());
- galleryImg.setLocation(x.getLocation());
- galleryImg.setGallertId(galleryId);
- galleryImg.setQrCodeId(x.getQrCode());
- galleryImg.setThumbId(x.getId());
- galleryImg.setWatermarkColor(x.getWatermarkColor());
- galleryImg.setWatermarkType(x.getWatermarkType());
- galleryImg.setCreateBy(createBy);
- galleryImg.setCreateTime(nowDate);
- galleryImg.setAuthorConcat(x.getConcat());
- galleryImg.setRemark(x.getRemark());
- return galleryImg;
- }).collect(Collectors.toList());
- if (imgList.size() > 0) {
- galleryImgService.saveBatch(imgList);
- }
- }
- return true;
- }
- @Override
- public GalleryDto getByGalleryId(Long id) {
- ZbGallery gallery = getById(id);
- if (gallery == null) {
- throw new BaseException("图库信息不存在");
- }
- GalleryDto galleryDto = new GalleryDto();
- BeanUtils.copyBeanProp(galleryDto, gallery);
- galleryDto.setId(gallery.getId());
- galleryDto.setSort(gallery.getSort());
- List<GalleryImgDto> galleryImg = galleryImgService.getByGalleryId(id);
- List<GalleryDto.ImgInfosDTO> infosDTOList = galleryImg.stream().map(x -> {
- GalleryDto.ImgInfosDTO imgInfosDTO = new GalleryDto.ImgInfosDTO();
- imgInfosDTO.setAuthor(x.getAuthor());
- imgInfosDTO.setId(x.getFileId());
- imgInfosDTO.setLocation(x.getLocation());
- imgInfosDTO.setQrCode(x.getQrCode());
- imgInfosDTO.setRemark(x.getRemark());
- imgInfosDTO.setConcat(x.getConcat());
- if (StrUtil.isNotBlank(x.getQrCodeUrl())) {
- imgInfosDTO.setQrCodeUrl(ruoYiConfig.getUrl() + x.getQrCodeUrl());
- }
- imgInfosDTO.setUrl(ruoYiConfig.getUrl() + x.getUrl());
- imgInfosDTO.setWatermarkType(x.getWatermarkType());
- imgInfosDTO.setWatermarkColor(x.getWatermarkColor());
- return imgInfosDTO;
- }).collect(Collectors.toList());
- galleryDto.setImgInfos(infosDTOList);
- return galleryDto;
- }
- /**
- * 删除图库
- * @param gallerys
- * @return
- */
- @Override
- @Transactional(rollbackFor = Exception.class)
- public boolean delGallery(List<Long> gallerys) {
- //删除图库表
- this.removeByIds(gallerys);
- //先删除附件表信息和服务器存储数据
- List<ZbGalleryImg> zbGalleryImgs = galleryImgService.selectByGalleryIds(gallerys);
- for (ZbGalleryImg zbGalleryImg : zbGalleryImgs) {
- ZbFile zbFile = new ZbFile();
- zbFile.setId(zbGalleryImg.getThumbId());
- zbFileService.deletePicture(zbFile);
- }
- //删除图库图片信息表
- galleryImgService.removeByGalleryIds(gallerys);
- //删除评论信息
- commentService.removeByTypeAndFk(CommentType.GALLERY, gallerys);
- return true;
- }
- @Override
- public Page<GalleryDto> selectGalleryDto(String categoryCode, Long categoryId, Page<GalleryDto> pageInfo) {
- List<Long> categorys = new ArrayList<>();
- if (StrUtil.isNotBlank(categoryCode) && categoryId == null) {
- ZbGalleryCategory category = galleryCategoryService.getByCode(categoryCode);
- if (category != null) {
- categoryId = category.getId();
- }
- }
- if (categoryId != null) {
- categorys = StrUtil.split(galleryCategoryService.getChildrens(categoryId), ',')
- .stream().map(Long::valueOf).collect(Collectors.toList());
- }
- String profile = ruoYiConfig.getUrl();
- /* List<GalleryDto> galleryDtos = baseMapper.selectGalleryDto(categorys, pageInfo)
- .stream().peek(
- x -> x.getImgInfos().forEach(i -> i.setUrl(profile + i.getUrl()))
- ).collect(Collectors.toList());*/
- //获取预览地址
- List<GalleryDto> galleryDtos = baseMapper.selectGalleryDtoThumbnail(categorys, pageInfo)
- .stream().peek(
- x -> x.getImgInfos().forEach(i -> i.setUrl(profile + i.getUrl()))
- ).collect(Collectors.toList());
- pageInfo.setRecords(galleryDtos);
- return pageInfo;
- }
- @Override
- public Integer checkCategoryHasValue(Long categoryId) {
- return baseMapper.checkCategoryHasValue(categoryId);
- }
- }
|