2706d12a3d4dff33da7ac2bb092826762398cc54.svn-base 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  1. package org.jeecg.modules.demo.mock;
  2. import java.io.File;
  3. import java.io.IOException;
  4. import java.io.InputStream;
  5. import java.util.ArrayList;
  6. import java.util.HashMap;
  7. import java.util.List;
  8. import java.util.Map;
  9. import javax.servlet.http.HttpServletRequest;
  10. import javax.servlet.http.HttpServletResponse;
  11. import javax.swing.filechooser.FileSystemView;
  12. import org.apache.commons.io.IOUtils;
  13. import org.jeecg.common.api.vo.Result;
  14. import org.springframework.web.bind.annotation.GetMapping;
  15. import org.springframework.web.bind.annotation.PathVariable;
  16. import org.springframework.web.bind.annotation.RequestMapping;
  17. import org.springframework.web.bind.annotation.RequestMethod;
  18. import org.springframework.web.bind.annotation.RestController;
  19. import lombok.extern.slf4j.Slf4j;
  20. @RestController
  21. @RequestMapping("/mock/api")
  22. @Slf4j
  23. public class MockController {
  24. private final String JSON_PATH = "classpath:org/jeecg/modules/demo/mock/json";
  25. /**
  26. * 通用json访问接口
  27. * 格式: http://localhost:8080/jeecg-boot/api/json/{filename}
  28. * @param filename
  29. * @return
  30. */
  31. @RequestMapping(value = "/json/{filename}", method = RequestMethod.GET)
  32. public String getJsonData(@PathVariable String filename) {
  33. String jsonpath = "classpath:org/jeecg/modules/demo/mock/json/"+filename+".json";
  34. return readJson(jsonpath);
  35. }
  36. @GetMapping(value = "/asynTreeList")
  37. public String asynTreeList(String id) {
  38. return readJson(JSON_PATH + "/asyn_tree_list_" + id + ".json");
  39. }
  40. @GetMapping(value = "/user")
  41. public String user() {
  42. return readJson("classpath:org/jeecg/modules/demo/mock/json/user.json");
  43. }
  44. /**
  45. * 老的登录获取用户信息接口
  46. * @return
  47. */
  48. @GetMapping(value = "/user/info")
  49. public String userInfo() {
  50. return readJson("classpath:org/jeecg/modules/demo/mock/json/user_info.json");
  51. }
  52. @GetMapping(value = "/role")
  53. public String role() {
  54. return readJson("classpath:org/jeecg/modules/demo/mock/json/role.json");
  55. }
  56. @GetMapping(value = "/service")
  57. public String service() {
  58. return readJson("classpath:org/jeecg/modules/demo/mock/json/service.json");
  59. }
  60. @GetMapping(value = "/permission")
  61. public String permission() {
  62. return readJson("classpath:org/jeecg/modules/demo/mock/json/permission.json");
  63. }
  64. @GetMapping(value = "/permission/no-pager")
  65. public String permission_no_page() {
  66. return readJson("classpath:org/jeecg/modules/demo/mock/json/permission_no_page.json");
  67. }
  68. /**
  69. * 省市县
  70. */
  71. @GetMapping(value = "/area")
  72. public String area() {
  73. return readJson("classpath:org/jeecg/modules/demo/mock/json/area.json");
  74. }
  75. /**
  76. * 测试报表数据
  77. */
  78. @GetMapping(value = "/report/getYearCountInfo")
  79. public String getYearCountInfo() {
  80. return readJson("classpath:org/jeecg/modules/demo/mock/json/getCntrNoCountInfo.json");
  81. }
  82. @GetMapping(value = "/report/getMonthCountInfo")
  83. public String getMonthCountInfo() {
  84. return readJson("classpath:org/jeecg/modules/demo/mock/json/getCntrNoCountInfo.json");
  85. }
  86. @GetMapping(value = "/report/getCntrNoCountInfo")
  87. public String getCntrNoCountInfo() {
  88. return readJson("classpath:org/jeecg/modules/demo/mock/json/getCntrNoCountInfo.json");
  89. }
  90. @GetMapping(value = "/report/getCabinetCountInfo")
  91. public String getCabinetCountInfo() {
  92. return readJson("classpath:org/jeecg/modules/demo/mock/json/getCntrNoCountInfo.json");
  93. }
  94. @GetMapping(value = "/report/getTubiao")
  95. public String getTubiao() {
  96. return readJson("classpath:org/jeecg/modules/demo/mock/json/getTubiao.json");
  97. }
  98. /**
  99. * 实时磁盘监控
  100. * @param request
  101. * @param response
  102. * @return
  103. */
  104. @GetMapping("/queryDiskInfo")
  105. public Result<List<Map<String,Object>>> queryDiskInfo(HttpServletRequest request, HttpServletResponse response){
  106. Result<List<Map<String,Object>>> res = new Result<>();
  107. try {
  108. // 当前文件系统类
  109. FileSystemView fsv = FileSystemView.getFileSystemView();
  110. // 列出所有windows 磁盘
  111. File[] fs = File.listRoots();
  112. log.info("查询磁盘信息:"+fs.length+"个");
  113. List<Map<String,Object>> list = new ArrayList<>();
  114. for (int i = 0; i < fs.length; i++) {
  115. if(fs[i].getTotalSpace()==0) {
  116. continue;
  117. }
  118. Map<String,Object> map = new HashMap<>();
  119. map.put("name", fsv.getSystemDisplayName(fs[i]));
  120. map.put("max", fs[i].getTotalSpace());
  121. map.put("rest", fs[i].getFreeSpace());
  122. map.put("restPPT", fs[i].getFreeSpace()*100/fs[i].getTotalSpace());
  123. list.add(map);
  124. log.info(map.toString());
  125. }
  126. res.setResult(list);
  127. res.success("查询成功");
  128. } catch (Exception e) {
  129. res.error500("查询失败"+e.getMessage());
  130. }
  131. return res;
  132. }
  133. //-------------------------------------------------------------------------------------------
  134. /**
  135. * 工作台首页的数据
  136. * @return
  137. */
  138. @GetMapping(value = "/list/search/projects")
  139. public String projects() {
  140. return readJson("classpath:org/jeecg/modules/demo/mock/json/workplace_projects.json");
  141. }
  142. @GetMapping(value = "/workplace/activity")
  143. public String activity() {
  144. return readJson("classpath:org/jeecg/modules/demo/mock/json/workplace_activity.json");
  145. }
  146. @GetMapping(value = "/workplace/teams")
  147. public String teams() {
  148. return readJson("classpath:org/jeecg/modules/demo/mock/json/workplace_teams.json");
  149. }
  150. @GetMapping(value = "/workplace/radar")
  151. public String radar() {
  152. return readJson("classpath:org/jeecg/modules/demo/mock/json/workplace_radar.json");
  153. }
  154. @GetMapping(value = "/task/process")
  155. public String taskProcess() {
  156. return readJson("classpath:org/jeecg/modules/demo/mock/json/task_process.json");
  157. }
  158. //-------------------------------------------------------------------------------------------
  159. //author:lvdandan-----date:20190315---for:添加数据日志json----
  160. public String sysDataLogJson() {
  161. return readJson("classpath:org/jeecg/modules/demo/mock/json/sysdatalog.json");
  162. }
  163. //author:lvdandan-----date:20190315---for:添加数据日志json----
  164. //--update-begin--author:wangshuai-----date:20201023---for:返回用户信息json数据----
  165. @GetMapping(value = "/getUserInfo")
  166. public String getUserInfo(){
  167. return readJson("classpath:org/jeecg/modules/demo/mock/json/userinfo.json");
  168. }
  169. //--update-end--author:wangshuai-----date:20201023---for:返回用户信息json数据----
  170. /**
  171. * 读取json格式文件
  172. * @param jsonSrc
  173. * @return
  174. */
  175. private String readJson(String jsonSrc) {
  176. String json = "";
  177. try {
  178. //File jsonFile = ResourceUtils.getFile(jsonSrc);
  179. //json = FileUtils.re.readFileToString(jsonFile);
  180. //换个写法,解决springboot读取jar包中文件的问题
  181. InputStream stream = getClass().getClassLoader().getResourceAsStream(jsonSrc.replace("classpath:", ""));
  182. json = IOUtils.toString(stream,"UTF-8");
  183. } catch (IOException e) {
  184. log.error(e.getMessage(),e);
  185. }
  186. return json;
  187. }
  188. }