9bba5447c3d772d6319a2b54f726b572242b0eed.svn-base 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. package org.jeecg.modules.ngalain.controller;
  2. import java.util.ArrayList;
  3. import java.util.List;
  4. import java.util.Map;
  5. import javax.servlet.http.HttpServletRequest;
  6. import org.apache.shiro.SecurityUtils;
  7. import org.jeecg.common.api.vo.Result;
  8. import org.jeecg.common.system.vo.DictModel;
  9. import org.jeecg.common.system.vo.LoginUser;
  10. import org.jeecg.modules.ngalain.service.NgAlainService;
  11. import org.jeecg.modules.system.service.ISysDictService;
  12. import org.springframework.beans.factory.annotation.Autowired;
  13. import org.springframework.web.bind.annotation.PathVariable;
  14. import org.springframework.web.bind.annotation.RequestMapping;
  15. import org.springframework.web.bind.annotation.RequestMethod;
  16. import org.springframework.web.bind.annotation.ResponseBody;
  17. import org.springframework.web.bind.annotation.RestController;
  18. import com.alibaba.fastjson.JSONObject;
  19. import lombok.extern.slf4j.Slf4j;
  20. @Slf4j
  21. @RestController
  22. @RequestMapping("/sys/ng-alain")
  23. public class NgAlainController {
  24. @Autowired
  25. private NgAlainService ngAlainService;
  26. @Autowired
  27. private ISysDictService sysDictService;
  28. @RequestMapping(value = "/getAppData")
  29. @ResponseBody
  30. public JSONObject getAppData(HttpServletRequest request) throws Exception {
  31. String token=request.getHeader("X-Access-Token");
  32. JSONObject j = new JSONObject();
  33. LoginUser user = (LoginUser) SecurityUtils.getSubject().getPrincipal();
  34. JSONObject userObjcet = new JSONObject();
  35. userObjcet.put("name", user.getUsername());
  36. userObjcet.put("avatar", user.getAvatar());
  37. userObjcet.put("email", user.getEmail());
  38. userObjcet.put("token", token);
  39. j.put("user", userObjcet);
  40. j.put("menu",ngAlainService.getMenu(user.getUsername()));
  41. JSONObject app = new JSONObject();
  42. app.put("name", "jeecg-boot-angular");
  43. app.put("description", "jeecg+ng-alain整合版本");
  44. j.put("app", app);
  45. return j;
  46. }
  47. @RequestMapping(value = "/getDictItems/{dictCode}", method = RequestMethod.GET)
  48. public Object getDictItems(@PathVariable String dictCode) {
  49. log.info(" dictCode : "+ dictCode);
  50. Result<List<DictModel>> result = new Result<List<DictModel>>();
  51. List<DictModel> ls = null;
  52. try {
  53. ls = sysDictService.queryDictItemsByCode(dictCode);
  54. result.setSuccess(true);
  55. result.setResult(ls);
  56. } catch (Exception e) {
  57. log.error(e.getMessage(),e);
  58. result.error500("操作失败");
  59. return result;
  60. }
  61. List<JSONObject> dictlist=new ArrayList<>();
  62. for (DictModel l : ls) {
  63. JSONObject dict=new JSONObject();
  64. try {
  65. dict.put("value",Integer.parseInt(l.getValue()));
  66. } catch (NumberFormatException e) {
  67. dict.put("value",l.getValue());
  68. }
  69. dict.put("label",l.getText());
  70. dictlist.add(dict);
  71. }
  72. return dictlist;
  73. }
  74. @RequestMapping(value = "/getDictItemsByTable/{table}/{key}/{value}", method = RequestMethod.GET)
  75. public Object getDictItemsByTable(@PathVariable String table,@PathVariable String key,@PathVariable String value) {
  76. return this.ngAlainService.getDictByTable(table,key,value);
  77. }
  78. }