From f73f8cb6753f8d8ab2c689b4640cd2688e6f6f62 Mon Sep 17 00:00:00 2001 From: Lius <Lius2225@163.com> Date: 星期二, 16 九月 2025 11:06:42 +0800 Subject: [PATCH] update --- lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/webservice/impl/EquipmentWebServiceImpl.java | 113 ++++++++++++++++++++++++++++++++++++++++++-------------- 1 files changed, 84 insertions(+), 29 deletions(-) diff --git a/lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/webservice/impl/EquipmentWebServiceImpl.java b/lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/webservice/impl/EquipmentWebServiceImpl.java index 26d8c68..4465b98 100644 --- a/lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/webservice/impl/EquipmentWebServiceImpl.java +++ b/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瑙f瀽澶辫触"); - 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. 鏁版嵁瑙f瀽涓庢牎楠� + List<EquipmentDaySchedule> equipmentDayScheduleList; + try { + equipmentDayScheduleList = JSONObject.parseArray(msg, EquipmentDaySchedule.class); + if (CollectionUtils.isEmpty(equipmentDayScheduleList)) { + return buildErrorResult("鏁版嵁涓虹┖鎴栬В鏋愬け璐�"); + } + } catch (Exception e) { + log.error("JSON瑙f瀽寮傚父", 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. 鎸塵esId鎵归噺淇濆瓨鎴栨洿鏂� + 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瑙f瀽澶辫触"); - return JSONObject.toJSONString(wsResult); + + // 1. 鏁版嵁瑙f瀽涓庢牎楠� + List<EquipmentDaySummary> equipmentDaySummaryList; + + try { + equipmentDaySummaryList = JSONObject.parseArray(msg, EquipmentDaySummary.class); + if (CollectionUtils.isEmpty(equipmentDaySummaryList)) { + return buildErrorResult("鏁版嵁涓虹┖鎴栬В鏋愬け璐�"); + } + } catch (Exception e) { + log.error("JSON瑙f瀽寮傚父", 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. 鎸塵esId鎵归噺淇濆瓨鎴栨洿鏂� + 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); + } } -- Gitblit v1.9.3