diff --git a/code/link56/link56-backend/src/main/java/cn/link56/common/mybatis/StringListTypeHandler.java b/code/link56/link56-backend/src/main/java/cn/link56/common/mybatis/StringListTypeHandler.java new file mode 100644 index 00000000..135ced8f --- /dev/null +++ b/code/link56/link56-backend/src/main/java/cn/link56/common/mybatis/StringListTypeHandler.java @@ -0,0 +1,54 @@ +package cn.link56.common.mybatis; + +import org.apache.ibatis.type.BaseTypeHandler; +import org.apache.ibatis.type.JdbcType; +import org.apache.ibatis.type.MappedJdbcTypes; +import org.apache.ibatis.type.MappedTypes; + +import java.sql.CallableStatement; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; + +@MappedTypes(List.class) +@MappedJdbcTypes(JdbcType.VARCHAR) +public class StringListTypeHandler extends BaseTypeHandler> { + + @Override + public void setNonNullParameter( + PreparedStatement ps, + int i, + List parameter, + JdbcType jdbcType + ) throws SQLException { + ps.setString(i, String.join(",", parameter)); + } + + @Override + public List getNullableResult(ResultSet rs, String columnName) + throws SQLException { + return parse(rs.getString(columnName)); + } + + @Override + public List getNullableResult(ResultSet rs, int columnIndex) + throws SQLException { + return parse(rs.getString(columnIndex)); + } + + @Override + public List getNullableResult(CallableStatement cs, int columnIndex) + throws SQLException { + return parse(cs.getString(columnIndex)); + } + + private List parse(String value) { + if (value == null || value.isEmpty()) { + return Collections.emptyList(); + } + return Arrays.asList(value.split(",")); + } +} diff --git a/code/link56/link56-backend/src/main/java/cn/link56/post/controller/PostController.java b/code/link56/link56-backend/src/main/java/cn/link56/post/controller/PostController.java index b4ca768f..b9a1fec4 100644 --- a/code/link56/link56-backend/src/main/java/cn/link56/post/controller/PostController.java +++ b/code/link56/link56-backend/src/main/java/cn/link56/post/controller/PostController.java @@ -1,16 +1,17 @@ package cn.link56.post.controller; +import cn.link56.common.BasePageVO; import cn.link56.common.Result; -import cn.link56.post.model.dto.PostAddDTO; -import cn.link56.post.model.vo.PostEditVO; -import cn.link56.post.model.vo.PostTagVO; +import cn.link56.post.model.dto.AddPostDTO; +import cn.link56.post.model.dto.QueryPostDTO; +import cn.link56.post.model.dto.UpdatePostDTO; +import cn.link56.post.model.vo.EditPostVO; +import cn.link56.post.model.vo.QueryPostVO; import cn.link56.post.service.PostService; -import cn.link56.post.service.PostTagService; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; import javax.annotation.Resource; -import java.util.List; @RestController @RequestMapping("/post") @@ -20,8 +21,20 @@ public class PostController { private PostService postService; @PostMapping("/add") - public Result addPost(@RequestBody @Validated PostAddDTO postAddDTO) { - PostEditVO postEditVO = postService.addPost(postAddDTO); - return Result.success(postEditVO); + public Result addPost(@RequestBody @Validated AddPostDTO addPostDTO) { + EditPostVO editPostVO = postService.addPost(addPostDTO); + return Result.success(editPostVO); + } + + @PostMapping("/update") + public Result updatePost(@RequestBody @Validated UpdatePostDTO updatePostDTO){ + EditPostVO editPostVO = postService.updatePost(updatePostDTO); + return Result.success(editPostVO); + } + + @PostMapping("/query") + public Result> queryPost(@RequestBody QueryPostDTO queryPostDTO){ + BasePageVO data = postService.queryPost(queryPostDTO); + return Result.success(data); } } diff --git a/code/link56/link56-backend/src/main/java/cn/link56/post/mapper/PostMapper.java b/code/link56/link56-backend/src/main/java/cn/link56/post/mapper/PostMapper.java index 75192c2b..ca6b47aa 100644 --- a/code/link56/link56-backend/src/main/java/cn/link56/post/mapper/PostMapper.java +++ b/code/link56/link56-backend/src/main/java/cn/link56/post/mapper/PostMapper.java @@ -1,9 +1,31 @@ package cn.link56.post.mapper; import cn.link56.post.model.po.PostPO; +import cn.link56.post.model.vo.QueryPostVO; import com.baomidou.mybatisplus.core.mapper.BaseMapper; import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Param; + +import java.util.List; @Mapper public interface PostMapper extends BaseMapper { + + List queryPostPage( + @Param("offset") int offset, + @Param("limit") int limit, + @Param("userId") Long userId, + @Param("title") String title, + @Param("status") Integer status, + @Param("year") String year, + @Param("month") String month + ); + + Long queryPostTotal( + @Param("userId") Long userId, + @Param("title") String title, + @Param("status") Integer status, + @Param("year") String year, + @Param("month") String month + ); } diff --git a/code/link56/link56-backend/src/main/java/cn/link56/post/model/dto/PostAddDTO.java b/code/link56/link56-backend/src/main/java/cn/link56/post/model/dto/AddPostDTO.java similarity index 95% rename from code/link56/link56-backend/src/main/java/cn/link56/post/model/dto/PostAddDTO.java rename to code/link56/link56-backend/src/main/java/cn/link56/post/model/dto/AddPostDTO.java index ca3941f8..39ec49b7 100644 --- a/code/link56/link56-backend/src/main/java/cn/link56/post/model/dto/PostAddDTO.java +++ b/code/link56/link56-backend/src/main/java/cn/link56/post/model/dto/AddPostDTO.java @@ -10,7 +10,7 @@ import java.util.List; @Data @AllArgsConstructor @NoArgsConstructor -public class PostAddDTO { +public class AddPostDTO { @NotBlank(message = "帖子标题不能为空") private String title; @NotBlank(message = "帖子内容不能为空") diff --git a/code/link56/link56-backend/src/main/java/cn/link56/post/model/dto/QueryPostDTO.java b/code/link56/link56-backend/src/main/java/cn/link56/post/model/dto/QueryPostDTO.java new file mode 100644 index 00000000..8ecb71fe --- /dev/null +++ b/code/link56/link56-backend/src/main/java/cn/link56/post/model/dto/QueryPostDTO.java @@ -0,0 +1,19 @@ +package cn.link56.post.model.dto; + +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +@Data +@AllArgsConstructor +@NoArgsConstructor +public class QueryPostDTO { + private Integer currentPage; + private Integer pageSize; + + private Integer status; + private String title; + + private String year; + private String month; +} diff --git a/code/link56/link56-backend/src/main/java/cn/link56/post/model/dto/UpdatePostDTO.java b/code/link56/link56-backend/src/main/java/cn/link56/post/model/dto/UpdatePostDTO.java new file mode 100644 index 00000000..7c3337c0 --- /dev/null +++ b/code/link56/link56-backend/src/main/java/cn/link56/post/model/dto/UpdatePostDTO.java @@ -0,0 +1,27 @@ +package cn.link56.post.model.dto; + +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +import javax.validation.constraints.NotBlank; +import javax.validation.constraints.NotNull; +import java.util.List; + +@Data +@AllArgsConstructor +@NoArgsConstructor +public class UpdatePostDTO { + @NotNull(message = "消息id不能为空") + private Long id; + @NotBlank(message = "帖子标题不能为空") + private String title; + @NotBlank(message = "帖子内容不能为空") + private String content; + @NotBlank(message = "帖子摘要不能为空") + private String summary; + private String cover; + private List tags; + + private Integer status; +} diff --git a/code/link56/link56-backend/src/main/java/cn/link56/post/model/enums/PostStatusEnum.java b/code/link56/link56-backend/src/main/java/cn/link56/post/model/enums/PostStatusEnum.java new file mode 100644 index 00000000..3dae667b --- /dev/null +++ b/code/link56/link56-backend/src/main/java/cn/link56/post/model/enums/PostStatusEnum.java @@ -0,0 +1,16 @@ +package cn.link56.post.model.enums; + +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.Getter; + +@Getter +@AllArgsConstructor +public enum PostStatusEnum { + DRAFT(0, "草稿"), + PUBLISHED(1, "已发布"), + OFFLINE(2, "已下架"); + + private final int code; + private final String desc; +} diff --git a/code/link56/link56-backend/src/main/java/cn/link56/post/model/po/PostPO.java b/code/link56/link56-backend/src/main/java/cn/link56/post/model/po/PostPO.java index c8aed793..fff82610 100644 --- a/code/link56/link56-backend/src/main/java/cn/link56/post/model/po/PostPO.java +++ b/code/link56/link56-backend/src/main/java/cn/link56/post/model/po/PostPO.java @@ -39,7 +39,7 @@ public class PostPO { private String cover; @TableField("b_publish_time") - private String publishTime; + private Date publishTime; @TableField("b_status") private Integer status; diff --git a/code/link56/link56-backend/src/main/java/cn/link56/post/model/vo/PostEditVO.java b/code/link56/link56-backend/src/main/java/cn/link56/post/model/vo/EditPostVO.java similarity index 85% rename from code/link56/link56-backend/src/main/java/cn/link56/post/model/vo/PostEditVO.java rename to code/link56/link56-backend/src/main/java/cn/link56/post/model/vo/EditPostVO.java index 71207ccf..2e941b22 100644 --- a/code/link56/link56-backend/src/main/java/cn/link56/post/model/vo/PostEditVO.java +++ b/code/link56/link56-backend/src/main/java/cn/link56/post/model/vo/EditPostVO.java @@ -1,6 +1,5 @@ package cn.link56.post.model.vo; -import com.fasterxml.jackson.annotation.JsonFormat; import lombok.AllArgsConstructor; import lombok.Data; import lombok.NoArgsConstructor; @@ -11,7 +10,7 @@ import java.util.List; @Data @AllArgsConstructor @NoArgsConstructor -public class PostEditVO { +public class EditPostVO { private Long id; private String title; private String content; diff --git a/code/link56/link56-backend/src/main/java/cn/link56/post/model/vo/QueryPostVO.java b/code/link56/link56-backend/src/main/java/cn/link56/post/model/vo/QueryPostVO.java new file mode 100644 index 00000000..47311bcc --- /dev/null +++ b/code/link56/link56-backend/src/main/java/cn/link56/post/model/vo/QueryPostVO.java @@ -0,0 +1,28 @@ +package cn.link56.post.model.vo; + +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.util.Date; +import java.util.List; + +@Data +@AllArgsConstructor +@NoArgsConstructor +public class QueryPostVO { + private Long id; + + private String title; + private String cover; + private List tags; + + private Date updateTime; + private Date publishTime; + private Integer status; + + private Integer viewCount; + private Integer likeCount; + private Integer favoriteCount; + private Integer commentCount; +} diff --git a/code/link56/link56-backend/src/main/java/cn/link56/post/service/PostService.java b/code/link56/link56-backend/src/main/java/cn/link56/post/service/PostService.java index 7fc80e84..445161ba 100644 --- a/code/link56/link56-backend/src/main/java/cn/link56/post/service/PostService.java +++ b/code/link56/link56-backend/src/main/java/cn/link56/post/service/PostService.java @@ -1,17 +1,31 @@ package cn.link56.post.service; +import cn.link56.common.BasePageVO; import cn.link56.common.context.UserContext; +import cn.link56.common.utils.snowflake.idgen.IdGenerator; +import cn.link56.company.model.po.CompanyUserPO; import cn.link56.post.mapper.PostMapper; -import cn.link56.post.model.dto.PostAddDTO; +import cn.link56.post.model.dto.AddPostDTO; +import cn.link56.post.model.dto.QueryPostDTO; +import cn.link56.post.model.dto.UpdatePostDTO; +import cn.link56.post.model.enums.PostStatusEnum; import cn.link56.post.model.po.PostPO; -import cn.link56.post.model.vo.PostEditVO; +import cn.link56.post.model.vo.EditPostVO; +import cn.link56.post.model.vo.QueryPostVO; +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import org.apache.commons.lang3.ObjectUtils; import org.apache.commons.lang3.StringUtils; import org.springframework.beans.BeanUtils; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import javax.annotation.Resource; +import java.util.Arrays; +import java.util.Date; +import java.util.List; +import java.util.stream.Collectors; @Service public class PostService extends ServiceImpl { @@ -19,21 +33,68 @@ public class PostService extends ServiceImpl { private PostMapper postMapper; @Transactional - public PostEditVO addPost(PostAddDTO postAddDTO) { + public EditPostVO addPost(AddPostDTO addPostDTO) { PostPO postPO = new PostPO(); - BeanUtils.copyProperties(postAddDTO, postPO); + BeanUtils.copyProperties(addPostDTO, postPO); - postPO.setTag(StringUtils.join(postAddDTO.getTags(), ",")); + postPO.setTag(StringUtils.join(addPostDTO.getTags(), ",")); postPO.setCompanyId(UserContext.getCompanyId()); + if(addPostDTO.getStatus() == PostStatusEnum.PUBLISHED.getCode()){ + postPO.setPublishTime(new Date()); + } + + postPO.setId(IdGenerator.nextId()); postMapper.insert(postPO); - PostEditVO postEditVO = new PostEditVO(); + EditPostVO editPostVO = new EditPostVO(); - BeanUtils.copyProperties(postPO, postEditVO); - postEditVO.setTags(postAddDTO.getTags()); + BeanUtils.copyProperties(postPO, editPostVO); + editPostVO.setTags(addPostDTO.getTags()); - return postEditVO; + return editPostVO; + } + + public BasePageVO queryPost(QueryPostDTO queryPostDTO) { + Integer currentPage = queryPostDTO.getCurrentPage(); + Integer pageSize = queryPostDTO.getPageSize(); + + String title = queryPostDTO.getTitle(); + Integer status = queryPostDTO.getStatus(); + String year = queryPostDTO.getYear(); + String month = queryPostDTO.getMonth(); + + int offset = (currentPage - 1) * pageSize + 1; + int limit = currentPage * pageSize; + + List queryPostVOS = postMapper.queryPostPage(offset, limit, UserContext.getUserId(), title, status, year, month); + Long total = postMapper.queryPostTotal(UserContext.getUserId(), title, status, year, month); + + BasePageVO result = new BasePageVO<>(); + result.setRecords(queryPostVOS); + result.setTotal(total); + + return result; + } + + public EditPostVO updatePost(UpdatePostDTO updatePostDTO) { + Long id = updatePostDTO.getId(); + + PostPO postPO = postMapper.selectById(id); + + System.out.println(postPO); + + BeanUtils.copyProperties(updatePostDTO,postPO); + postPO.setTag(StringUtils.join(updatePostDTO.getTags(), ",")); + + postMapper.updateById(postPO); + + EditPostVO editPostVO = new EditPostVO(); + + BeanUtils.copyProperties(postPO, editPostVO); + editPostVO.setTags(updatePostDTO.getTags()); + + return editPostVO; } } diff --git a/code/link56/link56-backend/src/main/resources/cn/link56/post/mapper/PostMapper.xml b/code/link56/link56-backend/src/main/resources/cn/link56/post/mapper/PostMapper.xml new file mode 100644 index 00000000..6a8fc3b2 --- /dev/null +++ b/code/link56/link56-backend/src/main/resources/cn/link56/post/mapper/PostMapper.xml @@ -0,0 +1,98 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/code/link56/link56-frontend-new/src/components/CustomEmpty.vue b/code/link56/link56-frontend-new/src/components/CustomEmpty.vue index 35e3254c..a03cf74d 100644 --- a/code/link56/link56-frontend-new/src/components/CustomEmpty.vue +++ b/code/link56/link56-frontend-new/src/components/CustomEmpty.vue @@ -4,9 +4,7 @@ import { computed } from 'vue' const props = defineProps({ title: { type: String, - }, - subTitle: { - type: String, + default: '这里什么也没有', }, inContainer: { type: Boolean, @@ -28,10 +26,6 @@ const containerClass = computed(() => { {{ title }} -
- {{ subTitle }} -
-
@@ -70,18 +64,10 @@ const containerClass = computed(() => { .empty-title { margin-top: 24px; - font-size: 24px; - font-weight: 600; - color: #333; - line-height: 1.4; -} - -.empty-subtitle { - margin-top: 12px; font-size: 18px; + font-weight: 500; color: #666; - line-height: 1.6; - max-width: 360px; + line-height: 1.4; } .empty-extra { diff --git a/code/link56/link56-frontend-new/src/request/api/post/index.ts b/code/link56/link56-frontend-new/src/request/api/post/index.ts index 8d91b31f..d1197183 100644 --- a/code/link56/link56-frontend-new/src/request/api/post/index.ts +++ b/code/link56/link56-frontend-new/src/request/api/post/index.ts @@ -1,6 +1,15 @@ -import type { AddPostParams, PostEditorForm } from '@/types/post' +import type { AddPostParams, Post, PostEditorForm, QueryPostParams, UpdatePostParams } from '@/types/post/editor' + import { httpGet, httpPostJson } from '@/request/utils' export function addPostApi(params: AddPostParams) { return httpPostJson('/post/add', params) } + +export function updatePostApi(params: UpdatePostParams) { + return httpPostJson('/post/update', params) +} + +export function queryPostApi(params: QueryPostParams) { + return httpPostJson>('/post/query', params) +} diff --git a/code/link56/link56-frontend-new/src/router/index.ts b/code/link56/link56-frontend-new/src/router/index.ts index 9ea970a7..5d56e293 100644 --- a/code/link56/link56-frontend-new/src/router/index.ts +++ b/code/link56/link56-frontend-new/src/router/index.ts @@ -52,7 +52,7 @@ const router = createRouter({ component: () => import('@/views/settings/creator/home.vue'), }, { - path: '/settings/creator/editor', + path: '/settings/creator/editor/:id?', component: () => import('@/views/settings/creator/editor.vue'), }, { diff --git a/code/link56/link56-frontend-new/src/styles/css/global.css b/code/link56/link56-frontend-new/src/styles/css/global.css index d9acece5..fc8340b2 100644 --- a/code/link56/link56-frontend-new/src/styles/css/global.css +++ b/code/link56/link56-frontend-new/src/styles/css/global.css @@ -1,4 +1,5 @@ -html, body { +html, +body { background-color: #f7f7f7; } diff --git a/code/link56/link56-frontend-new/src/types/auto-import.d.ts b/code/link56/link56-frontend-new/src/types/auto-import.d.ts index d8db3306..9d117c0d 100644 --- a/code/link56/link56-frontend-new/src/types/auto-import.d.ts +++ b/code/link56/link56-frontend-new/src/types/auto-import.d.ts @@ -31,6 +31,7 @@ declare module 'vue' { 'IIc:outlineSettings': typeof import('~icons/ic/outline-settings')['default'] 'IIc:twotoneHeadphones': typeof import('~icons/ic/twotone-headphones')['default'] 'IIconoir:infoCircleSolid': typeof import('~icons/iconoir/info-circle-solid')['default'] + 'IIon:iosMore': typeof import('~icons/ion/ios-more')['default'] ImageUploadCard: typeof import('./../components/ImageUploadCard.vue')['default'] 'IMajesticons:settingsCogLine': typeof import('~icons/majesticons/settings-cog-line')['default'] 'IMaterialSymbols:call': typeof import('~icons/material-symbols/call')['default'] diff --git a/code/link56/link56-frontend-new/src/types/post/editor.ts b/code/link56/link56-frontend-new/src/types/post/editor.ts new file mode 100644 index 00000000..53608b82 --- /dev/null +++ b/code/link56/link56-frontend-new/src/types/post/editor.ts @@ -0,0 +1,63 @@ +export enum PostStatusEnum { + DRAFT = 0, // 草稿 + PUBLISHED = 1, // 已发布 + OFFLINE = 2, // 已下架 +} + +export interface PostEditorForm { + id: number + title: string + content: string + summary: string + cover: string + tags: string[] + status: number + publishTime: string + updateTime: string +} + +export interface AddPostParams { + title: string + content: string + summary: string + cover: string + status: number + tags: string[] +} + +export interface UpdatePostParams { + id: number + title: string + content: string + summary: string + cover: string + status: number + tags: string[] +} + +export interface QueryPostParams { + currentPage: number + pageSize: number + + status: number + title: string + + year: string + month: string +} + +export interface Post { + id: number + title: string + cover: string + tags: string[] + + status: number + updateTime: string + publishTime: string + + viewCount: number + likeCount: number + favoriteCount: number + commentCount: number +} diff --git a/code/link56/link56-frontend-new/src/types/post/index.ts b/code/link56/link56-frontend-new/src/types/post/index.ts index 116fe920..e69de29b 100644 --- a/code/link56/link56-frontend-new/src/types/post/index.ts +++ b/code/link56/link56-frontend-new/src/types/post/index.ts @@ -1,20 +0,0 @@ -export interface PostEditorForm { - id: number - title: string - content: string - summary: string - cover: string - tags: string[] - status: number - publishTime: string - updateTime: string -} - -export interface AddPostParams { - title: string - content: string - summary: string - cover: string - status: number - tags: string[] -} diff --git a/code/link56/link56-frontend-new/src/views/settings/creator/editor.vue b/code/link56/link56-frontend-new/src/views/settings/creator/editor.vue index 542db8cb..ffdf56dd 100644 --- a/code/link56/link56-frontend-new/src/views/settings/creator/editor.vue +++ b/code/link56/link56-frontend-new/src/views/settings/creator/editor.vue @@ -1,17 +1,23 @@ @@ -153,10 +190,10 @@ async function handleSave(formEl: FormInstance | undefined) {