新闻添加接口
This commit is contained in:
parent
377261e938
commit
e16f0687a8
|
@ -98,7 +98,7 @@ id为主键(不管),团队成员信息定义value:organize_user_info,
|
||||||
## 新闻信息展示
|
## 新闻信息展示
|
||||||
1. `order`: 展示顺序,可选值[asc|desc]
|
1. `order`: 展示顺序,可选值[asc|desc]
|
||||||
2. `data`: 数据内容
|
2. `data`: 数据内容
|
||||||
1. `display_order`:展示顺序
|
1. `display_order`:展示顺序(输入integer,自定义处理)
|
||||||
2. `title`: 新闻标题
|
2. `title`: 新闻标题
|
||||||
3. `content`: 新闻内容
|
3. `content`: 新闻内容
|
||||||
4. `tags`: 标签
|
4. `tags`: 标签
|
||||||
|
@ -108,6 +108,6 @@ id为主键(不管),团队成员信息定义value:organize_user_info,
|
||||||
8. `is_active`: 是否展示[true|false]
|
8. `is_active`: 是否展示[true|false]
|
||||||
9. `created_at` : 创建时间
|
9. `created_at` : 创建时间
|
||||||
10. `updated_at` : 更新时间
|
10. `updated_at` : 更新时间
|
||||||
11. `author`: 作者名称
|
11. `author`: 填写作者
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -3,6 +3,7 @@ package com.jsl.oa.config.redis;
|
||||||
import org.springframework.beans.factory.annotation.Value;
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
import org.springframework.context.annotation.Bean;
|
import org.springframework.context.annotation.Bean;
|
||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
import org.springframework.context.annotation.Lazy;
|
||||||
import org.springframework.data.redis.connection.RedisConnectionFactory;
|
import org.springframework.data.redis.connection.RedisConnectionFactory;
|
||||||
import org.springframework.data.redis.connection.RedisStandaloneConfiguration;
|
import org.springframework.data.redis.connection.RedisStandaloneConfiguration;
|
||||||
import org.springframework.data.redis.connection.jedis.JedisConnectionFactory;
|
import org.springframework.data.redis.connection.jedis.JedisConnectionFactory;
|
||||||
|
|
52
src/main/java/com/jsl/oa/controllers/NewsController.java
Normal file
52
src/main/java/com/jsl/oa/controllers/NewsController.java
Normal file
|
@ -0,0 +1,52 @@
|
||||||
|
package com.jsl.oa.controllers;
|
||||||
|
|
||||||
|
|
||||||
|
import com.jsl.oa.model.voData.NewsAddVO;
|
||||||
|
import com.jsl.oa.model.voData.PermissionEditVO;
|
||||||
|
import com.jsl.oa.services.NewsService;
|
||||||
|
import com.jsl.oa.services.RoleService;
|
||||||
|
import com.jsl.oa.utils.BaseResponse;
|
||||||
|
import com.jsl.oa.utils.ErrorCode;
|
||||||
|
import com.jsl.oa.utils.Processing;
|
||||||
|
import com.jsl.oa.utils.ResultUtil;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.validation.BindingResult;
|
||||||
|
import org.springframework.validation.annotation.Validated;
|
||||||
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestBody;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <h1>新闻控制器</h1>
|
||||||
|
* <hr/>
|
||||||
|
* 角色控制器,包含角色获取接口
|
||||||
|
*
|
||||||
|
* @version v1.1.0
|
||||||
|
* @see NewsService
|
||||||
|
* @since v1.1.0
|
||||||
|
*/
|
||||||
|
|
||||||
|
@Slf4j
|
||||||
|
@RestController
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
public class NewsController {
|
||||||
|
|
||||||
|
private final NewsService newsService;
|
||||||
|
|
||||||
|
@PostMapping("/news/add")
|
||||||
|
public BaseResponse newsAdd(@RequestBody @Validated NewsAddVO newsAddVO, BindingResult bindingResult, HttpServletRequest request){
|
||||||
|
log.info("请求接口[POST]: /news/add");
|
||||||
|
// 判断是否有参数错误
|
||||||
|
if (bindingResult.hasErrors()) {
|
||||||
|
return ResultUtil.error(ErrorCode.REQUEST_BODY_ERROR, Processing.getValidatedErrorList(bindingResult));
|
||||||
|
}
|
||||||
|
|
||||||
|
return newsService.newsAdd(newsAddVO,request);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
30
src/main/java/com/jsl/oa/dao/NewsDAO.java
Normal file
30
src/main/java/com/jsl/oa/dao/NewsDAO.java
Normal file
|
@ -0,0 +1,30 @@
|
||||||
|
package com.jsl.oa.dao;
|
||||||
|
|
||||||
|
import com.jsl.oa.mapper.NewsMapper;
|
||||||
|
import com.jsl.oa.model.doData.NewsDO;
|
||||||
|
import com.jsl.oa.model.voData.NewsAddVO;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
|
||||||
|
@Slf4j
|
||||||
|
@Component
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
public class NewsDAO {
|
||||||
|
|
||||||
|
private final NewsMapper newsMapper;
|
||||||
|
|
||||||
|
public void addNews(NewsDO newsVO,Long uid){
|
||||||
|
log.info("\t> 执行 DAO 层 NewsDAO.addNews 方法");
|
||||||
|
log.info("\t\t> 从 MySQL 获取数据");
|
||||||
|
// 添加新闻数据
|
||||||
|
newsMapper.addNews(newsVO);
|
||||||
|
// 添加作者
|
||||||
|
newsMapper.addNewsUser(uid,newsVO.getId());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
35
src/main/java/com/jsl/oa/mapper/NewsMapper.java
Normal file
35
src/main/java/com/jsl/oa/mapper/NewsMapper.java
Normal file
|
@ -0,0 +1,35 @@
|
||||||
|
package com.jsl.oa.mapper;
|
||||||
|
|
||||||
|
|
||||||
|
import com.jsl.oa.model.doData.NewsDO;
|
||||||
|
import org.apache.ibatis.annotations.*;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Mapper
|
||||||
|
public interface NewsMapper {
|
||||||
|
|
||||||
|
@Select("SELECT * FROM organize_oa.oa_news WHERE id = #{id}")
|
||||||
|
NewsDO selectNewsById( Long id);
|
||||||
|
|
||||||
|
@Select("SELECT * FROM organize_oa.oa_news WHERE status = #{status}")
|
||||||
|
List<NewsDO> selectNewsByStatus( Integer status);
|
||||||
|
|
||||||
|
@Insert("INSERT INTO organize_oa.oa_news(title, content, tags, status) " +
|
||||||
|
"VALUES(#{title}, #{content}, #{tags}, #{status})")
|
||||||
|
@Options(useGeneratedKeys = true, keyProperty = "id")
|
||||||
|
void addNews(NewsDO news);
|
||||||
|
|
||||||
|
@Update("UPDATE organize_oa.oa_news SET title = #{title}, content = #{content}, tags = #{tags}, " +
|
||||||
|
"likes = #{likes}, comments = #{comments}, status = #{status}, update_at = CURRENT_TIMESTAMP " +
|
||||||
|
"WHERE id = #{id}")
|
||||||
|
void updateNews(NewsDO news);
|
||||||
|
|
||||||
|
@Delete("DELETE FROM organize_oa.oa_news WHERE id = #{id}")
|
||||||
|
void deleteNewsById( Long id);
|
||||||
|
|
||||||
|
@Insert("INSERT INTO organize_oa.oa_news_user(uid,nid)"+
|
||||||
|
"VALUES(#{uid}, #{nid})")
|
||||||
|
void addNewsUser(Long uid,Long nid);
|
||||||
|
|
||||||
|
}
|
35
src/main/java/com/jsl/oa/model/doData/NewsDO.java
Normal file
35
src/main/java/com/jsl/oa/model/doData/NewsDO.java
Normal file
|
@ -0,0 +1,35 @@
|
||||||
|
package com.jsl.oa.model.doData;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.experimental.Accessors;
|
||||||
|
|
||||||
|
import java.sql.Timestamp;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <h1>news 数据表</h1>
|
||||||
|
* <hr/>
|
||||||
|
* 映射 oa_news数据表内容进入自定义实体类
|
||||||
|
*
|
||||||
|
* @author 张睿相
|
||||||
|
* @since v1.1.0
|
||||||
|
* @version v1.1.0
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@Accessors(chain = true)
|
||||||
|
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||||
|
public class NewsDO {
|
||||||
|
|
||||||
|
private Long id;
|
||||||
|
private String title;
|
||||||
|
private String content;
|
||||||
|
private String tags;
|
||||||
|
private Integer likes;
|
||||||
|
private Integer comments;
|
||||||
|
private Short status;
|
||||||
|
private Timestamp createdAt;
|
||||||
|
private Timestamp updatedAt;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
24
src/main/java/com/jsl/oa/model/voData/NewsAddVO.java
Normal file
24
src/main/java/com/jsl/oa/model/voData/NewsAddVO.java
Normal file
|
@ -0,0 +1,24 @@
|
||||||
|
package com.jsl.oa.model.voData;
|
||||||
|
|
||||||
|
|
||||||
|
import lombok.Getter;
|
||||||
|
|
||||||
|
import javax.validation.constraints.NotBlank;
|
||||||
|
import javax.validation.constraints.NotNull;
|
||||||
|
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
public class NewsAddVO {
|
||||||
|
|
||||||
|
@NotBlank(message = "标题不能为空")
|
||||||
|
private String title;
|
||||||
|
@NotBlank(message = "内容不能为空")
|
||||||
|
private String content;
|
||||||
|
@NotBlank(message = "标签不能为空")
|
||||||
|
private String tags;
|
||||||
|
@NotNull(message = "状态不能为空")
|
||||||
|
private Short status;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
21
src/main/java/com/jsl/oa/services/NewsService.java
Normal file
21
src/main/java/com/jsl/oa/services/NewsService.java
Normal file
|
@ -0,0 +1,21 @@
|
||||||
|
package com.jsl.oa.services;
|
||||||
|
|
||||||
|
import com.jsl.oa.model.voData.NewsAddVO;
|
||||||
|
import com.jsl.oa.utils.BaseResponse;
|
||||||
|
|
||||||
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <h1>新闻服务接口</h1>
|
||||||
|
* <hr/>
|
||||||
|
* 用于新闻控制
|
||||||
|
*
|
||||||
|
* @author 张睿相
|
||||||
|
* @version v1.1.0
|
||||||
|
* @since v1.1.0
|
||||||
|
*/
|
||||||
|
public interface NewsService {
|
||||||
|
|
||||||
|
BaseResponse newsAdd(NewsAddVO newsAddVO, HttpServletRequest request);
|
||||||
|
|
||||||
|
}
|
|
@ -2,16 +2,16 @@ package com.jsl.oa.services.impl;
|
||||||
|
|
||||||
|
|
||||||
import com.jsl.oa.mapper.MessageMapper;
|
import com.jsl.oa.mapper.MessageMapper;
|
||||||
import com.jsl.oa.mapper.RoleMapper;
|
|
||||||
import com.jsl.oa.model.doData.MessageDO;
|
import com.jsl.oa.model.doData.MessageDO;
|
||||||
import com.jsl.oa.services.MessageService;
|
import com.jsl.oa.services.MessageService;
|
||||||
import com.jsl.oa.utils.*;
|
import com.jsl.oa.utils.*;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
import javax.swing.*;
|
|
||||||
|
|
||||||
|
|
||||||
|
@Slf4j
|
||||||
@Service
|
@Service
|
||||||
@RequiredArgsConstructor
|
@RequiredArgsConstructor
|
||||||
public class MessageServiceImpl implements MessageService {
|
public class MessageServiceImpl implements MessageService {
|
||||||
|
|
42
src/main/java/com/jsl/oa/services/impl/NewsServiceImpl.java
Normal file
42
src/main/java/com/jsl/oa/services/impl/NewsServiceImpl.java
Normal file
|
@ -0,0 +1,42 @@
|
||||||
|
package com.jsl.oa.services.impl;
|
||||||
|
|
||||||
|
|
||||||
|
import com.jsl.oa.dao.NewsDAO;
|
||||||
|
import com.jsl.oa.model.doData.NewsDO;
|
||||||
|
import com.jsl.oa.model.voData.NewsAddVO;
|
||||||
|
import com.jsl.oa.services.NewsService;
|
||||||
|
import com.jsl.oa.utils.BaseResponse;
|
||||||
|
import com.jsl.oa.utils.JwtUtil;
|
||||||
|
import com.jsl.oa.utils.Processing;
|
||||||
|
import com.jsl.oa.utils.ResultUtil;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
|
||||||
|
@Slf4j
|
||||||
|
@Service
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
public class NewsServiceImpl implements NewsService {
|
||||||
|
|
||||||
|
private final NewsDAO newsDAO;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public BaseResponse newsAdd(NewsAddVO newsAddVO, HttpServletRequest request) {
|
||||||
|
log.info("\t> 执行 Service 层 NewsService.newsAdd 方法");
|
||||||
|
// 拷贝新闻数据到实体类
|
||||||
|
NewsDO newsDO = new NewsDO();
|
||||||
|
Processing.copyProperties(newsAddVO,newsDO);
|
||||||
|
// 获取现在的用户id
|
||||||
|
String token = request.getHeader("Authorization").replace("Bearer ", "");
|
||||||
|
Long uid = JwtUtil.getUserId(token);
|
||||||
|
// 添加新闻数据
|
||||||
|
newsDAO.addNews(newsDO,uid);
|
||||||
|
|
||||||
|
return ResultUtil.success();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,18 +1,35 @@
|
||||||
server:
|
|
||||||
port: 8080
|
|
||||||
spring:
|
spring:
|
||||||
datasource:
|
datasource:
|
||||||
url: jdbc:mysql://localhost:3306
|
url: jdbc:mysql://localhost:3306?organize_oa
|
||||||
username: root
|
username: root
|
||||||
password: 123456
|
password: Zrx@20041009
|
||||||
driver-class-name: com.mysql.cj.jdbc.Driver
|
driver-class-name: com.mysql.cj.jdbc.Driver
|
||||||
redis:
|
redis:
|
||||||
database: 0
|
database: 0
|
||||||
host: 192.168.80.129
|
host: localhost
|
||||||
port: 6379
|
port: 6379
|
||||||
password: 123456
|
password: Zrx@20041009
|
||||||
profiles:
|
mail:
|
||||||
active: dev
|
default-encoding: UTF-8
|
||||||
|
host: smtp.qiye.aliyun.com
|
||||||
|
username: wxxydeveloper@x-lf.cn
|
||||||
|
password: 114477225588Zcw
|
||||||
|
properties:
|
||||||
|
form: wxxydeveloper@x-lf.cn
|
||||||
|
mail:
|
||||||
|
smtp:
|
||||||
|
auth: true
|
||||||
|
starttls:
|
||||||
|
enable: true
|
||||||
|
ssl:
|
||||||
|
enable: true
|
||||||
mybatis:
|
mybatis:
|
||||||
configuration:
|
configuration:
|
||||||
map-underscore-to-camel-case: true
|
map-underscore-to-camel-case: true
|
||||||
|
logging:
|
||||||
|
level:
|
||||||
|
root: TRACE
|
||||||
|
sun.rmi: OFF
|
||||||
|
org.apache.tomcat: WARN
|
||||||
|
server:
|
||||||
|
port: 8155
|
Loading…
Reference in New Issue
Block a user