🆗 切换回老的打卡模式,移除jsessionid登录
This commit is contained in:
@@ -13,6 +13,7 @@ import com.pomelotea.hoperun.sign.config.HoperunUserConfig.userConfigMap
|
||||
import com.pomelotea.hoperun.sign.config.UserConfig
|
||||
import com.pomelotea.hoperun.sign.scheduler.AutoDakaScheduler
|
||||
import com.pomelotea.hoperun.sign.scheduler.AutoDakaScheduler.Companion.dakaQueue
|
||||
import com.pomelotea.hoperun.sign.scheduler.AutoRenewSessionScheduler
|
||||
import okhttp3.FormBody
|
||||
import okhttp3.MediaType.Companion.toMediaTypeOrNull
|
||||
import okhttp3.Request
|
||||
@@ -35,8 +36,11 @@ import java.util.*
|
||||
@RequestMapping("/api/daka")
|
||||
class HoperunSignController {
|
||||
|
||||
val LOGIN_URL = "http://pom.hoperun.com:8187/attm/login/login"
|
||||
|
||||
init {
|
||||
AutoDakaScheduler()
|
||||
AutoRenewSessionScheduler()
|
||||
val yxl = UserConfig(
|
||||
project_id = "U2103S000112",
|
||||
projectcode = "U2103S000112",
|
||||
@@ -46,14 +50,22 @@ class HoperunSignController {
|
||||
userConfigMap["16638"] = yxl
|
||||
}
|
||||
|
||||
@GetMapping("/username/{employeeNo}/{jsessionId}/{checked}")
|
||||
// @GetMapping("/username/{employeeNo}/{checked}/{jsessionId}")
|
||||
@GetMapping("/username/{employeeNo}/{checked}")
|
||||
fun getUsername(
|
||||
@PathVariable employeeNo: String,
|
||||
@PathVariable jsessionId: String,
|
||||
@PathVariable checked: Boolean
|
||||
): WebResult<LoginResponse?> {
|
||||
getJsessionIdAutoLogin(employeeNo, jsessionId)
|
||||
val userConfig = getUserConfig(employeeNo) ?: return WebResult.getFailed("登陆失败")
|
||||
/*
|
||||
if (jsessionId != null) {
|
||||
getJsessionIdAutoLogin(employeeNo, jsessionId)
|
||||
}*/
|
||||
|
||||
val userConfig = getUserConfig(employeeNo).let {
|
||||
oldLogin(employeeNo)
|
||||
getUserConfig(employeeNo)
|
||||
}
|
||||
userConfig ?: return WebResult.getFailed("登陆失败")
|
||||
userConfig.autoDaka = checked
|
||||
userConfig.device = deviceMap[employeeNo]
|
||||
return WebResult.getSuccess(
|
||||
@@ -138,6 +150,7 @@ class HoperunSignController {
|
||||
if (sessionMap.get(employeeNo) == null) {
|
||||
login(employeeNo, jsessionId)
|
||||
}
|
||||
sessionMap[employeeNo] = jsessionId
|
||||
return sessionMap.get(employeeNo)
|
||||
}
|
||||
|
||||
@@ -186,10 +199,26 @@ class HoperunSignController {
|
||||
// 读取员工姓名
|
||||
if (userConfigMap[employeeNo]?.username == null) {
|
||||
setUserConfig(employeeNo, jsessionId)
|
||||
sessionMap.put(employeeNo, jsessionId)
|
||||
}
|
||||
}
|
||||
|
||||
private fun oldLogin(employeeNo: String) {
|
||||
val jsessionId: String?
|
||||
val loginRequest = Request.Builder()
|
||||
.url(LOGIN_URL)
|
||||
.post(
|
||||
FormBody.Builder()
|
||||
.add("login_id", padEmployeeNumber(employeeNo))
|
||||
.add("password", "123456")
|
||||
.build()
|
||||
)
|
||||
.build()
|
||||
val response = client.newCall(loginRequest).execute()
|
||||
jsessionId = response.request.url.pathSegments[2].substring(19)
|
||||
sessionMap.put(employeeNo, jsessionId)
|
||||
setUserConfigOld(employeeNo)
|
||||
}
|
||||
|
||||
private fun setUserConfig(employeeNo: String, jsessionId: String) {
|
||||
val attendancesDetailRequest = Request.Builder()
|
||||
.url("http://pom.hoperun.com:8187/attm/calendar/monthAtt?staff_code=${padEmployeeNumber(employeeNo)}&yearmonth=${getNowDateyyyy_MM()}-01")
|
||||
@@ -252,6 +281,77 @@ class HoperunSignController {
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
private fun setUserConfigOld(employeeNo: String) {
|
||||
// 获取deviceua
|
||||
val loginRequest = Request.Builder()
|
||||
.url("http://pom.hoperun.com:8187/attp/login/login.do")
|
||||
.post(
|
||||
JSON.toJSONString(
|
||||
mapOf(
|
||||
"login_id" to padEmployeeNumber(employeeNo),
|
||||
"password" to "123456",
|
||||
"roleType" to "0"
|
||||
)
|
||||
).toRequestBody("application/json;charset=utf-8".toMediaTypeOrNull())
|
||||
)
|
||||
.build()
|
||||
val response = client.newCall(loginRequest).execute()
|
||||
val jsessionId = response.headers("Set-Cookie")[0].substring(11, 43)
|
||||
|
||||
val attendancesDetailRequest = Request.Builder()
|
||||
.url("http://pom.hoperun.com:8187/attp/attendances/queryAttendancesDetail")
|
||||
.post(
|
||||
JSON.toJSONString(
|
||||
mapOf(
|
||||
"beginDate" to getLastDateyyyy_MM() + "-21",
|
||||
"endDate" to getNowDateyyyy_MM_dd(),
|
||||
"staffCode" to padEmployeeNumber(employeeNo)
|
||||
)
|
||||
).toRequestBody("application/json;charset=utf-8".toMediaTypeOrNull())
|
||||
)
|
||||
.addHeader("Cookie", "JSESSIONID=$jsessionId")
|
||||
.build()
|
||||
val attendancesDetailResponse = client.newCall(attendancesDetailRequest).execute()
|
||||
val bodyString = attendancesDetailResponse.body?.string()
|
||||
val dakaJsonArray = JSONObject.parseArray(bodyString)
|
||||
val dakaInfo = dakaJsonArray.getJSONObject(dakaJsonArray.size - 1)
|
||||
val dakaList = dakaInfo.getJSONArray("list")
|
||||
var lastDakaInfo = dakaList.getJSONObject(dakaList.size - 1)
|
||||
val userConfig: UserConfig = userConfigMap.get(employeeNo) ?: UserConfig()
|
||||
|
||||
if (lastDakaInfo.getString("begin_time") == null) {
|
||||
for (i in dakaList.size - 1 downTo 0) {
|
||||
lastDakaInfo = dakaList.getJSONObject(i)
|
||||
if (lastDakaInfo.getString("actual_area_end") != null) {
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
val username: String = lastDakaInfo.getString("staff_name")
|
||||
userConfig.username = username
|
||||
if (userConfig.device == null) {
|
||||
if (lastDakaInfo.getString("actual_area_end") != null) {
|
||||
val area: String = lastDakaInfo.getString("actual_area_end")
|
||||
userConfig.device = area.substring(area.lastIndexOf("Qing") + 13)
|
||||
} else if (lastDakaInfo.getString("actual_area_begin") != null) {
|
||||
val area: String = lastDakaInfo.getString("actual_area_begin")
|
||||
userConfig.device = area.substring(area.lastIndexOf("Qing") + 13)
|
||||
} else {
|
||||
userConfig.device = null
|
||||
}
|
||||
}
|
||||
if (userConfig.projectcode == null) {
|
||||
userConfig.projectcode = dakaInfo.getString("pro_id")
|
||||
}
|
||||
if (userConfig.projectname == null) {
|
||||
userConfig.projectname = dakaInfo.getString("pro_name")
|
||||
}
|
||||
if (userConfig.project_id == null) {
|
||||
userConfig.project_id = dakaInfo.getString("pro_id")
|
||||
}
|
||||
userConfigMap[employeeNo] = userConfig
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user