inleft
2022-03-02 42b7d05dfdf60ee67c876084a3240ff48a3bf3a5
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;
29 import org.springframework.web.bind.annotation.GetMapping;
30 import org.springframework.web.bind.annotation.RequestMapping;
31 import org.springframework.web.bind.annotation.RestController;
32 import vip.xiaonuo.core.annotion.BusinessLog;
33 import vip.xiaonuo.core.consts.CommonConstant;
34 import vip.xiaonuo.core.consts.MyConstant;
35 import vip.xiaonuo.core.enums.LogAnnotionOpTypeEnum;
36 import vip.xiaonuo.core.pojo.response.ResponseData;
37 import vip.xiaonuo.core.pojo.response.SuccessResponseData;
38 import vip.xiaonuo.modular.blogfriendshiplink.entity.BlogFriendshipLink;
39 import vip.xiaonuo.modular.blogfriendshiplink.param.BlogFriendshipLinkVo;
88f419 40 import vip.xiaonuo.modular.blogfriendshiplink.entity.BlogLinkVo;
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
70     /**
71      * 查询blog友情链接
72      *
73      * @author inleft
74      * @date 2022-02-09 18:20:22
75      */
76     @GetMapping("/blogLink/queryBlogLinkGroup")
77     @BusinessLog(title = "外部blog系统_blog友情链接组_查询", opType = LogAnnotionOpTypeEnum.QUERY)
78     public ResponseData queryBlogLinkGroup() {
79
80         List<BlogFriendshipLink> linkList = blogFriendshipLinkService.lambdaQuery()
81                 .eq(BlogFriendshipLink::getIsEnable,MyConstant.Yes)
82                 .orderByAsc(BlogFriendshipLink::getTopValue)
83                 .orderByAsc(BlogFriendshipLink::getName)
84                 .list();
85         Map<String, List<BlogFriendshipLink>> groupLink = linkList.stream()
86                 .collect(Collectors.groupingBy(e -> e.getLinkType().toString(), LinkedHashMap::new, Collectors.mapping(Function.identity(),
87                         Collectors.toList())));
88
89         SysDictTypeParam param = new SysDictTypeParam();
90         param.setCode("blog_link_type");
91         List<Dict> dictList = sysDictTypeService.dropDown(param);
92
93         List<BlogLinkVo> res = new ArrayList<>(dictList.size());
94         List<BlogFriendshipLink> tempLink;
95         BlogLinkVo vo;
96
97         for (Dict dict : dictList) {
98             if ((tempLink = groupLink.get(dict.get(CommonConstant.CODE))) != null) {
99                 vo = new BlogLinkVo();
100                 vo.setGroupName(dict.get(CommonConstant.VALUE).toString());
101                 vo.setLinkVoList(tempLink.stream().map(e -> {
102                     BlogFriendshipLinkVo tempLinkVo = new BlogFriendshipLinkVo();
103                     BeanUtil.copyProperties(e, tempLinkVo);
104                     return tempLinkVo;
105                 }).collect(Collectors.toList()));
106                 res.add(vo);
107             }
108         }
109
110         return new SuccessResponseData(res);
111     }
112 }