def __init__(self, con): self.con = con self.con.ping(True) self.cur = self.con.cursor() self.userController = UserController(self.con) self.planController = PlanController(self.con) self.srController = SrController(self.con) self.stageController = StageController(self.con) self.commentController = CommentController(self.con) self.messageController = MessageController(self.con)
class DataController(): def __init__(self, con): self.con = con self.con.ping(True) self.cur = self.con.cursor() self.userController = UserController(self.con) self.planController = PlanController(self.con) self.srController = SrController(self.con) self.stageController = StageController(self.con) self.commentController = CommentController(self.con) self.messageController = MessageController(self.con) def getUserIdByName(self, userName): return self.userController.getUserIdByName(userName) def createUser(self, user): return self.userController.createUser(user) def getUserByName(self, userName): return self.userController.getUserByName(userName) def getUserById(self, id): return self.userController.getUserById(id) def updateUserMottoById(self, userId, motto): return self.userController.updateUserMottoById(userId, motto) def createPlan(self, plan): return self.planController.createPlan(plan) def deletePlanById(self, id): return self.planController.deletePlanById(id) def getPlanById(self, id): return self.planController.getPlanById(id) def getPlansByUserId(self, userId): return self.planController.getPlansByUserId(userId) def updatePlan(self, plan): return self.planController.updatePlan(plan) def createSr(self, sr): return self.srController.createSr(sr) def deleteSr(self, sr): return self.srController.deleteSr(sr) def deleteSrsByPlanId(self, planId): return self.srController.deleteSrsByPlanId(planId) def getSrsByUserId(self, userId): return self.srController.getSrsByUserId(userId) def getSrsByPlanId(self, planId): return self.srController.getSrsByPlanId(planId) def createStage(self, stage): return self.stageController.createStage(stage) def deleteStageById(self, id): return self.stageController.deleteStageById(id) def deleteStagesByPlanId(self, planId): return self.stageController.deleteStagesByPlanId(planId) def getStageById(self, id): return self.stageController.getStageById(id) def getStagesByPlanId(self, planId): return self.stageController.getStagesByPlanId(planId) def updateStage(self, stage): return self.stageController.updateStage(stage) def createComment(self, comment): return self.commentController.createComment(comment) def deleteCommentById(self, id): return self.commentController.deleteCommentById(id) def deleteCommentsByPlanId(self, planId): return self.commentController.deleteCommentsByPlanId(planId) def getCommentById(self, id): return self.commentController.getCommentById(id) def getCommentsByPlanId(self, planId): return self.commentController.getCommentsByPlanId(planId) def getCommentsByUserId(self, userId): return self.commentController.getCommentsByUserId(userId) def createMessage(self, message): return self.messageController.createMessage(message) def updateMessage(self, message): return self.messageController.updateMessage(message) def deleteMessageById(self, id): return self.messageController.deleteMessageById(id) def deleteMessagesByPlanId(self, planId): return self.messageController.deleteMessagesByPlanId(planId) def getUnReadMessagesByUserId(self, userId): return self.messageController.getUnReadMessagesByUserId(userId) def getAllMessagesByUserId(self, userId): return self.messageController.getAllMessagesByUserId(userId) def getAllSupervisorsByUserId(self, userId): plans = self.getPlansByUserId(userId) supervisors = list() ids = list() if plans: for plan in plans: srs = self.getSrsByPlanId(plan['id']) for sr in srs: if sr['userId'] not in ids: ids.append(sr['userId']) supervisors.append(self.getUserById(sr['userId'])) return supervisors def getAllSupervisedsByUserId(self, userId): srs = self.getSrsByUserId(userId) superviseds = list() ids = list() for sr in srs: plan = self.getPlanById(sr['planId']) if plan['userId'] not in ids: ids.append(plan['userId']) superviseds.append(self.getUserById(plan['userId'])) return superviseds # get the user info by userId def getUserInfoByUserId(self, userId): user = self.getUserById(userId) supervisors = self.getAllSupervisorsByUserId(userId) superviseds = self.getAllSupervisedsByUserId(userId) plans = self.getPlansByUserId(userId) planNum = len(plans) completedPlanNum = 0 for plan in plans: if plan['unCompletedStageNum'] == 0: completedPlanNum += 1 unReadMessageNum = len(self.getUnReadMessagesByUserId(userId)) return (user, supervisors, superviseds, planNum, completedPlanNum, unReadMessageNum) # use user viewUserId to view the plans of planUserId def getPlansViewByUserId(self, planUserId, viewUserId): user = self.getUserById(planUserId) plans = self.getPlansByUserId(planUserId) plansForView = list() for plan in plans: plan['startTime'] = time.strftime("%Y-%m-%d", time.localtime(plan['startTime'])) plan['endTime'] = time.strftime("%Y-%m-%d", time.localtime(plan['endTime'])) plan['completingRate'] = 100 if plan['unCompletedStageNum'] > 0: plan['completingRate'] = int(round(float(plan['completedStageNum']) \ / (plan['completedStageNum'] + plan['unCompletedStageNum']) * 100)) if viewUserId == plan['userId']: plansForView.append(plan) else: srs = self.getSrsByPlanId(plan['id']) for sr in srs: if sr['userId'] == viewUserId: plansForView.append(plan) break return (user, plansForView) def __del__(self): del self.userController del self.planController del self.srController del self.stageController del self.commentController del self.messageController self.con.commit() self.cur.close()