package com.steerinfo.ems.trmunit.service.impl;

import com.steerinfo.ems.trmunit.controller.TRmUnitController;
import com.steerinfo.ems.trmunit.mapper.TRmUnitMapper;
import com.steerinfo.ems.trmunit.model.TRmUnit;
import com.steerinfo.ems.trmunit.service.ITRmUnitService;
import com.steerinfo.framework.mapper.IBaseMapper;
import com.steerinfo.framework.service.impl.BaseServiceImpl;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
import java.util.Set;

/**
 * TRmUnit服务实现：
 * @author 王金涛
 * @version 1.0-SNAPSHORT 2019-10-11
 * 类描述
 * 修订历史：
 * 日期：2019-10-11
 * 作者：王金涛
 * 参考：
 * 描述：TRmUnit服务实现
 * @see null
 * @Copyright 湖南视拓信息技术股份有限公司. All rights reserved.
 */
@Service(value = "tRmUnitService")
public class TRmUnitServiceImpl extends BaseServiceImpl<TRmUnit, String> implements ITRmUnitService {

    private static final Logger LOGGER = LoggerFactory.getLogger(TRmUnitServiceImpl.class);

    @Autowired
    private TRmUnitMapper tRmUnitMapper;

    @Override
    protected IBaseMapper<TRmUnit, String> getMapper() {
        return tRmUnitMapper;
    }

    public List<TRmUnit> getIdAndName(Map<String, Object> parameters) {
        return tRmUnitMapper.getIdAndName(parameters);
    }

    public String getMaxId(){
        return tRmUnitMapper.getMaxId();
    }

    /**
     * 获取单位换算的倍率
     * @param id
     * @param changeid
     * @return
     */
    public Double getchangerate(String id,String changeid){
        TRmUnit oldunit = tRmUnitMapper.selectByPrimaryKey(id);
        Double exp = Double.parseDouble(oldunit.getStdexp());
        TRmUnit changeunit = tRmUnitMapper.selectByPrimaryKey(changeid);
        Double changeexp = Double.parseDouble(changeunit.getStdexp());
        if (oldunit.getStdid() == null || "".equals(oldunit.getStdid()) || changeunit.getStdid() == null || "".equals(changeunit.getStdid()) || !oldunit.getStdid().equals(changeunit.getStdid())){
            LOGGER.error("单位转换异常,原单位id：" + id + "即将转换的id：" + changeid);
            return  0.0;
        }
        return changeexp/exp;
    }

    public static void main(String[] args) {
        //System.out.println(TRmUnitServiceImpl.getchangerate());
    }
}
