DBInfoController.java 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. package com.yihu.hos.tenant.controller;
  2. import com.yihu.hos.tenant.model.DBInfoModel;
  3. import com.yihu.hos.tenant.service.DBInfoService;
  4. import com.yihu.hos.web.framework.model.DetailModelResult;
  5. import com.yihu.hos.web.framework.model.Result;
  6. import com.yihu.hos.web.framework.util.controller.BaseController;
  7. import io.swagger.annotations.ApiOperation;
  8. import io.swagger.annotations.ApiParam;
  9. import org.apache.commons.beanutils.BeanUtils;
  10. import org.springframework.stereotype.Controller;
  11. import org.springframework.ui.Model;
  12. import org.springframework.util.StringUtils;
  13. import org.springframework.web.bind.annotation.RequestMapping;
  14. import org.springframework.web.bind.annotation.RequestMethod;
  15. import org.springframework.web.bind.annotation.RequestParam;
  16. import org.springframework.web.bind.annotation.ResponseBody;
  17. import javax.annotation.Resource;
  18. import javax.servlet.http.HttpServletRequest;
  19. import java.util.Date;
  20. import java.util.HashMap;
  21. import java.util.Map;
  22. /**
  23. * 数据库实例管理
  24. * @author HZY
  25. * @vsrsion 1.0
  26. * Created at 2016/12/16.
  27. */
  28. @RequestMapping("/tenant/dataBase")
  29. @Controller
  30. public class DBInfoController extends BaseController{
  31. @Resource(name = DBInfoService.BEAN_ID)
  32. private DBInfoService dbInfoService;
  33. /**
  34. * 管理界面
  35. *
  36. * @param model
  37. * @return
  38. */
  39. @RequestMapping("/initial")
  40. public String dbInfoInitial(Model model) {
  41. model.addAttribute("contentPage", "tenant/dataBase/dbInfo");
  42. return "partView";
  43. }
  44. /**
  45. * 列表
  46. *
  47. * @param request
  48. * @return
  49. */
  50. @RequestMapping("/getDBList")
  51. @ResponseBody
  52. public Result getDBInfoList(HttpServletRequest request,String name,String valid) {
  53. try {
  54. Map<String, Object> params = new HashMap<>();
  55. params.put("name", name);
  56. params.put("valid", valid);
  57. String page = StringUtils.isEmpty(request.getParameter("page")) ? "1" : request.getParameter("page");
  58. String rows = StringUtils.isEmpty(request.getParameter("rows")) ? "10" : request.getParameter("rows");
  59. params.put("page", page);
  60. params.put("rows", rows);
  61. Result result = dbInfoService.getDBInfoList(params);
  62. return result;
  63. } catch (Exception ex) {
  64. ex.printStackTrace();
  65. return Result.error(ex.getMessage());
  66. }
  67. }
  68. /**
  69. * 修改页面
  70. * @param model
  71. * @param id
  72. * @param categoryId
  73. * @return
  74. */
  75. @RequestMapping("/editorDbInfo")
  76. public String editorDBInfo(Model model, Long id, String flag, String categoryId) {
  77. try {
  78. DBInfoModel dbInfoModel = null;
  79. if (id != null) {
  80. dbInfoModel = dbInfoService.getDBInfoById(id);
  81. } else {
  82. dbInfoModel = new DBInfoModel();
  83. }
  84. model.addAttribute("model", dbInfoModel);
  85. model.addAttribute("flag", flag);
  86. model.addAttribute("categoryId", categoryId);
  87. model.addAttribute("contentPage", "/tenant/dataBase/editorDbInfo");
  88. } catch (Exception e) {
  89. e.printStackTrace();
  90. }
  91. return "pageView";
  92. }
  93. /**
  94. * 详情页
  95. * @param model
  96. * @param id
  97. * @return
  98. */
  99. @RequestMapping("/dbDetail")
  100. public String dBInfoDetail(Model model, Long id) {
  101. try {
  102. DBInfoModel dbInfoModel = null;
  103. if (id != null ) {
  104. dbInfoModel = dbInfoService.getDBInfoById(id);
  105. } else {
  106. dbInfoModel = new DBInfoModel();
  107. }
  108. model.addAttribute("model", dbInfoModel);
  109. model.addAttribute("contentPage", "/tenant/dataBase/dbDetail");
  110. } catch (Exception e) {
  111. e.printStackTrace();
  112. }
  113. return "pageView";
  114. }
  115. /**
  116. * 新增
  117. * @param request
  118. * @return
  119. */
  120. @RequestMapping("addDBInfo")
  121. @ResponseBody
  122. public Result addDBInfo(HttpServletRequest request) {
  123. try {
  124. DBInfoModel obj = new DBInfoModel();
  125. BeanUtils.populate(obj, request.getParameterMap());
  126. obj.setCreated(new Date());
  127. return dbInfoService.addDBInfo(obj);
  128. } catch (Exception ex) {
  129. ex.printStackTrace();
  130. return Result.error(ex.getMessage());
  131. }
  132. }
  133. /**
  134. * 删除
  135. * @param request
  136. * @return
  137. */
  138. @RequestMapping("/deleteDBInfo")
  139. @ResponseBody
  140. public Result deleteDBInfo(HttpServletRequest request) {
  141. try {
  142. String id = request.getParameter("id");
  143. dbInfoService.deleteDBInfo(Long.parseLong(id));
  144. return Result.success("删除成功!");
  145. } catch (Exception e) {
  146. e.printStackTrace();
  147. return Result.error("删除失败!");
  148. }
  149. }
  150. /**
  151. * 修改租户信息
  152. */
  153. @RequestMapping("updateDBInfo")
  154. @ResponseBody
  155. public Result updateDBInfo(HttpServletRequest request) {
  156. try {
  157. DBInfoModel obj = new DBInfoModel();
  158. BeanUtils.populate(obj, request.getParameterMap());
  159. return dbInfoService.updateDBInfo(obj);
  160. } catch (Exception ex) {
  161. ex.printStackTrace();
  162. return Result.error(ex.getMessage());
  163. }
  164. }
  165. @RequestMapping(value="/getDataBaseValues" , method = RequestMethod.GET)
  166. @ResponseBody
  167. @ApiOperation(value = "获取数据库实例下拉框信息", response = DetailModelResult.class, produces = "application/json", notes = "获取数据库实例下拉框信息")
  168. public DetailModelResult getSelectList(
  169. @ApiParam(name = "q", value = "数据库名称或实例名", required = false)
  170. @RequestParam(value = "q", required = false) String q,
  171. @ApiParam(name = "initVal", value = "初始化数据库名称", required = false)
  172. @RequestParam(value = "initVal", required = false) String initVal) {
  173. return dbInfoService.getDataBaseSelectList(q);
  174. }
  175. }