| Line 31... |
Line 31... |
| 31 |
import com.spice.profitmandi.dao.repository.catalog.SchemeRepository;
|
31 |
import com.spice.profitmandi.dao.repository.catalog.SchemeRepository;
|
| 32 |
import com.spice.profitmandi.dao.repository.dtr.RetailerRepository;
|
32 |
import com.spice.profitmandi.dao.repository.dtr.RetailerRepository;
|
| 33 |
import com.spice.profitmandi.dao.repository.fofo.InventoryItemRepository;
|
33 |
import com.spice.profitmandi.dao.repository.fofo.InventoryItemRepository;
|
| 34 |
import com.spice.profitmandi.dao.repository.fofo.SchemeInOutRepository;
|
34 |
import com.spice.profitmandi.dao.repository.fofo.SchemeInOutRepository;
|
| 35 |
import com.spice.profitmandi.dao.repository.fofo.SchemeItemRepository;
|
35 |
import com.spice.profitmandi.dao.repository.fofo.SchemeItemRepository;
|
| 36 |
import com.spice.profitmandi.service.sale.FofoOrderItemService;
|
36 |
import com.spice.profitmandi.service.inventory.OrderService;
|
| 37 |
import com.spice.profitmandi.service.wallet.WalletService;
|
37 |
import com.spice.profitmandi.service.wallet.WalletService;
|
| 38 |
|
38 |
|
| 39 |
import in.shop2020.model.v1.catalog.ItemType;
|
39 |
import in.shop2020.model.v1.catalog.ItemType;
|
| 40 |
import in.shop2020.model.v1.order.WalletReferenceType;
|
40 |
import in.shop2020.model.v1.order.WalletReferenceType;
|
| 41 |
|
41 |
|
| Line 46... |
Line 46... |
| 46 |
|
46 |
|
| 47 |
@Autowired
|
47 |
@Autowired
|
| 48 |
private InventoryItemRepository inventoryItemRepository;
|
48 |
private InventoryItemRepository inventoryItemRepository;
|
| 49 |
|
49 |
|
| 50 |
@Autowired
|
50 |
@Autowired
|
| 51 |
private FofoOrderItemService fofoOrderItemService;
|
51 |
private OrderService orderService;
|
| 52 |
|
52 |
|
| 53 |
@Autowired
|
53 |
@Autowired
|
| 54 |
private SchemeRepository schemeRepository;
|
54 |
private SchemeRepository schemeRepository;
|
| 55 |
|
55 |
|
| 56 |
@Autowired
|
56 |
@Autowired
|
| Line 72... |
Line 72... |
| 72 |
private WalletService walletService;
|
72 |
private WalletService walletService;
|
| 73 |
|
73 |
|
| 74 |
@Override
|
74 |
@Override
|
| 75 |
public void saveScheme(int creatorId, CreateSchemeRequest createSchemeRequest) throws ProfitMandiBusinessException {
|
75 |
public void saveScheme(int creatorId, CreateSchemeRequest createSchemeRequest) throws ProfitMandiBusinessException {
|
| 76 |
|
76 |
|
| 77 |
if(createSchemeRequest.getName().isEmpty()){
|
77 |
if(createSchemeRequest.getName() == null || createSchemeRequest.getName().isEmpty()){
|
| 78 |
throw new ProfitMandiBusinessException(ProfitMandiConstants.NAME, createSchemeRequest.getName(), "");
|
78 |
throw new ProfitMandiBusinessException(ProfitMandiConstants.NAME, createSchemeRequest.getName(), "SCHM_VE_1000");
|
| 79 |
}
|
79 |
}
|
| 80 |
if(createSchemeRequest.getAmount() <= 0){
|
80 |
if(createSchemeRequest.getAmount() <= 0){
|
| 81 |
throw new ProfitMandiBusinessException(ProfitMandiConstants.AMOUNT, createSchemeRequest.getAmount(), "");
|
81 |
throw new ProfitMandiBusinessException(ProfitMandiConstants.AMOUNT, createSchemeRequest.getAmount(), "SCHM_VE_1001");
|
| 82 |
}
|
82 |
}
|
| 83 |
|
83 |
|
| 84 |
if(SchemeAmountType.valueOf(createSchemeRequest.getAmountType()) == SchemeAmountType.PERCENTAGE && createSchemeRequest.getAmount() > 100){
|
84 |
if(SchemeAmountType.valueOf(createSchemeRequest.getAmountType()) == SchemeAmountType.PERCENTAGE && createSchemeRequest.getAmount() > 100){
|
| 85 |
throw new ProfitMandiBusinessException(ProfitMandiConstants.AMOUNT, createSchemeRequest.getAmount(), "");
|
85 |
throw new ProfitMandiBusinessException(ProfitMandiConstants.AMOUNT, createSchemeRequest.getAmount(), "SCHM_VE_1002");
|
| 86 |
}
|
86 |
}
|
| 87 |
|
87 |
|
| 88 |
if(createSchemeRequest.getStartDateString() == null || createSchemeRequest.getStartDateString().isEmpty()){
|
88 |
if(createSchemeRequest.getStartDateString() == null || createSchemeRequest.getStartDateString().isEmpty()){
|
| 89 |
throw new ProfitMandiBusinessException(ProfitMandiConstants.START_DATE, createSchemeRequest.getStartDateString(), "");
|
89 |
throw new ProfitMandiBusinessException(ProfitMandiConstants.START_DATE, createSchemeRequest.getStartDateString(), "SCHM_VE_1003");
|
| 90 |
}
|
90 |
}
|
| 91 |
|
91 |
|
| 92 |
if(createSchemeRequest.getEndDateString() == null || createSchemeRequest.getStartDateString().isEmpty()){
|
92 |
if(createSchemeRequest.getEndDateString() == null || createSchemeRequest.getStartDateString().isEmpty()){
|
| 93 |
throw new ProfitMandiBusinessException(ProfitMandiConstants.END_DATE, createSchemeRequest.getEndDateString(), "");
|
93 |
throw new ProfitMandiBusinessException(ProfitMandiConstants.END_DATE, createSchemeRequest.getEndDateString(), "SCHM_VE_1004");
|
| 94 |
}
|
94 |
}
|
| 95 |
|
95 |
|
| 96 |
Scheme scheme = this.toScheme(creatorId, createSchemeRequest);
|
96 |
Scheme scheme = this.toScheme(creatorId, createSchemeRequest);
|
| 97 |
|
97 |
|
| 98 |
if(scheme.getStartDate().isAfter(scheme.getEndDate())){
|
98 |
if(scheme.getStartDate().isAfter(scheme.getEndDate())){
|
| 99 |
throw new ProfitMandiBusinessException(ProfitMandiConstants.START_DATE + ", " + ProfitMandiConstants.END_DATE, scheme.getStartDate() + ", " + scheme.getEndDate(), "");
|
99 |
throw new ProfitMandiBusinessException(ProfitMandiConstants.START_DATE + ", " + ProfitMandiConstants.END_DATE, scheme.getStartDate() + ", " + scheme.getEndDate(), "SCHM_VE_1005");
|
| 100 |
}
|
100 |
}
|
| 101 |
|
101 |
|
| 102 |
this.validateItemIds(createSchemeRequest);
|
102 |
this.validateItemIds(createSchemeRequest);
|
| 103 |
schemeRepository.persist(scheme);
|
103 |
schemeRepository.persist(scheme);
|
| 104 |
if(!createSchemeRequest.isRetailerAll()){
|
104 |
if(!createSchemeRequest.isRetailerAll()){
|
| Line 135... |
Line 135... |
| 135 |
scheme.setRetailerAll(createSchemeRequest.isRetailerAll());
|
135 |
scheme.setRetailerAll(createSchemeRequest.isRetailerAll());
|
| 136 |
return scheme;
|
136 |
return scheme;
|
| 137 |
}
|
137 |
}
|
| 138 |
|
138 |
|
| 139 |
private void validateRetailerIds(CreateSchemeRequest createSchemeRequest) throws ProfitMandiBusinessException{
|
139 |
private void validateRetailerIds(CreateSchemeRequest createSchemeRequest) throws ProfitMandiBusinessException{
|
| 140 |
if(createSchemeRequest.getRetailerIds().isEmpty()){
|
140 |
if(createSchemeRequest.getRetailerIds() == null || createSchemeRequest.getRetailerIds().isEmpty()){
|
| 141 |
throw new ProfitMandiBusinessException(ProfitMandiConstants.RETAILER_ID, createSchemeRequest.getRetailerIds(), "");
|
141 |
throw new ProfitMandiBusinessException(ProfitMandiConstants.RETAILER_ID, createSchemeRequest.getRetailerIds(), "SCHM_1001");
|
| 142 |
}
|
142 |
}
|
| 143 |
List<Integer> foundRetailerIds = retailerRepository.selectIdsByIds(createSchemeRequest.getRetailerIds());
|
143 |
List<Integer> foundRetailerIds = retailerRepository.selectIdsByIds(createSchemeRequest.getRetailerIds());
|
| 144 |
if(foundRetailerIds.size() != createSchemeRequest.getRetailerIds().size()){
|
144 |
if(foundRetailerIds.size() != createSchemeRequest.getRetailerIds().size()){
|
| 145 |
createSchemeRequest.getRetailerIds().removeAll(foundRetailerIds);
|
145 |
createSchemeRequest.getRetailerIds().removeAll(foundRetailerIds);
|
| 146 |
throw new ProfitMandiBusinessException(ProfitMandiConstants.RETAILER_ID, createSchemeRequest.getRetailerIds(), "");
|
146 |
throw new ProfitMandiBusinessException(ProfitMandiConstants.RETAILER_ID, createSchemeRequest.getRetailerIds(), "SCHM_1002");
|
| 147 |
}
|
147 |
}
|
| 148 |
}
|
148 |
}
|
| 149 |
|
149 |
|
| 150 |
private void validateItemIds(CreateSchemeRequest createSchemeRequest) throws ProfitMandiBusinessException{
|
150 |
private void validateItemIds(CreateSchemeRequest createSchemeRequest) throws ProfitMandiBusinessException{
|
| 151 |
if(createSchemeRequest.getItemIds() == null || createSchemeRequest.getItemIds().isEmpty()){
|
151 |
if(createSchemeRequest.getItemIds() == null || createSchemeRequest.getItemIds().isEmpty()){
|
| 152 |
throw new ProfitMandiBusinessException(ProfitMandiConstants.ITEM_ID, createSchemeRequest.getItemIds(), "");
|
152 |
throw new ProfitMandiBusinessException(ProfitMandiConstants.ITEM_ID, createSchemeRequest.getItemIds(), "SCHM_1003");
|
| 153 |
}
|
153 |
}
|
| 154 |
List<Integer> foundItemIds = itemRepository.selectIdsByIdsAndType(createSchemeRequest.getItemIds(), ItemType.SERIALIZED);
|
154 |
List<Integer> foundItemIds = itemRepository.selectIdsByIdsAndType(createSchemeRequest.getItemIds(), ItemType.SERIALIZED);
|
| 155 |
if(foundItemIds.size() != createSchemeRequest.getItemIds().size()){
|
155 |
if(foundItemIds.size() != createSchemeRequest.getItemIds().size()){
|
| 156 |
createSchemeRequest.getItemIds().removeAll(foundItemIds);
|
156 |
createSchemeRequest.getItemIds().removeAll(foundItemIds);
|
| 157 |
throw new ProfitMandiBusinessException(ProfitMandiConstants.ITEM_ID, createSchemeRequest.getItemIds(), "");
|
157 |
throw new ProfitMandiBusinessException(ProfitMandiConstants.ITEM_ID, createSchemeRequest.getItemIds(), "SCHM_1004");
|
| 158 |
}
|
158 |
}
|
| 159 |
}
|
159 |
}
|
| 160 |
|
160 |
|
| 161 |
@Override
|
161 |
@Override
|
| 162 |
public Scheme getSchemeById(int schemeId) throws ProfitMandiBusinessException {
|
162 |
public Scheme getSchemeById(int schemeId) throws ProfitMandiBusinessException {
|
| Line 174... |
Line 174... |
| 174 |
|
174 |
|
| 175 |
@Override
|
175 |
@Override
|
| 176 |
public void activeSchemeById(int schemeId) throws ProfitMandiBusinessException {
|
176 |
public void activeSchemeById(int schemeId) throws ProfitMandiBusinessException {
|
| 177 |
Scheme scheme = schemeRepository.selectById(schemeId);
|
177 |
Scheme scheme = schemeRepository.selectById(schemeId);
|
| 178 |
if(scheme.getActiveTimestamp() != null){
|
178 |
if(scheme.getActiveTimestamp() != null){
|
| 179 |
throw new ProfitMandiBusinessException(ProfitMandiConstants.ACTIVE_TIMESTAMP, scheme.getActiveTimestamp(), "");
|
179 |
throw new ProfitMandiBusinessException(ProfitMandiConstants.ACTIVE_TIMESTAMP, scheme.getActiveTimestamp(), "SCHM_1005");
|
| 180 |
}
|
180 |
}
|
| 181 |
if(scheme.getExpireTimestamp() != null){
|
181 |
if(scheme.getExpireTimestamp() != null){
|
| 182 |
throw new ProfitMandiBusinessException(ProfitMandiConstants.EXPIRE_TIMESTAMP, scheme.getExpireTimestamp(), "");
|
182 |
throw new ProfitMandiBusinessException(ProfitMandiConstants.EXPIRE_TIMESTAMP, scheme.getExpireTimestamp(), "SCHM_1006");
|
| 183 |
}
|
183 |
}
|
| 184 |
scheme.setActiveTimestamp(LocalDateTime.now());
|
184 |
scheme.setActiveTimestamp(LocalDateTime.now());
|
| 185 |
schemeRepository.persist(scheme);
|
185 |
schemeRepository.persist(scheme);
|
| 186 |
}
|
186 |
}
|
| 187 |
|
187 |
|
| 188 |
@Override
|
188 |
@Override
|
| 189 |
public void expireSchemeById(int schemeId) throws ProfitMandiBusinessException {
|
189 |
public void expireSchemeById(int schemeId) throws ProfitMandiBusinessException {
|
| 190 |
Scheme scheme = schemeRepository.selectById(schemeId);
|
190 |
Scheme scheme = schemeRepository.selectById(schemeId);
|
| 191 |
if(scheme.getActiveTimestamp() == null){
|
191 |
if(scheme.getActiveTimestamp() == null){
|
| 192 |
throw new ProfitMandiBusinessException(ProfitMandiConstants.ACTIVE_TIMESTAMP, scheme.getActiveTimestamp(), "");
|
192 |
throw new ProfitMandiBusinessException(ProfitMandiConstants.ACTIVE_TIMESTAMP, scheme.getActiveTimestamp(), "SCHM_1007");
|
| 193 |
}
|
193 |
}
|
| 194 |
if(scheme.getExpireTimestamp() != null){
|
194 |
if(scheme.getExpireTimestamp() != null){
|
| 195 |
throw new ProfitMandiBusinessException(ProfitMandiConstants.EXPIRE_TIMESTAMP, scheme.getExpireTimestamp(), "");
|
195 |
throw new ProfitMandiBusinessException(ProfitMandiConstants.EXPIRE_TIMESTAMP, scheme.getExpireTimestamp(), "SCHM_1008");
|
| 196 |
}
|
196 |
}
|
| 197 |
scheme.setExpireTimestamp(LocalDateTime.now());
|
197 |
scheme.setExpireTimestamp(LocalDateTime.now());
|
| 198 |
schemeRepository.persist(scheme);
|
198 |
schemeRepository.persist(scheme);
|
| 199 |
}
|
199 |
}
|
| 200 |
|
200 |
|
| Line 383... |
Line 383... |
| 383 |
itemIdInventoryItemMap.put(inventoryItem.getId(), inventoryItem);
|
383 |
itemIdInventoryItemMap.put(inventoryItem.getId(), inventoryItem);
|
| 384 |
}
|
384 |
}
|
| 385 |
return itemIdInventoryItemMap;
|
385 |
return itemIdInventoryItemMap;
|
| 386 |
}
|
386 |
}
|
| 387 |
|
387 |
|
| 388 |
/*private Set<Integer> toFofoOrderItemIds(Set<FofoOrderItem> fofoOrderItems){
|
- |
|
| 389 |
Set<Integer> fofoOrderItemIds = new HashSet<>();
|
- |
|
| 390 |
for(FofoOrderItem fofoOrderItem : fofoOrderItems){
|
- |
|
| 391 |
fofoOrderItemIds.add(fofoOrderItem.getId());
|
- |
|
| 392 |
}
|
- |
|
| 393 |
return fofoOrderItemIds;
|
- |
|
| 394 |
}*/
|
- |
|
| 395 |
|
- |
|
| 396 |
/*private Map<Integer, Set<FofoLineItem>> toFofoOrderItemIdFofoLineItems(Set<FofoOrderItem> fofoOrderItems){
|
- |
|
| 397 |
Set<Integer> fofoOrderItemIds = this.toFofoOrderItemIds(fofoOrderItems);
|
- |
|
| 398 |
List<FofoLineItem> fofoLineItems = fofoLineItemRepository.selectByFofoOrderItemIds(fofoOrderItemIds);
|
- |
|
| 399 |
Map<Integer, Set<FofoLineItem>> fofoOrderItemIdFofoLineItemsMap = new HashMap<>();
|
- |
|
| 400 |
for(FofoLineItem fofoLineItem : fofoLineItems){
|
- |
|
| 401 |
if(!fofoOrderItemIdFofoLineItemsMap.containsKey(fofoLineItem.getFofoOrderItemId())){
|
- |
|
| 402 |
Set<FofoLineItem> fofoLineItems2 = new HashSet<>();
|
- |
|
| 403 |
fofoLineItems.add(fofoLineItem);
|
- |
|
| 404 |
fofoOrderItemIdFofoLineItemsMap.put(fofoLineItem.getFofoOrderItemId(), fofoLineItems2);
|
- |
|
| 405 |
}else{
|
- |
|
| 406 |
fofoOrderItemIdFofoLineItemsMap.get(fofoLineItem.getFofoOrderItemId()).add(fofoLineItem);
|
- |
|
| 407 |
}
|
- |
|
| 408 |
}
|
- |
|
| 409 |
return fofoOrderItemIdFofoLineItemsMap;
|
- |
|
| 410 |
}*/
|
- |
|
| 411 |
|
388 |
|
| 412 |
private Set<Integer> toInventoryItemIds(Set<FofoOrderItem> fofoOrderItems){
|
389 |
private Set<Integer> toInventoryItemIds(Set<FofoOrderItem> fofoOrderItems){
|
| 413 |
Set<Integer> inventoryItemIds = new HashSet<>();
|
390 |
Set<Integer> inventoryItemIds = new HashSet<>();
|
| 414 |
//Map<Integer, Set<FofoLineItem>> fofoOrderItemIdFofoLineItemsMap = this.toFofoOrderItemIdFofoLineItems(fofoOrderItems);
|
391 |
//Map<Integer, Set<FofoLineItem>> fofoOrderItemIdFofoLineItemsMap = this.toFofoOrderItemIdFofoLineItems(fofoOrderItems);
|
| 415 |
for(FofoOrderItem fofoOrderItem : fofoOrderItems){
|
392 |
for(FofoOrderItem fofoOrderItem : fofoOrderItems){
|
| Line 427... |
Line 404... |
| 427 |
float totalCashback = 0;
|
404 |
float totalCashback = 0;
|
| 428 |
if(schemes.isEmpty()){
|
405 |
if(schemes.isEmpty()){
|
| 429 |
return 0;
|
406 |
return 0;
|
| 430 |
}
|
407 |
}
|
| 431 |
|
408 |
|
| 432 |
List<FofoOrderItem> fofoOrderItems = fofoOrderItemService.getByOrderId(fofoOrderId);
|
409 |
List<FofoOrderItem> fofoOrderItems = orderService.getByOrderId(fofoOrderId);
|
| 433 |
//LOGGER.info("fofoOrderItems {}", fofoOrderItems);
|
410 |
//LOGGER.info("fofoOrderItems {}", fofoOrderItems);
|
| 434 |
|
411 |
|
| 435 |
Map<FofoOrderItem, Set<Scheme>> fofoOrderItemSchemesMap = this.toFofoOrderItemSchemesMap(schemes, fofoOrderItems);
|
412 |
Map<FofoOrderItem, Set<Scheme>> fofoOrderItemSchemesMap = this.toFofoOrderItemSchemesMap(schemes, fofoOrderItems);
|
| 436 |
|
413 |
|
| 437 |
LOGGER.info("fofoOrderItemSchemesMap {}", fofoOrderItemSchemesMap);
|
414 |
LOGGER.info("fofoOrderItemSchemesMap {}", fofoOrderItemSchemesMap);
|