Browse Source

fixed 云打印公共方法

fushengqian 1 year ago
parent
commit
c1f9bd0152

+ 20 - 2
fuint-application/src/main/java/com/fuint/common/service/impl/PrinterServiceImpl.java

@@ -5,6 +5,8 @@ import com.baomidou.mybatisplus.core.toolkit.Wrappers;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.fuint.common.util.PrintUtil;
 import com.fuint.common.vo.printer.AddPrinterRequest;
+import com.fuint.common.vo.printer.AddPrinterRequestItem;
+import com.fuint.common.vo.printer.DelPrinterRequest;
 import com.fuint.framework.annoation.OperationServiceLog;
 import com.fuint.framework.exception.BusinessCheckException;
 import com.fuint.framework.pagination.PaginationRequest;
@@ -13,6 +15,7 @@ import com.fuint.repository.model.MtPrinter;
 import com.fuint.common.service.PrinterService;
 import com.fuint.common.enums.StatusEnum;
 import com.fuint.repository.mapper.MtPrinterMapper;
+import com.fuint.utils.StringUtil;
 import com.github.pagehelper.PageHelper;
 import lombok.AllArgsConstructor;
 import org.apache.commons.lang.StringUtils;
@@ -107,8 +110,16 @@ public class PrinterServiceImpl extends ServiceImpl<MtPrinterMapper, MtPrinter>
 
         Integer printerId = mtPrinterMapper.insert(mtPrinter);
         if (printerId > 0) {
-            AddPrinterRequest restRequest = new AddPrinterRequest();
-            PrintUtil.addPrinters(restRequest);
+            // 添加云打印机
+            if (mtPrinter.getSn() != null && mtPrinter.getName() != null) {
+                AddPrinterRequest restRequest = new AddPrinterRequest();
+                AddPrinterRequestItem item = new AddPrinterRequestItem();
+                item.setName(mtPrinter.getName());
+                item.setSn(mtPrinter.getSn());
+                AddPrinterRequestItem[] items = {item};
+                restRequest.setItems(items);
+                PrintUtil.addPrinters(restRequest);
+            }
             return mtPrinter;
         } else {
             logger.error("新增打印机数据失败.");
@@ -142,6 +153,13 @@ public class PrinterServiceImpl extends ServiceImpl<MtPrinterMapper, MtPrinter>
         if (null == mtPrinter) {
             return;
         }
+        // 删除云打印机
+        if (StringUtil.isNotEmpty(mtPrinter.getSn())) {
+            DelPrinterRequest restRequest = new DelPrinterRequest();
+            String[] snList = { mtPrinter.getSn() };
+            restRequest.setSnlist(snList);
+            PrintUtil.delPrinters(restRequest);
+        }
         mtPrinter.setStatus(StatusEnum.DISABLE.getKey());
         mtPrinter.setUpdateTime(new Date());
         mtPrinterMapper.updateById(mtPrinter);

+ 13 - 13
fuint-application/src/main/java/com/fuint/common/util/PrintUtil.java

@@ -33,7 +33,7 @@ public class PrintUtil {
      * @param restRequest
      * @return
      */
-    public ObjectRestResponse<Boolean> setPrinterVoiceType(SetVoiceTypeRequest restRequest) {
+    public static ObjectRestResponse<Boolean> setPrinterVoiceType(SetVoiceTypeRequest restRequest) {
         String url = BASE_URL + "/xprinter/setVoiceType";
         String jsonRequest = JSON.toJSONString(restRequest);
         String resp = HttpClientUtil.doPostJSON(url, jsonRequest);
@@ -46,7 +46,7 @@ public class PrintUtil {
      * @param restRequest
      * @return
      */
-    public ObjectRestResponse<String> print(PrintRequest restRequest) {
+    public static ObjectRestResponse<String> print(PrintRequest restRequest) {
         String url = BASE_URL + "/xprinter/print";
         String jsonRequest = JSON.toJSONString(restRequest);
         String resp = HttpClientUtil.doPostJSON(url, jsonRequest);
@@ -60,7 +60,7 @@ public class PrintUtil {
      * @param restRequest
      * @return
      */
-    public ObjectRestResponse<String> printLabel(PrintRequest restRequest) {
+    public static ObjectRestResponse<String> printLabel(PrintRequest restRequest) {
         String url = BASE_URL + "/xprinter/printLabel";
         String jsonRequest = JSON.toJSONString(restRequest);
         String resp = HttpClientUtil.doPostJSON(url, jsonRequest);
@@ -74,7 +74,7 @@ public class PrintUtil {
      * @param restRequest
      * @return
      */
-    public ObjectRestResponse<PrinterResult> delPrinters(DelPrinterRequest restRequest) {
+    public static ObjectRestResponse<PrinterResult> delPrinters(DelPrinterRequest restRequest) {
         String url = BASE_URL + "/xprinter/delPrinters";
         String jsonRequest = JSON.toJSONString(restRequest);
         String resp = HttpClientUtil.doPostJSON(url, jsonRequest);
@@ -88,7 +88,7 @@ public class PrintUtil {
      * @param restRequest
      * @return
      */
-    public ObjectRestResponse<Boolean> updPrinter(UpdPrinterRequest restRequest) {
+    public static ObjectRestResponse<Boolean> updPrinter(UpdPrinterRequest restRequest) {
         String url = BASE_URL + "/xprinter/updPrinter";
         String jsonRequest = JSON.toJSONString(restRequest);
         String resp = HttpClientUtil.doPostJSON(url, jsonRequest);
@@ -102,7 +102,7 @@ public class PrintUtil {
      * @param restRequest
      * @return
      */
-    public ObjectRestResponse<Boolean> delPrinterQueue(PrinterRequest restRequest) {
+    public static ObjectRestResponse<Boolean> delPrinterQueue(PrinterRequest restRequest) {
         String url = BASE_URL + "/xprinter/delPrinterQueue";
         String jsonRequest = JSON.toJSONString(restRequest);
         String resp = HttpClientUtil.doPostJSON(url, jsonRequest);
@@ -116,7 +116,7 @@ public class PrintUtil {
      * @param restRequest
      * @return
      */
-    public ObjectRestResponse<Boolean> queryOrderState(QueryOrderStateRequest restRequest) {
+    public static ObjectRestResponse<Boolean> queryOrderState(QueryOrderStateRequest restRequest) {
         String url = BASE_URL + "/xprinter/queryOrderState";
         String jsonRequest = JSON.toJSONString(restRequest);
         String resp = HttpClientUtil.doPostJSON(url, jsonRequest);
@@ -130,7 +130,7 @@ public class PrintUtil {
      * @param restRequest
      * @return
      */
-    public ObjectRestResponse<OrderStatisResult> queryOrderStatis(QueryOrderStatisRequest restRequest) {
+    public static ObjectRestResponse<OrderStatisResult> queryOrderStatis(QueryOrderStatisRequest restRequest) {
         String url = BASE_URL + "/xprinter/queryOrderStatis";
         String jsonRequest = JSON.toJSONString(restRequest);
         String resp = HttpClientUtil.doPostJSON(url, jsonRequest);
@@ -146,7 +146,7 @@ public class PrintUtil {
      * @param restRequest
      * @return
      */
-    public ObjectRestResponse<Integer> queryPrinterStatus(PrinterRequest restRequest) {
+    public static ObjectRestResponse<Integer> queryPrinterStatus(PrinterRequest restRequest) {
         String url = BASE_URL + "/xprinter/queryPrinterStatus";
         String jsonRequest = JSON.toJSONString(restRequest);
         String resp = HttpClientUtil.doPostJSON(url, jsonRequest);
@@ -162,7 +162,7 @@ public class PrintUtil {
      * @param restRequest
      * @return
      */
-    public ObjectRestResponse<List<Integer>> queryPrintersStatus(PrintersRequest restRequest) {
+    public static ObjectRestResponse<List<Integer>> queryPrintersStatus(PrintersRequest restRequest) {
         String url = BASE_URL + "/xprinter/queryPrintersStatus";
         String jsonRequest = JSON.toJSONString(restRequest);
         String resp = HttpClientUtil.doPostJSON(url, jsonRequest);
@@ -176,7 +176,7 @@ public class PrintUtil {
      * @param restRequest
      * @return
      */
-    public ObjectRestResponse<String> playVoice(VoiceRequest restRequest) {
+    public static ObjectRestResponse<String> playVoice(VoiceRequest restRequest) {
         String url = BASE_URL + "/xprinter/playVoice";
         String jsonRequest = JSON.toJSONString(restRequest);
         String resp = HttpClientUtil.doPostJSON(url, jsonRequest);
@@ -190,7 +190,7 @@ public class PrintUtil {
      * @param restRequest
      * @return
      */
-    public ObjectRestResponse<String> pos(PrintRequest restRequest) {
+    public static ObjectRestResponse<String> pos(PrintRequest restRequest) {
         String url = BASE_URL + "/xprinter/pos";
         String jsonRequest = JSON.toJSONString(restRequest);
         String resp = HttpClientUtil.doPostJSON(url, jsonRequest);
@@ -204,7 +204,7 @@ public class PrintUtil {
      * @param restRequest
      * @return
      */
-    public ObjectRestResponse<String> controlBox(PrintRequest restRequest) {
+    public static ObjectRestResponse<String> controlBox(PrintRequest restRequest) {
         String url = BASE_URL + "/xprinter/controlBox";
         String jsonRequest = JSON.toJSONString(restRequest);
         String resp = HttpClientUtil.doPostJSON(url, jsonRequest);