diff --git a/.idea/dbnavigator.xml b/.idea/dbnavigator.xml index 0f70c694ac6d2d5027cab2a03c1a9727172acfde..449d1ced2b7ebdbea2398a112089507d37362171 100644 --- a/.idea/dbnavigator.xml +++ b/.idea/dbnavigator.xml @@ -8,20 +8,127 @@ - + + + + + + + + + + + + + + + + + + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
@@ -420,4 +527,7 @@
+ + + \ No newline at end of file diff --git a/HttpLibrary/src/main/java/com/ym/httplibrary/base/BaseModel.kt b/HttpLibrary/src/main/java/com/ym/httplibrary/base/BaseModel.kt index e30678470a149c795fd3b05fc1fe4a18cebe96e7..eaddeb680618347b3c8e07a71ce8bb17fe68c950 100644 --- a/HttpLibrary/src/main/java/com/ym/httplibrary/base/BaseModel.kt +++ b/HttpLibrary/src/main/java/com/ym/httplibrary/base/BaseModel.kt @@ -8,9 +8,6 @@ import com.ym.httplibrary.response.IBaseResponse * Create by lindepeng on 2020/12/2. */ abstract class BaseModel { - /** - * 解析本地或网路数据 - */ suspend fun cacheNetCall( remoto: suspend () -> IBaseResponse, local: suspend () -> T?, @@ -27,26 +24,4 @@ abstract class BaseModel { throw ResponseThrowable(net) } } - - /** - * 解析网路数据 - */ - suspend fun resultNetCall( - net:suspend ()->IBaseResponse - ):T{ - val net = net() - if (net.isSuccess()){ - return net.data()!! - } - throw ResponseThrowable(net) - } - /** - * 解析本地数据 - */ - suspend fun resultLocalCall( - local: suspend () -> T?, - ): T { - val localData = local() - return localData!! - } } \ No newline at end of file diff --git a/HttpLibrary/src/main/java/com/ym/httplibrary/network/interceptor/HttpLogInterceptor.kt b/HttpLibrary/src/main/java/com/ym/httplibrary/network/interceptor/HttpLogInterceptor.kt index ae30abf01730b613f515148a91165b2677a5a63a..e1193d86734ccfd4b96bb5edb26af74a67750c5b 100644 --- a/HttpLibrary/src/main/java/com/ym/httplibrary/network/interceptor/HttpLogInterceptor.kt +++ b/HttpLibrary/src/main/java/com/ym/httplibrary/network/interceptor/HttpLogInterceptor.kt @@ -5,7 +5,6 @@ import kotlin.jvm.JvmOverloads import kotlin.jvm.Volatile import okhttp3.* import okio.Buffer -import kotlin.Throws import java.io.EOFException import java.io.IOException import java.lang.Exception diff --git a/HttpLibrary/src/main/java/com/ym/httplibrary/viewmodel/BaseViewModel.kt b/HttpLibrary/src/main/java/com/ym/httplibrary/viewmodel/BaseViewModel.kt index 80d5fa1d0934887cbfbef2530753a28341e81f2b..89746e2172dce70dd01daff32fffbc9304a959c2 100644 --- a/HttpLibrary/src/main/java/com/ym/httplibrary/viewmodel/BaseViewModel.kt +++ b/HttpLibrary/src/main/java/com/ym/httplibrary/viewmodel/BaseViewModel.kt @@ -104,7 +104,7 @@ open class BaseViewModel : ViewModel(), LifecycleObserver { }, { - defUI.dismissDialog.call() +// defUI.dismissDialog.call() complete() } ) @@ -140,7 +140,7 @@ open class BaseViewModel : ViewModel(), LifecycleObserver { private suspend fun executeResponse( response: IBaseResponse, success: suspend CoroutineScope.(T?) -> Unit, - wrong: suspend CoroutineScope.(ResponseThrowable) -> Unit, + wrong: suspend CoroutineScope.(ResponseThrowable) -> Unit ) { coroutineScope { if (response.isSuccess()) { @@ -185,6 +185,7 @@ open class BaseViewModel : ViewModel(), LifecycleObserver { try { block() } catch (e: Throwable) { + defUI.toastEvent.value = e.message error(ExceptionHandle.handleException(e)) } finally { complete() diff --git a/app/build.gradle b/app/build.gradle index 8a70d49ee4a164e6f85748c616b0dd7644643a48..9ba42182b8c0199c70a3fae18867939d4c78eec6 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -33,20 +33,23 @@ android { buildTypes { release { minifyEnabled false + resValue("string", "app_name", "平阳生产") + proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' -// buildConfigField "String", "BASE_URL", '"https://scat.guangrufw.com"' - buildConfigField "String", "BASE_URL", '"http://10.11.2.231:30760"' + buildConfigField "String", "BASE_URL", '"https://itp.inm.cc"' signingConfig signingConfigs.signing } + debug { minifyEnabled false + resValue("string", "app_name", "平阳生产_debug") proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' -// buildConfigField "String", "BASE_URL", '"https://scat.guangrufw.com"' buildConfigField "String", "BASE_URL", '"http://10.11.2.231:30760"' - signingConfig signingConfigs.signing + applicationIdSuffix ".debug" + signingConfig signingConfigs.signing } } @@ -91,6 +94,11 @@ dependencies { implementation project(path: ':HttpLibrary') implementation "com.android.support:multidex:1.0.0" + //Room + api rootProject.ext.room["room-runtime"] + api rootProject.ext.room["room-ktx"] + kapt rootProject.ext.room["room-compiler"] + testImplementation rootProject.ext.room["room-testing"] diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index ebc0d465477286861489702d54934b053bac5f72..b73282143a9f78e819891f18ad5defcb9211fa98 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -30,10 +30,17 @@ + android:windowSoftInputMode="adjustResize"/> - + + + + diff --git a/app/src/main/java/com/ym/pysc/MyApplication.kt b/app/src/main/java/com/ym/pysc/MyApplication.kt index 2153f4a8646edd80f269e02417b4fc93684713a3..0343e73fa945faf535237d769e87b84e9b121966 100644 --- a/app/src/main/java/com/ym/pysc/MyApplication.kt +++ b/app/src/main/java/com/ym/pysc/MyApplication.kt @@ -2,10 +2,12 @@ package com.ym.pysc import android.app.Application import com.android.commonlibrary.app.LibraryConfig +import com.ym.pysc.utils.BaseDataManager class MyApplication : Application() { override fun onCreate() { super.onCreate() + BaseDataManager.initialize(this) //初始化AndroidLibrary initAndroidFrame() } diff --git a/app/src/main/java/com/ym/pysc/adapter/ItemPopAdapter.kt b/app/src/main/java/com/ym/pysc/adapter/ItemPopAdapter.kt index 6104d44e4ffcc4e5d8cb89d52dfa0e95b522008b..3d04138d2307961be37122da8730f6fc2f7cf1db 100644 --- a/app/src/main/java/com/ym/pysc/adapter/ItemPopAdapter.kt +++ b/app/src/main/java/com/ym/pysc/adapter/ItemPopAdapter.kt @@ -40,7 +40,11 @@ class ItemViewHolder( ) : BaseHolder(binding) { override fun onBind(item: ItemInfo) { - binding.info=item + val myItem = ItemInfo(name = item.name, + code = item.code, + isClicked = item.isClicked, + type = item.type) + binding.info=myItem binding.root.setOnClickListener { callback(item) } diff --git a/app/src/main/java/com/ym/pysc/api/InjectorUtil.kt b/app/src/main/java/com/ym/pysc/api/InjectorUtil.kt index 59d7d4a3b7ad72524fe732dd147200d0cd5a9466..dd56622a21aec3c869839be71d31f7be44ce242e 100644 --- a/app/src/main/java/com/ym/pysc/api/InjectorUtil.kt +++ b/app/src/main/java/com/ym/pysc/api/InjectorUtil.kt @@ -1,10 +1,27 @@ package com.ym.pysc.api +import com.ym.pysc.model.db.PYSCDataBase +import com.ym.pysc.repository.DefectiveRepository +import com.ym.pysc.repository.RiskRepository +import com.ym.pysc.repository.NetContentRepository + /** * Create by lindepeng on 2021/9/10. */ object InjectorUtil { fun getRepository() = Repository.getInstance( + NetWork.getInstance() + ) + fun getDefectiveRepository() = DefectiveRepository.getInstance( + NetWork.getInstance(), + PYSCDataBase.getInstance().getDefectInfoLocaData() + ) + fun getNetContentRepository() = NetContentRepository.getInstance( + NetWork.getInstance(), + PYSCDataBase.getInstance().getNetContentLocaData() + ) + fun getRiskRepository() = RiskRepository.getInstance( NetWork.getInstance(), + PYSCDataBase.getInstance().getRiskInfoLocaData() ) } \ No newline at end of file diff --git a/app/src/main/java/com/ym/pysc/api/NetWork.kt b/app/src/main/java/com/ym/pysc/api/NetWork.kt index dc7026a79e6c234532fa8bd0b4c139d8635ee669..e00b82c4ded7eba6905671e6b57ae69687ece3b2 100644 --- a/app/src/main/java/com/ym/pysc/api/NetWork.kt +++ b/app/src/main/java/com/ym/pysc/api/NetWork.kt @@ -3,20 +3,32 @@ package com.ym.pysc.api import com.ym.pysc.http.IServerApi import com.ym.pysc.http.RetrofitClient import com.ym.pysc.model.GainDefectInfo +import com.ym.pysc.model.GainRiskInfo import com.ym.pysc.model.GainNetContent class NetWork { public val mService by lazy { RetrofitClient.getInstance().create(IServerApi::class.java) } suspend fun login(params:HashMap) = mService.login(params) suspend fun checkVersion(params:HashMap) = mService.checkVersion(params) - suspend fun myWorkshop() = mService.myWorkshop() - suspend fun gainLine(params:HashMap) = mService.gainLine(params) - suspend fun gainProduct(params:HashMap) = mService.gainProduct(params) + suspend fun baseWorkshop() = mService.baseWorkshop() + suspend fun baseDefectiveType()=mService.baseDefectiveType() + suspend fun baseRisk()=mService.baseRisk() + suspend fun baseRiskHead()=mService.baseRiskHead() + suspend fun checkRating()=mService.checkRating() + suspend fun defectiveHistory(params:HashMap)=mService.defectiveHistory(params) + suspend fun netContentHistory(params:HashMap)=mService.netContentHistory(params) + suspend fun riskHistory(params:HashMap)=mService.riskHistory(params) + suspend fun insertDefect(params:MutableList)=mService.insertDefect(params) + suspend fun insertNet(params:MutableList)=mService.insertNet(params) + suspend fun insertFengxian(params:MutableList)=mService.insertFengxian(params) +// suspend fun myWorkshop() = mService.myWorkshop() +// suspend fun gainLine(params:HashMap) = mService.gainLine(params) +// suspend fun gainProduct(params:HashMap) = mService.gainProduct(params) suspend fun gainNetContent(params:HashMap) = mService.gainNetContent(params) - suspend fun insertNetContent(params:HashMap) = mService.insertNetContent(params) +// suspend fun insertNetContent(params:GainNetContent) = mService.insertNetContent(params) suspend fun gainDefectInfo(params:HashMap) = mService.gainDefectInfo(params) - suspend fun gainDefectTotal(params:HashMap) = mService.gainDefectTotal(params) - suspend fun insertDefectInfo(params:HashMap) = mService.insertDefectInfo(params) + suspend fun gainDefectTotal(params:HashMap) = mService.gainDefectTotal(params) + suspend fun insertDefectInfo(params:GainDefectInfo) = mService.insertDefectInfo(params) companion object{ @Volatile diff --git a/app/src/main/java/com/ym/pysc/api/Repository.kt b/app/src/main/java/com/ym/pysc/api/Repository.kt index 80525ddf72897d3441c45010bb66c613fca0e070..c00ee1bd35acb33d6020973f1d52245ba818d95d 100644 --- a/app/src/main/java/com/ym/pysc/api/Repository.kt +++ b/app/src/main/java/com/ym/pysc/api/Repository.kt @@ -3,6 +3,7 @@ package com.ym.pysc.api import com.ym.httplibrary.base.BaseData import com.ym.httplibrary.base.BaseModel import com.ym.pysc.model.GainDefectInfo +import com.ym.pysc.model.GainRiskInfo import com.ym.pysc.model.GainNetContent import com.ym.pysc.model.UpdateVersion import com.ym.pysc.model.UserInfo @@ -18,16 +19,23 @@ class Repository private constructor( return network.login(parmas) } suspend fun checkVersion(parmas: HashMap): BaseData { + return network.checkVersion(parmas) } - suspend fun myWorkshop()=network.myWorkshop() - suspend fun gainLine(parmas: HashMap)=network.gainLine(parmas) - suspend fun gainProduct(params:HashMap) = network.gainProduct(params) + suspend fun baseWorkshop()=network.baseWorkshop() + suspend fun baseDefectiveType()=network.baseDefectiveType() + suspend fun baseRisk()=network.baseRisk() + suspend fun baseRiskHead()=network.baseRiskHead() + suspend fun checkRating()=network.checkRating() + suspend fun defectiveHistory(params:HashMap)=network.defectiveHistory(params) + suspend fun netContentHistory(params:HashMap)=network.netContentHistory(params) + suspend fun riskHistory(params:HashMap)=network.riskHistory(params) + suspend fun insertDefect(params:MutableList)=network.insertDefect(params) + suspend fun insertNet(params:MutableList)=network.insertNet(params) + suspend fun insertFengxian(params:MutableList)=network.insertFengxian(params) + suspend fun gainNetContent(params:HashMap) = network.gainNetContent(params) - suspend fun insertNetContent(params:HashMap) = network.insertNetContent(params) - suspend fun gainDefectInfo(params:HashMap) = network.gainDefectInfo(params) - suspend fun gainDefectTotal(params:HashMap) = network.gainDefectTotal(params) - suspend fun insertDefectInfo(params:HashMap) = network.insertDefectInfo(params) + suspend fun gainDefectTotal(params:HashMap) = network.gainDefectTotal(params) companion object { @Volatile private var INSTANCE: Repository? = null diff --git a/app/src/main/java/com/ym/pysc/download/DownloadUtils.kt b/app/src/main/java/com/ym/pysc/download/DownloadUtils.kt index bc1942e737d77769327fbd1771c60b653aa7b13e..6af6cd57abd06e3bed658ee668a24bf2fcd0b2b7 100644 --- a/app/src/main/java/com/ym/pysc/download/DownloadUtils.kt +++ b/app/src/main/java/com/ym/pysc/download/DownloadUtils.kt @@ -3,7 +3,6 @@ package com.ym.pysc.download import okhttp3.ResponseBody import retrofit2.Retrofit import okhttp3.OkHttpClient -import kotlin.Throws import retrofit2.Call import retrofit2.Callback import retrofit2.Response diff --git a/app/src/main/java/com/ym/pysc/download/ProgressResponseBody.kt b/app/src/main/java/com/ym/pysc/download/ProgressResponseBody.kt index d6809a172fae8901894731c13f45974c41895c05..6221512d046203efd6c79e9943691bc9ab67aee4 100644 --- a/app/src/main/java/com/ym/pysc/download/ProgressResponseBody.kt +++ b/app/src/main/java/com/ym/pysc/download/ProgressResponseBody.kt @@ -4,7 +4,6 @@ import okhttp3.MediaType import okhttp3.ResponseBody import okio.* import java.io.IOException -import kotlin.Throws /** * @Author ldp diff --git a/app/src/main/java/com/ym/pysc/function/ExtendedFunctions.kt b/app/src/main/java/com/ym/pysc/function/ExtendedFunctions.kt index 9fc6ee0822fbb48cb653093f33045a4b45872d27..d02a859cb572387a6649a6920102ea8905648ece 100644 --- a/app/src/main/java/com/ym/pysc/function/ExtendedFunctions.kt +++ b/app/src/main/java/com/ym/pysc/function/ExtendedFunctions.kt @@ -5,6 +5,7 @@ import android.text.TextWatcher import android.widget.EditText import android.widget.ImageView import android.widget.TextView +import com.blankj.utilcode.util.ToastUtils import com.ym.pysc.model.ItemInfo import com.ym.pysc.widget.ItemChangePop import kotlinx.coroutines.channels.awaitClose @@ -39,10 +40,14 @@ fun TextView.showItemPop( datas: MutableList?, selectItem: (ItemInfo) -> Unit ) { + if (datas.isNullOrEmpty()){ + ToastUtils.showShort("没有数据") + return + } var windowWidth = this.width val customPopupWindow = ItemChangePop(windowWidth, datas, this.context, callBack = { selectItem(it) - }, { + }, onDismiss = { imageView.rotation = 90f }) customPopupWindow.showAtFixedItem(this) diff --git a/app/src/main/java/com/ym/pysc/http/IServerApi.kt b/app/src/main/java/com/ym/pysc/http/IServerApi.kt index a2f8bdc738964162426781dea53b653ab6f307e7..f2b7b8192a9916dc1ffd891f9d442724f8be2ef2 100644 --- a/app/src/main/java/com/ym/pysc/http/IServerApi.kt +++ b/app/src/main/java/com/ym/pysc/http/IServerApi.kt @@ -2,11 +2,13 @@ package com.ym.pysc.http import com.ym.httplibrary.base.BaseData import com.ym.pysc.model.GainDefectInfo +import com.ym.pysc.model.GainRiskInfo import com.ym.pysc.model.GainNetContent import com.ym.pysc.model.ItemInfo +import com.ym.pysc.model.RiskHeadInfo import com.ym.pysc.model.UpdateVersion import com.ym.pysc.model.UserInfo -import com.ym.pysc.model.WorkShop +import com.ym.pysc.model.WorkShopInfo import retrofit2.http.* interface IServerApi { @@ -22,24 +24,70 @@ interface IServerApi { @POST("/api/system/defAppVersion/anyTenant/latest") suspend fun checkVersion(@Body params: HashMap): BaseData + /** + * 获取车间产线的基础数据 + */ + @GET("/api/inventory/process_offline/base_workshop") + suspend fun baseWorkshop(): BaseData> + + /** + * 获取车间产线的不良品类型 + */ + @GET("/api/inventory/process_offline/base_type") + suspend fun baseDefectiveType(): BaseData> + + /** + * 获取风险点检查基础数据 + */ + @GET("/api/inventory/process_offline/base_risk") + suspend fun baseRisk(): BaseData> /** - * 获取我拥有的车间信息 + * 风险点基础头部数据 + */ + @GET("/api/inventory/process_offline/base_risk_head") + suspend fun baseRiskHead(): BaseData> + /** + * 风险点范围数据 */ - @GET("/api/inventory/processWorkshopUser/myWorkshop") - suspend fun myWorkshop(): BaseData> + @GET("/api/inventory/process_offline/check_rating") + suspend fun checkRating(): BaseData> + /** + * 获取不良品历史数据 + */ + @GET("/api/inventory/process_offline/defect_info") + suspend fun defectiveHistory(@QueryMap params:HashMap):BaseData> /** - * 根据工厂及车间获取产线信息 + *获取净含量历史数据 */ - @GET("/api/inventory/processProductLine/gainLine") - suspend fun gainLine(@QueryMap params: HashMap): BaseData> + @GET("/api/inventory/process_offline/net_content") + suspend fun netContentHistory(@QueryMap params:HashMap):BaseData> /** - * 根据工厂及车间获取产品信息 + *获取风险点历史数据 */ - @GET("/api/inventory/processWorkshopProduct/gainProduct") - suspend fun gainProduct(@QueryMap params: HashMap): BaseData> + + @GET("/api/inventory/process_offline/risk_info") + suspend fun riskHistory(@QueryMap params:HashMap):BaseData> + + + /** + *批量提交不良品信息 + */ + @POST("/api/inventory/process_offline/insert_defect") + suspend fun insertDefect(@Body params:MutableList):BaseData + /** + *批量提交净含量信息 + */ + @POST("/api/inventory/process_offline/insert_net") + suspend fun insertNet(@Body params:MutableList):BaseData + + /** + * 批量提交风险点 + */ + @POST("/api/inventory/process_offline/insert_risk") + suspend fun insertFengxian(@Body params:MutableList): BaseData /** * 获取净含量录入信息 @@ -47,11 +95,7 @@ interface IServerApi { @GET("/api/inventory/processNetContent/gainNetContent") suspend fun gainNetContent(@QueryMap params: HashMap): BaseData - /** - * 录入净含量信息 - */ - @POST("/api/inventory/processNetContent/insert") - suspend fun insertNetContent(@Body params:HashMap): BaseData + /** * 获取不良类型录入信息 @@ -63,12 +107,24 @@ interface IServerApi { * 不良类型小记 */ @GET("/api/inventory/processDefectInfo/gainDefectTotal") - suspend fun gainDefectTotal(@QueryMap params: HashMap): BaseData + suspend fun gainDefectTotal(@QueryMap params: HashMap): BaseData /** * 录入不良类型信息 */ @POST("/api/inventory/processDefectInfo/insert") - suspend fun insertDefectInfo(@Body params:HashMap): BaseData + suspend fun insertDefectInfo(@Body params:GainDefectInfo): BaseData + +// /** +// * 录入净含量信息 +// */ +// @POST("/api/inventory/processNetContent/insert") +// suspend fun insertNetContent(@Body params:GainNetContent): BaseData + +// /** +// * 风险点提交 +// */ +// @POST("") +// suspend fun insertFengxian(@Body params:GainRiskInfo): BaseData } \ No newline at end of file diff --git a/app/src/main/java/com/ym/pysc/http/RetrofitClient.kt b/app/src/main/java/com/ym/pysc/http/RetrofitClient.kt index b9eb4e8d9c5f8d497d438fc5873584b4ef0a2dd2..85f214ce2281ba3cc1e1a9a8e930f57b7e7ee53d 100644 --- a/app/src/main/java/com/ym/pysc/http/RetrofitClient.kt +++ b/app/src/main/java/com/ym/pysc/http/RetrofitClient.kt @@ -37,6 +37,7 @@ class RetrofitClient { return OkHttpClient.Builder() .connectTimeout(2L, TimeUnit.SECONDS) .addNetworkInterceptor(HttpLogInterceptor()) + .addInterceptor(TokenInterceptor()) .writeTimeout(2L, TimeUnit.SECONDS) .readTimeout(2L, TimeUnit.SECONDS) .addInterceptor(HeadersInterceptor()) diff --git a/app/src/main/java/com/ym/pysc/http/TokenInterceptor.kt b/app/src/main/java/com/ym/pysc/http/TokenInterceptor.kt new file mode 100644 index 0000000000000000000000000000000000000000..19556c9cbac4a9c71581dadd7ba630420b2b2aa3 --- /dev/null +++ b/app/src/main/java/com/ym/pysc/http/TokenInterceptor.kt @@ -0,0 +1,128 @@ +package com.ym.pysc.http + +import android.util.Log +import com.blankj.utilcode.util.SPUtils +import com.ym.pysc.BuildConfig +import com.ym.pysc.utils.constant +import com.ym.pysc.utils.constant.ACCOUNT +import com.ym.pysc.utils.constant.PASSWORD +import com.ym.pysc.utils.constant.PWD +import com.ym.pysc.utils.constant.USERNAME +import okhttp3.Interceptor +import okhttp3.OkHttpClient +import okhttp3.Request +import okhttp3.Response +import okhttp3.ResponseBody +import org.json.JSONObject +import retrofit2.Call +import retrofit2.Callback +import retrofit2.Retrofit +import retrofit2.adapter.rxjava.RxJavaCallAdapterFactory +import retrofit2.converter.gson.GsonConverterFactory +import retrofit2.http.Body +import retrofit2.http.POST +import java.util.concurrent.CountDownLatch + + +class TokenInterceptor : Interceptor { + private val tokenLatch = CountDownLatch(1) + + override fun intercept(chain: Interceptor.Chain): Response { + val originalRequest: Request = chain.request() + var response: Response = chain.proceed(originalRequest) +// var token: String = SPUtils.getInstance().getString(constant.TOKEN) + var isRefresh = false + // 检查返回的状态码,这里假设 401 表示 Token 过期 + Log.i("YM-http", "code:${response.code()}") + if (response.code() == 401) { + // 重新获取 Token + val retrofit = Retrofit.Builder() + .baseUrl(BuildConfig.BASE_URL) + .addConverterFactory(GsonConverterFactory.create()) + .addCallAdapterFactory(RxJavaCallAdapterFactory.create()) + .client(getOkHttpClient()) + .build() + val service = retrofit.create(ApiService::class.java) + val username = SPUtils.getInstance().getString(ACCOUNT) + val password = SPUtils.getInstance().getString(PWD) + val grantType = "PASSWORD" + var map = hashMapOf( + "username" to username, + "password" to password, + "grantType" to grantType + ) + + val get = service.login(map) + get.enqueue(object : Callback { + override fun onResponse( + call: Call, + response: retrofit2.Response + ) { + + if (response.isSuccessful) { + + val body = response.body() + + val reader = body!!.byteStream().bufferedReader() + val result = StringBuilder() + var line: String? + while (reader.readLine().also { line = it } != null) { + result.append(line) + } + + // 解析响应获取 Token + val jsonResponse = result.toString() + val jsonobject = JSONObject(jsonResponse) + val jsonData = jsonobject.getJSONObject("data") + val token = jsonData.getString("token") +// + SPUtils.getInstance().put(constant.TOKEN, token) + isRefresh = true + Log.i("YM-http", "刷新token:" + token) + + tokenLatch.countDown() + + } + } + + override fun onFailure(call: Call, t: Throwable) {} + }) + try { + // 等待异步获取 Token 的操作完成 + tokenLatch.await() + } catch (e: InterruptedException) { + e.printStackTrace() + } + } +// token = SPUtils.getInstance().getString(constant.TOKEN) + if (isRefresh) { +// val newRequest = originalRequest.newBuilder() +// .header("Token", "$token") +// .header("Authorization", BuildConfig.Authorization) +// .header("applicationId", BuildConfig.applicationId) +// .header("TenantId", BuildConfig.TenantId) +// .build() + Log.i("YM-http", "重新请求") + + return chain.proceed(originalRequest) + }else{ + isRefresh = false + return response + } + + } + + + private fun getOkHttpClient(): OkHttpClient { + val builder = OkHttpClient.Builder() + .addInterceptor(HeadersInterceptor()) + + return builder.build() + } + +} +interface ApiService { + @POST("/api/oauth/anyTenant/login") + fun login(@Body params: HashMap): Call + +} diff --git a/app/src/main/java/com/ym/pysc/model/datas.kt b/app/src/main/java/com/ym/pysc/model/datas.kt index 1da46532f94baf13664bf4ffe411c45a09a9700c..73ae1abd89b558d503fc3ef26d9927f509df7d29 100644 --- a/app/src/main/java/com/ym/pysc/model/datas.kt +++ b/app/src/main/java/com/ym/pysc/model/datas.kt @@ -1,6 +1,12 @@ package com.ym.pysc.model import androidx.annotation.Keep +import androidx.room.Entity +import androidx.room.PrimaryKey +import androidx.room.TypeConverters +import com.ym.pysc.model.db.converters.FengxianItemConverters +import com.ym.pysc.model.db.converters.RelateTypeConverters +import com.ym.pysc.utils.FloatUtil @Keep data class UserInfo( @@ -9,7 +15,7 @@ data class UserInfo( var token: String, var refreshToken: Int, var expire: String, - var expiration: String, + var expiration: String ) @Keep @@ -21,7 +27,7 @@ data class UpdateVersion( ) @Keep -data class WorkShop( +data class WorkShopInfo( /** * 工厂code */ @@ -38,8 +44,49 @@ data class WorkShop( * 车间名字 */ var workshopName: String, + /** + * 产线集合 + */ + var lineList: MutableList, + /** + * 产品集合 + */ + var productList: MutableList, + /** + * 不良品类型 + */ + var typeList: MutableList +) + +data class RiskHeadInfo( + /** + * 工厂code + */ + var factoryCode: String, + /** + * 工厂名字 + */ + var factoryName: String, + /** + * 车间code + */ + var workshopCode: String, + /** + * 车间名字 + */ + var workshopName: String, + /** + * 工序 + */ + var child: MutableList + ) +data class ChildItem( + var name: String, + var code: String, + var child: MutableList +) //@Keep //data class GainLineInfo( // /** @@ -62,25 +109,41 @@ data class WorkShop( // */ // var code: String, //) +/** + * 净含量表 + */ @Keep +@Entity(tableName = "gain_net_content") +@TypeConverters(RelateTypeConverters::class) data class GainNetContent( + @PrimaryKey + var id: Long = 0, /** * 工厂编码 */ - var factoryCode: String, + var factoryCode: String?, + var factoryName: String?, + /** * 车间编码 */ - var workshopCode: String, + var workshopCode: String?, + var workshopName: String?, + /** * 产线编码 */ - var lineCode: String, + var lineCode: String?, + var lineName: String?, /** * 产品编码 */ - var productCode: String, - + var productCode: String?, + var productName: String?, + /** + * 生产日期 + */ + var produceTime: String?, /** * 轮数 */ @@ -88,12 +151,9 @@ data class GainNetContent( /** * 总轮数 */ - var wheelTotal: Int, - - /** - * 生产日期 - */ - var produceTime: String, + var wheelTotal: Int = 0, + var status: Int = 0, + var average: String? = "", /** * 净含量详情 @@ -101,29 +161,41 @@ data class GainNetContent( var relateList: MutableList ) +/** + * 不良品表 + */ @Keep +@Entity(tableName = "gain_defect_info") +@TypeConverters(RelateTypeConverters::class) data class GainDefectInfo( + @PrimaryKey + var id: Long = 0, /** * 工厂编码 */ - var factoryCode: String, + var factoryCode: String?, + var factoryName: String?, + /** * 车间编码 */ - var workshopCode: String, + var workshopCode: String?, + var workshopName: String?, + /** * 产线编码 */ - var lineCode: String, + var lineCode: String?, + var lineName: String?, /** * 产品编码 */ - var productCode: String, - + var productCode: String?, + var productName: String?, /** * 生产日期 */ - var produceTime: String, + var produceTime: String?, /** * 轮数 */ @@ -131,13 +203,68 @@ data class GainDefectInfo( /** * 总轮数 */ - var wheelTotal: Int, + var wheelTotal: Int = 0, + var status: Int = 0, + /** * 数量详情 */ var relateList: MutableList ) +@Keep +@Entity(tableName = "gain_risk") +@TypeConverters(FengxianItemConverters::class) +data class GainRiskInfo( + @PrimaryKey + var id: Long = 0, + /** + * 工厂编码 + */ + var factoryCode: String?, + var factoryName: String?, + + /** + * 车间编码 + */ + var workshopCode: String?, + var workshopName: String?, + + /** + * 工序编码 + */ + var gxCode: String?, + var gxName: String?, + /** + * 工步编码 + */ + var gbCode: String?, + var gbName: String?, + + /** + * 日期 + */ + var produceTime: String?, + + var status: Int = 0, + /** + * 数量详情 + */ + var relateList: MutableList +) + +data class RiskInfoItem( + var infoId: String, + var fxyCode: String, + var fxyName: String, + var ywCode: String, + var ywName: String, + var standard: String, + var rating: String, + var ratingName: String, + var checkBox: String, + var remarks: String +) @Keep data class CommenData( @@ -151,43 +278,22 @@ data class ItemInfo( var name: String, var isClicked: Boolean = false, //类型: true:控制Edittext可编辑;false:不可编辑 - var type: Boolean = false + var type: Boolean = false, + + var standardValue: String? = "0", + var lowerLimit: String? = "0", + var upperLimit: String? = "0" ) @Keep -data class NetContentInfo( -// /** -// * 工厂编码 -// */ -// var factoryCode:String, -// /** -// * 车间编码 -// */ -// var workshopCode:String, -// /** -// * 产线编码 -// */ -// var lineCode:String, -// /** -// * 产品编码 -// */ -// var productCode:String, - - /** - * 轮数 - */ - var wheel: Int, - -// /** -// * 生产日期 -// */ -// var produceTime:String, - - /** - * 净含量详情 - */ - var relateList: MutableList +data class HistoryData( + var workshopName: String, + var lineName: String, + var productName: String, + var produceTime: String, + var totalWheel: String, + var status: String ) /** @@ -198,6 +304,17 @@ data class NetRelateInfo( var key: String?, var value: String?, var name: String?, -) + var standardValue: String? = "0", + var lowerLimit: String? = "0", + var upperLimit: String? = "0" + +) { + + var curValue: String? + get() = FloatUtil.getFloatValue(value) + set(newValue) { + value = newValue + } +} diff --git a/app/src/main/java/com/ym/pysc/model/db/PYSCDataBase.kt b/app/src/main/java/com/ym/pysc/model/db/PYSCDataBase.kt new file mode 100644 index 0000000000000000000000000000000000000000..259158e111646ee95353268cbba717fbbd5be576 --- /dev/null +++ b/app/src/main/java/com/ym/pysc/model/db/PYSCDataBase.kt @@ -0,0 +1,39 @@ +package com.ym.pysc.model.db + +import androidx.room.Database +import androidx.room.Room +import androidx.room.RoomDatabase +import com.blankj.utilcode.util.Utils +import com.ym.pysc.model.GainDefectInfo +import com.ym.pysc.model.GainRiskInfo +import com.ym.pysc.model.GainNetContent +import com.ym.pysc.model.db.dao.RiskInfoDao +import com.ym.pysc.model.db.dao.GainDefectInfoDao +import com.ym.pysc.model.db.dao.GainNetContentDao +import com.ym.pysc.model.db.migration.MIGRATION + +/** + * Created by dapeng on 2020/7/13. + */ +@Database( + entities = [GainDefectInfo::class,GainNetContent::class,GainRiskInfo::class], + version = 2, + exportSchema = false +) +abstract class PYSCDataBase : RoomDatabase() { + abstract fun getDefectInfoLocaData(): GainDefectInfoDao + abstract fun getNetContentLocaData(): GainNetContentDao + abstract fun getRiskInfoLocaData(): RiskInfoDao + companion object { + fun getInstance() = SingletonHolder.INSTANCE + } + + private object SingletonHolder { + val INSTANCE = Room.databaseBuilder( + Utils.getApp(), + PYSCDataBase::class.java, + "pysc_db" + ).addMigrations(MIGRATION.MIGRATION_1_2) + .build() + } +} \ No newline at end of file diff --git a/app/src/main/java/com/ym/pysc/model/db/converters/FengxianItemConverters.kt b/app/src/main/java/com/ym/pysc/model/db/converters/FengxianItemConverters.kt new file mode 100644 index 0000000000000000000000000000000000000000..1d53baf36bc041f2aaf15efbd70c4528bbdecdd9 --- /dev/null +++ b/app/src/main/java/com/ym/pysc/model/db/converters/FengxianItemConverters.kt @@ -0,0 +1,21 @@ +package com.ym.pysc.model.db.converters + +import androidx.room.TypeConverter +import com.blankj.utilcode.util.GsonUtils +import com.google.gson.reflect.TypeToken +import com.ym.pysc.model.RiskInfoItem + +/** + * Created by dapeng on 2020/7/14. + */ +class FengxianItemConverters { + @TypeConverter + fun stringToRelateList(json:String): MutableList { + val type = object : TypeToken>(){}.type + return GsonUtils.fromJson(json,type) + } + @TypeConverter + fun relateListToString(datas: MutableList):String{ + return GsonUtils.toJson(datas) + } +} \ No newline at end of file diff --git a/app/src/main/java/com/ym/pysc/model/db/converters/RelateTypeConverters.kt b/app/src/main/java/com/ym/pysc/model/db/converters/RelateTypeConverters.kt new file mode 100644 index 0000000000000000000000000000000000000000..523ce150e5808d3670d4df44497e3424183c93b9 --- /dev/null +++ b/app/src/main/java/com/ym/pysc/model/db/converters/RelateTypeConverters.kt @@ -0,0 +1,21 @@ +package com.ym.pysc.model.db.converters + +import androidx.room.TypeConverter +import com.blankj.utilcode.util.GsonUtils +import com.google.gson.reflect.TypeToken +import com.ym.pysc.model.NetRelateInfo + +/** + * Created by dapeng on 2020/7/14. + */ +class RelateTypeConverters { + @TypeConverter + fun stringToRelateList(json:String): MutableList { + val type = object : TypeToken>(){}.type + return GsonUtils.fromJson(json,type) + } + @TypeConverter + fun relateListToString(videos: MutableList):String{ + return GsonUtils.toJson(videos) + } +} \ No newline at end of file diff --git a/app/src/main/java/com/ym/pysc/model/db/dao/GainDefectInfoDao.kt b/app/src/main/java/com/ym/pysc/model/db/dao/GainDefectInfoDao.kt new file mode 100644 index 0000000000000000000000000000000000000000..22e6759986c5d3955bea00336af8357319964b1e --- /dev/null +++ b/app/src/main/java/com/ym/pysc/model/db/dao/GainDefectInfoDao.kt @@ -0,0 +1,49 @@ +package com.ym.pysc.model.db.dao + +import androidx.room.Dao +import androidx.room.Insert +import androidx.room.OnConflictStrategy +import androidx.room.Query +import androidx.room.Update +import com.ym.pysc.model.GainDefectInfo + +@Dao +interface GainDefectInfoDao { + @Insert(onConflict = OnConflictStrategy.REPLACE) + suspend fun insert(bean: GainDefectInfo): Long + + @Insert(onConflict = OnConflictStrategy.REPLACE) + suspend fun insertAll(datas: List): List + @Query("UPDATE GAIN_DEFECT_INFO SET status = 1 WHERE status = 0") + suspend fun updateSyncSuccess() + @Update + suspend fun update(bean: GainDefectInfo): Int + @Query("DELETE FROM GAIN_DEFECT_INFO") + suspend fun deleteAll() + @Query("SELECT * FROM GAIN_DEFECT_INFO WHERE factoryCode= :factoryCode AND workshopCode =:workshopCode AND lineCode = :lineCode AND productCode = :productCode AND produceTime = :produceTime ORDER BY WHEEL DESC") + suspend fun findOneDayData( + factoryCode: String?, + workshopCode: String?, + lineCode: String?, + productCode: String?, + produceTime: String? + ): MutableList + + @Query("SELECT * FROM GAIN_DEFECT_INFO WHERE factoryCode= :factoryCode AND workshopCode =:workshopCode AND lineCode = :lineCode AND productCode = :productCode AND produceTime = :produceTime AND WHEEL = :wheel") + suspend fun findOneData( + factoryCode: String?, + workshopCode: String?, + lineCode: String?, + productCode: String?, + produceTime: String?, + wheel: Int + ): GainDefectInfo +// @Query("SELECT * FROM GAIN_DEFECT_INFO " + +// "WHERE (:factoryCode = '' OR factoryCode = :factoryCode) " + +// "AND (:workshopCode = '' OR workshopCode = :workshopCode) " + +// "AND (:produceTime = '' OR produceTime = :produceTime) " + +// "AND status=0") + @Query("SELECT * FROM GAIN_DEFECT_INFO WHERE status=0") + suspend fun getHistoryNoSyncData(): MutableList + +} \ No newline at end of file diff --git a/app/src/main/java/com/ym/pysc/model/db/dao/GainNetContentDao.kt b/app/src/main/java/com/ym/pysc/model/db/dao/GainNetContentDao.kt new file mode 100644 index 0000000000000000000000000000000000000000..7f4c4d6ae1601a0c7ed9b989d9ed6b1f9a9789af --- /dev/null +++ b/app/src/main/java/com/ym/pysc/model/db/dao/GainNetContentDao.kt @@ -0,0 +1,53 @@ +package com.ym.pysc.model.db.dao + +import androidx.room.Dao +import androidx.room.Insert +import androidx.room.OnConflictStrategy +import androidx.room.Query +import androidx.room.Update +import com.ym.pysc.model.GainDefectInfo +import com.ym.pysc.model.GainNetContent + +@Dao +interface GainNetContentDao { + @Insert(onConflict = OnConflictStrategy.REPLACE) + suspend fun insert(bean: GainNetContent): Long + + @Insert(onConflict = OnConflictStrategy.REPLACE) + suspend fun insertAll(datas: MutableList) + @Query("UPDATE GAIN_NET_CONTENT SET status = 1 WHERE status = 0") + suspend fun updateSyncSuccess() + @Update + suspend fun update(bean: GainNetContent): Int + @Query("DELETE FROM GAIN_NET_CONTENT") + suspend fun deleteAll() + @Query("SELECT * FROM GAIN_NET_CONTENT WHERE factoryCode= :factoryCode AND workshopCode =:workshopCode AND lineCode = :lineCode AND productCode = :productCode AND produceTime = :produceTime ORDER BY WHEEL DESC") + suspend fun findOneDayData( + factoryCode: String?, + workshopCode: String?, + lineCode: String?, + productCode: String?, + produceTime: String? + ): MutableList + + @Query("SELECT * FROM GAIN_NET_CONTENT WHERE factoryCode= :factoryCode AND workshopCode =:workshopCode AND lineCode = :lineCode AND productCode = :productCode AND produceTime = :produceTime AND WHEEL = :wheel") + suspend fun findOneData( + factoryCode: String?, + workshopCode: String?, + lineCode: String?, + productCode: String?, + produceTime: String?, + wheel: Int + ): GainNetContent + + // @Query( +// "SELECT * FROM GAIN_NET_CONTENT " + +// "WHERE (:factoryCode = '' OR factoryCode = :factoryCode) " + +// "AND (:workshopCode = '' OR workshopCode = :workshopCode) " + +// "AND (:produceTime = '' OR produceTime = :produceTime) " + +// "AND status=0" +// ) + @Query("SELECT * FROM GAIN_NET_CONTENT WHERE status=0") + suspend fun getHistoryNoSyncData(): MutableList + +} \ No newline at end of file diff --git a/app/src/main/java/com/ym/pysc/model/db/dao/RiskInfoDao.kt b/app/src/main/java/com/ym/pysc/model/db/dao/RiskInfoDao.kt new file mode 100644 index 0000000000000000000000000000000000000000..4f2c48d3d4b6285cc4accbb86f3e0716d710b338 --- /dev/null +++ b/app/src/main/java/com/ym/pysc/model/db/dao/RiskInfoDao.kt @@ -0,0 +1,45 @@ +package com.ym.pysc.model.db.dao + +import androidx.room.Dao +import androidx.room.Insert +import androidx.room.OnConflictStrategy +import androidx.room.Query +import androidx.room.Update +import com.ym.pysc.model.GainRiskInfo + +@Dao +interface RiskInfoDao { + @Insert(onConflict = OnConflictStrategy.REPLACE) + suspend fun insert(bean: GainRiskInfo): Long + + @Insert(onConflict = OnConflictStrategy.REPLACE) + suspend fun insertAll(datas: MutableList) + + @Query("UPDATE GAIN_RISK SET status = 1 WHERE status = 0") + suspend fun updateSyncSuccess() + + @Update + suspend fun update(bean: GainRiskInfo): Int + + @Query("DELETE FROM GAIN_RISK") + suspend fun deleteAll() + + @Query( + "SELECT * FROM GAIN_RISK WHERE factoryCode= :factoryCode " + + "AND workshopCode =:workshopCode " + + "AND gxCode = :gxCode " + + "AND gbCode = :gbCode " + + "AND produceTime = :produceTime" + ) + suspend fun findOneDayData( + factoryCode: String?, + workshopCode: String?, + gxCode: String?, + gbCode: String?, + produceTime: String? + ): GainRiskInfo + + @Query("SELECT * FROM GAIN_RISK WHERE status=0") + suspend fun getHistoryNoSyncData(): MutableList + +} \ No newline at end of file diff --git a/app/src/main/java/com/ym/pysc/model/db/migration/MIGRATION_1_2.kt b/app/src/main/java/com/ym/pysc/model/db/migration/MIGRATION_1_2.kt new file mode 100644 index 0000000000000000000000000000000000000000..97a817d44b68fdcea1f2c36a4577c2e1f5412598 --- /dev/null +++ b/app/src/main/java/com/ym/pysc/model/db/migration/MIGRATION_1_2.kt @@ -0,0 +1,16 @@ +package com.ym.pysc.model.db.migration + +import androidx.room.migration.Migration +import androidx.sqlite.db.SupportSQLiteDatabase + + +object MIGRATION { + val MIGRATION_1_2 = object : Migration(1, 2) { + override fun migrate(database: SupportSQLiteDatabase) { + // 没有更改表结构,空实现 + + database.execSQL("ALTER TABLE gain_net_content ADD COLUMN average TEXT") + + } + } +} \ No newline at end of file diff --git a/app/src/main/java/com/ym/pysc/repository/DefectiveRepository.kt b/app/src/main/java/com/ym/pysc/repository/DefectiveRepository.kt new file mode 100644 index 0000000000000000000000000000000000000000..380a3987f606d6419a61558faafa2bced3e5584c --- /dev/null +++ b/app/src/main/java/com/ym/pysc/repository/DefectiveRepository.kt @@ -0,0 +1,210 @@ +package com.ym.pysc.repository + +import com.blankj.utilcode.util.NetworkUtils +import com.ym.httplibrary.base.BaseModel +import com.ym.pysc.api.InjectorUtil +import com.ym.pysc.api.NetWork +import com.ym.pysc.model.GainDefectInfo +import com.ym.pysc.model.NetRelateInfo +import com.ym.pysc.model.db.dao.GainDefectInfoDao +import com.ym.pysc.utils.LongData.generateRandomLong +import com.ym.pysc.utils.BaseDataManager + +/** + * Created by tuoni on 2020-03-04. + */ +class DefectiveRepository private constructor( + private val newWork: NetWork, + private val localData: GainDefectInfoDao +) : BaseModel() { + suspend fun findOneDayData( + params: HashMap + ): List { + return localData.findOneDayData( + factoryCode = params["factoryCode"].toString(), + workshopCode = params["workshopCode"].toString(), + lineCode = params["lineCode"].toString(), + productCode = params["productCode"].toString(), + produceTime = params["produceTime"].toString() + ) + } + + suspend fun insertOrUpdateDefectInfo(info: GainDefectInfo): String { + val oneDayData = localData.findOneData( + factoryCode = info.factoryCode, + workshopCode = info.workshopCode, + lineCode = info.lineCode, + productCode = info.productCode, + produceTime = info.produceTime, + wheel = info.wheel!! + ) + if (oneDayData != null) { + info.id =oneDayData.id + info.status = 0 + localData.update(info) + } else { + info.id = generateRandomLong() + localData.insert(info) + } + if (NetworkUtils.isConnected()) { + val code = newWork.insertDefectInfo(info).code + if (code == 0) { + info.status = 1 + localData.update(info) + } + } + return "" + } + + + suspend fun getNewRelateList(params: HashMap): GainDefectInfo { + val gainDefectInfo = findOneDayData(params) + if (gainDefectInfo.isNullOrEmpty()) { + var ret = mutableListOf() + val noramlData = BaseDataManager.getDefcetiveTypList() + val data = createGainDefectInfo(1, ret, params) + val resultList = noramlData.filter { + it.factoryCode == params["factoryCode"].toString() + && it.workshopCode == params["workshopCode"].toString() + }.toMutableList() + val typeItem = resultList[0].typeList + val result = typeItem.map { NetRelateInfo(key = it.code, value = "", name = it.name) } + .toMutableList() + data.relateList =result + return data + } else { + return gainDefectInfo.get(0) + } + + } + + suspend fun addDefectiveRound(params: HashMap): GainDefectInfo { + val gainDefectInfo = localData.findOneDayData( + factoryCode = params["factoryCode"].toString(), + workshopCode = params["workshopCode"].toString(), + lineCode = params["lineCode"].toString(), + productCode = params["productCode"].toString(), + produceTime = params["produceTime"].toString() + )[0] + var wheel = gainDefectInfo.wheel!! + 1 + //替换成从基础库查 + val resultList = BaseDataManager.getDefcetiveTypList().filter { + it.factoryCode == gainDefectInfo.factoryCode + && it.workshopCode == gainDefectInfo.workshopCode + }.toMutableList() + val typeItem = resultList[0].typeList + val result = typeItem.map { NetRelateInfo(key = it.code, value = "", name = it.name) } + .toMutableList() + val data = createGainDefectInfo(wheel, result, params) + data.id=generateRandomLong() + localData.insert(data) + return data + + + } + + private fun createGainDefectInfo( + wheel: Int, + ret: MutableList, + params: HashMap + ): GainDefectInfo { + val data = GainDefectInfo( + factoryCode = params["factoryCode"].toString(), + factoryName = params["factoryName"].toString(), + workshopCode = params["workshopCode"].toString(), + workshopName = params["workshopName"].toString(), + lineCode = params["lineCode"].toString(), + lineName = params["lineName"].toString(), + productCode = params["productCode"].toString(), + productName = params["productName"].toString(), + produceTime = params["produceTime"].toString(), + wheel = wheel, + relateList = ret + ) + return data + } + + suspend fun showListByWheel(params: HashMap): GainDefectInfo { + val gainDefectInfo = localData.findOneData( + factoryCode = params["factoryCode"] as String, + workshopCode = params["workshopCode"] as String, + lineCode = params["lineCode"] as String, + productCode = params["productCode"] as String, + produceTime = params["produceTime"] as String, + wheel = params["wheel"] as Int + ) + return gainDefectInfo + + + } + /** + * 初始化3天的数据 + */ + suspend fun insertAll(datas:MutableList){ + datas.forEach { + it.status = 1 + } + localData.insertAll(datas) + } + + suspend fun getHistoryNoSyncData(): MutableList { + val result = localData.getHistoryNoSyncData() +// val ret = aggregateDataList(result) + return result + + } + suspend fun updateSyncSuccess(){ + localData.updateSyncSuccess() + } + + suspend fun deleteAll(){ + localData.deleteAll() + } +// private fun aggregateDataList(dataList: List): MutableList { +// val aggregatedMap = mutableMapOf() +// +// for (data in dataList) { +// val key = +// data.factoryCode + data.workshopCode + data.lineCode + data.productCode + data.produceTime +// val existingAggregatedData = aggregatedMap[key] +// +// if (existingAggregatedData == null) { +// // 如果该时间的信息不存在,则创建一个新的聚合信息 +// val newAggregatedData = GainDefectInfo( +// factoryCode = data.factoryCode, +// factoryName = data.factoryName, +// workshopCode = data.workshopCode, +// workshopName = data.workshopName, +// lineCode = data.lineCode, +// lineName = data.lineName, +// productCode = data.productCode, +// productName = data.productName, +// produceTime = data.produceTime, +// status = data.status, +// wheel = 0, +// wheelTotal = 1, +// relateList = data.relateList +// ) +// aggregatedMap[key] = newAggregatedData +// } else { +// // 如果该时间的信息已存在,则更新总条数、总状态和总轮数 +// existingAggregatedData.status += data.status +// existingAggregatedData.wheelTotal += 1 +// } +// } +// +// return aggregatedMap.values.toMutableList() +// } + + companion object { + private var INSTANCE: DefectiveRepository? = null + fun getInstance(netWork: NetWork, gainDefectInfoDao: GainDefectInfoDao) = + INSTANCE ?: synchronized(this) { + INSTANCE ?: DefectiveRepository(netWork, gainDefectInfoDao).also { INSTANCE = it } + } + } +} + +val defectiveRepository by lazy { InjectorUtil.getDefectiveRepository() } + + diff --git a/app/src/main/java/com/ym/pysc/repository/NetContentRepository.kt b/app/src/main/java/com/ym/pysc/repository/NetContentRepository.kt new file mode 100644 index 0000000000000000000000000000000000000000..c8655172ca24b029d5f6d4f98b0af947c9fe321e --- /dev/null +++ b/app/src/main/java/com/ym/pysc/repository/NetContentRepository.kt @@ -0,0 +1,158 @@ +package com.ym.pysc.repository + +import com.blankj.utilcode.util.NetworkUtils +import com.ym.httplibrary.base.BaseModel +import com.ym.pysc.api.InjectorUtil +import com.ym.pysc.api.NetWork +import com.ym.pysc.model.GainDefectInfo +import com.ym.pysc.model.GainNetContent +import com.ym.pysc.model.NetRelateInfo +import com.ym.pysc.model.db.dao.GainDefectInfoDao +import com.ym.pysc.model.db.dao.GainNetContentDao +import com.ym.pysc.utils.LongData.generateRandomLong +import java.util.UUID + +/** + * Created by tuoni on 2020-03-04. + */ +class NetContentRepository private constructor( + private val newWork: NetWork, + private val localData: GainNetContentDao +) : BaseModel() { + suspend fun findOneDayData( + params: HashMap + ): List { + return localData.findOneDayData( + factoryCode = params["factoryCode"].toString(), + workshopCode = params["workshopCode"].toString(), + lineCode = params["lineCode"].toString(), + productCode = params["productCode"].toString(), + produceTime = params["produceTime"].toString() + ) + } + + suspend fun insertOrUpdateDefectInfo(info: GainNetContent): String { + val oneDayData = localData.findOneData( + factoryCode = info.factoryCode, + workshopCode = info.workshopCode, + lineCode = info.lineCode, + productCode = info.productCode, + produceTime = info.produceTime, + wheel = info.wheel!! + ) + if (oneDayData != null) { + info.id = oneDayData.id + info.status = 0 + localData.update(info) + } else { + info.id = generateRandomLong() + localData.insert(info) + } + if (NetworkUtils.isConnected()) { + val a = mutableListOf() + a.add(info) + val code = newWork.insertNet(a).code + if (code == 0) { + info.status = 1 + localData.update(info) + } + } + return "" + } + /** + * 初始化3天的数据 + */ + suspend fun insertAll(datas:MutableList){ + datas.forEach { + it.status = 1 + } + localData.insertAll(datas) + } + suspend fun getNewRelateList(params: HashMap): GainNetContent { + val gainDefectInfo =findOneDayData(params) + if (gainDefectInfo.isNullOrEmpty()) { + var ret = mutableListOf() + for (i in 1..10){ + ret.add(NetRelateInfo(key = "$i", value = "", name = "$i")) + } + val data = createGainDefectInfo(1,ret,params) + return data + } else { + return gainDefectInfo.get(0) + } + + } + + suspend fun addNetContentRound(params: HashMap): GainNetContent { + val gainDefectInfo = findOneDayData(params) + var wheel = gainDefectInfo.get(0).wheel!! + 1 + //替换成从基础库查 + var ret = mutableListOf() + for (i in 1..10){ + ret.add(NetRelateInfo(key = "$i", value = "", name = "$i")) + } + val data = createGainDefectInfo(wheel,ret,params) + data.id = generateRandomLong() + localData.insert(data) + return data + + + } + private fun createGainDefectInfo(wheel:Int, + ret : MutableList, + params: HashMap):GainNetContent { + + val data = GainNetContent( + factoryCode = params["factoryCode"].toString(), + factoryName = params["factoryName"].toString(), + workshopCode = params["workshopCode"].toString(), + workshopName = params["workshopName"].toString(), + lineCode = params["lineCode"].toString(), + lineName = params["lineName"].toString(), + productCode = params["productCode"].toString(), + productName = params["productName"].toString(), + produceTime = params["produceTime"].toString(), + wheel = wheel, + relateList = ret + ) + return data + } + suspend fun showListByWheel(params: HashMap): GainNetContent { + val gainNetContentInfo = localData.findOneData( + factoryCode = params["factoryCode"] as String, + workshopCode = params["workshopCode"] as String, + lineCode = params["lineCode"] as String, + productCode = params["productCode"] as String, + produceTime = params["produceTime"] as String, + wheel = params["wheel"] as Int + ) + return gainNetContentInfo + + + } + + suspend fun getHistoryNoSyncData(): MutableList { + val result = localData.getHistoryNoSyncData() +// val ret = aggregateDataList(result) + return result + } + suspend fun updateSyncSuccess(){ + localData.updateSyncSuccess() + } + suspend fun deleteAll(){ + localData.deleteAll() + } + + + companion object { + private var INSTANCE: NetContentRepository? = null + fun getInstance(netWork: NetWork, gainDefectInfoDao: GainNetContentDao) = + INSTANCE ?: synchronized(this) { + INSTANCE ?: NetContentRepository(netWork, gainDefectInfoDao).also { INSTANCE = it } + } + } +} + +val netContentRepository by lazy { InjectorUtil.getNetContentRepository() } + + diff --git a/app/src/main/java/com/ym/pysc/repository/RiskRepository.kt b/app/src/main/java/com/ym/pysc/repository/RiskRepository.kt new file mode 100644 index 0000000000000000000000000000000000000000..c8eebdaa286b2fa126f895097e285da6c0ad7616 --- /dev/null +++ b/app/src/main/java/com/ym/pysc/repository/RiskRepository.kt @@ -0,0 +1,139 @@ +package com.ym.pysc.repository + +import com.blankj.utilcode.util.NetworkUtils +import com.ym.httplibrary.base.BaseModel +import com.ym.pysc.api.InjectorUtil +import com.ym.pysc.api.NetWork +import com.ym.pysc.model.RiskInfoItem +import com.ym.pysc.model.GainRiskInfo +import com.ym.pysc.model.db.dao.RiskInfoDao +import com.ym.pysc.utils.BaseDataManager +import com.ym.pysc.utils.LongData.generateRandomLong + +/** + * Created by tuoni on 2020-03-04. + */ +class RiskRepository private constructor( + private val newWork: NetWork, + private val localData: RiskInfoDao +) : BaseModel() { + suspend fun insertOrUpdateInfo(info: GainRiskInfo): String { + val onDayData = localData.findOneDayData( + factoryCode = info.factoryCode, + workshopCode = info.workshopCode, + gxCode = info.gxCode, + gbCode = info.gbCode, + produceTime = info.produceTime + ) + if (onDayData != null) { + info.id = onDayData.id + localData.update(info) + } else { + info.id = generateRandomLong() + localData.insert(info) + } + + if (NetworkUtils.isConnected()) { + val datas = mutableListOf() + datas.add(info) + val code = newWork.insertFengxian(datas).code + if (code == 0) { + info.status = 1 + localData.update(info) + } + } + return "" + } + + /** + * 初始化3天的数据 + */ + suspend fun insertAll(datas: MutableList) { + datas.forEach { + it.status = 1 + } + localData.insertAll(datas) + } + + suspend fun selectRiskData(params: HashMap): GainRiskInfo { + val gainDefectInfo = localData.findOneDayData( + factoryCode = params["factoryCode"].toString(), + workshopCode = params["workshopCode"].toString(), + gxCode = params["gxCode"].toString(), + gbCode = params["gbCode"].toString(), + produceTime = params["produceTime"].toString() + ) +// val rating = params["fwCode"].toString() + + if (gainDefectInfo == null) { + val list = BaseDataManager.getRiskTypeList() + val oneData = list.filter { + it.factoryCode == params["factoryCode"].toString() + && it.workshopCode == params["workshopCode"].toString() + && it.gxCode == params["gxCode"].toString() + && it.gbCode == params["gbCode"].toString() + } + .toMutableList() +// if (rating == "null"){ + val data = createRiskInfo(oneData[0].relateList, params) + return data +// }else { +// val a = oneData?.let { +// it[0].relateList.filter { it.rating == rating }.toMutableList() +// } +// val data = createRiskInfo(a, params) +// return data +// } + + } else { + return gainDefectInfo + } + + } + + + private fun createRiskInfo( + ret: MutableList, + params: HashMap + ): GainRiskInfo { + val data = GainRiskInfo( + factoryCode = params["factoryCode"].toString(), + factoryName = params["factoryName"].toString(), + workshopCode = params["workshopCode"].toString(), + workshopName = params["workshopName"].toString(), + gxCode = params["gxCode"].toString(), + gxName = params["gxName"].toString(), + gbCode = params["gbCode"].toString(), + gbName = params["gbName"].toString(), + produceTime = params["produceTime"].toString(), + relateList = ret + ) + return data + } + + + suspend fun getHistoryNoSyncData(): MutableList { + val result = localData.getHistoryNoSyncData() + return result + } + + suspend fun updateSyncSuccess() { + localData.updateSyncSuccess() + } + + suspend fun deleteAll() { + localData.deleteAll() + } + + companion object { + private var INSTANCE: RiskRepository? = null + fun getInstance(netWork: NetWork, dao: RiskInfoDao) = + INSTANCE ?: synchronized(this) { + INSTANCE ?: RiskRepository(netWork, dao).also { INSTANCE = it } + } + } +} + +val riskRepository by lazy { InjectorUtil.getRiskRepository() } + + diff --git a/app/src/main/java/com/ym/pysc/ui/defective/DefectiveActivity.kt b/app/src/main/java/com/ym/pysc/ui/defective/DefectiveActivity.kt index e3350210fe251e797fc101b3ae7be577d2f301b3..afe7919d7e3b36183854cdfcbb68c6d76b4b7dfe 100644 --- a/app/src/main/java/com/ym/pysc/ui/defective/DefectiveActivity.kt +++ b/app/src/main/java/com/ym/pysc/ui/defective/DefectiveActivity.kt @@ -4,17 +4,18 @@ import android.app.AlertDialog import android.os.Bundle import android.view.View import androidx.recyclerview.widget.LinearLayoutManager -import com.android.commonlibrary.util.DateUtil -import com.android.commonlibrary.window.AppPopupWindow import com.blankj.utilcode.util.ToastUtils import com.ym.pysc.MyBaseActivity import com.ym.pysc.R import com.ym.pysc.databinding.ActivityDefectiveBinding import com.ym.pysc.function.showItemPop +import com.ym.pysc.model.GainDefectInfo import com.ym.pysc.model.ItemInfo import com.ym.pysc.model.NetRelateInfo +import com.ym.pysc.model.WorkShopInfo import com.ym.pysc.ui.defective.adapter.DefectiveAdapter -import com.ym.pysc.widget.DatePop +import com.ym.pysc.utils.BaseDataManager +import com.ym.pysc.widget.DatePopHelper import kotlinx.android.synthetic.main.activity_defective.* import kotlinx.android.synthetic.main.layout_defective.* import kotlinx.android.synthetic.main.layout_defective_total.rl_total_list @@ -27,16 +28,21 @@ import java.util.Date class DefectiveActivity : MyBaseActivity() { lateinit var mDefAdapter: DefectiveAdapter lateinit var mDefTotalAdapter: DefectiveAdapter - private var wheel = 0 + private var wheel = 1 + private var totalWheel = 1 private var factoryWorkList: MutableList? = null private var normalRelateList: MutableList? = null - private var isDialogFalse = false + private var params = hashMapOf() + + private lateinit var workshopList: MutableList override fun layoutId(): Int = R.layout.activity_defective override fun initView(savedInstanceState: Bundle?) { super.initView(savedInstanceState) + workshopList = BaseDataManager.getWorkshopList() binding!!.viewModel = viewModel - binding!!.isNext = false + binding!!.showNext = false + binding!!.wheel = wheel binding!!.emptyInfo = "请选择车间" binding!!.showTotal = false initDate() @@ -44,7 +50,7 @@ class DefectiveActivity : MyBaseActivity if (isChecked) { - if(isValueChange()){ + if (isValueChange()) { var dialog = AlertDialog.Builder(mContext) .setTitle("提示") .setMessage("数据发生了变化,您是否要先提交") @@ -52,14 +58,14 @@ class DefectiveActivity : MyBaseActivity - isDialogFalse = true rb_change.isChecked = false dialog.dismiss() } .setPositiveButton( "提交并切换" ) { dialog, which -> - submitData{ + submitData { + binding!!.ivAdd.visibility = View.GONE binding!!.showTotal = true gainDefectTotal() dialog.dismiss() @@ -68,50 +74,46 @@ class DefectiveActivity : MyBaseActivity - ItemInfo( - "${item.factoryCode}-${item.workshopCode}", - "${item.factoryName}${item.workshopName}" - ) - }?.toMutableList() + factoryWorkList = workshopList.map { item -> + ItemInfo( + "${item.factoryCode}-${item.workshopCode}", + "${item.factoryName}-${item.workshopName}" + ) + }?.toMutableList() - } tv_room.setOnClickListener { if (isValueChange()) { showValueChangeDialog() } else { tv_room.showItemPop(iv_room_arrow, factoryWorkList) { + params["factoryCode"] = it.code.split("-")[0] + params["factoryName"] = it.name.split("-")[0] + params["workshopCode"] = it.code.split("-")[1] + params["workshopName"] = it.name.split("-")[1] viewModel.factoryWorkShop.value = it - if (binding!!.showTotal == true){ - binding!!.isSelectRoom = false - binding!!.line = ItemInfo("", "请选择") - binding!!.product = ItemInfo("", "请选择") + + binding!!.isSelectRoom = false + binding!!.line = ItemInfo("", "请选择") + binding!!.product = ItemInfo("", "请选择") + params["lineCode"] = "null" + params["productCode"] = "null" + gainLines(it) + gainProduct(it) + if (binding!!.showTotal == true) { gainDefectTotal() - gainLines(it) - gainProduct(it) - }else{ - wheel = 0 - binding!!.isSelectRoom = false - binding!!.line = ItemInfo("", "请选择") - binding!!.product = ItemInfo("", "请选择") - getListData() - gainLines(it) - gainProduct(it) + } else { + initDefectiveList() } @@ -119,47 +121,32 @@ class DefectiveActivity : MyBaseActivity - wheel = 0 - getListData() dialog.dismiss() } .setPositiveButton( @@ -170,8 +157,7 @@ class DefectiveActivity : MyBaseActivity + showPageWheel(binding!!.wheel!!.toInt() - 1) + dialog.dismiss() + } + .setPositiveButton( + "提交并上一轮" + ) { dialog, which -> + submitData(isBefore = true) + dialog.dismiss() + }.create() + dialog.show() + } else { + showPageWheel(binding!!.wheel!!.toInt() - 1) + } + } + btn_next.setOnClickListener { + if (isValueChange()) { + var dialog = AlertDialog.Builder(mContext) + .setTitle("提示") + .setMessage("数据发生了变化,您是否要先提交") + .setCancelable(false) + .setNegativeButton( + "继续" + ) { dialog, which -> + showPageWheel(binding!!.wheel!!.toInt() + 1) + dialog.dismiss() + } + .setPositiveButton( + "提交并下一轮" + ) { dialog, which -> + submitData(isNext = true) + dialog.dismiss() + }.create() + dialog.show() + } else { + showPageWheel(binding!!.wheel!!.toInt() + 1) } + } + } + fun addDefectiveRound() { + viewModel.addDefectiveRound(params) { + createNormalRelateList(it.relateList!!) + mDefAdapter.setData(it.relateList!!) + binding!!.isSelectRoom = true + binding!!.showTotal = false + binding!!.wheel = it.wheel + binding!!.showNext = false + totalWheel = it.wheel!! } + + } + + + fun showPageWheel(wheel: Int) { + val mParams = params + mParams.put("wheel", wheel) + viewModel.showPageWheel(mParams) { + createNormalRelateList(it.relateList!!) + mDefAdapter.setData(it.relateList!!) + binding!!.isSelectRoom = true + binding!!.showTotal = false + binding!!.wheel = it.wheel + binding!!.showNext = it.wheel < totalWheel + + } + } private fun gainDefectTotal() { - val workShopItem = viewModel.factoryWorkShop.value - if (workShopItem == null) { + var bool = inputAllData() + if (bool) { + viewModel.gainDefectTotal(params) { + binding!!.isSelectRoom = true + mDefTotalAdapter.setData(it!!.relateList) + } + } + + + } + + private fun inputAllData(): Boolean { + if (params["factoryCode"].toString() == "null") { binding!!.emptyInfo = "请选择车间" binding!!.isSelectRoom = false - - return + return false } - val factoryCode = workShopItem.code.split("-")[0] - val workshopCode = workShopItem.code.split("-")[1] - val lineCode = binding!!.line?.code ?: "" - val productCode = binding!!.product?.code ?: "" - val produceTime = binding!!.date ?: "" - if (lineCode.isNullOrEmpty()) { + if (params["lineCode"].toString() == "null") { binding!!.emptyInfo = "请选择产线" binding!!.isSelectRoom = false + return false - - return } - if (productCode.isNullOrEmpty()) { + + if (params["productCode"].toString() == "null") { binding!!.emptyInfo = "请选择产品" binding!!.isSelectRoom = false - - return + return false } - if (produceTime.isNullOrEmpty()) { + if (params["produceTime"].toString() == "null") { binding!!.emptyInfo = "请选择日期" binding!!.isSelectRoom = false + return false - return - } - val params = hashMapOf( - "factoryCode" to factoryCode, - "workshopCode" to workshopCode, - "lineCode" to lineCode, - "productCode" to productCode, - "produceTime" to produceTime, - ) - viewModel.gainDefectTotal(params) { - binding!!.isSelectRoom = true - mDefTotalAdapter.setData(it!!.relateList) } - + return true } private fun createNormalRelateList(relateList: MutableList) { @@ -256,120 +309,33 @@ class DefectiveActivity : MyBaseActivity - wheel-- - getListData() - dialog.dismiss() - } - .setPositiveButton( - "提交并上一轮" - ) { dialog, which -> - submitData(isBefore = true) - dialog.dismiss() - }.create() - dialog.show() - } else { - wheel-- - getListData() - } - } - btn_next.setOnClickListener { - if (isValueChange()) { - var dialog = AlertDialog.Builder(mContext) - .setTitle("提示") - .setMessage("数据发生了变化,您是否要先提交") - .setCancelable(false) - .setNegativeButton( - "继续" - ) { dialog, which -> - wheel++ - getListData() - dialog.dismiss() - } - .setPositiveButton( - "提交并下一轮" - ) { dialog, which -> - submitData(isNext = true) - dialog.dismiss() - }.create() - dialog.show() - } else { - wheel++ - getListData() - } - - } + binding!!.isSelectRoom = true + binding!!.showTotal = false + binding!!.wheel = it.wheel + totalWheel = it.wheel } + + } private fun gainLines(item: ItemInfo) { - - val params = hashMapOf( - "factoryCode" to item.code.split("-")[0], - "workshopCode" to item.code.split("-")[1] - ) - viewModel.gainLine(params) { - linesResult(it) - } + val curWorkShop = workshopList.filter { + it.factoryCode == item.code.split("-")[0] + && it.workshopCode == item.code.split("-")[1] + }.toMutableList() + linesResult(curWorkShop[0].lineList) } private fun linesResult(it: MutableList?) { @@ -378,26 +344,28 @@ class DefectiveActivity : MyBaseActivity?) { - binding!!.product = ItemInfo(code = "", name = "请选择") val items = it tv_product.setOnClickListener { if (isValueChange()) { showValueChangeDialog() } else { + tv_product.showItemPop(iv_line_arrow, items) { binding!!.product = it - wheel = 0 - if (binding!!.showTotal == true){ + params.put("productCode", it.code) + params.put("productName", it.name) + if (binding!!.showTotal == true) { gainDefectTotal() - }else { - getListData() + } else { + initDefectiveList() } } } @@ -451,9 +417,10 @@ class DefectiveActivity : MyBaseActivity( - "factoryCode" to factoryCode, - "workshopCode" to workshopCode, - "lineCode" to lineCode, - "productCode" to productCode, - "produceTime" to produceTime, + + private fun submitData( + isSubmit: Boolean = false, + isNext: Boolean = false, + isBefore: Boolean = false + ) { + + val myParams = GainDefectInfo( + factoryCode = params["factoryCode"].toString(), + factoryName = params["factoryName"].toString(), + workshopCode = params["workshopCode"].toString(), + workshopName = params["workshopName"].toString(), + lineCode = params["lineCode"].toString(), + lineName = params["lineName"].toString(), + productCode = params["productCode"].toString(), + productName = params["productName"].toString(), + produceTime = params["produceTime"].toString(), + wheel = binding!!.wheel!!.toInt(), + relateList = mDefAdapter.datas ) - if (wheel != 0) { - params.put("wheel", wheel.toString()) - } - params.put("relateList", mDefAdapter.datas) - viewModel.insertDefectInfo(params) { + + viewModel.insertOrUpdateDefectInfo(myParams) { createNormalRelateList(mDefAdapter.datas) if (isNext) { - wheel++ - getListData() + addDefectiveRound() } else if (isBefore) { - wheel-- - getListData() + showPageWheel(binding!!.wheel!!.toInt() - 1) + } else if (isSubmit) { + ToastUtils.showShort("数据已保存") + viewModel. defUI.dismissDialog.call() } } } - private fun submitData(change:()->Unit) { - val factoryCode = viewModel.factoryWorkShop.value!!.code.split("-")[0] - val workshopCode = viewModel.factoryWorkShop.value!!.code.split("-")[1] - val lineCode = binding!!.line?.code ?: "" - val productCode = binding!!.product?.code ?: "" - val produceTime = binding!!.date ?: "" - val params = hashMapOf( - "factoryCode" to factoryCode, - "workshopCode" to workshopCode, - "lineCode" to lineCode, - "productCode" to productCode, - "produceTime" to produceTime, + + + private fun submitData(change: () -> Unit) { + val myParams = GainDefectInfo( + factoryCode = params["factoryCode"].toString(), + factoryName = params["factoryName"].toString(), + workshopCode = params["workshopCode"].toString(), + workshopName = params["workshopName"].toString(), + lineCode = params["lineCode"].toString(), + lineName = params["lineName"].toString(), + productCode = params["productCode"].toString(), + productName = params["productCode"].toString(), + produceTime = params["produceTime"].toString(), + wheel = binding!!.wheel!!.toInt(), + relateList = mDefAdapter.datas ) - if (wheel != 0) { - params.put("wheel", wheel.toString()) - } - params.put("relateList", mDefAdapter.datas) - viewModel.insertDefectInfo(params) { + viewModel.insertOrUpdateDefectInfo(myParams) { change() } } - /**弹出日期弹窗**/ - private fun showDatePop(data: (String) -> Unit) { - var datePop = DatePop(DateUtil.getDate(), mContext!!) - datePop.setFocuse(true)//点击返回键消失,一般设置为true - .setOuTouchCancel(true)//点击pop外部消失,默认true消失 - .setAnimation(AppPopupWindow.ANIMATION_SCREEN_BOTTOM_STYLE)//屏幕底部弹出 - .setBackgroundAlpha(0.5f)//设置背景遮罩透0f全黑,1.0f全透明) - //确认 - datePop.setBtnConfirm { - datePop.dismiss() - //选择日期 - var chooseDate: String = datePop.getChooseDate() - data(chooseDate) -// //"今天"tag的显示与隐藏 -// updateTodayTag(tvTodayTag,tvDate.text.toString()) - } - //关闭pop的监听处理 - datePop.setOnDismissListener { - datePop.setBackgroundAlpha(1.0f)//设置背景遮罩透明度(0f全黑,1.0f全透明) - } - //显示 - if (!datePop.isShowing()) { - //屏幕正下方弹出pop - datePop.showAtScreenBottom(binding!!.root) - } - } - - fun isValueChange(): Boolean { - if(binding!!.showTotal == true){ + if (binding!!.showTotal == true) { return false } if (normalRelateList == null) { return false } else { val valueChanged = mDefAdapter.datas.zip(normalRelateList!!).any { (item1, item2) -> - if (item1.value == ""){ - item1.value = null - } + if (item1.value == "") { + item1.value = null + } + if (item2.value == "") { + item2.value = null + } item1.value != item2.value } return valueChanged @@ -579,6 +525,9 @@ class DefectiveActivity : MyBaseActivity() { + lateinit var mAdapter: DefectiveHistoryAdapter + private var factoryWorkList: MutableList? = null + private lateinit var workshopList: MutableList + + override fun layoutId(): Int = R.layout.activity_defective_history + override fun initView(savedInstanceState: Bundle?) { + super.initView(savedInstanceState) + workshopList = BaseDataManager.getWorkshopList() + + initListView() + factoryWorkList = workshopList.map { item -> + ItemInfo( + "${item.factoryCode}-${item.workshopCode}", + "${item.factoryName}${item.workshopName}" + ) + }?.toMutableList() + + tv_room.setOnClickListener { + tv_room.showItemPop(iv_room_arrow, factoryWorkList) { + viewModel.factoryWorkShop.value = it + } + } + tv_date.setOnClickListener { + DatePopHelper.showDatePop(binding!!.root, mContext!!) { + binding!!.date = it + + } + } +// btn_search.setOnClickListener { +// var factoryCode = "" +// var workshopCode = "" +// val workShopItem = viewModel.factoryWorkShop.value +// if (workShopItem != null) { +// factoryCode = workShopItem!!.code.split("-")[0] +// workshopCode = workShopItem!!.code.split("-")[1] +// } +// val produceTime = binding!!.date ?: "" +// viewModel.getHistoryNoSyncData(factoryCode, workshopCode, produceTime) { +// mAdapter.setData(it) +// } +// +// } +// viewModel.getHistoryNoSyncData("", "", "") { +// mAdapter.setData(it) +// } + } + + private fun initListView() { + mAdapter = DefectiveHistoryAdapter(this) + var layoutManager = LinearLayoutManager(this) + layoutManager.orientation = LinearLayoutManager.VERTICAL + rl_list.layoutManager = layoutManager + rl_list.adapter = mAdapter + } + + +} \ No newline at end of file diff --git a/app/src/main/java/com/ym/pysc/ui/defective/DefectiveViewModel.kt b/app/src/main/java/com/ym/pysc/ui/defective/DefectiveViewModel.kt index 5f23fbef790fecafbf469d2834c078e529eb05f7..b1d8ae78ea3a1c082db605124918bfa22b22204a 100644 --- a/app/src/main/java/com/ym/pysc/ui/defective/DefectiveViewModel.kt +++ b/app/src/main/java/com/ym/pysc/ui/defective/DefectiveViewModel.kt @@ -1,131 +1,109 @@ package com.ym.pysc.ui.defective import androidx.lifecycle.MutableLiveData -import com.blankj.utilcode.util.SPUtils -import com.blankj.utilcode.util.ToastUtils +import com.blankj.utilcode.util.NetworkUtils import com.ym.httplibrary.viewmodel.BaseViewModel import com.ym.pysc.api.InjectorUtil import com.ym.pysc.model.GainDefectInfo -import com.ym.pysc.model.GainNetContent import com.ym.pysc.model.ItemInfo -import com.ym.pysc.model.UserInfo -import com.ym.pysc.model.WorkShop -import com.ym.pysc.utils.constant +import com.ym.pysc.model.NetRelateInfo +import com.ym.pysc.repository.defectiveRepository class DefectiveViewModel : BaseViewModel() { private val mRepository by lazy { InjectorUtil.getRepository() } var factoryWorkShop = MutableLiveData() - fun myWorkshop(result: (MutableList?) -> Unit) { - launchOnlyresult({ mRepository.myWorkshop() }, success = { - if (!it.isNullOrEmpty()) { - result(it) - } - }, worng = { - - }, error = { - if (it.code == 401) { - login { - launchOnlyresult({ mRepository.myWorkshop() }, success = { - if (!it.isNullOrEmpty()) { - result(it) - } - }, worng = { - }, isShowDialog = true) + fun gainDefectTotal(params: HashMap, result: (GainDefectInfo?) -> Unit) { + launchGo({ + val data = defectiveRepository.findOneDayData(params) + if (data.isNullOrEmpty() && NetworkUtils.isConnected()) { + val result1 = mRepository.gainDefectTotal(params).data + result(result1) + } else { + val netRelateInfos = sumValuesAtEachPosition(data) + val totalData = data[0] + totalData.relateList!!.forEachIndexed { index, item -> + item.value = netRelateInfos[index].value } + result(totalData) } - }, isShowDialog = true) + }) + } - fun gainLine(params: HashMap, result: (MutableList?) -> Unit) { - launchOnlyresult({ mRepository.gainLine(params) }, success = { - result(it) - }, worng = { - }, error = { - if (it.code == 401) { - login { - launchOnlyresult({ mRepository.gainLine(params) }, success = { - result(it) - }) - } - } + fun insertOrUpdateDefectInfo(params: GainDefectInfo, result: () -> Unit) { + defUI.showDialog.call() + launchGo({ + defectiveRepository.insertOrUpdateDefectInfo(params) + result() + }) } - fun gainProduct(params: HashMap, result: (MutableList?) -> Unit) { - launchOnlyresult({ mRepository.gainProduct(params) }, success = { - result(it) - }, worng = { - - }, error = { - if (it.code == 401) { - login { - launchOnlyresult({ mRepository.gainProduct(params) }, success = { - result(it) - }) - } - } + fun getNewRelateList(params: HashMap,result: (GainDefectInfo) -> Unit) { + launchGo({ + val a = defectiveRepository.getNewRelateList(params) + result(a) }) } - fun gainDefectInfo(params: HashMap, result: (GainDefectInfo?) -> Unit) { - launchOnlyresult({ mRepository.gainDefectInfo(params) }, success = { - result(it) - }, worng = { - }, error = { - if (it.code == 401) { - login { - launchOnlyresult({ mRepository.gainDefectInfo(params) }, success = { - result(it) - }) - } - } - }, isShowDialog = true) + /** + * 添加不良品 + */ + fun addDefectiveRound(params: HashMap,result: (GainDefectInfo) -> Unit) { + launchGo({ + val a = defectiveRepository.addDefectiveRound(params) + result(a) + defUI.dismissDialog.call() + + }) } - fun gainDefectTotal(params: HashMap, result: (GainDefectInfo?) -> Unit) { - launchOnlyresult({ mRepository.gainDefectTotal(params) }, success = { - result(it) - }, worng = { - }, error = { - if (it.code == 401) { - login { - launchOnlyresult({ mRepository.gainDefectTotal(params) }, success = { - result(it) - }) - } - } - }, isShowDialog = true) + /** + * 根据wheel显示 + */ + fun showPageWheel(params: HashMap,result: (GainDefectInfo) -> Unit) { + launchGo({ + val a = defectiveRepository.showListByWheel(params) + result(a) + defUI.dismissDialog.call() + }) } +// /** +// * 搜索不良品历史数据 +// */ +// fun getHistoryNoSyncData(factoryCode:String,workshopCode:String,produceTime:String,result: (MutableList) -> Unit){ +// launchGo({ +// val a = defectiveRepository.getHistoryNoSyncData(factoryCode,workshopCode,produceTime) +// result(a) +// }) +// } + fun sumValuesAtEachPosition(params: List): MutableList { + // 创建一个 Map 以存储每个位置的值之和 + val positionSumMap = mutableMapOf() - fun insertDefectInfo(params: HashMap, result: () -> Unit) { - launchOnlyresult({ mRepository.insertDefectInfo(params) }, success = { - ToastUtils.showShort("完成提交") - result() - }, worng = { - if (it.code == 401) { - login { - launchOnlyresult({ mRepository.insertDefectInfo(params) }, success = { - ToastUtils.showShort("完成提交") - result() - - }, isShowDialog = true) + // 遍历 params 列表 + for (gainDefectInfo in params) { + // 遍历 relateList 中的每个 NetRelateInfo + for ((index, netRelateInfo) in gainDefectInfo.relateList!!.withIndex()) { + // 获取当前位置的值之和 + val currentSum = positionSumMap[index] ?: "0" + var value =netRelateInfo.value?: "0" + if (netRelateInfo.value.isNullOrEmpty()){ + value="0" } + // 将当前位置的值加上 netRelateInfo 的 value + positionSumMap[index] = (Integer.parseInt(currentSum) + Integer.parseInt(value)).toString() } - }, isShowDialog = true) - } + } - fun login(result: (UserInfo?) -> Unit) { - val params = hashMapOf( - "username" to SPUtils.getInstance().getString(constant.ACCOUNT), - "password" to SPUtils.getInstance().getString(constant.PWD), - "grantType" to "PASSWORD" + // 将 Map 转换为 List + val resultList = positionSumMap.map { (position, sum) -> + NetRelateInfo(key = null, value = sum, name = null) + }.toMutableList() - ) - launchOnlyresult({ mRepository.login(params) }, success = { - SPUtils.getInstance().put(constant.TOKEN, it?.token) - result(it) - }, worng = { - }, isShowDialog = true) + return resultList } + + } \ No newline at end of file diff --git a/app/src/main/java/com/ym/pysc/ui/defective/adapter/DefectiveHistoryAdapter.kt b/app/src/main/java/com/ym/pysc/ui/defective/adapter/DefectiveHistoryAdapter.kt new file mode 100644 index 0000000000000000000000000000000000000000..1109e4c856fee2d9667e263c4a9afc0dea1871fd --- /dev/null +++ b/app/src/main/java/com/ym/pysc/ui/defective/adapter/DefectiveHistoryAdapter.kt @@ -0,0 +1,52 @@ +package com.ym.pysc.ui.defective.adapter + +import android.content.Context +import android.view.LayoutInflater +import android.view.ViewGroup +import androidx.databinding.DataBindingUtil +import androidx.recyclerview.widget.RecyclerView +import com.ym.httplibrary.base.BaseAdapter +import com.ym.httplibrary.base.BaseHolder +import com.ym.pysc.R +import com.ym.pysc.databinding.ItemDefectiveBinding +import com.ym.pysc.databinding.ItemDefectiveHistoryBinding +import com.ym.pysc.model.GainDefectInfo +import com.ym.pysc.model.HistoryData +import com.ym.pysc.model.NetRelateInfo + +class DefectiveHistoryAdapter(context: Context) : BaseAdapter(context) { + override fun onCreateHolder( + inflater: LayoutInflater, + parent: ViewGroup, + viewType: Int + ): RecyclerView.ViewHolder? { + + val binding = DataBindingUtil.inflate( + inflater, + R.layout.item_defective_history, + parent, + false + ) + return DefectiveHistoryViewHolder(binding) + } + +} + +class DefectiveHistoryViewHolder(val binding: ItemDefectiveHistoryBinding) : + BaseHolder(binding) { + override fun onBind(item: GainDefectInfo) { + var curStatus = "N" + if (item.status == item.wheelTotal) { + curStatus = "Y" + } + val historyData = HistoryData( + workshopName = item.workshopName?:"", + lineName = item.lineName?:"", + productName = item.productName?:"", + produceTime = item.produceTime?:"", + totalWheel = item.wheelTotal.toString(), + status =curStatus + ) + binding.info = historyData + } +} \ No newline at end of file diff --git a/app/src/main/java/com/ym/pysc/ui/login/LoginViewModel.kt b/app/src/main/java/com/ym/pysc/ui/login/LoginViewModel.kt index 1a56b1dc61b3cdaed4eaba58dbf1eda84d9831fb..5b1fa81b2c961eec9de1452797181bb5e107683b 100644 --- a/app/src/main/java/com/ym/pysc/ui/login/LoginViewModel.kt +++ b/app/src/main/java/com/ym/pysc/ui/login/LoginViewModel.kt @@ -1,25 +1,99 @@ package com.ym.pysc.ui.login +import com.blankj.utilcode.util.SPStaticUtils import com.blankj.utilcode.util.SPUtils import com.ym.httplibrary.viewmodel.BaseViewModel import com.ym.pysc.api.InjectorUtil -import com.ym.pysc.model.UserInfo +import com.ym.pysc.repository.defectiveRepository +import com.ym.pysc.repository.netContentRepository +import com.ym.pysc.repository.riskRepository +import com.ym.pysc.utils.BaseDataManager import com.ym.pysc.utils.constant +import com.ym.pysc.utils.constant.SYNC_BASE_TIME +import java.text.SimpleDateFormat +import java.util.Date /** * Created by dapeng on 2022/10/16. */ class LoginViewModel : BaseViewModel() { private val mRepository by lazy { InjectorUtil.getRepository() } - - fun login(params: HashMap,result:(UserInfo?)->Unit) { + fun login(params: HashMap, result: () -> Unit) { launchOnlyresult({ mRepository.login(params) }, success = { SPUtils.getInstance().put(constant.TOKEN, it?.token) - SPUtils.getInstance().put(constant.ACCOUNT,params["username"]) - SPUtils.getInstance().put(constant.PWD,params["password"]) - result(it) + SPUtils.getInstance().put(constant.ACCOUNT, params["username"]) + SPUtils.getInstance().put(constant.PWD, params["password"]) + //初始化基础数据 + syncBaseData(result) }, worng = { + defUI.dismissDialog.call() + + }, error = { + defUI.dismissDialog.call() + + }, isShowDialog = true) + } + + private fun syncBaseData(result: () -> Unit) { + launchGo({ + val baseWorkshop = mRepository.baseWorkshop() + val baseDefectiveType = mRepository.baseDefectiveType() + val baseRisk = mRepository.baseRisk() + val baseRiskHead = mRepository.baseRiskHead() + val checkRating = mRepository.checkRating() + val defectiveHistory = mRepository.defectiveHistory(hashMapOf()) + val netContentHistory = mRepository.netContentHistory(hashMapOf()) + val riskHistory = mRepository.riskHistory(hashMapOf()) + BaseDataManager.saveWorkshopList(baseWorkshop.data) + BaseDataManager.saveDefcetiveTypeList(baseDefectiveType.data) + BaseDataManager.saveRiskTypeList(baseRisk.data) + BaseDataManager.saveRiskHeadList(baseRiskHead.data) + BaseDataManager.saveCheckRatingList(checkRating.data) + SPStaticUtils.put(constant.SYNC_DEF_DATA_TIME, System.currentTimeMillis()) + SPStaticUtils.put(constant.SYNC_NETCONTENT_DATA_TIME, System.currentTimeMillis()) + SPStaticUtils.put(constant.SYNC_FENGXIAN_DATA_TIME, System.currentTimeMillis()) + defectiveRepository.insertAll(defectiveHistory.data) + netContentRepository.insertAll(netContentHistory.data) + + riskRepository.insertAll(riskHistory.data) + var dateString = SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(Date()) + SPStaticUtils.put(SYNC_BASE_TIME, dateString) + result() + }, error = { + defUI.toastEvent.value = it.message + defUI.dismissDialog.call() }, isShowDialog = true) +// viewModelScope.launch { +// combine( +// flow { emit(mRepository.baseWorkshop()) }, +// flow { emit(mRepository.baseDefectiveType()) }, +// flow { emit(mRepository.checkRating()) }, +// flow { emit(mRepository.defectiveHistory(hashMapOf())) }, +// flow { emit(mRepository.netContentHistory(hashMapOf())) } +// ) { baseWorkshop, baseDefectiveType, checkRating, defectiveHistory, netContentHistory -> +// // 移除多余的花括号 +// BaseDataManager.saveWorkshopList(baseWorkshop.data) +// BaseDataManager.saveDefcetiveTypeList(baseDefectiveType.data) +//// BaseDataManager.saveRiskTypeList(baseRisk.data) +//// BaseDataManager.saveCheckRatingList(checkRating.data) +// SPStaticUtils.put(constant.SYNC_DEF_DATA_TIME, System.currentTimeMillis()) +// SPStaticUtils.put(constant.SYNC_NETCONTENT_DATA_TIME, System.currentTimeMillis()) +// SPStaticUtils.put(constant.SYNC_FENGXIAN_DATA_TIME, System.currentTimeMillis()) +// launchGo({ +// defectiveRepository.insertAll(defectiveHistory.data) +// }) +// +// launchGo({ +// netContentRepository.insertAll(netContentHistory.data) +// }) +// var dateString = SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(Date()) +// SPStaticUtils.put(SYNC_BASE_TIME, dateString) +// result() +// }.catch { cause: Throwable -> defUI.toastEvent.value = cause.message } +// .flowOn(Dispatchers.IO) +// .collect() +// } + } } \ No newline at end of file diff --git a/app/src/main/java/com/ym/pysc/ui/main/MainActivity.kt b/app/src/main/java/com/ym/pysc/ui/main/MainActivity.kt index 89281b1fd9e08b11771765e32783f743f2af5c85..656cb508c4b639ecc9b9dc3c675d752d0c20f1d5 100644 --- a/app/src/main/java/com/ym/pysc/ui/main/MainActivity.kt +++ b/app/src/main/java/com/ym/pysc/ui/main/MainActivity.kt @@ -23,7 +23,12 @@ class MainActivity : MyBaseActivity() { override fun initView(savedInstanceState: Bundle?) { onTabClick(0) - + tab.tag1.setOnClickListener { + onTabClick(0) + } + tab.tag2.setOnClickListener { + onTabClick(1) + } } fun onTabClick(index: Int) { val fm = supportFragmentManager diff --git a/app/src/main/java/com/ym/pysc/ui/main/home/HomeFragment.kt b/app/src/main/java/com/ym/pysc/ui/main/home/HomeFragment.kt index f54b3396931c874ec6c835155799f56ff5e497a9..9ef638ac0097a54d0a331c83863baf1fc4f3c419 100644 --- a/app/src/main/java/com/ym/pysc/ui/main/home/HomeFragment.kt +++ b/app/src/main/java/com/ym/pysc/ui/main/home/HomeFragment.kt @@ -2,23 +2,39 @@ package com.ym.pysc.ui.main.home import android.content.Intent import android.os.Bundle +import android.util.Log +import android.view.View +import android.widget.TextView +import android.widget.ViewSwitcher +import com.blankj.utilcode.util.NetworkUtils +import com.blankj.utilcode.util.SPStaticUtils +import com.blankj.utilcode.util.ToastUtils import com.ym.httplibrary.base.BaseFragment -import com.ym.httplibrary.viewmodel.NoViewModel import com.ym.pysc.R import com.ym.pysc.databinding.FragmentHomeBinding import com.ym.pysc.ui.defective.DefectiveActivity import com.ym.pysc.ui.netContent.NetContentActivity -import com.ym.pysc.utils.constant.TITLE +import com.ym.pysc.ui.risk.RiskActivity +import com.ym.pysc.utils.constant.SYNC_BASE_TIME +import com.ym.pysc.utils.constant.SYNC_DEF_DATA_TIME +import com.ym.pysc.utils.constant.SYNC_FENGXIAN_DATA_TIME +import com.ym.pysc.utils.constant.SYNC_NETCONTENT_DATA_TIME import kotlinx.android.synthetic.main.fragment_home.btn1 import kotlinx.android.synthetic.main.fragment_home.btn2 import kotlinx.android.synthetic.main.fragment_home.btn3 +import kotlinx.android.synthetic.main.fragment_home.btn_Netcontent_data +import kotlinx.android.synthetic.main.fragment_home.btn_def_data +import kotlinx.android.synthetic.main.fragment_home.btn_fengxian_data +import kotlinx.android.synthetic.main.fragment_home.btn_sync +import kotlinx.android.synthetic.main.fragment_home.scrollingText + /** * @Author ldp * @Date 2023/7/4 15:27 * @Description: */ -class HomeFragment : BaseFragment() { +class HomeFragment : BaseFragment() { companion object { val TAG = "HomeFragment" fun newInstance() = HomeFragment() @@ -28,17 +44,79 @@ class HomeFragment : BaseFragment() { override fun layoutId(): Int = R.layout.fragment_home override fun initView(savedInstanceState: Bundle?) { super.initView(savedInstanceState) + + binding!!.viewModel = viewModel + + viewModel.syncTime.set(SPStaticUtils.getString(SYNC_BASE_TIME)) + btn_sync.setOnClickListener { + if (NetworkUtils.isConnected()) { + viewModel.syncBaseData() + } else { + ToastUtils.showShort("没有网络") + } + } btn1.setOnClickListener { val intent = Intent(requireActivity(), DefectiveActivity::class.java) startActivity(intent) } + btn_def_data.setOnClickListener { + if (NetworkUtils.isConnected()) { + viewModel.syncDefData() + } else { + ToastUtils.showShort("没有网络") + } + } btn2.setOnClickListener { val intent = Intent(requireActivity(), NetContentActivity::class.java) startActivity(intent) } + btn_Netcontent_data.setOnClickListener { + if (NetworkUtils.isConnected()) { + viewModel.syncNetContentData() + } else { + ToastUtils.showShort("没有网络") + } + } btn3.setOnClickListener { + val intent = Intent(requireActivity(), RiskActivity::class.java) + startActivity(intent) + } + btn_fengxian_data.setOnClickListener { + if (NetworkUtils.isConnected()) { + viewModel.syncFengxianData() + } else { + ToastUtils.showShort("没有网络") + } + } + } + private fun showScrollingText() { + val defTime = SPStaticUtils.getLong(SYNC_DEF_DATA_TIME, 0L) + val netTime = SPStaticUtils.getLong(SYNC_NETCONTENT_DATA_TIME, 0L) + val fengxianTime = SPStaticUtils.getLong(SYNC_FENGXIAN_DATA_TIME, 0L) + val minTime = minOf(defTime, netTime, fengxianTime) + + val curTime = System.currentTimeMillis() - minTime + if (curTime > 3 * 24 * 60 * 60 * 1000) { + scrollingText.visibility = View.VISIBLE + } else { + scrollingText.visibility = View.GONE + + } + + } + + override fun onResume() { + super.onResume() + viewModel.getHistoryNoSyncDefectData() + viewModel.getHistoryNoSyncNoContentData() + viewModel.getHistoryNoSyncRiskData() + scrollingText.isSelected = true + + showScrollingText() + + } } \ No newline at end of file diff --git a/app/src/main/java/com/ym/pysc/ui/main/home/HomeViewModel.kt b/app/src/main/java/com/ym/pysc/ui/main/home/HomeViewModel.kt new file mode 100644 index 0000000000000000000000000000000000000000..936f50e2e733ca200db8032ff059b2ba11406ad7 --- /dev/null +++ b/app/src/main/java/com/ym/pysc/ui/main/home/HomeViewModel.kt @@ -0,0 +1,148 @@ +package com.ym.pysc.ui.main.home + +import androidx.databinding.ObservableField +import androidx.lifecycle.MutableLiveData +import androidx.lifecycle.viewModelScope +import com.blankj.utilcode.util.SPStaticUtils +import com.blankj.utilcode.util.ToastUtils +import com.ym.httplibrary.viewmodel.BaseViewModel +import com.ym.pysc.api.InjectorUtil +import com.ym.pysc.repository.defectiveRepository +import com.ym.pysc.repository.riskRepository +import com.ym.pysc.repository.netContentRepository +import com.ym.pysc.utils.BaseDataManager +import com.ym.pysc.utils.constant +import com.ym.pysc.utils.constant.SYNC_BASE_TIME +import com.ym.pysc.utils.constant.SYNC_DEF_DATA_TIME +import com.ym.pysc.utils.constant.SYNC_FENGXIAN_DATA_TIME +import com.ym.pysc.utils.constant.SYNC_NETCONTENT_DATA_TIME +import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.flow.catch +import kotlinx.coroutines.flow.collect +import kotlinx.coroutines.flow.combine +import kotlinx.coroutines.flow.flow +import kotlinx.coroutines.flow.flowOn +import kotlinx.coroutines.launch +import java.text.SimpleDateFormat +import java.util.Date + +class HomeViewModel : BaseViewModel() { + private val mRepository by lazy { InjectorUtil.getRepository() } + + val hasDefectData = MutableLiveData(false) + val hasNetContentData = MutableLiveData(false) + val hasFengxianData = MutableLiveData(false) + val syncTime = ObservableField("") + + + /** + * 搜索不良品未同步数 + */ + fun getHistoryNoSyncDefectData() { + launchGo({ + val a = defectiveRepository.getHistoryNoSyncData() + hasDefectData.value = !a.isNullOrEmpty() + if (a.isNullOrEmpty()){ + SPStaticUtils.put(constant.SYNC_DEF_DATA_TIME, System.currentTimeMillis()) + + } + }) + } + + /** + * 搜索净含量未同步数据 + */ + fun getHistoryNoSyncNoContentData() { + launchGo({ + val a = netContentRepository.getHistoryNoSyncData() + hasNetContentData.value = !a.isNullOrEmpty() + if (a.isNullOrEmpty()){ + SPStaticUtils.put(constant.SYNC_NETCONTENT_DATA_TIME, System.currentTimeMillis()) + } + }) + } + /** + * 搜索检查点未同步数据 + */ + fun getHistoryNoSyncRiskData() { + launchGo({ + val a = riskRepository.getHistoryNoSyncData() + hasFengxianData.value = !a.isNullOrEmpty() + if (a.isNullOrEmpty()){ + SPStaticUtils.put(constant.SYNC_FENGXIAN_DATA_TIME, System.currentTimeMillis()) + } + + }) + } + fun syncDefData() { + launchGo({ + val syncData = defectiveRepository.getHistoryNoSyncData() + if (!syncData.isNullOrEmpty()) { + val code = mRepository.insertDefect(syncData).code + if (code == 0) { + defectiveRepository.updateSyncSuccess() + hasDefectData.value = false + SPStaticUtils.put(SYNC_DEF_DATA_TIME, System.currentTimeMillis()) + } + } else { + ToastUtils.showShort("没有可同步的数据") + } + }, isShowDialog = true) + } + + fun syncNetContentData() { + launchGo({ + val syncData = netContentRepository.getHistoryNoSyncData() + if (!syncData.isNullOrEmpty()) { + val code = mRepository.insertNet(syncData).code + if (code == 0) { + netContentRepository.updateSyncSuccess() + hasNetContentData.value = false + SPStaticUtils.put(SYNC_NETCONTENT_DATA_TIME, System.currentTimeMillis()) + + } + } else { + ToastUtils.showShort("没有可同步的数据") + } + }, isShowDialog = true) + } + + fun syncFengxianData() { + launchGo({ + val syncData = riskRepository.getHistoryNoSyncData() + if (!syncData.isNullOrEmpty()) { + val code = mRepository.insertFengxian(syncData).code + if (code == 0) { + riskRepository.updateSyncSuccess() + hasFengxianData.value = false + SPStaticUtils.put(SYNC_FENGXIAN_DATA_TIME, System.currentTimeMillis()) + } + } else { + ToastUtils.showShort("没有可同步的数据") + } + }, isShowDialog = true) + } + + fun syncBaseData() { + launchGo({ + val baseWorkshop = mRepository.baseWorkshop() + val baseDefectiveType = mRepository.baseDefectiveType() + val baseRisk = mRepository.baseRisk() + val baseRiskHead = mRepository.baseRiskHead() + val checkRating = mRepository.checkRating() + BaseDataManager.saveWorkshopList(baseWorkshop.data) + BaseDataManager.saveDefcetiveTypeList(baseDefectiveType.data) + BaseDataManager.saveRiskTypeList(baseRisk.data) + BaseDataManager.saveRiskHeadList(baseRiskHead.data) + BaseDataManager.saveCheckRatingList(checkRating.data) + SPStaticUtils.put(constant.SYNC_DEF_DATA_TIME, System.currentTimeMillis()) + SPStaticUtils.put(constant.SYNC_NETCONTENT_DATA_TIME, System.currentTimeMillis()) + SPStaticUtils.put(constant.SYNC_FENGXIAN_DATA_TIME, System.currentTimeMillis()) + var dateString = SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(Date()) + SPStaticUtils.put(SYNC_BASE_TIME, dateString) + syncTime.set(dateString) + }, error = { + defUI.toastEvent.value = it.message + }, isShowDialog = true) + } +} \ No newline at end of file diff --git a/app/src/main/java/com/ym/pysc/ui/main/mine/MineFragment.kt b/app/src/main/java/com/ym/pysc/ui/main/mine/MineFragment.kt index bbc4a04cfc0cf47c771864c0e0bfd5723e41c6b4..4b88c0b36c9374744e29a10fc618796917d89d81 100644 --- a/app/src/main/java/com/ym/pysc/ui/main/mine/MineFragment.kt +++ b/app/src/main/java/com/ym/pysc/ui/main/mine/MineFragment.kt @@ -1,20 +1,140 @@ package com.ym.pysc.ui.main.mine +import android.app.AlertDialog +import android.content.Intent +import android.os.Bundle +import android.view.View import androidx.databinding.ViewDataBinding +import com.blankj.utilcode.util.SPUtils +import com.blankj.utilcode.util.ToastUtils import com.ym.httplibrary.base.BaseFragment -import com.ym.httplibrary.viewmodel.NoViewModel +import com.ym.pysc.BuildConfig import com.ym.pysc.R +import com.ym.pysc.download.DownloadUtils +import com.ym.pysc.model.UpdateVersion +import com.ym.pysc.ui.login.LoginActivity +import com.ym.pysc.utils.FileUtil +import com.ym.pysc.utils.constant +import com.ym.pysc.widget.ProcessDialog +import kotlinx.android.synthetic.main.activity_login.tv_version -/** - * @Author ldp - * @Date 2023/7/4 15:27 - * @Description: - */ -class MineFragment:BaseFragment() { +import kotlinx.android.synthetic.main.fragment_mine.* +import java.io.File + +class MineFragment : BaseFragment() { companion object { val TAG = "MineFragment" fun newInstance() = MineFragment() + } + + protected var processDialog: ProcessDialog? = null + + override fun layoutId(): Int = R.layout.fragment_mine + override fun initView(savedInstanceState: Bundle?) { + super.initView(savedInstanceState) + processDialog = ProcessDialog(mContext) + tv_username.text = SPUtils.getInstance().getString(constant.ACCOUNT) + tv_version.text = "v${BuildConfig.VERSION_NAME}" + initVersionIcon() + tv_version_item.setOnClickListener { + checkVersion() + } + tv_logout_item.setOnClickListener { + var dialog = AlertDialog.Builder(mContext) + .setTitle("退出提示") + .setMessage("您确定要退出账号吗") + .setCancelable(false) + .setPositiveButton( + "取消" + ) { dialog, which -> + dialog.dismiss() + } + .setNegativeButton( + "确定" + ) { dialog, which -> + dialog.dismiss() + SPUtils.getInstance().put(constant.TOKEN,"") + viewModel.deleteAll{ + startActivity(Intent(mContext, LoginActivity::class.java)) + activity?.finish() + } + + }.create() + dialog.show() + } + } + + /** + * 点击显示是否下载 + */ + private fun checkVersion() { + var params = hashMapOf( + "appId" to BuildConfig.APPLICATION_ID, + "version" to BuildConfig.VERSION_NAME + ) + viewModel.update(isShowDialog = true, params = params, update = { + updateApp(it) + }, notUpdate = { + viewModel.defUI.toastEvent.value="当前已经是最新版本" + }) + } + + /** + * 初始化显示是否有新版本 + */ + private fun initVersionIcon() { + var params = hashMapOf( + "appId" to BuildConfig.APPLICATION_ID, + "version" to BuildConfig.VERSION_NAME + ) + viewModel.update(isShowDialog = false, params = params, update = { + v_new_version.visibility = View.VISIBLE + }, notUpdate = { + v_new_version.visibility = View.GONE + }) + } + ///更新app代码----start + fun updateApp(updateInfo: UpdateVersion?) { + var dialog = AlertDialog.Builder(mContext) + .setTitle("升级说明") + .setMessage("最新版本v") + .setCancelable(false) + .setPositiveButton( + "立即升级" + ) { dialog, which -> + processDialog?.showDialog("准备下载,请稍等...") { DownloadUtils.closeCall() } + val sApkFile = mContext?.getExternalFilesDir("")?.absolutePath + "/ymbz.apk" + downloadFile(updateInfo?.url, sApkFile) + } + .setNegativeButton( + "不更新" + ) { dialog, which -> + dialog.dismiss() + }.create() + dialog.show() + } + private fun downloadFile(url: String?, filePath: String?) { + DownloadUtils.downloadFile( + url, filePath + ) { bytesRead, contentLength, done -> + requireActivity().runOnUiThread { + processDialog?.setMessage( + "正在下载,已下载:" + FileUtil.intToMKB(bytesRead) + .toString() + "/" + FileUtil.intToMKB(contentLength) + ) + } + if (done) { + processDialog?.dismissDialog() + requireActivity().runOnUiThread { + FileUtil.openFile( + requireActivity(), + File(filePath) + ) + } + DownloadUtils.closeCall() + } + } } - override fun layoutId(): Int =R.layout.fragment_mine + ///更新app代码----end } \ No newline at end of file diff --git a/app/src/main/java/com/ym/pysc/ui/main/mine/MineViewModel.kt b/app/src/main/java/com/ym/pysc/ui/main/mine/MineViewModel.kt new file mode 100644 index 0000000000000000000000000000000000000000..e3abc40f5fb7cd6a1796d10bb6411c9d35f9d5ca --- /dev/null +++ b/app/src/main/java/com/ym/pysc/ui/main/mine/MineViewModel.kt @@ -0,0 +1,50 @@ +package com.ym.pysc.ui.main.mine + +import com.blankj.utilcode.util.ToastUtils +import com.ym.httplibrary.viewmodel.BaseViewModel +import com.ym.pysc.api.InjectorUtil +import com.ym.pysc.model.UpdateVersion +import com.ym.pysc.repository.defectiveRepository +import com.ym.pysc.repository.riskRepository +import com.ym.pysc.repository.netContentRepository + +/** + * @Author ldp + * @Date 2023/7/6 09:14 + * @Description: + */ +class MineViewModel : BaseViewModel() { + private val mRepository by lazy { InjectorUtil.getRepository() } + + fun update(isShowDialog:Boolean, params: HashMap, update:(UpdateVersion)->Unit, notUpdate:(UpdateVersion)->Unit) { + launchOnlyresult({ mRepository.checkVersion(params) }, + success = { + if (it?.status == 1){ + update(it) + }else{ + notUpdate(it!!) + } + },isShowDialog = isShowDialog) + } + fun deleteAll(result:()->Unit) { + launchGo({ + //搜索未同步数 + val a = defectiveRepository.getHistoryNoSyncData() + val b = netContentRepository.getHistoryNoSyncData() + val c = riskRepository.getHistoryNoSyncData() + if (a.isNullOrEmpty() && b.isNullOrEmpty() && c.isNullOrEmpty()){ + //删除所有数据 + defectiveRepository.deleteAll() + netContentRepository.deleteAll() + riskRepository.deleteAll() + result() + }else{ + ToastUtils.showShort("请先同步未同步数据后再退出") + + } + + }, isShowDialog = true) + } + + +} \ No newline at end of file diff --git a/app/src/main/java/com/ym/pysc/ui/netContent/NetContentActivity.kt b/app/src/main/java/com/ym/pysc/ui/netContent/NetContentActivity.kt index cd0b5414bb5e84cb091ac5ad87580d13bca0552b..7c9535f92eefb43ffe9f2306b56bb25fdb40eb3a 100644 --- a/app/src/main/java/com/ym/pysc/ui/netContent/NetContentActivity.kt +++ b/app/src/main/java/com/ym/pysc/ui/netContent/NetContentActivity.kt @@ -4,17 +4,20 @@ import android.app.AlertDialog import android.os.Bundle import android.view.View import androidx.recyclerview.widget.LinearLayoutManager -import com.android.commonlibrary.util.DateUtil -import com.android.commonlibrary.window.AppPopupWindow import com.blankj.utilcode.util.ToastUtils import com.ym.pysc.MyBaseActivity import com.ym.pysc.R import com.ym.pysc.databinding.ActivityNetContentBinding import com.ym.pysc.function.showItemPop +import com.ym.pysc.model.GainNetContent import com.ym.pysc.model.ItemInfo import com.ym.pysc.model.NetRelateInfo +import com.ym.pysc.model.WorkShopInfo import com.ym.pysc.ui.netContent.adapter.NetContentAdapter -import com.ym.pysc.widget.DatePop +import com.ym.pysc.utils.BaseDataManager +import com.ym.pysc.utils.FloatUtil +import com.ym.pysc.widget.DatePopHelper +import kotlinx.android.synthetic.main.activity_defective.iv_add import kotlinx.android.synthetic.main.activity_net_content.* import kotlinx.android.synthetic.main.layout_netcontent.* import java.text.SimpleDateFormat @@ -25,67 +28,68 @@ import java.util.Date */ class NetContentActivity : MyBaseActivity() { lateinit var mNetAdapter: NetContentAdapter - private var wheel = 0 + private var totalWheel = 1 private var factoryWorkList: MutableList? = null private var normalRelateList: MutableList? = null + private lateinit var workshopList: MutableList + private var params = hashMapOf() + override fun layoutId(): Int = R.layout.activity_net_content override fun initView(savedInstanceState: Bundle?) { super.initView(savedInstanceState) + workshopList = BaseDataManager.getWorkshopList() + binding!!.viewModel = viewModel - binding!!.isNext = false + binding!!.showNext = false binding!!.emptyInfo = "请选择车间" initDate() initNetListView() - viewModel.myWorkshop { - factoryWorkList = it?.map { item -> - ItemInfo( - "${item.factoryCode}-${item.workshopCode}", - "${item.factoryName}${item.workshopName}" - ) - }?.toMutableList() + factoryWorkList = workshopList.map { item -> + ItemInfo( + "${item.factoryCode}-${item.workshopCode}", + "${item.factoryName}-${item.workshopName}" + ) + }?.toMutableList() - } tv_room.setOnClickListener { if (isValueChange()) { showValueChangeDialog() } else { tv_room.showItemPop(iv_room_arrow, factoryWorkList) { + params["factoryCode"] = it.code.split("-")[0] + params["factoryName"] = it.name.split("-")[0] + params["workshopCode"] = it.code.split("-")[1] + params["workshopName"] = it.name.split("-")[1] viewModel.factoryWorkShop.value = it - wheel = 0 binding!!.isSelectRoom = false binding!!.line = ItemInfo("", "请选择") binding!!.product = ItemInfo("", "请选择") - getListData() + params["lineCode"] = "null" + params["productCode"] = "null" + initNetContentList() gainLines(it) gainProduct(it) } } } - iv_next.setOnClickListener { - val workShopItem = viewModel.factoryWorkShop.value - if (workShopItem == null) { + iv_add.setOnClickListener { + if (params["factoryCode"].toString() == "null") { ToastUtils.showShort("请选择车间") return@setOnClickListener } - val lineCode = binding!!.line?.code ?: "" - val productCode = binding!!.product?.code ?: "" - val produceTime = binding!!.date ?: "" - - if (lineCode.isNullOrEmpty()) { + if (params["lineCode"].toString() == "null") { ToastUtils.showShort("请选择产线") return@setOnClickListener } - if (productCode.isNullOrEmpty()) { - ToastUtils.showShort("请选择产品") + if (params["productCode"].toString() == "null") { + ToastUtils.showShort("请选择产品") return@setOnClickListener - } - if (produceTime.isNullOrEmpty()) { + if (params["produceTime"].toString() == "null") { ToastUtils.showShort("请选择日期") return@setOnClickListener - } if (isValueChange()) { var dialog = AlertDialog.Builder(mContext) @@ -93,10 +97,8 @@ class NetContentActivity : MyBaseActivity - wheel = 0 - getListData() dialog.dismiss() } .setPositiveButton( @@ -107,8 +109,7 @@ class NetContentActivity : MyBaseActivity + showPageWheel(binding!!.wheel!!.toInt() - 1) + dialog.dismiss() + } + .setPositiveButton( + "提交并上一轮" + ) { dialog, which -> + submitData(isBefore = true) + dialog.dismiss() + }.create() + dialog.show() + } else { + showPageWheel(binding!!.wheel!!.toInt() - 1) - private fun createNormalRelateList(relateList: MutableList) { - normalRelateList = mutableListOf() - relateList.forEach { - val netRelateInfo = - NetRelateInfo( - key = it.key ?: null, - name = it.name ?: null, - value = it.value ?: null - ) - normalRelateList!!.add(netRelateInfo) + } } - } + btn_next.setOnClickListener { + if (isValueChange()) { + var dialog = AlertDialog.Builder(mContext) + .setTitle("提示") + .setMessage("数据发生了变化,您是否要先提交") + .setCancelable(false) + .setNegativeButton( + "继续" + ) { dialog, which -> + showPageWheel(binding!!.wheel!!.toInt() + 1) + dialog.dismiss() + } + .setPositiveButton( + "提交并下一轮" + ) { dialog, which -> + submitData(isNext = true) + dialog.dismiss() + }.create() + dialog.show() + } else { + showPageWheel(binding!!.wheel!!.toInt() + 1) - private fun getListData() { - val workShopItem = viewModel.factoryWorkShop.value - if (workShopItem == null) { - binding!!.emptyInfo = "请选择车间" - binding!!.isSelectRoom = false + } - return } - val factoryCode = workShopItem!!.code.split("-")[0] - val workshopCode = workShopItem!!.code.split("-")[1] - val lineCode = binding!!.line?.code ?: "" - val productCode = binding!!.product?.code ?: "" - val produceTime = binding!!.date ?: "" + } - if (lineCode.isNullOrEmpty()) { - binding!!.emptyInfo = "请选择产线" - binding!!.isSelectRoom = false - return + fun addNetContentRound() { + viewModel.addNetContentRound(params) { + createNormalRelateList(it.relateList!!) + mNetAdapter.setData(it.relateList!!) + binding!!.isSelectRoom = true + binding!!.wheel = it.wheel + binding!!.showNext = false + totalWheel = it.wheel } - if (productCode.isNullOrEmpty()) { - binding!!.emptyInfo = "请选择产品" - binding!!.isSelectRoom = false - return + } + + private fun createNormalRelateList(relateList: MutableList) { + normalRelateList = mutableListOf() + relateList.forEach { + it.lowerLimit = binding!!.product!!.lowerLimit?:"0" + it.standardValue = binding!!.product!!.standardValue?:"0" + it. upperLimit = binding!!.product!!.upperLimit?:"0" + val netRelateInfo = NetRelateInfo( + key = it.key ?: null, + name = it.name ?: null, + value = it.value ?: null + ) + normalRelateList!!.add(netRelateInfo) } - if (produceTime.isNullOrEmpty()) { - binding!!.emptyInfo = "请选择日期" - binding!!.isSelectRoom = false + } + private fun initNetContentList() { + var bool = inputAllData() + if (!bool) { return } - val params = hashMapOf( - "factoryCode" to factoryCode, - "workshopCode" to workshopCode, - "lineCode" to lineCode, - "productCode" to productCode, - "produceTime" to produceTime, - ) - if (wheel != 0) { - params.put("wheel", wheel.toString()) + viewModel.getNewRelateList(params) { + var list =it.relateList + createNormalRelateList(list) + mNetAdapter.setData(list) + binding!!.isSelectRoom = true + binding!!.wheel = it.wheel + totalWheel = it.wheel } - viewModel.gainNetContent(params) { - binding!!.isSelectRoom = true - val netContentInfo = it - wheel = netContentInfo!!.wheel - binding!!.wheel = wheel - binding!!.isNext = wheel < netContentInfo.wheelTotal + } + + fun showPageWheel(wheel: Int) { + val mParams = params + mParams.put("wheel", wheel) + viewModel.showPageWheel(mParams) { createNormalRelateList(it.relateList) mNetAdapter.setData(it.relateList) - btn_before.setOnClickListener { - - if (isValueChange()) { - var dialog = AlertDialog.Builder(mContext) - .setTitle("提示") - .setMessage("数据发生了变化,您是否要先提交") - .setCancelable(false) - .setNegativeButton( - "继续" - ) { dialog, which -> - wheel-- - getListData() - dialog.dismiss() - } - .setPositiveButton( - "提交并上一轮" - ) { dialog, which -> - submitData(isBefore = true) - dialog.dismiss() - }.create() - dialog.show() - } else { - wheel-- - getListData() - } - } - btn_next.setOnClickListener { - if (isValueChange()) { - var dialog = AlertDialog.Builder(mContext) - .setTitle("提示") - .setMessage("数据发生了变化,您是否要先提交") - .setCancelable(false) - .setNegativeButton( - "继续" - ) { dialog, which -> - wheel++ - getListData() - dialog.dismiss() - } - .setPositiveButton( - "提交并下一轮" - ) { dialog, which -> - submitData(isNext = true) - dialog.dismiss() - }.create() - dialog.show() - } else { - wheel++ - getListData() - } + binding!!.isSelectRoom = true + binding!!.wheel = it.wheel + binding!!.showNext = it.wheel < totalWheel - } } + } private fun gainLines(item: ItemInfo) { - - val params = hashMapOf( - "factoryCode" to item.code.split("-")[0], - "workshopCode" to item.code.split("-")[1] - ) - viewModel.gainLine(params) { - linesResult(it) - } + val curWorkShop = workshopList.filter { + it.factoryCode == item.code.split("-")[0] + && it.workshopCode == item.code.split("-")[1] + }.toMutableList() + linesResult(curWorkShop[0].lineList) } private fun linesResult(it: MutableList?) { - val items = it if (items!!.size == 1) { tv_line.setOnClickListener { } binding!!.line = items[0] + params.put("lineCode", items[0].code) + params.put("lineName", items[0].name) iv_line_arrow.visibility = View.GONE - getListData() + initNetContentList() } else { iv_line_arrow.visibility = View.VISIBLE @@ -277,8 +263,9 @@ class NetContentActivity : MyBaseActivity it.upperLimit!!.toDouble()) { + tv_status.text = "偏高" + } else { + tv_status.text = "正常" + } + tv_average.text = FloatUtil.getFloatValue(average.toString()) + } var layoutManager = LinearLayoutManager(this) layoutManager.orientation = LinearLayoutManager.VERTICAL rl_list.layoutManager = layoutManager rl_list.adapter = mNetAdapter btn_back.setOnClickListener { finish() } btn_confirm.setOnClickListener { - submitData() + submitData(isSubmit = true) } } - private fun submitData(isNext: Boolean = false, isBefore: Boolean = false) { - val factoryCode = viewModel.factoryWorkShop.value!!.code.split("-")[0] - val workshopCode = viewModel.factoryWorkShop.value!!.code.split("-")[1] - val lineCode = binding!!.line?.code ?: "" - val productCode = binding!!.product?.code ?: "" - val produceTime = binding!!.date ?: "" - val params = hashMapOf( - "factoryCode" to factoryCode, - "workshopCode" to workshopCode, - "lineCode" to lineCode, - "productCode" to productCode, - "produceTime" to produceTime, + private fun submitData( + isSubmit: Boolean = false, + isNext: Boolean = false, + isBefore: Boolean = false + ) { + + val myParams = GainNetContent( + factoryCode = params["factoryCode"].toString(), + factoryName = params["factoryName"].toString(), + workshopCode = params["workshopCode"].toString(), + workshopName = params["workshopName"].toString(), + lineCode = params["lineCode"].toString(), + lineName = params["lineName"].toString(), + productCode = params["productCode"].toString(), + productName = params["productName"].toString(), + produceTime = params["produceTime"].toString(), + wheel = binding!!.wheel!!.toInt(), + average = tv_average.text.toString(), + relateList = mNetAdapter.datas ) - if (wheel != 0) { - params.put("wheel", wheel.toString()) - } - params.put("relateList", mNetAdapter.datas) - viewModel.insertNetContent(params) { + viewModel.insertOrUpdateDefectInfo(myParams) { createNormalRelateList(mNetAdapter.datas) if (isNext) { - wheel++ - getListData() + addNetContentRound() } else if (isBefore) { - wheel-- - getListData() - + showPageWheel(binding!!.wheel!!.toInt() - 1) + } else if (isSubmit) { + ToastUtils.showShort("数据已保存") } } } - - /**弹出日期弹窗**/ - private fun showDatePop(data: (String) -> Unit) { - var datePop = DatePop(DateUtil.getDate(), mContext!!) - datePop.setFocuse(true)//点击返回键消失,一般设置为true - .setOuTouchCancel(true)//点击pop外部消失,默认true消失 - .setAnimation(AppPopupWindow.ANIMATION_SCREEN_BOTTOM_STYLE)//屏幕底部弹出 - .setBackgroundAlpha(0.5f)//设置背景遮罩透0f全黑,1.0f全透明) - //确认 - datePop.setBtnConfirm { - datePop.dismiss() - //选择日期 - var chooseDate: String = datePop.getChooseDate() - data(chooseDate) -// //"今天"tag的显示与隐藏 -// updateTodayTag(tvTodayTag,tvDate.text.toString()) - } - //关闭pop的监听处理 - datePop.setOnDismissListener { - datePop.setBackgroundAlpha(1.0f)//设置背景遮罩透明度(0f全黑,1.0f全透明) - } - //显示 - if (!datePop.isShowing()) { - //屏幕正下方弹出pop - datePop.showAtScreenBottom(binding!!.root) - } - } - - fun defOrNet(defective: () -> Unit, netContent: () -> Unit) { - if (title == resources.getString(R.string.str_defective)) { - defective() - } else { - netContent() - - } - - } - fun isValueChange(): Boolean { if (normalRelateList == null) { return false } else { val valueChanged = mNetAdapter.datas.zip(normalRelateList!!).any { (item1, item2) -> - if (item1.value == ""){ - item1.value = null + if (item1.curValue == "") { + item1.curValue = null + } + if (item2.curValue == "") { + item2.curValue = null } - item1.value != item2.value + item1.curValue != item2.curValue } return valueChanged } @@ -434,6 +410,34 @@ class NetContentActivity : MyBaseActivity() { + lateinit var mAdapter: NetContentHistoryAdapter + private var factoryWorkList: MutableList? = null + private lateinit var workshopList: MutableList + override fun layoutId(): Int = R.layout.activity_net_content_history + override fun initView(savedInstanceState: Bundle?) { + super.initView(savedInstanceState) + workshopList = BaseDataManager.getWorkshopList() + + initListView() + factoryWorkList = workshopList.map { item -> + ItemInfo( + "${item.factoryCode}-${item.workshopCode}", + "${item.factoryName}${item.workshopName}" + ) + }?.toMutableList() + + tv_room.setOnClickListener { + tv_room.showItemPop(iv_room_arrow, factoryWorkList) { + viewModel.factoryWorkShop.value = it + } + } + tv_date.setOnClickListener { + DatePopHelper.showDatePop(binding!!.root, mContext!!) { + binding!!.date = it + + } + } +// btn_search.setOnClickListener { +// var factoryCode = "" +// var workshopCode = "" +// val workShopItem = viewModel.factoryWorkShop.value +// if (workShopItem != null) { +// factoryCode = workShopItem!!.code.split("-")[0] +// workshopCode = workShopItem!!.code.split("-")[1] +// } +// val produceTime = binding!!.date ?: "" +// viewModel.getHistoryNoSyncData(factoryCode, workshopCode, produceTime) { +// mAdapter.setData(it) +// } +// +// } +// viewModel.getHistoryNoSyncData("", "", "") { +// mAdapter.setData(it) +// } + } + + private fun initListView() { + mAdapter = NetContentHistoryAdapter(this) + var layoutManager = LinearLayoutManager(this) + layoutManager.orientation = LinearLayoutManager.VERTICAL + rl_list.layoutManager = layoutManager + rl_list.adapter = mAdapter + } + + +} \ No newline at end of file diff --git a/app/src/main/java/com/ym/pysc/ui/netContent/NetContentViewModel.kt b/app/src/main/java/com/ym/pysc/ui/netContent/NetContentViewModel.kt index 8198f9db555d33d01dd03bf8fe1f1f1da4d1f368..d544b258a03ff73be9369f3a875e86384f37a9d2 100644 --- a/app/src/main/java/com/ym/pysc/ui/netContent/NetContentViewModel.kt +++ b/app/src/main/java/com/ym/pysc/ui/netContent/NetContentViewModel.kt @@ -1,120 +1,49 @@ package com.ym.pysc.ui.netContent import androidx.lifecycle.MutableLiveData -import com.blankj.utilcode.util.SPUtils import com.blankj.utilcode.util.ToastUtils import com.ym.httplibrary.viewmodel.BaseViewModel import com.ym.pysc.api.InjectorUtil import com.ym.pysc.model.GainDefectInfo import com.ym.pysc.model.GainNetContent import com.ym.pysc.model.ItemInfo -import com.ym.pysc.model.UserInfo -import com.ym.pysc.model.WorkShop -import com.ym.pysc.utils.constant +import com.ym.pysc.repository.defectiveRepository +import com.ym.pysc.repository.netContentRepository class NetContentViewModel : BaseViewModel() { - private val mRepository by lazy { InjectorUtil.getRepository() } var factoryWorkShop = MutableLiveData() - fun myWorkshop(result: (MutableList?) -> Unit) { - launchOnlyresult({ mRepository.myWorkshop() }, success = { - if (!it.isNullOrEmpty()) { - result(it) - } - }, worng = { - - }, error = { - if (it.code == 401) { - login { - launchOnlyresult({ mRepository.myWorkshop() }, success = { - if (!it.isNullOrEmpty()) { - result(it) - } - }, worng = { - }, isShowDialog = true) - } - } - }, isShowDialog = true) - } - - fun gainLine(params: HashMap, result: (MutableList?) -> Unit) { - launchOnlyresult({ mRepository.gainLine(params) }, success = { - result(it) - }, worng = { + fun insertOrUpdateDefectInfo(params: GainNetContent, result: () -> Unit) { + launchGo({ + netContentRepository.insertOrUpdateDefectInfo(params) + result() - }, error = { - if (it.code == 401) { - login { - launchOnlyresult({ mRepository.gainLine(params) }, success = { - result(it) - }) - } - } }) } - - fun gainProduct(params: HashMap, result: (MutableList?) -> Unit) { - launchOnlyresult({ mRepository.gainProduct(params) }, success = { - result(it) - }, worng = { - - }, error = { - if (it.code == 401) { - login { - launchOnlyresult({ mRepository.gainProduct(params) }, success = { - result(it) - }) - } - } + fun getNewRelateList(params: HashMap,result: (GainNetContent) -> Unit) { + launchGo({ + val a = netContentRepository.getNewRelateList(params) + result(a) }) } - - fun gainNetContent(params: HashMap, result: (GainNetContent?) -> Unit) { - launchOnlyresult({ mRepository.gainNetContent(params) }, success = { - result(it) - }, worng = { - - }, error = { - if (it.code == 401) { - login { - launchOnlyresult({ mRepository.gainNetContent(params) }, success = { - result(it) - }, isShowDialog = true) - } - } - }, isShowDialog = true) + /** + * 获取当前默认的净含量列表 + */ + fun addNetContentRound(params: HashMap,result: (GainNetContent) -> Unit) { + launchGo({ + val a = netContentRepository.addNetContentRound(params) + result(a) + }) } - - fun insertNetContent(params: HashMap, result: () -> Unit) { - launchOnlyresult({ mRepository.insertNetContent(params) }, success = { - ToastUtils.showShort("完成提交") - result() - }, worng = { - - }, error = { - if (it.code == 401) { - login { - launchOnlyresult({ mRepository.insertNetContent(params) }, success = { - ToastUtils.showShort("完成提交") - result() - }, isShowDialog = true) - } - } - - }, isShowDialog = true) + /** + * 根据wheel显示 + */ + fun showPageWheel(params: HashMap,result: (GainNetContent) -> Unit) { + launchGo({ + val a = netContentRepository.showListByWheel(params) + result(a) + }) } - fun login(result: (UserInfo?) -> Unit) { - val params = hashMapOf( - "username" to SPUtils.getInstance().getString(constant.ACCOUNT), - "password" to SPUtils.getInstance().getString(constant.PWD), - "grantType" to "PASSWORD" - ) - launchOnlyresult({ mRepository.login(params) }, success = { - SPUtils.getInstance().put(constant.TOKEN, it?.token) - result(it) - }, worng = { - }, isShowDialog = true) - } } \ No newline at end of file diff --git a/app/src/main/java/com/ym/pysc/ui/netContent/adapter/NetContentAdapter.kt b/app/src/main/java/com/ym/pysc/ui/netContent/adapter/NetContentAdapter.kt index 2b7627608e0f6cdb64ef264f017e3834afb25121..08497e2c6e1aefa92bcbaa6911f07a343c559430 100644 --- a/app/src/main/java/com/ym/pysc/ui/netContent/adapter/NetContentAdapter.kt +++ b/app/src/main/java/com/ym/pysc/ui/netContent/adapter/NetContentAdapter.kt @@ -1,6 +1,8 @@ package com.ym.pysc.ui.netContent.adapter import android.content.Context +import android.text.Editable +import android.text.TextWatcher import android.view.LayoutInflater import android.view.ViewGroup import androidx.databinding.DataBindingUtil @@ -11,7 +13,7 @@ import com.ym.pysc.R import com.ym.pysc.databinding.ItemNetContentBinding import com.ym.pysc.model.NetRelateInfo -class NetContentAdapter(context: Context) : BaseAdapter(context) { +class NetContentAdapter(context: Context,val onTextChange:(NetRelateInfo)->Unit) : BaseAdapter(context) { override fun onCreateHolder( inflater: LayoutInflater, parent: ViewGroup, @@ -24,13 +26,33 @@ class NetContentAdapter(context: Context) : BaseAdapter(context) parent, false ) - return NetContentViewHolder(binding) + return NetContentViewHolder(binding,onTextChange) } } -class NetContentViewHolder(val binding: ItemNetContentBinding) : +class NetContentViewHolder(val binding: ItemNetContentBinding,val onTextChange:(NetRelateInfo)->Unit) : BaseHolder(binding) { override fun onBind(item: NetRelateInfo) { binding.info = item + if (adapterPosition%2==0){ + binding.tvKey.setBackgroundResource(R.color.white) + binding.etValue.setBackgroundResource(R.color.white) + }else{ + binding.tvKey.setBackgroundResource(R.color.color_cccccc) + binding.etValue.setBackgroundResource(R.color.color_cccccc) + } + binding.position = adapterPosition + binding.etValue.addTextChangedListener(object :TextWatcher{ + override fun beforeTextChanged(p0: CharSequence?, p1: Int, p2: Int, p3: Int) { + } + + override fun onTextChanged(p0: CharSequence?, p1: Int, p2: Int, p3: Int) { + } + + override fun afterTextChanged(p0: Editable?) { + onTextChange(item) + } + + }) } } \ No newline at end of file diff --git a/app/src/main/java/com/ym/pysc/ui/netContent/adapter/NetContentHistoryAdapter.kt b/app/src/main/java/com/ym/pysc/ui/netContent/adapter/NetContentHistoryAdapter.kt new file mode 100644 index 0000000000000000000000000000000000000000..6815a9401e6bf4ef9ce17ca0933f821ca41e3490 --- /dev/null +++ b/app/src/main/java/com/ym/pysc/ui/netContent/adapter/NetContentHistoryAdapter.kt @@ -0,0 +1,53 @@ +package com.ym.pysc.ui.netContent.adapter + +import android.content.Context +import android.view.LayoutInflater +import android.view.ViewGroup +import androidx.databinding.DataBindingUtil +import androidx.recyclerview.widget.RecyclerView +import com.ym.httplibrary.base.BaseAdapter +import com.ym.httplibrary.base.BaseHolder +import com.ym.pysc.R +import com.ym.pysc.databinding.ItemDefectiveBinding +import com.ym.pysc.databinding.ItemDefectiveHistoryBinding +import com.ym.pysc.model.GainDefectInfo +import com.ym.pysc.model.GainNetContent +import com.ym.pysc.model.HistoryData +import com.ym.pysc.model.NetRelateInfo + +class NetContentHistoryAdapter(context: Context) : BaseAdapter(context) { + override fun onCreateHolder( + inflater: LayoutInflater, + parent: ViewGroup, + viewType: Int + ): RecyclerView.ViewHolder? { + + val binding = DataBindingUtil.inflate( + inflater, + R.layout.item_defective_history, + parent, + false + ) + return DefectiveHistoryViewHolder(binding) + } + +} + +class DefectiveHistoryViewHolder(val binding: ItemDefectiveHistoryBinding) : + BaseHolder(binding) { + override fun onBind(item: GainNetContent) { + var curStatus = "N" + if (item.status == item.wheelTotal) { + curStatus = "Y" + } + val historyData = HistoryData( + workshopName = item.workshopName?:"", + lineName = item.lineName?:"", + productName = item.productName?:"", + produceTime = item.produceTime?:"", + totalWheel = item.wheelTotal.toString(), + status =curStatus + ) + binding.info = historyData + } +} \ No newline at end of file diff --git a/app/src/main/java/com/ym/pysc/ui/risk/RiskActivity.kt b/app/src/main/java/com/ym/pysc/ui/risk/RiskActivity.kt new file mode 100644 index 0000000000000000000000000000000000000000..cc5ff846a7ee240aa783e8ffc39fc2049106ada1 --- /dev/null +++ b/app/src/main/java/com/ym/pysc/ui/risk/RiskActivity.kt @@ -0,0 +1,287 @@ +package com.ym.pysc.ui.risk + +import android.app.AlertDialog +import android.os.Bundle +import android.view.View +import android.widget.CompoundButton +import android.widget.CompoundButton.OnCheckedChangeListener +import androidx.recyclerview.widget.LinearLayoutManager +import com.blankj.utilcode.util.ToastUtils +import com.ym.pysc.MyBaseActivity +import com.ym.pysc.R +import com.ym.pysc.databinding.ActivityRiskBinding +import com.ym.pysc.function.showItemPop +import com.ym.pysc.model.ChildItem +import com.ym.pysc.model.RiskInfoItem +import com.ym.pysc.model.GainRiskInfo +import com.ym.pysc.model.ItemInfo +import com.ym.pysc.model.RiskHeadInfo +import com.ym.pysc.ui.risk.adapter.RiskAdapter +import com.ym.pysc.utils.BaseDataManager +import com.ym.pysc.widget.DatePopHelper +import kotlinx.android.synthetic.main.activity_risk.* +import java.text.SimpleDateFormat +import java.util.Date + +class RiskActivity : MyBaseActivity() { + lateinit var mAdapter: RiskAdapter + private var factoryWorkList: MutableList? = null + private var normalRelateList: MutableList? = null + private var params = hashMapOf() + private lateinit var riskHeads: MutableList + private lateinit var checkRatingList: MutableList + override fun layoutId(): Int = R.layout.activity_risk + override fun initView(savedInstanceState: Bundle?) { + super.initView(savedInstanceState) + riskHeads = BaseDataManager.getRiskHeadList() + checkRatingList = BaseDataManager.getCheckRatingList() + binding!!.viewModel = viewModel + binding!!.isEmpty = true + binding!!.emptyInfo = "请选择车间" + + initDate() + initNetListView() + factoryWorkList = riskHeads.map { item -> + ItemInfo( + "${item.factoryCode}-${item.workshopCode}", + "${item.factoryName}-${item.workshopName}" + ) + }?.toMutableList() + + tv_room.setOnClickListener { + if (isValueChange()) { + showValueChangeDialog() + } else { + tv_room.showItemPop(iv_room_arrow, factoryWorkList) { + cb_checkAll.isChecked = false + + params["factoryCode"] = it.code.split("-")[0] + params["factoryName"] = it.name.split("-")[0] + params["workshopCode"] = it.code.split("-")[1] + params["workshopName"] = it.name.split("-")[1] + viewModel.factoryWorkShop.value = it + binding!!.gx = ItemInfo("", "请选择") + params["gxCode"] = "null" + selectFengxianData() + gainGx(it) + } + } + + } + tv_date.setOnClickListener { + if (isValueChange()) { + showValueChangeDialog() + } else { + DatePopHelper.showDatePop(binding!!.root, mContext!!) { + binding!!.date = it + params.put("produceTime", it) + selectFengxianData() + } + } + + } + btn_confirm.setOnClickListener { + submitData() + } + tv_fangwei.setOnClickListener { + tv_fangwei.showItemPop(iv_fanwei_arrow, checkRatingList) { + cb_checkAll.isChecked = false + + binding!!.fw = it + params.put("fwCode", it.code) + params.put("fwName", it.name) + val _it =it + //切换之后 重制列表 +// realDatas.forEach { +// it.checkBox="0" +// it.remarks="" +// } + var tempData =realDatas.filter { it.rating == _it.code }.toMutableList() + mAdapter.setData(tempData) +// selectFengxianData() + } + } + cb_checkAll.setOnCheckedChangeListener { p0, isCheck -> + if (isCheck) { + mAdapter.datas.map { it.checkBox = "1" } + + } else { + mAdapter.datas.map { it.checkBox = "0" } + + } + mAdapter.notifyDataSetChanged() + } + + } + + private fun initNetListView() { + mAdapter = RiskAdapter(this) + var layoutManager = LinearLayoutManager(this) + layoutManager.orientation = LinearLayoutManager.VERTICAL + rl_list.layoutManager = layoutManager + rl_list.adapter = mAdapter + + } + + + private fun submitData() { + val myParams = GainRiskInfo( + factoryCode = params["factoryCode"].toString(), + factoryName = params["factoryName"].toString(), + workshopCode = params["workshopCode"].toString(), + workshopName = params["workshopName"].toString(), + gxCode = params["gxCode"].toString(), + gxName = params["gxName"].toString(), + gbCode = params["gbCode"].toString(), + gbName = params["gbName"].toString(), + produceTime = params["produceTime"].toString(), + relateList = realDatas + ) + viewModel.insertOrUpdateInfo(myParams) { + createNormalRelateList(mAdapter.datas) + ToastUtils.showShort("数据已保存") + } + } + private lateinit var realDatas:MutableList + private fun selectFengxianData() { + var bool = inputAllData() + if (!bool) { + return + } + viewModel.selectFengxianData(params) { + createNormalRelateList(it.relateList) + binding!!.isEmpty = false + realDatas = it.relateList + mAdapter.setData(it.relateList) + } + } + + private fun gainGx(item: ItemInfo) { + val curWorkShop = riskHeads.filter { + it.factoryCode == item.code.split("-")[0] + && it.workshopCode == item.code.split("-")[1] + }.toMutableList() + gxResult(curWorkShop[0].child) + } + + private fun gxResult(it: MutableList?) { + val items = it + iv_line_arrow.visibility = View.VISIBLE + tv_line.setOnClickListener { + if (isValueChange()) { + showValueChangeDialog() + } else { + val itemInfos = + items!!.map { ItemInfo(name = it.name, code = it.code) }.toMutableList() + tv_line.showItemPop(iv_line_arrow, itemInfos) { item -> + cb_checkAll.isChecked = false + + binding!!.gx = item + params.put("gxCode", item.code) + params.put("gxName", item.name) + binding!!.gb = ItemInfo("", "请选择") + params["gbCode"] = "null" + selectFengxianData() + val gbList = items.filter { it.code == item.code }.toMutableList() + gainGb(gbList[0].child) + } + } + + } + + } + + private fun gainGb(items: MutableList) { + gbResult(items) + } + + private fun gbResult(it: MutableList?) { + val items = it + tv_product.setOnClickListener { + if (isValueChange()) { + showValueChangeDialog() + } else { + val itemInfos = + items!!.map { ItemInfo(name = it.name, code = it.code) }.toMutableList() + + tv_product.showItemPop(iv_line_arrow, itemInfos) { + cb_checkAll.isChecked = false + binding!!.gb = it + params.put("gbCode", it.code) + params.put("gbName", it.name) + selectFengxianData() + } + } + + } + } + + private fun createNormalRelateList(relateList: MutableList) { + normalRelateList = mutableListOf() + normalRelateList!!.addAll(relateList) + } + + fun isValueChange(): Boolean { + if (normalRelateList == null) { + return false + } else { + val valueChanged = mAdapter.datas.zip(normalRelateList!!).any { (item1, item2) -> + + item1.checkBox != item2.checkBox + } + return valueChanged + } + + } + + fun showValueChangeDialog() { + var dialog = AlertDialog.Builder(mContext) + .setTitle("提示") + .setMessage("你有数据变更先,请提交后再选择") + .setCancelable(false) + .setPositiveButton( + "确定" + ) { dialog, which -> + dialog.dismiss() + }.create() + dialog.show() + } + + /** + * 设置默认时间 + */ + private fun initDate() { + var dateString = SimpleDateFormat("yyyy-MM-dd").format(Date()) + binding!!.date = dateString + params.put("produceTime", dateString) + + } + + private fun inputAllData(): Boolean { + binding!!.isEmpty = true + if (params["factoryCode"].toString() == "null") { + binding!!.emptyInfo = "请选择车间" + return false + } + if (params["gxCode"].toString() == "null") { + binding!!.emptyInfo = "请选择工序" + return false + } + + if (params["gbCode"].toString() == "null") { + binding!!.emptyInfo = "请选择工步" + return false + } + if (params["produceTime"].toString() == "null") { + binding!!.emptyInfo = "请选择日期" + return false + + } +// if (params["fwCode"].toString() == "null") { +// binding!!.emptyInfo = "请选择范围" +// return false +// +// } + return true + } +} \ No newline at end of file diff --git a/app/src/main/java/com/ym/pysc/ui/risk/RiskViewModel.kt b/app/src/main/java/com/ym/pysc/ui/risk/RiskViewModel.kt new file mode 100644 index 0000000000000000000000000000000000000000..67fcfbdf2dcb1d23650cf9c676969add662358b0 --- /dev/null +++ b/app/src/main/java/com/ym/pysc/ui/risk/RiskViewModel.kt @@ -0,0 +1,39 @@ +package com.ym.pysc.ui.risk + +import androidx.lifecycle.MutableLiveData +import com.ym.httplibrary.viewmodel.BaseViewModel +import com.ym.pysc.model.GainRiskInfo +import com.ym.pysc.model.ItemInfo +import com.ym.pysc.repository.riskRepository + +class RiskViewModel : BaseViewModel() { + var factoryWorkShop = MutableLiveData() + +// /** +// * 搜索净含量历史数据 +// */ +// fun getHistoryNoSyncData(factoryCode:String,workshopCode:String,produceTime:String,result: (MutableList) -> Unit){ +// launchGo({ +// val a = netContentRepository.getHistoryNoSyncData(factoryCode,workshopCode,produceTime) +// result(a) +// }) +// } + fun insertOrUpdateInfo(params: GainRiskInfo, result: () -> Unit) { + launchGo({ + riskRepository.insertOrUpdateInfo(params) + result() + + }) + } + fun selectFengxianData(params: HashMap,result: (GainRiskInfo) -> Unit) { + launchGo({ + val a = riskRepository.selectRiskData(params) + result(a) + }) + } + + + + + +} \ No newline at end of file diff --git a/app/src/main/java/com/ym/pysc/ui/risk/adapter/RiskAdapter.kt b/app/src/main/java/com/ym/pysc/ui/risk/adapter/RiskAdapter.kt new file mode 100644 index 0000000000000000000000000000000000000000..4b670bf5c763c18f3d66608d5cdf526fa9098a9c --- /dev/null +++ b/app/src/main/java/com/ym/pysc/ui/risk/adapter/RiskAdapter.kt @@ -0,0 +1,60 @@ +package com.ym.pysc.ui.risk.adapter + +import android.content.Context +import android.view.LayoutInflater +import android.view.ViewGroup +import android.view.inputmethod.EditorInfo +import androidx.databinding.DataBindingUtil +import androidx.recyclerview.widget.RecyclerView +import com.ym.httplibrary.base.BaseAdapter +import com.ym.httplibrary.base.BaseHolder +import com.ym.pysc.R +import com.ym.pysc.databinding.ItemRiskBinding +import com.ym.pysc.model.RiskInfoItem + +class RiskAdapter(context: Context) : BaseAdapter(context) { + private var fwCode=""; + override fun onCreateHolder( + inflater: LayoutInflater, + parent: ViewGroup, + viewType: Int + ): RecyclerView.ViewHolder? { + + val binding = DataBindingUtil.inflate( + inflater, + R.layout.item_risk, + parent, + false + ) + return FengxianViewHolder(fwCode,datas,binding) + } + + fun setFwCode(code: String) { + fwCode = code + notifyDataSetChanged() + } + +} +class FengxianViewHolder(val fwCode:String,val datas:MutableList,val binding: ItemRiskBinding) : + BaseHolder(binding) { + override fun onBind(item: RiskInfoItem) { + binding.info = item + binding.position = (adapterPosition+1).toString() + binding.ivCheck.isSelected = !(item.checkBox ==null || item.checkBox=="0") + binding.ivCheck.setOnClickListener { + if (binding.ivCheck.isSelected){ + item.checkBox = "0" + }else{ + item.checkBox = "1" + } + binding.ivCheck.isSelected = !binding.ivCheck.isSelected + } + + binding.etRemark.imeOptions = if (adapterPosition ==datas.size-1) { + EditorInfo.IME_ACTION_DONE + } else { + EditorInfo.IME_ACTION_NEXT + } + + } +} \ No newline at end of file diff --git a/app/src/main/java/com/ym/pysc/ui/splash/SplashActivity.kt b/app/src/main/java/com/ym/pysc/ui/splash/SplashActivity.kt index ec3a197b20caa6eabfd5f3970b8985fc90620663..383e287af52981843caf834b8275331a10ddd8cc 100644 --- a/app/src/main/java/com/ym/pysc/ui/splash/SplashActivity.kt +++ b/app/src/main/java/com/ym/pysc/ui/splash/SplashActivity.kt @@ -41,7 +41,7 @@ open class SplashActivity : MyBaseActivity() { private fun checkVersion() { if (NetworkUtils.isConnected()) { - var map = hashMapOf( + var map = hashMapOf( "appId" to BuildConfig.APPLICATION_ID, "version" to BuildConfig.VERSION_NAME ) @@ -50,15 +50,12 @@ open class SplashActivity : MyBaseActivity() { }, startApp = { startApp() }, error = { - Log.i("123123","23123") cl_splash.postDelayed({ checkVersion() }, 5000) }) } else { - cl_splash.postDelayed({ - checkVersion() - }, 5000) + startApp() } } diff --git a/app/src/main/java/com/ym/pysc/ui/splash/SplashViewModel.kt b/app/src/main/java/com/ym/pysc/ui/splash/SplashViewModel.kt index f0d1bb73d71aadaf11b70107e08418e5d86cff2e..b029791a7d937c3913e7756e626c316d51559396 100644 --- a/app/src/main/java/com/ym/pysc/ui/splash/SplashViewModel.kt +++ b/app/src/main/java/com/ym/pysc/ui/splash/SplashViewModel.kt @@ -1,6 +1,5 @@ package com.ym.pysc.ui.splash -import androidx.lifecycle.MutableLiveData import com.ym.httplibrary.viewmodel.BaseViewModel import com.ym.pysc.api.InjectorUtil import com.ym.pysc.model.UpdateVersion @@ -10,7 +9,6 @@ import com.ym.pysc.model.UpdateVersion */ class SplashViewModel : BaseViewModel() { private val mRepository by lazy { InjectorUtil.getRepository() } - public val loginSuccess = MutableLiveData() fun checkVersion(params: HashMap,update:(UpdateVersion?)->Unit,startApp:()->Unit,error:()->Unit) { launchOnlyresult({ mRepository.checkVersion(params) }, success = { diff --git a/app/src/main/java/com/ym/pysc/utils/BaseDataManager.kt b/app/src/main/java/com/ym/pysc/utils/BaseDataManager.kt new file mode 100644 index 0000000000000000000000000000000000000000..7d351ae91421fbc08b98e9cf6ee11071ca59bec6 --- /dev/null +++ b/app/src/main/java/com/ym/pysc/utils/BaseDataManager.kt @@ -0,0 +1,113 @@ +package com.ym.pysc.utils + +import android.content.Context +import com.blankj.utilcode.util.SPStaticUtils +import com.google.gson.Gson +import com.google.gson.reflect.TypeToken +import com.ym.pysc.model.GainRiskInfo +import com.ym.pysc.model.ItemInfo +import com.ym.pysc.model.RiskHeadInfo +import com.ym.pysc.model.WorkShopInfo + +object BaseDataManager { + + private const val WORKSHOP_LIST_KEY = "workshopListKey" + private const val DEFCETIVE_TYPE_KEY = "defcetive_type_key" + private const val RISK_TYPE_KEY = "risk_type_key" + private const val RISK_HEAD_KEY = "risk_head_key" + private const val CHECK_RATING_KEY = "check_rating_key" + + private lateinit var gson: Gson + + fun initialize(context: Context) { + gson = Gson() + } + + // 存储车间产线基础数据 + fun saveWorkshopList(workshopList: MutableList) { + val json = gson.toJson(workshopList) + SPStaticUtils.put(WORKSHOP_LIST_KEY,json) + } + + // 获取车间产线基础数据 + fun getWorkshopList(): MutableList { + val json = SPStaticUtils.getString(WORKSHOP_LIST_KEY, "") + val type = object : TypeToken>() {}.type + + return if (json.isNullOrEmpty()) { + mutableListOf() + } else { + gson.fromJson(json, type) + } + } + + // 存储不良品类型基础数据 + fun saveDefcetiveTypeList(workshopList: MutableList) { + val json = gson.toJson(workshopList) + SPStaticUtils.put(DEFCETIVE_TYPE_KEY,json) + } + + + // 获取车间产线基础数据 + fun getDefcetiveTypList(): MutableList { + val json = SPStaticUtils.getString(DEFCETIVE_TYPE_KEY, "") + val type = object : TypeToken>() {}.type + return if (json.isNullOrEmpty()) { + mutableListOf() + } else { + gson.fromJson(json, type) + } + } + + // 存储风险点基础数据 + fun saveRiskTypeList(list: MutableList) { + val json = gson.toJson(list) + SPStaticUtils.put(RISK_TYPE_KEY,json) + } + + // 获取车间产线基础数据 + fun getRiskTypeList(): MutableList { + val json = SPStaticUtils.getString(RISK_TYPE_KEY, "") + val type = object : TypeToken>() {}.type + return if (json.isNullOrEmpty()) { + mutableListOf() + } else { + gson.fromJson(json, type) + } + } + + + // 存储范围数据 + fun saveRiskHeadList(list: MutableList) { + val json = gson.toJson(list) + SPStaticUtils.put(RISK_HEAD_KEY,json) + } + // 获取车间产线基础数据 + fun getRiskHeadList(): MutableList { + val json = SPStaticUtils.getString(RISK_HEAD_KEY, "") + val type = object : TypeToken>() {}.type + return if (json.isNullOrEmpty()) { + mutableListOf() + } else { + gson.fromJson(json, type) + } + } + + + + // 存储范围数据 + fun saveCheckRatingList(list: MutableList) { + val json = gson.toJson(list) + SPStaticUtils.put(CHECK_RATING_KEY,json) + } + // 获取车间产线基础数据 + fun getCheckRatingList(): MutableList { + val json = SPStaticUtils.getString(CHECK_RATING_KEY, "") + val type = object : TypeToken>() {}.type + return if (json.isNullOrEmpty()) { + mutableListOf() + } else { + gson.fromJson(json, type) + } + } +} \ No newline at end of file diff --git a/app/src/main/java/com/ym/pysc/utils/FloatUtil.java b/app/src/main/java/com/ym/pysc/utils/FloatUtil.java new file mode 100644 index 0000000000000000000000000000000000000000..d81132146d263e6b2bbf6cf6e229bb13e2dcf53a --- /dev/null +++ b/app/src/main/java/com/ym/pysc/utils/FloatUtil.java @@ -0,0 +1,20 @@ +package com.ym.pysc.utils; + +public class FloatUtil { + public static String getFloatValue(String value){ + if (value==null || "".equals(value)){ + return ""; + } + Float f = Float.valueOf(value); + int temp = Math.round((f-f.intValue())*100); + if (temp%100 == 0){ + value = String.format("%.0f",f); + }else if (temp%10 == 0){ + value = String.format("%.1f",f); + + }else{ + value = String.format("%.2f",f); + } + return value; + } +} diff --git a/app/src/main/java/com/ym/pysc/utils/LongData.kt b/app/src/main/java/com/ym/pysc/utils/LongData.kt new file mode 100644 index 0000000000000000000000000000000000000000..6b65d21ed1bb0a7748e42b421d7d518cf214d62d --- /dev/null +++ b/app/src/main/java/com/ym/pysc/utils/LongData.kt @@ -0,0 +1,11 @@ +package com.ym.pysc.utils + +import kotlin.random.Random + +object LongData { + fun generateRandomLong(): Long { + val random = Random.Default + val upperBound = 10_000_000_000_000_000_0L // 上限为19位数 + return (random.nextDouble() * upperBound).toLong() + } +} \ No newline at end of file diff --git a/app/src/main/java/com/ym/pysc/utils/constant.kt b/app/src/main/java/com/ym/pysc/utils/constant.kt index d6368f3d3f18d565565d0b83c53e4f51a9f4e6e8..864571a1213299e8ba7abada0b3604ad68cc1c4c 100644 --- a/app/src/main/java/com/ym/pysc/utils/constant.kt +++ b/app/src/main/java/com/ym/pysc/utils/constant.kt @@ -10,4 +10,12 @@ object constant { val TOKEN="token" val TITLE="title" + val USERNAME="username" + val PASSWORD="password" + val SYNC_BASE_TIME="sync_base_time" + val SYNC_DEF_DATA_TIME="sync_Def_data_time"//同步批量数据时间 + val SYNC_NETCONTENT_DATA_TIME="sync_netcontent_data_time"//同步批量数据时间 + val SYNC_FENGXIAN_DATA_TIME="sync_fengxian_data_time"//同步批量数据时间 + + } \ No newline at end of file diff --git a/app/src/main/java/com/ym/pysc/widget/DatePop.kt b/app/src/main/java/com/ym/pysc/widget/DatePop.kt index 8e597a5d000c3cea0ae496a737b935ebf8d4a9e7..0b54453e8ee16c27a6da7b0d3d2fe3df0ee4b0c1 100644 --- a/app/src/main/java/com/ym/pysc/widget/DatePop.kt +++ b/app/src/main/java/com/ym/pysc/widget/DatePop.kt @@ -99,8 +99,8 @@ class DatePop: AppPopupWindow{ } /**确定事件**/ - fun setBtnConfirm(listener: View.OnClickListener) { - mBtnConfirm!!.setOnClickListener(View.OnClickListener { v -> listener.onClick(v)}) + fun setBtnConfirm(onClick:(View)->Unit) { + mBtnConfirm!!.setOnClickListener(View.OnClickListener { v -> onClick(v)}) } } \ No newline at end of file diff --git a/app/src/main/java/com/ym/pysc/widget/DatePopHelper.kt b/app/src/main/java/com/ym/pysc/widget/DatePopHelper.kt new file mode 100644 index 0000000000000000000000000000000000000000..461075345e0c424d9795a0c94c260d9954e2378c --- /dev/null +++ b/app/src/main/java/com/ym/pysc/widget/DatePopHelper.kt @@ -0,0 +1,52 @@ +package com.ym.pysc.widget + +import android.content.Context +import android.view.View +import android.widget.TextView +import com.android.commonlibrary.util.DateUtil +import com.android.commonlibrary.widget.MaskButton +import com.android.commonlibrary.window.AppPopupWindow +import com.necer.calendar.BaseCalendar +import com.necer.calendar.MonthCalendar +import com.necer.enumeration.CheckModel +import com.necer.enumeration.DateChangeBehavior +import com.necer.listener.OnCalendarChangedListener +import com.necer.painter.InnerPainter +import com.ym.pysc.R +import org.joda.time.LocalDate + + +/** + * Title:日期弹窗 + * description: + * autor:pei + * created on 2020/12/2 + */ +object DatePopHelper{ + /**弹出日期弹窗**/ + public fun showDatePop(view:View,context: Context,data: (String) -> Unit) { + var datePop = DatePop(DateUtil.getDate(), context!!) + datePop.setFocuse(true)//点击返回键消失,一般设置为true + .setOuTouchCancel(true)//点击pop外部消失,默认true消失 + .setAnimation(AppPopupWindow.ANIMATION_SCREEN_BOTTOM_STYLE)//屏幕底部弹出 + .setBackgroundAlpha(0.5f)//设置背景遮罩透0f全黑,1.0f全透明) + //确认 + datePop.setBtnConfirm { + datePop.dismiss() + //选择日期 + var chooseDate: String = datePop.getChooseDate() + data(chooseDate) +// //"今天"tag的显示与隐藏 +// updateTodayTag(tvTodayTag,tvDate.text.toString()) + } + //关闭pop的监听处理 + datePop.setOnDismissListener { + datePop.setBackgroundAlpha(1.0f)//设置背景遮罩透明度(0f全黑,1.0f全透明) + } + //显示 + if (!datePop.isShowing()) { + //屏幕正下方弹出pop + datePop.showAtScreenBottom(view) + } + } +} \ No newline at end of file diff --git a/app/src/main/java/com/ym/pysc/widget/ItemChangePop.kt b/app/src/main/java/com/ym/pysc/widget/ItemChangePop.kt index 494e42721eff9085c1ae1db650c6f0db62bd692e..5ea96c7f019e0c51d01ce805e3140efa29ab99ec 100644 --- a/app/src/main/java/com/ym/pysc/widget/ItemChangePop.kt +++ b/app/src/main/java/com/ym/pysc/widget/ItemChangePop.kt @@ -3,8 +3,11 @@ package com.ym.pysc.widget import android.content.Context import android.graphics.Color import android.graphics.drawable.ColorDrawable +import android.text.Editable +import android.text.TextWatcher import android.view.LayoutInflater import android.view.View +import android.widget.EditText import android.widget.PopupWindow import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.RecyclerView @@ -45,6 +48,7 @@ class ItemChangePop( var layoutManager = LinearLayoutManager(context) layoutManager.orientation = LinearLayoutManager.VERTICAL var recycleView = contentView.findViewById(R.id.recycleView) + var etContent = contentView.findViewById(R.id.et_content) recycleView.layoutManager = layoutManager // 添加分隔线 val dividerItemDecoration = RecycleviewDriverDecoration(context) @@ -52,6 +56,23 @@ class ItemChangePop( recycleView.adapter = mAdapter mDatas?.let { mAdapter.setData(it) } this.setOnDismissListener { onDismiss() } + etContent.addTextChangedListener(object : TextWatcher { + override fun beforeTextChanged(p0: CharSequence?, p1: Int, p2: Int, p3: Int) { + } + + override fun onTextChanged(p0: CharSequence?, p1: Int, p2: Int, p3: Int) { + val str = p0.toString() ?: "" + val a = mDatas?.filter { it.name.contains(str) }?.toMutableList() + a?.let { + mAdapter.setData(it) + } + } + + override fun afterTextChanged(p0: Editable?) { + } + + }) + } fun showAtFixedItem(view: View) { @@ -65,7 +86,7 @@ class ItemChangePop( // 显示PopupWindow在item视图下方 // showAtLocation(view, Gravity.NO_GRAVITY, location[0] + offsetXPx, location[1] + view.height + offsetYPx) - showAsDropDown(view,offsetXPx,offsetYPx) + showAsDropDown(view, offsetXPx, offsetYPx) } diff --git a/app/src/main/java/com/ym/pysc/widget/ProcessDialog.kt b/app/src/main/java/com/ym/pysc/widget/ProcessDialog.kt new file mode 100644 index 0000000000000000000000000000000000000000..e4721b469721747eb11354be3da9af586944e5b8 --- /dev/null +++ b/app/src/main/java/com/ym/pysc/widget/ProcessDialog.kt @@ -0,0 +1,67 @@ +package com.ym.pysc.widget + +import android.app.ProgressDialog +import android.content.Context +import kotlin.jvm.JvmOverloads +import java.lang.Exception + +/** + * @Author ldp + * @Date 2023/7/3 10:52 + * @Description:下载进度 + */ +class ProcessDialog(ct: Context?) { + private var bCancelable = true + private var pContext: Context? = null + private var dlg: ProgressDialog? = null + fun setCancelable(b: Boolean) { + bCancelable = b + } + + fun setMessage(sMsg: String?) { + if (dlg != null) { + dlg!!.setMessage(sMsg) + } + } + + @JvmOverloads + fun showDialog( + sMsg: String, + onCancelled: () -> Unit + ) { + try { + if (dlg == null) { + dlg = ProgressDialog(pContext) + dlg?.apply{ + this.isIndeterminate = true + this.setCanceledOnTouchOutside(false) + this.setMessage(sMsg) + this.setCancelable(bCancelable) + this.setOnCancelListener { + onCancelled() + dismissDialog() + } + } + dlg!!.show() + } else { + dlg!!.setMessage(sMsg) + } + } catch (var4: Exception) { + } + } + + fun dismissDialog() { + try { + if (dlg != null) { + dlg!!.dismiss() + dlg = null + } + } catch (var2: Exception) { + } + } + + + init { + pContext = ct + } +} \ No newline at end of file diff --git a/app/src/main/res/drawable/bg_red_round.xml b/app/src/main/res/drawable/bg_red_round.xml new file mode 100644 index 0000000000000000000000000000000000000000..65da6bb5dab49f5ccc24ab9ed7f2b8504f4b162d --- /dev/null +++ b/app/src/main/res/drawable/bg_red_round.xml @@ -0,0 +1,12 @@ + + + + + + + + diff --git a/app/src/main/res/drawable/bg_title.xml b/app/src/main/res/drawable/bg_title.xml new file mode 100644 index 0000000000000000000000000000000000000000..fb77a598a410591afd42764b17d69af76f635845 --- /dev/null +++ b/app/src/main/res/drawable/bg_title.xml @@ -0,0 +1,7 @@ + + + + \ No newline at end of file diff --git a/app/src/main/res/drawable/ic_logout.xml b/app/src/main/res/drawable/ic_logout.xml new file mode 100644 index 0000000000000000000000000000000000000000..d088473a94a517e2681b8e95578a5dd306f9dcb3 --- /dev/null +++ b/app/src/main/res/drawable/ic_logout.xml @@ -0,0 +1,5 @@ + + + diff --git a/app/src/main/res/drawable/ic_multi_check.xml b/app/src/main/res/drawable/ic_multi_check.xml new file mode 100644 index 0000000000000000000000000000000000000000..2764bd6bd34d12bbfececc5c0d3db85c46e65b82 --- /dev/null +++ b/app/src/main/res/drawable/ic_multi_check.xml @@ -0,0 +1,13 @@ + + + + diff --git a/app/src/main/res/drawable/ic_multi_normal.xml b/app/src/main/res/drawable/ic_multi_normal.xml new file mode 100644 index 0000000000000000000000000000000000000000..ad0eb0f97b38afcb5c100a07e7352182bccf6355 --- /dev/null +++ b/app/src/main/res/drawable/ic_multi_normal.xml @@ -0,0 +1,10 @@ + + + diff --git a/app/src/main/res/drawable/ic_single_check.xml b/app/src/main/res/drawable/ic_single_check.xml new file mode 100644 index 0000000000000000000000000000000000000000..2e91b416ee000d3aab6b657a9502fcadf1baced9 --- /dev/null +++ b/app/src/main/res/drawable/ic_single_check.xml @@ -0,0 +1,13 @@ + + + + diff --git a/app/src/main/res/drawable/ic_single_normal.xml b/app/src/main/res/drawable/ic_single_normal.xml new file mode 100644 index 0000000000000000000000000000000000000000..cdd0b5cbf3316e8a7144a30b667ee87cce17e7e7 --- /dev/null +++ b/app/src/main/res/drawable/ic_single_normal.xml @@ -0,0 +1,10 @@ + + + diff --git a/app/src/main/res/drawable/ic_user_logo.xml b/app/src/main/res/drawable/ic_user_logo.xml new file mode 100644 index 0000000000000000000000000000000000000000..d1689ed55839c2ece585647050b8fa51cb07991c --- /dev/null +++ b/app/src/main/res/drawable/ic_user_logo.xml @@ -0,0 +1,10 @@ + + + + + + + + diff --git a/app/src/main/res/drawable/ic_version.xml b/app/src/main/res/drawable/ic_version.xml new file mode 100644 index 0000000000000000000000000000000000000000..48b95fdcd35c4cb048ddb6b1af310226d3e25bc5 --- /dev/null +++ b/app/src/main/res/drawable/ic_version.xml @@ -0,0 +1,16 @@ + + + + + diff --git a/app/src/main/res/drawable/selector_item_multi_checked.xml b/app/src/main/res/drawable/selector_item_multi_checked.xml new file mode 100644 index 0000000000000000000000000000000000000000..3cc440ad6ae5ec21a0242ab9d43682d2f2f45f8f --- /dev/null +++ b/app/src/main/res/drawable/selector_item_multi_checked.xml @@ -0,0 +1,5 @@ + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/activity_defective.xml b/app/src/main/res/layout/activity_defective.xml index 880d02bc411f9ea383856ca484d4d13fc530b2a4..43b3e355d9a28fe703fb5e8cb2cd5ddfdadd06a7 100644 --- a/app/src/main/res/layout/activity_defective.xml +++ b/app/src/main/res/layout/activity_defective.xml @@ -1,5 +1,6 @@ - + @@ -8,15 +9,17 @@ + + + @@ -39,176 +43,195 @@ type="Boolean" /> - - - - - - - - - - - - - - - - - - - - - - - + android:layout_height="match_parent" + android:fillViewport="true" + android:fitsSystemWindows="true"> + - - - + + + android:layout_height="match_parent"> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - \ No newline at end of file diff --git a/app/src/main/res/layout/activity_defective_history.xml b/app/src/main/res/layout/activity_defective_history.xml new file mode 100644 index 0000000000000000000000000000000000000000..fca0c943d6922455cc70924d7fa94b9c5c724f92 --- /dev/null +++ b/app/src/main/res/layout/activity_defective_history.xml @@ -0,0 +1,184 @@ + + + + + + + + + + + + + + + + + + + + +