Commit 77d1e463 authored by 赵啸非's avatar 赵啸非

修改固定班次考勤

parent 56961e1e
......@@ -10,7 +10,7 @@ public class LoginForm extends BaseForm {
private String securityCode;
private String dingCode;
private String code;
public String getLoginName() {
......@@ -38,12 +38,12 @@ public class LoginForm extends BaseForm {
this.securityCode = securityCode;
}
public String getDingCode() {
return dingCode;
public String getCode() {
return code;
}
public void setDingCode(String dingCode) {
this.dingCode = dingCode;
public void setCode(String code) {
this.code = code;
}
@Override
......
......@@ -21,9 +21,12 @@ import com.mortals.xhx.base.system.menu.model.MenuEntity;
import com.mortals.xhx.base.system.menu.service.MenuService;
import com.mortals.xhx.base.system.resource.service.ResourceService;
import com.mortals.xhx.base.system.user.model.UserEntity;
import com.mortals.xhx.base.system.user.model.UserQuery;
import com.mortals.xhx.base.system.user.service.UserService;
import com.mortals.xhx.base.system.valid.service.ValidCodeService;
import com.mortals.xhx.common.code.YesNoEnum;
import com.mortals.xhx.common.key.RedisKey;
import com.mortals.xhx.module.dingding.personal.service.IDingPersonService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.ObjectUtils;
......@@ -38,8 +41,7 @@ import java.util.HashSet;
import java.util.List;
import java.util.Set;
import static com.mortals.xhx.common.key.ErrorCode.ERROR_TOKEN_EXPIRED;
import static com.mortals.xhx.common.key.ErrorCode.ERROR_TOKEN_EXPIRED_CONTENT;
import static com.mortals.xhx.common.key.ErrorCode.*;
@RestController
@Slf4j
......@@ -51,10 +53,69 @@ public class ApiLoginController extends BaseJsonBodyController {
@Autowired
private IAuthTokenService authTokenService;
@Autowired
private IDingPersonService dingPersonService;
@RequestMapping("login")
public String login(@RequestBody LoginForm loginForm) throws Exception {
JSONObject ret = new JSONObject();
JSONObject data = new JSONObject();
UserEntity userEntity = null;
try {
if (ObjectUtils.isEmpty(loginForm.getCode())) {
throw new AppException("钉钉code不能为空!");
}
//根据code 查询钉钉用户id
Rest<String> personRest = dingPersonService.getPersonByCode(loginForm.getCode());
if (personRest.getCode() != YesNoEnum.YES.getValue()) {
throw new AppException(DING_AUTH_FAIL,String.format("获取钉钉用户异常,%s", personRest.getMsg()));
}
log.info(personRest.getData());
if (!ObjectUtils.isEmpty(loginForm.getCode())) {
//更新绑定钉钉
userEntity.setDingUserId(loginForm.getCode());
userService.getUserDao().update(userEntity);
}
HashSet<Integer> set = new HashSet<>();
set.add(0);
set.add(2);
set.add(3);
if (ObjectUtils.isEmpty(userEntity.getUserType()) || !set.contains(userEntity.getUserType())) {
throw new AppException("当前用户不支持H5登录!");
}
data.put("id", userEntity.getId());
data.put("userType", userEntity.getUserType());
userEntity.setLoginTime(System.currentTimeMillis());
userEntity.setToken(IdUtil.fastSimpleUUID());
userEntity.setExpireTime(DateUtils.addCurrDate(7).getTime());
String token = authTokenService.createToken(userEntity);
data.put("token", token);
ret.put(KEY_RESULT_DATA, data);
ret.put(KEY_RESULT_CODE, VALUE_RESULT_SUCCESS);
ret.put(KEY_RESULT_MSG, "用户登录系统成功!");
recordSysLog(request, userEntity, "钉钉用户登录系统成功!");
return ret.toJSONString();
} catch (AppException e) {
log.error("dinding login error ", e);
ret.put(KEY_RESULT_CODE, e.getCode());
ret.put(KEY_RESULT_MSG, super.convertException(e));
return ret.toJSONString();
} catch (Exception e) {
log.error("系统异常 error ", e);
ret.put(KEY_RESULT_CODE, VALUE_RESULT_FAILURE);
ret.put(KEY_RESULT_MSG, super.convertException(e));
return ret.toJSONString();
}
/*
JSONObject ret = new JSONObject();
String loginName = loginForm.getLoginName();
String password = loginForm.getPassword();
......@@ -108,7 +169,7 @@ public class ApiLoginController extends BaseJsonBodyController {
ret.put(KEY_RESULT_CODE, VALUE_RESULT_FAILURE);
ret.put(KEY_RESULT_MSG, super.convertException(e));
return ret.toJSONString();
}
}*/
}
@RequestMapping("logout")
......
......@@ -115,6 +115,9 @@ public interface ErrorCode {
public static final int REGISTER_AUTH_FAIL = 1011;
public static final String REGISTER_AUTH_FAIL_CONTENT = "token认证失败!";
public static final int DING_AUTH_FAIL = 2013;
public static final String DING_AUTH_FAIL_CONTENT = "获取钉钉用户异常!";
public static final int ERROR_TOKEN_EXPIRED = 9001;
public static final String ERROR_TOKEN_EXPIRED_CONTENT = "用户登录过期,请重新登录!";
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment