/* * 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.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.Factory; 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.FactoryMapper; 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.util.DictUtils; import com.chinaztt.ztt.admin.api.entity.SysDictItem; 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.Objects; /** * 库位基础数据 * * @author sunxl * @date 2020-09-21 08:18:12 */ @Service @AllArgsConstructor public class LocationServiceImpl extends ServiceImpl implements LocationService { private WarehouseMapper warehouseMapper; private FactoryMapper factoryMapper; 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; private DictUtils dictUtils; @Override public IPage> getLoc(Page page, QueryWrapper ew) { return baseMapper.getLoc(page, ew); } @Override public IPage> getLocationDtoPage(Page page, QueryWrapper ew) { return baseMapper.getLocationDtoPage(page, ew); } @Override public void deleteLocation(List ids) { baseMapper.deleteBatchIds(ids); } @Override public List getPrepare(Location location) { return baseMapper.getPrepare(location); } @Override public void importLocationExcel(List list) { if (CollectionUtil.isEmpty(list)) { return; } list.forEach(System.out::println); List factories = factoryMapper.selectList(null); List warehouses = warehouseMapper.selectList(null); List dict = dictUtils.getDict("warehouse_type"); for (LocationData data : list) { QueryWrapperQueryWrapper = new QueryWrapper<>(); QueryWrapper.lambda().eq(Location::getLocNo,data.getLocNo()); Location location = baseMapper.selectOne(QueryWrapper); if(!Objects.isNull(location)){ log.error("库位编号重复=====》"+data.getLocNo()); continue; } Location newLocation = new Location(); dict.forEach(a->{ if (a.getLabel().equals(data.getLocType())){ newLocation.setLocType(a.getValue()); } }); if("启用".equals(data.getLocState())){ newLocation.setLocStatus(1); }else{ newLocation.setLocStatus(0); } for (int i = 0; i pdaList(QueryWrapper 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.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 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 getLocationByGroups(List localGroups) { List locationByGroups = baseMapper.getLocationByGroups(localGroups); return locationByGroups; } }