mirror of
				https://github.com/dromara/RuoYi-Vue-Plus.git
				synced 2025-11-04 16:23:42 +08:00 
			
		
		
		
	fix 修复 脱敏没有实现类导致返回数据异常问题
This commit is contained in:
		@@ -11,6 +11,8 @@ import com.ruoyi.common.annotation.Sensitive;
 | 
				
			|||||||
import com.ruoyi.common.core.service.SensitiveService;
 | 
					import com.ruoyi.common.core.service.SensitiveService;
 | 
				
			||||||
import com.ruoyi.common.enums.SensitiveStrategy;
 | 
					import com.ruoyi.common.enums.SensitiveStrategy;
 | 
				
			||||||
import com.ruoyi.common.utils.spring.SpringUtils;
 | 
					import com.ruoyi.common.utils.spring.SpringUtils;
 | 
				
			||||||
 | 
					import lombok.extern.slf4j.Slf4j;
 | 
				
			||||||
 | 
					import org.springframework.beans.BeansException;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import java.io.IOException;
 | 
					import java.io.IOException;
 | 
				
			||||||
import java.util.Objects;
 | 
					import java.util.Objects;
 | 
				
			||||||
@@ -20,19 +22,24 @@ import java.util.Objects;
 | 
				
			|||||||
 *
 | 
					 *
 | 
				
			||||||
 * @author Yjoioooo
 | 
					 * @author Yjoioooo
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
 | 
					@Slf4j
 | 
				
			||||||
public class SensitiveJsonSerializer extends JsonSerializer<String> implements ContextualSerializer {
 | 
					public class SensitiveJsonSerializer extends JsonSerializer<String> implements ContextualSerializer {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    private SensitiveStrategy strategy;
 | 
					    private SensitiveStrategy strategy;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    @Override
 | 
					    @Override
 | 
				
			||||||
    public void serialize(String value, JsonGenerator gen, SerializerProvider serializers) throws IOException {
 | 
					    public void serialize(String value, JsonGenerator gen, SerializerProvider serializers) throws IOException {
 | 
				
			||||||
        SensitiveService sensitiveService = SpringUtils.getBean(SensitiveService.class);
 | 
					        try {
 | 
				
			||||||
        if (ObjectUtil.isNotNull(sensitiveService) && sensitiveService.isSensitive()) {
 | 
					            SensitiveService sensitiveService = SpringUtils.getBean(SensitiveService.class);
 | 
				
			||||||
            gen.writeString(strategy.desensitizer().apply(value));
 | 
					            if (ObjectUtil.isNotNull(sensitiveService) && sensitiveService.isSensitive()) {
 | 
				
			||||||
        } else {
 | 
					                gen.writeString(strategy.desensitizer().apply(value));
 | 
				
			||||||
 | 
					            } else {
 | 
				
			||||||
 | 
					                gen.writeString(value);
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					        } catch (BeansException e) {
 | 
				
			||||||
 | 
					            log.error("脱敏实现不存在, 采用默认处理 => {}", e.getMessage());
 | 
				
			||||||
            gen.writeString(value);
 | 
					            gen.writeString(value);
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    @Override
 | 
					    @Override
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user