Просмотр исходного кода

风险管理3月10日提交代码-liu.bolan-期货交易请求

Liu.bolan 4 лет назад
Родитель
Сommit
05189df239
20 измененных файлов с 964 добавлено и 118 удалено
  1. 6 5
      RMA/app/src/main/java/cn/muchinfo/rma/business/future/FutureManager.kt
  2. 14 0
      RMA/app/src/main/java/cn/muchinfo/rma/global/BaseGlobalData.java
  3. 23 0
      RMA/app/src/main/java/cn/muchinfo/rma/global/StringUtils.kt
  4. 7 2
      RMA/app/src/main/java/cn/muchinfo/rma/global/data/AccountData.kt
  5. 87 0
      RMA/app/src/main/java/cn/muchinfo/rma/global/data/AccountShowData.kt
  6. 55 0
      RMA/app/src/main/java/cn/muchinfo/rma/global/data/CalculateData.java
  7. 1 0
      RMA/app/src/main/java/cn/muchinfo/rma/global/data/FutureDetailsData.kt
  8. 224 0
      RMA/app/src/main/java/cn/muchinfo/rma/global/data/OpeTaAccountInfoData.java
  9. 29 0
      RMA/app/src/main/java/cn/muchinfo/rma/global/data/futureOrders/DealOrderData.kt
  10. 15 1
      RMA/app/src/main/java/cn/muchinfo/rma/view/base/future/FutureFragment.kt
  11. 4 4
      RMA/app/src/main/java/cn/muchinfo/rma/view/base/future/costs/CostFragment.kt
  12. 248 10
      RMA/app/src/main/java/cn/muchinfo/rma/view/base/future/costs/CostInfoFragment.kt
  13. 15 12
      RMA/app/src/main/java/cn/muchinfo/rma/view/base/future/deals/DealFragment.kt
  14. 47 12
      RMA/app/src/main/java/cn/muchinfo/rma/view/base/future/deals/DealViewModel.kt
  15. 1 2
      RMA/app/src/main/java/cn/muchinfo/rma/view/base/future/entrusts/EntrustChildViewModel.kt
  16. 15 3
      RMA/app/src/main/java/cn/muchinfo/rma/view/base/future/holds/HoldFragment.kt
  17. 125 60
      RMA/app/src/main/java/cn/muchinfo/rma/view/base/future/holds/HoldViewModel.kt
  18. 3 3
      RMA/app/src/main/java/cn/muchinfo/rma/view/base/future/trade/GoodsTradeActivity.kt
  19. 13 4
      RMA/app/src/main/java/cn/muchinfo/rma/view/base/future/trade/GoodsTradeViewModel.kt
  20. 32 0
      RMA/app/src/main/res/layout/future_list.xml

+ 6 - 5
RMA/app/src/main/java/cn/muchinfo/rma/business/future/FutureManager.kt

@@ -8,6 +8,7 @@ import cn.muchinfo.rma.global.data.FutureDetailsData
 import cn.muchinfo.rma.global.data.GoodsInfoAndQuotes
 import cn.muchinfo.rma.global.data.QuoteDayData
 import cn.muchinfo.rma.global.data.account.loginQeruy.GoodsInfo
+import cn.muchinfo.rma.global.data.futureOrders.DealOrderData
 import cn.muchinfo.rma.global.data.futureOrders.FutureEntrustData
 import cn.muchinfo.rma.global.data.futureOrders.FutureHoldData
 import cn.muchinfo.rma.global.database.AppDatabase
@@ -187,7 +188,7 @@ class FutureManager {
     fun queryErmcpEntrustDetails(responseBack: (isSuccess: Boolean, respData: List<FutureEntrustData>?, error: Error?) -> Unit
     ){
         val params = mutableMapOf<String, String>()
-        params["accountID"] = SPUtils.getInstance().getLong(Constant.SELECT_ACCOUNT_ID).toString()
+        params["accountID"] = GlobalDataCollection.instance?.accountId.toString()
         MyOkHttpUtils().query(
             URL = SPUtils.getInstance().getString(Constant.goCommonSearchUrl) + "/Ermcp/QueryErmcpOrderDetails",
             params = params,
@@ -209,20 +210,20 @@ class FutureManager {
 
     /**
      *
-     * 获取企业风管期货历史成交单信息
+     * 获取企业风管期货成交单信息
      * @param params Map<String, String> accountID/资金账户ID goodsID/商品ID buyOrSell/买卖方向,0:买 1:卖
      * @param responseBack Function3<[@kotlin.ParameterName] Boolean, [@kotlin.ParameterName] List<FutureDetailsData>?, [@kotlin.ParameterName] Error?, Unit>
      */
     fun queryErmcpTradeDetails(
         params: Map<String, String>,
-        responseBack: (isSuccess: Boolean, respData: List<FutureDetailsData>?, error: Error?) -> Unit
+        responseBack: (isSuccess: Boolean, respData: List<DealOrderData>?, error: Error?) -> Unit
     ){
         MyOkHttpUtils().query(
             URL = SPUtils.getInstance().getString(Constant.goCommonSearchUrl) + "/Ermcp/QueryErmcpTradeDetails",
             params = params,
             type = "1",
-            callback = object : ResponseCallback<BaseResult<List<FutureDetailsData>>>(){
-                override fun onResponse(response: BaseResult<List<FutureDetailsData>>?, id: Int) {
+            callback = object : ResponseCallback<BaseResult<List<DealOrderData>>>(){
+                override fun onResponse(response: BaseResult<List<DealOrderData>>?, id: Int) {
                     responseBack(true, response?.data, null)
                 }
 

+ 14 - 0
RMA/app/src/main/java/cn/muchinfo/rma/global/BaseGlobalData.java

@@ -69,6 +69,20 @@ public class BaseGlobalData {
     private List<GoodsInfo> goodsInfoList;
 
     /**
+     * 暂存的用于交易页面快捷反手的item数据
+     * @return
+     */
+    private FutureHoldData itemData;
+
+    public FutureHoldData getItemData() {
+        return itemData;
+    }
+
+    public void setItemData(FutureHoldData itemData) {
+        this.itemData = itemData;
+    }
+
+    /**
      * 包含商品信息和goodscode和盘面信息的实体类
      */
     private ArrayList<GoodsInfoAndQuotes> goodsInfoAndQuotesList;

+ 23 - 0
RMA/app/src/main/java/cn/muchinfo/rma/global/StringUtils.kt

@@ -1,7 +1,10 @@
 package cn.muchinfo.rma.global
 
+import cn.muchinfo.rma.global.data.futureOrders.FutureEntrustData
 import cn.muchinfo.rma.view.autoWidget.utils.NumberUtils
 import com.blankj.utilcode.util.TimeUtils
+import java.text.SimpleDateFormat
+import java.util.*
 
 /**
  * 页面显示的时间
@@ -46,3 +49,23 @@ fun String.toPercentage() : String{
     return percentage
 }
 
+/**
+ * 成交单类型
+ */
+fun String.channelbuildtype() : String{
+    if (this.isNullOrEmpty()){
+        return "--"
+    }
+    return  if (this == "1"){"建仓"} else{"平仓"}
+}
+
+fun String.toShowTime() : String{
+    if (this.isNullOrEmpty()){
+        return "--"
+    }
+    val sdf = SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss+08:00", Locale.CHINA)
+    val sdf1 = SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.CHINA)
+    return sdf1.format(sdf.parse(this))
+}
+
+

+ 7 - 2
RMA/app/src/main/java/cn/muchinfo/rma/global/data/AccountData.kt

@@ -55,7 +55,7 @@ package cn.muchinfo.rma.global.data
  * @property userid Int
  * @constructor
  */
-data class AccountData(
+open class AccountData(
     val accountflag : Long = 0,//账户标识 - 0\1 (默认为0, 当上级账户与本账户的关联用户均为自己时更新为1)
     val accountid : Long = 0,//资金账户ID
     val accountname : String = "",//账户名称
@@ -107,4 +107,9 @@ data class AccountData(
     val transferamount : Double = 0.0,//今日划转金额(母子账号资金划转,从划入账号为正,从账号划出为负)
     val usedmargin : Double = 0.0,//占用保证金
     val userid : Long = 0//用户ID
-)
+) {
+
+
+
+
+}

+ 87 - 0
RMA/app/src/main/java/cn/muchinfo/rma/global/data/AccountShowData.kt

@@ -0,0 +1,87 @@
+package cn.muchinfo.rma.global.data
+
+import cn.muchinfo.rma.global.GlobalDataCollection
+
+class AccountShowData {
+    var exchange_rate //汇率
+            : String? = null
+    var net_worth //净值
+            : String? = null
+    var available_funds //可用资金
+            : String? = null
+    var close_profit_and_loss = "0" //平仓浮动盈亏  3.75
+    var keep_profit_and_loss = "0" //持仓浮动盈亏
+    var close_watch_profit_and_loss = "0" //平仓盯市盈亏  7.5
+
+    /**
+     * 期货的浮动盈亏需要*汇率
+     * @return
+     */
+    var keep_watch_profit_and_loss = "0" //持仓盯市盈亏
+    var margin_occupancy = "0" //保证金占用
+    var commission = "0" //手续费
+    var freezing_margin = "0" //冻结保证金
+    var freezing_commission = "0" //冻结手续费
+    var freezing = "0" //冻结资金
+    var in_money //入金
+            : String? = null
+    private var out_money //出金
+            : String? = null
+    var take_precedence //优先资金
+            : String? = null
+    var back_precedence //劣后资金
+            : String? = null
+    var risk_degree // 风险度
+            : String? = null
+
+    fun getOut_money(): String {
+        if (out_money == null || out_money == "" || "null" == out_money) {
+            out_money = "0"
+        }
+        return out_money!!
+    }
+
+    val out_money1: Double
+        get() {
+            if (out_money == null || out_money == "" || "null" == out_money) {
+                out_money = "0"
+            }
+            return Math.abs(out_money!!.toDouble())
+        }
+
+    fun setOut_money(out_money: String?) {
+        this.out_money = out_money
+    }
+
+    /**
+     * 获取基本信息(主要计算持仓浮动盈亏和平仓浮动盈亏)
+     * 盯市浮盈【实时行情更新】(MTP:浮动盈亏、持仓盈亏) 买方向 = (最新价 - 持仓均价) * 买期末头寸 * 合约单位;卖方向 = (持仓均价 - 最新价) * 卖期末头寸 * 合约单位
+     * 逐笔浮盈【实时行情更新】(MTP:开仓盈亏、平仓盈亏) 买方向 = (最新价 - 开仓均价) * 买期末头寸 * 合约单位;卖方向 = (开仓均价 - 最新价) * 卖期末头寸 * 合约单位
+     */
+    fun setNormalData() {
+        val futureHoldDatalist = GlobalDataCollection.instance?.futureHoldData
+        val quotes = GlobalDataCollection.instance?.goodsInfoAndQuotesList
+        futureHoldDatalist?.forEach { data ->
+            val quoteData = quotes?.find {
+                data.outgoodscode == it.outgoodscode
+            }?.quoteDayData
+            /** 计算持仓浮动盈亏汇总 **/
+            var positionpl = 0.0
+            if (data.buyorsell == 0){//买
+                positionpl = quoteData?.last?.minus(data.positionaverageprice)?.times(data.curpositionqty)?.times(data.agreeunit) ?: 0.0
+            }else if (data.buyorsell == 1){
+                positionpl = data.positionaverageprice.minus(quoteData?.last ?: 0.0).times(data.curpositionqty).times(data.agreeunit)
+            }
+            keep_watch_profit_and_loss += positionpl
+            /** 计算平仓浮动盈亏汇总 **/
+            var openpl = 0.0
+            if (data.buyorsell == 0){
+                openpl = quoteData?.last?.minus(data.openaverageprice)?.times(data.curpositionqty)?.times(data.agreeunit) ?: 0.0
+            }else if (data.buyorsell == 1){
+                openpl = data.openaverageprice.minus(quoteData?.last ?: 0.0).times(data.curpositionqty).times(data.agreeunit)
+            }
+            close_watch_profit_and_loss += openpl
+        }
+    }
+
+}

+ 55 - 0
RMA/app/src/main/java/cn/muchinfo/rma/global/data/CalculateData.java

@@ -0,0 +1,55 @@
+package cn.muchinfo.rma.global.data;
+
+/**
+ * Created by simonzhou on 2018/4/26.
+ * 计算出来的资金信息
+ */
+
+public class CalculateData {
+
+    private double AmountWorth;//净值
+    private double AvailMargin;//可用资金
+    private double risk;//风险率
+    private double safeRisk;// 安全度
+    private double totalAmount;// 市值
+
+    public double getTotalAmount() {
+        return totalAmount;
+    }
+
+    public void setTotalAmount(double totalAmount) {
+        this.totalAmount = totalAmount;
+    }
+
+    public double getAmountWorth() {
+        return AmountWorth;
+    }
+
+    public void setAmountWorth(double amountWorth) {
+        AmountWorth = amountWorth;
+    }
+
+    public double getAvailMargin() {
+        return AvailMargin;
+    }
+
+    public void setAvailMargin(double availMargin) {
+        AvailMargin = availMargin;
+    }
+
+    public double getRisk() {
+        return risk;
+    }
+
+    public void setRisk(double risk) {
+        this.risk = risk;
+    }
+
+    public double getSafeRisk() {
+        return safeRisk;
+    }
+
+    public void setSafeRisk(double safeRisk) {
+        this.safeRisk = safeRisk;
+    }
+}

+ 1 - 0
RMA/app/src/main/java/cn/muchinfo/rma/global/data/FutureDetailsData.kt

@@ -25,6 +25,7 @@ data class FutureDetailsData(
     val pricemode: String = "",//取价方式 - 1:市价 2: 限价
     val tradedate: String = "",//交易日(yyyyMMdd)
     val tradeqty: String = "",//成交数量
+
     val closecharge: String = "",//平仓手续费(账户)
     val closecharge2: String = "",//平仓手续费(商品)
     val opencharge: String = "",//建仓手续费(账户)

+ 224 - 0
RMA/app/src/main/java/cn/muchinfo/rma/global/data/OpeTaAccountInfoData.java

@@ -0,0 +1,224 @@
+//package cn.muchinfo.rma.global.data;
+//
+//import java.util.ArrayList;
+//
+//import cn.muchinfo.rma.global.GlobalDataCollection;
+//import cn.muchinfo.rma.global.data.futureOrders.FutureHoldData;
+//
+///**
+// * Created by simonzhou on 2018/4/26.
+// * 操作资金账户 计算资金
+// */
+//
+//public class OpeTaAccountInfoData extends AccountData {
+//
+//    private double dynProfitTotal = 0.0;      // 浮动盈亏
+//    private double totalNum = 0.0;            // 全额市值
+//    private double entrustOrderAmount = 0d;// 委托冻结
+//
+////    /**
+////     * 获取资金信息
+////     *
+////     * @param accountId
+////     * @return
+////     */
+////    public AccountData getInfoAccount(long accountId) {
+////        for (TAAccountAllData ta : GlobalDataCollention.getInstance().getTaAccountAllData()) {
+////            if (ta.getTaAccountInfo() != null && ta.getTaAccountInfo().getAccountId() == accountId) {
+////                return ta.getTaAccountInfo();
+////            }
+////        }
+////        return null;
+////    }
+//
+//    /**
+//     * 计算资金信息
+//     *
+//     * @return
+//     */
+//    public CalculateData getCalculate(long accountId, boolean version) {
+//        totalNum = 0;
+//        dynProfitTotal = 0;
+//        CalculateData data = new CalculateData();
+//        //计算相关数据
+//        // 持仓单计算
+////        for (TradeHolderDetailChild holder : GlobalDataCollention.getInstance().getTradeHolderDetailChildren()) {
+////            if (holder.getAccountid().equals(String.valueOf(getAccountId()))) {
+////                holder.calc();
+////                GoodsInfoAndQuotes info = GlobalDataCollention.getInstance().getmGoodsInfoClass().get(Integer.parseInt(holder.getGoodsid()));
+////                if (info != null) {
+////                    // 收益权的时候才计算浮动盈亏
+////                    if (Integer.parseInt(holder.getTradeproperty()) == MTPEnums.TRADEPROPERTY_CANSHORT) {
+////                        dynProfitTotal += holder.getDynProfit();
+////                    }
+////
+////                    totalNum += holder.getTotalAmout();
+////                } else {
+////                    totalNum += Double.parseDouble(holder.getHolderamount());
+////                }
+////            }
+////
+////        }
+//
+//        // 持仓汇总计算
+//        try {
+//            ArrayList<FutureHoldData> summaryData = GlobalDataCollection.Companion.getInstance().getFutureHoldData();
+//            for (FutureHoldData summary : summaryData) {
+//                if (summary.getAccountid().equals(String.valueOf(accountId))) {
+//                    summary.calc();
+//                    GoodsInfoAndQuotes goodsInfoAndQuotes = GlobalDataCollention.getInstance().getmGoodsInfoClass().get(Integer.parseInt(String.valueOf(summary.getGoodsid())));
+//                    if (goodsInfoAndQuotes != null) {
+//                        String rate = GlobalDataCollention.getRate(String.valueOf(getAccountId()), String.valueOf(goodsInfoAndQuotes.getGoodsInfo().getCurrencyId()));
+//                        MarketsInfoData marketInfo = GlobalDataCollention.getInstance().getMarketInfo(goodsInfoAndQuotes.getGoodsInfo().getMarketID());
+//                        if (marketInfo == null) {
+//                            continue;
+//                        }
+//                        if (marketInfo.getTradeProperty() == MTPEnums.TRADEPROPERTY_CANSHORT) {
+//                            dynProfitTotal += summary.getDynProfit();
+//                        }
+//                        totalNum += summary.getTotalAmout() * goodsInfoAndQuotes.getGoodsInfo().getAgreeUnit() * Double.parseDouble(rate);
+//                    } else {
+//                        totalNum += Double.parseDouble(summary.getCurholderamount());
+//                    }
+//                }
+//            }
+//        } catch (Exception e) {
+//            e.printStackTrace();
+//        }
+//
+//
+//
+//        //region 资管用的单据
+////        for (InforInnerHolderRspData inforInnerHolderRspData : GlobalDataCollention.getInstance().getInforInnerHolderRspData()) {
+////            if (inforInnerHolderRspData.getAccountid().equals(String.valueOf(accountId))) {// 账户
+////                inforInnerHolderRspData.calc();
+////                GoodsInfoAndQuotes goodsInfoAndQuotes = GlobalDataCollention.getInstance().getmGoodsInfoClass().get(Integer.parseInt(String.valueOf(inforInnerHolderRspData.getGoodsid())));
+////                if (goodsInfoAndQuotes != null) {
+////                    String rate = GlobalDataCollention.getRate(String.valueOf(getAccountId()), String.valueOf(goodsInfoAndQuotes.getGoodsInfo().getCurrencyId()));
+////                    totalNum += inforInnerHolderRspData.getTotalAmout() * goodsInfoAndQuotes.getGoodsInfo().getAgreeUnit() * Double.parseDouble(rate);
+////                }
+////            }
+////        }
+//
+//
+//        // 委托单的冻结
+//        for (TradeEntrustData item : GlobalDataCollention.getInstance().getTradeEntrustDataList()) {
+//            if (item.getAccountid().equals(String.valueOf(accountId))) {// 账户
+//                if (item.getOrderstatus() == MTPEnums.INNERSTATUS_ORDERSUCC) { // 委托成功的才计算
+//                    // 冻结 = 委托价格*可用数量*汇率
+//                    double orderPrice = Double.parseDouble(item.getOrderprice());
+//                    double num = 0;
+//                    if (item.getBuyorsell() == 0) {
+//                        num = Double.parseDouble(item.getOpenqty()) - Double.parseDouble(item.getOpentradeqty());
+//                    } else if (item.getBuyorsell() == 1) {
+//                        num = Double.parseDouble(item.getCloseqty()) - Double.parseDouble(item.getClosetradeqty());
+//                    }
+//                    GoodsInfoAndQuotes goodsInfoAndQuotes = GlobalDataCollention.getInstance().getmGoodsInfoClass().get(Integer.parseInt(String.valueOf(item.getGoodsid())));
+//                    String rate = GlobalDataCollention.getRate(String.valueOf(getAccountId()), String.valueOf(goodsInfoAndQuotes.getGoodsInfo().getCurrencyId()));
+//                    entrustOrderAmount += orderPrice * num * Double.parseDouble(rate);
+////                    obj.orderPrice*Double((obj.buyOrSell == 0 ? (obj.openOrderQty-obj.openTradeQty) : (obj.closeOrderQty-obj.closeTradeQty)))*
+//                }
+//            }
+//        }
+//
+//        data.setTotalAmount(totalNum);
+//
+//        //endregion
+//
+//
+//
+//        //找到对应的资金账户
+//        TaAccountInfoData accountInfoData = getInfoAccount(accountId);
+//        if (accountInfoData != null) {
+//            // 增加交易端配置项,账户净值是否减冻结资金 - 0:不减 1:减
+//            // 期权商品没有市值
+//            double AmountWorth = 0;
+//            String config = "1";
+//            ConfigInfoData configInfoData = GlobalDataCollention.getInstance().getConfigInfoDatas().get("307");
+//            if (configInfoData != null && configInfoData.getParamValue().equals("0")) {
+//                config = configInfoData.getParamValue();
+//            }
+//            // FIXME ====== 计算净值这个一定要注意啊,只有香港资管项目才不需要计算浮动盈亏
+//            // FIXME ====== 计算净值这个一定要注意啊,只有香港资管项目才不需要计算浮动盈亏
+//            // FIXME ====== 计算净值这个一定要注意啊,只有香港资管项目才不需要计算浮动盈亏
+//            // FIXME ====== 计算净值这个一定要注意啊,只有香港资管项目才不需要计算浮动盈亏
+//            // FIXME ====== 计算净值这个一定要注意啊,只有香港资管项目才不需要计算浮动盈亏
+//            // FIXME ====== 计算净值这个一定要注意啊,只有香港资管项目才不需要计算浮动盈亏
+//            if (config.equals("0")) {
+//                // 0.净值=期末余额+市值+浮动盈亏(收益权)
+//                AmountWorth = accountInfoData.getCurrentBalance() + totalNum/* + dynProfitTotal*/;
+//            } else {
+//                if (version) {
+//                    // 1.净值=期末余额+浮动盈亏(收益权)-其他冻结-手续费冻结-出金冻结
+//                    AmountWorth = accountInfoData.getCurrentBalance() /*+ dynProfitTotal*/ - accountInfoData.getOtherFreezeMargin() - accountInfoData.getFreezeCharge() - accountInfoData.getOutAmountFreeze();
+//                } else {
+//                    // 1.净值=期末余额+市值+浮动盈亏(收益权)-其他冻结-手续费冻结-出金冻结
+//                    AmountWorth = accountInfoData.getCurrentBalance() + totalNum /*+ dynProfitTotal*/ - accountInfoData.getOtherFreezeMargin() - accountInfoData.getFreezeCharge() - accountInfoData.getOutAmountFreeze();
+//                }
+//            }
+//
+//            data.setAmountWorth(AmountWorth);
+//            LogUtils.e("totalNum", totalNum + "");
+//            LogUtils.e("dynProfitTotal", dynProfitTotal + "");
+//            LogUtils.e("balance", accountInfoData.getCurrentBalance() + "");
+//
+//            // 可用保证金=期末余额+浮动盈亏(收益权[亏损计算,盈利是否计算根据系统配置])-占用冻结-其它冻结-手续费冻结-出金冻结 - 委托冻结
+//            double AvailMargin = accountInfoData.getCurrentBalance() /*+ dynProfitTotal*/ - accountInfoData.getUsedMargin() - accountInfoData.getFreezeMargin() - accountInfoData.getOtherFreezeMargin() - accountInfoData.getFreezeCharge() - accountInfoData.getOutAmountFreeze() - entrustOrderAmount;
+//            data.setAvailMargin(AvailMargin);
+//
+//            // 风险率
+//            double risk;
+//            // 风险净值 风险净值公式修改-》=期末余额+市值+浮动盈亏(收益权)-其他冻结-出金冻结
+//            double riskAmountWorth = accountInfoData.getCurrentBalance() + totalNum + dynProfitTotal - accountInfoData.getOtherFreezeMargin() - accountInfoData.getOutAmountFreeze();
+//
+//            // 风险率
+//            if (accountInfoData.getUsedMargin() <= 0) {
+//                // 占用<= 0,风险率为0%
+//                risk = 0;
+//            } else {
+//                if (riskAmountWorth <= 0) {
+//                    // 占用>0 && 风险净值<=0时,风险率为10000%
+//                    risk = 100;
+//                } else {
+//                    // 风险率=占用/风险净值
+//                    risk = accountInfoData.getUsedMargin() / riskAmountWorth;
+//                }
+//            }
+//
+//            double safeRisk = 0;
+//            // 安全度
+//            if (riskAmountWorth <= 0) {
+//                // 风险净值为0或负数,安全度为0%
+//                safeRisk = 0;
+//            } else {
+//                if (accountInfoData.getMortgageCredit() == 0) {
+//                    // 授信资金为0,安全度为10000%
+//                    safeRisk = 100;
+//                } else {
+//                    // 安全度=(风险净值-授信资金)/授信资金
+//                    safeRisk = (riskAmountWorth - accountInfoData.getMortgageCredit()) / accountInfoData.getMortgageCredit();
+//                }
+//            }
+//            data.setRisk(risk);
+//            data.setSafeRisk(safeRisk);
+//
+//        }
+//        return data;
+//
+//    }
+//
+//    public double getDynProfitTotal() {
+//        return dynProfitTotal;
+//    }
+//
+//    public void setDynProfitTotal(double dynProfitTotal) {
+//        this.dynProfitTotal = dynProfitTotal;
+//    }
+//
+//
+//    public double getAllFreeze() {
+//        return getOutAmountFreeze() + getFreezeCharge() + getOtherFreezeMargin() + getFreezeMargin();
+//    }
+//
+//
+//}

+ 29 - 0
RMA/app/src/main/java/cn/muchinfo/rma/global/data/futureOrders/DealOrderData.kt

@@ -0,0 +1,29 @@
+package cn.muchinfo.rma.global.data.futureOrders
+
+/***成交单实体 */
+data class DealOrderData(
+    val accountid: String = "",//账户ID
+    val buyorsell: String = "",//买卖 - 0:买 1:卖
+    val channelbuildtype: String = "",//开平标志 - 0:无 1:建仓 2:平仓
+    val channelinnerorderstatus: String = "",//委托状态 - 1:委托请求 2:冻结成功 3:委托失败 4:委托部成部失败 5:委托成功 6:全部撤销 7:部成部撤 8:部成部撤部失败 9:全部成交
+    val channeloperatetype: String = "",//操作类型 - 1:正常委托 2:斩仓委托 3:强平委托
+    val closetype: String = "",//平仓方式 - 0:无 1:平今 2:平昨
+    val curexchangerate: String = "",//当前汇率
+    val exchangefullname: String = "",//外部交易所全称
+    val goodscode: String = "",//商品代码(内部)
+    val goodsid: String = "",//商品ID
+    val goodsname: String = "",//商品名称
+    val marketid: String = "",//市场ID
+    val openfreezemargin: String = "",//冻结保证金(冻结交易金额)
+
+    val orderid: String = "",//委托单号(107+Unix秒时间戳(10位)+2位(MarketServiceID)+xxxx)
+    val orderprice: String = "",//委托价格(账户)
+    val orderqty: String = "",//委托数量
+    val ordertime: String = "",//委托时间
+    val pricemode: String = "",//取价方式 - 1:市价 2: 限价
+    val tradedate: String = "",//交易日(yyyyMMdd)
+    val tradeqty: String = "",//成交数量
+    val tradetime : String = "",//成交时间
+    val tradeprice : String = "",//成交价格
+    var select: Boolean = false
+)

+ 15 - 1
RMA/app/src/main/java/cn/muchinfo/rma/view/base/future/FutureFragment.kt

@@ -4,8 +4,10 @@ import android.os.Bundle
 import android.view.LayoutInflater
 import android.view.View
 import android.view.ViewGroup
+import android.widget.TextView
 import androidx.annotation.NonNull
 import androidx.annotation.Nullable
+import androidx.core.view.marginTop
 import androidx.fragment.app.Fragment
 import androidx.fragment.app.FragmentPagerAdapter
 import androidx.lifecycle.MutableLiveData
@@ -32,6 +34,9 @@ class FutureFragment : BaseFragment<FutureViewModel>() {
     private var _view: View? = null
     private var idTab: QMUITabSegment? = null
     private var idPager: ViewPager? = null
+    var id_title : TextView? = null
+   lateinit var id_account : TextView
+    val selectIndex : MutableLiveData<Int> = MutableLiveData()
     // tab 值
     private val tabs: Array<String?> = arrayOf(
         MyApplication.getInstance()?.resources?.getString(R.string.str_markets), // 行情
@@ -63,7 +68,15 @@ class FutureFragment : BaseFragment<FutureViewModel>() {
     private fun initViews() {
         idTab = _view?.findViewById(R.id.id_tab)
         idPager = _view?.findViewById(R.id.id_pager)
-
+        id_title = view?.findViewById(R.id.id_title)
+//        id_account = view?.findViewById(R.id.id_account)!!
+//        selectIndex.bindOptional(context!!){
+//            if (it == 0){
+//                id_account.visibility = View.GONE
+//            }else{
+//                id_account.visibility = View.VISIBLE
+//            }
+//        }
         // 设置
         val builder = BaseFutureModel().qmuiTabSegmentConfig(idTab, 15, context)
         idTab?.mode = QMUITabSegment.MODE_FIXED
@@ -98,6 +111,7 @@ class FutureFragment : BaseFragment<FutureViewModel>() {
              * @param index 被选中的 Tab 下标
              */
             override fun onTabSelected(index: Int) {
+                selectIndex.postValue(index)
             }
 
             /**

+ 4 - 4
RMA/app/src/main/java/cn/muchinfo/rma/view/base/future/costs/CostFragment.kt

@@ -27,12 +27,12 @@ class CostFragment : BaseFragment<CostViewModel>() {
 
 //region 数据
     private val tabs: Array<String?> = arrayOf(
-        MyApplication.getInstance()?.resources?.getString(R.string.str_can_cancel_today), // 今日可撤
-        MyApplication.getInstance()?.resources?.getString(R.string.str_entrust_today) // 今日委托
+        "资金信息", // 资金信息
+        "资金流水" // 资金流水
     )
     private val tabFragments: Array<Fragment> = arrayOf(
-        CostInfoFragment.getInstance(MyApplication.getInstance()?.resources?.getString(R.string.str_can_cancel_today)!!),
-        CostListFragment.getInstance(MyApplication.getInstance()?.resources?.getString(R.string.str_entrust_today)!!)
+        CostInfoFragment.getInstance("资金信息"),
+        CostListFragment.getInstance("资金流水")
     )
 //endregion
 

+ 248 - 10
RMA/app/src/main/java/cn/muchinfo/rma/view/base/future/costs/CostInfoFragment.kt

@@ -1,14 +1,26 @@
 package cn.muchinfo.rma.view.base.future.costs
 
 import android.os.Bundle
+import android.view.Gravity
 import android.view.LayoutInflater
 import android.view.View
 import android.view.ViewGroup
+import androidx.lifecycle.MutableLiveData
 import androidx.recyclerview.widget.LinearLayoutManager
 import androidx.recyclerview.widget.RecyclerView
 import cn.muchinfo.rma.R
+import cn.muchinfo.rma.global.GlobalDataCollection
+import cn.muchinfo.rma.global.data.AccountData
+import cn.muchinfo.rma.lifecycle.bindOptional
+import cn.muchinfo.rma.view.autoWidget.autoSize
+import cn.muchinfo.rma.view.autoWidget.textColorInt
+import cn.muchinfo.rma.view.autoWidget.textSizeAuto
 import cn.muchinfo.rma.view.base.BaseFragment
 import cn.muchinfo.rma.view.base.future.deals.DealData
+import cn.muchinfo.rma.view.base.future.trade.itemView
+import cn.muchinfo.rma.view.base.home.contract.emptyView
+import org.jetbrains.anko.*
+import org.jetbrains.anko.support.v4.UI
 
 /**
  * 资金信息
@@ -23,22 +35,248 @@ class CostInfoFragment(type: String?) : BaseFragment<CostViewModel>() {
     private var _view: View? = null
     private var idCostInfoList: RecyclerView? = null
 
+    val userAccountData : MutableLiveData<AccountData> = MutableLiveData()
+
     override fun onCreateView(
         inflater: LayoutInflater,
         container: ViewGroup?,
         savedInstanceState: Bundle?
     ): View? {
-        _view = inflater.inflate(R.layout.cost_info, container, false)
-        initViews()
-        return _view
-    }
 
-    private fun initViews() {
-        idCostInfoList = _view?.findViewById(R.id.id_cost_info_list)
+        return UI {
+            userAccountData.postValue(GlobalDataCollection.instance?.accountData)
+            verticalLayout {
+                scrollView {
+                    verticalLayout {
+                        linearLayout {
+                            gravity = Gravity.CENTER_VERTICAL
+                            textView {
+                                text = "币种"
+                                textSizeAuto = 31
+                                textColorInt = R.color.rma_black_33
+                            }.lparams(wrapContent, wrapContent){
+                                marginStart = autoSize(36)
+                            }
+
+                            emptyView()
+
+                            textView {
+                                userAccountData.bindOptional(context){
+                                    text = it?.currencyid.toString()
+                                }
+                                textSizeAuto = 31
+                                textColorInt = R.color.rma_black_33
+                            }.lparams(wrapContent, wrapContent){
+                                marginEnd = autoSize(36)
+                            }
+                        }.lparams(matchParent, autoSize(90))
+                        itemView()
+
+                        linearLayout {
+                            gravity = Gravity.CENTER_VERTICAL
+                            textView {
+                                text = "当前权益"
+                                textSizeAuto = 31
+                                textColorInt = R.color.rma_black_33
+                            }.lparams(wrapContent, wrapContent){
+                                marginStart = autoSize(36)
+                            }
+
+                            emptyView()
+
+                            textView {
+                                userAccountData.bindOptional(context){
+
+                                }
+                                textSizeAuto = 31
+                                textColorInt = R.color.rma_black_33
+                            }.lparams(wrapContent, wrapContent){
+                                marginEnd = autoSize(36)
+                            }
+                        }.lparams(matchParent, autoSize(90))
+                        itemView()
+
+                        linearLayout {
+                            gravity = Gravity.CENTER_VERTICAL
+                            textView {
+                                text = "可用金额"
+                                textSizeAuto = 31
+                                textColorInt = R.color.rma_black_33
+                            }.lparams(wrapContent, wrapContent){
+                                marginStart = autoSize(36)
+                            }
+
+                            emptyView()
+
+                            textView {
+                                text = "USD"
+                                textSizeAuto = 31
+                                textColorInt = R.color.rma_black_33
+                            }.lparams(wrapContent, wrapContent){
+                                marginEnd = autoSize(36)
+                            }
+                        }.lparams(matchParent, autoSize(90))
+                        itemView()
+
+                        linearLayout {
+                            gravity = Gravity.CENTER_VERTICAL
+                            textView {
+                                text = "占用金额"
+                                textSizeAuto = 31
+                                textColorInt = R.color.rma_black_33
+                            }.lparams(wrapContent, wrapContent){
+                                marginStart = autoSize(36)
+                            }
+
+                            emptyView()
+
+                            textView {
+                                text = "USD"
+                                textSizeAuto = 31
+                                textColorInt = R.color.rma_black_33
+                            }.lparams(wrapContent, wrapContent){
+                                marginEnd = autoSize(36)
+                            }
+                        }.lparams(matchParent, autoSize(90))
+                        itemView()
+
+
+                        linearLayout {
+                            gravity = Gravity.CENTER_VERTICAL
+                            textView {
+                                text = "冻结金额"
+                                textSizeAuto = 31
+                                textColorInt = R.color.rma_black_33
+                            }.lparams(wrapContent, wrapContent){
+                                marginStart = autoSize(36)
+                            }
+
+                            emptyView()
+
+                            textView {
+                                text = "USD"
+                                textSizeAuto = 31
+                                textColorInt = R.color.rma_black_33
+                            }.lparams(wrapContent, wrapContent){
+                                marginEnd = autoSize(36)
+                            }
+                        }.lparams(matchParent, autoSize(90))
+                        itemView()
+
+
+                        linearLayout {
+                            gravity = Gravity.CENTER_VERTICAL
+                            textView {
+                                text = "持仓盈亏"
+                                textSizeAuto = 31
+                                textColorInt = R.color.rma_black_33
+                            }.lparams(wrapContent, wrapContent){
+                                marginStart = autoSize(36)
+                            }
+
+                            emptyView()
+
+                            textView {
+                                text = "USD"
+                                textSizeAuto = 31
+                                textColorInt = R.color.rma_black_33
+                            }.lparams(wrapContent, wrapContent){
+                                marginEnd = autoSize(36)
+                            }
+                        }.lparams(matchParent, autoSize(90))
+                        itemView()
+
+                        linearLayout {
+                            gravity = Gravity.CENTER_VERTICAL
+                            textView {
+                                text = "平仓盈亏"
+                                textSizeAuto = 31
+                                textColorInt = R.color.rma_black_33
+                            }.lparams(wrapContent, wrapContent){
+                                marginStart = autoSize(36)
+                            }
+
+                            emptyView()
+
+                            textView {
+                                text = "USD"
+                                textSizeAuto = 31
+                                textColorInt = R.color.rma_black_33
+                            }.lparams(wrapContent, wrapContent){
+                                marginEnd = autoSize(36)
+                            }
+                        }.lparams(matchParent, autoSize(90))
+                        itemView()
+
+                        linearLayout {
+                            gravity = Gravity.CENTER_VERTICAL
+                            textView {
+                                text = "入金"
+                                textSizeAuto = 31
+                                textColorInt = R.color.rma_black_33
+                            }.lparams(wrapContent, wrapContent){
+                                marginStart = autoSize(36)
+                            }
+
+                            emptyView()
+
+                            textView {
+                                text = "USD"
+                                textSizeAuto = 31
+                                textColorInt = R.color.rma_black_33
+                            }.lparams(wrapContent, wrapContent){
+                                marginEnd = autoSize(36)
+                            }
+                        }.lparams(matchParent, autoSize(90))
+                        itemView()
+
+                        linearLayout {
+                            gravity = Gravity.CENTER_VERTICAL
+                            textView {
+                                text = "出金"
+                                textSizeAuto = 31
+                                textColorInt = R.color.rma_black_33
+                            }.lparams(wrapContent, wrapContent){
+                                marginStart = autoSize(36)
+                            }
+
+                            emptyView()
+
+                            textView {
+                                text = "USD"
+                                textSizeAuto = 31
+                                textColorInt = R.color.rma_black_33
+                            }.lparams(wrapContent, wrapContent){
+                                marginEnd = autoSize(36)
+                            }
+                        }.lparams(matchParent, autoSize(90))
+                        itemView()
+
+                        linearLayout {
+                            gravity = Gravity.CENTER_VERTICAL
+                            textView {
+                                text = "资金使用率"
+                                textSizeAuto = 31
+                                textColorInt = R.color.rma_black_33
+                            }.lparams(wrapContent, wrapContent){
+                                marginStart = autoSize(36)
+                            }
+
+                            emptyView()
+
+                            textView {
+                                text = "USD"
+                                textSizeAuto = 31
+                                textColorInt = R.color.rma_black_33
+                            }.lparams(wrapContent, wrapContent){
+                                marginEnd = autoSize(36)
+                            }
+                        }.lparams(matchParent, autoSize(90))
+                        itemView()
 
-        val layoutManager = LinearLayoutManager(context)
-        idCostInfoList?.layoutManager = layoutManager
-        viewModel.makeCostInfo()
-        idCostInfoList?.adapter = viewModel.getCostInfoAdapter()
+                    }
+                }
+            }
+        }.view
     }
 }

+ 15 - 12
RMA/app/src/main/java/cn/muchinfo/rma/view/base/future/deals/DealFragment.kt

@@ -7,7 +7,10 @@ import android.view.ViewGroup
 import androidx.recyclerview.widget.LinearLayoutManager
 import androidx.recyclerview.widget.RecyclerView
 import cn.muchinfo.rma.R
+import cn.muchinfo.rma.lifecycle.bindOptional
+import cn.muchinfo.rma.view.autoWidget.toArrayList
 import cn.muchinfo.rma.view.base.BaseFragment
+import cn.muchinfo.rma.view.base.future.holds.HoldViewModel
 
 /**
  * 成交单
@@ -29,26 +32,26 @@ class DealFragment : BaseFragment<DealViewModel>() {
     ): View? {
         _view = inflater.inflate(R.layout.deal_fragment, container, false)
         initViews()
+        viewModel.dealLiveData.bindOptional(context!!) { data ->
+            (idDealList?.adapter as DealViewModel.HoldAdapter).update(data?.toArrayList())
+        }
         return _view
     }
 
     private fun initViews() {
         idDealList = _view?.findViewById(R.id.id_deal_list)
-        val list: ArrayList<DealData>? = ArrayList()
-        for (a in 1..5) {
-            val m = DealData()
-            m.goodsName = "铁矿石" + (2105 + a)
-            m.dealNum = 10.0 + a
-            m.dealPrice = 188.0 + a
-            m.dealTime = "2021-02-25 21:21:21"
-            m.direction = a
-            m.goodsId = a
-            list?.add(m)
-        }
 
         val layoutManager = LinearLayoutManager(context)
         idDealList?.layoutManager = layoutManager
-        viewModel.list = list
         idDealList?.adapter = viewModel.getAdapter()
     }
+
+    override fun onResume() {
+        super.onResume()
+        viewModel.queryDeal()
+    }
+    //主动更新数据
+    fun onRefresh(){
+        viewModel.queryDeal()
+    }
 }

+ 47 - 12
RMA/app/src/main/java/cn/muchinfo/rma/view/base/future/deals/DealViewModel.kt

@@ -6,17 +6,26 @@ import android.view.LayoutInflater
 import android.view.View
 import android.view.ViewGroup
 import android.widget.TextView
+import androidx.lifecycle.MutableLiveData
 import androidx.recyclerview.widget.RecyclerView
 import cn.muchinfo.rma.R
+import cn.muchinfo.rma.global.GlobalDataCollection
+import cn.muchinfo.rma.global.channelbuildtype
+import cn.muchinfo.rma.global.data.futureOrders.DealOrderData
+import cn.muchinfo.rma.global.data.futureOrders.FutureHoldData
+import cn.muchinfo.rma.global.isBlankString
+import cn.muchinfo.rma.global.toShowTime
+import cn.muchinfo.rma.view.MyApplication
 import cn.muchinfo.rma.view.base.BaseViewModel
 import cn.muchinfo.rma.view.base.future.interfaces.OnItemClickListener
 import org.jetbrains.anko.backgroundColor
 
 class DealViewModel : BaseViewModel() {
 
-    var list: ArrayList<DealData>? = null
+    val dealLiveData: MutableLiveData<List<DealOrderData>> = MutableLiveData() // 成交单
+    var list: ArrayList<DealOrderData>? = null
     var onItemClickListener: OnItemClickListener? = null // item点击事件
-    var currentDealData: DealData? = null // 当前选择的item对应的数据
+    var currentDealData: DealOrderData? = null // 当前选择的item对应的数据
 
     /**
      * 获取配置器。
@@ -27,8 +36,8 @@ class DealViewModel : BaseViewModel() {
     /**
      * 通用的适配器。
      */
-    inner class HoldAdapter(context: Context?, list: ArrayList<DealData>?) : RecyclerView.Adapter<HoldAdapter.DealHolder>() {
-        private var list: ArrayList<DealData>? = null
+    inner class HoldAdapter(context: Context?, list: ArrayList<DealOrderData>?) : RecyclerView.Adapter<HoldAdapter.DealHolder>() {
+        private var list: ArrayList<DealOrderData>? = null
         private var inflater: LayoutInflater? = null
         private var context: Context? = null
         private var pink: Drawable? = null
@@ -53,6 +62,11 @@ class DealViewModel : BaseViewModel() {
             return list?.size ?: 0
         }
 
+        fun update(list: ArrayList<DealOrderData>?) {
+            this.list = list
+            notifyDataSetChanged()
+        }
+
         inner class DealHolder(itemView: View?) : RecyclerView.ViewHolder(itemView!!) {
             var idGoodsName = itemView?.findViewById<TextView>(R.id.id_goods_name)
             var idTransType = itemView?.findViewById<TextView>(R.id.id_trans_type)
@@ -67,11 +81,11 @@ class DealViewModel : BaseViewModel() {
         override fun onBindViewHolder(holder: DealHolder, position: Int) {
             holder.itemView.tag = list?.get(position)
 
-            holder.idGoodsName?.text = list?.get(position)?.goodsName
-            holder.idTransType?.text = list?.get(position)?.direction.toString()
-            holder.idDealNum?.text = list?.get(position)?.dealNum.toString()
-            holder.idDealPrice?.text = list?.get(position)?.dealPrice.toString()
-            holder.idDealTime?.text = list?.get(position)?.dealTime
+            holder.idGoodsName?.text = list?.get(position)?.goodsname
+            holder.idTransType?.text = list?.get(position)?.channelbuildtype.toString().channelbuildtype()
+            holder.idDealNum?.text = list?.get(position)?.tradeqty.toString().isBlankString()
+            holder.idDealPrice?.text = list?.get(position)?.tradeprice.toString()
+            holder.idDealTime?.text = list?.get(position)?.tradetime?.toShowTime()
 
             // 下面三个按钮的点击事件
             holder.idChart?.tag = list?.get(position)
@@ -105,12 +119,16 @@ class DealViewModel : BaseViewModel() {
         }
 
         private fun clickItem(view: View) {
-            currentDealData = view.tag as DealData? // 临时存储当前点击item
+            currentDealData = view.tag as DealOrderData? // 临时存储当前点击item
 
             // 选择
             list?.forEach { itemValue ->
-                if (itemValue.goodsId == currentDealData?.goodsId) {
-                    itemValue.select = !itemValue.select
+                if (itemValue.goodsid == currentDealData?.goodsid) {
+                    if (itemValue.channelbuildtype == currentDealData?.channelbuildtype){
+                        itemValue.select = !itemValue.select
+                    }else{
+                        itemValue.select = false
+                    }
                 } else {
                     itemValue.select = false
                 }
@@ -120,4 +138,21 @@ class DealViewModel : BaseViewModel() {
             notifyDataSetChanged()
         }
     }
+
+    /**
+     * 请求成交单
+     */
+    fun queryDeal(){
+        val params = mutableMapOf<String, String>()
+        params["accountID"] = GlobalDataCollection.instance?.accountId.toString()
+        MyApplication.getInstance()?.futureManager?.queryErmcpTradeDetails(params) { isSuccess, respData, _ ->
+            if (isSuccess && !respData!!.isNullOrEmpty()) {
+                list = respData as ArrayList<DealOrderData>
+                dealLiveData.value = list
+            } else {
+                // 没有数据或者接口返回错误的时候,通知界面没有获取到数据
+
+            }
+        }
+    }
 }

+ 1 - 2
RMA/app/src/main/java/cn/muchinfo/rma/view/base/future/entrusts/EntrustChildViewModel.kt

@@ -167,8 +167,7 @@ class EntrustChildViewModel : BaseViewModel() {
                 val temps = arrayListOf<FutureEntrustData>()
                 respData.filter {
                     // 如果是TODAY_CANCEL_TYPE 那就channelinnerorderstatus == 5,如果是TODAY_TYPE,那么channelinnerorderstatus != 5
-                    (it.channelinnerorderstatus == 5 && type == CustomerEnums.EntrustType.TODAY_CANCEL_TYPE) ||
-                            (it.channelinnerorderstatus != 5 && type == CustomerEnums.EntrustType.TODAY_TYPE)
+                    (it.channelinnerorderstatus == 5 && type == CustomerEnums.EntrustType.TODAY_CANCEL_TYPE) || (type == CustomerEnums.EntrustType.TODAY_TYPE)
                 }.forEach {
                     temps.add(it)
                 }

+ 15 - 3
RMA/app/src/main/java/cn/muchinfo/rma/view/base/future/holds/HoldFragment.kt

@@ -1,18 +1,21 @@
 package cn.muchinfo.rma.view.base.future.holds
 
+import android.app.Dialog
 import android.os.Bundle
 import android.view.LayoutInflater
 import android.view.View
 import android.view.ViewGroup
+import androidx.lifecycle.MutableLiveData
 import androidx.recyclerview.widget.LinearLayoutManager
 import androidx.recyclerview.widget.RecyclerView
 import cn.muchinfo.rma.R
 import cn.muchinfo.rma.lifecycle.bindOptional
 import cn.muchinfo.rma.view.autoWidget.toArrayList
 import cn.muchinfo.rma.view.base.BaseFragment
-import cn.muchinfo.rma.view.eventbus.EventConstent
 import cn.muchinfo.rma.view.eventbus.MessageEvent
-import com.blankj.utilcode.util.ToastUtils
+import mtp.polymer.com.autowidget.dialog.createLoadingDialog
+import mtp.polymer.com.autowidget.utils.TaskUiModel
+import mtp.polymer.com.autowidget.utils.bindTaskStatus
 import org.greenrobot.eventbus.EventBus
 import org.greenrobot.eventbus.Subscribe
 import org.greenrobot.eventbus.ThreadMode
@@ -28,6 +31,13 @@ class HoldFragment : BaseFragment<HoldViewModel>() {
 //region views
     private var _view: View? = null
     private var idHoldList: RecyclerView? = null // 持仓列表
+    private var loadingDialog: Dialog? = null
+    var isBackhandByLose = 0 //是否是快捷反手操作,1是反手操作,0不是反手操作
+
+    /**
+     * 数据初始化状态控制
+     */
+    val loadingDialogStatus: MutableLiveData<TaskUiModel> = MutableLiveData()
 //endregion
     override fun onCreateView(
         inflater: LayoutInflater,
@@ -36,6 +46,8 @@ class HoldFragment : BaseFragment<HoldViewModel>() {
     ): View? {
         _view = inflater.inflate(R.layout.hold_fragment, container, false)
         initViews()
+        loadingDialog = createLoadingDialog(hintStr = "请求中")
+        loadingDialog?.bindTaskStatus(context!!, loadingDialogStatus)
         viewModel.holdLiveData.bindOptional(context!!) { data ->
             (idHoldList?.adapter as HoldViewModel.HoldAdapter).update(data?.toArrayList())
         }
@@ -61,7 +73,7 @@ class HoldFragment : BaseFragment<HoldViewModel>() {
     private fun initViews() {
         idHoldList = _view?.findViewById(R.id.id_hold_list)
 
-        val adapter = viewModel.getAdapter()
+        val adapter = viewModel.getAdapter(this)
         val layoutManager = LinearLayoutManager(context)
         idHoldList?.layoutManager = layoutManager
         idHoldList?.adapter = adapter

+ 125 - 60
RMA/app/src/main/java/cn/muchinfo/rma/view/base/future/holds/HoldViewModel.kt

@@ -6,14 +6,17 @@ import android.view.LayoutInflater
 import android.view.View
 import android.view.ViewGroup
 import android.widget.TextView
+import androidx.fragment.app.Fragment
 import androidx.lifecycle.MutableLiveData
 import androidx.recyclerview.widget.RecyclerView
 import cn.muchinfo.rma.R
 import cn.muchinfo.rma.business.future.adapter.ChannelOrderReqData
 import cn.muchinfo.rma.global.GlobalDataCollection
 import cn.muchinfo.rma.global.data.futureOrders.FutureHoldData
+import cn.muchinfo.rma.netManage.base.InteractiveException
 import cn.muchinfo.rma.view.MyApplication
 import cn.muchinfo.rma.view.autoWidget.onThrottleFirstClick
+import cn.muchinfo.rma.view.autoWidget.utils.NumberUtils
 import cn.muchinfo.rma.view.base.BaseViewModel
 import cn.muchinfo.rma.view.base.app.FutureConstent
 import cn.muchinfo.rma.view.eventbus.EventConstent
@@ -21,6 +24,8 @@ import cn.muchinfo.rma.view.eventbus.TradeMessageEvent
 import com.blankj.utilcode.util.TimeUtils
 import kotlinx.coroutines.GlobalScope
 import kotlinx.coroutines.launch
+import mtp.polymer.com.autowidget.dialog.createWarningDialog
+import mtp.polymer.com.autowidget.utils.TaskUiModel
 import org.greenrobot.eventbus.EventBus
 
 /**
@@ -37,13 +42,14 @@ class HoldViewModel : BaseViewModel() {
     /**
      * 获取配置器。
      */
-    fun getAdapter(): RecyclerView.Adapter<HoldAdapter.HoldHolder> {
-        return HoldAdapter(context)
+    fun getAdapter(fragment : Fragment): RecyclerView.Adapter<HoldAdapter.HoldHolder> {
+        return HoldAdapter(context,fragment)
     }
+
     /**
      * 通用的适配器。
      */
-    class HoldAdapter(context: Context?) : RecyclerView.Adapter<HoldAdapter.HoldHolder>() {
+    class HoldAdapter(context: Context?,fragment : Fragment) : RecyclerView.Adapter<HoldAdapter.HoldHolder>() {
         private var list: ArrayList<FutureHoldData>? = null
         private var inflater: LayoutInflater? = null
         private var context: Context? = null
@@ -51,13 +57,14 @@ class HoldViewModel : BaseViewModel() {
         private var green: Drawable? = null
         private var priceRed: Int = 0
         private var priceGreen: Int = 0
+        private var fragment : Fragment? = null
         var futureHoldData: FutureHoldData? = null // 当前选择的item对应的数据
 
         init {
             this.list = GlobalDataCollection.instance?.futureHoldData
             this.inflater = LayoutInflater.from(context)
             this.context = context
-
+            this.fragment = fragment
             pink = context?.getDrawable(R.drawable.rma_red)
             green = context?.getDrawable(R.drawable.rma_green)
             priceGreen = context?.getColor(R.color.p_price_green)!!
@@ -78,8 +85,10 @@ class HoldViewModel : BaseViewModel() {
             var idTransDirection = itemView?.findViewById<TextView>(R.id.id_trans_direction) // 方向
             var idAvailable = itemView?.findViewById<TextView>(R.id.id_available) // 可用
             var idHoldTotal = itemView?.findViewById<TextView>(R.id.id_hold_total) // 持仓
-            var idOpenAveragePrice = itemView?.findViewById<TextView>(R.id.id_open_average_price) // 开仓均价
-            var idHoldAveragePrice = itemView?.findViewById<TextView>(R.id.id_hold_average_price) // 持仓均价
+            var idOpenAveragePrice =
+                itemView?.findViewById<TextView>(R.id.id_open_average_price) // 开仓均价
+            var idHoldAveragePrice =
+                itemView?.findViewById<TextView>(R.id.id_hold_average_price) // 持仓均价
             var idZPl = itemView?.findViewById<TextView>(R.id.id_zpl) // 盯市浮盈
             var idPlp = itemView?.findViewById<TextView>(R.id.id_plp) // 盈亏比例
             var id_pl = itemView?.findViewById<TextView>(R.id.id_pl)//逐笔浮盈
@@ -97,11 +106,15 @@ class HoldViewModel : BaseViewModel() {
             holder.idGoodsName?.text = itemData?.goodsname
             holder.idAvailable?.text = itemData?.enableqty.toString() // 可用(总仓可用)
             holder.idHoldTotal?.text = itemData?.curpositionqty.toString() // 持仓(总仓数量, 期末头寸)
-            holder.idOpenAveragePrice?.text = itemData?.openaverageprice.toString()//开仓均价【头寸变化更新】 = 开仓成本 / 期末头寸 / 合约单位
-            holder.idHoldAveragePrice?.text = itemData?.positionaverageprice.toString()//持仓均价【头寸变化更新】= 持仓成本 / 期末头寸 / 合约单位
-            holder.idZPl?.text = itemData?.positionpl.toString()//盯市浮盈【实时行情更新】(MTP:浮动盈亏、持仓盈亏) 买方向 = (最新价 - 持仓均价) * 买期末头寸 * 合约单位;卖方向 = (持仓均价 - 最新价) * 卖期末头寸 * 合约单位
+            holder.idOpenAveragePrice?.text =
+                itemData?.openaverageprice.toString()//开仓均价【头寸变化更新】 = 开仓成本 / 期末头寸 / 合约单位
+            holder.idHoldAveragePrice?.text =
+                itemData?.positionaverageprice.toString()//持仓均价【头寸变化更新】= 持仓成本 / 期末头寸 / 合约单位
+            holder.idZPl?.text =
+                itemData?.positionpl.toString()//盯市浮盈【实时行情更新】(MTP:浮动盈亏、持仓盈亏) 买方向 = (最新价 - 持仓均价) * 买期末头寸 * 合约单位;卖方向 = (持仓均价 - 最新价) * 卖期末头寸 * 合约单位
             holder.idPlp?.text = itemData?.positionplrate.toString()//持仓盈亏比例【实时行情更新】 = 持仓盈亏 / 开仓成本
-            holder.id_pl?.text = itemData?.openpl.toString()//逐笔浮盈【实时行情更新】(MTP:开仓盈亏、平仓盈亏) 买方向 = (最新价 - 开仓均价) * 买期末头寸 * 合约单位;卖方向 = (开仓均价 - 最新价) * 卖期末头寸 * 合约单位
+            holder.id_pl?.text =
+                itemData?.openpl.toString()//逐笔浮盈【实时行情更新】(MTP:开仓盈亏、平仓盈亏) 买方向 = (最新价 - 开仓均价) * 买期末头寸 * 合约单位;卖方向 = (开仓均价 - 最新价) * 卖期末头寸 * 合约单位
             holder.idMargin?.text = itemData?.usedmargin.toString()//占用保证金
             if (list?.get(position)?.buyorsell == 0) {
                 holder.idTransDirection?.text = context?.resources?.getString(R.string.str_buy)
@@ -111,11 +124,28 @@ class HoldViewModel : BaseViewModel() {
 
             /** 快捷反手 */
             holder.quick_backhand?.onThrottleFirstClick {
-
+                fragment?.createWarningDialog {
+                    setTitle("快捷反手确认")
+                    setMessage("确认将该合约的所有持仓进行快捷反手操作?")
+                    addAction("取消") { dialog, _ -> dialog.dismiss() }
+                    addAction("确定") { dialog, _ ->
+                        commitDealData(true ,true)
+                        dialog.dismiss()
+                    }
+                }?.show()
             }
 
             /** 一键平仓 **/
             holder.key_positions?.onThrottleFirstClick {
+                fragment?.createWarningDialog {
+                    setTitle("快捷反手确认")
+                    setMessage("确认将该合约的所有持仓进行快捷反手操作?")
+                    addAction("取消") { dialog, _ -> dialog.dismiss() }
+                    addAction("确定") { dialog, _ ->
+                        commitDealData(false ,true)
+                        dialog.dismiss()
+                    }
+                }?.show()
 
             }
 
@@ -134,7 +164,7 @@ class HoldViewModel : BaseViewModel() {
                 holder.key_positions?.visibility = View.VISIBLE
                 holder.id_chart?.visibility = View.VISIBLE
                 holder.id_entrust_detail?.visibility = View.VISIBLE
-            } else if(list?.get(position)?.selected == false) {
+            } else if (list?.get(position)?.selected == false) {
                 holder.quick_backhand?.visibility = View.GONE
                 holder.key_positions?.visibility = View.GONE
                 holder.id_chart?.visibility = View.GONE
@@ -144,7 +174,14 @@ class HoldViewModel : BaseViewModel() {
             holder.itemView.onThrottleFirstClick {
                 clickItem(it!!)
                 val data = list?.get(position)
-                EventBus.getDefault().post(TradeMessageEvent(messageType = EventConstent.TRADEGOODSID,goodsId = data?.goodsid.toString(),buyOrSell = data?.buyorsell ?: 0,outGoodsCode = data?.outgoodscode ?: ""))
+                EventBus.getDefault().post(
+                    TradeMessageEvent(
+                        messageType = EventConstent.TRADEGOODSID,
+                        goodsId = data?.goodsid.toString(),
+                        buyOrSell = data?.buyorsell ?: 0,
+                        outGoodsCode = data?.outgoodscode ?: ""
+                    )
+                )
             }
 
         }
@@ -154,13 +191,17 @@ class HoldViewModel : BaseViewModel() {
 
             // 选择i
             list?.forEach { itemValue ->
-                if ((itemValue.goodsid + itemValue.buyorsell) == futureHoldData?.goodsid ?: "" + futureHoldData?.buyorsell) {
-                    itemValue.selected = !itemValue.selected
-                } else {
+                if (itemValue.goodsid == futureHoldData?.goodsid){
+                    if (itemValue.buyorsell == futureHoldData?.buyorsell){
+                        itemValue.selected = !itemValue.selected
+                    }else{
+                        itemValue.selected = false
+                    }
+                }else{
                     itemValue.selected = false
                 }
             }
-             // 刷新数据
+            // 刷新数据
             notifyDataSetChanged()
         }
 
@@ -172,69 +213,83 @@ class HoldViewModel : BaseViewModel() {
          * 操作请求
          * @param isClose Boolean 是否是平仓单
          */
-        private fun commitDealData(isClose: Boolean) {
+        fun commitDealData(isBackHand : Boolean,isClose: Boolean) {
+            (fragment as HoldFragment).loadingDialogStatus.postValue(TaskUiModel.inFlight())
+            var tradePrice = 0.0 //交易价格
+            var itemData : FutureHoldData
+            if (isClose){
+                itemData = futureHoldData ?: FutureHoldData()
+            }else{
+                itemData = GlobalDataCollection.instance?.itemData ?: FutureHoldData()
+            }
             val datas = ChannelOrderReqData()
             datas.setAccountID(GlobalDataCollection.instance?.accountId ?: 0) // 交易账号
-            val goodsQuote = GlobalDataCollection.instance?.getmGoodsInfoClass()?.get(futureHoldData?.outgoodscode)
+            val goodsQuote = GlobalDataCollection.instance?.goodsInfoAndQuotesList?.find {
+                it.outgoodscode == itemData.outgoodscode
+            }
             if (isClose) {
-                if (futureHoldData?.buyorsell == 0) {
+                if (itemData.buyorsell == 0) {
                     //平仓---平买单,方向是卖
-                    datas.setBuyOrSell(0)
+                    datas.setBuyOrSell(1)
                 } else {
                     //平仓---平卖单,方向是买
-                    datas.setBuyOrSell(1)
+                    datas.setBuyOrSell(0)
                 }
             } else {
-                datas.setBuyOrSell(futureHoldData?.buyorsell ?: 0)
+                if (itemData.buyorsell == 0) {
+                    //平仓---平买单,方向是卖
+                    datas.setBuyOrSell(1)
+                } else {
+                    //平仓---平卖单,方向是买
+                    datas.setBuyOrSell(0)
+                }
+            }
+            //在fragment内设置一个变量用来控制是否在平仓后再进行建仓/且把用来反手建仓的数据暂存在数据中心
+            if (isBackHand) {
+                GlobalDataCollection.instance?.setItemData(itemData)
+                (fragment as HoldFragment).isBackhandByLose = 1
+            }else{
+                (fragment as HoldFragment).isBackhandByLose = 0
             }
             datas.clientOrderTime = TimeUtils.getNowString() // 客户端委托时间  当前时间
             datas.clientType = 3 // 客户端类型: 1客户端  3 手机端 android
-            datas.goodsID = futureHoldData?.goodsid ?: 0//商品id
+            datas.goodsID = itemData.goodsid ?: 0//商品id
             datas.loginID = GlobalDataCollection.instance?.loginRsp?.loginID ?: 0 //登录账号
 
-            datas.marketID = futureHoldData?.marketid ?: 0
+            datas.marketID = itemData.marketid ?: 0
             datas.validType = 1 // 有效类型-1当日有效
-            datas.channelOperateType = FutureConstent.ChannelOperateType_ORDER // 操作类型  1:正常类型  默认写死???
+            datas.channelOperateType =
+                FutureConstent.ChannelOperateType_ORDER // 操作类型  1:正常类型  默认写死???
             datas.channelOrderSrc = 1 // 单据来源委托来源-1:客户端  //默认写死?
             datas.hedgeFlag = 0 // 投机套保标志-0:无
-//            if (goodsQuote.getQuoteDay() != null && goodsInfo.getQuoteDay().getAsk() != null) {
-//                val decial: Int = goodsInfo.getGoodsInfo().getDecimalPlace()
-//                val setp: Double
+            if (goodsQuote?.quoteDayData != null) {
+                val decial = goodsQuote.goodsInfo.decimalplace
+                val setp: Double
 //                setp = if ("0" == overDot) { //如果没有拿到超价点数则按照原来的计算吧
-//                    goodsInfo.getGoodsInfo().getQuoteMinUnit() * Math.pow(
-//                        10.0,
-//                        -goodsInfo.getGoodsInfo().getDecimalPlace()
-//                    )
+//
 //                } else {
 //                    goodsInfo.getGoodsInfo().getQuoteMinUnit() * Math.pow(
 //                        10.0,
 //                        -goodsInfo.getGoodsInfo().getDecimalPlace()
 //                    ) * java.lang.Double.valueOf(overDot)
 //                }
-//                val askLimitPrice: String = Utils.roundNum(
-//                    if (java.lang.Double.valueOf(
-//                            goodsInfo.getQuoteDay().getAsk()
-//                        ) != 0
-//                    ) java.lang.Double.valueOf(
-//                        goodsInfo.getQuoteDay().getAsk()
-//                    ) + setp /*limitStep*/ else 0, decial
-//                )
-//                val bidLimitPrice: String = Utils.roundNum(
-//                    if (java.lang.Double.valueOf(
-//                            goodsInfo.getQuoteDay().getBid()
-//                        ) != 0
-//                    ) java.lang.Double.valueOf(
-//                        goodsInfo.getQuoteDay().getBid()
-//                    ) - setp /*limitStep*/ else 0, decial
-//                )
-//                if (buyOrSell == 0) {
-//                    tradePrice = bidLimitPrice.toDouble()
-//                } else {
-//                    tradePrice = askLimitPrice.toDouble()
-//                }
-//            }
-//            datas.orderPrice = orderPrice.toDouble()
-            datas.orderQty = futureHoldData?.enableqty?.toLong() ?: 0
+                setp = goodsQuote.goodsInfo.quoteminunit * Math.pow(
+                    10.0,
+                    -decial.toDouble()
+                )
+                val askLimitPrice: String =
+                    NumberUtils.roundNum(goodsQuote.quoteDayData.ask + setp /*limitStep*/, decial)
+                val bidLimitPrice: String = NumberUtils.roundNum(
+                    goodsQuote.quoteDayData.bid - setp /*limitStep*/, decial
+                )
+                if (itemData.buyorsell == 0) {
+                    tradePrice = bidLimitPrice.toDouble()
+                } else {
+                    tradePrice = askLimitPrice.toDouble()
+                }
+            }
+            datas.orderPrice = tradePrice
+            datas.orderQty = itemData.enableqty?.toLong() ?: 0
 
             if (isClose) {
                 // 平仓
@@ -271,10 +326,20 @@ class HoldViewModel : BaseViewModel() {
 //        val bbb: String = Utils.getCommonIp()
 //        datas.setIp(bbb)
             datas.setValidtime("") // 有效时间string
-            GlobalScope.launch {
-                MyApplication.getInstance()?.futureManager?.tradeRequest(data = datas){isCompleted, err ->
-                    if (isCompleted){
 
+            GlobalScope.launch {
+                MyApplication.getInstance()?.futureManager?.tradeRequest(data = datas) { isCompleted, err ->
+                    if (isCompleted) {
+                        if ((fragment as HoldFragment).isBackhandByLose == 1){
+                            commitDealData(false ,false)
+                        }else{
+                            (fragment as HoldFragment).loadingDialogStatus.postValue(TaskUiModel.success(msg = "请求成功"))
+                            (fragment as HoldFragment).onRefresh()
+                        }
+                    }else{
+                        (fragment as HoldFragment).loadingDialogStatus.postValue(TaskUiModel.failed(
+                            InteractiveException(errorMessage = err?.message!!)
+                        ))
                     }
                 }
             }

+ 3 - 3
RMA/app/src/main/java/cn/muchinfo/rma/view/base/future/trade/GoodsTradeActivity.kt

@@ -190,7 +190,7 @@ class GoodsTradeActivity : BaseActivity<GoodsTradeViewModel>() {
     }
 
     /** 初始化当前选择的商品信息 **/
-    fun initData(goodsId: String, outGoodsCode: String = "",buyOrSell: Int = -1) {
+    fun initData(goodsId: String, outGoodsCode: String = "",buyOrSell: Int = -1,isShowLoading : Boolean = true) {
         //当buyorsell不为-1时则设置当前选择的持仓单
         if (buyOrSell != -1){
             futureHoldData = viewModel.getNowSelectHoldData(goodsId = goodsId,buyorsell = buyOrSell)
@@ -198,7 +198,7 @@ class GoodsTradeActivity : BaseActivity<GoodsTradeViewModel>() {
         viewModel.priceOrderType.postValue(FutureConstent.eOrderPriceSelectType_Last)//默认交易价格取价方式为最新价
         viewModel.tradeMode.postValue(FutureConstent.PriceMode_PRICEMODE_LIMIT)//通道下单类型默认为限价
         goodsInfoData.postValue(Builder.getDatabase<AppDatabase>().goodsInfoDao.getGoodsInfo(goodsId.toInt()))//获取商品详情
-        viewModel.queryQuoteDay(outGoodsCode)//请求盘面
+        viewModel.queryQuoteDay(outGoodsCode,isShowLoading = isShowLoading)//请求盘面
         viewModel.initAccountData()//拿到当前的资金账号
 
     }
@@ -213,7 +213,7 @@ class GoodsTradeActivity : BaseActivity<GoodsTradeViewModel>() {
     //持仓单点击消息通知
     @Subscribe(threadMode = ThreadMode.MAIN)
     fun onMeesageChangeTradeId(tradeMessageEvent: TradeMessageEvent){
-        initData(goodsId = tradeMessageEvent.goodsId,buyOrSell = tradeMessageEvent.buyOrSell,outGoodsCode = tradeMessageEvent.outGoodsCode)
+        initData(goodsId = tradeMessageEvent.goodsId,buyOrSell = tradeMessageEvent.buyOrSell,outGoodsCode = tradeMessageEvent.outGoodsCode,isShowLoading = false)
     }
 
     override fun onDestroy() {

+ 13 - 4
RMA/app/src/main/java/cn/muchinfo/rma/view/base/future/trade/GoodsTradeViewModel.kt

@@ -50,9 +50,13 @@ class GoodsTradeViewModel : BaseViewModel() {
      * @param callback Function2<[@kotlin.ParameterName] Boolean, [@kotlin.ParameterName] Error?, Unit>
      */
     fun queryQuoteDay(
-        goodsCodes: String
+        goodsCodes: String,
+        isShowLoading : Boolean
     ) {
-        loadingDialogStatus.postValue(TaskUiModel.inFlight())
+        if (isShowLoading){
+            loadingDialogStatus.postValue(TaskUiModel.inFlight())
+        }
+
         val params = mutableMapOf<String, String>().apply {
             put("goodsCodes", goodsCodes)
         }
@@ -65,9 +69,14 @@ class GoodsTradeViewModel : BaseViewModel() {
                 if (respData?.isEmpty()?.not() == true) {
                     quoteDayData.postValue(respData.get(0))
                 }
-                loadingDialogStatus.postValue(TaskUiModel.success(msg = "数据请求成功"))
+                if (isShowLoading){
+                    loadingDialogStatus.postValue(TaskUiModel.success(msg = "数据请求成功"))
+                }
+
             } else {
-                loadingDialogStatus.postValue(TaskUiModel.failed(InteractiveException(errorMessage = "数据请求失败")))
+                if (isShowLoading){
+                    loadingDialogStatus.postValue(TaskUiModel.failed(InteractiveException(errorMessage = "数据请求失败")))
+                }
             }
         }
     }

+ 32 - 0
RMA/app/src/main/res/layout/future_list.xml

@@ -1,6 +1,7 @@
 <?xml version="1.0" encoding="utf-8"?>
 <androidx.constraintlayout.widget.ConstraintLayout
     xmlns:android="http://schemas.android.com/apk/res/android"
+    xmlns:tools="http://schemas.android.com/tools"
     android:layout_width="match_parent"
     android:layout_height="match_parent"
     xmlns:app="http://schemas.android.com/apk/res-auto">
@@ -13,6 +14,37 @@
         android:id="@+id/id_head"
         android:layout_height="wrap_content"/>
 
+<!--    <LinearLayout-->
+<!--        android:id="@+id/id_head"-->
+<!--        app:layout_constraintTop_toTopOf="parent"-->
+<!--        android:orientation="vertical"-->
+<!--        android:layout_width="match_parent"-->
+<!--        android:layout_height="@dimen/dp_50"-->
+<!--        tools:ignore="MissingConstraints"-->
+<!--        android:background="@color/main_title_bg_color">-->
+
+<!--        <TextView-->
+<!--            android:layout_width="wrap_content"-->
+<!--            android:textSize="17sp"-->
+<!--            android:id="@+id/id_title"-->
+<!--            android:text="期货"-->
+<!--            android:layout_gravity="center"-->
+<!--            android:layout_marginTop="5dp"-->
+<!--            android:textColor="@color/white"-->
+<!--            android:layout_height="wrap_content"/>-->
+
+<!--        <TextView-->
+<!--            android:visibility="gone"-->
+<!--            android:layout_width="wrap_content"-->
+<!--            android:textSize="13sp"-->
+<!--            android:id="@+id/id_account"-->
+<!--            android:text="12312313123123123"-->
+<!--            android:layout_gravity="center"-->
+<!--            android:textColor="@color/white"-->
+<!--            android:layout_height="wrap_content"/>-->
+
+<!--    </LinearLayout>-->
+
     <!--    first tabs-->
     <com.qmuiteam.qmui.widget.tab.QMUITabSegment
         android:layout_width="match_parent"