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.entity.Organization;
import com.ym.mec.biz.dal.page.ManagerDownloadQueryInfo;
import com.ym.mec.biz.dal.page.OrganizationQueryInfo;
import com.ym.mec.biz.service.ManagerDownloadService;
import com.ym.mec.common.controller.BaseController;
import com.ym.mec.common.entity.HttpResponseResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

@RequestMapping("managerDownload")
@Api(tags = "下载列表")
@RestController
public class ManagerDownloadController extends BaseController {

    @Autowired
    private ManagerDownloadService managerDownloadService;
    @Autowired
    private SysUserFeignService sysUserFeignService;

    @ApiOperation(value = "分页查询列表")
    @GetMapping("/queryPage")
    @PreAuthorize("@pcs.hasPermissions('managerDownload/queryPage')")
    public Object queryPage(ManagerDownloadQueryInfo queryInfo) {
        SysUser sysUser = sysUserFeignService.queryUserInfo();
        if (sysUser == null) {
            return failed("用户信息获取失败");
        }
        queryInfo.setUserId(sysUser.getId());
        return succeed(managerDownloadService.queryPage(queryInfo));
    }

    @ApiOperation(value = "删除")
    @PostMapping("/del/{id}")
    @PreAuthorize("@pcs.hasPermissions('managerDownload/del')")
    public Object del(@ApiParam(value = "下载记录id", required = true) @PathVariable("id") Integer id) {
        return succeed(managerDownloadService.delete(id));
    }

}
