From 83bc0f64985c54cc6d4b6d0cdce5653d783f2437 Mon Sep 17 00:00:00 2001 From: "JinLu.Yin" <411641505@qq.com> Date: Fri, 2 Sep 2022 17:01:16 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9D=A1=E7=A0=81=E5=8A=9F=E8=83=BD=E5=AE=8C?= =?UTF-8?q?=E5=96=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- doc/设计文档/数据库设计/mes-wm.sql | 7 ++-- .../com/ktg/common/utils/file/FileUtils.java | 30 ++++++++++++---- .../wm/controller/WmBarcodeController.java | 13 +++++++ .../ktg/mes/wm/mapper/WmBarcodeMapper.java | 7 ++++ .../ktg/mes/wm/service/IWmBarcodeService.java | 16 +++++++++ .../wm/service/impl/WmBarcodeServiceImpl.java | 36 +++++++++++++++++++ .../resources/mapper/wm/WmBarcodeMapper.xml | 7 +++- 7 files changed, 106 insertions(+), 10 deletions(-) diff --git a/doc/设计文档/数据库设计/mes-wm.sql b/doc/设计文档/数据库设计/mes-wm.sql index 6416b5f..bccf48d 100644 --- a/doc/设计文档/数据库设计/mes-wm.sql +++ b/doc/设计文档/数据库设计/mes-wm.sql @@ -402,8 +402,11 @@ create table wm_barcode ( barcode_id bigint(20) not null auto_increment comment '条码ID', barcode_formart varchar(64) not null comment '条码格式', barcode_type varchar(64) not null comment '条码类型', - barcode_content varchar(255) not null comment '产品物料ID', - url varchar(255) comment '条码地址', + barcode_content varchar(255) not null comment '条码内容', + bussiness_id bigint(20) not null comment '业务ID', + bussiness_code varchar(64) comment '业务编码', + bussiness_name varchar(255) comment '业务名称', + barcode_url varchar(255) comment '条码地址', enable_flag char(1) default 'Y' comment '是否生效', remark varchar(500) default '' comment '备注', attr1 varchar(64) default null comment '预留字段1', diff --git a/ktg-common/src/main/java/com/ktg/common/utils/file/FileUtils.java b/ktg-common/src/main/java/com/ktg/common/utils/file/FileUtils.java index 27830eb..3f72c4e 100644 --- a/ktg-common/src/main/java/com/ktg/common/utils/file/FileUtils.java +++ b/ktg-common/src/main/java/com/ktg/common/utils/file/FileUtils.java @@ -1,22 +1,22 @@ package com.ktg.common.utils.file; -import java.io.File; -import java.io.FileInputStream; -import java.io.FileNotFoundException; -import java.io.FileOutputStream; -import java.io.IOException; -import java.io.OutputStream; -import java.io.UnsupportedEncodingException; +import java.io.*; import java.net.URLEncoder; import java.nio.charset.StandardCharsets; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; + +import org.apache.commons.fileupload.FileItem; +import org.apache.commons.fileupload.disk.DiskFileItemFactory; import org.apache.commons.io.IOUtils; import org.apache.commons.lang3.ArrayUtils; import com.ktg.common.config.RuoYiConfig; import com.ktg.common.utils.DateUtils; import com.ktg.common.utils.StringUtils; import com.ktg.common.utils.uuid.IdUtils; +import org.springframework.http.MediaType; +import org.springframework.web.multipart.MultipartFile; +import org.springframework.web.multipart.commons.CommonsMultipartFile; /** * 文件处理工具类 @@ -272,4 +272,20 @@ public class FileUtils int index = Math.max(lastUnixPos, lastWindowsPos); return fileName.substring(index + 1); } + + public static MultipartFile getMultipartFile(File file) { + FileItem item = new DiskFileItemFactory().createItem("file" + , MediaType.MULTIPART_FORM_DATA_VALUE + , true + , file.getName()); + try (InputStream input = new FileInputStream(file); + OutputStream os = item.getOutputStream()) { + // 流转移 + IOUtils.copy(input, os); + } catch (Exception e) { + throw new IllegalArgumentException("Invalid file: " + e, e); + } + + return new CommonsMultipartFile(item); + } } diff --git a/ktg-mes/src/main/java/com/ktg/mes/wm/controller/WmBarcodeController.java b/ktg-mes/src/main/java/com/ktg/mes/wm/controller/WmBarcodeController.java index 4ec0a89..9d407c2 100644 --- a/ktg-mes/src/main/java/com/ktg/mes/wm/controller/WmBarcodeController.java +++ b/ktg-mes/src/main/java/com/ktg/mes/wm/controller/WmBarcodeController.java @@ -2,6 +2,8 @@ package com.ktg.mes.wm.controller; import java.util.List; import javax.servlet.http.HttpServletResponse; + +import com.ktg.common.constant.UserConstants; import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.GetMapping; @@ -77,6 +79,12 @@ public class WmBarcodeController extends BaseController @PostMapping public AjaxResult add(@RequestBody WmBarcode wmBarcode) { + if(UserConstants.NOT_UNIQUE.equals(wmBarcodeService.checkBarcodeUnique(wmBarcode))){ + return AjaxResult.error("当前业务内容的条码已存在!"); + } + + String path =wmBarcodeService.generateBarcode(wmBarcode); + wmBarcode.setBarcodeUrl(path); return toAjax(wmBarcodeService.insertWmBarcode(wmBarcode)); } @@ -88,6 +96,11 @@ public class WmBarcodeController extends BaseController @PutMapping public AjaxResult edit(@RequestBody WmBarcode wmBarcode) { + if(UserConstants.NOT_UNIQUE.equals(wmBarcodeService.checkBarcodeUnique(wmBarcode))){ + return AjaxResult.error("当前业务内容的条码已存在!"); + } + String path =wmBarcodeService.generateBarcode(wmBarcode); + wmBarcode.setBarcodeUrl(path); return toAjax(wmBarcodeService.updateWmBarcode(wmBarcode)); } diff --git a/ktg-mes/src/main/java/com/ktg/mes/wm/mapper/WmBarcodeMapper.java b/ktg-mes/src/main/java/com/ktg/mes/wm/mapper/WmBarcodeMapper.java index 5dbad68..08a52cc 100644 --- a/ktg-mes/src/main/java/com/ktg/mes/wm/mapper/WmBarcodeMapper.java +++ b/ktg-mes/src/main/java/com/ktg/mes/wm/mapper/WmBarcodeMapper.java @@ -27,6 +27,13 @@ public interface WmBarcodeMapper */ public List selectWmBarcodeList(WmBarcode wmBarcode); + /** + * 检查当前条码类型下,对应的业务是否已经生成了条码 + * @param wmBarcode + * @return + */ + public WmBarcode checkBarcodeUnique(WmBarcode wmBarcode); + /** * 新增条码清单 * diff --git a/ktg-mes/src/main/java/com/ktg/mes/wm/service/IWmBarcodeService.java b/ktg-mes/src/main/java/com/ktg/mes/wm/service/IWmBarcodeService.java index 1ce91e3..4041dc8 100644 --- a/ktg-mes/src/main/java/com/ktg/mes/wm/service/IWmBarcodeService.java +++ b/ktg-mes/src/main/java/com/ktg/mes/wm/service/IWmBarcodeService.java @@ -27,6 +27,14 @@ public interface IWmBarcodeService */ public List selectWmBarcodeList(WmBarcode wmBarcode); + + /** + * 根据条码类型和业务内容ID判断条码是否已存在 + * @param wmBarcode + * @return + */ + public String checkBarcodeUnique(WmBarcode wmBarcode); + /** * 新增条码清单 * @@ -58,4 +66,12 @@ public interface IWmBarcodeService * @return 结果 */ public int deleteWmBarcodeByBarcodeId(Long barcodeId); + + /** + * 根据条码记录生成实际的条码,返回对应的url地址 + * @param wmBarcode + * @return + */ + public String generateBarcode(WmBarcode wmBarcode); + } diff --git a/ktg-mes/src/main/java/com/ktg/mes/wm/service/impl/WmBarcodeServiceImpl.java b/ktg-mes/src/main/java/com/ktg/mes/wm/service/impl/WmBarcodeServiceImpl.java index 06d39c8..2120ba4 100644 --- a/ktg-mes/src/main/java/com/ktg/mes/wm/service/impl/WmBarcodeServiceImpl.java +++ b/ktg-mes/src/main/java/com/ktg/mes/wm/service/impl/WmBarcodeServiceImpl.java @@ -1,12 +1,22 @@ package com.ktg.mes.wm.service.impl; +import java.io.File; +import java.io.IOException; import java.util.List; + +import com.ktg.common.constant.UserConstants; +import com.ktg.common.core.domain.AjaxResult; import com.ktg.common.utils.DateUtils; +import com.ktg.common.utils.StringUtils; +import com.ktg.common.utils.barcode.BarcodeUtil; +import com.ktg.common.utils.file.FileUploadUtils; +import com.ktg.common.utils.file.FileUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import com.ktg.mes.wm.mapper.WmBarcodeMapper; import com.ktg.mes.wm.domain.WmBarcode; import com.ktg.mes.wm.service.IWmBarcodeService; +import org.springframework.web.multipart.MultipartFile; /** * 条码清单Service业务层处理 @@ -44,6 +54,16 @@ public class WmBarcodeServiceImpl implements IWmBarcodeService return wmBarcodeMapper.selectWmBarcodeList(wmBarcode); } + @Override + public String checkBarcodeUnique(WmBarcode wmBarcode) { + WmBarcode barcode = wmBarcodeMapper.checkBarcodeUnique(wmBarcode); + Long barcodeId = wmBarcode.getBarcodeId()==null?-1L:wmBarcode.getBarcodeId(); + if(StringUtils.isNotNull(barcode) && barcode.getBarcodeId().longValue() != barcodeId.longValue()){ + return UserConstants.NOT_UNIQUE; + } + return UserConstants.UNIQUE; + } + /** * 新增条码清单 * @@ -93,4 +113,20 @@ public class WmBarcodeServiceImpl implements IWmBarcodeService { return wmBarcodeMapper.deleteWmBarcodeByBarcodeId(barcodeId); } + + @Override + public String generateBarcode(WmBarcode wmBarcode) { + File buf = BarcodeUtil.generateFile(wmBarcode.getBarcodeContent(),"./tmp/barcode/"+wmBarcode.getBarcodeContent()+".png"); + MultipartFile file = FileUtils.getMultipartFile(buf); + String fileName = null; + try { + fileName = FileUploadUtils.uploadMinio(file); + } catch (IOException e) { + e.printStackTrace(); + return null; + } + return fileName; + } + + } diff --git a/ktg-mes/src/main/resources/mapper/wm/WmBarcodeMapper.xml b/ktg-mes/src/main/resources/mapper/wm/WmBarcodeMapper.xml index c126d22..d9e6b05 100644 --- a/ktg-mes/src/main/resources/mapper/wm/WmBarcodeMapper.xml +++ b/ktg-mes/src/main/resources/mapper/wm/WmBarcodeMapper.xml @@ -51,7 +51,12 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" where barcode_id = #{barcodeId} - + + + insert into wm_barcode