src/modules/basicdata/controller/admin/site.ts
@@ -2,18 +2,13 @@ import { BasicdataSiteEntity } from '../../entity/site'; import { BasicdataSiteService } from '../../service/site'; import { BaseSysDepartmentEntity } from '../../../base/entity/sys/department'; import { WithDeptFilterWhere } from '../../../base/middleware/with-dept-filter-where' /** * 站点信息后台管理 */ @CoolController({ api: ['add', 'delete', 'update', 'info', 'list', 'page'], entity: BasicdataSiteEntity, service: BasicdataSiteService, pageQueryOp: { keyWordLikeFields: ['a.name', 'a.address', 'a.leader'], fieldEq: ['a.departmentId', 'a.siteType', 'a.status'], // ✅ page 方法已在 Service 中重写,这里配置仅作兜底 select: ['a.*', 'b.name AS departmentName'], join: [ { @@ -23,15 +18,6 @@ type: 'leftJoin', }, ], where: async ctx => { const conditions: any[][] = []; conditions.push(...(await WithDeptFilterWhere(ctx, { alias: 'a', field: 'departmentId' }))); // 其他关联表(举例) // conditions.push(...(await deptFilterWhere(ctx, 'd', 'id'))); return conditions; }, }, }) export class AdminBasicdataSiteController extends BaseController { } export class AdminBasicdataSiteController extends BaseController {} src/modules/basicdata/service/iot.ts
@@ -114,4 +114,24 @@ return result; } /** * 递归获取部门及其所有子部门 ID */ async getDepartmentAndChildren(deptId: number): Promise<number[]> { const result: number[] = [deptId]; const findChildren = async (pid: number) => { const children = await this.baseSysDepartmentEntity .createQueryBuilder('d') .select('d.id') .where('d.parentId = :pid', { pid }) .getMany(); for (const c of children) { result.push(c.id); await findChildren(c.id); } }; await findChildren(deptId); return result; } } src/modules/basicdata/service/site.ts
@@ -1,14 +1,112 @@ import { Provide } from '@midwayjs/core'; import { Provide, Inject, Context } from '@midwayjs/core'; import { BaseService } from '@cool-midway/core'; import { InjectEntityModel } from '@midwayjs/typeorm'; import { Repository } from 'typeorm'; import { BasicdataSiteEntity } from '../entity/site'; import { BaseSysDepartmentEntity } from '../../base/entity/sys/department'; import { WithDeptFilterWhere } from '../../base/middleware/with-dept-filter-where'; import { Context as KoaContext } from '@midwayjs/koa'; /** * 站点服务 */ @Provide() export class BasicdataSiteService extends BaseService { @InjectEntityModel(BasicdataSiteEntity) basicdataSiteEntity: Repository<BasicdataSiteEntity>; } @InjectEntityModel(BaseSysDepartmentEntity) baseSysDepartmentEntity: Repository<BaseSysDepartmentEntity>; @Inject() ctx: KoaContext; /** * 重写 page —— 显式列出字段,避免 a.* 的别名问题 */ async page(query: any) { const { page = 1, size = 20, departmentId, siteType, status, keyWord, sort, order, } = query; const qb = this.basicdataSiteEntity .createQueryBuilder('a') .leftJoin(BaseSysDepartmentEntity, 'b', 'a.departmentId = b.id') .select([ 'a.id', 'a.businessId', 'a.businessName', 'a.departmentId', 'a.siteType', 'a.address', 'a.leader', 'a.longitude', 'a.latitude', 'a.photo', 'a.status', 'a.remark', 'a.createTime', 'a.updateTime', 'b.name AS departmentName', ]); const authConds = await WithDeptFilterWhere(this.ctx, { alias: 'a', field: 'departmentId', }); for (const [sql, params] of authConds) { qb.andWhere(sql, params); } if (departmentId) { const deptIds = await this.getDepartmentAndChildren(Number(departmentId)); qb.andWhere('a.departmentId IN (:deptIds)', { deptIds }); } if (siteType !== undefined && siteType !== '') { qb.andWhere('a.siteType = :siteType', { siteType }); } if (status !== undefined && status !== '') { qb.andWhere('a.status = :status', { status: Number(status) }); } if (keyWord) { qb.andWhere( '(a.businessId LIKE :kw OR a.businessName LIKE :kw OR a.address LIKE :kw OR a.leader LIKE :kw)', { kw: `%${keyWord}%` } ); } const sortField = order || 'createTime'; const sortDir = sort === 'asc' ? 'ASC' : 'DESC'; qb.orderBy(`a.${sortField}`, sortDir); const skip = (Number(page) - 1) * Number(size); const [list, total] = await qb .offset(skip) .limit(Number(size)) .getManyAndCount(); return { list, pagination: { page: Number(page), size: Number(size), total }, }; } /** * 递归获取部门及其所有子部门 ID */ async getDepartmentAndChildren(deptId: number): Promise<number[]> { const result: number[] = [deptId]; const findChildren = async (pid: number) => { const children = await this.baseSysDepartmentEntity .createQueryBuilder('d') .select('d.id') .where('d.parentId = :pid', { pid }) .getMany(); for (const c of children) { result.push(c.id); await findChildren(c.id); } }; await findChildren(deptId); return result; } } src/modules/monitor/service/capturetask.ts
@@ -108,7 +108,7 @@ // 4. 本地目录 const dateDir = new Date().toISOString().slice(0, 10).replace(/-/g, ''); const localDir = path.join(process.cwd(), 'uploads', 'capture', dateDir); const localDir = path.join(process.cwd(), 'upload', 'capture', dateDir); fs.mkdirSync(localDir, { recursive: true }); console.log('[Capture] 本地目录=', localDir); @@ -121,9 +121,9 @@ console.log('[Capture] 图片下载完成'); const relativePath = path .relative(path.join(process.cwd(), 'uploads'), dest) .relative(path.join(process.cwd(), 'upload'), dest) .replace(/\\/g, '/'); const localUrl = `/uploads/${relativePath}`; const localUrl = `/upload/${relativePath}`; console.log('[Capture] localUrl=', localUrl); const entity = { @@ -278,7 +278,7 @@ const spaceId = await this.getSpaceID(); const imgs = await this.queryCaptureImages(deviceSerial, spaceId); const dateDir = new Date().toISOString().slice(0, 10).replace(/-/g, ''); const localDir = path.join(process.cwd(), 'uploads', 'capture', dateDir); const localDir = path.join(process.cwd(), 'upload', 'capture', dateDir); fs.mkdirSync(localDir, { recursive: true }); for (const img of imgs) { src/modules/push/controller/app/open.ts
@@ -116,7 +116,7 @@ this.ctx.body = { messageId: '' }; return; } console.log('【萤石云原始报文】:', rawBody.slice(0, 500)); console.log('【萤石云原始报文】:', rawBody); let msg: any; try { msg = JSON.parse(rawBody); upload/capture/20260812/GN3665735_1786492841353.jpg
upload/capture/20260812/GN3665735_1786492884239.jpg
upload/capture/20260812/GN3665735_1786507240759.jpg
upload/capture/20260812/GN3665735_1786507282434.jpg
upload/capture/20260812/GN3665735_1786521639978.jpg
upload/capture/20260812/GN3665735_1786521678020.jpg
upload/capture/20260812/GN3665735_1786536037960.jpg
upload/capture/20260812/GN3665735_1786536075542.jpg
upload/capture/20260812/GT7568358_1786492802427.jpg
upload/capture/20260812/GT7568358_1786492846144.jpg
upload/capture/20260812/GT7568358_1786507202622.jpg
upload/capture/20260812/GT7568358_1786507244873.jpg
upload/capture/20260812/GT7568358_1786521602750.jpg
upload/capture/20260812/GT7568358_1786521643256.jpg
upload/capture/20260812/GT7568358_1786536003041.jpg
upload/capture/20260812/GT7568358_1786536041238.jpg
upload/capture/20260812/GU7398831_1786492828667.jpg
upload/capture/20260812/GU7398831_1786492870648.jpg
upload/capture/20260812/GU7398831_1786507226196.jpg
upload/capture/20260812/GU7398831_1786507269933.jpg
upload/capture/20260812/GU7398831_1786521628313.jpg
upload/capture/20260812/GU7398831_1786521666059.jpg
upload/capture/20260812/GU7398831_1786536026138.jpg
upload/capture/20260812/GU7398831_1786536062205.jpg
upload/capture/20260812/GV6662502_1786492832279.jpg
upload/capture/20260812/GV6662502_1786492874391.jpg
upload/capture/20260812/GV6662502_1786507230536.jpg
upload/capture/20260812/GV6662502_1786507273313.jpg
upload/capture/20260812/GV6662502_1786521632355.jpg
upload/capture/20260812/GV6662502_1786521670102.jpg
upload/capture/20260812/GV6662502_1786536030786.jpg
upload/capture/20260812/GV6662502_1786536065877.jpg
upload/capture/20260812/GV6662505_1786492825151.jpg
upload/capture/20260812/GV6662505_1786492867323.jpg
upload/capture/20260812/GV6662505_1786507222821.jpg
upload/capture/20260812/GV6662505_1786507266189.jpg
upload/capture/20260812/GV6662505_1786521625196.jpg
upload/capture/20260812/GV6662505_1786521662522.jpg
upload/capture/20260812/GV6662505_1786536021780.jpg
upload/capture/20260812/GV6662505_1786536059139.jpg
upload/capture/20260812/GV6662514_1786492817062.jpg
upload/capture/20260812/GV6662514_1786492859120.jpg
upload/capture/20260812/GV6662514_1786507215511.jpg
upload/capture/20260812/GV6662514_1786507258115.jpg
upload/capture/20260812/GV6662514_1786521617223.jpg
upload/capture/20260812/GV6662514_1786521655544.jpg
upload/capture/20260812/GV6662514_1786536014676.jpg
upload/capture/20260812/GV6662514_1786536052794.jpg
upload/capture/20260812/GV7474259_1786492812545.jpg
upload/capture/20260812/GV7474259_1786492854950.jpg
upload/capture/20260812/GV7474259_1786507211871.jpg
upload/capture/20260812/GV7474259_1786507253789.jpg
upload/capture/20260812/GV7474259_1786521613046.jpg
upload/capture/20260812/GV7474259_1786521651663.jpg
upload/capture/20260812/GV7474259_1786536011033.jpg
upload/capture/20260812/GV7474259_1786536048816.jpg
upload/capture/20260812/GV7474275_1786492808255.jpg
upload/capture/20260812/GV7474275_1786492850608.jpg
upload/capture/20260812/GV7474275_1786507207443.jpg
upload/capture/20260812/GV7474275_1786507249665.jpg
upload/capture/20260812/GV7474275_1786521608541.jpg
upload/capture/20260812/GV7474275_1786521648124.jpg
upload/capture/20260812/GV7474275_1786536007341.jpg
upload/capture/20260812/GV7474275_1786536044927.jpg
upload/capture/20260812/GV7474288_1786492836109.jpg
upload/capture/20260812/GV7474288_1786492878638.jpg
upload/capture/20260812/GV7474288_1786507234862.jpg
upload/capture/20260812/GV7474288_1786507277701.jpg
upload/capture/20260812/GV7474288_1786521636292.jpg
upload/capture/20260812/GV7474288_1786521674570.jpg
upload/capture/20260812/GV7474288_1786536034039.jpg
upload/capture/20260812/GV7474288_1786536069578.jpg
upload/capture/20260812/GV7474291_1786492820563.jpg
upload/capture/20260812/GV7474291_1786492863758.jpg
upload/capture/20260812/GV7474291_1786507219198.jpg
upload/capture/20260812/GV7474291_1786507262088.jpg
upload/capture/20260812/GV7474291_1786521621017.jpg
upload/capture/20260812/GV7474291_1786521658986.jpg
upload/capture/20260812/GV7474291_1786536017684.jpg
upload/capture/20260812/GV7474291_1786536056032.jpg
upload/capture/20260813/GN3665735_1786579240984.jpg
upload/capture/20260813/GN3665735_1786579282053.jpg
upload/capture/20260813/GT7568358_1786579202008.jpg
upload/capture/20260813/GT7568358_1786579244480.jpg
upload/capture/20260813/GU7398831_1786579225930.jpg
upload/capture/20260813/GU7398831_1786579269645.jpg
upload/capture/20260813/GV6662502_1786579230374.jpg
upload/capture/20260813/GV6662502_1786579273691.jpg
upload/capture/20260813/GV6662505_1786579221670.jpg
upload/capture/20260813/GV6662505_1786579266010.jpg
upload/capture/20260813/GV6662514_1786579214399.jpg
upload/capture/20260813/GV6662514_1786579258227.jpg
upload/capture/20260813/GV7474259_1786579209995.jpg
upload/capture/20260813/GV7474259_1786579253499.jpg
upload/capture/20260813/GV7474275_1786579206310.jpg
upload/capture/20260813/GV7474275_1786579248997.jpg
upload/capture/20260813/GV7474288_1786579234470.jpg
upload/capture/20260813/GV7474288_1786579277797.jpg
upload/capture/20260813/GV7474291_1786579217673.jpg
upload/capture/20260813/GV7474291_1786579261598.jpg
uploads/capture/20260811/GN3665733_1786435210647.jpg
uploads/capture/20260811/GN3665733_1786435241031.jpg
uploads/capture/20260811/GN3665735_1786449649294.jpg
uploads/capture/20260811/GN3665735_1786449694873.jpg
uploads/capture/20260811/GT7568358_1786420802179.jpg
uploads/capture/20260811/GT7568358_1786420839321.jpg
uploads/capture/20260811/GT7568358_1786435204548.jpg
uploads/capture/20260811/GT7568358_1786435236873.jpg
uploads/capture/20260811/GT7568358_1786449601748.jpg
uploads/capture/20260811/GT7568358_1786449652045.jpg
uploads/capture/20260811/GU7398831_1786420816227.jpg
uploads/capture/20260811/GU7398831_1786420852726.jpg
uploads/capture/20260811/GU7398831_1786435214262.jpg
uploads/capture/20260811/GU7398831_1786435245842.jpg
uploads/capture/20260811/GU7398831_1786449637387.jpg
uploads/capture/20260811/GU7398831_1786449684411.jpg
uploads/capture/20260811/GV6662502_1786449641491.jpg
uploads/capture/20260811/GV6662502_1786449687972.jpg
uploads/capture/20260811/GV6662505_1786420836562.jpg
uploads/capture/20260811/GV6662505_1786420875056.jpg
uploads/capture/20260811/GV6662505_1786435233953.jpg
uploads/capture/20260811/GV6662505_1786435268196.jpg
uploads/capture/20260811/GV6662505_1786449633565.jpg
uploads/capture/20260811/GV6662505_1786449681517.jpg
uploads/capture/20260811/GV6662514_1786420829762.jpg
uploads/capture/20260811/GV6662514_1786420866979.jpg
uploads/capture/20260811/GV6662514_1786435227502.jpg
uploads/capture/20260811/GV6662514_1786435260168.jpg
uploads/capture/20260811/GV6662514_1786449626039.jpg
uploads/capture/20260811/GV6662514_1786449674071.jpg
uploads/capture/20260811/GV7474259_1786420825942.jpg
uploads/capture/20260811/GV7474259_1786420862502.jpg
uploads/capture/20260811/GV7474259_1786435223505.jpg
uploads/capture/20260811/GV7474259_1786435255456.jpg
uploads/capture/20260811/GV7474259_1786449621443.jpg
uploads/capture/20260811/GV7474259_1786449670226.jpg
uploads/capture/20260811/GV7474275_1786420820949.jpg
uploads/capture/20260811/GV7474275_1786420856674.jpg
uploads/capture/20260811/GV7474275_1786435218689.jpg
uploads/capture/20260811/GV7474275_1786435251133.jpg
uploads/capture/20260811/GV7474275_1786449617079.jpg
uploads/capture/20260811/GV7474275_1786449666086.jpg
uploads/capture/20260811/GV7474288_1786449644964.jpg
uploads/capture/20260811/GV7474288_1786449691579.jpg
uploads/capture/20260811/GV7474291_1786420832814.jpg
uploads/capture/20260811/GV7474291_1786420871234.jpg
uploads/capture/20260811/GV7474291_1786435230493.jpg
uploads/capture/20260811/GV7474291_1786435264760.jpg
uploads/capture/20260811/GV7474291_1786449629825.jpg
uploads/capture/20260811/GV7474291_1786449677844.jpg