1
2
3
4
5 package gboat2.web.action;
6
7 import gboat2.base.core.annotation.Domain;
8 import gboat2.base.core.annotation.ListDomain;
9 import gboat2.base.core.annotation.Module;
10 import gboat2.base.core.annotation.Operation;
11 import gboat2.base.core.annotation.Operations;
12 import gboat2.base.core.annotation.Preference;
13 import gboat2.base.core.cache.ICacheService;
14 import gboat2.base.core.web.BaseActionSupport;
15 import gboat2.base.core.web.JsonResultSupport;
16 import gboat2.base.bridge.model.UserSession;
17 import gboat2.base.bridge.GboatAppContext;
18 import gboat2.web.Constants;
19 import gboat2.web.business.IGroupBusiness;
20 import gboat2.web.business.ILoginBusiness;
21 import gboat2.web.business.IRoleBusiness;
22 import gboat2.web.business.ISystemConfigBusiness;
23 import gboat2.web.model.Group;
24 import gboat2.web.model.Role;
25 import gboat2.web.model.SystemAuthorityResourceVO;
26 import gboat2.web.model.SystemConfig;
27 import gboat2.web.util.BundleUtil;
28
29 import java.net.URL;
30 import java.util.List;
31
32 import org.apache.commons.lang3.StringUtils;
33 import org.apache.struts2.convention.annotation.ResultPath;
34 import org.springframework.beans.factory.annotation.Autowired;
35
36
37
38
39
40
41 @Domain(value = SystemConfig.class)
42 @ListDomain(value = SystemConfig.class)
43 @ResultPath("/content/systemconfig")
44 @Preference("/系统配置/系统管理")
45 @Module(name = "系统管理", desc = "管理各系统")
46 @Operations(value = { @Operation(code = "add", name = "新增系统"), @Operation(code = "edit", name = "编辑"), @Operation(name = "删除", code = "ajaxDelete") })
47 public class SystemConfigAction extends BaseActionSupport {
48
49 private static final long serialVersionUID = 3502812072080285347L;
50
51 @Autowired
52 private ICacheService cache;
53
54 @Autowired
55 private ISystemConfigBusiness syscfgBusi;
56
57 @Autowired
58 private ILoginBusiness loginBusiness;
59
60 @Autowired
61 private IGroupBusiness gropBusi;
62
63 @Autowired
64 private IRoleBusiness roleBusi;
65
66
67 public String systems() {
68 List<SystemConfig> systems = (List<SystemConfig>) syscfgBusi.getAllSystemConfig();
69 JsonResultSupport.output(systems);
70 return null;
71 }
72
73 protected void initSave() {
74 SystemConfig cfg = (SystemConfig) this.get_M();
75
76 if(StringUtils.isEmpty(cfg.getIndexUrl())){
77 String indexUrl = this.generateUrl(cfg.getLoginBundleName());
78 cfg.setIndexUrl(indexUrl);
79 }
80 }
81
82 private String generateUrl(String str) {
83 String ret = null;
84 if (StringUtils.isBlank(str)) {
85 return ret;
86 }
87 str = str.substring(0, str.lastIndexOf("."));
88 str = str.substring(str.lastIndexOf(".") + 1, str.length());
89 ret = "/" + str + "/g-index.do";
90 return ret;
91 }
92
93 @Override
94 protected void postSave() {
95
96
97 SystemConfig cfg = (SystemConfig) this.get_M();
98 String systemId = cfg.getSystemId();
99 this.cache.remove(Constants.SYS_CFG_CACHE_CATALOG, Constants.SYS_CFG_CACHE_KEY + "-" + systemId);
100 }
101
102 @Override
103 protected void postDelete() {
104
105
106 SystemConfig cfg = (SystemConfig) this.get_M();
107 String systemId = cfg.getSystemId();
108 this.cache.remove(Constants.SYS_CFG_CACHE_CATALOG, Constants.SYS_CFG_CACHE_KEY + "-" + systemId);
109 }
110
111 public void systemsOfUser() {
112 UserSession session = GboatAppContext.getUserSession();
113 if (StringUtils.isEmpty(session.getRoleCode())) {
114 JsonResultSupport.outputFailure("该用户没有角色!不能拥有多个系统!");
115 return;
116 }
117
118 Group group = gropBusi.findGroupByGroupCode(session.getGroupCode());
119 if (loginBusiness.isNeedToVerifyByGroup(group.getGroupId())) {
120 if (!loginBusiness.isVerifySuccess(session.getOrganId())) {
121 JsonResultSupport.outputFailure("用户信息未通过诚信系统验证,不能切换!");
122 return;
123 }
124 }
125
126 Role role = roleBusi.findRoleByRoleCode(session.getRoleCode());
127 List<SystemAuthorityResourceVO> sysList = syscfgBusi.getSystemsOfRole(role.getRoleId());
128
129 if (null != sysList) {
130 String bundleName = null;
131 for (SystemConfig sys : sysList) {
132 bundleName = sys.getLoginBundleName();
133 if (StringUtils.isNotEmpty(bundleName)) {
134 bundleName = bundleName.trim();
135 }
136 String icon = "static/" + bundleName + "/themes/default/images/system/icon.png";
137 URL url = BundleUtil.getResourceOfBundle(bundleName, icon);
138
139 if (null != url) {
140 sys.setIcon(icon);
141 } else {
142 sys.setIcon("static/gboat2.web/themes/default/images/system/icon.png");
143 }
144 }
145 }
146
147 JsonResultSupport.output(sysList);
148
149 }
150
151 }