333
schangxiang@126.com
2025-09-19 18966e02fb573c7e2bb0c6426ed792b38b910940
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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
import { default as BaseController } from "../baseController";
import { Post } from "egg-shell-decorators";
import { SysCodeRegular } from "../../entity/sys/core/sysCodeRegular";
import { SysCodeRegularUser } from "../../entity/sys/core/sysCodeRegularUser";
 
/**
 * 编码规则
 */
export default class CodeRegularController extends BaseController {
  //#region saveCommon
  /**
   * saveCommon
   */
  @Post()
  public async saveCommon() {
    let { ctx } = this;
    let body = ctx.request.body;
    let userInfo = await ctx.helper.userInfo();
 
    var regularInfo = await this.dbRead.findOne(SysCodeRegular, {
      code_Id: body.code_Id
    });
 
    if (!regularInfo) {
      this.info.result = false;
      this.info.msg = "当前不存在!";
      return this.info;
    }
 
    var regularUserInfo = await this.dbRead.findOne(SysCodeRegularUser, {
      where: {
        userProduct_Id: userInfo.userProduct_Id,
        code_Id: body.code_Id
      }
    });
    if (regularUserInfo == null) {
      regularUserInfo = new SysCodeRegularUser();
      regularUserInfo.platCorpName = userInfo.platCorpName;
      regularUserInfo.platUser_Id = userInfo.platUser_Id;
      regularUserInfo.platUserCode = userInfo.platUserCode;
      regularUserInfo.platUserName = userInfo.platUserName;
      regularUserInfo.userProductCode = userInfo.userProductCode;
      regularUserInfo.userProduct_Id = userInfo.userProduct_Id;
      regularUserInfo.userProductAlias = userInfo.userProductAlias;
 
      regularUserInfo.code_Id = body.code_Id;
      regularUserInfo.prefix = body.prefix;
      regularUserInfo.charLength = body.charLength;
      regularUserInfo.prefix = body.prefix;
      regularUserInfo.isCustom = body.isCustom;
      regularUserInfo.jsonData = body.jsonData;
      regularUserInfo.codeRegular = body.codeRegular;
 
      await this.dbWrite.insert(SysCodeRegularUser, regularUserInfo);
      this.info.result = true;
      this.info.msg = regularInfo.menuName + "新增编码成功!";
    } else {
      let _regularInfo: any = {};
      _regularInfo.code_Id = body.code_Id;
      _regularInfo.prefix = body.prefix;
      _regularInfo.charLength = body.charLength;
      _regularInfo.prefix = body.prefix;
      _regularInfo.isCustom = body.isCustom;
      _regularInfo.jsonData = body.jsonData;
      _regularInfo.codeRegular = body.codeRegular;
 
      await this.dbWrite.update(SysCodeRegularUser, regularUserInfo.codeUser_Id, _regularInfo);
      this.info.result = true;
      this.info.msg = regularInfo.menuName + "保存编码成功!";
    }
 
    ctx.body = this.info;
  }
  //#endregion
 
  //#region getTreeData
  /**
   * 获得tree类型数据
   */
  @Post()
  public async getTreeData() {
    let { ctx } = this;
    let body = ctx.request.body;
    let userInfo = await ctx.helper.userInfo();
 
    var regularInfo = await this.dbWrite.findOne(SysCodeRegularUser, {
      where: {
        userProduct_Id: userInfo.userProduct_Id,
        code_Id: body.code_Id
      }
    });
 
    //获得默认规则
    if (regularInfo == null) {
      var defaultInfo = await this.dbRead.findOne(SysCodeRegular, {
        code_Id: body.code_Id
      });
      if (defaultInfo) {
        this.info.code = defaultInfo.code;
      }
    }
 
    this.info.result = true;
    this.info.data = regularInfo;
 
    ctx.body = this.info;
  }
  //#endregion
 
  //#region reset
  /**
   * 还原为默认规则
   */
  @Post()
  public async reset() {
    let { ctx } = this;
    let body = ctx.request.body;
    let userInfo = await ctx.helper.userInfo();
 
    var regularInfo = await this.dbRead.findOne(SysCodeRegular, {
      code_Id: body.code_Id
    });
 
    if (!regularInfo) {
      this.info.result = false;
      this.info.msg = "当前不存在!";
      return this.info;
    }
 
    var regularUserInfo = await this.dbRead.findOne(SysCodeRegularUser, {
      userProduct_Id: userInfo.userProduct_Id,
      code_Id: body.code_Id
    });
    if (!regularUserInfo) {
      this.info.result = false;
      this.info.msg = "不存在自定义设置!";
    } else {
      await this.dbWrite.delete(SysCodeRegularUser, {
        userProduct_Id: userInfo.userProduct_Id,
        code_Id: regularUserInfo.code_Id
      });
      this.info.result = true;
      this.info.msg = regularInfo.menuName + "重置成功!";
    }
 
    ctx.body = this.info;
  }
  //#endregion
}