Pārlūkot izejas kodu

refactor(模式校验):
- 步骤模式校验 逻辑完成
- 人员模式校验 逻辑完成
- 进度模式校验 逻辑完成
- 模式切换 基本完成

(cherry picked from commit c73cc7462c8cbce87b980167c8bb6760feb56271)

周文健 6 mēneši atpakaļ
vecāks
revīzija
e6de4d9cad

+ 4 - 1
app/build.gradle

@@ -36,7 +36,8 @@ android {
 
     buildTypes {
         debug {
-
+            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
+            signingConfig signingConfigs.release
         }
         release {
             minifyEnabled true  // 混淆
@@ -124,4 +125,6 @@ dependencies {
 
     // ML Kit 面部检测库(备份,已改用虹软以补充活体检测)
     implementation 'com.google.mlkit:face-detection:16.1.5'
+
+    implementation 'io.github.razerdp:BasePopup:3.2.1'
 }

+ 3 - 1
app/src/main/java/com/grkj/iscs/model/UrlConsts.kt

@@ -3,7 +3,9 @@ package com.grkj.iscs.model
 object UrlConsts {
 //    const val BASE_URL = "http://192.168.28.82:9190"  // 本地
 //    const val BASE_URL = "http://192.168.28.97:9190"    // 车
-    const val BASE_URL = "http://36.133.174.236:9190"    // 外
+//    const val BASE_URL = "http://36.133.174.236:9190"    // 外
+    const val BASE_URL = "http://192.168.1.121:9190"    // 外
+//    const val BASE_URL = "http://120.27.232.27:9190"    // 外
     const val WEB_SOCKET = "ws://192.168.1.127:9090/websocket/iot/127"
 
     const val AUTOCODE_TICKET_NUMBER = "JOB_TICKET_CODE"

+ 1 - 1
app/src/main/java/com/grkj/iscs/model/vo/ticket/TicketDetailMonitorRespVO.kt

@@ -34,7 +34,7 @@ data class TicketDetailMonitorRespVO(
         val userName: String?,
         val userType: String?,
         val userRole: String?,
-        val jobStatus: Int?,
+        val jobStatus: Int?,//作业状态(0未开始,1 取锁具, 2取钥匙, 3待上锁(待共锁),4 已上锁(已共锁),5 已解锁)
         val delFlag: String?
     )
 

+ 1 - 1
app/src/main/java/com/grkj/iscs/model/vo/ticket/TicketDetailRespVO.kt

@@ -67,7 +67,7 @@ data class TicketDetailRespVO(
         val userName: String?,
         val userType: String?,
         val userRole: String?,
-        val jobStatus: Int?,
+        val jobStatus: Int?,//作业状态(0未开始,1 取锁具, 2取钥匙, 3待上锁(待共锁),4 已上锁(已共锁),5 已解锁)
     )
 
     data class JobTicketPointsVO(

+ 2 - 1
app/src/main/java/com/grkj/iscs/model/vo/ticket/TicketUserReqVO.kt

@@ -4,5 +4,6 @@ data class TicketUserReqVO(
     val userId: Long,
     val userName: String,
     val userType: String,
-    val userRole: String
+    val userRole: String,
+    val jobStatus: Int?//作业状态(0未开始,1 取锁具, 2取钥匙, 3待上锁(待共锁),4 已上锁(已共锁),5 已解锁)
 )

+ 1 - 0
app/src/main/java/com/grkj/iscs/view/activity/LoginActivity.kt

@@ -105,6 +105,7 @@ class LoginActivity : BaseMvpActivity<ILoginView, LoginPresenter, ActivityLoginB
         if (event.action == KeyEvent.ACTION_UP && event.source == InputDevice.SOURCE_KEYBOARD) {
             // 检测到回车开始处理
             if (event.keyCode == 66) {
+                LogUtil.i("Swipe card login Origin: $cardNo")
                 cardNo = cardNo.toLong().toByteArrays().toHexStrings(false)
                 LogUtil.i("Swipe card login: $cardNo")
                 presenter?.cardLogin(cardNo) { isSuccess, userInfoRespVO ->

+ 36 - 26
app/src/main/java/com/grkj/iscs/view/dialog/LoginDialog.kt

@@ -18,7 +18,11 @@ import com.grkj.iscs.view.base.BaseActivity
 import com.grkj.iscs.view.base.BaseDialog
 import com.grkj.iscs.view.presenter.LoginPresenter
 
-class LoginDialog(val presenter: LoginPresenter?, val ctx: BaseActivity<*>, private var callBack: ((Boolean, UserInfoRespVO?) -> Unit)? = null) :
+class LoginDialog(
+    val presenter: LoginPresenter?,
+    val ctx: BaseActivity<*>,
+    private var callBack: ((Boolean, UserInfoRespVO?) -> Unit)? = null
+) :
     BaseDialog<DialogLoginBinding>(ctx) {
 
     private var cardNo = ""
@@ -34,7 +38,11 @@ class LoginDialog(val presenter: LoginPresenter?, val ctx: BaseActivity<*>, priv
 
     override fun initView() {
         mBinding?.tvLogin?.setOnClickListener {
-            presenter?.login(ctx, mBinding?.etAccount?.text.toString(), mBinding?.etPassword?.text.toString()) { isSuccess, userInfoRespVO ->
+            presenter?.login(
+                ctx,
+                mBinding?.etAccount?.text.toString(),
+                mBinding?.etPassword?.text.toString()
+            ) { isSuccess, userInfoRespVO ->
                 if (isSuccess) {
                     dismiss()
                 }
@@ -66,6 +74,7 @@ class LoginDialog(val presenter: LoginPresenter?, val ctx: BaseActivity<*>, priv
                     }
                     startFace()
                 }
+
                 1 -> {
                     FingerprintUtil.init(ctx)
                     FingerprintUtil.start()
@@ -86,34 +95,33 @@ class LoginDialog(val presenter: LoginPresenter?, val ctx: BaseActivity<*>, priv
     }
 
     override fun dispatchKeyEvent(event: KeyEvent): Boolean {
-        if (mLoginType != 2) {
-            return super.dispatchKeyEvent(event)
-        }
-        if (event.action == KeyEvent.ACTION_UP && event.source == InputDevice.SOURCE_KEYBOARD) {
-//            val view = currentFocus
-//            if (view is EditText) {
-//                val text = view.text?.toString()
-//                if (text!!.isNotEmpty()) {
-//                    val rst = text.substring(0, text.length - 1)
-//                    view.setText(rst)
-//                }
-//            }
-            // 检测到回车开始处理
-            if (event.keyCode == 66) {
-                cardNo = cardNo.toLong().toByteArrays().toHexStrings(false)
-                LogUtil.i("Swipe card login: $cardNo")
-                presenter?.cardLogin(cardNo) { isSuccess, userInfoRespVO ->
-                    if (isSuccess) {
-                        dismiss()
+        val device = event.device
+        val isHidInput = device != null &&
+                (device.sources and InputDevice.SOURCE_KEYBOARD) == InputDevice.SOURCE_KEYBOARD &&
+                !device.isVirtual
+        LogUtil.d("is HID Input: ${isHidInput}")
+        // 如果是 HID 设备输入(扫码器等),自定义处理逻辑
+        if (isHidInput && mLoginType != 2) {
+            if (event.action == KeyEvent.ACTION_UP) {
+                if (event.keyCode == KeyEvent.KEYCODE_ENTER) {
+                    LogUtil.i("Swipe card login Origin: $cardNo")
+                    cardNo = cardNo.toLong().toByteArrays().toHexStrings(false)
+                    LogUtil.i("Swipe card login: $cardNo")
+                    presenter?.cardLogin(cardNo) { isSuccess, userInfoRespVO ->
+                        if (isSuccess) {
+                            dismiss()
+                        }
+                        callBack?.invoke(isSuccess, userInfoRespVO)
                     }
-                    callBack?.invoke(isSuccess, userInfoRespVO)
+                    cardNo = ""
+                } else {
+                    cardNo += event.keyCharacterMap.getDisplayLabel(event.keyCode)
                 }
-                // 重置cardNo
-                cardNo = ""
-                return super.dispatchKeyEvent(event)
             }
-            cardNo += event.keyCharacterMap.getDisplayLabel(event.keyCode)
+            return true // 消费 HID 事件
         }
+
+        // 非 HID 情况,正常让 EditText 或 Activity 处理
         return super.dispatchKeyEvent(event)
     }
 
@@ -140,10 +148,12 @@ class LoginDialog(val presenter: LoginPresenter?, val ctx: BaseActivity<*>, priv
             0 -> {
                 ArcSoftUtil.stop()
             }
+
             1 -> {
                 FingerprintUtil.stop()
                 FingerprintUtil.unInit()
             }
+
             3 -> {
                 mBinding?.etAccount?.text?.clear()
                 mBinding?.etPassword?.text?.clear()

+ 4 - 11
app/src/main/java/com/grkj/iscs/view/fragment/StepFragment.kt

@@ -318,8 +318,9 @@ class StepFragment(val goBack: () -> Unit, val changePage: (PageChangeBO) -> Uni
     }
 
     private fun updateStep(step: Int) {
-        if (presenter?.checkCanContinue(requireContext(), step, mTicketDetailData)
-                ?.isEmpty() == true
+        val canContinue =
+            presenter?.checkCanContinue(requireContext(), step, mTicketDetailData) ?: ""
+        if (canContinue.isEmpty() == true
         ) {
             val str = when (step) {
                 4 -> getString(R.string.action_confirm_shut_down)
@@ -369,15 +370,7 @@ class StepFragment(val goBack: () -> Unit, val changePage: (PageChangeBO) -> Uni
                 }
             }
         } else {
-            val str = when (step) {
-                4 -> getString(R.string.action_confirm_shut_down)
-                5 -> getString(R.string.action_confirm_lock)
-                6 -> getString(R.string.action_confirm_power_isolation)
-                7 -> getString(R.string.action_confirm_check_before_unlocking)
-                8 -> getString(R.string.action_confirm_restore)
-                else -> ""
-            }
-            mTipDialog.setTip(str)
+            mTipDialog.setTip(canContinue)
         }
         mTipDialog.show()
     }

+ 43 - 2
app/src/main/java/com/grkj/iscs/view/fragment/SystemSettingFragment.kt

@@ -1,25 +1,32 @@
 package com.grkj.iscs.view.fragment
 
+import android.graphics.Color
+import android.graphics.drawable.Icon
 import android.view.LayoutInflater
 import android.view.View
 import android.view.ViewGroup
 import android.widget.PopupWindow
+import android.widget.RadioButton
+import androidx.core.view.children
 import com.google.gson.Gson
 import com.grkj.iscs.R
 import com.grkj.iscs.databinding.FragmentSystemSettingBinding
 import com.grkj.iscs.databinding.LayoutSelectableinputSpinnerBinding
 import com.grkj.iscs.util.SPUtils
+import com.grkj.iscs.util.ToastUtils
 import com.grkj.iscs.util.byteToHexString
 import com.grkj.iscs.view.base.BaseMvpFragment
 import com.grkj.iscs.view.iview.ISystemSettingView
 import com.grkj.iscs.view.presenter.SystemSettingPresenter
+import com.grkj.iscs.view.step_mode.StepModeEnums
 import com.zhy.adapter.recyclerview.CommonAdapter
 import com.zhy.adapter.recyclerview.base.ViewHolder
 
 /**
  * 系统设置页
  */
-class SystemSettingFragment : BaseMvpFragment<ISystemSettingView, SystemSettingPresenter, FragmentSystemSettingBinding>() {
+class SystemSettingFragment :
+    BaseMvpFragment<ISystemSettingView, SystemSettingPresenter, FragmentSystemSettingBinding>() {
 
     private var mDockTypeList = mutableListOf<DockItem>()
     private var mPortList = mutableListOf<String>()
@@ -57,7 +64,11 @@ class SystemSettingFragment : BaseMvpFragment<ISystemSettingView, SystemSettingP
             R.layout.item_rv_board,
             mDockList
         ) {
-            override fun convert(holder: ViewHolder, t: DockTestFragment.DockTestBean, position: Int) {
+            override fun convert(
+                holder: ViewHolder,
+                t: DockTestFragment.DockTestBean,
+                position: Int
+            ) {
                 mDockTypeList.find { it.type == t.type }?.name?.let {
                     holder.setText(R.id.tv_board, it)
                 } ?: {
@@ -86,6 +97,36 @@ class SystemSettingFragment : BaseMvpFragment<ISystemSettingView, SystemSettingP
         mBinding?.cbSave?.setOnClickListener {
             presenter?.saveConfig(requireContext(), mDockList, mBinding?.tvPort?.text.toString())
         }
+
+        initStepModeRG()
+    }
+
+    private fun initStepModeRG() {
+        StepModeEnums.entries.forEach {
+            val radioButton = RadioButton(requireContext())
+            radioButton.id = View.generateViewId()
+            radioButton.text = it.description
+            radioButton.tag = it.type
+            radioButton.setTextColor(Color.WHITE)
+            mBinding?.stepModeRg?.addView(radioButton)
+        }
+
+        mBinding?.stepModeRg?.apply {
+            setOnCheckedChangeListener(null)
+            mBinding?.stepModeRg?.children?.filterIsInstance<RadioButton>()?.forEach {
+                val stepMode = SPUtils.getStepMode(requireContext())
+                if (it.tag as Int == stepMode) {
+                    it.isChecked = true
+                }
+            }
+            setOnCheckedChangeListener { radioGroup, i ->
+                SPUtils.saveStepMode(
+                    requireContext(),
+                    mBinding?.root?.findViewById<RadioButton>(i)?.tag as Int
+                )
+                ToastUtils.tip(getString(R.string.step_mode_change_success))
+            }
+        }
     }
 
     private fun showBoardTypeDropDown() {

+ 73 - 37
app/src/main/java/com/grkj/iscs/view/fragment/WorkerFragment.kt

@@ -7,7 +7,9 @@ import com.grkj.iscs.databinding.FragmentWorkerBinding
 import com.grkj.iscs.model.Constants.USER_ROLE_COLOCKER
 import com.grkj.iscs.model.Constants.USER_ROLE_LOCKER
 import com.grkj.iscs.model.bo.PageChangeBO
+import com.grkj.iscs.model.vo.ticket.StepDetailRespVO
 import com.grkj.iscs.model.vo.ticket.TicketDetailRespVO
+import com.grkj.iscs.model.vo.ticket.TicketDetailRespVO.JobTicketUserVO
 import com.grkj.iscs.model.vo.ticket.TicketUserReqVO
 import com.grkj.iscs.model.vo.user.UserListRespVO
 import com.grkj.iscs.util.SPUtils
@@ -31,8 +33,11 @@ class WorkerFragment(val goBack: () -> Unit, val changePage: (PageChangeBO) -> U
     private val mLockerList = mutableListOf<UserListRespVO.Row>()
     private val mColockerInsideList = mutableListOf<UserListRespVO.Row>()
     private val mColockerOutsideList = mutableListOf<UserListRespVO.Row>()
+    private val ticketUserVOList = mutableListOf<JobTicketUserVO>()
     private var mPageChangeBO: PageChangeBO? = null
     private var mStep: Int = 0
+    private var mStepDetailList: MutableList<StepDetailRespVO> = mutableListOf()
+    private var isColockerChanged: Boolean = false
 
     override val viewBinding: FragmentWorkerBinding
         get() = FragmentWorkerBinding.inflate(layoutInflater)
@@ -45,9 +50,13 @@ class WorkerFragment(val goBack: () -> Unit, val changePage: (PageChangeBO) -> U
             if (!checkUpdate()) {
                 return@setOnClickListener
             }
-            presenter?.updateTicketUser(mPageChangeBO?.ticketId!!, mSelectedList) {
-                if (it) {
-                    goBack()
+            if (isColockerChanged) {
+                presenter?.checkColockerChangedStepJump(requireContext(), mStepDetailList, mStep) {
+                    presenter?.updateTicketUser(mPageChangeBO?.ticketId!!, mSelectedList) {
+                        if (it) {
+                            goBack()
+                        }
+                    }
                 }
             }
         }
@@ -69,6 +78,7 @@ class WorkerFragment(val goBack: () -> Unit, val changePage: (PageChangeBO) -> U
                             mBinding?.rvColockerSelected?.adapter?.notifyDataSetChanged()
                             mBinding?.rvColockerInside?.adapter?.notifyDataSetChanged()
                             mBinding?.rvColockerOutside?.adapter?.notifyDataSetChanged()
+                            isColockerChanged = true
                         }
                     }
                 }
@@ -108,7 +118,8 @@ class WorkerFragment(val goBack: () -> Unit, val changePage: (PageChangeBO) -> U
                                     user.userId!!,
                                     user.nickName!!,
                                     "0",
-                                    USER_ROLE_LOCKER
+                                    USER_ROLE_LOCKER,
+                                    ticketUserVOList.find { ticketUser -> ticketUser.userId == user.userId }?.jobStatus
                                 )
                             )
                             mBinding?.layoutLocker?.root?.visibility = View.VISIBLE
@@ -130,22 +141,31 @@ class WorkerFragment(val goBack: () -> Unit, val changePage: (PageChangeBO) -> U
                         mSelectedList.any { it.userId == user.userId && it.userRole == USER_ROLE_COLOCKER }
                     holder.setText(R.id.tv_name, user.nickName)
                     holder.setOnClickListener(R.id.root) {
-                        // 内部共锁人选择
-                        if (mSelectedList.any { it.userId == user.userId }) {
-                            mSelectedList.removeIf { it.userId == user.userId }
-                            mColockerSelectedShowList.removeIf { it.userId == user.userId }
-                        } else {
-                            val addUser = TicketUserReqVO(
-                                user.userId!!,
-                                user.nickName!!,
-                                "0",
-                                USER_ROLE_COLOCKER
-                            )
-                            mSelectedList.add(addUser)
-                            mColockerSelectedShowList.add(addUser)
+                        if (presenter?.colockerInsideCanAdd(
+                                requireContext(),
+                                user,
+                                mStep
+                            ) == true
+                        ) {
+                            // 内部共锁人选择
+                            if (mSelectedList.any { it.userId == user.userId }) {
+                                mSelectedList.removeIf { it.userId == user.userId }
+                                mColockerSelectedShowList.removeIf { it.userId == user.userId }
+                            } else {
+                                val addUser = TicketUserReqVO(
+                                    user.userId!!,
+                                    user.nickName!!,
+                                    "0",
+                                    USER_ROLE_COLOCKER,
+                                    ticketUserVOList.find { ticketUser -> ticketUser.userId == user.userId }?.jobStatus
+                                )
+                                mSelectedList.add(addUser)
+                                mColockerSelectedShowList.add(addUser)
+                            }
+                            mBinding?.rvColockerSelected?.adapter?.notifyDataSetChanged()
+                            mBinding?.rvColockerInside?.adapter?.notifyDataSetChanged()
+                            isColockerChanged = true
                         }
-                        mBinding?.rvColockerSelected?.adapter?.notifyDataSetChanged()
-                        mBinding?.rvColockerInside?.adapter?.notifyDataSetChanged()
                     }
                 }
             }
@@ -161,22 +181,31 @@ class WorkerFragment(val goBack: () -> Unit, val changePage: (PageChangeBO) -> U
                         mSelectedList.any { it.userId == user.userId }
                     holder.setText(R.id.tv_name, user.nickName)
                     holder.setOnClickListener(R.id.root) {
-                        // 外部共锁人选择
-                        if (mSelectedList.any { it.userId == user.userId }) {
-                            mSelectedList.removeIf { it.userId == user.userId }
-                            mColockerSelectedShowList.removeIf { it.userId == user.userId }
-                        } else {
-                            val addUser = TicketUserReqVO(
-                                user.userId!!,
-                                user.nickName!!,
-                                "1",
-                                USER_ROLE_COLOCKER
-                            )
-                            mSelectedList.add(addUser)
-                            mColockerSelectedShowList.add(addUser)
+                        if (presenter?.colockerOutsideCanAdd(
+                                requireContext(),
+                                user,
+                                mStep
+                            ) == true
+                        ) {
+                            // 外部共锁人选择
+                            if (mSelectedList.any { it.userId == user.userId }) {
+                                mSelectedList.removeIf { it.userId == user.userId }
+                                mColockerSelectedShowList.removeIf { it.userId == user.userId }
+                            } else {
+                                val addUser = TicketUserReqVO(
+                                    user.userId!!,
+                                    user.nickName!!,
+                                    "1",
+                                    USER_ROLE_COLOCKER,
+                                    ticketUserVOList.find { ticketUser -> ticketUser.userId == user.userId }?.jobStatus
+                                )
+                                mSelectedList.add(addUser)
+                                mColockerSelectedShowList.add(addUser)
+                            }
+                            mBinding?.rvColockerSelected?.adapter?.notifyDataSetChanged()
+                            mBinding?.rvColockerOutside?.adapter?.notifyDataSetChanged()
+                            isColockerChanged = true
                         }
-                        mBinding?.rvColockerSelected?.adapter?.notifyDataSetChanged()
-                        mBinding?.rvColockerOutside?.adapter?.notifyDataSetChanged()
                     }
                 }
             }
@@ -211,6 +240,8 @@ class WorkerFragment(val goBack: () -> Unit, val changePage: (PageChangeBO) -> U
         mBinding?.layoutLocker?.root?.visibility = View.INVISIBLE
 
         presenter?.getTicketDetail(pageChangeBO.ticketId) {
+            ticketUserVOList.clear()
+            ticketUserVOList.addAll(it?.ticketUserVOList ?: mutableListOf())
             mBinding?.tvTitle?.text = it?.ticketName
 
             if (it?.ticketUserVOList.isNullOrEmpty()) {
@@ -227,7 +258,8 @@ class WorkerFragment(val goBack: () -> Unit, val changePage: (PageChangeBO) -> U
                         user.userId!!,
                         user.userName!!,
                         user.userType!!,
-                        user.userRole!!
+                        user.userRole!!,
+                        user.jobStatus
                     )
                 )
             }
@@ -241,7 +273,8 @@ class WorkerFragment(val goBack: () -> Unit, val changePage: (PageChangeBO) -> U
                             it.userId!!,
                             it.userName!!,
                             it.userType!!,
-                            USER_ROLE_LOCKER
+                            USER_ROLE_LOCKER,
+                            user.jobStatus
                         )
                     )
                     mBinding?.layoutLocker?.root?.visibility = View.VISIBLE
@@ -271,7 +304,8 @@ class WorkerFragment(val goBack: () -> Unit, val changePage: (PageChangeBO) -> U
                             it.userId!!,
                             it.nickName!!,
                             "0",
-                            USER_ROLE_LOCKER
+                            USER_ROLE_LOCKER,
+                            ticketUserVOList.find { ticketUser -> ticketUser.userId == it.userId }?.jobStatus
                         )
                     )
                     mBinding?.layoutLocker?.root?.visibility = View.VISIBLE
@@ -298,6 +332,8 @@ class WorkerFragment(val goBack: () -> Unit, val changePage: (PageChangeBO) -> U
         }
 
         presenter?.getStepDetail(pageChangeBO.ticketId!!) {
+            mStepDetailList.clear()
+            mStepDetailList.addAll(it ?: mutableListOf())
             mBinding?.tvWorker?.text =
                 "${it?.get(2)?.userNum}/${it?.get(4)?.userNum}/${it?.get(7)?.userNum}"
             mBinding?.tvLock?.text =

+ 2 - 14
app/src/main/java/com/grkj/iscs/view/presenter/JobProgressPresenter.kt

@@ -28,6 +28,7 @@ import com.grkj.iscs.util.log.LogUtil
 import com.grkj.iscs.view.base.BasePresenter
 import com.grkj.iscs.view.dialog.TipDialog
 import com.grkj.iscs.view.iview.IJobProgressView
+import com.grkj.iscs.view.step_mode.IStepMode
 
 class JobProgressPresenter : BasePresenter<IJobProgressView>() {
     private var tipDialog: TipDialog? = null
@@ -322,19 +323,6 @@ class JobProgressPresenter : BasePresenter<IJobProgressView>() {
         mPointList: MutableList<TicketDetailMonitorRespVO.IsJobTicketPointsVO>,
         mUserList: MutableList<TicketDetailMonitorRespVO.IsJobTicketUser>
     ): Boolean {
-        val stepMode = SPUtils.getStepMode(context)
-        return when (stepMode) {
-            0 -> {
-                !mPointList.all { it.pointStatus == "2" }
-            }
-
-            1 -> {
-                !mPointList.all { it.pointStatus == "2" } && mUserList.all { it.jobStatus == 5 }
-            }
-
-            else -> {
-                false
-            }
-        }
+        return IStepMode.getStepMode(context)?.showGoToUnlock(mPointList, mUserList) == true
     }
 }

+ 3 - 47
app/src/main/java/com/grkj/iscs/view/presenter/StepPresenter.kt

@@ -13,6 +13,7 @@ import com.grkj.iscs.util.SPUtils
 import com.grkj.iscs.util.ToastUtils
 import com.grkj.iscs.view.base.BasePresenter
 import com.grkj.iscs.view.iview.IStepView
+import com.grkj.iscs.view.step_mode.IStepMode
 
 class StepPresenter : BasePresenter<IStepView>() {
 
@@ -92,20 +93,7 @@ class StepPresenter : BasePresenter<IStepView>() {
      * 是否可以修改共锁人
      */
     fun canModifyColocker(context: Context, step: Int): Boolean {
-        val stepMode = SPUtils.getStepMode(context)
-        return when (stepMode) {
-            0 -> {
-                step > 5
-            }
-
-            1 -> {
-                step in 3..7
-            }
-
-            else -> {
-                false
-            }
-        }
+        return IStepMode.getStepMode(context)?.canModifyColocker(step) == true
     }
 
     /**
@@ -116,38 +104,6 @@ class StepPresenter : BasePresenter<IStepView>() {
         step: Int,
         mTicketDetailData: TicketDetailRespVO?
     ): String {
-        val stepMode = SPUtils.getStepMode(context)
-        return when (stepMode) {
-            0 -> {
-                when (step) {
-                    else -> ""
-                }
-            }
-
-            1 -> {
-                when (step) {
-                    6 -> {
-                        if (mTicketDetailData?.ticketUserVOList?.all { it.jobStatus!! >= 4 } == true) {
-                            ""
-                        } else {
-                            context.getString(R.string.please_wait_all_colocker_locked)
-                        }
-                    }
-
-                    8 -> {
-                        if (mTicketDetailData?.ticketUserVOList?.all { it.jobStatus!! == 5 } == true && mTicketDetailData.ticketPointsVOList?.all { it.pointStatus == "2" } == true) {
-                            ""
-                        } else {
-                            context.getString(R.string.please_wait_all_colocker_and_points_unlocked)
-                        }
-                    }
-                    else -> ""
-                }
-            }
-
-            else -> {
-                ""
-            }
-        }
+        return IStepMode.getStepMode(context)?.checkCanContinue(step, mTicketDetailData) ?: ""
     }
 }

+ 29 - 16
app/src/main/java/com/grkj/iscs/view/presenter/WorkerPresenter.kt

@@ -9,10 +9,10 @@ import com.grkj.iscs.model.vo.ticket.TicketUserReqVO
 import com.grkj.iscs.model.vo.user.UserListRespVO
 import com.grkj.iscs.util.Executor
 import com.grkj.iscs.util.NetApi
-import com.grkj.iscs.util.SPUtils
 import com.grkj.iscs.util.ToastUtils
 import com.grkj.iscs.view.base.BasePresenter
 import com.grkj.iscs.view.iview.IWorkerView
+import com.grkj.iscs.view.step_mode.IStepMode
 
 class WorkerPresenter : BasePresenter<IWorkerView>() {
     /**
@@ -75,23 +75,36 @@ class WorkerPresenter : BasePresenter<IWorkerView>() {
      * 是否可以移除共锁人
      */
     fun colockerCanRemove(context: Context, data: TicketUserReqVO, step: Int): Boolean {
-        val stepMode = SPUtils.getStepMode(context)
-        return when (stepMode) {
-            0 -> {
-                true
-            }
+        return IStepMode.getStepMode(context)?.colockerCanRemove(data, step) == true
+    }
 
-            1 -> {
-                when (step) {
-                    3, 4 -> {
-                        true
-                    }
+    /**
+     * 内部共锁人是否可以添加
+     */
+    fun colockerInsideCanAdd(
+        context: Context,
+        user: UserListRespVO.Row,
+        mStep: Int
+    ): Boolean {
+        return IStepMode.getStepMode(context)?.colockerInsideCanAdd(user, mStep) == true
+    }
 
-                    else -> false
-                }
-            }
+    /**
+     * 外部共锁人是否可以添加
+     */
+    fun colockerOutsideCanAdd(context: Context, user: UserListRespVO.Row, mStep: Int): Boolean {
+        return IStepMode.getStepMode(context)?.colockerOutsideCanAdd(user, mStep) == true
+    }
 
-            else -> false
-        }
+    /**
+     * 检查步骤跳转
+     */
+    fun checkColockerChangedStepJump(
+        context: Context,
+        stepDetailList: MutableList<StepDetailRespVO>,
+        mStep: Int,
+        jumpSuccess:()->Unit
+    ) {
+        IStepMode.getStepMode(context)?.checkStepJump(mStep, stepDetailList,jumpSuccess)
     }
 }

+ 74 - 0
app/src/main/java/com/grkj/iscs/view/step_mode/IStepMode.kt

@@ -0,0 +1,74 @@
+package com.grkj.iscs.view.step_mode
+
+import android.content.Context
+import com.grkj.iscs.model.vo.ticket.StepDetailRespVO
+import com.grkj.iscs.model.vo.ticket.TicketDetailMonitorRespVO
+import com.grkj.iscs.model.vo.ticket.TicketDetailRespVO
+import com.grkj.iscs.model.vo.ticket.TicketUserReqVO
+import com.grkj.iscs.model.vo.user.UserListRespVO
+import com.grkj.iscs.util.SPUtils
+
+/**
+ * 步骤模式
+ */
+interface IStepMode {
+    /**
+     * 是否可以修改共锁人
+     */
+    fun canModifyColocker(step: Int): Boolean
+
+    /**
+     * 是否可以移除共锁人
+     */
+    fun colockerCanRemove(data: TicketUserReqVO, step: Int): Boolean
+
+    /**
+     * 检查是否可以继续
+     */
+    fun checkCanContinue(
+        step: Int,
+        mTicketDetailData: TicketDetailRespVO?
+    ): String
+
+    /**
+     * 是否显示去解锁
+     */
+    fun showGoToUnlock(
+        mPointList: MutableList<TicketDetailMonitorRespVO.IsJobTicketPointsVO>,
+        mUserList: MutableList<TicketDetailMonitorRespVO.IsJobTicketUser>
+    ): Boolean
+
+    /**
+     * 内部共锁人是否可以添加
+     */
+    fun colockerInsideCanAdd(user: UserListRespVO.Row, mStep: Int): Boolean
+
+    /**
+     * 外部共锁人是否可以添加
+     */
+    fun colockerOutsideCanAdd(user: UserListRespVO.Row, mStep: Int): Boolean
+
+    /**
+     * 根据步骤检查是否需要跳转
+     */
+    fun checkStepJump(
+        mStep: Int,
+        stepDetailList: MutableList<StepDetailRespVO>,
+        jumpSuccess: () -> Unit
+    )
+
+    companion object {
+        /**
+         * 根据存储的模式获取模式
+         */
+        @JvmStatic
+        fun getStepMode(context: Context): IStepMode? {
+            val stepMode = SPUtils.getStepMode(context)
+            return when (stepMode) {
+                0 -> StepMode1()
+                1 -> StepMode2()
+                else -> null
+            }
+        }
+    }
+}

+ 53 - 0
app/src/main/java/com/grkj/iscs/view/step_mode/StepMode1.kt

@@ -0,0 +1,53 @@
+package com.grkj.iscs.view.step_mode
+
+import android.content.Context
+import com.grkj.iscs.model.vo.ticket.StepDetailRespVO
+import com.grkj.iscs.model.vo.ticket.TicketDetailMonitorRespVO
+import com.grkj.iscs.model.vo.ticket.TicketDetailRespVO
+import com.grkj.iscs.model.vo.ticket.TicketUserReqVO
+import com.grkj.iscs.model.vo.user.UserListRespVO
+
+/**
+ * 模式1
+ */
+class StepMode1 : IStepMode {
+    override fun canModifyColocker(step: Int): Boolean {
+        return step > 5
+    }
+
+    override fun colockerCanRemove(data: TicketUserReqVO, step: Int): Boolean {
+        return true
+    }
+
+    override fun checkCanContinue(
+        step: Int,
+        mTicketDetailData: TicketDetailRespVO?
+    ): String {
+        return when (step) {
+            else -> ""
+        }
+    }
+
+    override fun showGoToUnlock(
+        mPointList: MutableList<TicketDetailMonitorRespVO.IsJobTicketPointsVO>,
+        mUserList: MutableList<TicketDetailMonitorRespVO.IsJobTicketUser>
+    ): Boolean {
+        return !mPointList.all { it.pointStatus == "2" }
+    }
+
+    override fun colockerInsideCanAdd(user: UserListRespVO.Row, mStep: Int): Boolean {
+        return true
+    }
+
+    override fun colockerOutsideCanAdd(user: UserListRespVO.Row, mStep: Int): Boolean {
+        return true
+    }
+
+    override fun checkStepJump(
+        mStep: Int,
+        stepDetailList: MutableList<StepDetailRespVO>,
+        jumpSuccess: () -> Unit
+    ) {
+        jumpSuccess()
+    }
+}

+ 116 - 0
app/src/main/java/com/grkj/iscs/view/step_mode/StepMode2.kt

@@ -0,0 +1,116 @@
+package com.grkj.iscs.view.step_mode
+
+import androidx.core.content.ContextCompat
+import com.grkj.iscs.MyApplication
+import com.grkj.iscs.R
+import com.grkj.iscs.model.vo.ticket.StepDetailRespVO
+import com.grkj.iscs.model.vo.ticket.TicketDetailMonitorRespVO
+import com.grkj.iscs.model.vo.ticket.TicketDetailRespVO
+import com.grkj.iscs.model.vo.ticket.TicketUserReqVO
+import com.grkj.iscs.model.vo.user.UserListRespVO
+import com.grkj.iscs.util.NetApi
+import com.grkj.iscs.util.log.LogUtil
+
+class StepMode2 : IStepMode {
+    override fun canModifyColocker(step: Int): Boolean {
+        return step in 3..7
+    }
+
+    override fun colockerCanRemove(data: TicketUserReqVO, step: Int): Boolean {
+        return when (step) {
+            3, 4 -> {
+                true
+            }
+
+            5 -> {
+                if (data.jobStatus == null) {
+                    false
+                } else {
+                    data.jobStatus < 4
+                }
+            }
+
+            else -> false
+        }
+    }
+
+    override fun checkCanContinue(step: Int, mTicketDetailData: TicketDetailRespVO?): String {
+        return when (step) {
+            6 -> {
+                if (mTicketDetailData?.ticketUserVOList?.all { it.jobStatus!! >= 4 } == true) {
+                    ""
+                } else {
+                    ContextCompat.getString(
+                        MyApplication.instance?.applicationContext!!,
+                        R.string.please_wait_all_colocker_locked
+                    )
+                }
+            }
+
+            8 -> {
+                if (mTicketDetailData?.ticketUserVOList?.all { it.jobStatus!! == 5 } == true && mTicketDetailData.ticketPointsVOList?.all { it.pointStatus == "2" } == true) {
+                    ""
+                } else {
+                    ContextCompat.getString(
+                        MyApplication.instance?.applicationContext!!,
+                        R.string.please_wait_all_colocker_and_points_unlocked
+                    )
+                }
+            }
+
+            else -> ""
+        }
+    }
+
+    override fun showGoToUnlock(
+        mPointList: MutableList<TicketDetailMonitorRespVO.IsJobTicketPointsVO>,
+        mUserList: MutableList<TicketDetailMonitorRespVO.IsJobTicketUser>
+    ): Boolean {
+        return !mPointList.all { it.pointStatus == "2" } && mUserList.all { it.jobStatus == 5 }
+    }
+
+    override fun colockerInsideCanAdd(user: UserListRespVO.Row, mStep: Int): Boolean {
+        return when (mStep) {
+            3, 4, 5, 6, 7 -> {
+                true
+            }
+
+            else -> false
+        }
+    }
+
+    override fun colockerOutsideCanAdd(user: UserListRespVO.Row, mStep: Int): Boolean {
+        return when (mStep) {
+            3, 4, 5, 6, 7 -> {
+                true
+            }
+
+            else -> false
+        }
+    }
+
+    override fun checkStepJump(
+        mStep: Int,
+        stepDetailList: MutableList<StepDetailRespVO>,
+        jumpSuccess: () -> Unit
+    ) {
+        if (mStep < 8) {
+            //循环将前面的步骤状态重置,直到第五步
+            fun stepBack(step: Int) {
+                if (step > 5) {
+                    stepDetailList.find { it.stepIndex == step }?.stepId?.let {
+                        NetApi.updateStep(it, "0") { success ->
+                            if (success) {
+                                stepBack(step - 1)
+                            } else {
+                                LogUtil.i("重置步骤 ${step} 失败")
+                            }
+                        }
+                    }
+                }
+            }
+            stepBack(mStep)
+            jumpSuccess()
+        }
+    }
+}

+ 16 - 0
app/src/main/java/com/grkj/iscs/view/step_mode/StepModeEnums.kt

@@ -0,0 +1,16 @@
+package com.grkj.iscs.view.step_mode
+
+/**
+ * 步骤模式枚举
+ */
+enum class StepModeEnums(val type: Int, val description: String) {
+    /**
+     * 步骤模式1
+     */
+    STEP_MODE_ONE(0, "模式1"),
+
+    /**
+     * 步骤模式2
+     */
+    STEP_MODE_TWO(1, "模式2");
+}

+ 24 - 0
app/src/main/res/layout/fragment_system_setting.xml

@@ -130,6 +130,7 @@
             android:textSize="@dimen/common_text_size_big" />
 
         <LinearLayout
+            android:id="@+id/common_port_layout"
             android:layout_width="match_parent"
             android:layout_height="wrap_content"
             android:layout_below="@id/tv_port_title"
@@ -164,6 +165,29 @@
             </RelativeLayout>
         </LinearLayout>
 
+        <LinearLayout
+            android:layout_width="match_parent"
+            android:layout_height="wrap_content"
+            android:layout_below="@+id/common_port_layout"
+            android:orientation="vertical">
+
+            <TextView
+                style="@style/CommonTextView"
+                android:text="@string/step_mode_select" />
+
+            <androidx.core.widget.NestedScrollView
+                android:layout_width="match_parent"
+                android:layout_height="match_parent">
+
+                <RadioGroup
+                    android:id="@+id/step_mode_rg"
+                    android:layout_width="match_parent"
+                    android:layout_height="wrap_content"
+                    android:orientation="vertical" />
+            </androidx.core.widget.NestedScrollView>
+
+        </LinearLayout>
+
         <TextView
             android:id="@+id/tv_tip"
             style="@style/CommonTextView"

+ 4 - 0
app/src/main/res/values-en/strings.xml

@@ -316,4 +316,8 @@
     <string name="all_point_already_locked">all point already locked</string>
     <string name="please_wait_all_colocker_locked">please wait all colocker locked</string>
     <string name="please_wait_all_colocker_and_points_unlocked">please wait all colocker and points unlocked</string>
+    <string name="step_mode_select">select step mode</string>
+    <string name="mode_one">mode 1</string>
+    <string name="mode_two">mode 2</string>
+    <string name="step_mode_change_success">step mode change success</string>
 </resources>

+ 4 - 0
app/src/main/res/values-zh/strings.xml

@@ -316,4 +316,8 @@
     <string name="all_point_already_locked">所有隔离点已上锁</string>
     <string name="please_wait_all_colocker_locked">请等待所有共锁人上锁</string>
     <string name="please_wait_all_colocker_and_points_unlocked">请等待所有共锁人和隔离点解锁</string>
+    <string name="step_mode_select">选择流程模式</string>
+    <string name="mode_one">模式1</string>
+    <string name="mode_two">模式2</string>
+    <string name="step_mode_change_success">流程模式切换成功</string>
 </resources>

+ 4 - 0
app/src/main/res/values/strings.xml

@@ -316,4 +316,8 @@
     <string name="all_point_already_locked">所有隔离点已上锁</string>
     <string name="please_wait_all_colocker_locked">请等待所有共锁人上锁</string>
     <string name="please_wait_all_colocker_and_points_unlocked">请等待所有共锁人和隔离点解锁</string>
+    <string name="step_mode_select">选择流程模式</string>
+    <string name="mode_one">模式1</string>
+    <string name="mode_two">模式2</string>
+    <string name="step_mode_change_success">流程模式切换成功</string>
 </resources>