package com.crunii.micro.service.sysmgr.controller;

import com.crunii.micro.common.dto.Result;
import com.crunii.micro.domain.dto.Worker;
import com.crunii.micro.domain.entity.main.YcqAppConfigUrl;
import com.crunii.micro.service.sysmgr.dto.org.OrgTreeAuthorityReqDto;
import com.crunii.micro.service.sysmgr.dto.org.OrgTreeDto;
import com.crunii.micro.service.sysmgr.dto.sysmgr.AppConfigC;
import com.crunii.micro.service.sysmgr.dto.sysmgr.AppConfigU;
import com.crunii.micro.service.sysmgr.service.AppHomeConfigService;
import com.crunii.micro.web.mvc.CurrWorker;
import io.swagger.annotations.*;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

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

/**
 * @author baoxy
 * @date 2023-05-30
 */
@Api(tags = "app端首页配置")
@RestController
@RequestMapping("/auth/AppHomeConfigController")
public class AppHomeConfigController {

    @Resource
    private AppHomeConfigService appHomeConfigService;

    @ApiOperation(value = "查询app端配置url")
    @RequestMapping(path = "/findAppConfigUrl", method = RequestMethod.GET)
//    @ApiResponse(code=200,message = "成功",response = YcqAppConfigUrl.class)
    @ResponseBody
    public Result<List<YcqAppConfigUrl>> findAppConfigUrl() {
        return appHomeConfigService.findAppConfigUrl();
    }

    @ApiOperation(value = "保存app端配置url的数据")
    @RequestMapping(path = "/save", method = RequestMethod.POST)
    @ApiResponse(code=200,message = "成功")
    @ResponseBody
    public Result<?> save(@RequestBody @ApiParam AppConfigC dto) {
        return appHomeConfigService.save(dto);
    }

    @ApiOperation(value = "批量保存app端配置url的数据")
    @RequestMapping(path = "/batchSave", method = RequestMethod.POST)
    @ResponseBody
    public Result<Object> batchSave(@RequestBody @ApiParam List<AppConfigC> dtos) {
        return appHomeConfigService.batchSave(dtos);
    }

    @ApiOperation(value = "删除数据")
    @ApiImplicitParams(
            @ApiImplicitParam(name = "appId", value = "app端唯一主键", required = true, dataType = "String")
    )
    @RequestMapping(path = "/del", method = RequestMethod.GET)
    @ResponseBody
    public Result<Object> del(String appId) {
        return appHomeConfigService.del(appId);
    }

    @ApiOperation(value = "修改数据")
    @RequestMapping(path = "/update", method = RequestMethod.POST)
    @ResponseBody
    public Result<Object> update(@RequestBody @ApiParam AppConfigU dto) {
        return appHomeConfigService.update(dto);
    }

    @ApiOperation(value = "查询角色app配置权限")
    @RequestMapping(path = "/findRoleApp", method = RequestMethod.POST)
    @ResponseBody
    public Result<List<YcqAppConfigUrl>> findRoleApp(@CurrWorker @ApiIgnore Worker worker) {
        return appHomeConfigService.findRoleApp(worker);
    }

}
