desc author veaba
 *  desc import { BroadcastSchema , HelpsSchema , HospitalsSchema , LogSchema , LovesSchema , ReportSchema , NewsSchema , SocketSchema , TimelinesSchema , UsersSchema , WeibosSchema , AuditSchema , HistorysSchema , BarragesSchema } from "./model" ; import { isEmptyObject } from "../utils/check" ; desc param collection param limit param match export const taskChannelList = async ( collection , limit ? , match ? ) => { const list = await TheModel ( collection ) . aggregate ( [ { $match : match || { } } , { $sort : { count : - 1 } } , { $limit : limit || 20 } , ] ) ; return list || [ ] ; } ; desc param obj param newObj param collection_name export const updateOne = async ( obj , newObj , collection_name ) => { return await TheModel ( collection_name ) . updateOne ( obj , newObj ) || { } ; } ; desc param obj param newObj param collection_name export const updateMany = async ( obj , newObj , collection_name ) => { return await TheModel ( collection_name ) . updateMany ( obj , { $set : { ... newObj } } ) || { } ; } ; desc param obj param collection_name export const insertOne = async ( obj , collection_name ) => { return await TheSchema ( obj , collection_name ) . save ( ) || { } ; } ; desc param arr param collection_name export const insertMany = async ( arr , collection_name ) => { return await TheModel ( collection_name ) . insertMany ( arr ) || { } ; } ; export const findCount = async ( obj , collection_name ) => { return await TheModel ( collection_name ) . where ( obj ) . countDocuments ( ) ; } ; desc param _id const isIdDB = ( _id ) => { return ! ! ( _id && _id . length === 24 ) ; } ; desc export const deleteOneById = async ( _id , collection_name ) => { if ( isIdDB ( _id ) ) { return await TheModel ( collection_name ) . findOneAndRemove ( { _id } ) ; } throw new Error ( '非法_id==>:' + _id ) ; } ; desc export const deleteMany = async ( query , collection_name ) => { if ( ! isEmptyObject ( query ) ) { return await TheModel ( collection_name ) . findOneAndRemove ( query ) ; } throw new Error ( '非法参数==>:' + query ) ; } ; desc export const TheSchema = ( obj , collection_name ) => { let models = { } ; switch ( collection_name ) { case 'audits' : models = new AuditSchema ( obj ) ; break ; case 'barrages' : models = new BarragesSchema ( obj ) ; break ; case 'broadcasts' : models = new BroadcastSchema ( obj ) ; break ; case 'helps' : models = new HelpsSchema ( obj ) ; break ; case 'hospitals' : models = new HospitalsSchema ( obj ) ; break ; case 'logs' : models = new LogSchema ( obj ) ; break ; case 'loves' : models = new LovesSchema ( obj ) ; break ; case 'newss' : models = new NewsSchema ( obj ) ; break ; case 'sockets' : models = new SocketSchema ( obj ) ; break ; case 'timelines' : models = new TimelinesSchema ( obj ) ; break ; case 'reports' : models = new ReportSchema ( obj ) ; break ; case 'users' : models = new UsersSchema ( obj ) ; break ; case 'weibos' : models = new WeibosSchema ( obj ) ; break ; case 'history' : models = new HistorysSchema ( obj ) ; break ; default : throw new Error ( '未能识别TheSchema类型===>' + collection_name ) ; } return models ; } ; desc export const TheModel = ( collection_name ) => { let models = { } ; switch ( collection_name ) { case 'audits' : models = AuditSchema ; break ; case 'barrages' : models = BarragesSchema ; break ; case 'broadcasts' : models = BroadcastSchema ; break ; case 'helps' : models = HelpsSchema ; break ; case 'hospitals' : models = HospitalsSchema ; break ; case 'logs' : models = LogSchema ; break ; case 'loves' : models = LovesSchema ; break ; case 'newss' : models = NewsSchema ; break ; case 'sockets' : models = SocketSchema ; break ; case 'timelines' : models = TimelinesSchema ; break ; case 'reports' : models = ReportSchema ; break ; case 'users' : models = UsersSchema ; break ; case 'weibos' : models = WeibosSchema ; break ; case 'historys' : models = HistorysSchema ; break ; default : throw new Error ( '未能识别Model类型' ) ; } return models ; } ; desc param obj param collection_name return export const isHasOne = async ( obj , collection_name ) => { return ! ! ( await TheModel ( collection_name ) . where ( obj ) . countDocuments ( ) ) ; } ; desc export const getCount = async ( obj , collection_name ) => { return await TheModel ( collection_name ) . where ( obj ) . countDocuments ( ) ; } ; desc export const flipPage = async ( collection , skip , limit ? , project ? ) => { const $project = { } ; ( project || [ ] ) . map ( ( item ) => $project [ item ] = 1 ) ; const list = await TheModel ( collection ) . aggregate ( [ { $match : { } } , { $project : $project } , { $sort : { id : - 1 } } , { $skip : skip } , { $limit : limit || 20 } , ] ) ; return list || [ ] ; } ; desc export const getAllList = async ( obj , collection_name ) => { return ( await TheModel ( collection_name ) . find ( obj ) . lean ( ) ) ; } ; desc param obj param keys param collection_name return { key export const getKeysDB = async ( obj , keys , collection_name ) => { let selectedObj = { } ; keys . map ( item => selectedObj [ item ] = 1 ) ; return await TheModel ( collection_name ) . findOne ( obj , selectedObj ) || { } ; } ; desc param obj param keys param collection_name return { key getKeysAll-map getKeysAll-map count export const getKeysAll = async ( obj , keys , collection_name ) => { let selectedObj = { } ; keys . map ( item => selectedObj [ item ] = 1 ) ; return await TheModel ( collection_name ) . find ( obj , selectedObj ) . lean ( ) || { } ; } ; desc export const getRankAll = async ( obj , keys , collection_name ) => { const project = { } ; keys . map ( item => { project [ item ] = 1 ; } ) ; const list = await TheModel ( collection_name ) . aggregate ( [ { $match : obj || { } } , { $project : project } , { $sort : { count : 1 } } ] ) ; return list || [ ] ; } ;