/*
|
* 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;
|
}
|
}
|