package com.app.hxqh.assetdispo;

import psdi.mbo.MAXTableDomain;
import psdi.mbo.MboRemote;
import psdi.mbo.MboSetRemote;
import psdi.mbo.MboValue;
import psdi.util.MXException;
import java.util.Date;
import java.text.SimpleDateFormat;

import java.rmi.RemoteException;
import java.time.LocalDate;

/**
 * 币种-选择，带出汇率等
 * createby liuxq 2023-6-17
 */
public class FldCoin extends MAXTableDomain {

    public FldCoin(MboValue mbv) throws MXException,RemoteException {
        super(mbv);
        String thisAttr = getMboValue().getAttributeName();
        setRelationship("COINRATE", "1=1");//从货币表进行选择
        String[] FromStr = { "COINNUM","RATE" };//选择币种和月末汇率
        String[] ToStr = { thisAttr,"COINRATE" };
        setLookupKeyMapInOrder(ToStr, FromStr);
    }

    public void init() throws RemoteException, MXException {
        super.init();
    }
    public void action() throws RemoteException, MXException {
        super.action();
    }

    public MboSetRemote getList() throws RemoteException, MXException {
        MboRemote mbo = getMboValue().getMbo();
        //设置 where 后面的条件，直接写查询条件
        // 获取当前日期
//        Date currentDate = new Date();
//        // 创建SimpleDateFormat实例，指定日期格式
//        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM");
//        // 格式化日期为字符串
//        String formattedDate = sdf.format(currentDate);
//        // 从格式化后的字符串中提取年份和月份
//        String year = formattedDate.substring(0, 4);
//        String month = formattedDate.substring(5);
//        int monthInt = Integer.parseInt(month);
//        monthInt = monthInt - 1; //获取上个月
//        if(monthInt==1){
//            year = String.valueOf(Integer.parseInt(year) - 1) ;
//            monthInt = 12;
//        }
//        String sql = " 1=1 and NF='"+year+"' and YF='"+monthInt+"' and DHDMLX='TORMB'";
        String sql="COINRATEID in(SELECT MAX(COINRATEID) FROM COINRATE WHERE DHDMLX='TORMB' GROUP BY COINNUM ) ";
        setListCriteria(sql);
        return super.getList();
    }
}