ocr
This commit is contained in:
parent
1c209385d0
commit
d7dcbcddb6
|
|
@ -83,4 +83,20 @@ public class AppOcrController extends BaseController {
|
|||
{
|
||||
return appOcrService.submitOcrBack(bean);
|
||||
}
|
||||
|
||||
@ApiOperation(value = "获取ocr编码")
|
||||
@PreventRepeatSubmit
|
||||
@PostMapping("/getOcrCode")
|
||||
public AjaxResult getOcrCode(@RequestBody MachineOcrBean bean)
|
||||
{
|
||||
return appOcrService.getOcrCode(bean);
|
||||
}
|
||||
|
||||
@ApiOperation(value = "推送设备至第三方入库")
|
||||
@PreventRepeatSubmit
|
||||
@PostMapping("/addDeviceNumber")
|
||||
public AjaxResult addDeviceNumber(@RequestBody MachineOcrBean bean)
|
||||
{
|
||||
return appOcrService.addDeviceNumber(bean);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -13,6 +13,7 @@ public class MachineOcrBean extends BaseEntity {
|
|||
private String id;
|
||||
private String epcCode;
|
||||
private String deviceName;
|
||||
private String deviceNumber;
|
||||
private String deviceModel;
|
||||
private String maCode;
|
||||
private String batchStatus;
|
||||
|
|
|
|||
|
|
@ -47,4 +47,18 @@ public interface AppOcrService {
|
|||
* @return
|
||||
*/
|
||||
AjaxResult submitOcrBack(MachineOcrBean bean);
|
||||
|
||||
/**
|
||||
* 获取ocr编码
|
||||
* @param bean
|
||||
* @return
|
||||
*/
|
||||
AjaxResult getOcrCode(MachineOcrBean bean);
|
||||
|
||||
/**
|
||||
* 推送设备至第三方入库
|
||||
* @param bean
|
||||
* @return
|
||||
*/
|
||||
AjaxResult addDeviceNumber(MachineOcrBean bean);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,8 +1,10 @@
|
|||
package com.bonus.material.app.service.impl;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.alibaba.nacos.common.utils.CollectionUtils;
|
||||
import com.bonus.common.biz.config.AppOcrConfig;
|
||||
import com.bonus.common.biz.enums.HttpCodeEnum;
|
||||
import com.bonus.common.biz.utils.HttpHelper;
|
||||
import com.bonus.common.core.utils.DateUtils;
|
||||
import com.bonus.common.core.web.domain.AjaxResult;
|
||||
import com.bonus.common.security.utils.SecurityUtils;
|
||||
|
|
@ -19,6 +21,8 @@ import org.springframework.stereotype.Service;
|
|||
import javax.annotation.Resource;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
/**
|
||||
* @ClassName AppOcrServiceImpl
|
||||
|
|
@ -237,6 +241,115 @@ public class AppOcrServiceImpl implements AppOcrService {
|
|||
return AjaxResult.error(HttpCodeEnum.FAIL.getCode(), HttpCodeEnum.FAIL.getMsg());
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取ocr编码
|
||||
* @param bean
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public AjaxResult getOcrCode(MachineOcrBean bean) {
|
||||
String url = "http://10.138.55.102:10000/api_gqj/pre";
|
||||
JSONObject js = null;
|
||||
try {
|
||||
String jsonStr = JSONObject.toJSONString(bean);
|
||||
String data = HttpHelper.sendHttpPostForToken(url, jsonStr);
|
||||
js = JSONObject.parseObject(data);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return AjaxResult.success(js);
|
||||
}
|
||||
|
||||
/**
|
||||
* 推送设备至第三方入库
|
||||
* @param bean
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public AjaxResult addDeviceNumber(MachineOcrBean bean) {
|
||||
if (bean == null) {
|
||||
return AjaxResult.error(HttpCodeEnum.TO_PARAM_NULL.getCode(), HttpCodeEnum.TO_PARAM_NULL.getMsg());
|
||||
}
|
||||
String deviceNumber = bean.getDeviceNumber();
|
||||
if (deviceNumber != null) {
|
||||
String url = "http://10.138.55.102:10000/api_ruku_1/bianma_add";
|
||||
JSONObject obj = ofObject(deviceNumber);
|
||||
try {
|
||||
String objJSONString = JSONObject.toJSONString(obj);
|
||||
String result = HttpHelper.sendHttpPostForToken(url, objJSONString);
|
||||
if (result != null) {
|
||||
obj = JSONObject.parseObject(result);
|
||||
if (obj.getInteger("code") == 0) {
|
||||
// Java8 CompletableFuture异步工具类 ---- 推送nginx
|
||||
CompletableFuture.runAsync(() -> {
|
||||
// 输出异步执行的线程名称
|
||||
System.out.println("Executing task in thread: " + Thread.currentThread().getName());
|
||||
// 执行异步任务
|
||||
pushNginxByDeviceNumber(deviceNumber);
|
||||
// 异步任务执行结束
|
||||
System.out.println("Task completed.");
|
||||
});
|
||||
return AjaxResult.success("设备编号添加成功");
|
||||
} else {
|
||||
return AjaxResult.error("设备编号添加失败,外部接口调用返回内容:" + obj.getString("msg"));
|
||||
}
|
||||
} else {
|
||||
return AjaxResult.error("设备编号添加失败,外部接口调用返回内容为null");
|
||||
}
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
} else {
|
||||
return AjaxResult.error("设备编号不能为空");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 循环10次请求nginx
|
||||
* @param deviceNumber
|
||||
* @return
|
||||
*/
|
||||
private static boolean pushNginxByDeviceNumber(String deviceNumber) {
|
||||
boolean isSuccess = true;
|
||||
String url = "http://10.138.55.102:10000/api_ruku_1/bianma_reload";
|
||||
JSONObject obj = ofObject(deviceNumber);
|
||||
String objJsonString = JSONObject.toJSONString(obj);
|
||||
for (int i = 0; i < 10; i++) {
|
||||
try {
|
||||
String result = HttpHelper.sendHttpPostForToken(url, objJsonString);
|
||||
if (result != null) {
|
||||
obj = JSONObject.parseObject(result);
|
||||
if (obj.getInteger("code") != 0) {isSuccess = false;}
|
||||
} else {
|
||||
isSuccess = false;
|
||||
}
|
||||
// 暂停3秒
|
||||
TimeUnit.SECONDS.sleep(3);
|
||||
} catch (InterruptedException e) {
|
||||
Thread.currentThread().interrupt();
|
||||
System.err.println("线程被中断: " + e.getMessage());
|
||||
} catch (Exception e){
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
System.out.println("nginx推送结果:" + isSuccess);
|
||||
return isSuccess;
|
||||
}
|
||||
|
||||
/**
|
||||
* 方法抽取
|
||||
* @param deviceNumber
|
||||
* @return
|
||||
*/
|
||||
private static JSONObject ofObject(String deviceNumber) {
|
||||
JSONObject obj = new JSONObject();
|
||||
obj.put("table_name", "bianmaku_1");
|
||||
obj.put("name", "1");
|
||||
obj.put("type", "2");
|
||||
obj.put("number", deviceNumber);
|
||||
return obj;
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改ma_machine_type库存,在库
|
||||
* @param bean
|
||||
|
|
|
|||
Loading…
Reference in New Issue