Subversion Repositories SmartDukaan

Rev

Rev 35626 | Rev 35635 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 35626 Rev 35631
Line 12... Line 12...
12
import com.spice.profitmandi.dao.enumuration.cs.EscalationType;
12
import com.spice.profitmandi.dao.enumuration.cs.EscalationType;
13
import com.spice.profitmandi.dao.model.*;
13
import com.spice.profitmandi.dao.model.*;
14
import com.spice.profitmandi.dao.repository.auth.AuthRepository;
14
import com.spice.profitmandi.dao.repository.auth.AuthRepository;
15
import com.spice.profitmandi.dao.repository.dtr.FofoStoreRepository;
15
import com.spice.profitmandi.dao.repository.dtr.FofoStoreRepository;
16
import com.spice.profitmandi.service.user.RetailerService;
16
import com.spice.profitmandi.service.user.RetailerService;
17
import com.spice.profitmandi.dao.entity.cs.TicketReadStatus;
-
 
18
import com.spice.profitmandi.dao.entity.cs.TicketReadStatus.UserType;
-
 
19
import com.spice.profitmandi.service.EmailService;
-
 
20
import org.apache.commons.collections4.map.HashedMap;
17
import org.apache.commons.collections4.map.HashedMap;
21
import org.apache.commons.lang.RandomStringUtils;
18
import org.apache.commons.lang.RandomStringUtils;
22
import org.apache.commons.lang.StringUtils;
19
import org.apache.commons.lang.StringUtils;
23
import org.apache.logging.log4j.LogManager;
20
import org.apache.logging.log4j.LogManager;
24
import org.apache.logging.log4j.Logger;
21
import org.apache.logging.log4j.Logger;
Line 89... Line 86...
89
    private FofoStoreRepository fofoStoreRepository;
86
    private FofoStoreRepository fofoStoreRepository;
90
 
87
 
91
    @Autowired
88
    @Autowired
92
    private SessionFactory sessionFactory;
89
    private SessionFactory sessionFactory;
93
 
90
 
94
    @Autowired
-
 
95
    private TicketReadStatusRepository ticketReadStatusRepository;
-
 
96
 
-
 
97
    @Autowired
-
 
98
    private EmailService emailService;
-
 
99
 
-
 
100
    @Override
91
    @Override
101
    public void createTicket(int fofoId, int categoryId, int subcategoryId, String message) throws ProfitMandiBusinessException {
92
    public void createTicket(int fofoId, int categoryId, int subcategoryId, String message) throws ProfitMandiBusinessException {
102
        this.createTicket(fofoId, categoryId, subcategoryId, message, 0);
93
        this.createTicket(fofoId, categoryId, subcategoryId, message, 0);
103
    }
94
    }
104
 
95
 
Line 487... Line 478...
487
    @Override
478
    @Override
488
    public void addActivity(Ticket ticket, Activity activity) {
479
    public void addActivity(Ticket ticket, Activity activity) {
489
        activity.setTicketId(ticket.getId());
480
        activity.setTicketId(ticket.getId());
490
        ticket.setLastActivity(activity.getType());
481
        ticket.setLastActivity(activity.getType());
491
        ticket.setLastActivityId(activity.getId());
482
        ticket.setLastActivityId(activity.getId());
492
 
-
 
493
        if (activity.getType() == ActivityType.COMMUNICATION_OUT) {
-
 
494
            notifyPartnerOfExternalCommunication(ticket, activity);
-
 
495
        }
-
 
496
    }
483
    }
497
 
484
 
498
    private String getRandomString() {
485
    private String getRandomString() {
499
        int length = 4;
486
        int length = 4;
500
        boolean useLetters = false;
487
        boolean useLetters = false;
Line 1873... Line 1860...
1873
        } catch (Exception e) {
1860
        } catch (Exception e) {
1874
            LOGGER.error("Failed to send partner notification email for ticket {}", ticket.getId(), e);
1861
            LOGGER.error("Failed to send partner notification email for ticket {}", ticket.getId(), e);
1875
        }
1862
        }
1876
    }
1863
    }
1877
 
1864
 
-
 
1865
    @Override
-
 
1866
    public Set<Integer> getPartnerIdsByAuthUserId(int authUserId) throws ProfitMandiBusinessException {
-
 
1867
        Set<Integer> partnerIds = new HashSet<>();
-
 
1868
 
-
 
1869
        // Get all positions for this auth user
-
 
1870
        List<Position> userPositions = positionRepository.selectAllByAuthUserId(authUserId);
-
 
1871
 
-
 
1872
        // Filter to relevant categories (SALES, RBM, ABM, BI, TRAINING)
-
 
1873
        List<Integer> relevantCategoryIds = Arrays.asList(
-
 
1874
                ProfitMandiConstants.TICKET_CATEGORY_SALES,
-
 
1875
                ProfitMandiConstants.TICKET_CATEGORY_RBM,
-
 
1876
                ProfitMandiConstants.TICKET_CATEGORY_ABM,
-
 
1877
                ProfitMandiConstants.TICKET_CATEGORY_BUSINESSINTELLIGENT,
-
 
1878
                ProfitMandiConstants.TICKET_CATEGORY_TRAINING);
-
 
1879
 
-
 
1880
        List<Position> filteredPositions = userPositions.stream()
-
 
1881
                .filter(p -> relevantCategoryIds.contains(p.getCategoryId()))
-
 
1882
                .collect(Collectors.toList());
-
 
1883
 
-
 
1884
        if (filteredPositions.isEmpty()) {
-
 
1885
            return partnerIds;
-
 
1886
        }
-
 
1887
 
-
 
1888
        // Get position IDs
-
 
1889
        List<Integer> positionIds = filteredPositions.stream()
-
 
1890
                .map(Position::getId)
-
 
1891
                .collect(Collectors.toList());
-
 
1892
 
-
 
1893
        // Get partner positions for these positions
-
 
1894
        List<PartnerPosition> partnerPositions = partnerPositionRepository.selectByPositionIds(positionIds);
-
 
1895
 
-
 
1896
        // Check if any position has partnerId = 0 (means all active partners)
-
 
1897
        boolean hasAllPartnersAccess = partnerPositions.stream().anyMatch(pp -> pp.getFofoId() == 0);
-
 
1898
 
-
 
1899
        if (hasAllPartnersAccess) {
-
 
1900
            // Return all active partner IDs
-
 
1901
            partnerIds = fofoStoreRepository.selectActiveStores().stream()
-
 
1902
                    .map(FofoStore::getId)
-
 
1903
                    .collect(Collectors.toSet());
-
 
1904
        } else {
-
 
1905
            // Get partner IDs from direct assignments
-
 
1906
            Set<Integer> directPartnerIds = partnerPositions.stream()
-
 
1907
                    .filter(pp -> pp.getFofoId() != 0)
-
 
1908
                    .map(PartnerPosition::getFofoId)
-
 
1909
                    .collect(Collectors.toSet());
-
 
1910
            partnerIds.addAll(directPartnerIds);
-
 
1911
 
-
 
1912
            // Get partner IDs from region assignments
-
 
1913
            Set<Integer> regionIds = partnerPositions.stream()
-
 
1914
                    .filter(pp -> pp.getRegionId() > 0)
-
 
1915
                    .map(PartnerPosition::getRegionId)
-
 
1916
                    .collect(Collectors.toSet());
-
 
1917
 
-
 
1918
            if (!regionIds.isEmpty()) {
-
 
1919
                List<PartnerRegion> partnerRegions = partnerRegionRepository.selectAllByRegionIds(new ArrayList<>(regionIds));
-
 
1920
                Set<Integer> regionPartnerIds = partnerRegions.stream()
-
 
1921
                        .map(PartnerRegion::getFofoId)
-
 
1922
                        .collect(Collectors.toSet());
-
 
1923
                partnerIds.addAll(regionPartnerIds);
-
 
1924
            }
-
 
1925
        }
-
 
1926
 
-
 
1927
        // Filter to only active partners
-
 
1928
        Set<Integer> activeFofoIds = fofoStoreRepository.selectActiveStores().stream()
-
 
1929
                .map(FofoStore::getId)
-
 
1930
                .collect(Collectors.toSet());
-
 
1931
        partnerIds.retainAll(activeFofoIds);
-
 
1932
 
-
 
1933
        return partnerIds;
-
 
1934
    }
-
 
1935
 
1878
}
1936
}