严智鑫
2025-04-03 f2a5a09c879849110b42c46297ab4c080500e61d
JiuMuMesParent/moduleService/DeviceInteractionModule/src/test/java/com/mes/DeviceInteractionModuleApplicationTest.java
@@ -1,19 +1,35 @@
package com.mes;
import com.mes.job.CacheGlassTask;
import com.mes.md.entity.Account;
import com.mes.md.mapper.AccountMapper;
import com.mes.md.service.AccountService;
import cn.hutool.core.bean.BeanUtil;
import cn.smallbun.screw.core.util.CollectionUtils;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.github.yulichang.wrapper.MPJLambdaWrapper;
import com.mes.md.entity.*;
import com.mes.md.mapper.*;
import com.mes.md.service.*;
import com.mes.tools.HexConversion;
import com.mes.utils.HexUtil;
import lombok.extern.slf4j.Slf4j;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.Socket;
import java.nio.charset.StandardCharsets;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.util.*;
import java.util.stream.Collectors;
/**
 * @Author : yanzhixin
@@ -31,6 +47,188 @@
    @Autowired
    AccountService accountService;
    @Autowired
    KBBTJPDrawingBPMapper kBBTJPDrawingBPMapper;
    @Autowired
    PrimitiveTaskMapper primitiveTaskMapper;
    @Autowired
    PrimitiveTaskService primitiveTaskService;
    @Autowired
    TaskingService taskingService;
    @Autowired
    ProjectService projectService;
    @Autowired
    MachineMapper machineMapper;
    @Autowired
    TaskingMapper taskingMapper;
    @Autowired
    KBBTLensSortingMapper kBBTLensSortingMapper;
    @Autowired
    KBBTProgramsOperationLogBPMapper kBBTProgramsOperationLogBPMapper;
    @Autowired
    KBBTProgramsOperationLogBPService kBBTProgramsOperationLogBPService;
    @Autowired
    TaskingLogMapper taskingLogMapper;
    @Autowired
    TaskingLogService taskingLogService;
    /**
     * 测试 提交报工  以及玻璃数据
     */
    @Test
    public void reportTaskingLog() {
        taskingLogService.reportTaskingLog();
    }
    /**
     * 测试 扫码后库位
     */
    @Test
    public void testInset() {
        // 从数据库中查询出的对象集合
        List<Tasking> listTasking = taskingMapper.selectList(new QueryWrapper<Tasking>());
        List<KBBTProgramsOperationLogBP> abc =kBBTProgramsOperationLogBPMapper.selectList(new QueryWrapper<KBBTProgramsOperationLogBP>());
        // 判端是否为空
        if (CollectionUtils.isNotEmpty(listTasking)) {
            // 进行拆解封装
            List<KBBTProgramsOperationLogBP> stationDictVOS = listTasking.stream().map(item -> {
                KBBTProgramsOperationLogBP newData = new KBBTProgramsOperationLogBP();
                newData.setGlassId(item.getGlassId());
                newData.setState(item.getState());
                newData.setWorkState(item.getWorkState());
                newData.setGlassState(item.getGlassState());
                newData.setState(item.getState());
                newData.setScanId(item.getScanId());
                newData.setProgramId(item.getProgramId());
                newData.setBatchNumber(item.getBatchNumber()==null?"":item.getBatchNumber());
                newData.setTaskType(item.getTaskType());
                newData.setLength(item.getLength());
                newData.setWidth(item.getWidth());
                newData.setThickness(item.getThickness());
                newData.setDrawingMarking(item.getDrawingMarking());
                //newData.setIsMarking(item.getIsMarking());//是否打标:0不打标   1打标
                newData.setIsSilkScreen(item.getIsSilkScreen());
                newData.setIsWorking(1);
                newData.setSilkScreenX(item.getSilkScreenX());
                newData.setSilkScreenY(item.getSilkScreenY());
                newData.setR_1_1(item.getR_1_1());
                newData.setR_1_2(item.getR_1_2());
                newData.setR_2_1(item.getR_2_1());
                newData.setR_2_2(item.getR_2_2());
                newData.setR_3_1(item.getR_3_1());
                newData.setR_3_2(item.getR_3_2());
                newData.setR_4_1(item.getR_4_1());
                newData.setR_4_2(item.getR_4_2());
                newData.setCreateDate(new Date());
                kBBTProgramsOperationLogBPMapper.insert(newData);
                return newData;
            }).collect(Collectors.toList());
            log.info("保存数据是否成功:{},{}",stationDictVOS);
        }
    }
    /**
     * 测试 扫码后库位
     */
    @Test
    public void testStr() {
        //创建Calendar实例
        Calendar cal = Calendar.getInstance();
        //设置当前时间
        cal.setTime(new Date());
        cal.add(Calendar.DATE, -3);
        int deleteCount=taskingMapper.deleteJoin(new MPJLambdaWrapper<Tasking>()
                .selectAll(Tasking.class)
                .le(Tasking::getOperationRecordTime,cal.getTime()));
        log.info("{},删除数据:{}",cal.getTime(),deleteCount);
    }
    @Test
    public void testSaoMa3() {
        int deleteCount=taskingMapper.deleteJoin(new MPJLambdaWrapper<Tasking>()
                .selectAll(Tasking.class)
                .innerJoin(LineConfiguration.class,LineConfiguration::getId,Tasking::getLineConfigurationId)
                .innerJoin(Machine.class,Machine::getId,LineConfiguration::getMachineId)
                .eq(LineConfiguration::getMachineId,24L)
                .eq(Tasking::getGlassState,"正常")
                .eq(Tasking::getState,"线上")
                .ne(Tasking::getWorkState,"完工"));
        log.info("{}",deleteCount);
    }
    @Test
    public void testSaoMa() {
        try {
// 创建TCP客户端并连接到服务器
            String serverAddress = "10.36.164.19";
            int serverPort = 2001;
            Socket clientSocket = new Socket(serverAddress, serverPort);
            // 创建输入流和输出流
            InputStream inputStream = clientSocket.getInputStream();
            OutputStream outputStream = clientSocket.getOutputStream();
            // 发送数据给服务器
            String message = "start";
            outputStream.write(message.getBytes());
            // 读取服务器响应的数据
            byte[] buffer = new byte[1024];
            int bytesRead = inputStream.read(buffer);
            String receivedMessage = new String(buffer, 0, bytesRead);
            System.out.println("收到服务器响应:" + receivedMessage);
            // 发送数据给服务器
            String message2 = "stop";
            outputStream.write(message2.getBytes());
            // 关闭连接
            clientSocket.close();
        }catch (Exception e){
            log.info("扫码异常");
        }
    }
    @Test
    public void conncet(){
        try {
            int bufSizes = 0;
            byte[] msgs = new byte[2048];
            //创建连接  172.17.125.200  192.168.10.101
            Socket socket = new Socket("10.36.164.100", 1099);
            try {
                socket.setSoTimeout(3000);
                //写入需要数据
                DataOutputStream outToServer = new DataOutputStream(socket.getOutputStream());
                outToServer.write(HexUtil.stringToInt("000100000006010300000028"));
                outToServer.flush();
                //读取数据
                DataInputStream in = new DataInputStream(socket.getInputStream());
                bufSizes = in.read(msgs);
                String message = HexUtil.byteToHexString(bufSizes, msgs);
                System.out.println(message);
            } catch (Exception e) {
                System.out.println("读取失败");
                try {
                    SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");//设置日期格式
                } catch (Exception e2) {
                    // TODO: handle exception
                }
            }
            socket.close();
        } catch (Exception e) {
            System.out.println("异常");
        }
    }
    @Test
    public void testFindPath() {
        //String url = getClass().getResource("").getPath();
@@ -39,12 +237,238 @@
        log.info("完整路径");
    }
    @Test
    public void testByte() {
        //String url = getClass().getResource("").getPath();
        //log.info("完整路径:{}", Arrays.asList(url));
        byte[] msgs = new byte[2048];
        msgs[0]=(byte)0;
        msgs[1]=Byte.parseByte("1") ;
        int g=HexConversion.bytesToInt(msgs,0);
        String message = HexConversion.byteToHexString(4, msgs);
        byte font=msgs[1];
        String[] fontBit=String.format("%8s", Integer.toBinaryString((int)font)).replace(" ", "0").split("");
        byte[] bit=new byte[1];
        bit[0]=Byte.parseByte(fontBit[7]) ;
        log.info("结果:{},{}",fontBit,bit);
        //log.info("结果:{},{},{},{},{}",msgs,message,g,(msgs[0] & 0xFF),((msgs[1] & 0xFF)<<8));
    }
    @Test
    public void testFindAccount() {
        Map<String, Object> Account=accountService.selectAccount("admin","12345");
        Map<String, Object> Account=accountService.selectAccount("beibo","57858555");
        if(Account.isEmpty()){
            System.out.println("成功");
        }
        log.info("{}",Account);
    }
    //连接客户表
    @Test
    public void testInput() {
        Machine machine=machineMapper.selectById(14);
        taskingService.scanMachineAdd(machine, "46594135");
        log.info("内容{}",2);
    }
    //连接客户表
    @Test
    public void testSqlServerInput() {
        boolean is=projectService.insertProjectStandard();
        log.info("内容{}",is);
    }
    //连接客户表
    @Test
    public void testMachineFinsh() {
        Machine machine=machineMapper.selectById(14);
        int a=taskingService.finishMachineTask(machine);
        log.info("内容{}",a);
    }
    //定制查找任务
    @Test
    public void testSqlServer() {
        Machine machine=machineMapper.selectById(26);
        String scan_id="";
        List<Tasking> taskingList=taskingService.findMachineTask(machine);
        if(!taskingList.isEmpty()){
            Tasking tasking=taskingList.get(0);
            if (scan_id.equals(tasking.getScanId())){
            }else{
                List<Tasking> isExist=taskingService.findMachineTaskID(machine,scan_id);
                if(isExist.isEmpty()){
                    //读取客户数据库
                    projectService.insertProjectCustomization(scan_id);
                }
            }
        }
//        insertProjectCustomization();
        log.info("内容{}",taskingList);
    }
    //定制查找任务
    @Test
    public void testSqlServeraa() {
        Machine machine=machineMapper.selectById(12);
        String scan_id="46399819";
        projectService.insertProjectCustomization(scan_id);
        log.info("内容{}",machine);
    }
    //修改客户表
    @Test
    public void testSqlServerUpdate() {
        UpdateWrapper updateWrapper=new UpdateWrapper();
        KBBTJPDrawingBP kBBTJPDrawingBPs=new KBBTJPDrawingBP();
        kBBTJPDrawingBPMapper.update(kBBTJPDrawingBPs,updateWrapper);
        List<KBBTJPDrawingBP> kBBTJPDrawingBP=kBBTJPDrawingBPMapper.selectJoinList(KBBTJPDrawingBP.class,new MPJLambdaWrapper<KBBTJPDrawingBP>()
                .selectAll(KBBTJPDrawingBP.class)
                .eq(KBBTJPDrawingBP::getScanId,"011045108661010000")
                .orderByAsc(KBBTJPDrawingBP::getCreateDate)
                .orderByAsc(KBBTJPDrawingBP::getTaskSequence));
        kBBTJPDrawingBP.get(0).setIsWorking(1);
        kBBTJPDrawingBPMapper.updateById(kBBTJPDrawingBP.get(0));
        //kBBTJPDrawingBPMapper.update(kBBTJPDrawingBP,new QueryWrapper<>());
//        log.info("内容{}",KBBTJPDrawingBP);
    }
    //修改客户表
    @Test
    public void testSqlServerUpdate2() {
        UpdateWrapper<KBBTJPDrawingBP> updateWrapper=new UpdateWrapper<KBBTJPDrawingBP>();
        updateWrapper.lambda().eq(KBBTJPDrawingBP::getScanId,"011045108661010000");
        KBBTJPDrawingBP kBBTJPDrawingBPs=new KBBTJPDrawingBP();
        kBBTJPDrawingBPs.setIsWorking(2);
        kBBTJPDrawingBPMapper.update(kBBTJPDrawingBPs,updateWrapper);
//        log.info("内容{}",KBBTJPDrawingBP);
    }
    //周产量测试
    @Test
    public void testDailyOutput() {
        Map map=new HashMap();
        map.put("dayCount",1);
        int dayCount=0-Integer.valueOf(map.get("dayCount").toString());
        Calendar cal = Calendar.getInstance();
        //设置当前时间
        cal.setTime(new Date());
        cal.add(Calendar.DATE, dayCount);
        QueryWrapper<KBBTProgramsOperationLogBP> queryWrapper = new QueryWrapper<>();
        queryWrapper.select("CreateDate,isNull(sum(task_quantity),0) as task_quantity_sum,isNull(sum(report_count),0) as report_count_sum")
                .gt("CreateDate",cal.getTime()).groupBy("CreateDate");
        List<KBBTProgramsOperationLogBP> list=kBBTJPDrawingBPMapper.selectMaps((QueryWrapper)queryWrapper);
        log.info("内容{}{}",list,cal.getTime());
    }
    //日产量测试
    @Test
    public void testWeekOutput() {
        Map map=new HashMap();
        map.put("dayCount",1);
        int dayCount=0-Integer.valueOf(map.get("dayCount").toString());
        Calendar cal = Calendar.getInstance();
        //设置当前时间
        cal.setTime(new Date());
        cal.add(Calendar.DATE, dayCount);
        QueryWrapper<KBBTProgramsOperationLogBP> queryWrapper = new QueryWrapper<>();
        queryWrapper.select("CAST(CreateDate AS DATE) AS CreateDate,isNull(sum(task_quantity),0) as task_quantity_sum,isNull(sum(length*width*task_quantity)/1000000,0) as area_sum")
                .gt("CreateDate",cal.getTime()).groupBy("CAST(CreateDate AS DATE)");
        List<KBBTProgramsOperationLogBP> list=kBBTJPDrawingBPMapper.selectMaps((QueryWrapper)queryWrapper);
        log.info("内容{}{}",list,cal.getTime());
        log.info("内容{}",list);
    }
    //日产量未完成
    @Test
    public void testDayNotFinshOutput() {
        Map map=new HashMap();
        map.put("dayCount",1);
        int dayCount=0-Integer.valueOf(map.get("dayCount").toString());
        Calendar cal = Calendar.getInstance();
        //设置当前时间
        cal.setTime(new Date());
        cal.set(Calendar.HOUR_OF_DAY, 0);
        cal.set(Calendar.MINUTE, 0);
        cal.set(Calendar.SECOND, 0);
        cal.set(Calendar.MILLISECOND, 0);
        cal.add(Calendar.DATE, dayCount);
        QueryWrapper<KBBTJPDrawingBP> queryWrapper = new QueryWrapper<>();
        queryWrapper.select("OrderNo,(sum(task_quantity-isNull(report_count,0))) as notComplete,sum(isNull((length*width*(task_quantity-isNull(report_count,0)))/1000000,0)) as area_sum").
                gt("PlanDate",cal.getTime()).having("sum(task_quantity-isNull(report_count,0))>0")
                .groupBy("OrderNo");
        List<Map> list=kBBTJPDrawingBPMapper.selectMaps((QueryWrapper)queryWrapper);
        log.info("内容{}",list);
    }
    //日产量 分线 已完成
    @Test
    public void testDayss() {
        List<Map> map=taskingLogService.selectTaskingLog(20);
        log.info("内容{}",map);
    }
    //日产量 分线 已完成
    @Test
    public void testDays() {
        Map map=new HashMap();
        map.put("dayCount",5);
        int dayCount=Integer.valueOf(map.get("dayCount").toString());
        Calendar cal = Calendar.getInstance();
        //设置当前时间
        cal.setTime(new Date());
        cal.set(Calendar.HOUR_OF_DAY, 0);
        cal.set(Calendar.MINUTE, 0);
        cal.set(Calendar.SECOND, 0);
        cal.set(Calendar.MILLISECOND, 0);
        cal.add(Calendar.DATE, 0-dayCount);
        //近dayCount天的计划数量
        QueryWrapper<KBBTJPDrawingBP> queryWrapper = new QueryWrapper<>();
        queryWrapper.select("CAST(CreateDate AS DATE) AS CreateDate,isNull(sum(task_quantity),0) as task_quantity_sum")
                .gt("CreateDate",cal.getTime()).groupBy("CAST(CreateDate AS DATE)").orderByAsc("CAST(CreateDate AS DATE)");
        List<Map> list=kBBTJPDrawingBPMapper.selectMaps((QueryWrapper)queryWrapper);
        //近dayCount天的计划数量
        List<String> dateList=new ArrayList<>();
        Map<String,Object> mapList=new HashMap<>();
        for (int i=0;i<dayCount;i++){
            cal.add(Calendar.DATE, 1);
            log.info("内容{}",cal.getTime().toString());
            dateList.add(cal.getTime().toString());//日期顺序
            Map<String,Object> item=new HashMap<>();
            item.put("report_count_sum",0);
            item.put("task_quantity_sum",0);
            try {
                DateFormat df = new SimpleDateFormat("yyyy-MM-dd");
                Date d=df.parse(cal.getTime().toString());
                item.put("CreateDate",d.toString());
            }catch (Exception e){
                log.info("异常");
            }
            mapList.put(cal.getTime().toString(), item);//每个日期的数据 -匹配用
        }
        //遍历匹配
        for (int i=0;i<list.size();i++){
            cal.setTime((Date)list.get(i).get("CreateDate"));
            cal.set(Calendar.HOUR_OF_DAY, 0);
            cal.set(Calendar.MINUTE, 0);
            cal.set(Calendar.SECOND, 0);
            cal.set(Calendar.MILLISECOND, 0);
            mapList.put(cal.getTime().toString(), list.get(i));
        }
        //遍历顺序
        List result=new ArrayList();
        for (int i=0;i<dateList.size();i++){
            result.add(mapList.get(dateList.get(i)));
            //log.info("结果{}",mapList.get(dateList.get(i)));
        }
        log.info("返回内容{}",result);
    }
}