riku
2025-10-17 fbae5f3ea74727ccadc48314a864a1ea0099a945
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
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
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!!.isNotEmpty()) {
            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()
        }
    }
}