zhoushihao
2024-05-09 31c0c608f884ab548ba4c57ebcddef6f46da460e
卧式理片笼进出片任务优化
11个文件已修改
509 ■■■■ 已修改文件
hangzhoumesParent/common/servicebase/src/main/java/com/mes/common/config/Const.java 7 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
hangzhoumesParent/moduleService/CacheGlassModule/src/main/java/com/mes/AppRunnerConfig.java 4 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
hangzhoumesParent/moduleService/CacheGlassModule/src/main/java/com/mes/CacheGlassModuleApplication.java 14 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
hangzhoumesParent/moduleService/CacheGlassModule/src/main/java/com/mes/common/PlcHomeEdg.java 28 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
hangzhoumesParent/moduleService/CacheGlassModule/src/main/java/com/mes/edgstoragecage/service/impl/EdgStorageCageDetailsServiceImpl.java 142 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
hangzhoumesParent/moduleService/CacheGlassModule/src/main/java/com/mes/edgstoragecage/service/impl/EdgStorageCageServiceImpl.java 30 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
hangzhoumesParent/moduleService/CacheGlassModule/src/main/java/com/mes/job/CacheGlassTask.java 249 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
hangzhoumesParent/moduleService/CacheGlassModule/src/main/java/com/mes/taskcache/entity/TaskCache.java 5 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
hangzhoumesParent/moduleService/CacheGlassModule/src/main/java/com/mes/taskcache/service/impl/TaskCacheServiceImpl.java 16 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
hangzhoumesParent/moduleService/CacheGlassModule/src/main/resources/JsonFile/PlcCacheGlass.json 12 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
hangzhoumesParent/moduleService/CacheGlassModule/src/main/resources/application.yml 2 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
hangzhoumesParent/common/servicebase/src/main/java/com/mes/common/config/Const.java
@@ -6,6 +6,13 @@
 * @Description:
 */
public class Const {
    //默认密码
    public static final String DEFULT_PASSWORD = "123456";
    //默认角色
    public static final Long DEFULT_ROLE = 1L;
    //A09出片目标位置
    public static final String A09_OUT_TARGET_POSITION = "2001";
    //A09出片目标位置
    public static final String A10_OUT_TARGET_POSITION = "2002";
}
hangzhoumesParent/moduleService/CacheGlassModule/src/main/java/com/mes/AppRunnerConfig.java
@@ -1,6 +1,6 @@
package com.mes;
import com.mes.common.PlcHomeEdg;
import com.mes.common.S7object;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
@@ -17,7 +17,7 @@
    public void run(ApplicationArguments args) throws Exception {
        // TODO Auto-generated method stub
        log.info("启动完成");
       new PlcHomeEdg().start();
        S7object.getinstance().start();
    }
}
hangzhoumesParent/moduleService/CacheGlassModule/src/main/java/com/mes/CacheGlassModuleApplication.java
@@ -1,15 +1,12 @@
package com.mes;
import com.mes.common.WebSocketServer;
import lombok.extern.slf4j.Slf4j;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.scheduling.annotation.EnableScheduling;
import springfox.documentation.swagger2.annotations.EnableSwagger2;
import com.mes.edgstoragecage.service.*;
/**
 * @Author : zhoush
@@ -21,14 +18,15 @@
@MapperScan("com.mes.*.mapper")
@EnableDiscoveryClient
@EnableSwagger2
@EnableScheduling
public class CacheGlassModuleApplication {
    public static void main(String[] args) {
        try {
            SpringApplication springApplication = new SpringApplication(CacheGlassModuleApplication.class);
            ConfigurableApplicationContext applicationContext = springApplication.run(args);
            WebSocketServer.setApplicationContext(applicationContext);
            //SpringApplication.run(CacheGlassModuleApplication.class, args);
//            SpringApplication springApplication = new SpringApplication(CacheGlassModuleApplication.class);
//            ConfigurableApplicationContext applicationContext = springApplication.run(args);
//            WebSocketServer.setApplicationContext(applicationContext);
            SpringApplication.run(CacheGlassModuleApplication.class, args);
        } catch (Exception e) {
            log.error(e.getMessage());
        }
hangzhoumesParent/moduleService/CacheGlassModule/src/main/java/com/mes/common/PlcHomeEdg.java
@@ -1,6 +1,5 @@
package com.mes.common;
import cn.hutool.core.date.DateTime;
import cn.hutool.json.JSONObject;
import com.github.yulichang.wrapper.MPJLambdaWrapper;
import com.mes.edgstoragecage.entity.EdgStorageCage;
@@ -17,10 +16,7 @@
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.*;
@Service
@Slf4j
@@ -60,13 +56,13 @@
//        //mapType.put("A10_glass_status", "Word");
//        mapType.put("A09_prohibit_film_production", "Word");
//        mapType.put("A10_prohibit_film_production", "Word");
        mapValue.put("A06_request_word","1");//请求字
        mapValue.put("A05_scanning_ID","11111111111");//请求ID
        mapValue.put("MES_confirmation_word","0");//MES发送字
        mapValue.put("A09_glass_status","0");//A09玻璃状态
        mapValue.put("A10_glass_status","0");//A09玻璃状态
        mapValue.put("A09_prohibit_film_production","0");//A9禁止出片
        mapValue.put("A10_prohibit_film_production","0");//A10禁止出片
        mapValue.put("A06_request_word", "1");//请求字
        mapValue.put("A05_scanning_ID", "11111111111");//请求ID
        mapValue.put("MES_confirmation_word", "0");//MES发送字
        mapValue.put("A09_glass_status", "0");//A09玻璃状态
        mapValue.put("A10_glass_status", "0");//A09玻璃状态
        mapValue.put("A09_prohibit_film_production", "0");//A9禁止出片
        mapValue.put("A10_prohibit_film_production", "0");//A10禁止出片
    }
@@ -91,10 +87,10 @@
                taskCache.setStartCell(0);
                taskCache.setEndCell(edgStorageCage.getSlot());
                taskCache.setTaskType(1);
                taskCache.setCreateTime(new DateTime());
                taskCache.setCreateTime(new Date());
                edgStorageCageDetailsMapper.updateById(edgStorageCageDetails);
                taskCacheService.insertTaskCache(taskCache);
                S7object.getinstance().plccontrol.WriteWord(mapParameter.get("MES_confirmation_word"), (short)1);
                S7object.getinstance().plccontrol.WriteWord(mapParameter.get("MES_confirmation_word"), (short) 1);
            } else {
                log.info("不存在空格");
            }
@@ -129,9 +125,9 @@
            taskCache.setStartCell(outEdgStorageCageDetails.getSlot());
            taskCache.setEndCell(endcell);
            taskCache.setTaskType(2);
            taskCache.setCreateTime(new DateTime());
            taskCache.setCreateTime(new Date());
            taskCacheService.insertTaskCache(taskCache);
            S7object.getinstance().plccontrol.WriteWord(mapParameter.get("MES_confirmation_word"), (short)1);
            S7object.getinstance().plccontrol.WriteWord(mapParameter.get("MES_confirmation_word"), (short) 1);
        }
hangzhoumesParent/moduleService/CacheGlassModule/src/main/java/com/mes/edgstoragecage/service/impl/EdgStorageCageDetailsServiceImpl.java
@@ -1,10 +1,10 @@
package com.mes.edgstoragecage.service.impl;
import cn.hutool.core.lang.Assert;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
import com.github.yulichang.base.MPJBaseServiceImpl;
import com.github.yulichang.query.MPJLambdaQueryWrapper;
import com.github.yulichang.query.MPJQueryWrapper;
import com.github.yulichang.toolkit.JoinWrappers;
import com.github.yulichang.wrapper.MPJLambdaWrapper;
import com.mes.edgstoragecage.entity.EdgStorageCage;
@@ -16,13 +16,18 @@
import com.mes.pp.entity.OptimizeLayout;
import com.mes.pp.mapper.OptimizeDetailMapper;
import com.mes.taskcache.entity.TaskCache;
import com.mes.taskcache.service.TaskCacheService;
import com.mes.uppattenusage.entity.UpPattenUsage;
import com.mes.uppattenusage.mapper.UpPattenUsageMapper;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.stream.Collectors;
/**
 * <p>
@@ -33,28 +38,36 @@
 * @since 2024-04-07
 */
@Service
@Slf4j
public class EdgStorageCageDetailsServiceImpl extends MPJBaseServiceImpl<EdgStorageCageDetailsMapper, EdgStorageCageDetails> implements EdgStorageCageDetailsService {
    @Autowired
    @Resource
    UpPattenUsageMapper upPattenUsageMapper;
    @Autowired
    OptimizeDetailMapper optimizeDetailMapper;
    @Autowired
    @Resource
    EdgStorageCageMapper edgStorageCageMapper;
    @Autowired
    TaskCacheService taskCacheService;
    /**
     * 识别   拿走:200/破损:201
     *
     * @param glassId
     * @param ControlsId
     * @return
     */
    @Override
    public boolean identWorn(String glassId, int ControlsId) {
        List<EdgStorageCageDetails> edgStorageCageDetails = baseMapper.selectList(new MPJLambdaQueryWrapper<EdgStorageCageDetails>().selectAll(EdgStorageCageDetails.class).eq(EdgStorageCageDetails::getGlassId,glassId));
        List<EdgStorageCageDetails> edgStorageCageDetails = baseMapper.selectList(new MPJLambdaQueryWrapper<EdgStorageCageDetails>().selectAll(EdgStorageCageDetails.class).eq(EdgStorageCageDetails::getGlassId, glassId));
        if (edgStorageCageDetails.size() == 1) {
            EdgStorageCageDetails item=edgStorageCageDetails.get(0);
            EdgStorageCageDetails item = edgStorageCageDetails.get(0);
            item.setState(ControlsId);
            baseMapper.update(edgStorageCageDetails.get(0), new MPJLambdaWrapper<EdgStorageCageDetails>().selectAll(EdgStorageCageDetails.class).eq(EdgStorageCageDetails::getGlassId,glassId));
            baseMapper.update(edgStorageCageDetails.get(0), new MPJLambdaWrapper<EdgStorageCageDetails>().selectAll(EdgStorageCageDetails.class).eq(EdgStorageCageDetails::getGlassId, glassId));
            return true;
        }
//            Sql版本
@@ -70,25 +83,26 @@
    /**
     * 获取 切割当前版图
     *
     * @return
     */
    @Override
    public List<Map<String, Object>> selectCutTerritory() {
        List<UpPattenUsage> upPattenUsage=upPattenUsageMapper.selectList(new MPJLambdaWrapper<UpPattenUsage>()
        List<UpPattenUsage> upPattenUsage = upPattenUsageMapper.selectList(new MPJLambdaWrapper<UpPattenUsage>()
                .selectAll(UpPattenUsage.class)
                .eq(UpPattenUsage::getState, 1));
        if(!upPattenUsage.isEmpty()){
            UpPattenUsage upPattenUsage1=upPattenUsage.get(0);
        if (!upPattenUsage.isEmpty()) {
            UpPattenUsage upPattenUsage1 = upPattenUsage.get(0);
            return optimizeDetailMapper.selectJoinMaps(JoinWrappers.lambda(OptimizeDetail.class)
                    .selectAll(OptimizeDetail.class)
                    .selectAs(OptimizeLayout::getWidth,"olWidth")
                    .selectAs(OptimizeLayout::getWidth,"olHeight")
                    .leftJoin(OptimizeLayout.class,on->on
                            .eq(OptimizeLayout::getProjectNo,OptimizeDetail::getProjectNo)
                            .eq(OptimizeLayout::getStockId,OptimizeDetail::getStockId))
                    .selectAs(OptimizeLayout::getWidth, "olWidth")
                    .selectAs(OptimizeLayout::getWidth, "olHeight")
                    .leftJoin(OptimizeLayout.class, on -> on
                            .eq(OptimizeLayout::getProjectNo, OptimizeDetail::getProjectNo)
                            .eq(OptimizeLayout::getStockId, OptimizeDetail::getStockId))
                    .eq(OptimizeDetail::getProjectNo, upPattenUsage1.getEngineeringId())
                    .eq(OptimizeDetail::getStockId,upPattenUsage1.getLayoutSequence())
                    .eq(OptimizeDetail::getStockId, upPattenUsage1.getLayoutSequence())
            );
//            Sql版本
@@ -104,6 +118,7 @@
    /**
     * 获取 工程下的当前版图
     *
     * @param current
     * @return
     */
@@ -112,11 +127,11 @@
        return optimizeDetailMapper.selectJoinMaps(JoinWrappers.lambda(OptimizeDetail.class)
                .selectAll(OptimizeDetail.class)
                .selectAs(OptimizeLayout::getWidth,"olWidth")
                .selectAs(OptimizeLayout::getWidth,"olHeight")
                .leftJoin(OptimizeLayout.class,on->on
                        .eq(OptimizeLayout::getProjectNo,OptimizeDetail::getProjectNo)
                        .eq(OptimizeLayout::getStockId,OptimizeDetail::getStockId))
                .selectAs(OptimizeLayout::getWidth, "olWidth")
                .selectAs(OptimizeLayout::getWidth, "olHeight")
                .leftJoin(OptimizeLayout.class, on -> on
                        .eq(OptimizeLayout::getProjectNo, OptimizeDetail::getProjectNo)
                        .eq(OptimizeLayout::getStockId, OptimizeDetail::getStockId))
                .eq(OptimizeDetail::getProjectNo, current)
        );
//Sql版本
@@ -129,54 +144,71 @@
    /**
     * 查询笼内版图差值范围内的  此尺寸玻璃  如无则按照 钢化版图序号 以及玻璃序号
     *
     * @param glassId
     * @param poor
     * @return
     */
    @Override
    public EdgStorageCageDetails selectConformGlass(String glassId, int poor){
    public EdgStorageCageDetails selectConformGlass(String glassId, int poor) {
        //1.去笼内查询此尺寸的玻璃 目前版图差值内的玻璃  是否有同尺寸的
        //1.1 有同尺寸的 则生成同尺寸的任务
        //1.2 无同尺寸的 则生成版图顺序最小的出片
        EdgStorageCageDetails edgStorageCageDetails= baseMapper.selectOne(new MPJLambdaQueryWrapper<EdgStorageCageDetails>()
                .selectAll(EdgStorageCageDetails.class)
                .eq(EdgStorageCageDetails::getGlassId,glassId)
        );
        List<EdgStorageCageDetails> listEdgStorageCageDetails= baseMapper.selectList(new LambdaQueryWrapper<EdgStorageCageDetails>()
                .lt(EdgStorageCageDetails::getState,200)
                .orderByAsc(EdgStorageCageDetails::getTemperingLayoutId,EdgStorageCageDetails::getTemperingFeedSequence)
        );
        EdgStorageCageDetails minTemperingLayoutId=new EdgStorageCageDetails();
        if(!listEdgStorageCageDetails.isEmpty()){
            minTemperingLayoutId=listEdgStorageCageDetails.get(0);
        }
        EdgStorageCageDetails result=new EdgStorageCageDetails();
        if(edgStorageCageDetails!=null&&minTemperingLayoutId!=null){
            result=edgStorageCageMapper.selectJoinOne(EdgStorageCageDetails.class,new MPJLambdaWrapper<EdgStorageCage>()
        log.info("按照玻璃id:{}获取玻璃信息", glassId);
        EdgStorageCageDetails oldEdgStorageCageDetails = null;
        if (StringUtils.isNotEmpty(glassId)) {
            oldEdgStorageCageDetails = baseMapper.selectOne(new MPJLambdaQueryWrapper<EdgStorageCageDetails>()
                    .selectAll(EdgStorageCageDetails.class)
                    .leftJoin(EdgStorageCageDetails.class,on->on
                            .eq(EdgStorageCageDetails::getDeviceId,EdgStorageCage::getDeviceId)
                            .eq(EdgStorageCageDetails::getSlot,EdgStorageCage::getSlot))
                    .isNotNull(EdgStorageCageDetails::getSlot)
                    .eq(EdgStorageCageDetails::getWidth,edgStorageCageDetails.getWidth())
                    .eq(EdgStorageCageDetails::getHeight,edgStorageCageDetails.getHeight())
                    .ge(EdgStorageCageDetails::getTemperingLayoutId,minTemperingLayoutId.getTemperingLayoutId())
                    .le(EdgStorageCageDetails::getTemperingLayoutId,minTemperingLayoutId.getTemperingLayoutId()+poor)
                    .orderByAsc(EdgStorageCageDetails::getTemperingLayoutId,EdgStorageCageDetails::getTemperingFeedSequence)
            );
                    .eq(EdgStorageCageDetails::getGlassId, glassId));
        }
        if (result==null){
            result=edgStorageCageMapper.selectJoinOne(EdgStorageCageDetails.class,new MPJLambdaWrapper<EdgStorageCage>()
        LambdaQueryWrapper<TaskCache> wrapper = new LambdaQueryWrapper<TaskCache>().select(TaskCache::getGlassId).eq(TaskCache::getTaskType, "2");
        List<TaskCache> taskCacheList = taskCacheService.list(wrapper);
        List<String> glassIds = taskCacheList.stream().map(TaskCache::getGlassId).collect(Collectors.toList());
        log.info("获取笼内所有已出片的玻璃id信息:{}", glassIds);
        EdgStorageCageDetails minTemperingLayoutId = baseMapper.selectOne(new LambdaQueryWrapper<EdgStorageCageDetails>()
                .eq(EdgStorageCageDetails::getState, 100)
                .notIn(CollectionUtils.isNotEmpty(glassIds), EdgStorageCageDetails::getGlassId, glassIds)
                .orderByAsc(EdgStorageCageDetails::getTemperingLayoutId, EdgStorageCageDetails::getTemperingFeedSequence)
                .last("limit 1"));
        Assert.isTrue(minTemperingLayoutId != null, "笼内无符合要求的玻璃");
        log.info("获取笼内最小版图id{}及版序为{}的玻璃信息{}", minTemperingLayoutId.getTemperingLayoutId(),
                minTemperingLayoutId.getTemperingFeedSequence(), minTemperingLayoutId);
        EdgStorageCageDetails outEdgStorageCageDetails = null;
        if (oldEdgStorageCageDetails != null && minTemperingLayoutId != null) {
            log.info("按照上一片已出玻璃宽度{},高度{},及版图id区间{}到{}获取出片任务玻璃信息", oldEdgStorageCageDetails.getWidth()
                    , oldEdgStorageCageDetails.getHeight(), minTemperingLayoutId.getTemperingLayoutId(), minTemperingLayoutId.getTemperingLayoutId() + poor);
            outEdgStorageCageDetails = edgStorageCageMapper.selectJoinOne(EdgStorageCageDetails.class, new MPJLambdaWrapper<EdgStorageCage>()
                    .selectAll(EdgStorageCageDetails.class)
                    .leftJoin(EdgStorageCageDetails.class,on->on
                            .eq(EdgStorageCageDetails::getDeviceId,EdgStorageCage::getDeviceId)
                            .eq(EdgStorageCageDetails::getSlot,EdgStorageCage::getSlot))
                    .leftJoin(EdgStorageCageDetails.class, on -> on
                            .eq(EdgStorageCageDetails::getDeviceId, EdgStorageCage::getDeviceId)
                            .eq(EdgStorageCageDetails::getSlot, EdgStorageCage::getSlot))
                    .isNotNull(EdgStorageCageDetails::getSlot)
                    .orderByAsc(EdgStorageCageDetails::getTemperingLayoutId,EdgStorageCageDetails::getTemperingFeedSequence)
                    .eq(EdgStorageCageDetails::getWidth, oldEdgStorageCageDetails.getWidth())
                    .eq(EdgStorageCageDetails::getHeight, oldEdgStorageCageDetails.getHeight())
                    .ge(EdgStorageCageDetails::getTemperingLayoutId, minTemperingLayoutId.getTemperingLayoutId())
                    .le(EdgStorageCageDetails::getTemperingLayoutId, minTemperingLayoutId.getTemperingLayoutId() + poor)
                    .orderByAsc(EdgStorageCageDetails::getTemperingLayoutId, EdgStorageCageDetails::getTemperingFeedSequence)
                    .last("limit 1")
            );
            log.info("出片任务的玻璃信息:{}", outEdgStorageCageDetails);
        }
        return result;
        if (outEdgStorageCageDetails == null) {
            outEdgStorageCageDetails = minTemperingLayoutId;
//            outEdgStorageCageDetails = edgStorageCageMapper.selectJoinOne(EdgStorageCageDetails.class, new MPJLambdaWrapper<EdgStorageCage>()
//                    .selectAll(EdgStorageCageDetails.class)
//                    .leftJoin(EdgStorageCageDetails.class, on -> on
//                            .eq(EdgStorageCageDetails::getDeviceId, EdgStorageCage::getDeviceId)
//                            .eq(EdgStorageCageDetails::getSlot, EdgStorageCage::getSlot))
//                    .isNotNull(EdgStorageCageDetails::getSlot)
//                    .orderByAsc(EdgStorageCageDetails::getTemperingLayoutId, EdgStorageCageDetails::getTemperingFeedSequence)
//                    .last("limit 1")
//            );
        }
        return outEdgStorageCageDetails;
    }
}
hangzhoumesParent/moduleService/CacheGlassModule/src/main/java/com/mes/edgstoragecage/service/impl/EdgStorageCageServiceImpl.java
@@ -1,27 +1,21 @@
package com.mes.edgstoragecage.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.github.yulichang.base.MPJBaseServiceImpl;
import com.github.yulichang.query.MPJLambdaQueryWrapper;
import com.github.yulichang.query.MPJQueryWrapper;
import com.github.yulichang.toolkit.JoinWrappers;
import com.github.yulichang.wrapper.MPJLambdaWrapper;
import com.mes.edgstoragecage.entity.EdgStorageCage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.mes.edgstoragecage.entity.EdgStorageCageDetails;
import com.mes.edgstoragecage.mapper.EdgStorageCageMapper;
import com.mes.edgstoragecage.mapper.EdgStorageCageDetailsMapper;
import com.mes.edgstoragecage.mapper.EdgStorageCageMapper;
import com.mes.edgstoragecage.service.EdgStorageCageService;
import com.mes.uppattenusage.entity.UpPattenUsage;
import com.mes.uppattenusage.mapper.UpPattenUsageMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
import java.util.Map;
import java.util.*;
import java.util.stream.Collectors;
/**
 * <p>
@@ -49,24 +43,10 @@
        return baseMapper.selectJoinList(EdgStorageCage.class,new MPJLambdaWrapper<EdgStorageCage>()
                .selectAll(EdgStorageCage.class)
                .leftJoin(EdgStorageCageDetails.class,on->on
                        .eq(EdgStorageCageDetails::getDeviceId,EdgStorageCage::getDeviceId)
                        .eq(EdgStorageCageDetails::getSlot,EdgStorageCage::getSlot))
                        .eq(EdgStorageCageDetails::getSlot,EdgStorageCage::getSlot)
                        .eq(EdgStorageCageDetails::getState,"100"))
                .isNull(EdgStorageCageDetails::getSlot)
        );
//        return baseMapper.selectJoinMaps(JoinWrappers.lambda(EdgStorageCage.class).selectAll(EdgStorageCage.class)
//                .select(EdgStorageCageDetails::getWidth, EdgStorageCageDetails::getHeight,EdgStorageCageDetails::getGlassId)
//                .leftJoin(EdgStorageCageDetails.class,on->on
//                        .eq(EdgStorageCageDetails::getDeviceId,EdgStorageCage::getDeviceId)
//                        .eq(EdgStorageCageDetails::getSlot,EdgStorageCage::getSlot))
//                .isNull(EdgStorageCageDetails::getSlot)
//        );
//        return baseMapper.selectJoinMaps(new MPJQueryWrapper<EdgStorageCage>().selectAll(EdgStorageCage.class)
//                        .select("escd.glass_id","escd.flow_card_id","escd.width","escd.height")
//                        .leftJoin("edg_storage_cage_details escd on t.device_id=escd.device_id and t.slot=escd.slot")
//                        .isNull("escd.slot")
//        );
    }
    /**
hangzhoumesParent/moduleService/CacheGlassModule/src/main/java/com/mes/job/CacheGlassTask.java
@@ -1,13 +1,13 @@
package com.mes.job;
import cn.hutool.core.date.DateTime;
import cn.hutool.json.JSONObject;
import com.github.yulichang.wrapper.MPJLambdaWrapper;
import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.lang.Assert;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.mes.common.S7object;
import com.mes.common.WebSocketServer;
import com.mes.common.config.Const;
import com.mes.device.PlcParameterObject;
import com.mes.edgstoragecage.entity.EdgStorageCage;
import com.mes.edgstoragecage.entity.EdgStorageCageDetails;
import com.mes.edgstoragecage.mapper.EdgStorageCageDetailsMapper;
import com.mes.edgstoragecage.service.EdgStorageCageDetailsService;
import com.mes.edgstoragecage.service.EdgStorageCageService;
import com.mes.glassinfo.entity.GlassInfo;
@@ -15,15 +15,14 @@
import com.mes.taskcache.entity.TaskCache;
import com.mes.taskcache.service.TaskCacheService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Date;
import java.util.List;
import java.util.Map;
/**
 * @Author : zhoush
@@ -42,161 +41,123 @@
    EdgStorageCageService edgStorageCageService;
    @Autowired
    EdgStorageCageDetailsService edgStorageCageDetailsService;
    @Resource
    private EdgStorageCageDetailsMapper edgStorageCageDetailsMapper;
    private Map<String, String> mapParameter = new HashMap<>();
    private Map<String, String> mapValue = new HashMap<>();
    private Map<String, String> mapType = new HashMap<>();
    private Map<String, Object> mapSettings = new HashMap<>();
    @Value("${mes.threshold}")
    private int threshold;
    @Scheduled(fixedDelay = 1000)
    @Scheduled(fixedDelay = 10000)
    public void plcHomeEdgTask() {
        initialize();
        log.info("当前参数值:{}", mapValue);
        JSONObject jsonObject = new JSONObject();
//        for (String key : mapParameter.keySet()) {
//            String value = "";
//            if ("String".equals(mapType.get(key))) {
//                value = S7object.getinstance().plccontrol.readString(mapParameter.get(key));
//            } else {
//                value = S7object.getinstance().plccontrol.readWord(mapParameter.get(key)) + "";
//            }
//            mapValue.put(key, value);
//        }
        PlcParameterObject plcParameterObject = S7object.getinstance().PlcMesObject;
        if ("0".equals(mapValue.get("A06_request_word"))) {
            log.info("获取到的请求字为0,将确认字改为0");
            //清除
            S7object.getinstance().plccontrol.WriteWord(mapParameter.get("MES_confirmation_word"), (short) 0);
        } else if ("1".equals(mapValue.get("A06_request_word")) &&
                "0".equals(mapValue.get("MES_confirmation_word"))) {
            log.info("进片请求,且确认字为0,执行进片任务");
            inTo();
        } else if ("2".equals(mapValue.get("A06_request_word")) &&
                "0".equals(mapValue.get("MES_confirmation_word")) && !"0".equals(mapValue.get("A09_glass_status"))) {
        String taskRequestTypeValue = plcParameterObject.getPlcParameter("A06_request_word").getValue();
        String glassIdeValue = plcParameterObject.getPlcParameter("A05_scanning_ID").getValue();
        String confirmationWrodValue = plcParameterObject.getPlcParameter("MES_confirmation_word").getValue();
//        1为A09空闲,2为A10空闲,3为A09A10都空闲,0为A09A10都有玻璃
        String outGlassstate = plcParameterObject.getPlcParameter("A09_glass_status").getValue();
        String confirmationWrodAddress = plcParameterObject.getPlcParameter("MES_confirmation_word").getAddress();
        if ("0".equals(taskRequestTypeValue)) {
            log.info("1、获取到的请求字为0,将确认字改为0");
            S7object.getinstance().plccontrol.WriteWord(confirmationWrodAddress, (short) 0);
            return;
        }
        if (!"0".equals(confirmationWrodValue)) {
            log.info("1、获取到的请求字不为0,将确认字改为0");
            S7object.getinstance().plccontrol.WriteWord(confirmationWrodAddress, (short) 0);
            return;
        }
        if ("1".equals(taskRequestTypeValue)) {
            log.info("2、进片请求,且确认字为0,执行进片任务");
            inTo(glassIdeValue, confirmationWrodAddress);
        } else if ("2".equals(taskRequestTypeValue)) {
            //09空闲 :1      10空闲 :2        都空闲:3    其他0
            log.info("出片请求,且确认字为0,执行进片任务");
            outTo(Integer.parseInt(mapValue.get("A09_glass_status")));
        } else if ("3".equals(mapValue.get("A06_request_word")) &&
                "0".equals(mapValue.get("MES_confirmation_word"))) {
            if ("0".equals(mapValue.get("A09_glass_status")) || "0".equals(mapValue.get("A10_glass_status"))) {
                outTo(Integer.parseInt(mapValue.get("A09_glass_status")));
            log.info("2、出片请求,且确认字为0,执行进片任务");
            outTo(Integer.parseInt(outGlassstate), confirmationWrodAddress);
        } else if ("3".equals(taskRequestTypeValue)) {
            log.info("2、进片和出片都空闲,执行出片任务");
            if ("0".equals(outGlassstate)) {
                inTo(glassIdeValue, confirmationWrodAddress);
            } else {
                inTo();
            }
        }
//            log.info("推数据");
        // jsonObject.append("params", new short[] { 30, 40, });
        ArrayList<WebSocketServer> sendwServer = WebSocketServer.sessionMap.get("Home");
        if (sendwServer != null) {
            for (WebSocketServer webserver : sendwServer) {
                webserver.sendMessage(jsonObject.toString());
                if (webserver != null) {
                    List<String> messages = webserver.getMessages();
                    if (!messages.isEmpty()) {
                        // // 将最后一个消息转换为整数类型的列表
                        webserver.clearMessages();
                    }
                }
                outTo(Integer.parseInt(outGlassstate), confirmationWrodAddress);
            }
        }
    }
    /**
     * 初始化plc数据
     */
    private void initialize() {
//        mapParameter.put("A06_request_word", "DB11.0");   //work
//        mapParameter.put("A05_scanning_ID", "DB11.2");
//        mapParameter.put("MES_confirmation_word", "DB11.40");
//        mapParameter.put("A09_glass_status", "DB11.70");
//        //mapParameter.put("A10_glass_status", "DB11.72");
//        mapParameter.put("A09_prohibit_film_production", "DB11.74");
//        mapParameter.put("A10_prohibit_film_production", "DB11.76");
//        mapSettings.put("territoryPoor", 3);
//        mapType.put("A06_request_word", "Word");
//        mapType.put("A05_scanning_ID", "String");
//        mapType.put("MES_confirmation_word", "Word");
//        mapType.put("A09_glass_status", "Word");
//        //mapType.put("A10_glass_status", "Word");
//        mapType.put("A09_prohibit_film_production", "Word");
//        mapType.put("A10_prohibit_film_production", "Word");
        mapValue.put("A06_request_word", "2");//请求字
        mapValue.put("A05_scanning_ID", "11111111111");//请求ID
        mapValue.put("MES_confirmation_word", "0");//MES发送字
        mapValue.put("A09_glass_status", "1");//A09玻璃状态
        mapValue.put("A10_glass_status", "0");//A09玻璃状态
        mapValue.put("A09_prohibit_film_production", "0");//A9禁止出片
        mapValue.put("A10_prohibit_film_production", "0");//A10禁止出片
    }
    private void inTo() {
        List<GlassInfo> glassInfos = glassInfoService.selectId(mapValue.get("A05_scanning_ID"));
        if (glassInfos.size() < 1) {
            log.info("此玻璃编号不存在");
        } else if (glassInfos.size() == 1) {
            //添加进片任务  查找空格
            log.info("正常");
            List<EdgStorageCage> list = edgStorageCageService.selectCacheEmpty();
            if (list.size() > 1) {
                EdgStorageCageDetails edgStorageCageDetails = edgStorageCageDetailsMapper.selectOne(new MPJLambdaWrapper<EdgStorageCageDetails>()
                        .eq(EdgStorageCageDetails::getGlassId, glassInfos.get(0).getGlassId()));
                edgStorageCageDetails.setState(200);
                TaskCache taskCache = new TaskCache();
                EdgStorageCage edgStorageCage = list.get(0);
                taskCache.setGlassId(glassInfos.get(0).getGlassId());
                taskCache.setTaskStatus(0);
                taskCache.setStartCell(0);
                taskCache.setEndCell(edgStorageCage.getSlot());
                taskCache.setTaskType(1);
                taskCache.setCreateTime(new DateTime());
                edgStorageCageDetailsMapper.updateById(edgStorageCageDetails);
                taskCacheService.insertTaskCache(taskCache);
//                S7object.getinstance().plccontrol.WriteWord("DB11.40", (short) 1);
            } else {
                log.info("不存在空格");
            }
        } else {
            log.info("此玻璃编号存在多个");
    private void inTo(String glassId, String confirmationWrodAddress) {
        log.info("1、按照玻璃id:{}获取玻璃小片信息", glassId);
        GlassInfo glassInfo = glassInfoService.getOne(new LambdaQueryWrapper<GlassInfo>().eq(GlassInfo::getGlassId, glassId));
        if (glassInfo == null) {
            log.info("2、此玻璃编号不存在");
            return;
        }
        log.info("2、获取到的玻璃信息为{}", glassInfo);
        //添加进片任务  查找空格
        List<EdgStorageCage> list = edgStorageCageService.selectCacheEmpty();
        log.info("3、查询卧式理片笼里面的空格:{}", list);
        if (CollectionUtil.isEmpty(list)) {
            log.info("4、不存在空格");
            return;
        }
        log.info("4、将玻璃信息插入卧式理片笼:{}", glassInfo);
        EdgStorageCageDetails details = new EdgStorageCageDetails();
        BeanUtils.copyProperties(glassInfo, details);
        details.setState(100);
        Integer slot = list.get(0).getSlot();
        Integer deviceId = list.get(0).getDeviceId();
        log.info("5、获取空闲格子为:{},设备号为{}", slot, deviceId);
        details.setSlot(slot);
        details.setDeviceId(deviceId);
        edgStorageCageDetailsService.save(details);
        log.info("6、生成进片任务信息存入任务表");
        TaskCache taskCache = new TaskCache();
        taskCache.setGlassId(glassId);
        taskCache.setTaskStatus(0);
        taskCache.setStartCell(0);
        taskCache.setEndCell(slot);
        taskCache.setTaskType(1);
        taskCache.setCreateTime(new Date());
        taskCacheService.insertTaskCache(taskCache);
        log.info("6、发送确认字");
        S7object.getinstance().plccontrol.WriteWord(confirmationWrodAddress, (short) 1);
    }
    private void outTo(int line) {
    private void outTo(int line, String confirmationWrodAddress) {
        Assert.isTrue(line != 0, "A09、A10都有玻璃,无法出片");
        log.info("1、出片任务出【{}】号线,备注(09空闲:1;10空闲:2;都空闲:3)", line);
        int endcell = 0;
        EdgStorageCageDetails outEdgStorageCageDetails = new EdgStorageCageDetails();
        TaskCache taskCacheA09 = taskCacheService.selectLastOutCacheInfo("");
        TaskCache taskCacheA10 = taskCacheService.selectLastOutCacheInfo("");
        //两线各自要出的玻璃
        EdgStorageCageDetails glassInfo09 = edgStorageCageDetailsService.selectConformGlass(taskCacheA09.getGlassId(), (int) mapSettings.get("territoryPoor"));
        EdgStorageCageDetails glassInfo10 = edgStorageCageDetailsService.selectConformGlass(taskCacheA10.getGlassId(), (int) mapSettings.get("territoryPoor"));
        //决定线路
        if (line == 1) {
            endcell = 9000;
            outEdgStorageCageDetails = glassInfo09;
        } else if (line == 2) {
            endcell = 1000;
            outEdgStorageCageDetails = glassInfo10;
        } else if (line == 3) {
            endcell = 9000;//默认走一号线  优化方向可根据  对比两线速度/两线当前任务情况做
            outEdgStorageCageDetails = glassInfo09;
        List<TaskCache> oldTaskCacheList;
        log.info("2、判断出片线路,获取最后该条线已出片的任务信息(备注:0待执行,1已执行),都空闲优先出A09线");
        if (line == 2) {
            endcell = 2002;
            oldTaskCacheList = taskCacheService.selectLastOutCacheInfos(Const.A10_OUT_TARGET_POSITION);
        } else {
            endcell = 2001;
            oldTaskCacheList = taskCacheService.selectLastOutCacheInfos(Const.A09_OUT_TARGET_POSITION);
        }
        if (outEdgStorageCageDetails != null && endcell > 0) {
        String glassId = "";
        if (CollectionUtil.isNotEmpty(oldTaskCacheList)) {
            glassId = oldTaskCacheList.get(0).getGlassId();
        }
        log.info("3、按照历史已出玻璃id{}和阈值{},拿出理片笼内的出片信息", glassId, threshold);
        EdgStorageCageDetails glassInfo = edgStorageCageDetailsService.selectConformGlass(glassId, threshold);
        if (glassInfo != null) {
            log.info("4、添加出片任务,玻璃id:{},任务类型:{},起始位置:{},结束位置:{}", glassInfo.getGlassId(),
                    2, glassInfo.getSlot(), endcell);
            TaskCache taskCache = new TaskCache();
            taskCache.setGlassId(outEdgStorageCageDetails.getGlassId());
            taskCache.setGlassId(glassInfo.getGlassId());
            taskCache.setTaskStatus(0);
            taskCache.setStartCell(outEdgStorageCageDetails.getSlot());
            taskCache.setStartCell(glassInfo.getSlot());
            taskCache.setEndCell(endcell);
            taskCache.setTaskType(2);
            taskCache.setCreateTime(new DateTime());
            taskCache.setCreateTime(new Date());
            taskCacheService.insertTaskCache(taskCache);
//            S7object.getinstance().plccontrol.WriteWord(mapParameter.get("MES_confirmation_word"), (short) 1);
            S7object.getinstance().plccontrol.WriteWord(confirmationWrodAddress, (short) 1);
        }
hangzhoumesParent/moduleService/CacheGlassModule/src/main/java/com/mes/taskcache/entity/TaskCache.java
@@ -1,8 +1,9 @@
package com.mes.taskcache.entity;
import cn.hutool.core.date.DateTime;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data;
import java.util.Date;
@Data  //lombok 简写java代码 实体类的get与set
@TableName("task_cache")
@@ -12,6 +13,6 @@
    private int endCell;//结束
    private int taskType;//任务类型
    private int taskStatus;//任务状态
    private DateTime createTime;//任务状态
    private Date createTime;//任务状态
}
hangzhoumesParent/moduleService/CacheGlassModule/src/main/java/com/mes/taskcache/service/impl/TaskCacheServiceImpl.java
@@ -1,18 +1,10 @@
package com.mes.taskcache.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.github.yulichang.query.MPJLambdaQueryWrapper;
import com.github.yulichang.wrapper.MPJLambdaWrapper;
import com.mes.edgstoragecage.entity.EdgStorageCageDetails;
import com.mes.edgstoragecage.mapper.EdgStorageCageDetailsMapper;
import com.mes.glassinfo.entity.GlassInfo;
import com.mes.glassinfo.mapper.GlassInfoMapper;
import com.mes.taskcache.entity.TaskCache;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.yulichang.wrapper.MPJLambdaWrapper;
import com.mes.taskcache.entity.TaskCache;
import com.mes.taskcache.mapper.TaskCacheMapper;
import com.mes.taskcache.service.TaskCacheService;
import com.mes.uppattenusage.entity.UpPattenUsage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
@@ -98,7 +90,7 @@
     */
    @Override
    public List<TaskCache> selectLastOutCacheInfos(String line){
        return baseMapper.selectList(new MPJLambdaWrapper<TaskCache>().selectAll(TaskCache.class).eq(TaskCache::getEndCell,line).eq(TaskCache::getTaskStatus,1).orderByDesc(TaskCache::getGlassId));
        return baseMapper.selectList(new MPJLambdaWrapper<TaskCache>().selectAll(TaskCache.class).eq(TaskCache::getEndCell,line).eq(TaskCache::getTaskStatus,1).orderByDesc(TaskCache::getCreateTime));
//        return baseMapper.selectList(new QueryWrapper<TaskCache>().eq("end_cell",line).eq("task_status",1).orderByDesc("ID"));
    }
@@ -109,7 +101,7 @@
     */
    @Override
    public TaskCache selectLastOutCacheInfo(String line){
        return baseMapper.selectOne(new MPJLambdaWrapper<TaskCache>().selectAll(TaskCache.class).eq(TaskCache::getEndCell,line).eq(TaskCache::getTaskStatus,1).orderByDesc(TaskCache::getGlassId));
        return baseMapper.selectOne(new MPJLambdaWrapper<TaskCache>().selectAll(TaskCache.class).eq(TaskCache::getEndCell,line).eq(TaskCache::getTaskStatus,1).orderByDesc(TaskCache::getCreateTime));
    }
hangzhoumesParent/moduleService/CacheGlassModule/src/main/resources/JsonFile/PlcCacheGlass.json
@@ -1,5 +1,5 @@
{
   "plcAddressBegin":"DB14.0",
   "plcAddressBegin":"DB11.0",
   "plcAddressLenght":"80",
   "dataType":"word",
   "parameteInfor":[
@@ -19,28 +19,28 @@
       },
       {
          "codeId": "MES_confirmation_word",
          "addressIndex":"40",
          "addressIndex":"38",
          "addressLenght":"2",
          "ratio":"1",
          "unit":""
       },
       {
          "codeId": "A09_glass_status",
          "addressIndex":"70",
          "addressIndex":"68",
          "addressLenght":"2",
          "ratio":"1",
          "unit":""
       },
       {
          "codeId": "A10_glass_status",
          "addressIndex":"72",
          "addressIndex":"70",
          "addressLenght":"2",
          "ratio":"1",
          "unit":""
       },
       {
          "codeId": "A09_prohibit_film_production",
          "addressIndex":"74",
          "addressIndex":"72",
          "addressLenght":"2",
          "ratio":"1",
          "unit":""
@@ -48,7 +48,7 @@
       ,
       {
          "codeId": "A10_prohibit_film_production",
          "addressIndex":"76",
          "addressIndex":"74",
          "addressLenght":"2",
          "ratio":"1",
          "unit":""
hangzhoumesParent/moduleService/CacheGlassModule/src/main/resources/application.yml
@@ -10,3 +10,5 @@
  mapper-locations: classpath*:mapper/*.xml
  configuration:
    log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
mes:
  threshold: 3