|
|
|
@ -87,7 +87,7 @@ public class MaterialControllerService {
|
|
|
|
wmsMaterial.setCreateTime(LocalDateTime.now());
|
|
|
|
wmsMaterial.setCreateTime(LocalDateTime.now());
|
|
|
|
wmsMaterial.setId(null);
|
|
|
|
wmsMaterial.setId(null);
|
|
|
|
materialService.add(wmsMaterial);
|
|
|
|
materialService.add(wmsMaterial);
|
|
|
|
}else {
|
|
|
|
} else {
|
|
|
|
wmsMaterial.setUpdateBy(UserUtil.getUserName());
|
|
|
|
wmsMaterial.setUpdateBy(UserUtil.getUserName());
|
|
|
|
wmsMaterial.setUpdateTime(LocalDateTime.now());
|
|
|
|
wmsMaterial.setUpdateTime(LocalDateTime.now());
|
|
|
|
materialService.update(wmsMaterial);
|
|
|
|
materialService.update(wmsMaterial);
|
|
|
|
@ -113,16 +113,16 @@ public class MaterialControllerService {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void exportSelect(HttpServletResponse response, List<Long> ids) throws IOException {
|
|
|
|
public void exportSelect(HttpServletResponse response, List<Long> ids) throws IOException {
|
|
|
|
if (CollectionUtil.isEmpty(ids)){
|
|
|
|
if (CollectionUtil.isEmpty(ids)) {
|
|
|
|
exportTemplate(response);
|
|
|
|
exportTemplate(response);
|
|
|
|
}else {
|
|
|
|
} else {
|
|
|
|
List<WmsMaterial> wmsMaterials = materialService.listByIds(ids);
|
|
|
|
List<WmsMaterial> wmsMaterials = materialService.listByIds(ids);
|
|
|
|
List<MaterialAllExcelExportDTO> datas = wmsMaterials.stream().map(model -> Convert.convert(MaterialAllExcelExportDTO.class, model)).collect(Collectors.toList());
|
|
|
|
List<MaterialAllExcelExportDTO> datas = wmsMaterials.stream().map(model -> Convert.convert(MaterialAllExcelExportDTO.class, model)).collect(Collectors.toList());
|
|
|
|
response.setContentType(MediaType.APPLICATION_OCTET_STREAM_VALUE);
|
|
|
|
response.setContentType(MediaType.APPLICATION_OCTET_STREAM_VALUE);
|
|
|
|
response.setHeader(HttpHeaders.CONTENT_DISPOSITION, "attachment;filename=" + URLEncoder.encode("图纸导出.xlsx", StandardCharsets.UTF_8));
|
|
|
|
response.setHeader(HttpHeaders.CONTENT_DISPOSITION, "attachment;filename=" + URLEncoder.encode("图纸导出.xlsx", StandardCharsets.UTF_8));
|
|
|
|
if (CollectionUtil.isEmpty(datas)) {
|
|
|
|
if (CollectionUtil.isEmpty(datas)) {
|
|
|
|
exportTemplate(response);
|
|
|
|
exportTemplate(response);
|
|
|
|
}else {
|
|
|
|
} else {
|
|
|
|
new Workbook()
|
|
|
|
new Workbook()
|
|
|
|
.addSheet(new ListSheet<>(datas).setRowHeight(100))
|
|
|
|
.addSheet(new ListSheet<>(datas).setRowHeight(100))
|
|
|
|
.writeTo(response.getOutputStream());
|
|
|
|
.writeTo(response.getOutputStream());
|
|
|
|
@ -150,24 +150,25 @@ public class MaterialControllerService {
|
|
|
|
public ApiResult uploadPics(HttpServletResponse response, @Valid @NotEmpty List<MultipartFile> files) throws Exception {
|
|
|
|
public ApiResult uploadPics(HttpServletResponse response, @Valid @NotEmpty List<MultipartFile> files) throws Exception {
|
|
|
|
List<String> pics = new ArrayList<>();
|
|
|
|
List<String> pics = new ArrayList<>();
|
|
|
|
List<WmsMaterial> materials = new ArrayList<>();
|
|
|
|
List<WmsMaterial> materials = new ArrayList<>();
|
|
|
|
for (MultipartFile file : files){
|
|
|
|
for (MultipartFile file : files) {
|
|
|
|
String name = file.getOriginalFilename();
|
|
|
|
String name = file.getOriginalFilename();
|
|
|
|
String materialNo = name.substring(0, name.lastIndexOf("."));
|
|
|
|
String materialNo = name.substring(0, name.lastIndexOf("."));
|
|
|
|
BomMaterialDTO bomMaterialDTO = bomMaterialService.getMaterialInfo(materialNo);
|
|
|
|
BomMaterialDTO bomMaterialDTO = bomMaterialService.getMaterialInfo(materialNo);
|
|
|
|
if (Objects.isNull(bomMaterialDTO)) {
|
|
|
|
if (Objects.isNull(bomMaterialDTO)) {
|
|
|
|
pics.add(name);
|
|
|
|
pics.add(name);
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
WmsMaterial wmsMaterial=materialService.getCurrent(materialNo);
|
|
|
|
WmsMaterial wmsMaterial = materialService.getCurrent(materialNo);
|
|
|
|
if (Objects.isNull(wmsMaterial) || !(StrUtil.isNotBlank(wmsMaterial.getImage()) && Objects.nonNull(wmsMaterial.getWeight()))){
|
|
|
|
if (Objects.isNull(wmsMaterial) || StrUtil.isNotBlank(wmsMaterial.getImage()))
|
|
|
|
wmsMaterial=new WmsMaterial()
|
|
|
|
{
|
|
|
|
|
|
|
|
wmsMaterial = new WmsMaterial()
|
|
|
|
.setId(null)
|
|
|
|
.setId(null)
|
|
|
|
.setVersion(Objects.isNull(wmsMaterial)?1:wmsMaterial.getVersion()+1)
|
|
|
|
.setVersion(Objects.isNull(wmsMaterial) ? 1 : wmsMaterial.getVersion() + 1)
|
|
|
|
.setNo(bomMaterialDTO.getMaterialNo())
|
|
|
|
.setNo(bomMaterialDTO.getMaterialNo())
|
|
|
|
.setDescribe(bomMaterialDTO.getMaterialDesc())
|
|
|
|
.setDescribe(bomMaterialDTO.getMaterialDesc())
|
|
|
|
.setDrawingNo(bomMaterialDTO.getDrawingNo())
|
|
|
|
.setDrawingNo(bomMaterialDTO.getDrawingNo())
|
|
|
|
.setCreateBy(UserUtil.getUserName())
|
|
|
|
.setCreateBy(UserUtil.getUserName())
|
|
|
|
.setCreateTime(LocalDateTime.now());
|
|
|
|
.setCreateTime(LocalDateTime.now());
|
|
|
|
}else {
|
|
|
|
}else{
|
|
|
|
wmsMaterial.setDescribe(bomMaterialDTO.getMaterialDesc());
|
|
|
|
wmsMaterial.setDescribe(bomMaterialDTO.getMaterialDesc());
|
|
|
|
wmsMaterial.setDrawingNo(bomMaterialDTO.getDrawingNo());
|
|
|
|
wmsMaterial.setDrawingNo(bomMaterialDTO.getDrawingNo());
|
|
|
|
wmsMaterial.setUpdateBy(UserUtil.getUserName());
|
|
|
|
wmsMaterial.setUpdateBy(UserUtil.getUserName());
|
|
|
|
@ -183,18 +184,18 @@ public class MaterialControllerService {
|
|
|
|
materialService.saveOrUpdateBatch(materials);
|
|
|
|
materialService.saveOrUpdateBatch(materials);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return ApiResult.success();
|
|
|
|
return ApiResult.success();
|
|
|
|
}else {
|
|
|
|
} else {
|
|
|
|
return ApiResult.error("以下图片SAP料号无效:"+StrUtil.join(",", pics));
|
|
|
|
return ApiResult.error("以下图片SAP料号无效:" + StrUtil.join(",", pics));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private String buildFilePath(String fileName) {
|
|
|
|
private String buildFilePath(String fileName) {
|
|
|
|
String fileType="." + FilenameUtils.getExtension(fileName);
|
|
|
|
String fileType = "." + FilenameUtils.getExtension(fileName);
|
|
|
|
return StrUtil.format("admin/{}/{}/{}/{}{}", LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyyMMdd")), UserUtil.getUserId()
|
|
|
|
return StrUtil.format("admin/{}/{}/{}/{}{}", LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyyMMdd")), UserUtil.getUserId()
|
|
|
|
, RandomUtil.randomString(4), IdUtil.fastUUID(), fileType);
|
|
|
|
, RandomUtil.randomString(4), IdUtil.fastUUID(), fileType);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public ApiResult uploadZip(HttpServletResponse response, @Valid @NotEmpty MultipartFile file) throws Exception{
|
|
|
|
public ApiResult uploadZip(HttpServletResponse response, @Valid @NotEmpty MultipartFile file) throws Exception {
|
|
|
|
String name = file.getOriginalFilename();
|
|
|
|
String name = file.getOriginalFilename();
|
|
|
|
VUtil.trueThrowBusinessError(!StrUtil.endWith(name, ".zip")).throwMessage("请上传zip格式的压缩包");
|
|
|
|
VUtil.trueThrowBusinessError(!StrUtil.endWith(name, ".zip")).throwMessage("请上传zip格式的压缩包");
|
|
|
|
String url = fileUploadService.upload(buildFilePath(name), file);
|
|
|
|
String url = fileUploadService.upload(buildFilePath(name), file);
|
|
|
|
@ -202,7 +203,7 @@ public class MaterialControllerService {
|
|
|
|
query.setJobNameEq("图纸zip导入");
|
|
|
|
query.setJobNameEq("图纸zip导入");
|
|
|
|
ResultDTO<List<JobInfoDTO>> result = powerJobClient.queryJob(query);
|
|
|
|
ResultDTO<List<JobInfoDTO>> result = powerJobClient.queryJob(query);
|
|
|
|
if (result.isSuccess()) {
|
|
|
|
if (result.isSuccess()) {
|
|
|
|
powerJobClient.runJob(result.getData().get(0).getId(),url+"|"+UserUtil.getUserName(),0);
|
|
|
|
powerJobClient.runJob(result.getData().get(0).getId(), url + "|" + UserUtil.getUserName(), 0);
|
|
|
|
return ApiResult.success("任务已提交");
|
|
|
|
return ApiResult.success("任务已提交");
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
return ApiResult.error(result.getMessage());
|
|
|
|
return ApiResult.error(result.getMessage());
|
|
|
|
@ -225,14 +226,14 @@ public class MaterialControllerService {
|
|
|
|
if (checkAndImport(data)) {
|
|
|
|
if (checkAndImport(data)) {
|
|
|
|
return ApiResult.success();
|
|
|
|
return ApiResult.success();
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
try(ByteArrayOutputStream osOut = new ByteArrayOutputStream()) {
|
|
|
|
try (ByteArrayOutputStream osOut = new ByteArrayOutputStream()) {
|
|
|
|
new Workbook()
|
|
|
|
new Workbook()
|
|
|
|
.addSheet(new ListSheet<>(data))
|
|
|
|
.addSheet(new ListSheet<>(data))
|
|
|
|
.writeTo(osOut);
|
|
|
|
.writeTo(osOut);
|
|
|
|
try(ByteArrayInputStream isIn = new ByteArrayInputStream(osOut.toByteArray())) {
|
|
|
|
try (ByteArrayInputStream isIn = new ByteArrayInputStream(osOut.toByteArray())) {
|
|
|
|
return ApiResult.error(STATE.DataNoCheckPass, "导入文件失败", fileUploadService.upload("temp/" + DateTimeUtil.format(LocalDate.now(), "yyyyMMdd") + "/" + IdUtil.fastUUID() + ".xlsx", isIn, "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"));
|
|
|
|
return ApiResult.error(STATE.DataNoCheckPass, "导入文件失败", fileUploadService.upload("temp/" + DateTimeUtil.format(LocalDate.now(), "yyyyMMdd") + "/" + IdUtil.fastUUID() + ".xlsx", isIn, "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}catch (Exception e){
|
|
|
|
} catch (Exception e) {
|
|
|
|
return ApiResult.error(STATE.BusinessError, "保存文件出错");
|
|
|
|
return ApiResult.error(STATE.BusinessError, "保存文件出错");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@ -242,28 +243,28 @@ public class MaterialControllerService {
|
|
|
|
public boolean checkAndImport(List<MaterialExcelImportDTO> data) {
|
|
|
|
public boolean checkAndImport(List<MaterialExcelImportDTO> data) {
|
|
|
|
List<WmsMaterial> forAdd = new ArrayList<>();
|
|
|
|
List<WmsMaterial> forAdd = new ArrayList<>();
|
|
|
|
List<WmsMaterial> forupdate = new ArrayList<>();
|
|
|
|
List<WmsMaterial> forupdate = new ArrayList<>();
|
|
|
|
MaterialSearchQO qo=new MaterialSearchQO();
|
|
|
|
MaterialSearchQO qo = new MaterialSearchQO();
|
|
|
|
qo.setPageSize(Integer.MAX_VALUE);
|
|
|
|
qo.setPageSize(Integer.MAX_VALUE);
|
|
|
|
List<MaterialVO> dbMaterials=materialService.search(qo).getRecords();
|
|
|
|
List<MaterialVO> dbMaterials = materialService.search(qo).getRecords();
|
|
|
|
List<BomMaterialDTO> bomMaterials=bomMaterialService.getList(data.stream().map(MaterialExcelImportDTO::getNo).collect(Collectors.toSet()));
|
|
|
|
List<BomMaterialDTO> bomMaterials = bomMaterialService.getList(data.stream().map(MaterialExcelImportDTO::getNo).collect(Collectors.toSet()));
|
|
|
|
int index=0;
|
|
|
|
int index = 0;
|
|
|
|
for (MaterialExcelImportDTO dto : data) {
|
|
|
|
for (MaterialExcelImportDTO dto : data) {
|
|
|
|
System.out.println((++index)+" 处理物料:"+dto.getNo());
|
|
|
|
System.out.println((++index) + " 处理物料:" + dto.getNo());
|
|
|
|
WmsMaterial material = new WmsMaterial();
|
|
|
|
WmsMaterial material = new WmsMaterial();
|
|
|
|
StringBuilder sb = new StringBuilder();
|
|
|
|
StringBuilder sb = new StringBuilder();
|
|
|
|
if (StrUtil.isBlank(dto.getNo())) {
|
|
|
|
if (StrUtil.isBlank(dto.getNo())) {
|
|
|
|
sb.append("SAP料号不能为空;");
|
|
|
|
sb.append("SAP料号不能为空;");
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
BomMaterialDTO bomMaterial = bomMaterials.stream().filter(m->StrUtil.equals(dto.getNo(),m.getMaterialNo())).findFirst().orElse(null);
|
|
|
|
BomMaterialDTO bomMaterial = bomMaterials.stream().filter(m -> StrUtil.equals(dto.getNo(), m.getMaterialNo())).findFirst().orElse(null);
|
|
|
|
if (Objects.isNull(bomMaterial)) {
|
|
|
|
if (Objects.isNull(bomMaterial)) {
|
|
|
|
sb.append("SAP料号无效;");
|
|
|
|
sb.append("SAP料号无效;");
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
MaterialVO currentMaterial = dbMaterials.stream().filter(m->StrUtil.equals(m.getNo(),dto.getNo())).findFirst().orElse(null);
|
|
|
|
MaterialVO currentMaterial = dbMaterials.stream().filter(m -> StrUtil.equals(m.getNo(), dto.getNo())).findFirst().orElse(null);
|
|
|
|
if (Objects.isNull(currentMaterial) || (StrUtil.isNotBlank(currentMaterial.getImage()) && Objects.nonNull(currentMaterial.getWeight()))){
|
|
|
|
if (Objects.isNull(currentMaterial) || (StrUtil.isNotBlank(currentMaterial.getImage()) && Objects.nonNull(currentMaterial.getWeight()))) {
|
|
|
|
material.setCreateBy(UserUtil.getUserName());
|
|
|
|
material.setCreateBy(UserUtil.getUserName());
|
|
|
|
material.setCreateTime(LocalDateTime.now());
|
|
|
|
material.setCreateTime(LocalDateTime.now());
|
|
|
|
forAdd.add(material);
|
|
|
|
forAdd.add(material);
|
|
|
|
}else {
|
|
|
|
} else {
|
|
|
|
material.setId(currentMaterial.getId());
|
|
|
|
material.setId(currentMaterial.getId());
|
|
|
|
material.setUpdateBy(UserUtil.getUserName());
|
|
|
|
material.setUpdateBy(UserUtil.getUserName());
|
|
|
|
material.setUpdateTime(LocalDateTime.now());
|
|
|
|
material.setUpdateTime(LocalDateTime.now());
|
|
|
|
@ -276,41 +277,41 @@ public class MaterialControllerService {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (StrUtil.isBlank(dto.getWeight())) {
|
|
|
|
if (StrUtil.isBlank(dto.getWeight())) {
|
|
|
|
sb.append("重量不能为空;");
|
|
|
|
sb.append("重量不能为空;");
|
|
|
|
} else if (!NumberUtils.isCreatable(dto.getWeight())){
|
|
|
|
} else if (!NumberUtils.isCreatable(dto.getWeight())) {
|
|
|
|
sb.append("重量无效;");
|
|
|
|
sb.append("重量无效;");
|
|
|
|
}else {
|
|
|
|
} else {
|
|
|
|
material.setWeight(new BigDecimal(dto.getWeight()));
|
|
|
|
material.setWeight(new BigDecimal(dto.getWeight()));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (StrUtil.isBlank(dto.getHeight())) {
|
|
|
|
if (StrUtil.isBlank(dto.getHeight())) {
|
|
|
|
sb.append("高度不能为空;");
|
|
|
|
sb.append("高度不能为空;");
|
|
|
|
} else if (!NumberUtils.isCreatable(dto.getHeight())){
|
|
|
|
} else if (!NumberUtils.isCreatable(dto.getHeight())) {
|
|
|
|
sb.append("高度无效;");
|
|
|
|
sb.append("高度无效;");
|
|
|
|
}else {
|
|
|
|
} else {
|
|
|
|
material.setHeight(new BigDecimal(dto.getHeight()));
|
|
|
|
material.setHeight(new BigDecimal(dto.getHeight()));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (StrUtil.isBlank(dto.getLength())) {
|
|
|
|
if (StrUtil.isBlank(dto.getLength())) {
|
|
|
|
sb.append("长度不能为空;");
|
|
|
|
sb.append("长度不能为空;");
|
|
|
|
} else if (!NumberUtils.isCreatable(dto.getLength())){
|
|
|
|
} else if (!NumberUtils.isCreatable(dto.getLength())) {
|
|
|
|
sb.append("长度无效;");
|
|
|
|
sb.append("长度无效;");
|
|
|
|
}else {
|
|
|
|
} else {
|
|
|
|
material.setLength(new BigDecimal(dto.getLength()));
|
|
|
|
material.setLength(new BigDecimal(dto.getLength()));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (StrUtil.isBlank(dto.getWidth())) {
|
|
|
|
if (StrUtil.isBlank(dto.getWidth())) {
|
|
|
|
sb.append("宽度不能为空;");
|
|
|
|
sb.append("宽度不能为空;");
|
|
|
|
} else if (!NumberUtils.isCreatable(dto.getWidth())){
|
|
|
|
} else if (!NumberUtils.isCreatable(dto.getWidth())) {
|
|
|
|
sb.append("宽度无效;");
|
|
|
|
sb.append("宽度无效;");
|
|
|
|
}else {
|
|
|
|
} else {
|
|
|
|
material.setWidth(new BigDecimal(dto.getWidth()));
|
|
|
|
material.setWidth(new BigDecimal(dto.getWidth()));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
material.setRequirement(dto.getRequirement());
|
|
|
|
material.setRequirement(dto.getRequirement());
|
|
|
|
dto.setError(sb.toString());
|
|
|
|
dto.setError(sb.toString());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (data.stream().noneMatch(it -> StrUtil.isNotBlank(it.getError()))) {
|
|
|
|
if (data.stream().noneMatch(it -> StrUtil.isNotBlank(it.getError()))) {
|
|
|
|
if (CollectionUtil.isNotEmpty(forAdd)){
|
|
|
|
if (CollectionUtil.isNotEmpty(forAdd)) {
|
|
|
|
materialService.saveBatch(forAdd,1000);
|
|
|
|
materialService.saveBatch(forAdd, 1000);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (CollectionUtil.isNotEmpty(forupdate)){
|
|
|
|
if (CollectionUtil.isNotEmpty(forupdate)) {
|
|
|
|
materialService.updateBatchById(forupdate,1000);
|
|
|
|
materialService.updateBatchById(forupdate, 1000);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@ -318,7 +319,7 @@ public class MaterialControllerService {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void exportSearch(HttpServletResponse response, @Valid MaterialSearchQO request) throws IOException {
|
|
|
|
public void exportSearch(HttpServletResponse response, @Valid MaterialSearchQO request) throws IOException {
|
|
|
|
List<MaterialVO> list=materialService.searchNonPage(request);
|
|
|
|
List<MaterialVO> list = materialService.searchNonPage(request);
|
|
|
|
List<MaterialAllExcelExportDTO> datas = list.stream().map(model -> Convert.convert(MaterialAllExcelExportDTO.class, model)).collect(Collectors.toList());
|
|
|
|
List<MaterialAllExcelExportDTO> datas = list.stream().map(model -> Convert.convert(MaterialAllExcelExportDTO.class, model)).collect(Collectors.toList());
|
|
|
|
response.setContentType(MediaType.APPLICATION_OCTET_STREAM_VALUE);
|
|
|
|
response.setContentType(MediaType.APPLICATION_OCTET_STREAM_VALUE);
|
|
|
|
response.setHeader(HttpHeaders.CONTENT_DISPOSITION, "attachment;filename=" + URLEncoder.encode("图纸导出.xlsx", StandardCharsets.UTF_8));
|
|
|
|
response.setHeader(HttpHeaders.CONTENT_DISPOSITION, "attachment;filename=" + URLEncoder.encode("图纸导出.xlsx", StandardCharsets.UTF_8));
|
|
|
|
|