Subversion Repositories SmartDukaan

Rev

Rev 18321 | Rev 18331 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 18321 Rev 18329
Line 70... Line 70...
70
        
70
        
71
 
71
 
72
 
72
 
73
global RETAILER_DETAIL_CALL_COUNTER
73
global RETAILER_DETAIL_CALL_COUNTER
74
RETAILER_DETAIL_CALL_COUNTER = 0
74
RETAILER_DETAIL_CALL_COUNTER = 0
75
 
-
 
-
 
75
global USER_DETAIL_MAP
-
 
76
USER_DETAIL_MAP['accs_cart']=0
-
 
77
USER_DETAIL_MAP['accs_active']=0
-
 
78
USER_DETAIL_MAP['accs_order']=0
76
lgr = getLogger('/var/log/retailer-acquisition-api.log')
79
lgr = getLogger('/var/log/retailer-acquisition-api.log')
77
DEALER_RETRY_FACTOR = int(PythonPropertyReader.getConfig('DEALER_RETRY_FACTOR'))
80
DEALER_RETRY_FACTOR = int(PythonPropertyReader.getConfig('DEALER_RETRY_FACTOR'))
78
DEALER_FRESH_FACTOR = int(PythonPropertyReader.getConfig('DEALER_FRESH_FACTOR'))
81
DEALER_FRESH_FACTOR = int(PythonPropertyReader.getConfig('DEALER_FRESH_FACTOR'))
-
 
82
USER_CRM_DEFAULT_RETRY_FACTOR = int(PythonPropertyReader.getConfig('USER_CRM_DEFAULT_RETRY_FACTOR'))
-
 
83
USER_CRM_DEFAULT_FRESH_FACTOR = int(PythonPropertyReader.getConfig('USER_CRM_DEFAULT_FRESH_FACTOR'))
79
TOTAL = DEALER_RETRY_FACTOR + DEALER_FRESH_FACTOR  
84
TOTAL = DEALER_RETRY_FACTOR + DEALER_FRESH_FACTOR
-
 
85
TOTAL_USER = USER_CRM_DEFAULT_FRESH_FACTOR + USER_CRM_DEFAULT_RETRY_FACTOR  
80
class CategoryDiscountInfo(object):
86
class CategoryDiscountInfo(object):
81
    
87
    
82
    def on_get(self, req, resp):
88
    def on_get(self, req, resp):
83
        
89
        
84
        result = Mongo.getAllCategoryDiscount()
90
        result = Mongo.getAllCategoryDiscount()
Line 1622... Line 1628...
1622
            resp.body = json.dumps({}, encoding='utf-8')
1628
            resp.body = json.dumps({}, encoding='utf-8')
1623
 
1629
 
1624
class GetUserCrmApplication:
1630
class GetUserCrmApplication:
1625
    
1631
    
1626
    def on_get(self,req,resp):
1632
    def on_get(self,req,resp):
-
 
1633
        global USER_DETAIL_MAP
1627
        project_name = req.get_param("project_name")
1634
        project_name = req.get_param("project_name")
-
 
1635
        USER_DETAIL_MAP[project_name]+=1
-
 
1636
        lgr.info( "RETAILER_DETAIL_CALL_COUNTER " +  str(USER_DETAIL_MAP[project_name]))
-
 
1637
        retryFlag=False
-
 
1638
        if USER_DETAIL_MAP[project_name] % TOTAL_USER >= USER_CRM_DEFAULT_FRESH_FACTOR:
-
 
1639
                retryFlag=True
1628
        if project_name == 'accessories':
1640
        if project_name == 'accs_cart':
-
 
1641
            if retryFlag:
-
 
1642
                user = self.getRetryUser(1)
-
 
1643
            else:
-
 
1644
                user = self.getNewUser(1)
1629
            user = session.query(UserCrmCallingData).filter_by(project_id=1).filter(or_(UserCrmCallingData.next_call_time<=datetime.now(),UserCrmCallingData.status=='new')).filter(UserCrmCallingData.pincode_servicable==True).filter(UserCrmCallingData.user_available==0).filter(UserCrmCallingData.contact1!=None).order_by(UserCrmCallingData.next_call_time).order_by(UserCrmCallingData.id).with_lockmode("update").first()
1645
            
1630
            if user is None:
1646
            if user is None:
1631
                project_id=1
1647
                resp.body ={}
1632
                insertUserCrmData(project_id)
-
 
1633
                user = session.query(UserCrmCallingData).filter_by(project_id=1).filter(or_(UserCrmCallingData.next_call_time<=datetime.now(),UserCrmCallingData.status=='new')).filter(UserCrmCallingData.pincode_servicable==True).filter(UserCrmCallingData.user_available==0).filter(UserCrmCallingData.contact1!=None).order_by(UserCrmCallingData.next_call_time).order_by(UserCrmCallingData.id).with_lockmode("update").first()
1648
            else:        
1634
            user.status =  'assigned'
1649
                user.status =  'assigned'
1635
            user.agent_id = req.get_param("agent_id")
1650
                user.agent_id = req.get_param("agent_id")
1636
            user.counter=1
1651
                user.counter=1
1637
            user.modified = datetime.now()
1652
                user.modified = datetime.now()
1638
            session.commit()
1653
                session.commit()
1639
            resp.body = json.dumps(todict(getUserObject(user)), encoding='utf-8')
1654
                resp.body = json.dumps(todict(getUserObject(user)), encoding='utf-8')
-
 
1655
                session.close()
-
 
1656
 
-
 
1657
    def getRetryUser(self,projectId,failback=True):
-
 
1658
        status = "retry"
1640
            session.close()
1659
        user = session.query(UserCrmCallingData).filter_by(status=status,project_id=projectId).filter(UserCrmCallingData.next_call_time<=datetime.now()).filter(or_(UserCrmCallingData.agent_id==self.agentId, UserCrmCallingData.agent_id==None)).order_by(UserCrmCallingData.next_call_time).with_lockmode("update").first()
-
 
1660
        
-
 
1661
        if user is not None:
-
 
1662
            lgr.info( "getRetryRetailer " + str(user.id))
-
 
1663
        else:
-
 
1664
            if failback:
-
 
1665
                user = self.getNewUser(False)
-
 
1666
                return user
-
 
1667
            else:
-
 
1668
                return None
-
 
1669
        return user
1641
    
1670
    
-
 
1671
    
-
 
1672
    def getNewUser(self,failback=True,projectId):
-
 
1673
            retry = True
-
 
1674
            user = None 
-
 
1675
            try:
-
 
1676
                while(retry):
-
 
1677
                    user = session.query(UserCrmCallingData).filter_by(project_id=projectId).filter(or_(UserCrmCallingData.next_call_time<=datetime.now(),UserCrmCallingData.status=='new')).filter(UserCrmCallingData.pincode_servicable==True).filter(UserCrmCallingData.user_available==0).filter(UserCrmCallingData.contact1!=None).order_by(UserCrmCallingData.next_call_time).order_by(UserCrmCallingData.id).with_lockmode("update").first()
-
 
1678
                    if user is None:
-
 
1679
                        insertUserCrmData(projectId)
-
 
1680
                        user = session.query(UserCrmCallingData).filter_by(project_id=projectId).filter(or_(UserCrmCallingData.next_call_time<=datetime.now(),UserCrmCallingData.status=='new')).filter(UserCrmCallingData.pincode_servicable==True).filter(UserCrmCallingData.user_available==0).filter(UserCrmCallingData.contact1!=None).order_by(UserCrmCallingData.next_call_time).order_by(UserCrmCallingData.id).with_lockmode("update").first()
-
 
1681
                    retry=False
-
 
1682
            except:
-
 
1683
                print traceback.print_exc()
-
 
1684
            return user    
-
 
1685
        
1642
    def on_post(self, req, resp):
1686
    def on_post(self, req, resp):
1643
        returned = False
1687
        returned = False
1644
        self.agentId = req.get_param("agent_id")
1688
        self.agentId = req.get_param("agent_id")
1645
        project_name = req.get_param("project_name")
1689
        project_name = req.get_param("project_name")
1646
        if project_name == 'accessories':
1690
        if project_name == 'accs_cart':
1647
            jsonReq = json.loads(req.stream.read(), encoding='utf-8')
1691
            jsonReq = json.loads(req.stream.read(), encoding='utf-8')
1648
            lgr.info( "Request ----\n"  + str(jsonReq))
1692
            lgr.info( "Request ----\n"  + str(jsonReq))
1649
            self.jsonReq = jsonReq
1693
            self.jsonReq = jsonReq
1650
            self.callType="default"
1694
            self.callType="default"
1651
            callLaterAccs = self.callLaterAccs
1695
            callLaterAccs = self.callLaterAccs
Line 1709... Line 1753...
1709
            self.callHistoryCrm.disposition_description='Will Place Order'            
1753
            self.callHistoryCrm.disposition_description='Will Place Order'            
1710
        session.commit()
1754
        session.commit()
1711
        return True
1755
        return True
1712
        
1756
        
1713
    def callLaterAccs(self):
1757
    def callLaterAccs(self):
-
 
1758
        self.user.status='retry'
-
 
1759
        self.user.modified = datetime.now()
1714
        if self.callDisposition == 'call_later':
1760
        if self.callDisposition == 'call_later':
1715
            if self.callHistoryCrm.disposition_comments is not None:
1761
            if self.callHistoryCrm.disposition_comments is not None:
1716
                self.user.next_call_time = datetime.strptime(self.callHistoryCrm.disposition_comments, '%d/%m/%Y %H:%M:%S')
1762
                self.user.next_call_time = datetime.strptime(self.callHistoryCrm.disposition_comments, '%d/%m/%Y %H:%M:%S')
1717
                self.callHistoryCrm.disposition_description = 'User requested to call'
1763
                self.callHistoryCrm.disposition_description = 'User requested to call'
1718
                self.callHistoryCrm.disposition_comments = self.callHistoryCrm.disposition_comments
1764
                self.callHistoryCrm.disposition_comments = self.callHistoryCrm.disposition_comments
Line 1741... Line 1787...
1741
                self.user.next_call_time = self.callHistoryCrm.call_time + timedelta(minutes = retryConfig.minutes_ahead)
1787
                self.user.next_call_time = self.callHistoryCrm.call_time + timedelta(minutes = retryConfig.minutes_ahead)
1742
                self.callHistoryCrm.disposition_description = 'Call scheduled on ' + datetime.strftime(self.user.next_call_time, '%d/%m/%Y %H:%M:%S')
1788
                self.callHistoryCrm.disposition_description = 'Call scheduled on ' + datetime.strftime(self.user.next_call_time, '%d/%m/%Y %H:%M:%S')
1743
            else:
1789
            else:
1744
                self.user.status = 'failed'
1790
                self.user.status = 'failed'
1745
                self.callHistoryCrm.disposition_description = 'Call failed as all attempts exhausted'
1791
                self.callHistoryCrm.disposition_description = 'Call failed as all attempts exhausted'
1746
        self.user.status='retry'
-
 
1747
        self.user.disposition=self.callDisposition
1792
        self.user.disposition=self.callDisposition        
1748
        self.user.modified = datetime.now()
-
 
1749
        session.commit()
1793
        session.commit()
1750
        return True
1794
        return True
1751
    
1795
    
1752
def insertUserCrmData(project_id):
1796
def insertUserCrmData(project_id):
1753
    if project_id==1:  
1797
    if project_id==1: