2
13693261870
2022-09-16 653761a31dfeb50dd3d007e892d69c90bf0cdafc
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
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
package com.landtool.lanbase.modules.res.controller;
 
import java.io.File;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
 
import javax.servlet.http.HttpServletRequest;
 
import org.apache.commons.lang.StringUtils;
import org.apache.shiro.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
 
import com.alibaba.fastjson.JSONObject;
import com.landtool.lanbase.common.utils.HttpOperateUtils;
import com.landtool.lanbase.config.SysTemPropertyConfig;
import com.landtool.lanbase.modules.org.entity.OrgUnit;
import com.landtool.lanbase.modules.org.service.OrgUnitService;
import com.landtool.lanbase.modules.org.service.OrgUserService;
import com.landtool.lanbase.modules.res.entity.Res_ApplyRecommend;
import com.landtool.lanbase.modules.res.entity.Res_Catalog;
import com.landtool.lanbase.modules.res.entity.Res_MainInfo;
import com.landtool.lanbase.modules.res.service.ResApplyRecommendService;
import com.landtool.lanbase.modules.res.service.ResCatalogService;
import com.landtool.lanbase.modules.res.service.ResMainInfoService;
import com.landtool.lanbase.modules.sys.controller.AbstractController;
import com.landtool.lanbase.modules.sys.service.SysFieldvalueService;
 
/**
 * 功能描述:资源管理 - 资源注册
 */
@Controller
@RequestMapping("/res/ResManage/ResRegister")
public class ResRegisterController extends AbstractController {
    @Autowired
    private ResMainInfoService resMainInfoService;
 
    @Autowired
    private ResCatalogService resCatalogService;
 
    @Autowired
    private ResApplyRecommendService resApplyRecommendService;
 
    @Autowired
    private SysTemPropertyConfig sysConfig;
 
    @Autowired
    private SysFieldvalueService FieldUtils;
 
    @Autowired
    private OrgUnitService orgUnitService;
 
    @Autowired
    private OrgUserService orgUserService;
 
    @Value("${sys.iconResourcePath}")
    private String iconResourcePath;
 
    /**
     * 列表页面
     */
    @RequestMapping("/List")
    public String List(Model model) {
        HashMap<String, String> ResourceTypeList = FieldUtils.getFieldListByKey("ResourceType");// 获取资源类型列表
        System.out.println("测试资源类型--------------------------\n" + ResourceTypeList + "-------------------------------------------------");
        model.addAttribute("ResourceTypeList", ResourceTypeList);
        model.addAttribute("pubzyWebRoot", sysConfig.getPubzyWebRoot());
        model.addAttribute("systemName", sysConfig.getAppFullName());
        HashMap<String, String> SharProtocolList = FieldUtils.getFieldListByKey("SharProtocol");// 获取共享协议列表
        model.addAttribute("SharProtocolList",SharProtocolList);
        return "ResManage/ResRegister/List";
    }
 
    /**
     * 编辑页面
     */
    @RequestMapping("/ResEdit")
    public String Edit(Model model, Long resMainInfoId) {
        if (resMainInfoId != null) {
            Res_MainInfo resMainInfo = resMainInfoService.selectByPrimaryKey(resMainInfoId.intValue());
            HashMap<String, String> ResourceTypeList = FieldUtils.getFieldListByKey("ResourceType");// 获取资源类型列表
            model.addAttribute("resourceclass", ResourceTypeList.get(resMainInfo.getResourceclass()));
        }
        String pubzyWebRoot = sysConfig.getPubzyWebRoot();
        model.addAttribute("resMainInfoId", resMainInfoId);
        model.addAttribute("pubzyWebRoot", pubzyWebRoot);
        model.addAttribute("systemName", sysConfig.getAppFullName());
        model.addAttribute("jspwebroot", pubzyWebRoot.replace("javapubzy/", ""));// 临时处理
        return "ResManage/ResRegister/Edit";
    }
 
    /**
     * 基本信息
     */
    @RequestMapping("/MainInfo")
    public String MainInfo(HttpServletRequest request, Model model, Long resMainInfoId) throws IOException {
        Res_MainInfo res_mainInfo = new Res_MainInfo();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        Res_Catalog res_catalog = new Res_Catalog();
        String newDate = sdf.format(new Date());
        String Imagelujin = null;
        int auditstatus = -1;// 审核状态
        // 获取当前登录人id name 还有对应的单位id name
        Long userid = getUserId();
 
        // 修改
        if (resMainInfoId != null) {
            res_mainInfo = resMainInfoService.selectByPrimaryKey(resMainInfoId.intValue());
            String Pubdate = sdf.format(res_mainInfo.getPubdate());
            if (res_mainInfo.getProductiontime() != null) {
                String productiontimes = sdf.format(res_mainInfo.getProductiontime());
                model.addAttribute("productiontime", productiontimes);
            }
            model.addAttribute("Pubdate", Pubdate);
            if (res_mainInfo.getCatlogid() != null) {
                res_catalog = resCatalogService.selectByPrimaryKey(res_mainInfo.getCatlogid());
                if (res_catalog != null) {
                    model.addAttribute("catlogtitle", res_catalog.getTitle());
                }
            }
            if (res_mainInfo.getImgurl() != null && res_mainInfo.getImgurl() != "") {
                if(res_mainInfo.getImgurl().startsWith("Atkas")){//图集
                    Imagelujin = "/image/"+res_mainInfo.getImgurl();
                }else{
                    StringBuffer url = request.getRequestURL();
                    //TODO: 这个映射路径 直接写死代码里面2018.5.20
                    String ip = "/uploadPath/";
                    Imagelujin = ip + res_mainInfo.getImgurl();
                }
            }
            // modified by qufangxu 信创环境下,若 res_mainInfo.getAdministrativeid() = '        ',会返回单点登录页面,具体原因未知。 解决办法:提前去除空格、制表符
            String administrativeid = (String) res_mainInfo.getAdministrativeid();// 数据覆盖范围--行政区划Id
            String finalValue = null;
            if (StringUtils.isNotEmpty(administrativeid)){
                finalValue = administrativeid.trim();
            }
            if (StringUtils.isNotEmpty(finalValue)) {
                String getRegionInfourl = sysConfig.getApiServer() + "/api/org/region/getById/" + administrativeid;
                String jsonStr = HttpOperateUtils.httpGet(getRegionInfourl.trim());
                if (jsonStr != null && !jsonStr.isEmpty()) {
                    JSONObject item = JSONObject.parseObject(jsonStr);
                    String regionname = item.getString("regionname");
                    model.addAttribute("administrativename", regionname);
                }
            }
            // 审核状态
            if (res_mainInfo.getAuditstatus() != null) {
                auditstatus = res_mainInfo.getAuditstatus();
            }
            model.addAttribute("chinesename", orgUserService.queryObject(res_mainInfo.getCreateuserid()).getChinesename());
            if(res_mainInfo.getPubunitid() == 0) {
                OrgUnit orgunit = orgUserService.getDefaultUnit(res_mainInfo.getCreateuserid());
                model.addAttribute("unitname", orgunit.getUnitname());
                res_mainInfo.setPubunitid(orgunit.getUnitid().intValue());
            } else {
                OrgUnit orgunit = orgUnitService.getUnitById(res_mainInfo.getPubunitid().longValue());
                model.addAttribute("unitname", orgunit.getUnitname());
            }
        } else {
            //新增
            OrgUnit orgunit = orgUserService.getDefaultUnit(userid);
            String unitname = "";
            if(orgunit.getUnitid() != null) {
                res_mainInfo.setPubunitid(orgunit.getUnitid().intValue());
                unitname = orgunit.getUnitname();
            }
            res_mainInfo.setCreateuserid(userid);
            // modified by qufangxu
            res_mainInfo.setInsteadaudit(0);
            model.addAttribute("loginname", getUser().getLoginname());
            model.addAttribute("unitname", unitname);
            model.addAttribute("Pubdate", newDate);
            model.addAttribute("chinesename", getUser().getChinesename());
        }
        HashMap<String, String> ResourceTypeList = FieldUtils.getFieldListByKey("ResourceType");// 获取资源类型列表
        //获取数据来源列表
        LinkedHashMap<String, String> DataSourceList = FieldUtils.getDataSourceList();
        String datasources = res_mainInfo.getDatasources();
        if(StringUtils.isNotBlank(datasources)){
            DataSourceList.put(datasources, datasources);
        }
        HashMap<String, String> SharProtocolList = FieldUtils.getFieldListByKey("SharProtocol");// 获取共享协议列表
        List<String> list = resMainInfoService.selectTopHotSearch();
        String[] KeywordsList = new String[list.size()];// 获取关键字列表
        for (int i = 0; i < list.size(); i++) {
            KeywordsList[i] = list.get(i);
        }
        //换地址
        if(res_mainInfo != null && res_mainInfo.getDesurl() != null && res_mainInfo.getDesurl().indexOf("diydes") != -1 && res_mainInfo.getDesurl().indexOf(res_mainInfo.getResourceid().toString()) != -1){
            String url = sysConfig.getUploadRootPath()+res_mainInfo.getDesurl();
            res_mainInfo.setDesurl(url);
        }
        model.addAttribute("datasourcelist", DataSourceList);
        model.addAttribute("mainInfo", res_mainInfo);
        // model.addAttribute("rescatalog", res_catalog);
        model.addAttribute("resMainInfoId", resMainInfoId);
        model.addAttribute("ResourceTypeList", ResourceTypeList);
        model.addAttribute("Imagelujin", Imagelujin);
        model.addAttribute("auditstatus", auditstatus);
        model.addAttribute("SharProtocolList", SharProtocolList);
        model.addAttribute("KeywordsList", KeywordsList);
 
        HashMap<String, String> UpdateTimesList = FieldUtils.getFieldListByKey("UpdateTimes");// 获取更新频率列表
        model.addAttribute("UpdateTimesList", UpdateTimesList);
 
        if(SecurityUtils.getSubject().isPermitted("org_user_admin")) {
            //判断当前用户是否是管理员,是管理员或是未提交的资源才可以修改资源相关信息
            model.addAttribute("admin",true);
        }
        else {
            model.addAttribute("admin",false);
        }
        return "ResManage/ResRegister/MainInfo";
    }
 
    /**
     * 所属目录目录树
     */
    @RequestMapping("/MuLuShu")
    public String muLuShu(Model model) {
        model.addAttribute("backstageWebRoot", sysConfig.getApiServer() + "/");
        model.addAttribute("pubzyWebRoot", sysConfig.getPubzyWebRoot());
        return "ResManage/ResRegister/MuLuShu";
    }
 
    /**
     * 行政区划目录树
     */
    @RequestMapping("/AreaTree")
    public String areaTree(Model model) {
        model.addAttribute("backstageWebRoot", sysConfig.getApiServer() + "/");
        model.addAttribute("pubzyWebRoot", sysConfig.getPubzyWebRoot());
        model.addAttribute("systemName", sysConfig.getAppFullName());
        return "ResManage/ResRegister/AreaTree";
    }
 
    // 根据资源ID返回资源名称给专题地图扩展表
    @ResponseBody
    @RequestMapping("/dataname")
    public String dataname(int resourceid) {
        Res_MainInfo list = resMainInfoService.selectByPrimaryKey(resourceid);
        String name = list.getTitle();
        return name;
    }
 
    /**
     * 资源推荐页面
     */
    @RequestMapping("ZiYuanRecommend")
    public String ziYuanRecommend(int resourceid, Model model) { 
        Long userid = getUserId();
        model.addAttribute("backstageWebRoot", sysConfig.getApiServer() + "/");
        model.addAttribute("pubzyWebRoot", sysConfig.getPubzyWebRoot());
        model.addAttribute("resourceid", resourceid);
        model.addAttribute("userid", userid);
        String userIds = "";
        String unitIds = "";
        Res_ApplyRecommend entity = new Res_ApplyRecommend();
        entity.setResourceid(resourceid);
 
        List<Res_ApplyRecommend> resApplyRecommendList = resApplyRecommendService.getRecommendListByResourceid(entity);
        for (Res_ApplyRecommend resApplyRecommend : resApplyRecommendList) {
            if (resApplyRecommend.getApptype() == 0) {
                if (!userIds.isEmpty())
                    userIds += ",";
                userIds += resApplyRecommend.getAppuserid();
            } else if (resApplyRecommend.getApptype() == 1) {
                if (!unitIds.isEmpty())
                    unitIds += ",";
                unitIds += resApplyRecommend.getAppunitid();
            }
        }
 
        model.addAttribute("userIds", userIds);
        model.addAttribute("unitIds", unitIds);
 
        return "ResManage/ResRegister/ZiYuanRecommend";
    }
 
    /**
     * 图集列表
     */
    @RequestMapping("/AtkasList")
    public String AtkasList(Model model,String resourceclass) {
        List<String > atkasList = new ArrayList<>();
        String path = iconResourcePath;
        TraverseFolder(path,atkasList,resourceclass);
        model.addAttribute("atkasList",atkasList);
        model.addAttribute("backstageWebRoot", sysConfig.getApiServer() + "/");
        model.addAttribute("pubzyWebRoot", sysConfig.getPubzyWebRoot());
        model.addAttribute("systemName", sysConfig.getAppFullName());
        return "ResManage/ResRegister/AtkasList";
    }
 
    public void TraverseFolder(String path,List<String> atkasList,String resourceclass) {
        File file = new File(path);
        if (file.exists()) {
            File[] files = file.listFiles();
            if (files.length != 0) {
                for (File file2 : files) {
                    if (file2.isDirectory()) {//文件夹
                        TraverseFolder(file2.getAbsolutePath(),atkasList,resourceclass);
                    } else {//文件
                        if(resourceclass == null || resourceclass.length() == 0){
                            atkasList.add(file.getName()+"|"+file2.getName());
                        }else{
                            if(file.getName().equals(resourceclass)){
                                atkasList.add(file.getName()+"|"+file2.getName());
                            }
                        }
                    }
                }
            }
        }
    }
}