package com.xinelu.manage.controller.specialdiseasenode;

import com.xinelu.common.annotation.Log;
import com.xinelu.common.core.controller.BaseController;
import com.xinelu.common.core.domain.AjaxResult;
import com.xinelu.common.core.domain.R;
import com.xinelu.common.core.page.TableDataInfo;
import com.xinelu.common.enums.BusinessType;
import com.xinelu.common.exception.ServiceException;
import com.xinelu.common.utils.poi.ExcelUtil;
import com.xinelu.manage.domain.patientnodeparamscurrent.PatientNodeParamsCurrent;
import com.xinelu.manage.domain.specialdiseasenode.SpecialDiseaseNode;
import com.xinelu.manage.service.specialdiseasenode.ISpecialDiseaseNodeService;
import com.xinelu.manage.vo.specialdiseaseroute.SpecialDiseaseRouteVO;
import io.swagger.annotations.ApiOperation;
import java.util.List;
import java.util.Objects;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 专病路径-管理节点信息Controller
 *
 * @author xinelu
 * @date 2024-03-13
 */
@RestController
@RequestMapping("/system/specialDiseaseNode")
public class SpecialDiseaseNodeController extends BaseController {
    @Resource
    private ISpecialDiseaseNodeService specialDiseaseNodeService;

    /**
     * 查询专病路径-管理节点信息列表
     */
    @PreAuthorize("@ss.hasPermi('system:specialDiseaseNode:list')")
    @GetMapping("/list")
    public TableDataInfo list(SpecialDiseaseNode specialDiseaseNode) {
        startPage();
        List<SpecialDiseaseNode> list = specialDiseaseNodeService.selectSpecialDiseaseNodeList(specialDiseaseNode);
        return getDataTable(list);
    }

    /**
     * 导出专病路径-管理节点信息列表
     */
    @PreAuthorize("@ss.hasPermi('system:specialDiseaseNode:export')")
    @Log(title = "专病路径-管理节点信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SpecialDiseaseNode specialDiseaseNode) {
        List<SpecialDiseaseNode> list = specialDiseaseNodeService.selectSpecialDiseaseNodeList(specialDiseaseNode);
        ExcelUtil<SpecialDiseaseNode> util = new ExcelUtil<SpecialDiseaseNode>(SpecialDiseaseNode.class);
        util.exportExcel(response, list, "专病路径-管理节点信息数据");
    }

    /**
     * 获取专病路径-管理节点信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:specialDiseaseNode:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(specialDiseaseNodeService.selectSpecialDiseaseNodeById(id));
    }

    /**
     * 新增专病路径-管理节点信息(未使用)
     */
    @PreAuthorize("@ss.hasPermi('system:specialDiseaseNode:add')")
    @Log(title = "专病路径-管理节点信息", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    public AjaxResult add(@RequestBody SpecialDiseaseRouteVO specialDiseaseNode) {
        return specialDiseaseNodeService.insertSpecialDiseaseNode(specialDiseaseNode);
    }

    /**
     * 修改专病路径-管理节点信息(专病路径新增修改)
     */
    @PreAuthorize("@ss.hasPermi('system:specialDiseaseNode:edit')")
    @Log(title = "专病路径-管理节点信息", businessType = BusinessType.UPDATE)
    @PutMapping("/edit")
    public AjaxResult edit(@RequestBody SpecialDiseaseRouteVO specialDiseaseNode) {
        return specialDiseaseNodeService.updateSpecialDiseaseNode(specialDiseaseNode);
    }

    /**
     * 删除专病路径-管理节点信息
     */
    @PreAuthorize("@ss.hasPermi('system:specialDiseaseNode:remove')")
    @Log(title = "专病路径-管理节点信息", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(specialDiseaseNodeService.deleteSpecialDiseaseNodeByIds(ids));
    }

    /**
     * 查询专病路径-管理节点信息列表
     */
    @GetMapping("/selectSpecialDisease")
    public AjaxResult selectSpecialDisease(Long specialDiseaseRouteId) {
        if (Objects.isNull(specialDiseaseRouteId)) {
            return AjaxResult.error("请选择查询的专病路径信息！");
        }
        return specialDiseaseNodeService.selectSpecialDisease(specialDiseaseRouteId);
    }

    /**
     * 修改节点信息状态
     */
    @PostMapping("/updateRouteCheckStatus")
    public AjaxResult updateRouteCheckStatus(@RequestBody SpecialDiseaseNode specialDiseaseNode) {
        if (Objects.isNull(specialDiseaseNode)) {
            return AjaxResult.error("请选择需要修改的节点信息！");
        }
        return specialDiseaseNodeService.updateRouteCheckStatus(specialDiseaseNode);
    }

	/**
	 * 根据节点id提取参数列表
	 */
	@ApiOperation("根据节点id提取参数列表")
	@GetMapping("/getParams")
	public R<List<List<PatientNodeParamsCurrent>>> getParams(Long id, Long patientId) {
		if (id == null) {
			throw new ServiceException("请选择节点!");
		}
		return R.ok(specialDiseaseNodeService.getParams(id, patientId));
	}
}
