package cn.flightfeather.thirdappmodule.module.inspectioninfo
|
|
import android.content.Context
|
import android.content.Intent
|
import android.os.Build
|
import android.os.Bundle
|
import android.support.annotation.RequiresApi
|
import android.support.v4.app.Fragment
|
import android.support.v7.widget.GridLayoutManager
|
import android.support.v7.widget.LinearLayoutManager
|
import android.view.Gravity
|
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.Problemtype
|
import cn.flightfeather.thirdappmodule.bean.vo.ProblemCategoryVo
|
import cn.flightfeather.thirdappmodule.bean.vo.ProblemlistVo
|
import cn.flightfeather.thirdappmodule.common.net.ResultCallBack
|
import cn.flightfeather.thirdappmodule.httpservice.ProblemListService
|
import cn.flightfeather.thirdappmodule.repository.ProblemRepository
|
import cn.flightfeather.thirdappmodule.util.CommonUtils
|
import cn.flightfeather.thirdappmodule.util.Constant
|
import cn.flightfeather.thirdappmodule.util.DateFormatter
|
import cn.flightfeather.thirdappmodule.util.Domain
|
import com.ping.greendao.gen.DomainitemDao
|
import com.ping.greendao.gen.ScenseDao
|
import kotlinx.android.synthetic.main.fragment_inspection_info.*
|
import retrofit2.Call
|
import retrofit2.Callback
|
import retrofit2.Response
|
import java.io.Serializable
|
import java.util.*
|
|
/**
|
* 2019.1.22
|
* @author riku
|
* 监管情况界面,展示用户(工地、码头等)本月的问题分布情况
|
*/
|
class InspectionInfoFragment : Fragment(), Serializable {
|
private var application: CommonApplication? = null
|
|
//场景类型
|
private var sceneType = Constant.SCENE_TYPE_SITE
|
private var unbinder: Unbinder? = null
|
override fun onCreate(savedInstanceState: Bundle?) {
|
super.onCreate(savedInstanceState)
|
}
|
|
override fun onCreateView(
|
inflater: LayoutInflater, container: ViewGroup?,
|
savedInstanceState: Bundle?
|
): View? {
|
// Inflate the layout for this fragment
|
val view = inflater.inflate(R.layout.fragment_inspection_info, container, false)
|
unbinder = ButterKnife.bind(this, view)
|
return view
|
}
|
|
@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
|
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
super.onViewCreated(view, savedInstanceState)
|
application = activity!!.application as CommonApplication
|
initToolBar()
|
initData()
|
initView(sceneType)
|
val now = Date()
|
val date = DateFormatter.dateTimeFormat3.format(now)
|
refresh(application!!.currentUser.dguid, date) //对于客户来说,D_GUID就是场景id
|
}
|
|
override fun onAttach(context: Context) {
|
super.onAttach(context)
|
}
|
|
override fun onDetach() {
|
super.onDetach()
|
}
|
|
override fun onDestroy() {
|
super.onDestroy()
|
if (unbinder != null) {
|
unbinder!!.unbind()
|
}
|
}
|
|
@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
|
private fun initToolBar() {
|
// action_bar.setElevation(0);
|
// action_bar.setBackgroundColor(Color.alpha(0));
|
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.GONE
|
val title = action_bar!!.findViewById<TextView>(R.id.actionbar_title)
|
title.text = TITLE
|
title.gravity = Gravity.CENTER_HORIZONTAL
|
}
|
|
|
private var totalProblems = 0//总问题数
|
private var changedProblems = 0//已整改问题数
|
|
private fun refreshStatisticBar() {
|
text_total!!.text = totalProblems.toString()
|
text_changed!!.text = changedProblems.toString()
|
text_unchanged!!.text = (totalProblems - changedProblems).toString()
|
}
|
|
private val problemCategories = ArrayList<ProblemCategoryVo>() //列表中展示的数据,按问题类型分类
|
private val problemRepository = ProblemRepository()
|
private val domainitemDao: DomainitemDao? = null
|
private var scenseDao: ScenseDao? = null
|
private fun initData() {
|
|
//region 查询当前“企业”用户的场景类型
|
val sceneGuid = application!!.currentUser.dguid //登录用户为“企业”时,该变量表示场景guid
|
scenseDao = application!!.daoSession.scenseDao
|
val scenses = scenseDao?.queryBuilder()
|
?.where(
|
ScenseDao.Properties.Guid.eq(
|
sceneGuid
|
)
|
)
|
?.limit(1)?.list()
|
if (scenses != null && scenses.isNotEmpty()) {
|
sceneType = scenses[0].typeid.toString()
|
val s = scenses[0]
|
|
//查询当前场景类型下的问题类型值域
|
val b: Byte = 1
|
problemRepository.getProblemType(b, s.citycode, s.districtcode, s.typeid, object : ResultCallBack<ArrayList<Problemtype>> {
|
override fun onCacheSuccess(result: ArrayList<Problemtype>?) {}
|
override fun onSuccess(result: ArrayList<Problemtype>?) {
|
if (result != null) {
|
val types: MutableList<String> = ArrayList()
|
for (i in result.indices) {
|
val d = result[i]
|
if (!types.contains(d.typeid.toString())) {
|
types.add(d.typeid.toString())
|
val p = ProblemCategoryVo()
|
p.problemTypeId = d.typeid.toString()
|
p.problemTypeName = d.typename
|
problemCategories.add(p)
|
}
|
}
|
}
|
}
|
|
override fun onPage(current: Int, total: Int) {}
|
override fun onFailure() {}
|
})
|
}
|
//endregion
|
|
// this.domainitemDao = this.application.getDaoSession().getDomainitemDao();
|
// List<Domainitem> domainitems = domainitemDao.queryBuilder()
|
// .where(
|
// DomainitemDao.Properties.Dcguid.eq(
|
// CommonUtils.getProblemTypeGUID(this.sceneType)
|
// )
|
// )
|
// .orderAsc(DomainitemDao.Properties.Index).list();
|
// for (Domainitem d :
|
// domainitems) {
|
// ProblemCategoryVo p = new ProblemCategoryVo();
|
// p.setProblemTypeId(d.getValue());
|
// p.setProblemTypeName(d.getText());
|
// this.problemCategories.add(p);
|
// }
|
}
|
|
//问题按分类进行个数统计
|
var adapter: AllRecyclerViewAdapter<ProblemCategoryVo>? = null
|
private fun initView(sceneType: String) {
|
adapter = object : AllRecyclerViewAdapter<ProblemCategoryVo>(problemCategories, R.layout.item_problem_category, activity) {
|
override fun bindView(holder: MyViewHolder, obj: ProblemCategoryVo, isSelected: Boolean, position: Int) {
|
holder.setImageResource(R.id.image_problem_category, CommonUtils.getIconByProblemType(sceneType, obj.problemTypeId))
|
.setText(R.id.text_problem_category, obj.problemTypeName)
|
.setText(R.id.text_rectified_problem, obj.isRectifiedCount.toString())
|
.setText(R.id.text_total_problem, obj.totalCount.toString())
|
if (obj.totalCount > 0) {
|
holder.setItemSelected(true)
|
.setOnItemClickListener {
|
val intent = Intent(activity, ProblemChangeActivity::class.java)
|
intent.putExtra(ProblemChangeActivity.ARG_PROBLEM, obj.problemlistVos)
|
intent.putExtra(ProblemChangeActivity.ARG_TOTAL_PROBLEM, problemCategories)
|
startActivity(intent)
|
}
|
}
|
}
|
}
|
val gl = GridLayoutManager(activity, 3)
|
gl.orientation = LinearLayoutManager.VERTICAL
|
rv_problem_type!!.layoutManager = gl
|
rv_problem_type!!.adapter = adapter
|
}
|
|
private fun refresh(sceneId: String, date: String) {
|
val getProblemByScene = application!!.retrofit.create(ProblemListService::class.java).getProblemByScene(sceneId, date)
|
getProblemByScene.enqueue(object : Callback<List<ProblemlistVo>?> {
|
override fun onResponse(call: Call<List<ProblemlistVo>?>, response: Response<List<ProblemlistVo>?>) {
|
if (response.body() != null) {
|
updateData(response.body()!!.toMutableList())
|
adapter!!.notifyDataSetChanged()
|
refreshStatisticBar()
|
}
|
}
|
|
override fun onFailure(call: Call<List<ProblemlistVo>?>, t: Throwable) {}
|
})
|
}
|
|
private fun updateData(problemlistVos: MutableList<ProblemlistVo>?) {
|
totalProblems = 0
|
changedProblems = 0
|
for (p in problemCategories) {
|
p.totalCount = 0
|
p.isRectifiedCount = 0
|
p.problemlistVos.clear()
|
var i = 0
|
while (i < problemlistVos!!.size) {
|
val problemlistVo = problemlistVos[i]
|
if (problemlistVo.typeid != null && p.problemTypeId == problemlistVo.typeid.toString()) {
|
p.problemlistVos.add(problemlistVo)
|
//总问题数累加
|
p.totalCount = p.totalCount + 1
|
totalProblems++
|
//已整改问题数累加
|
if (problemlistVo.ischanged && problemlistVo.extension3 == Domain.CHANGE_CHECK_PASS) {
|
p.isRectifiedCount = p.isRectifiedCount + 1
|
changedProblems++
|
}
|
problemlistVos.removeAt(i)
|
i--
|
}
|
i++
|
}
|
}
|
//问题列表不为空则表示有异常的问题(可能问题类型不存在或为空), 都归类为"其他"类型
|
if (!problemlistVos!!.isEmpty()) {
|
val problemCategoryVo = problemCategories[problemCategories.size - 1] //得到“其他”这个问题类型(查询时已排序)
|
problemCategoryVo.problemlistVos.addAll(problemlistVos)
|
//总问题数累加
|
problemCategoryVo.totalCount = problemCategoryVo.totalCount + problemlistVos.size
|
totalProblems += problemlistVos.size
|
for (p in problemlistVos) {
|
//补充问题类型id和类型名称为"其他"类型
|
try {
|
p.typeid = java.lang.Byte.valueOf(problemCategoryVo.problemTypeId)
|
} catch (e: NumberFormatException) {
|
e.printStackTrace()
|
}
|
p.typename = problemCategoryVo.problemTypeName
|
if (p.ischanged) {
|
//已整改问题数累加
|
problemCategoryVo.isRectifiedCount = problemCategoryVo.isRectifiedCount + 1
|
changedProblems++
|
}
|
}
|
}
|
}
|
|
fun updateData() {
|
val now = Date()
|
val date = DateFormatter.dateTimeFormat3.format(now)
|
refresh(application!!.currentUser.dguid, date) //对于客户来说,D_GUID就是场景id
|
}
|
|
companion object {
|
private const val TITLE = "问题"
|
private const val serialVersionUID = 6072583863506447855L
|
@JvmStatic
|
fun newInstance(): InspectionInfoFragment {
|
// Bundle args = new Bundle();
|
// fragment.setArguments(args);
|
return InspectionInfoFragment()
|
}
|
}
|
}
|