package com.controller;

import com.config.BaseController;
import com.config.ControllerInterface;
import com.service.RegionService;
import com.tools.JwtUtils;

import java.util.Map;

/**
 * 区域汇总统计
 */
@ControllerInterface(path="/region")
public class RegionController extends BaseController {

    RegionService service = RegionService.me;
    public void index() {
        render("/view/index/index.html");
    }

    /**
     * 汇总统计
     */
    public void summaryList(){
        String token = this.getPara("token");
        try {
            int operatorid = JwtUtils.validateJWTForUserId(token);
            if(operatorid == 0){
                fail(3,"token错误");
                return;
            }
            Map info = JwtUtils.validateJWTForMap(this.getPara("token"));
            if(info == null){
                fail_token();
                return;
            }
            int orgid = (int)info.get("orgid");
            String schoolids = this.getSessionAttr("schoolids");
            success(service.summaryList(schoolids,orgid));
        }catch(Exception e){
            e.printStackTrace();
            fail();
        }
    }
    /**
     * 今日简报
     */
    public void dayBriefingList(){
        String token = this.getPara("token");
        try{
            int operatorid = JwtUtils.validateJWTForUserId(token);
            if(operatorid == 0){
                fail(3,"token错误");
                return;
            }
            Map info = JwtUtils.validateJWTForMap(this.getPara("token"));
            if(info == null){
                fail_token();
                return;
            }
            int orgid = (int)info.get("orgid");
            String schoolids = this.getSessionAttr("schoolids");
            success(service.dayBriefingList(schoolids,orgid));
        }catch(Exception e){
            e.printStackTrace();
            fail();
        }
    }

    /**
     * 流通统计
     */
    public void circulationList(){
        String token = this.getPara("token");
        String ksrq = this.getPara("ksrq");
        String jsrq = this.getPara("jsrq");
        try{
            int operatorid = JwtUtils.validateJWTForUserId(token);
            if(operatorid == 0){
                fail(3,"token错误");
                return;
            }
            String schoolids = this.getSessionAttr("schoolids");
            success(service.circulationList(schoolids,ksrq,jsrq));
        }catch(Exception e){
            e.printStackTrace();
            fail();
        }
    }

}
