Search in sources :

Example 1 with TagInfo

use of com.tony.billing.entity.TagInfo in project BillingDubbo by TonyJiangWJ.

the class BudgetServiceImpl method getBudgetReportByMonth.

@Override
public BudgetReportModel getBudgetReportByMonth(String monthInfo, Long userId) {
    Preconditions.checkState(YEAR_MONTH_PATTERN.matcher(monthInfo).find(), "参数错误");
    BudgetReportModel reportInfo = new BudgetReportModel();
    reportInfo.setYearMonthInfo(monthInfo);
    String year = monthInfo.substring(0, 4);
    Integer month = NumberUtils.toInt(monthInfo.substring(5));
    Budget query = new Budget();
    query.setBelongYear(year);
    query.setBelongMonth(month);
    query.setUserId(userId);
    List<Budget> budgets = mapper.findByYearMonth(query);
    if (CollectionUtils.isNotEmpty(budgets)) {
        List<Long> monthTagIds = tagInfoMapper.listTagIdsByBudgetMonth(year, month, userId, null);
        List<CostRecord> noBudgetRecords = costRecordMapper.listByMonthAndExceptTagIds(monthInfo, userId, monthTagIds);
        if (CollectionUtils.isNotEmpty(noBudgetRecords)) {
            reportInfo.setNoBudgetUsed(noBudgetRecords.stream().mapToLong(CostRecord::getMoney).sum());
        } else {
            logger.info("[{}] 未关联预算账单数据不存在", monthInfo);
        }
        List<CostRecord> budgetRecords = costRecordMapper.listByMonthAndTagIds(monthInfo, userId, monthTagIds);
        if (CollectionUtils.isNotEmpty(budgetRecords)) {
            reportInfo.setBudgetUsed(budgetRecords.stream().mapToLong(CostRecord::getMoney).sum());
        } else {
            logger.info("[{}] 预算关联账单数据不存在", monthInfo);
        }
        budgets.forEach(b -> {
            List<TagInfo> budgetTags = tagInfoMapper.listTagInfoByBudgetId(b.getId(), userId);
            Long sum = 0L;
            BudgetReportItemDTO item = new BudgetReportItemDTO();
            List<CostRecord> costRecords = new ArrayList<>();
            if (CollectionUtils.isNotEmpty(budgetTags)) {
                item.setTagInfos(budgetTags.parallelStream().map(tag -> {
                    TagCostInfoDTO costInfoDTO = new TagCostInfoDTO();
                    List<CostRecord> tagCostRecords = costRecordMapper.listByMonthAndTagIds(monthInfo, userId, Collections.singletonList(tag.getId()));
                    if (CollectionUtils.isNotEmpty(tagCostRecords)) {
                        costInfoDTO.setAmount(tagCostRecords.stream().mapToLong(CostRecord::getMoney).sum());
                        costRecords.addAll(tagCostRecords);
                    }
                    costInfoDTO.setTagId(tag.getId());
                    costInfoDTO.setTagName(tag.getTagName());
                    return costInfoDTO;
                }).collect(Collectors.toList()));
            }
            item.setVersion(b.getVersion());
            item.setId(b.getId());
            item.setName(b.getBudgetName());
            item.setAmount(b.getBudgetMoney());
            if (CollectionUtils.isNotEmpty(costRecords)) {
                sum = costRecords.parallelStream().distinct().mapToLong(CostRecord::getMoney).sum();
            }
            item.setUsed(sum);
            item.setRemain(b.getBudgetMoney() - sum);
            reportInfo.addBudgetInfos(item);
        });
        return reportInfo.build();
    }
    return null;
}
Also used : TagCostInfoDTO(com.tony.billing.dto.TagCostInfoDTO) ArrayList(java.util.ArrayList) CostRecord(com.tony.billing.entity.CostRecord) BudgetReportItemDTO(com.tony.billing.dto.BudgetReportItemDTO) TagInfo(com.tony.billing.entity.TagInfo) Budget(com.tony.billing.entity.Budget) BudgetReportModel(com.tony.billing.model.BudgetReportModel)

Example 2 with TagInfo

use of com.tony.billing.entity.TagInfo in project BillingDubbo by TonyJiangWJ.

the class BudgetServiceImpl method queryBudgetsByCondition.

@Override
public List<BudgetDTO> queryBudgetsByCondition(Budget condition) {
    Preconditions.checkNotNull(condition.getUserId(), "userId must not be null");
    Preconditions.checkNotNull(condition.getBelongMonth(), "month must not be null");
    Preconditions.checkNotNull(condition.getBelongYear(), "year must not be null");
    List<Budget> budgets = mapper.findByYearMonth(condition);
    return budgets.stream().map((budget) -> {
        BudgetDTO dto = new BudgetDTO();
        dto.setId(budget.getId());
        dto.setBudgetName(budget.getBudgetName());
        dto.setBudgetMoney(MoneyUtil.fen2Yuan(budget.getBudgetMoney()));
        dto.setYearMonth(YearMonth.of(Integer.parseInt(budget.getBelongYear()), budget.getBelongMonth()).format(DateTimeFormatter.ofPattern("yyyy-MM")));
        List<TagInfo> tagInfos = tagInfoMapper.listTagInfoByBudgetId(budget.getId(), budget.getUserId());
        dto.setTagInfos(new TagInfoToDtoListSupplier(tagInfos).get());
        return dto;
    }).collect(Collectors.toList());
}
Also used : RedisUtils(com.tony.billing.util.RedisUtils) LoggerFactory(org.slf4j.LoggerFactory) UserIdContainer(com.tony.billing.util.UserIdContainer) StringUtils(org.apache.commons.lang3.StringUtils) ArrayList(java.util.ArrayList) BudgetService(com.tony.billing.service.api.BudgetService) CollectionUtils(org.apache.commons.collections.CollectionUtils) CostRecordMapper(com.tony.billing.dao.mapper.CostRecordMapper) MoneyUtil(com.tony.billing.util.MoneyUtil) TagInfoToDtoListSupplier(com.tony.billing.functions.TagInfoToDtoListSupplier) AbstractServiceImpl(com.tony.billing.service.base.AbstractServiceImpl) Service(org.apache.dubbo.config.annotation.Service) TagInfoMapper(com.tony.billing.dao.mapper.TagInfoMapper) TagCostInfoDTO(com.tony.billing.dto.TagCostInfoDTO) BudgetReportModel(com.tony.billing.model.BudgetReportModel) TagInfo(com.tony.billing.entity.TagInfo) Logger(org.slf4j.Logger) Resource(javax.annotation.Resource) BudgetDTO(com.tony.billing.dto.BudgetDTO) Collectors(java.util.stream.Collectors) TimeConstants(com.tony.billing.constants.timing.TimeConstants) CostRecord(com.tony.billing.entity.CostRecord) Objects(java.util.Objects) List(java.util.List) Budget(com.tony.billing.entity.Budget) LocalDate(java.time.LocalDate) DateTimeFormatter(java.time.format.DateTimeFormatter) BudgetReportItemDTO(com.tony.billing.dto.BudgetReportItemDTO) NumberUtils(org.apache.commons.lang3.math.NumberUtils) YearMonth(java.time.YearMonth) Optional(java.util.Optional) Preconditions(com.google.common.base.Preconditions) Pattern(java.util.regex.Pattern) BudgetMapper(com.tony.billing.dao.mapper.BudgetMapper) Comparator(java.util.Comparator) TagInfoDTO(com.tony.billing.dto.TagInfoDTO) Collections(java.util.Collections) Budget(com.tony.billing.entity.Budget) ArrayList(java.util.ArrayList) List(java.util.List) TagInfoToDtoListSupplier(com.tony.billing.functions.TagInfoToDtoListSupplier) BudgetDTO(com.tony.billing.dto.BudgetDTO)

Example 3 with TagInfo

use of com.tony.billing.entity.TagInfo in project BillingDubbo by TonyJiangWJ.

the class TagInfoServiceImpl method listCommonTagInfos.

@Override
public List<TagInfoDTO> listCommonTagInfos(List<Long> recordIds) {
    Preconditions.checkState(CollectionUtils.isNotEmpty(recordIds));
    List<TagInfo> commonTags = mapper.listCommonTagInfos(recordIds, recordIds.size());
    return new TagInfoToDtoListSupplier(commonTags).get();
}
Also used : TagInfo(com.tony.billing.entity.TagInfo) TagInfoToDtoListSupplier(com.tony.billing.functions.TagInfoToDtoListSupplier)

Example 4 with TagInfo

use of com.tony.billing.entity.TagInfo in project BillingDubbo by TonyJiangWJ.

the class TagInfoController method listTag.

/**
 * 列出所有标签
 *
 * @param request
 * @return
 */
@RequestMapping(value = "/tag/list")
public TagInfoListResponse listTag(@ModelAttribute("request") BaseRequest request) {
    TagInfoListResponse response = new TagInfoListResponse();
    TagInfo tagInfo = new TagInfo();
    tagInfo.setUserId(request.getUserId());
    List<TagInfo> tagInfos = tagInfoService.listTagInfo(tagInfo);
    if (!CollectionUtils.isEmpty(tagInfos)) {
        response.setTagInfoList(tagInfos.parallelStream().map(tag -> {
            TagInfoDTO model = new TagInfoDTO();
            model.setTagName(tag.getTagName());
            model.setTagId(tag.getId());
            model.setUsageCount(tagInfoService.countTagUsage(tag.getId(), request.getUserId()));
            return model;
        }).sorted(Comparator.comparing(TagInfoDTO::getUsageCount).reversed()).collect(Collectors.toList()));
    }
    ResponseUtil.success(response);
    return response;
}
Also used : RequestParam(org.springframework.web.bind.annotation.RequestParam) BudgetTagAssignableListRequest(com.tony.billing.request.taginfo.BudgetTagAssignableListRequest) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) CostTagListResponse(com.tony.billing.response.taginfo.CostTagListResponse) ArrayList(java.util.ArrayList) ResponseUtil(com.tony.billing.util.ResponseUtil) BaseRequest(com.tony.billing.request.BaseRequest) BaseResponse(com.tony.billing.response.BaseResponse) ModelAttribute(org.springframework.web.bind.annotation.ModelAttribute) TagInfoToDtoListSupplier(com.tony.billing.functions.TagInfoToDtoListSupplier) CostRecordService(com.tony.billing.service.api.CostRecordService) CostTagBatchOperateRequest(com.tony.billing.request.taginfo.CostTagBatchOperateRequest) TagInfoService(com.tony.billing.service.api.TagInfoService) TagInfo(com.tony.billing.entity.TagInfo) BudgetTagDelRequest(com.tony.billing.request.taginfo.BudgetTagDelRequest) TagInfoPutRequest(com.tony.billing.request.taginfo.TagInfoPutRequest) Validated(org.springframework.validation.annotation.Validated) TagCostRef(com.tony.billing.entity.TagCostRef) Reference(org.apache.dubbo.config.annotation.Reference) BudgetTagPutRequest(com.tony.billing.request.taginfo.BudgetTagPutRequest) TagInfoDelRequest(com.tony.billing.request.taginfo.TagInfoDelRequest) RestController(org.springframework.web.bind.annotation.RestController) Collectors(java.util.stream.Collectors) CostRecord(com.tony.billing.entity.CostRecord) CostTagListRequest(com.tony.billing.request.taginfo.CostTagListRequest) CommunalTagsRequest(com.tony.billing.request.taginfo.CommunalTagsRequest) List(java.util.List) CollectionUtils(org.springframework.util.CollectionUtils) TagBudgetRef(com.tony.billing.entity.TagBudgetRef) CostTagDelRequest(com.tony.billing.request.taginfo.CostTagDelRequest) Comparator(java.util.Comparator) TagInfoDTO(com.tony.billing.dto.TagInfoDTO) TagInfoListResponse(com.tony.billing.response.taginfo.TagInfoListResponse) CostTagPutRequest(com.tony.billing.request.taginfo.CostTagPutRequest) TagInfoListResponse(com.tony.billing.response.taginfo.TagInfoListResponse) TagInfo(com.tony.billing.entity.TagInfo) TagInfoDTO(com.tony.billing.dto.TagInfoDTO) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 5 with TagInfo

use of com.tony.billing.entity.TagInfo in project BillingDubbo by TonyJiangWJ.

the class TagInfoController method listCostTag.

/**
 * 列出账单赋值的标签
 *
 * @param request
 * @return
 */
@RequestMapping(value = "/cost/tag/list")
public CostTagListResponse listCostTag(@ModelAttribute("request") @Validated CostTagListRequest request) {
    CostTagListResponse response = new CostTagListResponse();
    try {
        List<TagInfo> costTagList = tagInfoService.listTagInfoByTradeNo(request.getTradeNo());
        TagInfoDTO model;
        List<TagInfoDTO> result = new ArrayList<>();
        for (TagInfo entity : costTagList) {
            model = new TagInfoDTO();
            model.setTagName(entity.getTagName());
            model.setTagId(entity.getId());
            result.add(model);
        }
        if (!CollectionUtils.isEmpty(result)) {
            response.setTagInfoModels(result);
            ResponseUtil.success(response);
        } else {
            ResponseUtil.dataNotExisting(response);
        }
    } catch (Exception e) {
        ResponseUtil.sysError(response);
        logger.error("/cost/tag/list error", e);
    }
    return response;
}
Also used : CostTagListResponse(com.tony.billing.response.taginfo.CostTagListResponse) TagInfo(com.tony.billing.entity.TagInfo) ArrayList(java.util.ArrayList) TagInfoDTO(com.tony.billing.dto.TagInfoDTO) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

TagInfo (com.tony.billing.entity.TagInfo)13 CostRecord (com.tony.billing.entity.CostRecord)6 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)6 TagInfoDTO (com.tony.billing.dto.TagInfoDTO)5 TagInfoToDtoListSupplier (com.tony.billing.functions.TagInfoToDtoListSupplier)5 ArrayList (java.util.ArrayList)5 BaseResponse (com.tony.billing.response.BaseResponse)4 Budget (com.tony.billing.entity.Budget)3 TagCostRef (com.tony.billing.entity.TagCostRef)3 List (java.util.List)3 Collectors (java.util.stream.Collectors)3 Preconditions (com.google.common.base.Preconditions)2 BudgetMapper (com.tony.billing.dao.mapper.BudgetMapper)2 TagInfoMapper (com.tony.billing.dao.mapper.TagInfoMapper)2 BudgetReportItemDTO (com.tony.billing.dto.BudgetReportItemDTO)2 TagCostInfoDTO (com.tony.billing.dto.TagCostInfoDTO)2 TagBudgetRef (com.tony.billing.entity.TagBudgetRef)2 BudgetReportModel (com.tony.billing.model.BudgetReportModel)2 CostTagListResponse (com.tony.billing.response.taginfo.CostTagListResponse)2 TagInfoListResponse (com.tony.billing.response.taginfo.TagInfoListResponse)2