条码功能完善
This commit is contained in:
parent
0466be3d36
commit
83bc0f6498
@ -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',
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
@ -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));
|
||||
}
|
||||
|
||||
|
@ -27,6 +27,13 @@ public interface WmBarcodeMapper
|
||||
*/
|
||||
public List<WmBarcode> selectWmBarcodeList(WmBarcode wmBarcode);
|
||||
|
||||
/**
|
||||
* 检查当前条码类型下,对应的业务是否已经生成了条码
|
||||
* @param wmBarcode
|
||||
* @return
|
||||
*/
|
||||
public WmBarcode checkBarcodeUnique(WmBarcode wmBarcode);
|
||||
|
||||
/**
|
||||
* 新增条码清单
|
||||
*
|
||||
|
@ -27,6 +27,14 @@ public interface IWmBarcodeService
|
||||
*/
|
||||
public List<WmBarcode> 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);
|
||||
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -51,7 +51,12 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
<include refid="selectWmBarcodeVo"/>
|
||||
where barcode_id = #{barcodeId}
|
||||
</select>
|
||||
|
||||
|
||||
<select id="checkBarcodeUnique" parameterType="WmBarcode">
|
||||
<include refid="selectWmBarcodeVo"/>
|
||||
where bussiness_id = #{bussinessId} and barcode_type = #{barcodeType}
|
||||
</select>
|
||||
|
||||
<insert id="insertWmBarcode" parameterType="WmBarcode" useGeneratedKeys="true" keyProperty="barcodeId">
|
||||
insert into wm_barcode
|
||||
<trim prefix="(" suffix=")" suffixOverrides=",">
|
||||
|
Loading…
Reference in New Issue
Block a user