package com.ym.mec.web.controller;


import com.ym.mec.auth.api.entity.SysUser;
import com.ym.mec.biz.dal.dto.TenantProxyDto;
import com.ym.mec.biz.dal.vo.ProxyUserVo;
import com.ym.mec.biz.service.TenantProxyInfoService;
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.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;

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

/**
 * 机构代理商信息表(TenantProxyInfo)表控制层
 *
 * @author hgw
 * @since 2022-04-22 14:08:20
 */
@Api(tags = "机构代理商信息表")
@RestController
@RequestMapping("/tenantProxyInfo")
public class TenantProxyInfoController extends BaseController {
    /**
     * 服务对象
     */
    @Resource
    private TenantProxyInfoService tenantProxyInfoService;

    @ApiOperation("添加代理商信息")
    @PostMapping(value = "/addProxyInfo")
    public HttpResponseResult<Object> addProxyInfo(@Valid @RequestBody TenantProxyDto dto) {
        tenantProxyInfoService.addProxyInfo(dto);
        return succeed();
    }

    @ApiOperation("添加代理商下面的员工")
    @PostMapping(value = "/addProxyStaff")
    public HttpResponseResult<Object> addProxyStaff(@RequestBody TenantProxyDto dto) {
        tenantProxyInfoService.addProxyStaff(dto);
        return succeed();
    }

    @ApiOperation("查询代理商下级人员数据")
    @ApiImplicitParam(name = "id", value = "代理商负责人id", required = true, dataType = "Integer")
    @GetMapping("/queryProxyUserStaff")
    public HttpResponseResult<List<ProxyUserVo>> queryProxyUserStaff(Integer id) {
        return succeed(tenantProxyInfoService.queryProxyUserStaff(id));
    }

    @ApiImplicitParams({
            @ApiImplicitParam(name = "search", dataType = "String", value = "关键字"),
            @ApiImplicitParam(name = "state", dataType = "Integer", value = "状态 0正常 1冻结"),
            @ApiImplicitParam(name = "page", dataType = "Integer", value = "页数"),
            @ApiImplicitParam(name = "rows", dataType = "Integer", value = "每页数量"),
    })
    @ApiOperation("分页查询代理商负责人数据")
    @PostMapping(value = "/queryProxyUser")
    public HttpResponseResult<PageInfo<ProxyUserVo>> queryPage(@RequestBody Map<String, Object> param) {
        return succeed(tenantProxyInfoService.queryProxyUser(param));
    }

    @ApiOperation("冻结/解冻代理商")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", dataType = "Integer", value = "代理商负责人id"),
            @ApiImplicitParam(name = "state", dataType = "Integer", value = "状态 0正常 1冻结"),
    })
    @GetMapping("/freezeProxy")
    public HttpResponseResult<Object> freezeProxy(Integer id, Integer state) {
        tenantProxyInfoService.freezeProxy(id, state);
        return succeed();
    }

    @ApiOperation("修改人员信息")
    @PostMapping(value = "/updateProxyUserInfo")
    public HttpResponseResult<Object> updateProxyUserInfo(@RequestBody TenantProxyDto dto) {
        tenantProxyInfoService.updateProxyUserInfo(dto);
        return succeed();
    }

    @ApiImplicitParams({
            @ApiImplicitParam(name = "search", dataType = "String", value = "手机号/姓名模糊查询条件"),
    })
    @ApiOperation("手机号/姓名模糊查询所有平台账号信息手机号/姓名模糊查询所有平台账号信息")
    @PostMapping(value = "/queryUserList")
    public HttpResponseResult<List<SysUser>> queryUserList(@RequestBody Map<String, Object> param) {
        return succeed(tenantProxyInfoService.queryUserList(param));
    }

    @ApiOperation("根据token查询用户信息-代理商专用")
    @GetMapping("/queryUserListByToken")
    public HttpResponseResult<SysUser> queryUserList() {
        return succeed(tenantProxyInfoService.queryUserList());
    }

}

