package com.fjhx.attachment.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.fjhx.attachment.service.StockAttachmentService;
import com.fjhx.entity.attachment.StockAttachment;
import com.fjhx.params.stock.StockAttachmentVo;
import org.springblade.core.tool.api.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * <p>
 * 业务附件表 前端控制器
 * </p>
 *
 * @author ${author}
 * @since 2022-07-12
 */
@RestController
@RequestMapping("/stockAttachment")
public class StockAttachmentController {

    @Autowired
    private StockAttachmentService stockAttachmentService;

    @PostMapping("/page")
    public R page(@RequestBody Map<String, String> condition) {
        Page<StockAttachment> result = stockAttachmentService.getPage(condition);
        return R.success(result);
    }

    @PostMapping("/add")
    public R add(@RequestBody StockAttachmentVo stockAttachmentVo) {
        stockAttachmentService.add(stockAttachmentVo);
        return R.success();
    }

    @PostMapping("/edit")
    public R edit(@RequestBody StockAttachmentVo stockAttachmentVo) {
        stockAttachmentService.edit(stockAttachmentVo);
        return R.success();
    }

    @PostMapping("/delete")
    public R delete(@RequestBody StockAttachmentVo stockAttachmentVo) {
        stockAttachmentService.delete(stockAttachmentVo);
        return R.success();
    }

    /**
     * 根据业务ID查询文件列表
     *
     * @param busi
     * @return
     */
    @GetMapping("/getListByBusi")
    public R getListByBusi(@RequestParam("busi") String busi) {
        return R.success(stockAttachmentService.getListByBusi(busi));
    }
}

