Search in sources :

Example 1 with CostRecord

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

the class AlipayBillCsvConvertServiceImpl method convertPOJO2String.

@Override
public List<String> convertPOJO2String(List<CostRecord> recordList) {
    List<String> result = new ArrayList<>();
    RecordRefUtil utl = new RecordRefUtil();
    result.add(BACKUP_FLAG);
    try {
        for (CostRecord costRecord : recordList) {
            result.add(utl.convertPOJO2String(costRecord));
        }
    } catch (IllegalAccessException e) {
        logger.error("转换对象到csv文本失败", e);
    }
    return result;
}
Also used : CostRecord(com.tony.billing.entity.CostRecord) ArrayList(java.util.ArrayList)

Example 2 with CostRecord

use of com.tony.billing.entity.CostRecord 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 3 with CostRecord

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

the class TagInfoController method putCostTag.

/**
 * 添加账单标签
 *
 * @param request
 * @return
 */
@RequestMapping(value = "/cost/tag/put")
public BaseResponse putCostTag(@ModelAttribute("request") @Validated CostTagPutRequest request) {
    BaseResponse response = new BaseResponse();
    try {
        CostRecord costRecord = costRecordService.findByTradeNo(request.getTradeNo(), request.getUserId());
        TagInfo tagInfo = tagInfoService.getTagInfoById(request.getTagId());
        if (costRecord != null && tagInfo != null) {
            TagCostRef ref = new TagCostRef();
            ref.setCostId(costRecord.getId());
            ref.setTagId(tagInfo.getId());
            if (tagInfoService.insertTagCostRef(ref) > 0) {
                ResponseUtil.success(response);
            } else {
                ResponseUtil.error(response);
            }
        } else {
            ResponseUtil.paramError(response);
        }
    } catch (Exception e) {
        logger.error("/cost/tag/put error", e);
        ResponseUtil.sysError(response);
    }
    return response;
}
Also used : BaseResponse(com.tony.billing.response.BaseResponse) CostRecord(com.tony.billing.entity.CostRecord) TagInfo(com.tony.billing.entity.TagInfo) TagCostRef(com.tony.billing.entity.TagCostRef) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 4 with CostRecord

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

the class CostRecordController method putDetail.

/**
 * 添加消费记录
 *
 * @param request
 * @return
 */
@RequestMapping(value = "/record/put")
public BaseResponse putDetail(@ModelAttribute("request") @Validated CostRecordPutRequest request) {
    BaseResponse response = new BaseResponse();
    try {
        CostRecord record = new CostRecord();
        record.setTradeStatus(TradeStatus.TRADE_SUCCESS);
        record.setTradeNo(generateTradeNo(request.getCreateTime()));
        record.setTarget(request.getTarget());
        record.setPaidTime(request.getCreateTime());
        record.setOrderType(request.getOrderType());
        record.setMoney(MoneyUtil.yuan2fen(request.getMoney()));
        record.setCostCreateTime(request.getCreateTime());
        record.setIsDeleted(0);
        record.setOrderStatus(TradeStatus.TRADE_SUCCESS);
        record.setInOutType(request.getInOutType());
        record.setMemo(request.getMemo());
        record.setGoodsName(request.getMemo());
        record.setLocation(request.getLocation());
        record.setUserId(request.getUserId());
        if (costRecordService.orderPut(record) > 0) {
            ResponseUtil.success(response);
        } else {
            ResponseUtil.error(response);
        }
    } catch (Exception e) {
        logger.error("/record/put error", e);
        ResponseUtil.sysError(response);
    }
    return response;
}
Also used : BaseResponse(com.tony.billing.response.BaseResponse) CostRecord(com.tony.billing.entity.CostRecord) ParseException(java.text.ParseException) IOException(java.io.IOException) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 5 with CostRecord

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

the class CostRecordController method getDetail.

/**
 * 获取详情
 *
 * @param request
 * @return
 */
@RequestMapping(value = "/record/detail/get")
public CostRecordDetailResponse getDetail(@ModelAttribute("request") @Validated CostRecordDetailRequest request) {
    CostRecordDetailResponse response = new CostRecordDetailResponse();
    ResponseUtil.error(response);
    try {
        CostRecord record = costRecordService.findByTradeNo(request.getTradeNo(), request.getUserId());
        if (record != null) {
            response.setRecordDetail(formatDetailModel(record));
            ResponseUtil.success(response);
        }
    } catch (Exception e) {
        logger.error("/detail/get error", e);
    }
    return response;
}
Also used : CostRecord(com.tony.billing.entity.CostRecord) CostRecordDetailResponse(com.tony.billing.response.costrecord.CostRecordDetailResponse) ParseException(java.text.ParseException) IOException(java.io.IOException) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

CostRecord (com.tony.billing.entity.CostRecord)11 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)6 TagInfo (com.tony.billing.entity.TagInfo)4 BaseResponse (com.tony.billing.response.BaseResponse)4 IOException (java.io.IOException)3 ArrayList (java.util.ArrayList)3 ParseException (java.text.ParseException)2 InOutType (com.tony.billing.constants.InOutType)1 EnumDeleted (com.tony.billing.constants.enums.EnumDeleted)1 EnumHidden (com.tony.billing.constants.enums.EnumHidden)1 CostReportMapper (com.tony.billing.dao.mapper.CostReportMapper)1 BudgetReportItemDTO (com.tony.billing.dto.BudgetReportItemDTO)1 CostRecordDTO (com.tony.billing.dto.CostRecordDTO)1 TagCostInfoDTO (com.tony.billing.dto.TagCostInfoDTO)1 Budget (com.tony.billing.entity.Budget)1 RawReportEntity (com.tony.billing.entity.RawReportEntity)1 ReportEntity (com.tony.billing.entity.ReportEntity)1 TagCostRef (com.tony.billing.entity.TagCostRef)1 ReportEntityQuery (com.tony.billing.entity.query.ReportEntityQuery)1 BudgetReportModel (com.tony.billing.model.BudgetReportModel)1