| Line 16... |
Line 16... |
| 16 |
import org.springframework.stereotype.Component;
|
16 |
import org.springframework.stereotype.Component;
|
| 17 |
|
17 |
|
| 18 |
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
|
18 |
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
|
| 19 |
import com.spice.profitmandi.common.model.CustomAddress;
|
19 |
import com.spice.profitmandi.common.model.CustomAddress;
|
| 20 |
import com.spice.profitmandi.common.model.CustomShop;
|
20 |
import com.spice.profitmandi.common.model.CustomShop;
|
| - |
|
21 |
import com.spice.profitmandi.common.model.ProfitMandiConstants;
|
| 21 |
import com.spice.profitmandi.common.model.UpdateRetailerRequest;
|
22 |
import com.spice.profitmandi.common.model.UpdateRetailerRequest;
|
| - |
|
23 |
import com.spice.profitmandi.common.util.StringUtils;
|
| - |
|
24 |
import com.spice.profitmandi.common.util.Utils;
|
| - |
|
25 |
import com.spice.profitmandi.dao.entity.dtr.DistrictMaster;
|
| 22 |
import com.spice.profitmandi.dao.entity.dtr.Retailer;
|
26 |
import com.spice.profitmandi.dao.entity.dtr.Retailer;
|
| 23 |
import com.spice.profitmandi.dao.entity.dtr.RetailerRegisteredAddress;
|
27 |
import com.spice.profitmandi.dao.entity.dtr.RetailerRegisteredAddress;
|
| 24 |
import com.spice.profitmandi.dao.entity.dtr.Shop;
|
28 |
import com.spice.profitmandi.dao.entity.dtr.Shop;
|
| 25 |
import com.spice.profitmandi.dao.entity.dtr.ShopAddress;
|
29 |
import com.spice.profitmandi.dao.entity.dtr.ShopAddress;
|
| 26 |
import com.spice.profitmandi.dao.entity.dtr.User;
|
30 |
import com.spice.profitmandi.dao.entity.dtr.User;
|
| 27 |
import com.spice.profitmandi.dao.entity.dtr.UserAccount;
|
31 |
import com.spice.profitmandi.dao.entity.dtr.UserAccount;
|
| 28 |
import com.spice.profitmandi.dao.entity.dtr.UserRole;
|
32 |
import com.spice.profitmandi.dao.entity.dtr.UserRole;
|
| - |
|
33 |
import com.spice.profitmandi.dao.entity.fofo.FofoStore;
|
| - |
|
34 |
import com.spice.profitmandi.dao.entity.fofo.FofoStoreSequenceGeneration;
|
| 29 |
import com.spice.profitmandi.dao.entity.user.Address;
|
35 |
import com.spice.profitmandi.dao.entity.user.Address;
|
| 30 |
import com.spice.profitmandi.dao.entity.user.Cart;
|
36 |
import com.spice.profitmandi.dao.entity.user.Cart;
|
| - |
|
37 |
import com.spice.profitmandi.dao.entity.user.Counter;
|
| - |
|
38 |
import com.spice.profitmandi.dao.entity.user.PrivateDealUser;
|
| - |
|
39 |
import com.spice.profitmandi.dao.entity.user.PrivateDealUserAddressMapping;
|
| 31 |
import com.spice.profitmandi.dao.enumuration.dtr.AccountType;
|
40 |
import com.spice.profitmandi.dao.enumuration.dtr.AccountType;
|
| 32 |
import com.spice.profitmandi.dao.enumuration.dtr.RetailerType;
|
41 |
import com.spice.profitmandi.dao.enumuration.dtr.RetailerType;
|
| 33 |
import com.spice.profitmandi.dao.enumuration.dtr.RoleType;
|
42 |
import com.spice.profitmandi.dao.enumuration.dtr.RoleType;
|
| - |
|
43 |
import com.spice.profitmandi.dao.repository.dtr.DistrictMasterRepository;
|
| 34 |
import com.spice.profitmandi.dao.repository.dtr.DocumentRepository;
|
44 |
import com.spice.profitmandi.dao.repository.dtr.DocumentRepository;
|
| - |
|
45 |
import com.spice.profitmandi.dao.repository.dtr.FofoStoreRepository;
|
| - |
|
46 |
import com.spice.profitmandi.dao.repository.dtr.FofoStoreSequenceGenerationRepository;
|
| 35 |
import com.spice.profitmandi.dao.repository.dtr.RetailerRegisteredAddressRepository;
|
47 |
import com.spice.profitmandi.dao.repository.dtr.RetailerRegisteredAddressRepository;
|
| 36 |
import com.spice.profitmandi.dao.repository.dtr.RetailerRepository;
|
48 |
import com.spice.profitmandi.dao.repository.dtr.RetailerRepository;
|
| 37 |
import com.spice.profitmandi.dao.repository.dtr.ShopAddressRepository;
|
49 |
import com.spice.profitmandi.dao.repository.dtr.ShopAddressRepository;
|
| 38 |
import com.spice.profitmandi.dao.repository.dtr.ShopRepository;
|
50 |
import com.spice.profitmandi.dao.repository.dtr.ShopRepository;
|
| 39 |
import com.spice.profitmandi.dao.repository.dtr.UserAccountRepository;
|
51 |
import com.spice.profitmandi.dao.repository.dtr.UserAccountRepository;
|
| 40 |
import com.spice.profitmandi.dao.repository.dtr.UserRepository;
|
52 |
import com.spice.profitmandi.dao.repository.dtr.UserRepository;
|
| 41 |
import com.spice.profitmandi.dao.repository.dtr.UserRoleRepository;
|
53 |
import com.spice.profitmandi.dao.repository.dtr.UserRoleRepository;
|
| 42 |
import com.spice.profitmandi.dao.repository.user.AddressRepository;
|
54 |
import com.spice.profitmandi.dao.repository.user.AddressRepository;
|
| 43 |
import com.spice.profitmandi.dao.repository.user.CartRepository;
|
55 |
import com.spice.profitmandi.dao.repository.user.CartRepository;
|
| - |
|
56 |
import com.spice.profitmandi.dao.repository.user.CounterRepository;
|
| - |
|
57 |
import com.spice.profitmandi.dao.repository.user.PrivateDealUserAddressMappingRepository;
|
| - |
|
58 |
import com.spice.profitmandi.dao.repository.user.PrivateDealUserRepository;
|
| 44 |
|
59 |
|
| - |
|
60 |
import in.shop2020.model.v1.inventory.StateInfo;
|
| 45 |
import in.shop2020.model.v1.user.CartStatus;
|
61 |
import in.shop2020.model.v1.user.CartStatus;
|
| 46 |
|
62 |
|
| 47 |
@Component
|
63 |
@Component
|
| 48 |
public class RetailerServiceImpl implements RetailerService {
|
64 |
public class RetailerServiceImpl implements RetailerService {
|
| 49 |
|
65 |
|
| Line 78... |
Line 94... |
| 78 |
|
94 |
|
| 79 |
@Autowired
|
95 |
@Autowired
|
| 80 |
private DocumentRepository documentRepository;
|
96 |
private DocumentRepository documentRepository;
|
| 81 |
|
97 |
|
| 82 |
@Autowired
|
98 |
@Autowired
|
| - |
|
99 |
private PrivateDealUserRepository privateDealUserRepository;
|
| - |
|
100 |
|
| - |
|
101 |
@Autowired
|
| - |
|
102 |
private PrivateDealUserAddressMappingRepository privateDealUserAddressMappingRepository;
|
| - |
|
103 |
|
| - |
|
104 |
@Autowired
|
| - |
|
105 |
private CounterRepository counterRepository;
|
| - |
|
106 |
|
| - |
|
107 |
@Autowired
|
| 83 |
@Qualifier("userUserRepository")
|
108 |
@Qualifier("userUserRepository")
|
| 84 |
private com.spice.profitmandi.dao.repository.user.UserRepository userUserRepository;
|
109 |
private com.spice.profitmandi.dao.repository.user.UserRepository userUserRepository;
|
| 85 |
|
110 |
|
| - |
|
111 |
@Autowired
|
| - |
|
112 |
private DistrictMasterRepository districtMasterRepository;
|
| - |
|
113 |
|
| - |
|
114 |
@Autowired
|
| - |
|
115 |
private FofoStoreRepository fofoStoreRepository;
|
| - |
|
116 |
|
| - |
|
117 |
@Autowired
|
| - |
|
118 |
private FofoStoreSequenceGenerationRepository fofoStoreSequenceGenerationRepository;
|
| - |
|
119 |
|
| 86 |
@Override
|
120 |
@Override
|
| 87 |
public Map<String, Object> getByEmailIdOrMobileNumber(String emailIdOrMobileNumber)
|
121 |
public Map<String, Object> getByEmailIdOrMobileNumber(String emailIdOrMobileNumber)
|
| 88 |
throws ProfitMandiBusinessException {
|
122 |
throws ProfitMandiBusinessException {
|
| 89 |
User user = null;
|
123 |
User user = null;
|
| 90 |
try{
|
124 |
try{
|
| 91 |
user = userRepository.selectByEmailIdOrMobileNumber(emailIdOrMobileNumber);
|
125 |
user = userRepository.selectByEmailIdOrMobileNumber(emailIdOrMobileNumber);
|
| 92 |
}catch(ProfitMandiBusinessException profitMandiBusinessException){
|
126 |
}catch(ProfitMandiBusinessException profitMandiBusinessException){
|
| 93 |
|
127 |
|
| 94 |
}
|
128 |
}
|
| 95 |
if(user == null){
|
129 |
if(user == null){
|
| - |
|
130 |
try{
|
| 96 |
user = userRepository.selectBySecondryEmailId(emailIdOrMobileNumber);
|
131 |
user = userRepository.selectBySecondryEmailId(emailIdOrMobileNumber);
|
| - |
|
132 |
}catch(ProfitMandiBusinessException profitMandiBusinessException){
|
| - |
|
133 |
|
| - |
|
134 |
}
|
| 97 |
}
|
135 |
}
|
| 98 |
List<UserRole> userRoles = userRoleRepository.selectByUserId(user.getId());
|
- |
|
| 99 |
Map<String, Object> map = new HashMap<>();
|
136 |
Map<String, Object> map = new HashMap<>();
|
| 100 |
map.put("user", user);
|
- |
|
| 101 |
//map.put("retailer", retailer);
|
137 |
map.put("stateNames", Utils.getAllStateNames());
|
| 102 |
|
138 |
|
| - |
|
139 |
if(user != null){
|
| 103 |
|
140 |
|
| 104 |
map.put("userRoles", this.toString(userRoles));
|
- |
|
| 105 |
try{
|
- |
|
| 106 |
int retailerId = userAccountRepository.selectRetailerIdByUserId(user.getId());
|
141 |
List<UserRole> userRoles = userRoleRepository.selectByUserId(user.getId());
|
| 107 |
Retailer retailer = retailerRepository.selectById(retailerId);
|
- |
|
| 108 |
|
142 |
|
| - |
|
143 |
map.put("userRoles", userRoles);
|
| - |
|
144 |
map.put("user", user);
|
| 109 |
map.put("retailer", retailer);
|
145 |
//map.put("retailer", retailer);
|
| - |
|
146 |
map.put("fofoRole", this.containsRoleType(userRoles, RoleType.FOFO));
|
| - |
|
147 |
|
| - |
|
148 |
map.put("userRoleNames", this.toString(userRoles));
|
| 110 |
try{
|
149 |
try{
|
| - |
|
150 |
int retailerId = userAccountRepository.selectRetailerIdByUserId(user.getId());
|
| - |
|
151 |
Retailer retailer = retailerRepository.selectById(retailerId);
|
| - |
|
152 |
|
| - |
|
153 |
map.put("retailer", retailer);
|
| - |
|
154 |
|
| - |
|
155 |
if(this.containsRoleType(userRoles, RoleType.FOFO)){
|
| - |
|
156 |
try{
|
| - |
|
157 |
FofoStore fofoStore = fofoStoreRepository.selectByRetailerId(retailerId);
|
| - |
|
158 |
map.put("fofoStore", fofoStore);
|
| - |
|
159 |
}catch(ProfitMandiBusinessException profitMandiBusinessException){
|
| - |
|
160 |
LOGGER.error("FofoStore code not found");
|
| - |
|
161 |
}
|
| - |
|
162 |
}
|
| - |
|
163 |
|
| - |
|
164 |
|
| - |
|
165 |
try{
|
| - |
|
166 |
PrivateDealUser privateDealUser = privateDealUserRepository.selectById(retailer.getId());
|
| - |
|
167 |
if(privateDealUser.getCounterId() != null){
|
| - |
|
168 |
Counter counter = counterRepository.selectById(privateDealUser.getCounterId());
|
| - |
|
169 |
map.put("gstNumber", counter.getGstin());
|
| - |
|
170 |
}
|
| - |
|
171 |
}catch(ProfitMandiBusinessException profitMandiBusinessException){
|
| - |
|
172 |
LOGGER.error("PrivateDealUser not found");
|
| - |
|
173 |
}
|
| - |
|
174 |
try{
|
| 111 |
int retailerAddressId = retailerRegisteredAddressRepository.selectAddressIdByRetailerId(retailer.getId());
|
175 |
int retailerAddressId = retailerRegisteredAddressRepository.selectAddressIdByRetailerId(retailer.getId());
|
| 112 |
Address retailerAddress = addressRepository.selectById(retailerAddressId);
|
176 |
Address retailerAddress = addressRepository.selectById(retailerAddressId);
|
| 113 |
map.put("retailerAddress", retailerAddress);
|
177 |
map.put("retailerAddress", retailerAddress);
|
| - |
|
178 |
StateInfo stateInfo = null;
|
| - |
|
179 |
try {
|
| - |
|
180 |
stateInfo = Utils.getStateInfo(retailerAddress.getState());
|
| - |
|
181 |
} catch (Exception e) {
|
| - |
|
182 |
e.printStackTrace();
|
| - |
|
183 |
//throw new ProfitMandiBusinessException();
|
| - |
|
184 |
}
|
| - |
|
185 |
List<DistrictMaster> districtMasters = districtMasterRepository.selectByStateShortName(stateInfo.getShortName());
|
| - |
|
186 |
map.put("districtMasters", districtMasters);
|
| - |
|
187 |
|
| 114 |
List<Shop> shops = shopRepository.selectByRetailerId(retailer.getId());
|
188 |
List<Shop> shops = shopRepository.selectByRetailerId(retailer.getId());
|
| 115 |
map.put("shops", shops);
|
189 |
map.put("shops", shops);
|
| 116 |
this.addAddress(shops);
|
190 |
this.addAddress(shops);
|
| - |
|
191 |
}catch(ProfitMandiBusinessException profitMandiBusinessException){
|
| - |
|
192 |
LOGGER.error("Retailer Registered Address not found");
|
| - |
|
193 |
}
|
| 117 |
}catch(ProfitMandiBusinessException profitMandiBusinessException){
|
194 |
}catch(ProfitMandiBusinessException profitMandiBusinessException){
|
| 118 |
LOGGER.error("Retailer Registered Address not found");
|
195 |
LOGGER.error("Retailer not found in user_account");
|
| 119 |
}
|
196 |
}
|
| 120 |
}catch(ProfitMandiBusinessException profitMandiBusinessException){
|
- |
|
| 121 |
LOGGER.error("Retailer not found in user_account");
|
- |
|
| 122 |
}
|
197 |
}
|
| 123 |
|
198 |
|
| 124 |
return map;
|
199 |
return map;
|
| 125 |
}
|
200 |
}
|
| 126 |
|
201 |
|
| - |
|
202 |
private boolean containsRoleType(List<UserRole> userRoles, RoleType roleType){
|
| - |
|
203 |
for(UserRole userRole : userRoles){
|
| - |
|
204 |
if(userRole.getRoleType() == roleType){
|
| - |
|
205 |
return true;
|
| - |
|
206 |
}
|
| - |
|
207 |
}
|
| - |
|
208 |
return false;
|
| - |
|
209 |
}
|
| - |
|
210 |
|
| - |
|
211 |
private List<UserRole> addRole(List<UserRole> userRoles, int userId, RoleType roleType){
|
| - |
|
212 |
if(userRoles == null){
|
| - |
|
213 |
userRoles = new ArrayList<>();
|
| - |
|
214 |
}
|
| - |
|
215 |
if(!this.containsRoleType(userRoles, roleType)){
|
| - |
|
216 |
UserRole userRole = new UserRole();
|
| - |
|
217 |
userRole.setUserId(userId);
|
| - |
|
218 |
userRole.setRoleType(roleType);
|
| - |
|
219 |
try {
|
| - |
|
220 |
userRoleRepository.persist(userRole);
|
| - |
|
221 |
} catch (ProfitMandiBusinessException e) {
|
| - |
|
222 |
LOGGER.error("UserRole is already exist");
|
| - |
|
223 |
}
|
| - |
|
224 |
userRoles.add(userRole);
|
| - |
|
225 |
}
|
| - |
|
226 |
return userRoles;
|
| - |
|
227 |
|
| - |
|
228 |
}
|
| - |
|
229 |
|
| 127 |
@SuppressWarnings("unchecked")
|
230 |
@SuppressWarnings("unchecked")
|
| 128 |
@Override
|
231 |
@Override
|
| 129 |
public Map<String, Object> updateRetailerDetails(UpdateRetailerRequest updateRetailerRequest)
|
232 |
public Map<String, Object> updateRetailerDetails(UpdateRetailerRequest updateRetailerRequest)
|
| 130 |
throws ProfitMandiBusinessException {
|
233 |
throws ProfitMandiBusinessException {
|
| 131 |
Map<String, Object> map = this.getByEmailIdOrMobileNumber(updateRetailerRequest.getEmailIdOrMobileNumber());
|
234 |
Map<String, Object> map = this.getByEmailIdOrMobileNumber(updateRetailerRequest.getEmailIdOrMobileNumber());
|
| - |
|
235 |
|
| 132 |
User user = (User)map.get("user");
|
236 |
User user = (User)map.get("user");
|
| - |
|
237 |
user = this.createUser(user, updateRetailerRequest);
|
| - |
|
238 |
map.put("user", user);
|
| - |
|
239 |
|
| - |
|
240 |
List<UserRole> userRoles = (List<UserRole>)map.get("userRoles");
|
| - |
|
241 |
|
| - |
|
242 |
userRoles = this.addRole(userRoles, user.getId(), RoleType.USER);
|
| - |
|
243 |
|
| 133 |
Retailer retailer = (Retailer)map.get("retailer");
|
244 |
Retailer retailer = (Retailer)map.get("retailer");
|
| 134 |
if(retailer == null){
|
- |
|
| 135 |
retailer = this.updateRetailer(user, retailer, updateRetailerRequest);
|
245 |
retailer = this.updateRetailer(user, retailer, updateRetailerRequest);
|
| 136 |
map.put("retailer", retailer);
|
246 |
map.put("retailer", retailer);
|
| - |
|
247 |
|
| - |
|
248 |
userRoles = this.addRole(userRoles, user.getId(), RoleType.RETAILER);
|
| - |
|
249 |
|
| - |
|
250 |
if(updateRetailerRequest.isFofo()){
|
| - |
|
251 |
userRoles = this.addRole(userRoles, user.getId(), RoleType.FOFO);
|
| 137 |
}
|
252 |
}
|
| - |
|
253 |
|
| - |
|
254 |
if(this.containsRoleType(userRoles, RoleType.FOFO)){
|
| - |
|
255 |
|
| - |
|
256 |
}
|
| - |
|
257 |
|
| - |
|
258 |
map.put("userRoles", userRoles);
|
| - |
|
259 |
map.put("userRoleNames", this.toString(userRoles));
|
| - |
|
260 |
|
| 138 |
Address retailerAddress = (Address)map.get("retailerAddress");
|
261 |
Address retailerAddress = (Address)map.get("retailerAddress");
|
| 139 |
if(retailerAddress == null){
|
- |
|
| 140 |
retailerAddress = this.updateRetailerAddress(retailerAddress, updateRetailerRequest.getAddress(), retailer.getId());
|
262 |
retailerAddress = this.updateRetailerAddress(retailerAddress, updateRetailerRequest.getAddress(), retailer.getId());
|
| 141 |
map.put("retailerAddress", retailerAddress);
|
263 |
map.put("retailerAddress", retailerAddress);
|
| - |
|
264 |
|
| - |
|
265 |
if(updateRetailerRequest.isFofo()){
|
| - |
|
266 |
this.createFofoStoreCodeByUserId(user.getId(), updateRetailerRequest.getDistrictName(), retailerAddress.getState());
|
| 142 |
}
|
267 |
}
|
| - |
|
268 |
|
| - |
|
269 |
this.createPrivateDealUser(user, updateRetailerRequest.isFofo(), updateRetailerRequest.getGstNumber(), retailer, retailerAddress.getId());
|
| - |
|
270 |
map.put("gstNumber", updateRetailerRequest.getGstNumber());
|
| - |
|
271 |
this.updateSaholicUser(retailer.getId(), retailerAddress.getId());
|
| - |
|
272 |
|
| 143 |
List<Shop> shops = (List<Shop>)map.get("shops");
|
273 |
List<Shop> shops = (List<Shop>)map.get("shops");
|
| 144 |
if(shops == null){
|
274 |
if(shops == null){
|
| 145 |
shops = new ArrayList<>();
|
275 |
shops = new ArrayList<>();
|
| 146 |
map.put("shops", shops);
|
276 |
map.put("shops", shops);
|
| 147 |
}
|
277 |
}
|
| 148 |
this.updateRetailerShops(shops, updateRetailerRequest.getShops(), retailer.getId(), retailerAddress);
|
278 |
this.updateRetailerShops(shops, updateRetailerRequest.getShops(), retailer.getId(), retailerAddress);
|
| 149 |
return map;
|
279 |
return map;
|
| 150 |
}
|
280 |
}
|
| 151 |
|
281 |
|
| - |
|
282 |
private User createUser(User user, UpdateRetailerRequest updateRetailerRequest){
|
| - |
|
283 |
if(user == null){
|
| - |
|
284 |
user = new User();
|
| - |
|
285 |
user.setCity("");
|
| - |
|
286 |
user.setPinCode(0);
|
| - |
|
287 |
user.setState("");
|
| - |
|
288 |
user.setPassword("");
|
| - |
|
289 |
user.setMobile_verified(false);
|
| - |
|
290 |
user.setReferral_url("");
|
| - |
|
291 |
user.setGroup_id(1);
|
| - |
|
292 |
user.setStatus(1);
|
| - |
|
293 |
user.setActivated(true);
|
| - |
|
294 |
user.setCreateTimestamp(LocalDateTime.now());
|
| - |
|
295 |
user.setUpdateTimestamp(LocalDateTime.now());
|
| - |
|
296 |
userRepository.persist(user);
|
| - |
|
297 |
}
|
| - |
|
298 |
user.setFirstName(updateRetailerRequest.getUserFirstName());
|
| - |
|
299 |
user.setLastName(updateRetailerRequest.getUserLastName());
|
| - |
|
300 |
user.setMobileNumber(updateRetailerRequest.getUserMobileNumber());
|
| - |
|
301 |
user.setEmailId(updateRetailerRequest.getUserEmailId());
|
| - |
|
302 |
user.setUsername(updateRetailerRequest.getUserEmailId());
|
| - |
|
303 |
return user;
|
| - |
|
304 |
}
|
| - |
|
305 |
|
| - |
|
306 |
|
| - |
|
307 |
|
| 152 |
private int createSaholicUser(User user, String retailerName){
|
308 |
private int createSaholicUser(User user, String retailerName){
|
| 153 |
com.spice.profitmandi.dao.entity.user.User saholicUser = null;
|
309 |
com.spice.profitmandi.dao.entity.user.User saholicUser = null;
|
| 154 |
try {
|
310 |
try {
|
| 155 |
saholicUser = userUserRepository.selectByEmailId(user.getEmailId());
|
311 |
saholicUser = userUserRepository.selectByEmailId(user.getEmailId());
|
| 156 |
}catch (ProfitMandiBusinessException e) {
|
312 |
}catch (ProfitMandiBusinessException e) {
|
| Line 186... |
Line 342... |
| 186 |
if(retailer == null){
|
342 |
if(retailer == null){
|
| 187 |
int saholicUserId = this.createSaholicUser(user, updateRetailerRequest.getName());
|
343 |
int saholicUserId = this.createSaholicUser(user, updateRetailerRequest.getName());
|
| 188 |
retailer = new Retailer();
|
344 |
retailer = new Retailer();
|
| 189 |
retailer.setId(saholicUserId);
|
345 |
retailer.setId(saholicUserId);
|
| 190 |
}
|
346 |
}
|
| - |
|
347 |
retailer.setActive(updateRetailerRequest.isActive());
|
| 191 |
this.createRole(user.getId(), RoleType.RETAILER);
|
348 |
this.createRole(user.getId(), RoleType.RETAILER);
|
| 192 |
retailer.setName(updateRetailerRequest.getName());
|
349 |
retailer.setName(updateRetailerRequest.getName());
|
| 193 |
retailer.setNumber(updateRetailerRequest.getNumber());
|
350 |
retailer.setNumber(updateRetailerRequest.getNumber());
|
| 194 |
if(updateRetailerRequest.getNumber() == null || updateRetailerRequest.getNumber().isEmpty()){
|
351 |
if(updateRetailerRequest.getNumber() == null || updateRetailerRequest.getNumber().isEmpty()){
|
| 195 |
retailer.setType(RetailerType.UNREGISTERED_SHOP);
|
352 |
retailer.setType(RetailerType.UNREGISTERED_SHOP);
|
| Line 201... |
Line 358... |
| 201 |
}
|
358 |
}
|
| 202 |
retailerRepository.persist(retailer);
|
359 |
retailerRepository.persist(retailer);
|
| 203 |
return retailer;
|
360 |
return retailer;
|
| 204 |
}
|
361 |
}
|
| 205 |
|
362 |
|
| - |
|
363 |
private void updateSaholicUser(int retailerId, int retailerAddressId){
|
| - |
|
364 |
try {
|
| - |
|
365 |
com.spice.profitmandi.dao.entity.user.User user = userUserRepository.selectById(retailerId);
|
| - |
|
366 |
user.setAddressId(retailerAddressId);
|
| - |
|
367 |
userUserRepository.persist(user);
|
| - |
|
368 |
} catch (ProfitMandiBusinessException e) {
|
| - |
|
369 |
|
| - |
|
370 |
}
|
| - |
|
371 |
}
|
| - |
|
372 |
|
| - |
|
373 |
private void createPrivateDealUser(User user, boolean fofo, String gstNumber, Retailer retailer, int retailerAddressId){
|
| - |
|
374 |
PrivateDealUser privateDealUser = null;
|
| - |
|
375 |
try{
|
| - |
|
376 |
privateDealUser = privateDealUserRepository.selectById(retailer.getId());
|
| - |
|
377 |
}catch(ProfitMandiBusinessException profitMandiBusinessException){
|
| - |
|
378 |
LOGGER.error("PrivateDealUser not found");
|
| - |
|
379 |
}
|
| - |
|
380 |
|
| - |
|
381 |
//= privateDealUserRepository.selectById(saholicUser.getId());
|
| - |
|
382 |
if(privateDealUser == null){
|
| - |
|
383 |
Integer counterId = this.createCounter(user.getEmailId(), gstNumber, user.getMobileNumber(), retailer.getName(), retailerAddressId);
|
| - |
|
384 |
this.createPrivateDealUser(retailer.getId(), counterId, fofo);
|
| - |
|
385 |
}else{
|
| - |
|
386 |
if(privateDealUser.getCounterId() == null){
|
| - |
|
387 |
Integer counterId = this.createCounter(user.getEmailId(), gstNumber, user.getMobileNumber(), retailer.getName(), retailerAddressId);
|
| - |
|
388 |
privateDealUser.setCounterId(counterId);
|
| - |
|
389 |
privateDealUser.setFofo(fofo);
|
| - |
|
390 |
privateDealUserRepository.persist(privateDealUser);
|
| - |
|
391 |
}else{
|
| - |
|
392 |
Counter counter = null;
|
| - |
|
393 |
try{
|
| - |
|
394 |
counter = counterRepository.selectById(privateDealUser.getCounterId());
|
| - |
|
395 |
}catch(ProfitMandiBusinessException profitMandiBusinessException){
|
| - |
|
396 |
LOGGER.error("Counter not found with id [{}]", privateDealUser.getCounterId());
|
| - |
|
397 |
}
|
| - |
|
398 |
if(counter == null){
|
| - |
|
399 |
this.createCounter(user.getEmailId(), gstNumber, user.getMobileNumber(), retailer.getName(), retailerAddressId);
|
| - |
|
400 |
}else{
|
| - |
|
401 |
counter.setGstin(gstNumber);
|
| - |
|
402 |
counterRepository.persist(counter);
|
| - |
|
403 |
}
|
| - |
|
404 |
privateDealUser.setFofo(fofo);
|
| - |
|
405 |
privateDealUserRepository.persist(privateDealUser);
|
| - |
|
406 |
}
|
| - |
|
407 |
}
|
| - |
|
408 |
|
| - |
|
409 |
PrivateDealUserAddressMapping privateDealUserAddressMapping = new PrivateDealUserAddressMapping();
|
| - |
|
410 |
privateDealUserAddressMapping.setUserId(retailer.getId());
|
| - |
|
411 |
privateDealUserAddressMapping.setAddressId(retailerAddressId);
|
| - |
|
412 |
privateDealUserAddressMappingRepository.persist(privateDealUserAddressMapping);
|
| - |
|
413 |
}
|
| - |
|
414 |
|
| - |
|
415 |
//Specifically set isFofo to true that has to be used by old system
|
| - |
|
416 |
private void createPrivateDealUser(int retailerId, int counterId, boolean fofo){
|
| - |
|
417 |
PrivateDealUser privateDealUser = new PrivateDealUser();
|
| - |
|
418 |
privateDealUser.setActive(true);
|
| - |
|
419 |
privateDealUser.setBulkShipmentAmountLimit(fofo ? 1000000 : 50000);
|
| - |
|
420 |
privateDealUser.setId(retailerId);
|
| - |
|
421 |
privateDealUser.setCounterId(counterId);
|
| - |
|
422 |
privateDealUser.setFofo(fofo);
|
| - |
|
423 |
privateDealUserRepository.persist(privateDealUser);
|
| - |
|
424 |
}
|
| - |
|
425 |
|
| - |
|
426 |
private Integer createCounter(String emailId, String gstNumber, String mobileNumber, String name, int addressId){
|
| - |
|
427 |
if(gstNumber != null && !gstNumber.isEmpty()){
|
| - |
|
428 |
Counter counter = new Counter();
|
| - |
|
429 |
counter.setEmailId(emailId);
|
| - |
|
430 |
counter.setGstin(gstNumber);
|
| - |
|
431 |
counter.setMobileNumber(mobileNumber);
|
| - |
|
432 |
counter.setName(name);
|
| - |
|
433 |
counter.setAddressId(addressId);
|
| - |
|
434 |
counterRepository.persist(counter);
|
| - |
|
435 |
return counter.getId();
|
| - |
|
436 |
}else{
|
| - |
|
437 |
return null;
|
| - |
|
438 |
}
|
| - |
|
439 |
}
|
| - |
|
440 |
|
| 206 |
private void createRole(int userId, RoleType roleType){
|
441 |
private void createRole(int userId, RoleType roleType){
|
| 207 |
if(!userRoleRepository.isExistByUserIdAndType(userId, roleType)){
|
442 |
if(!userRoleRepository.isExistByUserIdAndType(userId, roleType)){
|
| 208 |
UserRole userRole = new UserRole();
|
443 |
UserRole userRole = new UserRole();
|
| 209 |
userRole.setUserId(userId);
|
444 |
userRole.setUserId(userId);
|
| 210 |
userRole.setRoleType(roleType);
|
445 |
userRole.setRoleType(roleType);
|
| Line 298... |
Line 533... |
| 298 |
shopAddress.setShopId(shop.getId());
|
533 |
shopAddress.setShopId(shop.getId());
|
| 299 |
}
|
534 |
}
|
| 300 |
shopAddressRepository.persist(shopAddress);
|
535 |
shopAddressRepository.persist(shopAddress);
|
| 301 |
}else{
|
536 |
}else{
|
| 302 |
Address address = addressRepository.selectById(shop.getAddressId());
|
537 |
Address address = addressRepository.selectById(shop.getAddressId());
|
| - |
|
538 |
LOGGER.info("found address : {}", address);
|
| 303 |
CustomAddress customAddress = customShop.getAddress();
|
539 |
CustomAddress customAddress = customShop.getAddress();
|
| - |
|
540 |
LOGGER.info("requested address : {}", customAddress);
|
| 304 |
if(address.getName().equals(customAddress.getName()) &&
|
541 |
if(!(address.getName().equals(customAddress.getName()) &&
|
| 305 |
address.getLine1().equals(customAddress.getLine1()) &&
|
542 |
address.getLine1().equals(customAddress.getLine1()) &&
|
| 306 |
address.getLine2().equals(customAddress.getLine2()) &&
|
543 |
address.getLine2().equals(customAddress.getLine2()) &&
|
| 307 |
address.getCity().equals(customAddress.getCity()) &&
|
544 |
address.getCity().equals(customAddress.getCity()) &&
|
| 308 |
address.getPinCode().equals(customAddress.getPinCode()) &&
|
545 |
address.getPinCode().equals(customAddress.getPinCode()) &&
|
| 309 |
address.getState().equals(customAddress.getState())){
|
546 |
address.getState().equals(customAddress.getState()))){
|
| 310 |
this.updateAddress(address, customShop.getAddress());
|
547 |
this.updateAddress(address, customShop.getAddress());
|
| 311 |
}else{
|
548 |
}else{
|
| 312 |
address = new Address();
|
549 |
address = new Address();
|
| 313 |
ShopAddress shopAddress = shopAddressRepository.selectByShopId(shop.getId());
|
550 |
ShopAddress shopAddress = shopAddressRepository.selectByShopId(shop.getId());
|
| 314 |
this.updateAddress(address, customAddress);
|
551 |
this.updateAddress(address, customAddress);
|
| Line 373... |
Line 610... |
| 373 |
};
|
610 |
};
|
| 374 |
};
|
611 |
};
|
| 375 |
Set<String> userRoleStrings = userRoles.stream().map(userRoleToRoleNameFunction).collect(Collectors.toSet());
|
612 |
Set<String> userRoleStrings = userRoles.stream().map(userRoleToRoleNameFunction).collect(Collectors.toSet());
|
| 376 |
return String.join(", ", userRoleStrings);
|
613 |
return String.join(", ", userRoleStrings);
|
| 377 |
}
|
614 |
}
|
| - |
|
615 |
|
| - |
|
616 |
@Override
|
| - |
|
617 |
public void createFofoStoreCodeByUserId(int userId, String districtName, String stateName) throws ProfitMandiBusinessException {
|
| - |
|
618 |
User user = userRepository.selectById(userId);
|
| - |
|
619 |
// = userAccountRepository.selectRetailerIdByUserId(user.getId());
|
| - |
|
620 |
UserAccount userAccounts = userAccountRepository.selectSaholicByUserId(user.getId());
|
| - |
|
621 |
Retailer retailer = retailerRepository.selectById(userAccounts.getAccountKey());
|
| - |
|
622 |
try{
|
| - |
|
623 |
userRoleRepository.selectByUserIdAndRoleType(user.getId(), RoleType.FOFO);
|
| - |
|
624 |
}catch(ProfitMandiBusinessException profitMandiBusinessException){
|
| - |
|
625 |
throw new ProfitMandiBusinessException(ProfitMandiConstants.USER_ID, user.getId(), "USR_1013");
|
| - |
|
626 |
}
|
| - |
|
627 |
|
| - |
|
628 |
boolean foundFofoStore = false;
|
| - |
|
629 |
try{
|
| - |
|
630 |
fofoStoreRepository.selectByRetailerId(retailer.getId());
|
| - |
|
631 |
foundFofoStore = true;
|
| - |
|
632 |
}catch (ProfitMandiBusinessException profitMandiBusinessException) {
|
| - |
|
633 |
|
| - |
|
634 |
}
|
| - |
|
635 |
|
| - |
|
636 |
if(foundFofoStore){
|
| - |
|
637 |
throw new ProfitMandiBusinessException(ProfitMandiConstants.RETAILER_ID, retailer.getId(), "USR_1014");
|
| - |
|
638 |
}
|
| - |
|
639 |
|
| - |
|
640 |
int retailerAddressId = retailerRegisteredAddressRepository.selectAddressIdByRetailerId(retailer.getId());
|
| - |
|
641 |
Address retailerAddress = addressRepository.selectById(retailerAddressId);
|
| - |
|
642 |
|
| - |
|
643 |
StateInfo stateInfo = null;
|
| - |
|
644 |
try {
|
| - |
|
645 |
stateInfo = Utils.getStateInfo(retailerAddress.getState());
|
| - |
|
646 |
} catch (Exception e) {
|
| - |
|
647 |
// TODO Auto-generated catch block
|
| - |
|
648 |
e.printStackTrace();
|
| - |
|
649 |
//throw new ProfitMandiBusinessException();
|
| - |
|
650 |
}
|
| - |
|
651 |
DistrictMaster districtMaster = districtMasterRepository.selectByNameAndStateShortName(districtName, stateInfo.getShortName());
|
| - |
|
652 |
|
| - |
|
653 |
FofoStoreSequenceGeneration fofoStoreSequenceGeneration = null;
|
| - |
|
654 |
boolean foundFofoStoreSequence = false;
|
| - |
|
655 |
try{
|
| - |
|
656 |
fofoStoreSequenceGeneration = fofoStoreSequenceGenerationRepository.selectByStateShortName(stateInfo.getShortName());
|
| - |
|
657 |
foundFofoStoreSequence = true;
|
| - |
|
658 |
}catch(ProfitMandiBusinessException profitMandiBusinessException){
|
| - |
|
659 |
fofoStoreSequenceGeneration = new FofoStoreSequenceGeneration();
|
| - |
|
660 |
fofoStoreSequenceGeneration.setSequence(1);
|
| - |
|
661 |
fofoStoreSequenceGeneration.setStateShortName(stateInfo.getShortName());
|
| - |
|
662 |
fofoStoreSequenceGenerationRepository.persist(fofoStoreSequenceGeneration);
|
| - |
|
663 |
}
|
| - |
|
664 |
|
| - |
|
665 |
FofoStore fofoStore = new FofoStore();
|
| - |
|
666 |
fofoStore.setId(retailer.getId());
|
| - |
|
667 |
String fofoStoreCode = StringUtils.generateFofoStoreSequence(districtMaster.getStateShortName() + districtMaster.getShortName(), fofoStoreSequenceGeneration.getSequence());
|
| - |
|
668 |
if(foundFofoStoreSequence){
|
| - |
|
669 |
fofoStoreSequenceGeneration.setSequence(fofoStoreSequenceGeneration.getSequence() + 1);
|
| - |
|
670 |
fofoStoreSequenceGenerationRepository.persist(fofoStoreSequenceGeneration);
|
| - |
|
671 |
}
|
| - |
|
672 |
fofoStore.setCode(fofoStoreCode);
|
| - |
|
673 |
fofoStoreRepository.persist(fofoStore);
|
| - |
|
674 |
}
|
| - |
|
675 |
|
| - |
|
676 |
@Override
|
| - |
|
677 |
public List<DistrictMaster> getAllDistrictMaster(String stateName) {
|
| - |
|
678 |
StateInfo stateInfo = null;
|
| - |
|
679 |
try {
|
| - |
|
680 |
stateInfo = Utils.getStateInfo(stateName);
|
| - |
|
681 |
} catch (Exception e) {
|
| - |
|
682 |
e.printStackTrace();
|
| - |
|
683 |
//throw new ProfitMandiBusinessException();
|
| - |
|
684 |
}
|
| - |
|
685 |
return districtMasterRepository.selectByStateShortName(stateInfo.getShortName());
|
| - |
|
686 |
}
|
| 378 |
|
687 |
|
| 379 |
}
|
688 |
}
|