Browse Source

Merge branch 'dev_exception_handle' into dev_temp

dev_shibei_match
wxz 5 years ago
parent
commit
7603db8a9a
  1. 16
      epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/aspect/BaseRequestLogAspect.java
  2. 96
      epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/exception/RenException.java
  3. 5
      epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/exception/RenExceptionHandler.java
  4. 4
      epmet-gateway/src/main/java/com/epmet/auth/ExternalAuthProcessor.java
  5. 4
      epmet-gateway/src/main/java/com/epmet/auth/InternalAuthProcessor.java
  6. 4
      epmet-module/epmet-third/epmet-third-client/src/main/java/com/epmet/dto/form/CustomerTemplateListFormDTO.java
  7. 4
      epmet-module/epmet-third/epmet-third-client/src/main/java/com/epmet/dto/form/GetTemplateListFormDTO.java
  8. 11
      epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/dao/PersonalTemplateDao.java
  9. 11
      epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/service/PersonalTemplateService.java
  10. 17
      epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/service/impl/PersonalTemplateServiceImpl.java
  11. 5
      epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/service/impl/SubscribeServiceImpl.java
  12. 13
      epmet-module/epmet-third/epmet-third-server/src/main/resources/mapper/PersonalTemplateDao.xml
  13. 5
      epmet-module/gov-issue/gov-issue-server/src/main/java/com/epmet/service/impl/IssueServiceImpl.java

16
epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/aspect/BaseRequestLogAspect.java

@ -66,7 +66,7 @@ public abstract class BaseRequestLogAspect {
resultInfoLog(transactionSerial, getExecPeriod(startTime), result); resultInfoLog(transactionSerial, getExecPeriod(startTime), result);
} catch (RenException e) { } catch (RenException e) {
result = handleRenException(e); result = handleRenException(e);
resultErrorLog(transactionSerial, getExecPeriod(startTime), result, e.getMsg(), ExceptionUtils.getErrorStackTrace(e)); resultErrorLog(transactionSerial, getExecPeriod(startTime), result, e.getInternalMsg(), ExceptionUtils.getErrorStackTrace(e));
} catch (ValidateException e) { } catch (ValidateException e) {
result = handleValidateException(e); result = handleValidateException(e);
resultErrorLog(transactionSerial, getExecPeriod(startTime), result, e.getMsg(), ExceptionUtils.getErrorStackTrace(e)); resultErrorLog(transactionSerial, getExecPeriod(startTime), result, e.getMsg(), ExceptionUtils.getErrorStackTrace(e));
@ -174,14 +174,20 @@ public abstract class BaseRequestLogAspect {
*/ */
private Result handleRenException(RenException e) { private Result handleRenException(RenException e) {
if (e.getCode() > 8000) { if (e.getCode() > 8000) {
// 原样返回 Result result;
Result result=new Result().error(e.getCode()); if (StringUtils.isNotBlank(e.getMsg())) {
result.setInternalMsg(e.getMsg()); // 抛出异常的时候填写了自定义显示信息,把显示信息返回
result = new Result().error(e.getCode(), e.getMsg());
} else {
// 没有填写显示信息,则根据code找固定的显示信息
result = new Result().error(e.getCode());
}
result.setInternalMsg(e.getInternalMsg());
return result; return result;
} }
// 转化成服务器开小差... // 转化成服务器开小差...
Result result=new Result().error(); Result result=new Result().error();
result.setInternalMsg(e.getMsg()); result.setInternalMsg(e.getInternalMsg());
//result.setMsg(e.getMsg()); //result.setMsg(e.getMsg());
return result; return result;
} }

96
epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/exception/RenException.java

@ -21,26 +21,67 @@ import org.apache.commons.lang3.StringUtils;
public class RenException extends RuntimeException { public class RenException extends RuntimeException {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
private int code; private int code;
/**
* 显示给客户的消息
*/
private String msg; private String msg;
/**
* 内部消息用于服务之间传递错误信息排错用
*/
private String internalMsg;
public RenException(int code) { public RenException(int code) {
this(code, ""); this(code, "");
} }
public RenException(int code, String internalMsg) {
super(internalMsg);
this.code = code;
if (StringUtils.isBlank(internalMsg)) {
this.internalMsg = EpmetErrorCode.getMsg(code);
if (StringUtils.isBlank(this.internalMsg)) {
this.internalMsg = MessageUtils.getMessage(code, internalMsg);
}
} else {
this.internalMsg = internalMsg;
}
}
public RenException(int code, String internalMsg, String msg) {
this(code, internalMsg);
this.msg = msg;
}
public RenException(String internalMsg) {
super(internalMsg);
// this.code = ErrorCode.INTERNAL_SERVER_ERROR;
this.code = EpmetErrorCode.SERVER_ERROR.getCode();
this.internalMsg = internalMsg;
}
public RenException(String internalMsg, String msg) {
this(internalMsg);
this.msg = msg;
}
public RenException(int code, String... params) { public RenException(int code, String... params) {
this.code = code; this.code = code;
this.msg = EpmetErrorCode.getMsg(code); this.internalMsg = EpmetErrorCode.getMsg(code);
if (StringUtils.isBlank(this.msg)) { if (StringUtils.isBlank(this.internalMsg)) {
this.msg = MessageUtils.getMessage(code, params); this.internalMsg = MessageUtils.getMessage(code, params);
} }
} }
public RenException(int code, Throwable e) { public RenException(int code, Throwable e) {
super(e); super(e);
this.code = code; this.code = code;
this.msg = EpmetErrorCode.getMsg(code); this.internalMsg = EpmetErrorCode.getMsg(code);
if (StringUtils.isBlank(this.msg)) { if (StringUtils.isBlank(this.internalMsg)) {
this.msg = MessageUtils.getMessage(code); this.internalMsg = MessageUtils.getMessage(code);
} }
} }
@ -50,40 +91,18 @@ public class RenException extends RuntimeException {
} }
public RenException(int code, String msg) { public RenException(String internalMsg, Throwable e) {
super(msg); super(internalMsg, e);
this.code = code;
if (StringUtils.isBlank(msg)) {
this.msg = EpmetErrorCode.getMsg(code);
if (StringUtils.isBlank(this.msg)) {
this.msg = MessageUtils.getMessage(code, msg);
}
} else {
this.msg = msg;
}
}
public RenException(String msg) {
super(msg);
// this.code = ErrorCode.INTERNAL_SERVER_ERROR;
this.code = EpmetErrorCode.SERVER_ERROR.getCode(); this.code = EpmetErrorCode.SERVER_ERROR.getCode();
this.msg = msg; this.internalMsg = internalMsg;
} }
public RenException(String msg, Throwable e) { public String getInternalMsg() {
super(msg, e); return internalMsg;
// this.code = ErrorCode.INTERNAL_SERVER_ERROR;
this.code = EpmetErrorCode.SERVER_ERROR.getCode();
this.msg = msg;
} }
public String getMsg() { public void setInternalMsg(String internalMsg) {
return msg; this.internalMsg = internalMsg;
}
public void setMsg(String msg) {
this.msg = msg;
} }
public int getCode() { public int getCode() {
@ -94,4 +113,11 @@ public class RenException extends RuntimeException {
this.code = code; this.code = code;
} }
public String getMsg() {
return msg;
}
public void setMsg(String msg) {
this.msg = msg;
}
} }

5
epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/exception/RenExceptionHandler.java

@ -24,7 +24,6 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.DuplicateKeyException; import org.springframework.dao.DuplicateKeyException;
import org.springframework.http.HttpHeaders; import org.springframework.http.HttpHeaders;
import org.springframework.web.bind.annotation.ExceptionHandler; import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import java.util.Date; import java.util.Date;
@ -56,12 +55,12 @@ public class RenExceptionHandler {
public Result handleRRException(RenException ex){ public Result handleRRException(RenException ex){
if (ex.getCode() > 8000) { if (ex.getCode() > 8000) {
Result result=new Result().error(ex.getCode()); Result result=new Result().error(ex.getCode());
result.setData(ex.getMsg()); result.setData(ex.getInternalMsg());
return result; return result;
} }
logger.error(ExceptionUtils.getErrorStackTrace(ex)); logger.error(ExceptionUtils.getErrorStackTrace(ex));
Result result=new Result().error(); Result result=new Result().error();
result.setData(ex.getMsg()); result.setData(ex.getInternalMsg());
return result; return result;
// return new Result().error(); // return new Result().error();
} }

4
epmet-gateway/src/main/java/com/epmet/auth/ExternalAuthProcessor.java

@ -3,7 +3,6 @@ package com.epmet.auth;
import com.epmet.commons.tools.exception.EpmetErrorCode; import com.epmet.commons.tools.exception.EpmetErrorCode;
import com.epmet.commons.tools.exception.ExceptionUtils; import com.epmet.commons.tools.exception.ExceptionUtils;
import com.epmet.commons.tools.exception.RenException; import com.epmet.commons.tools.exception.RenException;
import com.epmet.commons.tools.utils.Result;
import com.epmet.filter.CpProperty; import com.epmet.filter.CpProperty;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger; import org.slf4j.Logger;
@ -15,7 +14,6 @@ import org.springframework.http.server.reactive.ServerHttpRequest;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import org.springframework.util.AntPathMatcher; import org.springframework.util.AntPathMatcher;
import org.springframework.web.server.ServerWebExchange; import org.springframework.web.server.ServerWebExchange;
import reactor.core.publisher.Mono;
/** /**
* 外部应用认证 * 外部应用认证
@ -93,7 +91,7 @@ public class ExternalAuthProcessor extends AuthProcessor {
} }
} catch (RenException e) { } catch (RenException e) {
//return response(exchange, new Result<>().error(e.getCode(), e.getMsg())); //return response(exchange, new Result<>().error(e.getCode(), e.getMsg()));
throw new RenException(e.getCode(),e.getMsg()); throw new RenException(e.getCode(),e.getInternalMsg());
} catch (Exception e) { } catch (Exception e) {
logger.error("外部应用请求认证发生未知错误:" + ExceptionUtils.getErrorStackTrace(e)); logger.error("外部应用请求认证发生未知错误:" + ExceptionUtils.getErrorStackTrace(e));
//return response(exchange, new Result<>().error("外部应用请求认证发生未知错误")); //return response(exchange, new Result<>().error("外部应用请求认证发生未知错误"));

4
epmet-gateway/src/main/java/com/epmet/auth/InternalAuthProcessor.java

@ -54,7 +54,7 @@ public class InternalAuthProcessor extends AuthProcessor {
baseTokenDto = getBaseTokenDto(token, jwtTokenUtils); baseTokenDto = getBaseTokenDto(token, jwtTokenUtils);
}catch(RenException e){ }catch(RenException e){
//return response(exchange,new Result<>().error(e.getCode(),e.getMsg())); //return response(exchange,new Result<>().error(e.getCode(),e.getMsg()));
throw new RenException(e.getCode(), e.getMsg()); throw new RenException(e.getCode(), e.getInternalMsg());
} }
}else{ }else{
baseTokenDto = null; baseTokenDto = null;
@ -97,7 +97,7 @@ public class InternalAuthProcessor extends AuthProcessor {
validateTokenDto(baseTokenDto, token); validateTokenDto(baseTokenDto, token);
} catch (RenException e) { } catch (RenException e) {
//return response(exchange, new Result<>().error(e.getCode(), e.getMsg())); //return response(exchange, new Result<>().error(e.getCode(), e.getMsg()));
throw new RenException(e.getCode(), e.getMsg()); throw new RenException(e.getCode(), e.getInternalMsg());
} }
} }

4
epmet-module/epmet-third/epmet-third-client/src/main/java/com/epmet/dto/form/CustomerTemplateListFormDTO.java

@ -22,6 +22,10 @@ public class CustomerTemplateListFormDTO implements Serializable {
*/ */
@NotBlank(message="公共模板Id不能为空", groups = {AddUserInternalGroup.class}) @NotBlank(message="公共模板Id不能为空", groups = {AddUserInternalGroup.class})
private String publicId; private String publicId;
/**
* 模板关键词Id
*/
private String keyIds;
public interface AddUserInternalGroup {} public interface AddUserInternalGroup {}
} }

4
epmet-module/epmet-third/epmet-third-client/src/main/java/com/epmet/dto/form/GetTemplateListFormDTO.java

@ -26,6 +26,10 @@ public class GetTemplateListFormDTO implements Serializable {
* 模板类型(站内信提醒) * 模板类型(站内信提醒)
*/ */
private String templateType; private String templateType;
/**
* 模板关键词Id
*/
private String keyIds;
public interface AddUserInternalGroup {} public interface AddUserInternalGroup {}
} }

11
epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/dao/PersonalTemplateDao.java

@ -94,4 +94,15 @@ public interface PersonalTemplateDao extends BaseDao<PersonalTemplateEntity> {
* @author sun * @author sun
*/ */
List<CustomerTemplateListResultDTO> selectCustomerTemplateList(CustomerTemplateListFormDTO formDTO); List<CustomerTemplateListResultDTO> selectCustomerTemplateList(CustomerTemplateListFormDTO formDTO);
/**
* 根据tid和keyIds查询是否已存在该模板类型数据
* @author zhaoqifeng
* @date 2020/11/2 10:31
* @param appId
* @param tid
* @param keyIds
* @return java.util.List<com.epmet.dto.PersonalTemplateDTO>
*/
List<PersonalTemplateDTO> selectListByKey(@Param("appId") String appId, @Param("tid") String tid, @Param("keyIds") String keyIds);
} }

11
epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/service/PersonalTemplateService.java

@ -141,4 +141,15 @@ public interface PersonalTemplateService extends BaseService<PersonalTemplateEnt
* @author sun * @author sun
*/ */
List<CustomerTemplateListResultDTO> customerTemplateList(CustomerTemplateListFormDTO formDTO); List<CustomerTemplateListResultDTO> customerTemplateList(CustomerTemplateListFormDTO formDTO);
/**
* 根据tid和keyIds查询是否已存在该模板类型数据
* @author zhaoqifeng
* @date 2020/11/2 10:29
* @param appId
* @param tid
* @param keyIds
* @return java.util.List<com.epmet.dto.PersonalTemplateDTO>
*/
List<PersonalTemplateDTO> getListByKey(String appId, String tid, String keyIds);
} }

17
epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/service/impl/PersonalTemplateServiceImpl.java

@ -127,6 +127,7 @@ public class PersonalTemplateServiceImpl extends BaseServiceImpl<PersonalTemplat
*/ */
@Override @Override
public List<GetTemplateListResultDTO> templateList(GetTemplateListFormDTO formDTO) { public List<GetTemplateListResultDTO> templateList(GetTemplateListFormDTO formDTO) {
formDTO.setKeyIds("5,4,2");
//根据客户Id、appId、模板类型查询小程序订阅消息模板列表 //根据客户Id、appId、模板类型查询小程序订阅消息模板列表
return baseDao.selectTemplateList(formDTO); return baseDao.selectTemplateList(formDTO);
} }
@ -138,7 +139,23 @@ public class PersonalTemplateServiceImpl extends BaseServiceImpl<PersonalTemplat
*/ */
@Override @Override
public List<CustomerTemplateListResultDTO> customerTemplateList(CustomerTemplateListFormDTO formDTO) { public List<CustomerTemplateListResultDTO> customerTemplateList(CustomerTemplateListFormDTO formDTO) {
formDTO.setKeyIds("5,4,2");
return baseDao.selectCustomerTemplateList(formDTO); return baseDao.selectCustomerTemplateList(formDTO);
} }
/**
* 根据tid和keyIds查询是否已存在该模板类型数据
*
* @param appId
* @param tid
* @param keyIds
* @return java.util.List<com.epmet.dto.PersonalTemplateDTO>
* @author zhaoqifeng
* @date 2020/11/2 10:29
*/
@Override
public List<PersonalTemplateDTO> getListByKey(String appId, String tid, String keyIds) {
return baseDao.selectListByKey(appId, tid, keyIds);
}
} }

5
epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/service/impl/SubscribeServiceImpl.java

@ -180,6 +180,11 @@ public class SubscribeServiceImpl implements SubscribeService {
String keywords = String.join(",", formDTO.getNameList()); String keywords = String.join(",", formDTO.getNameList());
List<String> keyIdList = formDTO.getKidList().stream().map(Object::toString).collect(Collectors.toList()); List<String> keyIdList = formDTO.getKidList().stream().map(Object::toString).collect(Collectors.toList());
String keyIds = String.join(",", keyIdList); String keyIds = String.join(",", keyIdList);
//根据tid和keyIds查询是否已存在该模板类型数据
List<PersonalTemplateDTO> list = personalTemplateService.getListByKey(formDTO.getAppId(), formDTO.getTid(), keyIds);
if (null != list && list.size() > NumConstant.ZERO) {
throw new RenException(formDTO.getTitle() + "已存在所选关键词[" + keywords + "]的模板");
}
//将公共模板存入数据库 //将公共模板存入数据库
PersonalTemplateDTO personalTemplateDTO = new PersonalTemplateDTO(); PersonalTemplateDTO personalTemplateDTO = new PersonalTemplateDTO();
personalTemplateDTO.setCustomerId(authInfo.getCustomerId()); personalTemplateDTO.setCustomerId(authInfo.getCustomerId());

13
epmet-module/epmet-third/epmet-third-server/src/main/resources/mapper/PersonalTemplateDao.xml

@ -86,7 +86,8 @@
AND customer_id = #{customerId} AND customer_id = #{customerId}
AND app_id = #{appId} AND app_id = #{appId}
AND title = #{templateType} AND title = #{templateType}
ORDER BY CREATED_TIME DESC AND key_ids = '5,4,2'<!-- 消息更新,详情内容,时间 -->
ORDER BY created_time ASC
</select> </select>
<select id="selectCustomerTemplateList" resultType="com.epmet.dto.result.CustomerTemplateListResultDTO"> <select id="selectCustomerTemplateList" resultType="com.epmet.dto.result.CustomerTemplateListResultDTO">
@ -102,6 +103,16 @@
AND cm.del_flag = '0' AND cm.del_flag = '0'
AND pt.customer_id = #{customerId} AND pt.customer_id = #{customerId}
AND pt.tid = #{publicId} AND pt.tid = #{publicId}
AND key_ids = #{keyIds}<!-- 消息更新,详情内容,时间 -->
ORDER BY created_time ASC
</select>
<select id="selectListByKey" resultType="com.epmet.dto.PersonalTemplateDTO">
SELECT ID
FROM personal_template
WHERE DEL_FLAG = '0'
AND APP_ID=#{appId}
AND TID = #{tid}
AND KEY_IDS = #{keyIds}
</select> </select>
</mapper> </mapper>

5
epmet-module/gov-issue/gov-issue-server/src/main/java/com/epmet/service/impl/IssueServiceImpl.java

@ -31,7 +31,6 @@ import com.epmet.dto.result.*;
import com.epmet.entity.IssueEntity; import com.epmet.entity.IssueEntity;
import com.epmet.entity.IssueProcessEntity; import com.epmet.entity.IssueProcessEntity;
import com.epmet.entity.IssueProjectRelationEntity; import com.epmet.entity.IssueProjectRelationEntity;
import com.epmet.entity.IssueVoteStatisticalEntity;
import com.epmet.feign.*; import com.epmet.feign.*;
import com.epmet.redis.GovIssueRedis; import com.epmet.redis.GovIssueRedis;
import com.epmet.redis.IssueVoteDetailRedis; import com.epmet.redis.IssueVoteDetailRedis;
@ -446,7 +445,7 @@ public class IssueServiceImpl extends BaseServiceImpl<IssueDao, IssueEntity> imp
try { try {
issueVoteStatisticalService.syncVotingCacheToDbByParams(formDTO.getIssueId(),entity.getGridId(),null); issueVoteStatisticalService.syncVotingCacheToDbByParams(formDTO.getIssueId(),entity.getGridId(),null);
}catch (RenException e){ }catch (RenException e){
logger.error(e.getMsg()); logger.error(e.getInternalMsg());
} }
} }
@ -624,7 +623,7 @@ public class IssueServiceImpl extends BaseServiceImpl<IssueDao, IssueEntity> imp
try{ try{
issueVoteStatisticalService.syncVotingCacheToDbByParams(formDTO.getIssueId(),entity.getGridId(),null); issueVoteStatisticalService.syncVotingCacheToDbByParams(formDTO.getIssueId(),entity.getGridId(),null);
}catch(RenException e){ }catch(RenException e){
logger.error(e.getMsg()); logger.error(e.getInternalMsg());
} }
} }

Loading…
Cancel
Save