schangxiang@126.com
2025-09-09 3d8966ba2c81e7e0365c8b123e861d18ee4f94f5
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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
import BaseController from "../baseController";
import { Post } from "egg-shell-decorators";
import { SysParamValue } from "../../entity/sys/core/sysParamValue";
import { IsNull, Not, In } from "typeorm";
import { SysParamValue2 } from "../../entity/sys/core/sysParamValue2";
 
export default class ParamContrller extends BaseController {
  //#region getConfig
  /**
   * 获得参数值集合
   */
  @Post()
  public async getConfig() {
    let { ctx } = this;
    let body = ctx.body;
    let userInfo = await ctx.helper.userInfo();
    let type_Id = body.type_Id;
    if (!type_Id) type_Id = 585;
 
    var keys = body.keys;
    if (!Array.isArray(body.keys)) {
      keys = body.keys.split(",");
    }
    var valueList: Array<SysParamValue> = [];
    for (var key of keys) {
      var valueInfo = await this.dbRead.findOne(SysParamValue, {
        select: ["params_Id", "type_Id", "value01", "value02", "value03", "value04"],
        where: {
          type_Id: type_Id,
          userProduct_Id: userInfo.userProduct_Id,
          value02: key
        }
      });
 
      //获得默认规则
      if (!valueInfo) {
        valueInfo = await this.dbRead.findOne(SysParamValue, {
          where: {
            type_Id: type_Id,
            userProduct_Id: userInfo.userProduct_Id,
            value02: key
          }
        });
      }
      if (valueInfo) {
        valueList.push(valueInfo);
      }
    }
 
    this.info.result = true;
    this.info.data = valueList;
 
    ctx.body = this.info;
  }
  //#endregion
 
  //#region getValueList
  /**
   * 获得参数值集合
   */
  @Post()
  public async getValueList() {
    let { ctx } = this;
    let body = ctx.body;
    let userInfo = await ctx.helper.userInfo();
 
    var valueList = await this.dbRead.find(SysParamValue, {
      where: {
        type_Id: body.type_Id,
        userProduct_Id: userInfo.userProduct_Id
      }
    });
 
    //获得默认规则
    if (valueList.length === 0) {
      valueList = await this.dbRead.find(SysParamValue, {
        where: [
          {
            type_Id: body.type_Id,
            userProduct_Id: IsNull()
          },
          {
            type_Id: body.type_Id,
            userProduct_Id: 0
          }
        ]
      });
    }
 
    this.info.result = true;
    this.info.data = valueList;
 
    ctx.body = this.info;
  }
  //#endregion
 
  //#region saveParams
  /**
   * 保存参数值
   */
  @Post()
  public async saveParams() {
    let { ctx } = this;
    let body = ctx.body;
    let userInfo = await ctx.helper.userInfo();
 
    try {
      var params_Ids = "0";
      for (let valueInfo of body.valueList) {
        var valInfo = await this.dbRead.findOne(SysParamValue, {
          where: {
            type_Id: valueInfo.type_Id || body.type_Id,
            userProduct_Id: userInfo.userProduct_Id,
            value02: valueInfo.value02
          }
        });
 
        //更新自有参数值
        if (valInfo) {
          var _valInfo: any = {};
          _valInfo.value01 = valueInfo.value01;
          _valInfo.value02 = valueInfo.value02;
          _valInfo.value03 = valueInfo.value03;
          _valInfo.value04 = valueInfo.value04;
          _valInfo.value05 = valueInfo.value05;
          _valInfo.enable = 1;
          await this.dbWrite.update(SysParamValue, valInfo.params_Id, _valInfo);
          params_Ids += "," + valInfo.params_Id;
        } else {
          var paramInfo = new SysParamValue2();
          paramInfo.type_Id = body.type_Id;
          paramInfo.value01 = valueInfo.value01;
          paramInfo.value02 = valueInfo.value02;
          paramInfo.value03 = valueInfo.value03;
          paramInfo.value04 = valueInfo.value04;
          paramInfo.value05 = valueInfo.value05;
          paramInfo.enable = 1;
 
          paramInfo.platCorpName = userInfo.platCorpName;
          paramInfo.platUserCode = userInfo.platUserCode;
          paramInfo.platUserName = userInfo.platUserName;
          paramInfo.platUser_Id = userInfo.platUser_Id;
          paramInfo.userProductAlias = userInfo.userProductAlias;
          paramInfo.userProductCode = userInfo.userProductCode;
          paramInfo.userProduct_Id = userInfo.userProduct_Id;
          await this.dbWrite.insert(SysParamValue2, paramInfo);
 
          valInfo = await this.dbWrite.findOne(SysParamValue, {
            where: {
              type_Id: valueInfo.type_Id || body.type_Id,
              userProduct_Id: userInfo.userProduct_Id,
              value02: valueInfo.value02
            }
          });
          if (valInfo) {
            params_Ids += "," + valInfo.params_Id;
          }
        }
      }
 
      // 585=为系统参数
      if (body.type_Id != 585) {
        //删除不存在的数据
        await this.dbWrite.delete(SysParamValue, {
          type_Id: body.type_Id,
          userProduct_Id: userInfo.userProduct_Id,
          params_Id: Not(In(params_Ids.split(",")))
        });
      }
 
      this.info.result = true;
      this.info.msg = "保存成功";
    } catch (ex) {
      this.info.result = false;
      this.info.msg = "保存失败," + ex.message;
    }
 
    ctx.body = this.info;
  }
  //#endregion
}