来源标签增删改查
This commit is contained in:
parent
c7641d2b25
commit
4ed2b30801
|
|
@ -2,13 +2,17 @@ package com.jinrui.reference.admin.controller;
|
|||
|
||||
import com.jinrui.reference.admin.model.entity.AdminUser;
|
||||
import com.jinrui.reference.admin.service.AdminJwtService;
|
||||
import com.jinrui.reference.core.model.dto.news.SaveTagsDTO;
|
||||
import com.jinrui.reference.core.model.vo.PageObject;
|
||||
import com.jinrui.reference.core.model.vo.ResultObject;
|
||||
import com.jinrui.reference.core.model.vo.tag.TagVO;
|
||||
import com.jinrui.reference.core.service.TagService;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.util.StringUtils;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestHeader;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
|
|
@ -90,6 +94,95 @@ public class TagController {
|
|||
return queryTag(token, 1L, false, keyword, null, page, size, orderBy, direction);
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建来源标签
|
||||
*
|
||||
* @param token
|
||||
* @param name
|
||||
* @return
|
||||
*/
|
||||
@PostMapping("/source/create")
|
||||
public ResultObject<Void> sourceCreate(@RequestHeader("auth-token") String token,
|
||||
@RequestBody SaveTagsDTO saveTagsDTO
|
||||
) {
|
||||
AdminUser adminUser = AdminJwtService.parseToken(token);
|
||||
if (adminUser == null) {
|
||||
log.warn("解析token {}拿不到AdminUser对象!", token);
|
||||
return ResultObject.failed("登陆Token有误,请联系系统管理员!");
|
||||
}
|
||||
|
||||
if (!adminUser.isActive()) {
|
||||
log.warn("当前用户已被封禁! id = {}", adminUser.getId());
|
||||
return ResultObject.failed("当前用户已被封禁!请联系系统管理员!");
|
||||
}
|
||||
|
||||
return tagService.sourceCreate(saveTagsDTO.getName());
|
||||
}
|
||||
|
||||
/**
|
||||
* 编辑来源标签
|
||||
*
|
||||
* @param token
|
||||
* @param name
|
||||
* @return
|
||||
*/
|
||||
@PostMapping("/source/update")
|
||||
public ResultObject<Void> sourceUpdate(@RequestHeader("auth-token") String token,
|
||||
@RequestBody SaveTagsDTO saveTagsDTO
|
||||
) {
|
||||
AdminUser adminUser = AdminJwtService.parseToken(token);
|
||||
if (adminUser == null) {
|
||||
log.warn("解析token {}拿不到AdminUser对象!", token);
|
||||
return ResultObject.failed("登陆Token有误,请联系系统管理员!");
|
||||
}
|
||||
|
||||
if (!adminUser.isActive()) {
|
||||
log.warn("当前用户已被封禁! id = {}", adminUser.getId());
|
||||
return ResultObject.failed("当前用户已被封禁!请联系系统管理员!");
|
||||
}
|
||||
|
||||
return tagService.sourceUpdate(saveTagsDTO.getName(), saveTagsDTO.getId());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 删除来源标签
|
||||
*
|
||||
* @param token
|
||||
* @return
|
||||
*/
|
||||
@PostMapping("/source/delete")
|
||||
public ResultObject<Void> sourceDetele(@RequestHeader("auth-token") String token,
|
||||
@RequestBody SaveTagsDTO saveTagsDTO
|
||||
) {
|
||||
AdminUser adminUser = AdminJwtService.parseToken(token);
|
||||
if (adminUser == null) {
|
||||
log.warn("解析token {}拿不到AdminUser对象!", token);
|
||||
return ResultObject.failed("登陆Token有误,请联系系统管理员!");
|
||||
}
|
||||
|
||||
if (!adminUser.isActive()) {
|
||||
log.warn("当前用户已被封禁! id = {}", adminUser.getId());
|
||||
return ResultObject.failed("当前用户已被封禁!请联系系统管理员!");
|
||||
}
|
||||
|
||||
return tagService.sourceDelete(saveTagsDTO.getId());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 查询diy标签
|
||||
*
|
||||
* @param token
|
||||
* @param parent
|
||||
* @param needChildren
|
||||
* @param keyword
|
||||
* @param page
|
||||
* @param size
|
||||
* @param orderBy
|
||||
* @param direction
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("/diy")
|
||||
public PageObject<TagVO> queryDiy(@RequestHeader("auth-token") String token,
|
||||
@RequestParam(value = "parent", required = false) Long parent,
|
||||
|
|
|
|||
|
|
@ -19,16 +19,16 @@ spring:
|
|||
datasource:
|
||||
type: com.zaxxer.hikari.HikariDataSource
|
||||
driver-class-name: com.mysql.cj.jdbc.Driver
|
||||
url: jdbc:mysql://192.168.0.142:3306/reference?autoReconnect=true&useUnicode=true&useSSL=false&allowMultiQueries=true&characterEncoding=utf8&serverTimezone=Asia/Shanghai
|
||||
username: financial_prod
|
||||
password: mmTFncqmDal5HLRGY0BV
|
||||
# url: jdbc:mysql://121.37.185.246:3306/reference?autoReconnect=true&useUnicode=true&useSSL=false&allowMultiQueries=true&characterEncoding=utf8&serverTimezone=Asia/Shanghai
|
||||
# username: root
|
||||
# password: Xgf_8000
|
||||
# url: jdbc:mysql://192.168.0.142:3306/reference?autoReconnect=true&useUnicode=true&useSSL=false&allowMultiQueries=true&characterEncoding=utf8&serverTimezone=Asia/Shanghai
|
||||
# username: financial_prod
|
||||
# password: mmTFncqmDal5HLRGY0BV
|
||||
url: jdbc:mysql://121.37.185.246:3306/reference?autoReconnect=true&useUnicode=true&useSSL=false&allowMultiQueries=true&characterEncoding=utf8&serverTimezone=Asia/Shanghai
|
||||
username: root
|
||||
password: Xgf_8000
|
||||
redis:
|
||||
host: 192.168.0.172
|
||||
port: 6379
|
||||
password: Xgf_redis
|
||||
# host: 123.60.153.169
|
||||
# host: 192.168.0.172
|
||||
# port: 6379
|
||||
# password: Xgf_redis
|
||||
host: 123.60.153.169
|
||||
port: 6379
|
||||
password: Xgf_redis
|
||||
|
|
|
|||
|
|
@ -46,6 +46,15 @@ public interface TagMapper {
|
|||
@Insert("insert into news_tag_rel(news_id, tag_id) values (#{newsId}, #{tagId})")
|
||||
void saveNewsTagRel(@Param("newsId") Long newsId, @Param("tagId") Long tagId);
|
||||
|
||||
@Insert("insert into tag(parent_id, name, create_time, update_time) values (#{parentId},#{name}, now(), now())")
|
||||
void saveTag(@Param("parentId") Long parentId, @Param("name") String name);
|
||||
|
||||
@Insert("update tag set name=#{name}, update_time=now() where id=#{id}")
|
||||
void updateTag(@Param("id") Long id, @Param("name") String name);
|
||||
|
||||
@Delete("delete from tag where id = #{id}")
|
||||
void deleteTag(@Param("id") Long id);
|
||||
|
||||
@Results({
|
||||
@Result(column = "id", property = "id", id = true),
|
||||
@Result(column = "parent_id", property = "parentId"),
|
||||
|
|
@ -66,7 +75,7 @@ public interface TagMapper {
|
|||
"and id <> #{exclude}" +
|
||||
"</if>" +
|
||||
"</where>" +
|
||||
"order by concat('`', #{orderBy}, '`') " +
|
||||
"order by tag.${orderBy} " +
|
||||
"<if test=\"'desc'.equals(direction)\">" +
|
||||
"desc" +
|
||||
"</if>" +
|
||||
|
|
|
|||
|
|
@ -0,0 +1,23 @@
|
|||
package com.jinrui.reference.core.model.dto.news;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public class SaveTagsDTO {
|
||||
private Long id;
|
||||
private String name;
|
||||
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Long id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
}
|
||||
|
|
@ -5,11 +5,13 @@ import com.fasterxml.jackson.databind.ObjectMapper;
|
|||
import com.jinrui.reference.core.mapper.TagMapper;
|
||||
import com.jinrui.reference.core.model.entity.Tag;
|
||||
import com.jinrui.reference.core.model.vo.PageObject;
|
||||
import com.jinrui.reference.core.model.vo.ResultObject;
|
||||
import com.jinrui.reference.core.model.vo.tag.TagVO;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
|
@ -41,6 +43,19 @@ public class TagService {
|
|||
*/
|
||||
public PageObject<TagVO> queryTag(Long parent, boolean needChildren, String keyword,
|
||||
Long exclude, int page, int size, String orderBy, String direction) {
|
||||
if (StringUtils.hasText(orderBy)) {
|
||||
switch (orderBy) {
|
||||
case "updateTime": {
|
||||
orderBy = "update_time";
|
||||
break;
|
||||
}
|
||||
case "createTime": {
|
||||
orderBy = "create_time";
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
List<Tag> tags;
|
||||
try {
|
||||
tags = tagMapper.queryTag(parent, keyword, exclude, orderBy, direction);
|
||||
|
|
@ -91,4 +106,54 @@ public class TagService {
|
|||
return resultPage;
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建来源标签
|
||||
*
|
||||
* @param name
|
||||
* @return
|
||||
*/
|
||||
public ResultObject<Void> sourceCreate( String name) {
|
||||
|
||||
|
||||
/**
|
||||
* 目前来源标签写死为1
|
||||
* id=1的初始化的时候就是来源标签
|
||||
*/
|
||||
tagMapper.saveTag(1L, name);
|
||||
return ResultObject.success();
|
||||
}
|
||||
|
||||
/**
|
||||
* 编辑来源标签
|
||||
*
|
||||
* @param name
|
||||
* @return
|
||||
*/
|
||||
public ResultObject<Void> sourceUpdate( String name, Long id) {
|
||||
|
||||
|
||||
/**
|
||||
* 目前来源标签写死为1
|
||||
* id=1的初始化的时候就是来源标签
|
||||
*/
|
||||
tagMapper.updateTag(id, name);
|
||||
return ResultObject.success();
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除来源标签
|
||||
*
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
public ResultObject<Void> sourceDelete(Long id) {
|
||||
|
||||
|
||||
/**
|
||||
* 目前来源标签写死为1
|
||||
* id=1的初始化的时候就是来源标签
|
||||
*/
|
||||
tagMapper.deleteTag(id);
|
||||
return ResultObject.success();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue