package com.vincent.rsf.server.system.service.impl; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.vincent.rsf.server.system.entity.OpenApiApp; import com.vincent.rsf.server.system.mapper.OpenApiAppMapper; import com.vincent.rsf.server.system.service.OpenApiAppService; import org.springframework.security.crypto.password.PasswordEncoder; import org.springframework.stereotype.Service; import javax.annotation.Resource; @Service public class OpenApiAppServiceImpl extends ServiceImpl implements OpenApiAppService { @Resource private PasswordEncoder passwordEncoder; @Override public boolean save(OpenApiApp entity) { encodeScrectIfPlain(entity); return super.save(entity); } @Override public boolean updateById(OpenApiApp entity) { encodeScrectIfPlain(entity); return super.updateById(entity); } /** 若为明文则改为 BCrypt 再存库,便于 getToken 时用 BCrypt 校验 */ private void encodeScrectIfPlain(OpenApiApp entity) { if (entity == null) { return; } String s = entity.getScrect(); if (s == null || s.isEmpty() || s.startsWith("$2")) { return; } entity.setScrect(passwordEncoder.encode(s)); } }