李林
2023-10-07 658d4927d468c47208fd012d9128b09249c07eff
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
/*
 *    Copyright (c) 2018-2025, ztt All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *
 * Redistributions of source code must retain the above copyright notice,
 * this list of conditions and the following disclaimer.
 * Redistributions in binary form must reproduce the above copyright
 * notice, this list of conditions and the following disclaimer in the
 * documentation and/or other materials provided with the distribution.
 * Neither the name of the pig4cloud.com developer nor the names of its
 * contributors may be used to endorse or promote products derived from
 * this software without specific prior written permission.
 * Author: ztt
 */
package com.chinaztt.mes.basic.service.impl;
 
import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.chinaztt.ifs.api.feign.IfsFeignClient;
import com.chinaztt.mes.basic.dto.LocationDTO;
import com.chinaztt.mes.basic.dto.LocationIfsMoveDTO;
import com.chinaztt.mes.basic.entity.Location;
import com.chinaztt.mes.basic.entity.Warehouse;
import com.chinaztt.mes.basic.excel.LocationData;
import com.chinaztt.mes.basic.mapper.LocationMapper;
import com.chinaztt.mes.basic.mapper.WarehouseMapper;
import com.chinaztt.mes.basic.service.LocationService;
import com.chinaztt.mes.basic.service.WarehouseService;
import com.chinaztt.ztt.admin.api.feign.RemoteParamService;
import com.chinaztt.ztt.common.core.constant.SecurityConstants;
import com.chinaztt.ztt.common.core.util.R;
import com.google.gson.Gson;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;
 
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.stream.Collector;
import java.util.stream.Collectors;
 
/**
 * 库位基础数据
 *
 * @author sunxl
 * @date 2020-09-21 08:18:12
 */
@Service
@AllArgsConstructor
public class LocationServiceImpl extends ServiceImpl<LocationMapper, Location> implements LocationService {
    private WarehouseMapper warehouseMapper;
    private static final String LOCATION_QC_SEND_BACK = "LOCATION_QC_SEND_BACK";
    public static final String CONTRACT = "IFS_DOMAIN";
    private RemoteParamService remoteParamService;
    private IfsFeignClient ifsFeignClient;
 
    @Override
    public IPage<List<Location>> getLoc(Page page, QueryWrapper<LocationDTO> ew) {
        return baseMapper.getLoc(page, ew);
    }
 
    @Override
    public IPage<List<LocationDTO>> getLocationDtoPage(Page page, QueryWrapper<LocationDTO> ew) {
        return baseMapper.getLocationDtoPage(page, ew);
    }
 
    @Override
    public void deleteLocation(List<Long> ids) {
        baseMapper.deleteBatchIds(ids);
    }
 
    @Override
    public List<Location> getPrepare(Location location) {
        return baseMapper.getPrepare(location);
    }
 
    @Override
    public void importLocationExcel(List<LocationData> list) {
        if (CollectionUtil.isEmpty(list)) {
            return;
        }
        for (LocationData data : list) {
            Location newLocation = new Location();
            newLocation.setFactoryId(data.getFactoryId());
            newLocation.setLocGroup(data.getLocGroup());
            newLocation.setLocName(data.getLocName());
            newLocation.setLocNo(data.getLocNo());
            baseMapper.insert(newLocation);
        }
    }
 
    @Override
    public List<JSONObject> pdaList(QueryWrapper<LocationDTO> gen) {
        return baseMapper.pdaList(gen);
    }
 
    @Override
    public Location getDeaultLocation() {
        //查询参数配置的值
        String locationQcSendBack = remoteParamService.getByKey(LOCATION_QC_SEND_BACK, SecurityConstants.FROM_IN).getData();
        return baseMapper.selectOne(Wrappers.<Location>lambdaQuery().eq(Location::getLocNo, locationQcSendBack));
    }
 
    @Override
    public R getIfsLocation(String locationGroup, String locationNo, String locationDesc) {
        JSONObject jsonObject = new JSONObject();
        if (StringUtils.isNotBlank(locationGroup)) {
            jsonObject.put("LOCATION_GROUP", locationGroup);
        }
        if (StringUtils.isNotBlank(locationNo)) {
            jsonObject.put("LOCATION_NO", locationNo);
        }
        if (StringUtils.isNotBlank(locationDesc)) {
            jsonObject.put("LOCATION_DESC", locationDesc);
        }
        R result = ifsFeignClient.queryLocationInfoStd(jsonObject, true);
        if (result.getCode() == 0) {
            JSONObject data = (JSONObject) JSON.toJSON(result.getData());
            return R.ok(data.getJSONArray("LIST_INFO"), "OK");
        } else {
            return R.failed("IFS错误——" + result.getMsg());
        }
    }
 
    @Override
    public R getIfsLocationGroup() {
        R result = ifsFeignClient.queryLocationGroupStd(new JSONObject(), true);
        if (result.getCode() == 0) {
            JSONObject data = (JSONObject) JSON.toJSON(result.getData());
            return R.ok(data.getJSONArray("LIST_INFO"), "OK");
        } else {
            return R.failed("IFS错误——" + result.getMsg());
        }
    }
 
    @Override
    public R moveIfsLocation(LocationIfsMoveDTO moveDTO) {
        String contract = remoteParamService.getByKey(CONTRACT, SecurityConstants.FROM_IN).getData();
        if (StringUtils.isBlank(contract)) {
            throw new RuntimeException("系统参数中未配置IFS域,无法移库");
        }
        List<LocationIfsMoveDTO.DataBean> dataBeans = new ArrayList<>();
        moveDTO.getBATCH_INFO().forEach(e -> {
            if (!StrUtil.equals(e.getLOCATION_NO(), e.getTO_LOCATION_NO())) {
                e.setTO_CONTRACT(contract);
                dataBeans.add(e);
            }
        });
        if (CollectionUtil.isEmpty(dataBeans)) {
            return R.ok();
        }
        Gson gson = new Gson();
        String jsonstr = gson.toJson(moveDTO);
        JSONObject jsonObject = JSONObject.parseObject(jsonstr);//解决序列化时自动将大写转小写问题
        R response = ifsFeignClient.importMovePartStd(jsonObject, true);
        if (response.getCode() == 0) {
            return R.ok();
        } else {
            throw new RuntimeException("请求ifs失败" + response.getMsg());
        }
    }
 
    @Override
    public List<Map> getLocationByGroups(List<Long> localGroups) {
        List<Map> locationByGroups = baseMapper.getLocationByGroups(localGroups);
        return locationByGroups;
    }
}