package com.hotent.portal.controller;


import com.hotent.base.annotation.ApiGroup;
import com.hotent.base.constants.ApiGroupConsts;
import com.hotent.base.controller.BaseController;
import com.hotent.base.model.CommonResult;
import com.hotent.base.query.PageList;
import com.hotent.base.query.QueryFilter;
import com.hotent.portal.model.PortalBizSystem;
import com.hotent.portal.service.PortalBizSystemManager;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


/**
 *  外部系统管理
 *
 * @company 广州宏天软件股份有限公司
 * @author cola
 * @since 2021-08-25
 */
@RestController
@RequestMapping("/portalBizSystem/v1/")
@Api(tags="外部系统管理")
@ApiGroup(group= {ApiGroupConsts.GROUP_PORTAL})
public class PortalBizSystemController extends BaseController<PortalBizSystemManager, PortalBizSystem> {
    private static final Logger logger = LoggerFactory.getLogger(PortalBizSystemController.class);

    @Autowired
    PortalBizSystemManager portalBizSystemManager;

    @RequestMapping(value = "/save",method = RequestMethod.POST)
    @ApiOperation("添加实体的接口")
    public CommonResult<String> createPortalBizSystem(@ApiParam(name="PortalBizSystem", value="实体信息") @RequestBody PortalBizSystem  portalBizSystem) {
        return portalBizSystemManager.savePortalBizSystem(portalBizSystem);
    }

    @RequestMapping(value = "/update",method = RequestMethod.POST)
    @ApiOperation("更新实体的接口")
    public CommonResult<String> updatePortalBizSystem(@ApiParam(name="PortalBizSystem", value="实体信息") @RequestBody PortalBizSystem  portalBizSystem) {
        return portalBizSystemManager.updatePortalBizSystem(portalBizSystem);
    }

    @RequestMapping(value = "/queryData",method = RequestMethod.POST)
    @ApiOperation("查询列表")
    public PageList queryData(@ApiParam(name="queryFilter", value="分页查询信息") @RequestBody QueryFilter queryFilter){
        return portalBizSystemManager.queryData(queryFilter);
    }


    @RequestMapping(value = "/searchById",method = RequestMethod.GET)
    @ApiOperation("根据ID搜索外部系统信息")
    public CommonResult searchById(@RequestParam(value = "id")String id){
        return portalBizSystemManager.searchById(id);
    }

    @RequestMapping(value = "/getOpenApiList",method = RequestMethod.GET)
    @ApiOperation("获取外部接口的列表")
    public CommonResult getOpenApiList(){
        return portalBizSystemManager.getOpenApiList();
    }

    @RequestMapping(value = "/checkSysCode",method = RequestMethod.GET)
    @ApiOperation("验证系统编码或系统密匙是否正确")
    public CommonResult checkSysCode(@RequestParam(value = "sysCode",required = true)String sysCode,@RequestParam(value = "secretKey",required = false)String secretKey) throws Exception{
        return portalBizSystemManager.checkSysCode(sysCode,secretKey);
    }

    @RequestMapping(value = "/checkSysCodeAndUri",method = RequestMethod.GET)
    @ApiOperation("验证系统编码是否正确和URI是否已被授权")
    public CommonResult checkSysCode(@RequestParam(value = "sysCode",required = true)String sysCode,@RequestParam(value = "secretKey",required = false)String secretKey,
                                     @RequestParam(value = "uri")String uri,@RequestParam(value = "tenantId")String tenantId){
        return portalBizSystemManager.checkSysCodeAndUri(sysCode,secretKey,uri,tenantId);
    }

    @RequestMapping(value = "/getPortalBizSystemBySysCode",method = RequestMethod.GET)
    @ApiOperation("根据系统编码获取该外部系统对应的队列名，用于远程调用")
    public CommonResult getPortalBizSystemBySysCode(@RequestParam(value = "sysCode",required = true)String sysCode){
        return portalBizSystemManager.getPortalBizSystemBySysCode(sysCode);
    }

    @RequestMapping(value = "/getPortalBizSystemUrlBySysCode",method = RequestMethod.GET)
    @ApiOperation("根据系统编码获取该外部系统登录跳转地址，用于远程调用")
    public CommonResult getPortalBizSystemUrlBySysCode(@RequestParam(value = "sysCode",required = true)String sysCode){
        logger.info("feign:【查询平台信息】，sysCode:{}", sysCode);
        return portalBizSystemManager.getPortalBizSystemUrlBySysCode(sysCode);
    }


    @RequestMapping(value = "/getPortalBizSystemByCode",method = RequestMethod.GET)
    @ApiOperation("根据系统编码获取外部系统")
    public CommonResult getPortalBizSystemByCode(@RequestParam(value = "code",required = true)String code){
        return portalBizSystemManager.getPortalBizSystemByCode(code);
    }

    @RequestMapping(value = "getList",method = RequestMethod.POST)
    @ApiOperation("获取列表数据")
    public List<PortalBizSystem> getList() throws Exception {
		return portalBizSystemManager.getList();
    }

    @GetMapping(value="getDetail")
    @ApiOperation(value = "根据ID获取外部系统信息", httpMethod = "GET", notes = "根据ID获取外部系统信息")
    public PortalBizSystem getDetail(@ApiParam(name="id",value="ID")@RequestParam String id) throws Exception {
    	return portalBizSystemManager.get(id);
    }

    @RequestMapping(value = "getServiceList",method = RequestMethod.POST)
    @ApiOperation("获取服务数据（包含微服务及外部服务数据")
    public List<PortalBizSystem> getServiceList() throws Exception {
        return portalBizSystemManager.getServiceList();
    }


    @RequestMapping(value = "getAuthUserBySystemCode",method = RequestMethod.POST)
    @ApiOperation(value = "根据外部系统的编码获取管理人员", httpMethod = "POST", notes = "根据外部系统的编码获取管理人员")
    public CommonResult getAuthUserBySystemId(@RequestBody QueryFilter queryFilter){
        return portalBizSystemManager.getAuthUserBySystemCode(queryFilter);
    }

    @RequestMapping(value = "deleteAuthByIds",method = RequestMethod.DELETE)
    @ApiOperation(value = "根据管理员id和系统编码来删除管理员的权限",httpMethod = "GET",notes = "根据管理员id和系统编码来删除管理员的权限")
    public CommonResult deleteAuthByIds(@RequestParam(value = "ids")String ids){
        return portalBizSystemManager.deleteAuthByIds(ids);
    }

    @RequestMapping(value = "addAuthByUserIdAndSysCode",method = RequestMethod.GET)
    @ApiOperation(value = "根据管理员id和系统编码来添加管理员的权限",httpMethod = "GET",notes = "根据管理员id和系统编码来添加管理员的权限")
    public CommonResult addAuthByUserIdAndSysCode(@RequestParam(value = "userIds")String userIds,@RequestParam(value = "sysCode")String sysCode){
        return portalBizSystemManager.addAuthByUserIdAndSysCode(userIds,sysCode);
    }

    @RequestMapping(value = "/delete",method = RequestMethod.DELETE)
    @ApiOperation(value = "根据系统编码的id来删除",httpMethod = "DELETE",notes = "根据系统编码的id来删除")
    public CommonResult deleteBySystemId(@RequestParam(value = "sysCode")String sysCode){
        return portalBizSystemManager.deleteBySysCode(sysCode);
    }
}
