Merge branch 'master' of http://121.40.234.130:7788/lyd/zhuzhouzhongwu
This commit is contained in:
@@ -17,6 +17,7 @@ package org.nl.common.utils;
|
||||
|
||||
import cn.hutool.core.io.IoUtil;
|
||||
import cn.hutool.core.util.IdUtil;
|
||||
import cn.hutool.core.util.URLUtil;
|
||||
import cn.hutool.poi.excel.BigExcelWriter;
|
||||
import cn.hutool.poi.excel.ExcelUtil;
|
||||
import org.apache.poi.util.IOUtils;
|
||||
@@ -25,6 +26,7 @@ import org.nl.common.exception.BadRequestException;
|
||||
import org.nl.config.language.LangProcess;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.core.io.ClassPathResource;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import javax.servlet.ServletOutputStream;
|
||||
@@ -344,4 +346,20 @@ public class FileUtil extends cn.hutool.core.io.FileUtil {
|
||||
return getMd5(getByte(file));
|
||||
}
|
||||
|
||||
public static byte[] getByteByTemplate(String templateName) throws IOException {
|
||||
// 使用 ClassPathResource 获取资源
|
||||
ClassPathResource resource = new ClassPathResource(templateName);
|
||||
InputStream inputStream = resource.getInputStream();
|
||||
return IoUtil.readBytes(inputStream);
|
||||
}
|
||||
|
||||
public static void download(String fileName, byte[] fileBytes, HttpServletResponse response) throws IOException {
|
||||
response.setHeader("Content-Disposition", "attachment;filename=" + URLUtil.encode(fileName));
|
||||
response.addHeader("Content-Length", "" + fileBytes.length);
|
||||
response.setHeader("Access-Control-Allow-Origin", "*");
|
||||
response.setHeader("Access-Control-Expose-Headers", "Content-Disposition");
|
||||
response.setContentType("application/octet-stream;charset=UTF-8");
|
||||
IoUtil.write(response.getOutputStream(), true, fileBytes);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@ import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
/*
|
||||
/**
|
||||
* @author ZZQ
|
||||
* @Date 2024/5/29 16:26
|
||||
*/
|
||||
@@ -17,6 +17,7 @@ public class InteracteDto<T> {
|
||||
|
||||
private String service;
|
||||
private String type;
|
||||
private String system;
|
||||
private String ip;
|
||||
private String request_time;
|
||||
private String trace_id;
|
||||
|
||||
@@ -1,20 +1,12 @@
|
||||
package org.nl.gateway.service;
|
||||
|
||||
import cn.hutool.core.lang.Assert;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
||||
import org.nl.common.exception.BadRequestException;
|
||||
import org.nl.common.utils.RedissonUtils;
|
||||
import org.nl.gateway.dto.InteracteDto;
|
||||
import org.nl.gateway.service.impl.GateWayServiceImpl;
|
||||
import org.nl.wms.sch_manage.service.ISchBasePointService;
|
||||
import org.nl.wms.sch_manage.service.ISchBaseTaskService;
|
||||
import org.nl.wms.sch_manage.service.dao.SchBasePoint;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
|
||||
/**
|
||||
* 网关执行接口层
|
||||
@@ -24,11 +16,6 @@ import java.util.concurrent.atomic.AtomicReference;
|
||||
*/
|
||||
@Service
|
||||
public class GateWayService {
|
||||
|
||||
@Autowired
|
||||
private GateWayServiceImpl gateWayServiceImpl;
|
||||
@Autowired
|
||||
private ISchBasePointService iSchBasePointService;
|
||||
@Autowired
|
||||
private ISchBaseTaskService iSchBaseTaskService;
|
||||
|
||||
@@ -38,42 +25,11 @@ public class GateWayService {
|
||||
//处理日志相关
|
||||
JSONObject result = new JSONObject();
|
||||
String service = param.getService();
|
||||
String type = param.getType();
|
||||
//根据服务拆分不同的业务
|
||||
if ("InStorage".equals(service)) {
|
||||
RedissonUtils.lock(() -> {
|
||||
String taskCode = gateWayServiceImpl.applyTask(param.getService(), type, jsonObject, param);
|
||||
result.put("taskCode", taskCode);
|
||||
}, param.getService() + param.getType(), null);
|
||||
}
|
||||
if ("Task".equals(service)) {
|
||||
iSchBaseTaskService.operation(jsonObject);
|
||||
}
|
||||
if ("DeviceInfo".equals(service)) {
|
||||
|
||||
}
|
||||
if ("Device".equals(service)) {
|
||||
Assert.noNullElements(new Object[]{jsonObject.getString("devicePoint"), jsonObject.getString("status")}, "请求参数不能为空");
|
||||
if (!"1207".equals(jsonObject.getString("devicePoint")) && !"1210".equals(jsonObject.getString("devicePoint"))) {
|
||||
throw new BadRequestException("您输入的拣选位不存在,请输入1207或1210拣选位!");
|
||||
}
|
||||
RedissonUtils.lock(() -> {
|
||||
LambdaUpdateWrapper<SchBasePoint> updateWrapper = new LambdaUpdateWrapper<>();
|
||||
updateWrapper.set(SchBasePoint::getIs_used, "0".equals(jsonObject.getString("status")) ? 0 : 1);
|
||||
iSchBasePointService.update(updateWrapper);
|
||||
}, param.getService() + param.getType(), null);
|
||||
}
|
||||
if ("ErrorInfo".equals(service)) {
|
||||
Assert.noNullElements(new Object[]{type, jsonObject.getString("msg")}, "请求参数不能为空");
|
||||
String msg = jsonObject.getString("msg").trim();
|
||||
//iSchBasePointService.sendErrorMsg(type,null, msg);
|
||||
}
|
||||
if ("ErrorTask".equals(service)) {
|
||||
AtomicReference<JSONObject> reference = new AtomicReference<>(new JSONObject());
|
||||
RedissonUtils.lock(() -> {
|
||||
// reference.set(iSchBaseTaskService.errorTask(jsonObject, param.getType()));
|
||||
}, param.getService() + param.getType(), null);
|
||||
return reference.get();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -11,10 +11,14 @@ import org.nl.wms.basedata_manage.service.IMdMeMaterialbaseService;
|
||||
import org.nl.wms.basedata_manage.service.dao.MdMeMaterialbase;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.IOException;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
@@ -69,5 +73,18 @@ public class MaterialbaseController {
|
||||
return new ResponseEntity<>(HttpStatus.NO_CONTENT);
|
||||
}
|
||||
|
||||
@PostMapping("/importExcel")
|
||||
@Log("导入物料")
|
||||
public ResponseEntity<Object> importExcel(@RequestPart("file") MultipartFile file) {
|
||||
iMdMeMaterialbaseService.importExcel(file);
|
||||
return new ResponseEntity<>(HttpStatus.NO_CONTENT);
|
||||
}
|
||||
|
||||
@Log("下载导入模板")
|
||||
@GetMapping(value = "/downloadImportMaterialTemplate", produces = MediaType.APPLICATION_OCTET_STREAM_VALUE)
|
||||
public void downloadImportUserTemplate(HttpServletResponse response) {
|
||||
iMdMeMaterialbaseService.downloadImportMaterialTemplate(response);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -10,10 +10,13 @@ import org.nl.wms.basedata_manage.service.IMdPbMeasureunitService;
|
||||
import org.nl.wms.basedata_manage.service.dao.MdPbMeasureunit;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
@@ -61,4 +64,17 @@ public class MeasureUnitController {
|
||||
return new ResponseEntity<>(HttpStatus.OK);
|
||||
}
|
||||
|
||||
@PostMapping("/importExcel")
|
||||
@Log("导入单位")
|
||||
public ResponseEntity<Object> importExcel(@RequestPart("file") MultipartFile file) {
|
||||
iMdPbMeasureunitService.importExcel(file);
|
||||
return new ResponseEntity<>(HttpStatus.NO_CONTENT);
|
||||
}
|
||||
|
||||
@Log("下载导入模板")
|
||||
@GetMapping(value = "/downloadImportUnitTemplate", produces = MediaType.APPLICATION_OCTET_STREAM_VALUE)
|
||||
public void downloadImportUnitTemplate(HttpServletResponse response) {
|
||||
iMdPbMeasureunitService.downloadImportUnitTemplate(response);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -5,7 +5,9 @@ import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import org.nl.common.domain.query.PageQuery;
|
||||
import org.nl.wms.basedata_manage.service.dao.MdMeMaterialbase;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
@@ -55,7 +57,12 @@ public interface IMdMeMaterialbaseService extends IService<MdMeMaterialbase> {
|
||||
/**
|
||||
* 根据编码获取物料
|
||||
* @param material_code 物料编码
|
||||
* @param flag 为空是否抛出异常
|
||||
* @return 返回结果
|
||||
*/
|
||||
MdMeMaterialbase getByCode(String material_code);
|
||||
MdMeMaterialbase getByCode(String material_code, Boolean flag);
|
||||
|
||||
void importExcel(MultipartFile file);
|
||||
|
||||
void downloadImportMaterialTemplate(HttpServletResponse response);
|
||||
}
|
||||
|
||||
@@ -4,7 +4,9 @@ import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import org.nl.common.domain.query.PageQuery;
|
||||
import org.nl.wms.basedata_manage.service.dao.MdPbMeasureunit;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
@@ -49,6 +51,9 @@ public interface IMdPbMeasureunitService extends IService<MdPbMeasureunit> {
|
||||
* @param unit_code 编码
|
||||
* @return 实体类
|
||||
*/
|
||||
MdPbMeasureunit getByCode(String unit_code);
|
||||
MdPbMeasureunit getByCode(String unit_code, Boolean flag);
|
||||
|
||||
void importExcel(MultipartFile file);
|
||||
|
||||
void downloadImportUnitTemplate(HttpServletResponse response);
|
||||
}
|
||||
|
||||
@@ -1,16 +1,20 @@
|
||||
package org.nl.wms.basedata_manage.service.impl;
|
||||
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import cn.hutool.core.io.IoUtil;
|
||||
import cn.hutool.core.map.MapUtil;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.hutool.core.util.URLUtil;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import org.apache.poi.ss.usermodel.*;
|
||||
import org.nl.common.domain.query.PageQuery;
|
||||
import org.nl.common.exception.BadRequestException;
|
||||
import org.nl.common.utils.FileUtil;
|
||||
import org.nl.common.utils.IdUtil;
|
||||
import org.nl.common.utils.SecurityUtils;
|
||||
import org.nl.wms.basedata_manage.service.IMdMeMaterialbaseService;
|
||||
@@ -18,9 +22,14 @@ import org.nl.wms.basedata_manage.service.dao.MdMeMaterialbase;
|
||||
import org.nl.wms.basedata_manage.service.dao.mapper.MdMeMaterialbaseMapper;
|
||||
import org.nl.wms.ext_manage.service.WmsToErpService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.core.io.ClassPathResource;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@@ -43,6 +52,8 @@ public class MdMeMaterialbaseServiceImpl extends ServiceImpl<MdMeMaterialbaseMap
|
||||
*/
|
||||
@Autowired
|
||||
private WmsToErpService wmsToErpService;
|
||||
@Autowired
|
||||
private IMdMeMaterialbaseService materialbaseService;
|
||||
|
||||
@Override
|
||||
public IPage<MdMeMaterialbase> queryAll(Map whereJson, PageQuery page) {
|
||||
@@ -62,7 +73,7 @@ public class MdMeMaterialbaseServiceImpl extends ServiceImpl<MdMeMaterialbaseMap
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void create(MdMeMaterialbase dto) {
|
||||
// 根据物料编码查询是否有相同物料编码的物料
|
||||
MdMeMaterialbase mdMeMaterialbase = this.baseMapper.selectOne(
|
||||
@@ -70,7 +81,7 @@ public class MdMeMaterialbaseServiceImpl extends ServiceImpl<MdMeMaterialbaseMap
|
||||
.eq(MdMeMaterialbase::getMaterial_code, dto.getMaterial_code())
|
||||
);
|
||||
if (ObjectUtil.isNotEmpty(mdMeMaterialbase)) {
|
||||
throw new BadRequestException("当前物料编码已存在【"+dto.getMaterial_code()+"】");
|
||||
throw new BadRequestException("当前物料编码已存在【" + dto.getMaterial_code() + "】");
|
||||
}
|
||||
|
||||
// 新增
|
||||
@@ -85,7 +96,7 @@ public class MdMeMaterialbaseServiceImpl extends ServiceImpl<MdMeMaterialbaseMap
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void update(MdMeMaterialbase dto) {
|
||||
MdMeMaterialbase mdMeMaterialbase = this.baseMapper.selectById(dto.getMaterial_id());
|
||||
if (ObjectUtil.isEmpty(mdMeMaterialbase)) {
|
||||
@@ -100,13 +111,13 @@ public class MdMeMaterialbaseServiceImpl extends ServiceImpl<MdMeMaterialbaseMap
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void delete(Set<String> ids) {
|
||||
this.baseMapper.deleteBatchIds(ids);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void materialSync(JSONObject whereJson) {
|
||||
JSONObject resultJson = wmsToErpService.materialSync(whereJson);
|
||||
List<JSONObject> dataList = resultJson.getJSONArray("data").toJavaList(JSONObject.class);
|
||||
@@ -145,16 +156,76 @@ public class MdMeMaterialbaseServiceImpl extends ServiceImpl<MdMeMaterialbaseMap
|
||||
}
|
||||
|
||||
@Override
|
||||
public MdMeMaterialbase getByCode(String materialCode) {
|
||||
public MdMeMaterialbase getByCode(String materialCode, Boolean flag) {
|
||||
MdMeMaterialbase one = this.getOne(
|
||||
new QueryWrapper<MdMeMaterialbase>().lambda().nested(r -> {
|
||||
r.eq(MdMeMaterialbase::getMaterial_id, materialCode)
|
||||
.or()
|
||||
.eq(MdMeMaterialbase::getMaterial_code, materialCode);
|
||||
}));
|
||||
if (ObjectUtil.isEmpty(one)) {
|
||||
if (ObjectUtil.isEmpty(one) && flag) {
|
||||
throw new BadRequestException("物料信息为【" + materialCode + "】不存在!");
|
||||
}
|
||||
return one;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void importExcel(MultipartFile file) {
|
||||
// 1. 校验文件
|
||||
if (file.isEmpty()) {
|
||||
throw new IllegalArgumentException("上传文件不能为空");
|
||||
}
|
||||
|
||||
try (InputStream inputStream = file.getInputStream();
|
||||
Workbook workbook = WorkbookFactory.create(inputStream)) {
|
||||
|
||||
// 2. 获取第一个Sheet
|
||||
Sheet sheet = workbook.getSheetAt(0);
|
||||
|
||||
// 3. 从第二行开始遍历 (索引1)
|
||||
List<MdMeMaterialbase> dataList = new ArrayList<>();
|
||||
for (int rowIndex = 1; rowIndex <= sheet.getLastRowNum(); rowIndex++) {
|
||||
Row row = sheet.getRow(rowIndex);
|
||||
if (row == null) continue; // 跳过空行
|
||||
Cell materialCodeCell = row.getCell(0);
|
||||
MdMeMaterialbase byCode = materialbaseService.getByCode(String.valueOf(materialCodeCell), false);
|
||||
if (ObjectUtil.isNotEmpty(byCode)) {
|
||||
throw new BadRequestException("物料[" + materialCodeCell + "]已存在!");
|
||||
}
|
||||
|
||||
// 4. 读取6个字段
|
||||
MdMeMaterialbase entity = new MdMeMaterialbase();
|
||||
entity.setMaterial_id(IdUtil.getStringId());
|
||||
entity.setMaterial_code(String.valueOf(materialCodeCell));
|
||||
entity.setMaterial_name(String.valueOf(row.getCell(1)));
|
||||
entity.setMaterial_spec(String.valueOf(row.getCell(2)));
|
||||
entity.setMaterial_model(String.valueOf(row.getCell(3)));
|
||||
entity.setBase_unit_id(String.valueOf(row.getCell(4)));
|
||||
entity.setAss_unit_id(String.valueOf(row.getCell(5)));
|
||||
entity.setCreate_id(SecurityUtils.getCurrentUserId());
|
||||
entity.setCreate_name(SecurityUtils.getCurrentNickName());
|
||||
entity.setCreate_time(DateUtil.now());
|
||||
dataList.add(entity);
|
||||
}
|
||||
|
||||
// 6. 批量保存(根据实际持久层实现)
|
||||
materialbaseService.saveBatch(dataList);
|
||||
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException("文件读取失败: " + e.getMessage());
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException("导入失败: " + e.getMessage());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void downloadImportMaterialTemplate(HttpServletResponse response) {
|
||||
try {
|
||||
byte[] byteByTemplate = FileUtil.getByteByTemplate("excel/material_template.xlsx");
|
||||
FileUtil.download("物料导入模板.xlsx", byteByTemplate, response);
|
||||
} catch (Exception e) {
|
||||
log.error(">>> 下载导入模板失败:", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,17 +8,27 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import org.apache.poi.ss.usermodel.*;
|
||||
import org.nl.common.domain.query.PageQuery;
|
||||
import org.nl.common.exception.BadRequestException;
|
||||
import org.nl.common.utils.FileUtil;
|
||||
import org.nl.common.utils.IdUtil;
|
||||
import org.nl.common.utils.SecurityUtils;
|
||||
import org.nl.wms.basedata_manage.enums.BaseDataEnum;
|
||||
import org.nl.wms.basedata_manage.service.IMdPbMeasureunitService;
|
||||
import org.nl.wms.basedata_manage.service.dao.MdMeMaterialbase;
|
||||
import org.nl.wms.basedata_manage.service.dao.MdPbMeasureunit;
|
||||
import org.nl.wms.basedata_manage.service.dao.mapper.MdPbMeasureunitMapper;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.math.BigDecimal;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
@@ -95,14 +105,72 @@ public class MdPbMeasureunitServiceImpl extends ServiceImpl<MdPbMeasureunitMappe
|
||||
}
|
||||
|
||||
@Override
|
||||
public MdPbMeasureunit getByCode(String unit_code) {
|
||||
public MdPbMeasureunit getByCode(String unit_code, Boolean flag) {
|
||||
MdPbMeasureunit one = this.getOne(
|
||||
new QueryWrapper<MdPbMeasureunit>().lambda()
|
||||
.eq(MdPbMeasureunit::getUnit_code, unit_code)
|
||||
);
|
||||
if (ObjectUtil.isEmpty(one)) {
|
||||
if (ObjectUtil.isEmpty(one) && flag) {
|
||||
throw new BadRequestException("计量单位编码为【"+unit_code+"】不存在!");
|
||||
}
|
||||
return one;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void importExcel(MultipartFile file) {
|
||||
// 1. 校验文件
|
||||
if (file.isEmpty()) {
|
||||
throw new IllegalArgumentException("上传文件不能为空");
|
||||
}
|
||||
|
||||
try (InputStream inputStream = file.getInputStream();
|
||||
Workbook workbook = WorkbookFactory.create(inputStream)) {
|
||||
|
||||
// 2. 获取第一个Sheet
|
||||
Sheet sheet = workbook.getSheetAt(0);
|
||||
|
||||
// 3. 从第二行开始遍历 (索引1)
|
||||
List<MdPbMeasureunit> dataList = new ArrayList<>();
|
||||
for (int rowIndex = 1; rowIndex <= sheet.getLastRowNum(); rowIndex++) {
|
||||
Row row = sheet.getRow(rowIndex);
|
||||
if (row == null) {
|
||||
continue; // 跳过空行
|
||||
}
|
||||
Cell cell1 = row.getCell(0);
|
||||
MdPbMeasureunit byCode = this.getByCode(String.valueOf(cell1), false);
|
||||
if (ObjectUtil.isNotEmpty(byCode)) {
|
||||
throw new BadRequestException("物料[" + cell1 + "]已存在!");
|
||||
}
|
||||
|
||||
// 4. 读取6个字段
|
||||
MdPbMeasureunit entity = new MdPbMeasureunit();
|
||||
entity.setMeasure_unit_id(IdUtil.getStringId());
|
||||
entity.setUnit_code(String.valueOf(cell1));
|
||||
entity.setUnit_name(String.valueOf(row.getCell(1)));
|
||||
entity.setQty_precision(new BigDecimal(String.valueOf(row.getCell(2))));
|
||||
entity.setCreate_id(SecurityUtils.getCurrentUserId());
|
||||
entity.setCreate_name(SecurityUtils.getCurrentNickName());
|
||||
entity.setCreate_time(DateUtil.now());
|
||||
dataList.add(entity);
|
||||
}
|
||||
|
||||
// 6. 批量保存
|
||||
this.saveBatch(dataList);
|
||||
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException("文件读取失败: " + e.getMessage());
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException("导入失败: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void downloadImportUnitTemplate(HttpServletResponse response) {
|
||||
try {
|
||||
byte[] byteByTemplate = FileUtil.getByteByTemplate("excel/unit_template.xlsx");
|
||||
FileUtil.download("单位导入模板.xlsx", byteByTemplate, response);
|
||||
} catch (Exception e) {
|
||||
log.error(">>> 下载导入模板失败:", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -98,7 +98,7 @@ public class StructattrServiceImpl extends ServiceImpl<StructattrMapper, Structa
|
||||
.like(StrUtil.isNotEmpty(search), Structattr::getStruct_code, search)
|
||||
.like(StrUtil.isNotEmpty(search), Structattr::getStruct_name, search)
|
||||
.eq(StrUtil.isNotEmpty(stor_id), Structattr::getStor_id, stor_id)
|
||||
.eq(StrUtil.isNotEmpty(sect_id), Structattr::getSect_id, sect_id)
|
||||
.eq(StrUtil.isNotEmpty(sect_id), Structattr::getSect_code, sect_id)
|
||||
.eq(StrUtil.isNotEmpty(lock_type), Structattr::getLock_type, lock_type)
|
||||
.eq(StrUtil.isNotEmpty(layer_num), Structattr::getLayer_num, layer_num)
|
||||
.eq(StrUtil.isNotEmpty(is_used), Structattr::getIs_used, is_used)
|
||||
@@ -197,8 +197,9 @@ public class StructattrServiceImpl extends ServiceImpl<StructattrMapper, Structa
|
||||
dto.setUpdate_time(now);
|
||||
dto.setUpdate_id(currentUserId);
|
||||
dto.setUpdate_name(nickName);
|
||||
Sectattr sectattr = iSectattrService.findByCode(dto.getSect_id());
|
||||
Sectattr sectattr = iSectattrService.findByCode(dto.getSect_code());
|
||||
BsrealStorattr bsrealStorattr = iBsrealStorattrService.findById(sectattr.getStor_id());
|
||||
dto.setSect_id(sectattr.getSect_id());
|
||||
dto.setSect_code(sectattr.getSect_code());
|
||||
dto.setSect_name(sectattr.getSect_name());
|
||||
dto.setStor_id(bsrealStorattr.getStor_id());
|
||||
|
||||
@@ -79,107 +79,4 @@ public class AlleyAveRuleHandler extends Decisioner<Structattr, JSONObject> {
|
||||
return subList;
|
||||
}
|
||||
|
||||
// public static void main(String[] args) {
|
||||
// List<Structattr> list = new ArrayList<>();
|
||||
// for (int i =0;i<10;i++){
|
||||
// Structattr structattr = new Structattr();
|
||||
// structattr.setRow_num(new Random().nextInt(2)+1);
|
||||
// structattr.setCol_num(new Random().nextInt(10)+1);
|
||||
// structattr.setLayer_num(new Random().nextInt(2)+1);
|
||||
// list.add(structattr);
|
||||
// }
|
||||
// System.out.println(list);
|
||||
// ArrayList<String> of = ListOf.of("x", "z","y");
|
||||
// list.sort((o1, o2) -> {
|
||||
// Integer rowNum1 = o1.getRow_num();
|
||||
// Integer colNum1 = o1.getCol_num();
|
||||
// Integer layerNum1 = o1.getLayer_num();
|
||||
// Integer rowNum2 = o2.getRow_num();
|
||||
// Integer colNum2 = o2.getCol_num();
|
||||
// Integer layerNum2 = o2.getLayer_num();
|
||||
// HashMap<String,Integer> of1 = MapOf.of("x", rowNum1, "y", colNum1, "z", layerNum1);
|
||||
// HashMap<String,Integer> of2 = MapOf.of("x", rowNum2, "y", colNum2, "z", layerNum2);
|
||||
// for (String sort : of) {
|
||||
// Integer in1 = of1.get(sort);
|
||||
// Integer in2 = of2.get(sort);
|
||||
// if (in1 > in2){
|
||||
// return 1;
|
||||
// }
|
||||
// if (in1 < in2){
|
||||
// return -1;
|
||||
// }
|
||||
// }
|
||||
// return 0;
|
||||
// });
|
||||
// System.out.println(list.toString());
|
||||
// }
|
||||
|
||||
/**
|
||||
* 入库策略
|
||||
*
|
||||
* @param attrList :仓位集合
|
||||
* @param jsonParam:materialId :物料标识(此方法只根据物料进行匹配)
|
||||
* @return List<Structattr> :仓位集合
|
||||
*/
|
||||
// private List<Structattr> inHandler(List<Structattr> attrList, PmFormData jsonParam) {
|
||||
// // in查询条件处理
|
||||
// List<Integer> blockNumIn = attrList.stream()
|
||||
// .map(Structattr::getBlock_num)
|
||||
// .distinct()
|
||||
// .collect(Collectors.toList());
|
||||
// // 查询相同巷道货位相同物料
|
||||
// List<Structattr> blockAttrList = null;
|
||||
// iStructattrService.getByQuery(new StructattrQuery());
|
||||
// // 如果为空说明这些巷道都没有相同物料的巷道,则返回所有仓位
|
||||
// if (ObjectUtil.isEmpty(blockAttrList)) {
|
||||
// return attrList;
|
||||
// }
|
||||
// // 计算每个巷道的相同物料
|
||||
// Map<Integer, List<Structattr>> collectMap = blockAttrList.stream()
|
||||
// .collect(Collectors.groupingBy(Structattr::getBlock_num));
|
||||
// // 巷道
|
||||
// int blockNum = blockAttrList.get(0).getBlock_num().intValue();
|
||||
// // 集合数量
|
||||
// int size = blockAttrList.size();
|
||||
// for (Integer num : collectMap.keySet()) {
|
||||
// int min = Math.min(size, collectMap.get(num).size());
|
||||
// if (size > min) {
|
||||
// // 返回最小的巷道
|
||||
// blockNum = num.intValue();
|
||||
// size = min;
|
||||
// }
|
||||
// }
|
||||
// // 匹配相同巷道的集合并返回
|
||||
// int finalBlockNum = blockNum;
|
||||
// return attrList.stream()
|
||||
// .filter(row -> row.getBlock_num().intValue() == finalBlockNum)
|
||||
// .collect(Collectors.toList());
|
||||
// }
|
||||
|
||||
/**
|
||||
* 出库策略 - 查询物料最多的巷道
|
||||
*
|
||||
* @param attrList: 仓位物料
|
||||
* @return 巷道
|
||||
*/
|
||||
// private int getMaxMaterial(List<Structattr> attrList) {
|
||||
// // 根据巷道分组
|
||||
// Map<Integer, List<Structattr>> collectMap = attrList.stream()
|
||||
// .collect(Collectors.groupingBy(Structattr::getBlock_num));
|
||||
// // 找最大物料巷道
|
||||
// // 巷道
|
||||
// int blockNum = attrList.get(0).getBlock_num().intValue();
|
||||
// // 集合数量
|
||||
// int size = 0;
|
||||
// for (Integer num : collectMap.keySet()) {
|
||||
// int max = Math.max(size, collectMap.get(num).size());
|
||||
// if (size < max) {
|
||||
// // 返回最大的巷道
|
||||
// blockNum = num.intValue();
|
||||
// size = max;
|
||||
// }
|
||||
// }
|
||||
// return blockNum;
|
||||
// }
|
||||
|
||||
}
|
||||
|
||||
@@ -190,7 +190,7 @@ public class PdaIosInServiceImpl implements PdaIosInService {
|
||||
// 数量
|
||||
String qty = whereJson.getString("qty");
|
||||
MdPbStoragevehicleinfo vehicleDao = iMdPbStoragevehicleinfoService.getByCode(whereJson.getString("vehicle_code"));
|
||||
MdMeMaterialbase materDao = iMdMeMaterialbaseService.getByCode(materialId);
|
||||
MdMeMaterialbase materDao = iMdMeMaterialbaseService.getByCode(materialId, true);
|
||||
MdPbMeasureunit unitDao = iMdPbMeasureunitService.getById(materDao.getBase_unit_id());
|
||||
// 校验
|
||||
if (ObjectUtil.isEmpty(vehicleDao) || ObjectUtil.isEmpty(materDao) || ObjectUtil.isEmpty(materDao)) {
|
||||
@@ -778,7 +778,7 @@ public class PdaIosInServiceImpl implements PdaIosInService {
|
||||
ArrayList<HashMap> tableData = new ArrayList<>();
|
||||
HashMap<String, String> dtl = new HashMap<>();
|
||||
GroupPlate plateDao = plateDaoList.get(0);
|
||||
MdMeMaterialbase materDao = iMdMeMaterialbaseService.getByCode(plateDao.getMaterial_id());
|
||||
MdMeMaterialbase materDao = iMdMeMaterialbaseService.getByCode(plateDao.getMaterial_id(), true);
|
||||
dtl.put("storagevehicle_code", plateDao.getStoragevehicle_code());
|
||||
dtl.put("material_id", materDao.getMaterial_id());
|
||||
dtl.put("material_code", materDao.getMaterial_code());
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Reference in New Issue
Block a user