|
@@ -39,7 +39,13 @@ import com.persagy.server.http.HttpUntil
|
|
|
import com.persagy.server.util.QrCodeUntils
|
|
|
import com.persagy.service.SObjectService
|
|
|
import com.persagy.service.SPageContext
|
|
|
+import com.persagy.service.models.enums.SResponseType
|
|
|
+import com.persagy.service.models.requests.SCreateRequest
|
|
|
+import com.persagy.service.models.requests.SUpdateRequest
|
|
|
+import com.persagy.service.models.responses.SBaseResponse
|
|
|
+import com.persagy.service.models.responses.SCreateResponse
|
|
|
import org.slf4j.LoggerFactory
|
|
|
+import org.springframework.web.bind.annotation.RequestBody
|
|
|
import java.net.URL
|
|
|
|
|
|
/**
|
|
@@ -60,12 +66,58 @@ object UserService : SObjectService<User>(SMybatisDao(User::class.java)) {
|
|
|
override fun onCreateBefore(entity: User): Boolean {
|
|
|
val projectId = SPageContext.getHeader("projectId")
|
|
|
entity.projectId = projectId
|
|
|
- if (entity.userId.isNullOrEmpty()){
|
|
|
- entity.userId = QrCodeUntils.uuidCreate()
|
|
|
- }
|
|
|
+ entity.userId = QrCodeUntils.uuidCreate()
|
|
|
return super.onCreateBefore(entity)
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 创建
|
|
|
+ */
|
|
|
+ fun create(request: SCreateRequest<User>): SCreateResponse<User> {
|
|
|
+ val projectId = SPageContext.getHeader("projectId")
|
|
|
+ val coming = SPageContext.getHeader("coming")
|
|
|
+ val sCreateResponse = SCreateResponse<User>(SResponseType.success)
|
|
|
+ if (!request.content.isNullOrEmpty()) {
|
|
|
+ for (content in request.content) {
|
|
|
+ val entity = select(SFilter.eq("projectId", projectId!!), SFilter.eq("phone", content.phone!!)).entity()
|
|
|
+ if (entity!=null) {
|
|
|
+ sCreateResponse.result = SResponseType.failure
|
|
|
+ sCreateResponse.message = "手机号已存在!"
|
|
|
+ return sCreateResponse
|
|
|
+ }else {
|
|
|
+ content.projectId = projectId
|
|
|
+ content.userId = QrCodeUntils.uuidCreate()
|
|
|
+ val insert = insert(content)
|
|
|
+ if(insert){
|
|
|
+ try {
|
|
|
+ val userLog = UserLog()
|
|
|
+ userLog.comming = coming!!
|
|
|
+ userLog.action = "创建用户"
|
|
|
+ userLog.id = QrCodeUntils.uuidCreate()
|
|
|
+ userLog.note = QrCodeUntils.toLog(content,coming)
|
|
|
+ userLog.phone = content.phone
|
|
|
+ userLog.projectId = projectId
|
|
|
+ userLog.userId = content.userId
|
|
|
+ userLog.userName = content.userName
|
|
|
+ userLogService.insert(userLog)
|
|
|
+ } catch (e: Exception) {
|
|
|
+ e.printStackTrace()
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ sCreateResponse.entityList = request.content
|
|
|
+ } else {
|
|
|
+ sCreateResponse.result = SResponseType.failure
|
|
|
+ sCreateResponse.message = "用户信息不可以为空"
|
|
|
+ }
|
|
|
+ return sCreateResponse
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
override fun onCreateSuccess(entityList: ArrayList<User>) {
|
|
|
super.onCreateSuccess(entityList)
|
|
|
try {
|
|
@@ -109,6 +161,45 @@ object UserService : SObjectService<User>(SMybatisDao(User::class.java)) {
|
|
|
return super.onDeleteBefore(entity)
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 修改
|
|
|
+ */
|
|
|
+ fun update(@RequestBody request: SUpdateRequest<User>): SBaseResponse {
|
|
|
+ val sBaseResponse = SBaseResponse(SResponseType.success)
|
|
|
+ val projectId = SPageContext.getHeader("projectId")
|
|
|
+ val coming = SPageContext.getHeader("coming")
|
|
|
+ if (!request.content.isNullOrEmpty()) {
|
|
|
+ for (content in request.content!!) {
|
|
|
+ val entity = select(SFilter.eq("projectId", projectId!!), SFilter.eq("phone", content.phone!!)).entity()
|
|
|
+ if (entity!=null) {
|
|
|
+ sBaseResponse.message = "手机号已存在!"
|
|
|
+ sBaseResponse.result =SResponseType.failure
|
|
|
+ return sBaseResponse
|
|
|
+ }else {
|
|
|
+ val update = update(content)
|
|
|
+ if (update) {
|
|
|
+ try {
|
|
|
+ val userLog = UserLog()
|
|
|
+ userLog.comming = coming
|
|
|
+ userLog.action = "更新用户信息"
|
|
|
+ userLog.id = QrCodeUntils.uuidCreate()
|
|
|
+ userLog.note = QrCodeUntils.toLog(content,coming)
|
|
|
+ userLog.phone = content.phone
|
|
|
+ userLog.projectId = projectId
|
|
|
+ userLog.userId = content.userId
|
|
|
+ userLog.userName = content.userName
|
|
|
+ userLogService.insert(userLog)
|
|
|
+ } catch (e: Exception) {
|
|
|
+ e.printStackTrace()
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return sBaseResponse
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
override fun onUpdateBefore(entity: User): Boolean {
|
|
|
try {
|
|
|
val projectId = SPageContext.getHeader("projectId")
|
|
@@ -143,7 +234,7 @@ object UserService : SObjectService<User>(SMybatisDao(User::class.java)) {
|
|
|
val result = HttpUntil.postJson(URL(Opts.smsVerifyCode), json, BaseResponse::class.java)
|
|
|
logger.debug("result=${result.result}")
|
|
|
if (result.result != BaseResponse.ResultCode.success) {
|
|
|
- return UserLoginResponse(null, BaseResponse.ResultCode.failure, "手机号或验证码不正确!")
|
|
|
+ return UserLoginResponse(null,null, BaseResponse.ResultCode.failure, "手机号或验证码不正确!")
|
|
|
}
|
|
|
}
|
|
|
logger.debug("phone====$phone")
|
|
@@ -179,7 +270,7 @@ object UserService : SObjectService<User>(SMybatisDao(User::class.java)) {
|
|
|
val select = buildService.select(SFilter.eq("projectId", project.id!!)).exec()
|
|
|
project.buildList = select
|
|
|
}
|
|
|
- return UserLoginResponse(projectList)
|
|
|
+ return UserLoginResponse(projectList,userList[0])
|
|
|
}
|
|
|
|
|
|
// val projectList = projectDao.queryByPhone(phone)
|
|
@@ -187,11 +278,11 @@ object UserService : SObjectService<User>(SMybatisDao(User::class.java)) {
|
|
|
// project.buildList = buildingService.query(project.projId!!)
|
|
|
// }
|
|
|
val projectList = ArrayList<Project>()
|
|
|
- return UserLoginResponse(projectList)
|
|
|
+ return UserLoginResponse(projectList,userList[0])
|
|
|
} catch (e: Exception) {
|
|
|
e.printStackTrace()
|
|
|
}
|
|
|
- return UserLoginResponse(null, BaseResponse.ResultCode.failure, "登录失败!")
|
|
|
+ return UserLoginResponse(null,null, BaseResponse.ResultCode.failure, "登录失败!")
|
|
|
} // Function login()
|
|
|
|
|
|
/**
|