| | |
| | | import android.text.TextUtils; |
| | | import android.view.View; |
| | | |
| | | |
| | | import androidx.appcompat.content.res.AppCompatResources; |
| | | |
| | | import com.bigkoo.pickerview.builder.TimePickerBuilder; |
| | |
| | | import com.github.AAChartModel.AAChartCore.AAChartCreator.AAChartModel; |
| | | import com.github.AAChartModel.AAChartCore.AAChartCreator.AAChartView; |
| | | import com.github.AAChartModel.AAChartCore.AAChartCreator.AAMoveOverEventMessageModel; |
| | | import com.hdl.linkpm.sdk.core.exception.HDLException; |
| | | import com.hdl.photovoltaic.R; |
| | | import com.hdl.photovoltaic.base.CustomBaseFragment; |
| | | import com.hdl.photovoltaic.config.ConstantManage; |
| | | import com.hdl.photovoltaic.config.UserConfigManage; |
| | | import com.hdl.photovoltaic.databinding.FragmentHomePageBinding; |
| | | import com.hdl.photovoltaic.enums.HomepageTitleTabSwitch; |
| | | import com.hdl.photovoltaic.enums.TimeType; |
| | | import com.hdl.photovoltaic.listener.CloudCallBeak; |
| | | import com.hdl.photovoltaic.other.HdlDeviceLogic; |
| | | import com.hdl.photovoltaic.other.HdlLogLogic; |
| | | import com.hdl.photovoltaic.other.HdlPowerStationDataStatisticsLogic; |
| | | import com.hdl.photovoltaic.other.HdlThreadLogic; |
| | | import com.hdl.photovoltaic.ui.bean.DataOverBean; |
| | | import com.hdl.photovoltaic.ui.bean.SocialContributionBean; |
| | | import com.hdl.photovoltaic.ui.bean.StatisticsBean; |
| | | import com.hdl.photovoltaic.utils.TimeUtils; |
| | | import com.hdl.sdk.link.core.bean.eventbus.BaseEventBus; |
| | | |
| | |
| | | |
| | | import java.util.Calendar; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | |
| | | |
| | | /** |
| | |
| | | AAChartModel aaChartModel; |
| | | |
| | | |
| | | private TimeType timeType = TimeType.day;//时间类型(默认:天) |
| | | private String[] fieldNames = {"00:00", "02:00", "05:00", "07:00", "09:00", "17:00", "22:00", "23:59"};//图标X轴坐标值的数组 |
| | | private Object[] fieldValues = {35, 70.5, 150.5, 135, 170, 205, 222, 245};//图标Y轴坐标值的数组 |
| | | |
| | | |
| | | private String timeType = TimeType.day;//时间类型(默认:天) |
| | | |
| | | |
| | | @Override |
| | |
| | | initView(); |
| | | //初始化界面监听器 |
| | | initEvent(); |
| | | //读取数据 |
| | | readDate(); |
| | | |
| | | } |
| | | |
| | | /** |
| | | * 读取数据 |
| | | */ |
| | | private void readDate() { |
| | | HdlThreadLogic.runSubThread(new Runnable() { |
| | | @Override |
| | | public void run() { |
| | | getDataOver(); |
| | | getStatistics(); |
| | | getSocialContribution(); |
| | | |
| | | } |
| | | }); |
| | | } |
| | | |
| | | private void initEvent() { |
| | |
| | | viewBinding.dayTv.setOnClickListener(new View.OnClickListener() { |
| | | @Override |
| | | public void onClick(View v) { |
| | | if (timeType.equals(TimeType.day)) { |
| | | //点击同一个类型 |
| | | return; |
| | | } |
| | | timeType = TimeType.day; |
| | | |
| | | viewBinding.dayTv.setBackground(AppCompatResources.getDrawable(_mActivity, R.drawable.time_selected_38c494)); |
| | |
| | | |
| | | String dataStr = TimeUtils.getDateTimestamp(getCurrentTimestamp(), getTimeDateFormat()); |
| | | viewBinding.yearMonthDayTv.setText(dataStr); |
| | | setUpAAChartView(); |
| | | getStatistics(); |
| | | |
| | | } |
| | | }); |
| | |
| | | viewBinding.monthTv.setOnClickListener(new View.OnClickListener() { |
| | | @Override |
| | | public void onClick(View v) { |
| | | if (timeType.equals(TimeType.month)) { |
| | | //点击同一个类型 |
| | | return; |
| | | } |
| | | timeType = TimeType.month; |
| | | viewBinding.dayTv.setBackground(AppCompatResources.getDrawable(_mActivity, R.color.text_00000000)); |
| | | viewBinding.dayTv.setTextColor(_mActivity.getColor(R.color.text_40000000)); |
| | |
| | | viewBinding.homePageStationSelectTimeLl.setVisibility(View.VISIBLE); |
| | | String dataStr = TimeUtils.getDateTimestamp(getCurrentTimestamp(), getTimeDateFormat()); |
| | | viewBinding.yearMonthDayTv.setText(dataStr); |
| | | setUpAAChartView(); |
| | | getStatistics(); |
| | | |
| | | |
| | | } |
| | |
| | | viewBinding.yearTv.setOnClickListener(new View.OnClickListener() { |
| | | @Override |
| | | public void onClick(View v) { |
| | | if (timeType.equals(TimeType.year)) { |
| | | //点击同一个类型 |
| | | return; |
| | | } |
| | | timeType = TimeType.year; |
| | | viewBinding.dayTv.setBackground(AppCompatResources.getDrawable(_mActivity, R.color.text_00000000)); |
| | | viewBinding.dayTv.setTextColor(_mActivity.getColor(R.color.text_40000000)); |
| | |
| | | viewBinding.homePageStationSelectTimeLl.setVisibility(View.VISIBLE); |
| | | String dataStr = TimeUtils.getDateTimestamp(getCurrentTimestamp(), getTimeDateFormat()); |
| | | viewBinding.yearMonthDayTv.setText(dataStr); |
| | | setUpAAChartView(); |
| | | getStatistics(); |
| | | } |
| | | }); |
| | | //生命期 |
| | | viewBinding.lifeCycleTv.setOnClickListener(new View.OnClickListener() { |
| | | @Override |
| | | public void onClick(View v) { |
| | | timeType = TimeType.lifecycle; |
| | | if (timeType.equals(TimeType.all)) { |
| | | //点击同一个类型 |
| | | return; |
| | | } |
| | | timeType = TimeType.all; |
| | | viewBinding.dayTv.setBackground(AppCompatResources.getDrawable(_mActivity, R.color.text_00000000)); |
| | | viewBinding.dayTv.setTextColor(_mActivity.getColor(R.color.text_40000000)); |
| | | |
| | |
| | | viewBinding.v2.setVisibility(View.VISIBLE); |
| | | viewBinding.v3.setVisibility(View.GONE); |
| | | viewBinding.homePageStationSelectTimeLl.setVisibility(View.GONE); |
| | | |
| | | setUpAAChartView(); |
| | | getStatistics(); |
| | | |
| | | } |
| | | }); |
| | |
| | | }); |
| | | } |
| | | |
| | | private void initView() { |
| | | |
| | | String dataStr = TimeUtils.getDateTimestamp(getCurrentTimestamp(), getTimeDateFormat()); |
| | | viewBinding.yearMonthDayTv.setText(dataStr); |
| | | |
| | | String installed_capacity = getString(R.string.installed_capacity) + "(" + HdlDeviceLogic.kWp + ")"; |
| | | viewBinding.homePageStationInfoRl1Text2Tv.setText(installed_capacity); |
| | | String generated_power = getString(R.string.generated_power) + "(" + HdlDeviceLogic.kW + ")"; |
| | | viewBinding.homePageStationInfoRl1Text4Tv.setText(generated_power); |
| | | String generation = getString(R.string.generation) + "(" + HdlDeviceLogic.kWp + ")"; |
| | | viewBinding.homePageStationInfoRl1TitleTv.setText(generation); |
| | | |
| | | viewBinding.homePageStationInfoRl2DayIc.dataTypeTv.setText(R.string.day_power_generation); |
| | | viewBinding.homePageStationInfoRl2MonIc.dataTypeTv.setText(R.string.month_power_generation); |
| | | viewBinding.homePageStationInfoRl2YearIc.dataTypeTv.setText(R.string.year_power_generation); |
| | | viewBinding.homePageStationInfoRl2CumulativeIc.dataTypeTv.setText(R.string.cumulative_power_generation); |
| | | |
| | | |
| | | viewBinding.dayTv.setBackground(AppCompatResources.getDrawable(_mActivity, R.drawable.time_selected_38c494)); |
| | | viewBinding.dayTv.setTextColor(_mActivity.getColor(R.color.text_38C494)); |
| | | viewBinding.monthTv.setBackground(AppCompatResources.getDrawable(_mActivity, R.color.text_00000000)); |
| | | viewBinding.monthTv.setTextColor(_mActivity.getColor(R.color.text_40000000)); |
| | | viewBinding.yearTv.setBackground(AppCompatResources.getDrawable(_mActivity, R.color.text_00000000)); |
| | | viewBinding.yearTv.setTextColor(_mActivity.getColor(R.color.text_40000000)); |
| | | viewBinding.lifeCycleTv.setBackground(AppCompatResources.getDrawable(_mActivity, R.color.text_00000000)); |
| | | viewBinding.lifeCycleTv.setTextColor(_mActivity.getColor(R.color.text_40000000)); |
| | | viewBinding.v1.setVisibility(View.GONE); |
| | | viewBinding.v2.setVisibility(View.VISIBLE); |
| | | viewBinding.v3.setVisibility(View.VISIBLE); |
| | | viewBinding.homePageStationSelectTimeLl.setVisibility(View.VISIBLE); |
| | | setUpAAChartView();//图表加载 |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 时间选择器 |
| | | */ |
| | | private void selectedTimePickerBuilder() { |
| | | String currDate = viewBinding.yearMonthDayTv.getText().toString(); |
| | | if (TextUtils.isEmpty(currDate)) { |
| | | return; |
| | | } |
| | | //时间选择器 |
| | | Calendar selectedDate = TimeUtils.stringToCalendar(currDate, getTimeDateFormat()); |
| | | Calendar startDate = Calendar.getInstance(); |
| | |
| | | boolean day = true; |
| | | boolean month = true; |
| | | boolean year = true; |
| | | if (timeType == TimeType.month) { |
| | | if (timeType.equals(TimeType.month)) { |
| | | day = false; |
| | | } else if (timeType == TimeType.year) { |
| | | } else if (timeType.equals(TimeType.year)) { |
| | | day = false; |
| | | month = false; |
| | | } |
| | |
| | | public void onTimeSelect(Date date, View v) {//选中事件回调 |
| | | String timeDateFormat = getTimeDateFormat(); |
| | | String time = TimeUtils.dateToString(date, timeDateFormat); |
| | | if (viewBinding.yearMonthDayTv.getText().toString().equals(time)) { |
| | | //表示同一个时间 |
| | | return; |
| | | } |
| | | viewBinding.yearMonthDayTv.setText(time); |
| | | getStatistics(); |
| | | } |
| | | }).setType(new boolean[]{year, month, day, false, false, false})// 默认全部显示 |
| | | .setCancelText(_mActivity.getString(R.string.loading_cancel))//取消按钮文字 |
| | |
| | | private void setUpAAChartView() { |
| | | aaChartView = viewBinding.AAChartView; |
| | | aaChartView.callBack = this; |
| | | if (TimeType.day == timeType) { |
| | | aaChartModel = BasicChartComposer.configureAreaChart(); |
| | | } else if (TimeType.month == timeType |
| | | || TimeType.year == timeType |
| | | || TimeType.lifecycle == timeType) { |
| | | aaChartModel = configureColorfulColumnChart(); |
| | | if (TimeType.day.equals(timeType)) { |
| | | aaChartModel = BasicChartComposer.configureAreaChart("Pv发电功率", fieldNames, fieldValues); |
| | | } else if (TimeType.month.equals(timeType) |
| | | || TimeType.year.equals(timeType) |
| | | || TimeType.all.equals(timeType)) { |
| | | aaChartModel = configureColorfulColumnChart("Pv发电功率", fieldNames, fieldValues); |
| | | } |
| | | aaChartView.aa_drawChartWithChartModel(aaChartModel); |
| | | } |
| | | |
| | | private void initView() { |
| | | |
| | | String dataStr = TimeUtils.getDateTimestamp(getCurrentTimestamp(), getTimeDateFormat()); |
| | | viewBinding.yearMonthDayTv.setText(dataStr); |
| | | |
| | | String installed_capacity = getString(R.string.installed_capacity) + "(" + HdlDeviceLogic.kWp + ")"; |
| | | viewBinding.infoRl1Text2Tv.setText(installed_capacity); |
| | | String generated_power = getString(R.string.generated_power) + "(" + HdlDeviceLogic.kW + ")"; |
| | | viewBinding.infoRl1Text4Tv.setText(generated_power); |
| | | String generation = getString(R.string.generation) + "(" + HdlDeviceLogic.kWp + ")"; |
| | | viewBinding.homePageStationInfoRl1TitleTv.setText(generation); |
| | | |
| | | viewBinding.homePageStationInfoRl2DayIc.dataTypeTv.setText(R.string.day_power_generation); |
| | | viewBinding.homePageStationInfoRl2MonIc.dataTypeTv.setText(R.string.month_power_generation); |
| | | viewBinding.homePageStationInfoRl2YearIc.dataTypeTv.setText(R.string.year_power_generation); |
| | | viewBinding.homePageStationInfoRl2CumulativeIc.dataTypeTv.setText(R.string.cumulative_power_generation); |
| | | |
| | | viewBinding.unitTv.setText(HdlDeviceLogic.kW); |
| | | viewBinding.dayTv.setBackground(AppCompatResources.getDrawable(_mActivity, R.drawable.time_selected_38c494)); |
| | | viewBinding.dayTv.setTextColor(_mActivity.getColor(R.color.text_38C494)); |
| | | viewBinding.monthTv.setBackground(AppCompatResources.getDrawable(_mActivity, R.color.text_00000000)); |
| | | viewBinding.monthTv.setTextColor(_mActivity.getColor(R.color.text_40000000)); |
| | | viewBinding.yearTv.setBackground(AppCompatResources.getDrawable(_mActivity, R.color.text_00000000)); |
| | | viewBinding.yearTv.setTextColor(_mActivity.getColor(R.color.text_40000000)); |
| | | viewBinding.lifeCycleTv.setBackground(AppCompatResources.getDrawable(_mActivity, R.color.text_00000000)); |
| | | viewBinding.lifeCycleTv.setTextColor(_mActivity.getColor(R.color.text_40000000)); |
| | | viewBinding.v1.setVisibility(View.GONE); |
| | | viewBinding.v2.setVisibility(View.VISIBLE); |
| | | viewBinding.v3.setVisibility(View.VISIBLE); |
| | | viewBinding.homePageStationSelectTimeLl.setVisibility(View.VISIBLE); |
| | | setUpAAChartView();//图表加载 |
| | | } |
| | | |
| | | |
| | |
| | | |
| | | |
| | | /** |
| | | * 获取统计概览数据(公司维度) |
| | | */ |
| | | private void getDataOver() { |
| | | HdlPowerStationDataStatisticsLogic.getInstance().getDataOver(new CloudCallBeak<DataOverBean>() { |
| | | @Override |
| | | public void onSuccess(DataOverBean dataOverBean) { |
| | | if (dataOverBean == null) { |
| | | return; |
| | | } |
| | | viewBinding.infoRl1Text1Tv.setText(dataOverBean.getInstalledCapacity()); |
| | | viewBinding.infoRl1Text3Tv.setText(dataOverBean.getPower()); |
| | | viewBinding.infoRl1FText1Tv.setText(dataOverBean.getPowerRatio()); |
| | | |
| | | viewBinding.homePageStationInfoRl2DayIc.dataTv.setText(dataOverBean.getTodayElectricity()); |
| | | viewBinding.homePageStationInfoRl2MonIc.dataTv.setText(dataOverBean.getMonthElectricity()); |
| | | viewBinding.homePageStationInfoRl2YearIc.dataTv.setText(dataOverBean.getYearElectricity()); |
| | | viewBinding.homePageStationInfoRl2CumulativeIc.dataTv.setText(dataOverBean.getTotalElectricity()); |
| | | } |
| | | |
| | | @Override |
| | | public void onFailure(HDLException e) { |
| | | |
| | | } |
| | | }); |
| | | } |
| | | |
| | | /** |
| | | * 发电量统计(公司维度) |
| | | */ |
| | | private void getStatistics() { |
| | | String currDate = viewBinding.yearMonthDayTv.getText().toString(); |
| | | HdlPowerStationDataStatisticsLogic.getInstance().getStatistics(currDate, timeType, new CloudCallBeak<List<StatisticsBean>>() { |
| | | @Override |
| | | public void onSuccess(List<StatisticsBean> list) { |
| | | if (list == null || list.size() == 0) { |
| | | return; |
| | | } |
| | | String[] keys = new String[list.size()]; |
| | | Object[] values = new Object[list.size()]; |
| | | for (int i = 0; i < list.size(); i++) { |
| | | keys[i] = list.get(i).getFieldName(); |
| | | values[i] = list.get(i).getFieldValue(); |
| | | } |
| | | fieldNames = keys; |
| | | fieldValues = values; |
| | | setUpAAChartView(); |
| | | } |
| | | |
| | | @Override |
| | | public void onFailure(HDLException e) { |
| | | |
| | | } |
| | | }); |
| | | } |
| | | |
| | | /** |
| | | * 发电量统计(公司维度) |
| | | */ |
| | | private void getSocialContribution() { |
| | | HdlPowerStationDataStatisticsLogic.getInstance().getSocialContribution(new CloudCallBeak<SocialContributionBean>() { |
| | | @Override |
| | | public void onSuccess(SocialContributionBean socialContributionBean) { |
| | | if (socialContributionBean == null) { |
| | | return; |
| | | } |
| | | viewBinding.socialContributionData1Tv.setText(socialContributionBean.getCoal()); |
| | | viewBinding.socialContributionData2Tv.setText(socialContributionBean.getCo2()); |
| | | viewBinding.socialContributionData3Tv.setText(socialContributionBean.getTreePlanting()); |
| | | } |
| | | |
| | | @Override |
| | | public void onFailure(HDLException e) { |
| | | |
| | | } |
| | | }); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 获取当前系统日期时间戳 |
| | | * |
| | | * @return 时间戳 |
| | |
| | | private String getTimeDateFormat() { |
| | | String timeDateFormat = TimeUtils.zhDateYearMonthDayFormat; |
| | | switch (timeType) { |
| | | case day: { |
| | | case TimeType.day: { |
| | | timeDateFormat = TimeUtils.zhDateYearMonthDayFormat; |
| | | if (!UserConfigManage.getInstance().isZh()) { |
| | | timeDateFormat = TimeUtils.enDateYearMonthDayFormat; |
| | | } |
| | | } |
| | | break; |
| | | case month: { |
| | | case TimeType.month: { |
| | | timeDateFormat = TimeUtils.zhDateYearMonthFormat; |
| | | if (!UserConfigManage.getInstance().isZh()) { |
| | | timeDateFormat = TimeUtils.enDateYearMonthFormat; |
| | | } |
| | | } |
| | | break; |
| | | case year: |
| | | case lifecycle: { |
| | | case TimeType.year: |
| | | case TimeType.all: { |
| | | timeDateFormat = TimeUtils.zhDateYearFormat; |
| | | if (!UserConfigManage.getInstance().isZh()) { |
| | | timeDateFormat = TimeUtils.enDateYearFormat; |
| | |
| | | |
| | | } |
| | | return timeDateFormat; |
| | | } |
| | | |
| | | public enum TimeType { |
| | | day, month, year, lifecycle |
| | | } |
| | | |
| | | |