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.DevInfo;
import com.bonus.material.device.domain.MaDevQc;
import com.bonus.material.device.service.MaDevQcService;
import com.bonus.material.lease.domain.MaLeaseInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

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

/**
 * @Author ma_sh
 * @create 2024/12/5 15:53
 */
@RestController
@RequestMapping("/ma_qc")
@Api(value = "装备质检管理", tags = "装备质检")
public class MaDevQcController extends BaseController {

    @Resource
    private MaDevQcService maDevQcService;

    /**
     * 装备质检列表
     *
     * @param maDevQc
     * @return
     */
    @ApiOperation(value = "装备质检列表")
    @GetMapping("/list")
    public AjaxResult list(MaDevQc maDevQc) {
        startPage();
        List<MaDevQc> list = maDevQcService.selectDevQcList(maDevQc);
        return AjaxResult.success(getDataTable(list));
    }

    /**
     * 装备质检列表
     *
     * @param maDevQc
     * @return
     */
    @ApiOperation(value = "装备质检列表")
    @GetMapping("/qcList")
    public AjaxResult qcList(MaDevQc maDevQc) {
        startPage();
        List<MaDevQc> list = maDevQcService.selectQcList(maDevQc);
        return AjaxResult.success(getDataTable(list));
    }

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

    /**
     * 删除装备质检
     *
     * @param maDevQc
     * @return
     */
    @ApiOperation(value = "删除装备质检")
    @PostMapping("/deleteById")
    public AjaxResult deleteById(@RequestBody MaDevQc maDevQc) {
        if (maDevQc == null || maDevQc.getFileId() == null ||  maDevQc.getMaId() == null) {
            return AjaxResult.error(HttpCodeEnum.TO_PARAM_NULL.getMsg());
        }
        Integer count = maDevQcService.selectDevQcListByMaId(maDevQc.getMaId());
        if (count <= 1) {
            return AjaxResult.error("请保持质检数据至少有一条");
        }
        Integer i = maDevQcService.deleteById(maDevQc);
        return i > 0 ? AjaxResult.success("删除成功") : AjaxResult.error("删除失败");
    }
}
