package com.xintong.visualinspection.controller.gettway;

import com.alibaba.dubbo.config.annotation.Reference;
import com.xintong.visualinspection.bean.FwqDeptStatistic;
import com.xintong.visualinspection.bean.FwqStatisticsBean;
import com.xintong.visualinspection.controller.BaseController;
import com.xintong.visualinspection.dao.cluster.DepartmentDao;
import com.xintong.visualinspection.pojo.fwq.FwqRankingData;
import com.xintong.visualinspection.pojo.fwq.FwqStatisiticPojo;
import com.xintong.visualinspection.pojo.fwq.ServiceAreaStatistic;
import com.xintong.visualinspection.service.CommonService;
import com.xintong.visualinspection.service.StatisticsService_F;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

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

/**
 * @author huangcheng
 * @since 2018/5/9
 */
@RestController
@RequestMapping("/f/statistics")
public class StatisticsController_F extends BaseController {

    @Reference(version = "1.0.0",
            application = "${dubbo.application.id}",
            registry = "${dubbo.registry.address}")
    private StatisticsService_F statisticsService_f;

    @Reference(version = "1.0.0",
            application = "${dubbo.application.id}",
            registry = "${dubbo.registry.address}")
    private CommonService commonService;

    @Autowired
    private DepartmentDao departmentDao;

    /**
     * 公司12个月考核得分总体变化趋势分析
     */
//    @RequestMapping(value = "/score/year/info")
//    public String selectYearScoreChange(@RequestBody FwqStatisticsBean fwqStatisticsBean){
//        List<FwqStatisticsBean> lists=  statisticsService_f.getYearScoreChange(fwqStatisticsBean);
//        return super.returnSuccessResult(lists);
//    }

    /**
     * 运营管理综合检查情况统计表
     */
    @RequestMapping(value = "/operation/manage/integration")
    public String getOperationInfo(@RequestBody FwqStatisticsBean obj) {
        List<FwqStatisticsBean> lists = statisticsService_f.getOperationInfo(obj);
        int totalCompanyNum = 0,
                totalCompanyScore = 0,
                totalThirdNum = 0,
                totalThirdScore = 0,
                totalOnsiteNum = 0,
                totalOnsiteScore = 0;

        for (FwqStatisticsBean bean : lists) {
            totalCompanyNum += bean.getCompany_check_num();
            totalCompanyScore += bean.getCompany_total_score();
            totalThirdNum += bean.getThird_check_num();
            totalThirdScore += bean.getThird_total_score();
            totalOnsiteNum += bean.getOnsite_check_num();
            totalOnsiteScore += bean.getOnsite_total_score();
        }
        Map<String, Object> resultMap = new HashMap<>();
        resultMap.put("list", lists);
        resultMap.put("totalCompanyNum", totalCompanyNum);
        resultMap.put("totalCompanyScore", totalCompanyScore);
        resultMap.put("totalThirdNum", totalThirdNum);
        resultMap.put("totalThirdScore", totalThirdScore);
        resultMap.put("totalOnsiteNum", totalOnsiteNum);
        resultMap.put("totalOnsiteScore", totalOnsiteScore);
        return super.returnSuccessResult(resultMap);
    }

    /**
     * 营运管理提升综合成绩汇总表
     *
     * @param obj
     * @return
     */
    @RequestMapping(value = "/dept")
    public String getDeptStatistic(@RequestBody FwqDeptStatistic obj) {
        Map<String, List<FwqDeptStatistic>> s = statisticsService_f.getDeptStatistic(obj);
        return super.returnSuccessResult(s);
    }

    /**
     * 考核问题分布报表
     *
     * @param obj
     * @return
     */
    @RequestMapping(value = "/score/item/info")
    public String getScoreItemInfo(@RequestBody FwqStatisticsBean obj) {
        List<FwqStatisticsBean> lists = statisticsService_f.getFeeStationCheckItemScore(obj);
        int totalcheckedCount = 0,
                totalAll = 0;
        Map<String, Integer> scoreTypeMap = new HashMap<>();
        for (FwqStatisticsBean bean : lists) {
            totalcheckedCount += bean.getChecked_num();
            totalAll += bean.getAll_check_score();
            List<String> names = bean.getChecked_socre_name();
            List<Integer> scores = bean.getChecked_score();
            for (int i = 0; i < names.size(); i++) {
                Integer score = scoreTypeMap.get(names.get(i));
                if (score == null) {
                    score = 0;
                }
                score += scores.get(i);
                if (names.get(i) != null) {
                    scoreTypeMap.put(names.get(i), score);
                }
            }
        }
        Map<String, Object> resultMap = new HashMap<>();
        resultMap.put("list", lists);
        resultMap.put("totalcheckedCount", totalcheckedCount);
        resultMap.put("totalAll", totalAll);
        resultMap.put("organList", departmentDao.getOrganToSaCount());
        resultMap.put("itemList", commonService.getCheckItemName(28L));
        resultMap.putAll(scoreTypeMap);
        return super.returnSuccessResult(resultMap);
    }

    /**
     * 服务区数据查询分析---->获取服务区排名详情
     *
     * @param obj
     * @return
     */
    @RequestMapping(value = "/employee/order/detail")
    public String getEmployeeOrderByDeptId(@RequestBody FwqStatisticsBean obj) {
        FwqRankingData fwqRankingData = statisticsService_f.getEmployeeRankingData(obj);
        return super.returnSuccessResult(fwqRankingData);
    }

    /**
     * 服务区数据查询分析---->获取收费站具体某个人的扣分详情
     */
    @RequestMapping(value = "/one/checkedItem/detail/info/{page}/{size}")
    public String getFsOnePersonCheckedItemDetailInfo(@RequestBody FwqStatisticsBean obj, @PathVariable Integer page, @PathVariable Integer size) {
        Object returnList = statisticsService_f.getOneCheckedDetailInfo(page, size, obj);
        return super.returnSuccessResult(returnList);
    }

    /**
     * 服务区数据查询分析---->获取服务区的12月情况
     */
    @RequestMapping(value = "/one/serviceArea/year/info")
    public String getSaOnePersonInfo(@RequestBody FwqStatisticsBean obj){
        List<FwqStatisticsBean> returnList=  statisticsService_f.getOneSACheckedInfo(obj);
        return super.returnSuccessResult(returnList);
    }

    /**
     * 服务区数据查询分析---->获取服务区各项扣分情况
     */
    @RequestMapping(value = "/one/serviceArea/checkedItem/info")
    public String getFsOneServiceAreaCheckedItemInfo(@RequestBody FwqStatisticsBean obj){
        List<FwqStatisticsBean> returnList=  statisticsService_f.getOneCheckedItemInfo(obj);
        return super.returnSuccessResult(returnList);
    }

    /**
     * 公司总览--->12个月考核得分总体
     */
    @RequestMapping(value = "/score/year/info")
    public String selectYearScoreChange(@RequestBody FwqStatisticsBean obj){
        List<FwqStatisticsBean> lists=  statisticsService_f.getYearScoreChange(obj);
        return super.returnSuccessResult(lists);
    }

    /**
     * 公司总览--->公司考核扣分情况占比
     * @param obj
     * @return
     */
    @RequestMapping(value = "/score/info")
    public String getScoreInfo(@RequestBody FwqStatisticsBean obj){
        List<FwqStatisticsBean> lists=  statisticsService_f.getFeeStationCheckedScore(obj);
        int totalcheckedCount=0,total0=0,total15=0,total50=0,totalOver50=0,totalAll = 0;
        for(FwqStatisticsBean bean:lists){
            totalcheckedCount+=bean.getChecked_num();
            total0+=(bean.getChecked_num()-bean.getScore_fifteen()-bean.getScore_fifty()-bean.getScore_over_fifty());
            total15+=bean.getScore_fifteen();
            total50+=bean.getScore_fifty();
            totalOver50+=bean.getScore_over_fifty();
            totalAll+=bean.getAll_check_score();
        }
        Map<String,Object> resultMap = new HashMap<>();
        resultMap.put("list", lists);
        resultMap.put("totalcheckedCount", totalcheckedCount);
        resultMap.put("total0", total0);
        resultMap.put("total15", total15);
        resultMap.put("total50", total50);
        resultMap.put("totalOver50", totalOver50);
        resultMap.put("totalAll", totalAll);
        resultMap.put("organList", departmentDao.getOrganToSaCount());
        return super.returnSuccessResult(resultMap);
    }

    /**
     * 公司总览--->道管中心得分排名
     */
    @RequestMapping(value = "/score/center/manage/info")
    public String selectCentermanageScoreChange(@RequestBody FwqStatisticsBean obj){
        List<FwqStatisticsBean> lists=  statisticsService_f.getCenterManageScoreInfo(obj);
        return super.returnSuccessResult(lists);
    }

    /**
     * 公司总览--->公司全体服务区排名
     */
    @RequestMapping(value = "/score/tollgate/info")
    public String selectTollgateScoreChange(@RequestBody FwqStatisticsBean obj){
        List<FwqStatisticsBean> lists=  statisticsService_f.getFeeStationScoreInfo(obj);
        return super.returnSuccessResult(lists);
    }

    /**
     * 公司总览--->温馨服务检查问题类别占比
     */
    @RequestMapping(value = "/lost/itemscore/rate")
    public String getCheckedItemInfoRate(@RequestBody FwqStatisticsBean obj){
        List<FwqStatisticsBean> returnList=  statisticsService_f.getCheckedItemScoreInfo(obj);
        return super.returnSuccessResult(returnList);
    }

    /**
     * 公司总览--->各个问题类别的扣分情况
     */
    @RequestMapping(value = "/lost/twice/itemscore/rate")
    public String getTwiceCheckedItemInfoRate(@RequestBody FwqStatisticsBean obj){
        Map<String,Object> resultMap = new HashMap<>();
        Map<String,List<FwqStatisticsBean>> returnMap=  statisticsService_f.get2CheckedItemScoreInfo(obj);
        resultMap.put("itemList", commonService.getCheckItemName(28L));
        resultMap.put("list", returnMap);
        return super.returnSuccessResult(resultMap);
    }

    /**
     * 服务区连续月统计
     */
    @RequestMapping(value = "/user/score")
    public String getFsOnePersonCheckedItemDetailInfo(@RequestBody ServiceAreaStatistic obj){
        List<FwqStatisiticPojo> returnList=  statisticsService_f.getFwqStatistic(obj);
        return super.returnSuccessResult((returnList));
    }
}
