package com.yinet.web.controller.bjtj;

import com.alibaba.fastjson.JSON;
import com.yinet.bjtj.domain.FormBjtj;
import com.yinet.bjtj.service.IFormBjtjService;
import com.yinet.common.annotation.Log;
import com.yinet.common.core.controller.BaseController;
import com.yinet.common.core.domain.AjaxResult;
import com.yinet.common.core.page.TableDataInfo;
import com.yinet.common.enums.BusinessType;
import com.yinet.common.utils.poi.ExcelUtil;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

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

/**
 * 办件统计Controller
 * 
 * @author yinet
 * @date 2020-04-02
 */
@Controller
@RequestMapping("/bjtj/bjtj")
public class FormBjtjController extends BaseController
{
    private String prefix = "bjtj/bjtj";

    @Autowired
    private IFormBjtjService formBjtjService;

    @RequiresPermissions("bjtj:bjtj:view")
    @GetMapping()
    public String bjtj()
    {
        return prefix + "/bjtj";
    }

    /**
     * 查询办件统计列表
     */
    @RequiresPermissions("bjtj:bjtj:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(FormBjtj formBjtj)
    {
        startPage();
        List<FormBjtj> list = formBjtjService.selectFormBjtjList(formBjtj);
        return getDataTable(list);
    }

    /**
     * 导出办件统计列表
     */
    @RequiresPermissions("bjtj:bjtj:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(FormBjtj formBjtj)
    {
        List<FormBjtj> list = formBjtjService.selectFormBjtjList(formBjtj);
        ExcelUtil<FormBjtj> util = new ExcelUtil<FormBjtj>(FormBjtj.class);
        return util.exportExcel(list, "bjtj");
    }

    /**
     * 新增办件统计
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存办件统计
     */
    @RequiresPermissions("bjtj:bjtj:add")
    @Log(title = "办件统计", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(FormBjtj formBjtj)
    {
        return toAjax(formBjtjService.insertFormBjtj(formBjtj));
    }

    /**
     * 修改办件统计
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        FormBjtj formBjtj = formBjtjService.selectFormBjtjById(id);
        mmap.put("formBjtj", formBjtj);
        return prefix + "/edit";
    }

    /**
     * 修改保存办件统计
     */
    @RequiresPermissions("bjtj:bjtj:edit")
    @Log(title = "办件统计", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(FormBjtj formBjtj)
    {
        return toAjax(formBjtjService.updateFormBjtj(formBjtj));
    }

    /**
     * 删除办件统计
     */
    @RequiresPermissions("bjtj:bjtj:remove")
    @Log(title = "办件统计", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(formBjtjService.deleteFormBjtjByIds(ids));
    }

    @PostMapping("/selMonth")
    @ResponseBody
    public Map<String,Object> selMonth()
    {
        Map<String,Object> selMap = new HashMap<String,Object>();
        selMap.put("selObject","month");
        return formBjtjService.selectFormBjtjVoCountByConditiond(selMap);
    }
    @PostMapping("/selWeek")
    @ResponseBody
    public Map<String,Object> selWeek()
    {
        Map<String,Object> selMap = new HashMap<String,Object>();
        selMap.put("selObject","week");
        return formBjtjService.selectFormBjtjVoCountByConditiond(selMap);
    }
    @PostMapping("/selMonthes")
    @ResponseBody
    public String selMonthes()
    {
        List<Map<String, Integer>> maps = formBjtjService.selectFormBjtjByMonthes();
        return  JSON.toJSONString(maps);

    }
}

