[Improvement][ui] improving to find current version identifier(#15815)

This commit is contained in:
1462719985@qq.com 2024-05-08 17:26:01 +08:00
parent 50439164e4
commit db81822c21
6 changed files with 19 additions and 30 deletions

View File

@ -102,9 +102,8 @@ public class UiPluginController extends BaseController {
@ResponseStatus(HttpStatus.OK)
@ApiException(VERSION_INFO_STATE_ERROR)
public Result<ProductInfoDto> queryProductInfo(
@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
@RequestParam(value = "userId") Integer userId) {
ProductInfoDto result = uiPluginService.queryProductInfo(loginUser, userId);
@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser) {
ProductInfoDto result = uiPluginService.queryProductInfo(loginUser);
return Result.success(result);
}
}

View File

@ -32,6 +32,6 @@ public interface UiPluginService {
Map<String, Object> queryUiPluginDetailById(int id);
ProductInfoDto queryProductInfo(User loginUser, int userId);
ProductInfoDto queryProductInfo(User loginUser);
}

View File

@ -39,6 +39,7 @@ import java.util.Map;
import lombok.extern.slf4j.Slf4j;
import org.apache.dolphinscheduler.dao.repository.DsVersionDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@ -55,6 +56,11 @@ public class UiPluginServiceImpl extends BaseServiceImpl implements UiPluginServ
@Autowired
DsVersionMapper dsVersionMapper;
@Autowired
private DsVersionDao dsVersionDao;
private volatile String dsVersion;
@Override
public Map<String, Object> queryUiPluginsByType(PluginType pluginType) {
Map<String, Object> result = new HashMap<>();
@ -93,22 +99,16 @@ public class UiPluginServiceImpl extends BaseServiceImpl implements UiPluginServ
}
@Override
public ProductInfoDto queryProductInfo(User loginUser, int userId) {
public ProductInfoDto queryProductInfo(User loginUser) {
// check if user is existed
if (userId <= 0 || !(loginUser.getId() == userId)) {
throw new ServiceException(Status.REQUEST_PARAMS_NOT_VALID_ERROR,
"User id: " + userId + " should not less than or equals to 0.");
}
// persist to the database
DsVersion dsVersion = dsVersionMapper.selectById(1);
dsVersion = dsVersionDao.selectVersion().map(DsVersion::getVersion).orElse("unknown");
if(StringUtils.isBlank(dsVersion.getVersion())){
if(StringUtils.isBlank(dsVersion)){
throw new ServiceException(Status.VERSION_INFO_STATE_ERROR);
}
ProductInfoDto result = new ProductInfoDto();
result.setId(dsVersion.getId());
result.setVersion(dsVersion.getVersion());
result.setVersion(dsVersion);
return result;
}

View File

@ -107,7 +107,7 @@ public class UiPluginControllerTest extends AbstractControllerTest {
@Test
public void testQueryProductInfo() throws Exception {
ProductInfoDto mockResult = new ProductInfoDto();
Mockito.when(uiPluginService.queryProductInfo(Mockito.any(), Mockito.anyInt())).thenReturn(mockResult);
Mockito.when(uiPluginService.queryProductInfo(Mockito.any())).thenReturn(mockResult);
MultiValueMap<String, String> paramsMap = new LinkedMultiValueMap<>();
paramsMap.add("userId", "1");
@ -121,13 +121,5 @@ public class UiPluginControllerTest extends AbstractControllerTest {
Result result = JSONUtils.parseObject(mvcResult.getResponse().getContentAsString(), Result.class);
Assertions.assertEquals(Status.SUCCESS.getCode(), result.getCode().intValue());
logger.info(mvcResult.getResponse().getContentAsString());
}
private User getLoginUser() {
User user = new User();
user.setId(1);
user.setUserName("admin");
return user;
}
}

View File

@ -34,10 +34,9 @@ export function queryUiPluginDetailById(id: IPluginId): any {
})
}
export function queryProductInfo(params: UserIdReq): any {
export function queryProductInfo(): any {
return axios({
url: '/ui-plugins/queryProductInfo',
method: 'post',
params
method: 'post'
})
}

View File

@ -28,14 +28,13 @@ const about = defineComponent({
name: 'about',
setup() {
const info: any = ref('')
const queryProduct = async (userId: number) => {
const productInfo = await queryProductInfo(
{ userId })
const queryProduct = async () => {
const productInfo = await queryProductInfo()
if (!productInfo) throw Error()
info.value = productInfo.version
}
onMounted( () => {
queryProduct((userStore.getUserInfo as UserInfoRes).id)
queryProduct()
})
return { queryProduct, info }