async def post(self, category_id):
     r_dict = {'code': 0}
     try:
         subject_category = await SubjectCategory.get_by_id(category_id)
         title = self.get_argument('title', None)
         status = self.get_argument('status', None)  # 状态
         comment = self.get_argument('comment', None)
         if subject_category and title:
             t_count = await SubjectCategory.count(
                 dict(title=title, id={'$ne': ObjectId(category_id)}))
             if t_count > 0:
                 r_dict['code'] = -2
             else:
                 if status == 'on':
                     status = STATUS_SUBJECT_CATEGORY_ACTIVE
                 else:
                     status = STATUS_SUBJECT_CATEGORY_INACTIVE
                 subject_category.title = title
                 subject_category.status = status
                 subject_category.comment = comment if comment else None
                 subject_category.updated_dt = datetime.datetime.now()
                 subject_category.updated_id = self.current_user.oid
                 await subject_category.save()
                 r_dict['code'] = 1
         else:
             if not title:
                 r_dict['code'] = -1
     except RuntimeError:
         logger.error(traceback.format_exc())
     return r_dict
示例#2
0
 async def post(self):
     r_dict = {'code': 0}
     open_id = self.get_i_argument('open_id', None)
     race_cid = self.get_i_argument('race_cid', None)
     if not race_cid:
         r_dict['code'] = 1001
         return r_dict
     member = await find_member_by_open_id(open_id)
     if not member:
         r_dict['code'] = 1002
         return r_dict
     try:
         company_title_list = []
         company_dict = {}
         company_list = await Company.find({
             'race_cid':
             race_cid,
             'record_flag':
             1,
             "status":
             STATUS_UNIT_MANAGER_ACTIVE
         }).to_list(None)
         if company_list:
             for company in company_list:
                 company_title_list.append(company.title)
                 company_dict[company.title] = company.cid
         r_dict['code'] = 1000
         r_dict['company_title_list'] = company_title_list
         r_dict['company_dict'] = company_dict
     except Exception:
         logger.error(traceback.format_exc())
     return r_dict
示例#3
0
 async def post(self):
     r_dict = {'code': 0}
     open_id = self.get_i_argument('open_id', None)
     race_cid = self.get_i_argument('race_cid', None)
     if not race_cid:
         r_dict['code'] = 1001
         return r_dict
     member = await find_member_by_open_id(open_id)
     if not member:
         r_dict['code'] = 1002
         return r_dict
     try:
         race = await Race.find_one({'cid': race_cid, 'record_flag': 1})
         race_map = await RaceMapping.find_one({
             'member_cid': member.cid,
             'race_cid': race_cid,
             'record_flag': 1
         })
         if race.mobile_enabled:
             r_dict['mobile_enabled'] = True
         if race_map and race_map.mobile:
             r_dict['mobile_enabled'] = False
         r_dict['code'] = 1000
     except Exception:
         logger.error(traceback.format_exc())
     return r_dict
 async def post(self):
     r_dict = {'code': 0}
     subject_category_id = None
     try:
         title = self.get_argument('title', None)
         status = self.get_argument('status', None)  # 状态
         comment = self.get_argument('comment', None)
         if title:
             t_count = await SubjectCategory.count(dict(title=title))
             if t_count > 0:
                 r_dict['code'] = -2
             else:
                 if status == 'on':
                     status = STATUS_SUBJECT_CATEGORY_ACTIVE
                 else:
                     status = STATUS_SUBJECT_CATEGORY_INACTIVE
                 subject_category = SubjectCategory(title=title)
                 subject_category.status = status
                 subject_category.comment = comment if comment else None
                 subject_category.created_id = self.current_user.oid
                 subject_category.updated_id = self.current_user.oid
                 subject_category_id = await subject_category.save()
                 r_dict['code'] = 1
         else:
             if not title:
                 r_dict['code'] = -1
     except RuntimeError:
         if subject_category_id:
             await SubjectCategory.delete_by_ids(subject_category_id)
         logger.error(traceback.format_exc())
     return r_dict
 async def post(self, category_id):
     r_dict = {'code': 0}
     try:
         subject_category = await SubjectCategory.get_by_id(category_id)
         await subject_category.delete()
         r_dict['code'] = 1
     except Exception:
         logger.error(traceback.format_exc())
     return r_dict
示例#6
0
 async def post(self, dimension_id):
     r_dict = {'code': 0}
     try:
         subject_dimension = await SubjectDimension.get_by_id(dimension_id)
         code = self.get_argument('code', None)
         title = self.get_argument('title', None)
         category = self.get_argument('category', None)
         status = self.get_argument('status', None)  # 状态
         ordered = self.get_argument('ordered', None)
         comment = self.get_argument('comment', None)
         if subject_dimension and title and category and ordered:
             c_count = await SubjectDimension.count(
                 dict(code=code,
                      id={'$ne': ObjectId(dimension_id)},
                      parent_cid={'$in': [None, '']}))
             t_count = await SubjectDimension.count(
                 dict(title=title,
                      id={'$ne': ObjectId(dimension_id)},
                      parent_cid={'$in': [None, '']}))
             r_count = await SubjectDimension.count(
                 dict(ordered=int(ordered),
                      id={'$ne': ObjectId(dimension_id)},
                      parent_cid={'$in': [None, '']}))
             if c_count > 0:
                 r_dict['code'] = -7
             elif t_count > 0:
                 r_dict['code'] = -6
             elif r_count > 0:
                 r_dict['code'] = -5
             else:
                 subject_dimension.code = code
                 if status == 'on':
                     status = STATUS_SUBJECT_DIMENSION_ACTIVE
                 else:
                     status = STATUS_SUBJECT_DIMENSION_INACTIVE
                 subject_dimension.title = title
                 subject_dimension.category = int(category)
                 subject_dimension.ordered = int(ordered)
                 subject_dimension.status = status
                 subject_dimension.comment = comment if comment else None
                 subject_dimension.updated_dt = datetime.datetime.now()
                 subject_dimension.updated_id = self.current_user.oid
                 await subject_dimension.save()
                 await update_subject_sub_dimension_status(
                     self.current_user.oid, status, [subject_dimension.cid])
                 r_dict['code'] = 1
         else:
             if not title:
                 r_dict['code'] = -1
             if not category:
                 r_dict['code'] = -2
             if not ordered:
                 r_dict['code'] = -4
     except RuntimeError:
         logger.error(traceback.format_exc())
     return r_dict
示例#7
0
 async def post(self, difficulty_id):
     r_dict = {'code': 0}
     try:
         subject_difficulty = await SubjectDifficulty.get_by_id(
             difficulty_id)
         await subject_difficulty.delete()
         r_dict['code'] = 1
     except Exception:
         logger.error(traceback.format_exc())
     return r_dict
示例#8
0
 async def post(self):
     r_dict = {'code': 0}
     try:
         subject_dimension_id_list = self.get_body_arguments(
             'subject_dimension_id_list[]', [])
         if subject_dimension_id_list:
             operate = self.get_argument('operate', None)
             if operate is not None:
                 id_list = [
                     ObjectId(subject_id)
                     for subject_id in subject_dimension_id_list
                 ]
                 if int(operate) == 1:
                     update_requests = []
                     for dimension_id in subject_dimension_id_list:
                         update_requests.append(
                             UpdateOne({'_id': ObjectId(dimension_id)}, {
                                 '$set': {
                                     'status':
                                     STATUS_SUBJECT_DIMENSION_ACTIVE,
                                     'updated_dt': datetime.datetime.now(),
                                     'updated_id': self.current_user.oid
                                 }
                             }))
                     await SubjectDimension.update_many(update_requests)
                 elif int(operate) == 0:
                     update_requests = []
                     for dimension_id in subject_dimension_id_list:
                         update_requests.append(
                             UpdateOne({'_id': ObjectId(dimension_id)}, {
                                 '$set': {
                                     'status':
                                     STATUS_SUBJECT_DIMENSION_INACTIVE,
                                     'updated_dt': datetime.datetime.now(),
                                     'updated_id': self.current_user.oid
                                 }
                             }))
                     await SubjectDimension.update_many(update_requests)
                 elif int(operate) == -1:
                     if id_list:
                         subject_dimension_id = id_list[0]
                         subject_dimension = await SubjectDimension.find_one(
                             dict(_id=subject_dimension_id))
                         if subject_dimension:
                             p_subject_dimension_cid = subject_dimension.parent_cid
                             await do_subject_dimension(
                                 p_subject_dimension_cid)
                     await SubjectDimension.delete_many(
                         {'_id': {
                             '$in': id_list
                         }})
                 r_dict['code'] = 1
     except RuntimeError:
         logger.error(traceback.format_exc())
     return r_dict
示例#9
0
 async def post(self, sub_dimension_id):
     r_dict = {'code': 0}
     try:
         subject_dimension = await SubjectDimension.get_by_id(
             sub_dimension_id)
         p_subject_dimension_cid = copy.deepcopy(
             subject_dimension.parent_cid)
         await subject_dimension.delete()
         await do_subject_dimension(p_subject_dimension_cid)
         r_dict['code'] = 1
     except Exception:
         logger.error(traceback.format_exc())
     return r_dict
示例#10
0
 async def post(self):
     r_dict = {'code': 0}
     subject_dimension_id = None
     try:
         code = self.get_argument('code', None)
         title = self.get_argument('title', None)
         category = self.get_argument('category', None)
         status = self.get_argument('status', None)  # 状态
         ordered = self.get_argument('ordered', None)
         comment = self.get_argument('comment', None)
         if code and title and category and ordered:
             c_count = await SubjectDimension.count(
                 dict(code=code, parent_cid={'$in': [None, '']}))
             t_count = await SubjectDimension.count(
                 dict(title=title, parent_cid={'$in': [None, '']}))
             r_count = await SubjectDimension.count(
                 dict(ordered=int(ordered), parent_cid={'$in': [None, '']}))
             if c_count > 0:
                 r_dict['code'] = -7
             elif t_count > 0:
                 r_dict['code'] = -6
             elif r_count > 0:
                 r_dict['code'] = -5
             else:
                 if status == 'on':
                     status = STATUS_SUBJECT_DIMENSION_ACTIVE
                 else:
                     status = STATUS_SUBJECT_DIMENSION_INACTIVE
                 subject_dimension = SubjectDimension(
                     code=code,
                     title=title,
                     category=int(category),
                     ordered=int(ordered))
                 subject_dimension.status = status
                 subject_dimension.comment = comment if comment else None
                 subject_dimension.created_id = self.current_user.oid
                 subject_dimension.updated_id = self.current_user.oid
                 subject_dimension_id = await subject_dimension.save()
                 r_dict['code'] = 1
         else:
             if not title:
                 r_dict['code'] = -1
             if not category:
                 r_dict['code'] = -2
             if not ordered:
                 r_dict['code'] = -4
     except RuntimeError:
         if subject_dimension_id:
             await SubjectDimension.delete_by_ids(subject_dimension_id)
         logger.error(traceback.format_exc())
     return r_dict
示例#11
0
 async def post(self, dimension_id):
     p_subject_dimension = await SubjectDimension.find_one(
         {'_id': ObjectId(dimension_id)})
     r_dict = {'code': 0}
     sub_dimension_id = None
     try:
         title = self.get_argument('title', None)
         status = self.get_argument('status', None)  # 状态
         ordered = self.get_argument('ordered', None)
         code = self.get_argument('code', None)
         comment = self.get_argument('comment', None)
         if title and ordered and p_subject_dimension and code:
             t_count = await SubjectDimension.count(
                 dict(title=title, parent_cid=p_subject_dimension.cid))
             r_count = await SubjectDimension.count(
                 dict(ordered=int(ordered),
                      parent_cid=p_subject_dimension.cid))
             c_count = await SubjectDimension.count(
                 dict(code=code, parent_cid=p_subject_dimension.cid))
             if c_count > 0:
                 r_dict['code'] = -2
             elif t_count > 0:
                 r_dict['code'] = -6
             elif r_count > 0:
                 r_dict['code'] = -5
             else:
                 if status == 'on':
                     status = STATUS_SUBJECT_DIMENSION_ACTIVE
                 else:
                     status = STATUS_SUBJECT_DIMENSION_INACTIVE
                 subject_dimension = SubjectDimension(title=title,
                                                      ordered=int(ordered),
                                                      code=code)
                 subject_dimension.status = status
                 subject_dimension.comment = comment if comment else None
                 subject_dimension.created_id = self.current_user.oid
                 subject_dimension.updated_id = self.current_user.oid
                 subject_dimension.parent_cid = p_subject_dimension.cid
                 sub_dimension_id = await subject_dimension.save()
                 await do_subject_dimension(p_subject_dimension.cid)
                 r_dict['code'] = 1
         else:
             if not title:
                 r_dict['code'] = -1
             if not ordered:
                 r_dict['code'] = -4
     except RuntimeError:
         if sub_dimension_id:
             await SubjectDimension.delete_by_ids(sub_dimension_id)
         logger.error(traceback.format_exc())
     return r_dict
示例#12
0
 async def post(self):
     r_dict = {'code': 0}
     try:
         subject_category_id_list = self.get_body_arguments(
             'subject_category_id_list[]', [])
         if subject_category_id_list:
             operate = self.get_argument('operate', None)
             if operate is not None:
                 id_list = [
                     ObjectId(subject_id)
                     for subject_id in subject_category_id_list
                 ]
                 if int(operate) == 1:
                     update_requests = []
                     for category_id in subject_category_id_list:
                         update_requests.append(
                             UpdateOne({'_id': ObjectId(category_id)}, {
                                 '$set': {
                                     'status':
                                     STATUS_SUBJECT_CATEGORY_ACTIVE,
                                     'updated_dt': datetime.datetime.now(),
                                     'updated_id': self.current_user.oid
                                 }
                             }))
                     await SubjectCategory.update_many(update_requests)
                 elif int(operate) == 0:
                     update_requests = []
                     for category_id in subject_category_id_list:
                         update_requests.append(
                             UpdateOne({'_id': ObjectId(category_id)}, {
                                 '$set': {
                                     'status':
                                     STATUS_SUBJECT_CATEGORY_INACTIVE,
                                     'updated_dt': datetime.datetime.now(),
                                     'updated_id': self.current_user.oid
                                 }
                             }))
                     await SubjectCategory.update_many(update_requests)
                 elif int(operate) == -1:
                     await SubjectCategory.delete_many(
                         {'_id': {
                             '$in': id_list
                         }})
                 r_dict['code'] = 1
     except RuntimeError:
         logger.error(traceback.format_exc())
     return r_dict
示例#13
0
    async def post(self):
        r_dict = {'code': 0}
        open_id = self.get_i_argument('open_id', None)
        race_cid = self.get_i_argument('race_cid', None)
        company_cid = self.get_i_argument('company_cid', None)
        if not race_cid:
            r_dict['code'] = 1001
            return r_dict
        member = await find_member_by_open_id(open_id)
        if not member:
            r_dict['code'] = 1002
            return r_dict
        company = await Company.find_one({
            'cid': company_cid,
            'record_flag': 1
        })
        if not company:
            r_dict['code'] = 1003
            return r_dict
        try:
            mapping = await RaceMapping.find_one({
                'member_cid': member.cid,
                'race_cid': race_cid,
                'record_flag': 1
            })
            if not mapping:
                mapping = RaceMapping(race_cid=race_cid, member_cid=member.cid)
                mapping.province_code = member.province_code
                mapping.city_code = member.city_code
                mapping.district_code = member.district_code
                mapping.age_group = member.age_group
                mapping.sex = member.sex
                mapping.category = member.category
                mapping.education = member.education
                mapping.company_cid = company_cid
            else:
                mapping.company_cid = company_cid

            if not mapping.auth_address:
                mapping.auth_address = member.auth_address

            await mapping.save()
            r_dict['code'] = 1000
        except Exception:
            logger.error(traceback.format_exc())
        return r_dict
示例#14
0
 async def post(self, category_id):
     r_dict = {'code': 0}
     try:
         status = self.get_argument('status', False)
         if status == 'true':
             status = STATUS_SUBJECT_CATEGORY_ACTIVE
         else:
             status = STATUS_SUBJECT_CATEGORY_INACTIVE
         subject_category = await SubjectCategory.get_by_id(category_id)
         if subject_category:
             subject_category.status = status
             subject_category.updated = datetime.datetime.now()
             subject_category.updated_id = self.current_user.oid
             await subject_category.save()
         r_dict['code'] = 1
     except RuntimeError:
         logger.error(traceback.format_exc())
     return r_dict
示例#15
0
    async def post(self):
        r_dict = {'code': 0}
        open_id = self.get_i_argument('open_id', None)
        race_cid = self.get_i_argument('race_cid', None)
        mobile = self.get_i_argument('mobile', None)
        v_code = self.get_i_argument('v_code', '')
        if not race_cid:
            r_dict['code'] = 1001
            return r_dict
        member = await find_member_by_open_id(open_id)
        if not member:
            r_dict['code'] = 1002
            return r_dict
        if not mobile:
            r_dict['code'] = 1003
            return r_dict
        try:
            if check_digit_verify_code(mobile, v_code):
                r_dict['code'] = 1000
            else:
                r_dict['code'] = 1004
                return r_dict

            mapping = await RaceMapping.find_one({
                'member_cid': member.cid,
                'race_cid': race_cid,
                'record_flag': 1
            })
            if not mapping:
                mapping = RaceMapping(race_cid=race_cid, member_cid=member.cid)
                mapping.province_code = member.province_code
                mapping.city_code = member.city_code
                mapping.district_code = member.district_code
                mapping.mobile = mobile
            else:
                mapping.mobile = mobile
            mapping.auth_address = member.auth_address
            await mapping.save()

            member.mobile = mobile
            await member.save()
        except Exception:
            logger.error(traceback.format_exc())
        return r_dict
示例#16
0
    async def post(self):
        res_dict = {'ranking': 0}
        open_id = self.get_i_argument('open_id', '')
        if not open_id:
            res_dict['code'] = 1001
            return res_dict

        member = await find_member_by_open_id(open_id)
        if not member:
            res_dict['code'] = 1002
            return res_dict

        race_cid = self.get_i_argument('race_cid', '')
        if not race_cid:
            res_dict['code'] = 1003
            return res_dict

        try:
            me = await RaceCheckPointStatistics.find_one({
                'race_cid':
                race_cid,
                'member_cid':
                member.cid
            })
            if me:
                num = await RaceCheckPointStatistics.count({
                    'race_cid': race_cid,
                    'pass_checkpoint_num': {
                        '$gte': me.pass_checkpoint_num
                    },
                    'correct_num': {
                        '$gte': me.correct_num
                    }
                })

                res_dict['code'] = 1000
                res_dict['ranking'] = num
                return res_dict
        except Exception:
            logger.error(traceback.format_exc())

        res_dict['code'] = 1000
        return res_dict
示例#17
0
 async def post(self, sub_dimension_id):
     r_dict = {'code': 0}
     try:
         status = self.get_argument('status', False)
         if status == 'true':
             status = STATUS_SUBJECT_DIMENSION_ACTIVE
         else:
             status = STATUS_SUBJECT_DIMENSION_INACTIVE
         subject_dimension = await SubjectDimension.get_by_id(
             sub_dimension_id)
         if subject_dimension:
             subject_dimension.status = status
             subject_dimension.updated = datetime.datetime.now()
             subject_dimension.updated_id = self.current_user.oid
             await subject_dimension.save()
         r_dict['code'] = 1
     except RuntimeError:
         logger.error(traceback.format_exc())
     return r_dict
示例#18
0
 async def post(self):
     r_dict = {'code': 0}
     open_id = self.get_i_argument('open_id', None)
     race_cid = self.get_i_argument('race_cid', None)
     if not race_cid:
         r_dict['code'] = 1001
         return r_dict
     member = await find_member_by_open_id(open_id)
     if not member:
         r_dict['code'] = 1002
         return r_dict
     try:
         race = await Race.find_one({'cid': race_cid, 'record_flag': 1})
         if race.company_enabled:
             r_dict['has_company_ranking'] = True
         r_dict['code'] = 1000
     except Exception:
         logger.error(traceback.format_exc())
     return r_dict
示例#19
0
    async def post(self):
        res_dict = {'code': 0}
        try:
            open_id = self.get_i_argument('open_id', '')
            if not open_id:
                res_dict['code'] = 1001
                return res_dict

            member = await find_member_by_open_id(open_id)
            if not member:
                res_dict['code'] = 1002
                return res_dict

            race_cid = self.get_i_argument('race_cid', '')
            if not race_cid:
                res_dict['code'] = 1003
                return res_dict

            stat_list = await RaceCheckPointStatistics.aggregate(stage_list=[
                MatchStage({'race_cid': race_cid}),
                SortStage([('pass_checkpoint_num', DESC), ('correct_num',
                                                           DESC)]),
                LimitStage(30),
                LookupStage(Member, 'member_cid', 'cid', 'member_list'),
                ProjectStage(
                    **{
                        'nick_name': {
                            '$arrayElemAt': ['$member_list.nick_name', 0]
                        },
                        'avatar': {
                            '$arrayElemAt': ['$member_list.avatar', 0]
                        },
                        'correct_num': '$correct_num',
                        'pass_checkpoint_num': '$pass_checkpoint_num'
                    })
            ]).to_list(30)

            res_dict = {'code': 1000, 'rankings': stat_list}
        except Exception:
            logger.error(traceback.format_exc())

        return res_dict
示例#20
0
 async def post(self, difficulty_id):
     r_dict = {'code': 0}
     try:
         subject_difficulty = await SubjectDifficulty.get_by_id(
             difficulty_id)
         title = self.get_argument('title', None)
         status = self.get_argument('status', None)  # 状态
         ordered = self.get_argument('ordered', None)
         comment = self.get_argument('comment', None)
         if subject_difficulty and title and ordered:
             t_count = await SubjectDifficulty.count(
                 dict(title=title, id={'$ne': ObjectId(difficulty_id)}))
             r_count = await SubjectDifficulty.count(
                 dict(ordered=int(ordered),
                      id={'$ne': ObjectId(difficulty_id)}))
             if t_count > 0:
                 r_dict['code'] = -4
             elif r_count > 0:
                 r_dict['code'] = -3
             else:
                 if status == 'on':
                     status = STATUS_SUBJECT_DIFFICULTY_ACTIVE
                 else:
                     status = STATUS_SUBJECT_DIFFICULTY_INACTIVE
                 subject_difficulty.title = title
                 subject_difficulty.ordered = int(ordered)
                 subject_difficulty.status = status
                 subject_difficulty.comment = comment if comment else None
                 subject_difficulty.updated_dt = datetime.datetime.now()
                 subject_difficulty.updated_id = self.current_user.oid
                 await subject_difficulty.save()
                 r_dict['code'] = 1
         else:
             if not title:
                 r_dict['code'] = -1
             if not ordered:
                 r_dict['code'] = -2
     except RuntimeError:
         logger.error(traceback.format_exc())
     return r_dict
示例#21
0
 async def post(self):
     r_dict = {'code': 0}
     subject_difficulty_id = None
     try:
         title = self.get_argument('title', None)
         status = self.get_argument('status', None)  # 状态
         ordered = self.get_argument('ordered', None)
         comment = self.get_argument('comment', None)
         if title and ordered:
             t_count = await SubjectDifficulty.count(dict(title=title))
             r_count = await SubjectDifficulty.count(
                 dict(ordered=int(ordered)))
             if t_count > 0:
                 r_dict['code'] = -4
             elif r_count > 0:
                 r_dict['code'] = -3
             else:
                 if status == 'on':
                     status = STATUS_SUBJECT_DIFFICULTY_ACTIVE
                 else:
                     status = STATUS_SUBJECT_DIFFICULTY_INACTIVE
                 subject_difficulty = SubjectDifficulty(
                     title=title, ordered=int(ordered))
                 subject_difficulty.status = status
                 subject_difficulty.comment = comment if comment else None
                 subject_difficulty.created_id = self.current_user.oid
                 subject_difficulty.updated_id = self.current_user.oid
                 subject_difficulty_id = await subject_difficulty.save()
                 r_dict['code'] = 1
         else:
             if not title:
                 r_dict['code'] = -1
             if not ordered:
                 r_dict['code'] = -2
     except RuntimeError:
         if subject_difficulty_id:
             await SubjectDifficulty.delete_by_ids(subject_difficulty_id)
         logger.error(traceback.format_exc())
     return r_dict
示例#22
0
    async def post(self):
        r_dict = {'code': 0}
        open_id = self.get_i_argument('open_id', None)
        race_cid = self.get_i_argument('race_cid', None)
        if not race_cid:
            r_dict['code'] = 1001
            return r_dict
        member = await find_member_by_open_id(open_id)
        if not member:
            r_dict['code'] = 1002
            return r_dict
        try:
            rankings = []
            #  找到活动下面的所有的单位
            match_stage = MatchStage({'race_cid': race_cid, 'record_flag': 1})
            group_stage = GroupStage('company_cid', sum={'$sum': 1})

            company_list = await RaceMapping.aggregate(stage_list=[
                match_stage, group_stage,
                SortStage([('sum', DESC)])
            ]).to_list(None)
            for company in company_list:
                # 分类
                company_assort = await Company.find_one({
                    'cid': company.id,
                    'record_flag': 1
                })

                rank = {
                    'title': company_assort.title if company_assort else '其他',
                    'people_count': company.sum
                }
                rankings.append(rank)
            r_dict = {'code': 1000, 'rankings': rankings}
        except Exception:
            logger.error(traceback.format_exc())

        return r_dict
示例#23
0
 async def post(self):
     r_dict = {'code': 0}
     try:
         subject_dimension_id_list = self.get_body_arguments(
             'subject_dimension_id_list[]', [])
         if subject_dimension_id_list:
             operate = self.get_argument('operate', None)
             if operate is not None:
                 status = None
                 id_list = [
                     ObjectId(subject_id)
                     for subject_id in subject_dimension_id_list
                 ]
                 if int(operate) == 1:
                     status = STATUS_SUBJECT_DIMENSION_ACTIVE
                     update_requests = []
                     for dimension_id in subject_dimension_id_list:
                         update_requests.append(
                             UpdateOne({'_id': ObjectId(dimension_id)}, {
                                 '$set': {
                                     'status': status,
                                     'updated_dt': datetime.datetime.now(),
                                     'updated_id': self.current_user.oid
                                 }
                             }))
                     await SubjectDimension.update_many(update_requests)
                 elif int(operate) == 0:
                     status = STATUS_SUBJECT_DIMENSION_INACTIVE
                     update_requests = []
                     for dimension_id in subject_dimension_id_list:
                         update_requests.append(
                             UpdateOne({'_id': ObjectId(dimension_id)}, {
                                 '$set': {
                                     'status': status,
                                     'updated_dt': datetime.datetime.now(),
                                     'updated_id': self.current_user.oid
                                 }
                             }))
                     await SubjectDimension.update_many(update_requests)
                 elif int(operate) == -1:
                     cid_list = await SubjectDimension.distinct(
                         'cid', {
                             '_id': {
                                 '$in': id_list
                             },
                             'parent_cid': {
                                 '$in': [None, '']
                             }
                         })
                     await SubjectDimension.delete_many(
                         {'_id': {
                             '$in': id_list
                         }})
                     await SubjectDimension.delete_many(
                         {'parent_cid': {
                             '$in': cid_list
                         }})
                 # 状态变更子维度也变更
                 if int(operate) in [1, 0] and status:
                     cid_list = await SubjectDimension.distinct(
                         'cid', {
                             '_id': {
                                 '$in': id_list
                             },
                             'parent_cid': {
                                 '$in': [None, '']
                             }
                         })
                     await update_subject_sub_dimension_status(
                         self.current_user.oid, status, cid_list)
                 r_dict['code'] = 1
     except RuntimeError:
         logger.error(traceback.format_exc())
     return r_dict
示例#24
0
    async def post(self):
        order = self.get_argument('order', '')
        chart_name = self.get_argument('chart_name', '')
        time = datetime.datetime.now()
        export_time = datetime2str(time, date_format='%Y-%m-%d %H:%M:%S')
        try:
            output = BytesIO()
            workbook = Workbook(output, {'in_memory': True})
            title_format = workbook.add_format({'font_size': 12, 'bold': '1', 'valign': 'vcenter', 'align': 'center',
                                                'font_name': 'Microsoft YaHei', 'border': 1})
            data_format = workbook.add_format(
                {'valign': 'vcenter', 'align': 'left', 'font_name': 'Microsoft YaHei', 'border': 1})
            data_center_format = workbook.add_format(
                {'valign': 'vcenter', 'align': 'center', 'font_name': 'Microsoft YaHei', 'border': 1})
            #  公民素质答题数量
            if order == "1" and chart_name:
                #  答题正确分布的数据字典
                subject_quantity_data_dict = self.get_argument('answer_subject_quantity_data', '')
                # 横坐标题目数量的列表
                answer_subject_xAxis_list = self.get_argument('answer_subject_xAxis_list', '')
                if subject_quantity_data_dict and answer_subject_xAxis_list:
                    worksheet = workbook.add_worksheet(name=chart_name)
                    worksheet.merge_range(1, 2, 1, 10, '导出时间' + export_time, cell_format=title_format)
                    worksheet.merge_range(0, 0, 0, 10, chart_name, cell_format=title_format)
                    worksheet.merge_range(1, 0, 1, 1, '筛选条件', cell_format=title_format)
                    worksheet.merge_range(2, 0, 3, 1, '总体答题次数', cell_format=title_format)
                    worksheet.write_string(2, 2, '答对题目数', cell_format=data_format)
                    worksheet.write_string(3, 2, '答对题目分布(%)', cell_format=data_format)
                    subject_quantity_data_dict = json.loads(subject_quantity_data_dict)
                    answer_subject_xAxis_list = json.loads(answer_subject_xAxis_list)
                    subject_quantity_title = list(subject_quantity_data_dict.keys())
                    subject_quantity_title = [subject_quantity for subject_quantity in subject_quantity_title if
                                              subject_quantity]
                    subject_quantity_data = list(subject_quantity_data_dict.values())
                    #  有筛选条件的数据
                    if '全体人群答对题目分布' in subject_quantity_title:
                        position = subject_quantity_title.index('全体人群答对题目分布')
                    else:
                        position = subject_quantity_data.index(max(sum(subject_quantity_data)))
                    if len(subject_quantity_data) > position:
                        subject_quantity_title.remove(subject_quantity_title[position])
                    for index, subject_quantity in enumerate(answer_subject_xAxis_list):
                        worksheet.write_string(2, 3 + index, subject_quantity)
                        if '全体人群答对题目分布' in list(subject_quantity_data_dict.keys()):
                            worksheet.write_string(3, 3 + index, str(subject_quantity_data_dict['全体人群答对题目分布'][index]),
                                                   cell_format=data_center_format)
                        else:
                            max_data_list = max(sum(subject_quantity_data))
                            worksheet.write_string(3, 2 + order, max_data_list[index - 1],
                                                   cell_format=data_center_format)
                    if subject_quantity_title:
                        #  有筛选条件得数据写入到excel
                        for index, condition_title in enumerate(subject_quantity_title):
                            worksheet.merge_range(2 * (index + 2) + index + 1, 0, 2 * (index + 2) + 2 + index, 1,
                                                  condition_title, cell_format=title_format)
                            worksheet.write_string(2 * (index + 2) + index + 1, 2, '答对题目数', cell_format=data_format)
                            worksheet.write_string(2 * (index + 2) + index + 2, 2, '答对题目分布(%)', cell_format=data_format)
                            for condition_index, data in enumerate(subject_quantity_data_dict[condition_title]):
                                worksheet.write_string(2 * (index + 2) + index + 2, 2 + condition_index + 1, str(data),
                                                       cell_format=data_format)
                                worksheet.write_string(2 * (index + 2) + index + 1, 2 + condition_index + 1,
                                                       answer_subject_xAxis_list[condition_index],
                                                       cell_format=data_format)
            #  公民科学素质雷达图
            if order == "2" and chart_name:
                #  公民科学素质雷达图的数据列表
                radar_title_list = self.get_argument('radar_title_list', '')
                # 横坐标题目数量的列表
                radar_data_list = self.get_argument('radar_data_list', '')
                #  雷达图展示的文本
                text_list = self.get_argument('text_list', '')
                if radar_title_list and radar_data_list and text_list:
                    worksheet = workbook.add_worksheet(name=chart_name)
                    worksheet.merge_range(1, 2, 1, 10, '导出时间' + export_time, cell_format=title_format)
                    worksheet.merge_range(0, 0, 0, 10, chart_name, cell_format=title_format)
                    worksheet.merge_range(1, 0, 1, 1, '筛选条件', cell_format=title_format)
                    worksheet.merge_range(2, 0, 3, 1, '全部正确率', cell_format=title_format)
                    worksheet.write_string(2, 2, '学科部落', cell_format=data_format)
                    worksheet.write_string(3, 2, '正确率(%)', cell_format=data_format)
                    radar_title_list = json.loads(radar_title_list)
                    radar_data_list = json.loads(radar_data_list)
                    text_list = json.loads(text_list)
                    first_radar_data = radar_data_list[0]
                    #  有筛选条件的数据
                    if '全部正确率' in radar_title_list:
                        position = radar_title_list.index('全部正确率')
                    else:
                        sum_list = []
                        for radar_data in radar_data_list:
                            radar_data = [float(radar) for radar in radar_data]
                            sum_list.append(sum(radar_data))
                        position = sum_list.index(max(sum_list))
                    if len(radar_data_list) > position:
                        radar_title_list.remove(radar_title_list[position])
                        first_radar_data = radar_data_list[position]
                        radar_data_list.remove(radar_data_list[position])
                    for order, text in enumerate(text_list):
                        worksheet.write_string(2, 3 + order, text, cell_format=data_center_format)
                        worksheet.write_string(3, 3 + order, first_radar_data[order], cell_format=data_center_format)
                    #  有筛选条件的
                    for index, condition_title in enumerate(radar_title_list):
                        worksheet.merge_range(2 * (index + 2) + index + 1, 0,
                                              2 * (index + 2) + 2 + index, 1,
                                              condition_title, cell_format=title_format)
                        worksheet.write_string(2 * (index + 2) + index + 1, 2, '学科部落',
                                               cell_format=data_format)
                        for order, text in enumerate(text_list):
                            worksheet.write_string(2 * (index + 2) + index + 1, 3 + order, text_list[order],
                                                   cell_format=data_format)
                        worksheet.write_string(2 * (index + 2) + index + 2, 2, '正确率(%)',
                                               cell_format=data_format)
                        worksheet.write_string(2 * (index + 2) + index + 2, 2, '正确率(%)',
                                               cell_format=data_format)
                        for order, radar_data in enumerate(radar_data_list[index]):
                            worksheet.write_string(2 * (index + 2) + index + 2, 3 + order, radar_data,
                                                   cell_format=data_format)
            #  统计——科学素质题库参数比较分析
            if order == "3" and chart_name:
                #  难度的标题
                difficulty_title = self.get_argument('difficulty_title', '')
                # 难度的数据
                difficulty_param_dict = self.get_argument('difficulty_param_dict', '')
                difficulty_xAxis = self.get_argument('difficulty_xAxis', '')

                #  维度
                knowledge_title = self.get_argument('knowledge_title', '')
                knowledge_param_dict = self.get_argument('knowledge_param_dict', '')
                knowledge_xAxis = self.get_argument('knowledge_xAxis', '')
                #  难度和维度混合的数据
                difficulty_knowledge_title = self.get_argument('difficulty_knowledge_title', '')
                difficulty_knowledge_dict = self.get_argument('difficulty_knowledge_dict', '')
                if difficulty_title and difficulty_param_dict and difficulty_xAxis and knowledge_title and knowledge_param_dict and knowledge_xAxis and difficulty_knowledge_title and difficulty_knowledge_dict:
                    worksheet = workbook.add_worksheet(name=difficulty_title)
                    worksheet.merge_range(1, 2, 1, 7, '导出时间' + export_time, cell_format=title_format)
                    worksheet.merge_range(0, 0, 0, 7, chart_name, cell_format=title_format)
                    worksheet.merge_range(1, 0, 1, 1, '筛选条件', cell_format=title_format)
                    worksheet.merge_range(2, 0, 3, 1, '全部正确率', cell_format=title_format)
                    worksheet.write_string(2, 2, '难度', cell_format=data_format)
                    worksheet.write_string(3, 2, '正确率(%)', cell_format=data_format)
                    difficulty_param_dict = json.loads(difficulty_param_dict)
                    difficulty_param_title = list(difficulty_param_dict.keys())
                    difficulty_param_data = list(difficulty_param_dict.values())
                    difficulty_xAxis = json.loads(difficulty_xAxis)
                    #  有筛选条件的数据
                    if '总体正确率' in difficulty_param_title:
                        position = difficulty_param_title.index('总体正确率')
                    else:
                        position = difficulty_param_data.index(max(sum(difficulty_param_data)))
                    if len(difficulty_param_data) > position:
                        difficulty_param_title.remove(difficulty_param_title[position])

                    for index, title in enumerate(difficulty_xAxis):
                        worksheet.write_string(2, 3 + index, title)
                        if '总体正确率' in list(difficulty_param_dict.keys()):
                            worksheet.write_string(3, 3 + index, difficulty_param_dict['总体正确率'][index],
                                                   cell_format=data_center_format)
                        else:
                            max_data_list = max(sum(difficulty_param_data))
                            worksheet.write_string(3, 2 + order, max_data_list[index - 1],
                                                   cell_format=data_center_format)
                    if difficulty_param_title:
                        #  有筛选条件得数据写入到excel
                        for index, condition_title in enumerate(difficulty_param_title):
                            worksheet.merge_range(2 * (index + 2) + index + 1, 0, 2 * (index + 2) + 2 + index, 1,
                                                  condition_title, cell_format=title_format)
                            worksheet.write_string(2 * (index + 2) + index + 1, 2, '难度', cell_format=data_format)
                            worksheet.write_string(2 * (index + 2) + index + 2, 2, '答对题目分布(%)', cell_format=data_format)
                            for condition_index, data in enumerate(difficulty_param_dict[condition_title]):
                                worksheet.write_string(2 * (index + 2) + index + 2, 2 + condition_index + 1, str(data),
                                                       cell_format=data_format)
                                worksheet.write_string(2 * (index + 2) + index + 1, 2 + condition_index + 1,
                                                       difficulty_xAxis[condition_index],
                                                       cell_format=data_format)

                    worksheet = workbook.add_worksheet(name=knowledge_title)
                    worksheet.merge_range(1, 2, 1, 5, '导出时间' + export_time, cell_format=title_format)
                    worksheet.merge_range(0, 0, 0, 5, chart_name, cell_format=title_format)
                    worksheet.merge_range(1, 0, 1, 1, '筛选条件', cell_format=title_format)
                    worksheet.merge_range(2, 0, 3, 1, '全部正确率', cell_format=title_format)
                    worksheet.write_string(2, 2, '知识维度', cell_format=data_format)
                    worksheet.write_string(3, 2, '答对题目分布(%)', cell_format=data_format)
                    knowledge_param_dict = json.loads(knowledge_param_dict)
                    knowledge_param_title = list(knowledge_param_dict.keys())
                    knowledge_param_data = list(knowledge_param_dict.values())
                    knowledge_xAxis = json.loads(knowledge_xAxis)
                    #  有筛选条件的数据
                    if '总体正确率' in knowledge_param_title:
                        position = knowledge_param_title.index('总体正确率')
                    else:
                        position = knowledge_param_data.index(max(sum(knowledge_param_data)))
                    if len(knowledge_param_data) > position:
                        knowledge_param_title.remove(knowledge_param_title[position])
                    for index, title in enumerate(knowledge_xAxis):
                        worksheet.write_string(2, 3 + index, title)
                        if '总体正确率' in list(knowledge_param_dict.keys()):
                            worksheet.write_string(3, 3 + index, knowledge_param_dict['总体正确率'][index],
                                                   cell_format=data_center_format)
                        else:
                            max_data_list = max(sum(knowledge_param_data))
                            worksheet.write_string(3, 2 + order, max_data_list[index - 1],
                                                   cell_format=data_center_format)
                    if knowledge_param_title:
                        #  有筛选条件得数据写入到excel
                        for index, condition_title in enumerate(knowledge_param_title):
                            worksheet.merge_range(2 * (index + 2) + index + 1, 0, 2 * (index + 2) + 2 + index, 1,
                                                  condition_title, cell_format=title_format)
                            worksheet.write_string(2 * (index + 2) + index + 1, 2, '知识维度', cell_format=data_format)
                            worksheet.write_string(2 * (index + 2) + index + 2, 2, '答对题目分布(%)', cell_format=data_format)
                            for condition_index, data in enumerate(knowledge_param_dict[condition_title]):
                                worksheet.write_string(2 * (index + 2) + index + 2, 2 + condition_index + 1, str(data),
                                                       cell_format=data_format)
                                worksheet.write_string(2 * (index + 2) + index + 1, 2 + condition_index + 1,
                                                       knowledge_xAxis[condition_index],
                                                       cell_format=data_format)
                    #  难度和维度混合的数据
                    worksheet = workbook.add_worksheet(name=difficulty_knowledge_title)
                    worksheet.merge_range(1, 2, 1, 5, '导出时间' + export_time, cell_format=title_format)
                    worksheet.merge_range(0, 0, 0, 5, chart_name, cell_format=title_format)
                    worksheet.merge_range(1, 0, 1, 1, '筛选条件', cell_format=title_format)
                    worksheet.write_string(2, 0, '知识维度', cell_format=data_center_format)
                    worksheet.write_string(2, 1, '难度', cell_format=data_center_format)
                    difficulty_knowledge_dict = json.loads(difficulty_knowledge_dict)
                    title_list = list(difficulty_knowledge_dict.keys())
                    #  题目难度的title
                    difficulty_title_list = list(list(difficulty_knowledge_dict.values())[0].keys())
                    total_data_list = []
                    for index, title in enumerate(title_list):
                        total_data_list.append(list(list(difficulty_knowledge_dict.values())[index].values()))
                        worksheet.merge_range(3 + index, 0, 3 + index, 1, title, cell_format=data_center_format)
                    for index, difficulty_title in enumerate(difficulty_title_list):
                        worksheet.write_string(2, 2 + index, difficulty_title, cell_format=data_center_format)
                    for index, data_list in enumerate(total_data_list):
                        for order, data in enumerate(data_list):
                            worksheet.write_string(3 + index, 2 + order, str(data) + '%',
                                                   cell_format=data_center_format)
            workbook.close()
            self.set_header('Content-Type', 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet')
            self.set_header('Content-Disposition',
                            "attachment;filename*=utf-8''{}.xlsx".format(quote(chart_name.encode('utf-8'))))
            self.write(output.getvalue())
            self.finish()
        except Exception:
            logger.error(traceback.format_exc())