Search in sources :

Example 1 with TagBudgetRef

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

the class TagInfoController method putBudgetTag.

@RequestMapping("/budget/tag/put")
public BaseResponse putBudgetTag(@Validated @ModelAttribute("request") BudgetTagPutRequest request) {
    TagBudgetRef ref = new TagBudgetRef();
    ref.setTagId(request.getTagId());
    ref.setBudgetId(request.getBudgetId());
    return tagInfoService.insertTagBudgetRef(ref) > 0 ? ResponseUtil.success() : ResponseUtil.error();
}
Also used : TagBudgetRef(com.tony.billing.entity.TagBudgetRef) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 2 with TagBudgetRef

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

TagBudgetRef (com.tony.billing.entity.TagBudgetRef)2 Preconditions (com.google.common.base.Preconditions)1 EnumDeleted (com.tony.billing.constants.enums.EnumDeleted)1 EnumOwnershipCheckTables (com.tony.billing.constraints.enums.EnumOwnershipCheckTables)1 BudgetMapper (com.tony.billing.dao.mapper.BudgetMapper)1 BudgetTagMapper (com.tony.billing.dao.mapper.BudgetTagMapper)1 CostTagMapper (com.tony.billing.dao.mapper.CostTagMapper)1 TagInfoMapper (com.tony.billing.dao.mapper.TagInfoMapper)1 TagInfoDTO (com.tony.billing.dto.TagInfoDTO)1 Budget (com.tony.billing.entity.Budget)1 TagCostRef (com.tony.billing.entity.TagCostRef)1 TagInfo (com.tony.billing.entity.TagInfo)1 TagInfoToDtoListSupplier (com.tony.billing.functions.TagInfoToDtoListSupplier)1 CommonValidateService (com.tony.billing.service.api.CommonValidateService)1 TagInfoService (com.tony.billing.service.api.TagInfoService)1 AbstractServiceImpl (com.tony.billing.service.base.AbstractServiceImpl)1 UserIdContainer (com.tony.billing.util.UserIdContainer)1 Date (java.util.Date)1 HashMap (java.util.HashMap)1 List (java.util.List)1