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 | 104 ++++++++++++++++++++++++++++++++++++++++++++-------- 1 files changed, 88 insertions(+), 16 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 21e1507..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,6 +16,8 @@ import javax.annotation.Resource; import javax.jws.WebService; +import java.util.List; +import java.util.stream.Collectors; /** @@ -37,27 +40,96 @@ @Override public String equipmentDaySchedule(String msg) { - log.info("MES涓婃姤鏃ヨ鍒掑師濮嬫暟鎹� === {}", msg); - EquipmentDaySchedule equipmentDaySchedule = JSONObject.parseObject(msg, EquipmentDaySchedule.class); - MdcEquipmentDaySchedule mdcEquipmentDaySchedule = new MdcEquipmentDaySchedule(); - BeanUtils.copyProperties(equipmentDaySchedule, mdcEquipmentDaySchedule); - mdcEquipmentDayScheduleService.save(mdcEquipmentDaySchedule); + log.info("鎺ユ敹MES涓婃姤鏃ヨ鍒掑師濮嬫暟鎹� === {}", msg); - 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); - EquipmentDaySummary equipmentDaySummary = JSONObject.parseObject(msg, EquipmentDaySummary.class); - MdcEquipmentDaySummary mdcEquipmentDaySummary = new MdcEquipmentDaySummary(); - BeanUtils.copyProperties(equipmentDaySummary, mdcEquipmentDaySummary); - mdcEquipmentDaySummaryService.save(mdcEquipmentDaySummary); + log.info("鎺ユ敹MES涓婃姤鏃ユ眹鎬诲師濮嬫暟鎹� === {}", msg); - log.info("MES涓婃姤鏃ユ眹鎬绘暟鎹垚鍔燂紒"); - WsResult wsResult = new WsResult("1", "鎴愬姛"); - 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("鏁版嵁鏍煎紡閿欒"); + } + + // 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("绯荤粺澶勭悊寮傚父"); + } + } } -- Gitblit v1.9.3