| Line 1... |
Line 1... |
| 1 |
package com.spice.profitmandi.service;
|
1 |
package com.spice.profitmandi.service;
|
| 2 |
|
2 |
|
| 3 |
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
|
3 |
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
|
| - |
|
4 |
import com.spice.profitmandi.common.enumuration.FofoType;
|
| 4 |
import com.spice.profitmandi.common.model.CustomAddress;
|
5 |
import com.spice.profitmandi.common.model.CustomAddress;
|
| 5 |
import com.spice.profitmandi.common.model.CustomRetailer;
|
6 |
import com.spice.profitmandi.common.model.CustomRetailer;
|
| 6 |
import com.spice.profitmandi.dao.entity.transaction.*;
|
7 |
import com.spice.profitmandi.dao.entity.transaction.*;
|
| - |
|
8 |
import com.spice.profitmandi.dao.entity.fofo.FofoStore;
|
| - |
|
9 |
import com.spice.profitmandi.dao.entity.user.Address;
|
| - |
|
10 |
import com.spice.profitmandi.dao.entity.user.User;
|
| - |
|
11 |
import com.spice.profitmandi.dao.repository.dtr.FofoStoreRepository;
|
| 7 |
import com.spice.profitmandi.dao.repository.inventory.StateRepository;
|
12 |
import com.spice.profitmandi.dao.repository.inventory.StateRepository;
|
| - |
|
13 |
import com.spice.profitmandi.dao.repository.user.AddressRepository;
|
| - |
|
14 |
import com.spice.profitmandi.dao.repository.user.UserRepository;
|
| 8 |
import com.spice.profitmandi.dao.repository.transaction.*;
|
15 |
import com.spice.profitmandi.dao.repository.transaction.*;
|
| 9 |
import org.springframework.beans.factory.annotation.Autowired;
|
16 |
import org.springframework.beans.factory.annotation.Autowired;
|
| 10 |
import org.springframework.stereotype.Component;
|
17 |
import org.springframework.stereotype.Component;
|
| 11 |
|
18 |
|
| - |
|
19 |
import java.time.LocalDateTime;
|
| - |
|
20 |
|
| 12 |
@Component
|
21 |
@Component
|
| 13 |
public class SellerServiceImpl implements SellerService {
|
22 |
public class SellerServiceImpl implements SellerService {
|
| 14 |
|
23 |
|
| 15 |
@Autowired
|
24 |
@Autowired
|
| 16 |
OrganisationRepository organisationRepository;
|
25 |
OrganisationRepository organisationRepository;
|
| Line 28... |
Line 37... |
| 28 |
WarehouseAddressMappingRepository warehouseAddressMappingRepository;
|
37 |
WarehouseAddressMappingRepository warehouseAddressMappingRepository;
|
| 29 |
|
38 |
|
| 30 |
@Autowired
|
39 |
@Autowired
|
| 31 |
WarehouseAddressMasterRepository warehouseAddressMasterRepository;
|
40 |
WarehouseAddressMasterRepository warehouseAddressMasterRepository;
|
| 32 |
|
41 |
|
| - |
|
42 |
@Autowired
|
| - |
|
43 |
FofoStoreRepository fofoStoreRepository;
|
| - |
|
44 |
|
| - |
|
45 |
@Autowired
|
| - |
|
46 |
UserRepository userUserRepository;
|
| - |
|
47 |
|
| - |
|
48 |
@Autowired
|
| - |
|
49 |
AddressRepository addressRepository;
|
| - |
|
50 |
|
| 33 |
public CustomRetailer convertToSeller(String sellerPrefix) throws ProfitMandiBusinessException {
|
51 |
public CustomRetailer convertToSeller(String sellerPrefix) throws ProfitMandiBusinessException {
|
| 34 |
SellerWarehouse sellerWarehouse = sellerWarehouseRepository.selectByPrefix(sellerPrefix);
|
52 |
SellerWarehouse sellerWarehouse = sellerWarehouseRepository.selectByPrefix(sellerPrefix);
|
| 35 |
Seller sellerInfo = sellerRepository.selectById(sellerWarehouse.getSellerId());
|
53 |
Seller sellerInfo = sellerRepository.selectById(sellerWarehouse.getSellerId());
|
| 36 |
Organisation organisation = organisationRepository.selectById(sellerInfo.getOrganisationId());
|
54 |
Organisation organisation = organisationRepository.selectById(sellerInfo.getOrganisationId());
|
| 37 |
CustomRetailer customRetailer = new CustomRetailer();
|
55 |
CustomRetailer customRetailer = new CustomRetailer();
|
| Line 54... |
Line 72... |
| 54 |
|
72 |
|
| 55 |
customRetailer.setAddress(customAddress);
|
73 |
customRetailer.setAddress(customAddress);
|
| 56 |
|
74 |
|
| 57 |
return customRetailer;
|
75 |
return customRetailer;
|
| 58 |
}
|
76 |
}
|
| - |
|
77 |
|
| - |
|
78 |
/**
|
| - |
|
79 |
* An INTERNAL store is the buying identity of a warehouse, so its user.address has to BE the
|
| - |
|
80 |
* warehouse address: order creation reads user.address for every buyer alike and no longer
|
| - |
|
81 |
* special-cases internal stores. Lines are split exactly as getCustomAddress() does, because
|
| - |
|
82 |
* that is the shape the order columns were previously filled with directly - any other split
|
| - |
|
83 |
* would silently change the address printed on the next invoice.
|
| - |
|
84 |
*
|
| - |
|
85 |
* No fallback to whatever the store already had: a warehouse with no address mapping is a data
|
| - |
|
86 |
* fault and must surface here, rather than leave an internal store quietly billing to a stale
|
| - |
|
87 |
* address, which is the failure this sync exists to end.
|
| - |
|
88 |
*/
|
| - |
|
89 |
@Override
|
| - |
|
90 |
public int syncInternalStoreAddresses(int warehouseId) throws ProfitMandiBusinessException {
|
| - |
|
91 |
WarehouseAddressMapping mapping = warehouseAddressMappingRepository.selectByWarehouseId(warehouseId);
|
| - |
|
92 |
if (mapping == null) {
|
| - |
|
93 |
throw new ProfitMandiBusinessException("Warehouse Address Mapping", warehouseId,
|
| - |
|
94 |
"No address is mapped to this warehouse");
|
| - |
|
95 |
}
|
| - |
|
96 |
WarehouseAddressMaster master = warehouseAddressMasterRepository.selectById(mapping.getAddressId());
|
| - |
|
97 |
CustomAddress warehouseAddress = master.getCustomAddress();
|
| - |
|
98 |
String stateName;
|
| - |
|
99 |
try {
|
| - |
|
100 |
stateName = stateRepository.selectById(master.getStateId()).getName();
|
| - |
|
101 |
} catch (Exception e) {
|
| - |
|
102 |
throw new ProfitMandiBusinessException("Warehouse Address State", master.getStateId(),
|
| - |
|
103 |
"Problem while fetching state");
|
| - |
|
104 |
}
|
| - |
|
105 |
|
| - |
|
106 |
int synced = 0;
|
| - |
|
107 |
for (FofoStore store : fofoStoreRepository.selectActivePartnerByWarehouse(warehouseId)) {
|
| - |
|
108 |
if (!FofoType.INTERNAL.equals(store.getFofoType())) {
|
| - |
|
109 |
continue;
|
| - |
|
110 |
}
|
| - |
|
111 |
User user = userUserRepository.selectById(store.getId());
|
| - |
|
112 |
Address address = addressRepository.selectById(user.getAddressId());
|
| - |
|
113 |
address.setLine1(warehouseAddress.getLine1());
|
| - |
|
114 |
address.setLine2(warehouseAddress.getLine2());
|
| - |
|
115 |
address.setCity(warehouseAddress.getCity());
|
| - |
|
116 |
address.setState(stateName);
|
| - |
|
117 |
address.setPinCode(warehouseAddress.getPinCode());
|
| - |
|
118 |
address.setUpdateTimestamp(LocalDateTime.now());
|
| - |
|
119 |
addressRepository.persist(address);
|
| - |
|
120 |
synced++;
|
| - |
|
121 |
}
|
| - |
|
122 |
return synced;
|
| - |
|
123 |
}
|
| 59 |
}
|
124 |
}
|