package com.xinelu.manage.controller.signpatientmanageroute;

import com.aliyuncs.exceptions.ClientException;
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.enums.BusinessType;
import com.xinelu.common.utils.poi.ExcelUtil;
import com.xinelu.manage.domain.signpatientmanageroute.SignPatientManageRoute;
import com.xinelu.manage.domain.signpatientmanageroutenode.SignPatientManageRouteNode;
import com.xinelu.manage.dto.manualfollowup.ManualFollowUpDTO;
import com.xinelu.manage.dto.patientquestionsubmitresult.PatientQuestionSubmitResultDTO;
import com.xinelu.manage.dto.signpatientmanageroutenode.CreateAiobActualTimeTaskDto;
import com.xinelu.manage.service.signpatientmanageroute.ISignPatientManageRouteService;
import com.xinelu.manage.vo.manualfollowup.ManualFollowUpVO;
import com.xinelu.manage.vo.signpatientmanageroute.SignPatientManageRouteVO;
import com.xinelu.manage.vo.signpatientmanageroutenode.SignPatientManageNodeAuditVo;
import com.xinelu.manage.vo.signpatientrecord.SignPatientRecordSelectVo;
import com.xinelu.manage.vo.specialdiseaseroute.SpecialDiseaseRouteAuditVo;
import io.swagger.annotations.Api;
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 javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 签约患者管理任务路径控制器
 *
 * @author haown
 * @date 2024-03-18
 */
@Api(tags = "签约患者管理任务路径控制器")
@RestController
@RequestMapping("/manage/signroute")
public class SignPatientManageRouteController extends BaseController {
    @Resource
    private ISignPatientManageRouteService signPatientManageRouteService;

    /**
     * 查询签约患者管理任务路径列表
     */
    @GetMapping("/list")
    public TableDataInfo list(SignPatientManageRoute signPatientManageRoute) {
        startPage();
        List<SignPatientManageRoute> list = signPatientManageRouteService.selectSignPatientManageRouteList(signPatientManageRoute);
        return getDataTable(list);
    }

    /**
     * 导出签约患者管理任务路径列表
     */
    @PreAuthorize("@ss.hasPermi('manage:signroute:export')")
    @Log(title = "签约患者管理任务路径", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SignPatientManageRoute signPatientManageRoute) {
        List<SignPatientManageRoute> list = signPatientManageRouteService.selectSignPatientManageRouteList(signPatientManageRoute);
        ExcelUtil<SignPatientManageRoute> util = new ExcelUtil<SignPatientManageRoute>(SignPatientManageRoute.class);
        util.exportExcel(response, list, "签约患者管理任务路径数据");
    }

    /**
     * 获取签约患者管理任务路径详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(signPatientManageRouteService.selectSignPatientManageRouteById(id));
    }

    /**
     * 新增签约患者管理任务路径（手动创建任务）患者导入
     */
    @Log(title = "签约患者管理任务路径", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    public AjaxResult add(@RequestBody @Validated(Insert.class) SignPatientManageRouteVO signPatientManageRoute) {
        return signPatientManageRouteService.insertSignPatientManageRoute(signPatientManageRoute);
    }

    /**
     * 修改签约患者管理任务路径(未使用)
     */
    @Log(title = "签约患者管理任务路径", businessType = BusinessType.UPDATE)
    @PutMapping("/edit")
    public AjaxResult edit(@RequestBody SignPatientManageRouteVO signPatientManageRoute) {
        return signPatientManageRouteService.updateSignPatientManageRoute(signPatientManageRoute);
    }

    /**
     * 删除签约患者管理任务路径
     */
    @Log(title = "签约患者管理任务路径", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(signPatientManageRouteService.deleteSignPatientManageRouteByIds(ids));
    }

    /**
     * 查询人工随访代办列表
     */
    @GetMapping("/manualFollowUpList")
    public TableDataInfo getManualFollowUpList(ManualFollowUpDTO manualFollowUpDTO) {
        startPage();
        List<ManualFollowUpVO> list = signPatientManageRouteService.selectManualFollowUpList(manualFollowUpDTO);
        return getDataTable(list);
    }

	/**
	 * @description 随访待办列表-创建实时呼叫任务
	 * @Param createAiobActualTimeTaskDto 创建百度外呼实时任务传输对象
	 * @return 结果
	 * @Author haown
	 * @Date 2024-11-4 16:06
	*/
	@ApiOperation("随访待办列表-创建实时呼叫任务")
	@PostMapping("/createActualTimeTask")
	public R<String> createActualTimeTask(@RequestBody CreateAiobActualTimeTaskDto createAiobActualTimeTaskDto) {
		Long memberId = signPatientManageRouteService.createActualTimeTask(createAiobActualTimeTaskDto);
		return memberId != null && memberId > 0L ? R.ok() : R.fail();
	}

    /**
     * 查询人工随访患者基本信息
     */
    @GetMapping("/selectFollowPatientInfo/{id}")
    public AjaxResult selectFollowPatientInfo(@PathVariable Long id) {
        return signPatientManageRouteService.selectFollowPatientInfo(id);
    }

    /**
     * 人工随访代办处理
     */
    @PostMapping("/addPatientQuestionResult")
    public AjaxResult addPatientQuestionResult(@RequestBody PatientQuestionSubmitResultDTO dto) throws ClientException {
        return signPatientManageRouteService.addPatientQuestionResult(dto);
    }

    /**
     * 话术类型代办处理详情
     */
    @GetMapping("/selectPhonePush")
    public AjaxResult selectPhonePush(Long manageRouteNodeId){
        return signPatientManageRouteService.selectPhonePush(manageRouteNodeId);
    }

	/**
	 * 路径审核->路径信息,获取主路径及子路径信息及节点
	 * @param signRecordId 患者签约主键
	 * @return 主路径信息及节点、子路径信息及节点
	 */
	@ApiOperation("路径审核->路径信息")
	@GetMapping("/getRouteAuditInfo/{signRecordId}")
	public R<SpecialDiseaseRouteAuditVo> getRouteAuditInfo(@PathVariable("signRecordId")  Long signRecordId){
		return R.ok(signPatientManageRouteService.getRouteAuditInfo(signRecordId));
	}

	/**
	 * 路径审核->路径审核，获取节点详细信息
	 * @param signRecordId 患者签约主键
	 * @return 节点详细信息
	 */
	@ApiOperation("路径审核->路径任务")
	@GetMapping("/getRouteNodeInfo/{signRecordId}")
	public R<List<SignPatientManageNodeAuditVo>> getRouteNodeInfo(@PathVariable("signRecordId")  Long signRecordId) {
		return R.ok(signPatientManageRouteService.getRouteNodeInfo(signRecordId));
	}

	/**
	 * 患者详情--康复计划及记录，右上角签约记录下拉框
	 */
	@ApiOperation("患者详情--康复计划及记录，右上角签约记录下拉框")
	@GetMapping("/getRecordList/{patientId}")
	public R<List<SignPatientRecordSelectVo>> getRecordList(@PathVariable("patientId") Long patientId) {
		return R.ok(signPatientManageRouteService.getRecordList(patientId));
	}

    @ApiOperation("任务管理")
    @GetMapping("/taskManagement")
    public TableDataInfo taskManagement(ManualFollowUpDTO manualFollowUpDTO) {
        startPage();
        List<ManualFollowUpVO> list = signPatientManageRouteService.taskManagement(manualFollowUpDTO);
        return getDataTable(list);
    }

    @ApiOperation("批量删除未执行任务")
    @PostMapping("/batchDeleteTask")
    public AjaxResult batchDeleteTask(@RequestBody Long[] ids) {
        return signPatientManageRouteService.batchDeleteTask(ids);
    }

    @ApiOperation("外呼确认")
    @GetMapping("/outboundConfirmation")
    public AjaxResult outboundConfirmation() {
        return signPatientManageRouteService.outboundConfirmation();
    }

    @ApiOperation("直接外呼")
    @PostMapping("/directOutbound")
    public AjaxResult directOutbound(@RequestBody SignPatientManageRouteNode signPatientManageRouteNode) {
        return signPatientManageRouteService.directOutbound(signPatientManageRouteNode);
    }
}
