| Line 1... |
Line 1... |
| 1 |
package com.spice.profitmandi.dao.repository.cs;
|
1 |
package com.spice.profitmandi.dao.repository.cs;
|
| 2 |
|
2 |
|
| - |
|
3 |
import java.time.LocalDateTime;
|
| - |
|
4 |
import java.util.ArrayList;
|
| - |
|
5 |
import java.util.Arrays;
|
| - |
|
6 |
import java.util.HashMap;
|
| - |
|
7 |
import java.util.HashSet;
|
| - |
|
8 |
import java.util.LinkedHashSet;
|
| - |
|
9 |
import java.util.List;
|
| - |
|
10 |
import java.util.Map;
|
| - |
|
11 |
import java.util.Set;
|
| - |
|
12 |
import java.util.stream.Collectors;
|
| - |
|
13 |
|
| - |
|
14 |
import org.apache.commons.collections4.map.HashedMap;
|
| - |
|
15 |
import org.apache.commons.lang.RandomStringUtils;
|
| - |
|
16 |
import org.apache.commons.lang.StringUtils;
|
| - |
|
17 |
import org.apache.logging.log4j.LogManager;
|
| - |
|
18 |
import org.apache.logging.log4j.Logger;
|
| - |
|
19 |
import org.springframework.beans.factory.annotation.Autowired;
|
| - |
|
20 |
import org.springframework.cache.annotation.Cacheable;
|
| - |
|
21 |
import org.springframework.mail.javamail.JavaMailSender;
|
| - |
|
22 |
import org.springframework.stereotype.Component;
|
| - |
|
23 |
|
| 3 |
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
|
24 |
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
|
| 4 |
import com.spice.profitmandi.common.model.CustomRetailer;
|
25 |
import com.spice.profitmandi.common.model.CustomRetailer;
|
| 5 |
import com.spice.profitmandi.common.model.ProfitMandiConstants;
|
26 |
import com.spice.profitmandi.common.model.ProfitMandiConstants;
|
| 6 |
import com.spice.profitmandi.common.util.Utils;
|
27 |
import com.spice.profitmandi.common.util.Utils;
|
| 7 |
import com.spice.profitmandi.dao.entity.auth.AuthUser;
|
28 |
import com.spice.profitmandi.dao.entity.auth.AuthUser;
|
| - |
|
29 |
import com.spice.profitmandi.dao.entity.cs.Activity;
|
| - |
|
30 |
import com.spice.profitmandi.dao.entity.cs.PartnerRegion;
|
| - |
|
31 |
import com.spice.profitmandi.dao.entity.cs.Position;
|
| 8 |
import com.spice.profitmandi.dao.entity.cs.*;
|
32 |
import com.spice.profitmandi.dao.entity.cs.Region;
|
| - |
|
33 |
import com.spice.profitmandi.dao.entity.cs.Ticket;
|
| - |
|
34 |
import com.spice.profitmandi.dao.entity.cs.TicketAssigned;
|
| - |
|
35 |
import com.spice.profitmandi.dao.entity.cs.TicketCategory;
|
| - |
|
36 |
import com.spice.profitmandi.dao.entity.cs.TicketSubCategory;
|
| 9 |
import com.spice.profitmandi.dao.entity.fofo.ActivityType;
|
37 |
import com.spice.profitmandi.dao.entity.fofo.ActivityType;
|
| - |
|
38 |
import com.spice.profitmandi.dao.entity.fofo.FofoStore;
|
| 10 |
import com.spice.profitmandi.dao.enumuration.cs.EscalationType;
|
39 |
import com.spice.profitmandi.dao.enumuration.cs.EscalationType;
|
| - |
|
40 |
import com.spice.profitmandi.dao.model.FofoReportingModel;
|
| 11 |
import com.spice.profitmandi.dao.repository.auth.AuthRepository;
|
41 |
import com.spice.profitmandi.dao.repository.auth.AuthRepository;
|
| 12 |
import com.spice.profitmandi.dao.repository.dtr.FofoStoreRepository;
|
42 |
import com.spice.profitmandi.dao.repository.dtr.FofoStoreRepository;
|
| 13 |
import com.spice.profitmandi.service.user.RetailerService;
|
43 |
import com.spice.profitmandi.service.user.RetailerService;
|
| 14 |
import org.apache.commons.collections4.map.HashedMap;
|
- |
|
| 15 |
import org.apache.commons.lang.RandomStringUtils;
|
- |
|
| 16 |
import org.apache.logging.log4j.LogManager;
|
- |
|
| 17 |
import org.apache.logging.log4j.Logger;
|
- |
|
| 18 |
import org.springframework.beans.factory.annotation.Autowired;
|
- |
|
| 19 |
import org.springframework.cache.annotation.Cacheable;
|
- |
|
| 20 |
import org.springframework.mail.javamail.JavaMailSender;
|
- |
|
| 21 |
import org.springframework.stereotype.Component;
|
- |
|
| 22 |
|
- |
|
| 23 |
import java.time.LocalDateTime;
|
- |
|
| 24 |
import java.util.*;
|
- |
|
| 25 |
import java.util.stream.Collectors;
|
- |
|
| 26 |
|
44 |
|
| 27 |
@Component
|
45 |
@Component
|
| 28 |
public class CsServiceImpl implements CsService {
|
46 |
public class CsServiceImpl implements CsService {
|
| 29 |
|
47 |
|
| 30 |
private static final int ALL_PARTNERS_REGION = 5;
|
48 |
private static final int ALL_PARTNERS_REGION = 5;
|
| Line 783... |
Line 801... |
| 783 |
List<Position> positions = positionRepository.selectPositionByCategoryId(categoryId);
|
801 |
List<Position> positions = positionRepository.selectPositionByCategoryId(categoryId);
|
| 784 |
List<Integer> authIds = positions.stream().map(x -> x.getAuthUserId()).distinct().collect(Collectors.toList());
|
802 |
List<Integer> authIds = positions.stream().map(x -> x.getAuthUserId()).distinct().collect(Collectors.toList());
|
| 785 |
|
803 |
|
| 786 |
LOGGER.info("authIds" + authIds);
|
804 |
LOGGER.info("authIds" + authIds);
|
| 787 |
|
805 |
|
| 788 |
List<AuthUser> authUsers = authRepository.selectAllAuthUserByIds(authIds).stream().filter(x -> x.getActive()).collect(Collectors.toList());
|
806 |
List<AuthUser> authUsers = authRepository.selectAllAuthUserByIds(authIds).stream().filter(x -> x.getActive())
|
| - |
|
807 |
.collect(Collectors.toList());
|
| 789 |
|
808 |
|
| 790 |
LOGGER.info("authUsers" + authUsers);
|
809 |
LOGGER.info("authUsers" + authUsers);
|
| 791 |
return authUsers;
|
810 |
return authUsers;
|
| 792 |
}
|
811 |
}
|
| 793 |
|
812 |
|
| - |
|
813 |
private class SaleRoles {
|
| - |
|
814 |
|
| - |
|
815 |
private List<String> l1;
|
| - |
|
816 |
private List<String> l2;
|
| - |
|
817 |
|
| - |
|
818 |
public SaleRoles() {
|
| - |
|
819 |
l1 = new ArrayList<>();
|
| - |
|
820 |
l2 = new ArrayList<>();
|
| - |
|
821 |
}
|
| - |
|
822 |
|
| - |
|
823 |
public List<String> getL1() {
|
| - |
|
824 |
return l1;
|
| - |
|
825 |
}
|
| - |
|
826 |
|
| - |
|
827 |
public List<String> getL2() {
|
| - |
|
828 |
return l2;
|
| - |
|
829 |
}
|
| - |
|
830 |
|
| - |
|
831 |
}
|
| - |
|
832 |
|
| - |
|
833 |
@Override
|
| - |
|
834 |
@Cacheable(value = "partnerSaleHeader", cacheManager = "oneDayCacheManager")
|
| - |
|
835 |
public Map<Integer, FofoReportingModel> getPartnerIdSalesHeaders() {
|
| - |
|
836 |
Map<String, SaleRoles> partnerEmailSalesMap = new HashMap<>();
|
| - |
|
837 |
|
| - |
|
838 |
List<Position> positions = positionRepository
|
| - |
|
839 |
.selectPositionByCategoryId(ProfitMandiConstants.TICKET_CATEGORY_SALES);
|
| - |
|
840 |
Map<Integer, AuthUser> authUsersMap = authRepository.selectAllActiveUser().stream()
|
| - |
|
841 |
.collect(Collectors.toMap(x -> x.getId(), x -> x));
|
| - |
|
842 |
Map<Integer, List<CustomRetailer>> positionIdRetailerMap = this.getPositionCustomRetailerMap(positions);
|
| - |
|
843 |
for (Position position : positions) {
|
| - |
|
844 |
List<CustomRetailer> crList = positionIdRetailerMap.get(position.getId());
|
| - |
|
845 |
if (crList == null)
|
| - |
|
846 |
continue;
|
| - |
|
847 |
for (CustomRetailer cr : crList) {
|
| - |
|
848 |
if (!partnerEmailSalesMap.containsKey(cr.getEmail())) {
|
| - |
|
849 |
partnerEmailSalesMap.put(cr.getEmail(), new SaleRoles());
|
| - |
|
850 |
}
|
| - |
|
851 |
SaleRoles saleRoles = partnerEmailSalesMap.get(cr.getEmail());
|
| - |
|
852 |
AuthUser authUser = authUsersMap.get(position.getAuthUserId());
|
| - |
|
853 |
if (authUser == null) {
|
| - |
|
854 |
continue;
|
| - |
|
855 |
}
|
| - |
|
856 |
String name = authUser.getFirstName() + " " + authUser.getLastName();
|
| - |
|
857 |
if (position.getEscalationType().equals(EscalationType.L1)) {
|
| - |
|
858 |
saleRoles.getL1().add(name);
|
| - |
|
859 |
} else if (position.getEscalationType().equals(EscalationType.L2)) {
|
| - |
|
860 |
saleRoles.getL2().add(name);
|
| - |
|
861 |
}
|
| - |
|
862 |
}
|
| - |
|
863 |
}
|
| - |
|
864 |
|
| - |
|
865 |
Set<CustomRetailer> allCrList = new HashSet<>();
|
| - |
|
866 |
for (List<CustomRetailer> cr : positionIdRetailerMap.values()) {
|
| - |
|
867 |
allCrList.addAll(cr);
|
| - |
|
868 |
}
|
| - |
|
869 |
|
| - |
|
870 |
Map<Integer, FofoStore> fofoStoresMap = fofoStoreRepository.selectActiveStores().stream()
|
| - |
|
871 |
.collect(Collectors.toMap(x -> x.getId(), x -> x));
|
| - |
|
872 |
|
| - |
|
873 |
Map<Integer, FofoReportingModel> partnerIdSalesHeadersMap = new HashMap<>();
|
| - |
|
874 |
|
| - |
|
875 |
for (CustomRetailer cr : allCrList) {
|
| - |
|
876 |
FofoStore fofoStore = fofoStoresMap.get(cr.getPartnerId());
|
| - |
|
877 |
if (fofoStore == null) {
|
| - |
|
878 |
LOGGER.info("Could not find Store {} in active Store", cr.getBusinessName());
|
| - |
|
879 |
continue;
|
| - |
|
880 |
}
|
| - |
|
881 |
String code = fofoStore.getCode();
|
| - |
|
882 |
// String storeName = "SmartDukaan-" +
|
| - |
|
883 |
// fofoStore.getCode().replaceAll("[a-zA-Z]", "");
|
| - |
|
884 |
String businessName = cr.getBusinessName();
|
| - |
|
885 |
try {
|
| - |
|
886 |
String stateManager = StringUtils.join(partnerEmailSalesMap.get(cr.getEmail()).getL2(), ", ");
|
| - |
|
887 |
String territoryManager = StringUtils.join(partnerEmailSalesMap.get(cr.getEmail()).getL1(), ", ");
|
| - |
|
888 |
FofoReportingModel reportingModel = new FofoReportingModel();
|
| - |
|
889 |
reportingModel.setBusinessName(businessName);
|
| - |
|
890 |
reportingModel.setCode(code);
|
| - |
|
891 |
reportingModel.setFofoId(fofoStore.getId());
|
| - |
|
892 |
reportingModel.setRegionalManager(stateManager);
|
| - |
|
893 |
reportingModel.setTerritoryManager(territoryManager);
|
| - |
|
894 |
partnerIdSalesHeadersMap.put(fofoStore.getId(), reportingModel);
|
| - |
|
895 |
} catch (Exception e) {
|
| - |
|
896 |
LOGGER.warn("Could not find partner with email - {}", cr.getEmail());
|
| - |
|
897 |
}
|
| - |
|
898 |
}
|
| - |
|
899 |
return partnerIdSalesHeadersMap;
|
| - |
|
900 |
|
| - |
|
901 |
}
|
| - |
|
902 |
|
| 794 |
}
|
903 |
}
|