wangzhibo
2026-07-28 920cec41cedfde27f89d7c19b78e03147b926ab5
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
import { Inject } from '@midwayjs/core';
import { CoolController, BaseController } from '@cool-midway/core';
import { OperationWastesaleEntity } from '../../entity/wastesale';
import { OperationWastesaleService } from '../../service/wastesale';
import { BaseSysUserEntity } from '../../../base/entity/sys/user';
import { BasicdataBuyerEntity } from '../../../basicdata/entity/buyer'
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'
 
/**
 * 可回收物收益管理
 */
@CoolController({
  api: ['add', 'delete', 'update', 'info', 'list', 'page'],
  entity: OperationWastesaleEntity,
  service: OperationWastesaleService,
  insertParam: (ctx) => {
    return {
      handlerId: ctx.admin.userId,
    };
  },
  pageQueryOp: {
    select: [
      'a.*',
      'b.name AS departmentName',
      'c.businessName AS siteName',
      'd.name AS wasteName',
      'e.name AS handlerName',
      'f.name AS buyerName',
    ],
    join: [
      {
        entity: BaseSysDepartmentEntity,
        alias: 'b',
        condition: 'a.departmentId = b.id',
        type: 'leftJoin',
      },
      {
        entity: BasicdataSiteEntity,
        alias: 'c',
        condition: 'a.siteId = c.businessId',
        type: 'leftJoin',
      },
      {
        entity: BasicdataWastetypeEntity,
        alias: 'd',
        condition: 'a.wasteCode = d.code',
        type: 'leftJoin',
      },
      {
        entity: BaseSysUserEntity,
        alias: 'e',
        condition: 'a.handlerId = e.userId',
        type: 'leftJoin',
      },
      {
        entity: BasicdataBuyerEntity,
        alias: 'f',
        condition: 'a.buyerCode = f.code',
        type: 'leftJoin',
      },
    ],
    fieldEq: ['a.departmentId', 'a.collectionPointId'],
    where: async (ctx) => {
      const { startTime, endTime } = ctx.request.body;
      const conditions: any[][] = [];
      if (startTime && endTime) {
        conditions.push(['a.dateTime BETWEEN :startTime AND :endTime', { startTime, endTime }]);
      }
      conditions.push(...(await WithDeptFilterWhere(ctx, { alias: 'a', field: 'departmentId' })));
 
      return conditions;
    },
  },
})
export class AdminOperationWastesaleController extends BaseController {
  @Inject()
  ctx;
}