Java若依前后端分离_产线信息化项目工作日志_DAY3

1.后端代码底层业务逻辑实现

1.1定义线程方法完成基本变量的声明和定义
public class NettyTcpClient extends Thread{
    private static final int MAX_RETRY = 5;
    private static final int READ_TIMEOUT_SECONDS = 180;
    private static int[] array;
    private static String re_code;
    private static String flag_4;
    private static final org.slf4j.Logger log = LoggerFactory.getLogger(NettyTcpClient.class);
    private final String host;
1.2实现客户端与服务端之间的连接
 public void run(){

            String host = "192.168.0.12";
        //String host = "192.168.0.2";
        int port = 2000;
        array= new int[10];
        re_code="";
        flag_4="";
        //  NioEventLoopGroup 是Netty中处理事件循环的线程池,用于处理IO操作
        NioEventLoopGroup group = new NioEventLoopGroup();
        int retry = 0;
        while (true) {
            try {
                //用于配置客户端的启动参数,包括线程组、通道类型和处理器等
                Bootstrap bootstrap = new Bootstrap();
                //指定一个 EventLoopGroup,这个 group 被用来处理客户端的事件循环
                bootstrap.group(group)
               // 指定使用 NIO 方式的 SocketChannel 类型,表示这是一个基于 NIO 的客户端
                        .channel(NioSocketChannel.class)
                        //设置一个 ChannelInitializer,用于初始化新的 Channel。在 initChannel(SocketChannel ch) 方法中
                        .handler(new ChannelInitializer<SocketChannel>() {
                            @Override
                            //用于配置新连接的Channel,添加了 IdleStateHandler 和 ClientHandler 到pipeline中
                            public void initChannel(SocketChannel ch) {
                                //向 Channel 的 pipeline 中添加了一个 IdleStateHandler。
                                // 这个处理器用于处理连接空闲状态的事件,设置了读超时时间为 READ_TIMEOUT_SECONDS 秒
                                ch.pipeline().addLast(new IdleStateHandler(0, 0, READ_TIMEOUT_SECONDS, TimeUnit.SECONDS));
                                //向 Channel 的 pipeline 中添加了一个自定义的 ClientHandler。这个处理器用来处理客户端的业务逻辑
                                ch.pipeline().addLast(new ClientHandler());
                            }
                        });
                 //是 Netty 中对异步 I/O 操作的结果进行建模的对象
                //通过 ChannelFuture 可以获取连接操作的状态、结果或者注册监听器来处理连接成功或失败后的逻辑
                ChannelFuture future = bootstrap.connect(host, port).sync();
                System.out.println("客户端连接到" + host + ":" + port);

                String message = "Hello, server!";
                ByteBuf buffer = future.channel().alloc().buffer(message.length());
                //  buffer.writeBytes(message.getBytes());

                //  future.channel().writeAndFlush(buffer);
                System.out.println("Message sent to server: " + message);

                future.channel().closeFuture().sync();
            } catch (Exception e) {
                System.err.println("Failed to connect to " + host + ":" + port);
                retry++;
                try {
                    // Wait for 10 seconds before reconnecting
                    TimeUnit.SECONDS.sleep(10);
                } catch (InterruptedException interruptedException) {
                    Thread.currentThread().interrupt();
                }
            }
        }

        // NettyTcpClient.main(new String[0]);
    }
1.3定义与处理后端数据库业务逻辑的工具类
private static class ClientHandler extends ChannelInboundHandlerAdapter {


        PlfSignalMappingMapper plfSignalMappingMapper=SpringUtils.getBean(PlfSignalMappingMapper.class);

        PlfProcessingLocationMapper plfProcessingLocationMapper=SpringUtils.getBean(PlfProcessingLocationMapper.class);
        PlfMacProcedureMapper plfMacProcedureMapper=SpringUtils.getBean(PlfMacProcedureMapper.class);

        PlfTraceTimeMapper plfTraceTimeMapper=SpringUtils.getBean(PlfTraceTimeMapper.class);
        PlfWorkEquipmentMapper plfWorkEquipmentMapper =SpringUtils.getBean(PlfWorkEquipmentMapper .class);
        PlfPointMapper plfPointMapper=SpringUtils.getBean(PlfPointMapper .class);

        PlfErrorScanMapper plfErrorScanMapper=SpringUtils.getBean(PlfErrorScanMapper .class);
        PlfYieldMapper yieldMapper=SpringUtils.getBean(PlfYieldMapper .class);
        @Override
1.4根据实际072号线各机床的脉冲信号进行操作
public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {




            ByteBuf buf5 = (ByteBuf) msg;
            String message=buf5.toString(CharsetUtil.UTF_8);
            Long procedureid=1L;




            int ran=0;
            String code="";
            Long take=-1L;
            Long Machineid=-1L;
            int flag=-1;
            Boolean new_code=false;

            Long claw=-1L;//爪子


                System.out.println("===============================");
                System.out.println(message);
                String[] parts = message.split("\\s+");


                code=parts[0];

                flag = Integer.parseInt(parts[1]);

                Machineid=Long.parseLong(parts[2]);
                take=Long.parseLong(parts[3]);

                procedureid=Long.parseLong(parts[4]);

                claw=Long.parseLong(parts[5]);

            PlfPoint plfPoint_duty=new PlfPoint();
            plfPoint_duty.setDepamentId(procedureid);
            PlfPoint plfPoint1_duty =plfPointMapper.selectPlfPointList(plfPoint_duty).get(0);
            String duty_people=plfPoint1_duty.getPeopleName();
            String duty_depament=plfPoint1_duty.getDepamentName();

                System.out.println("p:"+procedureid+" M:"+Machineid+" t:"+take+" code: "+code+" flag:"+flag+"claw:"+claw);
                log.info("p:"+procedureid+" M:"+Machineid+" t:"+take+" code: "+code+" flag:"+flag);

                if(code.equals(""))
                {
                    System.out.println("null!");
                    return ;
                }



            if((!code.equals(re_code))&&take==0L&&flag == 0)
            {
                if (code .equals("9")) {

                    ran=1;
                    code=generateRandomString(18);
                }
                re_code=code;
                new_code=true;
                {
                    //创建了一个 PlfProcessingLocation 对象 plfProcessingLocation2
                    // 并设置了其时间、标志位、曲轴ID、机器位置和工序ID等属性
                    PlfProcessingLocation plfProcessingLocation2 = new PlfProcessingLocation();
                    plfProcessingLocation2.setTime(new Date());
                    plfProcessingLocation2.setFlag(0L);
                    plfProcessingLocation2.setCrankshaftId(re_code);
                    plfProcessingLocation2.setMachinePosition(0L);
                    plfProcessingLocation2.setProcedureId(procedureid);

                    plfProcessingLocation2.setPeopleId(claw);//扫码上线的时候设置爪子id
                    if(ran==1)
                    {

                        plfProcessingLocation2.setFlag(1L);
                    }
                    //通过 plfProcessingLocationMapper 将 plfProcessingLocation2 对象插入到数据库中
                    plfProcessingLocationMapper.insertPlfProcessingLocation(plfProcessingLocation2);
                }
                //进入上下线系统


                if(ran!=1){
                    //创建了一个 PlfErrorScan 对象 plfErrorScan
                    PlfErrorScan plfErrorScan = new PlfErrorScan();
                    //将 procedureid 设置为 plfErrorScan 的 peopleId
                    plfErrorScan.setPeopleId(procedureid);
                    //将 code 设置为 plfErrorScan 的 crankshaftIdBefore
                    plfErrorScan.setCrankshaftIdBefore(code);
                    //使用 DateUtils.getNowDate() 方法获取当前时间,并将其设置为 plfErrorScan 的 beginTime
                    plfErrorScan.setBeginTime(DateUtils.getNowDate());
                    plfErrorScan.setPeopleName(duty_people);
                    plfErrorScan.setDepamentName(duty_depament);
                    //最后,通过 plfErrorScanMapper 将 plfErrorScan 对象插入到数据库中
                    plfErrorScanMapper.insertPlfErrorScan(plfErrorScan);
                }


                //扫码进入trace数据库

                PlfPoint plfPoint2 = new PlfPoint();
                plfPoint2.setPositionId(Machineid);
                plfPoint2.setDepamentId(procedureid);
                //通过plfPoint2对象查询数据库中符合条件的PlfPoint对象列表,并将结果存储在plfPoints2列表中。
                // 具体实现取决于plfPointMapper中的selectPlfPointList方法的实现,该方法会根据传入的plfPoint2对象的属性值,
                // 查询数据库并返回符合条件的PlfPoint对象列表
                List<PlfPoint> plfPoints2 = plfPointMapper.selectPlfPointList(plfPoint2);

                PlfPoint plfPoint3=new PlfPoint();
                if (plfPoints2.size() == 0) {
//                    System.out.println("!213@");
//                    return;
                    System.out.println("上线扫码11112");
                    //设置 plfPoint3 的 positionId 为 0
                    plfPoint3.setPositionId(0L);
                    //将 duty_depament 设置为 plfPoint3 的 depamentName
                    plfPoint3.setDepamentName(duty_depament);

                }else{
                    plfPoint3 = plfPoints2.get(0);

                }



            //创建一个 PlfTraceTime 对象 plfTraceTime1,
            // 并从另一个对象 plfPoint3 中获取一系列属性值,然后设置一些固定的属性值
                PlfTraceTime plfTraceTime1 = new PlfTraceTime();
                plfTraceTime1.setBeginTime(DateUtils.getNowDate());
                plfTraceTime1.setDeviceId(Machineid);
                plfTraceTime1.setCrankshaftId(re_code);
                plfTraceTime1.setFlagWork(0);
                plfTraceTime1.setFlagInspect(1);//为扫码枪1
                plfTraceTime1.setFlagQuafilied(1);

                plfTraceTime1.setProcessName(plfPoint3.getWorkName());
                plfTraceTime1.setProcessNumber(plfPoint3.getWorkNumber());
                plfTraceTime1.setDeviceName(plfPoint3.getDeviceName());
                plfTraceTime1.setDeviceNumber(plfPoint3.getDeviceNumber());
                plfTraceTime1.setDepamentName(plfPoint3.getDepamentName());
                plfTraceTime1.setDepamentNumber(plfPoint3.getDepamentNumber());
                plfTraceTime1.setPeopleName(plfPoint3.getPeopleName());
                plfTraceTime1.setProductId(procedureid);
                //如果 ran 的值为 1,会将 plfTraceTime1 的 flagInspect 属性设为 2,
                // 并输出对象信息到控制台。
                // 无论条件成立与否,最后都会将 plfTraceTime1 对象插入到数据库中
                if(ran==1)
                {
                    System.out.println("suiji1");
                    plfTraceTime1.setFlagInspect(2);
                }
                System.out.println(plfTraceTime1);
                plfTraceTimeMapper.insertPlfTraceTime(plfTraceTime1);

            }
            if(flag==4)//下线扫码
            {

                flag_4=code;
                System.out.println("flag_4:"+flag_4);
            }
            if(flag==5)
            {
                System.out.println("1下线扫码完成"+"flag_4:"+flag_4+"code:"+code);
                Date date_now= DateUtils.getNowDate();
                PlfTraceTime plfTraceTime=new PlfTraceTime();
                plfTraceTime.setCrankshaftId(flag_4);
                plfTraceTime.setDeviceId(Machineid);  //和上线公用一个trace
                plfTraceTime.setProductId(procedureid);//一条产线有多段,区别段
                //使用 plfTraceTimeMapper 查询符合条件的 PlfTraceTime 记录列表
                List<PlfTraceTime> plfTraceTimeList= plfTraceTimeMapper.selectPlfTraceTimeList(plfTraceTime);
                System.out.println("2下线扫码完成"+"plfTraceTimeList:"+plfTraceTimeList.size());
                System.out.println("7下线扫码完成"+"plfTraceTime:"+plfTraceTime);
                if(plfTraceTimeList.size()>0){
                    System.out.println("3下线扫码完成"+"plfTraceTimeList:"+plfTraceTimeList.size());
                    PlfTraceTime plfTraceTime0 = plfTraceTimeList.get(0);
                    plfTraceTime0.setEndTime(date_now);
                    plfTraceTime0.setFlagWork(1);
                    plfTraceTimeMapper.updatePlfTraceTime(plfTraceTime0);  //用来记录trace下线扫码时间


                    System.out.println("!5!");
                    if(flag_4.equals(null))
                    {
                        System.out.println("f4");
                        return ;
                    }
                    if (!flag_4.equals(code)) {
                        PlfErrorScan plfErrorScan_select = new PlfErrorScan();
                        plfErrorScan_select.setPeopleId(procedureid);
                        //上线零件编号
                        plfErrorScan_select.setCrankshaftIdBefore(flag_4);
                        //写入数据库
                        //plfErrorScanMapper 是一个用于执行数据库操作的 Mapper 接口或实例
                        //selectPlfErrorScanList 是该 Mapper 接口中定义的方法,
                        // 用于根据给定的查询条件 plfErrorScan_select 查询数据库中的 PlfErrorScan 记录
                        List<PlfErrorScan> plfErrorScanList= plfErrorScanMapper.selectPlfErrorScanList(plfErrorScan_select);
                        if(plfErrorScanList.size()<=0)
                        {
                            return ;
                        }
                        //初始化一个布尔类型的变量 myBooleanVariable,并将其转换为字符串后发送到 WebSocket。
                        // 这里假设 Websocket.sendMessage 方法用于发送消息,
                        // 通常是将布尔值以某种形式传递给前端或其他系统
                        boolean myBooleanVariable = true;
                        Websocket.sendMessage(Boolean.toString(myBooleanVariable));
                        PlfErrorScan scan=plfErrorScanList.get(0);
                        scan.setCrankshaftIdAfter(code);
                        scan.setEndTime(date_now);

                        plfErrorScanMapper.updatePlfErrorScan(scan);
                    }else
                    {
                        System.out.println("下线扫码完成"+"flag_4:"+flag_4);
                        PlfErrorScan plfErrorScan_select = new PlfErrorScan();
                        plfErrorScan_select.setCrankshaftIdBefore(flag_4);
                        plfErrorScan_select.setPeopleId(procedureid);
                        List<PlfErrorScan> plfErrorScanList= plfErrorScanMapper.selectPlfErrorScanList(plfErrorScan_select);
                        if(plfErrorScanList.size()<=0)
                        {
                            return ;
                        }
                        PlfErrorScan scan=plfErrorScanList.get(0);
                        scan.setCrankshaftIdAfter(code);
                        scan.setEndTime(date_now);



                        plfErrorScanMapper.updatePlfErrorScan(scan);
                    }
                }
            }
             //分段
                    if(take==1L){
                        System.out.println("1!@#$");

                        Long position=0L;
                        if (flag == 1) {
                            position=0L;
                        }else
                        {
                            position=100L;
                        }

                        PlfProcessingLocation plfProcessingLocation = new PlfProcessingLocation();
                        // plfProcessingLocation.setProcedureId(procedureid);
                        plfProcessingLocation.setMachinePosition(position);
                        plfProcessingLocation.setProcedureId(procedureid);
                        plfProcessingLocation.setPeopleId(claw);
                        List<PlfProcessingLocation> plfProcessingLocationList = plfProcessingLocationMapper.selectPlfProcessingLocationList(plfProcessingLocation);  //找到手抓或者上线扫码的零件


                        //把头和中间已经加工完的设置100
                        PlfProcessingLocation plfProcessingLocation1 = new PlfProcessingLocation();
                        // plfProcessingLocation.setProcedureId(procedureid);
                        plfProcessingLocation1.setMachinePosition(-Machineid);
                        plfProcessingLocation1.setProcedureId(procedureid);
                        plfProcessingLocation1.setPeopleId(claw);
                        List<PlfProcessingLocation> plfProcessingLocationList1 = plfProcessingLocationMapper.selectPlfProcessingLocationList(plfProcessingLocation1);
                        //首先判断 plfProcessingLocationList1 的大小是否大于0,即是否有加工完成的工件需要处理。
                        //如果条件成立,打印 "!@#$" 到控制台。
                        //从 plfProcessingLocationList1 中获取第一个加工完成的工件对象 plfProcessingLocation2
                        if(plfProcessingLocationList1.size()>0) {
                            System.out.println("!@#$");
                            PlfProcessingLocation plfProcessingLocation2 = plfProcessingLocationList1.get(0);//当前的加工完的工件
                            //如果 flag 的值等于 3:
                            //如果 claw 大于 1,将 plfProcessingLocation2 的 machinePosition 设置为 0L,并将 peopleId 设置为 claw - 1。
                            //否则,打印 "shezhi -100" 到控制台,并将 plfProcessingLocation2 的 machinePosition 设置为 -100L。
                            //如果 flag 的值不等于 3,将 plfProcessingLocation2 的 machinePosition 设置为 100L
                            if (flag == 3) {
                                if(claw>1)//当前产线的当前手抓的已经走完塞到claw-1
                                {
                                    plfProcessingLocation2.setMachinePosition(0L);
                                    plfProcessingLocation2.setPeopleId(claw-1);
                                }else{
                                    System.out.println("shezhi -100");
                                    plfProcessingLocation2.setMachinePosition(-100L);
                                }

                            }else
                            {
                                plfProcessingLocation2.setMachinePosition(100L);
                            }

                            plfProcessingLocationMapper.updatePlfProcessingLocation(plfProcessingLocation2);//把加工完的工件,设置为100抓取状态
                        }//把头和中间已经加工完的设置100
                        System.out.println("2!@#$");
                        //把上一个放入当前机器
                        //首先判断 plfProcessingLocationList 的大小是否大于0,即是否有待加工的工件。
                        //如果条件成立,打印 "3!@#$" 到控制台。
                        //从 plfProcessingLocationList 中获取第一个待加工的工件对象 plfProcessingLocation0。
                        //将 plfProcessingLocation0 的 machinePosition 属性设置为 Machineid,表示将工件放入指定的机床。
                        //调用 plfProcessingLocationMapper 的 updatePlfProcessingLocation 方法,更新工件的信息(包括机床位置)到数据库
                        if (plfProcessingLocationList.size() > 0) {
                            System.out.println("3!@#$");
                            PlfProcessingLocation plfProcessingLocation0 = plfProcessingLocationList.get(0);//当前的工件
                            plfProcessingLocation0.setMachinePosition(Machineid);//当前工件放入机床
                            plfProcessingLocationMapper.updatePlfProcessingLocation(plfProcessingLocation0);

                            PlfPoint plfPoint = new PlfPoint();  //寻找点位数据
                            plfPoint.setPositionId(Machineid);
                            plfPoint.setDepamentId(procedureid);
                            List<PlfPoint> plfPoints = plfPointMapper.selectPlfPointList(plfPoint);
                            System.out.println("plfPoints:"+plfPoints.size()+"m:"+Machineid);
                            //处理点位数据
                            //如果 plfPoints 的大小为0,则打印调试信息并直接返回,不进行后续操作。
                            //否则,获取 plfPoints 中的第一个点位数据对象 plfPoint1,继续处理后续逻辑
                            if (plfPoints.size() == 0) {
                                System.out.println("plfPoints:"+plfPoints.size());
                                return;
                            }
                            //插入追踪时间记录
                            // 获取第一个工件的曲轴ID crankid。
                            //创建 PlfTraceTime 对象 plfTraceTime,设置该对象的各个属性,包括设备ID、开始时间、曲轴ID等。
                            //根据工件的标志 flag 设置 plfTraceTime 的检查标志 flagInspect。
                            //输出 plfTraceTime 对象的信息到控制台。
                            //调用 plfTraceTimeMapper 的 insertPlfTraceTime 方法,将 plfTraceTime 对象插入数据库,记录加工追踪时间信息
                            PlfPoint plfPoint1 = plfPoints.get(0);


                            String crankid = plfProcessingLocationList.get(0).getCrankshaftId();
                            PlfTraceTime plfTraceTime = new PlfTraceTime();

                            plfTraceTime.setDeviceId(Machineid);
                            plfTraceTime.setBeginTime(DateUtils.getNowDate());
                            plfTraceTime.setCrankshaftId(crankid);
                            plfTraceTime.setFlagWork(0);
                            plfTraceTime.setFlagInspect(0);
                            plfTraceTime.setFlagQuafilied(1);

                            plfTraceTime.setProcessName(plfPoint1.getWorkName());
                            plfTraceTime.setProcessNumber(plfPoint1.getWorkNumber());
                            plfTraceTime.setDeviceName(plfPoint1.getDeviceName());
                            plfTraceTime.setDeviceNumber(plfPoint1.getDeviceNumber());
                            plfTraceTime.setDepamentName(plfPoint1.getDepamentName());
                            plfTraceTime.setDepamentNumber(plfPoint1.getDepamentNumber());
                            plfTraceTime.setPeopleName(plfPoint1.getPeopleName());

                            plfTraceTime.setProductId(procedureid);//一条产线有多段,区别段

                            if(plfProcessingLocationList.get(0).getFlag()==1)//代表这是一个随机工件
                            {
                                System.out.println("suiji2");
                                plfTraceTime.setFlagInspect(2);//为2的时候是一个随机工件
                            }
                            System.out.println(plfTraceTime);
                            plfTraceTimeMapper.insertPlfTraceTime(plfTraceTime);



//                            if (flag == 1) {
//                                PlfProcessingLocation plfProcessingLocation2 = new PlfProcessingLocation();
//                                plfProcessingLocation2.setTime(new Date());
//                                plfProcessingLocation2.setCrankshaftId(generateRandomString(11));
//                                plfProcessingLocation2.setMachinePosition(0L);
//                                plfProcessingLocation2.setProcedureId(1L);
//
//                                plfProcessingLocationMapper.insertPlfProcessingLocation(plfProcessingLocation2);
//                            }
                        }
                    }
                    else if(take==2L)
                    {
//                        Long position =-1L;
//                        if(flag==2||flag==1)//如果是中间的
//                        {
//                            position =-1L;
//                        }else //如果是最后一个
//                        {
//                            position =-2L;
//                        }
                        PlfProcessingLocation plfProcessingLocation=new PlfProcessingLocation();
                        plfProcessingLocation.setMachinePosition(Machineid);
                        plfProcessingLocation.setPeopleId(claw);
                        List<PlfProcessingLocation> plfProcessingLocationList= plfProcessingLocationMapper.selectPlfProcessingLocationList(plfProcessingLocation);
                        if (plfProcessingLocationList.size()==0)
                        {
                            System.out.println("264");
                            return;
                        }


                        String CrankshaftId=plfProcessingLocationList.get(0).getCrankshaftId();

                        PlfProcessingLocation plfProcessingLocation0 = plfProcessingLocationList.get(0);
                        plfProcessingLocation0.setMachinePosition(-Machineid);
                        plfProcessingLocation0.setPeopleId(claw);
                        plfProcessingLocationMapper.updatePlfProcessingLocation(plfProcessingLocation0);

                        PlfTraceTime plfTraceTime=new PlfTraceTime();
                        plfTraceTime.setCrankshaftId(CrankshaftId);
                        plfTraceTime.setDeviceId(Machineid);
                        plfTraceTime.setProductId(procedureid);//一条产线有多段,区别段
                        List<PlfTraceTime> plfTraceTimeList= plfTraceTimeMapper.selectPlfTraceTimeList(plfTraceTime);
                        if(plfTraceTimeList.size()>0){
                            PlfTraceTime plfTraceTime0 = plfTraceTimeList.get(0);
                            plfTraceTime0.setEndTime(DateUtils.getNowDate());
                            plfTraceTime0.setFlagWork(1);
                            plfTraceTimeMapper.updatePlfTraceTime(plfTraceTime0);
                            if(plfTraceTime0.getProcessName().equals(null))
                            {
                                System.out.println("2线没有扫码枪不添加产量");
                                return ;
                            }
                            //产量代码
                            PlfYield plfYield=new PlfYield();
                            plfYield.setDepamentName(plfTraceTime0.getDepamentName());
                            plfYield.setDeviceNumber(plfTraceTime0.getDeviceNumber());
                            plfYield.setWorkNumber(plfTraceTime0.getProcessNumber());
                            plfYield.setPeopleName(plfTraceTime0.getPeopleName());
                            plfYield.setWorkDt(getTodayDateWithoutTime());
                            List<PlfYield> plfYields= yieldMapper.selectPlfYieldList(plfYield);
                            if(plfYields.size()>0)
                            {
                                PlfYield  plfYield1= plfYields.get(0);
                                Long n=plfYield1.getNumber();
                                plfYield1.setNumber(n+1);
                                yieldMapper.updatePlfYield(plfYield1);
                            }else
                            {
                                PlfYield  plfYield1=new PlfYield();
                                plfYield.setDepamentName(plfTraceTime0.getDepamentName());
                                plfYield.setDeviceNumber(plfTraceTime0.getDeviceNumber());
                                plfYield.setWorkNumber(plfTraceTime0.getProcessNumber());
                                plfYield.setPeopleName(plfTraceTime0.getPeopleName());
                                plfYield.setDeptCode(plfTraceTime0.getDepamentNumber());
                                plfYield.setDeviceName(plfTraceTime0.getDeviceName());
                                plfYield.setWorkName(plfTraceTime0.getProcessName());
                                plfYield.setNumber(0L);

                                yieldMapper.insertPlfYield(plfYield);
                            }

                        }else
                        {
                            System.out.println(CrankshaftId+"在机床"+Machineid+"只有完成没有开始");
                        }
                    }

//            Long procedureid=1L;
//            ByteBuf buf1 = (ByteBuf) msg;
//            int i=0;
//            Long Machineid=0L;
//            Long Machineid_t=0L;
//            Long take=0L;
//
//            int length = buf1.readableBytes();
//
//            System.out.println("length:"+length);
//            ByteBuf buf2 = (ByteBuf) msg;
//            int flag=0;
//            System.out.println("array"+array);
//            for(int l=0;l<array.length;l++)
//            {
//                System.out.println(array[l]);
//            }
//            while (buf1.isReadable()) {
//
//                int a=buf2.readByte();
//                System.out.println("当前的数据:"+a + " ");
//                i++;
//                Machineid_t++;
//
//
//                if(a!=0&&array[i-1]!=a)
//                {
//                    array[i-1]=a;
//                    Machineid=Machineid_t;
//                    String numberStr = String.valueOf(a);
//                    System.out.println(i+":::::::::::::::::::"+numberStr);
//                    flag=Character.getNumericValue(numberStr.charAt(0));
//                    take=new Long(Character.getNumericValue(numberStr.charAt(1))) ;
//
//
//                    if(take==1L){
//                        Long position=0L;
//                        if (flag == 1) {
//                            position=0L;
//                        }else
//                        {
//                            position=100L;
//                        }
//
//                        PlfProcessingLocation plfProcessingLocation = new PlfProcessingLocation();
//                        // plfProcessingLocation.setProcedureId(procedureid);
//                        plfProcessingLocation.setMachinePosition(position);
//                        plfProcessingLocation.setProcedureId(procedureid);
//                        List<PlfProcessingLocation> plfProcessingLocationList = plfProcessingLocationMapper.selectPlfProcessingLocationList(plfProcessingLocation);
//
//
//                        //把头和中间的设置100
//                        PlfProcessingLocation plfProcessingLocation1 = new PlfProcessingLocation();
//                        // plfProcessingLocation.setProcedureId(procedureid);
//                        plfProcessingLocation1.setMachinePosition(-Machineid);
//                        plfProcessingLocation1.setProcedureId(procedureid);
//                        List<PlfProcessingLocation> plfProcessingLocationList1 = plfProcessingLocationMapper.selectPlfProcessingLocationList(plfProcessingLocation1);
//                        if(plfProcessingLocationList1.size()>0) {
//                            PlfProcessingLocation plfProcessingLocation2 = plfProcessingLocationList1.get(0);
//                            if (flag == 3) {
//                                plfProcessingLocation2.setMachinePosition(-100L);
//                            }else
//                            {
//                                plfProcessingLocation2.setMachinePosition(100L);
//                            }
//
//                            plfProcessingLocationMapper.updatePlfProcessingLocation(plfProcessingLocation2);
//                        }
//
//                        //把上一个放入当前机器
//                        if (plfProcessingLocationList.size() > 0) {
//                            PlfProcessingLocation plfProcessingLocation0 = plfProcessingLocationList.get(0);
//                            plfProcessingLocation0.setMachinePosition(Machineid);
//                            plfProcessingLocationMapper.updatePlfProcessingLocation(plfProcessingLocation0);
//
//                            PlfPoint plfPoint = new PlfPoint();
//                            plfPoint.setPositionId(Machineid);
//                            plfPoint.setDepamentId(procedureid);
//                            List<PlfPoint> plfPoints = plfPointMapper.selectPlfPointList(plfPoint);
//                            if (plfPoints.size() == 0)
//                                continue;
//                            PlfPoint plfPoint1 = plfPoints.get(0);
//
//
//                            String crankid = plfProcessingLocationList.get(0).getCrankshaftId();
//                            PlfTraceTime plfTraceTime = new PlfTraceTime();
//                            plfTraceTime.setBeginTime(DateUtils.getNowDate());
//                            plfTraceTime.setDeviceId(Machineid);
//                            plfTraceTime.setCrankshaftId(crankid);
//                            plfTraceTime.setFlagWork(0);
//                            plfTraceTime.setFlagInspect(0);
//                            plfTraceTime.setFlagQuafilied(1);
//
//                            plfTraceTime.setProcessName(plfPoint1.getWorkName());
//                            plfTraceTime.setProcessNumber(plfPoint1.getWorkNumber());
//                            plfTraceTime.setDeviceName(plfPoint1.getDeviceName());
//                            plfTraceTime.setDeviceNumber(plfPoint1.getDeviceNumber());
//                            plfTraceTime.setDepamentName(plfPoint1.getDepamentName());
//                            plfTraceTime.setDepamentNumber(plfPoint1.getDepamentNumber());
//                            plfTraceTime.setPeopleName(plfPoint1.getPeopleName());
//                            System.out.println(plfTraceTime);
//                            plfTraceTimeMapper.insertPlfTraceTime(plfTraceTime);
//
//
//                            if (flag == 1) {
//                                PlfProcessingLocation plfProcessingLocation2 = new PlfProcessingLocation();
//                                plfProcessingLocation2.setTime(new Date());
//                                plfProcessingLocation2.setCrankshaftId(generateRandomString(11));
//                                plfProcessingLocation2.setMachinePosition(0L);
//                                plfProcessingLocation2.setProcedureId(1L);
//
//                                plfProcessingLocationMapper.insertPlfProcessingLocation(plfProcessingLocation2);
//                            }
//                        }
//                    }
//                    else if(take==2L)
//                    {
                        Long position =-1L;
                        if(flag==2||flag==1)//如果是中间的
                        {
                            position =-1L;
                        }else //如果是最后一个
                        {
                            position =-2L;
                        }
//                        PlfProcessingLocation plfProcessingLocation=new PlfProcessingLocation();
//                        plfProcessingLocation.setMachinePosition(Machineid);
//                        List<PlfProcessingLocation> plfProcessingLocationList= plfProcessingLocationMapper.selectPlfProcessingLocationList(plfProcessingLocation);
//                        if (plfProcessingLocationList.size()==0)
//                            continue;
//
//
//                        String CrankshaftId=plfProcessingLocationList.get(0).getCrankshaftId();
//
//                        PlfProcessingLocation plfProcessingLocation0 = plfProcessingLocationList.get(0);
//                        plfProcessingLocation0.setMachinePosition(-Machineid);
//                        plfProcessingLocationMapper.updatePlfProcessingLocation(plfProcessingLocation0);
//
//                        PlfTraceTime plfTraceTime=new PlfTraceTime();
//                        plfTraceTime.setCrankshaftId(CrankshaftId);
//                        plfTraceTime.setDeviceId(Machineid);
//                        List<PlfTraceTime> plfTraceTimeList= plfTraceTimeMapper.selectPlfTraceTimeList(plfTraceTime);
//                        PlfTraceTime plfTraceTime0= plfTraceTimeList.get(0);
//                        plfTraceTime0.setEndTime(DateUtils.getNowDate());
//                        plfTraceTime0.setFlagWork(1);
//                        plfTraceTimeMapper.updatePlfTraceTime(plfTraceTime0);
//                    }
//                    // break;
//                }
//                System.out.println("!Ma:"+Machineid);
//                System.out.println("!f:"+flag);
//                System.out.println("!t:"+take);
//
//            }


        }


        //0代表开始 1代表中间 2代表结束
//            Long Machineid=Long.valueOf(fruits[1]);
//            Long take=Long.valueOf(fruits[2]);






//            if(jedis.llen(listName_port)>0){
//                String pop=jedis.lpop(listName_port);
//
//            }else{
//                jedis.lpush(listName_netty,netty_flag);
//            }
//            System.out.println("从服务器接收到消息: " + message);

        public static String generateRandomString(int length) {
            String digits = "0123456789";
            Random random = new Random();
            StringBuilder sb = new StringBuilder(length);

            for (int i = 0; i < length; i++) {
                int randomIndex = random.nextInt(digits.length());
                char randomChar = digits.charAt(randomIndex);
                sb.append(randomChar);
            }

            return sb.toString();
        }
        @Override
        public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception {
            if (evt instanceof IdleStateEvent) {
                IdleStateEvent event = (IdleStateEvent) evt;
                if (event.state() == IdleStateEvent.READER_IDLE_STATE_EVENT.state()) {
                    System.err.println("未收到的数据 " + READ_TIMEOUT_SECONDS + " 秒,关闭频道。");
                    ctx.close();
                }
            }
        }

        public static Date getTodayDateWithoutTime() {
            Calendar cal = Calendar.getInstance();
            cal.set(Calendar.HOUR_OF_DAY, 0);
            cal.set(Calendar.MINUTE, 0);
            cal.set(Calendar.SECOND, 0);
            cal.set(Calendar.MILLISECOND, 0);

            return cal.getTime(); // 返回当天日期的开始时间,时分秒毫秒都为0
        }


        //报警
        @Override
        public void channelInactive(ChannelHandlerContext ctx) throws Exception {
            System.err.println("Connection lost, retrying to connect...");
            ctx.channel().eventLoop().schedule(new Runnable() {
                @Override
                public void run() {
                    NettyTcpClient.main(new String[0]);
                }
            }, 10, TimeUnit.SECONDS);
            super.channelInactive(ctx);
        }

        @Override
        public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) {
            cause.printStackTrace();
            ctx.close();
        }
    }
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值