| 23781 |
ashik.ali |
1 |
package com.spice.profitmandi.service.user;
|
| 21525 |
amit.gupta |
2 |
|
| 22845 |
amit.gupta |
3 |
import java.time.LocalDateTime;
|
| 23204 |
ashik.ali |
4 |
import java.util.HashMap;
|
| 23984 |
govind |
5 |
import java.util.HashSet;
|
|
|
6 |
import java.util.List;
|
| 23204 |
ashik.ali |
7 |
import java.util.Map;
|
| 22845 |
amit.gupta |
8 |
|
| 21525 |
amit.gupta |
9 |
import org.hibernate.Criteria;
|
|
|
10 |
import org.hibernate.Session;
|
|
|
11 |
import org.hibernate.SessionFactory;
|
|
|
12 |
import org.hibernate.criterion.Restrictions;
|
|
|
13 |
import org.springframework.beans.factory.annotation.Autowired;
|
| 23781 |
ashik.ali |
14 |
import org.springframework.beans.factory.annotation.Qualifier;
|
| 21525 |
amit.gupta |
15 |
import org.springframework.stereotype.Component;
|
| 22038 |
amit.gupta |
16 |
import org.springframework.transaction.annotation.Transactional;
|
| 21525 |
amit.gupta |
17 |
|
| 23204 |
ashik.ali |
18 |
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
|
|
|
19 |
import com.spice.profitmandi.common.model.ProfitMandiConstants;
|
| 22020 |
ashik.ali |
20 |
import com.spice.profitmandi.dao.entity.dtr.ActivationCode;
|
| 21729 |
ashik.ali |
21 |
import com.spice.profitmandi.dao.entity.dtr.Retailer;
|
| 23781 |
ashik.ali |
22 |
import com.spice.profitmandi.dao.entity.dtr.Role;
|
| 21729 |
ashik.ali |
23 |
import com.spice.profitmandi.dao.entity.dtr.User;
|
| 23273 |
ashik.ali |
24 |
import com.spice.profitmandi.dao.entity.dtr.UserAccount;
|
| 23204 |
ashik.ali |
25 |
import com.spice.profitmandi.dao.entity.fofo.FofoStore;
|
|
|
26 |
import com.spice.profitmandi.dao.enumuration.dtr.AccountType;
|
|
|
27 |
import com.spice.profitmandi.dao.enumuration.dtr.RoleType;
|
|
|
28 |
import com.spice.profitmandi.dao.repository.dtr.FofoStoreRepository;
|
| 21729 |
ashik.ali |
29 |
import com.spice.profitmandi.dao.repository.dtr.RetailerRepository;
|
| 23781 |
ashik.ali |
30 |
import com.spice.profitmandi.dao.repository.dtr.RoleRepository;
|
| 23204 |
ashik.ali |
31 |
import com.spice.profitmandi.dao.repository.dtr.UserAccountRepository;
|
| 21729 |
ashik.ali |
32 |
import com.spice.profitmandi.dao.repository.dtr.UserRepository;
|
| 23204 |
ashik.ali |
33 |
import com.spice.profitmandi.dao.repository.dtr.UserRoleRepository;
|
| 21525 |
amit.gupta |
34 |
import com.spice.profitmandi.thrift.clients.TransactionClient;
|
|
|
35 |
|
|
|
36 |
import in.shop2020.model.v1.order.TransactionService;
|
|
|
37 |
|
|
|
38 |
@Component
|
| 22038 |
amit.gupta |
39 |
@Transactional(rollbackFor=Throwable.class)
|
| 21525 |
amit.gupta |
40 |
public class UserServiceImpl implements UserService {
|
|
|
41 |
|
|
|
42 |
@Autowired
|
| 22931 |
ashik.ali |
43 |
private SessionFactory sessionFactory;
|
| 21525 |
amit.gupta |
44 |
|
|
|
45 |
@Autowired
|
| 23781 |
ashik.ali |
46 |
@Qualifier(value = "userRepository")
|
| 23204 |
ashik.ali |
47 |
private UserRepository userRepository;
|
| 21525 |
amit.gupta |
48 |
|
|
|
49 |
@Autowired
|
| 23204 |
ashik.ali |
50 |
private RetailerRepository retailerRepo;
|
| 21525 |
amit.gupta |
51 |
|
| 23204 |
ashik.ali |
52 |
@Autowired
|
|
|
53 |
private FofoStoreRepository fofoStoreRepository;
|
|
|
54 |
|
|
|
55 |
@Autowired
|
|
|
56 |
private UserAccountRepository userAccountRepository;
|
|
|
57 |
|
|
|
58 |
@Autowired
|
|
|
59 |
private UserRoleRepository userRoleRepository;
|
|
|
60 |
|
| 23781 |
ashik.ali |
61 |
@Autowired
|
|
|
62 |
private RoleRepository roleRepository;
|
|
|
63 |
|
| 21525 |
amit.gupta |
64 |
|
| 23204 |
ashik.ali |
65 |
@SuppressWarnings("deprecation")
|
| 21525 |
amit.gupta |
66 |
@Override
|
|
|
67 |
public boolean updateActivation(int userId, int retailerId, String activationCode) throws Throwable {
|
|
|
68 |
|
|
|
69 |
TransactionClient transactionServiceClient = new TransactionClient();
|
|
|
70 |
TransactionService.Client tsc = transactionServiceClient.getClient();
|
|
|
71 |
boolean registered = tsc.registerRsa(retailerId, activationCode);
|
|
|
72 |
|
|
|
73 |
Session session = sessionFactory.getCurrentSession();
|
|
|
74 |
|
|
|
75 |
if(!registered){
|
|
|
76 |
Criteria cr = session.createCriteria(ActivationCode.class);
|
|
|
77 |
cr.add(Restrictions.eq("code", activationCode)).add(Restrictions.eq("status", true));
|
|
|
78 |
ActivationCode code = (ActivationCode)cr.uniqueResult();
|
|
|
79 |
if(code==null) {
|
|
|
80 |
return false;
|
|
|
81 |
} else {
|
|
|
82 |
registered=true;
|
|
|
83 |
code.setStatus(false);
|
|
|
84 |
session.update(code);
|
|
|
85 |
}
|
|
|
86 |
}
|
|
|
87 |
|
|
|
88 |
if(registered) {
|
| 23204 |
ashik.ali |
89 |
User user = userRepository.selectById(userId);
|
| 21525 |
amit.gupta |
90 |
user.setActivated(true);
|
| 22845 |
amit.gupta |
91 |
user.setActivationTime(LocalDateTime.now());
|
| 21525 |
amit.gupta |
92 |
user.setReferrer(activationCode);
|
|
|
93 |
session.update(user);
|
|
|
94 |
|
|
|
95 |
Retailer retailer = retailerRepo.selectById(retailerId);
|
|
|
96 |
retailer.setActive(true);
|
|
|
97 |
session.update(retailer);
|
|
|
98 |
}
|
|
|
99 |
|
|
|
100 |
return registered;
|
|
|
101 |
}
|
| 22845 |
amit.gupta |
102 |
|
|
|
103 |
|
|
|
104 |
@Override
|
|
|
105 |
public boolean createActivationCode(int userId) throws Throwable {
|
|
|
106 |
// TODO Auto-generated method stub
|
|
|
107 |
return false;
|
|
|
108 |
}
|
| 23204 |
ashik.ali |
109 |
|
|
|
110 |
@Override
|
|
|
111 |
public Map<String, String> getEmailsAndFofoStoreCodeByUserId(int userId) throws ProfitMandiBusinessException {
|
|
|
112 |
User user = userRepository.selectById(userId);
|
| 23273 |
ashik.ali |
113 |
UserAccount userAccount = userAccountRepository.selectByUserIdType(userId, AccountType.saholic);
|
| 23781 |
ashik.ali |
114 |
Role role = roleRepository.selectByName(RoleType.FOFO.toString());
|
| 23204 |
ashik.ali |
115 |
Map<String, String> map = new HashMap<>();
|
|
|
116 |
map.put(ProfitMandiConstants.EMAIL_ID, user.getEmailId());
|
|
|
117 |
map.put(ProfitMandiConstants.SECONDRY_EMAIL_ID, user.getSecondryEmailId());
|
| 23781 |
ashik.ali |
118 |
userRoleRepository.selectByUserIdAndRoleId(userId, role.getId());
|
| 23273 |
ashik.ali |
119 |
FofoStore fofoStore = fofoStoreRepository.selectByRetailerId(userAccount.getAccountKey());
|
| 23204 |
ashik.ali |
120 |
map.put(ProfitMandiConstants.CODE, fofoStore.getCode());
|
|
|
121 |
return map;
|
|
|
122 |
}
|
| 23984 |
govind |
123 |
|
|
|
124 |
|
|
|
125 |
@Override
|
|
|
126 |
public Map<Integer, String> getAllUseUserIdEmailIdMap(List<Integer> userIds) {
|
|
|
127 |
Map<Integer, String> userIdEmailIdMap=new HashMap<>();
|
|
|
128 |
List<User> users=userRepository.selectAllByIds(new HashSet<>(userIds));
|
|
|
129 |
for(User user:users)
|
|
|
130 |
{
|
|
|
131 |
userIdEmailIdMap.put(user.getId(),user.getEmailId());
|
|
|
132 |
}
|
|
|
133 |
return userIdEmailIdMap;
|
|
|
134 |
}
|
| 23781 |
ashik.ali |
135 |
|
| 21525 |
amit.gupta |
136 |
}
|