package com.example.springboot.service;
|
|
import java.nio.charset.StandardCharsets;
|
import java.util.ArrayList;
|
import java.util.List;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.stereotype.Service;
|
import com.example.springboot.component.PLCAutoMes;
|
import com.example.springboot.component.S7control;
|
import com.example.springboot.entity.GlassInfo;
|
import com.example.springboot.entity.StorageCage;
|
import com.example.springboot.entity.device.PlcParameterObject;
|
import com.example.springboot.mapper.AlbaniaMapper;
|
import com.google.common.primitives.Bytes;
|
|
@Service
|
public class SpianServiceNew {
|
@Autowired
|
private AlbaniaMapper albaniaMapper;
|
@Autowired
|
private StorageCageService storageCageService;
|
// 读取DB105区文件
|
private PlcParameterObject plcmes = PLCAutoMes.PlcMesObject;
|
|
public Short selectAll(GlassInfo glassInfo) {
|
if (glassInfo == null) {
|
// 有进片请求但是测量台没有玻璃
|
return 400;
|
}
|
|
System.out.println(glassInfo + "初始");
|
// 定义初始字段
|
StorageCage cage;
|
String glassid = glassInfo.getGlassid();
|
Double width = glassInfo.getWidth();
|
Double height = glassInfo.getHeight();
|
String flowcard = glassInfo.getFlowcard();
|
Integer glasstype = glassInfo.getGlasstype();
|
Double thickness = glassInfo.getThickness();
|
GlassInfo glassfilms = albaniaMapper.SelectGlassinfo(glasstype);
|
// 判断是否有同类型的
|
cage = albaniaMapper.SelectCage(glasstype, width, 300);
|
// 如果有同类型时直接增加
|
if (cage != null) {
|
// 发送plc任务
|
Mestast(glassid, 1001, cage.getId(), 1, "MESID1", 1);
|
System.out.println("任务发送玻璃id:" + glassid + "起始位置:" + 1001 + "格子号:" + cage.getId() + "启动:" + 1);
|
|
} else {
|
// 判断玻璃是否进入大片笼
|
if (glassInfo.getThickness() >= 15) {
|
cage = albaniaMapper.SelectNewCell(3, 5);
|
} else {
|
cage = albaniaMapper.SelectNewCell(0, 4);
|
|
// System.out.println(cage + "理片笼判断");
|
}
|
// 当返回的格子号为空时,返回400笼子已满
|
if (cage != null) {
|
albaniaMapper.AddCage(cage.getId(), glassid, width, height, 1, glasstype, 0, thickness,
|
glassfilms.getFilms(),glassfilms.getFlowcard(),glassfilms.getMateid());
|
Mestast(glassid, 1001, cage.getId(), 1, "MESID1", 1);
|
System.out.println("任务发送玻璃id:" + glassid + "起始位置:" + 1001 + "格子号:" + cage.getId() + "启动:" + 1);
|
albaniaMapper.UpdateStorage(width, height, cage.getId());
|
} else {
|
return (400);
|
}
|
}
|
// 增加任务记录
|
albaniaMapper.Inserttask(0, 0, 1001, cage.getId(), glassid, glasstype, flowcard, glassfilms.getMateid(), 0);
|
albaniaMapper.UpdateQueueState(glassid);
|
return (200);
|
|
}
|
//补充出片
|
public Short mateOut() {
|
double carwidth = -300;
|
list<StorageTask> glassmate = albaniaMapper.SelectMateOut();
|
return (200);
|
}
|
// 出片
|
public Short selectout(int line) {
|
GlassInfo glassmate = new GlassInfo();
|
GlassInfo method = new GlassInfo();
|
StorageCage glass = new StorageCage();
|
int glassend = 0;
|
double carwidth = -300;
|
method = albaniaMapper.SelectMethod(line);
|
if (method == null) {
|
return (400);
|
}
|
double width = 0;
|
for (int i = 1; i <= 7; i++) {
|
// 如果不是直通模式只出有完整配片的流程卡
|
if (method.getMethod() == 0) {
|
// glassmate= albaniaMapper.SelectOutGlass(1);
|
//判断有数量的配片id
|
List<GlassInfo> peipianid = albaniaMapper.SelectOutGlass3(method.getFlowcard());
|
if (peipianid.size() == 0) {
|
System.out.println("peipianid:"+peipianid);
|
return (400);
|
} else {
|
for (int j = 0; j < peipianid.size(); j++) {
|
// 判断配片宽度是否够上大车
|
// GlassInfo glasswidth = albaniaMapper.SelectOutGlass6(peipianid.get(j).getFlowcard(),peipianid.get(j).getMateid());
|
// if (glasswidth.getWidth() <= 4300) {
|
//是否有足够的库存数量
|
List<String> peipiancage = albaniaMapper.SelectOutGlass4(peipianid.get(j).getFlowcard(),peipianid.get(j).getMateid());
|
//是否有足够的可出片数量
|
List<String> peipiancage2 = albaniaMapper.SelectOutGlass8(peipianid.get(j).getFlowcard(),peipianid.get(j).getMateid());
|
// System.out.println("peipiancage:"+peipiancage+peipianid.get(j).getMateid());
|
// System.out.println("peipiancage2:"+peipiancage2);
|
if (!peipiancage.contains("不足")&&!peipiancage2.contains("不足")) {
|
List<GlassInfo> chupian = albaniaMapper.SelectOutGlass7(peipianid.get(j).getFlowcard(),peipianid.get(j).getMateid());
|
for (int k = 0; k < chupian.size(); k++) {
|
glass = albaniaMapper.SelectCageGlass(chupian.get(k).getGlasstype());
|
carwidth= carwidth+glass.getGlassWidth()+300;
|
if (carwidth<=4300) {
|
// 发送配片数据
|
// Mestast(chupian.get(k).getGlassid(), glass.getId(), 2001, 0, "MESID" + (k+1), k+1);
|
albaniaMapper.AddFinishNumber(chupian.get(k).getFlowcard(), chupian.get(k).getMateid(), chupian.get(k).getTier());
|
storageCageService.UpdateStroageCageByCell(glass.getId(), -1);// 玻璃数量-1
|
albaniaMapper.Inserttask(1, 0, glass.getId(), 2001, chupian.get(k).getGlassid(),
|
chupian.get(k).getGlasstype(), chupian.get(k).getFlowcard(), chupian.get(k).getMateid(), chupian.get(k).getTier());
|
}else {
|
albaniaMapper.AddFinishNumber(chupian.get(k).getFlowcard(), chupian.get(k).getMateid(), chupian.get(k).getTier());
|
storageCageService.UpdateStroageCageByCell(glass.getId(), -1);// 玻璃数量-1
|
albaniaMapper.InsertOutTask(1, 0, glass.getId(), 2001, chupian.get(k).getGlassid(),
|
chupian.get(k).getGlasstype(), chupian.get(k).getFlowcard(), chupian.get(k).getMateid(), chupian.get(k).getTier());
|
}
|
|
}
|
// 本次配片完成发送启动命令
|
S7control.getinstance().WriteWord(plcmes.getPlcParameter("MESToPLC").getAddress(), (short) 1);// 出片任务启动
|
return (200);// 结束
|
}
|
// }
|
// else {
|
// continue;
|
// }
|
}
|
System.out.println("未有完整配片");
|
return (400);
|
}
|
|
} else {
|
// 直通模式时按顺序直出
|
glassmate= albaniaMapper.SelectOutGlass(1);
|
// glassmate = albaniaMapper.SelectOutGlass2(1);
|
// // 获取直通模式最后一块
|
// glassend = albaniaMapper.SelectOutGlassend(1);
|
|
}
|
System.err.println("出片:" + glassmate);
|
if (glassmate == null && i > 1) {
|
// 本次配片完成发送启动命令
|
S7control.getinstance().WriteWord(plcmes.getPlcParameter("MESToPLC").getAddress(), (short) 1);// 出片任务启动
|
System.out.println("出完任务:1,任务状态:0,起始:" + glass.getId() + ",目标" + "2001");
|
return (200);// 结束
|
}
|
if (glassmate == null) {
|
// 未领取任务
|
System.out.println("未领取任务:" + i);
|
return (400);
|
} else {
|
glass = albaniaMapper.SelectCageGlass(glassmate.getGlasstype());
|
System.out.println("glassmate:" + glassmate + "glass:" + glass);
|
if (glass != null) {
|
// 发送任务之前判断车上的剩余宽度是否大于此玻璃
|
width = width + glassmate.getWidth() + 300;
|
// 大于车上空余宽度时提前发送出片启动
|
if (width > 4300) {
|
// 本次配片完成发送启动命令
|
S7control.getinstance().WriteWord(plcmes.getPlcParameter("MESToPLC").getAddress(), (short) 1);// 出片任务启动
|
return (200);// 结束
|
}
|
// 发送配片数据
|
Mestast(glass.getGlassId(), glass.getId(), 2001, 0, "MESID" + i, i);
|
albaniaMapper.AddFinishNumber(glassmate.getFlowcard(), glassmate.getMateid(), glassmate.getTier());
|
storageCageService.UpdateStroageCageByCell(glass.getId(), -1);// 玻璃数量-1
|
albaniaMapper.Inserttask(1, 0, glass.getId(), 2001, glassmate.getGlassid(),
|
glassmate.getGlasstype(), glass.getFlowcard(), glassmate.getMateid(), glassmate.getTier());
|
// if (glassmate.getTier() == glassmate.getId() || glassmate.getTier() == glassend|| method.getMethod() == 1) {// 当配片数量等于成品小片总片数时
|
// // 本次配片完成发送启动命令
|
// S7control.getinstance().WriteWord(plcmes.getPlcParameter("MESToPLC").getAddress(), (short) 1);// 出片任务启动
|
// System.out.println("任务类型:1,任务状态:0,起始:" + glass.getId() + ",目标" + "2001");
|
// return (200);// 结束
|
// }
|
|
} else {
|
return (400);// 结束
|
}
|
|
}
|
}
|
return (200);// 结束
|
}
|
|
// 派发任务玻璃id
|
public void outmesid(String glassid, String address) {
|
// 读取DB105区文件
|
PlcParameterObject plcmes = PLCAutoMes.PlcMesObject;
|
// System.out.println("outmesid:" + glassid);
|
List<Byte> glassidlist = new ArrayList();
|
char ds[] = glassid.toCharArray();
|
for (char iditem : ds) {
|
glassidlist.add((byte) iditem);
|
}
|
byte[] bytes = Bytes.toArray(glassidlist);
|
// writeString
|
System.out.println("outmesidbytes:" + bytes.length);
|
System.out.println(plcmes.getPlcParameter(address).getAddress());
|
System.out.println();
|
|
}
|
|
// 获取地址内的玻璃id转字符串
|
public StringBuilder queGlassid(String address, int count) {
|
StringBuilder writedstrIdOut = new StringBuilder();
|
byte[] writedglassidbytesOut = S7control.getinstance().ReadByte(address, count);
|
if (writedglassidbytesOut != null) {
|
// 获取玻璃id
|
for (byte iditem : writedglassidbytesOut) {
|
writedstrIdOut.append((char) iditem);
|
}
|
}
|
return writedstrIdOut;
|
}
|
|
// char数组转化成bit数组
|
public static byte[] toBytes(char[] chars) {
|
String s = new String(chars);
|
return s.getBytes(StandardCharsets.UTF_8);
|
}
|
|
// bit数组转化成char数组
|
public static char[] toChars(byte[] bytes) {
|
String s = new String(bytes, StandardCharsets.UTF_8);
|
return s.toCharArray();
|
}
|
|
// 判断集合里是否为1
|
public boolean listbool(String address) {
|
List<Short> list = S7control.getinstance().ReadWord(address, 1);// 返回为ture时为1
|
boolean listbool = list.contains((short) 1);
|
return listbool;
|
}
|
|
// 下发理片任务
|
public void Mestast(String glassid, int MESToPLCStart1, int MESToPLCTarget1, int MESToPLC, String address, int i) {
|
// System.out.println("下发理片任务数据:");
|
// System.out.println("玻璃 ID: " + glassid);
|
// System.out.println("起始位置: " + MESToPLCStart1);
|
// System.out.println("目标位置: " + MESToPLCTarget1);
|
// System.out.println("任务类型: " + MESToPLC);
|
// System.out.println("地址: " + address);
|
// System.out.println("索引: " + i);
|
S7control.getinstance().writeString(plcmes.getPlcParameter(address).getAddress(), glassid);// 玻璃id
|
S7control.getinstance().WriteWord(plcmes.getPlcParameter("MESToPLCStart" + i).getAddress(),
|
(short) MESToPLCStart1);// 起始位置
|
S7control.getinstance().WriteWord(plcmes.getPlcParameter("MESToPLCTarget" + i).getAddress(),
|
(short) MESToPLCTarget1);// 目标位置
|
if (MESToPLC != 0) {
|
S7control.getinstance().WriteWord(plcmes.getPlcParameter("MESToPLC").getAddress(), (short) MESToPLC);// mes理片任务类型
|
}
|
}
|
|
// 扫码增加队列任务
|
public boolean scan(String address) {
|
List<Short> list = S7control.getinstance().ReadWord(address, 1);// 返回为ture时为1
|
boolean listbool = list.contains((short) 1);
|
return listbool;
|
}
|
|
}
|