package com.bofeng.wx.controller;


import com.bofeng.entity.*;
import com.bofeng.service.MsReportService;
import com.bofeng.service.MsSuspectedService;
import com.yvan.Model;
import com.yvan.mvc.Pd;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

/**
 * @Author: xielianghe
 * @Date: 2020/2/4 15:38
 */
@RestController
public class MsReportController {

    @Autowired
    private MsSuspectedService msSuspectedService;
    @Autowired
    private MsReportService msReportService;

    //添加家人
    @PostMapping("/home/addRibao")
    public Integer saveUser(HttpServletRequest request) {
        //初始化今日日报
        Long userCreate = Long.parseLong(request.getParameter("userCreate"));
        String userName = request.getParameter("userName");
        Integer grender = Integer.parseInt(request.getParameter("grender"));
        Integer age = Integer.parseInt(request.getParameter("age"));
        Integer familyStatus = Integer.parseInt(request.getParameter("familyStatus"));
        String statusDesp = request.getParameter("statusDesp");
        Integer medical = Integer.parseInt(request.getParameter("medical"));
        BigDecimal temperature = new BigDecimal(request.getParameter("temperature"));
        Integer cough = Integer.parseInt(request.getParameter("cough"));
        Integer muscle = Integer.parseInt(request.getParameter("muscle"));
        Integer dyspnea = Integer.parseInt(request.getParameter("dyspnea"));
        Integer chest = Integer.parseInt(request.getParameter("chest"));
        Integer fatigue = Integer.parseInt(request.getParameter("fatigue"));
        Integer diarrhea = Integer.parseInt(request.getParameter("diarrhea"));
        Integer diarrheaNum = Integer.parseInt(request.getParameter("diarrheaNum"));
        String others = request.getParameter("others");
        msSuspectedService.addSuspected(userName, grender, age, familyStatus,statusDesp,medical,temperature,cough,muscle,dyspnea,chest,fatigue,diarrhea,diarrheaNum, others, userCreate);
        return 1;
    }

    //删除家人病例
    @PostMapping("/home/deleteSuspected")
    public Integer deleteSuspected(HttpServletRequest request) {
        Long suspectedId = Long.parseLong(request.getParameter("suspectedId"));
        msSuspectedService.deleteSuspected(suspectedId);
        return 1;
    }

    //根据登录人获取家人
    @GetMapping("/home/home/queryRibao")
    public Model<List<MsSuspected>> queryRibao(@Pd(name = "userCreate") Long userCreate) {
        Date t = new Date();
        SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
        String reportDate = df.format(t);
        return Model.newSuccess(msReportService.getByReportReportDate(reportDate, userCreate));
    }

    //根据日报获取家人
    @GetMapping("/home/home/queryRibaoRefresh")
    public Model<List<MsSuspected>> queryRibaoRefresh(@Pd(name = "reportId") Long reportId) {
        return Model.newSuccess(msReportService.getByReportId(reportId));
    }

    //全家报平安
    @PostMapping("/home/addReport")
    public Integer addReport(HttpServletRequest request) {
        Long userCreate = Long.parseLong(request.getParameter("userCreate"));
        String safetyNum = request.getParameter("safetyNum");
        msReportService.addReport(safetyNum, userCreate);
        return 1;
    }

    //根据日期获取家人
    @GetMapping("/home/home/queryRibaoReportDate")
    public Model<List<MsSuspected>> queryRibaoReportDate(@Pd(name = "reportDate") String reportDate, @Pd(name = "userCreate") Long userCreate) {
        return Model.newSuccess(msReportService.getByReportReportDate(reportDate, userCreate));
    }
}
