예제 #1
0
    def getFileListByUser(self, jsonInfo):
        info = json.loads(jsonInfo)
        tokenID = info['tokenID']
        (status, userID) = self.isTokenValid(tokenID)
        if status is not True:
            errorInfo = ErrorInfo['TENDER_01']
            return (False, errorInfo)
        info['userID'] = userID

        userBaseManager = UserBaseManager()
        (status, userInfo) = userBaseManager.getUserInfo(info=info)
        if status is not True:
            return (False, userInfo)
        userType = userInfo['userType']

        info['userType'] = userType
        info = self.__getBaseQuery(info=info)
        info = self.__addFilterToQuery(info=info)
        query = info['query']
        countQuery = info['countQuery']
        dataResult = {}

        allResult = query.all()
        dataList = [self.__generateFileInfo(o=o) for o in allResult]
        count = countQuery.first()
        if count is None:
            count = 0
        else:
            count = count[0]
        dataResult['dataList'] = dataList
        dataResult['count'] = count
        return (True, dataResult)
예제 #2
0
    def createContract(self, jsonInfo):
        info = json.loads(jsonInfo)
        tokenID = info['tokenID']
        (status, userID) = self.isTokenValid(tokenID)
        if status is not True:
            errorInfo = ErrorInfo['TENDER_01']
            return (False, errorInfo)

        info['userID'] = userID
        userBaseManager = UserBaseManager()
        (status, userInfo) = userBaseManager.getUserInfo(info=info)
        if status is not True:
            return (False, userInfo)

        userBaseManager = UserBaseManager()
        info['operationTag'] = RIGHT_TAG_CONTRACT
        (status, reason) = userBaseManager.checkRight(info=info)
        if status is not True:
            return (False, ErrorInfo['TENDER_50'])

        (status, contractID) = self.__doCreateContract(info=info)
        imgManager = ImageManager()
        info['foreignID'] = contractID
        (status, reason) = imgManager.addImageListWithoutOSS(info=info)
        if status is not True:
            return (False, reason)
        return (True, contractID)
예제 #3
0
    def deleteFileInfo(self, info):
        userID = info['userID']
        fileID = info['fileID']

        try:
            # 先删除oss文件

            query = db.session.query(FileInfo).filter(
                FileInfo.fileID == fileID)

            dataResult = query.first()

            if dataResult is None:
                return (False, ErrorInfo['TENDER_40'])
            # 文件夹暂时不让删除
            if dataResult.isDirectory is True:
                superID = dataResult.fileID
                # 查看文件夹下是否有文件
                dirResult = db.session.query(FileInfo).filter(
                    FileInfo.superID == superID).first()
                if dirResult is not None:
                    return (False, ErrorInfo['TENDER_45'])
                query.delete(synchronize_session=False)
                db.session.commit()
                return (True, None)
                # return (False, ErrorInfo['TENDER_40'])
            filePath = dataResult.filePath
            deleteList = ['files/%s' % filePath]
            self.deleteOSSImages(deleteList, self.ossInfo)

            createUserID = dataResult.userID
            # 先判断是否是文件的创建者
            if userID != createUserID:
                userBaseManager = UserBaseManager()
                (status, userInfo) = userBaseManager.getUserInfo(info=info)
                if status is not True:
                    return (False, userInfo)
                userType = userInfo['userType']
                # 只有boss才能删除
                if userType != USER_TAG_BOSS:
                    return (False, ErrorInfo['TENDER_39'])
            query.delete(synchronize_session=False)
            db.session.commit()
            return (True, None)
        except Exception as e:
            print e
            traceback.print_exc()
            errorInfo = ErrorInfo['TENDER_02']
            errorInfo['detail'] = str(e)
            db.session.rollback()
            return (False, errorInfo)
예제 #4
0
    def renameDirectory(self, jsonInfo):
        info = json.loads(jsonInfo)
        tokenID = info['tokenID']
        (status, userID) = self.isTokenValid(tokenID)
        if status is not True:
            errorInfo = ErrorInfo['TENDER_01']
            return (False, errorInfo)

        info['userID'] = userID
        userBaseManager = UserBaseManager()
        (status, userInfo) = userBaseManager.getUserInfo(info=info)
        if status is not True:
            return (False, userInfo)
        userType = userInfo['userType']

        info['userType'] = userType
        return self.doRenameDirectory(info=info)
예제 #5
0
    def getTenderDetailForWechatApp(self, jsonInfo):
        info = json.loads(jsonInfo)
        tokenID = info['tokenID']
        (status, userID) = self.isTokenValid(tokenID)
        # 权限校验在getTenderDetail里
        (status, dataInfo) = self.getTenderDetail(jsonInfo=jsonInfo)
        if status is not True:
            return (False, dataInfo)

        info = json.loads(jsonInfo)
        tenderID = info['tenderID']
        try:
            result = db.session.query(PushedTenderInfo).filter(
                PushedTenderInfo.tenderID == tenderID).first()
            if result is None:
                return (False, ErrorInfo['TENDER_04'])
            dataInfo['deadline'] = str(result.deadline)
            dataInfo['state'] = result.state
            pushedTenderManager = PushedTenderManager()
            params = {}
            params['pushedTenderInfo'] = result
            params['userType'] = USER_TAG_BOSS
            userBaseManager = UserBaseManager()
            info['userID'] = userID
            (status, userInfo) = userBaseManager.getUserInfo(info=info)
            params['customizedCompanyID'] = userInfo['customizedCompanyID']
            params['selfUserType'] = USER_TAG_BOSS
            (status, pushedUserList) = pushedTenderManager.getPushedUserList(
                info=params)
            dataInfo['pushedUserList'] = pushedUserList
            soup = BeautifulSoup(dataInfo['detail'], 'lxml')
            detail = soup.get_text().encode("utf-8")
            dataInfo['detail'] = detail.strip()
            return (True, dataInfo)
        except Exception as e:
            print e
            traceback.print_exc()
            errorInfo = ErrorInfo['TENDER_02']
            errorInfo['detail'] = str(e)
            db.session.rollback()
            return (False, errorInfo)
예제 #6
0
    def getAreaTreeWithoutUserID(self, jsonInfo):
        info = json.loads(jsonInfo)
        tokenID = info['tokenID']
        (status, userID) = self.isTokenValid(tokenID)
        if status is not True:
            errorInfo = ErrorInfo['TENDER_01']
            return (False, errorInfo)
        info['userID'] = userID
        userBaseManager = UserBaseManager()
        (status, userInfo) = userBaseManager.getUserInfo(info=info)
        if status is not True:
            return (False, userInfo)
        userType = userInfo['userType']
        departmentRightManager = DepartmentRightManager()
        (status, rightDic) = departmentRightManager.getRightDicByUserID(info=info)
        if status is not True:
            return (False, rightDic)
        try:
            query = db.session.query(Department, DepartmentArea, DepartmentRight).outerjoin(
                DepartmentArea, Department.departmentID == DepartmentArea.departmentID
            )

            allResult = query.all()
            departmentDic = {}
            areaDic = {}
            def __generate(o, departmentDic):
                department = o.Department
                area = o.DepartmentArea

                departmentID = department.departmentID
                # if userType != USER_TAG_BOSS and not rightDic.has_key(departmentID):
                #     return None
                # 先将所有的department加入,然后再遍历一遍,将areaList为空的去掉
                if not departmentDic.has_key(departmentID):
                    res = {}
                    areaList = []
                    if area is not None:
                        areaID = area.areaID
                        if userType == USER_TAG_BOSS or rightDic.has_key(areaID):
                            if not areaDic.has_key(areaID):
                                areaObject = DepartmentArea.generate(o=area)
                                areaList.append(areaObject)
                                areaDic[areaID] = True
                    departmentDic[departmentID] = areaList
                    res['departmentID'] = departmentID
                    res['departmentName'] = department.departmentName
                    res['areaList'] = areaList
                    return res
                else:
                    if area is not None:
                        areaID = area.areaID
                        if userType == USER_TAG_BOSS or rightDic.has_key(area.areaID):
                            if not areaDic.has_key(areaID):
                                areaList = departmentDic[departmentID]
                                areaObject = DepartmentArea.generate(o=area)
                                areaList.append(areaObject)
                                areaDic[areaID] = True

            departmentList = [__generate(o=o, departmentDic=departmentDic) for o in allResult]
            departmentList = filter(None, departmentList)
            if userType != USER_TAG_BOSS:
                departmentList = [o for o in departmentList if len(o['areaList'])>0 or rightDic.has_key(o['departmentID'])]
            return (True, departmentList)

        except Exception as e:
            print e
            traceback.print_exc()
            errorInfo = ErrorInfo['TENDER_02']
            errorInfo['detail'] = str(e)
            db.session.rollback()
            return (False, errorInfo)