Example #1
0
 def put(self):
     # 取POST Form提交的数据
     alldata = self.getRequestData()
     inst = entity.Menuadmin(self.db)
     #先删除所有
     inst.remove(alldata['user_id'],
                 table="system.menu_authority_group_relation",
                 key='user_id',
                 delete=True)
     #再循环插入
     #if not alldata['groups']:
     #    raise BaseError(801)
     ids = 0
     for group_id in alldata['groups']:
         lstData = {
             'group_id':
             group_id,
             'create_time':
             time.strftime("%Y-%m-%d %H:%M:%S",
                           time.localtime(time.time())),
             'user_id':
             alldata['user_id'],
             'create_id':
             alldata['update_id']
         }
         id = inst.save(lstData,
                        table='system.menu_authority_group_relation')
         if id <= 0:
             raise BaseError(703)  #参数错误
         ids += 1
     operation_log(
         self.db).addLog(alldata['update_id'], alldata['hospital_code'],
                         'menus_aut_group_manage', "给用户授予菜单权限组",
                         alldata['user_id'])  #'menus_aut_user_group'
     self.response(ids)
Example #2
0
 def patch(self):
     #获取用户已有权限组
     alldata = self.getRequestData()
     uid = alldata['uid']
     inst = entity.Menuadmin(self.db)
     con = {'select': 'group_id', 'where': 'user_id=%s' % (uid)}
     data = inst.find(con, table="system.menu_authority_group_relation")
     self.response(data)
Example #3
0
    def put(self):
        # 取POST Form提交的数据
        alldata = self.getRequestData()
        inst = entity.Menuadmin(self.db)
        #先查看code是否存在
        id = alldata['id']
        cur = self.db.getCursor()
        cur.execute("select id from system.menu where code='%s' and id<>%s" %
                    (alldata['code'], id))
        if cur.fetchall():
            raise BaseError(807)  #code以存在
        rows = []
        lstData = {
            'code': 'code',
            'name': 'name',
            'sort': 'sort',
            'tier': 'tier',
            'parent_id': 'parent_id',
            'parent_code': 'parent_code',
            'update_id': 'update_id',
            'update_time': 'update_time'
        }
        data = {}
        for (k, v) in lstData.items():
            try:
                if k == 'code' or k == 'name':
                    if alldata[v] == "" or alldata[v] is None:
                        raise BaseError(801)
                    data[k] = alldata[v]
                elif k == "update_time":
                    try:
                        data[k] = time.strftime("%Y-%m-%d %H:%M:%S",
                                                time.localtime(time.time()))
                    except Exception as ex:
                        print(ex)
                elif k == "update_id" or k == "parent_id" or k == "parent_code":
                    if alldata[v] is None:
                        pass
                    else:
                        data[k] = alldata[v]
                else:
                    data[k] = alldata[v]
            except:
                pass

        if data is None or data == {}:
            raise BaseError(801)  #参数错误
        id = inst.save(data, id, table='system.menu')
        if id <= 0:
            raise BaseError(703)  #参数错误
        operation_log(self.db).addLog(alldata['update_id'],
                                      alldata['hospital_code'], 'edit_menu',
                                      "修改菜单:" + alldata['name'], alldata['id'])
        self.response(id)
Example #4
0
 def delete(self):
     alldata = self.getRequestData()
     e = entity.Menuadmin(self.db)
     r = e.remove(alldata['id'], delete=True)
     #删除下一级菜单
     e.remove(alldata['id'], key='parent_id', delete=True)
     if r <= 0:
         raise BaseError(703)
     operation_log(self.db).addLog(alldata['uid'], alldata['hospital_code'],
                                   'edit_menu', "删除菜单", alldata['id'])
     self.response(r)
Example #5
0
 def post(self):
     # 取所有权限组
     alldata = self.getRequestData()
     inst = entity.Menuadmin(self.db)
     code = alldata['hos_code']
     cur = self.db.getCursor()
     sql = "select mag.id,mag.name,ha.name create_name,hi.name hospital_name,mag.create_time from system.menu_authority_group mag left join "
     sql += "public.account ha on mag.create_id=ha.id,public.hospital_info hi where hi.code='%s' and mag.hospital_code=hi.code order by mag.id asc" % (
         code)
     cur.execute(sql)
     rows = cur.fetchall()
     data = {}
     data['rows'] = rows
     data['struct'] = "id,name,create_name,hospital_name,create_time"
     self.response(data)
Example #6
0
 def post(self):
     # 取POST Form提交的数据
     alldata = self.getRequestData()
     inst = entity.Menuadmin(self.db)
     user = self.objUserInfo['name']
     #先删除所有
     inst.remove(alldata['user_id'],
                 table="system.menu_authority_relation",
                 key='user_id',
                 delete=True)
     #再循环插入
     #if not alldata['items']:
     #   raise BaseError(801)
     ids = 0
     for menu_item_id in alldata['items']:
         lstData = {
             'menu_item_id':
             menu_item_id,
             'create_time':
             time.strftime("%Y-%m-%d %H:%M:%S",
                           time.localtime(time.time())),
             'user_id':
             alldata['user_id'],
             'create_id':
             alldata['create_id']
         }
         id = inst.save(lstData, table='system.menu_authority_relation')
         if id <= 0:
             raise BaseError(703)  #参数错误
         ids += 1
     cur = self.db.getCursor()
     cur.execute("select name from public.account where id=%s" %
                 alldata['user_id'])
     rows = cur.fetchall()
     oc = rows[0][0]
     operation_log(self.db).addLog(alldata['create_id'],
                                   alldata['hospital_code'],
                                   'menus_aut_user',
                                   "%s给用户%s授予菜单权限" % (user, oc),
                                   alldata['user_id'])
     #msg=Message(self.db)
     #msg.addMsg(alldata['hospital_code'], alldata['hospital_code'],"%s给用户%s授予菜单权限"%(user,oc))
     self.response(ids)