| | |
| | | package com.example.springboot.service; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | | |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.web.bind.annotation.GetMapping; |
| | | |
| | | import com.example.springboot.common.Result; |
| | | import com.example.springboot.component.S7control; |
| | | import com.example.springboot.entity.Glass; |
| | | import com.example.springboot.entity.StorageCage; |
| | | import com.example.springboot.mapper.SpianMapper; |
| | | |
| | |
| | | public class SpianService { |
| | | @Autowired |
| | | private SpianMapper spianMapper; |
| | | public void Save(StorageCage spian){ |
| | | if(spian.getId()==null){ |
| | | spianMapper.update(); |
| | | }else{ |
| | | spianMapper.update(); |
| | | @GetMapping("/all2") |
| | | public Result selectout(String orderid){ |
| | | //定义PRC数据传送数组 |
| | | List<String> adddresslist=new ArrayList<>(); |
| | | adddresslist.add("DB105.6");//出片车起始位置 |
| | | adddresslist.add("DB105.8");//出片车目标位置 |
| | | adddresslist.add("DB105.10");//出片笼玻璃数 |
| | | adddresslist.add("DB105.14");//出片车启动 1为启动 |
| | | List<Short> datas=new ArrayList<>(); |
| | | //获取优先出片的位置 |
| | | StorageCage cageout=spianMapper.selectOut(orderid); |
| | | int cage =cageout.getCage(); //储存出片位置,笼子格子几号玻璃 |
| | | int cell =cageout.getCell();//出片格号 |
| | | int tier =cageout.getTier();//出片内外片 |
| | | int prcid=cageout.getPrcId();//prcid |
| | | int prcid2; |
| | | int ids; |
| | | double glasswidth=cageout.getGlassWidth(); |
| | | //判断玻璃内外片 |
| | | if(tier==2){ |
| | | //判断玻璃可直接出片时 |
| | | //修改数据库笼子表(出片) |
| | | spianMapper.UpdataGlassCage("","",glasswidth, cage, cell, tier, 0); |
| | | |
| | | datas.add((short)prcid); |
| | | datas.add((short)1000); |
| | | datas.add((short)1); |
| | | datas.add((short)1); |
| | | S7control.getinstance().WriteWord(adddresslist, datas); |
| | | return Result.success(datas); |
| | | } |
| | | else{ |
| | | //获取格子的玻璃数量 |
| | | int state= spianMapper.selectGlassState(cage,cell); |
| | | //判断内片是否需要调拨 |
| | | if(state==0){ |
| | | return Result.success("状态为0,直接出片"); |
| | | }else{ |
| | | //玻璃需要调拨时,判断属于哪个半区的笼子 |
| | | if(cage<6){ |
| | | StorageCage cagecell= spianMapper.selectGlassCage(cage,glasswidth,0,6); |
| | | if(cagecell==null){ |
| | | return Result.success(cagecell); |
| | | } |
| | | //获取调拨位置进行调拨 |
| | | prcid2=cagecell.getPrcId();//调拨目标位PRCID |
| | | ids=cagecell.getId();//调拨目标位ID |
| | | //更换玻璃的笼子 |
| | | spianMapper.UpdateDBCage(ids, cage, cell);//将原格子数据更新到新格子里 |
| | | spianMapper.UpdataGlassCage("", "", glasswidth, cage, cell, 2, 0);//清除原格子数据 |
| | | //填入调拨数据 |
| | | datas.add((short)prcid);//调拨外片起始位置 |
| | | datas.add((short)prcid2); |
| | | datas.add((short)2); |
| | | datas.add((short)1); |
| | | //传输mes数据,坐标,数据 |
| | | S7control.getinstance().WriteWord(adddresslist, datas); |
| | | datas.clear(); // 清空整个列表 |
| | | //判断调拨结束后再次出片,填入出片数据 |
| | | datas.add((short)prcid); |
| | | datas.add((short)1000); |
| | | datas.add((short)1); |
| | | datas.add((short)1); |
| | | S7control.getinstance().WriteWord(adddresslist, datas); |
| | | //修改数据库笼子表(出片) |
| | | |
| | | return Result.success(cagecell); //调拨位置的参数内容 |
| | | |
| | | }else{//笼子号大于5时 |
| | | StorageCage cagecell= spianMapper.selectGlassCage(cage,glasswidth,5,11); |
| | | if(cagecell==null){ |
| | | return Result.success(cagecell); |
| | | } |
| | | //获取调拨位置进行调拨 |
| | | prcid2=cagecell.getPrcId();//调拨目标位prcID |
| | | ids=cagecell.getId();//调拨目标位ID |
| | | //填入调拨数据 |
| | | datas.add((short)prcid); |
| | | datas.add((short)prcid2); |
| | | datas.add((short)2); |
| | | datas.add((short)1); |
| | | //转移原调拨格子数据 |
| | | spianMapper.UpdateDBCage(ids, cage, cell);//将原格子数据更新到新格子里 |
| | | spianMapper.UpdataGlassCage("", "", glasswidth, cage, cell, 2, 0);//清除原格子数据 |
| | | //传输mes数据,坐标,数据 |
| | | S7control.getinstance().WriteWord(adddresslist, datas); |
| | | datas.clear(); // 清空整个列表 |
| | | //判断调拨结束后再次出片 |
| | | //填入出片数据 |
| | | datas.add((short)prcid); |
| | | datas.add((short)1000); |
| | | datas.add((short)1); |
| | | datas.add((short)1); |
| | | S7control.getinstance().WriteWord(adddresslist, datas); |
| | | return Result.success(cagecell); //调拨位置的参数内容 |
| | | |
| | | } |
| | | |
| | | } |
| | | } |
| | | |
| | | } |
| | | |
| | | @GetMapping("/all") |
| | | //进片任务,传订单id |
| | | //按订单优先进片 |
| | | public Result selectAll(Short glassid){ |
| | | //return spianMapper.selectAll(); |
| | | int cage1; |
| | | int cells; |
| | | int ids; |
| | | int prcid; |
| | | int tiers; |
| | | int prctier; |
| | | |
| | | Glass glasslist=spianMapper.selectGlass(glassid); |
| | | double widths=glasslist.getWidth(); |
| | | Short orderids=glasslist.getOrderId(); |
| | | |
| | | List<String> adddresslist=new ArrayList<>(); |
| | | adddresslist.add("DB105.0");//进片车起始位置 |
| | | adddresslist.add("DB105.2");//进片车目标位置 |
| | | adddresslist.add("DB105.4");//进片笼玻璃数 |
| | | adddresslist.add("DB105.12");//进片车启动 1为启动 |
| | | List<Short> datas=new ArrayList<>(); |
| | | |
| | | //String orderid="A001"; |
| | | //获取订单相关度最高的笼子排序 |
| | | List<StorageCage> storageCage=spianMapper.selectAll(glassid); |
| | | if(storageCage==null){ |
| | | return Result.success(storageCage); |
| | | } |
| | | for (StorageCage storageCage2 : storageCage) { |
| | | //保存订单优先顺序笼子号 |
| | | cage1=storageCage2.getCage(); |
| | | //判断该笼子号相邻最大的空格数 |
| | | int cages=spianMapper.selectCage(cage1); |
| | | //判断选中笼子是否有合适宽度空格 |
| | | StorageCage cages1=spianMapper.selectCage1(cage1,widths); |
| | | ids=cages1.getId();//数据库ID |
| | | tiers=cages1.getTier();//内外片 |
| | | cells=cages1.getCell();//格子号 |
| | | prcid=cages1.getPrcId();//传给prc的目标地id |
| | | prctier=spianMapper.selectsum(cage1, cells);//传给prc的格子内玻璃数 |
| | | //有合适空格时进片 |
| | | if(cages>1 &&cages1.getTier()!=null){ |
| | | //执行进片 |
| | | datas.add((short)1000); |
| | | datas.add((short)prcid); |
| | | datas.add((short)prctier); |
| | | datas.add((short)1); |
| | | S7control.getinstance().WriteWord(adddresslist, datas); |
| | | //数据库修改笼子表新增一条玻璃 |
| | | |
| | | spianMapper.UpdataAddCage(orderids, glassid, widths, cage1, cells, ids, 1); |
| | | return Result.success(cages1); |
| | | } |
| | | |
| | | |
| | | } |
| | | return Result.success("不可进片"); |
| | | |
| | | } |
| | | |
| | | @GetMapping("/all2") |
| | | public Result selectout2(String glassid){ |
| | | //定义PRC数据传送数组 |
| | | List<String> adddresslist=new ArrayList<>(); |
| | | adddresslist.add("DB105.6");//出片车起始位置 |
| | | adddresslist.add("DB105.8");//出片车目标位置 |
| | | adddresslist.add("DB105.10");//出片笼玻璃数 |
| | | adddresslist.add("DB105.14");//出片车启动 1为启动 |
| | | List<Short> datas=new ArrayList<>(); |
| | | //获取优先出片的位置 |
| | | StorageCage cageout=spianMapper.selectOut2(glassid); |
| | | int cage =cageout.getCage(); //储存出片位置,笼子格子几号玻璃 |
| | | int cell =cageout.getCell();//出片格号 |
| | | int tier =cageout.getTier();//出片内外片 |
| | | int prcid=cageout.getPrcId();//prcid |
| | | int prcid2; |
| | | int ids; |
| | | double glasswidth=cageout.getGlassWidth(); |
| | | //判断玻璃内外片 |
| | | if(tier==2){ |
| | | //判断玻璃可直接出片时 |
| | | //修改数据库笼子表(出片) |
| | | spianMapper.UpdataGlassCage("","",glasswidth, cage, cell, tier, 0); |
| | | |
| | | datas.add((short)prcid); |
| | | datas.add((short)1000); |
| | | datas.add((short)1); |
| | | datas.add((short)1); |
| | | S7control.getinstance().WriteWord(adddresslist, datas); |
| | | return Result.success(datas); |
| | | } |
| | | else{ |
| | | //获取格子的玻璃数量 |
| | | int state= spianMapper.selectGlassState(cage,cell); |
| | | //判断内片是否需要调拨 |
| | | if(state==0){ |
| | | return Result.success("状态为0,直接出片"); |
| | | }else{ |
| | | //玻璃需要调拨时,判断属于哪个半区的笼子 |
| | | if(cage<6){ |
| | | StorageCage cagecell= spianMapper.selectGlassCage(cage,glasswidth,0,6); |
| | | if(cagecell==null){ |
| | | return Result.success(cagecell); |
| | | } |
| | | //获取调拨位置进行调拨 |
| | | prcid2=cagecell.getPrcId();//调拨目标位PRCID |
| | | ids=cagecell.getId();//调拨目标位ID |
| | | //更换玻璃的笼子 |
| | | spianMapper.UpdateDBCage(ids, cage, cell);//将原格子数据更新到新格子里 |
| | | spianMapper.UpdataGlassCage("", "", glasswidth, cage, cell, 2, 0);//清除原格子数据 |
| | | //填入调拨数据 |
| | | datas.add((short)prcid);//调拨外片起始位置 |
| | | datas.add((short)prcid2); |
| | | datas.add((short)2); |
| | | datas.add((short)1); |
| | | //传输mes数据,坐标,数据 |
| | | S7control.getinstance().WriteWord(adddresslist, datas); |
| | | datas.clear(); // 清空整个列表 |
| | | //判断调拨结束后再次出片,填入出片数据 |
| | | datas.add((short)prcid); |
| | | datas.add((short)1000); |
| | | datas.add((short)1); |
| | | datas.add((short)1); |
| | | S7control.getinstance().WriteWord(adddresslist, datas); |
| | | //修改数据库笼子表(出片) |
| | | |
| | | return Result.success(cagecell); //调拨位置的参数内容 |
| | | |
| | | }else{//笼子号大于5时 |
| | | StorageCage cagecell= spianMapper.selectGlassCage(cage,glasswidth,5,11); |
| | | if(cagecell==null){ |
| | | return Result.success(cagecell); |
| | | } |
| | | //获取调拨位置进行调拨 |
| | | prcid2=cagecell.getPrcId();//调拨目标位prcID |
| | | ids=cagecell.getId();//调拨目标位ID |
| | | //填入调拨数据 |
| | | datas.add((short)prcid); |
| | | datas.add((short)prcid2); |
| | | datas.add((short)2); |
| | | datas.add((short)1); |
| | | //转移原调拨格子数据 |
| | | spianMapper.UpdateDBCage(ids, cage, cell);//将原格子数据更新到新格子里 |
| | | spianMapper.UpdataGlassCage("", "", glasswidth, cage, cell, 2, 0);//清除原格子数据 |
| | | //传输mes数据,坐标,数据 |
| | | S7control.getinstance().WriteWord(adddresslist, datas); |
| | | datas.clear(); // 清空整个列表 |
| | | //判断调拨结束后再次出片 |
| | | //填入出片数据 |
| | | datas.add((short)prcid); |
| | | datas.add((short)1000); |
| | | datas.add((short)1); |
| | | datas.add((short)1); |
| | | S7control.getinstance().WriteWord(adddresslist, datas); |
| | | return Result.success(cagecell); //调拨位置的参数内容 |
| | | |
| | | } |
| | | |
| | | } |
| | | } |
| | | |
| | | } |
| | | |
| | | } |