package com.hxhq.business.controller;

import java.util.List;

import com.hxhq.business.domain.GyzjJcgj;
import com.hxhq.business.domain.GyzjTz;
import com.hxhq.business.domain.GyzjJcgj;
import com.hxhq.business.domain.GyzjTz;
import com.hxhq.business.dto.gyzj.ListDto;
import com.hxhq.business.form.gyzj.*;
import com.hxhq.business.service.IGyzjJcgjService;
import com.hxhq.business.service.IGyzjTzService;
import com.hxhq.business.utils.pdf.PdfExportUtil;
import com.hxhq.common.security.annotation.Logical;
import com.hxhq.common.security.annotation.RequiresPermissions;
import com.hxhq.common.security.utils.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;
import com.hxhq.business.service.IGyzjService;
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 hxhq
 * @date 2025-12-18
 */
@RestController
@RequestMapping("/business/gyzj")
public class GyzjController extends BaseController
{
    @Autowired
    private IGyzjService gyzjService;
    @Autowired
    private IGyzjTzService gyzjTzService;
    @Autowired
    private IGyzjJcgjService gyzjJcgjService;
    /**
     * 上传文件存储在本地的根路径
     */
    @Value("${file.path}")
    private String localFilePath;
    /**
     * 资源映射路径 前缀
     */
    @Value("${file.prefix}")
    public String localFilePrefix;

    /**
     * 列表
     */
    @RequiresPermissions(value = {"business:studyGyzj:list","business:nonTrialGyzj:list","business:drugGyzj:list"}, logical= Logical.OR)
    @GetMapping("/studyList")
    public TableDataInfo studyList(SearchForm form)
    {
        startPage();
        List<ListDto> list = gyzjService.queryStudyList(form);
        return getDataTable(list);
    }


    /**
     * 列表
     */
    @RequiresPermissions("business:resource:gyzj:list")
    @GetMapping("/list")
    public TableDataInfo list(SearchForm form)
    {
        startPage();
        List<ListDto> list = gyzjService.queryList(form);
        return getDataTable(list);
    }

    /**
     * 稽查轨迹列表
     */
    @RequiresPermissions(value={"business:resource:gyzj:xq","business:archive:gyzj:xq"}, logical= Logical.OR)
    @GetMapping("/jcgjList")
    public TableDataInfo jcgjList(GyzjJcgj form)
    {
        startPage();
        List<GyzjJcgj> list = gyzjJcgjService.queryList(form);
        return getDataTable(list);
    }

    /**
     * 台账列表
     */
    @RequiresPermissions(value={"business:resource:gyzj:xq","business:archive:gyzj:xq"}, logical= Logical.OR)
    @GetMapping("/tzList")
    public TableDataInfo tzList(GyzjTz form)
    {
        startPage();
        List<GyzjTz> list = gyzjTzService.queryList(form);
        return getDataTable(list);
    }

    /**
     * 详细信息
     */
    @RequiresPermissions(value={"business:resource:gyzj:xq","business:archive:gyzj:xq"}, logical= Logical.OR)
    @GetMapping(value = "/info")
    public AjaxResult getInfo(Long id)
    {
        return AjaxResult.success(gyzjService.queryInfo(id));
    }

    /**
     * 导出
     */
    @RequiresPermissions(value={"business:resource:gyzj:xq","business:archive:gyzj:xq"}, logical= Logical.OR)
    @GetMapping(value = "/exportDetail")
    public AjaxResult exportDetail(Long id,String lang) {
        GyzjJcgj gyzjJcgj = new GyzjJcgj();
        gyzjJcgj.setGyzjId(id);
        List<GyzjJcgj> gyzjJcgjList = gyzjJcgjService.queryList(gyzjJcgj);
        GyzjTz gyzjTz = new GyzjTz();
        gyzjTz.setGyzjId(id);
        List<GyzjTz> gyzjTzList = gyzjTzService.queryList(gyzjTz);
        return AjaxResult.success(localFilePrefix + PdfExportUtil.export(
                "com.hxhq.business.utils.pdf.resource.Dosage",
                "exportDetail",
                gyzjService.queryInfo(id),
                gyzjTzList,
                gyzjJcgjList,
                lang,
                localFilePath));
    }

    /**
     * 解档
     */
    @PostMapping("/jd")
    @RequiresPermissions("business:resource:gyzj:jd")
    public AjaxResult jd(@RequestBody JdForm form)
    {
        gyzjService.jd(form);
        return AjaxResult.success("操作成功");
    }

    /**
     * 批量归档
     */
    @PostMapping("/plgd")
    @RequiresPermissions("business:resource:gyzj:gd")
    public AjaxResult plgd(@RequestBody GdForm form)
    {
        gyzjService.plgd(form);
        return AjaxResult.success("操作成功");
    }

    /**
     * 归档
     */
    @PostMapping("/gd")
    @RequiresPermissions("business:resource:gyzj:gd")
    public AjaxResult gd(@RequestBody GdForm form)
    {
        gyzjService.gd(form);
        return AjaxResult.success("操作成功");
    }


    /**
     * 批量锁定
     */
    @PostMapping("/plsd")
    @RequiresPermissions("business:resource:gyzj:sd")
    public AjaxResult plsd(@RequestBody SdForm form)
    {
        gyzjService.plsd(form);
        return AjaxResult.success("操作成功");
    }

    /**
     * 锁定
     */
    @PostMapping("/sd")
    @RequiresPermissions("business:resource:gyzj:sd")
    public AjaxResult sd(@RequestBody SdForm form)
    {
        gyzjService.sd(form);
        return AjaxResult.success("操作成功");
    }


    /**
     * 解锁
     */
    @PostMapping("/js")
    @RequiresPermissions("business:resource:gyzj:js")
    public AjaxResult js(@RequestBody JsForm form)
    {
        gyzjService.js(form);
        return AjaxResult.success("操作成功");
    }

    /**
     * 批量处置药剂
     */
    @PostMapping("/plczyj")
    @RequiresPermissions(value={"business:resource:gyzj:czyj","business:studyGyzj:czyj","business:nonTrialGyzj:czyj","business:drugGyzj:czyj"}, logical= Logical.OR)
    public AjaxResult plczyj(@RequestBody PlczyjForm form)
    {
        gyzjService.plczyj(form);
        return AjaxResult.success("操作成功");
    }

    /**
     * 处置药剂
     */
    @PostMapping("/czyj")
    @RequiresPermissions("business:resource:gyzj:czyj")
    public AjaxResult czyj(@RequestBody CzyjForm form)
    {
        gyzjService.czyj(form);
        return AjaxResult.success("操作成功");
    }

    /**
     * 批量处置容器
     */
    @PostMapping("/plczrq")
    @RequiresPermissions("business:resource:gyzj:czrq")
    public AjaxResult plczrq(@RequestBody PlczrqForm form)
    {
        gyzjService.plczrq(form);
        return AjaxResult.success("操作成功");
    }

    /**
     * 处置容器
     */
    @PostMapping("/czrq")
    @RequiresPermissions("business:resource:gyzj:czrq")
    public AjaxResult czrq(@RequestBody CzrqForm form)
    {
        gyzjService.czrq(form);
        return AjaxResult.success("操作成功");
    }


    /**
     * 钥匙发放
     */
    @PostMapping("ysff")
    @RequiresPermissions("business:resource:gyzj:ysff")
    public AjaxResult ysff(@RequestBody YsffForm form)
    {
        gyzjService.ysff(form);
        return AjaxResult.success("操作成功");
    }


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


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



    /**
     * 编辑
     */
    @PostMapping("bj")
    @RequiresPermissions(value={"business:resource:gyzj:bj","business:studyGyzj:bj","business:nonTrialGyzj:bj","business:drugGyzj:bj"}, logical= Logical.OR)
    public AjaxResult bj(@RequestBody BjForm form)
    {
        gyzjService.bj(form);
        return AjaxResult.success("操作成功");
    }


    /**
     * 审核编辑
     */
    @PostMapping("shbj")
    @RequiresPermissions("business:resource:gyzj:shbj")
    public AjaxResult shbj(@RequestBody ShbjForm form)
    {
        gyzjService.shbj(form);
        return AjaxResult.success("操作成功");
    }



    /**
     * 修改库存
     */
    @PostMapping("xgkc")
    @RequiresPermissions(value={"business:resource:gyzj:xgkc","business:studyGyzj:xgkc","business:nonTrialGyzj:xgkc","business:drugGyzj:xgkc"}, logical= Logical.OR)
    public AjaxResult xgkc(@RequestBody XgkcForm form)
    {
        gyzjService.xgkc(form);
        return AjaxResult.success("操作成功");
    }


    /**
     * 审核修改库存
     */
    @PostMapping("shxgkc")
    @RequiresPermissions("business:resource:gyzj:shxgkc")
    public AjaxResult shxgkc(@RequestBody ShxgkcForm form)
    {
        gyzjService.shxgkc(form);
        return AjaxResult.success("操作成功");
    }

    /**
     * 申请归还
     */
    @PostMapping("sqgh")
    @RequiresPermissions(value={"business:studyGyzj:gh","business:nonTrialGyzj:gh","business:drugGyzj:gh"}, logical= Logical.OR)
    public AjaxResult sqgh(@RequestBody GhForm form)
    {
        gyzjService.sqgh(form);
        return AjaxResult.success("操作成功");
    }

    /**
     * 确认归还
     */
    @PostMapping("gh")
    @RequiresPermissions({"business:resource:gyzj:gh"})
    public AjaxResult gh(@RequestBody GhForm form)
    {
        gyzjService.gh(form);
        return AjaxResult.success("操作成功");
    }


    /**
     * 申请入库
     */
    @PostMapping("sqrk")
    @RequiresPermissions(value={"business:studyGyzj:rk","business:nonTrialGyzj:rk","business:drugGyzj:rk"}, logical= Logical.OR)
    public AjaxResult sqrk(@RequestBody RkForm form)
    {
        gyzjService.sqrk(form);
        return AjaxResult.success("操作成功");
    }

    /**
     * 确认入库
     */
    @PostMapping("rk")
    @RequiresPermissions({"business:resource:gyzj:rk"})
    public AjaxResult rk(@RequestBody RkForm form)
    {
        gyzjService.rk(form);
        return AjaxResult.success("操作成功");
    }

    /**
     * 借阅
     */
    @PostMapping("/jy")
    @RequiresPermissions("business:resource:gyzj:jy")
    public AjaxResult jy(@RequestBody JyForm form)
    {
        gyzjService.jy(form);
        return AjaxResult.success("操作成功");
    }

    /**
     * 存储
     */
    @PostMapping("cc")
    @RequiresPermissions(value={"business:studyGyzj:cc","business:nonTrialGyzj:cc","business:drugGyzj:cc"}, logical= Logical.OR)
    public AjaxResult cc(@RequestBody CcForm form)
    {
        gyzjService.cc(form);
        return AjaxResult.success("操作成功");
    }


    /**
     * 取出
     */
    @PostMapping("qc")
    @RequiresPermissions(value={"business:studyGyzj:qc","business:nonTrialGyzj:qc","business:drugGyzj:qc"}, logical= Logical.OR)
    public AjaxResult qc(@RequestBody CcForm form)
    {
        gyzjService.qc(form);
        return AjaxResult.success("操作成功");
    }
}
