|
@@ -0,0 +1,147 @@
|
|
|
+package com.flyer.foster.service.impl;
|
|
|
+
|
|
|
+import cn.hutool.core.bean.BeanUtil;
|
|
|
+import cn.hutool.core.util.StrUtil;
|
|
|
+import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
+import com.flyer.exception.BusinessException;
|
|
|
+import com.flyer.foster.dto.*;
|
|
|
+import com.flyer.foster.entity.Cartoon;
|
|
|
+import com.flyer.foster.entity.CartoonUrl;
|
|
|
+import com.flyer.foster.entity.PosterLib;
|
|
|
+import com.flyer.foster.mapper.ICartoonMapper;
|
|
|
+import com.flyer.foster.service.ICartoonService;
|
|
|
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
+import com.flyer.foster.service.ICartoonUrlService;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
+
|
|
|
+import java.time.LocalDateTime;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.Arrays;
|
|
|
+import java.util.Collections;
|
|
|
+import java.util.List;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
+/**
|
|
|
+ * <p>
|
|
|
+ * 漫画 服务实现类
|
|
|
+ * </p>
|
|
|
+ *
|
|
|
+ * @author flyer
|
|
|
+ * @since 2024-05-25
|
|
|
+ */
|
|
|
+@Service
|
|
|
+public class CartoonServiceImpl extends ServiceImpl<ICartoonMapper, Cartoon> implements ICartoonService {
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private ICartoonUrlService iCartoonUrlService;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public IPage<CartoonRespDTO> getPageList(IPage<Cartoon> page, CartoonQueryDTO queryDTO) {
|
|
|
+ IPage<CartoonRespDTO> pageResult = new Page<>(page.getCurrent(), page.getSize());
|
|
|
+
|
|
|
+ IPage<Cartoon> pageInfo = this.lambdaQuery()
|
|
|
+ .like(StrUtil.isNotBlank(queryDTO.getName()), Cartoon::getName, queryDTO.getName())
|
|
|
+ .page(page);
|
|
|
+
|
|
|
+ List<CartoonRespDTO> list = new ArrayList<>();
|
|
|
+ CartoonRespDTO respDTO;
|
|
|
+ for (Cartoon cartoon : pageInfo.getRecords()) {
|
|
|
+ respDTO = new CartoonRespDTO();
|
|
|
+ BeanUtil.copyProperties(cartoon, respDTO);
|
|
|
+ list.add(respDTO);
|
|
|
+ }
|
|
|
+ pageResult.setRecords(list);
|
|
|
+ pageResult.setTotal(pageInfo.getTotal());
|
|
|
+ return pageResult;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Transactional
|
|
|
+ @Override
|
|
|
+ public boolean addCartoon(CartoonAddDTO addDTO) {
|
|
|
+ Cartoon cartoon = new Cartoon();
|
|
|
+ BeanUtil.copyProperties(addDTO, cartoon);
|
|
|
+ this.save(cartoon);
|
|
|
+
|
|
|
+ List<CartoonUrl> cartoonUrlList = new ArrayList<>();
|
|
|
+ CartoonUrl cartoonUrl;
|
|
|
+ int sort = 1;
|
|
|
+ for (String url : addDTO.getCartoonUrlList()) {
|
|
|
+ cartoonUrl = new CartoonUrl();
|
|
|
+ cartoonUrl.setCartoonId(cartoon.getId());
|
|
|
+ cartoonUrl.setUrl(url);
|
|
|
+ cartoonUrl.setSort(sort++);
|
|
|
+ cartoonUrlList.add(cartoonUrl);
|
|
|
+ }
|
|
|
+ if (cartoonUrlList.size() != 0) {
|
|
|
+ // 插入漫画地址
|
|
|
+ iCartoonUrlService.saveBatch(cartoonUrlList);
|
|
|
+ }
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Transactional
|
|
|
+ @Override
|
|
|
+ public boolean deleteByIdList(List<Integer> idList) {
|
|
|
+ // 删除漫画
|
|
|
+ baseMapper.deleteByIdList(idList);
|
|
|
+ // 删除漫画地址
|
|
|
+ iCartoonUrlService.deleteByCartoonIdList(idList);
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Transactional
|
|
|
+ @Override
|
|
|
+ public boolean updateCartoon(CartoonUpdateDTO updateDTO) {
|
|
|
+ Cartoon cartoon = this.lambdaQuery().eq(Cartoon::getId, updateDTO.getId()).one();
|
|
|
+ if (cartoon == null) {
|
|
|
+ throw new BusinessException("无效的漫画id");
|
|
|
+ }
|
|
|
+ BeanUtil.copyProperties(updateDTO, cartoon);
|
|
|
+ this.saveOrUpdate(cartoon);
|
|
|
+
|
|
|
+ if (updateDTO.getCartoonUrlList().size() != 0) {
|
|
|
+ // 删除漫画地址
|
|
|
+ iCartoonUrlService.deleteByCartoonIdList(Collections.singletonList(cartoon.getId()));
|
|
|
+
|
|
|
+ List<CartoonUrl> cartoonUrlList = new ArrayList<>();
|
|
|
+ CartoonUrl cartoonUrl;
|
|
|
+ int sort = 1;
|
|
|
+ for (String url : updateDTO.getCartoonUrlList()) {
|
|
|
+ cartoonUrl = new CartoonUrl();
|
|
|
+ cartoonUrl.setCartoonId(cartoon.getId());
|
|
|
+ cartoonUrl.setUrl(url);
|
|
|
+ cartoonUrl.setSort(sort++);
|
|
|
+ cartoonUrlList.add(cartoonUrl);
|
|
|
+ }
|
|
|
+ if (cartoonUrlList.size() != 0) {
|
|
|
+ // 插入漫画地址
|
|
|
+ iCartoonUrlService.saveBatch(cartoonUrlList);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public CartoonRespDTO getLatestCartoon(CartoonQueryDTO queryDTO) {
|
|
|
+ CartoonRespDTO respDTO = new CartoonRespDTO();
|
|
|
+
|
|
|
+ Cartoon cartoon = this.lambdaQuery()
|
|
|
+ .like(StrUtil.isNotBlank(queryDTO.getName()), Cartoon::getName, queryDTO.getName())
|
|
|
+ .orderByDesc(Cartoon::getCreatedTime)
|
|
|
+ .last("limit 1")
|
|
|
+ .one();
|
|
|
+ BeanUtil.copyProperties(cartoon, respDTO);
|
|
|
+ // 获取漫画地址
|
|
|
+ if (cartoon != null) {
|
|
|
+ List<CartoonUrl> cartoonUrlList = iCartoonUrlService.lambdaQuery()
|
|
|
+ .eq(CartoonUrl::getCartoonId, cartoon.getId())
|
|
|
+ .list();
|
|
|
+ // 地址集合
|
|
|
+ respDTO.setCartoonUrlList(cartoonUrlList.stream().map(CartoonUrl::getUrl).collect(Collectors.toList()));
|
|
|
+ }
|
|
|
+ return respDTO;
|
|
|
+ }
|
|
|
+}
|