| 21525 |
amit.gupta |
1 |
package com.spice.profitmandi.service;
|
|
|
2 |
|
|
|
3 |
import javax.transaction.Transactional;
|
|
|
4 |
|
|
|
5 |
import org.hibernate.Criteria;
|
|
|
6 |
import org.hibernate.Session;
|
|
|
7 |
import org.hibernate.SessionFactory;
|
|
|
8 |
import org.hibernate.criterion.Restrictions;
|
|
|
9 |
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
10 |
import org.springframework.stereotype.Component;
|
|
|
11 |
|
| 21729 |
ashik.ali |
12 |
import com.spice.profitmandi.dao.entity.dtr.Retailer;
|
|
|
13 |
import com.spice.profitmandi.dao.entity.dtr.User;
|
|
|
14 |
import com.spice.profitmandi.dao.entity.fofo.ActivationCode;
|
|
|
15 |
import com.spice.profitmandi.dao.repository.dtr.RetailerRepository;
|
|
|
16 |
import com.spice.profitmandi.dao.repository.dtr.UserRepository;
|
| 21525 |
amit.gupta |
17 |
import com.spice.profitmandi.thrift.clients.TransactionClient;
|
|
|
18 |
|
|
|
19 |
import in.shop2020.model.v1.order.TransactionService;
|
|
|
20 |
|
|
|
21 |
@Component
|
|
|
22 |
@Transactional
|
|
|
23 |
public class UserServiceImpl implements UserService {
|
|
|
24 |
|
|
|
25 |
@Autowired
|
|
|
26 |
SessionFactory sessionFactory;
|
|
|
27 |
|
|
|
28 |
@Autowired
|
|
|
29 |
UserRepository userRepo;
|
|
|
30 |
|
|
|
31 |
@Autowired
|
|
|
32 |
RetailerRepository retailerRepo;
|
|
|
33 |
|
|
|
34 |
|
|
|
35 |
@Override
|
|
|
36 |
public boolean updateActivation(int userId, int retailerId, String activationCode) throws Throwable {
|
|
|
37 |
|
|
|
38 |
TransactionClient transactionServiceClient = new TransactionClient();
|
|
|
39 |
TransactionService.Client tsc = transactionServiceClient.getClient();
|
|
|
40 |
boolean registered = tsc.registerRsa(retailerId, activationCode);
|
|
|
41 |
|
|
|
42 |
Session session = sessionFactory.getCurrentSession();
|
|
|
43 |
|
|
|
44 |
if(!registered){
|
|
|
45 |
Criteria cr = session.createCriteria(ActivationCode.class);
|
|
|
46 |
cr.add(Restrictions.eq("code", activationCode)).add(Restrictions.eq("status", true));
|
|
|
47 |
ActivationCode code = (ActivationCode)cr.uniqueResult();
|
|
|
48 |
if(code==null) {
|
|
|
49 |
return false;
|
|
|
50 |
} else {
|
|
|
51 |
registered=true;
|
|
|
52 |
code.setStatus(false);
|
|
|
53 |
session.update(code);
|
|
|
54 |
}
|
|
|
55 |
}
|
|
|
56 |
|
|
|
57 |
if(registered) {
|
|
|
58 |
User user = userRepo.selectById(userId);
|
|
|
59 |
user.setActivated(true);
|
|
|
60 |
user.setReferrer(activationCode);
|
|
|
61 |
session.update(user);
|
|
|
62 |
|
|
|
63 |
Retailer retailer = retailerRepo.selectById(retailerId);
|
|
|
64 |
retailer.setActive(true);
|
|
|
65 |
session.update(retailer);
|
|
|
66 |
}
|
|
|
67 |
|
|
|
68 |
return registered;
|
|
|
69 |
}
|
|
|
70 |
}
|