package com.xinelu.manage.controller.signpatientrecord;

import com.xinelu.common.core.controller.BaseController;
import com.xinelu.common.core.domain.R;
import com.xinelu.common.core.page.TableDataInfo;
import com.xinelu.manage.dto.signpatientrecord.IntentionalSignDto;
import com.xinelu.manage.dto.signpatientrecord.PortaitCheckDto;
import com.xinelu.manage.dto.signpatientrecord.RouteCheckDto;
import com.xinelu.manage.dto.signpatientrecord.SignPatientAddDto;
import com.xinelu.manage.dto.signpatientrecord.SignPatientListDto;
import com.xinelu.manage.dto.signpatientrecord.SignPatientStatusDto;
import com.xinelu.manage.service.signpatientrecord.ISignPatientRecordService;
import com.xinelu.manage.vo.patientinfo.PatientPortaitVo;
import com.xinelu.manage.vo.signpatientrecord.IntentionalSignVo;
import com.xinelu.manage.vo.signpatientrecord.SignPatientInfoVo;
import com.xinelu.manage.vo.signpatientrecord.SignPatientListVo;
import com.xinelu.manage.vo.signpatientrecord.SignPatientRecordVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import java.util.List;
import javax.annotation.Resource;
import javax.validation.Valid;
import org.springframework.security.access.prepost.PreAuthorize;
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.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @description: 患者签约记录Controller
 * @author: haown
 * @create: 2024-02-28 16:03
 **/
@Api(tags = "患者签约记录控制器")
@RestController
@RequestMapping("/manage/signRecord")
public class SignPatientRecordController extends BaseController {

	@Resource
	private ISignPatientRecordService signPatientRecordService;

	/**
	 * 查询签约患者列表
	 */
	@ApiOperation("查询签约患者列表")
	@PreAuthorize("@ss.hasPermi('manage:signRecord:list')")
	@GetMapping("/list")
	public TableDataInfo list(SignPatientListDto signPatientRecord) {
		startPage();
		List<SignPatientListVo> list = signPatientRecordService.selectList(signPatientRecord);
		return getDataTable(list);
	}

	/**
	 * 意向签约
	 */
	@ApiOperation("意向签约")
	@PreAuthorize("@ss.hasPermi('manage:signRecord:add')")
	@PostMapping("/intentionalSign")
	public R<String> intentionalSign(@Valid @RequestBody IntentionalSignDto body) {
		int flag = signPatientRecordService.intentionalSign(body);
		return flag > 0 ? R.ok() : R.fail();
	}

	/**
	 * @description 查询意向签约
	 * @param id 签约记录表主键
	 * @return 意向签约详情
	 * @Author haown
	 * @Date 2024-08-08 11:00
	*/
	@ApiOperation("查询意向签约")
	@PreAuthorize("@ss.hasPermi('manage:signRecord:list')")
	@PostMapping("/getIntentionalSign/{id}")
	public R<IntentionalSignVo> getIntentionalSign(@PathVariable("id") Long id) {
		return R.ok(signPatientRecordService.getIntentionalSign(id));
	}

	/**
	 * @description 修改意向签约
	 * @param body 意向签约传输对象
	 * @return 结果
	 * @Author haown
	 * @Date 2024-08-07 14:35
	*/
	@ApiOperation("修改意向签约")
	@PreAuthorize("@ss.hasPermi('manage:signRecord:edit')")
	@PostMapping("/updateIntentionalSign")
	public R<String> updateIntentionalSign(@Valid @RequestBody IntentionalSignDto body) {
		int flag = signPatientRecordService.updateIntentionalSign(body);
		return flag > 0 ? R.ok() : R.fail();
	}

	/**
	 * @description 撤销意向签约
	 * @param patientId 患者主键
	 * @return 结果
	 * @Author haown
	 * @Date 2024-08-07 14:34
	*/
	@ApiOperation("撤销意向签约")
	@PreAuthorize("@ss.hasPermi('manage:signRecord:add')")
	@GetMapping("/cancelIntentionalSign/{patientId}")
	public R<String> cancelIntentionalSign(@PathVariable("patientId") Long patientId) {
		int flag = signPatientRecordService.cancelIntentionalSign(patientId);
		return flag > 0 ? R.ok() : R.fail();
	}

	/**
	 * 签约
	 */
	@ApiOperation("签约/续约")
	@PreAuthorize("@ss.hasPermi('manage:signRecord:add')")
	@PostMapping("/sign")
	public R<String> sign(@Valid @RequestBody SignPatientAddDto body) {
		int flag = signPatientRecordService.add(body);
		return flag > 0 ? R.ok() : R.fail();
	}

	/**
	 * 修改签约信息
	 */
	@ApiOperation("修改签约信息")
	@PreAuthorize("@ss.hasPermi('manage:signRecord:edit')")
	@PostMapping("/updateSign")
	public R<String> updateSign(@Valid @RequestBody SignPatientAddDto body) {
		int flag = signPatientRecordService.edit(body);
		return flag > 0 ? R.ok() : R.fail();
	}

	/**
	 * 根据患者主键查询签约记录
	 */
	@ApiOperation("根据患者主键查询签约记录")
	@PreAuthorize("@ss.hasPermi('manage:signRecord:list')")
	@GetMapping("/getByPatient/{patientId}")
	public R<List<SignPatientRecordVo>> getByPatient(@PathVariable("patientId") Long patientId) {
		List<SignPatientRecordVo> list = signPatientRecordService.getByPatient(patientId);
		return R.ok(list);
	}

	/**
	 * 根据签约记录表主键查询签约详情
	 */
	@ApiOperation("根据签约记录表主键查询签约详情")
	@PreAuthorize("@ss.hasPermi('manage:signRecord:list')")
	@GetMapping("/getByRecordId/{id}")
	public R<SignPatientInfoVo> getByRecordId(@PathVariable("id") Long id) {
		SignPatientInfoVo signInfo = signPatientRecordService.getByRecordId(id);
		return R.ok(signInfo);
	}

	/**
	 * 解约
	 */
	@ApiOperation("解约")
	@PreAuthorize("@ss.hasPermi('manage:signRecord:edit')")
	@PostMapping("/updateSignStatus")
	public R<String> updateSignStatus(@RequestBody SignPatientStatusDto updateSignStatus) {
		int flag = signPatientRecordService.updateSignStatus(updateSignStatus);
		return flag < 0 ? R.fail() : R.ok();
	}

	/**
	 * 路径审核->左侧画像信息列表
	 */
	@ApiOperation("路径审核->左侧画像信息列表")
	@GetMapping("/getPortaitInfo/{patientId}")
	public R<PatientPortaitVo> getPortaitInfo(@PathVariable("patientId") Long patientId) {
		return R.ok(signPatientRecordService.getPortaitInfo(patientId));
	}

	/**
	 * 画像审核
	 */
	@ApiOperation("画像审核")
	@PostMapping("/updatePortaitCheckStatus")
	public R<String> updatePortaitCheckStatus(@RequestBody PortaitCheckDto portaitCheckDto) {
		int flag = signPatientRecordService.updatePortaitCheckStatus(portaitCheckDto);
		return flag < 0 ? R.fail() : R.ok();
	}
	/**
	 * 路径审核
	 */
	@ApiOperation("路径审核")
	@PostMapping("/updateRouteCheckStatus")
	public R<String> updateRouteCheckStatus(@RequestBody RouteCheckDto routeCheckDto) {
		int flag = signPatientRecordService.updateRouteCheckStatus(routeCheckDto);
		return flag < 0 ? R.fail() : R.ok();
	}
}
