222
schangxiang@126.com
2025-06-13 6a8393408d8cefcea02b7a598967de8dc1e565c2
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
import { Context, Service } from "egg";
import { EntityManager } from "typeorm";
import { LoginInfo } from "../entity/sys/loginInfo";
import { ResultInfo2 as ResultInfo } from "../public/commonInterface";
 
export default class baseApiService extends Service {
  private _info: ResultInfo;
  /**
   * 返回数据结构
   */
  public get info() {
    return this._info;
  }
  public set info(val: ResultInfo) {
    this._info = val;
  }
 
  constructor(ctx: Context) {
    super(ctx);
    this._info = {
      Result: false,
      Msg: undefined,
      statusCode: undefined,
      Data: undefined
    };
  }
 
  public async getToken() {
    const { ctx } = this;
    try {
      const guid = this.ctx.query.guid;
      ctx.body = {
        guid
      };
    } catch (error) {
      console.log("------------------" + error);
    }
  }
 
  /**
   * 主数据,读写
   */
  public get dbWrite(): EntityManager {
    return this.ctx.service.common.dbWrite;
  }
 
  /**
   * 主数据,只读
   */
  public get dbRead(): EntityManager {
    return this.ctx.service.common.dbRead;
  }
 
  /**
   * 用户信息
   */
  public get userInfo(): Promise<LoginInfo> {
    return this.ctx.helper.userInfo();
  }
 
  /**
   * 请求参数
   */
  public get body() {
    return this.ctx.request.body;
  }
 
  /**
   * 设置账套信息
   */
  public async setAccountInfo(dataInfo) {
    let userInfo = await this.userInfo;
    dataInfo.platCorpName = userInfo.platCorpName;
    dataInfo.platUserCode = userInfo.platUserCode;
    dataInfo.platUserName = userInfo.platUserName;
    dataInfo.platUser_Id = userInfo.platUser_Id;
    dataInfo.userProductAlias = userInfo.userProductAlias;
    dataInfo.userProductCode = userInfo.userProductCode;
    dataInfo.userProduct_Id = userInfo.userProduct_Id;
 
    // 设置新建信息
    let keyValue = dataInfo[this.body.idField];
    if (!keyValue) {
      dataInfo = Object.assign(dataInfo, {
        createID: userInfo.user_Id,
        creator: userInfo.userTrueName,
        createDate: new Date()
      });
    } else {
      // 设置修改信息
      dataInfo = Object.assign(dataInfo, {
        modifyID: userInfo.user_Id,
        modifier: userInfo.userTrueName,
        modifyDate: new Date()
      });
    }
  }
}