| Line 41... |
Line 41... |
| 41 |
import java.util.stream.Stream;
|
41 |
import java.util.stream.Stream;
|
| 42 |
|
42 |
|
| 43 |
@Component
|
43 |
@Component
|
| 44 |
public class RetailerServiceImpl implements RetailerService {
|
44 |
public class RetailerServiceImpl implements RetailerService {
|
| 45 |
|
45 |
|
| 46 |
private static final Logger LOGGER = LogManager.getLogger(RetailerServiceImpl.class);
|
46 |
private static final Logger LOGGER = LogManager.getLogger(RetailerServiceImpl.class);
|
| 47 |
|
47 |
|
| 48 |
@Autowired
|
48 |
@Autowired
|
| 49 |
private RetailerRepository retailerRepository;
|
49 |
private RetailerRepository retailerRepository;
|
| 50 |
|
50 |
|
| 51 |
@Autowired
|
51 |
@Autowired
|
| 52 |
private RetailerBlockBrandsRepository retailerBlockBrandsRepository;
|
52 |
private RetailerBlockBrandsRepository retailerBlockBrandsRepository;
|
| 53 |
|
53 |
|
| 54 |
@Autowired
|
54 |
@Autowired
|
| 55 |
private UserAccountRepository userAccountRepository;
|
55 |
private UserAccountRepository userAccountRepository;
|
| 56 |
|
56 |
|
| 57 |
@Autowired
|
57 |
@Autowired
|
| 58 |
private Mongo mongoClient;
|
58 |
private Mongo mongoClient;
|
| 59 |
|
59 |
|
| 60 |
@Autowired
|
60 |
@Autowired
|
| 61 |
private UserRepository userRepository;
|
61 |
private UserRepository userRepository;
|
| 62 |
|
62 |
|
| 63 |
@Autowired
|
63 |
@Autowired
|
| 64 |
private CartRepository cartRepository;
|
64 |
private CartRepository cartRepository;
|
| 65 |
|
65 |
|
| 66 |
@Autowired
|
66 |
@Autowired
|
| 67 |
private RetailerRegisteredAddressRepository retailerRegisteredAddressRepository;
|
67 |
private RetailerRegisteredAddressRepository retailerRegisteredAddressRepository;
|
| 68 |
|
68 |
|
| 69 |
@Autowired
|
69 |
@Autowired
|
| 70 |
private AddressRepository addressRepository;
|
70 |
private AddressRepository addressRepository;
|
| 71 |
|
71 |
|
| 72 |
@Autowired
|
72 |
@Autowired
|
| 73 |
private ShopRepository shopRepository;
|
73 |
private ShopRepository shopRepository;
|
| 74 |
|
74 |
|
| 75 |
@Autowired
|
75 |
@Autowired
|
| 76 |
private ShopAddressRepository shopAddressRepository;
|
76 |
private ShopAddressRepository shopAddressRepository;
|
| 77 |
|
77 |
|
| 78 |
@Autowired
|
78 |
@Autowired
|
| 79 |
private UserRoleRepository userRoleRepository;
|
79 |
private UserRoleRepository userRoleRepository;
|
| 80 |
|
80 |
|
| 81 |
@Autowired
|
81 |
@Autowired
|
| 82 |
private DocumentRepository documentRepository;
|
82 |
private DocumentRepository documentRepository;
|
| 83 |
|
83 |
|
| 84 |
@Autowired
|
84 |
@Autowired
|
| 85 |
private PrivateDealUserRepository privateDealUserRepository;
|
85 |
private PrivateDealUserRepository privateDealUserRepository;
|
| 86 |
|
86 |
|
| 87 |
@Autowired
|
87 |
@Autowired
|
| 88 |
private PrivateDealUserAddressMappingRepository privateDealUserAddressMappingRepository;
|
88 |
private PrivateDealUserAddressMappingRepository privateDealUserAddressMappingRepository;
|
| 89 |
|
89 |
|
| 90 |
@Autowired
|
90 |
@Autowired
|
| 91 |
private CounterRepository counterRepository;
|
91 |
private CounterRepository counterRepository;
|
| 92 |
|
92 |
|
| 93 |
@Autowired
|
93 |
@Autowired
|
| 94 |
private StateRepository stateRepository;
|
94 |
private StateRepository stateRepository;
|
| 95 |
|
95 |
|
| 96 |
@Autowired
|
96 |
@Autowired
|
| 97 |
@Qualifier("userUserRepository")
|
97 |
@Qualifier("userUserRepository")
|
| 98 |
private com.spice.profitmandi.dao.repository.user.UserRepository userUserRepository;
|
98 |
private com.spice.profitmandi.dao.repository.user.UserRepository userUserRepository;
|
| 99 |
|
99 |
|
| 100 |
@Autowired
|
100 |
@Autowired
|
| 101 |
private DistrictMasterRepository districtMasterRepository;
|
101 |
private DistrictMasterRepository districtMasterRepository;
|
| 102 |
|
102 |
|
| 103 |
@Autowired
|
103 |
@Autowired
|
| 104 |
private FofoStoreRepository fofoStoreRepository;
|
104 |
private FofoStoreRepository fofoStoreRepository;
|
| 105 |
|
105 |
|
| 106 |
@Autowired
|
106 |
@Autowired
|
| 107 |
private PaymentOptionRepository paymentOptionRepository;
|
107 |
private PaymentOptionRepository paymentOptionRepository;
|
| 108 |
|
108 |
|
| 109 |
@Autowired
|
109 |
@Autowired
|
| 110 |
private FofoPartnerPaymentOptionRepository fofoPartnerPaymentOptionRepository;
|
110 |
private FofoPartnerPaymentOptionRepository fofoPartnerPaymentOptionRepository;
|
| 111 |
|
111 |
|
| 112 |
@Autowired
|
112 |
@Autowired
|
| 113 |
private RoleRepository roleRepository;
|
113 |
private RoleRepository roleRepository;
|
| 114 |
|
114 |
|
| 115 |
@Autowired
|
115 |
@Autowired
|
| 116 |
private StoreTimelineTatService storeTimelineTatService;
|
116 |
private StoreTimelineTatService storeTimelineTatService;
|
| 117 |
|
117 |
|
| 118 |
@Autowired
|
118 |
@Autowired
|
| 119 |
private PartnerOnBoardingPanelRepository partnerOnBoardingPanelRepository;
|
119 |
private PartnerOnBoardingPanelRepository partnerOnBoardingPanelRepository;
|
| 120 |
|
120 |
|
| 121 |
@Autowired
|
121 |
@Autowired
|
| 122 |
private PartnerOnboardingVerificationRepository partnerOnboardingVerificationRepository;
|
122 |
private PartnerOnboardingVerificationRepository partnerOnboardingVerificationRepository;
|
| 123 |
|
123 |
|
| 124 |
@Autowired
|
124 |
@Autowired
|
| 125 |
private PincodePartnerRepository pincodePartnerRepository;
|
125 |
private PincodePartnerRepository pincodePartnerRepository;
|
| 126 |
|
126 |
|
| 127 |
@Override
|
127 |
@Override
|
| 128 |
public Map<String, Object> getByEmailIdOrMobileNumber(String emailIdOrMobileNumber)
|
128 |
public Map<String, Object> getByEmailIdOrMobileNumber(String emailIdOrMobileNumber) throws ProfitMandiBusinessException {
|
| 129 |
throws ProfitMandiBusinessException {
|
129 |
User user = null;
|
| 130 |
User user = null;
|
130 |
int fofoId = Utils.SYSTEM_PARTNER_ID;
|
| 131 |
int fofoId = Utils.SYSTEM_PARTNER_ID;
|
131 |
|
| 132 |
|
132 |
try {
|
| 133 |
try {
|
133 |
user = userRepository.selectByEmailIdOrMobileNumber(emailIdOrMobileNumber);
|
| 134 |
user = userRepository.selectByEmailIdOrMobileNumber(emailIdOrMobileNumber);
|
134 |
} catch (ProfitMandiBusinessException profitMandiBusinessException) {
|
| 135 |
} catch (ProfitMandiBusinessException profitMandiBusinessException) {
|
135 |
|
| 136 |
|
136 |
}
|
| 137 |
}
|
137 |
if (user == null) {
|
| 138 |
if (user == null) {
|
138 |
try {
|
| 139 |
try {
|
139 |
user = userRepository.selectBySecondryEmailId(emailIdOrMobileNumber);
|
| 140 |
user = userRepository.selectBySecondryEmailId(emailIdOrMobileNumber);
|
140 |
} catch (ProfitMandiBusinessException profitMandiBusinessException) {
|
| 141 |
} catch (ProfitMandiBusinessException profitMandiBusinessException) {
|
141 |
|
| 142 |
|
142 |
}
|
| 143 |
}
|
143 |
}
|
| 144 |
}
|
144 |
Map<String, Object> map = new HashMap<>();
|
| 145 |
Map<String, Object> map = new HashMap<>();
|
145 |
map.put("stateNames", stateRepository.selectAll().stream().map(x -> x.getName()).collect(Collectors.toList()));
|
| 146 |
map.put("stateNames", stateRepository.selectAll().stream().map(x -> x.getName()).collect(Collectors.toList()));
|
146 |
|
| 147 |
|
147 |
if (user != null) {
|
| 148 |
if (user != null) {
|
148 |
|
| 149 |
|
149 |
List<UserRole> userRoles = userRoleRepository.selectByUserId(user.getId());
|
| 150 |
List<UserRole> userRoles = userRoleRepository.selectByUserId(user.getId());
|
150 |
|
| 151 |
|
151 |
Role role = roleRepository.selectByName(RoleType.FOFO.toString());
|
| 152 |
Role role = roleRepository.selectByName(RoleType.FOFO.toString());
|
152 |
|
| 153 |
|
153 |
map.put("userRoles", userRoles);
|
| 154 |
map.put("userRoles", userRoles);
|
154 |
map.put("user", user);
|
| 155 |
map.put("user", user);
|
155 |
// map.put("retailer", retailer);
|
| 156 |
// map.put("retailer", retailer);
|
156 |
map.put("fofoRole", this.containsRoleType(userRoles, role.getId()));
|
| 157 |
map.put("fofoRole", this.containsRoleType(userRoles, role.getId()));
|
157 |
|
| 158 |
|
158 |
map.put("userRoleNames", this.toString(userRoles));
|
| 159 |
map.put("userRoleNames", this.toString(userRoles));
|
159 |
try {
|
| 160 |
try {
|
160 |
int retailerId = userAccountRepository.selectRetailerIdByUserId(user.getId());
|
| 161 |
int retailerId = userAccountRepository.selectRetailerIdByUserId(user.getId());
|
161 |
Retailer retailer = retailerRepository.selectById(retailerId);
|
| 162 |
Retailer retailer = retailerRepository.selectById(retailerId);
|
162 |
|
| 163 |
|
163 |
map.put("retailer", retailer);
|
| 164 |
map.put("retailer", retailer);
|
164 |
|
| 165 |
|
165 |
List<String> retailerBlockBrands = null;
|
| 166 |
List<String> retailerBlockBrands = null;
|
166 |
Set<String> brands = null;
|
| 167 |
Set<String> brands = null;
|
167 |
if (retailer.getId() != fofoId) {
|
| 168 |
if (retailer.getId() != fofoId) {
|
168 |
brands = mongoClient.getMongoBrands(retailer.getId(), null, 3).stream().map(x -> (String) x.get("name")).collect(Collectors.toSet());
|
| 169 |
brands = mongoClient.getMongoBrands(retailer.getId(), null, 3).stream()
|
169 |
retailerBlockBrands = retailerBlockBrandsRepository.selectAllByRetailer(retailer.getId()).stream().map(x -> x.getBlockBrands()).collect(Collectors.toList());
|
| 170 |
.map(x -> (String) x.get("name")).collect(Collectors.toSet());
|
170 |
|
| 171 |
retailerBlockBrands = retailerBlockBrandsRepository.selectAllByRetailer(retailer.getId()).stream()
|
171 |
LOGGER.info("loginDetailsFofoId" + retailer.getId());
|
| 172 |
.map(x -> x.getBlockBrands()).collect(Collectors.toList());
|
172 |
} else {
|
| 173 |
|
173 |
LOGGER.info("fofoId" + fofoId);
|
| 174 |
LOGGER.info("loginDetailsFofoId" + retailer.getId());
|
174 |
brands = mongoClient.getMongoBrands(fofoId, null, 3).stream().map(x -> (String) x.get("name")).collect(Collectors.toSet());
|
| 175 |
} else {
|
175 |
}
|
| 176 |
LOGGER.info("fofoId" + fofoId);
|
176 |
map.put("brands", brands);
|
| 177 |
brands = mongoClient.getMongoBrands(fofoId, null, 3).stream().map(x -> (String) x.get("name"))
|
177 |
map.put("retailerBlockBrands", retailerBlockBrands);
|
| 178 |
.collect(Collectors.toSet());
|
178 |
if (this.containsRoleType(userRoles, role.getId())) {
|
| 179 |
}
|
179 |
try {
|
| 180 |
map.put("brands", brands);
|
180 |
FofoStore fofoStore = fofoStoreRepository.selectByRetailerId(retailerId);
|
| 181 |
map.put("retailerBlockBrands", retailerBlockBrands);
|
181 |
map.put("fofoStore", fofoStore);
|
| 182 |
if (this.containsRoleType(userRoles, role.getId())) {
|
182 |
// map.put("counterSize", fofoStore.getCounterSize().toString());
|
| 183 |
try {
|
183 |
// LOGGER.info("fofoStore" + fofoStore);
|
| 184 |
FofoStore fofoStore = fofoStoreRepository.selectByRetailerId(retailerId);
|
184 |
} catch (ProfitMandiBusinessException profitMandiBusinessException) {
|
| 185 |
map.put("fofoStore", fofoStore);
|
185 |
LOGGER.error("FofoStore code not found");
|
| 186 |
// map.put("counterSize", fofoStore.getCounterSize().toString());
|
186 |
}
|
| 187 |
// LOGGER.info("fofoStore" + fofoStore);
|
187 |
}
|
| 188 |
} catch (ProfitMandiBusinessException profitMandiBusinessException) {
|
188 |
|
| 189 |
LOGGER.error("FofoStore code not found");
|
189 |
try {
|
| 190 |
}
|
190 |
PrivateDealUser privateDealUser = privateDealUserRepository.selectById(retailer.getId());
|
| 191 |
}
|
191 |
if (privateDealUser.getCounterId() != null) {
|
| 192 |
|
192 |
Counter counter = counterRepository.selectById(privateDealUser.getCounterId());
|
| 193 |
try {
|
193 |
map.put("gstNumber", counter.getGstin());
|
| 194 |
PrivateDealUser privateDealUser = privateDealUserRepository.selectById(retailer.getId());
|
194 |
// LOGGER.info("gstNumber" + counter.getGstin());
|
| 195 |
if (privateDealUser.getCounterId() != null) {
|
195 |
}
|
| 196 |
Counter counter = counterRepository.selectById(privateDealUser.getCounterId());
|
196 |
} catch (ProfitMandiBusinessException profitMandiBusinessException) {
|
| 197 |
map.put("gstNumber", counter.getGstin());
|
197 |
LOGGER.error("PrivateDealUser not found");
|
| 198 |
// LOGGER.info("gstNumber" + counter.getGstin());
|
198 |
}
|
| 199 |
}
|
199 |
try {
|
| 200 |
} catch (ProfitMandiBusinessException profitMandiBusinessException) {
|
200 |
int retailerAddressId = retailerRegisteredAddressRepository.selectAddressIdByRetailerId(retailer.getId());
|
| 201 |
LOGGER.error("PrivateDealUser not found");
|
201 |
Address retailerAddress = addressRepository.selectById(retailerAddressId);
|
| 202 |
}
|
202 |
map.put("retailerAddress", retailerAddress);
|
| 203 |
try {
|
203 |
State state = stateRepository.selectByName(retailerAddress.getState());
|
| 204 |
int retailerAddressId = retailerRegisteredAddressRepository
|
204 |
// LOGGER.info("retailerAddress.." + retailerAddress);
|
| 205 |
.selectAddressIdByRetailerId(retailer.getId());
|
205 |
List<DistrictMaster> districtMasters = districtMasterRepository.selectByStateShortName(state.getShortName());
|
| 206 |
Address retailerAddress = addressRepository.selectById(retailerAddressId);
|
206 |
map.put("districtMasters", districtMasters);
|
| 207 |
map.put("retailerAddress", retailerAddress);
|
207 |
// LOGGER.info("districtMasters" + districtMasters);
|
| 208 |
State state = stateRepository.selectByName(retailerAddress.getState());
|
208 |
List<Shop> shops = shopRepository.selectByRetailerId(retailer.getId());
|
| 209 |
// LOGGER.info("retailerAddress.." + retailerAddress);
|
209 |
map.put("shops", shops);
|
| 210 |
List<DistrictMaster> districtMasters = districtMasterRepository
|
210 |
this.addAddress(shops);
|
| 211 |
.selectByStateShortName(state.getShortName());
|
211 |
// LOGGER.info("shops" + shops);
|
| 212 |
map.put("districtMasters", districtMasters);
|
212 |
} catch (ProfitMandiBusinessException profitMandiBusinessException) {
|
| 213 |
// LOGGER.info("districtMasters" + districtMasters);
|
213 |
LOGGER.error("Retailer Registered Address not found");
|
| 214 |
List<Shop> shops = shopRepository.selectByRetailerId(retailer.getId());
|
214 |
}
|
| 215 |
map.put("shops", shops);
|
215 |
} catch (ProfitMandiBusinessException profitMandiBusinessException) {
|
| 216 |
this.addAddress(shops);
|
216 |
LOGGER.error("Retailer not found in user_account");
|
| 217 |
// LOGGER.info("shops" + shops);
|
217 |
}
|
| 218 |
} catch (ProfitMandiBusinessException profitMandiBusinessException) {
|
218 |
}
|
| 219 |
LOGGER.error("Retailer Registered Address not found");
|
219 |
|
| 220 |
}
|
220 |
return map;
|
| 221 |
} catch (ProfitMandiBusinessException profitMandiBusinessException) {
|
221 |
}
|
| 222 |
LOGGER.error("Retailer not found in user_account");
|
222 |
|
| 223 |
}
|
223 |
private boolean containsRoleType(List<UserRole> userRoles, int roleId) {
|
| 224 |
}
|
224 |
for (UserRole userRole : userRoles) {
|
| 225 |
|
225 |
if (userRole.getRoleId() == roleId) {
|
| 226 |
return map;
|
226 |
return true;
|
| 227 |
}
|
227 |
}
|
| 228 |
|
228 |
}
|
| 229 |
private boolean containsRoleType(List<UserRole> userRoles, int roleId) {
|
229 |
return false;
|
| 230 |
for (UserRole userRole : userRoles) {
|
230 |
}
|
| 231 |
if (userRole.getRoleId() == roleId) {
|
231 |
|
| 232 |
return true;
|
232 |
private List<UserRole> addRole(List<UserRole> userRoles, int userId, int roleId) {
|
| 233 |
}
|
233 |
if (userRoles == null) {
|
| 234 |
}
|
234 |
userRoles = new ArrayList<>();
|
| 235 |
return false;
|
235 |
}
|
| 236 |
}
|
236 |
if (!this.containsRoleType(userRoles, roleId)) {
|
| 237 |
|
237 |
UserRole userRole = new UserRole();
|
| 238 |
private List<UserRole> addRole(List<UserRole> userRoles, int userId, int roleId) {
|
238 |
userRole.setUserId(userId);
|
| 239 |
if (userRoles == null) {
|
239 |
userRole.setRoleId(roleId);
|
| 240 |
userRoles = new ArrayList<>();
|
240 |
try {
|
| 241 |
}
|
241 |
userRoleRepository.persist(userRole);
|
| 242 |
if (!this.containsRoleType(userRoles, roleId)) {
|
242 |
} catch (ProfitMandiBusinessException e) {
|
| 243 |
UserRole userRole = new UserRole();
|
243 |
LOGGER.error("UserRole is already exist");
|
| 244 |
userRole.setUserId(userId);
|
244 |
}
|
| 245 |
userRole.setRoleId(roleId);
|
245 |
userRoles.add(userRole);
|
| 246 |
try {
|
246 |
}
|
| 247 |
userRoleRepository.persist(userRole);
|
247 |
return userRoles;
|
| 248 |
} catch (ProfitMandiBusinessException e) {
|
248 |
|
| 249 |
LOGGER.error("UserRole is already exist");
|
249 |
}
|
| 250 |
}
|
250 |
|
| 251 |
userRoles.add(userRole);
|
251 |
private List<UserRole> removeRole(List<UserRole> userRoles, int userId, int roleId) {
|
| 252 |
}
|
252 |
if (userRoles == null) {
|
| 253 |
return userRoles;
|
253 |
userRoles = new ArrayList<>();
|
| 254 |
|
254 |
return userRoles;
|
| 255 |
}
|
255 |
}
|
| 256 |
|
256 |
try {
|
| 257 |
private List<UserRole> removeRole(List<UserRole> userRoles, int userId, int roleId) {
|
257 |
userRoles.remove(userRoleRepository.deleteByRoleUserId(userId, roleId));
|
| 258 |
if (userRoles == null) {
|
258 |
} catch (Exception e) {
|
| 259 |
userRoles = new ArrayList<>();
|
259 |
|
| 260 |
return userRoles;
|
260 |
}
|
| 261 |
}
|
261 |
return userRoles;
|
| 262 |
try {
|
262 |
|
| 263 |
userRoles.remove(userRoleRepository.deleteByRoleUserId(userId, roleId));
|
263 |
}
|
| 264 |
} catch (Exception e) {
|
264 |
|
| 265 |
|
265 |
@SuppressWarnings("unchecked")
|
| 266 |
}
|
266 |
@Override
|
| 267 |
return userRoles;
|
267 |
public Map<String, Object> updateRetailerDetails(UpdateRetailerRequest updateRetailerRequest) throws ProfitMandiBusinessException {
|
| 268 |
|
268 |
Map<String, Object> map = this.getByEmailIdOrMobileNumber(updateRetailerRequest.getEmailIdOrMobileNumber());
|
| 269 |
}
|
269 |
User user = (User) map.get("user");
|
| 270 |
|
270 |
|
| 271 |
@SuppressWarnings("unchecked")
|
271 |
user = this.createUser(user, updateRetailerRequest);
|
| 272 |
@Override
|
272 |
|
| 273 |
public Map<String, Object> updateRetailerDetails(UpdateRetailerRequest updateRetailerRequest)
|
273 |
map.put("user", user);
|
| 274 |
throws ProfitMandiBusinessException {
|
274 |
List<UserRole> userRoles = (List<UserRole>) map.get("userRoles");
|
| 275 |
Map<String, Object> map = this.getByEmailIdOrMobileNumber(updateRetailerRequest.getEmailIdOrMobileNumber());
|
275 |
Role roleUser = roleRepository.selectByName(RoleType.USER.toString());
|
| 276 |
User user = (User) map.get("user");
|
276 |
userRoles = this.addRole(userRoles, user.getId(), roleUser.getId());
|
| 277 |
|
277 |
Retailer retailer = (Retailer) map.get("retailer");
|
| 278 |
user = this.createUser(user, updateRetailerRequest);
|
278 |
retailer = this.updateRetailer(user, retailer, updateRetailerRequest);
|
| 279 |
|
279 |
|
| 280 |
map.put("user", user);
|
280 |
map.put("retailer", retailer);
|
| 281 |
List<UserRole> userRoles = (List<UserRole>) map.get("userRoles");
|
281 |
|
| 282 |
Role roleUser = roleRepository.selectByName(RoleType.USER.toString());
|
282 |
List<String> retailerBlockBrands = retailerBlockBrandsRepository.selectAllByRetailer(retailer.getId()).stream().map(x -> x.getBlockBrands()).collect(Collectors.toList());
|
| 283 |
userRoles = this.addRole(userRoles, user.getId(), roleUser.getId());
|
283 |
|
| 284 |
Retailer retailer = (Retailer) map.get("retailer");
|
284 |
LOGGER.info("retailerBlockBrands" + retailerBlockBrands);
|
| 285 |
retailer = this.updateRetailer(user, retailer, updateRetailerRequest);
|
285 |
|
| 286 |
|
286 |
if (!retailerBlockBrands.isEmpty()) {
|
| 287 |
map.put("retailer", retailer);
|
287 |
retailerBlockBrandsRepository.deleteBrands(retailer.getId());
|
| 288 |
|
288 |
}
|
| 289 |
List<String> retailerBlockBrands = retailerBlockBrandsRepository.selectAllByRetailer(retailer.getId()).stream()
|
289 |
|
| 290 |
.map(x -> x.getBlockBrands()).collect(Collectors.toList());
|
290 |
for (String blockBrand : updateRetailerRequest.getBlocksBrands()) {
|
| 291 |
|
291 |
RetailerBlockBrands retailerBlockBrand = new RetailerBlockBrands();
|
| 292 |
LOGGER.info("retailerBlockBrands" + retailerBlockBrands);
|
292 |
|
| 293 |
|
293 |
retailerBlockBrand.setFofoId(retailer.getId());
|
| 294 |
if (!retailerBlockBrands.isEmpty()) {
|
294 |
retailerBlockBrand.setBlockBrands(blockBrand);
|
| 295 |
retailerBlockBrandsRepository.deleteBrands(retailer.getId());
|
295 |
retailerBlockBrandsRepository.persist(retailerBlockBrand);
|
| 296 |
}
|
296 |
|
| 297 |
|
297 |
}
|
| 298 |
for (String blockBrand : updateRetailerRequest.getBlocksBrands()) {
|
298 |
map.put("retailerBlockBrands", retailerBlockBrands);
|
| 299 |
RetailerBlockBrands retailerBlockBrand = new RetailerBlockBrands();
|
299 |
|
| 300 |
|
300 |
Role roleRetailer = roleRepository.selectByName(RoleType.RETAILER.toString());
|
| 301 |
retailerBlockBrand.setFofoId(retailer.getId());
|
301 |
|
| 302 |
retailerBlockBrand.setBlockBrands(blockBrand);
|
302 |
userRoles = this.addRole(userRoles, user.getId(), roleRetailer.getId());
|
| 303 |
retailerBlockBrandsRepository.persist(retailerBlockBrand);
|
303 |
|
| 304 |
|
304 |
Role roleFofo = roleRepository.selectByName(RoleType.FOFO.toString());
|
| 305 |
}
|
305 |
|
| 306 |
map.put("retailerBlockBrands", retailerBlockBrands);
|
306 |
if (updateRetailerRequest.isFofo()) {
|
| 307 |
|
307 |
userRoles = this.addRole(userRoles, user.getId(), roleFofo.getId());
|
| 308 |
Role roleRetailer = roleRepository.selectByName(RoleType.RETAILER.toString());
|
308 |
} else {
|
| 309 |
|
309 |
userRoles = this.removeRole(userRoles, user.getId(), roleFofo.getId());
|
| 310 |
userRoles = this.addRole(userRoles, user.getId(), roleRetailer.getId());
|
310 |
}
|
| 311 |
|
311 |
map.put("fofoRole", this.containsRoleType(userRoles, roleFofo.getId()));
|
| 312 |
Role roleFofo = roleRepository.selectByName(RoleType.FOFO.toString());
|
312 |
|
| 313 |
|
313 |
if (this.containsRoleType(userRoles, roleFofo.getId())) {
|
| 314 |
if (updateRetailerRequest.isFofo()) {
|
314 |
this.createDefaultPaymentOption(retailer.getId());
|
| 315 |
userRoles = this.addRole(userRoles, user.getId(), roleFofo.getId());
|
315 |
}
|
| 316 |
} else {
|
316 |
|
| 317 |
userRoles = this.removeRole(userRoles, user.getId(), roleFofo.getId());
|
317 |
map.put("userRoles", userRoles);
|
| 318 |
}
|
318 |
map.put("userRoleNames", this.toString(userRoles));
|
| 319 |
map.put("fofoRole", this.containsRoleType(userRoles, roleFofo.getId()));
|
319 |
|
| 320 |
|
320 |
Address retailerAddress = (Address) map.get("retailerAddress");
|
| 321 |
if (this.containsRoleType(userRoles, roleFofo.getId())) {
|
321 |
retailerAddress = this.updateRetailerAddress(retailerAddress, updateRetailerRequest.getAddress(), retailer.getId());
|
| 322 |
this.createDefaultPaymentOption(retailer.getId());
|
322 |
map.put("retailerAddress", retailerAddress);
|
| 323 |
}
|
323 |
|
| 324 |
|
324 |
if (updateRetailerRequest.isFofo()) {
|
| 325 |
map.put("userRoles", userRoles);
|
325 |
FofoStore fofoStore = this.createFofoStoreCodeByRetailerId(retailer.getId(), updateRetailerRequest.getDistrictName(), retailerAddress.getState(), updateRetailerRequest);
|
| 326 |
map.put("userRoleNames", this.toString(userRoles));
|
326 |
map.put("fofoStore", fofoStore);
|
| 327 |
|
327 |
fofoStore.setActive(updateRetailerRequest.isActive());
|
| 328 |
Address retailerAddress = (Address) map.get("retailerAddress");
|
328 |
}
|
| 329 |
retailerAddress = this.updateRetailerAddress(retailerAddress, updateRetailerRequest.getAddress(),
|
329 |
|
| 330 |
retailer.getId());
|
330 |
this.createPrivateDealUser(user, updateRetailerRequest.isFofo(), updateRetailerRequest.getGstNumber(), retailer, retailerAddress.getId());
|
| 331 |
map.put("retailerAddress", retailerAddress);
|
331 |
map.put("gstNumber", updateRetailerRequest.getGstNumber());
|
| 332 |
|
332 |
this.updateSaholicUser(retailer.getId(), retailerAddress.getId());
|
| 333 |
if (updateRetailerRequest.isFofo()) {
|
333 |
|
| 334 |
FofoStore fofoStore = this.createFofoStoreCodeByRetailerId(retailer.getId(),
|
334 |
List<Shop> shops = (List<Shop>) map.get("shops");
|
| 335 |
updateRetailerRequest.getDistrictName(), retailerAddress.getState(), updateRetailerRequest);
|
335 |
if (shops == null) {
|
| 336 |
map.put("fofoStore", fofoStore);
|
336 |
shops = new ArrayList<>();
|
| 337 |
fofoStore.setActive(updateRetailerRequest.isActive());
|
337 |
map.put("shops", shops);
|
| 338 |
}
|
338 |
}
|
| 339 |
|
339 |
this.updateRetailerShops(shops, updateRetailerRequest.getShops(), retailer.getId(), retailerAddress);
|
| 340 |
this.createPrivateDealUser(user, updateRetailerRequest.isFofo(), updateRetailerRequest.getGstNumber(), retailer,
|
340 |
|
| 341 |
retailerAddress.getId());
|
341 |
return map;
|
| 342 |
map.put("gstNumber", updateRetailerRequest.getGstNumber());
|
342 |
|
| 343 |
this.updateSaholicUser(retailer.getId(), retailerAddress.getId());
|
343 |
}
|
| 344 |
|
344 |
|
| 345 |
List<Shop> shops = (List<Shop>) map.get("shops");
|
345 |
private void createDefaultPaymentOption(int fofoId) {
|
| 346 |
if (shops == null) {
|
346 |
List<Integer> paymentOptionIds = fofoPartnerPaymentOptionRepository.selectPaymentOptionIdsByFofoId(fofoId);
|
| 347 |
shops = new ArrayList<>();
|
347 |
if (paymentOptionIds.isEmpty()) {
|
| 348 |
map.put("shops", shops);
|
348 |
PaymentOption paymentOption = null;
|
| 349 |
}
|
349 |
try {
|
| 350 |
this.updateRetailerShops(shops, updateRetailerRequest.getShops(), retailer.getId(), retailerAddress);
|
350 |
paymentOption = paymentOptionRepository.selectByName(PaymentOptionType.CASH.toString());
|
| 351 |
|
351 |
} catch (ProfitMandiBusinessException profitMandiBusinessException) {
|
| 352 |
return map;
|
352 |
paymentOption = new PaymentOption();
|
| 353 |
|
353 |
paymentOption.setName(PaymentOptionType.CASH.toString());
|
| 354 |
}
|
354 |
paymentOptionRepository.persist(paymentOption);
|
| 355 |
|
355 |
}
|
| 356 |
private void createDefaultPaymentOption(int fofoId) {
|
356 |
FofoPartnerPaymentOption fofoPartnerPaymentOption = new FofoPartnerPaymentOption();
|
| 357 |
List<Integer> paymentOptionIds = fofoPartnerPaymentOptionRepository.selectPaymentOptionIdsByFofoId(fofoId);
|
357 |
fofoPartnerPaymentOption.setFofoId(fofoId);
|
| 358 |
if (paymentOptionIds.isEmpty()) {
|
358 |
fofoPartnerPaymentOption.setPaymentOptionId(paymentOption.getId());
|
| 359 |
PaymentOption paymentOption = null;
|
359 |
fofoPartnerPaymentOptionRepository.persist(fofoPartnerPaymentOption);
|
| 360 |
try {
|
360 |
}
|
| 361 |
paymentOption = paymentOptionRepository.selectByName(PaymentOptionType.CASH.toString());
|
361 |
|
| 362 |
} catch (ProfitMandiBusinessException profitMandiBusinessException) {
|
362 |
}
|
| 363 |
paymentOption = new PaymentOption();
|
363 |
|
| 364 |
paymentOption.setName(PaymentOptionType.CASH.toString());
|
364 |
private User createUser(User user, UpdateRetailerRequest updateRetailerRequest) {
|
| 365 |
paymentOptionRepository.persist(paymentOption);
|
365 |
if (user == null) {
|
| 366 |
}
|
366 |
user = new User();
|
| 367 |
FofoPartnerPaymentOption fofoPartnerPaymentOption = new FofoPartnerPaymentOption();
|
367 |
user.setCity("");
|
| 368 |
fofoPartnerPaymentOption.setFofoId(fofoId);
|
368 |
user.setPinCode(0);
|
| 369 |
fofoPartnerPaymentOption.setPaymentOptionId(paymentOption.getId());
|
369 |
user.setState("");
|
| 370 |
fofoPartnerPaymentOptionRepository.persist(fofoPartnerPaymentOption);
|
370 |
user.setPassword("");
|
| 371 |
}
|
371 |
user.setMobile_verified(false);
|
| 372 |
|
372 |
user.setReferral_url("");
|
| 373 |
}
|
373 |
user.setGroup_id(1);
|
| 374 |
|
374 |
user.setStatus(1);
|
| 375 |
private User createUser(User user, UpdateRetailerRequest updateRetailerRequest) {
|
375 |
user.setActivated(true);
|
| 376 |
if (user == null) {
|
376 |
user.setCreateTimestamp(LocalDateTime.now());
|
| 377 |
user = new User();
|
377 |
}
|
| 378 |
user.setCity("");
|
378 |
user.setActivated(updateRetailerRequest.isActive());
|
| 379 |
user.setPinCode(0);
|
379 |
user.setFirstName(updateRetailerRequest.getUserFirstName());
|
| 380 |
user.setState("");
|
380 |
user.setLastName(updateRetailerRequest.getUserLastName());
|
| 381 |
user.setPassword("");
|
381 |
user.setMobileNumber(updateRetailerRequest.getUserMobileNumber());
|
| 382 |
user.setMobile_verified(false);
|
382 |
user.setEmailId(updateRetailerRequest.getUserEmailId());
|
| 383 |
user.setReferral_url("");
|
383 |
user.setUsername(updateRetailerRequest.getUserEmailId());
|
| 384 |
user.setGroup_id(1);
|
384 |
user.setUpdateTimestamp(LocalDateTime.now());
|
| 385 |
user.setStatus(1);
|
385 |
userRepository.persist(user);
|
| 386 |
user.setActivated(true);
|
386 |
return user;
|
| 387 |
user.setCreateTimestamp(LocalDateTime.now());
|
387 |
|
| 388 |
}
|
388 |
}
|
| 389 |
user.setActivated(updateRetailerRequest.isActive());
|
389 |
|
| 390 |
user.setFirstName(updateRetailerRequest.getUserFirstName());
|
390 |
private int createSaholicUser(User user, String retailerName) {
|
| 391 |
user.setLastName(updateRetailerRequest.getUserLastName());
|
391 |
com.spice.profitmandi.dao.entity.user.User saholicUser = null;
|
| 392 |
user.setMobileNumber(updateRetailerRequest.getUserMobileNumber());
|
392 |
try {
|
| 393 |
user.setEmailId(updateRetailerRequest.getUserEmailId());
|
393 |
saholicUser = userUserRepository.selectByEmailId(user.getEmailId());
|
| 394 |
user.setUsername(updateRetailerRequest.getUserEmailId());
|
394 |
} catch (ProfitMandiBusinessException e) {
|
| 395 |
user.setUpdateTimestamp(LocalDateTime.now());
|
395 |
LOGGER.info("User doesnt exist in old system");
|
| 396 |
userRepository.persist(user);
|
396 |
}
|
| 397 |
return user;
|
397 |
if (saholicUser == null) {
|
| 398 |
|
398 |
Cart cart = new Cart();
|
| 399 |
}
|
399 |
cart.setCartStatus(CartStatus.ACTIVE);
|
| 400 |
|
400 |
cartRepository.persist(cart);
|
| 401 |
private int createSaholicUser(User user, String retailerName) {
|
401 |
saholicUser = new com.spice.profitmandi.dao.entity.user.User();
|
| 402 |
com.spice.profitmandi.dao.entity.user.User saholicUser = null;
|
402 |
saholicUser.setEmailId(user.getEmailId());
|
| 403 |
try {
|
403 |
saholicUser.setName(retailerName);
|
| 404 |
saholicUser = userUserRepository.selectByEmailId(user.getEmailId());
|
404 |
saholicUser.setActiveCartId(cart.getId());
|
| 405 |
} catch (ProfitMandiBusinessException e) {
|
405 |
saholicUser.setCreateTimestamp(LocalDateTime.now());
|
| 406 |
LOGGER.info("User doesnt exist in old system");
|
406 |
userUserRepository.persist(saholicUser);
|
| 407 |
}
|
407 |
|
| 408 |
if (saholicUser == null) {
|
408 |
UserAccount ua = new UserAccount();
|
| 409 |
Cart cart = new Cart();
|
409 |
ua.setAccountKey(saholicUser.getId());
|
| 410 |
cart.setCartStatus(CartStatus.ACTIVE);
|
410 |
ua.setUserId(user.getId());
|
| 411 |
cartRepository.persist(cart);
|
411 |
ua.setType(AccountType.saholic);
|
| 412 |
saholicUser = new com.spice.profitmandi.dao.entity.user.User();
|
412 |
userAccountRepository.persist(ua);
|
| 413 |
saholicUser.setEmailId(user.getEmailId());
|
413 |
|
| 414 |
saholicUser.setName(retailerName);
|
414 |
UserAccount ua2 = new UserAccount();
|
| 415 |
saholicUser.setActiveCartId(cart.getId());
|
415 |
ua2.setAccountKey(saholicUser.getActiveCartId());
|
| 416 |
saholicUser.setCreateTimestamp(LocalDateTime.now());
|
416 |
ua2.setUserId(user.getId());
|
| 417 |
userUserRepository.persist(saholicUser);
|
417 |
ua2.setType(AccountType.cartId);
|
| 418 |
|
418 |
userAccountRepository.persist(ua2);
|
| 419 |
UserAccount ua = new UserAccount();
|
419 |
LOGGER.info("created....");
|
| 420 |
ua.setAccountKey(saholicUser.getId());
|
420 |
}
|
| 421 |
ua.setUserId(user.getId());
|
421 |
return saholicUser.getId();
|
| 422 |
ua.setType(AccountType.saholic);
|
422 |
}
|
| 423 |
userAccountRepository.persist(ua);
|
423 |
|
| 424 |
|
424 |
private com.spice.profitmandi.dao.entity.user.User createSaholicUser(
|
| 425 |
UserAccount ua2 = new UserAccount();
|
425 |
LoginRequestResponseModel loginRequestResponseModel) {
|
| 426 |
ua2.setAccountKey(saholicUser.getActiveCartId());
|
426 |
com.spice.profitmandi.dao.entity.user.User saholicUser = null;
|
| 427 |
ua2.setUserId(user.getId());
|
427 |
try {
|
| 428 |
ua2.setType(AccountType.cartId);
|
428 |
saholicUser = userUserRepository.selectByEmailId(loginRequestResponseModel.getEmail());
|
| 429 |
userAccountRepository.persist(ua2);
|
429 |
saholicUser.setCreateTimestamp(LocalDateTime.now());
|
| 430 |
LOGGER.info("created....");
|
430 |
} catch (ProfitMandiBusinessException e) {
|
| 431 |
}
|
431 |
LOGGER.info("User doesnt exist in old system");
|
| 432 |
return saholicUser.getId();
|
432 |
}
|
| 433 |
}
|
433 |
if (saholicUser == null) {
|
| 434 |
|
434 |
Cart cart = new Cart();
|
| 435 |
private com.spice.profitmandi.dao.entity.user.User createSaholicUser(
|
435 |
cart.setCartStatus(CartStatus.ACTIVE);
|
| 436 |
LoginRequestResponseModel loginRequestResponseModel) {
|
436 |
cartRepository.persist(cart);
|
| 437 |
com.spice.profitmandi.dao.entity.user.User saholicUser = null;
|
437 |
saholicUser = new com.spice.profitmandi.dao.entity.user.User();
|
| 438 |
try {
|
438 |
saholicUser.setPassword(getHash256(loginRequestResponseModel.getPassword()));
|
| 439 |
saholicUser = userUserRepository.selectByEmailId(loginRequestResponseModel.getEmail());
|
439 |
saholicUser.setEmailId(loginRequestResponseModel.getEmail());
|
| 440 |
saholicUser.setCreateTimestamp(LocalDateTime.now());
|
440 |
saholicUser.setName(loginRequestResponseModel.getCustomerName());
|
| 441 |
} catch (ProfitMandiBusinessException e) {
|
441 |
saholicUser.setActiveCartId(cart.getId());
|
| 442 |
LOGGER.info("User doesnt exist in old system");
|
442 |
saholicUser.setCreateTimestamp(LocalDateTime.now());
|
| 443 |
}
|
443 |
loginRequestResponseModel.setPassword(null);
|
| 444 |
if (saholicUser == null) {
|
444 |
userUserRepository.persist(saholicUser);
|
| 445 |
Cart cart = new Cart();
|
445 |
}
|
| 446 |
cart.setCartStatus(CartStatus.ACTIVE);
|
446 |
return saholicUser;
|
| 447 |
cartRepository.persist(cart);
|
447 |
}
|
| 448 |
saholicUser = new com.spice.profitmandi.dao.entity.user.User();
|
448 |
|
| 449 |
saholicUser.setPassword(getHash256(loginRequestResponseModel.getPassword()));
|
449 |
private Retailer updateRetailer(User user, Retailer retailer, UpdateRetailerRequest updateRetailerRequest) throws ProfitMandiBusinessException {
|
| 450 |
saholicUser.setEmailId(loginRequestResponseModel.getEmail());
|
450 |
if (retailer == null) {
|
| 451 |
saholicUser.setName(loginRequestResponseModel.getCustomerName());
|
451 |
LOGGER.info("createSaholicUser.....");
|
| 452 |
saholicUser.setActiveCartId(cart.getId());
|
452 |
int saholicUserId = this.createSaholicUser(user, updateRetailerRequest.getName());
|
| 453 |
saholicUser.setCreateTimestamp(LocalDateTime.now());
|
453 |
retailer = new Retailer();
|
| 454 |
loginRequestResponseModel.setPassword(null);
|
454 |
retailer.setId(saholicUserId);
|
| 455 |
userUserRepository.persist(saholicUser);
|
455 |
}
|
| 456 |
}
|
456 |
retailer.setActive(updateRetailerRequest.isActive());
|
| 457 |
return saholicUser;
|
457 |
user.setActivated(updateRetailerRequest.isActive());//
|
| 458 |
}
|
458 |
// this.createRole(user.getId(), RoleType.RETAILER);
|
| 459 |
|
459 |
retailer.setName(updateRetailerRequest.getName());
|
| 460 |
private Retailer updateRetailer(User user, Retailer retailer, UpdateRetailerRequest updateRetailerRequest)
|
460 |
retailer.setNumber(updateRetailerRequest.getNumber());
|
| 461 |
throws ProfitMandiBusinessException {
|
461 |
if (updateRetailerRequest.getNumber() == null || updateRetailerRequest.getNumber().isEmpty()) {
|
| 462 |
if (retailer == null) {
|
462 |
retailer.setType(RetailerType.UNREGISTERED_SHOP);
|
| 463 |
LOGGER.info("createSaholicUser.....");
|
463 |
} else {
|
| 464 |
int saholicUserId = this.createSaholicUser(user, updateRetailerRequest.getName());
|
464 |
retailer.setType(RetailerType.GSTIN);
|
| 465 |
retailer = new Retailer();
|
465 |
}
|
| 466 |
retailer.setId(saholicUserId);
|
466 |
if (updateRetailerRequest.getDocumentId() > 0) {
|
| 467 |
}
|
467 |
if (retailer.getDocumentId() != null && retailer.getDocumentId() != updateRetailerRequest.getDocumentId()) {
|
| 468 |
retailer.setActive(updateRetailerRequest.isActive());
|
468 |
try {
|
| 469 |
user.setActivated(updateRetailerRequest.isActive());//
|
469 |
documentRepository.deleteById(retailer.getDocumentId());
|
| 470 |
// this.createRole(user.getId(), RoleType.RETAILER);
|
470 |
} catch (Exception e) {
|
| 471 |
retailer.setName(updateRetailerRequest.getName());
|
471 |
e.printStackTrace();
|
| 472 |
retailer.setNumber(updateRetailerRequest.getNumber());
|
472 |
}
|
| 473 |
if (updateRetailerRequest.getNumber() == null || updateRetailerRequest.getNumber().isEmpty()) {
|
473 |
}
|
| 474 |
retailer.setType(RetailerType.UNREGISTERED_SHOP);
|
474 |
retailer.setDocumentId(updateRetailerRequest.getDocumentId());
|
| 475 |
} else {
|
475 |
documentRepository.markDocumentAsPersisted(updateRetailerRequest.getDocumentId());
|
| 476 |
retailer.setType(RetailerType.GSTIN);
|
476 |
}
|
| 477 |
}
|
477 |
retailerRepository.persist(retailer);
|
| 478 |
if (updateRetailerRequest.getDocumentId() > 0) {
|
478 |
return retailer;
|
| 479 |
if (retailer.getDocumentId() != null && retailer.getDocumentId() != updateRetailerRequest.getDocumentId()) {
|
479 |
}
|
| 480 |
try {
|
480 |
|
| 481 |
documentRepository.deleteById(retailer.getDocumentId());
|
481 |
private void updateSaholicUser(int retailerId, int retailerAddressId) {
|
| 482 |
} catch (Exception e) {
|
482 |
try {
|
| 483 |
e.printStackTrace();
|
483 |
com.spice.profitmandi.dao.entity.user.User user = userUserRepository.selectById(retailerId);
|
| 484 |
}
|
484 |
user.setAddressId(retailerAddressId);
|
| 485 |
}
|
485 |
} catch (ProfitMandiBusinessException e) {
|
| 486 |
retailer.setDocumentId(updateRetailerRequest.getDocumentId());
|
486 |
|
| 487 |
documentRepository.markDocumentAsPersisted(updateRetailerRequest.getDocumentId());
|
487 |
}
|
| 488 |
}
|
488 |
}
|
| 489 |
retailerRepository.persist(retailer);
|
489 |
|
| 490 |
return retailer;
|
490 |
private void createPrivateDealUser(User user, boolean fofo, String gstNumber, Retailer retailer, int retailerAddressId) {
|
| 491 |
}
|
491 |
PrivateDealUser privateDealUser = null;
|
| 492 |
|
492 |
try {
|
| 493 |
private void updateSaholicUser(int retailerId, int retailerAddressId) {
|
493 |
privateDealUser = privateDealUserRepository.selectById(retailer.getId());
|
| 494 |
try {
|
494 |
} catch (ProfitMandiBusinessException profitMandiBusinessException) {
|
| 495 |
com.spice.profitmandi.dao.entity.user.User user = userUserRepository.selectById(retailerId);
|
495 |
LOGGER.error("PrivateDealUser not found");
|
| 496 |
user.setAddressId(retailerAddressId);
|
496 |
}
|
| 497 |
} catch (ProfitMandiBusinessException e) {
|
497 |
|
| 498 |
|
498 |
// = privateDealUserRepository.selectById(saholicUser.getId());
|
| 499 |
}
|
499 |
if (privateDealUser == null) {
|
| 500 |
}
|
500 |
Integer counterId = this.createCounter(user.getEmailId(), gstNumber, user.getMobileNumber(), retailer.getName(), retailerAddressId);
|
| 501 |
|
501 |
try {
|
| 502 |
private void createPrivateDealUser(User user, boolean fofo, String gstNumber, Retailer retailer,
|
502 |
this.createPrivateDealUser(retailer.getId(), counterId, fofo);
|
| 503 |
int retailerAddressId) {
|
503 |
} catch (Exception e) {
|
| 504 |
PrivateDealUser privateDealUser = null;
|
504 |
LOGGER.error("ERROR : ", e);
|
| 505 |
try {
|
505 |
}
|
| 506 |
privateDealUser = privateDealUserRepository.selectById(retailer.getId());
|
506 |
} else {
|
| 507 |
} catch (ProfitMandiBusinessException profitMandiBusinessException) {
|
507 |
if (privateDealUser.getCounterId() == null) {
|
| 508 |
LOGGER.error("PrivateDealUser not found");
|
508 |
Integer counterId = this.createCounter(user.getEmailId(), gstNumber, user.getMobileNumber(), retailer.getName(), retailerAddressId);
|
| 509 |
}
|
509 |
privateDealUser.setCounterId(counterId);
|
| 510 |
|
510 |
privateDealUser.setFofo(fofo);
|
| 511 |
// = privateDealUserRepository.selectById(saholicUser.getId());
|
511 |
privateDealUserRepository.persist(privateDealUser);
|
| 512 |
if (privateDealUser == null) {
|
512 |
} else {
|
| 513 |
Integer counterId = this.createCounter(user.getEmailId(), gstNumber, user.getMobileNumber(),
|
513 |
Counter counter = null;
|
| 514 |
retailer.getName(), retailerAddressId);
|
514 |
try {
|
| 515 |
try {
|
515 |
counter = counterRepository.selectById(privateDealUser.getCounterId());
|
| 516 |
this.createPrivateDealUser(retailer.getId(), counterId, fofo);
|
516 |
} catch (ProfitMandiBusinessException profitMandiBusinessException) {
|
| 517 |
} catch (Exception e) {
|
517 |
LOGGER.error("Counter not found with id [{}]", privateDealUser.getCounterId());
|
| 518 |
LOGGER.error("ERROR : ", e);
|
518 |
}
|
| 519 |
}
|
519 |
if (counter == null) {
|
| 520 |
} else {
|
520 |
this.createCounter(user.getEmailId(), gstNumber, user.getMobileNumber(), retailer.getName(), retailerAddressId);
|
| 521 |
if (privateDealUser.getCounterId() == null) {
|
521 |
} else {
|
| 522 |
Integer counterId = this.createCounter(user.getEmailId(), gstNumber, user.getMobileNumber(),
|
522 |
counter.setGstin(gstNumber);
|
| 523 |
retailer.getName(), retailerAddressId);
|
523 |
counterRepository.persist(counter);
|
| 524 |
privateDealUser.setCounterId(counterId);
|
524 |
}
|
| 525 |
privateDealUser.setFofo(fofo);
|
525 |
privateDealUser.setFofo(fofo);
|
| 526 |
privateDealUserRepository.persist(privateDealUser);
|
526 |
privateDealUserRepository.persist(privateDealUser);
|
| 527 |
} else {
|
527 |
}
|
| 528 |
Counter counter = null;
|
528 |
}
|
| 529 |
try {
|
529 |
|
| 530 |
counter = counterRepository.selectById(privateDealUser.getCounterId());
|
530 |
PrivateDealUserAddressMapping privateDealUserAddressMapping = new PrivateDealUserAddressMapping();
|
| 531 |
} catch (ProfitMandiBusinessException profitMandiBusinessException) {
|
531 |
privateDealUserAddressMapping.setUserId(retailer.getId());
|
| 532 |
LOGGER.error("Counter not found with id [{}]", privateDealUser.getCounterId());
|
532 |
privateDealUserAddressMapping.setAddressId(retailerAddressId);
|
| 533 |
}
|
533 |
privateDealUserAddressMappingRepository.persist(privateDealUserAddressMapping);
|
| 534 |
if (counter == null) {
|
534 |
}
|
| 535 |
this.createCounter(user.getEmailId(), gstNumber, user.getMobileNumber(), retailer.getName(),
|
535 |
|
| 536 |
retailerAddressId);
|
536 |
// Specifically set isFofo to true that has to be used by old system
|
| 537 |
} else {
|
537 |
private void createPrivateDealUser(int retailerId, int counterId, boolean fofo) {
|
| 538 |
counter.setGstin(gstNumber);
|
538 |
PrivateDealUser privateDealUser = new PrivateDealUser();
|
| 539 |
counterRepository.persist(counter);
|
539 |
privateDealUser.setActive(true);
|
| 540 |
}
|
540 |
privateDealUser.setBulkShipmentAmountLimit(fofo ? 1000000 : 50000);
|
| 541 |
privateDealUser.setFofo(fofo);
|
541 |
privateDealUser.setId(retailerId);
|
| 542 |
privateDealUserRepository.persist(privateDealUser);
|
542 |
privateDealUser.setCounterId(counterId);
|
| 543 |
}
|
543 |
privateDealUser.setFofo(fofo);
|
| 544 |
}
|
544 |
privateDealUserRepository.persist(privateDealUser);
|
| 545 |
|
545 |
}
|
| 546 |
PrivateDealUserAddressMapping privateDealUserAddressMapping = new PrivateDealUserAddressMapping();
|
546 |
|
| 547 |
privateDealUserAddressMapping.setUserId(retailer.getId());
|
547 |
private Integer createCounter(String emailId, String gstNumber, String mobileNumber, String name, int addressId) {
|
| 548 |
privateDealUserAddressMapping.setAddressId(retailerAddressId);
|
548 |
if (gstNumber != null && !gstNumber.isEmpty()) {
|
| 549 |
privateDealUserAddressMappingRepository.persist(privateDealUserAddressMapping);
|
549 |
Counter counter = new Counter();
|
| 550 |
}
|
550 |
counter.setEmailId(emailId);
|
| 551 |
|
551 |
counter.setGstin(gstNumber);
|
| 552 |
// Specifically set isFofo to true that has to be used by old system
|
552 |
counter.setMobileNumber(mobileNumber);
|
| 553 |
private void createPrivateDealUser(int retailerId, int counterId, boolean fofo) {
|
553 |
counter.setName(name);
|
| 554 |
PrivateDealUser privateDealUser = new PrivateDealUser();
|
554 |
counter.setAddressId(addressId);
|
| 555 |
privateDealUser.setActive(true);
|
555 |
counterRepository.persist(counter);
|
| 556 |
privateDealUser.setBulkShipmentAmountLimit(fofo ? 1000000 : 50000);
|
556 |
return counter.getId();
|
| 557 |
privateDealUser.setId(retailerId);
|
557 |
} else {
|
| 558 |
privateDealUser.setCounterId(counterId);
|
558 |
return null;
|
| 559 |
privateDealUser.setFofo(fofo);
|
559 |
}
|
| 560 |
privateDealUserRepository.persist(privateDealUser);
|
560 |
}
|
| 561 |
}
|
561 |
|
| 562 |
|
562 |
private Address updateRetailerAddress(Address address, CustomAddress customAddress, int retailerId) throws ProfitMandiBusinessException {
|
| 563 |
private Integer createCounter(String emailId, String gstNumber, String mobileNumber, String name, int addressId) {
|
563 |
if (address == null) {
|
| 564 |
if (gstNumber != null && !gstNumber.isEmpty()) {
|
564 |
address = new Address();
|
| 565 |
Counter counter = new Counter();
|
565 |
address.setRetaierId(retailerId);
|
| 566 |
counter.setEmailId(emailId);
|
566 |
this.updateAddress(address, customAddress);
|
| 567 |
counter.setGstin(gstNumber);
|
567 |
// addressRepository.persist(addressRetailer);
|
| 568 |
counter.setMobileNumber(mobileNumber);
|
568 |
|
| 569 |
counter.setName(name);
|
569 |
final RetailerRegisteredAddress retailerRegisteredAddress = new RetailerRegisteredAddress();
|
| 570 |
counter.setAddressId(addressId);
|
570 |
retailerRegisteredAddress.setRetailerId(retailerId);
|
| 571 |
counterRepository.persist(counter);
|
571 |
retailerRegisteredAddress.setAddressId(address.getId());
|
| 572 |
return counter.getId();
|
572 |
retailerRegisteredAddressRepository.persist(retailerRegisteredAddress);
|
| 573 |
} else {
|
573 |
} else {
|
| 574 |
return null;
|
574 |
this.updateAddress(address, customAddress);
|
| 575 |
}
|
575 |
RetailerRegisteredAddress retailerRegisteredAddress = retailerRegisteredAddressRepository.selectByRetailerId(retailerId);
|
| 576 |
}
|
576 |
retailerRegisteredAddress.setAddressId(address.getId());
|
| 577 |
|
577 |
retailerRegisteredAddressRepository.persist(retailerRegisteredAddress);
|
| 578 |
private Address updateRetailerAddress(Address address, CustomAddress customAddress, int retailerId)
|
578 |
}
|
| 579 |
throws ProfitMandiBusinessException {
|
579 |
return address;
|
| 580 |
if (address == null) {
|
580 |
}
|
| 581 |
address = new Address();
|
581 |
|
| 582 |
address.setRetaierId(retailerId);
|
582 |
private void updateAddress(Address address, CustomAddress customAddress) throws ProfitMandiBusinessException {
|
| 583 |
this.updateAddress(address, customAddress);
|
583 |
address.setName(customAddress.getName());
|
| 584 |
// addressRepository.persist(addressRetailer);
|
584 |
address.setPhoneNumber(customAddress.getPhoneNumber());
|
| 585 |
|
585 |
address.setLine1(customAddress.getLine1());
|
| 586 |
final RetailerRegisteredAddress retailerRegisteredAddress = new RetailerRegisteredAddress();
|
586 |
address.setLine2(customAddress.getLine2());
|
| 587 |
retailerRegisteredAddress.setRetailerId(retailerId);
|
587 |
address.setCity(customAddress.getCity());
|
| 588 |
retailerRegisteredAddress.setAddressId(address.getId());
|
588 |
address.setPinCode(customAddress.getPinCode());
|
| 589 |
retailerRegisteredAddressRepository.persist(retailerRegisteredAddress);
|
589 |
State state = stateRepository.selectByName(customAddress.getState());
|
| 590 |
} else {
|
590 |
if (state == null) {
|
| 591 |
this.updateAddress(address, customAddress);
|
591 |
throw new ProfitMandiBusinessException("State name", "Invalid State - Pls Contact Technology", "Invalid State - Pls Contact Technology");
|
| 592 |
RetailerRegisteredAddress retailerRegisteredAddress = retailerRegisteredAddressRepository
|
592 |
}
|
| 593 |
.selectByRetailerId(retailerId);
|
593 |
address.setState(state.getName());
|
| 594 |
retailerRegisteredAddress.setAddressId(address.getId());
|
594 |
addressRepository.persist(address);
|
| 595 |
retailerRegisteredAddressRepository.persist(retailerRegisteredAddress);
|
595 |
LOGGER.info("Address Updated" + address);
|
| 596 |
}
|
596 |
}
|
| 597 |
return address;
|
597 |
|
| 598 |
}
|
598 |
private void updateRetailerShops(List<Shop> shops, Set<CustomShop> customShops, int retailerId, Address sameAsRetailerAddressValue) throws ProfitMandiBusinessException {
|
| 599 |
|
599 |
if (shops.isEmpty()) {
|
| 600 |
private void updateAddress(Address address, CustomAddress customAddress) throws ProfitMandiBusinessException {
|
600 |
for (CustomShop customShop : customShops) {
|
| 601 |
address.setName(customAddress.getName());
|
601 |
Shop shop = new Shop();
|
| 602 |
address.setPhoneNumber(customAddress.getPhoneNumber());
|
602 |
this.createOrUpdateShop(shop, customShop, retailerId, sameAsRetailerAddressValue);
|
| 603 |
address.setLine1(customAddress.getLine1());
|
603 |
shops.add(shop);
|
| 604 |
address.setLine2(customAddress.getLine2());
|
604 |
}
|
| 605 |
address.setCity(customAddress.getCity());
|
605 |
} else {
|
| 606 |
address.setPinCode(customAddress.getPinCode());
|
606 |
for (Shop shop : shops) {
|
| 607 |
State state = stateRepository.selectByName(customAddress.getState());
|
607 |
for (CustomShop customShop : customShops) {
|
| 608 |
if (state == null) {
|
608 |
if (shop.getId() == customShop.getShopId()) {
|
| 609 |
throw new ProfitMandiBusinessException("State name", "Invalid State - Pls Contact Technology",
|
609 |
this.createOrUpdateShop(shop, customShop, retailerId, sameAsRetailerAddressValue);
|
| 610 |
"Invalid State - Pls Contact Technology");
|
610 |
}
|
| 611 |
}
|
611 |
}
|
| 612 |
address.setState(state.getName());
|
612 |
}
|
| 613 |
addressRepository.persist(address);
|
613 |
for (CustomShop customShop : customShops) {
|
| 614 |
LOGGER.info("Address Updated" + address);
|
614 |
if (customShop.getShopId() == 0) {
|
| 615 |
}
|
615 |
Shop shop = new Shop();
|
| 616 |
|
616 |
this.createOrUpdateShop(shop, customShop, retailerId, sameAsRetailerAddressValue);
|
| 617 |
private void updateRetailerShops(List<Shop> shops, Set<CustomShop> customShops, int retailerId,
|
617 |
shops.add(shop);
|
| 618 |
Address sameAsRetailerAddressValue) throws ProfitMandiBusinessException {
|
618 |
}
|
| 619 |
if (shops.isEmpty()) {
|
619 |
}
|
| 620 |
for (CustomShop customShop : customShops) {
|
620 |
}
|
| 621 |
Shop shop = new Shop();
|
621 |
}
|
| 622 |
this.createOrUpdateShop(shop, customShop, retailerId, sameAsRetailerAddressValue);
|
622 |
|
| 623 |
shops.add(shop);
|
623 |
private void createOrUpdateShop(Shop shop, CustomShop customShop, int retailerId, Address sameAsRetailerAddressValue) throws ProfitMandiBusinessException {
|
| 624 |
}
|
624 |
shop.setRetailerId(retailerId);
|
| 625 |
} else {
|
625 |
shop.setName(customShop.getName());
|
| 626 |
for (Shop shop : shops) {
|
626 |
if (customShop.getDocumentId() > 0) {
|
| 627 |
for (CustomShop customShop : customShops) {
|
627 |
if (shop.getDocumentId() != null && shop.getDocumentId() != customShop.getDocumentId()) {
|
| 628 |
if (shop.getId() == customShop.getShopId()) {
|
628 |
try {
|
| 629 |
this.createOrUpdateShop(shop, customShop, retailerId, sameAsRetailerAddressValue);
|
629 |
documentRepository.deleteById(shop.getDocumentId());
|
| 630 |
}
|
630 |
} catch (Exception e) {
|
| 631 |
}
|
631 |
e.printStackTrace();
|
| 632 |
}
|
632 |
}
|
| 633 |
for (CustomShop customShop : customShops) {
|
633 |
}
|
| 634 |
if (customShop.getShopId() == 0) {
|
634 |
shop.setDocumentId(customShop.getDocumentId());
|
| 635 |
Shop shop = new Shop();
|
635 |
documentRepository.markDocumentAsPersisted(customShop.getDocumentId());
|
| 636 |
this.createOrUpdateShop(shop, customShop, retailerId, sameAsRetailerAddressValue);
|
636 |
}
|
| 637 |
shops.add(shop);
|
637 |
if (shop.getAddressId() == null) {
|
| 638 |
}
|
638 |
Address address = null;
|
| 639 |
}
|
639 |
if (customShop.isSameAsRetailerAddress()) {
|
| 640 |
}
|
640 |
address = sameAsRetailerAddressValue;
|
| 641 |
}
|
641 |
} else {
|
| 642 |
|
642 |
// shop.setDocumentId(customShop.getDocumentId());
|
| 643 |
private void createOrUpdateShop(Shop shop, CustomShop customShop, int retailerId,
|
643 |
address = new Address();
|
| 644 |
Address sameAsRetailerAddressValue) throws ProfitMandiBusinessException {
|
644 |
this.updateAddress(address, customShop.getAddress());
|
| 645 |
shop.setRetailerId(retailerId);
|
645 |
}
|
| 646 |
shop.setName(customShop.getName());
|
646 |
shop.setAddressId(address.getId());
|
| 647 |
if (customShop.getDocumentId() > 0) {
|
647 |
shop.setAddress(address);
|
| 648 |
if (shop.getDocumentId() != null && shop.getDocumentId() != customShop.getDocumentId()) {
|
648 |
shopRepository.persist(shop);
|
| 649 |
try {
|
649 |
ShopAddress shopAddress = null;
|
| 650 |
documentRepository.deleteById(shop.getDocumentId());
|
650 |
try {
|
| 651 |
} catch (Exception e) {
|
651 |
shopAddress = shopAddressRepository.selectByShopId(shop.getId());
|
| 652 |
e.printStackTrace();
|
652 |
shopAddress.setAddressId(address.getId());
|
| 653 |
}
|
653 |
} catch (ProfitMandiBusinessException profitMandiBusinessException) {
|
| 654 |
}
|
654 |
shopAddress = new ShopAddress();
|
| 655 |
shop.setDocumentId(customShop.getDocumentId());
|
655 |
shopAddress.setAddressId(address.getId());
|
| 656 |
documentRepository.markDocumentAsPersisted(customShop.getDocumentId());
|
656 |
shopAddress.setShopId(shop.getId());
|
| 657 |
}
|
657 |
}
|
| 658 |
if (shop.getAddressId() == null) {
|
658 |
shopAddressRepository.persist(shopAddress);
|
| 659 |
Address address = null;
|
659 |
} else {
|
| 660 |
if (customShop.isSameAsRetailerAddress()) {
|
660 |
Address address = null;
|
| 661 |
address = sameAsRetailerAddressValue;
|
661 |
try {
|
| 662 |
} else {
|
662 |
address = addressRepository.selectById(shop.getAddressId());
|
| 663 |
// shop.setDocumentId(customShop.getDocumentId());
|
663 |
CustomAddress customAddress = customShop.getAddress();
|
| 664 |
address = new Address();
|
664 |
if (!(address.getName().equals(customAddress.getName()) && address.getLine1().equals(customAddress.getLine1()) && address.getLine2().equals(customAddress.getLine2()) && address.getCity().equals(customAddress.getCity()) && address.getPinCode().equals(customAddress.getPinCode()) && address.getState().equals(customAddress.getState()))) {
|
| 665 |
this.updateAddress(address, customShop.getAddress());
|
665 |
address = new Address();
|
| 666 |
}
|
666 |
ShopAddress shopAddress = shopAddressRepository.selectByShopId(shop.getId());
|
| 667 |
shop.setAddressId(address.getId());
|
667 |
this.updateAddress(address, customAddress);
|
| 668 |
shop.setAddress(address);
|
668 |
shopAddress.setAddressId(address.getId());
|
| 669 |
shopRepository.persist(shop);
|
669 |
shopAddressRepository.persist(shopAddress);
|
| 670 |
ShopAddress shopAddress = null;
|
670 |
shop.setAddress(address);
|
| 671 |
try {
|
671 |
shopRepository.persist(shop);
|
| 672 |
shopAddress = shopAddressRepository.selectByShopId(shop.getId());
|
672 |
}
|
| 673 |
shopAddress.setAddressId(address.getId());
|
673 |
} catch (Exception e) {
|
| 674 |
} catch (ProfitMandiBusinessException profitMandiBusinessException) {
|
674 |
if (customShop.isSameAsRetailerAddress()) {
|
| 675 |
shopAddress = new ShopAddress();
|
675 |
address = sameAsRetailerAddressValue;
|
| 676 |
shopAddress.setAddressId(address.getId());
|
676 |
} else {
|
| 677 |
shopAddress.setShopId(shop.getId());
|
677 |
// shop.setDocumentId(customShop.getDocumentId());
|
| 678 |
}
|
678 |
address = new Address();
|
| 679 |
shopAddressRepository.persist(shopAddress);
|
679 |
this.updateAddress(address, customShop.getAddress());
|
| 680 |
} else {
|
680 |
}
|
| 681 |
Address address = null;
|
681 |
shop.setAddressId(address.getId());
|
| 682 |
try {
|
682 |
shop.setAddress(address);
|
| 683 |
address = addressRepository.selectById(shop.getAddressId());
|
683 |
shopRepository.persist(shop);
|
| 684 |
CustomAddress customAddress = customShop.getAddress();
|
684 |
ShopAddress shopAddress = null;
|
| 685 |
if (!(address.getName().equals(customAddress.getName())
|
685 |
try {
|
| 686 |
&& address.getLine1().equals(customAddress.getLine1())
|
686 |
shopAddress = shopAddressRepository.selectByShopId(shop.getId());
|
| 687 |
&& address.getLine2().equals(customAddress.getLine2())
|
687 |
shopAddress.setAddressId(address.getId());
|
| 688 |
&& address.getCity().equals(customAddress.getCity())
|
688 |
} catch (ProfitMandiBusinessException profitMandiBusinessException) {
|
| 689 |
&& address.getPinCode().equals(customAddress.getPinCode())
|
689 |
shopAddress = new ShopAddress();
|
| 690 |
&& address.getState().equals(customAddress.getState()))) {
|
690 |
shopAddress.setAddressId(address.getId());
|
| 691 |
address = new Address();
|
691 |
shopAddress.setShopId(shop.getId());
|
| 692 |
ShopAddress shopAddress = shopAddressRepository.selectByShopId(shop.getId());
|
692 |
}
|
| 693 |
this.updateAddress(address, customAddress);
|
693 |
shopAddressRepository.persist(shopAddress);
|
| 694 |
shopAddress.setAddressId(address.getId());
|
694 |
}
|
| 695 |
shopAddressRepository.persist(shopAddress);
|
695 |
|
| 696 |
shop.setAddress(address);
|
696 |
}
|
| 697 |
shopRepository.persist(shop);
|
697 |
|
| 698 |
}
|
698 |
}
|
| 699 |
} catch (Exception e) {
|
699 |
|
| 700 |
if (customShop.isSameAsRetailerAddress()) {
|
700 |
private void addAddress(List<Shop> shops) {
|
| 701 |
address = sameAsRetailerAddressValue;
|
701 |
Set<Integer> shopIds = this.toShopIds(shops);
|
| 702 |
} else {
|
702 |
if (shopIds.isEmpty()) {
|
| 703 |
// shop.setDocumentId(customShop.getDocumentId());
|
703 |
return;
|
| 704 |
address = new Address();
|
704 |
}
|
| 705 |
this.updateAddress(address, customShop.getAddress());
|
705 |
List<ShopAddress> shopAddresses = shopAddressRepository.selectByShopIds(shopIds);
|
| 706 |
}
|
706 |
Map<Integer, Address> addressIdAddressMap = this.toAddressIdAddressMap(shopAddresses);
|
| 707 |
shop.setAddressId(address.getId());
|
707 |
|
| 708 |
shop.setAddress(address);
|
708 |
for (Shop shop : shops) {
|
| 709 |
shopRepository.persist(shop);
|
709 |
shop.setAddress(addressIdAddressMap.get(shop.getAddressId()));
|
| 710 |
ShopAddress shopAddress = null;
|
710 |
}
|
| 711 |
try {
|
711 |
}
|
| 712 |
shopAddress = shopAddressRepository.selectByShopId(shop.getId());
|
712 |
|
| 713 |
shopAddress.setAddressId(address.getId());
|
713 |
private Map<Integer, Address> toAddressIdAddressMap(List<ShopAddress> shopAddresses) {
|
| 714 |
} catch (ProfitMandiBusinessException profitMandiBusinessException) {
|
714 |
Map<Integer, Address> addressIdAddressMap = new HashMap<>();
|
| 715 |
shopAddress = new ShopAddress();
|
715 |
List<Integer> addressIds = this.toAddressIds(shopAddresses);
|
| 716 |
shopAddress.setAddressId(address.getId());
|
716 |
List<Address> addresses = addressRepository.selectByIds(addressIds);
|
| 717 |
shopAddress.setShopId(shop.getId());
|
717 |
for (Address address : addresses) {
|
| 718 |
}
|
718 |
addressIdAddressMap.put(address.getId(), address);
|
| 719 |
shopAddressRepository.persist(shopAddress);
|
719 |
}
|
| 720 |
}
|
720 |
return addressIdAddressMap;
|
| 721 |
|
721 |
}
|
| 722 |
}
|
722 |
|
| 723 |
|
723 |
private List<Integer> toAddressIds(List<ShopAddress> shopAddresses) {
|
| 724 |
}
|
724 |
Function<ShopAddress, Integer> shopAddressToAddressIdFunction = new Function<ShopAddress, Integer>() {
|
| 725 |
|
725 |
@Override
|
| 726 |
private void addAddress(List<Shop> shops) {
|
726 |
public Integer apply(ShopAddress shopAddress) {
|
| 727 |
Set<Integer> shopIds = this.toShopIds(shops);
|
727 |
return shopAddress.getAddressId();
|
| 728 |
if (shopIds.isEmpty()) {
|
728 |
}
|
| 729 |
return;
|
729 |
};
|
| 730 |
}
|
730 |
return shopAddresses.stream().map(shopAddressToAddressIdFunction).collect(Collectors.toList());
|
| 731 |
List<ShopAddress> shopAddresses = shopAddressRepository.selectByShopIds(shopIds);
|
731 |
}
|
| 732 |
Map<Integer, Address> addressIdAddressMap = this.toAddressIdAddressMap(shopAddresses);
|
732 |
|
| 733 |
|
733 |
private Set<Integer> toShopIds(List<Shop> shops) {
|
| 734 |
for (Shop shop : shops) {
|
734 |
Function<Shop, Integer> shopToAddressIdFunction = new Function<Shop, Integer>() {
|
| 735 |
shop.setAddress(addressIdAddressMap.get(shop.getAddressId()));
|
735 |
@Override
|
| 736 |
}
|
736 |
public Integer apply(Shop shop) {
|
| 737 |
}
|
737 |
return shop.getId();
|
| 738 |
|
738 |
}
|
| 739 |
private Map<Integer, Address> toAddressIdAddressMap(List<ShopAddress> shopAddresses) {
|
739 |
};
|
| 740 |
Map<Integer, Address> addressIdAddressMap = new HashMap<>();
|
740 |
return shops.stream().map(shopToAddressIdFunction).collect(Collectors.toSet());
|
| 741 |
List<Integer> addressIds = this.toAddressIds(shopAddresses);
|
741 |
}
|
| 742 |
List<Address> addresses = addressRepository.selectByIds(addressIds);
|
742 |
|
| 743 |
for (Address address : addresses) {
|
743 |
private String toString(List<UserRole> userRoles) {
|
| 744 |
addressIdAddressMap.put(address.getId(), address);
|
744 |
Set<Integer> roleIds = new HashSet<>();
|
| 745 |
}
|
745 |
for (UserRole userRole : userRoles) {
|
| 746 |
return addressIdAddressMap;
|
746 |
roleIds.add(userRole.getRoleId());
|
| 747 |
}
|
747 |
}
|
| 748 |
|
748 |
List<Role> roles = roleRepository.selectByIds(roleIds);
|
| 749 |
private List<Integer> toAddressIds(List<ShopAddress> shopAddresses) {
|
749 |
Function<Role, String> roleToNameFunction = new Function<Role, String>() {
|
| 750 |
Function<ShopAddress, Integer> shopAddressToAddressIdFunction = new Function<ShopAddress, Integer>() {
|
750 |
public String apply(Role role) {
|
| 751 |
@Override
|
751 |
return String.valueOf(role.getName());
|
| 752 |
public Integer apply(ShopAddress shopAddress) {
|
752 |
};
|
| 753 |
return shopAddress.getAddressId();
|
753 |
};
|
| 754 |
}
|
754 |
Set<String> userRoleStrings = roles.stream().map(roleToNameFunction).collect(Collectors.toSet());
|
| 755 |
};
|
755 |
return String.join(", ", userRoleStrings);
|
| 756 |
return shopAddresses.stream().map(shopAddressToAddressIdFunction).collect(Collectors.toList());
|
756 |
}
|
| 757 |
}
|
757 |
|
| 758 |
|
758 |
private FofoStore createFofoStoreCodeByRetailerId(int retailerId, String districtName, String stateName, UpdateRetailerRequest updateRetailerRequest) throws ProfitMandiBusinessException {
|
| 759 |
private Set<Integer> toShopIds(List<Shop> shops) {
|
759 |
FofoStore fofoStore = null;
|
| 760 |
Function<Shop, Integer> shopToAddressIdFunction = new Function<Shop, Integer>() {
|
760 |
try {
|
| 761 |
@Override
|
761 |
fofoStore = fofoStoreRepository.selectByRetailerId(retailerId);
|
| 762 |
public Integer apply(Shop shop) {
|
762 |
fofoStore.setActivationType(ActivationType.ACTIVE);
|
| 763 |
return shop.getId();
|
763 |
|
| 764 |
}
|
764 |
} catch (ProfitMandiBusinessException profitMandiBusinessException) {
|
| 765 |
};
|
765 |
|
| 766 |
return shops.stream().map(shopToAddressIdFunction).collect(Collectors.toSet());
|
766 |
}
|
| 767 |
}
|
767 |
|
| 768 |
|
768 |
if (fofoStore != null) {
|
| 769 |
private String toString(List<UserRole> userRoles) {
|
769 |
fofoStore.setCounterSize(updateRetailerRequest.getCountersize());
|
| 770 |
Set<Integer> roleIds = new HashSet<>();
|
770 |
fofoStore.setMinimumInvestment(updateRetailerRequest.getMinInvestment());
|
| 771 |
for (UserRole userRole : userRoles) {
|
771 |
fofoStore.setWarehouseId(updateRetailerRequest.getWarehouseId());
|
| 772 |
roleIds.add(userRole.getRoleId());
|
772 |
fofoStore.setCounterPotential(updateRetailerRequest.getCounterPotential());
|
| 773 |
}
|
773 |
fofoStore.setFofoType(updateRetailerRequest.getFofoType());
|
| 774 |
List<Role> roles = roleRepository.selectByIds(roleIds);
|
774 |
|
| 775 |
Function<Role, String> roleToNameFunction = new Function<Role, String>() {
|
775 |
} else {
|
| 776 |
public String apply(Role role) {
|
776 |
int retailerAddressId = retailerRegisteredAddressRepository.selectAddressIdByRetailerId(retailerId);
|
| 777 |
return String.valueOf(role.getName());
|
777 |
Address retailerAddress = addressRepository.selectById(retailerAddressId);
|
| 778 |
};
|
778 |
|
| 779 |
};
|
779 |
// StateInfo stateInfo = null;
|
| 780 |
Set<String> userRoleStrings = roles.stream().map(roleToNameFunction).collect(Collectors.toSet());
|
780 |
State stateInfo = null;
|
| 781 |
return String.join(", ", userRoleStrings);
|
781 |
try {
|
| 782 |
}
|
782 |
|
| 783 |
|
783 |
stateInfo = stateRepository.selectByName(retailerAddress.getState());
|
| 784 |
private FofoStore createFofoStoreCodeByRetailerId(int retailerId, String districtName, String stateName,
|
784 |
// stateInfo = Utils.getStateInfo(retailerAddress.getState());
|
| 785 |
UpdateRetailerRequest updateRetailerRequest) throws ProfitMandiBusinessException {
|
785 |
} catch (Exception e) {
|
| 786 |
FofoStore fofoStore = null;
|
786 |
// TODO Auto-generated catch block
|
| 787 |
try {
|
787 |
e.printStackTrace();
|
| 788 |
fofoStore = fofoStoreRepository.selectByRetailerId(retailerId);
|
788 |
// throw new ProfitMandiBusinessException();
|
| 789 |
fofoStore.setActivationType(ActivationType.ACTIVE);
|
789 |
}
|
| 790 |
|
790 |
DistrictMaster districtMaster = districtMasterRepository.selectByNameAndStateShortName(districtName, stateInfo.getShortName());
|
| 791 |
} catch (ProfitMandiBusinessException profitMandiBusinessException) {
|
791 |
|
| 792 |
|
792 |
fofoStore = new FofoStore();
|
| 793 |
}
|
793 |
fofoStore.setId(retailerId);
|
| 794 |
|
794 |
fofoStore.setCounterSize(updateRetailerRequest.getCountersize());
|
| 795 |
if (fofoStore != null) {
|
795 |
fofoStore.setMinimumInvestment(updateRetailerRequest.getMinInvestment());
|
| 796 |
fofoStore.setCounterSize(updateRetailerRequest.getCountersize());
|
796 |
|
| 797 |
fofoStore.setMinimumInvestment(updateRetailerRequest.getMinInvestment());
|
797 |
fofoStore.setCounterPotential(updateRetailerRequest.getCounterPotential());
|
| 798 |
fofoStore.setWarehouseId(updateRetailerRequest.getWarehouseId());
|
798 |
fofoStore.setWarehouseId(updateRetailerRequest.getWarehouseId());
|
| 799 |
fofoStore.setCounterPotential(updateRetailerRequest.getCounterPotential());
|
799 |
String latestStoreCode = fofoStoreRepository.selectLatestStore().getCode();
|
| 800 |
fofoStore.setFofoType(updateRetailerRequest.getFofoType());
|
800 |
int latestCodeCounter = Integer.parseInt(latestStoreCode.replaceAll("[A-Z]", ""));
|
| 801 |
|
801 |
String fofoStoreCode = StringUtils.generateFofoStoreSequence(
|
| 802 |
} else {
|
802 |
districtMaster.getStateShortName() + districtMaster.getShortName(), latestCodeCounter + 1);
|
| 803 |
int retailerAddressId = retailerRegisteredAddressRepository.selectAddressIdByRetailerId(retailerId);
|
803 |
fofoStore.setCode(fofoStoreCode);
|
| 804 |
Address retailerAddress = addressRepository.selectById(retailerAddressId);
|
804 |
fofoStore.setBagsLastCredited(LocalDateTime.now());
|
| 805 |
|
805 |
fofoStore.setFofoType(updateRetailerRequest.getFofoType());
|
| 806 |
// StateInfo stateInfo = null;
|
806 |
fofoStore.setActivationType(ActivationType.ACTIVE);
|
| 807 |
State stateInfo = null;
|
807 |
fofoStoreRepository.persist(fofoStore);
|
| 808 |
try {
|
808 |
|
| 809 |
|
809 |
// Auto fill in onboarding Panel
|
| 810 |
stateInfo = stateRepository.selectByName(retailerAddress.getState());
|
810 |
PartnerOnBoardingPanel pobp = partnerOnBoardingPanelRepository.selectByPhoneNumber(Long.parseLong(retailerAddress.getPhoneNumber()));
|
| 811 |
// stateInfo = Utils.getStateInfo(retailerAddress.getState());
|
811 |
if (pobp != null) {
|
| 812 |
} catch (Exception e) {
|
812 |
|
| 813 |
// TODO Auto-generated catch block
|
813 |
PartnerVerificationpanel partnerVerificationpanel = partnerOnboardingVerificationRepository.selectByOnboardingId(pobp.getId());
|
| 814 |
e.printStackTrace();
|
814 |
|
| 815 |
// throw new ProfitMandiBusinessException();
|
815 |
if (partnerVerificationpanel != null) {
|
| 816 |
}
|
816 |
if (partnerVerificationpanel.getApproval().equals(PartnerVerificationApprovalStatus.YES)) {
|
| 817 |
DistrictMaster districtMaster = districtMasterRepository.selectByNameAndStateShortName(districtName,
|
817 |
pobp.setCode(fofoStore.getCode());
|
| 818 |
stateInfo.getShortName());
|
818 |
|
| 819 |
|
819 |
storeTimelineTatService.onCodeCreated(pobp.getId());
|
| 820 |
fofoStore = new FofoStore();
|
820 |
|
| 821 |
fofoStore.setId(retailerId);
|
821 |
}
|
| 822 |
fofoStore.setCounterSize(updateRetailerRequest.getCountersize());
|
822 |
|
| 823 |
fofoStore.setMinimumInvestment(updateRetailerRequest.getMinInvestment());
|
823 |
}
|
| 824 |
|
824 |
|
| 825 |
fofoStore.setCounterPotential(updateRetailerRequest.getCounterPotential());
|
825 |
}
|
| 826 |
fofoStore.setWarehouseId(updateRetailerRequest.getWarehouseId());
|
826 |
|
| 827 |
String latestStoreCode = fofoStoreRepository.selectLatestStore().getCode();
|
827 |
PincodePartner pincodePartner = pincodePartnerRepository.selectPartnerByPincode(retailerAddress.getPinCode(), fofoStore.getId());
|
| 828 |
int latestCodeCounter = Integer.parseInt(latestStoreCode.replaceAll("[A-Z]", ""));
|
828 |
if (pincodePartner == null) {
|
| 829 |
String fofoStoreCode = StringUtils.generateFofoStoreSequence(
|
829 |
PincodePartner pinPartner = new PincodePartner();
|
| 830 |
districtMaster.getStateShortName() + districtMaster.getShortName(), latestCodeCounter + 1);
|
830 |
pinPartner.setFofoId(fofoStore.getId());
|
| 831 |
fofoStore.setCode(fofoStoreCode);
|
831 |
pinPartner.setPincode(retailerAddress.getPinCode());
|
| 832 |
fofoStore.setBagsLastCredited(LocalDateTime.now());
|
832 |
pincodePartnerRepository.perist(pinPartner);
|
| 833 |
fofoStore.setFofoType(updateRetailerRequest.getFofoType());
|
833 |
}
|
| 834 |
fofoStore.setActivationType(ActivationType.ACTIVE);
|
834 |
}
|
| 835 |
fofoStoreRepository.persist(fofoStore);
|
835 |
|
| 836 |
|
836 |
return fofoStore;
|
| 837 |
// Auto fill in onboarding Panel
|
837 |
}
|
| 838 |
PartnerOnBoardingPanel pobp = partnerOnBoardingPanelRepository
|
838 |
|
| 839 |
.selectByPhoneNumber(Long.parseLong(retailerAddress.getPhoneNumber()));
|
839 |
@Override
|
| 840 |
if (pobp != null) {
|
840 |
public FofoStore createFofoStoreCodeByUserId(int userId, String districtName, String stateName, UpdateRetailerRequest updateRetailerRequest) throws ProfitMandiBusinessException {
|
| 841 |
|
841 |
User user = userRepository.selectById(userId);
|
| 842 |
PartnerVerificationpanel partnerVerificationpanel = partnerOnboardingVerificationRepository
|
842 |
// = userAccountRepository.selectRetailerIdByUserId(user.getId());
|
| 843 |
.selectByOnboardingId(pobp.getId());
|
843 |
UserAccount userAccounts = userAccountRepository.selectSaholicByUserId(user.getId());
|
| 844 |
|
844 |
Retailer retailer = retailerRepository.selectById(userAccounts.getAccountKey());
|
| 845 |
if (partnerVerificationpanel != null) {
|
845 |
Role roleFofo = roleRepository.selectByName(RoleType.FOFO.toString());
|
| 846 |
if (partnerVerificationpanel.getApproval().equals(PartnerVerificationApprovalStatus.YES)) {
|
846 |
try {
|
| 847 |
pobp.setCode(fofoStore.getCode());
|
847 |
userRoleRepository.selectByUserIdAndRoleId(user.getId(), roleFofo.getId());
|
| 848 |
|
848 |
} catch (ProfitMandiBusinessException profitMandiBusinessException) {
|
| 849 |
storeTimelineTatService.onCodeCreated(pobp.getId());
|
849 |
throw new ProfitMandiBusinessException(ProfitMandiConstants.USER_ID, user.getId(), "USR_1013");
|
| 850 |
|
850 |
}
|
| 851 |
}
|
851 |
return this.createFofoStoreCodeByRetailerId(retailer.getId(), districtName, stateName, updateRetailerRequest);
|
| 852 |
|
852 |
|
| 853 |
}
|
853 |
}
|
| 854 |
|
854 |
|
| 855 |
}
|
855 |
@Override
|
| 856 |
|
856 |
public List<DistrictMaster> getAllDistrictMaster(String stateName) {
|
| 857 |
PincodePartner pincodePartner = pincodePartnerRepository
|
857 |
// StateInfo stateInfo = null;
|
| 858 |
.selectPartnerByPincode(retailerAddress.getPinCode(), fofoStore.getId());
|
858 |
State stateInfo = null;
|
| 859 |
if (pincodePartner == null) {
|
859 |
try {
|
| 860 |
PincodePartner pinPartner = new PincodePartner();
|
860 |
// stateInfo = Utils.getStateInfo(stateName);
|
| 861 |
pinPartner.setFofoId(fofoStore.getId());
|
861 |
|
| 862 |
pinPartner.setPincode(retailerAddress.getPinCode());
|
862 |
stateInfo = stateRepository.selectByName(stateName);
|
| 863 |
pincodePartnerRepository.perist(pinPartner);
|
863 |
} catch (Exception e) {
|
| 864 |
}
|
864 |
e.printStackTrace();
|
| 865 |
}
|
865 |
// throw new ProfitMandiBusinessException();
|
| 866 |
|
866 |
}
|
| 867 |
return fofoStore;
|
867 |
return districtMasterRepository.selectByStateShortName(stateInfo.getShortName());
|
| 868 |
}
|
868 |
}
|
| 869 |
|
869 |
|
| 870 |
@Override
|
870 |
@Override
|
| 871 |
public FofoStore createFofoStoreCodeByUserId(int userId, String districtName, String stateName,
|
871 |
public Map<Integer, CustomRetailer> getFofoRetailers(List<Integer> fofoIds) {
|
| 872 |
UpdateRetailerRequest updateRetailerRequest) throws ProfitMandiBusinessException {
|
872 |
List<com.spice.profitmandi.dao.entity.user.User> saholicUsers = userUserRepository.selectByIds(fofoIds);
|
| 873 |
User user = userRepository.selectById(userId);
|
873 |
Map<Integer, com.spice.profitmandi.dao.entity.user.User> userAddressMap = saholicUsers.stream().filter(x -> x.getAddressId() != null).collect(Collectors.toMap(x -> x.getAddressId(), x -> x));
|
| 874 |
// = userAccountRepository.selectRetailerIdByUserId(user.getId());
|
874 |
List<Address> addresses = addressRepository.selectByIds(new ArrayList<>(userAddressMap.keySet()));
|
| 875 |
UserAccount userAccounts = userAccountRepository.selectSaholicByUserId(user.getId());
|
875 |
Map<Integer, CustomRetailer> customRetailersMap = new HashMap<>();
|
| 876 |
Retailer retailer = retailerRepository.selectById(userAccounts.getAccountKey());
|
876 |
for (Address address : addresses) {
|
| 877 |
Role roleFofo = roleRepository.selectByName(RoleType.FOFO.toString());
|
877 |
com.spice.profitmandi.dao.entity.user.User user = userAddressMap.get(address.getId());
|
| 878 |
try {
|
878 |
CustomRetailer customRetailer = new CustomRetailer();
|
| 879 |
userRoleRepository.selectByUserIdAndRoleId(user.getId(), roleFofo.getId());
|
879 |
customRetailer.setEmail(user.getEmailId());
|
| 880 |
} catch (ProfitMandiBusinessException profitMandiBusinessException) {
|
880 |
customRetailer.setBusinessName(address.getName());
|
| 881 |
throw new ProfitMandiBusinessException(ProfitMandiConstants.USER_ID, user.getId(), "USR_1013");
|
881 |
customRetailer.setMobileNumber(address.getPhoneNumber());
|
| 882 |
}
|
882 |
try {
|
| 883 |
return this.createFofoStoreCodeByRetailerId(retailer.getId(), districtName, stateName, updateRetailerRequest);
|
883 |
FofoStore fs = fofoStoreRepository.selectByRetailerId(address.getRetaierId());
|
| 884 |
|
884 |
customRetailer.setCode(fs.getCode());
|
| 885 |
}
|
885 |
customRetailer.setActivationType(fs.getActivationType());
|
| 886 |
|
886 |
customRetailer.setCounterSize(fs.getCounterSize());
|
| 887 |
@Override
|
887 |
|
| 888 |
public List<DistrictMaster> getAllDistrictMaster(String stateName) {
|
888 |
customRetailer.setWarehouseId(fs.getWarehouseId());
|
| 889 |
// StateInfo stateInfo = null;
|
889 |
customRetailer.setPartnerId(fs.getId());
|
| 890 |
State stateInfo = null;
|
890 |
customRetailer.setFofoType(fs.getFofoType());
|
| 891 |
try {
|
891 |
} catch (Exception e) {
|
| 892 |
// stateInfo = Utils.getStateInfo(stateName);
|
892 |
continue;
|
| 893 |
|
893 |
}
|
| 894 |
stateInfo = stateRepository.selectByName(stateName);
|
894 |
try {
|
| 895 |
} catch (Exception e) {
|
895 |
customRetailer.setCartId(user.getActiveCartId());
|
| 896 |
e.printStackTrace();
|
896 |
PrivateDealUser pdu = privateDealUserRepository.selectById(address.getRetaierId());
|
| 897 |
// throw new ProfitMandiBusinessException();
|
897 |
Counter counter = counterRepository.selectById(pdu.getCounterId());
|
| 898 |
}
|
898 |
customRetailer.setGstNumber(counter.getGstin());
|
| 899 |
return districtMasterRepository.selectByStateShortName(stateInfo.getShortName());
|
899 |
} catch (Exception e) {
|
| 900 |
}
|
900 |
customRetailer.setGstNumber(null);
|
| 901 |
|
901 |
}
|
| 902 |
@Override
|
902 |
CustomAddress address1 = new CustomAddress();
|
| 903 |
public Map<Integer, CustomRetailer> getFofoRetailers(List<Integer> fofoIds) {
|
903 |
address1.setCity(address.getCity());
|
| 904 |
List<com.spice.profitmandi.dao.entity.user.User> saholicUsers = userUserRepository.selectByIds(fofoIds);
|
904 |
address1.setState(address.getState());
|
| 905 |
Map<Integer, com.spice.profitmandi.dao.entity.user.User> userAddressMap = saholicUsers.stream()
|
905 |
address1.setLine1(address.getLine1());
|
| 906 |
.filter(x -> x.getAddressId() != null).collect(Collectors.toMap(x -> x.getAddressId(), x -> x));
|
906 |
address1.setLine2(address.getLine2());
|
| 907 |
List<Address> addresses = addressRepository.selectByIds(new ArrayList<>(userAddressMap.keySet()));
|
907 |
address1.setPinCode(address.getPinCode());
|
| 908 |
Map<Integer, CustomRetailer> customRetailersMap = new HashMap<>();
|
908 |
address1.setName(address.getName());
|
| 909 |
for (Address address : addresses) {
|
909 |
customRetailer.setAddress(address1);
|
| 910 |
com.spice.profitmandi.dao.entity.user.User user = userAddressMap.get(address.getId());
|
910 |
customRetailer.setDisplayName(
|
| 911 |
CustomRetailer customRetailer = new CustomRetailer();
|
911 |
customRetailer.getBusinessName() + "-" + customRetailer.getCode() + "- " + address1.getCity());
|
| 912 |
customRetailer.setEmail(user.getEmailId());
|
912 |
customRetailersMap.put(customRetailer.getPartnerId(), customRetailer);
|
| 913 |
customRetailer.setBusinessName(address.getName());
|
913 |
}
|
| 914 |
customRetailer.setMobileNumber(address.getPhoneNumber());
|
914 |
return customRetailersMap;
|
| 915 |
try {
|
915 |
}
|
| 916 |
FofoStore fs = fofoStoreRepository.selectByRetailerId(address.getRetaierId());
|
916 |
|
| 917 |
customRetailer.setCode(fs.getCode());
|
917 |
@Override
|
| 918 |
customRetailer.setActivationType(fs.getActivationType());
|
918 |
@Cacheable(value = "getFofoRetailer", cacheManager = "thirtyMinsTimeOutCacheManager")
|
| 919 |
customRetailer.setCounterSize(fs.getCounterSize());
|
919 |
public CustomRetailer getFofoRetailer(int fofoId) throws ProfitMandiBusinessException {
|
| 920 |
|
920 |
com.spice.profitmandi.dao.entity.user.User saholicUser = userUserRepository.selectById(fofoId);
|
| 921 |
customRetailer.setWarehouseId(fs.getWarehouseId());
|
921 |
FofoStore store = fofoStoreRepository.selectByRetailerId(fofoId);
|
| 922 |
customRetailer.setPartnerId(fs.getId());
|
922 |
Address address = null;
|
| 923 |
customRetailer.setFofoType(fs.getFofoType());
|
923 |
try {
|
| 924 |
} catch (Exception e) {
|
924 |
address = addressRepository.selectById(saholicUser.getAddressId());
|
| 925 |
continue;
|
925 |
} catch (ProfitMandiBusinessException e1) {
|
| 926 |
}
|
926 |
// TODO Auto-generated catch block
|
| 927 |
try {
|
927 |
e1.printStackTrace();
|
| 928 |
customRetailer.setCartId(user.getActiveCartId());
|
928 |
}
|
| 929 |
PrivateDealUser pdu = privateDealUserRepository.selectById(address.getRetaierId());
|
929 |
Map<Integer, CustomRetailer> customRetailersMap = new HashMap<>();
|
| 930 |
Counter counter = counterRepository.selectById(pdu.getCounterId());
|
930 |
CustomRetailer customRetailer = new CustomRetailer();
|
| 931 |
customRetailer.setGstNumber(counter.getGstin());
|
931 |
customRetailer.setEmail(saholicUser.getEmailId());
|
| 932 |
} catch (Exception e) {
|
932 |
customRetailer.setBusinessName(address.getName());
|
| 933 |
customRetailer.setGstNumber(null);
|
933 |
customRetailer.setMobileNumber(address.getPhoneNumber());
|
| 934 |
}
|
934 |
try {
|
| 935 |
CustomAddress address1 = new CustomAddress();
|
935 |
customRetailer.setCartId(saholicUser.getActiveCartId());
|
| 936 |
address1.setCity(address.getCity());
|
936 |
PrivateDealUser pdu = privateDealUserRepository.selectById(address.getRetaierId());
|
| 937 |
address1.setState(address.getState());
|
937 |
Counter counter = counterRepository.selectById(pdu.getCounterId());
|
| 938 |
address1.setLine1(address.getLine1());
|
938 |
customRetailer.setGstNumber(counter.getGstin());
|
| 939 |
address1.setLine2(address.getLine2());
|
939 |
} catch (Exception e) {
|
| 940 |
address1.setPinCode(address.getPinCode());
|
940 |
customRetailer.setGstNumber(null);
|
| 941 |
address1.setName(address.getName());
|
941 |
}
|
| 942 |
customRetailer.setAddress(address1);
|
942 |
CustomAddress address1 = new CustomAddress();
|
| 943 |
customRetailer.setDisplayName(
|
943 |
address1.setCity(address.getCity());
|
| 944 |
customRetailer.getBusinessName() + "-" + customRetailer.getCode() + "- " + address1.getCity());
|
944 |
address1.setState(address.getState());
|
| 945 |
customRetailersMap.put(customRetailer.getPartnerId(), customRetailer);
|
945 |
address1.setLine1(address.getLine1());
|
| 946 |
}
|
946 |
address1.setLine2(address.getLine2());
|
| 947 |
return customRetailersMap;
|
947 |
address1.setPinCode(address.getPinCode());
|
| 948 |
}
|
948 |
address1.setPhoneNumber(address.getPhoneNumber());
|
| 949 |
|
949 |
address1.setName(address.getName());
|
| 950 |
@Override
|
950 |
customRetailer.setDisplayName(address.getName() + " - " + address.getCity());
|
| 951 |
@Cacheable(value = "getFofoRetailer", cacheManager = "thirtyMinsTimeOutCacheManager")
|
951 |
customRetailer.setAddress(address1);
|
| 952 |
public CustomRetailer getFofoRetailer(int fofoId) throws ProfitMandiBusinessException {
|
952 |
customRetailer.setPartnerId(address.getRetaierId());
|
| 953 |
com.spice.profitmandi.dao.entity.user.User saholicUser = userUserRepository.selectById(fofoId);
|
953 |
customRetailer.setCode(store.getCode());
|
| 954 |
FofoStore store = fofoStoreRepository.selectByRetailerId(fofoId);
|
954 |
customRetailer.setActivationType(store.getActivationType());
|
| 955 |
Address address = null;
|
955 |
customRetailer.setWarehouseId(store.getWarehouseId());
|
| 956 |
try {
|
956 |
customRetailersMap.put(address.getRetaierId(), customRetailer);
|
| 957 |
address = addressRepository.selectById(saholicUser.getAddressId());
|
957 |
return customRetailer;
|
| 958 |
} catch (ProfitMandiBusinessException e1) {
|
958 |
|
| 959 |
// TODO Auto-generated catch block
|
959 |
}
|
| 960 |
e1.printStackTrace();
|
960 |
|
| 961 |
}
|
961 |
@Override
|
| 962 |
Map<Integer, CustomRetailer> customRetailersMap = new HashMap<>();
|
962 |
public Map<Integer, CustomRetailer> getFofoRetailerUserId(List<Integer> fofoIds) {
|
| 963 |
CustomRetailer customRetailer = new CustomRetailer();
|
963 |
List<com.spice.profitmandi.dao.entity.user.User> saholicUsers = userUserRepository.selectByIds(fofoIds);
|
| 964 |
customRetailer.setEmail(saholicUser.getEmailId());
|
964 |
Map<Integer, com.spice.profitmandi.dao.entity.user.User> userAddressMap = saholicUsers.stream().filter(x -> x.getAddressId() != null).collect(Collectors.toMap(x -> x.getAddressId(), x -> x));
|
| 965 |
customRetailer.setBusinessName(address.getName());
|
965 |
List<Address> addresses = addressRepository.selectByIds(new ArrayList<>(userAddressMap.keySet()));
|
| 966 |
customRetailer.setMobileNumber(address.getPhoneNumber());
|
966 |
Map<Integer, CustomRetailer> customRetailersMap = new HashMap<>();
|
| 967 |
try {
|
967 |
for (Address address : addresses) {
|
| 968 |
customRetailer.setCartId(saholicUser.getActiveCartId());
|
968 |
com.spice.profitmandi.dao.entity.user.User user = userAddressMap.get(address.getId());
|
| 969 |
PrivateDealUser pdu = privateDealUserRepository.selectById(address.getRetaierId());
|
969 |
CustomRetailer customRetailer = new CustomRetailer();
|
| 970 |
Counter counter = counterRepository.selectById(pdu.getCounterId());
|
970 |
customRetailer.setEmail(user.getEmailId());
|
| 971 |
customRetailer.setGstNumber(counter.getGstin());
|
971 |
customRetailer.setBusinessName(address.getName());
|
| 972 |
} catch (Exception e) {
|
972 |
customRetailer.setMobileNumber(address.getPhoneNumber());
|
| 973 |
customRetailer.setGstNumber(null);
|
973 |
int userId = 0;
|
| 974 |
}
|
974 |
try {
|
| 975 |
CustomAddress address1 = new CustomAddress();
|
975 |
userId = userAccountRepository.selectUserIdByRetailerId(user.getId());
|
| 976 |
address1.setCity(address.getCity());
|
976 |
} catch (ProfitMandiBusinessException e) {
|
| 977 |
address1.setState(address.getState());
|
977 |
continue;
|
| 978 |
address1.setLine1(address.getLine1());
|
978 |
}
|
| 979 |
address1.setLine2(address.getLine2());
|
979 |
try {
|
| 980 |
address1.setPinCode(address.getPinCode());
|
980 |
customRetailer.setCartId(user.getActiveCartId());
|
| 981 |
address1.setPhoneNumber(address.getPhoneNumber());
|
981 |
PrivateDealUser pdu = privateDealUserRepository.selectById(address.getRetaierId());
|
| 982 |
address1.setName(address.getName());
|
982 |
Counter counter = counterRepository.selectById(pdu.getCounterId());
|
| 983 |
customRetailer.setDisplayName(address.getName() + " - " + address.getCity());
|
983 |
customRetailer.setGstNumber(counter.getGstin());
|
| 984 |
customRetailer.setAddress(address1);
|
984 |
} catch (Exception e) {
|
| 985 |
customRetailer.setPartnerId(address.getRetaierId());
|
985 |
customRetailer.setGstNumber(null);
|
| 986 |
customRetailer.setCode(store.getCode());
|
986 |
}
|
| 987 |
customRetailer.setActivationType(store.getActivationType());
|
987 |
CustomAddress address1 = new CustomAddress();
|
| 988 |
customRetailer.setWarehouseId(store.getWarehouseId());
|
988 |
address1.setCity(address.getCity());
|
| 989 |
customRetailersMap.put(address.getRetaierId(), customRetailer);
|
989 |
address1.setState(address.getState());
|
| 990 |
return customRetailer;
|
990 |
address1.setLine1(address.getLine1());
|
| 991 |
|
991 |
address1.setLine2(address.getLine2());
|
| 992 |
}
|
992 |
address1.setPinCode(address.getPinCode());
|
| 993 |
|
993 |
address1.setName(address.getName());
|
| 994 |
@Override
|
994 |
customRetailer.setAddress(address1);
|
| 995 |
public Map<Integer, CustomRetailer> getFofoRetailerUserId(List<Integer> fofoIds) {
|
995 |
customRetailer.setPartnerId(address.getRetaierId());
|
| 996 |
List<com.spice.profitmandi.dao.entity.user.User> saholicUsers = userUserRepository.selectByIds(fofoIds);
|
996 |
customRetailer.setDisplayName(customRetailer.getBusinessName() + "-" + address1.getCity());
|
| 997 |
Map<Integer, com.spice.profitmandi.dao.entity.user.User> userAddressMap = saholicUsers.stream()
|
997 |
customRetailersMap.put(userId, customRetailer);
|
| 998 |
.filter(x -> x.getAddressId() != null).collect(Collectors.toMap(x -> x.getAddressId(), x -> x));
|
998 |
}
|
| 999 |
List<Address> addresses = addressRepository.selectByIds(new ArrayList<>(userAddressMap.keySet()));
|
999 |
return customRetailersMap;
|
| 1000 |
Map<Integer, CustomRetailer> customRetailersMap = new HashMap<>();
|
1000 |
}
|
| 1001 |
for (Address address : addresses) {
|
1001 |
|
| 1002 |
com.spice.profitmandi.dao.entity.user.User user = userAddressMap.get(address.getId());
|
1002 |
@Override
|
| 1003 |
CustomRetailer customRetailer = new CustomRetailer();
|
1003 |
public Map<Integer, String> getAllFofoRetailerIdEmailIdMap() {
|
| 1004 |
customRetailer.setEmail(user.getEmailId());
|
1004 |
Role roleFofo = null;
|
| 1005 |
customRetailer.setBusinessName(address.getName());
|
1005 |
try {
|
| 1006 |
customRetailer.setMobileNumber(address.getPhoneNumber());
|
1006 |
roleFofo = roleRepository.selectByName(RoleType.FOFO.toString());
|
| 1007 |
int userId = 0;
|
1007 |
} catch (ProfitMandiBusinessException e) {
|
| 1008 |
try {
|
1008 |
// TODO Auto-generated catch block
|
| 1009 |
userId = userAccountRepository.selectUserIdByRetailerId(user.getId());
|
1009 |
e.printStackTrace();
|
| 1010 |
} catch (ProfitMandiBusinessException e) {
|
1010 |
}
|
| 1011 |
continue;
|
1011 |
Role roleRetailer = null;
|
| 1012 |
}
|
1012 |
try {
|
| 1013 |
try {
|
1013 |
roleRetailer = roleRepository.selectByName(RoleType.RETAILER.toString());
|
| 1014 |
customRetailer.setCartId(user.getActiveCartId());
|
1014 |
} catch (ProfitMandiBusinessException e) {
|
| 1015 |
PrivateDealUser pdu = privateDealUserRepository.selectById(address.getRetaierId());
|
1015 |
// TODO Auto-generated catch block
|
| 1016 |
Counter counter = counterRepository.selectById(pdu.getCounterId());
|
1016 |
e.printStackTrace();
|
| 1017 |
customRetailer.setGstNumber(counter.getGstin());
|
1017 |
}
|
| 1018 |
} catch (Exception e) {
|
1018 |
Set<Integer> roleIds = new HashSet<>();
|
| 1019 |
customRetailer.setGstNumber(null);
|
1019 |
roleIds.add(roleFofo.getId());
|
| 1020 |
}
|
1020 |
roleIds.add(roleRetailer.getId());
|
| 1021 |
CustomAddress address1 = new CustomAddress();
|
1021 |
List<Integer> userIds = userRoleRepository.selectUserIdsByRoleIds(roleIds);
|
| 1022 |
address1.setCity(address.getCity());
|
1022 |
List<User> users = userRepository.selectAllByIds(new HashSet<>(userIds));
|
| 1023 |
address1.setState(address.getState());
|
1023 |
Map<Integer, Integer> userIdRetailerIdMap = this.getUserIdRetailerIdMap(userIds);
|
| 1024 |
address1.setLine1(address.getLine1());
|
1024 |
Map<Integer, String> retailerIdEmailIdMap = new HashMap<>();
|
| 1025 |
address1.setLine2(address.getLine2());
|
1025 |
for (User user : users) {
|
| 1026 |
address1.setPinCode(address.getPinCode());
|
1026 |
retailerIdEmailIdMap.put(userIdRetailerIdMap.get(user.getId()), user.getEmailId());
|
| 1027 |
address1.setName(address.getName());
|
1027 |
}
|
| 1028 |
customRetailer.setAddress(address1);
|
1028 |
return retailerIdEmailIdMap;
|
| 1029 |
customRetailer.setPartnerId(address.getRetaierId());
|
1029 |
}
|
| 1030 |
customRetailer.setDisplayName(customRetailer.getBusinessName() + "-" + address1.getCity());
|
1030 |
|
| 1031 |
customRetailersMap.put(userId, customRetailer);
|
1031 |
private Map<Integer, Integer> getUserIdRetailerIdMap(List<Integer> userIds) {
|
| 1032 |
}
|
1032 |
List<UserAccount> userAccounts = userAccountRepository.selectAllSaholicByUserIds(new HashSet<>(userIds));
|
| 1033 |
return customRetailersMap;
|
1033 |
Map<Integer, Integer> userIdRetailerIdMap = new HashMap<>();
|
| 1034 |
}
|
1034 |
for (UserAccount userAccount : userAccounts) {
|
| 1035 |
|
1035 |
userIdRetailerIdMap.put(userAccount.getUserId(), userAccount.getAccountKey());
|
| 1036 |
@Override
|
1036 |
}
|
| 1037 |
public Map<Integer, String> getAllFofoRetailerIdEmailIdMap() {
|
1037 |
return userIdRetailerIdMap;
|
| 1038 |
Role roleFofo = null;
|
1038 |
}
|
| 1039 |
try {
|
1039 |
|
| 1040 |
roleFofo = roleRepository.selectByName(RoleType.FOFO.toString());
|
1040 |
private Map<Integer, String> getUserIdEmailIdMap(Set<Integer> userIds) {
|
| 1041 |
} catch (ProfitMandiBusinessException e) {
|
1041 |
List<User> users = userRepository.selectAllByIds(userIds);
|
| 1042 |
// TODO Auto-generated catch block
|
1042 |
Map<Integer, String> userIdEmailIdMap = new HashMap<>();
|
| 1043 |
e.printStackTrace();
|
1043 |
for (User user : users) {
|
| 1044 |
}
|
1044 |
userIdEmailIdMap.put(user.getId(), user.getEmailId());
|
| 1045 |
Role roleRetailer = null;
|
1045 |
}
|
| 1046 |
try {
|
1046 |
return userIdEmailIdMap;
|
| 1047 |
roleRetailer = roleRepository.selectByName(RoleType.RETAILER.toString());
|
1047 |
}
|
| 1048 |
} catch (ProfitMandiBusinessException e) {
|
1048 |
|
| 1049 |
// TODO Auto-generated catch block
|
1049 |
@Override
|
| 1050 |
e.printStackTrace();
|
1050 |
public Map<Integer, String> getAllFofoRetailerIdEmailIdMap(Set<Integer> retailerIds) {
|
| 1051 |
}
|
1051 |
List<UserAccount> userAccounts = userAccountRepository.selectAllSaholicByRetailerIds(retailerIds);
|
| 1052 |
Set<Integer> roleIds = new HashSet<>();
|
1052 |
Set<Integer> userIds = new HashSet<>();
|
| 1053 |
roleIds.add(roleFofo.getId());
|
1053 |
for (UserAccount userAccount : userAccounts) {
|
| 1054 |
roleIds.add(roleRetailer.getId());
|
1054 |
userIds.add(userAccount.getUserId());
|
| 1055 |
List<Integer> userIds = userRoleRepository.selectUserIdsByRoleIds(roleIds);
|
1055 |
}
|
| 1056 |
List<User> users = userRepository.selectAllByIds(new HashSet<>(userIds));
|
1056 |
Map<Integer, String> retailerIdEmailIdMap = new HashMap<>();
|
| 1057 |
Map<Integer, Integer> userIdRetailerIdMap = this.getUserIdRetailerIdMap(userIds);
|
1057 |
Map<Integer, String> userIdEmailIdMap = this.getUserIdEmailIdMap(userIds);
|
| 1058 |
Map<Integer, String> retailerIdEmailIdMap = new HashMap<>();
|
1058 |
for (UserAccount userAccount : userAccounts) {
|
| 1059 |
for (User user : users) {
|
1059 |
retailerIdEmailIdMap.put(userAccount.getAccountKey(), userIdEmailIdMap.get(userAccount.getUserId()));
|
| 1060 |
retailerIdEmailIdMap.put(userIdRetailerIdMap.get(user.getId()), user.getEmailId());
|
1060 |
}
|
| 1061 |
}
|
1061 |
return retailerIdEmailIdMap;
|
| 1062 |
return retailerIdEmailIdMap;
|
1062 |
}
|
| 1063 |
}
|
1063 |
|
| 1064 |
|
1064 |
@Override
|
| 1065 |
private Map<Integer, Integer> getUserIdRetailerIdMap(List<Integer> userIds) {
|
1065 |
public Map<Integer, String> getAllFofoRetailerIdNameMap(List<Integer> storeIds) {
|
| 1066 |
List<UserAccount> userAccounts = userAccountRepository.selectAllSaholicByUserIds(new HashSet<>(userIds));
|
1066 |
Map<Integer, CustomRetailer> retailersMap = this.getFofoRetailers(storeIds);
|
| 1067 |
Map<Integer, Integer> userIdRetailerIdMap = new HashMap<>();
|
1067 |
Map<Integer, String> retailerIdNameMap = new HashMap<>();
|
| 1068 |
for (UserAccount userAccount : userAccounts) {
|
1068 |
for (Map.Entry<Integer, CustomRetailer> entry : retailersMap.entrySet()) {
|
| 1069 |
userIdRetailerIdMap.put(userAccount.getUserId(), userAccount.getAccountKey());
|
1069 |
retailerIdNameMap.put(entry.getKey(), entry.getValue().getBusinessName() + "-" + entry.getValue().getAddress().getCity());
|
| 1070 |
}
|
1070 |
}
|
| 1071 |
return userIdRetailerIdMap;
|
1071 |
return retailerIdNameMap;
|
| 1072 |
}
|
1072 |
}
|
| 1073 |
|
1073 |
|
| 1074 |
private Map<Integer, String> getUserIdEmailIdMap(Set<Integer> userIds) {
|
1074 |
@Override
|
| 1075 |
List<User> users = userRepository.selectAllByIds(userIds);
|
1075 |
@Cacheable(value = "FofoRetailerIdNameMap", cacheManager = "thirtyMinsTimeOutCacheManager")
|
| 1076 |
Map<Integer, String> userIdEmailIdMap = new HashMap<>();
|
1076 |
public Map<Integer, String> getAllFofoRetailerIdNameMap() {
|
| 1077 |
for (User user : users) {
|
1077 |
List<FofoStore> stores = fofoStoreRepository.selectAll();
|
| 1078 |
userIdEmailIdMap.put(user.getId(), user.getEmailId());
|
1078 |
List<Integer> storeIds = stores.stream().map(x -> x.getId()).collect(Collectors.toList());
|
| 1079 |
}
|
1079 |
return this.getAllFofoRetailerIdNameMap(storeIds);
|
| 1080 |
return userIdEmailIdMap;
|
1080 |
}
|
| 1081 |
}
|
1081 |
|
| 1082 |
|
1082 |
@Override
|
| 1083 |
@Override
|
1083 |
public List<MapWrapper<Integer, String>> getAllFofoRetailerIdNameList() {
|
| 1084 |
public Map<Integer, String> getAllFofoRetailerIdEmailIdMap(Set<Integer> retailerIds) {
|
1084 |
List<MapWrapper<Integer, String>> mapWrappers = new ArrayList<>();
|
| 1085 |
List<UserAccount> userAccounts = userAccountRepository.selectAllSaholicByRetailerIds(retailerIds);
|
1085 |
// TODO Auto-generated method stub
|
| 1086 |
Set<Integer> userIds = new HashSet<>();
|
1086 |
Map<Integer, String> fofoIdNameMap = this.getAllFofoRetailerIdNameMap();
|
| 1087 |
for (UserAccount userAccount : userAccounts) {
|
1087 |
fofoIdNameMap.forEach((fofoId, name) -> {
|
| 1088 |
userIds.add(userAccount.getUserId());
|
1088 |
MapWrapper<Integer, String> idWrapper = new MapWrapper<>();
|
| 1089 |
}
|
1089 |
idWrapper.setKey(fofoId);
|
| 1090 |
Map<Integer, String> retailerIdEmailIdMap = new HashMap<>();
|
1090 |
idWrapper.setValue(name);
|
| 1091 |
Map<Integer, String> userIdEmailIdMap = this.getUserIdEmailIdMap(userIds);
|
1091 |
mapWrappers.add(idWrapper);
|
| 1092 |
for (UserAccount userAccount : userAccounts) {
|
1092 |
});
|
| 1093 |
retailerIdEmailIdMap.put(userAccount.getAccountKey(), userIdEmailIdMap.get(userAccount.getUserId()));
|
1093 |
return mapWrappers;
|
| 1094 |
}
|
1094 |
}
|
| 1095 |
return retailerIdEmailIdMap;
|
1095 |
|
| 1096 |
}
|
1096 |
@Override
|
| 1097 |
|
1097 |
@Cacheable(value = "retailerNames", cacheManager = "thirtyMinsTimeOutCacheManager")
|
| 1098 |
@Override
|
1098 |
public Map<Integer, CustomRetailer> getFofoRetailers(boolean activeOnly) {
|
| 1099 |
public Map<Integer, String> getAllFofoRetailerIdNameMap(List<Integer> storeIds) {
|
1099 |
// TODO Auto-generated method stub
|
| 1100 |
Map<Integer, CustomRetailer> retailersMap = this.getFofoRetailers(storeIds);
|
1100 |
Stream<FofoStore> storeStream = fofoStoreRepository.selectAll().stream().filter(x -> !x.isInternal());
|
| 1101 |
Map<Integer, String> retailerIdNameMap = new HashMap<>();
|
1101 |
if (activeOnly) {
|
| 1102 |
for (Map.Entry<Integer, CustomRetailer> entry : retailersMap.entrySet()) {
|
1102 |
storeStream = storeStream.filter(x -> x.isActive());
|
| 1103 |
retailerIdNameMap.put(entry.getKey(),
|
1103 |
}
|
| 1104 |
entry.getValue().getBusinessName() + "-" + entry.getValue().getAddress().getCity());
|
1104 |
List<Integer> storeIds = storeStream.map(x -> x.getId()).collect(Collectors.toList());
|
| 1105 |
}
|
1105 |
return this.getFofoRetailers(storeIds);
|
| 1106 |
return retailerIdNameMap;
|
1106 |
}
|
| 1107 |
}
|
1107 |
|
| 1108 |
|
1108 |
@Override
|
| 1109 |
@Override
|
1109 |
@Cacheable(value = "allFofoRetailers", cacheManager = "thirtyMinsTimeOutCacheManager")
|
| 1110 |
@Cacheable(value = "FofoRetailerIdNameMap", cacheManager = "thirtyMinsTimeOutCacheManager")
|
1110 |
public Map<Integer, CustomRetailer> getAllFofoRetailers() {
|
| 1111 |
public Map<Integer, String> getAllFofoRetailerIdNameMap() {
|
1111 |
// TODO Auto-generated method stub
|
| 1112 |
List<FofoStore> stores = fofoStoreRepository.selectAll();
|
1112 |
Stream<FofoStore> storeStream = fofoStoreRepository.selectAll().stream();
|
| 1113 |
List<Integer> storeIds = stores.stream().map(x -> x.getId()).collect(Collectors.toList());
|
1113 |
|
| 1114 |
return this.getAllFofoRetailerIdNameMap(storeIds);
|
1114 |
List<Integer> storeIds = storeStream.map(x -> x.getId()).collect(Collectors.toList());
|
| 1115 |
}
|
1115 |
return this.getFofoRetailers(storeIds);
|
| 1116 |
|
1116 |
}
|
| 1117 |
@Override
|
1117 |
|
| 1118 |
public List<MapWrapper<Integer, String>> getAllFofoRetailerIdNameList() {
|
1118 |
@Override
|
| 1119 |
List<MapWrapper<Integer, String>> mapWrappers = new ArrayList<>();
|
1119 |
public LoginRequestResponseModel registerWebUser(LoginRequestResponseModel loginRequestModel) throws ProfitMandiBusinessException {
|
| 1120 |
// TODO Auto-generated method stub
|
1120 |
|
| 1121 |
Map<Integer, String> fofoIdNameMap = this.getAllFofoRetailerIdNameMap();
|
1121 |
com.spice.profitmandi.dao.entity.user.User saholicUser = this.createSaholicUser(loginRequestModel);
|
| 1122 |
fofoIdNameMap.forEach((fofoId, name) -> {
|
1122 |
loginRequestModel.setUserId(saholicUser.getId());
|
| 1123 |
MapWrapper<Integer, String> idWrapper = new MapWrapper<>();
|
1123 |
|
| 1124 |
idWrapper.setKey(fofoId);
|
1124 |
this.createRetailerAddress(loginRequestModel);
|
| 1125 |
idWrapper.setValue(name);
|
1125 |
|
| 1126 |
mapWrappers.add(idWrapper);
|
1126 |
this.createPrivateDealUser(loginRequestModel);
|
| 1127 |
});
|
1127 |
this.updateSaholicUser(saholicUser.getId(), loginRequestModel.getBusinessAddress().getId());
|
| 1128 |
return mapWrappers;
|
1128 |
|
| 1129 |
}
|
1129 |
return loginRequestModel;
|
| 1130 |
|
1130 |
|
| 1131 |
@Override
|
1131 |
}
|
| 1132 |
@Cacheable(value = "retailerNames", cacheManager = "thirtyMinsTimeOutCacheManager")
|
1132 |
|
| 1133 |
public Map<Integer, CustomRetailer> getFofoRetailers(boolean activeOnly) {
|
1133 |
private void createPrivateDealUser(LoginRequestResponseModel loginRequestModel) {
|
| 1134 |
// TODO Auto-generated method stub
|
1134 |
|
| 1135 |
Stream<FofoStore> storeStream = fofoStoreRepository.selectAll().stream().filter(x -> !x.isInternal());
|
1135 |
Integer counterId = this.createCounter(loginRequestModel.getEmail(), loginRequestModel.getGstNumber(), loginRequestModel.getBusinessAddress().getPhoneNumber(), loginRequestModel.getBusinessAddress().getName(), loginRequestModel.getBusinessAddress().getId());
|
| 1136 |
if (activeOnly) {
|
1136 |
try {
|
| 1137 |
storeStream = storeStream.filter(x -> x.isActive());
|
1137 |
this.createPrivateDealUser(loginRequestModel.getUserId(), counterId, false);
|
| 1138 |
}
|
1138 |
} catch (Exception e) {
|
| 1139 |
List<Integer> storeIds = storeStream.map(x -> x.getId()).collect(Collectors.toList());
|
1139 |
LOGGER.error("ERROR : ", e);
|
| 1140 |
return this.getFofoRetailers(storeIds);
|
1140 |
}
|
| 1141 |
}
|
1141 |
|
| 1142 |
|
1142 |
PrivateDealUserAddressMapping privateDealUserAddressMapping = new PrivateDealUserAddressMapping();
|
| 1143 |
@Override
|
1143 |
privateDealUserAddressMapping.setUserId(loginRequestModel.getUserId());
|
| 1144 |
@Cacheable(value = "allFofoRetailers", cacheManager = "thirtyMinsTimeOutCacheManager")
|
1144 |
privateDealUserAddressMapping.setAddressId(loginRequestModel.getBusinessAddress().getId());
|
| 1145 |
public Map<Integer, CustomRetailer> getAllFofoRetailers() {
|
1145 |
privateDealUserAddressMappingRepository.persist(privateDealUserAddressMapping);
|
| 1146 |
// TODO Auto-generated method stub
|
1146 |
|
| 1147 |
Stream<FofoStore> storeStream = fofoStoreRepository.selectAll().stream();
|
1147 |
}
|
| 1148 |
|
1148 |
|
| 1149 |
List<Integer> storeIds = storeStream.map(x -> x.getId()).collect(Collectors.toList());
|
1149 |
private void createRetailerAddress(LoginRequestResponseModel loginRequestResponseModel) throws ProfitMandiBusinessException {
|
| 1150 |
return this.getFofoRetailers(storeIds);
|
1150 |
Address businessAddress = loginRequestResponseModel.getBusinessAddress();
|
| 1151 |
}
|
1151 |
businessAddress.setRetaierId(loginRequestResponseModel.getUserId());
|
| 1152 |
|
1152 |
addressRepository.persist(businessAddress);
|
| 1153 |
@Override
|
1153 |
}
|
| 1154 |
public LoginRequestResponseModel registerWebUser(LoginRequestResponseModel loginRequestModel)
|
1154 |
|
| 1155 |
throws ProfitMandiBusinessException {
|
1155 |
private String getHash256(String originalString) {
|
| 1156 |
|
1156 |
String hashString = Hashing.sha256().hashString(originalString, StandardCharsets.UTF_8).toString();
|
| 1157 |
com.spice.profitmandi.dao.entity.user.User saholicUser = this.createSaholicUser(loginRequestModel);
|
1157 |
LOGGER.info("Hash String {}", hashString);
|
| 1158 |
loginRequestModel.setUserId(saholicUser.getId());
|
1158 |
return hashString;
|
| 1159 |
|
1159 |
}
|
| 1160 |
this.createRetailerAddress(loginRequestModel);
|
1160 |
|
| 1161 |
|
1161 |
@Override
|
| 1162 |
this.createPrivateDealUser(loginRequestModel);
|
1162 |
@Cacheable(value = "fofoIdUrl", cacheManager = "thirtyMinsTimeOutCacheManager")
|
| 1163 |
this.updateSaholicUser(saholicUser.getId(), loginRequestModel.getBusinessAddress().getId());
|
1163 |
public Map<Integer, String> getAllFofoRetailerIdUrlMap() {
|
| 1164 |
|
1164 |
Map<Integer, String> fofoRetailerUrlMap = new HashMap<>();
|
| 1165 |
return loginRequestModel;
|
1165 |
List<FofoStore> stores = fofoStoreRepository.selectAll().stream().filter(x -> x.isActive()).collect(Collectors.toList());
|
| 1166 |
|
1166 |
Map<Integer, com.spice.profitmandi.dao.entity.user.User> userMap = userUserRepository.selectByIds(stores.stream().map(x -> x.getId()).collect(Collectors.toList())).stream().collect(Collectors.toMap(x -> x.getId(), x -> x));
|
| 1167 |
}
|
1167 |
for (FofoStore store : stores) {
|
| 1168 |
|
1168 |
LOGGER.info("Store is {}", store);
|
| 1169 |
private void createPrivateDealUser(LoginRequestResponseModel loginRequestModel) {
|
1169 |
String districtShortName = store.getCode().replaceAll("\\d+", "").substring(2);
|
| 1170 |
|
1170 |
String stateShortName = store.getCode().replaceAll("\\d+", "").substring(0, 2);
|
| 1171 |
Integer counterId = this.createCounter(loginRequestModel.getEmail(), loginRequestModel.getGstNumber(),
|
1171 |
DistrictMaster districtMaster = null;
|
| 1172 |
loginRequestModel.getBusinessAddress().getPhoneNumber(),
|
1172 |
LOGGER.info("Store shortname is {}", districtShortName);
|
| 1173 |
loginRequestModel.getBusinessAddress().getName(), loginRequestModel.getBusinessAddress().getId());
|
1173 |
districtMaster = districtMasterRepository.selectByShortnameNameAndStateShortName(districtShortName, stateShortName);
|
| 1174 |
try {
|
1174 |
if (districtMaster == null) {
|
| 1175 |
this.createPrivateDealUser(loginRequestModel.getUserId(), counterId, false);
|
1175 |
districtMaster = districtMasterRepository.selectByShortnameNameAndStateShortName("FB", "HR");
|
| 1176 |
} catch (Exception e) {
|
1176 |
}
|
| 1177 |
LOGGER.error("ERROR : ", e);
|
1177 |
LOGGER.info("Store id - {}", store.getId());
|
| 1178 |
}
|
1178 |
// com.spice.profitmandi.dao.entity.user.User user = userMap.get(store.getId());
|
| 1179 |
|
1179 |
String urlString = districtMaster.getStateShortName() + "/" + Utils.getHyphenatedString(districtMaster.getName()) + "/" + store.getCode();
|
| 1180 |
PrivateDealUserAddressMapping privateDealUserAddressMapping = new PrivateDealUserAddressMapping();
|
1180 |
fofoRetailerUrlMap.put(store.getId(), urlString.toLowerCase());
|
| 1181 |
privateDealUserAddressMapping.setUserId(loginRequestModel.getUserId());
|
1181 |
LOGGER.info("Store is {} end", store);
|
| 1182 |
privateDealUserAddressMapping.setAddressId(loginRequestModel.getBusinessAddress().getId());
|
1182 |
|
| 1183 |
privateDealUserAddressMappingRepository.persist(privateDealUserAddressMapping);
|
1183 |
}
|
| 1184 |
|
1184 |
return fofoRetailerUrlMap;
|
| 1185 |
}
|
1185 |
}
|
| 1186 |
|
1186 |
|
| 1187 |
private void createRetailerAddress(LoginRequestResponseModel loginRequestResponseModel)
|
1187 |
@Override
|
| 1188 |
throws ProfitMandiBusinessException {
|
1188 |
@Cacheable(value = "storeCodeRetailerMap", cacheManager = "thirtyMinsTimeOutCacheManager")
|
| 1189 |
Address businessAddress = loginRequestResponseModel.getBusinessAddress();
|
1189 |
public Map<String, Integer> getStoreCodeRetailerMap() {
|
| 1190 |
businessAddress.setRetaierId(loginRequestResponseModel.getUserId());
|
1190 |
Map<Integer, String> map = this.getAllFofoRetailerIdUrlMap();
|
| 1191 |
addressRepository.persist(businessAddress);
|
1191 |
Map<String, Integer> returnMap = map.entrySet().stream().collect(Collectors.toMap(x -> {
|
| 1192 |
}
|
1192 |
String[] splitString = x.getValue().split("/");
|
| 1193 |
|
1193 |
return splitString[splitString.length - 1];
|
| 1194 |
private String getHash256(String originalString) {
|
1194 |
}, x -> x.getKey()));
|
| 1195 |
String hashString = Hashing.sha256().hashString(originalString, StandardCharsets.UTF_8).toString();
|
1195 |
LOGGER.info("returnMap {}", returnMap);
|
| 1196 |
LOGGER.info("Hash String {}", hashString);
|
1196 |
return returnMap;
|
| 1197 |
return hashString;
|
1197 |
}
|
| 1198 |
}
|
1198 |
|
| 1199 |
|
1199 |
@Override
|
| 1200 |
@Override
|
1200 |
public String getPartnerCriteriaString(PartnerCriteria partnerCriteria) {
|
| 1201 |
@Cacheable(value = "fofoIdUrl", cacheManager = "thirtyMinsTimeOutCacheManager")
|
1201 |
|
| 1202 |
public Map<Integer, String> getAllFofoRetailerIdUrlMap() {
|
1202 |
StringBuilder sb = new StringBuilder();
|
| 1203 |
Map<Integer, String> fofoRetailerUrlMap = new HashMap<>();
|
1203 |
if (partnerCriteria.getFofoIds().size() > 0) {
|
| 1204 |
List<FofoStore> stores = fofoStoreRepository.selectAll().stream().filter(x -> x.isActive())
|
1204 |
List<Integer> fofoIds = partnerCriteria.getFofoIds();
|
| 1205 |
.collect(Collectors.toList());
|
1205 |
Map<Integer, CustomRetailer> customRetailers = this.getFofoRetailerUserId(fofoIds);
|
| 1206 |
Map<Integer, com.spice.profitmandi.dao.entity.user.User> userMap = userUserRepository
|
1206 |
List<String> businessNames = customRetailers.values().stream().map(x -> x.getBusinessName()).collect(Collectors.toList());
|
| 1207 |
.selectByIds(stores.stream().map(x -> x.getId()).collect(Collectors.toList())).stream()
|
1207 |
sb.append(String.join(", ", businessNames));
|
| 1208 |
.collect(Collectors.toMap(x -> x.getId(), x -> x));
|
1208 |
|
| 1209 |
for (FofoStore store : stores) {
|
1209 |
} else {
|
| 1210 |
LOGGER.info("Store is {}", store);
|
1210 |
sb.append("All");
|
| 1211 |
String districtShortName = store.getCode().replaceAll("\\d+", "").substring(2);
|
1211 |
if (partnerCriteria.getPartnerTypes().size() > 0) {
|
| 1212 |
String stateShortName = store.getCode().replaceAll("\\d+", "").substring(0, 2);
|
1212 |
sb.append(" ").append(String.join(", ", partnerCriteria.getPartnerTypes().stream().map(x -> x.getValue()).collect(Collectors.toList())));
|
| 1213 |
DistrictMaster districtMaster = null;
|
1213 |
}
|
| 1214 |
LOGGER.info("Store shortname is {}", districtShortName);
|
1214 |
sb.append(" partners ");
|
| 1215 |
districtMaster = districtMasterRepository.selectByShortnameNameAndStateShortName(districtShortName,
|
1215 |
if (partnerCriteria.getRegionIds().size() > 0) {
|
| 1216 |
stateShortName);
|
1216 |
sb.append("from ");
|
| 1217 |
if (districtMaster == null) {
|
1217 |
sb.append(String.join(", ", partnerCriteria.getRegionIds().stream().map(x -> ProfitMandiConstants.WAREHOUSE_MAP.get(x)).collect(Collectors.toList())));
|
| 1218 |
districtMaster = districtMasterRepository.selectByShortnameNameAndStateShortName("FB", "HR");
|
1218 |
}
|
| 1219 |
}
|
1219 |
if (partnerCriteria.getExcludeFofoIds() != null && partnerCriteria.getExcludeFofoIds().size() > 0) {
|
| 1220 |
LOGGER.info("Store id - {}", store.getId());
|
1220 |
sb.append("excluding ");
|
| 1221 |
// com.spice.profitmandi.dao.entity.user.User user = userMap.get(store.getId());
|
1221 |
Map<Integer, CustomRetailer> customRetailers = this.getFofoRetailerUserId(partnerCriteria.getExcludeFofoIds());
|
| 1222 |
String urlString = districtMaster.getStateShortName() + "/"
|
1222 |
List<String> businessNames = customRetailers.values().stream().map(x -> x.getBusinessName()).collect(Collectors.toList());
|
| 1223 |
+ Utils.getHyphenatedString(districtMaster.getName()) + "/" + store.getCode();
|
1223 |
sb.append(String.join(", ", businessNames));
|
| 1224 |
fofoRetailerUrlMap.put(store.getId(), urlString.toLowerCase());
|
1224 |
}
|
| 1225 |
LOGGER.info("Store is {} end", store);
|
1225 |
}
|
| 1226 |
|
1226 |
return sb.toString();
|
| 1227 |
}
|
1227 |
}
|
| 1228 |
return fofoRetailerUrlMap;
|
1228 |
|
| 1229 |
}
|
1229 |
@Override
|
| 1230 |
|
1230 |
public Map<Integer, CustomRetailer> getFofoRetailersPaginated(boolean activeOnly, int offset, int limit, FofoType fofoType) {
|
| 1231 |
@Override
|
1231 |
|
| 1232 |
@Cacheable(value = "storeCodeRetailerMap", cacheManager = "thirtyMinsTimeOutCacheManager")
|
1232 |
Stream<FofoStore> storeStream = fofoStoreRepository.selectByStatusFofoType(activeOnly, fofoType, offset, limit).stream();
|
| 1233 |
public Map<String, Integer> getStoreCodeRetailerMap() {
|
1233 |
|
| 1234 |
Map<Integer, String> map = this.getAllFofoRetailerIdUrlMap();
|
1234 |
List<Integer> storeIds = storeStream.map(x -> x.getId()).collect(Collectors.toList());
|
| 1235 |
Map<String, Integer> returnMap = map.entrySet().stream().collect(Collectors.toMap(x -> {
|
1235 |
return this.getFofoRetailers(storeIds);
|
| 1236 |
String[] splitString = x.getValue().split("/");
|
1236 |
}
|
| 1237 |
return splitString[splitString.length - 1];
|
- |
|
| 1238 |
}, x -> x.getKey()));
|
- |
|
| 1239 |
LOGGER.info("returnMap {}", returnMap);
|
- |
|
| 1240 |
return returnMap;
|
- |
|
| 1241 |
}
|
- |
|
| 1242 |
|
- |
|
| 1243 |
@Override
|
- |
|
| 1244 |
public String getPartnerCriteriaString(PartnerCriteria partnerCriteria) {
|
- |
|
| 1245 |
|
- |
|
| 1246 |
StringBuilder sb = new StringBuilder();
|
- |
|
| 1247 |
if (partnerCriteria.getFofoIds().size() > 0) {
|
- |
|
| 1248 |
List<Integer> fofoIds = partnerCriteria.getFofoIds();
|
- |
|
| 1249 |
Map<Integer, CustomRetailer> customRetailers = this.getFofoRetailerUserId(fofoIds);
|
- |
|
| 1250 |
List<String> businessNames = customRetailers.values().stream().map(x -> x.getBusinessName())
|
- |
|
| 1251 |
.collect(Collectors.toList());
|
- |
|
| 1252 |
sb.append(String.join(", ", businessNames));
|
- |
|
| 1253 |
|
- |
|
| 1254 |
} else {
|
- |
|
| 1255 |
sb.append("All");
|
- |
|
| 1256 |
if (partnerCriteria.getPartnerTypes().size() > 0) {
|
- |
|
| 1257 |
sb.append(" ").append(String.join(", ", partnerCriteria.getPartnerTypes().stream()
|
- |
|
| 1258 |
.map(x -> x.getValue()).collect(Collectors.toList())));
|
- |
|
| 1259 |
}
|
- |
|
| 1260 |
sb.append(" partners ");
|
- |
|
| 1261 |
if (partnerCriteria.getRegionIds().size() > 0) {
|
- |
|
| 1262 |
sb.append("from ");
|
- |
|
| 1263 |
sb.append(String.join(", ", partnerCriteria.getRegionIds().stream()
|
- |
|
| 1264 |
.map(x -> ProfitMandiConstants.WAREHOUSE_MAP.get(x)).collect(Collectors.toList())));
|
- |
|
| 1265 |
}
|
- |
|
| 1266 |
if (partnerCriteria.getExcludeFofoIds() != null && partnerCriteria.getExcludeFofoIds().size() > 0) {
|
- |
|
| 1267 |
sb.append("excluding ");
|
- |
|
| 1268 |
Map<Integer, CustomRetailer> customRetailers = this
|
- |
|
| 1269 |
.getFofoRetailerUserId(partnerCriteria.getExcludeFofoIds());
|
- |
|
| 1270 |
List<String> businessNames = customRetailers.values().stream().map(x -> x.getBusinessName())
|
- |
|
| 1271 |
.collect(Collectors.toList());
|
- |
|
| 1272 |
sb.append(String.join(", ", businessNames));
|
- |
|
| 1273 |
}
|
- |
|
| 1274 |
}
|
- |
|
| 1275 |
return sb.toString();
|
- |
|
| 1276 |
}
|
- |
|
| 1277 |
|
- |
|
| 1278 |
@Override
|
- |
|
| 1279 |
public Map<Integer, CustomRetailer> getFofoRetailersPaginated(boolean activeOnly, int offset, int limit,
|
- |
|
| 1280 |
FofoType fofoType) {
|
- |
|
| 1281 |
|
- |
|
| 1282 |
Stream<FofoStore> storeStream = fofoStoreRepository.selectByStatusFofoType(activeOnly, fofoType, offset, limit)
|
- |
|
| 1283 |
.stream();
|
- |
|
| 1284 |
|
- |
|
| 1285 |
List<Integer> storeIds = storeStream.map(x -> x.getId()).collect(Collectors.toList());
|
- |
|
| 1286 |
return this.getFofoRetailers(storeIds);
|
- |
|
| 1287 |
}
|
- |
|
| 1288 |
|
1237 |
|
| 1289 |
}
|
1238 |
}
|