Subversion Repositories SmartDukaan

Rev

Rev 35394 | Blame | Compare with Previous | Last modification | View Log | RSS feed

package com.spice.profitmandi.dao.repository.cs;

import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
import com.spice.profitmandi.common.model.ProfitMandiConstants;
import com.spice.profitmandi.dao.entity.auth.AuthUser;
import com.spice.profitmandi.dao.entity.cs.Position;
import com.spice.profitmandi.dao.repository.auth.AuthRepository;
import com.spice.profitmandi.service.AuthService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;

@Component
public class CsService1Impl implements CsService1 {

    @Autowired
    AuthService authService;


    @Autowired
    AuthRepository authRepository;


    @Autowired
    CsService csService;

    @Autowired
    PositionRepository positionRepository;

    private static List<Integer> categoryIds = Arrays.asList(ProfitMandiConstants.TICKET_CATEGORY_LOGISTICS,
            ProfitMandiConstants.TICKET_CATEGORY_FINANCIAL_SERVICES, ProfitMandiConstants.TICKET_CATEGORY_CATEGORY,
            ProfitMandiConstants.TICKET_CATEGORY_RBM, ProfitMandiConstants.TICKET_CATEGORY_SALES, ProfitMandiConstants.TICKET_CATEGORY_ABM,
            ProfitMandiConstants.TICKET_CATEGORY_MARKETING, ProfitMandiConstants.TICKET_CATEGORY_ACCOUNTS,
            ProfitMandiConstants.TICKET_CATEGORY_BUSINESSINTELLIGENT, ProfitMandiConstants.TICKET_CATEGORY_STOCKS,
            ProfitMandiConstants.TICKET_CATEGORY_TECHNOLOGY, ProfitMandiConstants.TICKET_CATEGORY_TRAINING,ProfitMandiConstants.TICKET_CATEGORY_RECOVERY);

    @Override
    public Set<Integer> getAuthFofoIds(String email, boolean active) throws ProfitMandiBusinessException {
        Map<String, Set<Integer>> storeGuyMap = csService.getAuthUserPartnerIdMappingByCategoryIds(categoryIds, active);
        Set<Integer> authfofoIds = storeGuyMap.get(email);

        if (authfofoIds == null) {
            AuthUser authUser = authRepository.selectByEmailOrMobile(email);
            if (authUser != null) {
                List<Position> positions1 = positionRepository.selectAllByAuthUserId(authUser.getId());
                if (positions1.stream().anyMatch(x -> x.getCategoryId() == ProfitMandiConstants.TICKET_CATEGORY_MASTER)) {
                    authfofoIds = csService.getPositionCustomRetailerMap(positions1).values().stream().flatMap(x -> x.stream())
                            .map(x -> x.getPartnerId()).collect(Collectors.toSet());
                }
            }
        }
        return authfofoIds;
    }
}