提交 3a95ef27 authored 作者: inroi's avatar inroi

微调

上级 4efd7800
......@@ -97,14 +97,6 @@
<!-- Sdk -->
<dependency>
<groupId>loginapi</groupId>
<artifactId>kingdee_Ltpa</artifactId>
<scope>system</scope>
<version>1.0</version>
<systemPath>${project.basedir}/src/main/resources/lib/kingdee_Ltpa.jar</systemPath>
</dependency>
<dependency>
<groupId>webapi</groupId>
<artifactId>shr_sso_client</artifactId>
<scope>system</scope>
......
......@@ -2,6 +2,7 @@ package com.shr.api;
import com.kingdee.shr.api.Response;
import com.kingdee.shr.api.SHRClient;
import com.shr.exception.ShrException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
......@@ -20,18 +21,18 @@ public class CallShrOsfApi {
private String serverUrl;
public CallShrOsfApi() {
serverUrl = "http://172.19.112.139:6888/shr";
serverUrl = "http://192.168.2.219:6888/shr";
}
public Response callShrOsf(String serviceName, Map<String, Object> param) {
SHRClient shrClient = new SHRClient();
try {
Response response = shrClient.executeService(serverUrl, serviceName, param);
log.info("S-HR的返回结果:" + response);
log.info("SHR返回结果: " + response);
return response;
} catch (IOException e) {
e.printStackTrace();
return new Response();
throw new ShrException(e.getMessage());
}
}
......
......@@ -20,33 +20,38 @@ public class ErrorResponseData {
*/
private String timestamp;
/**
* 响应状态码
*/
private Integer status;
private Integer code;
/**
* 响应信息
*/
private String message;
/**
* 异常的具体类名称
*/
private String error;
/**
* 路径
*/
private String path;
public ErrorResponseData(Integer status, String message, String error, String path) {
public ErrorResponseData(Integer code, String message, String error, String path) {
this.timestamp = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date());
this.status = status;
this.code = code;
this.message = message;
this.error = error;
this.path = path;
}
}
......@@ -12,11 +12,11 @@ public class RestResponse {
public static final int CODE_FORBIDDEN = 406;
public static final int CODE_SERVER_ERROR = 500;
private int code;
private String msg;
private Object data = null;
public static RestResponse success() {
RestResponse restResponse = new RestResponse();
restResponse.setCode(200);
......
......@@ -20,7 +20,7 @@ public class AdminOrgController {
private IAdminOrgService adminOrgService;
@GetMapping("/admin/org/list")
@PostMapping("/admin/org/list")
public RestResponse adminOrgList(@RequestBody(required = true) @Validated AdminOrgListInVo inVo) {
AdminOrgListOutVo outVo = adminOrgService.adminOrgList(inVo);
return RestResponse.success(outVo);
......
package com.shr.controller;
import com.kingdee.eas.cp.eip.sso.ltpa.LtpaTokenManager;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.CrossOrigin;
import com.kingdee.shr.sso.client.ltpa.LtpaTokenManager;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
......@@ -11,36 +9,29 @@ import javax.servlet.http.HttpServletResponse;
import java.io.File;
import java.io.IOException;
@CrossOrigin
/**
* @author Lnori
*/
@RestController
@RequestMapping("/eas")
@Slf4j
@RequestMapping("/api")
public class EasController {
@GetMapping(value = "/ssoLogin")
@GetMapping(value = "/eas/ssoLogin")
public void ssoLogin(HttpServletResponse response) throws IOException {
response.sendRedirect(login_easportal());
response.sendRedirect(loginEasportal());
}
public static String login_easportal() {
public static String loginEasportal() {
//从EAS服务器上下载 server\profiles\server(1...n)\config\portalConfig\LtpaToken.properties
File file2 = new File("src/main/resources/LtpaToken.properties");
// File file2 = new File("D:\\LtpaToken.properties");
String configPath = String.valueOf(file2.getAbsolutePath());
String configPath = file2.getAbsolutePath();
//用户
String username = "administrator";
// String username = "assassin";
//要跳转的url
String redirectTo = "//"; //"//"表示首页
// String redirectTo ="http://192.168.2.219:6888/portal/main.jsp";
//String redirectTo = "http://192.168.0.12:8080/portal/index.jsp";
//要跳转的url '//'代表首页
String redirectTo = "//";
//调用LtpaTokenManager,根据密钥生成用户令牌
String username = "administrator";
String password = LtpaTokenManager.generate(username, configPath).toString();
System.out.println("password1=" + password);
//http://localhost:6888/easportal/%2Findex_sso.jsp#tab0
//http://localhost:6888/eassso/login?service=http%3A%2F%2Flocalhost%3A6888%2Fportal%2F
System.out.println("password: " + password);
//生成EAS单点登录地址
String url = "http://192.168.2.219:6888/portal/index2sso.jsp?username=" + username + "&password=" + password + "&redirectTo=" + redirectTo + "&isNotCheckRelogin=true";
......@@ -50,4 +41,6 @@ public class EasController {
System.out.println(url);
return url;
}
}
package com.shr.controller;
import com.shr.common.response.RestResponse;
import com.shr.serivce.IUnProcessAssign;
import com.shr.transfer.unprocessassign.UnProcessAssignDetailedInVo;
import com.shr.transfer.unprocessassign.UnProcessAssignDetailedOutVo;
import com.shr.transfer.unprocessassign.UnProcessAssignListInVo;
import com.shr.transfer.unprocessassign.UnProcessAssignListOutVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
/**
* @author Inori
*/
@RestController
@RequestMapping("/api")
public class UnProcessAssignController {
@Autowired
private IUnProcessAssign unProcessAssign;
@PostMapping("/un/process/assign/list")
public RestResponse unProcessAssignList(@RequestBody(required = true) @Validated UnProcessAssignListInVo inVo) {
UnProcessAssignListOutVo outVo = unProcessAssign.unProcessAssignList(inVo);
return RestResponse.success(outVo);
}
@PostMapping("/un/process/assign/detailed")
public RestResponse unProcessAssignDetailed(@RequestBody(required = true) @Validated UnProcessAssignDetailedInVo inVo) {
UnProcessAssignDetailedOutVo outVo = unProcessAssign.unProcessAssignDetailed(inVo);
return RestResponse.success(outVo);
}
}
package com.shr.exception;
import lombok.Getter;
/**
* @author Lnori
*/
@Getter
public class ShrException extends RuntimeException {
/**
* 状态码
*/
private Integer code;
public ShrException(String message) {
super(message);
}
public ShrException(Integer code, String message) {
super(message);
this.code = code;
}
}
package com.shr.handler;
import com.shr.common.HttpContext;
import com.shr.common.response.ErrorResponseData;
import com.shr.common.response.RestResponse;
import com.shr.exception.ShrException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.core.annotation.Order;
......@@ -16,9 +16,9 @@ import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.ResponseStatus;
import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
/**
* 全局的的异常拦截器
......@@ -31,12 +31,11 @@ public class BlogExceptionHandler {
private static final Logger log = LoggerFactory.getLogger(BlogExceptionHandler.class);
/**
* 参数校验异常
*/
@ResponseStatus(HttpStatus.OK)
@ExceptionHandler(MethodArgumentNotValidException.class)
@ResponseStatus(HttpStatus.OK)
@ResponseBody
public RestResponse handlerMethodArgumentNotValidException(MethodArgumentNotValidException e) {
BindingResult bindingResult = e.getBindingResult();
......@@ -51,15 +50,30 @@ public class BlogExceptionHandler {
return RestResponse.fail(errorMsg);
}
/**
* 拦截未知的运行时异常
*/
@ExceptionHandler(RuntimeException.class)
@ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
@ResponseBody
public ErrorResponseData notFount(RuntimeException e) {
log.error("运行时异常:", e);
return new ErrorResponseData(500, e.getMessage(), "Internal Server Error", Objects.requireNonNull(HttpContext.getRequest()).getRequestURI());
public ErrorResponseData notFount(HttpServletRequest request, RuntimeException e) {
log.error("---------------->运行时异常: {}", e.getMessage());
return new ErrorResponseData(HttpStatus.INTERNAL_SERVER_ERROR.value(), e.getMessage(), HttpStatus.INTERNAL_SERVER_ERROR.getReasonPhrase(), request.getRequestURI());
}
/**
* 拦截SHR返回异常
*/
@ExceptionHandler(ShrException.class)
@ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
@ResponseBody
public RestResponse blogExceptionHandler(HttpServletRequest request, ShrException e) {
log.error("---------------->Request URL : {}, ErrorMassage : {}", request.getRequestURL(), e.getMessage());
return RestResponse.error(e.getMessage());
}
......
package com.shr.serivce;
import com.shr.transfer.unprocessassign.UnProcessAssignDetailedInVo;
import com.shr.transfer.unprocessassign.UnProcessAssignDetailedOutVo;
import com.shr.transfer.unprocessassign.UnProcessAssignListInVo;
import com.shr.transfer.unprocessassign.UnProcessAssignListOutVo;
/**
* @author Inori
*/
public interface IUnProcessAssign {
/**
* 代表消息列表
* @param inVo 条件
* @return 列表
*/
UnProcessAssignListOutVo unProcessAssignList(UnProcessAssignListInVo inVo);
/**
* 代表消息列表
* @param inVo 条件
* @return 列表
*/
UnProcessAssignDetailedOutVo unProcessAssignDetailed(UnProcessAssignDetailedInVo inVo);
}
package com.shr.serivce.impl;
import com.kingdee.shr.api.Response;
import com.shr.api.CallShrOsfApi;
import com.shr.serivce.IUnProcessAssign;
import com.shr.transfer.unprocessassign.UnProcessAssignDetailedInVo;
import com.shr.transfer.unprocessassign.UnProcessAssignDetailedOutVo;
import com.shr.transfer.unprocessassign.UnProcessAssignListInVo;
import com.shr.transfer.unprocessassign.UnProcessAssignListOutVo;
import com.shr.utils.JsonUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
/**
* @author Inori
*/
@Service
public class UnProcessAssignImpl implements IUnProcessAssign {
@Autowired
private CallShrOsfApi callShrOsfApi;
@Override
public UnProcessAssignListOutVo unProcessAssignList(UnProcessAssignListInVo inVo) {
Response response = callShrOsfApi.callShrOsf("getUnProcessAssignCount", null);
UnProcessAssignListOutVo outVo = new UnProcessAssignListOutVo();
outVo.setRecords(JsonUtil.toList(JsonUtil.toString(response.getData()), Object.class));
return outVo;
}
@Override
public UnProcessAssignDetailedOutVo unProcessAssignDetailed(UnProcessAssignDetailedInVo inVo) {
Response response = callShrOsfApi.callShrOsf("getUnProcessAssignCount", null);
UnProcessAssignDetailedOutVo outVo = new UnProcessAssignDetailedOutVo();
outVo.setRecords(JsonUtil.toList(JsonUtil.toString(response.getData()), Object.class));
return outVo;
}
}
package com.shr.transfer.unprocessassign;
import lombok.Data;
import javax.validation.constraints.NotBlank;
/**
* @author Inori
*/
@Data
public class UnProcessAssignDetailedInVo {
/**
* 系统类型
*/
@NotBlank(message = "参数systemType缺失")
private String systemType;
}
package com.shr.transfer.unprocessassign;
import lombok.Data;
import javax.validation.constraints.NotNull;
import java.util.List;
/**
* @author Inori
*/
@Data
public class UnProcessAssignDetailedOutVo {
/**
* 记录
*/
@NotNull(message = "参数records缺失")
private List<Object> records;
}
package com.shr.transfer.unprocessassign;
import lombok.Data;
import javax.validation.constraints.NotBlank;
/**
* @author Inori
*/
@Data
public class UnProcessAssignListInVo {
/**
* 系统类型
*/
@NotBlank(message = "参数systemType缺失")
private String systemType;
}
package com.shr.transfer.unprocessassign;
import lombok.Data;
import javax.validation.constraints.NotNull;
import java.util.List;
/**
* @author Inori
*/
@Data
public class UnProcessAssignListOutVo {
/**
* 记录
*/
@NotNull(message = "参数records缺失")
private List<Object> records;
}
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论