123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166 |
- package com.huaxu.controller;
- import com.baomidou.mybatisplus.core.metadata.IPage;
- import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
- import com.huaxu.common.FileUploadUtil;
- import com.huaxu.dto.TenantDto;
- import com.huaxu.entity.TenantEntity;
- import com.huaxu.model.AjaxMessage;
- import com.huaxu.model.Pagination;
- import com.huaxu.model.ResultStatus;
- import com.huaxu.service.TenantService;
- import com.huaxu.service.UserService;
- import io.swagger.annotations.Api;
- import io.swagger.annotations.ApiOperation;
- import io.swagger.annotations.ApiParam;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.beans.factory.annotation.Value;
- import org.springframework.web.bind.annotation.*;
- import org.springframework.web.multipart.MultipartFile;
- import java.io.IOException;
- import java.util.List;
- /**
- * @description 租户(Tenant)控制层
- * @auto wangli
- * @data 2020-10-26 15:44
- */
- @RestController
- @RequestMapping("/tenant")
- @Api(tags = "租户管理")
- public class TenantController {
- /**
- * 租户
- */
- @Autowired
- private TenantService tenantService;
- @Autowired
- private UserService userService;
- @Value("${UMIS.sys_config_path}")
- private String baseDir;
- /**
- * 通过主键查询单条数据
- *
- * @param id
- * @return 单条数据
- */
- @RequestMapping(value = "get", method = RequestMethod.POST)
- @ApiOperation(value = "根据id查询租户")
- public AjaxMessage<TenantDto> selectOne(
- @ApiParam(value = "租户信息", required = true) @RequestParam Integer id) {
- TenantDto result = tenantService.selectById(id);
- return new AjaxMessage<>(ResultStatus.OK, result);
- }
- /**
- * 查询租户信息
- *
- * @param tenantDto 参数对象
- * @return 多条数据
- */
- @RequestMapping(value = "selectList", method = RequestMethod.POST)
- @ApiOperation(value = "查询租户信息")
- public AjaxMessage<List<TenantDto>> selectList(
- @ApiParam(value = "租户信息") @RequestBody TenantDto tenantDto) {
- List<TenantDto> result = tenantService.selectList(tenantDto);
- return new AjaxMessage<>(ResultStatus.OK, result);
- }
- /**
- * 新增租户logo
- */
- @RequestMapping(value = "addTenantLogo", method = RequestMethod.POST)
- @ResponseBody
- @ApiOperation(value = "租户logo")
- public AjaxMessage<String> addUserPhoto(@ApiParam(value = "租户logo", required = true)@RequestParam("avatarfile") MultipartFile file) {
- String avatar = "";
- if (!file.isEmpty()) {
- try {
- avatar = FileUploadUtil.uploadWeb(baseDir, file);
- } catch (IOException e) {
- return new AjaxMessage<>(ResultStatus.ERROR, e.getMessage());
- }
- }
- return new AjaxMessage<>(ResultStatus.OK, avatar);
- }
- /**
- * 新增一条数据
- *
- * @param tenantDto 实体类
- * @return Response对象t
- */
- @RequestMapping(value = "insert", method = RequestMethod.POST)
- @ApiOperation(value = "插入租户信息")
- public AjaxMessage<Integer> insert(@ApiParam(value = "租户信息", required = true) @RequestBody TenantDto tenantDto) {
- if (tenantDto.getPhone() != null) {
- boolean isExsit = userService.checkMobileUnique(tenantDto.getPhone());
- if (isExsit) {
- return new AjaxMessage<>(ResultStatus.MEMBER_TELPHONE_ALREADY_EXISTS, 0);
- }
- }
- int result = tenantService.insert(tenantDto);
- return new AjaxMessage<>(ResultStatus.OK, result);
- }
- /**
- * 修改一条数据
- *
- * @param tenantDto 实体类
- * @return Response对象
- */
- @RequestMapping(value = "update", method = RequestMethod.POST)
- @ApiOperation(value = "修改租户信息")
- public AjaxMessage<Integer> update(@ApiParam(value = "租户信息", required = true) @RequestBody TenantDto tenantDto) {
- int result = tenantService.update(tenantDto);
- return new AjaxMessage<>(ResultStatus.OK, result);
- }
- /**
- * 单条删除数据
- *
- * @param id
- * @return Response对象
- */
- @RequestMapping(value = "delete", method = RequestMethod.POST)
- @ApiOperation(value = "删除租户信息")
- public AjaxMessage<Integer> delete(@ApiParam(value = "租户信息", required = true) @RequestParam Integer id) {
- int result = tenantService.deleteById(id);
- return new AjaxMessage<>(ResultStatus.OK, result);
- }
- /**
- * 分页查询
- *
- * @param pageNum 偏移
- * @param pageSize 条数
- * @return Response对象
- */
- @RequestMapping(value = "selectPage", method = RequestMethod.POST)
- @ApiOperation(value = "查询租户信息列表")
- public AjaxMessage<Pagination<TenantDto>> selectPage(
- @ApiParam(value = "租户名称") @RequestBody TenantDto tenantDto,
- @ApiParam(value = "页数,非必传,默认第一页", defaultValue = "1") @RequestParam(required = false, defaultValue = "1") Integer pageNum,
- @ApiParam(value = "条数,非必传,默认30条", defaultValue = "30") @RequestParam(required = false, defaultValue = "30") Integer pageSize
- ) {
- IPage<TenantDto> iPage = new Page<>(pageNum, pageSize);
- iPage = tenantService.selectPage(iPage, tenantDto );
- Pagination<TenantDto> pages = new Pagination<>(iPage);
- return new AjaxMessage<>(ResultStatus.OK, pages);
- }
- }
|