Search in sources :

Example 26 with ModelMapper

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);
}
Also used : QTransaction(pl.morecraft.dev.settler.domain.QTransaction) ResponseEntity(org.springframework.http.ResponseEntity) Category(pl.morecraft.dev.settler.domain.Category) QCategory(pl.morecraft.dev.settler.domain.QCategory) ArrayList(java.util.ArrayList) CategoryWithValueDTO(pl.morecraft.dev.settler.web.dto.CategoryWithValueDTO) QCategory(pl.morecraft.dev.settler.domain.QCategory) Tuple(com.querydsl.core.Tuple) ModelMapper(org.modelmapper.ModelMapper)

Example 27 with ModelMapper

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));
    }
}
Also used : XmEntityService(com.icthh.xm.ms.entity.service.XmEntityService) StorageService(com.icthh.xm.ms.entity.service.StorageService) RequiredArgsConstructor(lombok.RequiredArgsConstructor) Autowired(org.springframework.beans.factory.annotation.Autowired) StringUtils(org.apache.commons.lang3.StringUtils) XmEntityPermittedRepository(com.icthh.xm.ms.entity.repository.XmEntityPermittedRepository) LogicExtensionPoint(com.icthh.xm.commons.lep.LogicExtensionPoint) Collectors.toMap(java.util.stream.Collectors.toMap) Vote(com.icthh.xm.ms.entity.domain.Vote) Arrays.asList(java.util.Arrays.asList) FileFormatEnum(com.icthh.xm.ms.entity.domain.FileFormatEnum) EntityToCsvConverterUtils(com.icthh.xm.ms.entity.domain.converter.EntityToCsvConverterUtils) Map(java.util.Map) EntityToExcelConverterUtils(com.icthh.xm.ms.entity.domain.converter.EntityToExcelConverterUtils) Pageable(org.springframework.data.domain.Pageable) FindWithPermission(com.icthh.xm.commons.permission.annotation.FindWithPermission) URI(java.net.URI) Resource(org.springframework.core.io.Resource) Link(com.icthh.xm.ms.entity.domain.Link) LifecycleLepStrategy(com.icthh.xm.ms.entity.service.LifecycleLepStrategy) BusinessException(com.icthh.xm.commons.exceptions.BusinessException) Collections.emptyList(java.util.Collections.emptyList) PageRequest(org.springframework.data.domain.PageRequest) Set(java.util.Set) TypeSpec(com.icthh.xm.ms.entity.domain.spec.TypeSpec) LinkService(com.icthh.xm.ms.entity.service.LinkService) XmEntitySearchRepository(com.icthh.xm.ms.entity.repository.search.XmEntitySearchRepository) Page(org.springframework.data.domain.Page) Instant(java.time.Instant) Collectors(java.util.stream.Collectors) Slf4j(lombok.extern.slf4j.Slf4j) HttpEntity(org.springframework.http.HttpEntity) List(java.util.List) ProfileService(com.icthh.xm.ms.entity.service.ProfileService) XmEntitySpecService(com.icthh.xm.ms.entity.service.XmEntitySpecService) XmEntity(com.icthh.xm.ms.entity.domain.XmEntity) Specification(org.springframework.data.jpa.domain.Specification) Comment(com.icthh.xm.ms.entity.domain.Comment) Optional(java.util.Optional) XmAuthenticationContextHolder(com.icthh.xm.commons.security.XmAuthenticationContextHolder) CustomCollectionUtils.nullSafe(com.icthh.xm.ms.entity.util.CustomCollectionUtils.nullSafe) Constants(com.icthh.xm.ms.entity.config.Constants) XmEntityTypeKeyResolver(com.icthh.xm.ms.entity.lep.keyresolver.XmEntityTypeKeyResolver) XmEntityIdKeyTypeKey(com.icthh.xm.ms.entity.projection.XmEntityIdKeyTypeKey) Callable(java.util.concurrent.Callable) LepService(com.icthh.xm.commons.lep.spring.LepService) ModelMapper(org.modelmapper.ModelMapper) XmEntityStateProjection(com.icthh.xm.ms.entity.projection.XmEntityStateProjection) Propagation(org.springframework.transaction.annotation.Propagation) SimpleExportXmEntityDto(com.icthh.xm.ms.entity.domain.SimpleExportXmEntityDto) EntityNotFoundException(com.icthh.xm.commons.exceptions.EntityNotFoundException) IdOrKey(com.icthh.xm.ms.entity.domain.ext.IdOrKey) AttachmentService(com.icthh.xm.ms.entity.service.AttachmentService) SEARCH_BUILDER_TYPE(com.icthh.xm.ms.entity.domain.spec.LinkSpec.SEARCH_BUILDER_TYPE) Rating(com.icthh.xm.ms.entity.domain.Rating) Iterator(java.util.Iterator) Optional.ofNullable(java.util.Optional.ofNullable) ErrorConstants(com.icthh.xm.commons.exceptions.ErrorConstants) LifecycleLepStrategyFactory(com.icthh.xm.ms.entity.service.LifecycleLepStrategyFactory) ObjectUtils(org.springframework.util.ObjectUtils) LinkSpec(com.icthh.xm.ms.entity.domain.spec.LinkSpec) Attachment(com.icthh.xm.ms.entity.domain.Attachment) Tag(com.icthh.xm.ms.entity.domain.Tag) Location(com.icthh.xm.ms.entity.domain.Location) Consumer(java.util.function.Consumer) StateSpec(com.icthh.xm.ms.entity.domain.spec.StateSpec) XmEntityPermittedSearchRepository(com.icthh.xm.ms.entity.repository.search.XmEntityPermittedSearchRepository) XmEntityRepository(com.icthh.xm.ms.entity.repository.XmEntityRepository) Calendar(com.icthh.xm.ms.entity.domain.Calendar) MultipartFile(org.springframework.web.multipart.MultipartFile) NEW_BUILDER_TYPE(com.icthh.xm.ms.entity.domain.spec.LinkSpec.NEW_BUILDER_TYPE) Collections(java.util.Collections) Transactional(org.springframework.transaction.annotation.Transactional) PageRequest(org.springframework.data.domain.PageRequest) BusinessException(com.icthh.xm.commons.exceptions.BusinessException) SimpleExportXmEntityDto(com.icthh.xm.ms.entity.domain.SimpleExportXmEntityDto) XmEntity(com.icthh.xm.ms.entity.domain.XmEntity) ModelMapper(org.modelmapper.ModelMapper) LogicExtensionPoint(com.icthh.xm.commons.lep.LogicExtensionPoint)

Example 28 with ModelMapper

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));
}
Also used : SimpleExportXmEntityDto(com.icthh.xm.ms.entity.domain.SimpleExportXmEntityDto) ModelMapper(org.modelmapper.ModelMapper) Test(org.junit.Test)

Example 29 with ModelMapper

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;
}
Also used : UacMenu(com.paascloud.provider.model.domain.UacMenu) UacBizException(com.paascloud.provider.model.exceptions.UacBizException) ViewMenuVo(com.paascloud.provider.model.vo.ViewMenuVo) ModelMapper(org.modelmapper.ModelMapper) Transactional(org.springframework.transaction.annotation.Transactional)

Example 30 with ModelMapper

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);
}
Also used : UacUser(com.paascloud.provider.model.domain.UacUser) UserAgent(eu.bitwalker.useragentutils.UserAgent) UacUserToken(com.paascloud.provider.model.domain.UacUserToken) UserTokenDto(com.paascloud.base.dto.UserTokenDto) OAuth2ClientProperties(com.paascloud.security.core.properties.OAuth2ClientProperties) ModelMapper(org.modelmapper.ModelMapper)

Aggregations

ModelMapper (org.modelmapper.ModelMapper)78 ArrayList (java.util.ArrayList)16 Date (java.util.Date)5 Actor (com.management.entities.Actor)4 CinemaTheatre (com.management.entities.CinemaTheatre)4 Event (com.management.entities.Event)4 Hall (com.management.entities.Hall)4 Performance (com.management.entities.Performance)4 Props (com.management.entities.Props)4 Seat (com.management.entities.Seat)4 User (com.management.entities.User)4 Actorperformances (com.management.entities.Actorperformances)3 FanZone (com.management.entities.FanZone)3 Friendslist (com.management.entities.Friendslist)3 History (com.management.entities.History)3 OmcOrder (com.paascloud.provider.model.domain.OmcOrder)3 UacUserToken (com.paascloud.provider.model.domain.UacUserToken)3 Transactional (org.springframework.transaction.annotation.Transactional)3 SimpleExportXmEntityDto (com.icthh.xm.ms.entity.domain.SimpleExportXmEntityDto)2 ActorDTO (com.management.dto.ActorDTO)2