package com.bofeng.wx.controller;

import com.bofeng.entity.QzTask;
import com.bofeng.entity.UserHelpAnaly;
import com.bofeng.service.QzTaskReplyService;
import com.bofeng.service.QzTaskService;
import com.bofeng.service.WuYeService;
import com.google.common.collect.Maps;
import com.yvan.Model;
import com.yvan.mvc.Pd;
import com.yvan.platform.YvanUtil;
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.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

import java.util.List;
import java.util.Map;

@RestController
public class WuYeController {

    @Autowired
    private QzTaskService qzTaskService;
    @Autowired
    private WuYeService wuYeService;

    @Autowired
    private QzTaskReplyService qzTaskReplyService;

    @GetMapping("/wuye/home.html")
    public ModelAndView wuye(ModelMap model, @RequestParam(value = "userId", required = false, defaultValue = "0") Long userId) {

        Map<String, Object> queryParam = Maps.newLinkedHashMap();
        queryParam.put("userId", "12345677");
        queryParam.put("statistics", "M");

        List<QzTask> taskList = qzTaskService.selectAll(userId);
//        List<sysUptownUnit> rbList = rbService.selectAll();
        model.put("taskList", YvanUtil.toJsonPretty(taskList));
//        model.put("rbList", YvanUtil.toJsonPretty(rbList));

        return new ModelAndView("/wuye/home.ftl", model);
    }

    @GetMapping("/wuye/qiuzhu.html")
    public ModelAndView wuyeUserHelp(ModelMap model) {

//        List<QzTask> taskList = qzTaskService.selectAll();
//
//        model.put("taskList", YvanUtil.toJsonPretty(taskList));

        return new ModelAndView("/wuye/qiuzhu.ftl", model);
    }

    @GetMapping("/wuye/fabu.html")
    public ModelAndView wuyePub(ModelMap model) {

//        List<QzTask> taskList = qzTaskService.selectAll();
//
//        model.put("taskList", YvanUtil.toJsonPretty(taskList));

        return new ModelAndView("/wuye/fabu.ftl", model);
    }

    //小区求助的查看
    @GetMapping("/wuye/userHelpAnaly")
    public Model<UserHelpAnaly> taskQuery(@Pd(name = "queryDate") String queryDate, @Pd(name = "userId") Long userId) {
        return Model.newSuccess(wuYeService.queryUserHelpAnaly(userId, queryDate));
    }

}
