package com.huatek.busi.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.github.pagehelper.PageInfo;
import com.huatek.busi.dto.ServerFilePathDto;
import com.huatek.busi.service.IServerFilePathService;
import com.huatek.busi.vo.ServerFilePathVo;
import com.huatek.busi.where.ServerFilePathSelectVo;
import com.huatek.torch.frame.tools.ConstantUtil;
import com.huatek.torch.frame.tools.ResultUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@Api(tags = {"服务器文件路径管理接口"})
@RestController
@RequestMapping("/api/serverFilePath")
public class ServerFilePathController {

    @Reference(check = false)
    IServerFilePathService serverFilePathService;

    @ApiOperation(value = "服务器文件路径列表",httpMethod="POST", notes= "服务器文件路径列表", produces = "application/json;charset=utf-8", response= Map.class)
    @PostMapping(value = "/list", produces = { "application/json;charset=utf-8" })
    public Map<String, Object> list(@RequestBody ServerFilePathSelectVo serverFilePathSelectVo){
        PageInfo<ServerFilePathDto> pageInfo = serverFilePathService.list(serverFilePathSelectVo);
        return ResultUtil.put(ConstantUtil.REQUEST_SUCCESS, pageInfo.getTotal(), "BUSINESS.QUERY.SUCCESS", pageInfo.getList());
    }

    @ApiOperation(value = "新增或更新服务器文件路径",httpMethod="POST", notes= "查询服务器文件路径单条数据", produces = "application/json;charset=utf-8", response= Map.class)
    @PostMapping("/saveOrUpdate")
    public Map<String, Object> saveOrUpdate(@RequestBody ServerFilePathVo serverFilePathVo, @RequestHeader("token") String token){
        return serverFilePathService.saveOrUpdate(serverFilePathVo, token);
    }

    @ApiOperation(value = "查询服务器文件路径单条数据",httpMethod="GET", notes= "查询服务器文件路径单条数据", produces = "application/json;charset=utf-8", response= Map.class)
    @GetMapping("/findOne/{id}")
    public Map<String, Object> findOne(@PathVariable("id") String id){
        return serverFilePathService.findOne(id);
    }

    @ApiOperation(value = "删除服务器文件路径",httpMethod="POST", notes= "查询服务器文件路径单条数据", produces = "application/json;charset=utf-8", response= Map.class)
    @PostMapping("/delete")
    public Map<String, Object> delete(@RequestBody List<String> ids){
        return serverFilePathService.delete(ids);
    }
}
