Пример #1
0
    def doDelete(self, table, fields=["id"], cfields="id,create_id", res=True):
        data = self.getReq(fields, None)
        if not data:
            raise BaseError(801)
        db = self.getDB(table)

        #pre delete callback
        if hasattr(self, "preDelete"):
            preDelete = self.preDelete
            results = db.findByAttr(cfields, data)
            if False == preDelete(results["rows"], data):
                raise BaseError(801)
            db.select(table)
        ret = db.deleteByAttr(data)

        #post update callback
        if hasattr(self, "postDelete"):
            postDelete = self.postDelete
            if False == postDelete(ret, data):
                raise BaseError(801)

        r = {"result": ret}
        if res:
            self.response(r)
        return r
Пример #2
0
    def doAdd(self, table, fileds, optional, preAdd=None, postAdd=None):
        data = self.getReq(fileds, optional)
        if not data:
            raise BaseError(801)
        data["create_id"] = self.user["id"]
        # if hoscode:
        # 	data["create_hoscode"] = self.user["hospital_code"]

        #pre add callback
        if not preAdd and hasattr(self, "preAdd"):
            preAdd = self.preAdd
        if preAdd and preAdd(data) == False:
            raise BaseError(801)

        db = self.getDB(table)
        D("doAdd====>" + table)
        results = db.add(data)

        #post add callback
        if not postAdd and hasattr(self, "postAdd"):
            postAdd = self.postAdd
        if postAdd and postAdd(results, data) == False:
            raise BaseError(801)

        #D(results)
        self.response(results)
Пример #3
0
    def doAction(self):
        data = self.getReq("action", None)
        if not data:
            raise BaseError(801)

        action = str(data["action"])
        if not hasattr(self, action):
            raise BaseError(801)

        actionFunc = getattr(self, action)
        if isAction(actionFunc):
            actionFunc()
        else:
            raise BaseError(801)
Пример #4
0
    def getRequestData(self):
        if hasattr(self, "objRequestBody"):
            return self.objRequestBody
        try:
            objRequestBody = ujson.loads(self.request.body.decode('utf-8'))
            #objRequestBody=json.loads(self.request.body.decode('utf-8'))
        except:
            raise BaseError(801)  # 参数错误

        if objRequestBody == None:
            raise BaseError(801)  # 参数错误
        else:
            self.objRequestBody = objRequestBody
            return objRequestBody
Пример #5
0
    def put(self):
        alldata = self.getRequestData()

        # 更新的时候只能更新路径
        lsData = {'id': 'id', 'menu_code': 'menu_code', 'path': 'path'}

        data = {}
        for (k, v) in lsData.items():
            try:
                data[k] = alldata[v]
            except:
                pass

        if 'id' not in data or 'path' not in data or 'menu_code' not in data:
            raise BaseError(801, "参数错误:缺少菜单项数据!")

        data['update_id'] = self.objUserInfo['id']
        data['update_time'] = datetime.datetime.now().strftime(
            '%Y-%m-%d %H:%M:%S')

        s = MenuItem(self.db)
        id = s.save(data, data['id'], table="system.menu_item")

        operation_log(self.db).addLog(
            self.GetUserInfo(), "menuItemManage",
            "更新菜单项: code: %s, path: %s" % (data['menu_code'], data['path']),
            id)

        self.response(id)
Пример #6
0
    def post(self):
        alldata = self.getRequestData()

        lsData = {
            'menu_code': 'menu_code',
            'menu_id': 'menu_id',
            'path': 'path'
        }

        data = {}
        for (k, v) in lsData.items():
            try:
                data[k] = alldata[v]
            except:
                pass

        if 'menu_code' not in data or 'menu_id' not in data or 'path' not in data:
            raise BaseError(801, "参数错误:缺少菜单项数据!")

        db = self.getDB("system.menu")

        # 检查菜单是否存在
        result = db.findByCond("code", "id = %d" % (data['menu_id']))
        if len(result['rows']) == 0:
            raise BaseError(801, "数据错误:菜单 %s 不存在!" % (data['code']))

        # 检查菜单是否已经有菜单项
        db = self.getDB("system.menu_item")

        result = db.findByCond("id", "menu_code = '%s' " % (data['menu_code']))
        if len(result['rows']) > 0:
            raise BaseError(
                801,
                "数据错误:菜单编号 %s 已经有菜单项!当前模式下,一个菜单只能有一个菜单项。" % (data['code']))

        data['create_id'] = self.objUserInfo['id']
        data['create_time'] = datetime.datetime.now().strftime(
            '%Y-%m-%d %H:%M:%S')

        s = MenuItem(self.db)
        id = s.save(data, table="system.menu_item")
        operation_log(self.db).addLog(
            self.GetUserInfo(), "menuItemManage",
            "创建菜单项: code: %s, path: %s" % (data['menu_code'], data['path']),
            id)

        self.response(id)
Пример #7
0
 def gen_status(self, *args, **kwargs):
     result = None, None
     try:
         result = func(self, *args, **kwargs)
         func(self, *args, **kwargs)
     except:
         raise BaseError(801)  # 参数错误
     return result
Пример #8
0
    def doAddRst(self, table, fileds, optional, preAdd=None, postAdd=None):
        data = self.getReq(fileds, optional)
        if not data:
            raise BaseError(801)
        data["create_id"] = self.user["id"]
        data["create_time"] = self.now_time()
        # data["hospital_code"] = self.user["hospital_code"]

        if preAdd and not preAdd(data):
            raise BaseError(801)

        db = self.getDB(table)
        # D("doAdd====>" + table)
        results = db.add(data)

        if postAdd and not postAdd(results, data):
            raise BaseError(801)

        # D(results)
        self.response(results)
Пример #9
0
    def doUpdate(self,
                 table,
                 fileds,
                 optional,
                 cfields,
                 preUpdate=None,
                 postUpdate=None):
        data = self.getReq(fileds, optional)
        if not data:
            raise BaseError(801)

        db = self.getDB(table)
        _id = data["id"]

        #pre update callback
        if not preUpdate and hasattr(self, "preUpdate"):
            preUpdate = self.preUpdate
        if preUpdate:
            obj = db.findById(cfields, _id)
            if not obj:
                raise BaseError(802)
            if False == preUpdate(obj, data):
                raise BaseError(801)
            #select table again after check
            db.select(table)

        self.setUpdateInfo(data)

        #D("doUpdate====>" + table)
        #D(data)
        result = db.update(data, ids=_id)
        # D(result)

        #post update callback
        if not postUpdate and hasattr(self, "postUpdate"):
            postUpdate = self.postUpdate
        if postUpdate:
            if False == postUpdate(result, data):
                raise BaseError(801)

        self.response(result)
Пример #10
0
    def getRequestArguments(self):
        try:
            data = self.request.arguments
            if data == {}:
                return {}

            #objRequestBody=json.loads(self.request.arguments.decode('utf-8'))
            objData = {}
            for (k, v) in data.items():
                objData[k] = v[0].decode('utf-8')
            return objData
        except:
            raise BaseError(801)  # 参数错误
Пример #11
0
    def gen_status(self, *args, **kwargs):
        #result = None, None

        try:
            self.init()
            self.db = self.openDB()
            func(self, *args, **kwargs)
            self.closeDB()
        except Exception as e:
            if isinstance(e, BaseError):
                # help=True 将显示错误信息
                self.returnErrorInfo(e, help=True)
            else:
                self.returnErrorInfo(BaseError(900), help=True)
Пример #12
0
    def __init(self, *args, **kwargs):
        self._db_ = None

        self.objUserInfo = None
        self._now_time_ = None
        self._now_date_ = None

        # if not hasattr(self, "useHisDb") :
        # 	self.useHisDb = False

        self.objUserInfo = self.getUserToObjct()
        self.user = self.objUserInfo

        if not self.objUserInfo:
            if self.checkUnauthAccess():
                return
            raise BaseError(602)  # 未登录
Пример #13
0
 def doDeleteMine(self,
                  table,
                  fields=["id"],
                  cfields="id,create_id",
                  res=True):
     data = self.getReq(fields, None)
     data["create_id"] = self.user["id"]
     db = self.getDB(table)
     #pre delete callback
     if hasattr(self, "preDelete"):
         preDelete = self.preDelete
         results = db.findByAttr(cfields, data)
         if False == preDelete(results["rows"], data):
             raise BaseError(801)
     ret = db.deleteByAttr(data)
     data["result"] = ret
     if res:
         self.response(data)
     return data
Пример #14
0
    def delete(self):
        alldata = self.getRequestData()
        e = MenuItem(self.db)

        if 'id' not in alldata:
            raise BaseError(801, "参数错误:缺少待删除的菜单项ID")

        sql = " select mi.menu_code, mi.path from system.menu_item mi "
        sql += " where mi.id = %s" % alldata['id']

        cur = self.db.getCursor()
        cur.execute(sql)
        rows = cur.fetchall()
        key = ['menu_code', 'path']
        data = dict(zip(key, rows[0]))

        r = e.remove(alldata['id'], table='system.menu_item', delete=True)

        operation_log(self.db).addLog(
            self.GetUserInfo(), "menuItemManage",
            "删除菜单项:code: %s, path: %s" % (data['menu_code'], data['path']), r)
        self.response(r)
Пример #15
0
    def get(self):

        menuID = self.get_argument("mid", default='')
        if menuID == '':
            raise BaseError(801)

        sql = """
            select mi.*, ac.name, m.name  
            from system.menu_item mi 
            left join system.account ac on mi.create_id = ac.id 
            inner join system.menu m on m.id = mi.menu_id 
            where mi.menu_id = %s
            """ % menuID

        cur = self.db.getCursor()
        cur.execute(sql)
        rows = cur.fetchall()

        rowdata = {}
        rowdata['rows'] = rows
        rowdata[
            'struct'] = "id, create_time, update_time, create_id, update_id, menu_code, menu_id, path, create_name, menu_name"

        self.response(rowdata)
Пример #16
0
 def onError(self, code):
     raise BaseError(code)
Пример #17
0
 def checkAppKey(self):
     if self.request.headers.get('app-key') != config.App_Key:
         raise BaseError(601)