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.ICompanyUserService;
import com.fs.company.vo.DocCompanyUserVO;
import com.fs.doc.domain.Doc;
import com.fs.doc.domain.DocOrder;
import com.fs.doc.domain.DocRecord;
import com.fs.doc.domain.DocRecordReply;
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
	private IDocService docService;
	@Autowired
	private IDocRecordService docRecordService;
	@Autowired
	private IDocRecordReplyService docRecordReplyService;
	@Autowired
	private ICompanyUserService companyUserService;
	@Login
	@ApiOperation("获取健康档案")
	@GetMapping("/getMyDocList")
	public R getMyDocList(DocQueryParam param){
		param.setUserId(Long.parseLong(getUserId()));
		List<DocListQueryVO> list=docService.selectDocListVOQuery(param);
		return R.ok().put("data",list);
	}

	@Login
	@ApiOperation("获取健康档案")
	@GetMapping("/getDocDetails")
	public R getDocDetails(@RequestParam("docId") Long docId){
		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("添加健康档案")
	@PostMapping("/addDoc")
	public R addDoc(@Valid @RequestBody Doc param){
		param.setUserId(Long.parseLong(getUserId()));
		param.setCreateTime(new Date());
		docService.insertDoc(param);
		return R.ok("操作成功");
	}

	@Login
	@ApiOperation("编辑健康档案")
	@PostMapping("/editDoc")
	public R editDoc(@Valid @RequestBody Doc param){
		param.setUserId(Long.parseLong(getUserId()));
		param.setUpdateTime(new Date());
		docService.updateDoc(param);
		return R.ok("操作成功");
	}

	@Login
	@ApiOperation("删除健康档案")
	@PostMapping("/delDoc")
	public R delDoc(@Valid @RequestBody Doc param){
		docService.deleteDocById(param.getDocId());
		return R.ok("操作成功");
	}
	@Login
	@ApiOperation("获取健康记录列表")
	@GetMapping("/getMyDocRecordList")
	public R getMyDocRecordList(DocRecordQueryParam param){
		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){
		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("/addDocRecord")
	public R addDocRecord(@Valid @RequestBody DocRecord param){
		param.setUserId(Long.parseLong(getUserId()));
		param.setCreateTime(new Date());
		docRecordService.insertDocRecord(param);
		return R.ok("操作成功");
	}

}
