3
13693261870
2022-09-16 63ba114e70e380442fcbed4a5157ee52c9491216
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
package com.landtool.lanbase.modules.api.controller;
 
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.serializer.SimplePropertyPreFilter;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.landtool.lanbase.common.utils.ComplexPropertyPreFilter;
import com.landtool.lanbase.common.utils.IPUtils;
import com.landtool.lanbase.common.utils.Result;
import com.landtool.lanbase.modules.api.utils.PageBean;
import com.landtool.lanbase.modules.org.entity.OrgUser;
import com.landtool.lanbase.modules.org.entity.OrgUserGroup;
import com.landtool.lanbase.modules.org.entity.OrgUserJoinUnit;
import com.landtool.lanbase.modules.org.entity.OrgUserunit;
import com.landtool.lanbase.modules.org.service.OrgUserService;
import com.landtool.lanbase.modules.sys.entity.PubNews;
import com.landtool.lanbase.modules.sys.entity.PubNewsApi;
import com.landtool.lanbase.modules.sys.entity.SysResource;
import com.landtool.lanbase.modules.sys.service.PubNewsService;
import com.landtool.lanbase.modules.sys.service.SysResourceService;
 
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
 
import io.swagger.models.auth.In;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
 
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
 
import java.io.IOException;
import java.net.URLDecoder;
import java.sql.Timestamp;
import java.text.SimpleDateFormat;
import java.util.*;
 
/**
 * @Description: 用户信息模块提供的api
 * @Author: zimao.guo
 * @Date: 9:53 2018/1/31
 *
 */
@Controller
@RequestMapping(path = "/api/sys/pubnews/")
@Api(value = "", tags = {"资讯发布相关接口"})
public class PubNewsApiController {
    
    @Autowired
    private PubNewsService pubNewsService;
    
 
    /**
     * @Description: 获取前资讯发布列表
     */
    @GetMapping(path = "/queryTopList/{num}")
    @ApiOperation(
            value = "获取前资讯发布列表",
            notes = "获取前资讯发布列表"
            )
    public void queryTopList(@ApiParam(name="num",value="数量",required=true)
                            @PathVariable(name = "num")Integer num,
                            HttpServletResponse response,
                            HttpServletRequest request) throws IOException {
 
        ComplexPropertyPreFilter filter = new ComplexPropertyPreFilter();
        List<PubNewsApi> list = pubNewsService.queryTopList(num);
        response.setHeader("Content-Type","application/json;charset=UTF-8");
        response.getWriter().write(JSONObject.toJSONString(list,filter));
    }
    
    /*
     * 查询资讯信息
     */
    @GetMapping("/getInfoById/{newsid}")
    @ApiOperation(
            value = "查询资讯信息",
            notes = ""
    )
    public void getInfoById(@ApiParam(name="newsid",value="资讯Id",required=true)
                            @PathVariable(name = "newsid") Integer newsid,
                            HttpServletResponse response) throws IOException {
        SimplePropertyPreFilter filter = new SimplePropertyPreFilter();
        filter.getExcludes().add("rcreatedate");
        filter.getExcludes().add("rcreateuser");
 
        response.setHeader("Content-Type","application/json;charset=UTF-8");
        response.getWriter().write(JSONObject.toJSONString(pubNewsService.queryObject(newsid),filter));
    }
 
    /**
     * @Description: 获取全部资讯信息列表
     */
    @GetMapping(path = "/queryAllList")
    @ApiOperation(value = "获取全部资讯信息列表", notes = "获取全部资讯信息列表")
    @ResponseBody
    public String queryAllList(@ApiParam(name = "title", value = "标题")  String title,
                               @ApiParam(name = "type", value = "类型") String type,
                               HttpServletResponse response, HttpServletRequest request) throws IOException {
        ComplexPropertyPreFilter filter = new ComplexPropertyPreFilter();
        PubNews params = new PubNews();
        params.setType(type);
        params.setTitle(title);
        List<PubNews> list = pubNewsService.queryAllList(params);
        StringBuilder rsb = new StringBuilder();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
 
        List<Map<String,Object>> maps = new LinkedList<>();
        for (Integer i = 0; i < list.size(); i++) {
            Map<String, Object> map = new HashMap<>();
            map.put("newsid",list.get(i).getNewsid());
            map.put("title",list.get(i).getTitle());
            map.put("type",list.get(i).getType());
            map.put("createusername",list.get(i).getCreateusername());
            map.put("createdate",sdf.format(list.get(i).getCreatedate()));
            maps.add(map);
        }
        return JSON.toJSONString(maps);
    }
 
    /**
     * @Description: 获取资讯信息分页列表
     * add:dsh(2018/12/05)
     */
    @GetMapping(path = "/queryListByPage")
    @ApiOperation(value = "获取资讯信息分页列表", notes = "获取资讯信息分页列表")
    @ResponseBody
    public String queryListByPage(@ApiParam(name = "title", value = "标题")  String title,
                                  @ApiParam(name = "type", value = "类型") String type,
                                  @ApiParam(name = "pageszie", value = "页数",required = true) Integer pageszie,
                                  @ApiParam(name = "pagecount", value = "条数") Integer pagecount,
                                  HttpServletResponse response, HttpServletRequest request) throws IOException {
        ComplexPropertyPreFilter filter = new ComplexPropertyPreFilter();
        PageBean pageBean = new PageBean();
        pageBean.setPage(pageszie);
        PubNews params = new PubNews();
        params.setType(type);
        if(title != null && !title.isEmpty()) {
            params.setTitle(URLDecoder.decode(title));
        }
        Page<PubNews> page = PageHelper.startPage(pageBean.getPage(), (pagecount!=null?pagecount:15));
        List<PubNews> list = pubNewsService.queryAllList(params);
        StringBuilder rsb = new StringBuilder();
        int countNums = (int) ((Page) list).getTotal();
        PageBean<PubNews> pageData = new PageBean<>(pageBean.getPage(), pageBean.getLimit(), countNums);
        pageData.setItems(list);
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
 
        List<Map<String,Object>> maps = new LinkedList<>();
        for (Integer i = 0; i < list.size(); i++) {
            Map<String, Object> map = new HashMap<>();
            map.put("newsid",list.get(i).getNewsid());
            map.put("title",list.get(i).getTitle());
            map.put("type",list.get(i).getType());
            map.put("createusername",list.get(i).getCreateusername());
            map.put("count",countNums);
            map.put("createdate",sdf.format(list.get(i).getCreatedate()));
            maps.add(map);
        }
        rsb.append("]");
        return JSON.toJSONString(maps);
    }
}