|
@ -45,6 +45,8 @@ import java.time.LocalDate; |
|
|
import java.time.LocalDateTime; |
|
|
import java.time.LocalDateTime; |
|
|
import java.time.LocalTime; |
|
|
import java.time.LocalTime; |
|
|
import java.util.*; |
|
|
import java.util.*; |
|
|
|
|
|
import java.util.regex.Matcher; |
|
|
|
|
|
import java.util.regex.Pattern; |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* 纸箱贴标机 |
|
|
* 纸箱贴标机 |
|
@ -196,9 +198,12 @@ public class CartonLabelingMachineDeviceDriver extends AbstractOpcDeviceDriver i |
|
|
String carton_qty = tickets.getCarton_qty(); |
|
|
String carton_qty = tickets.getCarton_qty(); |
|
|
//计划数量
|
|
|
//计划数量
|
|
|
String planned_quantity = tickets.getPlanned_quantity(); |
|
|
String planned_quantity = tickets.getPlanned_quantity(); |
|
|
|
|
|
//纸箱模板名称
|
|
|
|
|
|
String carton_board=tickets.getCarton_board(); |
|
|
//晶科每罐重量
|
|
|
//晶科每罐重量
|
|
|
String bottle_weight = null; |
|
|
String bottle_weight = tickets.getBottle_weight(); |
|
|
Integer bottle_weight1 = 0; |
|
|
Integer bottle_weight1 = 0; |
|
|
|
|
|
Integer bottle_weight2 = Integer.parseInt(bottle_weight); |
|
|
//当前纸箱完成数量
|
|
|
//当前纸箱完成数量
|
|
|
String fcarton_number = tickets.getFcarton_number(); |
|
|
String fcarton_number = tickets.getFcarton_number(); |
|
|
Integer fcarton_number1 = Integer.parseInt(fcarton_number); |
|
|
Integer fcarton_number1 = Integer.parseInt(fcarton_number); |
|
@ -207,6 +212,50 @@ public class CartonLabelingMachineDeviceDriver extends AbstractOpcDeviceDriver i |
|
|
// Float carton_qty1 = Float.parseFloat(carton_qty);
|
|
|
// Float carton_qty1 = Float.parseFloat(carton_qty);
|
|
|
//总纸箱数
|
|
|
//总纸箱数
|
|
|
Integer sum_carton1 = (planned_quantity1 + carton_qty1 - 1) / carton_qty1; |
|
|
Integer sum_carton1 = (planned_quantity1 + carton_qty1 - 1) / carton_qty1; |
|
|
|
|
|
//罐数
|
|
|
|
|
|
Integer cartonnumber = 0; |
|
|
|
|
|
//净重
|
|
|
|
|
|
Integer standardweight = 0; |
|
|
|
|
|
if (fcarton_number1 == 0) { |
|
|
|
|
|
cartonnumber = carton_qty1 - (sum_carton1 * carton_qty1 - planned_quantity1); |
|
|
|
|
|
} else { |
|
|
|
|
|
cartonnumber = carton_qty1; |
|
|
|
|
|
} |
|
|
|
|
|
standardweight = cartonnumber * bottle_weight2; |
|
|
|
|
|
//批次号
|
|
|
|
|
|
String batch_number = tickets.getBatch_number(); |
|
|
|
|
|
String pcn=""; |
|
|
|
|
|
String pcy=""; |
|
|
|
|
|
String pcr=""; |
|
|
|
|
|
Integer yxy=0; |
|
|
|
|
|
Integer yxn=0; |
|
|
|
|
|
if(!customer.contains("马来韩华")&&!customer.contains("韩国韩华")) { |
|
|
|
|
|
pcn = "20" + batch_number.substring(2, 4); |
|
|
|
|
|
pcy = batch_number.substring(4, 6); |
|
|
|
|
|
pcr = batch_number.substring(6, 8); |
|
|
|
|
|
yxy = Integer.parseInt(pcy) + 6; |
|
|
|
|
|
yxn = Integer.parseInt(pcn); |
|
|
|
|
|
if (yxy > 12) { |
|
|
|
|
|
yxn = yxn + 1; |
|
|
|
|
|
yxy = yxy - 12; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
//通威重量
|
|
|
|
|
|
double roundedValue = 0.0; |
|
|
|
|
|
if (!tickets.getIs_ice()) { |
|
|
|
|
|
double lowerBound = 2.181; |
|
|
|
|
|
double upperBound = 2.221; |
|
|
|
|
|
// 生成随机值并映射到区间 [2.181, 2.221]
|
|
|
|
|
|
double randomValue = lowerBound + (upperBound - lowerBound) * Math.random(); |
|
|
|
|
|
// 将结果四舍五入到三位小数
|
|
|
|
|
|
roundedValue =Math.round(randomValue * 1000.0)*cartonnumber / 1000.0; |
|
|
|
|
|
}else{ |
|
|
|
|
|
double lowerBound = 2.921; |
|
|
|
|
|
double upperBound = 3.021; |
|
|
|
|
|
double randomValue = lowerBound + (upperBound - lowerBound) * Math.random(); |
|
|
|
|
|
// 将结果四舍五入到三位小数
|
|
|
|
|
|
roundedValue =Math.round(randomValue * 1000.0)*cartonnumber / 1000.0; |
|
|
|
|
|
} |
|
|
//总纸箱数(Integer)
|
|
|
//总纸箱数(Integer)
|
|
|
//纸箱号
|
|
|
//纸箱号
|
|
|
String carton_number = tickets.getCarton_number(); |
|
|
String carton_number = tickets.getCarton_number(); |
|
@ -249,6 +298,28 @@ public class CartonLabelingMachineDeviceDriver extends AbstractOpcDeviceDriver i |
|
|
} |
|
|
} |
|
|
last_number = last_number5; |
|
|
last_number = last_number5; |
|
|
} |
|
|
} |
|
|
|
|
|
//眉山通威
|
|
|
|
|
|
String real_zxdigits1=null; |
|
|
|
|
|
String twcarton_number=null; |
|
|
|
|
|
if (customer.contains("眉山通威")||customer.contains("宜宾东磁")) { |
|
|
|
|
|
String zxletters = carton_number.replaceAll("\\d+$", ""); // 匹配并去掉末尾的数字
|
|
|
|
|
|
String zxdigits = extractNumberAfterLastLetter(carton_number); // 匹配并取出末尾的数字部分
|
|
|
|
|
|
Integer zxdigits1=Integer.parseInt(zxdigits)-real_carton; |
|
|
|
|
|
if(zxdigits1<=9){ |
|
|
|
|
|
real_zxdigits1="0"+String.valueOf(zxdigits1); |
|
|
|
|
|
}else{ |
|
|
|
|
|
real_zxdigits1=String.valueOf(zxdigits1); |
|
|
|
|
|
} |
|
|
|
|
|
twcarton_number=zxletters+real_zxdigits1; |
|
|
|
|
|
} |
|
|
|
|
|
//zx通威系统标准
|
|
|
|
|
|
String real_zxdigits2=null; |
|
|
|
|
|
if (carton_board.contains("通威系统标准")) { |
|
|
|
|
|
String zxletters = carton_number.substring(0, 14); |
|
|
|
|
|
String zxdigits = carton_number.substring(14, 18); |
|
|
|
|
|
Integer zxdigits1=Integer.parseInt(zxdigits)-real_carton; |
|
|
|
|
|
real_zxdigits2=zxletters+zxdigits1; |
|
|
|
|
|
} |
|
|
//晶澳纸箱数据
|
|
|
//晶澳纸箱数据
|
|
|
String janumber = ""; |
|
|
String janumber = ""; |
|
|
if (customer.contains("晶澳")) { |
|
|
if (customer.contains("晶澳")) { |
|
@ -282,7 +353,7 @@ public class CartonLabelingMachineDeviceDriver extends AbstractOpcDeviceDriver i |
|
|
} else { |
|
|
} else { |
|
|
for (Integer i = 0; i < carton_qty1; i++) { |
|
|
for (Integer i = 0; i < carton_qty1; i++) { |
|
|
Integer last_number2 = Integer.parseInt(last_number); |
|
|
Integer last_number2 = Integer.parseInt(last_number); |
|
|
last_number2 = (sum_carton1 - real_carton - 1) * 10 + i + 1; |
|
|
last_number2 = (sum_carton1 - real_carton - 1) * carton_qty1 + i + 1; |
|
|
String last_number3 = String.valueOf(last_number2); |
|
|
String last_number3 = String.valueOf(last_number2); |
|
|
if (last_number2 > 100) { |
|
|
if (last_number2 > 100) { |
|
|
last_number3 = String.valueOf(last_number2) + ",2;"; |
|
|
last_number3 = String.valueOf(last_number2) + ",2;"; |
|
@ -321,6 +392,11 @@ public class CartonLabelingMachineDeviceDriver extends AbstractOpcDeviceDriver i |
|
|
options.put("title", "日期: " + currentDate); |
|
|
options.put("title", "日期: " + currentDate); |
|
|
printElement.put("options", options); |
|
|
printElement.put("options", options); |
|
|
} |
|
|
} |
|
|
|
|
|
if (options.get("testData").equals("jkdate")) { |
|
|
|
|
|
LocalDate currentDate = LocalDate.now(); |
|
|
|
|
|
options.put("title", "发货日期: " + currentDate); |
|
|
|
|
|
printElement.put("options", options); |
|
|
|
|
|
} |
|
|
if (options.get("testData").equals("weight")) { |
|
|
if (options.get("testData").equals("weight")) { |
|
|
options.put("title", "重量: " + weight1 + "kg"); |
|
|
options.put("title", "重量: " + weight1 + "kg"); |
|
|
printElement.put("options", options); |
|
|
printElement.put("options", options); |
|
@ -330,6 +406,67 @@ public class CartonLabelingMachineDeviceDriver extends AbstractOpcDeviceDriver i |
|
|
options.put("title", "箱号: " + sum_carton1 + "——" + real_carton); |
|
|
options.put("title", "箱号: " + sum_carton1 + "——" + real_carton); |
|
|
printElement.put("options", options); |
|
|
printElement.put("options", options); |
|
|
} |
|
|
} |
|
|
|
|
|
if (options.get("testData").equals("batchnumber")) { |
|
|
|
|
|
options.put("title", "批号: " +tickets.getSmall_model()+"-"+tickets.getBatch_number()); |
|
|
|
|
|
printElement.put("options", options); |
|
|
|
|
|
} |
|
|
|
|
|
//爱旭批次号
|
|
|
|
|
|
if (options.get("testData").equals("axbatchnumber")) { |
|
|
|
|
|
options.put("title", "批次号: " +tickets.getBatch_number()); |
|
|
|
|
|
printElement.put("options", options); |
|
|
|
|
|
} |
|
|
|
|
|
if (options.get("testData").equals("model")) { |
|
|
|
|
|
options.put("title", "型号: " +tickets.getModel()); |
|
|
|
|
|
printElement.put("options", options); |
|
|
|
|
|
} |
|
|
|
|
|
//爱旭尺寸/规格
|
|
|
|
|
|
if (options.get("testData").equals("ccgg")) { |
|
|
|
|
|
options.put("title", "尺寸/规格: " +bottle_weight2+"*"+cartonnumber+"罐"); |
|
|
|
|
|
printElement.put("options", options); |
|
|
|
|
|
} |
|
|
|
|
|
//爱旭数量
|
|
|
|
|
|
if (options.get("testData").equals("axstandardweight")) { |
|
|
|
|
|
options.put("title", "数量: " +standardweight+"KG"); |
|
|
|
|
|
printElement.put("options", options); |
|
|
|
|
|
} |
|
|
|
|
|
//通威批号
|
|
|
|
|
|
if (options.get("testData").equals("twbatchnumber")) { |
|
|
|
|
|
options.put("title", "批号: " +tickets.getBatch()); |
|
|
|
|
|
printElement.put("options", options); |
|
|
|
|
|
} |
|
|
|
|
|
//通威重量
|
|
|
|
|
|
if (options.get("testData").equals("twweight")) { |
|
|
|
|
|
options.put("title", "重量: " + roundedValue + "kg"); |
|
|
|
|
|
printElement.put("options", options); |
|
|
|
|
|
} |
|
|
|
|
|
if (options.get("testData").equals("materialcode")) { |
|
|
|
|
|
options.put("title", "物料编码: " +tickets.getMaterial_code()); |
|
|
|
|
|
printElement.put("options", options); |
|
|
|
|
|
} |
|
|
|
|
|
if (options.get("testData").equals("materialname")) { |
|
|
|
|
|
options.put("title", "物料名称: " +tickets.getMaterial_number()); |
|
|
|
|
|
printElement.put("options", options); |
|
|
|
|
|
} |
|
|
|
|
|
if (options.get("testData").equals("cartonnumber")) { |
|
|
|
|
|
options.put("title", "罐数: " +cartonnumber+"罐"); |
|
|
|
|
|
printElement.put("options", options); |
|
|
|
|
|
} |
|
|
|
|
|
if (options.get("testData").equals("weightnumber")) { |
|
|
|
|
|
options.put("title", "重量: " +cartonnumber+"罐"+"/"+standardweight+"KG"); |
|
|
|
|
|
printElement.put("options", options); |
|
|
|
|
|
} |
|
|
|
|
|
if (options.get("testData").equals("standardweight")) { |
|
|
|
|
|
options.put("title", "净重: " +standardweight+"KG"); |
|
|
|
|
|
printElement.put("options", options); |
|
|
|
|
|
} |
|
|
|
|
|
if (options.get("testData").equals("productdate")) { |
|
|
|
|
|
options.put("title", "生产日期: " +pcn+"."+pcy+"."+pcr); |
|
|
|
|
|
printElement.put("options", options); |
|
|
|
|
|
} |
|
|
|
|
|
if (options.get("testData").equals("effective")) { |
|
|
|
|
|
options.put("title", "生产日期: " +yxn+"."+yxy+"."+pcr); |
|
|
|
|
|
printElement.put("options", options); |
|
|
|
|
|
} |
|
|
if (options.get("testData").equals("纸箱号")) { |
|
|
if (options.get("testData").equals("纸箱号")) { |
|
|
log.info("纸箱号{}{}", first_number, last_number); |
|
|
log.info("纸箱号{}{}", first_number, last_number); |
|
|
String number = ""; |
|
|
String number = ""; |
|
@ -346,6 +483,16 @@ public class CartonLabelingMachineDeviceDriver extends AbstractOpcDeviceDriver i |
|
|
options.put("testData", number); |
|
|
options.put("testData", number); |
|
|
printElement.put("options", options); |
|
|
printElement.put("options", options); |
|
|
} |
|
|
} |
|
|
|
|
|
if (options.get("testData").equals("眉山通威纸箱号")) { |
|
|
|
|
|
options.put("title", twcarton_number); |
|
|
|
|
|
options.put("testData", twcarton_number); |
|
|
|
|
|
printElement.put("options", options); |
|
|
|
|
|
} |
|
|
|
|
|
if (options.get("testData").equals("宜宾东磁纸箱号")) { |
|
|
|
|
|
options.put("title", "纸箱号:"+twcarton_number); |
|
|
|
|
|
options.put("testData", twcarton_number); |
|
|
|
|
|
printElement.put("options", options); |
|
|
|
|
|
} |
|
|
if (options.get("testData").equals("晶澳纸箱号")) { |
|
|
if (options.get("testData").equals("晶澳纸箱号")) { |
|
|
log.info("晶澳纸箱号{}{}", janumber); |
|
|
log.info("晶澳纸箱号{}{}", janumber); |
|
|
String number = janumber; |
|
|
String number = janumber; |
|
@ -424,7 +571,7 @@ public class CartonLabelingMachineDeviceDriver extends AbstractOpcDeviceDriver i |
|
|
psletters = bottle_number.substring(0, 20); |
|
|
psletters = bottle_number.substring(0, 20); |
|
|
psdigits = bottle_number.substring(20, 23); |
|
|
psdigits = bottle_number.substring(20, 23); |
|
|
psdigits1 = Integer.parseInt(psdigits) - fbottle_number1; |
|
|
psdigits1 = Integer.parseInt(psdigits) - fbottle_number1; |
|
|
if(psdigits1>100){ |
|
|
if(psdigits1>=100){ |
|
|
psdigits=String.valueOf(psdigits1); |
|
|
psdigits=String.valueOf(psdigits1); |
|
|
}else if(psdigits1>=10){ |
|
|
}else if(psdigits1>=10){ |
|
|
psdigits="0"+ psdigits1; |
|
|
psdigits="0"+ psdigits1; |
|
@ -446,6 +593,15 @@ public class CartonLabelingMachineDeviceDriver extends AbstractOpcDeviceDriver i |
|
|
psdigits = "00" + String.valueOf(psdigits1); |
|
|
psdigits = "00" + String.valueOf(psdigits1); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
//通威瓶盖
|
|
|
|
|
|
long real_psdigits1 = 0; // 赋初值为0
|
|
|
|
|
|
String twpg=null; |
|
|
|
|
|
if (customer.contains("眉山通威")) { |
|
|
|
|
|
psletters = bottle_number.substring(0,4); |
|
|
|
|
|
psdigits = bottle_number.substring(4,15); |
|
|
|
|
|
real_psdigits1=Long.valueOf(psdigits)-fbottle_number1; |
|
|
|
|
|
twpg=psletters+real_psdigits1; |
|
|
|
|
|
} |
|
|
String jsonString = template.toString(); |
|
|
String jsonString = template.toString(); |
|
|
ObjectMapper objectMapper = new ObjectMapper(); |
|
|
ObjectMapper objectMapper = new ObjectMapper(); |
|
|
// 解析外部 JSON 字符串,获取 "template" 字段的值
|
|
|
// 解析外部 JSON 字符串,获取 "template" 字段的值
|
|
@ -478,6 +634,10 @@ public class CartonLabelingMachineDeviceDriver extends AbstractOpcDeviceDriver i |
|
|
options.put("testData", number1 + ",2"); |
|
|
options.put("testData", number1 + ",2"); |
|
|
printElement.put("options", options); |
|
|
printElement.put("options", options); |
|
|
} |
|
|
} |
|
|
|
|
|
else if (options.get("testData").equals("通威瓶号")) { |
|
|
|
|
|
options.put("testData", twpg); |
|
|
|
|
|
printElement.put("options", options); |
|
|
|
|
|
} |
|
|
} else { |
|
|
} else { |
|
|
continue; |
|
|
continue; |
|
|
} |
|
|
} |
|
@ -493,7 +653,6 @@ public class CartonLabelingMachineDeviceDriver extends AbstractOpcDeviceDriver i |
|
|
ticketsMapper.updateById(tickets); |
|
|
ticketsMapper.updateById(tickets); |
|
|
Map map = new HashMap(); |
|
|
Map map = new HashMap(); |
|
|
map.put("to_command", 200); |
|
|
map.put("to_command", 200); |
|
|
map.put("to_message", ""); |
|
|
|
|
|
this.writing(map); |
|
|
this.writing(map); |
|
|
} else { |
|
|
} else { |
|
|
message = "无请求"; |
|
|
message = "无请求"; |
|
@ -575,7 +734,17 @@ public class CartonLabelingMachineDeviceDriver extends AbstractOpcDeviceDriver i |
|
|
public String toString() { |
|
|
public String toString() { |
|
|
return ""; |
|
|
return ""; |
|
|
} |
|
|
} |
|
|
|
|
|
public static String extractNumberAfterLastLetter(String input) { |
|
|
|
|
|
// 正则表达式:匹配最后一个字母后面的数字
|
|
|
|
|
|
Pattern pattern = Pattern.compile("[a-zA-Z]([0-9]+)$"); |
|
|
|
|
|
Matcher matcher = pattern.matcher(input); |
|
|
|
|
|
|
|
|
|
|
|
if (matcher.find()) { |
|
|
|
|
|
return matcher.group(1); // 返回匹配的数字部分
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return ""; // 如果没有匹配到数字,返回空字符串
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
@Override |
|
|
@Override |
|
|
public JSONObject getDeviceStatusName() throws Exception { |
|
|
public JSONObject getDeviceStatusName() throws Exception { |
|
|