package com.fs.app.controller;


import com.fs.app.annotation.Login;
import com.fs.app.utils.JwtUtils;
import com.fs.common.core.domain.R;
import com.fs.company.service.ICompanyService;
import com.fs.company.service.ICompanyUserService;
import com.fs.company.vo.DocCompanyUserVO;
import com.fs.doc.domain.*;
import com.fs.doc.param.*;
import com.fs.doc.service.*;
import com.fs.doc.vo.*;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;
import java.util.Date;
import java.util.List;


@Api("随访接口")
@RestController
@RequestMapping(value="/app/doc")
public class DocController extends  AppBaseController {
	@Autowired
	JwtUtils jwtUtils;
	@Autowired
	IDocService docService;
	@Autowired
	IDocOrderService docOrderService;
	@Autowired
	IDocRecordService docRecordService;
	@Autowired
	IDocRecordReplyService docRecordReplyService;
	@Autowired
	IDocOrderReplyService docOrderReplyService;
	@Autowired
	ICompanyUserService companyUserService;
	@Login
	@ApiOperation("获取健康档案")
	@GetMapping("/getDocList")
	public R getDocList(DocQueryParam param, HttpServletRequest request){
		List<DocListQueryVO> list=docService.selectDocListVOQuery(param);
		return R.ok().put("data",list);
	}

	@Login
	@ApiOperation("获取健康档案")
	@GetMapping("/getDocDetails")
	public R getDocDetails(@RequestParam("docId") Long docId, HttpServletRequest request){
		//获取服务销售列表
		Doc doc=docService.selectDocById(docId);
		List<DocCompanyUserVO> users=companyUserService.selectDocCompanyUserListByIds(doc.getCompanyUserIds());
		return R.ok().put("data",docService.selectDocById(docId)).put("users",users);
	}

	@Login
	@ApiOperation("获取健康记录列表")
	@GetMapping("/getDocRecordList")
	public R getDocRecordList(DocRecordQueryParam param, HttpServletRequest request){
		PageHelper.startPage(param.getPage(), param.getPageSize());
		List<DocRecordListQueryVO> list=docRecordService.selectDocRecordListVOQuery(param);
		PageInfo<DocRecordListQueryVO> listPageInfo=new PageInfo<>(list);
		return R.ok().put("data",listPageInfo);
	}

	@Login
	@ApiOperation("获取健康记录回复列表")
	@GetMapping("/getDocRecordReplyList")
	public R getDocRecordReplyList(DocRecordReplyQueryParam param, HttpServletRequest request){
		PageHelper.startPage(param.getPage(), param.getPageSize());
		List<DocRecordReplyListQueryVO> list=docRecordReplyService.selectDocRecordReplyListVOQuery(param);
		PageInfo<DocRecordReplyListQueryVO> listPageInfo=new PageInfo<>(list);
		return R.ok().put("data",listPageInfo);
	}


	@Login
	@ApiOperation("回复记录")
	@PostMapping("/replyRecord")
	public R replyRecord(@Valid @RequestBody DocRecordReply param, HttpServletRequest request){
		param.setCompanyId(getCompanyId());
		param.setCompanyUserId(Long.parseLong(getUserId()));
		param.setCreateTime(new Date());
		docRecordReplyService.insertDocRecordReply(param);
		return R.ok("操作成功");
	}

//	@Login
//	@ApiOperation("获取问医生列表")
//	@GetMapping("/getDocOrderList")
//	public R getDocOrderList(DocOrderQueryParam param, HttpServletRequest request){
//		PageHelper.startPage(param.getPage(), param.getPageSize());
//		List<DocOrderListQueryVO> list=docOrderService.selectDocOrderListVOQuery(param);
//		PageInfo<DocOrderListQueryVO> listPageInfo=new PageInfo<>(list);
//		return R.ok().put("data",listPageInfo);
//	}
//
//	@Login
//	@ApiOperation("获取问医生回复列表")
//	@GetMapping("/getDocOrderReplyList")
//	public R getDocOrderReplyList(DocOrderReplyQueryParam param, HttpServletRequest request){
//		PageHelper.startPage(param.getPage(), param.getPageSize());
//		List<DocOrderReplyListQueryVO> list=docOrderReplyService.selectDocOrderReplyListVOQuery(param);
//		PageInfo<DocOrderReplyListQueryVO> listPageInfo=new PageInfo<>(list);
//		return R.ok().put("data",listPageInfo);
//	}
//
//
//	@Login
//	@ApiOperation("回复问医生")
//	@PostMapping("/replyDocOrder")
//	public R replyDocOrder(@Valid @RequestBody DocOrderReply param, HttpServletRequest request){
//		param.setCompanyId(getCompanyId());
//		param.setCompanyUserId(Long.parseLong(getUserId()));
//		param.setCreateTime(new Date());
//		docOrderReplyService.insertDocOrderReply(param);
//		return R.ok("操作成功");
//	}
}
