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
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
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
import BaseController from "../../baseController";
import { Post } from "egg-shell-decorators";
import { BaseProductInfo } from "../../../entity/basicInfo/base/baseProductInfo";
import { BaseProvider } from "../../../entity/basicInfo/base/baseProvider";
import { BaseBrand } from "../../../entity/basicInfo/base/baseBrand";
import { SysParamValue } from "../../../entity/sys/core/sysParamValue";
 
/**
 * 物料信息
 */
export default class ProductController extends BaseController {
  //#region 查询物料信息
  /// <summary>
  /// 查询物料信息
  /// </summary>
  /// <returns>返回物料信息列表</returns>
  @Post()
  public async searchProductList() {
    let userInfo = await this.userInfo;
 
    try {
      //#region 校验数据
      if (!this.body.code) {
        this.info.result = false;
        this.info.msg = "查询条件不能为空";
 
        this.ctx.body = this.info;
      }
      //#endregion
      let where =
        "userProduct_Id=:userProduct_Id and productCode like :productCode  OR productModel like :productModel  OR productName like :productName";
      var productList = await this.dbRead
        .createQueryBuilder(BaseProductInfo, "t")
        .where(where, {
          userProduct_Id: userInfo.userProduct_Id,
          productCode: "%" + this.body.code + "%",
          productModel: "%" + this.body.code + "%",
          productName: "%" + this.body.code + "%"
        })
        .take(30)
        .getMany();
 
      // var productList = await this.dbRead.find(BaseProductInfo, {
      //   where: [
      //     {
      //       userProduct_Id: userInfo.userProduct_Id
      //     },
      //     {
      //       productCode: Like("%" + this.body.code + "%"),
      //       productModel: Like("%" + this.body.code + "%"),
      //       productName: Like("%" + this.body.code + "%")
      //     }
      //   ],
      //   take: 30
      // });
 
      this.info.result = true;
      this.info.data = productList;
 
      this.ctx.body = this.info;
    } catch (ex) {
      let msg = "出现异常:" + ex.message;
      this.info.result = false;
      this.info.msg = msg;
      this.ctx.body = this.info;
    }
  }
  //#endregion
 
  //#region 初始化数据
  /// <summary>
  /// 初始化数据
  /// </summary>
  /// <returns>返回下拉框数据列表</returns>
  @Post()
  public async initData() {
    let userInfo = await this.userInfo;
    try {
      // 供应商
      var providerList = await this.dbRead.find(BaseProvider, {
        userProduct_Id: userInfo.userProduct_Id
      });
 
      // 品牌
      var brandList = await this.dbRead.find(BaseBrand, {
        userProduct_Id: userInfo.userProduct_Id
      });
 
      // 品牌
      var unitList = await this.dbRead.find(SysParamValue, {
        type_Id: 522,
        userProduct_Id: userInfo.userProduct_Id
      });
      if (!unitList.length) {
        // 获得默认参数
        let where = "type_Id=522 And ISNULL(userProduct_Id, 0)=0";
        unitList = await this.dbRead.createQueryBuilder(SysParamValue, "t").where(where).getMany();
      }
 
      // 获得类目集合树
      let where = { parentId: 0, userProduct_Id: userInfo.userProduct_Id };
      var loadInfo = {
        folder: "basicInfo/base",
        dbServer: "Sys",
        tableName: "Base_ProductType",
        tableView: "Base_ProductType",
        keyName: "type_Id",
        nodeName: "typeName",
        fixHasChild: false,
        isBreakWay: false,
        displayBreakWay: false,
        parentName: "parentId",
        orderBy: "OrderNo desc, type_Id",
        where: where,
        extendColumns: ""
      };
      var typeList = await this.ctx.service.common.getTreeDataAll(loadInfo, 10);
 
      this.info.result = true;
      this.info.data = {
        providerList: providerList,
        brandList: brandList,
        unitList: unitList,
        typeList: typeList
      };
      this.info.msg = "";
    } catch (ex) {
      let msg = "出现异常:" + ex.message;
      this.info.result = false;
      this.info.msg = msg;
    }
    this.ctx.body = this.info;
  }
  //#endregion
 
  //#region 新建物料信息
  /// <summary>
  /// 新建物料信息
  /// </summary>
  @Post()
  public async addProduct() {
    let userInfo = await this.userInfo;
    try {
      //#region
      if (!this.body.productModel) {
        this.info.result = false;
        this.info.msg = "物料信息不能为空";
 
        this.ctx.body = this.info;
        return;
      }
 
      var productList = await this.dbRead.find(BaseProductInfo, {
        productModel: this.body.productModel
      });
      if (productList.length > 0) {
        this.info.result = false;
        this.info.msg = this.body.productModel + "物料条码已存在,不能重复添加";
 
        this.ctx.body = this.info;
      }
 
      productList = await this.dbRead.find(BaseProductInfo, {
        productName: this.body.productName,
        userProduct_Id: userInfo.userProduct_Id
      });
      if (productList.length > 0) {
        this.info.result = false;
        this.info.msg = this.body.productName + "物料名称已存在,不能重复添加";
 
        this.ctx.body = this.info;
      }
      //#endregion
 
      let prodInfo = new BaseProductInfo();
      prodInfo = Object.assign(prodInfo, this.body);
      await this.setAccountInfo(prodInfo);
 
      prodInfo.consignorCode = userInfo.consignorCode;
      prodInfo.consignorName = userInfo.consignorName;
      prodInfo.consignor_Id = userInfo.consignor_Id;
      prodInfo.auditing = 0;
      prodInfo.productStatus = 1;
      prodInfo.productCode = await this.service.common.getCodeRegular(254);
      await this.dbWrite.save(prodInfo);
 
      this.info.result = true;
      this.info.msg = "新增成功,等待管理员审核";
    } catch (ex) {
      let msg = "出现异常:" + ex.message;
      this.info.result = false;
      this.info.msg = msg;
    }
    this.ctx.body = this.info;
  }
  //#endregion
 
  //#region getUnitList 获得单位
  /// <summary>
  /// 获得单位
  /// </summary>
  @Post()
  public async getUnitList() {
    let userInfo = await this.userInfo;
    try {
      var unitList = await this.dbRead.find(SysParamValue, {
        type_Id: 522,
        userProduct_Id: userInfo.userProduct_Id
      });
      if (unitList.length <= 0) {
        // 获得默认参数
        let where = "type_Id=522 And ISNULL(userProduct_Id, 0)=0";
        unitList = await this.dbRead.createQueryBuilder(SysParamValue, "t").where(where).getMany();
      }
      this.info.data = unitList.map(item => {
        return {
          smallUnit: item.value02
        };
      });
      this.info.result = true;
      this.ctx.body = this.info;
    } catch (ex) {
      let msg = "出现异常:" + ex.message;
      this.info.result = false;
      this.info.msg = msg;
      this.ctx.body = this.info;
    }
  }
  //#endregion
}