package com.gxwebsoft.open.controller;

import com.gxwebsoft.common.core.web.ApiResult;
import com.gxwebsoft.common.core.web.BaseController;
import com.gxwebsoft.common.core.web.PageParam;
import com.gxwebsoft.common.core.web.PageResult;
import com.gxwebsoft.common.system.entity.Tenant;
import com.gxwebsoft.common.system.entity.User;
import com.gxwebsoft.common.system.param.TenantParam;
import com.gxwebsoft.common.system.service.TenantService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * 应用管理
 *
 * @author 科技小王子
 * @since 2022-11-25 19:04:43
 */
@Api(tags = "应用管理(已废弃)")
@RestController
@RequestMapping("/api/open/appstore")
public class OpenAppstoreController extends BaseController {
    @Resource
    private TenantService tenantService;

    @ApiOperation("分页查询应用")
    @GetMapping("/page")
    public ApiResult<PageResult<Tenant>> page(TenantParam param) {
        PageParam<Tenant, TenantParam> page = new PageParam<>(param);
        page.setDefaultOrder("create_time desc");
        // 记录当前登录用户id、应用id
        User user = getLoginUser();
        if (user != null) {
          param.setUserId(user.getUserId());
        }
        // 使用关联查询
        return success(tenantService.pageRel(param));
    }

    @ApiOperation("查询全部应用")
    @GetMapping()
    public ApiResult<List<Tenant>> list(TenantParam param) {
        PageParam<Tenant, TenantParam> page = new PageParam<>(param);
        page.setDefaultOrder("create_time desc");
        // 记录当前登录用户id、应用id
        User user = getLoginUser();
        if (user != null) {
          param.setUserId(user.getUserId());
        }
        // 使用关联查询
        return success(tenantService.listRel(param));
    }
}
