package com.aucma.report.service.impl;

import com.aucma.common.utils.StringUtils;
import com.aucma.report.mapper.BoardReportMapper;
import com.aucma.report.service.IBoardReportService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.parameters.P;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;

/**
 * 看板报表Service业务层处理
 *
 * @Author YinQ
 * @create 2023-10-26 10:51
 */
@Service
public class BoardReportServiceImpl implements IBoardReportService {

    @Autowired
    private BoardReportMapper boardReportMapper;


    /**
     * 看板通用接口List
     *
     * @param paramMap
     * @return
     */
    @Override
    public List<LinkedHashMap<String, Object>> generalInterfaceList(HashMap paramMap) {
        return boardReportMapper.generalInterfaceList(paramMap);
    }

    /**
     * 首页接口
     *
     * @param paramMap
     * @return
     */
    @Override
    public HashMap<String, Object> homePageInterface(HashMap<String, String> paramMap) {

        HashMap<String, Object> result = new HashMap<>();
        List<HashMap<String, Object>> todayOrderList = boardReportMapper.homePageInterface(paramMap);
        List<HashMap<String, Object>> orderList = new ArrayList<>();
        for (HashMap<String, Object> map : todayOrderList) {
            if (Long.valueOf(String.valueOf(map.get("ORDER_AMOUNT"))).equals(Long.valueOf(String.valueOf(map.get("COMPLETE_AMOUNT"))))){
                continue;
            }
            orderList.add(map);
        }
        result.put("todayOrderList", orderList);
        if (todayOrderList.size() > 0) {
            Long planOrderSum = 0L;
            Long prodOrderSum = 0L;
            Long planProductSum = 0L;
            for (HashMap<String, Object> map : todayOrderList) {
                if (Integer.parseInt(String.valueOf(map.get("STATUS"))) != 0){
                    continue;
                }
                planOrderSum++;
                if (Integer.parseInt(String.valueOf(map.get("COMPLETE_AMOUNT"))) > 0) {
                    prodOrderSum++;
                }
                Long orderAmount = Long.parseLong(String.valueOf(map.get("ORDER_AMOUNT")));
                planProductSum += orderAmount;
            }
            result.put("planOrderSum", planOrderSum);
            result.put("prodOrderSum", prodOrderSum);
            result.put("planProductSum", planProductSum);
        }
        HashMap<String, Object> map = boardReportMapper.todayOfflineProduction(paramMap);
        result.put("compProductSum", map.get("OFFLINE_SUM"));

        List<HashMap<String, Object>> columnarList = boardReportMapper.homeColumnarInterface(paramMap);
        result.put("columnarList", columnarList);
        List<HashMap<String, Object>> lineList = boardReportMapper.homeLineInterface(paramMap);
        result.put("lineList", lineList);
        List<HashMap<String, Object>> pieList = boardReportMapper.homePieChartInterface(paramMap);
        result.put("pieList", pieList);

        return result;
    }


    /**
     * 箱体发泡生产数据监控平台-生产统计数据
     * @param paramMap
     * @return
     */
    @Override
    public List<HashMap<String, Object>> boxFoamingProductionInterface(HashMap<String, String> paramMap) {
        return boardReportMapper.boxFoamingProductionInterface(paramMap);
    }

    /**
     * 获取当前班组时间
     * @param paramMap
     * @return
     */
    @Override
    public List<HashMap<String, Object>> getCurrentTeamTimeList(HashMap<String, String> paramMap) {
        return boardReportMapper.getCurrentTeamTimeList(paramMap);
    }


}
