def deleteContractEmergency(self, jsonInfo): userBaseManager = UserBaseManager() (status, info) = userBaseManager.tokenCheck(jsonInfo=jsonInfo) if status is not True: return (False, info) return self.__doDeleteContractEmergency(info=info)
def createContractProjectProcess(self, jsonInfo): userBaseManager = UserBaseManager() (status, info) = userBaseManager.tokenCheck(jsonInfo=jsonInfo) if status is not True: return (False, info) return self.__doCreateContractProjectProcess(info=info)
def getContractList(self, jsonInfo): userBaseManager = UserBaseManager() (status, info) = userBaseManager.tokenCheck(jsonInfo=jsonInfo) if status is not True: return (False, info) startIndex = info['startIndex'] pageCount = info['pageCount'] try: allResult = db.session.query( Contract ).offset(startIndex).limit(pageCount).all() count = db.session.query(func.count(Contract.contractID)).first() if count is None: count = 0 else: count = count[0] dataList = [self.__generateContractBrief(o=o) for o in allResult] dataInfo = {} dataInfo['dataList'] = dataList dataInfo['count'] = count 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)
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)
def getContractFileList(self, jsonInfo): userBaseManager = UserBaseManager() (status, info) = userBaseManager.tokenCheck(jsonInfo=jsonInfo) if status is not True: return (False, info) imgManager = ImageManager() info['foreignID'] = info['contractID'] return imgManager.getImageList(info=info)
def deleteContractFile(self, jsonInfo): userBaseManager = UserBaseManager() (status, info) = userBaseManager.tokenCheck(jsonInfo=jsonInfo) if status is not True: return (False, info) imgManager = ImageManager() info['directory'] = 'contract' return imgManager.deleteImage(info=info)
def addFileToContract(self, jsonInfo): userBaseManager = UserBaseManager() (status, info) = userBaseManager.tokenCheck(jsonInfo=jsonInfo) if status is not True: return (False, info) info['foreignID'] = info['contractID'] imgManager = ImageManager() return imgManager.addImageListWithoutOSS(info=info)
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)
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)
def deleteContract(self, jsonInfo): userBaseManager = UserBaseManager() (status, info) = userBaseManager.tokenCheck(jsonInfo=jsonInfo) if status is not True: return (False, info) contractID = info['contractID'] # 检查是否存在突发事件 contractEmergencyManager = ContractEmergencyManager() (status, reason) = contractEmergencyManager.checkEmergency(info=info) if status is not True: return (False, reason) contractFinalAccountsManager = ContractFinalAccountsManager() (status, reason) = contractFinalAccountsManager.checkAccount(info=info) if status is not True: return (False, reason) contractProjectProcessManager = ContractProjectProcessManager() (status, reason) = contractProjectProcessManager.checkProcess(info=info) if status is not True: return (False, reason) fileInfoManager = FileInfoManager() info['areaID'] = contractID (status, reason) = fileInfoManager.checkFileExists(info=info) if status is not True: return (False, reason) try: # 在删除contract之前,要先删除文件,和其他列表 db.session.query(Contract).filter( Contract.contractID == contractID ).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)
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)
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)
def getContractDetail(self, jsonInfo): userBaseManager = UserBaseManager() (status, info) = userBaseManager.tokenCheck(jsonInfo=jsonInfo) if status is not True: return (False, info) contractID = info['contractID'] try: result = db.session.query(Contract).filter( Contract.contractID == contractID ).first() dataInfo = {} dataInfo.update(Contract.generate(o=result)) 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)
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)
def getContractFinalAccountList(self, jsonInfo): userBaseManager = UserBaseManager() (status, info) = userBaseManager.tokenCheck(jsonInfo=jsonInfo) if status is not True: return (False, info) return self.__doGetContractFinalAccountList(info=info)
def updateContract(self, jsonInfo): userBaseManager = UserBaseManager() (status, info) = userBaseManager.tokenCheck(jsonInfo=jsonInfo) if status is not True: return (False, info) contractID = info['contractID'] try: # 在删除contract之前,要先删除文件,和其他列表 query = db.session.query(Contract).filter( Contract.contractID == contractID ) if info.has_key('createTime'): if info['createTime'] == '': createTime = None else: createTime = info['createTime'] else: createTime = None if info.has_key('contractPrice'): if info['contractPrice'] == '': contractPrice = None else: contractPrice = info['contractPrice'] else: contractPrice = None if info.has_key('biddingDate'): if info['biddingDate'] == '': biddingDate = None else: biddingDate = info['biddingDate'] else: biddingDate = None if info.has_key('contractRecordDate'): if info['contractRecordDate'] == '': contractRecordDate = None else: contractRecordDate = info['contractRecordDate'] else: contractRecordDate = None query.update({ Contract.title : info['title'], Contract.serialNumber : info['serialNumber'], Contract.createTime : createTime, Contract.projectTypeName : info['projectTypeName'], Contract.operationTypeName : info['operationTypeName'], Contract.contractPrice : contractPrice, Contract.contractWorkContent : info['contractWorkContent'], Contract.contractor : info['contractor'], Contract.responsiblePerson : info['responsiblePerson'], Contract.biddingDate : biddingDate, Contract.contractRecordDate : contractRecordDate, Contract.contractKeepingDeprt : info['contractKeepingDeprt'], Contract.archiveInfo : info['archiveInfo'], Contract.contractDuration : info['contractDuration'] }, 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)