Lius
昨天 f73f8cb6753f8d8ab2c689b4640cd2688e6f6f62
update
已修改8个文件
226 ■■■■ 文件已修改
lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/mapper/xml/MdcEquipmentMapper.xml 6 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/service/IMdcEquipmentDayScheduleService.java 4 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/service/IMdcEquipmentDaySummaryService.java 4 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/service/impl/LogTableServiceImpl.java 4 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/service/impl/MdcEquipmentDayScheduleServiceImpl.java 46 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/service/impl/MdcEquipmentDaySummaryServiceImpl.java 48 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/vo/MdcEquipmentVo.java 1 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/webservice/impl/EquipmentWebServiceImpl.java 113 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/mapper/xml/MdcEquipmentMapper.xml
@@ -218,6 +218,12 @@
            <if test="mdcEquipment.deviceCategory != null and mdcEquipment.deviceCategory != '' ">
                AND t1.device_category = #{mdcEquipment.deviceCategory}
            </if>
            <if test="mdcEquipment.equipmentStatus != null ">
                AND t1.equipment_status = #{mdcEquipment.equipmentStatus}
            </if>
            <if test="mdcEquipment.attribute != null ">
                AND t1.attribute = #{mdcEquipment.attribute}
            </if>
            <if test="mdcEquipment.productionIds != null and mdcEquipment.productionIds.size() > 0 ">
                AND t3.id IN
                <foreach collection="mdcEquipment.productionIds" index="index" item="id" open="(" separator="," close=")">
lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/service/IMdcEquipmentDayScheduleService.java
@@ -6,9 +6,13 @@
import org.jeecg.modules.mdc.entity.MdcEquipmentDaySchedule;
import org.jeecg.modules.mdc.vo.MdcEquipmentDayScheduleVo;
import java.util.List;
public interface IMdcEquipmentDayScheduleService extends IService<MdcEquipmentDaySchedule> {
    IPage<MdcEquipmentDaySchedule> pageList(MdcEquipmentDayScheduleVo mdcEquipmentDayScheduleVo, Page<MdcEquipmentDaySchedule> page);
    MdcEquipmentDaySchedule selectLast(String equipmentId);
    boolean saveOrUpdateBatchByMesId(List<MdcEquipmentDaySchedule> mdcList);
}
lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/service/IMdcEquipmentDaySummaryService.java
@@ -3,7 +3,11 @@
import com.baomidou.mybatisplus.extension.service.IService;
import org.jeecg.modules.mdc.entity.MdcEquipmentDaySummary;
import java.util.List;
public interface IMdcEquipmentDaySummaryService extends IService<MdcEquipmentDaySummary> {
    MdcEquipmentDaySummary statisticsQty(String productionId);
    boolean saveOrUpdateBatchByMesId(List<MdcEquipmentDaySummary> mdcList);
}
lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/service/impl/LogTableServiceImpl.java
@@ -107,8 +107,6 @@
            // 文件路径
            String locFilePath = localFilePath + TYPE + today + String.format("%06d", sequenceNumber) + ".xml";
//            FileWriter writer = new FileWriter(locFilePath);
//            writer.writeLines(sqlList);
            String listSql = String.join("\n", sqlList);
            try {
                FileUtils.fileWriterSql(locFilePath, listSql);
@@ -226,7 +224,6 @@
                        sqlExecutor.execute(sql);
                    } catch (Exception e) {
                        failedSqlList.add(sql);
//                        throw new JeecgBootException("执行sql失败!");
                    }
                }
                if (!failedSqlList.isEmpty()) {
@@ -236,7 +233,6 @@
                        throw new JeecgBootException("数据写入文件失败!");
                    }
                }
//                String sqlList = fileReader.readString();
                if (Integer.parseInt(file.getName().substring(file.getName().length() - 10, file.getName().length() - 4)) == 1) {
                    // 删除历史文件
lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/service/impl/MdcEquipmentDayScheduleServiceImpl.java
@@ -1,6 +1,7 @@
package org.jeecg.modules.mdc.service.impl;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.jeecg.modules.mdc.entity.MdcEquipmentDaySchedule;
@@ -9,11 +10,17 @@
import org.jeecg.modules.mdc.vo.MdcEquipmentDayScheduleVo;
import org.jeecg.modules.system.entity.MdcProduction;
import org.jeecg.modules.system.service.IMdcProductionService;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
/**
 * @Author: Lius
@@ -52,4 +59,43 @@
    public MdcEquipmentDaySchedule selectLast(String equipmentId) {
        return this.baseMapper.selectLast(equipmentId);
    }
    @Override
    @Transactional(rollbackFor = Exception.class)
    public boolean saveOrUpdateBatchByMesId(List<MdcEquipmentDaySchedule> entityList) {
        if (CollectionUtils.isEmpty(entityList)) {
            return true;
        }
        // 按mesId分组处理
        Map<String, MdcEquipmentDaySchedule> mesIdMap = entityList.stream()
                .collect(Collectors.toMap(MdcEquipmentDaySchedule::getMesId,
                        mdcEquipmentDaySchedule -> mdcEquipmentDaySchedule,       // 值:用户对象本身
                        (existing, replacement) -> existing));
        // 批量查询已存在的mesId
        List<MdcEquipmentDaySchedule> existList = this.lambdaQuery()
                .in(MdcEquipmentDaySchedule::getMesId, mesIdMap.keySet())
                .list();
        // 分离需要新增和更新的数据
        List<MdcEquipmentDaySchedule> toInsert = new ArrayList<>();
        List<MdcEquipmentDaySchedule> toUpdate = new ArrayList<>();
        existList.forEach(exist -> {
            MdcEquipmentDaySchedule newData = mesIdMap.get(exist.getMesId());
            // 保留原ID
            BeanUtils.copyProperties(newData, exist);
            toUpdate.add(exist);
            mesIdMap.remove(exist.getMesId());
        });
        toInsert.addAll(mesIdMap.values());
        // 执行批量操作
        boolean insertResult = toInsert.isEmpty() || this.saveBatch(toInsert);
        boolean updateResult = toUpdate.isEmpty() || this.updateBatchById(toUpdate);
        return insertResult && updateResult;
    }
}
lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/service/impl/MdcEquipmentDaySummaryServiceImpl.java
@@ -1,10 +1,18 @@
package org.jeecg.modules.mdc.service.impl;
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.jeecg.modules.mdc.entity.MdcEquipmentDaySummary;
import org.jeecg.modules.mdc.mapper.MdcEquipmentDaySummaryMapper;
import org.jeecg.modules.mdc.service.IMdcEquipmentDaySummaryService;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
/**
 * @Author: Lius
@@ -17,4 +25,44 @@
    public MdcEquipmentDaySummary statisticsQty(String productionId) {
        return this.baseMapper.statisticsQty(productionId);
    }
    @Override
    @Transactional(rollbackFor = Exception.class)
    public boolean saveOrUpdateBatchByMesId(List<MdcEquipmentDaySummary> entityList) {
        if (CollectionUtils.isEmpty(entityList)) {
            return true;
        }
        // 按mesId分组处理
        Map<String, MdcEquipmentDaySummary> mesIdMap = entityList.stream()
                .collect(Collectors.toMap(MdcEquipmentDaySummary::getMesId,
                        mdcEquipmentDaySummary -> mdcEquipmentDaySummary,       // 值:用户对象本身
                        (existing, replacement) -> existing));
        // 批量查询已存在的mesId
        List<MdcEquipmentDaySummary> existList = this.lambdaQuery()
                .in(MdcEquipmentDaySummary::getMesId, mesIdMap.keySet())
                .list();
        // 分离需要新增和更新的数据
        List<MdcEquipmentDaySummary> toInsert = new ArrayList<>();
        List<MdcEquipmentDaySummary> toUpdate = new ArrayList<>();
        existList.forEach(exist -> {
            MdcEquipmentDaySummary newData = mesIdMap.get(exist.getMesId());
            // 保留原ID
            BeanUtils.copyProperties(newData, exist);
            toUpdate.add(exist);
            mesIdMap.remove(exist.getMesId());
        });
        toInsert.addAll(mesIdMap.values());
        // 执行批量操作
        boolean insertResult = toInsert.isEmpty() || this.saveBatch(toInsert);
        boolean updateResult = toUpdate.isEmpty() || this.updateBatchById(toUpdate);
        return insertResult && updateResult;
    }
}
lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/vo/MdcEquipmentVo.java
@@ -21,5 +21,6 @@
    private String deviceCategory;
    private String driveType;
    private String productionName;
    private String attribute;
    private List<String> productionIds;
}
lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/webservice/impl/EquipmentWebServiceImpl.java
@@ -1,6 +1,7 @@
package org.jeecg.modules.mdc.webservice.impl;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
import lombok.extern.slf4j.Slf4j;
import org.jeecg.modules.mdc.entity.MdcEquipmentDaySchedule;
import org.jeecg.modules.mdc.entity.MdcEquipmentDaySummary;
@@ -15,8 +16,8 @@
import javax.annotation.Resource;
import javax.jws.WebService;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
/**
@@ -40,41 +41,95 @@
    @Override
    public String equipmentDaySchedule(String msg) {
        log.info("接收MES上报日计划原始数据 === {}", msg);
        List<EquipmentDaySchedule> equipmentDayScheduleList = JSONObject.parseArray(msg, EquipmentDaySchedule.class);
        if (equipmentDayScheduleList == null || equipmentDayScheduleList.isEmpty()) {
            WsResult wsResult = new WsResult("0", "json解析失败");
            return JSONObject.toJSONString(wsResult);
        }
        List<MdcEquipmentDaySchedule> mdcEquipmentDayScheduleList = new ArrayList<>();
        for (EquipmentDaySchedule equipmentDaySchedule : equipmentDayScheduleList) {
            MdcEquipmentDaySchedule mdcEquipmentDaySchedule = new MdcEquipmentDaySchedule();
            BeanUtils.copyProperties(equipmentDaySchedule, mdcEquipmentDaySchedule);
            mdcEquipmentDayScheduleList.add(mdcEquipmentDaySchedule);
        }
        mdcEquipmentDayScheduleService.saveBatch(mdcEquipmentDayScheduleList);
        log.info("接收MES上报日计划数据成功!");
        WsResult wsResult = new WsResult("1", "成功");
        return JSONObject.toJSONString(wsResult);
        // 1. 数据解析与校验
        List<EquipmentDaySchedule> equipmentDayScheduleList;
        try {
            equipmentDayScheduleList = JSONObject.parseArray(msg, EquipmentDaySchedule.class);
            if (CollectionUtils.isEmpty(equipmentDayScheduleList)) {
                return buildErrorResult("数据为空或解析失败");
            }
        } catch (Exception e) {
            log.error("JSON解析异常", e);
            return buildErrorResult("数据格式错误");
        }
        // 2. 数据转换
        List<MdcEquipmentDaySchedule> mdcList = equipmentDayScheduleList.stream()
                .map(source -> {
                    MdcEquipmentDaySchedule target = new MdcEquipmentDaySchedule();
                    BeanUtils.copyProperties(source, target);
                    return target;
                })
                .collect(Collectors.toList());
        // 3. 按mesId批量保存或更新
        try {
            boolean result = mdcEquipmentDayScheduleService.saveOrUpdateBatchByMesId(mdcList);
            if (!result) {
                log.error("部分数据保存失败");
                return buildErrorResult("部分数据保存失败");
            }
            log.info("成功处理{}条日计划数据", mdcList.size());
            return buildSuccessResult();
        } catch (Exception e) {
            log.error("日计划数据保存异常", e);
            return buildErrorResult("系统处理异常");
        }
    }
    // 构建成功响应
    private String buildSuccessResult() {
        return JSONObject.toJSONString(new WsResult("1", "成功"));
    }
    // 构建错误响应
    private String buildErrorResult(String message) {
        return JSONObject.toJSONString(new WsResult("0", message));
    }
    @Override
    public String equipmentDaySummary(String msg) {
        log.info("接收MES上报日汇总原始数据 === {}", msg);
        List<EquipmentDaySummary> equipmentDaySummaryList = JSONObject.parseArray(msg, EquipmentDaySummary.class);
        if (equipmentDaySummaryList == null || equipmentDaySummaryList.isEmpty()) {
            WsResult wsResult = new WsResult("0", "json解析失败");
            return JSONObject.toJSONString(wsResult);
        // 1. 数据解析与校验
        List<EquipmentDaySummary> equipmentDaySummaryList;
        try {
            equipmentDaySummaryList = JSONObject.parseArray(msg, EquipmentDaySummary.class);
            if (CollectionUtils.isEmpty(equipmentDaySummaryList)) {
                return buildErrorResult("数据为空或解析失败");
            }
        } catch (Exception e) {
            log.error("JSON解析异常", e);
            return buildErrorResult("数据格式错误");
        }
        List<MdcEquipmentDaySummary> mdcEquipmentDaySummaryList = new ArrayList<>();
        for (EquipmentDaySummary equipmentDaySummary : equipmentDaySummaryList) {
            MdcEquipmentDaySummary mdcEquipmentDaySummary = new MdcEquipmentDaySummary();
            BeanUtils.copyProperties(equipmentDaySummary, mdcEquipmentDaySummary);
            mdcEquipmentDaySummaryList.add(mdcEquipmentDaySummary);
        // 2. 数据转换
        List<MdcEquipmentDaySummary> mdcList = equipmentDaySummaryList.stream()
                .map(source -> {
                    MdcEquipmentDaySummary target = new MdcEquipmentDaySummary();
                    BeanUtils.copyProperties(source, target);
                    return target;
                })
                .collect(Collectors.toList());
        // 3. 按mesId批量保存或更新
        try {
            boolean result = mdcEquipmentDaySummaryService.saveOrUpdateBatchByMesId(mdcList);
            if (!result) {
                log.error("部分数据保存失败");
                return buildErrorResult("部分数据保存失败");
            }
            log.info("成功处理{}条日计划数据", mdcList.size());
            return buildSuccessResult();
        } catch (Exception e) {
            log.error("日计划数据保存异常", e);
            return buildErrorResult("系统处理异常");
        }
        mdcEquipmentDaySummaryService.saveBatch(mdcEquipmentDaySummaryList);
        log.info("接收MES上报日汇总数据成功!");
        WsResult wsResult = new WsResult("1", "成功");
        return JSONObject.toJSONString(wsResult);
    }
}