inleft
2022-08-12 fc74b40b05413d2fbf5667c129e23245d54ae6a8
commit | author | age
4d51af 1 /*
I 2 Copyright [2020] [https://www.xiaonuo.vip]
3
4 Licensed under the Apache License, Version 2.0 (the "License");
5 you may not use this file except in compliance with the License.
6 You may obtain a copy of the License at
7
8   http://www.apache.org/licenses/LICENSE-2.0
9
10 Unless required by applicable law or agreed to in writing, software
11 distributed under the License is distributed on an "AS IS" BASIS,
12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 See the License for the specific language governing permissions and
14 limitations under the License.
15
16 Snowy采用APACHE LICENSE 2.0开源协议,您在使用过程中,需要注意以下几点:
17
18 1.请不要删除和修改根目录下的LICENSE文件。
19 2.请不要删除和修改Snowy源码头部的版权声明。
20 3.请保留源码和相关描述文件的项目出处,作者声明等。
21 4.分发源码时候,请注明软件出处 https://gitee.com/xiaonuobase/snowy
22 5.在修改包名,模块名称,项目代码等时,请注明软件出处 https://gitee.com/xiaonuobase/snowy
23 6.若您的项目无法满足以上几点,可申请商业授权,获取Snowy商业授权许可,请在官网购买授权,地址为 https://www.xiaonuo.vip
24  */
25 package vip.xiaonuo.modular.blogfriendshiplink.controller;
26
27 import cn.hutool.core.bean.BeanUtil;
28 import cn.hutool.core.lang.Dict;
ff14c4 29 import org.springframework.validation.annotation.Validated;
I 30 import org.springframework.web.bind.annotation.*;
4d51af 31 import vip.xiaonuo.core.annotion.BusinessLog;
I 32 import vip.xiaonuo.core.consts.CommonConstant;
33 import vip.xiaonuo.core.consts.MyConstant;
34 import vip.xiaonuo.core.enums.LogAnnotionOpTypeEnum;
35 import vip.xiaonuo.core.pojo.response.ResponseData;
36 import vip.xiaonuo.core.pojo.response.SuccessResponseData;
37 import vip.xiaonuo.modular.blogfriendshiplink.entity.BlogFriendshipLink;
88f419 38 import vip.xiaonuo.modular.blogfriendshiplink.entity.BlogLinkVo;
ff14c4 39 import vip.xiaonuo.modular.blogfriendshiplink.param.BlogFriendshipLinkParam;
I 40 import vip.xiaonuo.modular.blogfriendshiplink.param.BlogFriendshipLinkVo;
4d51af 41 import vip.xiaonuo.modular.blogfriendshiplink.service.BlogFriendshipLinkService;
I 42 import vip.xiaonuo.sys.modular.dict.param.SysDictTypeParam;
43 import vip.xiaonuo.sys.modular.dict.service.SysDictTypeService;
44
45 import javax.annotation.Resource;
46 import java.util.ArrayList;
47 import java.util.LinkedHashMap;
48 import java.util.List;
49 import java.util.Map;
50 import java.util.function.Function;
51 import java.util.stream.Collectors;
52
53 /**
54  * 友情链接 控制器
55  *
56  * @author inleft
57  * @date 2022-02-15 15:17:15
58  */
59 @RestController
60 @RequestMapping("/outside")
61 public class BlogLinkOutsideController {
62
63     @Resource
64     private BlogFriendshipLinkService blogFriendshipLinkService;
65
66
67     @Resource
68     private SysDictTypeService sysDictTypeService;
69
ff14c4 70
4d51af 71     /**
I 72      * 查询blog友情链接
73      *
74      * @author inleft
75      * @date 2022-02-09 18:20:22
76      */
77     @GetMapping("/blogLink/queryBlogLinkGroup")
78     @BusinessLog(title = "外部blog系统_blog友情链接组_查询", opType = LogAnnotionOpTypeEnum.QUERY)
79     public ResponseData queryBlogLinkGroup() {
80
81         List<BlogFriendshipLink> linkList = blogFriendshipLinkService.lambdaQuery()
ff14c4 82                 .eq(BlogFriendshipLink::getIsEnable, MyConstant.Yes)
4d51af 83                 .orderByAsc(BlogFriendshipLink::getTopValue)
I 84                 .orderByAsc(BlogFriendshipLink::getName)
85                 .list();
86         Map<String, List<BlogFriendshipLink>> groupLink = linkList.stream()
87                 .collect(Collectors.groupingBy(e -> e.getLinkType().toString(), LinkedHashMap::new, Collectors.mapping(Function.identity(),
88                         Collectors.toList())));
89
90         SysDictTypeParam param = new SysDictTypeParam();
91         param.setCode("blog_link_type");
92         List<Dict> dictList = sysDictTypeService.dropDown(param);
93
94         List<BlogLinkVo> res = new ArrayList<>(dictList.size());
95         List<BlogFriendshipLink> tempLink;
96         BlogLinkVo vo;
97
98         for (Dict dict : dictList) {
99             if ((tempLink = groupLink.get(dict.get(CommonConstant.CODE))) != null) {
100                 vo = new BlogLinkVo();
101                 vo.setGroupName(dict.get(CommonConstant.VALUE).toString());
102                 vo.setLinkVoList(tempLink.stream().map(e -> {
103                     BlogFriendshipLinkVo tempLinkVo = new BlogFriendshipLinkVo();
104                     BeanUtil.copyProperties(e, tempLinkVo);
105                     return tempLinkVo;
106                 }).collect(Collectors.toList()));
107                 res.add(vo);
108             }
109         }
110
111         return new SuccessResponseData(res);
112     }
ff14c4 113
I 114
115     /**
116      * 添加友情链接
117      *
118      * @author inleft
119      * @date 2022-02-17 15:05:44
120      */
121     @PostMapping("/blogLink/add")
122     @BusinessLog(title = "外部blog系统_blog友情链接_增加", opType = LogAnnotionOpTypeEnum.ADD)
123     public ResponseData add(@RequestBody @Validated(BlogFriendshipLinkParam.add.class) BlogFriendshipLinkParam blogFriendshipLinkParam) {
124         blogFriendshipLinkParam.setIsEnable(MyConstant.Yes);
125         blogFriendshipLinkService.add(blogFriendshipLinkParam);
126         return new SuccessResponseData();
127     }
128
129
130     @GetMapping("/blogLink/getLinkType")
131     @BusinessLog(title = "外部blog系统_blog友情链接_获取链接类型", opType = LogAnnotionOpTypeEnum.QUERY)
132     public ResponseData getLinkType() {
133
134
135         SysDictTypeParam param = new SysDictTypeParam();
136         param.setCode("blog_link_type");
137         param.setStatus(MyConstant.No);
138         List<Dict> dictList = sysDictTypeService.dropDown(param);
139
140         List<BlogLinkVo> res = new ArrayList<>(dictList.size());
141         BlogLinkVo vo;
142
143         for (Dict dict : dictList) {
144             vo = new BlogLinkVo();
145             vo.setGroupName(dict.get(CommonConstant.VALUE).toString());
146             vo.setLinkTypeId(dict.getLong(CommonConstant.CODE));
147             res.add(vo);
148         }
149         return new SuccessResponseData(res);
150     }
151
4d51af 152 }