diff --git a/admin/src/main/java/com/jinrui/reference/admin/controller/TagController.java b/admin/src/main/java/com/jinrui/reference/admin/controller/TagController.java index 8aef240..3c80a61 100644 --- a/admin/src/main/java/com/jinrui/reference/admin/controller/TagController.java +++ b/admin/src/main/java/com/jinrui/reference/admin/controller/TagController.java @@ -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 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 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 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 queryDiy(@RequestHeader("auth-token") String token, @RequestParam(value = "parent", required = false) Long parent, diff --git a/admin/src/main/resources/application.yml b/admin/src/main/resources/application.yml index 083ce49..c2ab94d 100644 --- a/admin/src/main/resources/application.yml +++ b/admin/src/main/resources/application.yml @@ -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 diff --git a/core/src/main/java/com/jinrui/reference/core/mapper/TagMapper.java b/core/src/main/java/com/jinrui/reference/core/mapper/TagMapper.java index 9947cda..e88c4ff 100644 --- a/core/src/main/java/com/jinrui/reference/core/mapper/TagMapper.java +++ b/core/src/main/java/com/jinrui/reference/core/mapper/TagMapper.java @@ -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}" + "" + "" + - "order by concat('`', #{orderBy}, '`') " + + "order by tag.${orderBy} " + "" + "desc" + "" + diff --git a/core/src/main/java/com/jinrui/reference/core/model/dto/news/SaveTagsDTO.java b/core/src/main/java/com/jinrui/reference/core/model/dto/news/SaveTagsDTO.java new file mode 100644 index 0000000..62103d3 --- /dev/null +++ b/core/src/main/java/com/jinrui/reference/core/model/dto/news/SaveTagsDTO.java @@ -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; + } +} diff --git a/core/src/main/java/com/jinrui/reference/core/service/TagService.java b/core/src/main/java/com/jinrui/reference/core/service/TagService.java index 21ecabb..f92e12f 100644 --- a/core/src/main/java/com/jinrui/reference/core/service/TagService.java +++ b/core/src/main/java/com/jinrui/reference/core/service/TagService.java @@ -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 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 tags; try { tags = tagMapper.queryTag(parent, keyword, exclude, orderBy, direction); @@ -91,4 +106,54 @@ public class TagService { return resultPage; } + /** + * 创建来源标签 + * + * @param name + * @return + */ + public ResultObject sourceCreate( String name) { + + + /** + * 目前来源标签写死为1 + * id=1的初始化的时候就是来源标签 + */ + tagMapper.saveTag(1L, name); + return ResultObject.success(); + } + + /** + * 编辑来源标签 + * + * @param name + * @return + */ + public ResultObject sourceUpdate( String name, Long id) { + + + /** + * 目前来源标签写死为1 + * id=1的初始化的时候就是来源标签 + */ + tagMapper.updateTag(id, name); + return ResultObject.success(); + } + + /** + * 删除来源标签 + * + * @param id + * @return + */ + public ResultObject sourceDelete(Long id) { + + + /** + * 目前来源标签写死为1 + * id=1的初始化的时候就是来源标签 + */ + tagMapper.deleteTag(id); + return ResultObject.success(); + } }