package com.hxhq.business.controller;

import com.hxhq.business.domain.Gsp;
import com.hxhq.business.domain.GspJcgj;
import com.hxhq.business.domain.GspTz;
import com.hxhq.business.dto.gsp.GspListDto;
import com.hxhq.business.enums.zykgl.DaztEnum;
import com.hxhq.business.form.gsp.*;
import com.hxhq.business.service.IGspJcgjService;
import com.hxhq.business.service.IGspService;
import com.hxhq.business.service.IGspTzService;
import com.hxhq.common.core.web.controller.BaseController;
import com.hxhq.common.core.web.domain.AjaxResult;
import com.hxhq.common.core.web.page.TableDataInfo;
import com.hxhq.common.security.annotation.RequiresPermissions;
import com.hxhq.common.security.utils.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;


/**
 * 供试品档案管理Controller
 *
 * @author HanLong
 * @date 2025-12-30
 */
@RestController
@RequestMapping("/business/gspArchive")
public class GspArchiveController extends BaseController {
    @Autowired
    private IGspService gspService;



    /**
     * 供试品-档案列表
     */
    @GetMapping("/list")
    @RequiresPermissions("business:archive:gsp:list")
    public TableDataInfo archiveList(GspSearchListForm form) {
        startPage();
        form.setArchive(DaztEnum.ygd.getValue());
        List<Gsp> list = gspService.queryList(form);
        return getDataTable(list);
    }

    /**
     * 同意归档
     */
    @PostMapping("/gd/agree")
    @RequiresPermissions("business:archive:gsp:tygd")
    public AjaxResult agreeGd(@RequestBody @Validated GspGdForm form)
    {
        form.setQmrId(SecurityUtils.getUserId());
        gspService.agreeGd(form);
        return AjaxResult.success("操作成功");
    }

    /**
     * 拒绝归档
     */
    @PostMapping("/gd/refuse")
    @RequiresPermissions("business:archive:gsp:jjgd")
    public AjaxResult refuseGd(@RequestBody @Validated GspGdForm form)
    {
        form.setQmrId(SecurityUtils.getUserId());
        gspService.refuseGd(form);
        return AjaxResult.success("操作成功");
    }

    /**
     * 同意解档
     */
    @PostMapping("/jd/agree")
    @RequiresPermissions("business:archive:gsp:tyjd")
    public AjaxResult agreeJd(@RequestBody @Validated GspGdForm form)
    {
        form.setQmrId(SecurityUtils.getUserId());
        gspService.agreeJd(form);
        return AjaxResult.success("操作成功");
    }

    /**
     * 拒绝解档
     */
    @PostMapping("/jd/refuse")
    @RequiresPermissions("business:archive:gsp:jjjd")
    public AjaxResult refuseJd(@RequestBody @Validated GspGdForm form)
    {
        form.setQmrId(SecurityUtils.getUserId());
        gspService.refuseJd(form);
        return AjaxResult.success("操作成功");
    }

    /**
     * 同意借阅
     */
    @PostMapping("/jy/agree")
    @RequiresPermissions("business:resource:gsp:gd")
    public AjaxResult agreeJy(@RequestBody @Validated GspJyForm form)
    {
        form.setQmrId(SecurityUtils.getUserId());
        gspService.agreeJy(form);
        return AjaxResult.success("操作成功");
    }

    /**
     * 拒绝借阅
     */
    @PostMapping("/jy/refuse")
    @RequiresPermissions("business:resource:gsp:gd")
    public AjaxResult refuseJy(@RequestBody @Validated GspJyForm form)
    {
        form.setQmrId(SecurityUtils.getUserId());
        gspService.refuseJy(form);
        return AjaxResult.success("操作成功");
    }

    /**
     * 档案确认归还
     */
    @PostMapping("/gh")
    @RequiresPermissions("business:resource:gsp:gd")
    public AjaxResult archiveGh(@RequestBody @Validated GspGdForm form)
    {
        form.setQmrId(SecurityUtils.getUserId());
        gspService.archiveGh(form);
        return AjaxResult.success("操作成功");
    }
}
