Beispiel #1
0
    def __exchange_apply_by_user_name(self, user_name, present_id):
        present_exchange = self.db.query(ExchangeRulesModule).filter(
            ExchangeRulesModule.id == present_id).first()

        # 1、判断规则是否存在
        if present_exchange is None:
            logging.info("present min point is None")
            return False
        # 2、判断当前可兑换积分是否满足当前需要兑换物品的最小积分
        current = self.__get_current_point(user_name)
        if current["exchange"] < present_exchange.exchange_min_score:
            logging.info(
                "current point [%d], need point [%d]" %
                (current["exchange"], present_exchange.exchange_min_score))
            return False

        logging.info("current point [%d], exchanged point [%d]" %
                     (current["current"], current["exchange"]))

        date_kits = DateToolKits()
        exchange_apply = ExchangeApplyModule()
        exchange_apply.exchange_accept = False
        exchange_apply.exchange_status = "apply"
        exchange_apply.user_name = user_name
        exchange_apply.current_scores = current["current"]
        exchange_apply.exchange_item = present_exchange.exchange_rule_name
        exchange_apply.datetime = date_kits.get_now_time()
        exchange_apply.need_score = present_exchange.exchange_rule_score
        self.db.add(exchange_apply)
        self.db.commit()
        return True
Beispiel #2
0
    def __set_attendance_leave_accept_by_user_name(self, user_name):
        attendance = self.db.query(AttendanceModule).filter(AttendanceModule.user_name == user_name).first()

        if attendance is not None:
            score_criteria = self.db.query(ScoringCriteriaModule).filter(ScoringCriteriaModule.id == attendance.absence_id).first()
            # 1. 更新积分表
            user_score = self.db.query(ScoreInfoModule).filter(ScoreInfoModule.user_name == user_name).first()

            score = user_score.current_scores + score_criteria.score_value
            recharge = False

            if user_score.purchase_points is True:
                if score > DefaultScoreConfig.current_scores:
                    recharge = True

            if user_score and score_criteria:
                self.db.query(ScoreInfoModule).filter(ScoreInfoModule.user_name == user_name).update({
                    ScoreInfoModule.last_scores: user_score.current_scores,
                    ScoreInfoModule.current_scores: score,
                    ScoreInfoModule.purchase_points: recharge,
                })
                self.db.commit()
            else:
                return False
            # 2. 更新出勤表
            date_kits = DateToolKits()
            self.db.query(AttendanceModule).filter(AttendanceModule.user_name == user_name).update({
                AttendanceModule.checked_in: True,
                AttendanceModule.attended: True,
                AttendanceModule.absence_apply_accept: True,
                AttendanceModule.checked_in_time: date_kits.get_now_str(),
            })
            self.db.commit()
            logging.info("modify attendance succeed")

            # 3.更新积分历史信息表
            date_kits = DateToolKits()
            history_module = ScoringHistoryModule()
            history_module.user_name = user_name
            history_module.criteria_id = score_criteria.id
            history_module.criteria_name = score_criteria.criteria_name
            history_module.score_value = score_criteria.score_value  # 对应分数
            history_module.transactor = self.get_current_user()  # 处理人
            history_module.date_time = date_kits.get_now_time()  # 处理时间
            self.db.add(history_module)
            self.db.commit()
            opt = "absent sub score"
            self.record_operation_history(user_name, opt)

            return True
        else:
            logging.error("modify attendance failed")
            return False
Beispiel #3
0
    def __evaluate_by_issues_id(self, issues_id, prepare_score, novel_score,
                                report_score):
        issues_module = self.db.query(IssuesInfoModule).filter(
            IssuesInfoModule.id == issues_id).first()

        if issues_module is None:
            return False, "没有待评价议题"

        user_name = self.get_current_user()

        if user_name is None:
            return False, "获取用户失败"

        evaluation = self.db.query(EvaluationInfoModule).filter(EvaluationInfoModule.issues_id == issues_id).\
            filter(EvaluationInfoModule.evaluate_user_name == user_name).first()
        if evaluation:
            self.db.query(EvaluationInfoModule).filter(
                EvaluationInfoModule.issues_id == issues_id).update(
                    {EvaluationInfoModule.evaluate_finish: False})
            self.db.commit()
            logging.info("already evaluate")
            return False, "您已评价该议题"

        date_kits = DateToolKits()
        evaluation_module = EvaluationInfoModule()
        evaluation_module.issues_id = issues_module.id  # 议题ID
        evaluation_module.issues_title = issues_module.issues_title  # 议题名称
        evaluation_module.keynote_user_name = issues_module.user_name  # 主讲人用户名
        evaluation_module.evaluate_user_name = user_name  # 评价者用户名
        evaluation_module.evaluate_time = date_kits.get_now_time()  # 评价时间

        evaluation_module.issues_prepare_score = prepare_score  # 议题准备情况得分
        evaluation_module.issues_content_score = novel_score  # 议题内容得分
        evaluation_module.issues_lecture_score = report_score  # 演讲情况得分
        evaluation_module.issues_reserved_score = 0  # 保留备用
        evaluation_module.evaluate_finish = False  # 是否结束评价

        self.db.add(evaluation_module)
        self.db.commit()

        logging.info("issues_evaluate_count:%d" %
                     issues_module.issues_evaluate_count)
        self.db.query(IssuesInfoModule).filter(
            IssuesInfoModule.id == issues_id).update({
                IssuesInfoModule.issues_evaluate_count:
                issues_module.issues_evaluate_count + 1,
            })
        self.db.commit()

        return True, "评价议题成功"
Beispiel #4
0
    def __attendance_sign_by_user_name(self, user_name):
        attendance = self.db.query(AttendanceModule).filter(AttendanceModule.user_name == user_name).first()
        date_kits = DateToolKits()

        if attendance is not None:
            # 1.更新签到表
            self.db.query(AttendanceModule).filter(AttendanceModule.user_name == user_name).update({
                AttendanceModule.checked_in: True,
                AttendanceModule.attended: True,
                AttendanceModule.absence_apply_accept: False,
                AttendanceModule.checked_in_time: date_kits.get_now_str()
            })
            self.db.commit()
            logging.info("=====>modify attendance succeed")

            # 2. 如果是组织者,加分
            organizer = self.db.query(OrganizerInfoModule).filter(OrganizerInfoModule.user_name == user_name).first()
            if organizer:
                logging.info("=====>%s is current organizer" % user_name)
                if organizer.current is True:
                    logging.info("*******>%s is current organizer" % user_name)
                    # 2.1. 更新积分表
                    score_criteria = self.db.query(ScoringCriteriaModule).filter(
                        ScoringCriteriaModule.criteria_name == "例会主持").first()
                    user_score = self.db.query(ScoreInfoModule).filter(ScoreInfoModule.user_name == user_name).first()
                    if user_score and score_criteria:
                        self.db.query(ScoreInfoModule).filter(ScoreInfoModule.user_name == user_name).update({
                            ScoreInfoModule.last_scores: user_score.current_scores,
                            ScoreInfoModule.current_scores: user_score.current_scores + score_criteria.score_value,
                        })
                        self.db.commit()

                        # 2.2. 更新积分历史信息表
                        date_kits = DateToolKits()
                        history_module = ScoringHistoryModule()
                        history_module.user_name = user_name
                        history_module.criteria_id = score_criteria.id
                        history_module.criteria_name = score_criteria.criteria_name
                        history_module.score_value = score_criteria.score_value  # 对应分数
                        history_module.transactor = self.get_current_user()  # 处理人
                        history_module.date_time = date_kits.get_now_time()  # 处理时间
                        self.db.add(history_module)
                        self.db.commit()
                        opt = "add organizer score"
                        self.record_operation_history(user_name, opt)

            return True
        else:
            logging.error("modify attendance failed")
            return False
Beispiel #5
0
    def __check_date_time_is_valid(self):
        date_time_valid = False
        date_kits = DateToolKits()

        meetings = self.db.query(MeetingInfoModule).filter(MeetingInfoModule.current_meeting == True).all()
        min_date_time = meetings[0].meeting_date

        if meetings:
            for meeting in meetings:
                if date_kits.compare_time_src_less_then_dest(min_date_time, meeting.meeting_date) is False:
                    min_date_time = meeting.meeting_date
            logging.info(min_date_time)
            if date_kits.compare_time_src_less_then_dest(min_date_time, date_kits.get_now_time()) is True:
                date_time_valid = True

        logging.info(date_time_valid)
        return date_time_valid
Beispiel #6
0
    def __leave_apply_by_id(self, user_name, leave_id, leave_date):
        criteria = self.db.query(ScoringCriteriaModule).filter(
            ScoringCriteriaModule.id == leave_id).first()
        if criteria is None:
            logging.error("not scoring criteria exist, leave_id = %s" %
                          leave_id)
            return False
        attendance = self.db.query(AttendanceModule).filter(
            AttendanceModule.user_name == user_name).first()

        if attendance is None:
            logging.error("not attendance exist user_name=%s" % user_name)
            return False

        date_kits = DateToolKits()
        absence_apply_time = date_kits.get_now_time()  # 申请时间

        self.db.query(AttendanceModule).filter(
            AttendanceModule.user_name == user_name).update({
                AttendanceModule.absence_reason:
                criteria.criteria_name,
                AttendanceModule.absence_id:
                criteria.id,
                AttendanceModule.attended:
                False,
                AttendanceModule.absence_apply_accept:
                False,
                AttendanceModule.absence_apply_time:
                absence_apply_time,
                AttendanceModule.date_time:
                leave_date,
            })

        self.db.commit()
        logging.info("user leave apply  succeed")

        return True
Beispiel #7
0
    def __mark_interested_by_issues_id(self, issues_id, interested, user_name):

        issues_module = self.db.query(IssuesInfoModule).filter(
            IssuesInfoModule.id == issues_id).first()

        if issues_module:
            assessment_module = self.db.query(AssessmentInfoModule).filter(AssessmentInfoModule.issues_id == issues_id).\
                filter(AssessmentInfoModule.assessment_user_name == user_name).first()

            interested_count = issues_module.interested_count
            uninterested_count = issues_module.uninterested_count
            date_kits = DateToolKits()
            #  已存在
            if assessment_module:
                if interested is True:
                    if assessment_module.interested is True:
                        return True, "评估议题成功"
                    else:
                        interested_count = interested_count + 1
                        uninterested_count = uninterested_count - 1
                else:
                    if assessment_module.interested is False:
                        return True, "评估议题成功"
                    else:
                        interested_count = interested_count - 1
                        uninterested_count = uninterested_count + 1

                self.db.query(AssessmentInfoModule).filter(
                    AssessmentInfoModule.issues_id == issues_id).update({
                        AssessmentInfoModule.interested:
                        interested,
                    })
                self.db.commit()

                self.db.query(IssuesInfoModule).filter(
                    IssuesInfoModule.id == issues_id).update({
                        IssuesInfoModule.interested_count:
                        interested_count,
                        IssuesInfoModule.uninterested_count:
                        uninterested_count,
                    })
                self.db.commit()

                return True, "评估议题成功"
            else:  # 不存在
                assessments = AssessmentInfoModule()
                assessments.issues_id = issues_id  # 议题ID
                assessments.assessment_user_name = user_name  # 评估者
                assessments.assessment_time = date_kits.get_now_time()  # 评估时间
                assessments.assessment_finish = False
                if interested is True:
                    assessments.interested = True
                    interested_count = interested_count + 1
                else:
                    assessments.interested = False
                    uninterested_count = uninterested_count + 1

                self.db.add(assessments)
                self.db.commit()

                self.db.query(IssuesInfoModule).filter(
                    IssuesInfoModule.id == issues_id).update({
                        IssuesInfoModule.interested_count:
                        interested_count,
                        IssuesInfoModule.uninterested_count:
                        uninterested_count,
                    })
                self.db.commit()
                return True, "评估议题成功"

        else:
            return False, "没有待评估议题"