zm
2020-05-18 a18bfacbf56b401f6e0fdae8710fbca4df8cff77
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
package com.changhong.epc.count.service.system.func.set.util;
 
import com.changhong.epc.constter.system.businesscode.BudgetBusinessMeaningCode;
import com.changhong.epc.count.service.system.func.set.AbsFuncSupper;
import com.changhong.epc.count.service.tool.SystemFunTool;
import com.changhong.epc.rely.api.epc.admin.CurrencyApi;
import com.changhong.epc.rely.api.tool.CurrencyTool;
import com.googlecode.aviator.runtime.type.AviatorObject;
import com.googlecode.aviator.runtime.type.AviatorString;
import com.googlecode.aviator.runtime.type.AviatorType;
import com.iemsoft.framework.cloud.core.tools.ObjectUtil;
import com.iemsoft.framework.cloud.core.tools.SpringUtil;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
 
import java.util.Date;
import java.util.Map;
 
public class CurrencyAmount extends AbsFuncSupper implements BudgetBusinessMeaningCode {
 
    @Override
    public AviatorObject call(Map<String, Object> env, AviatorObject arg1, AviatorObject arg2) {
        String date = SystemFunTool.getStringVal(new AviatorString(BUDGET_START_DATE), env);
        // 获得汇率
        String exchangeRate = SpringUtil.getBean(CurrencyApi.class)
                .exchangeRate(
                        SystemFunTool.getStringVal(arg1, env)
                        , SystemFunTool.getStringVal(new AviatorString(APPLYCATION_CURRENCY), env)
                        , ObjectUtil.empty(date) ? new Date() : date
                );
        return new AviatorString(CurrencyTool.valueOf(exchangeRate, SystemFunTool.getStringVal(arg2, env)));
    }
 
    @Override
    public String getName() {
        return "amount";
    }
 
    @Data
    @AllArgsConstructor
    @NoArgsConstructor
    public class AviatorAmount extends AviatorObject{
 
        private String currency;
 
        private String amount;
 
        @Override
        public int compare(AviatorObject other, Map<String, Object> env) {
            if(other instanceof AviatorAmount){
                return other.hashCode() - this.hashCode();
            }
            return -1;
        }
 
        @Override
        public AviatorType getAviatorType() {
            return AviatorType.JavaType;
        }
 
        @Override
        public AviatorAmount getValue(Map<String, Object> env) {
            return this;
        }
    }
 
}