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
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
import BaseController from "../baseController";
import { Post } from "egg-shell-decorators";
import { TMSWayBill } from "../../entity/express/tms/tmsWayBill";
 
import { TMSVoyage } from "../../entity/express/tms/tmsVoyage";
import { TMSWayBillTracking } from "../../entity/express/tms/tmsWayBillTracking";
import { In } from "typeorm";
 
/**
 * 菜单管理
 */
export default class VoyageController extends BaseController {
  //#region  实际起飞时间
  /**
   * 实际起飞时间
   */
  @Post()
  public async upActualTakeOffTime() {
    let { ctx } = this;
    let body = ctx.request.body;
    let userInfo = await ctx.helper.userInfo();
    try {
      //#region 校验数据
      if (!body.voyageCode) {
        this.info.result = false;
        this.info.msg = "数据不存在";
        ctx.body = this.info;
        return;
      }
      //#endregion
      this.info.result = true;
      var voyageInfo = await this.dbRead.findOne(TMSVoyage, {
        voyageCode: body.voyageCode
      });
      if (voyageInfo != null) {
        await this.dbWrite.update(TMSVoyage, voyageInfo.voyage_Id, {
          actualTakeOffTime: body.actualTakeOffTime
        });
        await this.dbWrite
          .createQueryBuilder(TMSWayBill, "t")
          .update()
          .set({
            orderStatus: "航空已发运"
          })
          .where(
            `voyageCode=:voyageCode AND NOT EXISTS (SELECT 1 FROM TMS_WayBillTracking WHERE wayBillCode=TMS_WayBill.wayBillCode AND FromStatus='航空已发运')`,
            {
              voyageCode: body.voyageCode
            }
          )
          .execute();
 
        this.dbWrite
          .createQueryBuilder(TMSWayBillTracking, "t")
          .update()
          .set({
            createDate: body.actualTakeOffTime
          })
          .where(
            `action='ATD录入' AND EXISTS (SELECT 1 FROM TMS_WayBill WHERE wayBillCode=TMS_WayBillTracking.wayBillCode AND voyageCode=:voyageCode)`,
            {
              voyageCode: body.voyageCode
            }
          )
          .execute();
 
        let sql = `
                    INSERT INTO TMS_WayBillTracking
                    (
                        Action, Remark, user_Id, userTrueName, CreateID, Creator, createDate, 
                        PlatUser_Id, PlatUserCode, PlatUserName, PlatCorpName, UserProduct_Id, UserProductCode, UserProductAlias, 
                        WayBill_Id, wayBillCode, FromStatus, ToStatus, Consignor_Id, ConsignorName, Storage_Id, StorageName, 
                        clientDesc
                    )
                    SELECT 'ATD录入' AS Action, Remark, ${userInfo.user_Id}, '${userInfo.userTrueName}', ${userInfo.user_Id}, '${userInfo.userTrueName}', '${body.actualTakeOffTime}', 
                        1 AS PlatUser_Id, PlatUserCode, PlatUserName, PlatCorpName, 1007 AS UserProduct_Id, UserProductCode, UserProductAlias, 
                        WayBill_Id, wayBillCode, orderStatus AS FromStatus, '航空已发运' AS ToStatus, Consignor_Id, ConsignorName, 
                        Storage_Id, StorageName, '航班起飞' AS clientDesc
                    FROM TMS_WayBill
                    WHERE voyageCode='${voyageInfo.voyageCode}' AND NOT EXISTS (SELECT 1 FROM TMS_WayBillTracking WHERE wayBillCode=TMS_WayBill.wayBillCode AND Action='ATD录入');`;
        await this.dbWrite.query(sql);
      } else {
        this.info.result = false;
        this.info.msg = "数据不存在";
      }
    } catch (ex) {
      this.info.result = false;
      this.info.msg = "错误信息:" + ex.message;
    }
    ctx.body = this.info;
  }
  //#endregion
 
  //#region  实际落地时间
  /**
   * 实际落地时间
   */
  @Post()
  public async upActualLandingTime() {
    let { ctx } = this;
    let body = ctx.request.body;
    let userInfo = await ctx.helper.userInfo();
    try {
      //#region 校验数据
      if (!body.voyageCode) {
        this.info.result = false;
        this.info.msg = "数据不存在";
        ctx.body = this.info;
        return;
      }
      //#endregion
      var voyageInfo = await this.dbRead.findOne(TMSVoyage, {
        voyageCode: body.voyageCode
      });
      if (voyageInfo != null) {
        await this.dbWrite.update(TMSVoyage, voyageInfo.voyage_Id, {
          actualLandingTime: body.actualLandingTime
        });
        this.info.result = true;
 
        this.dbWrite
          .createQueryBuilder(TMSWayBillTracking, "t")
          .update()
          .set({
            createDate: body.actualLandingTime
          })
          .where(
            `action='实落ATA' AND EXISTS (SELECT 1 FROM TMS_WayBill WHERE wayBillCode=TMS_WayBillTracking.wayBillCode AND voyageCode=:voyageCode)`,
            {
              voyageCode: body.voyageCode
            }
          )
          .execute();
 
        let sql = `
                    INSERT INTO TMS_WayBillTracking
                    (
                        Action, Remark, user_Id, userTrueName, CreateID, Creator, createDate, 
                        PlatUser_Id, PlatUserCode, PlatUserName, PlatCorpName, UserProduct_Id, UserProductCode, UserProductAlias, 
                        WayBill_Id, wayBillCode, FromStatus, ToStatus, Consignor_Id, ConsignorName, Storage_Id, StorageName, 
                        clientDesc
                    )
                    SELECT '实落ATA' AS Action, Remark, ${userInfo.user_Id}, '${userInfo.userTrueName}', ${userInfo.user_Id}, '${userInfo.userTrueName}', '${body.actualLandingTime}', 
                        1 AS PlatUser_Id, PlatUserCode, PlatUserName, PlatCorpName, 1007 AS UserProduct_Id, UserProductCode, UserProductAlias, 
                        WayBill_Id, wayBillCode, orderStatus AS FromStatus, '航班到达' AS ToStatus, Consignor_Id, ConsignorName, 
                        Storage_Id, StorageName, '航班到达' AS clientDesc
                    FROM TMS_WayBill
          WHERE voyageCode='${voyageInfo.voyageCode}'  AND NOT EXISTS (SELECT 1 FROM TMS_WayBillTracking WHERE wayBillCode=TMS_WayBill.wayBillCode AND Action='实落ATA');`;
        await this.dbWrite.query(sql);
 
        await this.dbWrite
          .createQueryBuilder(TMSWayBill, "t")
          .update()
          .set({
            orderStatus: "航班到达",
            modifyDate: new Date()
          })
          .where(
            `voyageCode=:voyageCode AND NOT EXISTS (SELECT 1 FROM TMS_WayBillTracking WHERE wayBillCode=TMS_WayBill.wayBillCode AND FromStatus='航班到达')`,
            {
              voyageCode: body.voyageCode
            }
          )
          .execute();
 
        this.info.result = true;
      } else {
        this.info.result = false;
        this.info.msg = "数据不存在";
      }
    } catch (ex) {
      this.info.result = false;
      this.info.msg = "错误信息:" + ex.message;
    }
    ctx.body = this.info;
    return;
  }
  //#endregion
 
  //#region 校验托盘号
  /**
   * 校验托盘号
   */
  @Post()
  public async checkPlateCode() {
    let { ctx } = this;
    let body = ctx.request.body;
    try {
      if (!body.voyageCode) {
        this.info.result = true;
        this.info.msg = "托盘号不能为空";
        ctx.body = this.info;
        return;
      }
 
      var waybill = await this.dbRead.findOne(TMSWayBill, {
        plateCode: body.voyageCode
      });
      if (waybill != null) {
        this.info.result = true;
      } else {
        this.info.result = false;
        this.info.msg = "该托盘号不符合规则";
      }
    } catch (ex) {
      this.info.msg = ex.message;
      this.info.result = false;
    }
    ctx.body = this.info;
    return;
  }
  //#endregion
 
  //#region 航空发运
  /**
   * 航空发运
   */
  @Post()
  public async send() {
    let { ctx } = this;
    let body = ctx.request.body;
    try {
      if (!Array.isArray(body.ids) || !body.ids.length) {
        this.info.result = true;
        this.info.msg = "至少选择一项";
        ctx.body = this.info;
        return;
      }
 
      let voyageInfo = await this.dbRead.findOne(TMSVoyage, {
        voyage_Id: In(body.ids)
      });
 
      if (voyageInfo) {
        for (let plateCode of voyageInfo.plateCodes.split(",")) {
          // 根据托盘号查询运单号
          var wayInfo = await this.dbRead.findOne(TMSWayBill, {
            plateCode: plateCode
          });
          if (wayInfo) {
            // 修改运单中的航空主单号
            await this.dbWrite.update(
              TMSWayBill,
              {
                plateCode: plateCode
              },
              {
                voyageCode: voyageInfo.voyageCode
              }
            );
          }
        }
      }
 
      await this.dbWrite.update(
        TMSVoyage,
        {
          voyage_Id: In(body.ids)
        },
        {
          voyageStatus: "已发运"
        }
      );
      this.info.result = true;
      this.info.msg = "发运成功";
    } catch (ex) {
      this.info.msg = ex.message;
      this.info.result = false;
    }
    ctx.body = this.info;
    return;
  }
  //#endregion
 
  //#region 清关
  /**
   * 清关
   */
  @Post()
  public async clearance() {
    let { ctx } = this;
    let body = ctx.request.body;
    try {
      if (!Array.isArray(body.ids) || !body.ids.length) {
        this.info.result = true;
        this.info.msg = "至少选择一项";
        ctx.body = this.info;
        return;
      }
      await this.dbWrite.update(
        TMSVoyage,
        {
          voyage_Id: In(body.ids)
        },
        {
          voyageStatus: "清关中"
        }
      );
 
      this.info.result = true;
      this.info.msg = "已设置为清关中";
    } catch (ex) {
      this.info.msg = ex.message;
      this.info.result = false;
    }
    ctx.body = this.info;
    return;
  }
  //#endregion
 
  //#region 清空运单表中的航空主单号
  @Post()
  public async deleteVoyageCode() {
    if (!this.body.voyageCode) {
      this.info.result = false;
      this.info.msg = "未找到航空主单号";
      this.ctx.body = this.info;
    }
    try {
      for (let item of this.body.voyageCode) {
        await this.dbWrite.update(
          TMSWayBill,
          { voyageCode: item },
          {
            voyageCode: null
          }
        );
      }
      this.info.result = true;
      this.info.msg = "清除运单表航空主单号成功";
      this.ctx.body = this.info;
    } catch (error) {
      this.info.result = false;
      this.info.msg = "未找到航空主单号" + error.message;
      this.ctx.body = this.info;
    }
  }
 
  //#endregion
}