package cn.flightfeather.thirdappmodule.dataanalysis
|
|
import android.app.Dialog
|
import android.content.Context
|
import android.content.Intent
|
import android.os.Bundle
|
import android.os.Handler
|
import android.support.v4.app.Fragment
|
import android.support.v7.widget.GridLayoutManager
|
import android.support.v7.widget.LinearLayoutManager
|
import android.support.v7.widget.RecyclerView
|
import android.view.LayoutInflater
|
import android.view.View
|
import android.view.ViewGroup
|
import android.widget.TextView
|
import butterknife.ButterKnife
|
import butterknife.Unbinder
|
import cn.flightfeather.thirdappmodule.CommonApplication
|
import cn.flightfeather.thirdappmodule.R
|
import cn.flightfeather.thirdappmodule.adapter.AllRecyclerViewAdapter
|
import cn.flightfeather.thirdappmodule.bean.entity.Domainitem
|
import cn.flightfeather.thirdappmodule.bean.vo.RankVo
|
import cn.flightfeather.thirdappmodule.bean.vo.RankVo.SceneRank
|
import cn.flightfeather.thirdappmodule.bean.vo.RankVo.TownRank
|
import cn.flightfeather.thirdappmodule.bean.vo.StatisticsVo
|
import cn.flightfeather.thirdappmodule.bean.vo.TaskFrequencyVo
|
import cn.flightfeather.thirdappmodule.bean.vo.TaskFrequencyVo.FrequencyInfo
|
import cn.flightfeather.thirdappmodule.bean.vo.TaskVo
|
import cn.flightfeather.thirdappmodule.dataanalysis.rank.AnalysisRankActivity
|
import cn.flightfeather.thirdappmodule.httpservice.ProblemListService
|
import cn.flightfeather.thirdappmodule.httpservice.TaskService
|
import cn.flightfeather.thirdappmodule.util.*
|
import com.ping.greendao.gen.DomainitemDao
|
import kotlinx.android.synthetic.main.fragment_analysis_over_view.*
|
import kotlinx.android.synthetic.main.layout_no_data.*
|
import kotlinx.android.synthetic.main.tab_time_swtich.*
|
import retrofit2.Call
|
import retrofit2.Callback
|
import retrofit2.Response
|
import retrofit2.Retrofit
|
import java.util.*
|
|
/**
|
* 2018.12.25 created by riku
|
* 分析总览界面
|
* 综合简略展示各统计概况:
|
* 任务进度、街镇排名、场景排名、问题类型分布
|
*/
|
class AnalysisOverViewFragment : Fragment() {
|
private val TITLE = "总览"
|
private var app: CommonApplication? = null
|
private var retrofit: Retrofit? = null
|
private var unbinder: Unbinder? = null
|
private var curSceneTypeId = "1" //当前场景类型
|
private var curSceneTypeName = "工地" //当前场景类型
|
private var rankVo: RankVo? = RankVo()
|
private val maxShowItems = 3
|
private var dialog: Dialog? = null
|
private var container: ViewGroup? = null
|
|
override fun onCreateView(
|
inflater: LayoutInflater, container: ViewGroup?,
|
savedInstanceState: Bundle?
|
): View? {
|
// Inflate the layout for this fragment
|
this.container = container
|
val view = inflater.inflate(R.layout.fragment_analysis_over_view, container, false)
|
unbinder = ButterKnife.bind(this, view)
|
return view
|
}
|
|
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
super.onViewCreated(view, savedInstanceState)
|
app = activity?.application as CommonApplication
|
retrofit = app?.retrofit
|
initPopup()
|
initToolBar()
|
initBlock1()
|
initBlock2()
|
initBlock3()
|
initBlock4()
|
initPanel()
|
initClickListener()
|
}
|
|
override fun onAttach(context: Context) {
|
super.onAttach(context)
|
}
|
|
override fun onDetach() {
|
super.onDetach()
|
}
|
|
/**
|
* Called when the fragment is no longer in use. This is called
|
* after [.onStop] and before [.onDetach].
|
*/
|
override fun onDestroy() {
|
super.onDestroy()
|
if (unbinder != null) {
|
unbinder!!.unbind()
|
}
|
}
|
|
//</editor-fold>
|
//<editor-fold desc="标题栏">
|
private fun initToolBar() {
|
action_bar!!.findViewById<View>(R.id.spinner_topclass_task).visibility = View.GONE
|
action_bar!!.findViewById<View>(R.id.img_left).visibility = View.GONE
|
action_bar!!.findViewById<View>(R.id.img_right).visibility = View.INVISIBLE
|
action_bar!!.findViewById<View>(R.id.ll_menu_text).visibility = View.VISIBLE
|
val title = action_bar!!.findViewById<TextView>(R.id.actionbar_title)
|
title.text = TITLE
|
// title.setGravity(Gravity.CENTER_HORIZONTAL);
|
// ViewGroup.LayoutParams layoutParams = title.getLayoutParams();
|
// layoutParams.width = ViewGroup.LayoutParams.MATCH_PARENT;
|
}
|
|
var allTaskVoList: MutableList<TaskVo> = ArrayList()
|
var showingTasks: MutableList<TaskVo> = ArrayList()
|
var offset = 0
|
private fun initPanel() {
|
showDialog()
|
//顶层任务
|
val getTopClassTaskList = retrofit!!.create(TaskService::class.java).getTopClassTaskList(0)
|
getTopClassTaskList.enqueue(object : Callback<ArrayList<TaskVo>?> {
|
override fun onResponse(call: Call<ArrayList<TaskVo>?>, response: Response<ArrayList<TaskVo>?>) {
|
showingTasks.clear()
|
allTaskVoList.clear()
|
if (response.body() != null) {
|
allTaskVoList.addAll(response.body()!!) //返回结果默认按时间降序排序
|
for (t in allTaskVoList) {
|
if (t.districtcode == app!!.currentUser.dguid) { //主管部门的部门id就是区县id
|
showingTasks.add(t)
|
}
|
}
|
}
|
refreshPanel()
|
}
|
|
override fun onFailure(call: Call<ArrayList<TaskVo>?>, t: Throwable) {
|
refreshPanel()
|
}
|
})
|
}
|
|
var text: TextView? = null
|
private fun refreshPanel() {
|
showDialog()
|
text = tab_time_pannel.findViewById(R.id.text_time)
|
if (showingTasks.isNotEmpty()) {
|
val date = showingTasks[offset].starttime
|
val s = DateFormatter.YearMonthFormat_CN.format(date)
|
text?.text = s
|
refresh()
|
}
|
}
|
|
var freAdapter: AllRecyclerViewAdapter<FrequencyInfo>? = null
|
var frequencyInfos: MutableList<FrequencyInfo> = ArrayList()
|
private fun initBlock1() {
|
freAdapter = object : AllRecyclerViewAdapter<FrequencyInfo>(frequencyInfos, R.layout.item_common_news, activity) {
|
override fun bindView(holder: MyViewHolder, obj: FrequencyInfo, isSelected: Boolean, position: Int) {
|
val totalFrequency = StringBuilder("总监管频次: " + obj.totalFrequency + "次")
|
val clearFrequency = StringBuilder("已监管频次: " + obj.clearFrequency + "次")
|
val tmpLeft = obj.totalFrequency - obj.clearFrequency
|
val leftFrequency =
|
StringBuilder("剩余监管频次: " + (if (tmpLeft >= 0) tmpLeft else 0) + "次")
|
holder.setText(R.id.text_head, obj.sceneTypeName)
|
.setText(R.id.text_1_1, totalFrequency)
|
.setText(R.id.text_2_1, clearFrequency)
|
.setText(R.id.text_3_1, leftFrequency)
|
.setVisibility(R.id.text_1_2, View.GONE)
|
.setVisibility(R.id.text_2_2, View.GONE)
|
.setVisibility(R.id.text_3_2, View.GONE)
|
.setImageResource(
|
R.id.image_head,
|
CommonUtils.getIconBySceneType(obj.sceneTypeId)
|
)
|
}
|
}
|
val lm = LinearLayoutManager(activity)
|
lm.orientation = LinearLayoutManager.VERTICAL
|
rv_task_progress!!.layoutManager = lm
|
rv_task_progress!!.adapter = freAdapter
|
}
|
|
private fun refreshBlock1() {
|
val id = topTaskId
|
val getFrequency = retrofit!!.create(
|
TaskService::class.java
|
).getFrequency(id)
|
getFrequency.enqueue(object : Callback<TaskFrequencyVo?> {
|
override fun onResponse(
|
call: Call<TaskFrequencyVo?>,
|
response: Response<TaskFrequencyVo?>
|
) {
|
if (response.body() != null) {
|
val frequencyVo = response.body()
|
frequencyInfos.clear()
|
frequencyInfos.addAll(frequencyVo!!.frequencyInfos)
|
freAdapter!!.notifyDataSetChanged()
|
} else {
|
loadingOver(false)
|
}
|
}
|
|
override fun onFailure(call: Call<TaskFrequencyVo?>, t: Throwable) {
|
loadingOver(false)
|
}
|
})
|
}
|
|
|
var townRankAdapter: AllRecyclerViewAdapter<TownRank>? = null
|
var townRanks: MutableList<TownRank> = ArrayList()
|
var allTownRanks: MutableList<TownRank> = ArrayList()
|
private fun initBlock2() {
|
townRankAdapter = object :
|
AllRecyclerViewAdapter<TownRank>(townRanks, R.layout.item_problem_count, activity) {
|
override fun bindView(holder: MyViewHolder, obj: TownRank, isSelected: Boolean, position: Int) {
|
if (position < 3) {
|
val rank = obj.rankNo
|
holder.setText(R.id.text_name, obj.townName)
|
.setText(R.id.text_firstCount, getScore(obj.averageScore))
|
.setVisibility(R.id.text_secondCount, View.GONE)
|
.setVisibility(R.id.image_rank, View.GONE)
|
.setText(R.id.text_no, rank.toString())
|
when (rank) {
|
1 -> holder.setImageResource(R.id.image_no, R.drawable.icon_rank_4)
|
2 -> holder.setImageResource(R.id.image_no, R.drawable.icon_rank_3)
|
3 -> holder.setImageResource(R.id.image_no, R.drawable.icon_rank_2)
|
else -> holder.setImageResource(R.id.image_no, R.drawable.icon_rank_1)
|
}
|
}
|
}
|
}
|
val lm = LinearLayoutManager(activity)
|
lm.orientation = LinearLayoutManager.VERTICAL
|
rv_rank_town!!.layoutManager = lm
|
rv_rank_town!!.adapter = townRankAdapter
|
}
|
|
private fun refreshBlock2and3() {
|
val id = topTaskId
|
val getRank = retrofit!!.create(
|
TaskService::class.java
|
).getRank(id, curSceneTypeId, null)
|
getRank.enqueue(object : Callback<RankVo?> {
|
override fun onResponse(call: Call<RankVo?>, response: Response<RankVo?>) {
|
if (response.body() != null) {
|
rankVo = response.body()
|
rankS(rankVo!!.sceneRanks)
|
rankT(rankVo!!.townRanks)
|
townRanks.clear()
|
allTownRanks.clear()
|
allTownRanks.addAll(rankVo!!.townRanks)
|
val tmpMax =
|
if (maxShowItems <= allTownRanks.size) maxShowItems else allTownRanks.size
|
for (i in 0 until tmpMax) {
|
townRanks.add(allTownRanks[i])
|
}
|
townRankAdapter!!.notifyDataSetChanged()
|
sceneRanks.clear()
|
allSceneRanks.clear()
|
allSceneRanks.addAll(rankVo!!.sceneRanks)
|
val tmpMax1 =
|
if (maxShowItems <= allSceneRanks.size) maxShowItems else allSceneRanks.size
|
for (i in 0 until tmpMax1) {
|
sceneRanks.add(allSceneRanks[i])
|
}
|
sceneRankAdapter!!.notifyDataSetChanged()
|
} else {
|
loadingOver(false)
|
}
|
}
|
|
override fun onFailure(call: Call<RankVo?>, t: Throwable) {
|
loadingOver(false)
|
}
|
})
|
}
|
|
//<editor-fold desc="场景排名">
|
var sceneRankAdapter: AllRecyclerViewAdapter<SceneRank>? = null
|
var sceneRanks: MutableList<SceneRank> = ArrayList()
|
var allSceneRanks: MutableList<SceneRank> = ArrayList()
|
private fun initBlock3() {
|
sceneRankAdapter = object :
|
AllRecyclerViewAdapter<SceneRank>(sceneRanks, R.layout.item_problem_count, activity) {
|
override fun bindView(
|
holder: MyViewHolder,
|
obj: SceneRank,
|
isSelected: Boolean,
|
position: Int
|
) {
|
if (position < 3) {
|
val rank = obj.rankNo
|
holder.setText(R.id.text_name, obj.sceneName)
|
.setText(R.id.text_firstCount, getScore(obj.score))
|
.setVisibility(R.id.text_secondCount, View.GONE)
|
.setVisibility(R.id.image_rank, View.GONE)
|
.setText(R.id.text_no, rank.toString())
|
when (rank) {
|
1 -> holder.setImageResource(R.id.image_no, R.drawable.icon_rank_4)
|
2 -> holder.setImageResource(R.id.image_no, R.drawable.icon_rank_3)
|
3 -> holder.setImageResource(R.id.image_no, R.drawable.icon_rank_2)
|
else -> holder.setImageResource(R.id.image_no, R.drawable.icon_rank_1)
|
}
|
}
|
}
|
}
|
val lm = LinearLayoutManager(activity)
|
lm.orientation = LinearLayoutManager.VERTICAL
|
rv_rank_scene!!.layoutManager = lm
|
rv_rank_scene!!.adapter = sceneRankAdapter
|
}
|
|
//</editor-fold>
|
//<editor-fold desc="问题分析">
|
var datas = HashMap<String, Float>()
|
private fun initBlock4() {
|
ChartGenerator.quickSetupChart(pie_chart_problem)
|
}
|
|
private fun refreshBlock4() {
|
val id = topTaskId
|
val getStatisticalResultbyId = retrofit!!.create(
|
ProblemListService::class.java
|
).getStatisticalResultbyId(id, curSceneTypeId)
|
getStatisticalResultbyId.enqueue(object : Callback<List<StatisticsVo>?> {
|
override fun onResponse(
|
call: Call<List<StatisticsVo>?>,
|
response: Response<List<StatisticsVo>?>
|
) {
|
datas.clear()
|
if (response.body() != null) {
|
val statisticsVos = response.body()
|
for (s in statisticsVos!!) {
|
datas[s.name] = s.count.toFloat()
|
}
|
if (datas.isEmpty()) {
|
pie_chart_problem!!.visibility = View.GONE
|
ll_no_data!!.visibility = View.VISIBLE
|
} else {
|
pie_chart_problem!!.visibility = View.VISIBLE
|
ll_no_data!!.visibility = View.GONE
|
}
|
ChartGenerator.quickSetData(pie_chart_problem, datas, "问题统计")
|
loadingOver(true)
|
} else {
|
loadingOver(false)
|
}
|
}
|
|
override fun onFailure(call: Call<List<StatisticsVo>?>, t: Throwable) {
|
datas.clear()
|
ChartGenerator.quickSetData(pie_chart_problem, datas, "问题统计")
|
loadingOver(false)
|
}
|
})
|
}//返回顶层任务id
|
|
//</editor-fold>
|
//<editor-fold desc="获取查询参数">
|
private val topTaskId: String
|
get() = showingTasks[offset].tguid //返回顶层任务id
|
|
//</editor-fold>
|
//<editor-fold desc="联网刷新">
|
private fun refresh() {
|
showDialog()
|
refreshBlock1()
|
refreshBlock2and3()
|
refreshBlock4()
|
}
|
|
//</editor-fold>
|
//<editor-fold desc="获取弹出框">
|
var rv_popup: RecyclerView? = null
|
var sceneAdapter: AllRecyclerViewAdapter<Domainitem>? = null
|
private val sceneTypeData: MutableList<Domainitem> = ArrayList() //场景类型
|
var popup: PopupGenerator? = null
|
private fun initPopup() {
|
val domainitemDao = app!!.daoSession.domainitemDao
|
//场景类型
|
val queryBuilder = domainitemDao.queryBuilder()
|
.where(DomainitemDao.Properties.Dcguid.eq(Domain.DOMAINGUID_SCENSETYPE))
|
.orderAsc(DomainitemDao.Properties.Value)
|
sceneTypeData.addAll(queryBuilder.list())
|
popup = PopupGenerator(activity, R.layout.popup_scene_selector)
|
rv_popup = popup!!.findViewById(R.id.rv_popup)
|
sceneAdapter = object :
|
AllRecyclerViewAdapter<Domainitem>(sceneTypeData, R.layout.item_scene, activity) {
|
override fun bindView(
|
holder: MyViewHolder,
|
obj: Domainitem,
|
isSelected: Boolean,
|
position: Int
|
) {
|
val sceneType = obj.value.toString()
|
holder.setText(R.id.text_scene, obj.text)
|
.setImageResource(R.id.image_scene, CommonUtils.getIconBySceneType(sceneType))
|
.setOnItemClickListener {
|
curSceneTypeId = obj.value
|
curSceneTypeName = obj.text
|
}
|
}
|
}
|
val layoutManager = GridLayoutManager(activity, 3)
|
layoutManager.orientation = GridLayoutManager.VERTICAL
|
layoutManager.isAutoMeasureEnabled = true
|
rv_popup?.layoutManager = layoutManager
|
rv_popup?.adapter = sceneAdapter
|
popup!!.setPopupWindowFullScreen(false)
|
}
|
|
//</editor-fold>
|
//<editor-fold desc="点击事件">
|
fun initClickListener() {
|
//切换顶层任务
|
image_left.setOnClickListener { onClickChangeTask(it) }
|
image_right.setOnClickListener { onClickChangeTask(it) }
|
|
//场景选择菜单
|
// ll_menu_text.setOnClickListener { }
|
|
//详细内容按钮
|
text_all_2.setOnClickListener { onClickMoreInfo(it) }
|
text_all_3.setOnClickListener { onClickMoreInfo(it) }
|
|
//重新加载按钮
|
button_refresh.setOnClickListener { refresh() }
|
}
|
|
//切换顶层任务
|
private fun onClickChangeTask(v: View) {
|
val tmpOffset = offset
|
when (v) {
|
image_left -> {
|
val tmp = offset + 1
|
offset = if (tmp >= showingTasks.size) offset else tmp
|
}
|
image_right -> {
|
val tmp1 = offset - 1
|
offset = if (tmp1 < 0) offset else tmp1
|
}
|
}
|
if (tmpOffset != offset) {
|
refreshPanel()
|
}
|
}
|
|
//详细内容按钮
|
private fun onClickMoreInfo(v: View) {
|
val intent = Intent(activity, AnalysisRankActivity::class.java)
|
val bundle = Bundle()
|
bundle.putSerializable(AnalysisRankActivity.ARG_PARAM1, rankVo)
|
bundle.putString(AnalysisRankActivity.ARG_PARAM2, rankVo!!.topTaskName)
|
bundle.putString(AnalysisRankActivity.ARG_PARAM3, curSceneTypeName)
|
when (v) {
|
text_all_2 -> bundle.putInt(AnalysisRankActivity.ARG_PARAM4, 1)
|
text_all_3 -> bundle.putInt(AnalysisRankActivity.ARG_PARAM4, 0)
|
}
|
intent.putExtras(bundle)
|
startActivity(intent)
|
}
|
|
//</editor-fold>
|
//<editor-fold desc="更新当前场景">
|
private fun refreshCurScene(id: String, name: String) {
|
curSceneTypeId = id
|
curSceneTypeName = name
|
}
|
|
//</editor-fold>
|
//<editor-fold desc="网络加载完成">
|
private fun loadingOver(b: Boolean) {
|
Handler().postDelayed({
|
if (dialog!!.isShowing) {
|
dialog!!.dismiss()
|
}
|
}, 500)
|
if (b) { //加载成功
|
sl_content!!.visibility = View.VISIBLE
|
no_data!!.visibility = View.GONE
|
} else { //加载失败
|
sl_content!!.visibility = View.GONE
|
no_data!!.visibility = View.VISIBLE
|
}
|
}
|
|
//</editor-fold>
|
private fun showDialog() {
|
if (dialog == null) {
|
dialog = DialogUtil.createLoadingDialog(activity, "")
|
}
|
if (!dialog!!.isShowing) {
|
dialog!!.show()
|
}
|
}
|
|
private fun getScore(score: Int): String {
|
return if (score == -1) "未评分" else score.toString()
|
}
|
|
//刷新排名信息
|
private fun rankT(townRanks: List<TownRank>?) {
|
if (townRanks == null) return
|
var last: TownRank? = null
|
var current: TownRank? = null
|
var rankNo = 1
|
for (i in townRanks.indices) {
|
if (i > 0) {
|
last = townRanks[i - 1]
|
}
|
current = townRanks[i]
|
if (last != null) {
|
//同分时并列排名
|
if (current.averageScore == last.averageScore) {
|
current.rankNo = last.rankNo
|
} else {
|
current.rankNo = rankNo
|
}
|
} else {
|
current.rankNo = rankNo
|
}
|
rankNo++
|
}
|
}
|
|
companion object {
|
@JvmStatic
|
fun newInstance(): AnalysisOverViewFragment {
|
return AnalysisOverViewFragment()
|
}
|
|
//刷新排名信息
|
@JvmStatic
|
fun rankS(sceneRanks: List<SceneRank?>?) {
|
if (sceneRanks == null) return
|
var last: SceneRank? = null
|
var current: SceneRank? = null
|
var rankNo = 1
|
for (i in sceneRanks.indices) {
|
if (i > 0) {
|
last = sceneRanks[i - 1]
|
}
|
current = sceneRanks[i]
|
if (last != null) {
|
//同分时并列排名
|
if (current!!.score == last.score) {
|
current.rankNo = last.rankNo
|
} else {
|
current.rankNo = rankNo
|
}
|
} else {
|
current!!.rankNo = rankNo
|
}
|
rankNo++
|
}
|
}
|
}
|
}
|