package com.bonus.material.device.controller;

import com.bonus.common.biz.enums.HttpCodeEnum;
import com.bonus.common.core.web.controller.BaseController;
import com.bonus.common.core.web.domain.AjaxResult;
import com.bonus.material.device.domain.MaDevQc;
import com.bonus.material.device.domain.MaDevRm;
import com.bonus.material.device.service.MaDevQcService;
import com.bonus.material.device.service.MaDevRmService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Author ma_sh
 * @create 2024/12/5 15:53
 */
@RestController
@RequestMapping("/ma_rm")
@Api(value = "装备维修保养管理",tags = "维修保养")
public class MaDevRmController extends BaseController {

    @Resource
    private MaDevRmService maDevRmService;

    /**
     * 装备质检列表
     * @param maDevQc
     * @return
     */
    @ApiOperation(value = "维修保养列表")
    @GetMapping("/list")
    public AjaxResult list(MaDevRm maDevRm) {
        startPage();
        List<MaDevRm> list = maDevRmService.selectDevQcList(maDevRm);
        return AjaxResult.success(getDataTable(list));
    }
    /**
     * 装备质检列表
     * @param maDevQc
     * @return
     */
    @ApiOperation(value = "维修保养列表")
    @GetMapping("/rmList")
    public AjaxResult qcList(MaDevRm maDevRm) {
        startPage();
        List<MaDevRm> list = maDevRmService.selectQcList(maDevRm);
        return AjaxResult.success(getDataTable(list));
    }

    /**
     * 新增装备质检--含附件上传
     * @param maDevQc
     * @return
     */
    @ApiOperation(value = "新增装备维保--含附件上传")
    @PostMapping("/add")
    public AjaxResult add(@RequestBody MaDevRm maDevRm) {
        return maDevRmService.insertDevQc(maDevRm);
    }

    /**
     * 删除装备质检
     * @param maDevQc
     * @return
     */
    @ApiOperation(value = "删除装备维保")
    @PostMapping("/deleteById")
    public AjaxResult deleteById(@RequestBody MaDevRm maDevRm) {
        if (maDevRm == null || maDevRm.getFileId() == null) {
            return AjaxResult.error(HttpCodeEnum.TO_PARAM_NULL.getCode(), HttpCodeEnum.TO_PARAM_NULL.getMsg());
        }
        Integer i = maDevRmService.deleteById(maDevRm);
        return i > 0 ? AjaxResult.success("删除成功") : AjaxResult.error("删除失败");
    }
}
