Search in sources :

Example 6 with CostRecord

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

the class CostRecordController method backUp.

@RequestMapping("/record/backup/csv/get")
public void backUp(HttpServletResponse response, @ModelAttribute("request") BaseRequest request) {
    CostRecord requestParam = new CostRecord();
    requestParam.setUserId(request.getUserId());
    List<CostRecord> records = costRecordService.find(requestParam);
    List<String> result = alipayBillCsvUtil.convertPOJO2String(records);
    OutputStreamWriter outputStreamWriter = null;
    BufferedWriter bufferedWriter = null;
    try {
        response.reset();
        response.setContentType("application/octet-stream; charset=utf-8");
        response.setHeader("Content-Disposition", "attachment; filename=" + "backup" + LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyyMMddHHmmss")) + ".csv");
        OutputStream outputStream = response.getOutputStream();
        outputStreamWriter = new OutputStreamWriter(outputStream, "GBK");
        bufferedWriter = new BufferedWriter(outputStreamWriter);
        for (String rs : result) {
            bufferedWriter.write(rs);
            bufferedWriter.newLine();
        }
        bufferedWriter.flush();
        bufferedWriter.close();
        outputStream.close();
    } catch (IOException e) {
        logger.error("创建备份文件失败", e);
    }
}
Also used : CostRecord(com.tony.billing.entity.CostRecord) OutputStream(java.io.OutputStream) OutputStreamWriter(java.io.OutputStreamWriter) IOException(java.io.IOException) BufferedWriter(java.io.BufferedWriter) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 7 with CostRecord

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

the class CostRecordController method formatModelList.

private List<CostRecordDTO> formatModelList(List<CostRecord> list, boolean showTags) {
    if (!CollectionUtils.isEmpty(list)) {
        List<CostRecordDTO> models = new ArrayList<>();
        CostRecordDTO model;
        List<TagInfo> tagInfos;
        for (CostRecord entity : list) {
            model = new CostRecordDTO();
            model.setId(entity.getId());
            model.setCreateTime(entity.getCostCreateTime());
            model.setGoodsName(entity.getGoodsName());
            model.setInOutType(entity.getInOutType());
            model.setIsDeleted(entity.getIsDeleted());
            model.setMoney(MoneyUtil.fen2Yuan(entity.getMoney()));
            model.setLocation(entity.getLocation());
            model.setOrderStatus(entity.getOrderStatus());
            model.setOrderType(entity.getOrderType());
            model.setTradeNo(entity.getTradeNo());
            model.setTarget(entity.getTarget());
            model.setMemo(entity.getMemo());
            model.setIsHidden(entity.getIsHidden());
            if (showTags) {
                tagInfos = tagInfoService.listTagInfoByTradeNo(entity.getTradeNo());
                if (!CollectionUtils.isEmpty(tagInfos)) {
                    model.setTags(tagInfos.stream().map(TagInfo::getTagName).collect(Collectors.toList()));
                }
            }
            models.add(model);
        }
        return models;
    } else {
        return null;
    }
}
Also used : CostRecord(com.tony.billing.entity.CostRecord) TagInfo(com.tony.billing.entity.TagInfo) ArrayList(java.util.ArrayList) CostRecordDTO(com.tony.billing.dto.CostRecordDTO)

Example 8 with CostRecord

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

the class CostRecordController method updateRecord.

/**
 * 修改消费记录
 *
 * @param request
 * @return
 */
@RequestMapping(value = "/record/update")
public BaseResponse updateRecord(@ModelAttribute("request") @Validated CostRecordUpdateRequest request) {
    BaseResponse response = new BaseResponse();
    CostRecord record = new CostRecord();
    record.setLocation(request.getLocation());
    record.setGoodsName(request.getGoodsName());
    record.setMemo(request.getMemo());
    record.setTradeNo(request.getTradeNo());
    record.setUserId(request.getUserId());
    record.setOrderType(request.getOrderType());
    record.setVersion(request.getVersion());
    if (costRecordService.updateByTradeNo(record) > 0) {
        return ResponseUtil.success(response);
    }
    return ResponseUtil.error(response);
}
Also used : BaseResponse(com.tony.billing.response.BaseResponse) CostRecord(com.tony.billing.entity.CostRecord) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 9 with CostRecord

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

the class AlipayBillCsvConvertServiceImpl method convertToDoForInsert.

private CostRecord convertToDoForInsert(Record entity, Long userId) {
    if (entity == null) {
        return null;
    }
    CostRecord record = new CostRecord();
    record.setIsDeleted(0);
    record.setCostCreateTime(entity.getCreateTime());
    record.setGoodsName(entity.getGoodsName());
    record.setInOutType(entity.getInOutType());
    record.setLocation(entity.getLocation());
    record.setMemo(entity.getMemo());
    record.setCostModifyTime(entity.getModifyTime());
    record.setMoney(MoneyUtil.yuan2fen(entity.getMoney()));
    record.setOrderNo(entity.getOrderNo());
    record.setOrderStatus(entity.getOrderStatus());
    record.setOrderType(entity.getOrderType());
    record.setPaidTime(entity.getPaidTime());
    record.setRefundMoney(MoneyUtil.yuan2fen(entity.getRefundMoney()));
    record.setServiceCost(MoneyUtil.yuan2fen(entity.getServiceCost()));
    record.setTarget(entity.getTarget());
    record.setTradeNo(entity.getTradeNo());
    record.setTradeStatus(entity.getTradeStatus());
    record.setUserId(userId);
    record.setVersion(0);
    record.setIsHidden(EnumHidden.NOT_HIDDEN.val());
    record.setIsDeleted(EnumDeleted.NOT_DELETED.val());
    record.setCreateTime(new Date());
    record.setModifyTime(new Date());
    return record;
}
Also used : CostRecord(com.tony.billing.entity.CostRecord) Date(java.util.Date)

Example 10 with CostRecord

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

the class TagInfoController method delCostTag.

/**
 * 删除账单标签
 *
 * @param request
 * @return
 */
@RequestMapping(value = "/cost/tag/delete")
public BaseResponse delCostTag(@ModelAttribute("request") @Validated CostTagDelRequest 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) {
            if (tagInfoService.deleteCostTag(costRecord.getId(), tagInfo.getId())) {
                ResponseUtil.success(response);
            } else {
                ResponseUtil.error(response);
            }
        } else {
            ResponseUtil.paramError(response);
        }
    } catch (Exception e) {
        logger.error("/cost/tag/delete 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) 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