Prechádzať zdrojové kódy

新增补充打印标签功能

LinWuTai 1 rok pred
rodič
commit
fa9914061f

+ 71 - 1
ruoyi-admin/src/main/java/com/ruoyi/asset/controller/TbAssetInformationController.java

@@ -13,6 +13,7 @@ import cn.hutool.json.JSONUtil;
 import com.ruoyi.asset.domain.TbLocation;
 import com.ruoyi.asset.domain.dto.AssetEpcInfo;
 import com.ruoyi.asset.domain.dto.PrintDTO;
+import com.ruoyi.asset.domain.dto.SinglePrintDTO;
 import com.ruoyi.common.core.domain.entity.SysDept;
 import com.ruoyi.label.domain.TbLabelModelInfo;
 import com.ruoyi.label.service.ITbLabelModelInfoService;
@@ -107,6 +108,75 @@ public class TbAssetInformationController extends BaseController
     @Resource
     private ITbLabelModelInfoService labelModelInfoService;
 
+    @PostMapping("/print/single")
+    public AjaxResult printSingle(@RequestBody SinglePrintDTO singlePrintDTO) {
+        // 获取资产ID
+        Long id = singlePrintDTO.getId();
+        // 判断资产是否存在
+        TbAssetInformation tbAssetInformation = tbAssetInformationService.selectTbAssetInformationById(id);
+        if (tbAssetInformation == null) {
+            return error("资产不存在");
+        }
+
+        // 获取标签模板
+        String labelCode = singlePrintDTO.getLabelCode();
+        // 判断标签模板是否存在
+        TbLabelModelInfo tbLabelModelInfo = labelModelInfoService.selectTbLabelModelByLabelCode(labelCode);
+        if (tbLabelModelInfo == null) {
+            return AjaxResult.error("标签模板不存在");
+        }
+
+        // 获取打印标签的下标
+        List<Integer> indexes = singlePrintDTO.getIndexes();
+
+        // 获取标签模板内容
+        String ptxLabelInfoModel = tbLabelModelInfo.getLabelValue();
+
+        // 准备打印标签容器
+        List<PTXLabelInfo> ptxLabelInfos = new ArrayList<>();
+
+        // 获取资产子编码
+        List<AssetEpcInfo> childNumberInfo = tbAssetInformation.getChildNumberInfo();
+
+        // 判断是否全部打印
+        if (indexes == null || indexes.isEmpty()) {
+            for (AssetEpcInfo assetEpcInfo : childNumberInfo) {
+                tbAssetInformation.setNumber(assetEpcInfo.getNumber());
+                tbAssetInformation.setEpc(assetEpcInfo.getEpc());
+                tbAssetInformation.setEpcReplenishLength(assetEpcInfo.getEpcReplenishLength());
+                // 然后再转回对象,便不会影响到原对象
+                PTXLabelInfo ptxLabelInfo = JSONUtil.toBean(ptxLabelInfoModel, PTXLabelInfo.class);
+                ptxLabelInfo = ptxService.filterInfo(ptxLabelInfo, tbAssetInformation);
+                ptxLabelInfos.add(ptxLabelInfo);
+            }
+        } else { // 有选择的打印标签
+            for (Integer index : indexes) {
+                if (index != null) {
+                    if (index > childNumberInfo.size()) {
+                        continue;
+                    }
+                    if (index < 0) {
+                        continue;
+                    }
+                    AssetEpcInfo assetEpcInfo = childNumberInfo.get(index);
+                    tbAssetInformation.setNumber(assetEpcInfo.getNumber());
+                    tbAssetInformation.setEpc(assetEpcInfo.getEpc());
+                    tbAssetInformation.setEpcReplenishLength(assetEpcInfo.getEpcReplenishLength());
+                    // 然后再转回对象,便不会影响到原对象
+                    PTXLabelInfo ptxLabelInfo = JSONUtil.toBean(ptxLabelInfoModel, PTXLabelInfo.class);
+                    ptxLabelInfo = ptxService.filterInfo(ptxLabelInfo, tbAssetInformation);
+                    ptxLabelInfos.add(ptxLabelInfo);
+                }
+            }
+        }
+
+        for (PTXLabelInfo ptxLabelInfo : ptxLabelInfos) {
+            ptxService.printLabel(ptxLabelInfo);
+        }
+
+        return AjaxResult.success();
+    }
+
     @PostMapping("/print")
     public AjaxResult print(@RequestBody PrintDTO printDTO) {
         List<Long> ids = printDTO.getIds();
@@ -146,7 +216,7 @@ public class TbAssetInformationController extends BaseController
              ptxService.printLabel(ptxLabelInfo);
         }
 
-        return AjaxResult.success(ptxLabelInfos);
+        return AjaxResult.success();
     }
 
     /**

+ 12 - 0
ruoyi-admin/src/main/java/com/ruoyi/asset/domain/dto/SinglePrintDTO.java

@@ -0,0 +1,12 @@
+package com.ruoyi.asset.domain.dto;
+
+import lombok.Data;
+
+import java.util.List;
+
+@Data
+public class SinglePrintDTO {
+    private Long id;
+    private List<Integer> indexes;
+    private String labelCode;
+}

+ 9 - 0
ruoyi-ui/src/api/asset/information.js

@@ -60,6 +60,15 @@ export function printLabel(data) {
   })
 }
 
+// 单个标签打印
+export function singlePrintLabel(data) {
+  return request({
+    url: '/asset/information/print/single',
+    method: 'post',
+    data: data
+  })
+}
+
 //自定义字段
 export function getDiy() {
   return request({

+ 77 - 11
ruoyi-ui/src/views/asset/information/index.vue

@@ -321,7 +321,7 @@
     <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize" @pagination="getList" />
 
     <!-- 添加或修改资产信息对话框 -->
-    <el-dialog :title="title" :visible.sync="open" width="1200px" append-to-body @close="dialogColose">
+    <el-dialog :title="title" :visible.sync="open" width="1200px" append-to-body>
       <el-form ref="form" :model="form" :rules="rules" label-width="130px">
         <el-row :gutter="10">
           <el-col :span="8">
@@ -628,8 +628,8 @@
       </div>
     </el-dialog>
     <el-dialog title="标签打印" :visible.sync="isPrinter" width="400px" append-to-body>
-      <el-form ref="printForm" :model="printForm" :rules="printRules" label-width="80px">
-        <el-form-item label="资产编号" prop="ids">
+      <el-form ref="printForm" :model="printForm" :rules="printRules" label-width="80px" v-if="!isSinglePrinter">
+        <el-form-item label="资产ID" prop="ids">
           {{ printForm.ids }}
         </el-form-item>
         <el-form-item label="标签编码" prop="labelCode">
@@ -641,6 +641,30 @@
           </el-select>
         </el-form-item>
       </el-form>
+      <el-form ref="printForm" :model="singlePrintForm" :rules="printRules" label-width="80px" v-if="isSinglePrinter">
+        <el-form-item label="资产ID" prop="id">
+          {{ singlePrintForm.id }}
+        </el-form-item>
+        <el-form-item label="标签编码" prop="labelCode">
+          <el-select v-model="singlePrintForm.labelCode" placeholder="请选择标签编码">
+            <el-option v-for="item in labelCodes" :key="item.value" :label="item.label" :value="item.value">
+              <span style="float: left">{{ item.label }}</span>
+              <span style="float: right; color: #8492a6; font-size: 13px">{{ item.value }}</span>
+            </el-option>
+          </el-select>
+        </el-form-item>
+        <el-form-item label="可选标签" prop="indexes">
+          <el-select v-model="singlePrintForm.indexes" multiple placeholder="默认全选" clearable :filterable="true">
+            <el-option
+              v-for="item in singlePrintIndexes"
+              :key="item.value"
+              :label="item.label"
+              :value="item.value">
+            </el-option>
+          </el-select>
+        </el-form-item>
+        <p class="msg" v-if="form.orderType !== 1"><i class="el-icon-info"></i> 可选标签留空,即默认全选</p>
+      </el-form>
       <div slot="footer" class="dialog-footer">
         <el-button type="primary" @click="onSubmitPrint">确 定</el-button>
         <el-button @click="cancel">取 消</el-button>
@@ -650,7 +674,7 @@
 </template>
 
 <script>
-import { listInformation, getInformation, delInformation, addInformation, updateInformation, setDiy, getDiy, printLabel } from '@/api/asset/information'
+import { listInformation, getInformation, delInformation, addInformation, updateInformation, setDiy, getDiy, printLabel, singlePrintLabel } from '@/api/asset/information'
 import { listCategory } from '@/api/asset/category'
 import { treeSelect } from '@/api/asset/location'
 import ImageUploadTemp from '@/components/ImageUploadTemp'
@@ -793,6 +817,13 @@ export default {
         labelCode: [{ required: true, message: '标签编码不能为空', trigger: 'change' }],
       },
       isPrinter: false,
+      singlePrintForm: {
+        id: null,
+        indexes: null,
+        labelCode: null,
+      },
+      singlePrintIndexes: [],
+      isSinglePrinter: false,
     }
   },
   created() {
@@ -997,25 +1028,56 @@ export default {
       const ids = row.id || this.ids
 
       if (Object.prototype.toString.call(ids) === '[object Array]') {
+        if (ids.length === 1) {
+          row = this.informationList.filter(item => item.id === ids[0])[0]
+          this.handSinglePrint(row, ids)
+          this.isPrinter = true
+          return
+        }
         this.printForm.ids = ids
+        this.isSinglePrinter = false
       } else {
-        this.printForm.ids = [ids]
+        this.handSinglePrint(row, row.id)
       }
       this.isPrinter = true
     },
+    handSinglePrint(row, id) {
+      this.isSinglePrinter = true
+      this.singlePrintForm.id = id
+      const singlePrintIndexes = [];
+      if (row.quantity <= 1) {
+        singlePrintIndexes.push({
+          label: `${row.number}`,
+          value: 0
+        });
+      } else {
+        for (let i = 0; i < row.quantity; i++) {
+          singlePrintIndexes.push({
+            label: `${row.number}-${i+1}`,
+            value: i
+          });
+        }
+      }
+      this.singlePrintIndexes = singlePrintIndexes
+    },
     onSubmitPrint() {
       this.$refs.printForm.validate((valid) => {
         if (valid) {
-          printLabel(this.printForm).then((res) => {
-            this.$modal.msgSuccess('操作成功,等待打印...')
-            this.cancel()
-          })
+          if (this.isSinglePrinter) {
+            singlePrintLabel(this.singlePrintForm).then((res) => {
+              this.$modal.msgSuccess('操作成功,等待打印...')
+              this.cancel()
+            })
+          } else {
+            printLabel(this.printForm).then((res) => {
+              this.$modal.msgSuccess('操作成功,等待打印...')
+              this.cancel()
+            })
+          }
         } else {
           return false
         }
       })
-
-      printLabel(this.printForm)
     },
     /** 自定义字段按钮 */
     handleDIY() {
@@ -1140,4 +1202,8 @@ export default {
     height: 32px;
   }
 }
+.msg {
+  text-align: left;
+  color: red;
+}
 </style>