+ * APP用户信息表 + *
+ * + * @author itheima + */ +@Data +@TableName("ap_user") +public class ApUser implements Serializable { + + private static final long serialVersionUID = 1L; + + /** + * 主键 + */ + @TableId(value = "id", type = IdType.AUTO) + private Integer id; + + /** + * 密码、通信等加密盐 + */ + @TableField("salt") + private String salt; + + /** + * 用户名 + */ + @TableField("name") + private String name; + + /** + * 密码,md5加密 + */ + @TableField("password") + private String password; + + /** + * 手机号 + */ + @TableField("phone") + private String phone; + + /** + * 头像 + */ + @TableField("image") + private String image; + + /** + * 0 男 + 1 女 + 2 未知 + */ + @TableField("sex") + private Boolean sex; + + /** + * 0 未 + 1 是 + */ + @TableField("is_certification") + private Boolean certification; + + /** + * 是否身份认证 + */ + @TableField("is_identity_authentication") + private Boolean identityAuthentication; + + /** + * 0正常 + 1锁定 + */ + @TableField("status") + private Boolean status; + + /** + * 0 普通用户 + 1 自媒体人 + 2 大V + */ + @TableField("flag") + private Short flag; + + /** + * 注册时间 + */ + @TableField("created_time") + private Date createdTime; + +} \ No newline at end of file diff --git a/heima-leadnews-service/heima-leadnews-user/pom.xml b/heima-leadnews-service/heima-leadnews-user/pom.xml new file mode 100644 index 00000000..5c5ca4d7 --- /dev/null +++ b/heima-leadnews-service/heima-leadnews-user/pom.xml @@ -0,0 +1,19 @@ + ++ * 文章信息表,存储已发布的文章 + *
+ * + * @author itheima + */ + +@Data +@TableName("ap_article") +public class ApArticle implements Serializable { + + @TableId(value = "id",type = IdType.ASSIGN_ID) + private Long id; + + + /** + * 标题 + */ + private String title; + + /** + * 作者id + */ + @TableField("author_id") + private Long authorId; + + /** + * 作者名称 + */ + @TableField("author_name") + private String authorName; + + /** + * 频道id + */ + @TableField("channel_id") + private Integer channelId; + + /** + * 频道名称 + */ + @TableField("channel_name") + private String channelName; + + /** + * 文章布局 0 无图文章 1 单图文章 2 多图文章 + */ + private Short layout; + + /** + * 文章标记 0 普通文章 1 热点文章 2 置顶文章 3 精品文章 4 大V 文章 + */ + private Byte flag; + + /** + * 文章封面图片 多张逗号分隔 + */ + private String images; + + /** + * 标签 + */ + private String labels; + + /** + * 点赞数量 + */ + private Integer likes; + + /** + * 收藏数量 + */ + private Integer collection; + + /** + * 评论数量 + */ + private Integer comment; + + /** + * 阅读数量 + */ + private Integer views; + + /** + * 省市 + */ + @TableField("province_id") + private Integer provinceId; + + /** + * 市区 + */ + @TableField("city_id") + private Integer cityId; + + /** + * 区县 + */ + @TableField("county_id") + private Integer countyId; + + /** + * 创建时间 + */ + @TableField("created_time") + private Date createdTime; + + /** + * 发布时间 + */ + @TableField("publish_time") + private Date publishTime; + + /** + * 同步状态 + */ + @TableField("sync_status") + private Boolean syncStatus; + + /** + * 来源 + */ + private Boolean origin; + + /** + * 静态页面地址 + */ + @TableField("static_url") + private String staticUrl; +} diff --git a/heima-leadnews-model/src/main/java/com/heima/model/article/pojos/ApArticleConfig.java b/heima-leadnews-model/src/main/java/com/heima/model/article/pojos/ApArticleConfig.java new file mode 100644 index 00000000..e01bae86 --- /dev/null +++ b/heima-leadnews-model/src/main/java/com/heima/model/article/pojos/ApArticleConfig.java @@ -0,0 +1,63 @@ +package com.heima.model.article.pojos; + +import com.baomidou.mybatisplus.annotation.IdType; +import com.baomidou.mybatisplus.annotation.TableField; +import com.baomidou.mybatisplus.annotation.TableId; +import com.baomidou.mybatisplus.annotation.TableName; +import lombok.Data; + +import java.io.Serializable; + +/** + *+ * APP已发布文章配置表 + *
+ * + * @author itheima + */ + +@Data +@TableName("ap_article_config") +public class ApArticleConfig implements Serializable { + + @TableId(value = "id",type = IdType.ASSIGN_ID) + private Long id; + + /** + * 文章id + */ + @TableField("article_id") + private Long articleId; + + /** + * 是否可评论 + * true: 可以评论 1 + * false: 不可评论 0 + */ + @TableField("is_comment") + private Boolean isComment; + + /** + * 是否转发 + * true: 可以转发 1 + * false: 不可转发 0 + */ + @TableField("is_forward") + private Boolean isForward; + + /** + * 是否下架 + * true: 下架 1 + * false: 没有下架 0 + */ + @TableField("is_down") + private Boolean isDown; + + /** + * 是否已删除 + * true: 删除 1 + * false: 没有删除 0 + */ + @TableField("is_delete") + private Boolean isDelete; +} diff --git a/heima-leadnews-model/src/main/java/com/heima/model/article/pojos/ApArticleContent.java b/heima-leadnews-model/src/main/java/com/heima/model/article/pojos/ApArticleContent.java new file mode 100644 index 00000000..c71583f5 --- /dev/null +++ b/heima-leadnews-model/src/main/java/com/heima/model/article/pojos/ApArticleContent.java @@ -0,0 +1,28 @@ +package com.heima.model.article.pojos; + +import com.baomidou.mybatisplus.annotation.IdType; +import com.baomidou.mybatisplus.annotation.TableField; +import com.baomidou.mybatisplus.annotation.TableId; +import com.baomidou.mybatisplus.annotation.TableName; +import lombok.Data; + +import java.io.Serializable; + +@Data +@TableName("ap_article_content") +public class ApArticleContent implements Serializable { + + @TableId(value = "id",type = IdType.ASSIGN_ID) + private Long id; + + /** + * 文章id + */ + @TableField("article_id") + private Long articleId; + + /** + * 文章内容 + */ + private String content; +} diff --git a/heima-leadnews-model/src/main/java/com/heima/model/article/vos/ApArticleVo.java b/heima-leadnews-model/src/main/java/com/heima/model/article/vos/ApArticleVo.java new file mode 100644 index 00000000..b083a5f7 --- /dev/null +++ b/heima-leadnews-model/src/main/java/com/heima/model/article/vos/ApArticleVo.java @@ -0,0 +1,125 @@ +package com.heima.model.article.vos; + +import lombok.Data; + +import java.io.Serializable; +import java.util.Date; + +/** + *+ * 文章信息表,存储已发布的文章 + *
+ * + * @author itheima + */ + +@Data +public class ApArticleVo implements Serializable { + + private String id; + + /** + * 标题 + */ + private String title; + + /** + * 作者id + */ + private Long authorId; + + /** + * 作者名称 + */ + private String authorName; + + /** + * 频道id + */ + private Integer channelId; + + /** + * 频道名称 + */ + private String channelName; + + /** + * 文章布局 0 无图文章 1 单图文章 2 多图文章 + */ + private Short layout; + + /** + * 文章标记 0 普通文章 1 热点文章 2 置顶文章 3 精品文章 4 大V 文章 + */ + private Byte flag; + + /** + * 文章封面图片 多张逗号分隔 + */ + private String images; + + /** + * 标签 + */ + private String labels; + + /** + * 点赞数量 + */ + private Integer likes; + + /** + * 收藏数量 + */ + private Integer collection; + + /** + * 评论数量 + */ + private Integer comment; + + /** + * 阅读数量 + */ + private Integer views; + + /** + * 省市 + */ + private Integer provinceId; + + /** + * 市区 + */ + private Integer cityId; + + /** + * 区县 + */ + private Integer countyId; + + /** + * 创建时间 + */ + private Date createdTime; + + /** + * 发布时间 + */ + private Date publishTime; + + /** + * 同步状态 + */ + private Boolean syncStatus; + + /** + * 来源 + */ + private Boolean origin; + + /** + * 静态页面地址 + */ + private String staticUrl; +} diff --git a/heima-leadnews-service/heima-leadnews-article/pom.xml b/heima-leadnews-service/heima-leadnews-article/pom.xml new file mode 100644 index 00000000..14208e6b --- /dev/null +++ b/heima-leadnews-service/heima-leadnews-article/pom.xml @@ -0,0 +1,31 @@ + ++ * APP已发布文章配置表 Mapper 接口 + *
+ * + * @author ghy + * @since 2023-09-21 + */ +@Mapper +public interface ApArticleConfigMapper extends BaseMapper+ * APP已发布文章内容表 Mapper 接口 + *
+ * + * @author ghy + * @since 2023-09-21 + */ +@Mapper +public interface ApArticleContentMapper extends BaseMapper+ * 文章信息表,存储已发布的文章 Mapper 接口 + *
+ * + * @author ghy + * @since 2023-09-21 + */ +@Mapper +public interface ApArticleMapper extends BaseMapper+ * APP已发布文章配置表 服务类 + *
+ * + * @author ghy + * @since 2023-09-21 + */ +public interface ApArticleConfigService extends IService+ * APP已发布文章内容表 服务类 + *
+ * + * @author ghy + * @since 2023-09-21 + */ +public interface ApArticleContentService extends IService+ * 文章信息表,存储已发布的文章 服务类 + *
+ * + * @author ghy + * @since 2023-09-21 + */ +public interface ApArticleService extends IService+ * APP已发布文章配置表 服务实现类 + *
+ * + * @author ghy + * @since 2023-09-21 + */ +@Service +public class ApArticleConfigServiceImpl extends ServiceImpl+ * APP已发布文章内容表 服务实现类 + *
+ * + * @author ghy + * @since 2023-09-21 + */ +@Service +public class ApArticleContentServiceImpl extends ServiceImpl+ * 文章信息表,存储已发布的文章 服务实现类 + *
+ * + * @author ghy + * @since 2023-09-21 + */ +@Service +public class ApArticleServiceImpl extends ServiceImpl+ * 联想词表 + *
+ * + * @author itheima + */ +@Data +@Document("ap_associate_words") //用来映射实体与文档的对应关系 +public class ApAssociateWords implements Serializable { + + private static final long serialVersionUID = 1L; + + private String id; + + /** + * 联想词 + */ + private String associateWords; + + /** + * 创建时间 + */ + private Date createdTime; + +} \ No newline at end of file diff --git a/heima-leadnews-service/heima-leadnews-search/src/main/java/com/heima/search/pojos/ApUserSearch.java b/heima-leadnews-service/heima-leadnews-search/src/main/java/com/heima/search/pojos/ApUserSearch.java new file mode 100644 index 00000000..33771fcd --- /dev/null +++ b/heima-leadnews-service/heima-leadnews-search/src/main/java/com/heima/search/pojos/ApUserSearch.java @@ -0,0 +1,42 @@ +package com.heima.search.pojos; + +import lombok.Data; +import org.springframework.data.mongodb.core.mapping.Document; + +import java.io.Serializable; +import java.util.Date; + +/** + *+ * APP用户搜索信息表 + *
+ * @author itheima + */ +@Data +@Document("ap_user_search") +public class ApUserSearch implements Serializable { + + private static final long serialVersionUID = 1L; + + /** + * 主键 + */ + private String id; + + /** + * 用户ID + */ + private Integer userId; + + /** + * 搜索词 + */ + private String keyword; + + /** + * 创建时间 + */ + //private String createdTime; + private Date createdTime; + +} \ No newline at end of file diff --git a/heima-leadnews-service/heima-leadnews-search/src/main/java/com/heima/search/service/ApAssociateWordsService.java b/heima-leadnews-service/heima-leadnews-search/src/main/java/com/heima/search/service/ApAssociateWordsService.java new file mode 100644 index 00000000..d46b4116 --- /dev/null +++ b/heima-leadnews-service/heima-leadnews-search/src/main/java/com/heima/search/service/ApAssociateWordsService.java @@ -0,0 +1,16 @@ +package com.heima.search.service; + +import com.heima.model.common.dtos.ResponseResult; +import com.heima.model.search.dtos.UserSearchDto; +import org.springframework.web.bind.annotation.RequestBody; + +/** + * @author ghy + * @version 1.0.1 + * @date 2024-07-15 17:18:58 + */ +public interface ApAssociateWordsService { + + ResponseResult search(@RequestBody UserSearchDto userSearchDto); + +} diff --git a/heima-leadnews-service/heima-leadnews-search/src/main/java/com/heima/search/service/ApUserSearchService.java b/heima-leadnews-service/heima-leadnews-search/src/main/java/com/heima/search/service/ApUserSearchService.java new file mode 100644 index 00000000..fb91072f --- /dev/null +++ b/heima-leadnews-service/heima-leadnews-search/src/main/java/com/heima/search/service/ApUserSearchService.java @@ -0,0 +1,17 @@ +package com.heima.search.service; + +/** + * @author ghy + * @version 1.0.1 + * @date 2024-07-15 14:57:10 + */ +public interface ApUserSearchService { + + /** + * 保存用户搜索记录 + * @param keyword + * @param userId + */ + void save(String keyword, Integer userId); + +} diff --git a/heima-leadnews-service/heima-leadnews-search/src/main/java/com/heima/search/service/impl/ApAssociateWordsServiceImpl.java b/heima-leadnews-service/heima-leadnews-search/src/main/java/com/heima/search/service/impl/ApAssociateWordsServiceImpl.java new file mode 100644 index 00000000..5b504f22 --- /dev/null +++ b/heima-leadnews-service/heima-leadnews-search/src/main/java/com/heima/search/service/impl/ApAssociateWordsServiceImpl.java @@ -0,0 +1,50 @@ +package com.heima.search.service.impl; + +import com.heima.common.exception.CustomException; +import com.heima.model.common.dtos.ResponseResult; +import com.heima.model.common.enums.AppHttpCodeEnum; +import com.heima.model.search.dtos.UserSearchDto; +import com.heima.search.pojos.ApAssociateWords; +import com.heima.search.service.ApAssociateWordsService; +import lombok.extern.slf4j.Slf4j; +import org.apache.commons.lang3.StringUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.data.domain.Sort; +import org.springframework.data.mongodb.core.MongoTemplate; +import org.springframework.data.mongodb.core.query.Criteria; +import org.springframework.data.mongodb.core.query.Query; +import org.springframework.stereotype.Service; + +import java.util.List; +import java.util.regex.Pattern; + + +/** + * @author ghy + * @version 1.0.1 + * @date 2024-07-15 17:19:31 + */ +@Service +@Slf4j +public class ApAssociateWordsServiceImpl implements ApAssociateWordsService { + + @Autowired + private MongoTemplate mongoTemplate; + + @Override + public ResponseResult search(UserSearchDto userSearchDto) { + if(userSearchDto == null || StringUtils.isBlank(userSearchDto.getSearchWords())) { + throw new CustomException(AppHttpCodeEnum.PARAM_INVALID); + } + if(userSearchDto.getPageSize() <= 0 || userSearchDto.getPageSize() > 10){ + userSearchDto.setPageSize(10); + } + Query query = Query.query( + Criteria.where("associateWords") + .regex(Pattern.compile("^.*" + userSearchDto.getSearchWords() + ".*$", Pattern.CASE_INSENSITIVE))) + .with(Sort.by(Sort.Direction.DESC, "createdTime")) + .limit(userSearchDto.getPageSize()); + List+ * 联想词表 + *
+ * + * @author itheima + */ +@Data +@Document("ap_associate_words") //用来映射实体与文档的对应关系 +public class ApAssociateWords implements Serializable { + + private static final long serialVersionUID = 1L; + + private String id; + + /** + * 联想词 + */ + private String associateWords; + + /** + * 创建时间 + */ + private Date createdTime; + +} \ No newline at end of file diff --git a/heima-leadnews-test/mongo-demo/src/main/java/com/itheima/mongo/pojo/ApUserSearch.java b/heima-leadnews-test/mongo-demo/src/main/java/com/itheima/mongo/pojo/ApUserSearch.java new file mode 100644 index 00000000..7e26d42f --- /dev/null +++ b/heima-leadnews-test/mongo-demo/src/main/java/com/itheima/mongo/pojo/ApUserSearch.java @@ -0,0 +1,42 @@ +package com.itheima.mongo.pojo; + +import lombok.Data; +import org.springframework.data.mongodb.core.mapping.Document; + +import java.io.Serializable; +import java.util.Date; + +/** + *+ * APP用户搜索信息表 + *
+ * @author itheima + */ +@Data +@Document("ap_user_search") +public class ApUserSearch implements Serializable { + + private static final long serialVersionUID = 1L; + + /** + * 主键 + */ + private String id; + + /** + * 用户ID + */ + private Integer userId; + + /** + * 搜索词 + */ + private String keyword; + + /** + * 创建时间 + */ + //private String createdTime; + private Date createdTime; + +} \ No newline at end of file diff --git a/heima-leadnews-test/mongo-demo/src/main/resources/application.yml b/heima-leadnews-test/mongo-demo/src/main/resources/application.yml new file mode 100644 index 00000000..9d76bb1b --- /dev/null +++ b/heima-leadnews-test/mongo-demo/src/main/resources/application.yml @@ -0,0 +1,8 @@ +server: + port: 9998 +spring: + data: + mongodb: + host: 192.168.200.130 + port: 27017 + database: leadnews-history \ No newline at end of file diff --git a/heima-leadnews-test/mongo-demo/src/test/java/com/itheima/mongo/test/MongoTest.java b/heima-leadnews-test/mongo-demo/src/test/java/com/itheima/mongo/test/MongoTest.java new file mode 100644 index 00000000..f74e0d09 --- /dev/null +++ b/heima-leadnews-test/mongo-demo/src/test/java/com/itheima/mongo/test/MongoTest.java @@ -0,0 +1,80 @@ +package com.itheima.mongo.test; + + +import com.itheima.mongo.MongoApplication; +import com.itheima.mongo.pojo.ApAssociateWords; +import com.itheima.mongo.pojo.ApUserSearch; +import com.mongodb.client.result.DeleteResult; +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.data.mongodb.core.MongoTemplate; +import org.springframework.data.mongodb.core.query.Criteria; +import org.springframework.data.mongodb.core.query.Query; + +import java.util.Date; +import java.util.List; + +@SpringBootTest(classes = MongoApplication.class) +public class MongoTest { + + @Autowired + private MongoTemplate mongoTemplate; + + /** + * + * @throws Exception + */ + @Test + public void Test() throws Exception { + Query query = Query.query(Criteria.where("keyword").is("测试搜索4").and("userId").is(1)); + ApUserSearch apUserSearch = mongoTemplate.findOne(query, ApUserSearch.class); + System.out.println(apUserSearch); + } + + //保存 + @Test + public void saveTest(){ + ApAssociateWords apAssociateWords = new ApAssociateWords(); + apAssociateWords.setAssociateWords("测试"); + apAssociateWords.setCreatedTime(new Date()); + ApAssociateWords words = mongoTemplate.save(apAssociateWords); + System.out.println(words); + } + + //根据ID查询一个 + @Test + public void saveFindById(){ + ApAssociateWords associateWords = mongoTemplate.findById("669499a234d38e625fafb701", ApAssociateWords.class); + System.out.println(associateWords); + } + + //根据条件查询一个 + @Test + public void saveFindOne(){ + Query query = Query.query( + Criteria.where("associateWords").is("测试")); + ApAssociateWords associateWords = mongoTemplate.findOne(query, ApAssociateWords.class); + System.out.println(associateWords); + } + + //条件查询 + @Test + public void testQuery(){ + Query query = Query.query( + Criteria.where("createdTime") + .gt(java.sql.Date.valueOf("2020-01-01")) + .and("associateWords").in("测试") + ); + List