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 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 list = pubNewsService.queryAllList(params); StringBuilder rsb = new StringBuilder(); SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); List> maps = new LinkedList<>(); for (Integer i = 0; i < list.size(); i++) { Map 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 page = PageHelper.startPage(pageBean.getPage(), (pagecount!=null?pagecount:15)); List list = pubNewsService.queryAllList(params); StringBuilder rsb = new StringBuilder(); int countNums = (int) ((Page) list).getTotal(); PageBean pageData = new PageBean<>(pageBean.getPage(), pageBean.getLimit(), countNums); pageData.setItems(list); SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); List> maps = new LinkedList<>(); for (Integer i = 0; i < list.size(); i++) { Map 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); } }