package com.xinelu.manage.controller.appfileinfo;


import com.xinelu.common.annotation.Log;
import com.xinelu.common.core.controller.BaseController;
import com.xinelu.common.core.domain.AjaxResult;
import com.xinelu.common.core.page.TableDataInfo;
import com.xinelu.common.custominterface.Insert;
import com.xinelu.common.enums.BusinessType;
import com.xinelu.common.utils.poi.ExcelUtil;
import com.xinelu.manage.domain.appfileinfo.AppFileInfo;
import com.xinelu.manage.dto.appfileInfo.AppFileInfoDTO;
import com.xinelu.manage.service.appfileinfo.IAppFileInfoService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 护理员App文件管理Controller
 *
 * @author xinyilu
 * @date 2022-11-15
 */
@RestController
@RequestMapping("/system/appFileInfo")
public class AppFileInfoController extends BaseController {
    @Resource
    private IAppFileInfoService appFileInfoService;

    /**
     * 查询护理员App文件管理列表
     */
    @PreAuthorize("@ss.hasPermi('system:appFileInfo:list')")
    @GetMapping("/list")
    public TableDataInfo list(AppFileInfo appFileInfo) {
        startPage();
        List<AppFileInfo> list = appFileInfoService.selectAppFileInfoList(appFileInfo);
        return getDataTable(list);
    }

    /**
     * 导出护理员App文件管理列表
     */
    @PreAuthorize("@ss.hasPermi('system:appFileInfo:export')")
    @Log(title = "护理员App文件管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, AppFileInfo appFileInfo) {
        List<AppFileInfo> list = appFileInfoService.selectAppFileInfoList(appFileInfo);
        ExcelUtil<AppFileInfo> util = new ExcelUtil<>(AppFileInfo.class);
        util.exportExcel(response, list, "护理员App文件管理数据");
    }

    /**
     * 获取护理员App文件管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:appFileInfo:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(appFileInfoService.selectAppFileInfoById(id));
    }

    /**
     * 新增护理员App文件管理
     */
    @PreAuthorize("@ss.hasPermi('system:appFileInfo:add')")
    @Log(title = "护理员App文件管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AppFileInfo appFileInfo) {
        return toAjax(appFileInfoService.insertAppFileInfo(appFileInfo));
    }

    /**
     * 修改护理员App文件管理
     */
    @PreAuthorize("@ss.hasPermi('system:appFileInfo:edit')")
    @Log(title = "护理员App文件管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AppFileInfo appFileInfo) {
        return toAjax(appFileInfoService.updateAppFileInfo(appFileInfo));
    }

    /**
     * 删除护理员App文件管理
     */
    @PreAuthorize("@ss.hasPermi('system:appFileInfo:remove')")
    @Log(title = "护理员App文件管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(appFileInfoService.deleteAppFileInfoByIds(ids));
    }

    /**
     * 护理员App上传apk
     *
     * @param appFileInfoDTO 文件及版本
     * @return 结果
     * @throws Exception 异常
     */
    @PostMapping("uploadAppFileUrl")
    public AjaxResult uploadAppFileUrl(@Validated(Insert.class) AppFileInfoDTO appFileInfoDTO) throws Exception {
        return appFileInfoService.uploadAppFileInfo(appFileInfoDTO);
    }
}
