package com.hxhq.business.controller;

import com.hxhq.business.domain.Sj;
import com.hxhq.business.domain.SjJcgj;
import com.hxhq.business.domain.SjTz;
import com.hxhq.business.dto.sj.SjListDto;
import com.hxhq.business.enums.zykgl.DaztEnum;
import com.hxhq.business.enums.zykgl.JyztEnum;
import com.hxhq.business.enums.zykgl.ZjztEnum;
import com.hxhq.business.form.gsp.GspGdForm;
import com.hxhq.business.form.gsp.GspJyForm;
import com.hxhq.business.form.gsp.GspSearchListForm;
import com.hxhq.business.form.sj.*;
import com.hxhq.business.service.ISjJcgjService;
import com.hxhq.business.service.ISjService;
import com.hxhq.business.service.ISjTzService;
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.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;


/**
 * 试剂档案Controller
 *
 * @author HanLong
 * @date 2025-12-22
 */
@RestController
@RequestMapping("/business/sjArchive")
public class SjArchiveController extends BaseController
{
    @Autowired
    private ISjService sjService;

    /**
     * 查询试剂列表
     */
    @GetMapping("/list")
    @RequiresPermissions("business:resource:sj:list")
    public TableDataInfo list(SjSearchListForm form)
    {
        startPage();
        form.setArchive(DaztEnum.ygd.getValue());
        List<SjListDto> list = sjService.queryList(form);
        return getDataTable(list);
    }


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

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

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

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

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

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

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