CZT
2023-09-06 71c4fa1e27f75ae4b765c95c67a3069c84dc72ba
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
package com.ld.igds.web;
 
import com.bstek.bdf2.core.business.IDept;
import com.bstek.bdf2.core.business.IUser;
import com.bstek.bdf2.core.model.DefaultCompany;
import com.bstek.bdf2.core.model.DefaultDept;
import com.ld.igds.common.CoreCommonService;
import com.ld.igds.constant.BizType;
import com.ld.igds.constant.Constant;
import com.ld.igds.data.Menu;
import com.ld.igds.models.DicSysConf;
import com.ld.igds.sys.service.SysCompanyService;
import com.ld.igds.sys.service.SysDeptService;
import com.ld.igds.sys.service.SystemService;
import com.ld.igds.util.ContextUtil;
import com.ld.igds.util.FilesUtil;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;
 
import java.util.List;
 
/**
 * 系统总控制层,包括登录,登出等
 *
 * @author Andy
 */
@Controller
@RequestMapping
public class WebController {
 
    @Autowired
    private SysCompanyService companyService;
    @Autowired
    private SystemService systemService;
    @Autowired
    private SysDeptService sysDeptService;
    @Autowired
    private CoreCommonService coreCommonService;
 
    /**
     * 跳转不同页面
     *
     * @return
     */
    @RequestMapping("/index-gateway")
    public String indexGateway() {
 
        //获取当前用户的部门
        IUser user = ContextUtil.getLoginUser();
        DefaultDept defaultDept = sysDeptService.loadUserDept(user.getUsername());
 
        if (Constant.DEPT_TYPE_10.equals(defaultDept.getType())) {
            return "redirect:home-group";
        }
 
        DefaultCompany company = companyService.getCompany(user.getCompanyId());
        if (!"all".equals(company.getModel())) {
            return "redirect:home?t=" + company.getModel();
        }
        return "redirect:index";
    }
 
    /**
     * 首页
     *
     * @return
     */
    @RequestMapping("/index")
    public ModelAndView index(@RequestParam(value = "g", required = false) String groupTag) {
        ModelAndView view = new ModelAndView();
 
 
        IUser user = ContextUtil.getLoginUser();
 
        String companyId = user.getCompanyId();
        view.addObject(Constant.MODEL_KEY_LOGIN_USER, user);
 
        // 设置logo
        String logName = FilesUtil.getLogoTitleByCompanyId(companyId);
        view.addObject("logoTitle", "./static/img/" + logName);
 
        DicSysConf sysConf = coreCommonService.getCacheSysConf(user.getCompanyId());
 
        // 数量检测地址,如果没有用#代替
        view.addObject("quantityPath", StringUtils.isEmpty(sysConf
                .getQuantityPath()) ? "#" : sysConf.getQuantityPath());
 
        // 三维演示地址
        view.addObject(
                "threePath",
                StringUtils.isEmpty(sysConf.getThreePath()) ? "#" : sysConf
                        .getThreePath());
 
        // 技术支持信息
        view.addObject("support", "技术支持:" + sysConf.getSupport());
        if (StringUtils.isEmpty(groupTag)){
            groupTag = "0";
        }
        view.addObject("groupTag", groupTag);
 
        view.setViewName("index/index");
 
        //定制首页-上海嘉定
        if ("5303".equals(companyId)) {
            view.setViewName("index/index-5303");
        }
        if ("5318".equals(companyId)) {
            view.setViewName("index/index-5318");
        }
 
        return view;
    }
 
    /**
     * 主页
     *
     * @param code URL模块的标记位置,需要调整格式为:companyId-code
     * @return
     */
    @RequestMapping("/home")
    public ModelAndView home(
            @RequestParam(value = "t", required = false) String code,
            @RequestParam(value = "g", required = false) String groupTag) {
        ModelAndView view = new ModelAndView();
 
        // 用户信息
        IUser user = ContextUtil.getLoginUser();
 
        // 避免非管理恶意访问
        if (StringUtils.isEmpty(code)) {
            code = "0000";
            if (user.isAdministrator()) {
                code = null;
            }
        }
 
        view.addObject(Constant.MODEL_KEY_LOGIN_USER, user);
 
        DicSysConf sysConf = coreCommonService.getCacheSysConf(user
                .getCompanyId());
 
        // 获取当前人选择的分库ID,如果页面没有带入默认获取当前人所在分库。
        String deptId = ContextUtil.subDeptId(user);
        view.addObject(Constant.MODEL_KEY_DEPT_ID, deptId);
 
        // 设置logo
        String logName = FilesUtil.getLogoByCompanyId(user.getCompanyId());
        view.addObject("logo", "./static/img/" + logName);
 
        // 技术支持信息
        view.addObject("support", "技术支持:" + sysConf.getSupport());
        if ("5318".equals(user.getCompanyId())) {
            view.addObject("support", "");
        }
 
        // 系统名称
        String sysName = sysConf.getSysName();
        if (sysName.indexOf(Constant.TAG_SUB_NAME) != -1) {
            DefaultDept defaultDept = sysDeptService.getCacheDept(
                    user.getCompanyId(), deptId);
 
            sysName = sysName.replace(Constant.TAG_SUB_NAME,
                    (null == defaultDept ? "" : defaultDept.getName()));
        }
        view.addObject("sysName", sysName);
 
        // 组织信息
        DefaultCompany company = companyService.getCompany(user.getCompanyId());
        view.addObject("model", company.getModel());
        view.addObject(Constant.MODEL_KEY_DEFAULT_COMPANY, company);
 
        view.addObject("bizType", BizType.SYS.getCode());
 
        // 获取整个分库下拉框
        List<DefaultDept> listDept = sysDeptService.getCacheDept(user.getCompanyId());
        view.addObject("listDept", listDept);
 
        // 验证当前登录人分库权限
        boolean isMain = ContextUtil.isMainDept(user);
        view.addObject("isMain", isMain);
 
        // 获取当前登陆人的菜单
        List<Menu> menuList;
        String welcomeUrl = "./basic/common/welcome?t=";
        if (StringUtils.isEmpty(code)) {
            menuList = systemService.getSysMenu();
            welcomeUrl += "all";
        } else {
            welcomeUrl += code;
            menuList = systemService.getMenuBySystemId(company.getId(), code,user);
        }
 
        view.addObject("menuList", menuList);
        if (null == menuList || menuList.isEmpty()) {
            welcomeUrl = "./no-access";
            view.addObject("menuTag", "NO");
        } else {
            view.addObject("menuTag", "YES");
        }
 
        // 配置默认模块欢迎页面
        view.addObject("welcomeUrl", welcomeUrl);
 
 
        if (StringUtils.isEmpty(groupTag)) {
            groupTag = "0";
        }
        view.addObject("groupTag", groupTag);
 
        view.setViewName("admin/home");
        return view;
    }
 
    /**
     * 集团/公司-主页,主页直接展示当前人所在的实际部门,并获取组织专用菜单
     *
     * @param code
     * @return
     */
    @RequestMapping("/home-group")
    public ModelAndView homeGroup(@RequestParam(value = "t", required = false) String code) {
 
        ModelAndView view = new ModelAndView();
 
        // 用户信息
        IUser user = ContextUtil.getLoginUser();
        view.addObject(Constant.MODEL_KEY_LOGIN_USER, user);
 
        DicSysConf sysConf = coreCommonService.getCacheSysConf(user.getCompanyId());
        // 获取当前人选择的分库ID,如果页面没有带入默认获取当前人所在分库。
        String deptId = ContextUtil.subDeptId(user);
        view.addObject(Constant.MODEL_KEY_DEPT_ID, deptId);
 
        // 获取当前人所配置的实际部门
        IDept dept = user.getDepts().get(0);
        view.addObject("dept", dept);
 
        //框架上左侧的LGOO
        // 设置logo
        String logName = FilesUtil.getLogoByCompanyId(user.getCompanyId());
        view.addObject("logo", "./static/img/" + logName);
 
        // 技术支持信息
        view.addObject("support", "技术支持:" + sysConf.getSupport());
 
        // 系统名称
        String sysName = sysConf.getSysName();
        if (sysName.indexOf(Constant.TAG_SUB_NAME) != -1) {
            DefaultDept defaultDept = sysDeptService.getCacheDept(user.getCompanyId(), dept.getId());
            sysName = sysName.replace(Constant.TAG_SUB_NAME, (null == defaultDept ? "" : defaultDept.getName()));
        }
        view.addObject("sysName", sysName);
 
        view.addObject("bizType", BizType.SYS.getCode());
 
        // 获取当前登陆人的菜单-公司集团专用
        List<Menu> menuList = systemService.getSysGroupMenu();
        view.addObject("menuList", menuList);
 
        // 配置默认模块欢迎页面
        String welcomeUrl = ".../../basic/gis/gis-group";
        view.addObject("welcomeUrl", welcomeUrl);
 
 
        if (null == menuList || menuList.isEmpty()) {
            view.addObject("menuTag", "NO");
        } else {
            view.addObject("menuTag", "YES");
        }
 
        view.setViewName("admin/home-group");
        return view;
    }
 
    /**
     * 无权限页面
     *
     * @return
     */
    @RequestMapping("/no-access")
    public String noAccess() {
        return "no-access";
    }
 
    /**
     * 会话超时
     *
     * @return
     */
    @RequestMapping("/session-out")
    public String sessionOut() {
        return "session-out";
    }
 
    /**
     * 登陆被踢出
     *
     * @return
     */
    @RequestMapping("/session-kick-away")
    public String sessionKickAway() {
        return "session-kick-away";
    }
 
    /**
     * 没有授权页面
     *
     * @return
     */
    @RequestMapping("/no-license")
    public String noLicense() {
        return "no-license";
    }
 
}