package com.hxhq.business.controller;

import java.util.List;

import com.hxhq.business.domain.MjyJcgj;
import com.hxhq.business.domain.MjyTz;
import com.hxhq.business.dto.mjy.ListDto;
import com.hxhq.business.form.mjy.*;
import com.hxhq.business.service.IMjyJcgjService;
import com.hxhq.business.service.IMjyTzService;
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.IMjyService;
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/mjy")
public class MjyController extends BaseController {
    @Autowired
    private IMjyService mjyService;
    @Autowired
    private IMjyTzService mjyTzService;
    @Autowired
    private IMjyJcgjService mjyJcgjService;
    /**
     * 上传文件存储在本地的根路径
     */
    @Value("${file.path}")
    private String localFilePath;
    /**
     * 资源映射路径 前缀
     */
    @Value("${file.prefix}")
    public String localFilePrefix;

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

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

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

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

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

    /**
     * 导出
     */
    @RequiresPermissions(value={"business:resource:mjy:xq","business:archive:mjy:xq"}, logical= Logical.OR)
    @GetMapping(value = "/exportDetail")
    public AjaxResult exportDetail(Long id,String lang) {
        MjyJcgj mjyJcgj = new MjyJcgj();
        mjyJcgj.setMjyId(id);
        List<MjyJcgj> mjyJcgjList = mjyJcgjService.queryList(mjyJcgj);
        MjyTz mjyTz = new MjyTz();
        mjyTz.setMjyId(id);
        List<MjyTz> mjyTzList = mjyTzService.queryList(mjyTz);
        return AjaxResult.success(localFilePrefix + PdfExportUtil.export(
                "com.hxhq.business.utils.pdf.resource.Drug",
                "exportDetail",
                mjyService.queryInfo(id),
                mjyTzList,
                mjyJcgjList,
                lang,
                localFilePath));
    }


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

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

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


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

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


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

    /**
     * 批量处置药剂
     */
    @PostMapping("/plczyj")
    @RequiresPermissions(value={"business:resource:mjy:czyj", "business:studyMjy:czyj", "business:nonTrialMjy:czyj", "business:drugMjy:czyj"}, logical= Logical.OR)
    public AjaxResult plczyj(@RequestBody PlczyjForm form) {
        form.setClrId(SecurityUtils.getUserId());
        mjyService.plczyj(form);
        return AjaxResult.success("操作成功");
    }

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

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

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


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


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


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


    /**
     * 编辑
     */
    @PostMapping("bj")
    @RequiresPermissions(value={"business:resource:mjy:bj", "business:studyMjy:bj", "business:nonTrialMjy:bj", "business:drugMjy:bj"}, logical= Logical.OR)
    public AjaxResult bj(@RequestBody BjForm form) {
        form.setQmrId(SecurityUtils.getUserId());
        mjyService.bj(form);
        return AjaxResult.success("操作成功");
    }


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


    /**
     * 修改库存
     */
    @PostMapping("xgkc")
    @RequiresPermissions(value={"business:resource:mjy:xgkc", "business:studyMjy:xgkc", "business:nonTrialMjy:xgkc", "business:drugMjy:xgkc"}, logical= Logical.OR)
    public AjaxResult xgkc(@RequestBody XgkcForm form) {
        form.setQmrId(SecurityUtils.getUserId());
        mjyService.xgkc(form);
        return AjaxResult.success("操作成功");
    }


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

    /**
     * 归还
     */
    @PostMapping("gh")
    @RequiresPermissions({"business:resource:mjy:gh"})
    public AjaxResult gh(@RequestBody GhForm form) {
        form.setQmrId(SecurityUtils.getUserId());
        mjyService.gh(form);
        return AjaxResult.success("操作成功");
    }

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

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

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

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