package com.mvc.service.beihai;


import com.mvc.model.beihai.DdEqClassify;
import com.mvc.netty.dealconstant.ResourcePath;
import com.mvc.netty.dealconstant.ResourceTag;
import com.mvc.netty.dealconstant.ResultTag;
import com.mvc.netty.dealconstant.ResultType;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.env.Environment;
import org.springframework.stereotype.Service;

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

/**
 * 设备分类服务
 */
@Service
public class EqClassifyService {

    @Autowired
    private Environment env;

    /**
     * 根据companyId，检索分类信息
     */
    public Map<String, Object> findByCompany(DdEqClassify ddEqClassify) {
        String baseImageUrl = env.getProperty(ResourceTag.ResourceUrlTag.getTag()) + ResourcePath.Image.getPath() + ResourcePath.Classify.getPath();
        Map<String, Object> retMap = new HashMap<>();
        if (ddEqClassify.getCompanyId() == null) {
            retMap.put(ResultTag.ERROR.getTag(), ResultType.FAILURE.getResult());
            retMap.put(ResultTag.MESSAGE.getTag(), "未选择组织机构");
            return retMap;
        }
        List<DdEqClassify> classifyList =new ArrayList<>();
        DdEqClassify ddEqClassify1 = new DdEqClassify(1,"水表","watermeter.png",1,null,0,null);
        DdEqClassify ddEqClassify2 = new DdEqClassify(2,"压力表","ylb.png",1,null,0,null);
        classifyList.add(ddEqClassify1);
        classifyList.add(ddEqClassify2);
        for (DdEqClassify classify : classifyList) {
            if (classify.getIconUrl() != null) {
                classify.setIconUrl(baseImageUrl + classify.getIconUrl());
            }
        }
        retMap.put(ResultTag.ERROR.getTag(), ResultType.SUCCESS.getResult());
        retMap.put(ResultTag.DATA.getTag(), classifyList);
        return retMap;
    }


}
