package com.zksy.web.controller.basicData;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zksy.basicData.domain.XcrFile;
import com.zksy.basicData.service.IXcrFileService;
import com.zksy.common.annotation.Log;
import com.zksy.common.core.controller.BaseController;
import com.zksy.common.enums.BusinessType;
import com.zksy.common.utils.SearchUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

/**
 * 文件管理Controller
 *
 * @author sy
 * @date 2024-05-20
 */
@RestController
@RequestMapping("/xcrFile")
@Api(tags = "文件管理", description = "文件管理desc")
public class XcrFileController extends BaseController {

    @Autowired
    private IXcrFileService service;

    @GetMapping("/getById/{borrowId}")
    @ApiOperation(value = "文件管理搜索getById")
    public XcrFile getById(@PathVariable String borrowId) {
        return service.getById(borrowId);
    }

    @GetMapping("/findByPage")
    @ApiOperation(value = "文件管理分页")
    public Page findByPage(long pageNum, long pageSize, String conditionJson) throws Exception {
        return service.page(new Page<>(pageNum, pageSize), SearchUtil.parseWhereSql(conditionJson));
    }

    @GetMapping("/getList")
    @ApiOperation(value = "文件管理根据条件查询所有")
    public List<XcrFile> getList(String conditionJson) throws Exception {
        return service.list(SearchUtil.parseWhereSql(conditionJson));
    }

    /**
     * 新增文件管理
     */
    @PostMapping("/save")
    @ApiOperation(value = "文件管理新增")
    @Log(title = "新增文件管理", businessType = BusinessType.INSERT)
    public boolean save(XcrFile crmFile,@RequestParam("file") MultipartFile file) {
        return service.saveMinio(crmFile,file);
    }

    /**
     * 修改文件管理
     */
    @PostMapping("/updateById")
    @ApiOperation(value = "文件管理修改")
    @Log(title = "修改文件管理", businessType = BusinessType.UPDATE)
    public boolean updateById(@RequestBody XcrFile crmFile,MultipartFile multipartFile) {
        return service.updateMinio(crmFile,multipartFile);
    }

    /**
     * 删除文件管理
     */
    @GetMapping("/deleteFile")
    @ApiOperation(value = "文件管理删除")
    @Log(title = "删除文件管理", businessType = BusinessType.DELETE)
    public boolean deleteFile(@PathVariable String id) {
        return service.deleteFile(id);
    }

}

