package com.hxhq.business.controller;

import java.util.List;

import com.hxhq.business.domain.*;
import com.hxhq.business.dto.gsp.GspListDto;
import com.hxhq.business.enums.zykgl.DaztEnum;
import com.hxhq.business.form.gsp.*;
import com.hxhq.business.form.gyzj.SearchForm;
import com.hxhq.business.service.IGspJcgjService;
import com.hxhq.business.service.IGspTzService;
import com.hxhq.common.core.constant.Constants;
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 com.hxhq.business.service.IGspService;
import com.hxhq.common.core.web.controller.BaseController;
import com.hxhq.common.core.web.domain.AjaxResult;
import com.hxhq.common.core.web.page.TableDataInfo;


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

    @Autowired
    private IGspJcgjService gspJcgjService;

    @Autowired
    private IGspTzService gspTzService;

    /**
     * 试验物资列表
     */
    @GetMapping("/studyList")
    public TableDataInfo studyList(GspSearchListForm form)
    {
        startPage();
        List<GspListDto> list = gspService.queryStudyList(form);
        return getDataTable(list);
    }

    /**
     * 查询供试品管理列表
     */
    @GetMapping("/list")
    @RequiresPermissions("business:resource:gsp:list")
    public TableDataInfo list(GspSearchListForm form) {
        startPage();
        List<Gsp> list = gspService.queryList(form);
        return getDataTable(list);
    }

    /**
     * 供试品-档案列表
     */
    @GetMapping("/archive/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);
    }

    /**
     * 稽查轨迹列表
     */
    @GetMapping("/jcgjList")
    @RequiresPermissions("business:resource:gsp:list")
    public TableDataInfo jcgjList(GspJcgj form)
    {
        startPage();
        List<GspJcgj> list = gspJcgjService.queryList(form);
        return getDataTable(list);
    }

    /**
     * 台账列表
     */
    @GetMapping("/tzList")
    @RequiresPermissions("business:resource:gsp:list")
    public TableDataInfo tzList(GspTz form)
    {
        startPage();
        List<GspTz> list = gspTzService.queryList(form);
        return getDataTable(list);
    }

    /**
     * 获取供试品管理详细信息
     */
    @GetMapping(value = "/info")
    @RequiresPermissions("business:resource:gsp:xq")
    public AjaxResult getInfo(Long id) {
        return AjaxResult.success(gspService.queryInfo(id));
    }

    /**
     * 新增供试品管理信息
     */
    @PostMapping("/save")
    @RequiresPermissions("business:resource:gsp:xz")
    public AjaxResult save(@RequestBody @Validated GspForm form) {
        form.setQmrId(SecurityUtils.getUserId());
        gspService.save(form);
        return AjaxResult.success("操作成功");
    }

    /**
     * 编辑供试品管理信息
     */
    @PostMapping("/edit")
    @RequiresPermissions("business:resource:gsp:bj")
    public AjaxResult edit(@RequestBody @Validated GspBjForm form) {
        form.setQmrId(SecurityUtils.getUserId());
        gspService.edit(form);
        return AjaxResult.success("操作成功");
    }

    /**
     * 审核编辑
     */
    @RequiresPermissions("business:resource:gsp:shbj")
    @PostMapping("shbj")
    public AjaxResult shbj(@RequestBody GspShbjForm form)
    {
        form.setQmrId(SecurityUtils.getUserId());
        gspService.shbj(form);
        return AjaxResult.success("操作成功");
    }
    /**
     * 钥匙发放
     */
    @PostMapping("/ysff")
    @RequiresPermissions("business:resource:gsp:ysff")
    public AjaxResult ysff(@RequestBody GspYsffForm form)
    {
        form.setFfrId(SecurityUtils.getUserId());
        gspService.ysff(form);
        return AjaxResult.success("操作成功");
    }

    /**
     * 发放
     */
    @PostMapping("/ff")
    @RequiresPermissions("business:resource:gsp:ff")
    public AjaxResult ff(@RequestBody @Validated FfGspForm form) {
        gspService.ff(form);
        return AjaxResult.success("操作成功");
    }

    /**
     * 批量发放
     */
    @PostMapping("/plff")
    @RequiresPermissions("business:resource:gsp:ff")
    public AjaxResult plff(@RequestBody GspPlffForm form)
    {
        gspService.plff(form);
        return AjaxResult.success("操作成功");
    }

    /**
     * 归还
     */
    @PostMapping("gh")
    @RequiresPermissions("business:resource:gsp:gh")
    public AjaxResult gh(@RequestBody GspGhForm form)
    {
        gspService.gh(form);
        return AjaxResult.success("操作成功");
    }

    /**
     * 修改库存
     */
    @PostMapping("xgkc")
    @RequiresPermissions("business:resource:gsp:xgkc")
    public AjaxResult xgkc(@RequestBody GspXgkcForm form)
    {
        form.setQmrId(SecurityUtils.getUserId());
        gspService.xgkc(form);
        return AjaxResult.success("操作成功");
    }

    /**
     * 审核修改库存
     */
    @PostMapping("shxgkc")
    @RequiresPermissions("business:resource:gsp:shxgkc")
    public AjaxResult shxgkc(@RequestBody GspShxgkcForm form)
    {
        form.setQmrId(SecurityUtils.getUserId());
        gspService.shxgkc(form);
        return AjaxResult.success("操作成功");
    }

    /**
     * 批量锁定
     */
    @PostMapping("/plsd")
    @RequiresPermissions("business:resource:gsp:sd")
    public AjaxResult plsd(@RequestBody GspSdForm form)
    {
        form.setQmrId(SecurityUtils.getUserId());
        gspService.plsd(form);
        return AjaxResult.success("操作成功");
    }

    /**
     * 锁定
     */
    @PostMapping("/sd")
    @RequiresPermissions("business:resource:gsp:sd")
    public AjaxResult sd(@RequestBody GspSdForm form)
    {
        form.setQmrId(SecurityUtils.getUserId());
        gspService.sd(form);
        return AjaxResult.success("操作成功");
    }


    /**
     * 解锁
     */
    @PostMapping("/js")
    @RequiresPermissions("business:resource:gsp:js")
    public AjaxResult js(@RequestBody GspJsForm form)
    {
        form.setQmrId(SecurityUtils.getUserId());
        gspService.js(form);
        return AjaxResult.success("操作成功");
    }

    /** 处置 */
    @PostMapping("/cz")
    @RequiresPermissions("business:resource:gsp:cz")
    public AjaxResult cz(@RequestBody @Validated GspCzForm form)
    {
        form.setQmrId(SecurityUtils.getUserId());
        gspService.cz(form);
        return AjaxResult.success("操作成功");
    }

    /** 批量处置 */
    @PostMapping("/plcz")
    @RequiresPermissions("business:resource:gsp:cz")
    public AjaxResult plcz(@RequestBody @Validated GspPlczForm form)
    {
        form.setQmrId(SecurityUtils.getUserId());
        gspService.plcz(form);
        return AjaxResult.success("操作成功");
    }

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

    /**
     * 解档
     */
    @PostMapping("/jd")
    @RequiresPermissions("business:resource:gsp:jd")
    public AjaxResult jd(@RequestBody @Validated GspJdForm form)
    {
        form.setQmrId(SecurityUtils.getUserId());
        gspService.jd(form);
        return AjaxResult.success("操作成功");
    }

    /**
     * 批量归档
     */
    @PostMapping("/plgd")
    @RequiresPermissions("business:resource:gsp:gd")
    public AjaxResult plgd(@RequestBody GspGdForm form)
    {
        form.setQmrId(SecurityUtils.getUserId());
        gspService.plgd(form);
        return AjaxResult.success("操作成功");
    }

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

}
