BoardFragment.java
9.53 KB
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
package com.huaheng.wms.fragment;
import android.content.Context;
import android.graphics.Color;
import android.os.Bundle;
import android.support.constraint.ConstraintLayout;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import com.github.mikephil.charting.charts.LineChart;
import com.github.mikephil.charting.charts.PieChart;
import com.github.mikephil.charting.components.Description;
import com.huaheng.wms.R;
import com.huaheng.wms.WMSLog;
import com.huaheng.wms.barchart.IncomeBean;
import com.huaheng.wms.bean.InventoryDetails;
import com.huaheng.wms.barchart.LineChartManager;
import com.huaheng.wms.barchart.PieChartManager;
import com.huaheng.wms.https.HttpInterface;
import com.huaheng.wms.https.Subscribers.ProgressSubscriber;
import com.huaheng.wms.https.Subscribers.SubscriberOnNextListener;
import com.huaheng.wms.bean.ShipmentDetail;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
public class BoardFragment extends BaseFragment {
private List<IncomeBean> mReceiptList;//收货量
private List<IncomeBean> mDeliverList;//发货量
private List<ShipmentDetail> mTodayReceiptList;//今日收货详情
private List<ShipmentDetail> mTodayDeliverList;//今日发货详情
private double mTodayReceiptSum;
private double mTodayDeliverSum;
private LineChart lineChart1;
private PieChart mReceiptPieChart;
private PieChart mDeliverPieChart;
private ConstraintLayout cl_shanghai;
private View view_shanghai;
private Context mContext;
private LineChartManager lineChartManager;
@Override
public View layout(LayoutInflater inflater) {
View view = inflater.inflate(R.layout.fragment_board, null);
return view;
}
@Override
public void releaseMemory() {
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View rootView = super.onCreateView(inflater, container, savedInstanceState);
mContext = getContext();
initView(rootView);
get7daysShipment();
return rootView;
}
@Override
public void onHiddenChanged(boolean hidden) {
WMSLog.d("onHiddenChanged :" + hidden);
if(!hidden) {
get7daysShipment();
}
super.onHiddenChanged(hidden);
}
private void get7daysShipment() {
HttpInterface.getInsstance().get7daysShipment(new ProgressSubscriber<List<InventoryDetails>>(mContext, get7daysShipmentListener));
}
SubscriberOnNextListener get7daysShipmentListener = new SubscriberOnNextListener<List<InventoryDetails>>() {
@Override
public void onNext(List<InventoryDetails> InventoryDetails) {
initData(InventoryDetails);
showLineChart();
getTodayShipmentDetail();
}
@Override
public void onError(String str) {
}
};
private void getTodayShipmentDetail() {
HttpInterface.getInsstance().getTodayShipmentDetail(new ProgressSubscriber<List<ShipmentDetail>>(mContext, getTodayShipmentListener));
}
SubscriberOnNextListener getTodayShipmentListener = new SubscriberOnNextListener<List<ShipmentDetail>>() {
@Override
public void onNext(List<ShipmentDetail> shipmentDetails) {
initPieChartData(shipmentDetails);
showPieChart();
}
@Override
public void onError(String str) {
}
};
private void initData(List<InventoryDetails> inventoryDetailList) {
mReceiptList = new ArrayList<>();
mDeliverList = new ArrayList<>();
for(int i=0; i< inventoryDetailList.size(); i++) {
InventoryDetails inventoryDetail = inventoryDetailList.get(i);
String date = inventoryDetail.getDate();
date = date.replace("-", "");
if(i < 7) {
mDeliverList.add(newIncomeBean(date, inventoryDetail.getQty().doubleValue()));
} else {
mReceiptList.add(newIncomeBean(date, inventoryDetail.getQty().doubleValue()));
}
}
}
private IncomeBean newIncomeBean(String tradeDate, double value) {
IncomeBean incomeBean = new IncomeBean();
incomeBean.setTradeDate(tradeDate);
incomeBean.setValue(value);
return incomeBean;
}
private ShipmentDetail newShipmentDetail(String materialName, BigDecimal qty){
ShipmentDetail shipmentDetail = new ShipmentDetail();
shipmentDetail.setMaterialName(materialName);
shipmentDetail.setQty(qty);
return shipmentDetail;
}
private void initView(View rootView) {
lineChart1 = rootView.findViewById(R.id.lineChart);
lineChartManager = new LineChartManager(lineChart1);
cl_shanghai = rootView.findViewById(R.id.cl_shanghai);
view_shanghai = rootView.findViewById(R.id.view_shanghai);
mReceiptPieChart = rootView.findViewById(R.id.pie_chart1);
mDeliverPieChart = rootView.findViewById(R.id.pie_chart2);
}
private void showLineChart() {
//展示图表
if(!getBigger()) {
lineChartManager.showLineChart(mReceiptList, mContext.getString(R.string.volume_of_receipt), getResources().getColor(R.color.blue));
lineChartManager.addLine(mDeliverList, mContext.getString(R.string.delivering_amount), getResources().getColor(R.color.orange));
} else {
lineChartManager.showLineChart(mDeliverList, mContext.getString(R.string.delivering_amount), getResources().getColor(R.color.orange));
lineChartManager.addLine(mReceiptList, mContext.getString(R.string.volume_of_receipt), getResources().getColor(R.color.blue));
}
//设置曲线填充色 以及 MarkerView
lineChartManager.setMarkerView(mContext);
}
private void initPieChartData(List<ShipmentDetail> shipmentDetails) {
mTodayDeliverList = new ArrayList<>();
mTodayReceiptList = new ArrayList<>();
int flag = 0;
for(ShipmentDetail shipmentDetail : shipmentDetails) {
String materialName = shipmentDetail.getMaterialName();
if(materialName.equals("delete")) {
flag = 1;
continue;
}
if(flag == 0) {
mTodayDeliverList.add(shipmentDetail);
} else {
mTodayReceiptList.add(shipmentDetail);
}
}
Collections.sort(mTodayDeliverList);
Collections.sort(mTodayReceiptList);
mTodayReceiptSum = mReceiptList.get(6).getValue();
mTodayDeliverSum = mDeliverList.get(6).getValue();
}
private void showPieChart() {
Description description = new Description();
description.setText("");
mReceiptPieChart.setDescription(description);//饼状图中间的文字
mDeliverPieChart.setDescription(description);
List<String> names = new ArrayList<>(); //每个模块的内容描述
List<Float> date = new ArrayList<>(); //每个模块的值(占比率)
float fiveQty = 0;
for(int i=0; i< mTodayDeliverList.size(); i++) {
if(i > 4 && (i == mTodayDeliverList.size() - 1)) {
names.add(mContext.getString(R.string.other));
date.add((float)mTodayDeliverSum - fiveQty);
} else if(i <= 4) {
names.add(mTodayDeliverList.get(i).getMaterialName());
date.add(mTodayDeliverList.get(i).getQty().floatValue());
fiveQty = fiveQty + mTodayDeliverList.get(i).getQty().floatValue();
}
}
List<String> names2 = new ArrayList<>(); //每个模块的内容描述
List<Float> date2 = new ArrayList<>(); //每个模块的值(占比率)
fiveQty = 0;
for(int i=0; i< mTodayReceiptList.size(); i++) {
if(i > 4 && (i == mTodayReceiptList.size() - 1)) {
names2.add(mContext.getString(R.string.other));
date2.add((float)mTodayReceiptSum - fiveQty);
} else if(i<=4) {
names2.add(mTodayReceiptList.get(i).getMaterialName());
date2.add(mTodayReceiptList.get(i).getQty().floatValue());
fiveQty = fiveQty + mTodayReceiptList.get(i).getQty().floatValue();
}
}
List<Integer> colors = new ArrayList<>(); //每个模块的颜色
colors.add(Color.RED);
colors.add(Color.GREEN);
colors.add(Color.BLUE);
colors.add(Color.DKGRAY);
colors.add(Color.rgb(0xff,0x40,0x81));
colors.add(Color.MAGENTA);
//饼状图管理类
PieChartManager pieChartManager1 = new PieChartManager(mReceiptPieChart);
pieChartManager1.setSolidPieChart(names2, date2, colors);
PieChartManager pieChartManager2 = new PieChartManager(mDeliverPieChart);
pieChartManager2.setSolidPieChart(names, date, colors);
}
private boolean getBigger() {
List<Double> qtyList = new ArrayList<>();
for(IncomeBean incomeBean : mReceiptList) {
qtyList.add(incomeBean.getValue());
}
for(IncomeBean compositeIndexBean : mDeliverList) {
qtyList.add(compositeIndexBean.getValue());
}
double max = Collections.max(qtyList);
for(int i=0; i<qtyList.size(); i++) {
double value = qtyList.get(i);
if(max == value) {
if(i<7) {
return false;
} else {
return true;
}
}
}
return false;
}
}