Commit 5223744b authored by wanghao's avatar wanghao

1 上传MES后 失败记录记录;

2 失败记录可以再重新上传,上传后记录成功多少,失败多少
parent debf3249
package com.zehong.web.controller.equipment;
import com.zehong.common.core.controller.BaseController;
import com.zehong.common.core.domain.AjaxResult;
import com.zehong.common.core.page.TableDataInfo;
import com.zehong.common.utils.poi.ExcelUtil;
import com.zehong.system.domain.PalletDeviceUploadHistory;
import com.zehong.system.service.IPalletDeviceUploadHistoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;
/**
* 未上传成功的历史数据列Controller
*
* @author zehong
* @date 2025-11-24
*/
@RestController
@RequestMapping("/palletDevice/binding/history")
public class PalletDeviceUploadHistoryController extends BaseController
{
@Autowired
private IPalletDeviceUploadHistoryService palletDeviceUploadHistoryService;
/**
* 查询未上传成功的历史数据列列表
*/
@GetMapping("/list")
public TableDataInfo list(PalletDeviceUploadHistory palletDeviceUploadHistory)
{
startPage();
List<PalletDeviceUploadHistory> list = palletDeviceUploadHistoryService.selectPalletDeviceUploadHistoryList(palletDeviceUploadHistory);
return getDataTable(list);
}
/**
* 导出未上传成功的历史数据列列表
*/
@GetMapping("/export")
public AjaxResult export(PalletDeviceUploadHistory palletDeviceUploadHistory)
{
List<PalletDeviceUploadHistory> list = palletDeviceUploadHistoryService.selectPalletDeviceUploadHistoryList(palletDeviceUploadHistory);
ExcelUtil<PalletDeviceUploadHistory> util = new ExcelUtil<PalletDeviceUploadHistory>(PalletDeviceUploadHistory.class);
return util.exportExcel(list, "未上传成功的历史数据列数据");
}
/**
* 获取未上传成功的历史数据列详细信息
*/
@GetMapping(value = "/{id}")
public AjaxResult getInfo(@PathVariable("id") Long id)
{
return AjaxResult.success(palletDeviceUploadHistoryService.selectPalletDeviceUploadHistoryById(id));
}
/**
* 新增未上传成功的历史数据列
*/
@PostMapping
public AjaxResult add(@RequestBody PalletDeviceUploadHistory palletDeviceUploadHistory)
{
return toAjax(palletDeviceUploadHistoryService.insertPalletDeviceUploadHistory(palletDeviceUploadHistory));
}
/**
* 重新上传
*/
@GetMapping("/handleReUpload")
public AjaxResult handleReUpload(){
return palletDeviceUploadHistoryService.handleReUpload();
}
/**
* 修改未上传成功的历史数据列
*/
@PutMapping
public AjaxResult edit(@RequestBody PalletDeviceUploadHistory palletDeviceUploadHistory)
{
return toAjax(palletDeviceUploadHistoryService.updatePalletDeviceUploadHistory(palletDeviceUploadHistory));
}
/**
* 删除未上传成功的历史数据列
*/
@DeleteMapping("/{ids}")
public AjaxResult remove(@PathVariable Long[] ids)
{
return toAjax(palletDeviceUploadHistoryService.deletePalletDeviceUploadHistoryByIds(ids));
}
}
package com.zehong.common.utils.http;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.ConnectException;
import java.net.SocketTimeoutException;
import java.net.URL;
import java.net.URLConnection;
import java.io.*;
import java.net.*;
import java.nio.charset.StandardCharsets;
import java.security.cert.X509Certificate;
import javax.net.ssl.HostnameVerifier;
import javax.net.ssl.HttpsURLConnection;
......@@ -108,72 +102,69 @@ public class HttpUtils
* 向指定 URL 发送POST方法的请求
*
* @param url 发送请求的 URL
* @param param 请求参数,请求参数应该是 name1=value1&name2=value2 的形式。
* @param jsonParam 请求参数,请求参数应该是 name1=value1&name2=value2 的形式。
* @return 所代表远程资源的响应结果
*/
public static String sendPost(String url, String param)
{
PrintWriter out = null;
public static String sendPost(String url, String jsonParam) {
HttpURLConnection conn = null;
BufferedReader in = null;
StringBuilder result = new StringBuilder();
try
{
String urlNameString = url;
log.info("sendPost - {}", urlNameString);
URL realUrl = new URL(urlNameString);
URLConnection conn = realUrl.openConnection();
conn.setRequestProperty("accept", "*/*");
conn.setRequestProperty("connection", "Keep-Alive");
conn.setRequestProperty("user-agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1;SV1)");
conn.setRequestProperty("Accept-Charset", "utf-8");
conn.setRequestProperty("contentType", "utf-8");
try {
URL realUrl = new URL(url);
conn = (HttpURLConnection) realUrl.openConnection();
// 设置连接参数
conn.setRequestMethod("POST");
conn.setRequestProperty("Content-Type", "application/json; charset=utf-8");
conn.setRequestProperty("Accept", "application/json");
conn.setRequestProperty("User-Agent", "Mozilla/5.0");
conn.setDoOutput(true);
conn.setDoInput(true);
out = new PrintWriter(conn.getOutputStream());
out.print(param);
out.flush();
in = new BufferedReader(new InputStreamReader(conn.getInputStream(), "utf-8"));
String line;
while ((line = in.readLine()) != null)
{
result.append(line);
conn.setConnectTimeout(5000);
conn.setReadTimeout(30000);
// 发送请求体
try (OutputStream os = conn.getOutputStream();
OutputStreamWriter osw = new OutputStreamWriter(os, StandardCharsets.UTF_8)) {
osw.write(jsonParam);
osw.flush();
}
log.info("recv - {}", result);
}
catch (ConnectException e)
{
log.error("调用HttpUtils.sendPost ConnectException, url=" + url + ",param=" + param, e);
}
catch (SocketTimeoutException e)
{
log.error("调用HttpUtils.sendPost SocketTimeoutException, url=" + url + ",param=" + param, e);
}
catch (IOException e)
{
log.error("调用HttpUtils.sendPost IOException, url=" + url + ",param=" + param, e);
}
catch (Exception e)
{
log.error("调用HttpsUtil.sendPost Exception, url=" + url + ",param=" + param, e);
}
finally
{
try
{
if (out != null)
{
out.close();
// 读取响应
int responseCode = conn.getResponseCode();
if (responseCode == HttpURLConnection.HTTP_OK) {
in = new BufferedReader(new InputStreamReader(conn.getInputStream(), StandardCharsets.UTF_8));
String line;
while ((line = in.readLine()) != null) {
result.append(line);
}
if (in != null)
{
} else {
// 读取错误流
in = new BufferedReader(new InputStreamReader(conn.getErrorStream(), StandardCharsets.UTF_8));
String line;
while ((line = in.readLine()) != null) {
result.append(line);
}
log.error("HTTP error code: {}, response: {}", responseCode, result);
}
} catch (Exception e) {
log.error("调用HttpUtils.sendPost Exception, url=" + url + ",param=" + jsonParam, e);
throw new RuntimeException("HTTP请求失败: " + e.getMessage());
} finally {
if (in != null) {
try {
in.close();
} catch (IOException e) {
log.error("关闭输入流异常", e);
}
}
catch (IOException ex)
{
log.error("调用in.close Exception, url=" + url + ",param=" + param, ex);
if (conn != null) {
conn.disconnect();
}
}
return result.toString();
}
......
package com.zehong.system.domain;
import java.util.Date;
import com.fasterxml.jackson.annotation.JsonFormat;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
import com.zehong.common.annotation.Excel;
import com.zehong.common.core.domain.BaseEntity;
/**
* 未上传成功的历史数据列对象 t_pallet_device_upload_history
*
* @author zehong
* @date 2025-11-24
*/
public class PalletDeviceUploadHistory extends BaseEntity
{
private static final long serialVersionUID = 1L;
/** 托盘id */
private Long id;
/** 托盘id */
@Excel(name = "托盘id")
private Long trayId;
/** 托盘编号 */
private String trayCode;
/** 绑定的设备编号 */
@Excel(name = "绑定的设备编号")
private String deviceCode;
/** 行 */
@Excel(name = "行")
private Integer row;
/** 列 */
@Excel(name = "列")
private Integer col;
/** 第几个 */
@Excel(name = "第几个")
private Integer index;
/** 编号 */
@Excel(name = "编号")
private Integer number;
/** 绑定时间 */
@JsonFormat(pattern = "yyyy-MM-dd")
@Excel(name = "绑定时间", width = 30, dateFormat = "yyyy-MM-dd")
private Date bindingTime;
/** 解绑时间 */
@JsonFormat(pattern = "yyyy-MM-dd")
@Excel(name = "解绑时间", width = 30, dateFormat = "yyyy-MM-dd")
private Date unbindingTime;
/** 0-预热;1-正常;3-传感器故障;4-报警;5-通讯故障 */
@Excel(name = "0-预热;1-正常;3-传感器故障;4-报警;5-通讯故障")
private String status;
/** 设置-年 */
@Excel(name = "设置-年")
private String recordYear;
/** 设置-月 */
@Excel(name = "设置-月")
private String recordMonth;
/** 设置-日 */
@Excel(name = "设置-日")
private String recordDate;
/** 设置-时 */
@Excel(name = "设置-时")
private String recordHour;
/** 设置-分 */
@Excel(name = "设置-分")
private String recordMinute;
/** 写入时间状态;0-失败;1-成功 */
@Excel(name = "写入时间状态;0-失败;1-成功")
private String writeTimeStatus;
/** 调零AD */
@Excel(name = "调零AD")
private String adjustmentZeroAd;
/** 合格;不合格 */
@Excel(name = "合格;不合格")
private String zeroStatus;
/** 标定AD */
@Excel(name = "标定AD")
private String calibrationAd;
/** 合格;不合格 */
@Excel(name = "合格;不合格")
private String calibrationStatus;
/** 浓度值 */
@Excel(name = "浓度值")
private String concentration;
/** 写入时间状态;0-失败;1-成功 */
@Excel(name = "写入时间状态;0-失败;1-成功")
private String runTimeStatus;
/** 实时AD值 */
@Excel(name = "实时AD值")
private Integer realTimeAd;
/** 实时AD状态;0-异常;1-正常 */
@Excel(name = "实时AD状态;0-异常;1-正常")
private String realTimeAdStatus;
public void setId(Long id)
{
this.id = id;
}
public Long getId()
{
return id;
}
public void setTrayId(Long trayId)
{
this.trayId = trayId;
}
public Long getTrayId()
{
return trayId;
}
public void setDeviceCode(String deviceCode)
{
this.deviceCode = deviceCode;
}
public String getDeviceCode()
{
return deviceCode;
}
public void setRow(Integer row)
{
this.row = row;
}
public Integer getRow()
{
return row;
}
public void setCol(Integer col)
{
this.col = col;
}
public Integer getCol()
{
return col;
}
public void setIndex(Integer index)
{
this.index = index;
}
public Integer getIndex()
{
return index;
}
public void setNumber(Integer number)
{
this.number = number;
}
public Integer getNumber()
{
return number;
}
public void setBindingTime(Date bindingTime)
{
this.bindingTime = bindingTime;
}
public Date getBindingTime()
{
return bindingTime;
}
public void setUnbindingTime(Date unbindingTime)
{
this.unbindingTime = unbindingTime;
}
public Date getUnbindingTime()
{
return unbindingTime;
}
public void setStatus(String status)
{
this.status = status;
}
public String getStatus()
{
return status;
}
public void setRecordYear(String recordYear)
{
this.recordYear = recordYear;
}
public String getRecordYear()
{
return recordYear;
}
public void setRecordMonth(String recordMonth)
{
this.recordMonth = recordMonth;
}
public String getRecordMonth()
{
return recordMonth;
}
public void setRecordDate(String recordDate)
{
this.recordDate = recordDate;
}
public String getRecordDate()
{
return recordDate;
}
public void setRecordHour(String recordHour)
{
this.recordHour = recordHour;
}
public String getRecordHour()
{
return recordHour;
}
public void setRecordMinute(String recordMinute)
{
this.recordMinute = recordMinute;
}
public String getRecordMinute()
{
return recordMinute;
}
public void setWriteTimeStatus(String writeTimeStatus)
{
this.writeTimeStatus = writeTimeStatus;
}
public String getWriteTimeStatus()
{
return writeTimeStatus;
}
public void setAdjustmentZeroAd(String adjustmentZeroAd)
{
this.adjustmentZeroAd = adjustmentZeroAd;
}
public String getAdjustmentZeroAd()
{
return adjustmentZeroAd;
}
public void setZeroStatus(String zeroStatus)
{
this.zeroStatus = zeroStatus;
}
public String getZeroStatus()
{
return zeroStatus;
}
public void setCalibrationAd(String calibrationAd)
{
this.calibrationAd = calibrationAd;
}
public String getCalibrationAd()
{
return calibrationAd;
}
public void setCalibrationStatus(String calibrationStatus)
{
this.calibrationStatus = calibrationStatus;
}
public String getCalibrationStatus()
{
return calibrationStatus;
}
public void setConcentration(String concentration)
{
this.concentration = concentration;
}
public String getConcentration()
{
return concentration;
}
public void setRunTimeStatus(String runTimeStatus)
{
this.runTimeStatus = runTimeStatus;
}
public String getRunTimeStatus()
{
return runTimeStatus;
}
public void setRealTimeAd(Integer realTimeAd)
{
this.realTimeAd = realTimeAd;
}
public Integer getRealTimeAd()
{
return realTimeAd;
}
public void setRealTimeAdStatus(String realTimeAdStatus)
{
this.realTimeAdStatus = realTimeAdStatus;
}
public String getRealTimeAdStatus()
{
return realTimeAdStatus;
}
public String getTrayCode() {
return trayCode;
}
public void setTrayCode(String trayCode) {
this.trayCode = trayCode;
}
@Override
public String toString() {
return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE)
.append("id", getId())
.append("trayId", getTrayId())
.append("deviceCode", getDeviceCode())
.append("row", getRow())
.append("col", getCol())
.append("index", getIndex())
.append("number", getNumber())
.append("bindingTime", getBindingTime())
.append("unbindingTime", getUnbindingTime())
.append("createTime", getCreateTime())
.append("status", getStatus())
.append("recordYear", getRecordYear())
.append("recordMonth", getRecordMonth())
.append("recordDate", getRecordDate())
.append("recordHour", getRecordHour())
.append("recordMinute", getRecordMinute())
.append("writeTimeStatus", getWriteTimeStatus())
.append("adjustmentZeroAd", getAdjustmentZeroAd())
.append("zeroStatus", getZeroStatus())
.append("calibrationAd", getCalibrationAd())
.append("calibrationStatus", getCalibrationStatus())
.append("concentration", getConcentration())
.append("runTimeStatus", getRunTimeStatus())
.append("realTimeAd", getRealTimeAd())
.append("realTimeAdStatus", getRealTimeAdStatus())
.toString();
}
}
package com.zehong.system.mapper;
import java.util.List;
import com.zehong.system.domain.PalletDeviceUploadHistory;
/**
* 未上传成功的历史数据列Mapper接口
*
* @author zehong
* @date 2025-11-24
*/
public interface PalletDeviceUploadHistoryMapper
{
/**
* 查询未上传成功的历史数据列
*
* @param id 未上传成功的历史数据列ID
* @return 未上传成功的历史数据列
*/
public PalletDeviceUploadHistory selectPalletDeviceUploadHistoryById(Long id);
/**
* 查询未上传成功的历史数据列列表
*
* @param palletDeviceUploadHistory 未上传成功的历史数据列
* @return 未上传成功的历史数据列集合
*/
public List<PalletDeviceUploadHistory> selectPalletDeviceUploadHistoryList(PalletDeviceUploadHistory palletDeviceUploadHistory);
/**
* 新增未上传成功的历史数据列
*
* @param palletDeviceUploadHistory 未上传成功的历史数据列
* @return 结果
*/
public int insertPalletDeviceUploadHistory(PalletDeviceUploadHistory palletDeviceUploadHistory);
public int batchInsert(List<PalletDeviceUploadHistory> list);
/**
* 修改未上传成功的历史数据列
*
* @param palletDeviceUploadHistory 未上传成功的历史数据列
* @return 结果
*/
public int updatePalletDeviceUploadHistory(PalletDeviceUploadHistory palletDeviceUploadHistory);
/**
* 删除未上传成功的历史数据列
*
* @param id 未上传成功的历史数据列ID
* @return 结果
*/
public int deletePalletDeviceUploadHistoryById(Long id);
/**
* 批量删除未上传成功的历史数据列
*
* @param ids 需要删除的数据ID
* @return 结果
*/
public int deletePalletDeviceUploadHistoryByIds(Long[] ids);
}
package com.zehong.system.netty.handler;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.zehong.common.utils.StringUtils;
import com.zehong.common.utils.bean.BeanUtils;
import com.zehong.common.utils.http.HttpUtils;
import com.zehong.system.domain.MesDeviceDomain;
import com.zehong.system.domain.PalletDeviceBinding;
import com.zehong.system.domain.PalletDeviceUploadHistory;
import com.zehong.system.domain.RobotArmCommand;
import com.zehong.system.service.IPalletDeviceBindingService;
import com.zehong.system.service.IPalletDeviceUploadHistoryService;
import com.zehong.system.service.IRobotArmCommandService;
import com.zehong.system.service.ISysConfigService;
import com.zehong.system.service.websocket.RobotArmWebSocketHandler;
......@@ -32,6 +36,7 @@ import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.locks.ReentrantLock;
import java.io.*;
import java.util.stream.Collectors;
/**
* @author lenovo
......@@ -73,6 +78,9 @@ public class NettyUdpServerHandler extends SimpleChannelInboundHandler<DatagramP
@Resource
private ISysConfigService sysConfigService;
@Resource
private IPalletDeviceUploadHistoryService palletDeviceUploadHistoryService;
/**
* 接收UDP消息
*/
......@@ -192,19 +200,15 @@ public class NettyUdpServerHandler extends SimpleChannelInboundHandler<DatagramP
// 1 根据信息拿到点位信息 假如说1L是传过来的
List<PalletDeviceBinding> palletDeviceBindings = initAdAndStatus(message);
// 2 解析数据上传MES 返回是否成功
Boolean aBoolean = initMesDataAndUpload(palletDeviceBindings);
// 3 三次失败后 记录到本系统,之后有时间再手动上传
if(!aBoolean) {
}
// 2 解析数据上传MES 返回如果失败则记录失败,等下次有时间再上传
initMesDataAndUpload(palletDeviceBindings);
}
/**
* 初始化MES数据并上传
*/
private Boolean initMesDataAndUpload(List<PalletDeviceBinding> palletDeviceBindings) {
private void initMesDataAndUpload(List<PalletDeviceBinding> palletDeviceBindings) {
List<MesDeviceDomain> mesDeviceDomains = new ArrayList<>();
......@@ -234,17 +238,101 @@ public class NettyUdpServerHandler extends SimpleChannelInboundHandler<DatagramP
String result = HttpUtils.sendPost(mesUploadAddress, JSON.toJSONString(mesDeviceDomains));
if(StringUtils.isBlank(result)) {
return false;
}
JSONObject jsonObject = JSON.parseObject(result);
if(jsonObject.getInteger("code") == 200) {
return true;
if(jsonObject.getInteger("code") != 200) {
String data = jsonObject.getString("data");
if(StringUtils.isNotBlank(data)) {
processPalletDeviceUploadHistory(palletDeviceBindings,data);
}
}
}
return false;
}
/**
* 处理托盘设备上传历史数据
*/
private void processPalletDeviceUploadHistory(List<PalletDeviceBinding> palletDeviceBindings,String data){
JSONObject jsonObject = JSON.parseObject(data);
if (!jsonObject.containsKey("failedCodes")) {
return;
}
JSONArray failedCodes = jsonObject.getJSONArray("failedCodes");
if (failedCodes == null || failedCodes.isEmpty()) {
return;
}
// 使用Set提高查找效率
Set<String> failedCodeSet = failedCodes.stream()
.map(Object::toString)
.collect(Collectors.toSet());
List<PalletDeviceUploadHistory> palletDeviceUploadHistories = palletDeviceBindings.stream()
.filter(binding -> failedCodeSet.contains(binding.getDeviceCode()))
.map(this::convertToUploadHistory)
.collect(Collectors.toList());
if (!palletDeviceUploadHistories.isEmpty()) {
palletDeviceUploadHistoryService.batchInsert(palletDeviceUploadHistories);
}
}
/**
* 转换对象
*/
private PalletDeviceUploadHistory convertToUploadHistory(PalletDeviceBinding binding) {
PalletDeviceUploadHistory history = new PalletDeviceUploadHistory();
// 基础信息字段
history.setTrayId(binding.getTrayId());
history.setDeviceCode(binding.getDeviceCode());
history.setRow(binding.getRow());
history.setCol(binding.getCol());
history.setIndex(binding.getIndex());
history.setNumber(binding.getNumber());
history.setBindingTime(binding.getBindingTime());
history.setUnbindingTime(binding.getUnbindingTime());
// 状态字段
history.setStatus(binding.getStatus());
// 时间记录字段
history.setRecordYear(binding.getRecordYear());
history.setRecordMonth(binding.getRecordMonth());
history.setRecordDate(binding.getRecordDate());
history.setRecordHour(binding.getRecordHour());
history.setRecordMinute(binding.getRecordMinute());
// 写入状态字段
history.setWriteTimeStatus(binding.getWriteTimeStatus());
history.setRunTimeStatus(binding.getRunTimeStatus());
// 调零相关字段
history.setAdjustmentZeroAd(binding.getAdjustmentZeroAd());
history.setZeroStatus(binding.getZeroStatus());
// 标定相关字段 - 注意字段名称不同
history.setCalibrationAd(binding.getCalibrationAd());
history.setCalibrationStatus(binding.getCalibrationAdStatus()); // 注意:这里字段名不同
// 浓度字段
history.setConcentration(binding.getConcentration());
// 实时AD相关字段
history.setRealTimeAd(binding.getRealTimeAd());
history.setRealTimeAdStatus(binding.getRealTimeStatus()); // 注意:这里字段名不同
// 托盘编号字段 - 注意字段名称不同
history.setTrayCode(binding.getfTrayCode()); // 注意:这里字段名不同
// 创建时间和更新时间(如果需要)
history.setCreateTime(binding.getCreateTime());
history.setUpdateTime(binding.getUpdateTime());
return history;
}
/**
* 根据托盘码查询托盘绑定的设备列
*/
......
package com.zehong.system.service;
import java.util.List;
import com.zehong.common.core.domain.AjaxResult;
import com.zehong.system.domain.PalletDeviceUploadHistory;
/**
* 未上传成功的历史数据列Service接口
*
* @author zehong
* @date 2025-11-24
*/
public interface IPalletDeviceUploadHistoryService
{
/**
* 查询未上传成功的历史数据列
*
* @param id 未上传成功的历史数据列ID
* @return 未上传成功的历史数据列
*/
public PalletDeviceUploadHistory selectPalletDeviceUploadHistoryById(Long id);
/**
* 查询未上传成功的历史数据列列表
*
* @param palletDeviceUploadHistory 未上传成功的历史数据列
* @return 未上传成功的历史数据列集合
*/
public List<PalletDeviceUploadHistory> selectPalletDeviceUploadHistoryList(PalletDeviceUploadHistory palletDeviceUploadHistory);
public int batchInsert(List<PalletDeviceUploadHistory> palletDeviceUploadHistoryList);
/**
* 新增未上传成功的历史数据列
*
* @param palletDeviceUploadHistory 未上传成功的历史数据列
* @return 结果
*/
public int insertPalletDeviceUploadHistory(PalletDeviceUploadHistory palletDeviceUploadHistory);
public AjaxResult handleReUpload();
/**
* 修改未上传成功的历史数据列
*
* @param palletDeviceUploadHistory 未上传成功的历史数据列
* @return 结果
*/
public int updatePalletDeviceUploadHistory(PalletDeviceUploadHistory palletDeviceUploadHistory);
/**
* 批量删除未上传成功的历史数据列
*
* @param ids 需要删除的未上传成功的历史数据列ID
* @return 结果
*/
public int deletePalletDeviceUploadHistoryByIds(Long[] ids);
/**
* 删除未上传成功的历史数据列信息
*
* @param id 未上传成功的历史数据列ID
* @return 结果
*/
public int deletePalletDeviceUploadHistoryById(Long id);
}
package com.zehong.system.service.impl;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.zehong.common.core.domain.AjaxResult;
import com.zehong.common.utils.DateUtils;
import com.zehong.common.utils.StringUtils;
import com.zehong.common.utils.bean.BeanUtils;
import com.zehong.common.utils.http.HttpUtils;
import com.zehong.system.domain.MesDeviceDomain;
import com.zehong.system.domain.PalletDeviceBinding;
import com.zehong.system.domain.PalletDeviceUploadHistory;
import com.zehong.system.mapper.PalletDeviceUploadHistoryMapper;
import com.zehong.system.netty.handler.NettyUdpServerHandler;
import com.zehong.system.service.IPalletDeviceUploadHistoryService;
import com.zehong.system.service.ISysConfigService;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.*;
import java.util.stream.Collectors;
/**
* 未上传成功的历史数据列Service业务层处理
*
* @author zehong
* @date 2025-11-24
*/
@Service
public class PalletDeviceUploadHistoryServiceImpl implements IPalletDeviceUploadHistoryService
{
@Resource
private PalletDeviceUploadHistoryMapper palletDeviceUploadHistoryMapper;
@Resource
private ISysConfigService sysConfigService;
@Resource
private IPalletDeviceUploadHistoryService palletDeviceUploadHistoryService;
/**
* 查询未上传成功的历史数据列
*
* @param id 未上传成功的历史数据列ID
* @return 未上传成功的历史数据列
*/
@Override
public PalletDeviceUploadHistory selectPalletDeviceUploadHistoryById(Long id)
{
return palletDeviceUploadHistoryMapper.selectPalletDeviceUploadHistoryById(id);
}
/**
* 查询未上传成功的历史数据列列表
*
* @param palletDeviceUploadHistory 未上传成功的历史数据列
* @return 未上传成功的历史数据列
*/
@Override
public List<PalletDeviceUploadHistory> selectPalletDeviceUploadHistoryList(PalletDeviceUploadHistory palletDeviceUploadHistory)
{
return palletDeviceUploadHistoryMapper.selectPalletDeviceUploadHistoryList(palletDeviceUploadHistory);
}
@Override
public int batchInsert(List<PalletDeviceUploadHistory> palletDeviceUploadHistoryList) {
return palletDeviceUploadHistoryMapper.batchInsert(palletDeviceUploadHistoryList);
}
/**
* 新增未上传成功的历史数据列
*
* @param palletDeviceUploadHistory 未上传成功的历史数据列
* @return 结果
*/
@Override
public int insertPalletDeviceUploadHistory(PalletDeviceUploadHistory palletDeviceUploadHistory)
{
palletDeviceUploadHistory.setCreateTime(DateUtils.getNowDate());
return palletDeviceUploadHistoryMapper.insertPalletDeviceUploadHistory(palletDeviceUploadHistory);
}
/**
* 批量处理未上传成功的数据
* @return r
*/
@Override
public AjaxResult handleReUpload() {
AjaxResult ajax = AjaxResult.success();
List<PalletDeviceUploadHistory> palletDeviceUploadHistoriesDb = palletDeviceUploadHistoryMapper.selectPalletDeviceUploadHistoryList(new PalletDeviceUploadHistory());
if (palletDeviceUploadHistoriesDb == null || palletDeviceUploadHistoriesDb.isEmpty()) {
ajax.put("code", 200);
ajax.put("msg", "上传数据列表不能为空");
return ajax;
}
List<PalletDeviceUploadHistory> palletDeviceUploadHistories = palletDeviceUploadHistoriesDb.stream().filter(item -> StringUtils.isNotBlank(item.getDeviceCode())).collect(Collectors.toList());
try {
// 1. 初始化MES数据并上传
List<PalletDeviceUploadHistory> failedUploads = initMesDataAndUpload(palletDeviceUploadHistories);
// 2. 处理上传结果
if (failedUploads.isEmpty()) {
// 全部成功,删除所有历史数据
List<Long> successIds = palletDeviceUploadHistories.stream()
.map(PalletDeviceUploadHistory::getId)
.collect(Collectors.toList());
if (!successIds.isEmpty()) {
int deleteCount = deletePalletDeviceUploadHistoryByIds(successIds.toArray(new Long[0]));
return AjaxResult.success("所有数据上传成功,已删除 " + deleteCount + " 条历史记录");
}
} else {
// 部分成功,只删除成功的数据
List<Long> successIds = palletDeviceUploadHistories.stream()
.filter(item -> !failedUploads.contains(item))
.map(PalletDeviceUploadHistory::getId)
.collect(Collectors.toList());
int successCount = 0;
if (!successIds.isEmpty()) {
successCount = deletePalletDeviceUploadHistoryByIds(successIds.toArray(new Long[0]));
}
// 构建失败设备列表
List<String> failedDeviceCodes = failedUploads.stream()
.map(PalletDeviceUploadHistory::getDeviceCode)
.collect(Collectors.toList());
Map<String, Object> result = new HashMap<>();
result.put("successCount", successCount);
result.put("failedCount", failedUploads.size());
result.put("failedDeviceCodes", failedDeviceCodes);
ajax.put("code", 200);
ajax.put("msg", "部分数据上传失败,成功 " + successCount + " 条,失败 " + failedUploads.size() + " 条");
ajax.put("data", result);
return ajax;
}
return AjaxResult.success("数据处理完成");
} catch (Exception e) {
ajax.put("code", 200);
ajax.put("msg", "处理上传数据时发生异常" + e.getMessage());
return ajax;
}
}
/**
* 初始化MES数据并上传,返回上传失败的设备列表
*/
private List<PalletDeviceUploadHistory> initMesDataAndUpload(List<PalletDeviceUploadHistory> palletDeviceUploadHistoryList) {
List<MesDeviceDomain> mesDeviceDomains = new ArrayList<>();
for (PalletDeviceUploadHistory palletDeviceBinding : palletDeviceUploadHistoryList) {
MesDeviceDomain mesDeviceDomain = new MesDeviceDomain();
if(StringUtils.isBlank(palletDeviceBinding.getDeviceCode())
|| StringUtils.isBlank(palletDeviceBinding.getAdjustmentZeroAd())
|| StringUtils.isBlank(palletDeviceBinding.getZeroStatus())
|| StringUtils.isBlank(palletDeviceBinding.getCalibrationAd())
|| StringUtils.isBlank(palletDeviceBinding.getCalibrationStatus())
|| StringUtils.isBlank(palletDeviceBinding.getConcentration())
|| palletDeviceBinding.getRealTimeAd() == null
|| StringUtils.isBlank(palletDeviceBinding.getRealTimeAdStatus())) {
throw new RuntimeException("数据不完整");
}
// 主板码
mesDeviceDomain.setMotherboardCode(palletDeviceBinding.getDeviceCode());
// 零点AD
mesDeviceDomain.setZeroAdValue(palletDeviceBinding.getAdjustmentZeroAd());
// 零点AD状态
mesDeviceDomain.setZeroStatus(palletDeviceBinding.getZeroStatus());
// 标定AD
mesDeviceDomain.setCalibratedAdValue(palletDeviceBinding.getCalibrationAd());
// 标定AD状态
mesDeviceDomain.setCalibrationStatus(palletDeviceBinding.getCalibrationStatus());
// 浓度
mesDeviceDomain.setConcentration(palletDeviceBinding.getConcentration());
// 实时AD
mesDeviceDomain.setRealTimeAd(palletDeviceBinding.getRealTimeAd());
// 实时状态
mesDeviceDomain.setRealTimeStatus(palletDeviceBinding.getRealTimeAdStatus());
mesDeviceDomains.add(mesDeviceDomain);
}
String mesUploadAddress = sysConfigService.directSelectConfigByKey(NettyUdpServerHandler.UPLOAD_MES_ADDRESS);
if (StringUtils.isBlank(mesUploadAddress)) {
throw new RuntimeException("MES上传地址未配置");
}
try {
String result = HttpUtils.sendPost(mesUploadAddress, JSON.toJSONString(mesDeviceDomains));
if (StringUtils.isBlank(result)) {
throw new RuntimeException("MES接口返回为空");
}
JSONObject jsonObject = JSON.parseObject(result);
if (jsonObject.getInteger("code") == 200) {
// 全部成功,返回空列表
return new ArrayList<>();
} else {
// 部分失败,处理失败的数据
String data = jsonObject.getString("data");
if (StringUtils.isNotBlank(data)) {
return processPalletDeviceUploadHistory(palletDeviceUploadHistoryList, data);
} else {
JSONObject jsonObject1 = JSON.parseObject(data);
throw new RuntimeException("调用MES接口失败: " + jsonObject1.get("msg").toString());
}
}
} catch (Exception e) {
throw new RuntimeException("调用MES接口失败: " + e.getMessage());
}
}
/**
* 处理托盘设备上传历史数据,返回上传失败的设备列表
*/
private List<PalletDeviceUploadHistory> processPalletDeviceUploadHistory(List<PalletDeviceUploadHistory> palletDeviceBindings, String data) {
JSONObject jsonObject = JSON.parseObject(data);
if (!jsonObject.containsKey("failedCount")) {
return new ArrayList<>(palletDeviceBindings);
}
JSONArray failedCodes = jsonObject.getJSONArray("failedCodes");
if (failedCodes == null || failedCodes.isEmpty()) {
return new ArrayList<>();
}
// 使用Set提高查找效率
Set<String> failedCodeSet = failedCodes.stream()
.map(Object::toString)
.collect(Collectors.toSet());
// 返回失败的数据列表
return palletDeviceBindings.stream()
.filter(binding -> failedCodeSet.contains(binding.getDeviceCode()))
.collect(Collectors.toList());
}
/**
* 转换对象 - 修正方法签名(如果需要的话)
*/
private PalletDeviceUploadHistory convertToUploadHistory(PalletDeviceUploadHistory binding) {
PalletDeviceUploadHistory history = new PalletDeviceUploadHistory();
// 正确的参数顺序:源对象在前,目标对象在后
BeanUtils.copyProperties(binding, history);
return history;
}
/**
* 修改未上传成功的历史数据列
*
* @param palletDeviceUploadHistory 未上传成功的历史数据列
* @return 结果
*/
@Override
public int updatePalletDeviceUploadHistory(PalletDeviceUploadHistory palletDeviceUploadHistory)
{
return palletDeviceUploadHistoryMapper.updatePalletDeviceUploadHistory(palletDeviceUploadHistory);
}
/**
* 批量删除未上传成功的历史数据列
*
* @param ids 需要删除的未上传成功的历史数据列ID
* @return 结果
*/
@Override
public int deletePalletDeviceUploadHistoryByIds(Long[] ids)
{
return palletDeviceUploadHistoryMapper.deletePalletDeviceUploadHistoryByIds(ids);
}
/**
* 删除未上传成功的历史数据列信息
*
* @param id 未上传成功的历史数据列ID
* @return 结果
*/
@Override
public int deletePalletDeviceUploadHistoryById(Long id)
{
return palletDeviceUploadHistoryMapper.deletePalletDeviceUploadHistoryById(id);
}
}
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.zehong.system.mapper.PalletDeviceUploadHistoryMapper">
<resultMap type="PalletDeviceUploadHistory" id="PalletDeviceUploadHistoryResult">
<result property="id" column="f_id" />
<result property="trayId" column="f_tray_id" />
<result property="deviceCode" column="f_device_code" />
<result property="row" column="f_row" />
<result property="col" column="f_col" />
<result property="index" column="f_index" />
<result property="number" column="f_number" />
<result property="bindingTime" column="f_binding_time" />
<result property="unbindingTime" column="f_unbinding_time" />
<result property="createTime" column="f_create_time" />
<result property="status" column="f_status" />
<result property="recordYear" column="f_record_year" />
<result property="recordMonth" column="f_record_month" />
<result property="recordDate" column="f_record_date" />
<result property="recordHour" column="f_record_hour" />
<result property="recordMinute" column="f_record_minute" />
<result property="writeTimeStatus" column="f_write_time_status" />
<result property="adjustmentZeroAd" column="f_adjustment_zero_ad" />
<result property="zeroStatus" column="f_zero_status" />
<result property="calibrationAd" column="f_calibration_ad" />
<result property="calibrationStatus" column="f_calibration_status" />
<result property="concentration" column="f_concentration" />
<result property="runTimeStatus" column="f_run_time_status" />
<result property="realTimeAd" column="f_real_time_ad" />
<result property="realTimeAdStatus" column="f_real_time_ad_status" />
</resultMap>
<sql id="selectPalletDeviceUploadHistoryVo">
select palDeviceBinding.f_id,
palDeviceBinding.f_tray_id,
trayInfo.f_tray_code as trayCode,
palDeviceBinding.f_device_code,
palDeviceBinding.f_row,
palDeviceBinding.f_col,
palDeviceBinding.f_index,
palDeviceBinding.f_number,
palDeviceBinding.f_binding_time,
palDeviceBinding.f_unbinding_time,
palDeviceBinding.f_create_time,
palDeviceBinding.f_status,
palDeviceBinding.f_record_year,
palDeviceBinding.f_record_month,
palDeviceBinding.f_record_date,
palDeviceBinding.f_record_hour,
palDeviceBinding.f_record_minute,
palDeviceBinding.f_write_time_status,
palDeviceBinding.f_adjustment_zero_ad,
palDeviceBinding.f_zero_status,
palDeviceBinding.f_calibration_ad,
palDeviceBinding.f_calibration_status,
palDeviceBinding.f_concentration,
palDeviceBinding.f_run_time_status,
palDeviceBinding.f_real_time_ad,
palDeviceBinding.f_real_time_ad_status
from t_pallet_device_upload_history palDeviceBinding
left join t_tray_info trayInfo on trayInfo.f_tray_id = palDeviceBinding.f_tray_id
</sql>
<select id="selectPalletDeviceUploadHistoryList" parameterType="PalletDeviceUploadHistory" resultMap="PalletDeviceUploadHistoryResult">
<include refid="selectPalletDeviceUploadHistoryVo"/>
<where>
<if test="deviceCode != null and deviceCode != ''"> and palDeviceBinding.f_device_code = #{deviceCode}</if>
</where>
</select>
<select id="selectPalletDeviceUploadHistoryById" parameterType="Long" resultMap="PalletDeviceUploadHistoryResult">
<include refid="selectPalletDeviceUploadHistoryVo"/>
where palDeviceBinding.f_id = #{id}
</select>
<insert id="batchInsert" parameterType="list">
insert into t_pallet_device_upload_history
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="list != null and list.size() > 0">
<if test="list[0].trayId != null">f_tray_id,</if>
<if test="list[0].deviceCode != null">f_device_code,</if>
<if test="list[0].row != null">f_row,</if>
<if test="list[0].col != null">f_col,</if>
<if test="list[0].index != null">f_index,</if>
<if test="list[0].number != null">f_number,</if>
<if test="list[0].bindingTime != null">f_binding_time,</if>
<if test="list[0].unbindingTime != null">f_unbinding_time,</if>
<if test="list[0].createTime != null">f_create_time,</if>
<if test="list[0].status != null">f_status,</if>
<if test="list[0].recordYear != null">f_record_year,</if>
<if test="list[0].recordMonth != null">f_record_month,</if>
<if test="list[0].recordDate != null">f_record_date,</if>
<if test="list[0].recordHour != null">f_record_hour,</if>
<if test="list[0].recordMinute != null">f_record_minute,</if>
<if test="list[0].writeTimeStatus != null">f_write_time_status,</if>
<if test="list[0].adjustmentZeroAd != null">f_adjustment_zero_ad,</if>
<if test="list[0].zeroStatus != null">f_zero_status,</if>
<if test="list[0].calibrationAd != null">f_calibration_ad,</if>
<if test="list[0].calibrationStatus != null">f_calibration_status,</if>
<if test="list[0].concentration != null">f_concentration,</if>
<if test="list[0].runTimeStatus != null">f_run_time_status,</if>
<if test="list[0].realTimeAd != null">f_real_time_ad,</if>
<if test="list[0].realTimeAdStatus != null">f_real_time_ad_status,</if>
</if>
</trim>
values
<foreach collection="list" item="item" separator=",">
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="item.trayId != null">#{item.trayId},</if>
<if test="item.deviceCode != null">#{item.deviceCode},</if>
<if test="item.row != null">#{item.row},</if>
<if test="item.col != null">#{item.col},</if>
<if test="item.index != null">#{item.index},</if>
<if test="item.number != null">#{item.number},</if>
<if test="item.bindingTime != null">#{item.bindingTime},</if>
<if test="item.unbindingTime != null">#{item.unbindingTime},</if>
<if test="item.createTime != null">#{item.createTime},</if>
<if test="item.status != null">#{item.status},</if>
<if test="item.recordYear != null">#{item.recordYear},</if>
<if test="item.recordMonth != null">#{item.recordMonth},</if>
<if test="item.recordDate != null">#{item.recordDate},</if>
<if test="item.recordHour != null">#{item.recordHour},</if>
<if test="item.recordMinute != null">#{item.recordMinute},</if>
<if test="item.writeTimeStatus != null">#{item.writeTimeStatus},</if>
<if test="item.adjustmentZeroAd != null">#{item.adjustmentZeroAd},</if>
<if test="item.zeroStatus != null">#{item.zeroStatus},</if>
<if test="item.calibrationAd != null">#{item.calibrationAd},</if>
<if test="item.calibrationStatus != null">#{item.calibrationStatus},</if>
<if test="item.concentration != null">#{item.concentration},</if>
<if test="item.runTimeStatus != null">#{item.runTimeStatus},</if>
<if test="item.realTimeAd != null">#{item.realTimeAd},</if>
<if test="item.realTimeAdStatus != null">#{item.realTimeAdStatus},</if>
</trim>
</foreach>
</insert>
<insert id="insertPalletDeviceUploadHistory" parameterType="PalletDeviceUploadHistory" useGeneratedKeys="true" keyProperty="id">
insert into t_pallet_device_upload_history
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="trayId != null">f_tray_id,</if>
<if test="deviceCode != null">f_device_code,</if>
<if test="row != null">f_row,</if>
<if test="col != null">f_col,</if>
<if test="index != null">f_index,</if>
<if test="number != null">f_number,</if>
<if test="bindingTime != null">f_binding_time,</if>
<if test="unbindingTime != null">f_unbinding_time,</if>
<if test="createTime != null">f_create_time,</if>
<if test="status != null">f_status,</if>
<if test="recordYear != null">f_record_year,</if>
<if test="recordMonth != null">f_record_month,</if>
<if test="recordDate != null">f_record_date,</if>
<if test="recordHour != null">f_record_hour,</if>
<if test="recordMinute != null">f_record_minute,</if>
<if test="writeTimeStatus != null">f_write_time_status,</if>
<if test="adjustmentZeroAd != null">f_adjustment_zero_ad,</if>
<if test="zeroStatus != null">f_zero_status,</if>
<if test="calibrationAd != null">f_calibration_ad,</if>
<if test="calibrationStatus != null">f_calibration_status,</if>
<if test="concentration != null">f_concentration,</if>
<if test="runTimeStatus != null">f_run_time_status,</if>
<if test="realTimeAd != null">f_real_time_ad,</if>
<if test="realTimeAdStatus != null">f_real_time_ad_status,</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="trayId != null">#{trayId},</if>
<if test="deviceCode != null">#{deviceCode},</if>
<if test="row != null">#{row},</if>
<if test="col != null">#{col},</if>
<if test="index != null">#{index},</if>
<if test="number != null">#{number},</if>
<if test="bindingTime != null">#{bindingTime},</if>
<if test="unbindingTime != null">#{unbindingTime},</if>
<if test="createTime != null">#{createTime},</if>
<if test="status != null">#{status},</if>
<if test="recordYear != null">#{recordYear},</if>
<if test="recordMonth != null">#{recordMonth},</if>
<if test="recordDate != null">#{recordDate},</if>
<if test="recordHour != null">#{recordHour},</if>
<if test="recordMinute != null">#{recordMinute},</if>
<if test="writeTimeStatus != null">#{writeTimeStatus},</if>
<if test="adjustmentZeroAd != null">#{adjustmentZeroAd},</if>
<if test="zeroStatus != null">#{zeroStatus},</if>
<if test="calibrationAd != null">#{calibrationAd},</if>
<if test="calibrationStatus != null">#{calibrationStatus},</if>
<if test="concentration != null">#{concentration},</if>
<if test="runTimeStatus != null">#{runTimeStatus},</if>
<if test="realTimeAd != null">#{realTimeAd},</if>
<if test="realTimeAdStatus != null">#{realTimeAdStatus},</if>
</trim>
</insert>
<update id="updatePalletDeviceUploadHistory" parameterType="PalletDeviceUploadHistory">
update t_pallet_device_upload_history
<trim prefix="SET" suffixOverrides=",">
<if test="trayId != null">f_tray_id = #{trayId},</if>
<if test="deviceCode != null">f_device_code = #{deviceCode},</if>
<if test="row != null">f_row = #{row},</if>
<if test="col != null">f_col = #{col},</if>
<if test="index != null">f_index = #{index},</if>
<if test="number != null">f_number = #{number},</if>
<if test="bindingTime != null">f_binding_time = #{bindingTime},</if>
<if test="unbindingTime != null">f_unbinding_time = #{unbindingTime},</if>
<if test="createTime != null">f_create_time = #{createTime},</if>
<if test="status != null">f_status = #{status},</if>
<if test="recordYear != null">f_record_year = #{recordYear},</if>
<if test="recordMonth != null">f_record_month = #{recordMonth},</if>
<if test="recordDate != null">f_record_date = #{recordDate},</if>
<if test="recordHour != null">f_record_hour = #{recordHour},</if>
<if test="recordMinute != null">f_record_minute = #{recordMinute},</if>
<if test="writeTimeStatus != null">f_write_time_status = #{writeTimeStatus},</if>
<if test="adjustmentZeroAd != null">f_adjustment_zero_ad = #{adjustmentZeroAd},</if>
<if test="zeroStatus != null">f_zero_status = #{zeroStatus},</if>
<if test="calibrationAd != null">f_calibration_ad = #{calibrationAd},</if>
<if test="calibrationStatus != null">f_calibration_status = #{calibrationStatus},</if>
<if test="concentration != null">f_concentration = #{concentration},</if>
<if test="runTimeStatus != null">f_run_time_status = #{runTimeStatus},</if>
<if test="realTimeAd != null">f_real_time_ad = #{realTimeAd},</if>
<if test="realTimeAdStatus != null">f_real_time_ad_status = #{realTimeAdStatus},</if>
</trim>
where f_id = #{id}
</update>
<delete id="deletePalletDeviceUploadHistoryById" parameterType="Long">
delete from t_pallet_device_upload_history where f_id = #{id}
</delete>
<delete id="deletePalletDeviceUploadHistoryByIds" parameterType="String">
delete from t_pallet_device_upload_history where f_id in
<foreach item="id" collection="array" open="(" separator="," close=")">
#{id}
</foreach>
</delete>
</mapper>
\ No newline at end of file
import request from '@/utils/request'
// 查询未上传成功的历史数据列列表
export function listHistory(query) {
return request({
url: '/palletDevice/binding/history/list',
method: 'get',
params: query
})
}
// 查询未上传成功的历史数据列详细
export function getHistory(id) {
return request({
url: '/palletDevice/binding/history/' + id,
method: 'get'
})
}
// 新增未上传成功的历史数据列
export function addHistory(data) {
return request({
url: '/palletDevice/binding/history',
method: 'post',
data: data
})
}
// 修改未上传成功的历史数据列
export function updateHistory(data) {
return request({
url: '/palletDevice/binding/history',
method: 'put',
data: data
})
}
// 删除未上传成功的历史数据列
export function delHistory(id) {
return request({
url: '/palletDevice/binding/history/' + id,
method: 'delete'
})
}
// 导出未上传成功的历史数据列
export function exportHistory(query) {
return request({
url: '/palletDevice/binding/history/export',
method: 'get',
params: query
})
}
export function reUpload() {
return request({
url: '/palletDevice/binding/history/handleReUpload',
method: 'get'
})
}
<template>
<div class="app-container">
<el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
<el-form-item label="设备编号" prop="deviceCode">
<el-input
v-model="queryParams.deviceCode"
placeholder="请输入绑定的设备编号"
clearable
size="small"
@keyup.enter.native="handleQuery"
/>
</el-form-item>
<el-form-item>
<el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
<el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
</el-form-item>
</el-form>
<el-row :gutter="10" class="mb8">
<el-col :span="1.5">
<el-button
type="primary"
plain
icon="el-icon-plus"
size="mini"
@click="handleAdd"
>新增</el-button>
</el-col>
<el-col :span="1.5">
<el-button
type="warning"
plain
icon="el-icon-download"
size="mini"
:loading="exportLoading"
@click="handleExport"
>导出</el-button>
</el-col>
<el-col :span="1.5">
<el-button
type="primary"
plain
icon="el-icon-upload"
size="mini"
:loading="exportLoading"
@click="handleReUpload"
>重新上传</el-button>
</el-col>
<right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
</el-row>
<el-table v-loading="loading" :data="historyList" @selection-change="handleSelectionChange">
<el-table-column label="托盘编号" align="center" prop="trayCode" />
<el-table-column label="设备编号" align="center" prop="deviceCode" />
<el-table-column label="行" align="center" prop="row" />
<el-table-column label="列" align="center" prop="col" />
<el-table-column label="第几个" align="center" prop="index" />
<el-table-column label="编号" align="center" prop="number" />
<el-table-column label="绑定时间" align="center" prop="bindingTime" width="180">
<template slot-scope="scope">
<span>{{ parseTime(scope.row.bindingTime, '{y}-{m}-{d}') }}</span>
</template>
</el-table-column>
<el-table-column label="解绑时间" align="center" prop="unbindingTime" width="180">
<template slot-scope="scope">
<span>{{ parseTime(scope.row.unbindingTime, '{y}-{m}-{d}') }}</span>
</template>
</el-table-column>
<el-table-column label="创建时间" align="center" prop="createTime" width="180">
<template slot-scope="scope">
<span>{{ parseTime(scope.row.createTime, '{y}-{m}-{d}') }}</span>
</template>
</el-table-column>
<el-table-column label="状态" align="center" prop="status" >
<template slot-scope="scope">
<el-tag type="info" v-if="scope.row.status === '0'">预热</el-tag>
<el-tag type="success" v-if="scope.row.status === '1'">正常</el-tag>
<el-tag type="warning" v-if="scope.row.status === '3'">传感器故障</el-tag>
<el-tag type="danger" v-if="scope.row.status === '4'">报警</el-tag>
<el-tag type="danger" v-if="scope.row.status === '5'">通讯故障</el-tag>
</template>
</el-table-column>
<el-table-column label="设置-年" align="center" prop="recordYear" />
<el-table-column label="设置-月" align="center" prop="recordMonth" />
<el-table-column label="设置-日" align="center" prop="recordDate" />
<el-table-column label="设置-时" align="center" prop="recordHour" />
<el-table-column label="设置-分" align="center" prop="recordMinute" />
<el-table-column label="写时间状态" align="center" prop="writeTimeStatus" width="100px" >
<template slot-scope="scope">
<el-tag type="info" v-if="scope.row.writeTimeStatus === '0'">失败</el-tag>
<el-tag type="success" v-if="scope.row.writeTimeStatus === '1'">成功</el-tag>
</template>
</el-table-column>
<el-table-column label="调零AD" align="center" prop="adjustmentZeroAd" />
<el-table-column label="调零状态" align="center" prop="zeroStatus" />
<el-table-column label="标定AD" align="center" prop="calibrationAd" />
<el-table-column label="标定状态" align="center" prop="calibrationStatus" />
<el-table-column label="浓度值" align="center" prop="concentration" />
<el-table-column label="运行时间状态" align="center" prop="runTimeStatus" width="110px">
<template slot-scope="scope">
<el-tag type="info" v-if="scope.row.runTimeStatus === '0'">失败</el-tag>
<el-tag type="success" v-if="scope.row.runTimeStatus === '1'">成功</el-tag>
</template>
</el-table-column>
<el-table-column label="实时AD值" align="center" prop="realTimeAd" />
<el-table-column label="实时AD状态" align="center" prop="realTimeAdStatus" width="110px" >
<template slot-scope="scope">
<el-tag type="info" v-if="scope.row.realTimeAdStatus === '0'">异常</el-tag>
<el-tag type="success" v-if="scope.row.realTimeAdStatus === '1'">正常</el-tag>
</template>
</el-table-column>
<!-- <el-table-column label="操作" align="center" class-name="small-padding fixed-width">-->
<!-- <template slot-scope="scope">-->
<!-- <el-button-->
<!-- size="mini"-->
<!-- type="text"-->
<!-- icon="el-icon-edit"-->
<!-- @click="handleSingleUpload(scope.row)"-->
<!-- >上传</el-button>-->
<!-- </template>-->
<!-- </el-table-column>-->
</el-table>
<pagination
v-show="total>0"
:total="total"
:page.sync="queryParams.pageNum"
:limit.sync="queryParams.pageSize"
@pagination="getList"
/>
<!-- 添加或修改未上传成功的历史数据列对话框 -->
<el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
<el-form ref="form" :model="form" :rules="rules" label-width="80px">
<el-form-item label="托盘id" prop="trayId">
<el-input v-model="form.trayId" placeholder="请输入托盘id" />
</el-form-item>
<el-form-item label="绑定的设备编号" prop="deviceCode">
<el-input v-model="form.deviceCode" placeholder="请输入绑定的设备编号" />
</el-form-item>
<el-form-item label="行" prop="row">
<el-input v-model="form.row" placeholder="请输入行" />
</el-form-item>
<el-form-item label="列" prop="col">
<el-input v-model="form.col" placeholder="请输入列" />
</el-form-item>
<el-form-item label="第几个" prop="index">
<el-input v-model="form.index" placeholder="请输入第几个" />
</el-form-item>
<el-form-item label="编号" prop="number">
<el-input v-model="form.number" placeholder="请输入编号" />
</el-form-item>
<el-form-item label="绑定时间" prop="bindingTime">
<el-date-picker clearable size="small"
v-model="form.bindingTime"
type="date"
value-format="yyyy-MM-dd"
placeholder="选择绑定时间">
</el-date-picker>
</el-form-item>
<el-form-item label="解绑时间" prop="unbindingTime">
<el-date-picker clearable size="small"
v-model="form.unbindingTime"
type="date"
value-format="yyyy-MM-dd"
placeholder="选择解绑时间">
</el-date-picker>
</el-form-item>
<el-form-item label="0-预热;1-正常;3-传感器故障;4-报警;5-通讯故障">
<el-radio-group v-model="form.status">
<el-radio label="1">请选择字典生成</el-radio>
</el-radio-group>
</el-form-item>
<el-form-item label="设置-年" prop="recordYear">
<el-input v-model="form.recordYear" placeholder="请输入设置-年" />
</el-form-item>
<el-form-item label="设置-月" prop="recordMonth">
<el-input v-model="form.recordMonth" placeholder="请输入设置-月" />
</el-form-item>
<el-form-item label="设置-日" prop="recordDate">
<el-input v-model="form.recordDate" placeholder="请输入设置-日" />
</el-form-item>
<el-form-item label="设置-时" prop="recordHour">
<el-input v-model="form.recordHour" placeholder="请输入设置-时" />
</el-form-item>
<el-form-item label="设置-分" prop="recordMinute">
<el-input v-model="form.recordMinute" placeholder="请输入设置-分" />
</el-form-item>
<el-form-item label="写入时间状态;0-失败;1-成功">
<el-radio-group v-model="form.writeTimeStatus">
<el-radio label="1">请选择字典生成</el-radio>
</el-radio-group>
</el-form-item>
<el-form-item label="调零AD" prop="adjustmentZeroAd">
<el-input v-model="form.adjustmentZeroAd" placeholder="请输入调零AD" />
</el-form-item>
<el-form-item label="合格;不合格">
<el-radio-group v-model="form.zeroStatus">
<el-radio label="1">请选择字典生成</el-radio>
</el-radio-group>
</el-form-item>
<el-form-item label="标定AD" prop="calibrationAd">
<el-input v-model="form.calibrationAd" placeholder="请输入标定AD" />
</el-form-item>
<el-form-item label="合格;不合格">
<el-radio-group v-model="form.calibrationStatus">
<el-radio label="1">请选择字典生成</el-radio>
</el-radio-group>
</el-form-item>
<el-form-item label="浓度值" prop="concentration">
<el-input v-model="form.concentration" placeholder="请输入浓度值" />
</el-form-item>
<el-form-item label="写入时间状态;0-失败;1-成功">
<el-radio-group v-model="form.runTimeStatus">
<el-radio label="1">请选择字典生成</el-radio>
</el-radio-group>
</el-form-item>
<el-form-item label="实时AD值" prop="realTimeAd">
<el-input v-model="form.realTimeAd" placeholder="请输入实时AD值" />
</el-form-item>
<el-form-item label="实时AD状态;0-异常;1-正常">
<el-radio-group v-model="form.realTimeAdStatus">
<el-radio label="1">请选择字典生成</el-radio>
</el-radio-group>
</el-form-item>
</el-form>
<div slot="footer" class="dialog-footer">
<el-button type="primary" @click="submitForm"> </el-button>
<el-button @click="cancel"> </el-button>
</div>
</el-dialog>
</div>
</template>
<script>
import { listHistory, getHistory, delHistory, addHistory, updateHistory, exportHistory ,reUpload} from "@/api/palletDeviceBinding/palletDeviceUploadHistory";
export default {
name: "History",
components: {
},
data() {
return {
// 遮罩层
loading: true,
// 导出遮罩层
exportLoading: false,
// 选中数组
ids: [],
// 非单个禁用
single: true,
// 非多个禁用
multiple: true,
// 显示搜索条件
showSearch: true,
// 总条数
total: 0,
// 未上传成功的历史数据列表格数据
historyList: [],
// 弹出层标题
title: "",
// 是否显示弹出层
open: false,
// 查询参数
queryParams: {
pageNum: 1,
pageSize: 10,
trayId: null,
deviceCode: null,
row: null,
col: null,
index: null,
number: null,
bindingTime: null,
unbindingTime: null,
createTime: null,
status: null,
recordYear: null,
recordMonth: null,
recordDate: null,
recordHour: null,
recordMinute: null,
writeTimeStatus: null,
adjustmentZeroAd: null,
zeroStatus: null,
calibrationAd: null,
calibrationStatus: null,
concentration: null,
runTimeStatus: null,
realTimeAd: null,
realTimeAdStatus: null
},
// 表单参数
form: {},
// 表单校验
rules: {
trayId: [
{ required: true, message: "托盘id不能为空", trigger: "blur" }
],
}
};
},
created() {
this.getList();
},
methods: {
/** 查询未上传成功的历史数据列列表 */
getList() {
this.loading = true;
listHistory(this.queryParams).then(response => {
this.historyList = response.rows;
this.total = response.total;
this.loading = false;
});
},
// 取消按钮
cancel() {
this.open = false;
this.reset();
},
// 表单重置
reset() {
this.form = {
id: null,
trayId: null,
deviceCode: null,
row: null,
col: null,
index: null,
number: null,
bindingTime: null,
unbindingTime: null,
createTime: null,
status: "0",
recordYear: null,
recordMonth: null,
recordDate: null,
recordHour: null,
recordMinute: null,
writeTimeStatus: "0",
adjustmentZeroAd: null,
zeroStatus: "0",
calibrationAd: null,
calibrationStatus: "0",
concentration: null,
runTimeStatus: "0",
realTimeAd: null,
realTimeAdStatus: "0"
};
this.resetForm("form");
},
/** 搜索按钮操作 */
handleQuery() {
this.queryParams.pageNum = 1;
this.getList();
},
/** 重置按钮操作 */
resetQuery() {
this.resetForm("queryForm");
this.handleQuery();
},
// 多选框选中数据
handleSelectionChange(selection) {
this.ids = selection.map(item => item.id)
this.single = selection.length!==1
this.multiple = !selection.length
},
//单个设备重新上传
handleSingleUpload(row) {
},
/** 新增按钮操作 */
handleAdd() {
this.reset();
this.open = true;
this.title = "添加未上传成功的历史数据列";
},
/** 修改按钮操作 */
handleUpdate(row) {
this.reset();
const id = row.id || this.ids
getHistory(id).then(response => {
this.form = response.data;
this.open = true;
this.title = "修改未上传成功的历史数据列";
});
},
/** 提交按钮 */
submitForm() {
this.$refs["form"].validate(valid => {
if (valid) {
if (this.form.id != null) {
updateHistory(this.form).then(response => {
this.msgSuccess("修改成功");
this.open = false;
this.getList();
});
} else {
addHistory(this.form).then(response => {
this.msgSuccess("新增成功");
this.open = false;
this.getList();
});
}
}
});
},
/** 删除按钮操作 */
handleDelete(row) {
const ids = row.id || this.ids;
this.$confirm('是否确认删除未上传成功的历史数据列编号为"' + ids + '"的数据项?', "警告", {
confirmButtonText: "确定",
cancelButtonText: "取消",
type: "warning"
}).then(function() {
return delHistory(ids);
}).then(() => {
this.getList();
this.msgSuccess("删除成功");
}).catch(() => {});
},
handleReUpload() {
this.$confirm('是否确认重新上传当前时间下设备编号不为空的所有数据?', '提示-成功后数据直接删除', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning'
}).then(() => {
reUpload().then(response => {
// 确保 response 有正确的结构
if (response && response.code === 200) {
// 处理部分失败或完全失败的情况
this.handleUploadResult(response);
}
this.getList(); // 重新加载数据
})
}).catch(() => {
});
},
// 单独处理上传结果的方法
handleUploadResult(response) {
if (!response) {
this.$message.error('上传失败,服务器无响应');
return;
}
// 检查是否有 data 字段
if (response.data) {
const data = response.data;
if (data.successCount >= 0 && data.failedCount >= 0) {
// 部分失败的情况
if (data.failedCount > 0) {
// 显示失败设备列表
if (data.failedDeviceCodes && data.failedDeviceCodes.length > 0) {
this.$alert(`失败设备:${data.failedDeviceCodes.join(', ')}`, '上传失败设备', {
confirmButtonText: '确定',
type: 'warning',
callback: () => {
this.getList();
}
})
}
} else {
this.$message.success('所有数据上传成功');
}
} else {
// 没有统计信息,显示通用错误消息
this.$message.error(response.msg || '上传失败');
}
} else {
// 没有 data 字段,显示错误消息
this.$message.error(response.msg || '上传失败');
}
},
/** 导出按钮操作 */
handleExport() {
const queryParams = this.queryParams;
this.$confirm('是否确认导出所有未上传成功的历史数据列数据项?', "警告", {
confirmButtonText: "确定",
cancelButtonText: "取消",
type: "warning"
}).then(() => {
this.exportLoading = true;
return exportHistory(queryParams);
}).then(response => {
this.download(response.msg);
this.exportLoading = false;
}).catch(() => {});
}
}
};
</script>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment