package com.ym.mec.web.controller;


import com.ym.mec.auth.api.client.SysUserFeignService;
import com.ym.mec.auth.api.entity.SysUser;
import com.ym.mec.biz.dal.dto.TenantPreJoinDto;
import com.ym.mec.biz.dal.entity.TenantPreJoin;
import com.ym.mec.biz.dal.vo.TenantPreJoinVo;
import com.ym.mec.biz.service.TenantPreJoinService;
import com.ym.mec.common.controller.BaseController;
import com.ym.mec.common.entity.HttpResponseResult;
import com.ym.mec.common.page.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.Map;

/**
 * 机构入驻表(预加入)(TenantPreJoin)表控制层
 *
 * @author hgw
 * @since 2022-02-09 14:38:08
 */
@Api(tags = "机构入驻")
@RestController
@RequestMapping("/tenantPreJoin")
public class TenantPreJoinController extends BaseController {
    /**
     * 服务对象
     */
    @Resource
    private TenantPreJoinService tenantPreJoinService;
    @Resource
    private SysUserFeignService sysUserFeignService;

    @ApiOperation("分页查询")
    @PostMapping("/queryPage")
    @PreAuthorize("@pcs.hasPermissions('tenantPreJoin/queryPage')")
    public HttpResponseResult<PageInfo<TenantPreJoinVo>> queryPage(@RequestBody Map<String, Object> param) {
        //如果不是超管，那么只能看到推荐人自己的机构
        //2022年4月26日 需求要求变更为平台账号就看所有数据
//        SysUser sysUser = sysUserFeignService.queryUserInfo();
//        if(!sysUser.getIsSuperAdmin()){
//            param.put("recommender",sysUser.getId());
//        }
        return succeed(tenantPreJoinService.queryPage(param));
    }

    @ApiOperation("添加")
    @PostMapping("/add")
    public HttpResponseResult add(@Valid  @RequestBody TenantPreJoinDto dto) {
        tenantPreJoinService.insert(dto);
        return succeed();
    }

}

