| | |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | | |
| | | import javax.websocket.Session; |
| | | |
| | | import com.example.springboot.controller.SpianController; |
| | | import com.example.springboot.service.SpianService; |
| | | import com.example.springboot.mapper.AlarmMapper; |
| | | import com.example.springboot.mapper.HomeMapper; |
| | | |
| | | import cn.hutool.json.JSONArray; |
| | | import cn.hutool.json.JSONObject; |
| | | |
| | | public class PlcHold extends Thread { |
| | | |
| | |
| | | // TODO Auto-generated catch block |
| | | e.printStackTrace(); |
| | | } |
| | | List<Boolean> bitlist = S7control.getinstance().ReadBits("DB2.0.0", 100); |
| | | List<Short> paramlist = S7control.getinstance().ReadWord("DB100.6", 1); |
| | | |
| | | |
| | | spianService = WebSocketServer.applicationContext.getBean(SpianService.class); |
| | | //spianService.selectout("112"); |
| | | |
| | | //判断进片请求 |
| | | // List<Short> datas1List=S7control.getinstance().ReadWord("DB106.24", 1); |
| | | // List<Short> datas1ListState=S7control.getinstance().ReadWord("DB106.8", 1); |
| | | SpianController spianController=new SpianController(); |
| | | List<Short> datas1List1=new ArrayList<>(); |
| | | List<Short> datas1List2=new ArrayList<>(); |
| | | datas1List1.add((short)1); |
| | | datas1List2.add((short)0); |
| | | //获取prc进片请求数据 |
| | | boolean exist = datas1List1.contains((short)1); |
| | | boolean exist1 = datas1List2.contains((short)0); |
| | | List<Short> datas1List=S7control.getinstance().ReadWord("DB106.24", 1); |
| | | List<Short> datas1ListState=S7control.getinstance().ReadWord("DB106.8", 1); |
| | | if(datas1List!=null &&datas1ListState!=null){ |
| | | //获取prc进片请求数据 |
| | | boolean exist = datas1List.contains((short)1); |
| | | //获取进片车状态 |
| | | boolean exist1 = datas1ListState.contains((short)0); |
| | | //进片请求为1时 |
| | | if(exist=true){ |
| | | if(exist=true){ |
| | | //当进片车空闲时 |
| | | if(exist=true){ |
| | | //List<Short> datas1ListID=S7control.getinstance().ReadWord("DB106.26", 13); |
| | | List<Short> datas1ListID=new ArrayList<>(); |
| | | datas1ListID.add((short)001); |
| | | spianService = WebSocketServer.applicationContext.getBean(SpianService.class); |
| | | //获取玻璃id |
| | | if(exist1=true){ |
| | | //获取进片id |
| | | List<Short> datas1ListID=S7control.getinstance().ReadWord("DB106.26", 13); |
| | | //获取玻璃id |
| | | for(Short list1:datas1ListID){ |
| | | spianService.selectAll(list1); |
| | | spianService.selectAll((short)list1); |
| | | } |
| | | } |
| | | |
| | | |
| | | |
| | | |
| | | //System.out.println(exist); |
| | | } |
| | | } |
| | | //获取进片id |
| | | // List<Short> datas1ListID=S7control.getinstance().ReadWord("DB106.26", 13); |
| | | |
| | | |
| | | |
| | | |
| | | // 查询数据库 |
| | |
| | | @GetMapping("/all2") |
| | | public void selectdd(String orderid){ |
| | | SpianService service=new SpianService(); |
| | | service.selectadd(orderid); |
| | | service.selectout(orderid); |
| | | |
| | | } |
| | | |
| | |
| | | |
| | | public class StorageCage { |
| | | private Integer id; |
| | | private Integer prcId; |
| | | private String glassId; |
| | | private Integer cage; |
| | | private Integer cell; |
| | |
| | | public Integer getId() { |
| | | return id; |
| | | } |
| | | public Integer getPrcId() { |
| | | return prcId; |
| | | } |
| | | |
| | | public void setPrcId(Integer prcId) { |
| | | this.prcId = prcId; |
| | | } |
| | | |
| | | |
| | | public String getGlassId() { |
| | | return glassId; |
| | |
| | | import org.apache.ibatis.annotations.*; |
| | | |
| | | import com.example.springboot.common.Result; |
| | | import com.example.springboot.entity.Glass; |
| | | import com.example.springboot.entity.StorageCage; |
| | | import com.example.springboot.entity.StorageTask; |
| | | import com.example.springboot.entity.StorageCage; |
| | |
| | | |
| | | public interface SpianMapper { |
| | | //判断相邻笼子是否有空格 |
| | | @Select("select COUNT(if(a.state1=0,cell,null))as cell,ROUND(id/2)as id from (select *,max(state)as state1 from storage_cage a GROUP BY cage,cell)as a where (a.cage=#{cage1}-1 or a.cage=#{cage1}+1)and if(#{cage1}<6,a.cage>0 and a.cage<6,a.cage>5) GROUP BY cage ORDER BY cell desc LIMIT 1") |
| | | @Select("select COUNT(if(a.state1=0,cell,null))as cell,ROUND(id/2)as id from (select *,max(state)as state1 from storage_cage a GROUP BY cage,cell)as a where (a.cage=#{cage1}-1 or a.cage=#{cage1}+1)and if(a.cage<6,a.cage>0 and a.cage<6,a.cage>5) GROUP BY cage ORDER BY cell desc LIMIT 1") |
| | | int selectCage(int cage1); |
| | | |
| | | //@Select("(select*from storage_cage as a where a.state=0 and cage%2=0 ORDER BY id LIMIT 1)union (select a.* from storage_cage a inner join (select cage,if(shu2=1,shu3,shu5) as gezi from ( select cage, count(case when state1=1 and state2=0 then cell else null end)as shu1, count(case when state1=0 then cell else null end) as shu2, min(case when state1=1 and state2=0 then cell else null end) as shu3, min(case when state1=0 then cell else null end) as shu4, min(case when state1=0 or state2=0 then cell else null end) as shu5 from (select *,max(state) as state1,min(state) as state2 from storage_cage group by cage,cell) as a where cage%2!=0 GROUP BY cage HAVING shu2>1 or (shu2=1 and shu1>0) ) as sss limit 1)as b on a.cage=b.cage and a.cell=b.gezi and a.state=0 order by tier limit 1) ORDER BY id LIMIT 1;") |
| | |
| | | List<StorageCage> selectAll(Short glassid); |
| | | |
| | | //判断该笼子是否有合适宽度空格 |
| | | @Select("select COUNT(*),cage,cell,IF(tier=1,0,1)as tier,ROUND(id/2)as id from storage_cage where cage=#{cage1} and state=0 and width>=#{width} ORDER BY cell,tier") |
| | | @Select("select cage,cell,tier,id,ROUND(id/2)as prcId from storage_cage where cage=#{cage1} and state=0 and width>=#{width} ORDER BY cell,tier LIMIT 1") |
| | | StorageCage selectCage1(int cage1,double width); |
| | | //判断笼子内玻璃数 |
| | | @Select("select COUNT(tier)as tier from storage_cage where cage=#{cage} and cell=#{cell} and state=1;") |
| | | int selectsum(int cage,int cell); |
| | | |
| | | //@Update("update longzi set glass_id = #{glass_id}, width = #{width}, state = #{state} where cell = #{cell}") |
| | | @Update("update longzi set glass_id =123, width =1600, state =1 where cell =24") |
| | | void update(); |
| | | //获取玻璃信息 |
| | | @Select("select orderid,width from glass where glassid=#{glassid}") |
| | | Glass selectGlass(Short glassid); |
| | | |
| | | @Insert("insert into storage_task(task_type,task_state,shelf_rack,load_rack)values(#{storage_task},#{task_state},#{shelf_rack},#{load_rack})") |
| | | void insert(StorageTask storageTask); |
| | | |
| | | //出片任务查询 |
| | | @Select("select cage,cell,tier,glasswidth,ROUND(id/2)as id from storage_cage as a where a.order_id=#{orderId} and state=1 order by cage desc,tier desc,cell desc LIMIT 1") |
| | | @Select("select cage,cell,tier,glasswidth,ROUND(id/2)as prcId,id from storage_cage as a where a.order_id=#{orderId} and state=1 order by cage desc,tier desc,cell desc LIMIT 1") |
| | | StorageCage selectOut(String orderId); |
| | | //按玻璃ID出片任务查询 |
| | | @Select("select cage,cell,tier,glasswidth,ROUND(id/2)as prcid,id from storage_cage as a where a.order_id=#{orderId} and state=1 order by cage desc,tier desc,cell desc LIMIT 1") |
| | | StorageCage selectOut2(String glassid); |
| | | |
| | | //判断出片为1时,是否可直接出片 |
| | | @Select("select state from storage_cage where cage=#{cage} and cell=#{cell} and tier=2;") |
| | | int selectGlassState(int cage,int cell); |
| | | |
| | | //判断该调拨的笼子 |
| | | @Select("select cage,cell,max(state)as shu,ROUND(id/2)as id from storage_cage where width>=#{width} and cage>#{cage1} and cage<#{cage2} GROUP BY cage,cell HAVING shu=0 order by abs(#{cage} - cage) limit 1;") |
| | | @Select("select cage,cell,max(state)as shu,ROUND(id/2)as prcid,id from storage_cage where width>=#{width} and cage>#{cage1} and cage<#{cage2} GROUP BY cage,cell HAVING shu=0 order by abs(#{cage} - cage) limit 1;") |
| | | StorageCage selectGlassCage(int cage,double width,int cage1,int cage2); |
| | | |
| | | //修改笼子信息(出片) |
| | | //删除笼子信息(出片) |
| | | @Update("update storage_cage set state=#{state},width=width+#{width},glass_id=#{glassid},order_id=#{orderid},glasswidth=0 where cage=#{cage} and cell=#{cell} and tier=#{tier};") |
| | | void UpdataGlassCage(String orderid,String glassid,double width,int cage,int cell,int tier,int state); |
| | | |
| | | //修改笼子信息(进片) |
| | | @Update("update storage_cage set state=#{state},width=width-#{width},glass_id=#{glassid},order_id=#{orderid},glasswidth=#{width} where cage=#{cage} and cell=#{cell} and tier=#{tier};") |
| | | void UpdataAddCage(String orderid,Short glassid,double width,int cage,int cell,int tier,int state); |
| | | @Update("update storage_cage set state=#{state},width=width-#{width},glass_id=#{glassid},order_id=#{orderid},glasswidth=#{width} where id=#{id};") |
| | | void UpdataAddCage(Short orderid,Short glassid,double width,int cage,int cell,int id,int state); |
| | | //调拨更换笼子信息 |
| | | @Update("update storage_cage as a,(select*from storage_cage b where b.cage=#{cage} and b.cell=#{cell} and b.tier=2)as b set a.glass_id=b.glass_id,a.order_id=b.order_id,a.glasswidth=b.glasswidth,a.width=a.width-b.glasswidth,a.state=1 where a.id=#{id1}") |
| | | void UpdateDBCage(int id1,int cage,int cell); |
| | | // @Insert("insert into user(name, date, address, user_no) values (#{name}, #{date}, #{address}, #{userNo})") |
| | | // void insert (Spian spian); |
| | | |
| | |
| | | |
| | | 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; |
| | | |
| | |
| | | @Autowired |
| | | private SpianMapper spianMapper; |
| | | @GetMapping("/all2") |
| | | public Result selectadd(String orderid){ |
| | | public Result selectout(String orderid){ |
| | | //定义PRC数据传送数组 |
| | | List<String> adddresslist=new ArrayList<>(); |
| | | adddresslist.add("DB105.6");//出片车起始位置 |
| | |
| | | //获取优先出片的位置 |
| | | StorageCage cageout=spianMapper.selectOut(orderid); |
| | | int cage =cageout.getCage(); //储存出片位置,笼子格子几号玻璃 |
| | | int cell =cageout.getCell(); |
| | | int tier =cageout.getTier(); |
| | | int id=cageout.getId(); |
| | | int cell =cageout.getCell();//出片格号 |
| | | int tier =cageout.getTier();//出片内外片 |
| | | int prcid=cageout.getPrcId();//prcid |
| | | int prcid2; |
| | | int ids; |
| | | double glasswidth=cageout.getGlassWidth(); |
| | | //判断玻璃内外片 |
| | |
| | | //判断玻璃可直接出片时 |
| | | //修改数据库笼子表(出片) |
| | | spianMapper.UpdataGlassCage("","",glasswidth, cage, cell, tier, 0); |
| | | datas.add((short)id); |
| | | |
| | | datas.add((short)prcid); |
| | | datas.add((short)1000); |
| | | datas.add((short)1); |
| | | datas.add((short)1); |
| | |
| | | //玻璃需要调拨时,判断属于哪个半区的笼子 |
| | | 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)id); |
| | | datas.add((short)ids); |
| | | 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)id); |
| | | datas.add((short)prcid); |
| | | datas.add((short)1000); |
| | | datas.add((short)1); |
| | | datas.add((short)1); |
| | | S7control.getinstance().WriteWord(adddresslist, datas); |
| | | //修改数据库笼子表(出片) |
| | | spianMapper.UpdataGlassCage("","",glasswidth, cage, cell, tier, 0); |
| | | |
| | | return Result.success(cagecell); //调拨位置的参数内容 |
| | | |
| | | }else{ |
| | | }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)id); |
| | | datas.add((short)ids); |
| | | 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)id); |
| | | datas.add((short)prcid); |
| | | datas.add((short)1000); |
| | | datas.add((short)1); |
| | | datas.add((short)1); |
| | |
| | | public Result selectAll(Short glassid){ |
| | | //return spianMapper.selectAll(); |
| | | int cage1; |
| | | int cells; |
| | | int ids; |
| | | int tier; |
| | | double widths=1500; |
| | | 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(); |
| | | tier=cages1.getTier(); |
| | | 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)ids); |
| | | datas.add((short)tier); |
| | | datas.add((short)prcid); |
| | | datas.add((short)prctier); |
| | | datas.add((short)1); |
| | | S7control.getinstance().WriteWord(adddresslist, datas); |
| | | //数据库修改笼子表新增一条玻璃 |
| | | spianMapper.UpdataAddCage("glassid", glassid, widths, cages, ids, tier, 1);//还未获取玻璃id |
| | | |
| | | 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); //调拨位置的参数内容 |
| | | |
| | | } |
| | | |
| | | } |
| | | } |
| | | |
| | | } |
| | | |
| | | } |