feat(traycode): 优化托盘码生成逻辑并调整打印样式
- 移除旧的条码生成逻辑,使用新的序列规则生成托盘码 - 引入条码格式服务以支持更灵活的编码规则 - 更新前端打印模板,使用CODE39条形码替代二维码 - 调整打印页面尺寸为80mm x 50mm以适配标签打印机 - 修改CSS样式以提高打印质量,避免缩放导致的模糊问题 - 更新依赖包,添加vue-barcode库支持条形码渲染
This commit is contained in:
@@ -1,9 +1,12 @@
|
|||||||
package com.ruoyi.bas.traycode.service.impl;
|
package com.ruoyi.bas.traycode.service.impl;
|
||||||
|
|
||||||
import cn.hutool.core.collection.CollUtil;
|
import cn.hutool.core.collection.CollUtil;
|
||||||
|
import cn.hutool.core.convert.Convert;
|
||||||
import com.ruoyi.bas.traycode.domain.BasTraycode;
|
import com.ruoyi.bas.traycode.domain.BasTraycode;
|
||||||
import com.ruoyi.bas.traycode.mapper.BasTraycodeMapper;
|
import com.ruoyi.bas.traycode.mapper.BasTraycodeMapper;
|
||||||
import com.ruoyi.bas.traycode.service.IBasTraycodeService;
|
import com.ruoyi.bas.traycode.service.IBasTraycodeService;
|
||||||
|
import com.ruoyi.bas.traycodeformat.domain.BasTraycodeFormat;
|
||||||
|
import com.ruoyi.bas.traycodeformat.service.IBasTraycodeFormatService;
|
||||||
import com.ruoyi.common.utils.DateUtils;
|
import com.ruoyi.common.utils.DateUtils;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
@@ -21,6 +24,8 @@ public class BasTraycodeServiceImpl implements IBasTraycodeService
|
|||||||
{
|
{
|
||||||
@Autowired
|
@Autowired
|
||||||
private BasTraycodeMapper basTraycodeMapper;
|
private BasTraycodeMapper basTraycodeMapper;
|
||||||
|
@Autowired
|
||||||
|
private IBasTraycodeFormatService basTraycodeFormatService;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 查询条码信息
|
* 查询条码信息
|
||||||
@@ -56,24 +61,28 @@ public class BasTraycodeServiceImpl implements IBasTraycodeService
|
|||||||
public int insertBasTraycode(BasTraycode basTraycode)
|
public int insertBasTraycode(BasTraycode basTraycode)
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
Integer i = basTraycodeMapper.selectBasTrayCodeMax();
|
BasTraycodeFormat basTraycodeFormat = basTraycodeFormatService.selectBasTraycodeFormatById(basTraycode.getFormatId());
|
||||||
if (i == null) {
|
|
||||||
i = 0;
|
|
||||||
}
|
|
||||||
int i1 = Integer.parseInt(basTraycode.getSpare1());
|
int i1 = Integer.parseInt(basTraycode.getSpare1());
|
||||||
//如果i<4位数,前面补0
|
//如果i<4位数,前面补0
|
||||||
String code = "";
|
String code = "";
|
||||||
for (int j = 0; j < i1; j++) {
|
for (int j = 0; j < i1; j++) {
|
||||||
code = String.format("%04d", i + 1 + j);
|
code = String.format("%07d",Convert.toInt( basTraycodeFormat.getSerialRule()) + 1 + j);
|
||||||
if("9999".equals( code)){
|
if(basTraycodeFormat.getMaxNum() < Convert.toLong( code)){
|
||||||
throw new RuntimeException("已生成最大值");
|
throw new RuntimeException("已生成最大值");
|
||||||
}
|
}
|
||||||
basTraycode.setTrayCode(code);
|
String finalCode = basTraycodeFormat.getBarcodeFormat()+code;
|
||||||
|
basTraycode.setTrayCode(finalCode);
|
||||||
basTraycode.setSpare1(null);
|
basTraycode.setSpare1(null);
|
||||||
basTraycode.setCreateTime(DateUtils.getNowDate());
|
basTraycode.setCreateTime(DateUtils.getNowDate());
|
||||||
basTraycode.setSpare2("Y");
|
basTraycode.setSpare2("Y");
|
||||||
basTraycodeMapper.insertBasTraycode(basTraycode);
|
basTraycodeMapper.insertBasTraycode(basTraycode);
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
basTraycodeFormat.setSerialRule(Convert.toLong( code).toString());
|
||||||
|
basTraycodeFormatService.updateBasTraycodeFormat(basTraycodeFormat);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -79,20 +79,7 @@ public class BasTraycodeFormatServiceImpl implements IBasTraycodeFormatService
|
|||||||
public int updateBasTraycodeFormat(BasTraycodeFormat basTraycodeFormat)
|
public int updateBasTraycodeFormat(BasTraycodeFormat basTraycodeFormat)
|
||||||
{
|
{
|
||||||
BasTraycodeFormat old = selectBasTraycodeFormatById(basTraycodeFormat.getId());
|
BasTraycodeFormat old = selectBasTraycodeFormatById(basTraycodeFormat.getId());
|
||||||
int oldSerialRule = Convert.toInt(old.getSerialRule());
|
|
||||||
int newSerialRule = Convert.toInt(basTraycodeFormat.getSerialRule());
|
|
||||||
|
|
||||||
List<BasTraycode> traycodeList = new ArrayList<>();
|
|
||||||
for (int i = oldSerialRule; i < newSerialRule; i++) {
|
|
||||||
BasTraycode basTraycode = new BasTraycode();
|
|
||||||
basTraycode.setFormatId(basTraycodeFormat.getId());
|
|
||||||
String traycode = old.getBarcodeFormat()+ StrUtil.padPre(Convert.toStr(i),5,'0');
|
|
||||||
basTraycode.setTrayCode(traycode);
|
|
||||||
traycodeList.add(basTraycode);
|
|
||||||
}
|
|
||||||
basTraycodeFormat.setUpdateTime(DateUtils.getNowDate());
|
basTraycodeFormat.setUpdateTime(DateUtils.getNowDate());
|
||||||
//插入条码信息
|
|
||||||
basTraycodeService.insertBasTraycodeList(traycodeList);
|
|
||||||
return basTraycodeFormatMapper.updateBasTraycodeFormat(basTraycodeFormat);
|
return basTraycodeFormatMapper.updateBasTraycodeFormat(basTraycodeFormat);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -44,6 +44,7 @@
|
|||||||
"sortablejs": "1.10.2",
|
"sortablejs": "1.10.2",
|
||||||
"splitpanes": "2.4.1",
|
"splitpanes": "2.4.1",
|
||||||
"vue": "2.6.12",
|
"vue": "2.6.12",
|
||||||
|
"vue-barcode": "^1.3.0",
|
||||||
"vue-count-to": "1.0.13",
|
"vue-count-to": "1.0.13",
|
||||||
"vue-cropper": "0.5.5",
|
"vue-cropper": "0.5.5",
|
||||||
"vue-easy-print": "^0.0.8",
|
"vue-easy-print": "^0.0.8",
|
||||||
|
|||||||
@@ -103,7 +103,7 @@
|
|||||||
<div class="qrcode-container">
|
<div class="qrcode-container">
|
||||||
<vue-qr
|
<vue-qr
|
||||||
:text="qrCodeValue"
|
:text="qrCodeValue"
|
||||||
:size="180"
|
:size="80"
|
||||||
:margin="0"
|
:margin="0"
|
||||||
:correctLevel="2"
|
:correctLevel="2"
|
||||||
error-correction-level="M"
|
error-correction-level="M"
|
||||||
@@ -116,8 +116,8 @@
|
|||||||
|
|
||||||
<!-- 打印专用区域(隐藏) -->
|
<!-- 打印专用区域(隐藏) -->
|
||||||
<vue-easy-print style="display: none;" ref="easyPrint2">
|
<vue-easy-print style="display: none;" ref="easyPrint2">
|
||||||
<div class="vue-easy-print" style="page-break-after:always">
|
<div class="vue-easy-print">
|
||||||
<div class="label-content">
|
<div class="print-label">
|
||||||
<div class="preview-box">
|
<div class="preview-box">
|
||||||
<div class="preview-content">
|
<div class="preview-content">
|
||||||
<div class="preview-row">
|
<div class="preview-row">
|
||||||
@@ -158,10 +158,10 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<!-- 二维码区域 -->
|
<!-- 二维码区域 -->
|
||||||
<div class="qrcode-container">
|
<div class="qrcode-container" style="top:2mm;right:2mm;">
|
||||||
<vue-qr
|
<vue-qr
|
||||||
:text="qrCodeValue"
|
:text="qrCodeValue"
|
||||||
:size="180"
|
:size="120"
|
||||||
:margin="0"
|
:margin="0"
|
||||||
:correctLevel="2"
|
:correctLevel="2"
|
||||||
error-correction-level="M"
|
error-correction-level="M"
|
||||||
@@ -969,7 +969,7 @@ export default {
|
|||||||
}
|
}
|
||||||
|
|
||||||
.preview-display {
|
.preview-display {
|
||||||
padding: 0 20px 20px;
|
padding: 0 10px 10px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.label-content {
|
.label-content {
|
||||||
@@ -978,6 +978,19 @@ export default {
|
|||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* 打印单页标签尺寸(按实际贴纸尺寸调整) */
|
||||||
|
.print-label {
|
||||||
|
width: 90mm; /* 贴纸宽度 */
|
||||||
|
height: 30mm; /* 贴纸高度 */
|
||||||
|
padding: 6mm; /* 安全边距 */
|
||||||
|
box-sizing: border-box;
|
||||||
|
display: flex;
|
||||||
|
align-items: stretch;
|
||||||
|
background: #fff;
|
||||||
|
border: 1px solid #e4e7ed;
|
||||||
|
border-radius: 6px;
|
||||||
|
}
|
||||||
|
|
||||||
.preview-box {
|
.preview-box {
|
||||||
padding: 20px;
|
padding: 20px;
|
||||||
font-family: 'Arial', sans-serif;
|
font-family: 'Arial', sans-serif;
|
||||||
@@ -1103,26 +1116,63 @@ export default {
|
|||||||
@media print {
|
@media print {
|
||||||
@page {
|
@page {
|
||||||
margin: 0;
|
margin: 0;
|
||||||
size: auto;
|
size: 90mm 30mm;
|
||||||
}
|
}
|
||||||
|
|
||||||
body {
|
body {
|
||||||
margin: 0;
|
margin: 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.vue-easy-print {
|
||||||
|
width: 90mm;
|
||||||
|
height: 30mm;
|
||||||
|
}
|
||||||
|
|
||||||
.preview-box {
|
.preview-box {
|
||||||
border: none;
|
border: none;
|
||||||
box-shadow: none;
|
box-shadow: none;
|
||||||
position: relative;
|
position: relative;
|
||||||
|
width: 100%;
|
||||||
|
height: 100%;
|
||||||
|
padding: 0;
|
||||||
|
display: flex;
|
||||||
|
flex-direction: row;
|
||||||
|
}
|
||||||
|
|
||||||
|
.preview-content {
|
||||||
|
margin-right: 38mm;
|
||||||
|
padding-right: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.preview-row {
|
||||||
|
margin-bottom: 4px;
|
||||||
|
min-height: auto;
|
||||||
|
}
|
||||||
|
|
||||||
|
.preview-label {
|
||||||
|
font-size: 14px;
|
||||||
|
min-width: 10mm;
|
||||||
|
margin-right: 3px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.preview-value {
|
||||||
|
font-size: 14px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.qrcode-container {
|
.qrcode-container {
|
||||||
border: none;
|
border: none;
|
||||||
position: absolute !important;
|
position: absolute !important;
|
||||||
top: 20px !important;
|
top: 2mm !important;
|
||||||
right: 20px !important;
|
right: 2mm !important;
|
||||||
padding: 0;
|
padding: 0;
|
||||||
background-color: transparent;
|
background-color: transparent;
|
||||||
|
text-align: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* 提高打印品质,避免缩放导致模糊 */
|
||||||
|
* {
|
||||||
|
-webkit-print-color-adjust: exact;
|
||||||
|
print-color-adjust: exact;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|||||||
@@ -150,7 +150,7 @@
|
|||||||
<!-- 添加或修改条码信息对话框 -->
|
<!-- 添加或修改条码信息对话框 -->
|
||||||
<el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
|
<el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
|
||||||
<el-form ref="form" :model="form" :rules="rules" label-width="100px">
|
<el-form ref="form" :model="form" :rules="rules" label-width="100px">
|
||||||
<!-- <el-form-item label="格式ID" prop="formatId">
|
<el-form-item label="格式ID" prop="formatId">
|
||||||
<el-select v-model="form.formatId" placeholder="请选择格式ID">
|
<el-select v-model="form.formatId" placeholder="请选择格式ID">
|
||||||
<el-option
|
<el-option
|
||||||
v-for="item in traycodeFormatList"
|
v-for="item in traycodeFormatList"
|
||||||
@@ -159,7 +159,7 @@
|
|||||||
:value="item.id"
|
:value="item.id"
|
||||||
/>
|
/>
|
||||||
</el-select>
|
</el-select>
|
||||||
</el-form-item>-->
|
</el-form-item>
|
||||||
|
|
||||||
<el-form-item label="数量" prop="spare1" v-if="form.id == null">
|
<el-form-item label="数量" prop="spare1" v-if="form.id == null">
|
||||||
<el-input v-model="form.spare1" placeholder="请输入数量" />
|
<el-input v-model="form.spare1" placeholder="请输入数量" />
|
||||||
@@ -189,10 +189,13 @@
|
|||||||
<!-- 打印模板 -->
|
<!-- 打印模板 -->
|
||||||
<vue-easy-print v-show="true" ref="easyPrint2">
|
<vue-easy-print v-show="true" ref="easyPrint2">
|
||||||
<div v-for="item in printData" :key="item.id" style="page-break-after:always" class="vue-easy-print">
|
<div v-for="item in printData" :key="item.id" style="page-break-after:always" class="vue-easy-print">
|
||||||
<vue-qr :text='item.trayCode' :size="150" :margin="10" :align-item="center" :correctLevel="2"></vue-qr>
|
<vue-barcode
|
||||||
<div>
|
:value=item.trayCode
|
||||||
<span class="num">{{ item.trayCode }}</span>
|
format="CODE39"
|
||||||
</div>
|
width="2"
|
||||||
|
height="100"
|
||||||
|
display-value
|
||||||
|
/>
|
||||||
</div>
|
</div>
|
||||||
</vue-easy-print>
|
</vue-easy-print>
|
||||||
</div>
|
</div>
|
||||||
@@ -203,14 +206,15 @@ import { listTraycode, getTraycode, delTraycode, addTraycode, updateTraycode } f
|
|||||||
import { listTraycodeFormat } from "@/api/bas/traycodeFormat"
|
import { listTraycodeFormat } from "@/api/bas/traycodeFormat"
|
||||||
import vueEasyPrint from 'vue-easy-print'
|
import vueEasyPrint from 'vue-easy-print'
|
||||||
import VueQr from 'vue-qr'
|
import VueQr from 'vue-qr'
|
||||||
|
import VueBarcode from 'vue-barcode'
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: "Traycode",
|
name: "Traycode",
|
||||||
dicts:['sys_yes_no'],
|
dicts:['sys_yes_no'],
|
||||||
components: {
|
components: {
|
||||||
vueEasyPrint,
|
vueEasyPrint,
|
||||||
VueQr
|
VueQr,
|
||||||
|
VueBarcode
|
||||||
},
|
},
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
@@ -455,7 +459,7 @@ export default {
|
|||||||
|
|
||||||
@media print {
|
@media print {
|
||||||
@page {
|
@page {
|
||||||
size: A4;
|
size: 80mm 50mm;
|
||||||
margin: 0;
|
margin: 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user