Commit eb97f95a authored by wangsong's avatar wangsong

update api

parent cbd73dbe
package com.chineseall.eden.authcenter.agent.controller; package com.chineseall.eden.authcenter.agent.controller;
import cn.sh.chineseall.framework.api.MapMessage;
import cn.sh.chineseall.framework.core.util.StringUtils; import cn.sh.chineseall.framework.core.util.StringUtils;
import com.chineseall.eden.authcenter.agent.result.ResponseCode;
import com.chineseall.eden.authcenter.agent.result.ResultModel;
import com.chineseall.eden.authcenter.config.entity.AuthClient; import com.chineseall.eden.authcenter.config.entity.AuthClient;
import com.chineseall.eden.authcenter.config.entity.AuthSource; import com.chineseall.eden.authcenter.config.entity.AuthSource;
import com.chineseall.eden.authcenter.config.service.AuthClientService; import com.chineseall.eden.authcenter.config.service.AuthClientService;
...@@ -12,7 +11,6 @@ import org.springframework.stereotype.Controller; ...@@ -12,7 +11,6 @@ import org.springframework.stereotype.Controller;
import org.springframework.ui.Model; import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletRequest;
import java.util.List; import java.util.List;
@Controller @Controller
...@@ -46,33 +44,36 @@ public class AuthConfigController { ...@@ -46,33 +44,36 @@ public class AuthConfigController {
@PostMapping("authsource/save") @PostMapping("authsource/save")
@ResponseBody @ResponseBody
public ResultModel<Boolean> saveAuthSource(@RequestBody AuthSource data){ public MapMessage saveAuthSource(@RequestBody AuthSource data){
return ResultModel.success(authSourceService.saveAuthSource(data)); boolean result = authSourceService.saveAuthSource(data);
return result ? MapMessage.successMessage(): MapMessage.errorMessage();
} }
@GetMapping("authsource/detail") @GetMapping("authsource/detail")
@ResponseBody @ResponseBody
public ResultModel<AuthSource> authSourceDetail(@RequestParam("key") String key){ public MapMessage authSourceDetail(@RequestParam("key") String key){
if(StringUtils.isBlank(key)){ if(StringUtils.isBlank(key)){
return ResultModel.error(ResponseCode.ParamsNull); return MapMessage.errorMessage("参数不全");
} }
AuthSource data = authSourceService.getAuthSourceByKey(key); AuthSource data = authSourceService.getAuthSourceByKey(key);
if(data == null){ if(data == null){
return ResultModel.error(ResponseCode.RecordNotExist); return MapMessage.errorMessage("数据不存在");
} }
return ResultModel.success(data); return MapMessage.successMessage().add("data", data);
} }
@GetMapping("authsource/changestatus") @PostMapping("authsource/changestatus")
@ResponseBody @ResponseBody
public ResultModel<Boolean> changeAuthSourceStatus(@RequestParam("key") String key, @RequestParam("status") Integer status){ public MapMessage changeAuthSourceStatus(@RequestParam("key") String key, @RequestParam("status") Integer status){
if(StringUtils.isBlank(key) || status == null){ if(StringUtils.isBlank(key) || status == null){
return ResultModel.error(ResponseCode.ParamsNull); return MapMessage.errorMessage("参数不全");
} }
return ResultModel.success(authSourceService.changeStatus(key, status)); MapMessage message = new MapMessage();
message.setSuccess(authSourceService.changeStatus(key, status));
return message;
} }
...@@ -93,33 +94,37 @@ public class AuthConfigController { ...@@ -93,33 +94,37 @@ public class AuthConfigController {
@PostMapping("authclient/save") @PostMapping("authclient/save")
@ResponseBody @ResponseBody
public ResultModel<Boolean> saveAuthClient(@RequestBody AuthClient data){ public MapMessage saveAuthClient(@RequestBody AuthClient data){
return ResultModel.success(authClientService.saveAuthClient(data)); MapMessage message = new MapMessage();
message.setSuccess(authClientService.saveAuthClient(data));
return message;
} }
@GetMapping("authclient/detail") @GetMapping("authclient/detail")
@ResponseBody @ResponseBody
public ResultModel<AuthClient> authClientDetail(@RequestParam("key") String key){ public MapMessage authClientDetail(@RequestParam("key") String key){
if(StringUtils.isBlank(key)){ if(StringUtils.isBlank(key)){
return ResultModel.error(ResponseCode.ParamsNull); return MapMessage.errorMessage("参数不全");
} }
AuthClient data = authClientService.getAuthClientByKey(key); AuthClient data = authClientService.getAuthClientByKey(key);
if(data == null){ if(data == null){
return ResultModel.error(ResponseCode.RecordNotExist); return MapMessage.errorMessage("数据不存在");
} }
return ResultModel.success(data); return MapMessage.successMessage().add("data", data);
} }
@GetMapping("authclient/changestatus") @PostMapping("authclient/changestatus")
@ResponseBody @ResponseBody
public ResultModel<Boolean> changeAuthClientStatus(@RequestParam("key") String key, @RequestParam("status") Integer status){ public MapMessage changeAuthClientStatus(@RequestParam("key") String key, @RequestParam("status") Integer status){
if(StringUtils.isBlank(key) || status == null){ if(StringUtils.isBlank(key) || status == null){
return ResultModel.error(ResponseCode.ParamsNull); return MapMessage.errorMessage("参数不全");
} }
return ResultModel.success(authClientService.changeStatus(key, status)); MapMessage message = new MapMessage();
message.setSuccess(authClientService.changeStatus(key, status));
return message;
} }
......
...@@ -25,7 +25,7 @@ public class LoginController { ...@@ -25,7 +25,7 @@ public class LoginController {
@GetMapping("index") @GetMapping("index")
public String index(){ public String index(){
return "login_page"; return "/login/index";
} }
......
package com.chineseall.eden.authcenter.agent.result;
import lombok.AllArgsConstructor;
import lombok.Getter;
import java.util.Arrays;
/**
* 状态码
*
*/
@AllArgsConstructor
@Getter
public enum ResponseCode {
/**
* 所有失败的操作均指定为999,未知错误
*/
Error(999, "失败"),
/**
* 令牌不合法
*/
TokenUnValidate(998, "令牌不合法"),
/**
* 签名不合法
*/
SignUnValidate(997, "签名不合法"),
/**
* 签名丢失
*/
SignHeaderMiss(996, "必须传递签名"),
/**
* 用户类型缺失
*/
UserTypeMiss(990, "必须传递用户类型"),
AppIdMiss(993,"缺少APPID"),
/**
* 签名时间不正确
*/
SignTimeOver(995, "签名时间不正确"),
/**
* 用户名或者密码不正确
*/
ErrorUserNameOrPassword(994, "用户名或者密码不正确"),
UserNameInvalid(9941, "用户名无效"),
PasswordIncorrect(9942, "密码不正确"),
AccountDisabled(9943, "账户已冻结"),
NoLogin(9945, "请登录后在操作"),
/**
* 签名时间错误
*/
DeviceLocalTimeError(991,"签名时间错误"),
/**
* 成功
*/
Success(1, "成功"),
/**
* 数据库操作失败
*/
DBError(1015, "数据库操作错误"),
/**
* 参数不全
*/
ParamsNull(1002, "参数不全"),
/**
* 不支持的HTTP方法
*/
MethodNotSupport(1001, "不支持的HTTP方法"),
NoHandlerFoundException(1003, "请求的方法不存在"),
/**
* 请求数据错误
*/
DataInvalid(1500,"请求数据无效"),
/**
* 验证码无效
*/
VerifyCodeError(2001,"验证码错误"),
RecordNotExist(2002,"数据不存在"),
RecordAlreadyExist(2000,"数据已存在"),
RecordAlreadyProcess(2003,"数据已处理"),
HasNoRight(2004, "您无权进行操作"),
/**
* 未进行初始化
*/
NotInitialized(3001,"未进行初始化"),
/**
* 不支持
*/
UnSupport(99999,"不支持"),
;
public final Integer code;
public final String desc;
public static ResponseCode of(Integer code) {
return Arrays.stream(values()).filter(i -> i.code.equals(code)).findFirst().orElse(Error);
}
}
package com.chineseall.eden.authcenter.agent.result;
import cn.sh.chineseall.framework.core.repackaged.org.apache.commons.lang3.StringUtils;
import lombok.Data;
import java.util.Objects;
/**
* 返回数据模型定义
* @param <T>
*/
@Data
public class ResultModel<T> {
private Integer code;
private String msg;
private T data;
public ResultModel(){
}
public boolean isSuccess(){
return Objects.equals(getCode(),ResponseCode.Success.getCode());
}
public ResultModel(ResponseCode responseCode){
this.setCode(responseCode.code);
this.setMsg(responseCode.desc);
}
public ResultModel(ResponseCode responseCode, String msg){
this.setCode(responseCode.code);
this.setMsg(StringUtils.isNotBlank(msg)? msg : responseCode.desc);
}
public ResultModel(Integer code, String msg){
this.setCode(code);
this.setMsg(msg);
}
public static <T> ResultModel<T> success(){
return success(null);
}
public static <T> ResultModel<T> ok(){
return success();
}
public static <T> ResultModel<T> ok(T data){
return success(data);
}
public static <T> ResultModel<T> success(T data){
ResultModel<T> model = new ResultModel<T>();
model.setCode(1);
model.setMsg("成功");
model.setData(data);
return model;
}
public static <T> ResultModel<T> error(){
return error(ResponseCode.Error);
}
public static <T> ResultModel<T> error(ResponseCode responseCode){
return new ResultModel<>(responseCode);
}
public static <T> ResultModel<T> error(String msg){
return new ResultModel<>(ResponseCode.Error,msg);
}
public static <T> ResultModel<T> error(ResponseCode responseCode, String msg){
return new ResultModel<>(responseCode,msg);
}
public static <T> ResultModel<T> error(Integer code, String msg){
return new ResultModel<>(code,msg);
}
}
\ No newline at end of file
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