package com.fs.app.controller;


import com.fs.app.annotation.Login;
import com.fs.app.param.FollowFinishParam;
import com.fs.common.core.domain.R;
import com.fs.his.domain.FsDoctor;
import com.fs.his.domain.FsFollow;
import com.fs.his.domain.FsUser;
import com.fs.his.param.FsFollowListDParam;
import com.fs.his.param.FsFollowListUParam;
import com.fs.his.service.IFsDoctorService;
import com.fs.his.service.IFsFollowService;
import com.fs.his.service.IFsUserService;
import com.fs.his.vo.FsFollowListDVO;
import com.fs.his.vo.FsFollowListUVO;
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.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

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


@Api("随访接口")
@RestController
@RequestMapping(value="/app/follow")
public class FollowController extends AppBaseController {

    @Autowired
    private IFsFollowService followService;
    @Autowired
    private IFsDoctorService doctorService;

    @Autowired
    private IFsUserService userService;
    @ApiOperation("获取随访列表")
    @GetMapping("/getFollowList")
    public R getFollowList(FsFollowListDParam param)
    {
        param.setDoctorId(Long.parseLong(getDoctorId()));
        PageHelper.startPage(param.getPageNum(), param.getPageSize());
        List<FsFollowListDVO> list=followService.selectFsFollowListDVO(param);
        for (FsFollowListDVO fsFollowListDVO : list) {
            if(fsFollowListDVO.getPatientPhone()!=null&&!fsFollowListDVO.getPatientPhone().equals("")) {
                fsFollowListDVO.setPatientPhone(fsFollowListDVO.getPatientPhone().replaceAll("(\\d{3})\\d*(\\d{4})", "$1****$2"));
            }

        }
        PageInfo<FsFollowListDVO> listPageInfo=new PageInfo<>(list);
        return R.ok().put("data",listPageInfo);
    }

    @ApiOperation("获取随访详情")
    @GetMapping("/getFollowById")
    public R getFollowById(@RequestParam("followId")Long followId, HttpServletRequest request){
        FsFollow follow=followService.selectFsFollowByFollowId(followId);
        if(follow.getPatientPhone()!=null&&!follow.getPatientPhone().equals("")) {
            follow.setPatientPhone(follow.getPatientPhone().replaceAll("(\\d{3})\\d*(\\d{4})", "$1****$2"));
        }
        FsUser user=userService.selectFsUserByUserId(follow.getUserId());
        return R.ok().put("follow",follow).put("user",user);
    }



}
