Search in sources :

Example 11 with TagInfo

use of com.tony.billing.entity.TagInfo 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)

Example 12 with TagInfo

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

the class TagInfoServiceImpl method findTagInfoByName.

@Override
public TagInfo findTagInfoByName(String tagName) {
    TagInfo tagInfo = new TagInfo();
    tagInfo.setTagName(tagName);
    tagInfo.setUserId(UserIdContainer.getUserId());
    List<TagInfo> tagInfos = mapper.list(tagInfo);
    if (!CollectionUtils.isEmpty(tagInfos)) {
        return tagInfos.get(0);
    } else {
        return null;
    }
}
Also used : TagInfo(com.tony.billing.entity.TagInfo)

Example 13 with TagInfo

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

the class TagInfoServiceImpl method insertTagBudgetRef.

@Override
public Long insertTagBudgetRef(TagBudgetRef budgetRef) {
    Preconditions.checkNotNull(budgetRef.getBudgetId());
    Preconditions.checkNotNull(budgetRef.getTagId());
    budgetRef.setCreateTime(new Date());
    budgetRef.setModifyTime(new Date());
    if (budgetTagMapper.countByBudgetIdAndTagId(budgetRef.getBudgetId(), budgetRef.getTagId()) > 0) {
        logger.error("tag:{} 已经绑定到当前预算 budget:{}", budgetRef.getTagId(), budgetRef.getBudgetId());
        return -3L;
    }
    budgetRef.setIsDeleted(EnumDeleted.NOT_DELETED.val());
    TagInfo tagInfo = mapper.getTagInfoById(budgetRef.getTagId());
    Budget budget = budgetMapper.getById(budgetRef.getBudgetId(), UserIdContainer.getUserId());
    if (tagInfo != null && budget != null && tagInfo.getUserId().equals(UserIdContainer.getUserId())) {
        List<Long> boundTagsToThisMonth = mapper.listTagIdsByBudgetMonth(budget.getBelongYear(), budget.getBelongMonth(), UserIdContainer.getUserId(), budget.getId());
        if (CollectionUtils.isNotEmpty(boundTagsToThisMonth) && boundTagsToThisMonth.stream().anyMatch(tagId -> tagId.equals(tagInfo.getId()))) {
            logger.error("tag:{} 已经绑定到当月其他预算", tagInfo.getId());
            return -2L;
        }
        if (mapper.insertTagBudgetRef(budgetRef) > 0) {
            return budgetRef.getId();
        }
    }
    return -1L;
}
Also used : CommonValidateService(com.tony.billing.service.api.CommonValidateService) Date(java.util.Date) HashMap(java.util.HashMap) UserIdContainer(com.tony.billing.util.UserIdContainer) StringUtils(org.apache.commons.lang3.StringUtils) BudgetTagMapper(com.tony.billing.dao.mapper.BudgetTagMapper) EnumDeleted(com.tony.billing.constants.enums.EnumDeleted) CollectionUtils(org.apache.commons.collections.CollectionUtils) Map(java.util.Map) 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) TagInfoService(com.tony.billing.service.api.TagInfoService) TagInfo(com.tony.billing.entity.TagInfo) EnumOwnershipCheckTables(com.tony.billing.constraints.enums.EnumOwnershipCheckTables) Resource(javax.annotation.Resource) TagCostRef(com.tony.billing.entity.TagCostRef) Collectors(java.util.stream.Collectors) List(java.util.List) CostTagMapper(com.tony.billing.dao.mapper.CostTagMapper) Budget(com.tony.billing.entity.Budget) Preconditions(com.google.common.base.Preconditions) BudgetMapper(com.tony.billing.dao.mapper.BudgetMapper) TagBudgetRef(com.tony.billing.entity.TagBudgetRef) TagInfoDTO(com.tony.billing.dto.TagInfoDTO) TagInfo(com.tony.billing.entity.TagInfo) Budget(com.tony.billing.entity.Budget) Date(java.util.Date)

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