ZengTao
2023-09-12 cdc594d12e46b7dd2e37c7a2071c133f8404f9be
测试代码,部分代码进行优化
8个文件已修改
1个文件已添加
768 ■■■■■ 已修改文件
CanadaMes-ui/src/api/home.js 4 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
CanadaMes-ui/src/views/home/index.vue 62 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
springboot-vue3/src/main/java/com/example/springboot/component/PlcHold.java 29 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
springboot-vue3/src/main/java/com/example/springboot/component/Plchome.java 39 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
springboot-vue3/src/main/java/com/example/springboot/controller/HomeController.java 16 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
springboot-vue3/src/main/java/com/example/springboot/mapper/HomeMapper.java 12 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
springboot-vue3/src/main/java/com/example/springboot/mapper/SpianMapper.java 6 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
springboot-vue3/src/main/java/com/example/springboot/service/JdbcConnections.java 70 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
springboot-vue3/src/main/java/com/example/springboot/service/SpianService.java 530 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
CanadaMes-ui/src/api/home.js
@@ -43,9 +43,9 @@
    })
}
export function UpdateTask(types,shelfrack) {
export function UpdateTask(types,glassid,shelfrack) {
    return request({
        url: '/home/UpdateTask?types=' + types + '&shelfrack='+shelfrack,
        url: '/home/UpdateTask?types=' + types + '&glassid='+glassid+'&shelfrack='+shelfrack,
        method: 'get',
        data :""
    })
CanadaMes-ui/src/views/home/index.vue
@@ -164,8 +164,11 @@
                    <el-table-column prop="lengthWidth" label="Length and width"></el-table-column>
                    <el-table-column prop="coating" label="coating"></el-table-column>
                    <el-table-column label="Operate">
                        <el-button type="primary" style="padding: 4px 10px;font-size: 12px;" @click="endtask(0)">end
                            task</el-button>
                        <template slot-scope='scope'>
                            <el-button type="primary" style="padding: 4px 10px;font-size: 12px;"
                                @click="endtask(0, scope.row.glassId, scope.row.cell)">end
                                task</el-button>
                        </template>
                    </el-table-column>
                </el-table>
                <el-table :data="this.tasklist2" border style="width: 100%">
@@ -175,8 +178,11 @@
                    <el-table-column prop="lengthWidth" label="Length and width"></el-table-column>
                    <el-table-column prop="coating" label="coating"></el-table-column>
                    <el-table-column label="Operate">
                        <el-button type="primary" style="padding: 4px 10px;font-size: 12px;" @click="endtask(1)">end
                            task</el-button>
                        <template slot-scope='scope'>
                            <el-button type="primary" style="padding: 4px 10px;font-size: 12px;"
                                @click="endtask(1, scope.row.glassId, scope.row.cell)">end
                                task</el-button>
                        </template>
                    </el-table-column>
                </el-table>
            </div>
@@ -262,7 +268,7 @@
                <el-table-column prop="endTime" label="endTime"></el-table-column>
            </el-table>
        </el-dialog>
        <el-dialog :visible.sync="dialogFormVisible3" title="Ordering Information">
        <el-dialog :visible.sync="dialogFormVisible3" title="Cage Details">
            <el-table :data="this.cageinfo" border style="width: 100%;height: 700px;overflow: auto;">
                <el-table-column :width="150" prop="cage" label="the grille number"></el-table-column>
                <el-table-column prop="cell" label="cell"></el-table-column>
@@ -276,7 +282,7 @@
                        <el-button type="primary" style="padding: 4px 10px;font-size: 12px;"
                            @click="deleteglass(scope.row.glassId, scope.row.state)">delete</el-button>
                        <el-button type="primary" style="padding: 4px 10px;font-size: 12px;"
                            @click="outglass(scope.row.glassId,scope.row.state)">out</el-button>
                            @click="outglass(scope.row.glassId, scope.row.state)">out</el-button>
                    </template>
                </el-table-column>
            </el-table>
@@ -324,8 +330,6 @@
            url: "../../img/bigcar01.png",
            car1: 150,
            car2: 242,
            incell: "",
            outcell: "",
            cageinfo: [],
            cage: 0
        };
@@ -362,7 +366,6 @@
                        this.car1 = 150 + 24.6 * obj.params[0][0];
                        this.car2 = 242 + 24.6 * obj.params[0][1];
                    }
                    this.tableData = obj.tableData[0];
                    this.cagelist1 = obj.cagelist1[0];
                    this.cagelist2 = obj.cagelist2[0];
@@ -370,12 +373,6 @@
                    this.cagelist4 = obj.cagelist4[0];
                    this.tasklist1 = obj.tasklist1[0];
                    this.tasklist2 = obj.tasklist2[0];
                    if (this.tasklist1.length > 0) {
                        this.incell = this.tasklist1[0]['cell'];
                    }
                    if (this.tasklist1.length > 0) {
                        this.outcell = this.tasklist2[0]['cell'];
                    }
                    this.alarm = obj.alarmmg[0];
                    SelectCageInfo(this.cage).then(res => {
@@ -461,8 +458,14 @@
                    if (res.data.message2 == 200) {
                        this.$message.success("Operation successful");
                        this.cancal();
                    } else {
                    } else if(res.data.message2 == 500) {
                        this.$message.success("There are currently tasks");
                    }
                    else if(res.data.message2 == 300) {
                        this.$message.success("There is no such grid");
                    }
                    else if(res.data.message2 == 400) {
                        this.$message.success("There is no such grid");
                    }
                });
            }
@@ -499,21 +502,12 @@
            this.dialogFormVisible1 = false;
            this.form1 = {};
        },
        endtask(type) {
            if (type == 0) {
                UpdateTask(type, this.incell).then(res => {
                    if (res.data.message3 == 200) {
                        this.$message.success("Operation successful");
                    }
                });
            } else {
                UpdateTask(type, this.outcell).then(res => {
                    if (res.data.message3 == 200) {
                        this.$message.success("Operation successful");
                    }
                });
            }
        endtask(type, glassid, cell) {
            UpdateTask(type, glassid, cell).then(res => {
                if (res.data.message3 == 200) {
                    this.$message.success("Operation successful");
                }
            });
        },
        showcageinfo(cage) {
            this.cage = cage;
@@ -524,7 +518,7 @@
        },
        deleteglass(glassid, state) {
            if (state == 1) {
                DeleteByGlassID(glassid).then(res=>{
                DeleteByGlassID(glassid).then(res => {
                    if (res.data.message3 == 200) {
                        this.$message.success("Operation successful");
                    }
@@ -533,9 +527,9 @@
                this.$message.success("No out allowed");
            }
        },
        outglass(glassid,state){
        outglass(glassid, state) {
            if (state == 1) {
                OutByGlassID(glassid).then(res=>{
                OutByGlassID(glassid).then(res => {
                    if (res.data.message3 == 200) {
                        this.$message.success("Operation successful");
                    }
springboot-vue3/src/main/java/com/example/springboot/component/PlcHold.java
@@ -1,15 +1,24 @@
package com.example.springboot.component;
import java.sql.SQLException;
import java.util.List;
import com.example.springboot.service.SpianService;
import com.example.springboot.mapper.AlarmMapper;
import org.springframework.beans.factory.annotation.Autowired;
import com.example.springboot.service.JdbcConnections;
import com.example.springboot.service.SpianService;
import com.example.springboot.entity.Glass;
import com.example.springboot.mapper.AlarmMapper;
public class PlcHold extends Thread {
  private AlarmMapper alarmMapper;
  @Autowired
  private JdbcConnections jdbcConnections;
  private SpianService spianService;
  @Override
  public void run() {
@@ -19,12 +28,20 @@
        Thread.sleep(500);
      } catch (InterruptedException e) {
        // TODO Auto-generated catch block
        //\\ TODO Auto-generated catch block
        e.printStackTrace();
      }
      spianService = WebSocketServer.applicationContext.getBean(SpianService.class);
      //spianService.selectout("112");
      jdbcConnections = WebSocketServer.applicationContext.getBean(JdbcConnections.class);
      try {
          Glass glass=jdbcConnections.selectGlass(112);
          //System.out.println(glass.getOrderId());
        } catch (SQLException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
        }
      //判断进片请求 
       List<Short> datas1List=S7control.getinstance().ReadWord("DB106.24", 1);
       List<Short> datas1ListState=S7control.getinstance().ReadWord("DB106.8", 1);
@@ -41,6 +58,7 @@
        List<Short> datas1ListID=S7control.getinstance().ReadWord("DB106.26", 13);
        //获取玻璃id    
        for(Short list1:datas1ListID){
            spianService.selectAll((short)list1);
        }
      }
@@ -60,4 +78,5 @@
    }
  }
}
springboot-vue3/src/main/java/com/example/springboot/component/Plchome.java
@@ -5,7 +5,6 @@
import java.util.ArrayList;
import java.util.List;
import com.example.springboot.entity.StorageCage;
import com.example.springboot.entity.alarmmg;
import com.example.springboot.mapper.HomeMapper;
@@ -18,19 +17,18 @@
    public void run() {
        while (this != null) {
            try {
                Thread.sleep(5000);
                Thread.sleep(10000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            JSONObject jsonObject = new JSONObject();
            //注入mapper
            // 注入mapper
            homeMapper = WebSocketServer.applicationContext.getBean(HomeMapper.class);
            // 笼子使用情况
            List<StorageCage> tableData = homeMapper.selectAll();
            jsonObject.append("tableData", tableData);
            //格理片笼格子状态
            // 格理片笼格子状态
            List<StorageCage> cagelist1 = homeMapper.selectRack1();
            List<StorageCage> cagelist2 = homeMapper.selectRack2();
            List<StorageCage> cagelist3 = homeMapper.selectRack3();
@@ -39,23 +37,30 @@
            jsonObject.append("cagelist2", cagelist2);
            jsonObject.append("cagelist3", cagelist3);
            jsonObject.append("cagelist4", cagelist4);
            //进出片任务
            List<StorageCage> tasklist1=homeMapper.selectinout(2);
            List<StorageCage> tasklist2=homeMapper.selectinout(3);
            // 进出片任务
            List<StorageCage> tasklist1 = homeMapper.selectinout(2);
            List<StorageCage> tasklist2 = homeMapper.selectinout(3);
            jsonObject.append("tasklist1", tasklist1);
            jsonObject.append("tasklist2", tasklist2);
            //查询报警信息
            List<alarmmg> alarmmg=homeMapper.SelectAlarmmgInfo();
            // 查询报警信息
            List<alarmmg> alarmmg = homeMapper.SelectAlarmmgInfo();
            jsonObject.append("alarmmg", alarmmg);
            //读去Plc进片车与出片车位置W
            // 读去Plc进片车与出片车位置W
            List<String> addressList = new ArrayList<String>();
            addressList.add("DB105.DBW0");
            addressList.add("DB105.DBW12");
            addressList.add("DB106.0");
            addressList.add("DB106.12");
            List<Short> paramlist = S7control.getinstance().ReadWord(addressList);
            //将集合转为数组
            // List<Short> paramlists = new ArrayList<Short>();
            // short para1 = 1;
            // short para2 = 2;
            // paramlists.add(para1);
            // paramlists.add(para2);
            // System.out.println(paramlists);
            if(paramlist!=null){
                Short[] paramlists = paramlist.toArray(new Short[0]);
                jsonObject.append("params", paramlists);
            // Short[] paramlists = paramlist.toArray(new Short[0]);
            jsonObject.append("params", paramlist);
            }
            // jsonObject.append("params", new short[] { 30, 40, });
            WebSocketServer sendwServer = WebSocketServer.sessionMap.get("Home");
springboot-vue3/src/main/java/com/example/springboot/controller/HomeController.java
@@ -78,21 +78,27 @@
        if (taskno > 0) {
            map.put("message2", "500");
        } else {
            map.put("message2", "200");
            // 调用伍上片函数
            spianService.selectAll(glassid);
            short results= spianService.selectAll(glassid);
            if(results==200){
                map.put("message2", "200");
            }else if(results==300){
                map.put("message2", "300");
            }else if(results==400){
                map.put("message2", "400");
            }
        }
        return Result.success(map);
    }
    @GetMapping("/UpdateTask")
    public Result UpdateTask(Integer types, Integer shelfrack) {
    public Result UpdateTask(Integer types, Integer shelfrack, Integer glassid) {
        Map<String, Object> map = new HashMap<>();
        homeMapper.UpdateTask(types, shelfrack);
        if (types == 0) {
            homeMapper.UpdateCageTask1(shelfrack);
            homeMapper.UpdateCageTask1(shelfrack,glassid);
        } else {
            homeMapper.UpdateCageTask2(shelfrack);
            homeMapper.UpdateCageTask2(shelfrack,glassid);
        }
        map.put("message3", "200");
        return Result.success(map);
springboot-vue3/src/main/java/com/example/springboot/mapper/HomeMapper.java
@@ -34,11 +34,11 @@
  List<StorageCage> selectinout(@Param("task_type") Integer task_type);
  // 查询是否存在此订单
  @Select("select count(*) from storage_cage where order_id=#{orderid} and state=0")
  @Select("select count(*) from storage_cage where order_id=#{orderid} and state=1")
  short SelectOrder(@Param("orderid") String orderid);
  // @Insert("insert into order_out(orderid) values('#{orderid}')")
  @Insert("INSERT INTO `canadames`.`order_out`( `orderid`,`mod_time`) VALUES ( #{orderid},now())")
  @Insert("INSERT INTO `canadames`.`order_out`( `order_id`,`state`) VALUES ( #{orderid},0)")
  void InsertOrder(String orderid);
  // 停止按当前订单出片
@@ -54,12 +54,12 @@
  void UpdateTask(@Param("task_type") Integer task_type, @Param("shelf_rack") Integer shelf_rack);
  // 手动完成进片任务修改笼子数据
  @Update("update storage_cage set state=1 where cell=#{cell} and state=2")
  void UpdateCageTask1(@Param("cell") Integer cell);
  @Update("update storage_cage set state=1 where cell=#{cell} and glass_id=#{glassid} and state=2")
  void UpdateCageTask1(@Param("cell") Integer cell,@Param("glassid") Integer glassid);
  // 手动完成出片任务修改笼子数据
  @Update("update storage_cage set state=0,glass_id=null,order_id=null,glasswidth=null,glassheight=null,coating=null where cell=#{cell} and state=2")
  void UpdateCageTask2(@Param("cell") Integer cell);
  @Update("update storage_cage set state=0,glass_id=null,order_id=null,glasswidth=null,glassheight=null,coating=null where cell=#{cell} and glass_id=#{glassid} and state=3")
  void UpdateCageTask2(@Param("cell") Integer cell,@Param("glassid") Integer glassid);
  //获取报警信息
  @Select("select id,content,timeon as timeons,endTime from alarmmg where endTime is null")
springboot-vue3/src/main/java/com/example/springboot/mapper/SpianMapper.java
@@ -18,8 +18,8 @@
     
     //@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;")
    //获取订单号排序的空订单笼子
     @Select("select cage,COUNT(if(order_id=#{glassid},order_id,null))as orderid from storage_cage where (order_id=#{glassid} or ''='') GROUP BY cage ORDER BY orderid desc; ")
     List<StorageCage> selectAll(Short glassid);
     @Select("select cage,COUNT(if(order_id=#{orderids},order_id,null))as orderid from storage_cage where (order_id=#{orderids} or ''='') GROUP BY cage ORDER BY orderid desc; ")
     List<StorageCage> selectAll(Short orderids);
     //判断该笼子是否有合适宽度空格
     @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")
@@ -42,7 +42,7 @@
    @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")
    @Select("select cage,cell,tier,glasswidth,ROUND(id/2)as prcId,id from storage_cage as a where a.glass_id=#{glassid} and state=1 order by cage desc,tier desc,cell desc LIMIT 1")
     StorageCage selectOut2(String  glassid);
    //判断出片为1时,是否可直接出片
springboot-vue3/src/main/java/com/example/springboot/service/JdbcConnections.java
New file
@@ -0,0 +1,70 @@
package com.example.springboot.service;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import org.springframework.stereotype.Component;
import com.example.springboot.entity.Glass;
@Component
public class JdbcConnections {
    /**
     * 数据库连接参数
     * driver,url,username,password
     */
    private static final String DRIVER = "com.mysql.jdbc.Driver";
    private static final String URL = "jdbc:mysql://localhost:3306/canadames";
    private static final String USERNAME = "root";
    private static final String PASSWORD = "beibo.123/";
    private static Connection conn = null;
    private static PreparedStatement ps = null;
    private static ResultSet rs = null;
    public  Glass selectGlass(int glassid) throws SQLException {
        conn = getConn();
        Glass glass=new Glass();
        String sql = "select orderid from glass where glassid=?";
         ps = conn.prepareStatement(sql);
         ps.setInt(1, glassid);
         rs= ps.executeQuery();
         while (rs.next()) {
            glass.setOrderId(rs.getShort("orderid"));
         }
         return glass;
    }
    /**
     * 1. 加载驱动
     * 2. 获取连接    conn
     * 3. 创建语句 ps
     * 4. 执行语句 rs
     * 5. 处理结果
     * 6. 回收资源
     *
     * 实现CRUD
     *     更新:
     *         1增加
     *         2删除
     *         3修改
     *  查询:
     *      1. 查一个,一个对象
     *      2. 查一组,做成一个对象列表,查全部
     */
    public static Connection getConn() throws SQLException {
        Connection conn = null;
        conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/canadames?serverTimezone=GMT%2B8&characterEncoding=utf-8", "root", "beibo.123/");
        return conn;
    }
    static {
        try {
            Class.forName(DRIVER);
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }
    }
}
springboot-vue3/src/main/java/com/example/springboot/service/SpianService.java
@@ -5,7 +5,6 @@
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;
@@ -17,114 +16,120 @@
public class SpianService {
    @Autowired
    private SpianMapper spianMapper;
    @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();
    // @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) {
                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("状态为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 Short selectAll(Short glassid) {
        int cage1;
        int cells;
        int ids;
@@ -132,156 +137,177 @@
        int tiers;
        int prctier;
        Glass glasslist=spianMapper.selectGlass(glassid);
        double widths=glasslist.getWidth();
        Short orderids=glasslist.getOrderId();
        Glass glasslist = spianMapper.selectGlass(glassid);
        if (glasslist == null) {
            return (300);
        }
        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<>();
        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);
                }
        // String orderid="A001";
        // 获取订单相关度最高的笼子排序
        List<StorageCage> storageCage = spianMapper.selectAll(orderids);
        if (storageCage == null) {
            return (400);
        }
        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);
            // 保存订单优先顺序笼子号
            cage1 = storageCage2.getCage();
            // 判断该笼子号相邻最大的空格数
            int cages = spianMapper.selectCage(cage1);
            // 判断选中笼子是否有合适宽度空格
            StorageCage cages1 = spianMapper.selectCage1(cage1, widths);
            if (cages1 != null) {
                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);
                    // 数据库修改笼子表新增一条玻璃
                    spianMapper.UpdataAddCage(orderids, glassid, widths, cage1, cells, ids, 1);
                    S7control.getinstance().WriteWord(adddresslist, datas);
                    return (200);
                }
            }
        }
        return Result.success("不可进片");
        }
        return (300);
    }
   @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);
    // @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); // 调拨位置的参数内容
                }
                //获取调拨位置进行调拨
                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);  //调拨位置的参数内容
               }
             }
            }
        }
}
    }
    /*** 修改用户* @throws SQLException */
    // public static int updateUser(Glass user) throws SQLException {conn =
    // getConn();
    // String sql = "update t_user set name=?,gender=?,age=?,score=?"+ " where
    // id=?";ps = conn.prepareStatement(sql);
    // ps.setString(1, user.getName());ps.setString(2, user.getGender());
    // ps.setInt(3, user.getAge());ps.setDouble(4, user.getScore());ps.setInt(5,
    // user.getId());return ps.executeUpdate();}
    // /*** 增加用户* @throws SQLException */
    // public static int insertUser(User user) throws SQLException {
    // conn = getConn();
    // String sql = "insert into t_user(name,gender,age,score)"+ " values(?,?,?,?)";
    // ps = conn.prepareStatement(sql);ps.setString(1,
    // user.getName());ps.setString(2, user.getGender());
    // ps.setInt(3, user.getAge());ps.setDouble(4, user.getScore());return
    // ps.executeUpdate();
    // }
}