shuhao 5 mesiacov pred
rodič
commit
5565dedf8f

+ 28 - 0
admin/src/main/java/com/flyer/foster/controller/app/AppCartoonController.java

@@ -1,13 +1,18 @@
 package com.flyer.foster.controller.app;
 
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.flyer.foster.dto.CartoonQueryDTO;
 import com.flyer.foster.service.ICartoonService;
 import com.flyer.util.R;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.PathVariable;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RestController;
 
+import java.time.LocalDate;
+import java.time.LocalDateTime;
+
 /**
  * 漫画(小程序)
  *
@@ -20,6 +25,18 @@ public class AppCartoonController {
     @Autowired
     private ICartoonService iCartoonService;
 
+
+    /**
+     * 漫画列表-分页
+     *
+     * @return
+     */
+    @GetMapping("/list/{current}/{size}")
+    public R getPageList(@PathVariable Integer current, @PathVariable Integer size, CartoonQueryDTO queryDTO) {
+        return R.ok().result(iCartoonService.getPageList(new Page<>(current, size), queryDTO));
+    }
+
+
     /**
      * 漫画列表(小程序)
      *
@@ -29,4 +46,15 @@ public class AppCartoonController {
     public R getLatestCartoon(CartoonQueryDTO queryDTO) {
         return R.ok().result(iCartoonService.getLatestCartoon(queryDTO));
     }
+
+    /**
+     * 查询今天的漫画
+     *
+     * @return
+     */
+    @GetMapping("/now")
+    public R getNowCartoon() {
+        return R.ok().result(iCartoonService.getNowCartoon(        LocalDateTime.now()
+        ));
+    }
 }

+ 12 - 0
admin/src/main/java/com/flyer/foster/dto/CartoonAddDTO.java

@@ -20,5 +20,17 @@ public class CartoonAddDTO {
     @NotBlank(message = "名称不能为空")
     private String name;
 
+    /**
+     * 开始时间
+     */
+    @NotBlank(message = "开始时间不能为空")
+    private String startTime;
+
+    /**
+     * 结束时间
+     */
+    @NotBlank(message = "结束时间不能为空")
+    private String endTime;
+
     private List<String> cartoonUrlList = new ArrayList<>();
 }

+ 11 - 0
admin/src/main/java/com/flyer/foster/dto/CartoonRespDTO.java

@@ -2,6 +2,7 @@ package com.flyer.foster.dto;
 
 import lombok.Data;
 
+import javax.validation.constraints.NotBlank;
 import java.time.LocalDateTime;
 import java.util.ArrayList;
 import java.util.List;
@@ -35,6 +36,16 @@ public class CartoonRespDTO {
     private String createdBy;
 
     /**
+     * 开始时间
+     */
+    private String startTime;
+
+    /**
+     * 结束时间
+     */
+    private String endTime;
+
+    /**
      * 创建时间
      */
     private String createdTime;

+ 12 - 0
admin/src/main/java/com/flyer/foster/dto/CartoonUpdateDTO.java

@@ -21,5 +21,17 @@ public class CartoonUpdateDTO {
      */
     private String name;
 
+    /**
+     * 开始时间
+     */
+    @NotBlank(message = "开始时间不能为空")
+    private String startTime;
+
+    /**
+     * 结束时间
+     */
+    @NotBlank(message = "结束时间不能为空")
+    private String endTime;
+
     private List<String> cartoonUrlList = new ArrayList<>();
 }

+ 9 - 0
admin/src/main/java/com/flyer/foster/service/ICartoonService.java

@@ -8,6 +8,8 @@ import com.flyer.foster.dto.CartoonUpdateDTO;
 import com.flyer.foster.entity.Cartoon;
 import com.baomidou.mybatisplus.extension.service.IService;
 
+import java.time.LocalDate;
+import java.time.LocalDateTime;
 import java.util.List;
 
 /**
@@ -35,4 +37,11 @@ public interface ICartoonService extends IService<Cartoon> {
      * @return
      */
     CartoonRespDTO getLatestCartoon(CartoonQueryDTO queryDTO);
+
+    /**
+     * 查询今天的漫画
+     * @param now
+     * @return
+     */
+    CartoonRespDTO getNowCartoon(LocalDateTime now);
 }

+ 24 - 0
admin/src/main/java/com/flyer/foster/service/impl/CartoonServiceImpl.java

@@ -16,6 +16,8 @@ import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 
+import java.time.LocalDate;
+import java.time.LocalDateTime;
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.List;
@@ -145,4 +147,26 @@ public class CartoonServiceImpl extends ServiceImpl<ICartoonMapper, Cartoon> imp
         }
         return respDTO;
     }
+
+    @Override
+    public CartoonRespDTO getNowCartoon(LocalDateTime now) {
+        CartoonRespDTO respDTO = new CartoonRespDTO();
+
+        Cartoon cartoon = this.lambdaQuery()
+                .le(Cartoon::getStartTime, now)
+                .ge(Cartoon::getEndTime, now)
+                .orderByDesc(Cartoon::getId)
+                .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;
+    }
 }