异常处理

dev
youhong.ai 2023-07-14 20:41:18 +08:00
parent 31c1ca0202
commit b23aadb572
3 changed files with 217 additions and 229 deletions

View File

@ -16,7 +16,6 @@ import weaver.hrm.User;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import java.io.UnsupportedEncodingException;
import java.net.URI; import java.net.URI;
import java.net.URISyntaxException; import java.net.URISyntaxException;
import java.util.Date; import java.util.Date;
@ -166,7 +165,7 @@ public class SignFtService {
try { try {
try { try {
tokenUtils.setAlgorithm(Algorithm.HMAC256(secretMap.get("clientSecret"))); tokenUtils.setAlgorithm(Algorithm.HMAC256(secretMap.get("clientSecret")));
} catch (UnsupportedEncodingException e) { } catch (Exception e) {
throw new RuntimeException(e); throw new RuntimeException(e);
} }
tokenUtils.setExpiresAt(new Date()); tokenUtils.setExpiresAt(new Date());

View File

@ -12,7 +12,6 @@ import lombok.Getter;
import lombok.NoArgsConstructor; import lombok.NoArgsConstructor;
import lombok.Setter; import lombok.Setter;
import java.io.UnsupportedEncodingException;
import java.util.Date; import java.util.Date;
import java.util.Map; import java.util.Map;
@ -68,7 +67,7 @@ public class TokenUtils {
this.secret = secret; this.secret = secret;
try { try {
this.algorithm = Algorithm.HMAC256(secret); this.algorithm = Algorithm.HMAC256(secret);
} catch (UnsupportedEncodingException e) { } catch (Exception e) {
throw new RuntimeException(e); throw new RuntimeException(e);
} }
this.claims = claims; this.claims = claims;

View File

@ -22,7 +22,6 @@ import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType; import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response; import javax.ws.rs.core.Response;
import javax.ws.rs.core.StreamingOutput; import javax.ws.rs.core.StreamingOutput;
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder; import java.net.URLDecoder;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
import java.util.Base64; import java.util.Base64;
@ -35,228 +34,219 @@ import java.util.Map;
*/ */
@Path("/fadada") @Path("/fadada")
public class FaDDController { public class FaDDController {
private final FaDDServiceImpl faDDService = new FaDDServiceImpl(); private final FaDDServiceImpl faDDService = new FaDDServiceImpl();
private final FaDDServiceMapping faDDServiceMapping = new FaDDServiceMapping(); private final FaDDServiceMapping faDDServiceMapping = new FaDDServiceMapping();
private final ToolUtil toolUtil = new ToolUtil(); private final ToolUtil toolUtil = new ToolUtil();
/** /**
* *
* *
* @param workflowId * @param workflowId id
* id * @return
* @return */
*/ @GET
@GET @Path("/getConfig/{workflowId}")
@Path("/getConfig/{workflowId}") public String getConfig(@PathParam("workflowId") String workflowId) {
public String getConfig(@PathParam("workflowId") String workflowId) { try {
try { Map<String, Object> configParam = faDDService.getConfigParam(workflowId);
Map<String, Object> configParam = faDDService.getConfigParam(workflowId); return ApiResult.success(configParam);
return ApiResult.success(configParam); } catch (Exception e) {
} catch (Exception e) { return ApiResult.error(e.toString());
return ApiResult.error(e.toString()); }
} }
}
/**
/** *
* *
* * @param params
* @param params * @return
* */
* @return @Path("/signature")
*/ @POST
@Path("/signature") @Consumes(MediaType.APPLICATION_JSON)
@POST @Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON) public String checkCertification(@RequestBody Map<String, Object> params) {
@Produces(MediaType.APPLICATION_JSON) try {
public String checkCertification(@RequestBody Map<String, Object> params) { Map<String, Object> certificationResult = faDDService.checkCertification(params);
try { return ApiResult.success(certificationResult);
Map<String, Object> certificationResult = faDDService.checkCertification(params); } catch (Exception e) {
return ApiResult.success(certificationResult); return ApiResult.error(e.toString());
} catch (Exception e) { }
return ApiResult.error(e.toString()); }
}
} /**
*
/** *
* * @param workflowId id
* * @param requestId id
* @param workflowId * @return
* id */
* @param requestId @Path("/signedContract/{languageGroupId}/{requestId}/{workflowId}")
* id @GET
* @return @Consumes(MediaType.APPLICATION_JSON)
*/ @Produces(MediaType.APPLICATION_JSON)
@Path("/signedContract/{languageGroupId}/{requestId}/{workflowId}") public String signedContract(@Context HttpServletRequest request, @Context HttpServletResponse response,
@GET @PathParam("workflowId") String workflowId, @PathParam("requestId") String requestId,
@Consumes(MediaType.APPLICATION_JSON) @PathParam("languageGroupId") int languageGroupId) {
@Produces(MediaType.APPLICATION_JSON) User user = HrmUserVarify.getUser(request, response);
public String signedContract(@Context HttpServletRequest request, @Context HttpServletResponse response, try {
@PathParam("workflowId") String workflowId, @PathParam("requestId") String requestId, faDDService.queryContractStatus(workflowId, requestId, 0);
@PathParam("languageGroupId") int languageGroupId) { Map<String, String> language = Util.queryLanguage(languageGroupId, user.getLanguage());
User user = HrmUserVarify.getUser(request, response); String info = language.get("rushInfo");
try { return ApiResult.success(info);
faDDService.queryContractStatus(workflowId, requestId, 0); } catch (Exception e) {
Map<String, String> language = Util.queryLanguage(languageGroupId, user.getLanguage()); toolUtil.writeErrorLog("错误:" + e);
String info = language.get("rushInfo"); return ApiResult.error(e.toString());
return ApiResult.success(info); }
} catch (Exception e) { }
toolUtil.writeErrorLog("错误:" + e);
return ApiResult.error(e.toString()); /**
} *
} *
* @param workflowId id
/** * @param requestId id
* * @return
* */
* @param workflowId @Path("/signedContract/own/{languageGroupId}/{requestId}/{workflowId}")
* id @GET
* @param requestId @Consumes(MediaType.APPLICATION_JSON)
* id @Produces(MediaType.APPLICATION_JSON)
* @return public String signedContractOwn(@Context HttpServletRequest request, @Context HttpServletResponse response,
*/ @PathParam("workflowId") String workflowId, @PathParam("requestId") String requestId,
@Path("/signedContract/own/{languageGroupId}/{requestId}/{workflowId}") @PathParam("languageGroupId") int languageGroupId) {
@GET User user = HrmUserVarify.getUser(request, response);
@Consumes(MediaType.APPLICATION_JSON) try {
@Produces(MediaType.APPLICATION_JSON) faDDService.signedContractOwn(workflowId, requestId);
public String signedContractOwn(@Context HttpServletRequest request, @Context HttpServletResponse response, String mainTable = faDDServiceMapping.getMainTable(workflowId);
@PathParam("workflowId") String workflowId, @PathParam("requestId") String requestId, // TODO 更新本方签署
@PathParam("languageGroupId") int languageGroupId) { PrepSqlResultImpl sqlResult =
User user = HrmUserVarify.getUser(request, response); Util.createSqlBuilder().updateSql(mainTable, ParaMap.create().put("signed_oneself", 1),
try { Util.createPrepWhereImpl().whereAnd("requestid").whereEqual(requestId));
faDDService.signedContractOwn(workflowId, requestId); RecordSet rs = new RecordSet();
String mainTable = faDDServiceMapping.getMainTable(workflowId); rs.executeUpdate(sqlResult.getSqlStr(), sqlResult.getArgs());
// TODO 更新本方签署 Map<String, String> language = Util.queryLanguage(languageGroupId, user.getLanguage());
PrepSqlResultImpl sqlResult = String info = language.get("contractSignedInfo");
Util.createSqlBuilder().updateSql(mainTable, ParaMap.create().put("signed_oneself", 1), return ApiResult.success(info);
Util.createPrepWhereImpl().whereAnd("requestid").whereEqual(requestId)); } catch (Exception e) {
RecordSet rs = new RecordSet(); toolUtil.writeErrorLog("错误:" + e);
rs.executeUpdate(sqlResult.getSqlStr(), sqlResult.getArgs()); return ApiResult.error(e.toString());
Map<String, String> language = Util.queryLanguage(languageGroupId, user.getLanguage()); }
String info = language.get("contractSignedInfo"); }
return ApiResult.success(info);
} catch (Exception e) { /**
toolUtil.writeErrorLog("错误:" + e.toString()); *
return ApiResult.error(e.toString()); *
} * @param requestId id
} * @return
*/
/** @Path("/contract/download/{workflowId}/{requestId}")
* @GET
* @Produces(MediaType.APPLICATION_OCTET_STREAM)
* @param requestId public Response contractDownload(@PathParam("requestId") String requestId,
* id @PathParam("workflowId") String workflowId) {
* @return toolUtil.writeErrorLog("进入请求方法获取到请求id" + requestId);
*/ try {
@Path("/contract/download/{workflowId}/{requestId}") StreamingOutput contractZipStream = faDDService.contractDownload(requestId, workflowId);
@GET return Response.ok(contractZipStream, MediaType.APPLICATION_OCTET_STREAM).type("application/zip")
@Produces(MediaType.APPLICATION_OCTET_STREAM) .header("Content-Disposition", "attachment;filename=contracts.zip").build();
public Response contractDownload(@PathParam("requestId") String requestId, } catch (Exception e) {
@PathParam("workflowId") String workflowId) { toolUtil.writeErrorLog("转换失败," + e);
toolUtil.writeErrorLog("进入请求方法获取到请求id" + requestId); return Response.ok(ApiResult.error("出现错误,错误原因: " + e), MediaType.APPLICATION_JSON).build();
try { }
StreamingOutput contractZipStream = faDDService.contractDownload(requestId, workflowId); }
return Response.ok(contractZipStream, MediaType.APPLICATION_OCTET_STREAM).type("application/zip")
.header("Content-Disposition", "attachment;filename=contracts.zip").build(); /**
} catch (Exception e) { *
toolUtil.writeErrorLog("转换失败," + e.toString()); *
return Response.ok(ApiResult.error("出现错误,错误原因: " + e), MediaType.APPLICATION_JSON).build(); * @param workflowId id
} * @return id
} */
@Path("/getAllVersion/{workflowId}/{markOnly}")
/** @GET
* @Produces(MediaType.APPLICATION_JSON)
* @Consumes(MediaType.APPLICATION_JSON)
* @param workflowId public String getAllVersion(@PathParam("workflowId") String workflowId, @PathParam("markOnly") String markOnly) {
* id try {
* @return id Map<String, Object> allVersion = faDDService.getAllVersion(workflowId, markOnly);
*/ return ApiResult.success(allVersion);
@Path("/getAllVersion/{workflowId}/{markOnly}") } catch (Exception e) {
@GET toolUtil.writeErrorLog("错误:" + e);
@Produces(MediaType.APPLICATION_JSON) return ApiResult.error(e.toString());
@Consumes(MediaType.APPLICATION_JSON) }
public String getAllVersion(@PathParam("workflowId") String workflowId, @PathParam("markOnly") String markOnly) { }
try {
Map<String, Object> allVersion = faDDService.getAllVersion(workflowId, markOnly); /**
return ApiResult.success(allVersion); *
} catch (Exception e) { *
toolUtil.writeErrorLog("错误:" + e.toString()); * @param requestId id
return ApiResult.error(e.toString()); * @return
} */
} @Path("/isAllSigned/{workflowId}/{requestId}")
@GET
/** @Produces(MediaType.APPLICATION_JSON)
* @Consumes(MediaType.APPLICATION_JSON)
* public String isAllSinged(@PathParam("requestId") String requestId, @PathParam("workflowId") String workflowId) {
* @param requestId try {
* id faDDService.queryContractStatus(workflowId, requestId, 1);
* @return boolean isAllSinged = faDDService.isAllSinged(requestId, workflowId);
*/ boolean isSingedOneself = faDDService.isSingedOneself(requestId, workflowId);
@Path("/isAllSigned/{workflowId}/{requestId}") Map<String, Object> result =
@GET ParaMap.create().put("isAllSinged", isAllSinged).put("isSingedOneself", isSingedOneself);
@Produces(MediaType.APPLICATION_JSON) return ApiResult.success(result);
@Consumes(MediaType.APPLICATION_JSON) } catch (Exception e) {
public String isAllSinged(@PathParam("requestId") String requestId, @PathParam("workflowId") String workflowId) { toolUtil.writeErrorLog("错误:" + e);
try { return ApiResult.error(e.toString());
faDDService.queryContractStatus(workflowId, requestId, 1); }
boolean isAllSinged = faDDService.isAllSinged(requestId, workflowId); }
boolean isSingedOneself = faDDService.isSingedOneself(requestId, workflowId);
Map<String, Object> result = @Path("/getLanguage/{languageGroupId}")
ParaMap.create().put("isAllSinged", isAllSinged).put("isSingedOneself", isSingedOneself); @GET
return ApiResult.success(result); @Produces(MediaType.APPLICATION_JSON)
} catch (Exception e) { public String getLanguage(@Context HttpServletRequest request, @Context HttpServletResponse response,
toolUtil.writeErrorLog("错误:" + e); @PathParam("languageGroupId") int languageGroupId) {
return ApiResult.error(e.toString()); User user = HrmUserVarify.getUser(request, response);
} Map<String, String> map = Util.queryLanguage(languageGroupId, user.getLanguage());
} return ApiResult.success(map);
}
@Path("/getLanguage/{languageGroupId}")
@GET @Path("/callback/signed")
@Produces(MediaType.APPLICATION_JSON) @POST
public String getLanguage(@Context HttpServletRequest request, @Context HttpServletResponse response, @Produces(MediaType.APPLICATION_JSON)
@PathParam("languageGroupId") int languageGroupId) { @Consumes(MediaType.APPLICATION_JSON)
User user = HrmUserVarify.getUser(request, response); public String callBackSigned(@RequestBody Map<String, Object> params) {
Map<String, String> map = Util.queryLanguage(languageGroupId, user.getLanguage()); toolUtil.writeErrorLog("回调方法:" + JSONObject.toJSONString(params));
return ApiResult.success(map); Map<String, Object> result = new HashMap<>();
} String bizContent = String.valueOf(params.get("bizContent"));
if (StringUtils.isNullOrEmpty(bizContent)) {
@Path("/callback/signed") toolUtil.writeErrorLog("参数没获取到!");
@POST result.put("code", "200");
@Produces(MediaType.APPLICATION_JSON) result.put("msg", "操作失败!");
@Consumes(MediaType.APPLICATION_JSON) return JSONObject.toJSONString(result);
public String callBackSigned(@RequestBody Map<String, Object> params) { }
toolUtil.writeErrorLog("回调方法:" + JSONObject.toJSONString(params)); byte[] decode = Base64.getDecoder().decode(bizContent.getBytes(StandardCharsets.UTF_8));
Map<String, Object> result = new HashMap<>(); String decodeStr = null;
String bizContent = String.valueOf(params.get("bizContent")); try {
if (StringUtils.isNullOrEmpty(bizContent)) { decodeStr = new String(decode, StandardCharsets.UTF_8);
toolUtil.writeErrorLog("参数没获取到!"); } catch (Exception e) {
result.put("code", "200"); e.printStackTrace();
result.put("msg", "操作失败!"); }
return JSONObject.toJSONString(result); String jsonStr = null;
} try {
byte[] decode = Base64.getDecoder().decode(bizContent.getBytes(StandardCharsets.UTF_8)); jsonStr = URLDecoder.decode(decodeStr, "UTF-8");
String decodeStr = null; } catch (Exception e) {
try { e.printStackTrace();
decodeStr = new String(decode, "UTF-8"); }
} catch (UnsupportedEncodingException e) { JSONObject jsonObject = JSON.parseObject(jsonStr);
e.printStackTrace(); String resultCode = String.valueOf(jsonObject.getString("resultCode"));
} String docNo = String.valueOf(jsonObject.getString("docNo"));
String jsonStr = null; if (!"1".equals(resultCode)) {
try { toolUtil.writeErrorLog("重复签署合同!" + docNo);
jsonStr = URLDecoder.decode(decodeStr, "UTF-8"); }
} catch (UnsupportedEncodingException e) { // Util.createSqlBuilder().updateSql()
e.printStackTrace();
} this.toolUtil.writeErrorLog(jsonObject.toJSONString());
JSONObject jsonObject = JSON.parseObject(jsonStr); result.put("code", "200");
String resultCode = String.valueOf(jsonObject.getString("resultCode")); result.put("msg", "操作成功!");
String docNo = String.valueOf(jsonObject.getString("docNo")); return JSONObject.toJSONString(result);
if (!"1".equals(resultCode)) { }
toolUtil.writeErrorLog("重复签署合同!" + docNo);
}
// Util.createSqlBuilder().updateSql()
this.toolUtil.writeErrorLog(jsonObject.toJSONString());
result.put("code", "200");
result.put("msg", "操作成功!");
return JSONObject.toJSONString(result);
}
} }