package com.bofeng.wx.controller;

import com.baomidou.mybatisplus.toolkit.IdWorker;
import com.bofeng.Consts;
import com.bofeng.JwtHelper;
import com.bofeng.dao.UserOpenMapper;
import com.bofeng.entity.*;
import com.bofeng.service.*;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.google.common.collect.Maps;
import com.yvan.Model;
import com.yvan.ModelOps;
import com.yvan.mvc.JsonBody;
import com.yvan.mvc.Pd;
import com.yvan.platform.JsonWapper;
import com.yvan.platform.YvanUtil;
import lombok.val;
import lombok.var;
import me.chanjar.weixin.mp.bean.result.WxMpUser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

import javax.annotation.PreDestroy;
import java.util.List;
import java.util.Map;

@RestController
public class HomeController {

    @Autowired
    private HomeService homeService;

    @Autowired
    private QzTaskService qzTaskService;

    @Autowired
    private QzTaskReplyService qzTaskReplyService;

    @Autowired
    private MsReportService msReportService;


    @GetMapping("/home/home.html")
    public ModelAndView home(ModelMap model) throws JsonProcessingException {
        model.put("user", new JsonWapper("{\"www\": \"er\"}"));
        //初始化今日日报
        UserOpen userOpen = homeService.getUserOpen();
        Long userId = userOpen.getUserId();
       // Long userId = 1224706869998772226L;
        MsReport msReport = msReportService.getReportByDateNow(userId);
        model.put("msReport", new JsonWapper(msReport));
        return new ModelAndView("/home/home.ftl", model);
    }


    //家庭求助
    @GetMapping("/home/home/addFimaly")
    public ModelOps family(@Pd(name = "taskTitle") String taskTitle,
                           @Pd(name = "taskTarget") String taskTarget,
                           @Pd(name = "remark") String remark,
                           @Pd(name = "userId", required = false) Long userId) {
        return ModelOps.newSuccess(qzTaskService.addHelp(taskTitle, taskTarget, remark, userId));
    }

    //我的在求助的展示
    @GetMapping("/home/home/queryQzTask")
    public Model<List<QzTask>> queryQzTask(@Pd(name = "taskStatus", required = false) Integer taskStatus,
                                           @Pd(name = "taskTitle", required = false) String taskTitle,
                                           @Pd(name = "userId", required = false) Long userId) {
        return Model.newSuccess(qzTaskService.queryQzTask(taskStatus, taskTitle, userId));
    }


    //页面存储taskId
    @GetMapping("/home/qiuzhu/reply.json")
    public ModelOps taskQueryTaskId(@RequestParam(value = "taskId") Long taskId) {
        int i = qzTaskService.taskQueryTaskId(taskId);
        return ModelOps.newSuccess(i);
    }

    //小区求助的查看
    @GetMapping("/home/home/taskQuery")
    public Model<List<QzTaskReply>> taskQuery(@Pd(name = "taskId") Long taskId) {
        return Model.newSuccess(qzTaskReplyService.taskQuery(taskId));
    }

    @GetMapping("/home/home_new.html")
    public ModelAndView hmoe_new(ModelMap model) {
        model.put("user", new JsonWapper("{\"www\": \"er\"}"));
        return new ModelAndView("/home/home_new.ftl", model);
    }
}
