TenantController.java 5.4 KB

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