|
@@ -9,6 +9,7 @@ import com.ydd.third.print.request.PrintOrderActDto;
|
|
|
import com.ydd.third.print.request.PrintOrderDto;
|
|
|
import com.ydd.third.print.request.PrintOrderGoodsDto;
|
|
|
import com.ydd.third.print.response.PrintStatusResp;
|
|
|
+import com.ydd.third.print.service.PrintService;
|
|
|
import com.ydd.third.print.yilian.dto.Format;
|
|
|
import com.ydd.third.print.yilian.tag.*;
|
|
|
import com.ydd.third.print.yilian.utils.CloudPrintUtils;
|
|
@@ -25,7 +26,7 @@ import java.math.BigDecimal;
|
|
|
*/
|
|
|
@Service
|
|
|
@Slf4j
|
|
|
-public class YlyPrintService {
|
|
|
+public class YlyPrintService implements PrintService {
|
|
|
|
|
|
static PrintUtil p = new PrintUtil();
|
|
|
/**
|
|
@@ -34,37 +35,92 @@ public class YlyPrintService {
|
|
|
@Resource
|
|
|
private RedisCache redisCache;
|
|
|
|
|
|
- /**
|
|
|
- * 获取易联云访问token
|
|
|
- *
|
|
|
- * @return
|
|
|
- */
|
|
|
- public void getToken() {
|
|
|
- // String accessToken = null;
|
|
|
- String accessToken = redisCache.getCacheObject(PrintConfig.cloud_token_key);
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public String addPrintSn(PrintDeviceDto printDeviceDto) {
|
|
|
+ String deviceSn = printDeviceDto.getDeviceSn();
|
|
|
+ String deviceSecret = printDeviceDto.getDeviceSecret();
|
|
|
+
|
|
|
+ getToken();
|
|
|
CloudPrintUtils.getInstance().init(PrintConfig.cloud_clientId, PrintConfig.cloud_clientSecret);
|
|
|
- CloudPrintUtils.token = accessToken;
|
|
|
- if (StringUtils.isBlank(accessToken)) {
|
|
|
- CloudPrintUtils.getInstance().getFreedomToken();
|
|
|
- accessToken = CloudPrintUtils.token;
|
|
|
- String refreshToken = CloudPrintUtils.refresh_token;
|
|
|
- redisCache.setCacheObject(PrintConfig.cloud_token_key, accessToken);
|
|
|
- redisCache.setCacheObject(PrintConfig.cloud_refresh_token_key, refreshToken);
|
|
|
+ String result = CloudPrintUtils.getInstance().addPrinter(deviceSn, deviceSecret);
|
|
|
+ log.info("易联云添加打印机返回---"+result);
|
|
|
+ JSONObject json1 = JSONObject.parseObject(result);
|
|
|
+ if(json1.get("error").toString().equals("18")){
|
|
|
+ CloudPrintUtils.refresh_token=redisCache.getCacheObject(PrintConfig.cloud_refresh_token_key);
|
|
|
+ CloudPrintUtils.getInstance().refreshToken();
|
|
|
+ redisCache.setCacheObject(PrintConfig.cloud_token_key, CloudPrintUtils.token);
|
|
|
+ redisCache.setCacheObject(PrintConfig.cloud_refresh_token_key, CloudPrintUtils.refresh_token);
|
|
|
+ result = CloudPrintUtils.getInstance().addPrinter(deviceSn, deviceSecret);
|
|
|
+ }
|
|
|
+ JSONObject json = JSONObject.parseObject(result);
|
|
|
+ log.info("易联云绑定返回result---->"+result);
|
|
|
+ if (!json.get("error").toString().equals("0")) {
|
|
|
+ return json.getString("error_description");
|
|
|
+ }else{
|
|
|
+ return "ok";
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * 打印订单
|
|
|
- *
|
|
|
- * @param printDeviceDto
|
|
|
- * @param printOrderDto
|
|
|
- */
|
|
|
+ @Override
|
|
|
+ public void deleteSn(String deviceSn) {
|
|
|
+ try {
|
|
|
+ getToken();
|
|
|
+ CloudPrintUtils.getInstance().init(PrintConfig.cloud_clientId, PrintConfig.cloud_clientSecret);
|
|
|
+ String result = CloudPrintUtils.getInstance().deletePrinter(deviceSn);
|
|
|
+ JSONObject json1 = JSONObject.parseObject(result);
|
|
|
+ if (json1.getString("error").equals("18")){
|
|
|
+ CloudPrintUtils.refresh_token=redisCache.getCacheObject(PrintConfig.cloud_refresh_token_key);
|
|
|
+ CloudPrintUtils.getInstance().refreshToken();
|
|
|
+ redisCache.setCacheObject(PrintConfig.cloud_token_key, CloudPrintUtils.token);
|
|
|
+ redisCache.setCacheObject(PrintConfig.cloud_refresh_token_key, CloudPrintUtils.refresh_token);
|
|
|
+ result=CloudPrintUtils.getInstance().deletePrinter(deviceSn);
|
|
|
+ log.info("易联云删除result"+result);
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.info("易联云删除result出错");
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public PrintStatusResp getPrintStatus(PrintDeviceDto printDeviceDto) {
|
|
|
+ String machine_code = printDeviceDto.getDeviceSn();
|
|
|
+
|
|
|
+ PrintStatusResp resp = new PrintStatusResp();
|
|
|
+ getToken();
|
|
|
+ CloudPrintUtils.getInstance().init(PrintConfig.cloud_clientId, PrintConfig.cloud_clientSecret);
|
|
|
+ String result = CloudPrintUtils.getInstance().getPrintStatus(machine_code);
|
|
|
+ JSONObject json = JSONObject.parseObject(result);
|
|
|
+ log.info("易联云打印机返回---"+json);
|
|
|
+ //token过期
|
|
|
+ if(json.get("error").toString().equals("18")){
|
|
|
+ CloudPrintUtils.refresh_token=redisCache.getCacheObject(PrintConfig.cloud_refresh_token_key);
|
|
|
+ CloudPrintUtils.getInstance().refreshToken();
|
|
|
+ redisCache.setCacheObject(PrintConfig.cloud_token_key, CloudPrintUtils.token);
|
|
|
+ redisCache.setCacheObject(PrintConfig.cloud_refresh_token_key, CloudPrintUtils.refresh_token);
|
|
|
+ result = CloudPrintUtils.getInstance().getPrintStatus(machine_code);
|
|
|
+ }
|
|
|
+ JSONObject json1 = JSONObject.parseObject(result);
|
|
|
+ if (json1.get("error").toString().equals("0")) {
|
|
|
+ String body = json1.get("body").toString();
|
|
|
+ JSONObject bodyjson = JSONObject.parseObject(body);
|
|
|
+ if (bodyjson.get("state").toString().equals("1")) {
|
|
|
+ resp.setData("在线,工作状态正常。");
|
|
|
+ } else if (bodyjson.get("state").toString().equals("0")) {
|
|
|
+ resp.setData("离线。");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return resp;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
public void printOrder(PrintOrderDto printOrderDto, PrintDeviceDto printDeviceDto) {
|
|
|
getToken();
|
|
|
//打印小票
|
|
|
String content = getPrintContent(printOrderDto,printDeviceDto);
|
|
|
log.info("易连云打印请求:"+content);
|
|
|
- // CloudPrintUtils.getInstance().addPrinter(printDeviceDto.getDeviceSn(), LAVApi.getSin());
|
|
|
+ // CloudPrintUtils.getInstance().addPrinter(printDeviceDto.getDeviceSn(), LAVApi.getSin());
|
|
|
// String result = CloudPrintUtils.getInstance().print(printDeviceDto.getDeviceSn(), content, printOrderDto.getOrderidView());
|
|
|
// JSONObject jsonObject = JSONObject.parseObject(result);
|
|
|
// log.info("易连云返回+"+jsonObject);
|
|
@@ -75,7 +131,29 @@ public class YlyPrintService {
|
|
|
// redisCache.setCacheObject(PrintConfig.cloud_refresh_token_key, CloudPrintUtils.refresh_token);
|
|
|
// result = CloudPrintUtils.getInstance().print(printDeviceDto.getDeviceSn(), content, printOrderDto.getOrderidView());
|
|
|
// }
|
|
|
- // log.info("易连云返回:" + result);
|
|
|
+ // log.info("易连云返回:" + result);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取易联云访问token
|
|
|
+ *
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public void getToken() {
|
|
|
+ // String accessToken = null;
|
|
|
+ String accessToken = redisCache.getCacheObject(PrintConfig.cloud_token_key);
|
|
|
+ CloudPrintUtils.getInstance().init(PrintConfig.cloud_clientId, PrintConfig.cloud_clientSecret);
|
|
|
+ CloudPrintUtils.token = accessToken;
|
|
|
+ if (StringUtils.isBlank(accessToken)) {
|
|
|
+ CloudPrintUtils.getInstance().getFreedomToken();
|
|
|
+ accessToken = CloudPrintUtils.token;
|
|
|
+ String refreshToken = CloudPrintUtils.refresh_token;
|
|
|
+ redisCache.setCacheObject(PrintConfig.cloud_token_key, accessToken);
|
|
|
+ redisCache.setCacheObject(PrintConfig.cloud_refresh_token_key, refreshToken);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
|
|
@@ -157,34 +235,6 @@ public class YlyPrintService {
|
|
|
return "";
|
|
|
}
|
|
|
|
|
|
- public PrintStatusResp getPrintStatus(String machine_code) {
|
|
|
- PrintStatusResp resp = new PrintStatusResp();
|
|
|
- getToken();
|
|
|
- CloudPrintUtils.getInstance().init(PrintConfig.cloud_clientId, PrintConfig.cloud_clientSecret);
|
|
|
- String result = CloudPrintUtils.getInstance().getPrintStatus(machine_code);
|
|
|
- JSONObject json = JSONObject.parseObject(result);
|
|
|
- log.info("易联云打印机返回---"+json);
|
|
|
- //token过期
|
|
|
- if(json.get("error").toString().equals("18")){
|
|
|
- CloudPrintUtils.refresh_token=redisCache.getCacheObject(PrintConfig.cloud_refresh_token_key);
|
|
|
- CloudPrintUtils.getInstance().refreshToken();
|
|
|
- redisCache.setCacheObject(PrintConfig.cloud_token_key, CloudPrintUtils.token);
|
|
|
- redisCache.setCacheObject(PrintConfig.cloud_refresh_token_key, CloudPrintUtils.refresh_token);
|
|
|
- result = CloudPrintUtils.getInstance().getPrintStatus(machine_code);
|
|
|
- }
|
|
|
- JSONObject json1 = JSONObject.parseObject(result);
|
|
|
- if (json1.get("error").toString().equals("0")) {
|
|
|
- String body = json1.get("body").toString();
|
|
|
- JSONObject bodyjson = JSONObject.parseObject(body);
|
|
|
- if (bodyjson.get("state").toString().equals("1")) {
|
|
|
- resp.setData("在线,工作状态正常。");
|
|
|
- } else if (bodyjson.get("state").toString().equals("0")) {
|
|
|
- resp.setData("离线。");
|
|
|
- }
|
|
|
- }
|
|
|
- return resp;
|
|
|
- }
|
|
|
-
|
|
|
public void printerKitrContent(Format format, PrintOrderDto order, String printTime) {
|
|
|
FontLargeFormatTag fontLargeFormatTag = new FontLargeFormatTag("","2");
|
|
|
fontLargeFormatTag.prefixTag();
|
|
@@ -487,49 +537,6 @@ public class YlyPrintService {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- public String addPrintSn(String deviceSn, String deviceSecret) {
|
|
|
-
|
|
|
- getToken();
|
|
|
- CloudPrintUtils.getInstance().init(PrintConfig.cloud_clientId, PrintConfig.cloud_clientSecret);
|
|
|
- String result = CloudPrintUtils.getInstance().addPrinter(deviceSn, deviceSecret);
|
|
|
- log.info("易联云添加打印机返回---"+result);
|
|
|
- JSONObject json1 = JSONObject.parseObject(result);
|
|
|
- if(json1.get("error").toString().equals("18")){
|
|
|
- CloudPrintUtils.refresh_token=redisCache.getCacheObject(PrintConfig.cloud_refresh_token_key);
|
|
|
- CloudPrintUtils.getInstance().refreshToken();
|
|
|
- redisCache.setCacheObject(PrintConfig.cloud_token_key, CloudPrintUtils.token);
|
|
|
- redisCache.setCacheObject(PrintConfig.cloud_refresh_token_key, CloudPrintUtils.refresh_token);
|
|
|
- result = CloudPrintUtils.getInstance().addPrinter(deviceSn, deviceSecret);
|
|
|
- }
|
|
|
- JSONObject json = JSONObject.parseObject(result);
|
|
|
- log.info("易联云绑定返回result---->"+result);
|
|
|
- if (!json.get("error").toString().equals("0")) {
|
|
|
- return json.getString("error_description");
|
|
|
- }else{
|
|
|
- return "ok";
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- public void deleteSn(String deviceSn) {
|
|
|
- try {
|
|
|
- getToken();
|
|
|
- CloudPrintUtils.getInstance().init(PrintConfig.cloud_clientId, PrintConfig.cloud_clientSecret);
|
|
|
- String result = CloudPrintUtils.getInstance().deletePrinter(deviceSn);
|
|
|
- JSONObject json1 = JSONObject.parseObject(result);
|
|
|
- if (json1.getString("error").equals("18")){
|
|
|
- CloudPrintUtils.refresh_token=redisCache.getCacheObject(PrintConfig.cloud_refresh_token_key);
|
|
|
- CloudPrintUtils.getInstance().refreshToken();
|
|
|
- redisCache.setCacheObject(PrintConfig.cloud_token_key, CloudPrintUtils.token);
|
|
|
- redisCache.setCacheObject(PrintConfig.cloud_refresh_token_key, CloudPrintUtils.refresh_token);
|
|
|
- result=CloudPrintUtils.getInstance().deletePrinter(deviceSn);
|
|
|
- log.info("易联云删除result"+result);
|
|
|
- }
|
|
|
- } catch (Exception e) {
|
|
|
- log.info("易联云删除result出错");
|
|
|
- e.printStackTrace();
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
public void printTxt( String content,String deviceSn,String orderId) {
|
|
|
getToken();
|
|
|
|