package com.landtool.lanbase.modules.api.controller; import java.io.IOException; import java.util.Date; import java.util.HashMap; import java.util.Iterator; import java.util.List; import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.serializer.SimplePropertyPreFilter; import com.landtool.lanbase.common.utils.ComplexPropertyPreFilter; import com.landtool.lanbase.common.utils.IPUtils; import com.landtool.lanbase.modules.org.entity.OrgUnitRegion; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.format.annotation.DateTimeFormat; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.*; import com.landtool.lanbase.modules.org.entity.OrgUnit; import com.landtool.lanbase.modules.org.entity.OrgUnitJoinRegion; import com.landtool.lanbase.modules.org.entity.OrgUser; import com.landtool.lanbase.modules.org.service.OrgUnitService; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiParam; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; /** * @Description: 单位信息模块提供的api * @Author: bing.guo * @Date: 2018/2/01 */ @Controller @RequestMapping(path = "/api/org/unit/") @Api(value = "", tags = { "用户单位相关接口" }) public class OrgUnitApiController { @Autowired private OrgUnitService unitService; private String http = "http://"; /** * 查询单位信息 * * @param unitid * @return */ @GetMapping(path = "/getInfoById/{unitid}") @ApiOperation(value = "查询单位信息", notes = "包含单位管辖行政区划信息") public void getInfoById( @ApiParam(name = "unitid", value = "单位Id", required = true) @PathVariable(name = "unitid") Long unitid, HttpServletResponse response, HttpServletRequest request) throws IOException { ComplexPropertyPreFilter filter = new ComplexPropertyPreFilter(); filter.setExcludes(new HashMap, String[]>() { private static final long serialVersionUID = -23423423423423434L; { put(OrgUnitJoinRegion.class, new String[] { "spellfirst", "rcreatedate", "rcreateuser", "rlasteditdate", "rorder" }); put(OrgUnitRegion.class, new String[] { "rcreatedate", "rcreateuser", "rlasteditdate" }); } }); OrgUnitJoinRegion orgUnitJoinRegion = unitService.queryObjectJoinRegion(unitid); String photourl = ""; if (orgUnitJoinRegion.getPhotourl() != null) { // TODO: bug需要获取服务器IP而不是客户端IP地址 photourl = http + (IPUtils.getIpAddr(request)) + ":" + request.getServerPort() + "/uploadFile" + orgUnitJoinRegion.getPhotourl(); orgUnitJoinRegion.setPhotourl(photourl); } response.setHeader("Content-Type", "application/json;charset=UTF-8"); response.getWriter().write(JSONObject.toJSONString(orgUnitJoinRegion, filter)); } /** * 根据时间戳获取单位信息列表 * * @param time * @return */ @GetMapping(path = "/queryListByTime/{time}") @ApiOperation(value = "根据时间戳获取单位信息列表", notes = "") public void queryListByTime( @ApiParam(name = "time", value = "时间戳", required = true) @PathVariable(name = "time") Long time, HttpServletResponse response, HttpServletRequest request) throws IOException { SimplePropertyPreFilter filter = new SimplePropertyPreFilter(); filter.getExcludes().add("spellfirst"); filter.getExcludes().add("rcreatedate"); filter.getExcludes().add("rcreateuser"); filter.getExcludes().add("rlasteditdate"); filter.getExcludes().add("rorder"); Date date = new Date(time); List orgUnit = unitService.queryListByTime(date); String ourl = ""; Iterator it = orgUnit.iterator(); while (it.hasNext()) { OrgUnit user = (OrgUnit) it.next(); String photourl = user.getPhotourl(); if (photourl != null) { ourl = http + (IPUtils.getIpAddr(request)) + ":" + request.getServerPort() + "/uploadFile" + photourl; user.setPhotourl(ourl); } } response.setHeader("Content-Type", "application/json;charset=UTF-8"); response.getWriter().write(JSONObject.toJSONString(orgUnit, filter)); } /** * @Description: 获取单位列表 */ @GetMapping(path = "/queryAllList") @ApiOperation(value = "获取单位列表", notes = "获取单位列表") public void queryAllList(HttpServletResponse response, HttpServletRequest request) throws IOException { ComplexPropertyPreFilter filter = new ComplexPropertyPreFilter(); List list = unitService.queryAllList(); StringBuilder rsb = new StringBuilder(); rsb.append("[{id:'0',name:'全国',parentid:'-1',open:true}"); for (int i = 0; i < list.size(); i++) { OrgUnit orgUnit = list.get(i); rsb.append(",{id: '" + orgUnit.getUnitid() + "', name: '" + orgUnit.getUnitname() + "',parentid:'" + orgUnit.getParentid() + "'}"); } rsb.append("]"); response.setHeader("Content-Type", "application/json;charset=UTF-8"); response.getWriter().write(rsb.toString()); } }