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.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.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();
	}

	/**
	 * 签约
	 */
	@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: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();
	}
}
