| | |
| | | ctx.status = 401; |
| | | throw new CoolCommException('登录失效~', ctx.status); |
| | | } |
| | | } catch (error) {} |
| | | // 添加用户的数据权限 |
| | | if (ctx.admin && ctx.admin.userId) { |
| | | const departmentIds = await this.midwayCache.get( |
| | | `admin:department:${ctx.admin.userId}` |
| | | ); |
| | | ctx.admin.departmentIds = Array.isArray(departmentIds) |
| | | ? departmentIds |
| | | : []; |
| | | } |
| | | |
| | | } catch (error) { } |
| | | // 使用matchUrl方法来检查URL是否应该被忽略 |
| | | const isIgnored = this.ignoreUrls.some(pattern => |
| | | this.utils.matchUrl(pattern, url) |
| New file |
| | |
| | | import { Context } from '@midwayjs/koa'; |
| | | |
| | | |
| | | export interface DeptFilterOptions { |
| | | alias?: string; |
| | | field?: string; |
| | | } |
| | | |
| | | export async function WithDeptFilterWhere( |
| | | ctx: Context, |
| | | options: DeptFilterOptions = {} |
| | | ): Promise<any[][]> { |
| | | const { alias = 'a', field = 'departmentId' } = options; |
| | | const admin = ctx.admin; |
| | | if (!admin || admin.username == 'admin') return []; |
| | | |
| | | const deptIds = admin.departmentIds; |
| | | if (!Array.isArray(deptIds) || deptIds.length === 0) { |
| | | return [['1 = 0']]; |
| | | } |
| | | |
| | | return [ |
| | | [ |
| | | `${alias}.${field} IN (:departmentIds)`, |
| | | { departmentIds: deptIds }, |
| | | ], |
| | | ]; |
| | | } |
| | |
| | | import { BasicdataBuyerEntity } from '../../entity/buyer'; |
| | | import { BasicdataBuyerService } from '../../service/buyer'; |
| | | import { BaseSysDepartmentEntity } from '../../../base/entity/sys/department'; |
| | | import { WithDeptFilterWhere } from '../../../base/middleware/with-dept-filter-where' |
| | | |
| | | /** |
| | | * 购买方管理 |
| | |
| | | service: BasicdataBuyerService, |
| | | pageQueryOp: { |
| | | fieldEq: ['a.departmentId', 'a.name', 'a.contact'], |
| | | fieldLike: ['a.name','a.address'], |
| | | fieldLike: ['a.name', 'a.address'], |
| | | select: ['a.*', 'b.name AS departmentName'], |
| | | join: [ |
| | | { |
| | |
| | | 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 AdminOperationBuyerController extends BaseController {} |
| | | export class AdminOperationBuyerController extends BaseController { } |
| | |
| | | import { BasicdataDriverEntity } from '../../entity/driver'; |
| | | import { BasicdataDriverService } from '../../service/driver'; |
| | | import { BaseSysDepartmentEntity } from '../../../base/entity/sys/department'; |
| | | import { WithDeptFilterWhere } from '../../../base/middleware/with-dept-filter-where' |
| | | |
| | | /** |
| | | * 转运司机 |
| | |
| | | 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; |
| | | }, |
| | | |
| | | }, |
| | | }) |
| | |
| | | import { BasicdataIotEntity } from '../../entity/iot'; |
| | | import { BasicdataIotService } from '../../service/iot'; |
| | | import { BaseSysDepartmentEntity } from '../../../base/entity/sys/department'; |
| | | import { WithDeptFilterWhere } from '../../../base/middleware/with-dept-filter-where' |
| | | |
| | | /** |
| | | * 数据源定义信息后台管理 |
| | |
| | | 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 AdminBasicdataIotController extends BaseController { |
| | |
| | | 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' |
| | | |
| | | /** |
| | | * 站点信息后台管理 |
| | |
| | | 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 { } |
| | |
| | | import { BasicdataSorterService } from '../../service/sorter'; |
| | | import { BaseSysDepartmentEntity } from '../../../base/entity/sys/department'; |
| | | import { BasicdataSiteEntity } from '../../entity/site'; |
| | | import { WithDeptFilterWhere } from '../../../base/middleware/with-dept-filter-where' |
| | | |
| | | /** |
| | | * 分拣人员后台管理 |
| | | */ |
| | |
| | | { |
| | | entity: BasicdataSiteEntity, |
| | | alias: 'c', |
| | | condition: 'a.workSiteId = c.businessId', |
| | | condition: 'a.workSiteId = c.businessId', |
| | | 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 AdminBasicdataSorterController extends BaseController {} |
| | | export class AdminBasicdataSorterController extends BaseController { } |
| | |
| | | import { BasicdataVehicleEntity } from '../../entity/vehicle'; |
| | | import { BasicdataVehicleService } from '../../service/vehicle'; |
| | | import { BaseSysDepartmentEntity } from '../../../base/entity/sys/department'; |
| | | import { WithDeptFilterWhere } from '../../../base/middleware/with-dept-filter-where' |
| | | |
| | | /** |
| | | * 转运车辆后台管理 |
| | |
| | | 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 AdminBasicdataVehicleController extends BaseController {} |
| | |
| | | import { BaseSysDepartmentEntity } from '../../../base/entity/sys/department'; |
| | | import { BasicdataSiteEntity } from '../../../basicdata/entity/site' |
| | | import { BasicdataWastetypeEntity } from '../../../basicdata/entity/wastetype'; |
| | | import { WithDeptFilterWhere } from '../../../base/middleware/with-dept-filter-where' |
| | | |
| | | /** |
| | | * 可回收物收益管理 |
| | |
| | | fieldEq: ['a.departmentId', 'a.collectionPointId'], |
| | | where: async (ctx) => { |
| | | const { startTime, endTime } = ctx.request.body; |
| | | const condition = []; |
| | | const conditions: any[][] = []; |
| | | if (startTime && endTime) { |
| | | condition.push(['a.dateTime BETWEEN :startTime AND :endTime', { startTime, endTime }]); |
| | | conditions.push(['a.dateTime BETWEEN :startTime AND :endTime', { startTime, endTime }]); |
| | | } |
| | | return condition; |
| | | conditions.push(...(await WithDeptFilterWhere(ctx, { alias: 'a', field: 'departmentId' }))); |
| | | |
| | | return conditions; |
| | | }, |
| | | }, |
| | | }) |
| | |
| | | import { BaseSysDepartmentEntity } from '../../../base/entity/sys/department'; |
| | | import {BasicdataWastetypeEntity} from '../../../basicdata/entity/wastetype' |
| | | import { BasicdataSiteEntity } from '../../../basicdata/entity/site'; |
| | | import { WithDeptFilterWhere } from '../../../base/middleware/with-dept-filter-where' |
| | | |
| | | /** |
| | | * 业务称重数据管理 |
| | | */ |
| | |
| | | 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 AdminPushSiteweightController extends BaseController {} |
| | |
| | | import { CoolController, BaseController } from '@cool-midway/core'; |
| | | import { PushVehicleGpsEntity } from '../../entity/vehiclegps'; |
| | | import { PushVehicleGpsService } from '../../service/vehiclegps'; |
| | | import { BaseSysDepartmentEntity } from '../../../base/entity/sys/department' |
| | | import { WithDeptFilterWhere } from '../../../base/middleware/with-dept-filter-where' |
| | | |
| | | /** |
| | | * 车载监控GPS位置数据 |
| | |
| | | pageQueryOp: { |
| | | keyWordLikeFields: ['a.sn', 'a.vehicleNo'], |
| | | fieldEq: ['a.status'], |
| | | select: ['a.*', 'b.name AS departmentName'], |
| | | join: [ |
| | | { |
| | | entity: BaseSysDepartmentEntity, |
| | | alias: 'b', |
| | | condition: 'a.departmentId = b.id', |
| | | type: 'leftJoin', |
| | | }, |
| | | ], |
| | | where: async (ctx) => { |
| | | const { createDate, gpsTime } = ctx.request.body; |
| | | const condition = []; |
| | | const conditions: any[][] = []; |
| | | if (createDate && createDate.length === 2) { |
| | | condition.push(['a.createDate BETWEEN :createStartDate AND :createEndDate', { createStartDate: createDate[0], createEndDate: createDate[1] }]); |
| | | conditions.push(['a.createDate BETWEEN :createStartDate AND :createEndDate', { createStartDate: createDate[0], createEndDate: createDate[1] }]); |
| | | } |
| | | if (gpsTime && gpsTime.length === 2) { |
| | | condition.push(['a.gpsTime BETWEEN :gpsStartDate AND :gpsEndDate', { gpsStartDate: gpsTime[0], gpsEndDate: gpsTime[1] }]); |
| | | conditions.push(['a.gpsTime BETWEEN :gpsStartDate AND :gpsEndDate', { gpsStartDate: gpsTime[0], gpsEndDate: gpsTime[1] }]); |
| | | } |
| | | return condition; |
| | | |
| | | conditions.push(...(await WithDeptFilterWhere(ctx, { alias: 'a', field: 'departmentId' }))); |
| | | |
| | | return conditions; |
| | | } |
| | | } |
| | | }) |
| | |
| | | @Column({ comment: '车牌号', nullable: true }) |
| | | vehicleNo: string; |
| | | |
| | | @Index() |
| | | @Column({ comment: '归属单位' }) |
| | | departmentId: number; |
| | | |
| | | departmentName: string; |
| | | |
| | | @Column({ comment: 'GPS定位时间', nullable: true }) |
| | | gpsTime: Date; |
| | | |
| | |
| | | import { CoolController, BaseController } from '@cool-midway/core'; |
| | | import { ReportDailyDepartmentEntity } from '../../entity/dailydepartment'; |
| | | import { ReportDailyDepartmentService } from '../../service/dailydepartment'; |
| | | import { WithDeptFilterWhere } from '../../../base/middleware/with-dept-filter-where' |
| | | |
| | | /** |
| | | * 每日部门汇总控制器 |
| | |
| | | service: ReportDailyDepartmentService, |
| | | pageQueryOp: { |
| | | keyWordLikeFields: ['a.departmentName'], |
| | | fieldEq: ['a.date', 'a.departmentId'] |
| | | fieldEq: ['a.date', 'a.departmentId'], |
| | | where: async (ctx) => { |
| | | const conditions: any[][] = []; |
| | | conditions.push(...(await WithDeptFilterWhere(ctx, { alias: 'a', field: 'departmentId' }))); |
| | | return conditions; |
| | | } |
| | | } |
| | | }) |
| | | export class AdminReportDailydepartmentController extends BaseController {} |
| | | export class AdminReportDailydepartmentController extends BaseController { } |
| | |
| | | import { CoolController, BaseController } from '@cool-midway/core'; |
| | | import { ReportDailysiteEntity } from '../../entity/dailysite'; |
| | | import { ReportDailysiteService } from '../../service/dailysite'; |
| | | import { BaseSysDepartmentEntity } from '../../../base/entity/sys/department' |
| | | import { WithDeptFilterWhere } from '../../../base/middleware/with-dept-filter-where' |
| | | |
| | | /** |
| | | * 每日站点汇总控制器 |
| | |
| | | service: ReportDailysiteService, |
| | | pageQueryOp: { |
| | | keyWordLikeFields: ['a.siteName'], |
| | | fieldEq: ['a.date', 'a.siteId'] |
| | | fieldEq: ['a.date', 'a.siteId'], |
| | | select: ['a.*', 'b.name AS departmentName'], |
| | | join: [ |
| | | { |
| | | entity: BaseSysDepartmentEntity, |
| | | alias: 'b', |
| | | condition: 'a.departmentId = b.id', |
| | | type: 'leftJoin', |
| | | }, |
| | | ], |
| | | |
| | | where: async (ctx) => { |
| | | const conditions: any[][] = []; |
| | | conditions.push(...(await WithDeptFilterWhere(ctx, { alias: 'a', field: 'departmentId' }))); |
| | | return conditions; |
| | | } |
| | | } |
| | | }) |
| | | export class AdminReportDailysiteController extends BaseController {} |
| | | export class AdminReportDailysiteController extends BaseController { } |
| | |
| | | @Column({ comment: '站点名称' }) |
| | | siteName: string; |
| | | |
| | | @Index() |
| | | @Column({ comment: '部门ID' }) |
| | | departmentId: number; |
| | | |
| | | departmentName: string; |
| | | |
| | | @Column({ comment: '总重量', type: 'decimal', precision: 15, scale: 2, default: 0.00 }) |
| | | weightTotal: number; |
| | | |
| | |
| | | .select([ |
| | | 'site.id AS siteId', // 拿最新的自增ID作为每日表的 siteId |
| | | 'site.businessName AS siteName', // 永远拿当前后台最新的站点名称,防止设备传旧名称 |
| | | 'site.departmentId AS departmentId', |
| | | 'weight.weight AS weight', |
| | | 'weight.garbageType AS garbageType' |
| | | ]) |
| | |
| | | date: targetDate, |
| | | siteId: siteId, |
| | | siteName: row.siteName, |
| | | departmentId:row.departmentId, |
| | | weightTotal: 0, timeTotal: 0, carbonTotal: 0 |
| | | }; |
| | | // 动态初始化宽表里各子类型的 0 值 |