package cn.com.victorysoft.business.cyyzs.service;

import cn.com.victorysoft.business.cyyzs.dao.FailureReasonDao;
import cn.com.victorysoft.business.cyyzs.entity.FailureReason;
import cn.com.victorysoft.business.cyyzs.entity.FailureReasonDetails;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

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

/**
 * @Author TY
 * @Date: 2022/10/11 15:20
 */
@Slf4j
@Service
public class FailureReasonService {

    @Autowired
    private FailureReasonDao failureReasonDao;

    public List<FailureReason> selectList(String yclx, String dwdm, String dydm, String gylx, String type) {

        List<FailureReason> failureReasonDetails = new ArrayList<>();
        if ("gylx".equals(type)) {
            failureReasonDetails = failureReasonDao.selectListGroupGylx(yclx, dwdm, dydm, gylx);
        }
        if ("yclx".equals(type)) {
            failureReasonDetails = failureReasonDao.selectListGroupYclx(yclx, dwdm, dydm, gylx);
        }

        return failureReasonDetails;
    }

    public List<FailureReasonDetails> selectDetails(String yclx, String dwdm, String dydm, String jh, String gylx) {
        return failureReasonDao.selectDetails(yclx, dwdm, dydm, jh, gylx);
    }


    public Map<String, Object> getBarData(String yclx, String dwdm, String dydm, String gylx) {
        Map<String, Object> map = new HashMap<>();

        List<FailureReason> barDataList = failureReasonDao.getBarData(yclx, dwdm, dydm, gylx);

        List<String> name = new ArrayList<>();
        List<Object> data = new ArrayList<>();

        for (FailureReason barData : barDataList) {
            data.add(barData.getFsyzCk());
            name.add(barData.getGylxName());
        }

        map.put("name", name);
        map.put("data", data);

        return map;
    }

    public List<Map<String, Object>> getPieData(String yclx, String dwdm, String dydm, String gylx) {
        List<Map<String, Object>> list = new ArrayList<>();
        Map<String, Object> pieData = failureReasonDao.getPieData(yclx, dwdm, dydm, gylx);

        for (String key : pieData.keySet()) {
            Map<String, Object> map = new HashMap<>();
            map.put("name", key);
            map.put("value",  pieData.get(key));
            list.add(map);
        }
        return list;
    }
}
