From 3123d186be22216e93d6d80c370784d4bcf012d9 Mon Sep 17 00:00:00 2001
From: zxl <763096477@qq.com>
Date: 星期二, 24 六月 2025 14:16:00 +0800
Subject: [PATCH] 新闻功能

---
 framework/src/main/java/cn/lili/modules/lmk/domain/entity/News.java           |   44 ++++
 manager-api/src/main/java/cn/lili/controller/lmk/NewsController.java          |   77 +++++++
 buyer-api/src/main/java/cn/lili/controller/lmk/NewsController.java            |   77 +++++++
 framework/src/main/java/cn/lili/modules/lmk/domain/query/NewsQuery.java       |   23 ++
 framework/src/main/java/cn/lili/modules/lmk/mapper/NewsMapper.java            |   29 ++
 framework/src/main/java/cn/lili/modules/lmk/domain/form/NewsForm.java         |   55 +++++
 framework/src/main/java/cn/lili/modules/lmk/service/NewsService.java          |   61 ++++++
 framework/src/main/java/cn/lili/modules/lmk/service/impl/NewsServiceImpl.java |  108 ++++++++++
 framework/src/main/resources/mapper/lmk/NewsMapper.xml                        |   44 ++++
 framework/src/main/java/cn/lili/modules/lmk/domain/vo/NewsVO.java             |   49 ++++
 10 files changed, 567 insertions(+), 0 deletions(-)

diff --git a/buyer-api/src/main/java/cn/lili/controller/lmk/NewsController.java b/buyer-api/src/main/java/cn/lili/controller/lmk/NewsController.java
new file mode 100644
index 0000000..c30b3a8
--- /dev/null
+++ b/buyer-api/src/main/java/cn/lili/controller/lmk/NewsController.java
@@ -0,0 +1,77 @@
+package cn.lili.controller.lmk;
+import cn.lili.base.Result;
+import cn.lili.group.Add;
+import cn.lili.group.Update;
+import cn.lili.modules.lmk.domain.form.ActivityForm;
+import cn.lili.modules.lmk.domain.form.NewsForm;
+import cn.lili.modules.lmk.domain.query.ActivityQuery;
+import cn.lili.modules.lmk.domain.query.NewsQuery;
+import cn.lili.modules.lmk.service.NewsService;
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiOperation;
+import lombok.RequiredArgsConstructor;
+import org.springframework.validation.annotation.Validated;
+import org.springframework.web.bind.annotation.*;
+
+import javax.validation.constraints.NotEmpty;
+import java.util.List;
+
+
+/**
+ * lmk-shop-java
+ * 鐢ㄦ埛绔柊闂�
+ *
+ * @author : zxl
+ * @date : 2025-06-23 18:39
+ **/
+@Validated
+@RequiredArgsConstructor
+@Api(value = "鏂伴椈", tags = "鏂伴椈")
+@RestController
+@RequestMapping("/buyer/lmk/news")
+public class NewsController {
+    private final NewsService newsService;
+
+    @PostMapping
+    @ApiOperation(value = "娣诲姞", notes = "娣诲姞")
+    public Result add(@RequestBody @Validated(Add.class) NewsForm form) {
+        return newsService.add(form);
+    }
+
+    @PutMapping
+    @ApiOperation(value = "淇敼", notes = "淇敼")
+    public Result update(@RequestBody @Validated(Update.class) NewsForm form) {
+        return newsService.update(form);
+    }
+
+    @DeleteMapping("/{id}")
+    @ApiOperation(value = "ID鍒犻櫎", notes = "ID鍒犻櫎")
+    public Result removeById(@PathVariable("id") String id) {
+        return newsService.removeById(id);
+    }
+
+    @DeleteMapping("/batch")
+    @ApiOperation(value = "鎵归噺鍒犻櫎", notes = "鎵归噺鍒犻櫎")
+    public Result remove(@RequestBody @NotEmpty(message = "璇烽�夋嫨鏁版嵁") List<String> ids) {
+        return newsService.remove(ids);
+    }
+
+    @GetMapping("/page")
+    @ApiOperation(value = "鍒嗛〉", notes = "鍒嗛〉")
+    public Result page(NewsQuery query) {
+        return newsService.page(query);
+    }
+
+    @GetMapping("/{id}")
+    @ApiOperation(value = "璇︽儏", notes = "璇︽儏")
+    public Result detail(@PathVariable("id") String id) {
+        return newsService.detail(id);
+    }
+
+    @PutMapping("/publish/{id}")
+    public Result publish(@PathVariable("id") String id){
+        return newsService.publish(id);
+    }
+
+}
+
diff --git a/framework/src/main/java/cn/lili/modules/lmk/domain/entity/News.java b/framework/src/main/java/cn/lili/modules/lmk/domain/entity/News.java
new file mode 100644
index 0000000..26097b8
--- /dev/null
+++ b/framework/src/main/java/cn/lili/modules/lmk/domain/entity/News.java
@@ -0,0 +1,44 @@
+package cn.lili.modules.lmk.domain.entity;
+
+import cn.lili.mybatis.BaseEntity;
+import com.baomidou.mybatisplus.annotation.TableField;
+import com.baomidou.mybatisplus.annotation.TableName;
+import lombok.Data;
+
+import java.util.Date;
+
+/**
+ * 鏂伴椈
+ *
+ */
+@Data
+@TableName("lmk_news")
+public class News extends BaseEntity {
+    private static final long serialVersionUID = 1L;
+
+    /**
+     * 鏍囬
+     */
+    @TableField("title")
+    private String title;
+
+    /**
+     * 鏄惁鍙戝竷
+     */
+    @TableField("publish")
+    private Boolean publish;
+
+    /**
+     * 鍐呭
+     */
+    @TableField("content")
+    private String content;
+
+    /**
+     * 鍙戝竷鏃ユ湡
+     */
+    @TableField("publish_date")
+    private Date publishDate;
+
+
+}
diff --git a/framework/src/main/java/cn/lili/modules/lmk/domain/form/NewsForm.java b/framework/src/main/java/cn/lili/modules/lmk/domain/form/NewsForm.java
new file mode 100644
index 0000000..dc05302
--- /dev/null
+++ b/framework/src/main/java/cn/lili/modules/lmk/domain/form/NewsForm.java
@@ -0,0 +1,55 @@
+package cn.lili.modules.lmk.domain.form;
+
+import cn.lili.base.AbsForm;
+import cn.lili.group.Add;
+import cn.lili.group.Update;
+import cn.lili.modules.lmk.domain.entity.News;
+import cn.lili.modules.lmk.domain.entity.ShareClickRecord;
+import com.baomidou.mybatisplus.annotation.TableField;
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+import org.springframework.beans.BeanUtils;
+import org.springframework.lang.NonNull;
+
+import javax.validation.constraints.NotBlank;
+import javax.validation.constraints.NotNull;
+
+/**
+ * 鏂伴椈琛ㄥ崟
+ *
+ * @author zxl
+ * @since 2025-06-20
+ */
+@Data
+@ApiModel(value = "NewsForm琛ㄥ崟", description = "鏂伴椈琛ㄥ崟")
+public class NewsForm extends AbsForm {
+    /**
+     * 鏍囬
+     */
+    @NotBlank(message = "鏍囬涓嶈兘涓虹┖", groups = {Add.class, Update.class})
+    @ApiModelProperty("鏍囬")
+    private String title;
+
+    /**
+     * 鏄惁鍙戝竷
+     */
+    @NotNull(message = "鍙戝竷鐘舵�佷笉鑳戒负绌�", groups = {Add.class, Update.class})
+    @ApiModelProperty("鏄惁鍙戝竷")
+    private Boolean publish;
+
+    /**
+     * 鍐呭
+     */
+    @NotBlank(message = "鍐呭涓嶈兘涓虹┖", groups = {Add.class, Update.class})
+    @ApiModelProperty("鍐呭")
+    private String content;
+
+    public static News getEntityByForm(@NonNull NewsForm form, News entity) {
+        if(entity == null) {
+            entity = new News();
+        }
+        BeanUtils.copyProperties(form, entity);
+        return entity;
+    }
+}
diff --git a/framework/src/main/java/cn/lili/modules/lmk/domain/query/NewsQuery.java b/framework/src/main/java/cn/lili/modules/lmk/domain/query/NewsQuery.java
new file mode 100644
index 0000000..8fb0382
--- /dev/null
+++ b/framework/src/main/java/cn/lili/modules/lmk/domain/query/NewsQuery.java
@@ -0,0 +1,23 @@
+package cn.lili.modules.lmk.domain.query;
+
+import cn.lili.base.AbsQuery;
+import io.swagger.annotations.ApiModel;
+import lombok.Data;
+
+/**
+ * 鏂伴椈鏌ヨ鍙傛暟
+ *
+ * @author zxl
+ * @since 2025-06-20
+ */
+@Data
+@ApiModel(value = "鏂伴椈鏌ヨ鍙傛暟", description = "鏂伴椈鏌ヨ鍙傛暟")
+public class NewsQuery extends AbsQuery {
+
+    /**
+     * 鏍囬
+     */
+    private String title;
+
+    private String publish;
+}
diff --git a/framework/src/main/java/cn/lili/modules/lmk/domain/vo/NewsVO.java b/framework/src/main/java/cn/lili/modules/lmk/domain/vo/NewsVO.java
new file mode 100644
index 0000000..545831b
--- /dev/null
+++ b/framework/src/main/java/cn/lili/modules/lmk/domain/vo/NewsVO.java
@@ -0,0 +1,49 @@
+package cn.lili.modules.lmk.domain.vo;
+
+
+import cn.lili.base.AbsVo;
+import com.baomidou.mybatisplus.annotation.TableField;
+import com.fasterxml.jackson.annotation.JsonFormat;
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+import org.springframework.format.annotation.DateTimeFormat;
+
+import java.util.Date;
+
+/**
+ * lmk-shop-java
+ * 鏂伴椈vo
+ *
+ * @author : zxl
+ * @date : 2025-06-20 14:43
+ **/
+@Data
+@ApiModel(value = "NewsVO鍝嶅簲鏁版嵁", description = "鍝嶅簲鏁版嵁")
+public class NewsVO extends AbsVo {
+    /**
+     * 鏍囬
+     */
+    @ApiModelProperty(value = "鏍囬")
+    private String title;
+
+    /**
+     * 鏄惁鍙戝竷
+     */
+    @ApiModelProperty(value = "鏄惁鍙戝竷")
+    private Boolean publish;
+
+    /**
+     * 鍐呭
+     */
+    @ApiModelProperty(value = "鍐呭")
+    private String content;
+
+    /**
+     * 鍙戝竷鏃ユ湡
+     */
+    @ApiModelProperty(value = "鍙戝竷鏃ユ湡")
+    @JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
+    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
+    private Date publishDate;
+}
diff --git a/framework/src/main/java/cn/lili/modules/lmk/mapper/NewsMapper.java b/framework/src/main/java/cn/lili/modules/lmk/mapper/NewsMapper.java
new file mode 100644
index 0000000..c3c5a77
--- /dev/null
+++ b/framework/src/main/java/cn/lili/modules/lmk/mapper/NewsMapper.java
@@ -0,0 +1,29 @@
+package cn.lili.modules.lmk.mapper;
+
+import cn.lili.modules.lmk.domain.entity.News;
+import cn.lili.modules.lmk.domain.query.ActivityQuery;
+import cn.lili.modules.lmk.domain.query.NewsQuery;
+import cn.lili.modules.lmk.domain.vo.ActivityVO;
+import cn.lili.modules.lmk.domain.vo.NewsVO;
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import com.baomidou.mybatisplus.core.metadata.IPage;
+import org.apache.ibatis.annotations.Mapper;
+import org.apache.ibatis.annotations.Param;
+
+/**
+ * 鏂伴椈鎺ュ彛
+ */
+@Mapper
+public interface NewsMapper extends BaseMapper<News> {
+    /**
+     * id鏌ユ壘鏂伴椈璇︽儏
+     * @param id
+     * @return
+     */
+    NewsVO getById(String id);
+
+    /**
+     *  鍒嗛〉
+     */
+    IPage getPage(IPage page, @Param("query") NewsQuery query);
+}
diff --git a/framework/src/main/java/cn/lili/modules/lmk/service/NewsService.java b/framework/src/main/java/cn/lili/modules/lmk/service/NewsService.java
new file mode 100644
index 0000000..de84b83
--- /dev/null
+++ b/framework/src/main/java/cn/lili/modules/lmk/service/NewsService.java
@@ -0,0 +1,61 @@
+package cn.lili.modules.lmk.service;
+
+import cn.lili.base.Result;
+import cn.lili.modules.lmk.domain.entity.MySubscribe;
+import cn.lili.modules.lmk.domain.entity.News;
+import cn.lili.modules.lmk.domain.form.NewsForm;
+import cn.lili.modules.lmk.domain.query.NewsQuery;
+import com.baomidou.mybatisplus.extension.service.IService;
+import org.springframework.stereotype.Service;
+
+import java.util.List;
+
+
+/**
+ * 鏂伴椈 鏈嶅姟绫�
+ */
+public interface NewsService extends IService<News> {
+    /**
+     * 娣诲姞
+     * @param form
+     * @return
+     */
+    Result add(NewsForm form);
+
+    /**
+     * 淇敼
+     * @param form
+     * @return
+     */
+    Result update(NewsForm form);
+
+    /**
+     * 鎵归噺鍒犻櫎
+     * @param ids
+     * @return
+     */
+    Result remove(List<String> ids);
+
+    /**
+     * id鍒犻櫎
+     * @param id
+     * @return
+     */
+    Result removeById(String id);
+
+    /**
+     * 鍒嗛〉鏌ヨ
+     * @param query
+     * @return
+     */
+    Result page(NewsQuery query);
+
+    /**
+     * 鏍规嵁id鏌ユ壘
+     * @param id
+     * @return
+     */
+    Result detail(String id);
+
+    Result publish(String id);
+}
diff --git a/framework/src/main/java/cn/lili/modules/lmk/service/impl/NewsServiceImpl.java b/framework/src/main/java/cn/lili/modules/lmk/service/impl/NewsServiceImpl.java
new file mode 100644
index 0000000..92011fc
--- /dev/null
+++ b/framework/src/main/java/cn/lili/modules/lmk/service/impl/NewsServiceImpl.java
@@ -0,0 +1,108 @@
+package cn.lili.modules.lmk.service.impl;
+
+
+import cn.lili.base.Result;
+import cn.lili.common.enums.ActivityCoverTypeEnum;
+import cn.lili.modules.lmk.domain.entity.Activity;
+import cn.lili.modules.lmk.domain.entity.MySubscribe;
+import cn.lili.modules.lmk.domain.entity.News;
+import cn.lili.modules.lmk.domain.form.ActivityForm;
+import cn.lili.modules.lmk.domain.form.NewsForm;
+import cn.lili.modules.lmk.domain.query.NewsQuery;
+import cn.lili.modules.lmk.domain.vo.ActivityVO;
+import cn.lili.modules.lmk.domain.vo.NewsVO;
+import cn.lili.modules.lmk.mapper.NewsMapper;
+import cn.lili.modules.lmk.service.NewsService;
+import cn.lili.utils.PageUtil;
+import com.baomidou.mybatisplus.core.conditions.Wrapper;
+import com.baomidou.mybatisplus.core.metadata.IPage;
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import lombok.RequiredArgsConstructor;
+import org.springframework.beans.BeanUtils;
+import org.springframework.stereotype.Service;
+import org.springframework.util.Assert;
+
+import java.util.*;
+import java.util.function.Function;
+
+/**
+ * lmk-shop-java
+ * 鏂伴椈鏈嶅姟瀹炵幇绫�
+ *
+ * @author : zxl
+ * @date : 2025-06-20 14:55
+ **/
+@Service
+@RequiredArgsConstructor
+public class NewsServiceImpl extends ServiceImpl<NewsMapper, News> implements NewsService {
+
+    private final NewsMapper newsMapper;
+    @Override
+    public Result add(NewsForm form) {
+        News entity = NewsForm.getEntityByForm(form, null);
+        baseMapper.insert(entity);
+        return Result.ok("娣诲姞鎴愬姛");
+    }
+
+    @Override
+    public Result update(NewsForm form) {
+        News entity = baseMapper.selectById(form.getId());
+
+        Assert.notNull(entity, "璁板綍涓嶅瓨鍦�");
+        BeanUtils.copyProperties(form, entity);
+
+        baseMapper.updateById(entity);
+
+
+        return Result.ok("淇敼鎴愬姛");
+    }
+
+    @Override
+    public Result remove(List<String> ids) {
+        baseMapper.deleteBatchIds(ids);
+        return Result.ok("鍒犻櫎鎴愬姛");
+    }
+
+    @Override
+    public Result removeById(String id) {
+        //鍒ゆ柇鏄惁鍙戝竷鍙戝竷鍒欐彁绀哄厛涓嬫灦锛屽啀鍒犻櫎
+        News entity = baseMapper.selectById(id);
+        if(entity.getPublish()){
+            throw new RuntimeException("璇ユ柊闂诲凡鍙戝竷");
+        }
+
+        baseMapper.deleteById(id);
+        return Result.ok("鍒犻櫎鎴愬姛");
+    }
+
+    @Override
+    public Result page(NewsQuery query) {
+        IPage<NewsVO> page = PageUtil.getPage(query, NewsVO.class);
+
+        baseMapper.getPage(page, query);
+
+        return Result.ok().data(page.getRecords()).total(page.getTotal());
+    }
+
+    @Override
+    public Result detail(String id) {
+        NewsVO vo = baseMapper.getById(id);
+        Assert.notNull(vo, "璁板綍涓嶅瓨鍦�");
+        return Result.ok().data(vo);
+    }
+
+    @Override
+    public Result publish(String id) {
+        News entity = baseMapper.selectById(id);
+        if (!entity.getPublish()) {
+            entity.setPublishDate(new Date());
+        }else {
+            entity.setPublishDate(null);
+        }
+        entity.setPublish(!entity.getPublish());
+        baseMapper.updateById(entity);
+        return Result.ok("鎴愬姛");
+    }
+
+
+}
diff --git a/framework/src/main/resources/mapper/lmk/NewsMapper.xml b/framework/src/main/resources/mapper/lmk/NewsMapper.xml
new file mode 100644
index 0000000..52e26c3
--- /dev/null
+++ b/framework/src/main/resources/mapper/lmk/NewsMapper.xml
@@ -0,0 +1,44 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+<mapper namespace="cn.lili.modules.lmk.mapper.NewsMapper">
+
+    <!-- 閫氱敤鏌ヨ鏄犲皠缁撴灉 -->
+    <resultMap id="BaseResultMap" type="cn.lili.modules.lmk.domain.vo.NewsVO">
+        <result column="title" property="title" />
+        <result column="content" property="content"/>
+        <result column="publish" property="publish" />
+        <result column="publishDate" property="publish_date" />
+
+    </resultMap>
+
+    <select id="getById" resultMap="BaseResultMap">
+        SELECT
+            LN.id,
+            LN.publish,
+            LN.publish_date,
+            LN.content,
+            LN.title
+        FROM
+            lmk_news LN
+        WHERE
+            LN.id = #{id} AND LN.delete_flag = 0
+    </select>
+
+
+    <select id="getPage" resultMap="BaseResultMap">
+        SELECT
+        LN.id,
+        LN.publish,
+        LN.publish_date,
+        LN.content,
+        LN.title
+        FROM
+            lmk_news LN
+        WHERE
+            LN.delete_flag = 0
+            <if test="query.title != null and query.title != ''">AND LN.title LIKE CONCAT('%', #{query.title}, '%')</if>
+            <if test="query.publish != null and query.publish != ''">AND LN.publish = #{query.publish}</if>
+    </select>
+
+
+</mapper>
diff --git a/manager-api/src/main/java/cn/lili/controller/lmk/NewsController.java b/manager-api/src/main/java/cn/lili/controller/lmk/NewsController.java
new file mode 100644
index 0000000..703546c
--- /dev/null
+++ b/manager-api/src/main/java/cn/lili/controller/lmk/NewsController.java
@@ -0,0 +1,77 @@
+package cn.lili.controller.lmk;
+
+
+import cn.lili.base.Result;
+import cn.lili.group.Add;
+import cn.lili.group.Update;
+import cn.lili.modules.lmk.domain.form.ActivityForm;
+import cn.lili.modules.lmk.domain.form.NewsForm;
+import cn.lili.modules.lmk.domain.query.ActivityQuery;
+import cn.lili.modules.lmk.domain.query.NewsQuery;
+import cn.lili.modules.lmk.service.NewsService;
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiOperation;
+import lombok.RequiredArgsConstructor;
+import org.springframework.validation.annotation.Validated;
+import org.springframework.web.bind.annotation.*;
+
+import javax.validation.constraints.NotEmpty;
+import java.util.List;
+
+/**
+ * lmk-shop-java
+ * 鏂伴椈
+ *
+ * @author : zxl
+ * @date : 2025-06-20 15:41
+ **/
+@Validated
+@RequiredArgsConstructor
+@Api(value = "鏂伴椈", tags = "鏂伴椈")
+@RestController
+@RequestMapping("/manager/news")
+public class NewsController {
+    private final NewsService newsService;
+
+    @PostMapping
+    @ApiOperation(value = "娣诲姞", notes = "娣诲姞")
+    public Result add(@RequestBody @Validated(Add.class) NewsForm form) {
+        return newsService.add(form);
+    }
+
+    @PutMapping
+    @ApiOperation(value = "淇敼", notes = "淇敼")
+    public Result update(@RequestBody @Validated(Update.class) NewsForm form) {
+        return newsService.update(form);
+    }
+
+    @DeleteMapping("/{id}")
+    @ApiOperation(value = "ID鍒犻櫎", notes = "ID鍒犻櫎")
+    public Result removeById(@PathVariable("id") String id) {
+        return newsService.removeById(id);
+    }
+
+    @DeleteMapping("/batch")
+    @ApiOperation(value = "鎵归噺鍒犻櫎", notes = "鎵归噺鍒犻櫎")
+    public Result remove(@RequestBody @NotEmpty(message = "璇烽�夋嫨鏁版嵁") List<String> ids) {
+        return newsService.remove(ids);
+    }
+
+    @GetMapping("/page")
+    @ApiOperation(value = "鍒嗛〉", notes = "鍒嗛〉")
+    public Result page(NewsQuery query) {
+        return newsService.page(query);
+    }
+
+    @GetMapping("/{id}")
+    @ApiOperation(value = "璇︽儏", notes = "璇︽儏")
+    public Result detail(@PathVariable("id") String id) {
+        return newsService.detail(id);
+    }
+
+    @PutMapping("/publish/{id}")
+    public Result publish(@PathVariable("id") String id){
+        return newsService.publish(id);
+    }
+
+}

--
Gitblit v1.8.0