def addDistri(oracle, **args): result = checkIfExist(oracle, tax_code=args['tax_code'], tax_begin_nbr=args['tax_begin_nbr'], tax_end_nbr=args['tax_end_nbr']) if (result != "0"): raise Warning_, result dic = {} dic['distri_id'] = getNextVal(oracle) dic['parent_distri_id'] = '-1' dic['tax_code'] = args['tax_code'] dic['tax_begin_nbr'] = args['tax_begin_nbr'] dic['tax_end_nbr'] = args['tax_end_nbr'] dic['sys_type'] = 'B' dic['state'] = 'in' dic['state_date'] = '/sysdate' dic['staff_id'] = args['staff_id'] insert(oracle, 'distri', dic) where_dic = {} where_dic['distri_id'] = dic['distri_id'] add_infos = {'oper': 'add'} add_infos['oper_staff_id'] = args['oper_staff_id'] add_infos['oper_date'] = '/sysdate' insertLog(oracle, 'distri', where_dic, add_infos)
def addRolePrivilege(oracle, **args): select_colums = ['role_id'] where_dic = {} where_dic['role_id'] = args['role_id'] sql = 'from role' role_info = select(oracle, select_colums, sql, where_dic) if (role_info == None): raise Warning_, '角色role_id = %s不存在' % (args['role_id']) select_colums = ['role_id', 'privilege_id'] where_dic = {} where_dic['role_id'] = args['role_id'] where_dic['privilege_id'] = args['privilege_id'] sql = 'from role_privilege' role_info = select(oracle, select_colums, sql, where_dic) if (role_info != None): raise Warning_, '角色权限role_id = %s privilege_id = %s已经存在' % ( role_info[0]['role_id'], role_info[0]['privilege_id']) insert_value = args.copy() del insert_value['oper_staff_id'] insert(oracle, 'role_privilege', insert_value) where_dic = {} where_dic['role_id'] = args['role_id'] where_dic['privilege_id'] = args['privilege_id'] add_infos = {'oper': 'add'} add_infos['oper_staff_id'] = args['oper_staff_id'] add_infos['oper_date'] = '/sysdate' insertLog(oracle, 'role_privilege', where_dic, add_infos)
def addBssOrg(self): insert(self.oracle, 'bss_org', self.args) add_infos = { 'oper': 'add', 'oper_staff_id': self.oper_staff_id, 'oper_date': '/sysdate' } insertLog(self.oracle, 'bss_org', {'bss_org_id': self.bss_org_id}, add_infos)
def insertHandInvoice(self): '''insert table hand_invoice''' insert( self.oracle, 'hand_invoice', { 'invoice_id': self.invoice_seq_id, 'tax_code': self.tax_code, 'tax_nbr': self.tax_nbr, 'staff_id': self.staff_id, 'sys_type': 'H', 'state_date': '/sysdate' })
def insertBillItemList(self): '''insert table bill_item_list''' bill_item = [] for i in self.bill_item_list: dic = { 'invoice_id': self.invoice_seq_id, 'region': 'BillItemList', 'content': i, 'sort': self.bill_item_list.index(i) } bill_item.append(dic) insert(self.oracle, 'hand_invoice_detail', bill_item, len(bill_item))
def insertHandInvoiceDetail(self): '''insert table hand_invoice_detail''' invoice_detail = [] for key, value in self.hand_info.items(): dic = { 'invoice_id': self.invoice_seq_id, 'region': key, 'content': value, 'sort': '0' } invoice_detail.append(dic) insert(self.oracle, 'hand_invoice_detail', invoice_detail, len(invoice_detail))
def addStaff(oracle, dic): '''增加工号 dic: staff_id, staff_desc, passwd, bss_org_id, oper_staff_id, [remark]''' dic['staff_id'] = int(dic['staff_id']) dic['bss_org_id'] = int(dic['bss_org_id']) dic['oper_staff_id'] = int(dic['oper_staff_id']) dic['state'] = '1' staff_info = getStaff(oracle, dic['staff_id']) if(staff_info!= None): staff_info = staff_info[0] print staff_info raise Exception, '工号%s(%s)已经存在,属于机构 %s'%(staff_info['staff_id'], staff_info['staff_desc'], staff_info['bss_org_id']) #加密 passwd = dic['passwd'] m = hashlib.md5() m.update(passwd) dic['passwd'] = m.hexdigest() dic2 = dic.copy() print dic2 del dic2['oper_staff_id'] if(dic2.get('remark')): del dic2['remark'] row_count = insert(oracle, 'staff', dic2) where_dic = {} where_dic['staff_id'] = dic['staff_id'] add_infos = {'oper':'add staff'} add_infos['oper_staff_id'] = dic['oper_staff_id'] add_infos['oper_date'] = '/sysdate' insertLog(oracle, 'staff', where_dic, add_infos)
def addStaffRole(oracle, **args): '''增加工号角色 dic: role_id, staff_id, oper_staff_id''' insert_value = args.copy() del insert_value['oper_staff_id'] where_dic = insert_value select_colums = ['role_id','staff_id'] sql = 'from staff_role' role_info = select(oracle, select_colums, sql, where_dic) print role_info if(role_info!= None): raise Warning_, '角色%s己经挂到工号%s上了'%(role_info[0]['role_id'], role_info[0]['staff_id'] ) insert(oracle, 'staff_role', insert_value) add_infos = {'oper':'add'} add_infos['oper_staff_id'] = args['oper_staff_id'] add_infos['oper_date'] = '/sysdate' insertLog(oracle, 'staff_role', where_dic, add_infos)
def changeRetail(oracle, dic): ''' id, flex_id, name, score, value, num''' for k, v in dic.items(): exec "%s = '%s'" % (k, v) where_dic = {'id': id, 'flex_id': flex_id} update_dic = { 'num': num, 'name': name, 'score': score, 'value': value, 'state_date': '/sysdate' } count = update(oracle=oracle, table_name='retail_detail', update_dic=update_dic, where_dic=where_dic, count=0) if (count == 0): dic['state_date'] = '/sysdate' insert(oracle, 'retail_detail', dic)
def addOrg(oracle, dic): '''depend on flex''' for k, v in dic.items(): exec "%s = '%s'" % (k, v) print dic.__doc__ if ('id' in dic): id = dic['id'] else: select_result = select(oracle, ['org_seq.nextval'], 'from dual') id = select_result[0]['nextval'] dic['id'] = id del dic['oper_staff_id'] insert(oracle, 'org', dic) add_infos = { 'oper': 'add', 'oper_staff_id': oper_staff_id, 'oper_date': '/sysdate' } insertLog(oracle, 'org', {'id': id}, add_infos)
def addRole(oracle, **args): '''增加角色 dic: role_id''' select_colums = ['role_id', 'name'] where_dic = {} where_dic['role_id'] = args['role_id'] sql = 'from role' role_info = select(oracle, select_colums, sql, where_dic) if (role_info != None): raise Exception, '角色%s(%s)已经存在' % (role_info[0]['role_id'], role_info[0]['name']) insert_value = args.copy() del insert_value['oper_staff_id'] insert_value['state_date'] = '/sysdate' insert(oracle, 'role', insert_value) where_dic = {} where_dic['role_id'] = args['role_id'] add_infos = {'oper': 'add'} add_infos['oper_staff_id'] = args['oper_staff_id'] add_infos['oper_date'] = '/sysdate' insertLog(oracle, 'role', where_dic, add_infos)
def bondStaff(oracle, **args): '''工号绑定 staff_id out_staff_id sys_type passwd sys_type''' for k, v in args.items(): exec "%s = '%s'"%(k,v) if(sys_type!= 'C' and sys_type!= 'B'): raise Warning_,'绑定工号时传入的系统类型为%s,不正确' result = select(oracle, ['out_staff_id','sys_type'], 'from staff_map', {'staff_id':staff_id, 'state':'1','sys_type':sys_type}) if(result!= None): raise Warning_,'工号%s已经绑定到系统%s的工号%s,不能重复绑定'%(staff_id, result[0]['sys_type'], result[0]['out_staff_id']) result = select(oracle, ['staff_id'], 'from staff_map', {'out_staff_id':out_staff_id, 'state':'1', 'sys_type':sys_type}) if(result!= None): raise Exception,'系统%s工号%s已经绑定到了工号%s上,不能重复绑定'%(sys_type, out_staff_id, result[0]['staff_id']) if(sys_type == 'C'): result = oracle.execute('select passwd,staff_id from v_staff_crm where upper(staff_id) = :staff_id',{'staff_id':out_staff_id.upper()}) elif(sys_type == 'B'): result = oracle.execute('select passwd,staff_id from acct.staff where upper(staff_code) = :staff_id',{'staff_id':out_staff_id.upper()}) if(len(result) == 0): raise Warning_,'外部系统%s 工号%s不存在'%(sys_type,out_staff_id) crm_passwd = result[0][0] out_staff_id = result[0][1] if(sys_type == 'C'): m = hashlib.md5() m.update(passwd) passwd = m.hexdigest().upper() if(passwd!= crm_passwd): raise Warning_,'crm工号%s在密码不正确'%out_staff_id insert_dic = {'staff_id':staff_id, 'out_staff_id':out_staff_id, 'state':1, 'sys_type':sys_type, 'created_date':'/sysdate', 'state_date':'/sysdate'} insert(oracle, 'staff_map', insert_dic)
def addDistrit(oracle, **args): for k, v in args.items(): exec "%s = '%s'" % (k, v) #checkIfExist(oracle, tax_code = tax_code, tax_begin_nbr = tax_begin_nbr, tax_end_nbr = tax_end_nbr) dic = {} dic['distri_id'] = getNextVal(oracle) dic['parent_distri_id'] = distri_id dic['tax_code'] = tax_code dic['tax_begin_nbr'] = tax_begin_nbr dic['tax_end_nbr'] = tax_end_nbr #dic['sys_type'] = 'B' dic['state'] = 'hold' dic['state_date'] = '/sysdate' #dic['created_date'] = '/sysdate' dic['staff_id'] = oper_staff_id insert(oracle, 'distri', dic) where_dic = {} where_dic['distri_id'] = dic['distri_id'] add_infos = {'oper': 'abstract'} add_infos['oper_staff_id'] = oper_staff_id add_infos['oper_date'] = '/sysdate' insertLog(oracle, 'distri', where_dic, add_infos)
def allInstance(oracle, **args): '''全部上架''' for k, v in args.items(): exec "%s = '%s'" % (k, v) state = 'instance' update_dic = {'state': state, 'state_date': '/sysdate'} where_dic = {'distri_id': distri_id} update(oracle, 'distri', update_dic, where_dic, "and state in('in','hold')") insertDistriLog(oracle=oracle, distri_id=distri_id, oper_staff_id=oper_staff_id, oper='instance', state=state) #先插入一条 dic = {} pool_id = pool.getNextVal(oracle) dic['pool_id'] = pool_id dic['distri_id'] = distri_id dic['tax_code'] = tax_code dic['tax_nbr'] = tax_begin_nbr #dic['sys_type'] = 'B' dic['state'] = 'instance' dic['state_date'] = '/sysdate' dic['staff_id'] = oper_staff_id insert(oracle, 'pool', dic) must_instance_count = int(tax_end_nbr) - int(tax_begin_nbr) + 1 if (hold_tax_begin_nbr != hold_tax_end_nbr): length = len(hold_tax_begin_nbr) tax_nbr_list = [] sql = ''' insert into pool (pool_id, distri_id, tax_code, tax_nbr, state, state_date, staff_id, sys_type) (select pool_seq.nextval, distri_id, tax_code, :tax_nbr, state, state_date, staff_id, sys_type from pool where pool_id = %s) ''' % pool_id if (int(hold_tax_end_nbr) - int(hold_tax_begin_nbr) > 100000): raise Warning_, '一次上架记录数有%s条,业务不允许,请下发拆分小于10W再上架' % ( int(hold_tax_end_nbr) - int(hold_tax_begin_nbr)) for i in range(int(hold_tax_begin_nbr) + 1, int(hold_tax_end_nbr) + 1): tax_nbr = addZero(length, i) dic = {'tax_nbr': tax_nbr} tax_nbr_list.append(dic) if (len(tax_nbr_list) > 100000): raise Warning_, '一次上架记录数有%s条,业务不允许,请下发拆分小于10W再上架' if (len(tax_nbr_list) > 50000): row_count = oracle.executemany(sql, tax_nbr_list[:50000]) row_count += oracle.executemany(sql, tax_nbr_list[50000:]) else: row_count = oracle.executemany(sql, tax_nbr_list) if (row_count != must_instance_count - 1): raise Exception, '未能正确上架 distri_id = %s,应上架%s,实际只上了%s,数据发生变动,请重新查' % ( distri_id, must_instance_count, row_count + 1) where_dic = { 'tax_code': tax_code, 'distri_id': distri_id, 'state': 'instance', 'staff_id': oper_staff_id } and_the = "and to_number(tax_nbr)> = to_number('%s') and to_number(tax_nbr)< = to_number('%s')" % ( tax_begin_nbr, tax_end_nbr) add_infos = {'oper': 'instance'} add_infos['oper_staff_id'] = oper_staff_id add_infos['oper_date'] = '/sysdate' insertLog(oracle, 'pool', where_dic, add_infos, and_the, must_instance_count)