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
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<Class<?>, 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> orgUnit = unitService.queryListByTime(date);
        String ourl = "";
        Iterator<OrgUnit> 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<OrgUnit> 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());
    }
}