| Line 1... |
Line 1... |
| 1 |
package com.spice.profitmandi.web.controller;
|
1 |
package com.spice.profitmandi.web.controller;
|
| 2 |
|
2 |
|
| 3 |
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
|
3 |
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
|
| 4 |
import com.spice.profitmandi.common.model.CustomRetailer;
|
4 |
import com.spice.profitmandi.common.model.CustomRetailer;
|
| - |
|
5 |
import com.spice.profitmandi.common.model.ProfitMandiConstants;
|
| 5 |
import com.spice.profitmandi.common.util.Utils;
|
6 |
import com.spice.profitmandi.common.util.Utils;
|
| 6 |
import com.spice.profitmandi.dao.entity.auth.AuthUser;
|
7 |
import com.spice.profitmandi.dao.entity.auth.AuthUser;
|
| 7 |
import com.spice.profitmandi.dao.entity.cs.*;
|
8 |
import com.spice.profitmandi.dao.entity.cs.*;
|
| 8 |
import com.spice.profitmandi.dao.entity.dtr.Document;
|
9 |
import com.spice.profitmandi.dao.entity.dtr.Document;
|
| 9 |
import com.spice.profitmandi.dao.entity.fofo.ActivityType;
|
10 |
import com.spice.profitmandi.dao.entity.fofo.ActivityType;
|
| - |
|
11 |
import com.spice.profitmandi.dao.entity.fofo.FofoStore;
|
| 10 |
import com.spice.profitmandi.dao.enumuration.cs.EscalationType;
|
12 |
import com.spice.profitmandi.dao.enumuration.cs.EscalationType;
|
| 11 |
import com.spice.profitmandi.dao.enumuration.cs.TicketStatus;
|
13 |
import com.spice.profitmandi.dao.enumuration.cs.TicketStatus;
|
| 12 |
import com.spice.profitmandi.dao.model.CreatePositionModel;
|
14 |
import com.spice.profitmandi.dao.model.CreatePositionModel;
|
| 13 |
import com.spice.profitmandi.dao.repository.auth.AuthRepository;
|
15 |
import com.spice.profitmandi.dao.repository.auth.AuthRepository;
|
| 14 |
import com.spice.profitmandi.dao.repository.cs.*;
|
16 |
import com.spice.profitmandi.dao.repository.cs.*;
|
| Line 778... |
Line 780... |
| 778 |
activityRepository.persist(activity);
|
780 |
activityRepository.persist(activity);
|
| 779 |
model.addAttribute("response1", mvcResponseSender.createResponseString(true));
|
781 |
model.addAttribute("response1", mvcResponseSender.createResponseString(true));
|
| 780 |
return "response";
|
782 |
return "response";
|
| 781 |
}
|
783 |
}
|
| 782 |
|
784 |
|
| - |
|
785 |
|
| - |
|
786 |
|
| - |
|
787 |
|
| - |
|
788 |
|
| - |
|
789 |
@PostMapping(value = "/partner-position/update")
|
| - |
|
790 |
public String positionUpdated(Model model, @RequestBody List<PartnerPositonUpdateModel> partnerPositionUpdateModels)
|
| - |
|
791 |
throws Exception {
|
| - |
|
792 |
|
| - |
|
793 |
Map<Integer, List<String>> positionIdsToAddMap = partnerPositionUpdateModels.stream().collect(Collectors.groupingBy(x->x.getPositionIdTo(),
|
| - |
|
794 |
Collectors.mapping(x->x.getStoreCode(), Collectors.toList())));
|
| - |
|
795 |
|
| - |
|
796 |
Map<Integer, List<String>> positionIdsToRemoveMap = partnerPositionUpdateModels.stream().collect(Collectors.groupingBy(x->x.getPositionIdFrom(),
|
| - |
|
797 |
Collectors.mapping(x->x.getStoreCode(), Collectors.toList())));
|
| - |
|
798 |
|
| - |
|
799 |
List<Integer> positionIdsToUpdate = new ArrayList<>();
|
| - |
|
800 |
positionIdsToUpdate.addAll(positionIdsToAddMap.keySet());
|
| - |
|
801 |
positionIdsToUpdate.addAll(positionIdsToRemoveMap.keySet());
|
| - |
|
802 |
|
| - |
|
803 |
Map<Integer, Position> positionsToUpdateMap = positionRepository.selectAll(positionIdsToUpdate).stream().collect(Collectors.toMap(x->x.getId(), x->x));
|
| - |
|
804 |
List<Integer> invalidPositionIds = positionsToUpdateMap.values().stream().filter(x-> x.getCategoryId()!= ProfitMandiConstants.TICKET_CATEGORY_RBM
|
| - |
|
805 |
&& x.getCategoryId()!= ProfitMandiConstants.TICKET_CATEGORY_SALES).map(x->x.getId()).collect(Collectors.toList());
|
| - |
|
806 |
if(invalidPositionIds.size() > 0) {
|
| - |
|
807 |
String message = "Non RBM/Sales are not allowed - " + invalidPositionIds;
|
| - |
|
808 |
throw new ProfitMandiBusinessException(message, message, message);
|
| - |
|
809 |
}
|
| - |
|
810 |
|
| - |
|
811 |
for (Map.Entry<Integer, List<String>> positionIdStoreMapEntry : positionIdsToAddMap.entrySet()) {
|
| - |
|
812 |
int positionId = positionIdStoreMapEntry.getKey();
|
| - |
|
813 |
Position position = positionsToUpdateMap.get(positionId);
|
| - |
|
814 |
List<String> storeCodesToAdd = positionIdStoreMapEntry.getValue();
|
| - |
|
815 |
List<Integer> retailerIdsToAdd = fofoStoreRepository.selectByStoreCodes(storeCodesToAdd).stream().map(x->x.getId()).collect(Collectors.toList());
|
| - |
|
816 |
Map<Integer, PartnerPosition> partnerPositionsMapByFofoId = partnerPositionRepository
|
| - |
|
817 |
.selectByRegionIdAndPostionId(Arrays.asList(position.getRegionId()),Arrays.asList(positionId)).stream().collect(Collectors.toMap(x->x.getFofoId(),x->x));
|
| - |
|
818 |
for (Integer retailerIdToAdd : retailerIdsToAdd) {
|
| - |
|
819 |
if (!partnerPositionsMapByFofoId.containsKey(retailerIdToAdd)) {
|
| - |
|
820 |
PartnerPosition partnerPositionNew = new PartnerPosition();
|
| - |
|
821 |
partnerPositionNew.setPositionId(positionId);
|
| - |
|
822 |
partnerPositionNew.setFofoId(retailerIdToAdd);
|
| - |
|
823 |
partnerPositionNew.setRegionId(position.getRegionId());
|
| - |
|
824 |
}
|
| - |
|
825 |
}
|
| - |
|
826 |
}
|
| - |
|
827 |
|
| - |
|
828 |
for (Map.Entry<Integer, List<String>> positionIdStoreMapEntry : positionIdsToRemoveMap.entrySet()) {
|
| - |
|
829 |
|
| - |
|
830 |
int positionId = positionIdStoreMapEntry.getKey();
|
| - |
|
831 |
Position position = positionsToUpdateMap.get(positionId);
|
| - |
|
832 |
List<String> storeCodesToRemove = positionIdStoreMapEntry.getValue();
|
| - |
|
833 |
List<Integer> retailerIdsToRemove = fofoStoreRepository.selectByStoreCodes(storeCodesToRemove).stream().map(x->x.getId()).collect(Collectors.toList());
|
| - |
|
834 |
Map<Integer, PartnerPosition> partnerPositionsMapByFofoId = partnerPositionRepository
|
| - |
|
835 |
.selectByRegionIdAndPostionId(Arrays.asList(position.getRegionId()),Arrays.asList(positionId)).stream().collect(Collectors.toMap(x->x.getFofoId(),x->x));
|
| - |
|
836 |
for (Integer retailerIdToRemove : retailerIdsToRemove) {
|
| - |
|
837 |
if (partnerPositionsMapByFofoId.containsKey(retailerIdToRemove)) {
|
| - |
|
838 |
PartnerPosition partnerPositionToRemove = partnerPositionsMapByFofoId.get(retailerIdToRemove);
|
| - |
|
839 |
partnerPositionRepository.delete(partnerPositionToRemove);
|
| - |
|
840 |
}
|
| - |
|
841 |
}
|
| - |
|
842 |
}
|
| - |
|
843 |
|
| - |
|
844 |
|
| - |
|
845 |
|
| - |
|
846 |
/*partnerPositionUpdateModels.str
|
| - |
|
847 |
|
| - |
|
848 |
Map<Integer, Position> positionIdMap = positionsToUpdate.stream().collect(Collectors.toMap(x->x.getId(), x->x));
|
| - |
|
849 |
for (PartnerPositonUpdateModel partnerPositionUpdateModel : partnerPositionUpdateModels) {
|
| - |
|
850 |
FofoStore fofoStore = fofoStoreRepository.selectByStoreCode(partnerPositionUpdateModel.getStoreCode());
|
| - |
|
851 |
Position positionFrom = positionIdMap.get(partnerPositionUpdateModel.getPositionIdFrom());
|
| - |
|
852 |
Position positionTo = positionIdMap.get(partnerPositionUpdateModel.getPositionIdTo());
|
| - |
|
853 |
if(positionFrom != null) {
|
| - |
|
854 |
partnerPositionRepository.selectByRegionIdAndPostionId(Arrays.)
|
| - |
|
855 |
int regionId = positionFrom.getRegionId()
|
| - |
|
856 |
}
|
| - |
|
857 |
if(positionTo != null) {
|
| - |
|
858 |
|
| - |
|
859 |
}
|
| - |
|
860 |
}*/
|
| - |
|
861 |
model.addAttribute("response1", mvcResponseSender.createResponseString(true));
|
| - |
|
862 |
return "response";
|
| - |
|
863 |
|
| - |
|
864 |
}
|
| - |
|
865 |
|
| - |
|
866 |
|
| 783 |
}
|
867 |
}
|