package com.xinelu.manage.controller.specialdiseaseroute;

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.custominterface.Insert;
import com.xinelu.common.custominterface.Update;
import com.xinelu.common.enums.BusinessType;
import com.xinelu.manage.domain.specialdiseaseroute.SpecialDiseaseRoute;
import com.xinelu.manage.dto.specialdiseaseroute.SpecialDiseaseRouteDTO;
import com.xinelu.manage.service.specialdiseaseroute.ISpecialDiseaseRouteService;
import com.xinelu.manage.vo.signpatientmanageroutenode.SignPatientManageNodeAuditVo;
import com.xinelu.manage.vo.specialdiseaseroute.SpecialDiseaseRouteAuditVo;
import com.xinelu.manage.vo.specialdiseaseroute.SpecialDiseaseRouteInfoVo;
import com.xinelu.manage.vo.specialdiseaseroute.SpecialDiseaseRouteVO;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * 专病路径信息Controller
 *
 * @author xinelu
 * @date 2024-03-13
 */
@RestController
@RequestMapping("/system/specialDiseaseRoute")
public class SpecialDiseaseRouteController extends BaseController {
    @Resource
    private ISpecialDiseaseRouteService specialDiseaseRouteService;

    /**
     * 查询专病路径信息列表
     */
    @GetMapping("/list")
    public TableDataInfo list(SpecialDiseaseRouteDTO specialDiseaseRoute) {
        startPage();
        List<SpecialDiseaseRouteVO> list = specialDiseaseRouteService.selectSpecialDiseaseRouteList(specialDiseaseRoute);
        return getDataTable(list);
    }

    /**
     * 获取专病路径信息详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(specialDiseaseRouteService.selectSpecialDiseaseRouteById(id));
    }

	/**
	 * 获取专病管理路径及子路径信息
	 */
	@GetMapping(value = "/getById/{id}")
	public R<SpecialDiseaseRouteInfoVo> getById(@PathVariable("id") Long id) {
		return R.ok(specialDiseaseRouteService.getById(id));
	}

    /**
     * 新增专病路径信息及服务包信息
     */
    @Log(title = "专病路径信息", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    public AjaxResult add(@RequestBody @Validated(Insert.class) SpecialDiseaseRouteVO specialDiseaseRoute) {
        return specialDiseaseRouteService.insertSpecialDiseaseRoute(specialDiseaseRoute);
    }

    /**
     * 修改专病路径信息及服务包信息
     */
    @Log(title = "专病路径信息", businessType = BusinessType.UPDATE)
    @PutMapping("/edit")
    public AjaxResult edit(@RequestBody @Validated(Update.class) SpecialDiseaseRouteVO specialDiseaseRoute) {
        return specialDiseaseRouteService.updateSpecialDiseaseRoute(specialDiseaseRoute);
    }

    /**
     * 删除专病路径信息
     */
    @PreAuthorize("@ss.hasPermi('system:specialDiseaseRoute:remove')")
    @Log(title = "专病路径信息", businessType = BusinessType.DELETE)
    @DeleteMapping("/{id}")
    public AjaxResult remove(@PathVariable Long id) {
        return specialDiseaseRouteService.deleteSpecialDiseaseRouteById(id);
    }

    /**
     * 科室路径数量
     */
    @GetMapping("/departmentRouteCount")
    public AjaxResult departmentRouteCount(SpecialDiseaseRouteDTO specialDiseaseRouteQueryDto) {
        return specialDiseaseRouteService.departmentRouteCount(specialDiseaseRouteQueryDto);
    }

    /**
     * 发布专病路径信息
     */
    @PostMapping("/editReleaseStatus")
    public AjaxResult editReleaseStatus(@RequestBody SpecialDiseaseRoute specialDiseaseRoute) {
        return AjaxResult.success(specialDiseaseRouteService.editReleaseStatus(specialDiseaseRoute));
    }

	/**
	 * 路径详情->路径信息,获取主路径及子路径信息及节点
	 * @param id 专病路径主键
	 * @return 主路径信息及节点、子路径信息及节点
	 * @author haown
	 * @date 2024-07-26 15:51
	 */
	@ApiOperation("路径详情->路径信息")
	@GetMapping("/getRouteInfo/{id}")
	public R<SpecialDiseaseRouteAuditVo> getRouteInfo(@PathVariable("id")  Long id){
		return R.ok(specialDiseaseRouteService.getRouteAuditInfo(id));
	}

	/**
	 * 路径详情->路径任务,获取主路径及子路径信息及节点
	 * @param id 专病路径主键
	 * @return 主路径信息及节点、子路径信息及节点
	 * @author haown
	 * @date 2024-07-26 16:00
	 */
	@ApiOperation("路径详情->路径任务")
	@GetMapping("/getRouteNodeInfo/{id}")
	public R<List<SignPatientManageNodeAuditVo>> getRouteNodeInfo(@PathVariable("id")  Long id){
		return R.ok(specialDiseaseRouteService.getRouteNodeInfo(id));
	}

    /**
     * 克隆
     */
    @PostMapping("/cloneRoute")
    public AjaxResult cloneRoute(Long id) {
        return specialDiseaseRouteService.cloneRoute(id);
    }
}
