wangfei
昨天 7e5796e4813bb1f4d2696a0fd05f408147c3b96e
hangzhoumesParent/common/servicebase/src/main/java/com/mes/temperingglass/service/impl/TemperingGlassInfoServiceImpl.java
@@ -1,15 +1,26 @@
package com.mes.temperingglass.service.impl;
import com.baomidou.dynamic.datasource.annotation.DS;
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.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.github.yulichang.base.MPJBaseServiceImpl;
import com.github.yulichang.query.MPJQueryWrapper;
import com.kangaroohy.milo.model.ReadWriteEntity;
import com.kangaroohy.milo.service.MiloService;
import com.mes.glassinfo.entity.GlassInfo;
import com.mes.glassinfo.entity.LoadGlassInfo;
import com.mes.glassinfo.mapper.GlassInfoMapper;
import com.mes.largenscreen.entity.PieChartVO;
import com.mes.temperingglass.entity.TemperingGlassInfo;
import com.mes.temperingglass.mapper.TemperingGlassInfoMapper;
import com.mes.temperingglass.service.TemperingGlassInfoService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.github.yulichang.base.MPJBaseServiceImpl;
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;
/**
@@ -21,23 +32,60 @@
 * @since 2024-04-07
 */
@Service
@DS("salve_hangzhoumes")
@DS("north_glass_mes")
@Slf4j
public class TemperingGlassInfoServiceImpl extends MPJBaseServiceImpl<TemperingGlassInfoMapper, TemperingGlassInfo> implements TemperingGlassInfoService {
    @Autowired
    @Resource
    TemperingGlassInfoMapper temperingMapper;
    @Resource
    private GlassInfoMapper glassInfoMapper;
    @Autowired(required = false)
    MiloService miloService;
    @Override
    public List<TemperingGlassInfo> selectWaitingGlassByOpc() {
        //获取等待进炉中的玻璃信息
        try {
            ReadWriteEntity engineerEntity = miloService.readFromOpcUa("GH2S7.GH2S7.F09_ENGINEER_ID");
            ReadWriteEntity temperingLayoutIdEntity = miloService.readFromOpcUa("GH2S7.GH2S7.F09_TEMPERING_LAYOUT_ID");
            if (null == engineerEntity || null == temperingLayoutIdEntity) {
                engineerEntity = miloService.readFromOpcUa("GH2S7.GH2S7.F08_ENGINEER_ID");
                temperingLayoutIdEntity = miloService.readFromOpcUa("GH2S7.GH2S7.F08_TEMPERING_LAYOUT_ID");
                if (null == engineerEntity || null == temperingLayoutIdEntity) {
                    log.info("获取参数异常,结束本次任务");
                    return new ArrayList<>();
                }
            }
            return this.list(new LambdaQueryWrapper<TemperingGlassInfo>()
                    .eq(TemperingGlassInfo::getEngineerId, engineerEntity.getValue() + "")
                    .eq(TemperingGlassInfo::getTemperingLayoutId, temperingLayoutIdEntity.getValue() + ""));
        } catch (Exception e) {
            log.info("获取钢化参数异常:{}", e);
            return new ArrayList<>();
        }
    }
    @Override
    public List<TemperingGlassInfo> selectWaitingGlass() {
        //获取等待进炉中的玻璃信息
        QueryWrapper<TemperingGlassInfo> wrapper = new QueryWrapper<>();
        wrapper.select("Top 1 *").in("state",1,0);
        TemperingGlassInfo glass=temperingMapper.selectOne(wrapper);
        if(glass!=null) {
        wrapper.select("Top 1 *").in("state", 1, 0).orderByDesc("id");
        TemperingGlassInfo glass = temperingMapper.selectOne(wrapper);
        if (glass != null) {
            this.update(new LambdaUpdateWrapper<TemperingGlassInfo>().set(TemperingGlassInfo::getState, 2).in(TemperingGlassInfo::getState, 0, 1)
                    .and(e -> e.ne(TemperingGlassInfo::getEngineerId, glass.getEngineerId())
                            .or(e1 -> e1.eq(TemperingGlassInfo::getEngineerId, glass.getEngineerId())
                                    .ne(TemperingGlassInfo::getTemperingLayoutId, glass.getTemperingLayoutId()))));
            QueryWrapper<TemperingGlassInfo> glassinfo = new QueryWrapper<>();
            glassinfo.eq("engineer_id", glass.getEngineerId())
                    .eq("tempering_layout_id", glass.getTemperingLayoutId());
            return temperingMapper.selectList(glassinfo);
        }else {
            //return temperingMapper.selectList(glassinfo);
            return temperingMapper.selectByEngineerIdAndLayoutId(glass.getEngineerId(), glass.getTemperingLayoutId());
        } else {
            return null;
        }
    }
@@ -45,28 +93,27 @@
    @Override
    public List<TemperingGlassInfo> selectIntoGlass(TemperingGlassInfo temperingGlassInfo) {
        //获取进炉中的玻璃信息
        QueryWrapper<TemperingGlassInfo> wrapper = new QueryWrapper<>();
        wrapper.eq("tempering_layout_id", temperingGlassInfo.getTemperingLayoutId())
                .eq("engineer_id", temperingGlassInfo.getEngineerId())
                .orderByAsc("tempering_layout_id","tempering_feed_sequence");
        return temperingMapper.selectList(wrapper);
//        QueryWrapper<TemperingGlassInfo> wrapper = new QueryWrapper<>();
//        wrapper.eq("tempering_layout_id", temperingGlassInfo.getTemperingLayoutId())
//                .eq("engineer_id", temperingGlassInfo.getEngineerId())
//                .orderByAsc("tempering_layout_id","tempering_feed_sequence");
//        return temperingMapper.selectList(wrapper);
        return temperingMapper.selectByEngineerIdAndLayoutId(temperingGlassInfo.getEngineerId(), temperingGlassInfo.getTemperingLayoutId());
    }
    @Override
    public List<TemperingGlassInfo> selectOutGlass() {
        //获取出炉中的玻璃信息
        QueryWrapper<TemperingGlassInfo> wrap = new QueryWrapper<>();
        wrap.select("Top 1 *").eq("state",3);
        TemperingGlassInfo glass=temperingMapper.selectOne(wrap);
        wrap.select("Top 1 *").eq("state", 4)
                .orderByDesc("id");
        TemperingGlassInfo glass = temperingMapper.selectOne(wrap);
        //根据工程号和版图获取数据
        if(glass != null) {
            QueryWrapper<TemperingGlassInfo> wapper = new QueryWrapper<>();
            wapper.eq("engineer_id", glass.getEngineerId())
                    .eq("tempering_layout_id", glass.getTemperingLayoutId())
                    .orderByAsc("tempering_layout_id", "tempering_feed_sequence");
            return temperingMapper.selectList(wapper);
        if (glass != null) {
            return temperingMapper.selectByEngineerIdAndLayoutId(glass.getEngineerId(), glass.getTemperingLayoutId());
        }
            return  null;
        return null;
    }
    @Override
@@ -74,30 +121,28 @@
        //获取过旋转台最大的钢化版图id
        QueryWrapper<TemperingGlassInfo> wapper = new QueryWrapper<>();
        wapper.select("Top 1 *").eq("state", 4)
                .orderByDesc("tempering_layout_id,engineer_id");
                .orderByDesc("id");
        //根据最大的版图id显示钢化后的版图信息
        TemperingGlassInfo glassinfo= temperingMapper.selectOne(wapper);
        TemperingGlassInfo glassinfo = temperingMapper.selectOne(wapper);
        if (glassinfo == null) {
            return null;  // 直接返回null,表示没有找到符合条件的记录
        }
        QueryWrapper<TemperingGlassInfo> wrapper = new QueryWrapper<>();
        wrapper.eq("tempering_layout_id",glassinfo.getTemperingLayoutId())
                .eq("engineer_id",glassinfo.getEngineerId());
        return temperingMapper.selectByEngineerIdAndLayoutId(glassinfo.getEngineerId(), glassinfo.getTemperingLayoutId());
        return  temperingMapper.selectList(wrapper);
    }
    @Override
    public List<TemperingGlassInfo> selectLayoutId() {
        QueryWrapper<TemperingGlassInfo> wrapper = new QueryWrapper<>();
        wrapper.select("distinct tempering_layout_id,engineer_id")
                .eq("state",2)
                .orderByAsc("tempering_layout_id");
        wrapper.select("tempering_layout_id,engineer_id,max(id) as id")
                .eq("state", 2)
                .groupBy("tempering_layout_id,engineer_id")
                .orderByAsc("id");
        return temperingMapper.selectList(wrapper);
    }
    @Override
        public List<TemperingGlassInfo> selectTaskType() {
    public List<TemperingGlassInfo> selectTaskType() {
        QueryWrapper<TemperingGlassInfo> wrapper = new QueryWrapper<>();
        wrapper.select("state")
                .groupBy("state");
@@ -106,14 +151,60 @@
    @Override
    public Integer updateTemperingState(TemperingGlassInfo temperingGlassInfo) {
        UpdateWrapper<TemperingGlassInfo> wrapper = new UpdateWrapper<>();
        wrapper.eq("glass_id",temperingGlassInfo.getGlassId())
                .lt("state",6)
                .set("state", temperingGlassInfo.getState());;
        if (temperingMapper.update(null,wrapper) > 0) {
        if (temperingMapper.updateTemperingGlassInfo(temperingGlassInfo) > 0) {
            return 200;
        }else {
        } else {
            return 100;
        }
    }
    @Override
    public List<TemperingGlassInfo> selectGlassInfoById(Integer id) {
        List<TemperingGlassInfo> result = null;
        QueryWrapper<TemperingGlassInfo> wrapper = new QueryWrapper<>();
        wrapper.select("Top 1 *").in("state", 1, 0).eq("tempering_layout_id", id);
        TemperingGlassInfo glass = temperingMapper.selectOne(wrapper);
        if (glass != null) {
            QueryWrapper<TemperingGlassInfo> glassinfo = new QueryWrapper<>();
            glassinfo.eq("engineer_id", glass.getEngineerId())
                    .eq("tempering_layout_id", id)
                    .orderByDesc("tempering_layout_id")
                    .orderByAsc("tempering_feed_sequence");
            return temperingMapper.selectList(glassinfo);
//            result= temperingMapper.selectByEngineerIdAndLayoutId(glass.getEngineerId(),glass.getTemperingLayoutId());
        }
        return result;
    }
    @Override
    public GlassInfo selectTempering(GlassInfo glassInfo) {
        QueryWrapper<GlassInfo> wrapper = new QueryWrapper<>();
        wrapper.select("max(tempering_layout_id)as id")
                .eq("engineer_id", glassInfo.getEngineerId());
        return glassInfoMapper.selectOne(wrapper);
    }
    @Override
    public List<LoadGlassInfo> selectTemperingGlass(GlassInfo glassInfo) {
        List<LoadGlassInfo> glassInfos = null;
        glassInfos = glassInfoMapper.selectJoinList(LoadGlassInfo.class, new MPJQueryWrapper<GlassInfo>()
                .select("IFNULL(b.state, 0) AS state,engineer_id,tempering_layout_id,width,height,tempering_feed_sequence,x_coordinate,y_coordinate,angle,t.glass_id,t.flow_card_id")
                .leftJoin("(SELECT glass_id, MAX(type) AS state FROM damage GROUP BY glass_id) b\n" +
                        "ON t.glass_id = b.glass_id")
                .eq("engineer_id", glassInfo.getEngineerId())
                .eq("tempering_layout_id", glassInfo.getTemperingLayoutId()));
        return glassInfos;
//        QueryWrapper<GlassInfo> wrapper = new QueryWrapper<>();
//        wrapper.eq("engineer_id", glassInfo.getEngineerId())
//                .eq("tempering_layout_id", glassInfo.getTemperingLayoutId())
//                .select("engineer_id,tempering_layout_id,width,height,tempering_feed_sequence,x_coordinate,y_coordinate,angle,glass_id");
//        return glassInfoMapper.selectList(wrapper);
    }
    @Override
    public List<PieChartVO> queryPieChart() {
        return baseMapper.queryPieChart();
    }
}