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;
}
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;
}
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;
}
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;
}
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;
}
Aggregations