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
//#region
import { default as BaseController } from "../baseController";
import { Post } from "egg-shell-decorators";
import { PurchaseOrder } from "../../entity/inbound/purchase/purchaseOrder";
import { PurchaseOrderList } from "../../entity/inbound/purchase/purchaseOrderList";
import { BaseProductInfo } from "../../entity/basicInfo/base/baseProductInfo";
 
//#endregion
 
/**
 * 分拣区回库
 */
export default class PurchaseOrderController extends BaseController {
  //#region savedata 保存数据
  @Post()
  public async savedata() {
    let { ctx } = this;
    let body = ctx.request.body;
    let purchase = new PurchaseOrder();
    let userInfo = await ctx.helper.userInfo();
    let header: any;
    let bodylist: any;
 
    try {
      if (!body.orderCode) {
        let orderCode = await ctx.service.common.getCodeRegular(102);
        let orderDate = body.masterData;
        purchase.orderCode = orderCode;
        purchase.plateCode = orderDate.plateCode;
        purchase.orderType = body.orderType;
        purchase.partStatus = body.partStatus;
        purchase.storageName = orderDate.storageName;
        purchase.storage_Id = orderDate.storage_Id;
        purchase.repairType = "焊装待返修";
        purchase.consignor_Id = 30;
        purchase.consignorCode = "GX30";
        purchase.consignorName = "广州西门子";
 
        purchase.statusText = "焊装待返修";
        purchase.createDate = new Date();
        purchase.createID = userInfo.user_Id;
        purchase.creator = userInfo.userTrueName;
        purchase.applyDate = new Date();
        await this.setAccountInfo(purchase);
        await this.dbWrite.save(purchase);
        let ordermoel = new PurchaseOrderList();
        let orderlist = body.datalist;
        let orderInfo = await this.dbRead.findOne(PurchaseOrder, {
          orderCode: orderCode
        });
        let quantitySum = 0;
        for (let item of orderlist) {
          ordermoel.order_Id = orderInfo.order_Id;
          ordermoel.productCode = item.productCode;
          ordermoel.product_Id = item.product_Id;
 
          var product = await this.dbRead.findOne(BaseProductInfo, {
            product_Id: item.product_Id,
            userProduct_Id: userInfo.userProduct_Id
          });
          ordermoel.productModel = product.productModel;
 
          ordermoel.productName = item.productName;
          ordermoel.quantity = orderDate.nowQuantityOrder;
          ordermoel.produceDate = item.produceDate;
          ordermoel.batchNumber = item.batchNumber;
          await this.setAccountInfo(ordermoel);
 
          await this.dbWrite.save(ordermoel);
 
          quantitySum += ordermoel.quantity;
        }
        if (quantitySum) {
          await this.dbWrite.update(
            PurchaseOrder,
            {
              userProduct_Id: userInfo.userProduct_Id,
              order_Id: orderInfo.order_Id
            },
            {
              totalQuantity: quantitySum
            }
          );
        }
 
        header = await this.dbRead.findOne(PurchaseOrder, {
          orderCode: orderCode,
          userProduct_Id: userInfo.userProduct_Id
        });
        bodylist = await this.dbRead.find(PurchaseOrderList, {
          order_Id: header.order_Id
        });
      } else {
        header = await this.dbRead.findOne(PurchaseOrder, {
          orderCode: body.orderCode,
          userProduct_Id: userInfo.userProduct_Id
        });
 
        bodylist = await this.dbRead.find(PurchaseOrderList, {
          order_Id: header.order_Id,
          productCode: body.datalist[0].productCode
        });
        await this.dbWrite.update(
          PurchaseOrderList,
          {
            userProduct_Id: userInfo.userProduct_Id,
            orderList_Id: bodylist[0].orderList_Id
          },
          {
            quantity: body.masterData.quantity
          }
        );
        var quantityList = await this.dbRead.find(PurchaseOrderList, {
          order_Id: header.order_Id
        });
        let quantitySum = 0;
        for (let item of quantityList) {
          quantitySum += item.quantity;
        }
 
        await this.dbWrite.update(
          PurchaseOrder,
          {
            userProduct_Id: userInfo.userProduct_Id,
            order_Id: header.order_Id
          },
          {
            totalQuantity: quantitySum
          }
        );
      }
    } catch (error) {
      this.info.result = false;
      this.info.msg = "错误:" + error.message;
    }
    this.info.data = header;
    this.info.data2 = bodylist;
    this.info.result = true;
    ctx.body = this.info;
  }
  //#endregion
 
  //#region getlist 选择物料编号获取数据
  @Post()
  public async getlist() {
    let { ctx } = this;
    let body = ctx.request.body;
    let userInfo = await ctx.helper.userInfo();
    try {
      let sql = `
      SELECT product_Id, productName, productCode, '' AS quantity, '合格'AS partStatus, 'WX-01' as positionName, CONVERT(VARCHAR(100),GETDATE(),23) as produceDate FROM Base_ProductInfo where productCode =@0 and userProduct_Id =@1`;
      let datalist = await this.dbRead.query(sql, [body.productCode, userInfo.userProduct_Id]);
      sql = `
      SELECT T.batchNumber FROM Purchase_OrderList AS P,TMS_QuotationList AS T WHERE P.productCode = T.ProductCode AND P.produceDate =T.produceDate AND T.ProductCode =@0`;
      let batchNumber = await this.dbRead.query(sql, [body.productCode]);
      this.info.data = datalist;
      this.info.data2 = batchNumber;
    } catch (error) {
      this.info.result = false;
      this.info.msg = "错误:" + error.message;
    }
    this.info.result = true;
    ctx.body = this.info;
  }
  //#endregion
  //#region getData 器具编号获取数据
  @Post()
  public async getData() {
    let { ctx } = this;
    let body = ctx.request.body;
    // let userInfo = await ctx.helper.userInfo();
    try {
      // let posionName = await this.dbRead.findOne(PurchaseOrder, {
      //   plateCode: body.plateCode,
      //   userProduct_Id: userInfo.userProduct_Id
      // });
      let sql = `SELECT B.productModel,B.productCode,P.storage_Id,P.storageName FROM  Base_ProductInfo B  INNER JOIN Base_Plate P ON B.plateType = P.plateType WHERE   P.plateCode =@0`;
      let productCodes = await this.dbRead.query(sql, [body.plateCode]);
      if (!productCodes || !productCodes.length) {
        this.info.result = false;
        this.info.msg = body.plateCode + "器具编号不存在";
        return;
      }
      this.info.data = {
        storage_Id: productCodes[0].storage_Id,
        storageName: productCodes[0].storageName
      };
      this.info.data2 = productCodes;
    } catch (error) {
      this.info.result = false;
      this.info.msg = "错误:" + error.message;
    }
    this.info.result = true;
    ctx.body = this.info;
  }
  //#endregion
 
  //#region 页面加载
  @Post()
  public async initData() {
    let { ctx } = this;
    let body = ctx.request.body;
    // this.info.result = true;
    let userInfo = await ctx.helper.userInfo();
    let returnInfo = await this.dbRead.findOne(PurchaseOrder, {
      userProduct_Id: userInfo.userProduct_Id,
      order_Id: body.id
    });
    let bodylist = await this.dbRead.find(PurchaseOrderList, {
      order_Id: body.id
    });
    this.info.result = true;
    this.info.data = returnInfo;
    this.info.data2 = bodylist;
 
    this.ctx.body = this.info;
  }
  //#endregion
}