Ben Lin
2024-07-04 68d75a540ec8b3168c3af956ea00b898036d92cd
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
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
import { buildUUID } from '../../../utils/uuid';
import { ApiAction } from '../../model/baseModel';
import {
  WhPageListGetResultModel,
  HouseListItem,
  WhListItem,
  RegionListItem,
  ShelfListItem,
  LocationListItem,
} from '../model/warehoueseModel';
import { genAction, Api, isExist } from '../system';
import { useUserStore } from '/@/store/modules/user';
import { formatToDateTime } from '/@/utils/dateUtil';
import { defHttp } from '/@/utils/http/axios';
//仓库结构树状下拉
export const getTreeList = (params?: HouseListItem) =>
  defHttp.get<WhPageListGetResultModel>(
    { url: Api.GetHouseTreeList, params },
    {
      isTransformResponse: false,
    },
  );
//通过仓库code查要修改的数据
export function getWHList(params: string) {
  let rmParams = genAction('', '');
  if (params.slice(0, 1) == 'W') {
    rmParams = genAction('WMS_WAREHOUSE', " ID = '" + params.slice(1) + "'");
  }
  if (params.slice(0, 1) == 'R') {
    rmParams = genAction('WMS_REGION', " ID = '" + params.slice(1) + "'");
  }
  if (params.slice(0, 1) == 'S') {
    rmParams = genAction('WMS_SHELF', " ID = '" + params.slice(1) + "'");
  }
 
  return getWareHouse(rmParams);
}
async function getWareHouse(params: ApiAction<string>) {
  let data;
  if (params.DataType == 'WMS_WAREHOUSE') {
    data = await defHttp.post<ApiAction<WhListItem>>(
      {
        url: Api.EntityList,
        params,
      },
      {
        errorMessageMode: 'modal',
        isTransformResponse: false,
      },
    );
  }
  if (params.DataType == 'WMS_REGION') {
    data = await defHttp.post<ApiAction<RegionListItem>>(
      {
        url: Api.EntityList,
        params,
      },
      {
        errorMessageMode: 'modal',
        isTransformResponse: false,
      },
    );
  }
  if (params.DataType == 'WMS_SHELF') {
    data = await defHttp.post<ApiAction<ShelfListItem>>(
      {
        url: Api.EntityList,
        params,
      },
      {
        errorMessageMode: 'modal',
        isTransformResponse: false,
      },
    );
  }
  return data.Data;
}
 
/*
 * 新增仓库部分
 */
export const SaveWareHouse = async (params: Recordable, isUpdate: boolean) => {
  const whitem: any = {
    ID: params.ID,
    IS_ACTIVE: params.IS_ACTIVE,
    REMARK: params.REMARK,
    TRANSFER_WH: params.TRANSFER_WH?.trim(),
    WH_NAME: params.WH_NAME,
    WH_CODE: params.WH_CODE,
    ORG_CODE: params.ORG_CODE,
    CREATE_TIME: params.CREATE_TIME,
    CREATE_USER: params.CREATE_USER,
    AUTH_ORG: params.AUTH_ORG,
    //SCAN_AF_CUT:params.SCAN_AF_CUT
  };
  let data;
  if (isUpdate) {
    const time = new Date();
    whitem.UPDATE_TIME = formatToDateTime(time);
    whitem.UPDATE_USER = useUserStore().getUserInfo.userId as string;
    //whitem.ORG_CODE = useUserStore().getUserInfo.orgCode as string;
    //whitem.AUTH_ORG = useUserStore().getUserInfo.orgCode as string;
    data = await defHttp.post(
      { url: Api.UpdateEntity, params: genAction('WMS_WAREHOUSE', whitem) },
      {
        errorMessageMode: 'none',
        isTransformResponse: false,
      },
    );
    defHttp.get(
      { url: Api.GetUpdateOrg, params: { id: whitem.ID } },
      {
        isTransformResponse: false,
      },
    );
  } else {
    const usParams = genAction('WMS_WAREHOUSE', "WH_CODE='" + params.WH_CODE + "'");
    const check = await isExist(usParams);
    console.log('check', check);
    if (!check.Data) {
      const time = new Date();
      whitem.ID = buildUUID(); //生成GUID
      whitem.UPDATE_TIME = formatToDateTime(time);
      whitem.CREATE_USER = useUserStore().getUserInfo.userId as string;
      whitem.UPDATE_USER = useUserStore().getUserInfo.userId as string;
      //whitem.ORG_CODE = useUserStore().getUserInfo.orgCode as string;
      //whitem.AUTH_ORG = useUserStore().getUserInfo.orgCode as string;
      data = await defHttp.post(
        { url: Api.AddEntity, params: genAction('WMS_WAREHOUSE', whitem) },
        {
          errorMessageMode: 'none',
          isTransformResponse: false,
        },
      );
    } else {
      return check.Message;
    }
  }
  return data;
};
/*
 * 新增储区部分
 */
export const SaveRegion = async (params: Recordable, isUpdate: boolean) => {
  const regionitem: RegionListItem = {
    ID: params.ID,
    IS_ACTIVE: params.IS_ACTIVE,
    REMARK: params.REMARK,
    REGION_CODE: params.REGION_CODE,
    REGION_NAME: params.REGION_NAME,
    WH_ID: isUpdate ? params.WH_ID : params.field1,
    ORG_CODE: isUpdate ? params?.ORG_CODE : params?.field2,
    CREATE_TIME: params.CREATE_TIME,
    CREATE_USER: params.CREATE_USER,
    AUTH_ORG: isUpdate ? params?.AUTH_ORG : params?.field2,
  };
  let data;
 
  if (isUpdate) {
    const time = new Date();
    regionitem.UPDATE_TIME = formatToDateTime(time);
    regionitem.UPDATE_USER = useUserStore().getUserInfo.userId as string;
    regionitem.ORG_CODE = useUserStore().getUserInfo.orgCode as string;
    regionitem.AUTH_ORG = useUserStore().getUserInfo.orgCode as string;
    data = await defHttp.post(
      { url: Api.UpdateEntity, params: genAction('WMS_REGION', regionitem) },
      {
        errorMessageMode: 'none',
        isTransformResponse: false,
      },
    );
  } else {
    const usParams = genAction(
      'WMS_REGION',
      "REGION_CODE='" + params.REGION_CODE + "'AND AUTH_ORG='" + regionitem.ORG_CODE + "'",
    );
    const check = await isExist(usParams);
    console.log('check', check);
    if (!check.Data) {
      regionitem.ID = buildUUID(); //生成GUID
      regionitem.UPDATE_TIME = formatToDateTime(new Date());
      regionitem.CREATE_USER = useUserStore().getUserInfo.userId as string;
      regionitem.UPDATE_USER = useUserStore().getUserInfo.userId as string;
      // regionitem.ORG_CODE = useUserStore().getUserInfo.orgCode as string;
      // regionitem.AUTH_ORG = useUserStore().getUserInfo.orgCode as string;
      data = await defHttp.post(
        { url: Api.AddEntity, params: genAction('WMS_REGION', regionitem) },
        {
          errorMessageMode: 'none',
          isTransformResponse: false,
        },
      );
    } else {
      // return check.Message;
      return '重复了';
    }
  }
  return data;
};
/*
 * 新增货架部分
 */
export const SaveShelf = async (params: Recordable, isUpdate: boolean) => {
  const Shelfitem: ShelfListItem = {
    ID: params.ID,
    //SEQ_NO: params.SEQ_NO,
    IS_ACTIVE: params.IS_ACTIVE,
    SHELF_TYPE: params.SHELF_TYPE,
    REMARK: params.REMARK,
    SHELF_NAME: params.SHELF_NAME,
    SHELF_CODE: params.SHELF_CODE,
    FLOORS: params.FLOORS,
    FLOOR_COUNT: params.FLOOR_COUNT,
    REGION_ID: isUpdate ? params?.REGION_ID : params.field1,
    ORG_CODE: isUpdate ? params?.ORG_CODE : params?.field2,
    CREATE_TIME: params.CREATE_TIME,
    CREATE_USER: params.CREATE_USER,
    // AUTH_ORG:params.AUTH_ORG,
    AUTH_ORG: isUpdate ? params?.AUTH_ORG : params?.field2,
  };
  let data;
  if (isUpdate) {
    const time = new Date();
    Shelfitem.UPDATE_TIME = formatToDateTime(time);
    Shelfitem.UPDATE_USER = useUserStore().getUserInfo.userId as string;
    Shelfitem.ORG_CODE = useUserStore().getUserInfo.orgCode as string;
    Shelfitem.AUTH_ORG = useUserStore().getUserInfo.orgCode as string;
    data = await defHttp.post(
      { url: Api.UpdateEntity, params: genAction('WMS_SHELF', Shelfitem) },
      {
        errorMessageMode: 'none',
        isTransformResponse: false,
      },
    );
  } else {
    Shelfitem.ID = buildUUID(); //生成GUID
    Shelfitem.UPDATE_TIME = formatToDateTime(new Date());
    Shelfitem.CREATE_USER = useUserStore().getUserInfo.userId as string;
    Shelfitem.UPDATE_USER = useUserStore().getUserInfo.userId as string;
    // Shelfitem.ORG_CODE = useUserStore().getUserInfo.orgCode as string;
    // Shelfitem.AUTH_ORG = useUserStore().getUserInfo.orgCode as string;
    const usParams = genAction(
      'WMS_SHELF',
      "SHELF_CODE='" + params.SHELF_CODE + "'AND AUTH_ORG='" + Shelfitem.ORG_CODE + "'",
    );
    const check = await isExist(usParams);
    if (!check.Data) {
      //Shelfitem.AUTH_ORG = useUserStore().getUserInfo.orgCode as string;
      data = await defHttp.post(
        { url: Api.AddEntity, params: genAction('WMS_SHELF', Shelfitem) },
        {
          errorMessageMode: 'none',
          isTransformResponse: false,
        },
      );
    } else {
      data = false;
    }
  }
  return data;
};
/*
 * 保存储位
 */
export const UpdateLocation = async (params: Recordable) => {
  const Locationitem: LocationListItem = {
    ID: params.ID,
    //SEQ_NO: params.SEQ_NO,
    IS_ACTIVE: params.IS_ACTIVE,
    IS_SINGLE: params.IS_SINGLE,
    REMARK: params.REMARK,
    LOCATION_CODE: params.LOCATION_CODE,
    LOCATION_NAME: params.LOCATION_NAME,
    SEQ_NO: params.SEQ_NO,
    ORG_CODE: params.ORG_CODE,
    SHELF_ID: params.SHELF_ID,
    FLOOR_NO: params.FLOOR_NO,
    IS_MIX: params.IS_MIX,
    LEDID: params.LEDID,
    CREATE_TIME: params.CREATE_TIME,
    CREATE_USER: params.CREATE_USER,
    AUTH_ORG: params.AUTH_ORG,
  };
  let data;
 
  const time = new Date();
  Locationitem.UPDATE_TIME = formatToDateTime(time);
  Locationitem.UPDATE_USER = useUserStore().getUserInfo.userId as string;
  //Locationitem.ORG_CODE = useUserStore().getUserInfo.orgCode as string;
  Locationitem.AUTH_ORG = useUserStore().getUserInfo.orgCode as string;
  data = await defHttp.post(
    { url: Api.UpdateEntity, params: genAction('WMS_LOCATION', Locationitem) },
    {
      errorMessageMode: 'none',
      isTransformResponse: false,
    },
  );
 
  return data;
};
/*
 * 新增储位部分
 */
export const SaveLocation = async (params: Recordable, isUpdate: boolean) => {
  let data;
  {
    const locations = [];
    params.forEach((items) => {
      items.forEach((item) => {
        item.CREATE_USER = useUserStore().getUserInfo.userId as string;
        item.UPDATE_USER = useUserStore().getUserInfo.userId as string;
        //item.ORG_CODE=useUserStore().getUserInfo.orgCode as string;
        item.AUTH_ORG = useUserStore().getUserInfo.orgCode as string;
        locations.push(item);
      });
    });
    // const locationcode_guize: LocationGuiZeListItem = {
    //   LOCATION_CODE:params.LOCATION_CODE,
    //   IS_ACTIVE:params.IS_ACTIVE,
    //   ORG_CODE:params.ORG_CODE,
    //   SHELF_CODE:params.SHELF_CODE,
    //   ISMIX:params.ISMIX,
    // };
    data = await defHttp.post(
      { url: Api.AddLocation, params: locations },
      {
        errorMessageMode: 'none',
        isTransformResponse: false,
      },
    );
  }
  return data;
};
//查询货架的所有储位
export function getLocationListByPage(params: string, ORG: string) {
  const rmParams = genAction('WMS_LOCATION', {
    QueryAble_T: '',
    where: "SHELF_ID = '" + params + "'",
    order: 'FLOOR_NO desc, SEQ_NO desc',
  });
  return getLocationList(rmParams);
}
async function getLocationList(params: ApiAction<string>) {
  const data = await defHttp.post<ApiAction<LocationListItem[]>>(
    {
      url: Api.QueryUrl,
      params,
    },
    {
      errorMessageMode: 'modal',
      isTransformResponse: false,
    },
  );
  return data.Data;
}
 
//查询货架所在的仓库
export function getWareHouseListByPage(params: string) {
  const rmParams = genAction('V_WH_UNIT', {
    QueryAble_T: '',
    where: "SHELF_CODE = '" + params + "'",
  });
  return getWhList(rmParams);
}
async function getWhList(params: ApiAction<string>) {
  const data = await defHttp.post(
    {
      url: Api.QueryUrl,
      params,
    },
    {
      errorMessageMode: 'modal',
      isTransformResponse: false,
    },
  );
  return data.Data;
}
//查询货架中单个储位
export function getLocationByPage(params: string) {
  let sqlcmd = '';
  if (params != undefined && params != '') {
    sqlcmd += " LOCATION_CODE = '" + params + "'";
  }
  const rmParams = genAction('WMS_LOCATION', sqlcmd);
  return getLocation(rmParams);
}
async function getLocation(params: ApiAction<string>) {
  const data = await defHttp.post<ApiAction<LocationListItem[]>>(
    {
      url: Api.EntityList,
      params,
    },
    {
      errorMessageMode: 'modal',
      isTransformResponse: false,
    },
  );
  return data.Data;
}
//查询检查储位是否有东西
export const CheckLocation = async (params: string) => {
  const dParams = { ID: params, Type: 'shelf' };
  return await defHttp.post(
    { url: Api.CheckLocation, params: dParams },
    {
      errorMessageMode: 'none',
      isTransformResponse: false,
    },
  );
};
 
/*
 * 删除仓库
 */
export const DeleteWareHouse = async (params: Recordable) => {
  const dParams = { ID: params.id.slice(1), Type: params.houseType };
  return await defHttp.post(
    { url: Api.DeleteWareHouse, params: dParams },
    {
      errorMessageMode: 'none',
      isTransformResponse: false,
    },
  );
};
 
//下拉列表
export const optionsListApi = async (params: Recordable) => {
  const usParams = genAction('WMS_SHELF+SHELF_TYPEs', '');
  return await defHttp.post(
    { url: Api.urlQueryEnum, params: usParams },
    {
      errorMessageMode: 'none',
      isTransformResponse: false,
    },
  );
};