package com.project.zcustom.service.logistics.impl;

import com.project.zcustom.domain.addional.LargeAssetDirs;
import com.project.zcustom.domain.addional.LargeLogistics;
import com.project.zcustom.mapper.logistics.PlatAssetMapper;
import com.project.zcustom.service.logistics.ILargePlatAssetService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

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

@Service
public class LargePlatAssetServiceImpl implements ILargePlatAssetService {

    @Autowired
    private PlatAssetMapper platAssetMapper;

    public LargeLogistics getBuildingAssetRate(String appOrg){
        LargeLogistics largeLogistics = new LargeLogistics();
        List<LargeAssetDirs> list1 = platAssetMapper.getBuildingAssetRate(appOrg);
        if (list1.size() > 0){
            largeLogistics.setBuildingAssetList(list1);
            largeLogistics.setBuildingAssetNum(platAssetMapper.getBuildingAssetNum(appOrg));
        }
        else {
            largeLogistics.setBuildingAssetNum(0L);
            List<LargeAssetDirs> list2 = new ArrayList<>();
            LargeAssetDirs largeAssetDirs1 = new LargeAssetDirs();
            LargeAssetDirs largeAssetDirs2 = new LargeAssetDirs();
            LargeAssetDirs largeAssetDirs3 = new LargeAssetDirs();
            LargeAssetDirs largeAssetDirs4 = new LargeAssetDirs();
            LargeAssetDirs largeAssetDirs5 = new LargeAssetDirs();
            LargeAssetDirs largeAssetDirs6 = new LargeAssetDirs();
            LargeAssetDirs largeAssetDirs7 = new LargeAssetDirs();
            largeAssetDirs1.setAssetNum(0L);
            largeAssetDirs2.setAssetNum(0L);
            largeAssetDirs3.setAssetNum(0L);
            largeAssetDirs4.setAssetNum(0L);
            largeAssetDirs5.setAssetNum(0L);
            largeAssetDirs6.setAssetNum(0L);
            largeAssetDirs7.setAssetNum(0L);
            largeAssetDirs1.setCategoryName("电梯");
            largeAssetDirs2.setCategoryName("电气");
            largeAssetDirs3.setCategoryName("空调通风");
            largeAssetDirs4.setCategoryName("供热采暖");
            largeAssetDirs5.setCategoryName("消防");
            largeAssetDirs6.setCategoryName("给排水");
            largeAssetDirs7.setCategoryName("楼宇智能化");
            list2.add(largeAssetDirs1);
            list2.add(largeAssetDirs2);
            list2.add(largeAssetDirs3);
            list2.add(largeAssetDirs4);
            list2.add(largeAssetDirs5);
            list2.add(largeAssetDirs6);
            list2.add(largeAssetDirs7);
            largeLogistics.setBuildingAssetList(list2);
        }
        return largeLogistics;
    }

    public LargeLogistics getServiceAssetRate(String appOrg){
        LargeLogistics largeLogistics = new LargeLogistics();
        List<LargeAssetDirs> list1 = platAssetMapper.getServiceAssetRate(appOrg);
        if (list1.size() > 0){
            largeLogistics.setServiceAssetList(list1);
            largeLogistics.setServiceAssetNum(platAssetMapper.getServiceAssetNum(appOrg));
        }
        else {
            largeLogistics.setServiceAssetNum(0L);
            List<LargeAssetDirs> list2 = new ArrayList<>();
            LargeAssetDirs largeAssetDirs1 = new LargeAssetDirs();
            LargeAssetDirs largeAssetDirs2 = new LargeAssetDirs();
            largeAssetDirs1.setAssetNum(0L);
            largeAssetDirs2.setAssetNum(0L);
            largeAssetDirs1.setCategoryName("物业设备");
            largeAssetDirs2.setCategoryName("食堂设备");
            list2.add(largeAssetDirs1);
            list2.add(largeAssetDirs2);
            largeLogistics.setServiceAssetList(list2);
        }

        return largeLogistics;
    }

    public LargeLogistics getOfficeAssetRate(String appOrg){
        LargeLogistics largeLogistics = new LargeLogistics();
        List<LargeAssetDirs> list1 = platAssetMapper.getOfficeAssetRate(appOrg);
        if (list1.size() > 0){
            largeLogistics.setOfficeAssetList(list1);
            largeLogistics.setOfficeAssetNum(platAssetMapper.getOfficeAssetNum(appOrg));
        }
        else {
            largeLogistics.setOfficeAssetNum(0L);
            List<LargeAssetDirs> list2 = new ArrayList<>();
            LargeAssetDirs largeAssetDirs1 = new LargeAssetDirs();
            LargeAssetDirs largeAssetDirs2 = new LargeAssetDirs();
            LargeAssetDirs largeAssetDirs3 = new LargeAssetDirs();
            largeAssetDirs1.setAssetNum(0L);
            largeAssetDirs2.setAssetNum(0L);
            largeAssetDirs3.setAssetNum(0L);
            largeAssetDirs1.setCategoryName("普通低值易耗品");
            largeAssetDirs2.setCategoryName("重点低值易耗品");
            largeAssetDirs3.setCategoryName("办公固定资产");
            list2.add(largeAssetDirs1);
            list2.add(largeAssetDirs2);
            list2.add(largeAssetDirs3);
            largeLogistics.setOfficeAssetList(list2);
        }
        return largeLogistics;
    }

    public LargeLogistics getStockAssetNum(String appOrg){
        LargeLogistics largeLogistics = platAssetMapper.getStockAssetNum(appOrg);
        if (largeLogistics == null){
            largeLogistics = new LargeLogistics();
            largeLogistics.setStockBuildingAssetNum(0L);
            largeLogistics.setStockServiceAssetNum(0L);
            largeLogistics.setStockOfficeAssetNum(0L);
        }
        return largeLogistics;
    }

    public LargeLogistics getNewAssetNum(String appOrg){
        LargeLogistics largeLogistics = platAssetMapper.getNewAssetNum(appOrg);
        if (largeLogistics == null){
            largeLogistics = new LargeLogistics();
            largeLogistics.setNewBuildingAssetNum(0L);
            largeLogistics.setNewServiceAssetNum(0L);
            largeLogistics.setNewOfficeAssetNum(0L);
        }
        return largeLogistics;
    }

    public LargeLogistics getScrapAssetNum(String appOrg){
        LargeLogistics largeLogistics = platAssetMapper.getScrapAssetNum(appOrg);
        if (largeLogistics == null){
            largeLogistics = new LargeLogistics();
            largeLogistics.setScrapBuildingAssetNum(0L);
            largeLogistics.setScrapServiceAssetNum(0L);
            largeLogistics.setScrapOfficeAssetNum(0L);
        }
        return largeLogistics;
    }

    public Map<String, Object> getCodedAndLabelRate(String appOrg){
        Map<String, Object> map = platAssetMapper.getCodedAndLabelRate(appOrg);
        if (map == null) {
            map = new HashMap<>();
            map.put("labelRate", 0);
            map.put("codedRate", 0);
        }
        return map;
    }

    public LargeLogistics getMainlyRate(String appOrg){
        LargeLogistics largeLogistics =  platAssetMapper.getMainlyRate(appOrg);
        if (largeLogistics == null) {
            largeLogistics = new LargeLogistics();
            largeLogistics.setBuildingAssetNum(0L);
            largeLogistics.setServiceAssetNum(0L);
            largeLogistics.setOfficeAssetNum(0L);
        }
        return largeLogistics;
    }

    public Map<String, Object> getSceneRate(int flag){
        List<LargeLogistics> list;
        List<String> list1 = new ArrayList<>();
        List<BigDecimal> list2 = new ArrayList<>();
        if (flag == 0){
            list = platAssetMapper.getSceneRateX();
            for (LargeLogistics it : list){
                it.setAppName(it.getAppName().substring(2, 4));
            }
        }
        else {
            list = platAssetMapper.getSceneRateY();
        }
        for (LargeLogistics it : list){
            list1.add(it.getAppName());
            list2.add(it.getSceneRate());
        }
        Map<String, Object> map = new HashMap<>();
        map.put("xList", list1);
        map.put("yList", list2);
        return map;
    }

    public LargeLogistics getOperation(String appOrg){
        LargeLogistics largeLogistics =  platAssetMapper.getOperation(appOrg);
        if (largeLogistics == null){
            largeLogistics = new LargeLogistics();
            largeLogistics.setImportantDeviceTypeInspectionExecuteRate(new BigDecimal(0));
            largeLogistics.setInspectionAnomalyRecordNum(0L);
            largeLogistics.setRepairRecordNum(0L);
            largeLogistics.setMaintenanceRecordNum(0L);
        }
        return largeLogistics;
    }

    public Map<String, Object> getInspectionSchemeNumX(){
        List<LargeLogistics> list = platAssetMapper.getInspectionSchemeNumX();
        List<String> list1 = new ArrayList<>();
        List<Long> list2 = new ArrayList<>();
        for (LargeLogistics it : list){
            list1.add(it.getAppName().substring(2, 4));
            list2.add(it.getInspectionSchemeNum());
        }
        Map<String, Object> map = new HashMap<>();
        map.put("xList", list1);
        map.put("yList", list2);
        return map;
    }

    public Map<String, Object> getInspectionSchemeNumY(){
        List<LargeLogistics> list = platAssetMapper.getInspectionSchemeNumY();
        List<String> list1 = new ArrayList<>();
        List<Long> list2 = new ArrayList<>();
        for (LargeLogistics it : list){
            list1.add(it.getAppName());
            list2.add(it.getInspectionSchemeNum());
        }
        Map<String, Object> map = new HashMap<>();
        map.put("xList", list1);
        map.put("yList", list2);
        return map;
    }
}
