异常处理

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.HttpServletResponse;
import java.io.UnsupportedEncodingException;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.Date;
@ -166,7 +165,7 @@ public class SignFtService {
try {
try {
tokenUtils.setAlgorithm(Algorithm.HMAC256(secretMap.get("clientSecret")));
} catch (UnsupportedEncodingException e) {
} catch (Exception e) {
throw new RuntimeException(e);
}
tokenUtils.setExpiresAt(new Date());

View File

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