ZengTao
2024-05-13 c85904597bf93e0fbae321093a970dd973b0f64f
springboot-vue3/src/main/java/com/example/springboot/mapper/SpianMapper.java
@@ -1,95 +1,241 @@
package com.example.springboot.mapper;
import org.apache.ibatis.annotations.*;
import com.example.springboot.entity.Glass;
import com.example.springboot.entity.StorageCage;
import com.example.springboot.entity.StorageTask;
import com.example.springboot.entity.north_glass_buffer1;
import java.util.List;
@Mapper
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(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;")
    //获取订单号排序的空订单笼子
     @Select("select cage,COUNT(if(order_id=#{orderids},order_id,null))as orderid,cell,min(state)as state1 from storage_cage where (order_id=#{orderids} or ''='') GROUP BY cage,cell HAVING state1=0 ORDER BY orderid desc; ")
     List<StorageCage> selectAll(Short orderids);
    // 判断相邻笼子是否有空格
    @Select("select COUNT(if(a.state1=0,cell,0))as cell 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 or a.cage=#{cage1})and if(a.cage<6,a.cage>0 and a.cage<6,a.cage>5) and disabled=0 GROUP BY cage ORDER BY cell desc LIMIT 1")
    StorageCage selectCage(int cage1);
    // 获取笼子号订单号排序的空订单笼子
    @Select("select a.cage,FrameBarcode,COUNT(if(a.order_id=#{orderids},a.order_id,null))as orderid,b.shu,c.shu2,a.cell,min(a.state)as state1,max(a.state)as state2,disabled,FrameBarcode from storage_cage a left join (select COUNT(*)shu,cage from storage_cage  where order_id=#{orderids} GROUP BY cage)as b on a.cage=b.cage left join(select cage ,COUNT(glass_id)as shu2 from storage_cage GROUP BY cage)c  on a.cage=c.cage where (order_id=#{orderids} or ''='') and a.disabled=0 GROUP BY cage,cell HAVING state1=0 ORDER BY shu desc,shu2,state2 asc,cage asc;")
    List<StorageCage> selectAll(String orderids,String Fbarcode);
    //优先判断一次是否有同铝框的空位
    @Select("select *,min(state) state1 from storage_cage where width>=(#{width}+#{width2})  GROUP BY cage,cell HAVING state1=0 and  FrameBarcode=#{Fbarcode} and disabled=0 ORDER BY width desc LIMIT 1;")
    List<StorageCage> selectAllFbarcode(String Fbarcode,double width,double width2);
    // 获取判断该格子是否需要把外片推入内片位置
    @Select("select state from storage_cage where  cage=#{cage} and cell=#{cell} and tier=1;")
    int selectcell(int cage, int cell);
     //判断该笼子是否有合适宽度空格
     @Select("select cage,cell,tier,id,ROUND(id/2)as prcId,width from storage_cage where cage=#{cage1} and cell=#{cell} and state=0 and width>=#{width} ORDER BY cell asc,tier desc LIMIT 1")
     StorageCage selectCage1(int  cage1,int cell,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);
    // 判断该笼子是否有合适宽度空格
    @Select("select cage,cell,tier,id,ROUND(id/2)as prcId,width from storage_cage where cage=#{cage1} and cell=#{cell} and state=0 and disabled=0 and width>=#{width} ORDER BY cell asc,tier asc LIMIT 1")
    StorageCage selectCage1(int cage1, int cell, double width);
    //@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 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.glass_id=#{glassid} and state=1 order by cage desc,tier desc,cell desc LIMIT 1")
     StorageCage selectOut2(String  glassid);
    // 判断笼子内玻璃数
    @Select("select COUNT(tier)as tier from storage_cage where  cage=#{cage} and cell=#{cell} and state!=0 and state!=3;")
    int selectsum(int cage, int cell);
    //判断出片为1时,是否可直接出片
    @Select("select state from storage_cage where cage=#{cage} and cell=#{cell} and tier=2;")
     int selectGlassState(int  cage,int cell);
    // 完成出片中的玻璃状态
    @Update("update storage_cage set state=#{state} where glass_id=#{glassid} and state=3;")
    void UpdateCageOver(String glassid, int state);
    // 完成进片中的玻璃状态
    @Update("update storage_cage set state=#{state} where glass_id=#{glassid} and state=2;")
    void UpdateCageadd(String glassid, int state);
    //查询是否有该类型的任务还未完成
     // 判断出片为1时,是否可直接出片
    @Select("select COUNT(state) from storage_cage where state=#{state}")
    int SelectCageState(int state);
    // 获取玻璃信息
    @Select("select *,ordernumber ,glasslength_mm as glasslengthmm,glassheight_mm as glassheightmm,barcode,listnumber,boxnumber,glasslength,glassheight,FrameBarcode from north_glass_buffer1 where barcode=#{glassid}")
    north_glass_buffer1 selectGlass(String glassid);
     //判断该调拨的笼子
     @Select("select glass_id,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);
    // 出片任务查询
    @Select("select COUNT(order_id)order_id,cage,cell,glasswidth,tier,ROUND(id/2)as prcId,glass_id from storage_cage a where a.order_id=#{orderId} and disabled=0 and state=1 GROUP BY cage,cell ORDER BY cage desc,order_id desc,cell desc,glasswidth desc limit 1")
    StorageCage selectOut(String orderId);
    //删除笼子信息(出片)
    @Update("update storage_cage as a set state=#{state},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);
    // @Select("select cage,cell,tier,glasswidth,ROUND(id/2)as prcId,id,glass_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,glassheight,ROUND(id/2)as prcId,id from storage_cage as a where a.glass_id=#{glassid} and state=1 and disabled=0 order by cage desc,tier desc,cell desc LIMIT 1")
    StorageCage selectOut2(String glassid);
    //修改笼子信息(进片)
    // 判断出片为1时,是否可直接出片
    @Select("select COUNT(state) from storage_cage where cage=#{cage} and cell=#{cell} and state!=0")
    int selectGlassState(int cage, int cell);
    // 判断该调拨的笼子
    @Select("select glass_id,cage,cell,max(state)as shu,ROUND(id/2)as prcid,id,abs(#{cell}-cell)as xuhao from storage_cage where width>=#{width} and cage>#{cage1} and cage<#{cage2} and  disabled=0 GROUP BY cage,cell HAVING shu=0 order by abs(#{cage} - cage),xuhao desc  limit 1;")
    StorageCage selectGlassCage(int cage, double width, int cage1, int cage2,int cell);
    // 删除笼子信息(出片)
    @Update("update storage_cage as a set state=#{state},glass_id=null,FrameBarcode=null,order_id=null,glasswidth=null,a.glassheight=null,a.glasswidthmm=null,a.glassheightmm=null,a.listid=null,a.boxid=null where glass_id=#{glassid} and state=3;")
    void UpdataGlassCage(String glassid, int state);
    // 改变玻璃状态为出片中
    @Update("update storage_cage as a set state=#{state} where glass_id=#{glassid};")
    void UpdataGlassCageState(String glassid, int state);
    // 修改笼子信息(进片)
    @Update("update storage_cage set state=#{state},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 set width=width-#{width} where   cage=#{cage} and cell=#{cell};")
    void UpdataAddCage1(double width,int cage,int cell);
    //修改同笼子格子宽度(出片)
     @Update("update storage_cage set width=width+#{width} where   cage=#{cage} and cell=#{cell};")
    void UpdataOutCage1(double width,int cage,int cell);
    //调拨更换笼子信息
    @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.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 UpdataAddCage(String orderid, String glassid, double width, int cage, int cell, int id, int state);
    @Update("update storage_cage set state=#{state},glass_id=#{glassid},order_id=#{glass.ordernumber},glasswidth=#{widths},glassheight=#{glass.glassheightmm},glasswidthmm=#{glass.glasslength},glassheightmm=#{glass.glassheight},listid=#{glass.listnumber},boxid=#{glass.boxnumber},FrameBarcode=#{glass.frameBarcode} where id=#{id};")
    void UpdataAddCage2(String orderid, String glassid, north_glass_buffer1 glass, int cage, int cell, int id,int state,Double widths);
    // 修改笼子信息(多片进片)
    @Update("update storage_cage set state=#{state},glass_id=#{glassid},order_id=#{orderid},glasswidth=#{width} where cage=#{cage} and cell=#{cell} and tier=#{tier};")
    void UpdataAddqueCage(String orderid, String glassid, double width, int cage, int cell, int tier, int state);
    // 修改同笼子格子宽度
    @Update("update storage_cage set width=width-#{width} where   cage=#{cage} and cell=#{cell};")
    void UpdataAddCage1(double width, int cage, int cell);
    // 修改同笼子格子宽度
    @Update("update storage_cage set state=#{state} where   state=#{oldstate};")
    void UpdataAddCageState(int state, int oldstate);
    // 修改同笼子格子宽度(出片)
    @Update("update storage_cage set width=width+#{width} where   cage=#{cage} and cell=#{cell};")
    void UpdataOutCage1(double width, int cage, int cell);
    // 调拨更换笼子信息
    @Update("update storage_cage as a,(select*from storage_cage b where b.cage=#{cage} and b.cell=#{cell} and b.tier=#{tier})as b set a.glass_id=b.glass_id,a.order_id=b.order_id,a.state=2,a.glasswidth=b.glasswidth,a.glassheight=b.glassheight,a.glasswidthmm=b.glasswidthmm,a.glassheightmm=b.glassheightmm,a.listid=b.listid,a.boxid=b.boxid,a.FrameBarcode=b.FrameBarcode where a.id=#{id1}")
    void UpdateDBCage(int id1, int cage, int cell, int tier);
     // 进片更换笼子信息
     @Update("update storage_cage as a,(select*from storage_cage b where b.cage=#{cage} and b.cell=#{cell} and b.tier=#{tier})as b set a.glass_id=b.glass_id,a.order_id=b.order_id,a.state=1,a.glasswidth=b.glasswidth,a.glassheight=b.glassheight,a.glasswidthmm=b.glasswidthmm,a.glassheightmm=b.glassheightmm,a.listid=b.listid,a.boxid=b.boxid,a.FrameBarcode=b.FrameBarcode where a.id=#{id1}")
     void UpdateDBCageAdd(int id1, int cage, int cell, int tier);
    // @Insert("insert into user(name, date, address, user_no) values (#{name},
    // #{date}, #{address}, #{userNo})")
    // void insert (Spian spian);
    //新增任务表
    @Insert("INSERT INTO `canadames`.`storage_task`(`task_type`, `task_state`, `shelf_rack`, `load_rack`,start_time,glass_id) VALUES (#{tasktype},#{taskstate},#{shelfrack},#{loadrack},now(),#{glassid});")
    void Inserttask(int tasktype,int taskstate,int shelfrack,int loadrack,String glassid);
    //修改任务表
    // 新增任务表
    @Insert("INSERT INTO `canadames`.`storage_task`(`task_type`, `task_state`, `shelf_rack`, `load_rack`,start_time,glass_id,count,finsh_time) VALUES (#{tasktype},#{taskstate},#{shelfrack},#{loadrack},now(),#{glassid},#{count},#{qidong});")
    void Inserttask(int tasktype, int taskstate, int shelfrack, int loadrack, String glassid, int count,int qidong);
    // 修改任务表
    @Update("update storage_task set task_state=#{state} where task_type=#{type} and task_state=0;")
    void Updatetask(int state,int type);
    //修改任务表
    @Update("update storage_task set task_state=1 where (task_type=1 or task_type=2) and task_state=0;")
    void UpdatetaskOut();
    //查询按订单出片
    void Updatetask(int state, int type);
    // 修改任务表
    @Update("update storage_task set task_state=1 where  task_state=0 and glass_id=#{glassid};")
    void UpdatetaskOut(String glassid);
    // 查询按订单出片
    @Select("select order_id state from order_out where state=0")
    String  SelectOrderout();
    //内外片调换
    @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.state=1,a.glasswidth=b.glasswidth where a.cage=#{cage} and a.cell=#{cell} and a.tier=1")
    void UpdateDBCage1(int cage,int cell);
    //清除内片数据
    @Update("update storage_cage set glass_id='',order_id='',state=0,glasswidth=0 where a.cage=#{cage} and a.cell=#{cell} and a.tier=1;")
    void UpdateDBCage2(int cage,int cell);
    //判断是否有调拨完后出片的任务
    @Select("select COUNT(*)as id,glass_id from storage_task where (task_type=1 or task_type=2) and task_state=0;")
    Glass SelectDBOut();
}
    String SelectOrderout();
    // 内外片调换
    @Update("update storage_cage as a,(select*from storage_cage b where b.cage=#{cage} and b.cell=#{cell} and b.tier=1)as b set a.glass_id=b.glass_id,a.order_id=b.order_id,a.state=1,a.glasswidth=b.glasswidth,a.glassheight=b.glassheight,a.glasswidthmm=b.glasswidthmm,a.glassheightmm=b.glassheightmm,a.listid=b.listid,a.boxid=b.boxid,a.FrameBarcode=b.FrameBarcode where a.cage=#{cage} and a.cell=#{cell} and a.tier=2")
    void UpdateDBCage1(int cage, int cell);
    // 清除内片数据
    @Update("update storage_cage a set glass_id=null,order_id=null,state=0,glasswidth=null,glassheight=null,glasswidthmm=null,glassheightmm=null,listid=null,boxid=null,FrameBarcode=null where a.cage=#{cage} and a.cell=#{cell} and a.tier=1;")
    void UpdateDBCage2(int cage, int cell);
    // 判断是否有调拨完后出片的任务
    @Select("select COUNT(*)as id,glass_id as barcode from storage_task where (task_type=1 or task_type=2) and task_state=0;")
    north_glass_buffer1 SelectDBOut();
    // 根据笼子格子层数获取玻璃id
    @Select("select glass_id,glasswidth from storage_cage where cage=#{cage} and cell=#{cell} and tier=2;")
    StorageCage SelectGlassid(int cage, int cell);
    // 判断有几块玻璃还在出片中
    @Select("SELECT COUNT(*) FROM `storage_cage` where state=3;")
    Integer Selectoutstate();
    // 判断队列表是否有该玻璃
    @Select("select COUNT(*) from queue where glassid=#{glassid} and state=1;")
    int Selectquecount(String glassid);
    // 更新进片队列
    @Update("update queue set glassid=#{glassid},orderid=#{orderid},listid=#{listid},boxid=#{boxid},state=#{state},glasswidthmm=#{glasswidthmm},glassheightmm=#{glassheightmm},glasswidth=#{glasswidth},glassheight=#{glassheight} where type=#{type};")
    void Updatequeue(String glassid, String orderid, String listid, String boxid, int state, String glasswidth,
            String glassheight, String glasswidthmm, String glassheightmm, int type);
    // 完成进片队列任务
    @Update("update queue set state=#{state} where glassid=#{glassid};")
    void overqueue(String glassid, int state);
    // 更换任务队列
    @Update("update queue set state=#{state} where glassid=#{glassid} and type=#{type};")
    void overqueue2(String glassid, int state, int type);
    // 获取任务序列
    @Select("select glassid,orderid,width,type from queue where state=#{state}")
    StorageCage SelectQueue(int state);
    // 获取序列表的玻璃宽
    @Select("select sum(width)+400 as width,orderid from queue where state=0 limit 1")
    StorageCage SelectQueueWidth();
    // 判断该笼子是否有合适完整空格
    @Select("select cage,cell,tier,id,ROUND(id/2)as prcId,width,max(state)state1 from storage_cage where cage=#{cage1} and cell=#{cell} and state=0 and width>=#{width} HAVING state1=0 ORDER BY cell asc,tier desc LIMIT 1")
    StorageCage selectqueCage1(int cage1, int cell, double width);
    // 获取序列表的玻璃
    @Select("select glassid as barcode,orderid as ordernumber,width as glasslengthmm from queue where state=0 and type=#{type}")
    north_glass_buffer1 SelectQueueGlass(int type);
    // 多片出库清除一整个空格
    @Update("update storage_cage set glass_id='',order_id='',glasswidth=0,width=2750,state=0 where cage=#{cage} and cell=#{cell}")
    void UpdatequeOut(int cage, int cell);
    // 判断序列表里的玻璃是否是同一订单
    @Select("select  COUNT(distinct orderid) from queue ")
    int SelectQueOrder();
    // 寻找可以多片出片的玻璃
    @Select("select cage,cell,ROUND(id/2)as prcId,width,count(glass_id)shu from storage_cage where order_id=#{orderid} and (cage!=#{cage} or cell!=#{cell}) GROUP BY cage,cell HAVING shu=1 ORDER BY cage desc,cell desc limit 1")
    StorageCage SelectQueout(String orderid, int cage, int cell);
    // 获取进片队列id
    @Select("select glassid from queue where type=1")
    String Selectqueueid();
    // 获取进片队列是否有待入库
    @Select("select state from queue where type=1")
    int Selectqueuestate();
    // 判断铝框出片表是否有玻璃需要出
    @Select("SELECT glassid FROM `out_slice` where state=0  order by sequence,id  limit 1;")
    String SelectOutSlice();
    // 判断铝框出片表是否有玻璃正在出片中
    @Select("SELECT count(*) FROM `out_slice` where state=1;")
    int SelectOutSliceshu();
    //判断是否有调拨任务未完成
    @Select("SELECT count(*) FROM `storage_cage` where state=#{state};")
    int Selectcageout(int state);
    // 更新出片队列的任务状态
    @Update("update out_slice set state=#{state} where glassid=#{glassid} and state=#{state2}")
    void OverOutSlice(String glassid, int state,int state2);
    // 获取玻璃的铝框id
    @Select("select barcode from out_slice where glassid=#{glassid};")
    String SelectBarcode(String glassId);
    // 获取出片队列的铝框是否全部完成
    @Select("select count(*) from out_slice where barcode=#{barcode} and (state=1 or state=0);")
    int SelectOverState(String barcode);
    // 删除出片队列该铝框的id
    @Delete("delete from out_slice where barcode=#{barcode};")
    void DeleteQueue(String barcode);
    // 把该进片的玻璃更新到出片队列
    @Select("update out_slice set state=0 where glassId=#{glassId} and state=3")
    void UpdateAddQueue(String glassId);
    //新增日志表格
    @Insert("INSERT INTO `canadames`.`log`( `text`,time) VALUES (#{logtxt},now());")
    void insertlog(String logtxt);
    //获取该半区是否有执行的任务
    @Select(" select count(*) from storage_cage where state=#{state} and cage>#{cage1} and cage<#{cage2}")
    int SelectCageTask(int state,int cage1,int cage2);
    //判断玻璃是否禁用
    @Select(" select disabled from storage_cage where glass_id=#{glassid} limit 1;")
    StorageCage SelectCageGlassState(String glassid);
    //判断汇报的id是否正确
    @Select("SELECT count(*) FROM `storage_cage` where state!=0 and glass_id=#{glassid}")
    int SelectHB(String glassid);
}