yusm 6 months ago
parent
commit
ffa72088f4

+ 6 - 0
fhKeeper/formulahousekeeper/ArticleOperation/src/main/java/com/my/bigevent/controller/ArticleController.java

@@ -95,4 +95,10 @@ public class ArticleController
         return Result.success(relatedList);
         return Result.success(relatedList);
     }
     }
 
 
+    @GetMapping ("/deleteById")
+    public Result deleteById(@RequestParam("id") Integer id) {
+        articleService.deleteById(id);
+        return Result.success();
+    }
+
 }
 }

+ 4 - 0
fhKeeper/formulahousekeeper/ArticleOperation/src/main/java/com/my/bigevent/mapper/ArticleCoverImgMapper.java

@@ -4,6 +4,7 @@ import com.my.bigevent.pojo.ArticleCoverImg;
 import org.apache.ibatis.annotations.Delete;
 import org.apache.ibatis.annotations.Delete;
 import org.apache.ibatis.annotations.Insert;
 import org.apache.ibatis.annotations.Insert;
 import org.apache.ibatis.annotations.Mapper;
 import org.apache.ibatis.annotations.Mapper;
+import org.apache.ibatis.annotations.Select;
 
 
 @Mapper
 @Mapper
 public interface ArticleCoverImgMapper {
 public interface ArticleCoverImgMapper {
@@ -12,4 +13,7 @@ public interface ArticleCoverImgMapper {
 
 
     @Insert("insert into article_cover_img(article_id,cover_img_data) values (#{articleId},#{coverImgData})")
     @Insert("insert into article_cover_img(article_id,cover_img_data) values (#{articleId},#{coverImgData})")
     void insert(ArticleCoverImg articleCoverImg);
     void insert(ArticleCoverImg articleCoverImg);
+
+    @Select("select * from article_cover_img where article_id=#{articleId}")
+    ArticleCoverImg selectByArticleId(Integer articleId);
 }
 }

+ 5 - 4
fhKeeper/formulahousekeeper/ArticleOperation/src/main/java/com/my/bigevent/mapper/ArticleMapper.java

@@ -1,9 +1,7 @@
 package com.my.bigevent.mapper;
 package com.my.bigevent.mapper;
 
 
 import com.my.bigevent.pojo.Article;
 import com.my.bigevent.pojo.Article;
-import org.apache.ibatis.annotations.Insert;
-import org.apache.ibatis.annotations.Mapper;
-import org.apache.ibatis.annotations.Select;
+import org.apache.ibatis.annotations.*;
 
 
 import java.util.List;
 import java.util.List;
 
 
@@ -16,7 +14,7 @@ public interface ArticleMapper
     void add(Article article);
     void add(Article article);
 
 
     // 动态实现 sql,所以这里不用注解
     // 动态实现 sql,所以这里不用注解
-    List<Article> list(Integer userId, Integer categoryId, String state);
+    List<Article> list(@Param("userId") Integer userId,@Param("categoryId") String categoryId,@Param("state") String state);
     List<Article> pageList(Integer userId, String info);
     List<Article> pageList(Integer userId, String info);
 
 
     @Select("select * from article where id = #{id}")
     @Select("select * from article where id = #{id}")
@@ -29,4 +27,7 @@ public interface ArticleMapper
     List<Article> latestList();
     List<Article> latestList();
 
 
     List<Article> relatedList(List<String> strings);
     List<Article> relatedList(List<String> strings);
+
+    @Delete("delete from article where id = #{articleId}")
+    void deleteById(Integer articleId);
 }
 }

+ 2 - 0
fhKeeper/formulahousekeeper/ArticleOperation/src/main/java/com/my/bigevent/service/ArticleService.java

@@ -23,4 +23,6 @@ public interface ArticleService
     List<Article> latestList();
     List<Article> latestList();
 
 
     List<Article> relatedList(Integer articleId);
     List<Article> relatedList(Integer articleId);
+
+    void deleteById(Integer articleId);
 }
 }

+ 16 - 1
fhKeeper/formulahousekeeper/ArticleOperation/src/main/java/com/my/bigevent/service/impl/ArticleServiceImpl.java

@@ -103,7 +103,16 @@ public class ArticleServiceImpl implements ArticleService
         // 调用 mapper
         // 调用 mapper
         Map<String,Object> map=ThreadLocalUtil.get();
         Map<String,Object> map=ThreadLocalUtil.get();
         Integer userId=(Integer)map.get("id");
         Integer userId=(Integer)map.get("id");
-        List<Article> as=articleMapper.list(userId,categoryId,state);
+        String categoryIdStr=categoryId==null?"":categoryId.toString();
+        List<Article> as=articleMapper.list(userId,categoryIdStr,state);
+        if (!as.isEmpty()){
+            for (Article a : as) {
+                ArticleCoverImg articleCoverImg= coverImgMapper.selectByArticleId(a.getId());
+                if(null!=articleCoverImg&&articleCoverImg.getCoverImgData()!=null){
+                    a.setCoverImg(articleCoverImg.getCoverImgData());
+                }
+            }
+        }
         // Page 中提供了方法,可以获取 PageHelper 分页查询后,得到的总记录条数和当前页数据
         // Page 中提供了方法,可以获取 PageHelper 分页查询后,得到的总记录条数和当前页数据
         Page<Article> p=(Page<Article>) as;
         Page<Article> p=(Page<Article>) as;
 
 
@@ -213,6 +222,12 @@ public class ArticleServiceImpl implements ArticleService
         }
         }
     }
     }
 
 
+    @Override
+    public void deleteById(Integer articleId) {
+        articleMapper.deleteById(articleId);
+        coverImgMapper.deleteByArticleId(articleId);
+    }
+
     private void handleCoverImage(MultipartFile coverImage, Integer articleId) {
     private void handleCoverImage(MultipartFile coverImage, Integer articleId) {
         String fileName = coverImage.getOriginalFilename();
         String fileName = coverImage.getOriginalFilename();
         String fileType = fileName.substring(fileName.lastIndexOf("."));
         String fileType = fileName.substring(fileName.lastIndexOf("."));

+ 4 - 0
fhKeeper/formulahousekeeper/ArticleOperation/src/main/java/com/my/bigevent/service/impl/CategoryServiceImpl.java

@@ -1,5 +1,6 @@
 package com.my.bigevent.service.impl;
 package com.my.bigevent.service.impl;
 
 
+import com.my.bigevent.mapper.ArticleMapper;
 import com.my.bigevent.mapper.CategoryMapper;
 import com.my.bigevent.mapper.CategoryMapper;
 import com.my.bigevent.pojo.Category;
 import com.my.bigevent.pojo.Category;
 import com.my.bigevent.service.CategoryService;
 import com.my.bigevent.service.CategoryService;
@@ -16,6 +17,9 @@ public class CategoryServiceImpl implements CategoryService
 {
 {
     @Autowired
     @Autowired
     CategoryMapper categoryMapper;
     CategoryMapper categoryMapper;
+
+    @Autowired
+    ArticleMapper articleMapper;
     @Override
     @Override
     public void add(Category category)
     public void add(Category category)
     {
     {

+ 8 - 4
fhKeeper/formulahousekeeper/ArticleOperation/src/main/resources/com/my/bigevent/mapper/ArticleMapper.xml

@@ -87,15 +87,19 @@
     <select id="list" resultType="com.my.bigevent.pojo.Article">
     <select id="list" resultType="com.my.bigevent.pojo.Article">
         select * from article
         select * from article
         <where>
         <where>
-            <if test="categoryId!=null">
-                category_id=#{categoryId}
+            <if test="categoryId!=null and categoryId !='' ">
+               and JSON_CONTAINS(category_ids, #{categoryId})
             </if>
             </if>
 
 
-            <if test="state!=null">
-                and state=#{state}
+            <if test="state!=null and state=='yes'">
+                and state='已发布'
+            </if>
+            <if test="state!=null and state=='no'">
+                and state='草稿'
             </if>
             </if>
         and create_user=#{userId}
         and create_user=#{userId}
         </where>
         </where>
+        order by update_time desc
     </select>
     </select>
     <select id="pageList" resultType="com.my.bigevent.pojo.Article">
     <select id="pageList" resultType="com.my.bigevent.pojo.Article">
         select a.* ,aci.cover_img_data coverImg
         select a.* ,aci.cover_img_data coverImg