|
|
@@ -5,6 +5,9 @@ import cn.muchinfo.rma.global.GlobalDataCollection
|
|
|
import cn.muchinfo.rma.global.data.BannerData
|
|
|
import cn.muchinfo.rma.global.data.NoticeData
|
|
|
import cn.muchinfo.rma.global.data.WrAverageTradePriceData
|
|
|
+import cn.muchinfo.rma.global.data.account.loginQeruy.GoodsInfo
|
|
|
+import cn.muchinfo.rma.global.data.chart.HistoryDatas
|
|
|
+import cn.muchinfo.rma.global.database.DataBase
|
|
|
import cn.muchinfo.rma.netManage.base.ResponseCallback
|
|
|
import cn.muchinfo.rma.netManage.utils.MyOkHttpUtils
|
|
|
import cn.muchinfo.rma.view.MyApplication
|
|
|
@@ -15,6 +18,8 @@ import cn.muchinfo.rma.view.base.app.Constant
|
|
|
import cn.muchinfo.rma.view.base.home.yrdz.market.IndexData
|
|
|
import com.blankj.utilcode.util.LogUtils
|
|
|
import com.blankj.utilcode.util.SPUtils
|
|
|
+import kotlinx.coroutines.GlobalScope
|
|
|
+import kotlinx.coroutines.launch
|
|
|
import mtp.polymer.com.autowidget.utils.TaskUiModel
|
|
|
import okhttp3.Call
|
|
|
import java.lang.Exception
|
|
|
@@ -38,38 +43,139 @@ class TjmdHomeViewModel : BaseViewModel(){
|
|
|
*/
|
|
|
val noticeDataList : MutableLiveData<List<NoticeData>> = MutableLiveData()
|
|
|
|
|
|
- fun setDataList(){
|
|
|
|
|
|
- val list = arrayListOf(
|
|
|
- TjmdDemoData(goodsName = "橡胶2019",price = 12434.0,gains = 0.0021,forehead = +132.2,id = "1"),
|
|
|
- TjmdDemoData(goodsName = "焦炭2019",price = 4164.2,gains = 0.023,forehead = +113.2,id = "2"),
|
|
|
- TjmdDemoData(goodsName = "棕榈油",price = 4164.2,gains = 0.023,forehead = +113.2,id = "2")
|
|
|
- )
|
|
|
+ val sonItemList : MutableLiveData<List<GoodsInfo>> = MutableLiveData()
|
|
|
|
|
|
+
|
|
|
+ fun setOnItemClick(goodsid : String){
|
|
|
+ val newDataList = arrayListOf<TjmdDemoData>()
|
|
|
+ dataList.value?.forEach {
|
|
|
+ if (it.goodsid == goodsid){
|
|
|
+ newDataList.add(it.copy(isClick = 1))
|
|
|
+ }else{
|
|
|
+ newDataList.add(it.copy(isClick = 0))
|
|
|
+ }
|
|
|
+ }
|
|
|
+ dataList.postValue(newDataList)
|
|
|
+ }
|
|
|
+
|
|
|
+ //天津麦顿首页初始化参考行情以及掉期商品数据
|
|
|
+ fun setDataList(tag: String,callback: (isCompleted: Boolean, err: Error?) -> Unit){
|
|
|
+ //组装掉期商品
|
|
|
+ val sonlist = arrayListOf<GoodsInfo>()
|
|
|
+ val allList = DataBase.getInstance().goodsInfoDao().all
|
|
|
+ //需要知道掉期trademodel
|
|
|
+ allList.forEach {data ->
|
|
|
+ if (data.trademode == 46 && data.goodsstatus == 3){
|
|
|
+ sonlist.add(data)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ sonItemList.postValue(sonlist)
|
|
|
+
|
|
|
+ //组装参考行情商品
|
|
|
+ val list = arrayListOf<TjmdDemoData>()
|
|
|
+ allList.forEach {data ->
|
|
|
+ if (data.trademode == 99 && data.goodsstatus == 3){
|
|
|
+ if (allList.indexOf(data) == 0){
|
|
|
+ list.add(TjmdDemoData(goodsid = data.goodsid.toString(),isClick = 1,goodsInfo = data))
|
|
|
+ }else{
|
|
|
+ list.add(TjmdDemoData(goodsid = data.goodsid.toString(),isClick = 0,goodsInfo = data))
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
dataList.postValue(list)
|
|
|
+ if (list.size > 0){
|
|
|
+ queryKChartData(list.get(0).goodsInfo?.goodscode ?: "","11")
|
|
|
+ }
|
|
|
+
|
|
|
+ if (list.size > 4){
|
|
|
+ queryQuoteDay(tag,0,10,list){isCompleted, err ->
|
|
|
+ callback(isCompleted, err)
|
|
|
+ }
|
|
|
+ }else{
|
|
|
+ queryQuoteDay(tag,0,list.size,list){isCompleted, err ->
|
|
|
+ callback(isCompleted, err)
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 请求盘面信息
|
|
|
+ * @param first Int
|
|
|
+ * @param last Int
|
|
|
+ * @param callback Function2<[@kotlin.ParameterName] Boolean, [@kotlin.ParameterName] Error?, Unit>
|
|
|
+ */
|
|
|
+ fun queryQuoteDay(
|
|
|
+ tag: String,
|
|
|
+ first: Int,
|
|
|
+ last: Int,
|
|
|
+ list : List<TjmdDemoData> = arrayListOf(),
|
|
|
+ callback: (isCompleted: Boolean, err: Error?) -> Unit
|
|
|
+ ) {
|
|
|
+ val goodsCodes = getgoodsCodes(first, last,list)
|
|
|
+ val params = mutableMapOf<String, String>().apply {
|
|
|
+ put("goodsCodes", goodsCodes)
|
|
|
+ }
|
|
|
+ MyApplication.getInstance()?.futureManager?.queryQuoteDay(params = params) { isSuccess, respData, error ->
|
|
|
+ if (isSuccess) {
|
|
|
+ callback(true, null)
|
|
|
+ } else {
|
|
|
+ callback(false, error)
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ list.subList(first, last).let { addSubscriptQuote(tag = tag, goodsInfoList = it) }
|
|
|
+ }
|
|
|
+
|
|
|
+ //获取本商品的盘面信息的同时,还要获取关联商品的盘面信息
|
|
|
+ fun getgoodsCodes(first: Int, last: Int,list : List<TjmdDemoData>): String {
|
|
|
+ var goodsCodes = ""
|
|
|
+ val newList = list.subList(first, last)
|
|
|
+ newList.forEach {
|
|
|
+ goodsCodes = goodsCodes + it.goodsInfo?.goodscode + ","
|
|
|
+ }
|
|
|
+ return goodsCodes
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 订阅行情
|
|
|
+ * @param tag String
|
|
|
+ * @param goodsInfoList List<GoodsInfo>
|
|
|
+ */
|
|
|
+ fun addSubscriptQuote(tag: String, goodsInfoList: List<TjmdDemoData>) {
|
|
|
+ GlobalScope.launch {
|
|
|
+ MyApplication.getInstance()?.quoteManager?.addSubscriptQuote(
|
|
|
+ tag = tag, goodsCodeSet = goodsInfoList.map { it.goodsInfo?.goodscode ?: "" }.toSet()
|
|
|
+ ) { isCompleted, err ->
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
|
|
|
+
|
|
|
/**
|
|
|
* 历史走势图
|
|
|
*/
|
|
|
- val wrAverageTradePriceDataList : MutableLiveData<List<ChartViewData>> = MutableLiveData()
|
|
|
-
|
|
|
- val sonItemList : MutableLiveData<List<String>> = MutableLiveData()
|
|
|
-
|
|
|
- fun resetChartViewData(){
|
|
|
- val chartList = arrayListOf(
|
|
|
- ChartViewData(price = 12334.2,time = "09-01",gains = "1.2%"),
|
|
|
- ChartViewData(price = 12326.4,time = "09-02",gains = "0.2%"),
|
|
|
- ChartViewData(price = 12462.3,time = "09-03",gains = "0.22%"),
|
|
|
- ChartViewData(price = 12663.4,time = "09-04",gains = "0.29%"),
|
|
|
- ChartViewData(price = 12902.3,time = "09-05",gains = "1.2%"),
|
|
|
- ChartViewData(price = 14361.5,time = "09-06",gains = "2.2%"),
|
|
|
- ChartViewData(price = 11346.9,time = "09-07",gains = "2.8%")
|
|
|
- )
|
|
|
- wrAverageTradePriceDataList.postValue(chartList)
|
|
|
- val sonItemDataList = arrayListOf<String>("橡胶20天","橡胶30天","橡胶60天","焦炭20天","焦炭30天","焦炭60天","棕榈油20天","棕榈油30天","棕榈油60天")
|
|
|
- sonItemList.postValue(sonItemDataList)
|
|
|
+ val wrAverageTradePriceDataList : MutableLiveData<List<HistoryDatas>> = MutableLiveData()
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 请求k线数据
|
|
|
+ */
|
|
|
+ fun queryKChartData(goodsCode: String, type: String){
|
|
|
+ val params = mutableMapOf<String, String>().apply {
|
|
|
+ put("goodsCode", goodsCode)
|
|
|
+ put("cycleType", type)
|
|
|
+ put("count", "30")
|
|
|
+ put("isAsc", "true")
|
|
|
+ }
|
|
|
+ MyApplication.getInstance()?.chartManager?.queryHistoryDatas(params = params) { isSuccess, respData, _ ->
|
|
|
+ if (isSuccess) {
|
|
|
+ wrAverageTradePriceDataList.postValue(respData)
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
/**
|