package com.yinet.web.controller.bjtj;

import java.text.SimpleDateFormat;
import java.util.*;

import com.yinet.bjtj.service.IFormBjtjService;
import com.yinet.common.utils.StringUtils;
import com.yinet.system.service.TouchScreenHaoService;
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.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.yinet.common.annotation.Log;
import com.yinet.common.enums.BusinessType;
import com.yinet.system.domain.Bjlb;
import com.yinet.system.service.IBjlbService;
import com.yinet.common.core.controller.BaseController;
import com.yinet.common.core.domain.AjaxResult;
import com.yinet.common.utils.poi.ExcelUtil;
import com.yinet.common.core.page.TableDataInfo;

/**
 * 【请填写功能名称】Controller
 *
 * @author yinet
 * @date 2020-04-22
 */
@Controller
@RequestMapping("/system/bjlb")
public class BjlbController extends BaseController
{
    private String prefix = "system/bjlb";

    @Autowired
    private IBjlbService bjlbService;
    @Autowired
    private IFormBjtjService formBjtjService;

    @Autowired
    private TouchScreenHaoService touchScreenHaoService;

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

    @GetMapping("/index")
    public String index(ModelMap map)
    {
        System.err.println("index");
        Map<String,Object> selMap = new HashMap<String,Object>();
        selMap.put("selObject","week");
        map.put("week",formBjtjService.selectFormBjtjVoCountByConditiond(selMap));

        selMap.put("selObject","month");
        map.put("month",formBjtjService.selectFormBjtjVoCountByConditiond(selMap));

        //------ 审批服务类别比例与大厅取号量--------
        Map<String, Integer> pieNum = touchScreenHaoService.selectPieNum();
        Map<String, Integer> callNum = touchScreenHaoService.selectNum();
        Integer haoCount = touchScreenHaoService.selectCount();
        map.addAttribute("pieNum", pieNum);
        if (StringUtils.isNotEmpty(callNum)) {
            Integer today = callNum.get("today");
            Integer blz = callNum.get("blz");
            Integer deng = callNum.get("deng");
            Integer month=callNum.get("month");
            Integer week=callNum.get("week");
            Integer yb = today - blz - deng;
            map.addAttribute("today", today);
            map.addAttribute("blz", blz);
            map.addAttribute("deng", deng);
            map.addAttribute("yb", yb < 0 ? 0 : yb);
            map.addAttribute("monthqh",month);
            map.addAttribute("weekqh",week);
        } else {
            map.addAttribute("today", 0);
            map.addAttribute("blz", 0);
            map.addAttribute("deng", 0);
            map.addAttribute("yb", 0);
            map.addAttribute("monthqh",0);
            map.addAttribute("weekqh",0);
        }
        map.addAttribute("zong", haoCount);
        //------ 审批服务类别比例与大厅取号量  end--------
        return "largescreen/index";
    }
    @GetMapping("/echars")
    public String echars(ModelMap mmap)
    {
        Map<String, Integer> pieNum = touchScreenHaoService.selectPieNum();
        mmap.addAttribute("pieNum", pieNum);
        return "largescreen/echars";
    }

    @GetMapping("/mone")
    public String mone()
    {
        return "largescreen/mone";
    }

    @GetMapping("/line")
    public String line()
    {
        return "largescreen/line";
    }

    @GetMapping("/canvasbg")
    public String canvasbg()
    {
        return "largescreen/canvasbg";
    }
    /**
     * 查询【请填写功能名称】列表
     */
    @RequiresPermissions("system:bjlb:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(Bjlb bjlb)
    {
        startPage();
        List<Bjlb> list = bjlbService.selectBjlbList(bjlb);
        return getDataTable(list);
    }

    /**
     * 导出【请填写功能名称】列表
     */
    @RequiresPermissions("system:bjlb:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(Bjlb bjlb)
    {
        List<Bjlb> list = bjlbService.selectBjlbList(bjlb);
        ExcelUtil<Bjlb> util = new ExcelUtil<Bjlb>(Bjlb.class);
        return util.exportExcel(list, "bjlb");
    }

    /**
     * 新增【请填写功能名称】
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存【请填写功能名称】
     */
    @RequiresPermissions("system:bjlb:add")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(Bjlb bjlb)
    {
        return toAjax(bjlbService.insertBjlb(bjlb));
    }

    /**
     * 修改【请填写功能名称】
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        Bjlb bjlb = bjlbService.selectBjlbById(id);
        mmap.put("bjlb", bjlb);
        return prefix + "/edit";
    }

    /**
     * 修改保存【请填写功能名称】
     */
    @RequiresPermissions("system:bjlb:edit")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(Bjlb bjlb)
    {
        return toAjax(bjlbService.updateBjlb(bjlb));
    }

    /**
     * 删除【请填写功能名称】
     */
    @RequiresPermissions("system:bjlb:remove")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(bjlbService.deleteBjlbByIds(ids));
    }

    @PostMapping("/selMonth")
    @ResponseBody
    public Map<String,Object> selMonth()
    {
        Map<String,Object> selMap = new HashMap<String,Object>();
        selMap.put("selObject","month");
        return bjlbService.selectBjlbVoCountByConditiond(selMap);
    }
    //上周
    @PostMapping("/selWeek")
    @ResponseBody
    public Map<String,Object> selWeek()
    {
        Map<String,Object> selMap = new HashMap<String,Object>();
        selMap.put("selObject","week");
        return bjlbService.selectBjlbVoCountByConditiond(selMap);
    }

    @PostMapping("/selList")
    @ResponseBody
    public Map<String,Object> selList()
    {
        Map<String,Object> selMap = new HashMap<String,Object>();
        selMap.put("selObject","list");
        return bjlbService.selectBjlbVoCountByConditiond(selMap);
    }
}
