package com.yunfeiyun.agmp.fms.controller;


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

import com.yunfeiyun.agmp.common.constant.ErrorCode;
import com.yunfeiyun.agmp.common.constant.ResConstants;
import com.yunfeiyun.agmp.common.framework.manager.ResManager;
import com.yunfeiyun.agmp.common.web.system.domain.SysRes;
import com.yunfeiyun.agmp.fms.domain.MppQualitycheck;
import com.yunfeiyun.agmp.fms.domain.reqvo.AddMppQualitycheckReqVo;
import com.yunfeiyun.agmp.fms.service.IMppQualitycheckService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.yunfeiyun.agmp.common.annotation.Log;
import com.yunfeiyun.agmp.common.core.controller.BaseController;
import com.yunfeiyun.agmp.common.core.domain.AjaxResult;
import com.yunfeiyun.agmp.common.enums.BusinessType;
import com.yunfeiyun.agmp.common.utils.poi.ExcelUtil;
import com.yunfeiyun.agmp.common.core.page.TableDataInfo;
import org.springframework.web.multipart.MultipartFile;

/**
 *  质检Controller
 * 
 * @author 杨晓辉
 * @date 2023-05-30
 */
@RestController
@RequestMapping("/mpp/qualitycheck")
public class MppQualitycheckController extends BaseController
{
    @Autowired
    private IMppQualitycheckService mppQualitycheckService;
    @Autowired
    private ResManager resManager;

    /**
     * 查询 质检列表
     */
    @PreAuthorize("@ss.hasPermi('mpp:qualitycheck:list')")
    @GetMapping("/list")
    public TableDataInfo list(MppQualitycheck mppQualitycheck)
    {
        startPage();
        List<MppQualitycheck> list = mppQualitycheckService.selectMppQualitycheckList(mppQualitycheck);
        return getDataTable(list);
    }

    /**
     * 导出 质检列表
     */
    @PreAuthorize("@ss.hasPermi('mpp:qualitycheck:export')")
    @Log(title = " 质检", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, MppQualitycheck mppQualitycheck)
    {
        List<MppQualitycheck> list = mppQualitycheckService.selectMppQualitycheckList(mppQualitycheck);
        ExcelUtil<MppQualitycheck> util = new ExcelUtil<MppQualitycheck>(MppQualitycheck.class);
        util.exportExcel(response, list, " 质检数据");
    }

    /**
     * 获取 质检详细信息
     */
    @PreAuthorize("@ss.hasPermi('mpp:qualitycheck:info')")
    @GetMapping(value = "/info")
    public AjaxResult getInfo(@RequestParam("qualitycheckId") String qualitycheckId)
    {
        return success(mppQualitycheckService.selectMppQualitycheckByQualitycheckId(qualitycheckId));
    }

    /**
     * 新增 质检
     */
    @PreAuthorize("@ss.hasPermi('mpp:qualitycheck:add')")
    @Log(title = " 质检", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    public AjaxResult add(@RequestBody AddMppQualitycheckReqVo reqVo)
    {
        return mppQualitycheckService.insertMppQualitycheck(reqVo);
    }

    /**
     * 修改 质检
     */
    @PreAuthorize("@ss.hasPermi('mpp:qualitycheck:edit')")
    @Log(title = " 质检", businessType = BusinessType.UPDATE)
    @PutMapping("/edit")
    public AjaxResult edit(@RequestBody MppQualitycheck mppQualitycheck)
    {
        return toAjax(mppQualitycheckService.updateMppQualitycheck(mppQualitycheck));
    }

    /**
     * 删除 质检
     */
    @PreAuthorize("@ss.hasPermi('mpp:qualitycheck:delete')")
    @Log(title = " 质检", businessType = BusinessType.DELETE)
	@DeleteMapping("/delete")
    public AjaxResult remove(@RequestParam("qualitycheckIds") String[] qualitycheckIds)
    {
        return toAjax(mppQualitycheckService.deleteMppQualitycheckByQualitycheckIds(qualitycheckIds));
    }

    /**
     * 质检图片上传
     */
    @PreAuthorize("@ss.hasPermi('mpp:qualitycheck:upload')")
    @Log(title = "质检图片上传", businessType = BusinessType.UPDATE)
    @PostMapping("/upload")
    public AjaxResult periodUpload(MultipartFile file) throws Exception
    {
        if (!file.isEmpty())
        {
            SysRes sysRes  = resManager.uploadRes( ResConstants.BizType.MPPQUALITYCHECK, ResConstants.mediaType.IMG, "", file,getLoginUser());
            return success(sysRes);
        }
        return error(ErrorCode.UPLOAD_FAIL.getCode());
    }

}
