|
|
@@ -1,5 +1,6 @@
|
|
|
package org.dromara.server.consume.controller.v1;
|
|
|
|
|
|
+import cn.hutool.core.util.ObjectUtil;
|
|
|
import lombok.RequiredArgsConstructor;
|
|
|
import org.dromara.common.core.constant.ApiErrorTypeConstants;
|
|
|
import org.dromara.common.core.domain.R;
|
|
|
@@ -13,32 +14,38 @@ import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
@RestController
|
|
|
@RequiredArgsConstructor
|
|
|
-@RequestMapping(path = { "/v1/Auth" })
|
|
|
+@RequestMapping(path = {"/v1/Auth"})
|
|
|
public class AuthController {
|
|
|
|
|
|
- private final TermBusiness termBusiness;
|
|
|
-
|
|
|
- /**
|
|
|
- * 获取设备Token
|
|
|
- *
|
|
|
- * @param termId 设备的机号(兼容UP)
|
|
|
- * @return token
|
|
|
- */
|
|
|
- @GetMapping("/token/term/{termId}")
|
|
|
- public Object termToken(@PathVariable("termId") Long termId, @RequestHeader(name = "admin") String admin,
|
|
|
- @RequestHeader(name = "pwd") String pwd) {
|
|
|
-
|
|
|
- R<TermToken> mapResult = termBusiness.getTermToken(termId, admin, pwd);
|
|
|
-
|
|
|
- if (R.isError(mapResult)) {
|
|
|
- ErrorResult result = new ErrorResult();
|
|
|
- result.setStatusCode(HttpStatus.BAD_REQUEST.value());
|
|
|
- result.setMessage("获取Token失败");
|
|
|
- result.getErrors().add(new ErrorInfo(1, "获取设备Token失败", ApiErrorTypeConstants.BAD_REQUEST, mapResult.getMsg()));
|
|
|
-
|
|
|
- return new ResponseEntity<Object>(result, null, HttpStatus.BAD_REQUEST);
|
|
|
- }
|
|
|
-
|
|
|
- return mapResult.getData();
|
|
|
- }
|
|
|
+ private final TermBusiness termBusiness;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取设备Token
|
|
|
+ *
|
|
|
+ * @param termId 设备的机号(兼容UP)
|
|
|
+ * @return token
|
|
|
+ */
|
|
|
+ @GetMapping("/token/term/{termId}")
|
|
|
+ public Object termToken(@PathVariable("termId") Long termId, @RequestHeader(name = "admin", required = false) String admin,
|
|
|
+ @RequestHeader(name = "pwd", required = false) String pwd) {
|
|
|
+
|
|
|
+ if (ObjectUtil.isEmpty(admin)) {
|
|
|
+ admin = "administrator";
|
|
|
+ }
|
|
|
+ if (ObjectUtil.isEmpty(pwd)) {
|
|
|
+ pwd = "123456";
|
|
|
+ }
|
|
|
+ R<TermToken> mapResult = termBusiness.getTermToken(termId, admin, pwd);
|
|
|
+
|
|
|
+ if (R.isError(mapResult)) {
|
|
|
+ ErrorResult result = new ErrorResult();
|
|
|
+ result.setStatusCode(HttpStatus.BAD_REQUEST.value());
|
|
|
+ result.setMessage("获取Token失败");
|
|
|
+ result.getErrors().add(new ErrorInfo(1, "获取设备Token失败", ApiErrorTypeConstants.BAD_REQUEST, mapResult.getMsg()));
|
|
|
+
|
|
|
+ return new ResponseEntity<Object>(result, null, HttpStatus.BAD_REQUEST);
|
|
|
+ }
|
|
|
+
|
|
|
+ return mapResult.getData();
|
|
|
+ }
|
|
|
}
|