def create_company(self): name = self.get_argument("name","") desc = self.get_argument("desc","") uuid = self.get_argument("uuid","").lower() prop = self.get_argument("property","") self.logger.info("name:"+name+" desc:"+desc) if name == "" or uuid == "": self.set_status(400) return {"result":False,'msg':err_msgs['PARAMS_MISSING']} token = self.request.headers.get("user_token",None) redis = RedisBase() token_info = redis.get_token_info(token) user_id = token_info['uuid'] parent_uuid = token_info['syndicate_uuid'] com_db = CompanyDao(session=self.session) es_index = self.build_es_index(parent_uuid,uuid) # 当uuid已存在时添加失败,返回推荐uuid if not com_db.insert_company(name,desc,prop,user_id,parent_uuid,uuid,es_index): result = { 'result': False, 'msg': err_msgs['COM_UUID_EXIST'], 'recommendation': self.build_company_uuid(uuid) } self.set_status(400) return result # 在es中创建公司索引,当公司索引创建失败时删除公司返回错误信息 if not EsBase().create_index(es_index): com_db.delete_company(uuid) result = { 'result': False, 'msg': err_msgs['INDEX_CREATE_ERR'] } self.set_status(400) return result # 在grout中设置公司的配置信息,设置失败删除公司和es中的索引,返回错误信息 if not self.post_company_grout(uuid,es_index): com_db.delete_company(uuid) EsBase().delete_index(es_index) result = { 'result': False, 'msg': err_msgs['COM_CONF_ERR'] } self.set_status(400) return result # 设置公司的关注媒体类型 self.set_com_media(uuid) self.log_user_action(self.get_token().get("uuid"),"create_company","-") result = { 'result': True } return result
def create_syndicate(self): name = self.get_argument("name","") desc = self.get_argument("desc","") uuid = self.get_argument("uuid","") user_name = self.get_argument("user_name","") telephone = self.get_argument("telephone","") self.logger.info("name:"+name+" desc:"+desc+" user_name:"+user_name+" telephone:"+telephone) if name == "" or user_name == "" or telephone == "" or uuid == "": self.set_status(400) return {"result":False,'msg':err_msgs['PARAMS_MISSING']} usr_db = UserDao(session= self.session) # 一个超级运营员只允许管理一个集团 if usr_db.exist_role_group_by_tel(telephone, Users.ROLE_SUP_MGR): result = { 'result': False, 'msg': err_msgs['ROLE_SUP_MGR_EXIST'] } self.set_status(400) return result match, usr_id, user_name = usr_db.insert_user(user_name,telephone, Users.ROLE_SUP_MGR) if not match: result = { 'result': False, 'msg': err_msgs['TEL_NAME_NOT_MATCH'], 'name': user_name } self.set_status(400) return result token = self.request.headers.get("user_token",None) redis = RedisBase() token_info = redis.get_token_info(token) user_id = token_info['uuid'] com_db = CompanyDao(session=self.session) # 当uuid已存在时插入失败,返回推荐uuid if not com_db.insert_company(name,desc,None,user_id,Company.NO_PARENT,uuid,None): result = { 'result': False, 'msg': err_msgs['COM_UUID_EXIST'], 'recommendation': self.build_company_uuid(uuid) } self.set_status(400) return result usr_rle_db = UserConfDao(session=self.session) usr_rle_db.insert_role(usr_id,uuid,UserConf.SUB_ROLE_SUP_MGR,UserConf.TYPE_ROLE_SUPMGR) # 日志 self.log_user_action(token_info.get("uuid"),"create_syndicate",uuid) result = { 'result': True } return result