DictionariesController.java
7.97 KB
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
package com.fh.controller.system.dictionaries;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.annotation.Resource;
import net.sf.json.JSONArray;
import org.springframework.beans.propertyeditors.CustomDateEditor;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.WebDataBinder;
import org.springframework.web.bind.annotation.InitBinder;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;
import com.fh.controller.base.BaseController;
import com.fh.entity.Page;
import com.fh.util.AppUtil;
import com.fh.util.PageData;
import com.fh.util.Jurisdiction;
import com.fh.service.system.dictionaries.DictionariesManager;
/**
* 说明:数据字典
* 创建时间:2015-12-16
*/
@Controller
@RequestMapping(value="/dictionaries")
public class DictionariesController extends BaseController {
String menuUrl = "dictionaries/list.do"; //菜单地址(权限用)
@Resource(name="dictionariesService")
private DictionariesManager dictionariesService;
/**保存
* @param
* @throws Exception
*/
@RequestMapping(value="/save")
public ModelAndView save() throws Exception{
logBefore(logger, Jurisdiction.getUsername()+"新增Dictionaries");
if(!Jurisdiction.buttonJurisdiction(menuUrl, "add")){return null;} //校验权限
ModelAndView mv = this.getModelAndView();
PageData pd = new PageData();
pd = this.getPageData();
pd.put("DICTIONARIES_ID", this.get32UUID()); //主键
dictionariesService.save(pd);
mv.addObject("msg","success");
mv.setViewName("save_result");
return mv;
}
/**
* 删除
* @param DICTIONARIES_ID
* @param
* @throws Exception
*/
@RequestMapping(value="/delete")
@ResponseBody
public Object delete(@RequestParam String DICTIONARIES_ID) throws Exception{
if(!Jurisdiction.buttonJurisdiction(menuUrl, "del")){return null;} //校验权限
logBefore(logger, Jurisdiction.getUsername()+"删除Dictionaries");
Map<String,String> map = new HashMap<String,String>();
PageData pd = new PageData();
pd.put("DICTIONARIES_ID", DICTIONARIES_ID);
String errInfo = "success";
if(dictionariesService.listSubDictByParentId(DICTIONARIES_ID).size() > 0){//判断是否有子级,是:不允许删除
errInfo = "false";
}else{
pd = dictionariesService.findById(pd);//根据ID读取
if(null != pd.get("TBSNAME") && !"".equals(pd.getString("TBSNAME"))){
String[] table = pd.getString("TBSNAME").split(",");
for(int i=0;i<table.length;i++){
pd.put("thisTable", table[i]);
try {
if(Integer.parseInt(dictionariesService.findFromTbs(pd).get("zs").toString())>0){//判断是否被占用,是:不允许删除(去排查表检查字典表中的编码字段)
errInfo = "false";
break;
}
} catch (Exception e) {
errInfo = "false2";
break;
}
}
}
}
if("success".equals(errInfo)){
dictionariesService.delete(pd); //执行删除
}
map.put("result", errInfo);
return AppUtil.returnObject(new PageData(), map);
}
/**修改
* @param
* @throws Exception
*/
@RequestMapping(value="/edit")
public ModelAndView edit() throws Exception{
logBefore(logger, Jurisdiction.getUsername()+"修改Dictionaries");
if(!Jurisdiction.buttonJurisdiction(menuUrl, "edit")){return null;} //校验权限
ModelAndView mv = this.getModelAndView();
PageData pd = new PageData();
pd = this.getPageData();
dictionariesService.edit(pd);
mv.addObject("msg","success");
mv.setViewName("save_result");
return mv;
}
/**列表
* @param page
* @throws Exception
*/
@RequestMapping(value="/list")
public ModelAndView list(Page page) throws Exception{
logBefore(logger, Jurisdiction.getUsername()+"列表Dictionaries");
ModelAndView mv = this.getModelAndView();
PageData pd = new PageData();
pd = this.getPageData();
String keywords = pd.getString("keywords"); //检索条件
if(null != keywords && !"".equals(keywords)){
pd.put("keywords", keywords.trim());
}
String DICTIONARIES_ID = null == pd.get("DICTIONARIES_ID")?"":pd.get("DICTIONARIES_ID").toString();
if(null != pd.get("id") && !"".equals(pd.get("id").toString())){
DICTIONARIES_ID = pd.get("id").toString();
}
pd.put("DICTIONARIES_ID", DICTIONARIES_ID); //上级ID
page.setPd(pd);
List<PageData> varList = dictionariesService.list(page); //列出Dictionaries列表
mv.addObject("pd", dictionariesService.findById(pd)); //传入上级所有信息
mv.addObject("DICTIONARIES_ID", DICTIONARIES_ID); //上级ID
mv.setViewName("system/dictionaries/dictionaries_list");
mv.addObject("varList", varList);
mv.addObject("QX",Jurisdiction.getHC()); //按钮权限
return mv;
}
/**
* 显示列表ztree
* @param model
* @return
*/
@RequestMapping(value="/listAllDict")
public ModelAndView listAllDict(Model model,String DICTIONARIES_ID)throws Exception{
ModelAndView mv = this.getModelAndView();
PageData pd = new PageData();
pd = this.getPageData();
try{
JSONArray arr = JSONArray.fromObject(dictionariesService.listAllDict("0"));
String json = arr.toString();
json = json.replaceAll("DICTIONARIES_ID", "id").replaceAll("PARENT_ID", "pId").replaceAll("NAME", "name").replaceAll("subDict", "nodes").replaceAll("hasDict", "checked").replaceAll("treeurl", "url");
model.addAttribute("zTreeNodes", json);
mv.addObject("DICTIONARIES_ID",DICTIONARIES_ID);
mv.addObject("pd", pd);
mv.setViewName("system/dictionaries/dictionaries_ztree");
} catch(Exception e){
logger.error(e.toString(), e);
}
return mv;
}
/**去新增页面
* @param
* @throws Exception
*/
@RequestMapping(value="/goAdd")
public ModelAndView goAdd()throws Exception{
ModelAndView mv = this.getModelAndView();
PageData pd = new PageData();
pd = this.getPageData();
String DICTIONARIES_ID = null == pd.get("DICTIONARIES_ID")?"":pd.get("DICTIONARIES_ID").toString();
pd.put("DICTIONARIES_ID", DICTIONARIES_ID); //上级ID
mv.addObject("pds",dictionariesService.findById(pd)); //传入上级所有信息
mv.addObject("DICTIONARIES_ID", DICTIONARIES_ID); //传入ID,作为子级ID用
mv.setViewName("system/dictionaries/dictionaries_edit");
mv.addObject("msg", "save");
return mv;
}
/**去修改页面
* @param
* @throws Exception
*/
@RequestMapping(value="/goEdit")
public ModelAndView goEdit()throws Exception{
ModelAndView mv = this.getModelAndView();
PageData pd = new PageData();
pd = this.getPageData();
String DICTIONARIES_ID = pd.getString("DICTIONARIES_ID");
pd = dictionariesService.findById(pd); //根据ID读取
mv.addObject("pd", pd); //放入视图容器
pd.put("DICTIONARIES_ID",pd.get("PARENT_ID").toString()); //用作上级信息
mv.addObject("pds",dictionariesService.findById(pd)); //传入上级所有信息
mv.addObject("DICTIONARIES_ID", pd.get("PARENT_ID").toString()); //传入上级ID,作为子ID用
pd.put("DICTIONARIES_ID",DICTIONARIES_ID); //复原本ID
mv.setViewName("system/dictionaries/dictionaries_edit");
mv.addObject("msg", "edit");
return mv;
}
/**判断编码是否存在
* @return
*/
@RequestMapping(value="/hasBianma")
@ResponseBody
public Object hasBianma(){
Map<String,String> map = new HashMap<String,String>();
String errInfo = "success";
PageData pd = new PageData();
try{
pd = this.getPageData();
if(dictionariesService.findByBianma(pd) != null){
errInfo = "error";
}
} catch(Exception e){
logger.error(e.toString(), e);
}
map.put("result", errInfo); //返回结果
return AppUtil.returnObject(new PageData(), map);
}
@InitBinder
public void initBinder(WebDataBinder binder){
DateFormat format = new SimpleDateFormat("yyyy-MM-dd");
binder.registerCustomEditor(Date.class, new CustomDateEditor(format,true));
}
}