wangjun 4 tahun lalu
induk
melakukan
33f6b22527

+ 6 - 0
business/base-service/src/main/java/com/yihu/jw/dict/dao/BaseExceptionDictDao.java

@ -2,7 +2,13 @@ package com.yihu.jw.dict.dao;
import com.yihu.jw.entity.base.dict.BaseExceptionDictDO;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;
import java.util.List;
import java.util.Map;
public interface BaseExceptionDictDao  extends PagingAndSortingRepository<BaseExceptionDictDO, String>, JpaSpecificationExecutor<BaseExceptionDictDO> {
    @Query("from BaseExceptionDictDO  t where t.isDel='1' and t.code=?1")
    List<Map<String,Object>> findByCode(String code);
}

+ 8 - 7
business/base-service/src/main/java/com/yihu/jw/dict/service/BaseExceptionService.java

@ -7,12 +7,13 @@ import com.yihu.jw.entity.base.dict.BaseExceptionServerDictDO;
import com.yihu.jw.utils.hibernate.HibenateUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;
import java.util.List;
import java.util.Map;
@Service
@Component
public class BaseExceptionService {
    @Autowired
    private BaseExceptionDictDao baseExceptionDictDao;
@ -40,18 +41,18 @@ public class BaseExceptionService {
                " t.exception_type as \"exceptionType\"," +
                " t.exception_type_name as \"exceptionTypeName\"," +
                " t.remind_content as \"remindContent\"" +
                " from base_exception_dict t ";
                " from base_exception_dict t where 1=1";
        if (StringUtils.isNoneBlank(id)){
            sql+=" t.id ='"+id+"'";
            sql+=" and t.id ='"+id+"'";
        }
        if (StringUtils.isNoneBlank(code)){
            sql+=" t.code ='"+code+"'";
            sql+=" and t.code ='"+code+"'";
        }
        if (StringUtils.isNoneBlank(exceptionType)){
            sql+=" t.exception_type ='"+exceptionType+"'";
            sql+=" and t.exception_type ='"+exceptionType+"'";
        }
        if (StringUtils.isNoneBlank(isDel)){
            sql+=" t.is_del ='"+isDel+"'";
            sql+=" and t.is_del ='"+isDel+"'";
        }
        List<Map<String,Object>> list = hibenateUtils.createSQLQuery(sql);
        return list;
@ -63,7 +64,7 @@ public class BaseExceptionService {
                " t.update_time as \"updateTime\"," +
                " t.is_del as \"isDel\"," +
                " t.path_url as \"pathUrl\"" +
                " from base_exception_server_dict t ";
                " from base_exception_server_dict t where 1=1 ";
        if (StringUtils.isNoneBlank(id)){
            sql+=" and t.id ='"+id+"'";
        }

+ 5 - 5
common/common-entity/src/main/java/com/yihu/jw/entity/base/dict/BaseExceptionLogDO.java

@ -11,7 +11,7 @@ import java.util.Date;
@Table(name = "base_exception_log")
public class BaseExceptionLogDO extends UuidIdentityEntity {
    private String serviceCode;
    private String exceptionVode;
    private String exceptionCode;
    private String exceptionType;
    private Date createTime;
    private String request;
@ -25,12 +25,12 @@ public class BaseExceptionLogDO extends UuidIdentityEntity {
        this.serviceCode = serviceCode;
    }
    @Column(name = "exception_code")
    public String getExceptionVode() {
        return exceptionVode;
    public String getExceptionCode() {
        return exceptionCode;
    }
    public void setExceptionVode(String exceptionVode) {
        this.exceptionVode = exceptionVode;
    public void setExceptionCode(String exceptionCode) {
        this.exceptionCode = exceptionCode;
    }
    @Column(name = "exception_type")
    public String getExceptionType() {

+ 46 - 1
gateway/ag-basic/src/main/java/com/yihu/jw/gateway/filter/DidiFilterProcessor.java

@ -4,6 +4,20 @@ import com.netflix.zuul.FilterProcessor;
import com.netflix.zuul.ZuulFilter;
import com.netflix.zuul.context.RequestContext;
import com.netflix.zuul.exception.ZuulException;
import com.yihu.jw.entity.base.dict.BaseExceptionLogDO;
import com.yihu.jw.gateway.methlog.BaseExceptionService;
import com.yihu.jw.gateway.methlog.dao.BaseExceptionDictDao;
import com.yihu.jw.gateway.methlog.dao.BaseExceptionLogDao;
import com.yihu.jw.gateway.methlog.dao.BaseExceptionServerDictDao;
import com.yihu.jw.gateway.security.BeanUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;
import java.util.Date;
import java.util.List;
import java.util.Map;
/**
 * Created with IntelliJ IDEA.
@ -12,6 +26,7 @@ import com.netflix.zuul.exception.ZuulException;
 * @Date: 2021/5/19
 * @Description:
 */
@Component
public class DidiFilterProcessor extends FilterProcessor {
    @Override
    public Object processZuulFilter(ZuulFilter filter) throws ZuulException {
@ -19,8 +34,38 @@ public class DidiFilterProcessor extends FilterProcessor {
            return super.processZuulFilter(filter);
        } catch (ZuulException e) {
            if (e.nStatusCode==500){
                String message="";
                String cause="";
                String serviceId="";
                String responseCode="";
                String exceptionType="";
                BaseExceptionLogDao baseExceptionLogDao = BeanUtil.getBean(BaseExceptionLogDao.class);
                //BaseExceptionDictDao baseExceptionDictDao = BeanUtil.getBean(BaseExceptionDictDao.class);
                BaseExceptionService baseExceptionService = BeanUtil.getBean(BaseExceptionService.class);
                List<Map<String,Object>> list = baseExceptionService.findExceptionDict("","110001","","1");
                RequestContext ctx = RequestContext.getCurrentContext();
                ZuulException e1 = new ZuulException("123456",10085,"10000");
                List<Map<String,Object>> serviceList=baseExceptionService.findExceptionService("","","1","");
                for (Map<String,Object> map:serviceList){
                    if (ctx.getRequest().getServletPath().contains(map.get("pathUrl").toString())){
                        serviceId=map.get("id").toString();
                        break;
                    }
                }
                if (list!=null&&list.size()>0){
                    message = list.get(0).get("remindContent").toString();
                    cause=list.get(0).get("exceptionMessage").toString();
                    responseCode=serviceId+list.get(0).get("code").toString();
                    exceptionType = list.get(0).get("exceptionType").toString();
                }
                ZuulException e1 = new ZuulException(message, StringUtils.isEmpty(responseCode)?99999999:Integer.valueOf(responseCode),cause);
                BaseExceptionLogDO baseExceptionLogDO = new BaseExceptionLogDO();
                baseExceptionLogDO.setCreateTime(new Date());
                baseExceptionLogDO.setExceptionType(exceptionType);
                baseExceptionLogDO.setServiceCode(serviceId);
                baseExceptionLogDO.setExceptionCode(responseCode);
                baseExceptionLogDO.setRequest(ctx.getRequest().toString());
                baseExceptionLogDO.setResponse(ctx.toString());
                baseExceptionLogDao.save(baseExceptionLogDO);
                ctx.set("failed.exception", e1);
                ctx.set("failed.filter", filter);
                throw e1 ;

+ 83 - 0
gateway/ag-basic/src/main/java/com/yihu/jw/gateway/methlog/BaseExceptionService.java

@ -0,0 +1,83 @@
package com.yihu.jw.gateway.methlog;
import com.yihu.jw.entity.base.dict.BaseExceptionServerDictDO;
import com.yihu.jw.gateway.methlog.dao.BaseExceptionDictDao;
import com.yihu.jw.gateway.methlog.dao.BaseExceptionLogDao;
import com.yihu.jw.gateway.methlog.dao.BaseExceptionServerDictDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Component;
import org.springframework.util.StringUtils;
import java.util.List;
import java.util.Map;
@Component
public class BaseExceptionService {
    @Autowired
    private BaseExceptionDictDao baseExceptionDictDao;
    @Autowired
    private BaseExceptionLogDao baseExceptionLogDao;
    @Autowired
    private BaseExceptionServerDictDao baseExceptionServerDictDao;
    @Autowired
    private JdbcTemplate jdbcTemplate;
    public String findServiceByPath(String path){
        BaseExceptionServerDictDO baseExceptionServerDictDO = baseExceptionServerDictDao.findServiceByPath(path);
        String id ="";
        if (baseExceptionServerDictDO !=null){
            id = baseExceptionServerDictDO.getId();
        }
        return id;
    }
    public List<Map<String,Object>> findExceptionDict(String id,String code,String exceptionType,String isDel){
        String sql = "select t.id as \"id\"," +
                " t.code as \"code\"," +
                " t.exception_message as \"exceptionMessage\"," +
                " t.create_time as \"createTime\"," +
                " t.is_del \"isDel\"," +
                " t.model_name as \"modelName\"," +
                " t.exception_type as \"exceptionType\"," +
                " t.exception_type_name as \"exceptionTypeName\"," +
                " t.remind_content as \"remindContent\"" +
                " from base_exception_dict t where 1=1";
        if (!StringUtils.isEmpty(id)){
            sql+=" and t.id ='"+id+"'";
        }
        if (!StringUtils.isEmpty(code)){
            sql+=" and t.code ='"+code+"'";
        }
        if (!StringUtils.isEmpty(exceptionType)){
            sql+=" and t.exception_type ='"+exceptionType+"'";
        }
        if (!StringUtils.isEmpty(isDel)){
            sql+=" and t.is_del ='"+isDel+"'";
        }
        List<Map<String,Object>> list = jdbcTemplate.queryForList(sql);
        return list;
    }
    public List<Map<String,Object>> findExceptionService(String id,String name,String isDel,String pathUrl){
        String sql = "select t.id as \"id\"," +
                " t.name as \"name\"," +
                " t.create_time as \"createTime\"," +
                " t.update_time as \"updateTime\"," +
                " t.is_del as \"isDel\"," +
                " t.path_url as \"pathUrl\"" +
                " from base_exception_server_dict t where 1=1 ";
        if (!StringUtils.isEmpty(id)){
            sql+=" and t.id ='"+id+"'";
        }
        if (!StringUtils.isEmpty(name)){
            sql+=" and t.name ='"+name+"'";
        }
        if (!StringUtils.isEmpty(isDel)){
            sql+=" and t.is_del ='"+isDel+"'";
        }
        if (!StringUtils.isEmpty(pathUrl)){
            sql+=" and t.path_url ='"+pathUrl+"'";
        }
        List<Map<String,Object>> list = jdbcTemplate.queryForList(sql);
        return  list;
    }
}

+ 0 - 3
gateway/ag-basic/src/main/java/com/yihu/jw/gateway/methlog/BaseLoginLogService.java

@ -3,11 +3,9 @@ package com.yihu.jw.gateway.methlog;
import com.yihu.jw.entity.base.login.BaseLoginLogDO;
import com.yihu.jw.entity.hospital.consult.WlyyHospitalSysDictDO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.repository.CrudRepository;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;
import java.util.Date;
import java.util.List;
@ -19,7 +17,6 @@ public class BaseLoginLogService {
    private BaseLoginLogDao baseLoginLogDao;
    @Autowired
    private WlyyHospitalSysDictDao wlyyHospitalSysDictDao;
    /**
     * 根据openid 获取最新的一条数据
     * @param openid

+ 14 - 0
gateway/ag-basic/src/main/java/com/yihu/jw/gateway/methlog/dao/BaseExceptionDictDao.java

@ -0,0 +1,14 @@
package com.yihu.jw.gateway.methlog.dao;
import com.yihu.jw.entity.base.dict.BaseExceptionDictDO;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;
import java.util.List;
import java.util.Map;
public interface BaseExceptionDictDao  extends PagingAndSortingRepository<BaseExceptionDictDO, String>, JpaSpecificationExecutor<BaseExceptionDictDO> {
    @Query("from BaseExceptionDictDO  t where t.isDel='1' and t.code=?1")
    List<Map<String,Object>> findByCode(String code);
}

+ 8 - 0
gateway/ag-basic/src/main/java/com/yihu/jw/gateway/methlog/dao/BaseExceptionLogDao.java

@ -0,0 +1,8 @@
package com.yihu.jw.gateway.methlog.dao;
import com.yihu.jw.entity.base.dict.BaseExceptionLogDO;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.repository.PagingAndSortingRepository;
public interface BaseExceptionLogDao extends PagingAndSortingRepository<BaseExceptionLogDO, String>, JpaSpecificationExecutor<BaseExceptionLogDO> {
}

+ 11 - 0
gateway/ag-basic/src/main/java/com/yihu/jw/gateway/methlog/dao/BaseExceptionServerDictDao.java

@ -0,0 +1,11 @@
package com.yihu.jw.gateway.methlog.dao;
import com.yihu.jw.entity.base.dict.BaseExceptionServerDictDO;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;
public interface BaseExceptionServerDictDao extends PagingAndSortingRepository<BaseExceptionServerDictDO, String>, JpaSpecificationExecutor<BaseExceptionServerDictDO> {
    @Query("from BaseExceptionServerDictDO t where t.isDel='1' and t.path=?1")
    BaseExceptionServerDictDO findServiceByPath(String path);
}

+ 38 - 0
gateway/ag-basic/src/main/java/com/yihu/jw/gateway/security/BeanUtil.java

@ -0,0 +1,38 @@
package com.yihu.jw.gateway.security;
import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Component;
@Component
public class BeanUtil implements ApplicationContextAware {
    private static ApplicationContext applicationContext;
    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        if (BeanUtil.applicationContext == null) {
            BeanUtil.applicationContext = applicationContext;
        }
    }
    // 获取applicationContext
    public static ApplicationContext getApplicationContext() {
        return applicationContext;
    }
    // 通过name获取 Bean.
    public static Object getBean(String name) {
        return getApplicationContext().getBean(name);
    }
    // 通过class获取Bean.
    public static <T> T getBean(Class<T> clazz) {
        return getApplicationContext().getBean(clazz);
    }
    // 通过name,以及Clazz返回指定的Bean
    public static <T> T getBean(String name, Class<T> clazz) {
        return getApplicationContext().getBean(name, clazz);
    }
}