wangzhibo
4 天以前 c19f1f7e21c93d1f13b4f44a8a615f65af577559
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
import { CoolController, BaseController } from '@cool-midway/core';
import { Body, Inject, Post } from '@midwayjs/core';
import { OperationTradeRecordEntity } from '../../entity/traderecord';
import { OperationTradeRecordService } from '../../service/traderecord';
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: OperationTradeRecordEntity,
  service: OperationTradeRecordService,
  pageQueryOp: {
    keyWordLikeFields: ['a.goodsName', 'a.opponent'],
    fieldEq: [
      'a.transactionType',
      'a.incomeType',
      'a.payMethod'
    ],
    select: ['a.*', 'b.name AS departmentName'],
    join: [
      {
        entity: BaseSysDepartmentEntity,
        alias: 'b',
        condition: 'a.departmentId = b.id',
        type: 'leftJoin'
      }
    ],
    where: async (ctx) => {
      const { startTime, endTime } = ctx.request.body;
      const conditions: any[][] = [];
 
      if (startTime && endTime) {
        conditions.push(['a.transactionTime BETWEEN :startTime AND :endTime', { startTime, endTime }]);
      }
      
      conditions.push(...(await WithDeptFilterWhere(ctx, { alias: 'a', field: 'departmentId' })));
      return conditions;
    },
    addOrderBy: {
      transactionTime: 'desc'
    }
  }
})
export class AdminOperationTradeRecordController extends BaseController {
  @Inject()
  tradeRecordService: OperationTradeRecordService;
 
  @Post('/import', { summary: '导入账单' })
  async importData(@Body('list') list: any[]) {
    return this.ok(await this.tradeRecordService.importData(list));
  }
}