优化打印机管理
This commit is contained in:
parent
50643690f1
commit
6a440d95bc
@ -1,43 +0,0 @@
|
||||
package com.suisung.mall.common.pojo.res;
|
||||
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* 飞鹅云打印机接口响应结果
|
||||
*
|
||||
* @author 潘军杰
|
||||
* @since 2024-10-30 10:10:02
|
||||
*/
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class FeiePrinterApiDataRes implements Serializable {
|
||||
private static final long serialVersionUID = 2L;
|
||||
|
||||
@ApiModelProperty(value = "成功信息数组")
|
||||
private String[] ok;
|
||||
|
||||
@ApiModelProperty(value = "失败信息数组")
|
||||
private String[] no;
|
||||
|
||||
@ApiModelProperty(value = "失败指导信息数组")
|
||||
private NoGuide[] noGuide;
|
||||
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class NoGuide implements Serializable {
|
||||
private static final long serialVersionUID = 3L;
|
||||
|
||||
@ApiModelProperty(value = "设备编号标识")
|
||||
private String sn;
|
||||
|
||||
@ApiModelProperty(value = "指导图片路径")
|
||||
private String imgUrl;
|
||||
}
|
||||
}
|
||||
@ -1,6 +1,5 @@
|
||||
package com.suisung.mall.common.pojo.res;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
@ -20,23 +19,72 @@ import java.util.List;
|
||||
@AllArgsConstructor
|
||||
public class FeiePrinterApiRes<T> implements Serializable {
|
||||
private static final long serialVersionUID = 1L;
|
||||
@ApiModelProperty(value = "返回码,正确返回0,【注意:结果正确与否的判断请用此返回参数】 ,错误返回非零。")
|
||||
private Integer ret;
|
||||
@ApiModelProperty(value = "结果提示信息,正确返回”ok”,如果有错误,返回错误信息。")
|
||||
private String msg;
|
||||
@ApiModelProperty(value = "服务器程序执行时间,单位:毫秒。")
|
||||
private Long serverExecutedTime;
|
||||
@ApiModelProperty("数据类型和内容详看私有返回参数data,如果有错误,返回null。")
|
||||
private T data;
|
||||
|
||||
public FeiePrinterApiRes fail(String msg) {
|
||||
this.ret = 1001;
|
||||
this.msg = msg;
|
||||
this.serverExecutedTime = System.currentTimeMillis()/1000;
|
||||
this.serverExecutedTime = System.currentTimeMillis() / 1000;
|
||||
return this;
|
||||
}
|
||||
|
||||
@ApiModelProperty(value = "返回码,正确返回0,【注意:结果正确与否的判断请用此返回参数】 ,错误返回非零。")
|
||||
private Integer ret;
|
||||
// @Data
|
||||
// @NoArgsConstructor
|
||||
// @AllArgsConstructor
|
||||
public class FeiePrinterApiData implements Serializable {
|
||||
private static final long serialVersionUID = 2L;
|
||||
|
||||
@ApiModelProperty(value = "结果提示信息,正确返回”ok”,如果有错误,返回错误信息。")
|
||||
private String msg;
|
||||
@ApiModelProperty(value = "成功信息数组")
|
||||
private String[] ok;
|
||||
|
||||
@ApiModelProperty(value = "服务器程序执行时间,单位:毫秒。")
|
||||
private Long serverExecutedTime;
|
||||
@ApiModelProperty(value = "失败信息数组")
|
||||
private String[] no;
|
||||
|
||||
@ApiModelProperty("数据类型和内容详看私有返回参数data,如果有错误,返回null。")
|
||||
private T data;
|
||||
@ApiModelProperty(value = "失败指导信息数组")
|
||||
private FeiePrinterApiDataNoGuide[] noGuide;
|
||||
|
||||
public String[] getOk() {
|
||||
return ok;
|
||||
}
|
||||
|
||||
public void setOk(String[] ok) {
|
||||
this.ok = ok;
|
||||
}
|
||||
|
||||
public FeiePrinterApiDataNoGuide[] getNoGuide() {
|
||||
return noGuide;
|
||||
}
|
||||
|
||||
public void setNoGuide(FeiePrinterApiDataNoGuide[] noGuide) {
|
||||
this.noGuide = noGuide;
|
||||
}
|
||||
|
||||
public String[] getNo() {
|
||||
return no;
|
||||
}
|
||||
|
||||
public void setNo(String[] no) {
|
||||
this.no = no;
|
||||
}
|
||||
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class FeiePrinterApiDataNoGuide implements Serializable {
|
||||
private static final long serialVersionUID = 3L;
|
||||
|
||||
@ApiModelProperty(value = "设备编号标识")
|
||||
private String sn;
|
||||
|
||||
@ApiModelProperty(value = "指导图片路径")
|
||||
private String imgUrl;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -24,15 +24,12 @@ import lombok.NoArgsConstructor;
|
||||
public class SFExpressApiRes {
|
||||
@ApiModelProperty(value = "错误码")
|
||||
private Integer error_code;
|
||||
|
||||
@ApiModelProperty(value = "错误信息")
|
||||
private String error_msg;
|
||||
|
||||
@ApiModelProperty(value = "响应结果")
|
||||
private Object result;
|
||||
|
||||
@ApiModelProperty(value = "错误数据")
|
||||
public Object error_data;
|
||||
@ApiModelProperty(value = "响应结果")
|
||||
private Object result;
|
||||
|
||||
public SFExpressApiRes fail(Integer errorCode, String errorMsg) {
|
||||
return new SFExpressApiRes(errorCode, errorMsg, null, null);
|
||||
|
||||
@ -115,6 +115,7 @@ public class ShopStorePrinterServiceImpl extends BaseServiceImpl<ShopStorePrinte
|
||||
|
||||
Integer userId = user.getId() == null ? 0 : user.getId();
|
||||
record.setStore_id(Integer.parseInt(user.getStore_id()));
|
||||
|
||||
// 默认不向厂家绑定打印机
|
||||
record.setStatus(ConstantError.Disable2);
|
||||
record.setFlag(record.getStatus());
|
||||
@ -242,12 +243,12 @@ public class ShopStorePrinterServiceImpl extends BaseServiceImpl<ShopStorePrinte
|
||||
if (existRecord2 == null || existRecord2.getPrinter_id() <= 0) {
|
||||
// 打印机从未加入到厂家到情况,往厂商添加打印机
|
||||
// 格式:"922441475#r6ZXPvHH#核销柜台";
|
||||
boolean success = feieUtil.addPrinter(String.format("%s#%s#%s", record.getPrinter_sn(), record.getPrinter_key(), record.getPrinter_name()));
|
||||
if (success) {
|
||||
Pair<Boolean,String> retPair = feieUtil.addPrinter(String.format("%s#%s#%s", record.getPrinter_sn(), record.getPrinter_key(), record.getPrinter_name()));
|
||||
if (retPair.getFirst()) {
|
||||
updateWrapper.set("flag", ConstantError.Enable);
|
||||
updateWrapper.set("status",ConstantError.Enable);
|
||||
} else {
|
||||
msg = msg + ",但打印机绑定未成功,请检查打印机编号和密钥是否正确。";
|
||||
msg = msg + ",但打印机绑定未成功,请检查打印机编号和密钥是否填写正确。";
|
||||
updateWrapper.set("flag", ConstantError.Disable2);
|
||||
updateWrapper.set("status",ConstantError.Disable2);
|
||||
}
|
||||
@ -275,8 +276,8 @@ public class ShopStorePrinterServiceImpl extends BaseServiceImpl<ShopStorePrinte
|
||||
|
||||
// 判断有没有权限
|
||||
UserDto user = getCurrentUser();
|
||||
if (!user.isStore()) {
|
||||
return CommonResult.failed("用户信息异常!");
|
||||
if (user==null || !user.isStore()) {
|
||||
return CommonResult.failed("无权操作!");
|
||||
}
|
||||
|
||||
ShopStorePrinter record = getById(printerId);
|
||||
@ -284,18 +285,18 @@ public class ShopStorePrinterServiceImpl extends BaseServiceImpl<ShopStorePrinte
|
||||
return CommonResult.failed("打票机不存在,无法操作!");
|
||||
}
|
||||
|
||||
boolean success;
|
||||
|
||||
if (ConstantError.Enable.equals(status)) {
|
||||
// 向厂家新增打印机
|
||||
// 格式:"922441475#r6ZXPvHH#核销柜台";
|
||||
success = feieUtil.addPrinter(String.format("%s#%s#%s", record.getPrinter_sn(), record.getPrinter_key(), record.getPrinter_name()));
|
||||
if (!success) {
|
||||
return CommonResult.failed("打印机绑定未成功,操作失败。");
|
||||
Pair<Boolean,String> retPair = feieUtil.addPrinter(String.format("%s#%s#%s", record.getPrinter_sn(), record.getPrinter_key(), record.getPrinter_name()));
|
||||
if (!retPair.getFirst()) {
|
||||
return CommonResult.failed(retPair.getSecond());
|
||||
}
|
||||
} else {
|
||||
status = ConstantError.Disable2;
|
||||
// 向厂家解绑打印机
|
||||
success = feieUtil.delPrinter(record.getPrinter_sn());
|
||||
boolean success = feieUtil.delPrinter(record.getPrinter_sn());
|
||||
if (!success) {
|
||||
return CommonResult.failed("打印机解绑定未成功,操作失败。");
|
||||
}
|
||||
@ -323,8 +324,8 @@ public class ShopStorePrinterServiceImpl extends BaseServiceImpl<ShopStorePrinte
|
||||
|
||||
// 判断有没有权限
|
||||
UserDto user = getCurrentUser();
|
||||
if (!user.isStore()) {
|
||||
return CommonResult.failed("用户信息异常!");
|
||||
if (user==null || !user.isStore()) {
|
||||
return CommonResult.failed("无权操作!");
|
||||
}
|
||||
|
||||
ShopStorePrinter record = getById(printer_id);
|
||||
|
||||
@ -1,8 +1,11 @@
|
||||
package com.suisung.mall.shop.store.utis;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.collection.CollectionUtil;
|
||||
import cn.hutool.core.util.ObjUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.suisung.mall.common.pojo.res.FeiePrinterApiDataRes;
|
||||
import cn.hutool.json.JSONObject;
|
||||
import cn.hutool.json.JSONUtil;
|
||||
import com.suisung.mall.common.pojo.res.FeiePrinterApiRes;
|
||||
import com.suisung.mall.common.pojo.vo.ShopStoreOrderProductPrintVO;
|
||||
import com.suisung.mall.common.utils.JsonUtil;
|
||||
@ -91,18 +94,25 @@ public class FeieUtil {
|
||||
* 每次最多添加100台。
|
||||
* @return
|
||||
*/
|
||||
public boolean addPrinter(String printerInfo) {
|
||||
public Pair<Boolean,String> addPrinter(String printerInfo) {
|
||||
List<NameValuePair> nvps = new ArrayList<NameValuePair>();
|
||||
nvps.add(new BasicNameValuePair("printerContent", printerInfo));
|
||||
FeiePrinterApiRes<FeiePrinterApiDataRes> reps = sendHttpPost("Open_printerAddlist", nvps);
|
||||
logger.info("飞鹅添加打印机返回数据:{}", reps);
|
||||
if (reps != null && reps.getRet().equals(0)) {
|
||||
// && reps.getData()!=null && reps.getData().getOk()!=null &&reps.getData().getOk().length>0
|
||||
return true;
|
||||
JSONObject reps = sendHttpPost2("Open_printerAddlist", nvps);
|
||||
if (reps == null) {
|
||||
return Pair.of(false, "打印机未返回数据,操作失败");
|
||||
}
|
||||
|
||||
logger.error("飞鹅添加打印机操作失败:{}", reps.getMsg());
|
||||
return false;
|
||||
if (ObjUtil.equals(reps.get("ret"), 0) && ObjUtil.isNotEmpty(reps.get("data"))) {
|
||||
if (ObjUtil.isNotEmpty(reps.getByPath("data.ok"))) {
|
||||
return Pair.of(true, "打印机完成绑定,操作成功!");
|
||||
} else if (ObjUtil.isNotEmpty(reps.getByPath("data.no"))) {
|
||||
logger.error("飞鹅添加打印机操作失败:{}", reps.getByPath("data.no"));
|
||||
return Pair.of(false, reps.getByPath("data.no.0") + ",操作失败!");
|
||||
}
|
||||
}
|
||||
|
||||
logger.error("飞鹅添加打印机操作失败:{}", reps);
|
||||
return Pair.of(false, reps.getByPath("msg") + ",操作失败!");
|
||||
}
|
||||
|
||||
/**
|
||||
@ -115,7 +125,7 @@ public class FeieUtil {
|
||||
List<NameValuePair> nvps = new ArrayList<NameValuePair>();
|
||||
nvps.add(new BasicNameValuePair("snlist", snList));
|
||||
|
||||
FeiePrinterApiRes<FeiePrinterApiDataRes> reps = sendHttpPost("Open_printerDelList", nvps);
|
||||
FeiePrinterApiRes reps = sendHttpPost("Open_printerDelList", nvps);
|
||||
logger.info("飞鹅删除打印机返回数据:{}", reps);
|
||||
if (reps != null && reps.getRet().equals(0)) {
|
||||
return true;
|
||||
@ -265,6 +275,52 @@ public class FeieUtil {
|
||||
return null;
|
||||
}
|
||||
|
||||
private JSONObject sendHttpPost2(String apiName, List<NameValuePair> paramPair) {
|
||||
if (StrUtil.isBlank(apiName) || CollectionUtil.isEmpty(paramPair)) {
|
||||
logger.info("缺少必要参数!");
|
||||
return null;
|
||||
}
|
||||
|
||||
//通过POST请求,发送打印信息到服务器
|
||||
RequestConfig requestConfig = RequestConfig.custom()
|
||||
.setSocketTimeout(30000)//读取超时
|
||||
.setConnectTimeout(30000)//连接超时
|
||||
.build();
|
||||
|
||||
CloseableHttpClient httpClient = HttpClients.custom()
|
||||
.setDefaultRequestConfig(requestConfig)
|
||||
.build();
|
||||
|
||||
HttpPost post = new HttpPost(URL);
|
||||
|
||||
paramPair.add(new BasicNameValuePair("user", USER));
|
||||
String STIME = String.valueOf(System.currentTimeMillis() / 1000);
|
||||
paramPair.add(new BasicNameValuePair("stime", STIME));
|
||||
paramPair.add(new BasicNameValuePair("sig", signature(USER, UKEY, STIME)));
|
||||
paramPair.add(new BasicNameValuePair("apiname", apiName));
|
||||
|
||||
CloseableHttpResponse response = null;
|
||||
try {
|
||||
post.setEntity(new UrlEncodedFormEntity(paramPair, "utf-8"));
|
||||
response = httpClient.execute(post);
|
||||
int stateCode = response.getStatusLine().getStatusCode();
|
||||
if (stateCode == 200) {
|
||||
HttpEntity httpentity = response.getEntity();
|
||||
if (httpentity != null) {
|
||||
String result = EntityUtils.toString(httpentity);
|
||||
logger.debug("飞鹅云返回到信息:{}", result);
|
||||
return JSONUtil.parseObj(result);
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
logger.error("发送飞鹅接口请求失败:{}", e.getMessage());
|
||||
} finally {
|
||||
close(response, post, httpClient);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成商品的打印字符串
|
||||
*
|
||||
|
||||
Loading…
Reference in New Issue
Block a user