TenantController.java 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. package com.huaxu.controller;
  2. import com.baomidou.mybatisplus.core.metadata.IPage;
  3. import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
  4. import com.huaxu.common.FileUploadUtil;
  5. import com.huaxu.entity.TenantEntity;
  6. import com.huaxu.model.AjaxMessage;
  7. import com.huaxu.model.Pagination;
  8. import com.huaxu.model.ResultStatus;
  9. import com.huaxu.service.TenantService;
  10. import io.swagger.annotations.Api;
  11. import io.swagger.annotations.ApiOperation;
  12. import io.swagger.annotations.ApiParam;
  13. import org.springframework.beans.factory.annotation.Autowired;
  14. import org.springframework.beans.factory.annotation.Value;
  15. import org.springframework.web.bind.annotation.*;
  16. import org.springframework.web.multipart.MultipartFile;
  17. import java.io.IOException;
  18. import java.util.List;
  19. /**
  20. * 租户(Tenant)控制层
  21. *
  22. * @author makejava
  23. * @since 2020-10-20 16:56:39
  24. */
  25. @RestController
  26. @RequestMapping("/tenant")
  27. @Api(tags = "租户接口")
  28. public class TenantController {
  29. /**
  30. * 租户
  31. */
  32. @Autowired
  33. private TenantService tenantService;
  34. @Value("${UMIS.sys_config_path}")
  35. private String baseDir;
  36. /**
  37. * 通过主键查询单条数据
  38. *
  39. * @param id
  40. * @return 单条数据
  41. */
  42. @RequestMapping(value = "get", method = RequestMethod.POST)
  43. @ApiOperation(value = "根据id查询租户")
  44. public AjaxMessage<TenantEntity> selectOne(
  45. @ApiParam(value = "租户信息", required = true) Integer id) {
  46. TenantEntity result = tenantService.selectById(id);
  47. return new AjaxMessage<>(ResultStatus.OK, result);
  48. }
  49. /**
  50. * 查询租户信息
  51. *
  52. * @param tenantEntity 参数对象
  53. * @return 多条数据
  54. */
  55. @RequestMapping(value = "selectList", method = RequestMethod.POST)
  56. @ApiOperation(value = "查询租户信息")
  57. public AjaxMessage<List<TenantEntity>> selectList(
  58. @ApiParam(value = "租户信息", required = true) @RequestBody TenantEntity tenantEntity) {
  59. List<TenantEntity> result = tenantService.selectList(tenantEntity);
  60. return new AjaxMessage<>(ResultStatus.OK, result);
  61. }
  62. /**
  63. * 新增
  64. */
  65. @RequestMapping(value = "addTenantLogo", method = RequestMethod.POST)
  66. @ResponseBody
  67. @ApiOperation(value = "租户logo")
  68. public AjaxMessage<String> addUserPhoto(@ApiParam(value = "租户logo", required = true)@RequestParam("avatarfile") MultipartFile file) {
  69. String avatar = "";
  70. if (!file.isEmpty()) {
  71. try {
  72. avatar = FileUploadUtil.uploadWeb(baseDir, file);
  73. } catch (IOException e) {
  74. return new AjaxMessage<>(ResultStatus.ERROR, e.getMessage());
  75. }
  76. }
  77. return new AjaxMessage<>(ResultStatus.OK, avatar);
  78. }
  79. /**
  80. * 新增一条数据
  81. *
  82. * @param tenantEntity 实体类
  83. * @return Response对象
  84. */
  85. @RequestMapping(value = "insert", method = RequestMethod.POST)
  86. @ApiOperation(value = "插入租户信息")
  87. public AjaxMessage<Integer> insert(@ApiParam(value = "租户信息", required = true) @RequestBody TenantEntity tenantEntity) {
  88. int result = tenantService.insert(tenantEntity);
  89. return new AjaxMessage<>(ResultStatus.OK, result);
  90. }
  91. /**
  92. * 修改一条数据
  93. *
  94. * @param tenantEntity 实体类
  95. * @return Response对象
  96. */
  97. @RequestMapping(value = "update", method = RequestMethod.POST)
  98. @ApiOperation(value = "修改租户信息")
  99. public AjaxMessage<Integer> update(@ApiParam(value = "租户信息", required = true) @RequestBody TenantEntity tenantEntity) {
  100. int result = tenantService.update(tenantEntity);
  101. return new AjaxMessage<>(ResultStatus.OK, result);
  102. }
  103. /**
  104. * 单条删除数据
  105. *
  106. * @param id
  107. * @return Response对象
  108. */
  109. @RequestMapping(value = "delete", method = RequestMethod.POST)
  110. @ApiOperation(value = "删除租户信息")
  111. public AjaxMessage<Integer> delete(@ApiParam(value = "租户信息", required = true) Integer id) {
  112. int result = tenantService.deleteById(id);
  113. return new AjaxMessage<>(ResultStatus.OK, result);
  114. }
  115. /**
  116. * 分页查询
  117. *
  118. * @param pageNum 偏移
  119. * @param pageSize 条数
  120. * @return Response对象
  121. */
  122. @RequestMapping(value = "selectPage", method = RequestMethod.POST)
  123. @ApiOperation(value = "查询租户信息列表")
  124. public AjaxMessage<Pagination<TenantEntity>> selectPage(
  125. @ApiParam(value = "租户信息", required = true) @RequestBody TenantEntity tenantEntity,
  126. @ApiParam(value = "页数,非必传,默认第一页", defaultValue = "1") int pageNum,
  127. @ApiParam(value = "条数,非必传,默认15条", defaultValue = "30") int pageSize
  128. ) {
  129. IPage<TenantEntity> iPage = new Page<>(pageNum, pageSize);
  130. iPage = tenantService.selectPage(tenantEntity, iPage);
  131. Pagination<TenantEntity> pages = new Pagination<>(iPage);
  132. return new AjaxMessage<>(ResultStatus.OK, pages);
  133. }
  134. }