NgAlainController.java
3.2 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
package com.skua.modules.ngalain.controller;
import java.util.ArrayList;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import com.skua.core.api.vo.Result;
import com.skua.core.api.vo.DictModel;
import com.skua.core.api.vo.LoginUser;
import com.skua.modules.ngalain.service.NgAlainService;
import com.skua.modules.system.service.ISysDictService;
import org.apache.shiro.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import com.alibaba.fastjson.JSONObject;
import lombok.extern.slf4j.Slf4j;
@Slf4j
@RestController
@RequestMapping("/sys/ng-alain")
public class NgAlainController {
@Autowired
private NgAlainService ngAlainService;
@Autowired
private ISysDictService sysDictService;
@RequestMapping(value = "/getAppData")
@ResponseBody
public JSONObject getAppData(HttpServletRequest request) throws Exception {
String token=request.getHeader("X-Access-Token");
JSONObject j = new JSONObject();
LoginUser user = (LoginUser) SecurityUtils.getSubject().getPrincipal();
JSONObject userObjcet = new JSONObject();
userObjcet.put("name", user.getUsername());
userObjcet.put("avatar", user.getAvatar());
userObjcet.put("email", user.getEmail());
userObjcet.put("token", token);
j.put("user", userObjcet);
j.put("menu",ngAlainService.getMenu(user.getUsername()));
JSONObject app = new JSONObject();
app.put("name", "jeecg-boot-angular");
app.put("description", "jeecg+ng-alain整合版本");
j.put("app", app);
return j;
}
@RequestMapping(value = "/getDictItems/{dictCode}", method = RequestMethod.GET)
public Object getDictItems(@PathVariable String dictCode) {
log.info(" dictCode : "+ dictCode);
Result<List<DictModel>> result = new Result<List<DictModel>>();
List<DictModel> ls = null;
try {
ls = sysDictService.queryDictItemsByCode(dictCode);
result.setSuccess(true);
result.setResult(ls);
} catch (Exception e) {
log.error(e.getMessage(),e);
result.error500("操作失败");
return result;
}
List<JSONObject> dictlist=new ArrayList<>();
for (DictModel l : ls) {
JSONObject dict=new JSONObject();
try {
dict.put("value",Integer.parseInt(l.getValue()));
} catch (NumberFormatException e) {
dict.put("value",l.getValue());
}
dict.put("label",l.getText());
dictlist.add(dict);
}
return dictlist;
}
@RequestMapping(value = "/getDictItemsByTable/{table}/{key}/{value}", method = RequestMethod.GET)
public Object getDictItemsByTable(@PathVariable String table,@PathVariable String key,@PathVariable String value) {
return this.ngAlainService.getDictByTable(table,key,value);
}
}