异常处理

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