@ -1,8 +1,14 @@
package com.yipin.liuwanr.service ;
import java.text.SimpleDateFormat ;
import java.util.ArrayList ;
import java.util.Date ;
import java.util.HashMap ;
import java.util.List ;
import com.yipin.liuwanr.entity.* ;
import com.yipin.liuwanr.mapper.StaffMapper ;
import com.yipin.liuwanr.mapper.StudentMapper ;
import org.jboss.logging.Logger ;
import org.springframework.beans.factory.BeanFactory ;
import org.springframework.beans.factory.annotation.Autowired ;
@ -13,11 +19,6 @@ import com.aliyun.oss.OSSClient;
import com.github.pagehelper.PageHelper ;
import com.github.pagehelper.PageInfo ;
import com.yipin.liuwanr.AliyunOssConfig ;
import com.yipin.liuwanr.entity.Demo ;
import com.yipin.liuwanr.entity.FilesResult ;
import com.yipin.liuwanr.entity.PageResult ;
import com.yipin.liuwanr.entity.User ;
import com.yipin.liuwanr.entity.UserM ;
import com.yipin.liuwanr.helper.OssConfigUtil ;
import com.yipin.liuwanr.helper.RandomUtil ;
import com.yipin.liuwanr.mapper.UserMapper ;
@ -32,6 +33,10 @@ public class UserService {
@Autowired
private UserMapper userMapper ;
@Autowired
private StaffMapper staffMapper ;
@Autowired
private StudentMapper studentMapper ;
@Autowired
private JedisCluster jedis ;
@ -195,21 +200,72 @@ public class UserService {
return resp ;
}
public HashMap < String , Object > logins ( UserM user ) {
// public HashMap<String, Object> logins(UserM user){
////
//// HashMap<String, Object> resp = new HashMap<String, Object>();
//// try {
//// resp.put("retvalue", userMapper.logins(user));
//// if (resp.get("retvalue")==null) {
//// resp.put("retcode", 300);
//// resp.put("retvalue", "登录失败,账号密码有误或不存在!");
//// }else {
//// resp.put("retcode", 200);
//// }
//// } catch (RuntimeException e) {
//// logger.error(e.getMessage());
//// resp.put("retcode", 500);
//// resp.put("retvalue", "登录异常,请稍后再试!");
//// return resp;
//// }
//// return resp;
//// }
public HashMap < String , Object > logins ( UserM userM ) {
HashMap < String , Object > resp = new HashMap < String , Object > ( ) ;
List < Object > obj = new ArrayList < > ( ) ;
String param = userM . getPhone ( ) ;
String password = userM . getPassword ( ) ;
Student student ;
Staff staff ;
try {
resp . put ( "retvalue" , userMapper . logins ( user ) ) ;
if ( resp . get ( "retvalue" ) = = null ) {
resp . put ( "retcode" , 300 ) ;
resp . put ( "retvalue" , "登录失败,账号密码有误或不存在!" ) ;
} else {
UserM user = userMapper . loginsQ ( param , password ) ;
if ( user ! = null ) {
int loginNumber = user . getLogInNumber ( ) + 1 ;
Integer userId = user . getUserId ( ) ;
long time = System . currentTimeMillis ( ) ;
Date date = new Date ( time ) ;
SimpleDateFormat sd = new SimpleDateFormat ( "yyyy-MM-dd HH:mm:ss" ) ;
String lastTime = sd . format ( date ) ;
if ( user . getAccountRole ( ) . equals ( 4 ) ) {
student = studentMapper . queryStudentQ ( user ) ;
if ( student ! = null ) {
Integer studentId = student . getStudentId ( ) ;
studentMapper . updateStudentQ ( lastTime , loginNumber , studentId ) ;
obj . add ( student ) ;
}
} else if ( user . getAccountRole ( ) . equals ( 3 ) ) {
staff = staffMapper . queryStaffQ ( user ) ;
if ( staff ! = null ) {
Integer staffId = staff . getStaffId ( ) ;
staffMapper . updateStaffQ ( lastTime , loginNumber , staffId ) ;
obj . add ( staff ) ;
}
}
user . setPassword ( null ) ;
obj . add ( user ) ;
userMapper . updateUserQ ( lastTime , loginNumber , userId ) ;
resp . put ( "retcode" , 200 ) ;
resp . put ( "retvalue" , obj ) ;
} else {
resp . put ( "retcode" , 300 ) ;
resp . put ( "retvalue" , "Login failed" ) ;
}
} catch ( RuntimeException e ) {
logger . error ( e . getMessage ( ) ) ;
resp . put ( "retcode" , 500 ) ;
resp . put ( "retvalue" , "登录异常,请稍后再试!" ) ;
resp . put ( "retvalue" , "Inquiry Failed " ) ;
return resp ;
}
return resp ;