use of org.modelmapper.ModelMapper in project Settler by EmhyrVarEmreis.
the class CategoryService method getCategoriesWithValue.
public ResponseEntity<List<CategoryWithValueDTO>> getCategoriesWithValue(Long userId) {
getPermissionManager().authorizeGlobalAdmin();
if (Objects.isNull(userId) || userId < 0) {
userId = Security.currentUser().getId();
}
QCategory category = QCategory.category;
QTransaction transaction = QTransaction.transaction;
List<Tuple> fetch = new JPAQuery<>(entityManager).from(category, transaction).select(category, transaction.value.sum()).where(transaction.creator.id.eq(userId)).where(transaction.categories.contains(category)).groupBy(category.code, category.description, category.id).orderBy(transaction.value.sum().desc()).fetch();
ModelMapper preparedModelMapper = getModelMapper();
List<CategoryWithValueDTO> categoryWithValueDTOList = new ArrayList<>(fetch.size());
for (Tuple tuple : fetch) {
Category c = tuple.get(category);
Double d = tuple.get(transaction.value.sum());
if (Objects.nonNull(c)) {
categoryWithValueDTOList.add(new CategoryWithValueDTO(userId, preparedModelMapper.map(c, CategoryDTO.class), d));
}
}
return new ResponseEntity<>(categoryWithValueDTOList, HttpStatus.OK);
}
use of org.modelmapper.ModelMapper in project xm-ms-entity by xm-online.
the class XmEntityServiceImpl method exportEntities.
@LogicExtensionPoint("Export")
@Override
public byte[] exportEntities(String fileFormat, String typeKey) {
Set<String> typeKeys = xmEntitySpecService.findNonAbstractTypesByPrefix(typeKey).stream().map(TypeSpec::getKey).collect(Collectors.toSet());
List<XmEntity> xmEntities = xmEntityRepository.findAllByTypeKeyIn(new PageRequest(0, Integer.MAX_VALUE), typeKeys).getContent();
ModelMapper modelMapper = new ModelMapper();
List<SimpleExportXmEntityDto> simpleEntities = xmEntities.stream().map(entity -> modelMapper.map(entity, SimpleExportXmEntityDto.class)).collect(Collectors.toList());
switch(FileFormatEnum.valueOf(fileFormat.toUpperCase())) {
case CSV:
return EntityToCsvConverterUtils.toCsv(simpleEntities, SimpleExportXmEntityDto.class);
case XLSX:
return EntityToExcelConverterUtils.toExcel(simpleEntities, typeKey);
default:
throw new BusinessException(ErrorConstants.ERR_VALIDATION, String.format("Converter doesn't support '%s' file format", fileFormat));
}
}
use of org.modelmapper.ModelMapper in project xm-ms-entity by xm-online.
the class EntityToExcelConverterUnitTest method convertEntityToExcel.
@Test
public void convertEntityToExcel() throws Exception {
ModelMapper modelMapper = new ModelMapper();
byte[] media = EntityToExcelConverterUtils.toExcel(xmEntities.stream().map(entity -> modelMapper.map(entity, SimpleExportXmEntityDto.class)).collect(Collectors.toList()), "defaultSheetName");
Assert.assertNotNull(media);
Assert.assertThat(media.length, Matchers.greaterThan(1));
}
use of org.modelmapper.ModelMapper in project paascloud-master by paascloud.
the class UacMenuServiceImpl method getViewVoById.
@Override
@Transactional(readOnly = true, rollbackFor = Exception.class)
public ViewMenuVo getViewVoById(Long id) {
Preconditions.checkArgument(id != null, "菜单ID不能为空");
UacMenu menu = uacMenuMapper.selectByPrimaryKey(id);
if (menu == null) {
logger.error("找不到菜单信息id={}", id);
throw new UacBizException(ErrorCodeEnum.UAC10013003, id);
}
// 获取父级菜单信息
UacMenu parentMenu = uacMenuMapper.selectByPrimaryKey(menu.getPid());
ModelMapper modelMapper = new ModelMapper();
ViewMenuVo menuVo = modelMapper.map(menu, ViewMenuVo.class);
if (parentMenu != null) {
menuVo.setParentMenuName(parentMenu.getMenuName());
}
return menuVo;
}
use of org.modelmapper.ModelMapper in project paascloud-master by paascloud.
the class UacUserTokenServiceImpl method saveUserToken.
@Override
public void saveUserToken(String accessToken, String refreshToken, LoginAuthDto loginAuthDto, HttpServletRequest request) {
// 获取登录时间
Long userId = loginAuthDto.getUserId();
UacUser uacUser = uacUserService.selectByKey(userId);
final UserAgent userAgent = UserAgent.parseUserAgentString(request.getHeader("User-Agent"));
// 获取客户端操作系统
final String os = userAgent.getOperatingSystem().getName();
// 获取客户端浏览器
final String browser = userAgent.getBrowser().getName();
final String remoteAddr = RequestUtil.getRemoteAddr(request);
// 根据IP获取位置信息
final String remoteLocation = opcRpcService.getLocationById(remoteAddr);
// 存入mysql数据库
UacUserToken uacUserToken = new UacUserToken();
OAuth2ClientProperties[] clients = securityProperties.getOauth2().getClients();
int accessTokenValidateSeconds = clients[0].getAccessTokenValidateSeconds();
int refreshTokenValiditySeconds = clients[0].getRefreshTokenValiditySeconds();
uacUserToken.setOs(os);
uacUserToken.setBrowser(browser);
uacUserToken.setAccessToken(accessToken);
uacUserToken.setAccessTokenValidity(accessTokenValidateSeconds);
uacUserToken.setLoginIp(remoteAddr);
uacUserToken.setLoginLocation(remoteLocation);
uacUserToken.setLoginTime(uacUser.getLastLoginTime());
uacUserToken.setLoginName(loginAuthDto.getLoginName());
uacUserToken.setRefreshToken(refreshToken);
uacUserToken.setRefreshTokenValidity(refreshTokenValiditySeconds);
uacUserToken.setStatus(UacUserTokenStatusEnum.ON_LINE.getStatus());
uacUserToken.setUserId(userId);
uacUserToken.setUserName(loginAuthDto.getUserName());
uacUserToken.setUpdateInfo(loginAuthDto);
uacUserToken.setGroupId(loginAuthDto.getGroupId());
uacUserToken.setGroupName(loginAuthDto.getGroupName());
uacUserToken.setId(generateId());
uacUserTokenMapper.insertSelective(uacUserToken);
UserTokenDto userTokenDto = new ModelMapper().map(uacUserToken, UserTokenDto.class);
// 存入redis数据库
updateRedisUserToken(accessToken, accessTokenValidateSeconds, userTokenDto);
}
Aggregations