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 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 addPoolLog(oracle, dic, pool_id): where_dic = {} where_dic['pool_id'] = pool_id add_infos = {'oper': 'nullify'} add_infos['oper_staff_id'] = dic['oper_staff_id'] add_infos['oper_date'] = '/sysdate' insertLog(oracle, 'pool', where_dic, add_infos)
def roll(oracle, **args): ''' 发票回滚 tax_code tax_nbr oper_staff_id remark ''' sql = '''update pool p set p.state = 'instance', p.state_date = sysdate where p.tax_code = :tax_code and p.tax_nbr = :tax_nbr and p.state not in ('instance') ''' dic_tmp = {} dic_tmp['tax_code'] = args['tax_code'] dic_tmp['tax_nbr'] = args['tax_nbr'] row_count = oracle.execute(sql,dic_tmp) if(row_count != 1): raise Exception, '给出条件未能找到可以回滚的发票记录;update pool %s 条记录'%row_count #取出 pool_id 顺便再次检查其是否更新成功 select_colums = ['pool_id',] dic_tmp['state'] = 'instance' pool_id = selectPool(oracle, select_colums, dic_tmp) if(pool_id == None): raise Exception, '给出条件未能找到可以回滚的发票记录;update pool 失败' if(len(pool_id) != 1): raise Exception, '状态同时为instance的记录有%s条'%len(pool_id) #根据pool_id 插入 pool_log表 where_dic = {} where_dic['pool_id'] = pool_id[0]['pool_id'] add_infos = {'oper':'roll'} add_infos['oper_staff_id'] = args['oper_staff_id'] add_infos['oper_date'] = '/sysdate' insertLog(oracle, 'pool', where_dic, add_infos)
def addDistriLog(oracle, distri_id, oper_staff_id): where_dic = {} where_dic['distri_id'] = distri_id add_infos = {'oper': 'nullify'} add_infos['oper_staff_id'] = oper_staff_id add_infos['oper_date'] = '/sysdate' insertLog(oracle, 'distri', where_dic, add_infos)
def updatePool(self): table_name = 'pool' #将要调的发票先置-1 update_dic = {'tax_nbr': '-1', 'tax_code': '-1'} where_dic = { 'pool_id': self.pool_id, 'tax_code': self.tax_code, 'tax_nbr': self.tax_nbr } update(oracle=self.oracle, table_name=table_name, update_dic=update_dic, where_dic=where_dic, and_the=self.and_the) #将被影响的发票置之 update_dic = {'tax_nbr': self.tax_nbr, 'tax_code': self.tax_code} where_dic = { 'pool_id': self.be_pool_id, 'tax_code': self.new_tax_code, 'tax_nbr': self.new_tax_nbr } update(oracle=self.oracle, table_name=table_name, update_dic=update_dic, where_dic=where_dic, and_the=self.and_the) where_dic = {'pool_id': self.be_pool_id} add_infos = { 'oper': 'adjust', 'oper_staff_id': self.oper_staff_id, 'oper_date': '/sysdate' } insertLog(self.oracle, table_name, where_dic, add_infos) #将-1的置之 update_dic = { 'tax_nbr': self.new_tax_nbr, 'tax_code': self.new_tax_code } where_dic = { 'pool_id': self.pool_id, 'tax_code': '-1', 'tax_nbr': '-1' } update(oracle=self.oracle, table_name=table_name, update_dic=update_dic, where_dic=where_dic, and_the=self.and_the) where_dic = {'pool_id': self.pool_id} add_infos = { 'oper': 'adjust', 'oper_staff_id': self.oper_staff_id, 'oper_date': '/sysdate' } insertLog(self.oracle, table_name, where_dic, add_infos)
def insertDistriLog(oracle, **args): '''日志记录''' where_dic = {} where_dic['distri_id'] = args['distri_id'] add_infos = {'oper': args['oper']} add_infos['oper_staff_id'] = args['oper_staff_id'] add_infos['oper_date'] = '/sysdate' insertLog(oracle, 'distri', 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 changeBssOrg(self): update_dic = self.args del update_dic['bss_org_id'] update(self.oracle, 'bss_org', update_dic, where_dic={'bss_org_id': self.bss_org_id}) add_infos = { 'oper': 'change', '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 delBssOrg(self): if (hasChrild(self.oracle, self.bss_org_id) is not None): raise Warning_, '请先删除子机构' if (hasStaff(self.oracle, self.bss_org_id) is not None): raise Warning_, '机构%s下还有工号,请先删除该机构下的工号' % self.bss_org_id add_infos = { 'oper': 'del', 'oper_staff_id': self.oper_staff_id, 'oper_date': '/sysdate' } insertLog(self.oracle, 'bss_org', {'bss_org_id': self.bss_org_id}, add_infos) sql = 'delete from bss_org where bss_org_id = %s' % self.bss_org_id row_count = self.oracle.execute(sql) if (row_count != 1): raise Exception, '删除机构%s %s个,出现异常' % (self.bss_org_id, row_count)
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)