package com.billion.main.da.service.impl;
|
|
import cn.hutool.http.HttpRequest;
|
import cn.hutool.http.HttpResponse;
|
import cn.hutool.json.JSONUtil;
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
import com.billion.common.utils.http.HttpUtils;
|
import com.billion.main.constant.Constants;
|
import com.billion.main.da.domain.DaStationCollection;
|
import com.billion.main.da.domain.CollectTrack;
|
import com.billion.main.da.mapper.DaStationCollectionMapper;
|
import com.billion.main.da.service.IDaStationCollectionService;
|
import com.billion.main.om.domain.OmOrderScheduling;
|
import com.billion.main.om.service.IOmOrderSchedulingService;
|
import lombok.extern.slf4j.Slf4j;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.stereotype.Service;
|
|
import java.text.SimpleDateFormat;
|
import java.util.List;
|
import java.util.Objects;
|
|
/**
|
* 过站采集Service业务层处理
|
*
|
* @author HDY
|
* @date 2025-02-12
|
*/
|
@Slf4j
|
@Service
|
public class DaStationCollectionServiceImpl extends ServiceImpl<DaStationCollectionMapper, DaStationCollection> implements IDaStationCollectionService
|
{
|
@Autowired
|
private DaStationCollectionMapper daStationCollectionMapper;
|
@Autowired
|
public IOmOrderSchedulingService omOrderSchedulingService;
|
/**
|
* 查询过站采集
|
*
|
* @param id 过站采集主键
|
* @return 过站采集
|
*/
|
@Override
|
public DaStationCollection selectDaStationCollectionById(Long id)
|
{
|
return daStationCollectionMapper.selectDaStationCollectionById(id);
|
}
|
|
/**
|
* 查询过站采集列表
|
*
|
* @param daStationCollection 过站采集
|
* @return 过站采集
|
*/
|
@Override
|
public List<DaStationCollection> selectDaStationCollectionList(DaStationCollection daStationCollection)
|
{
|
return daStationCollectionMapper.selectDaStationCollectionList(daStationCollection);
|
}
|
|
/**
|
* 新增过站采集
|
*
|
* @param daStationCollection 过站采集
|
* @return 结果
|
*/
|
// @Override
|
// public int insertDaStationCollection(DaStationCollection daStationCollection)
|
// {
|
//// EngineData engineData = new EngineData();
|
//// engineData.setEngineType("1");
|
//// String s = HttpUtils.sendPost("http://172.40.161.71:8080/prod-api/CollectTrack", JSONUtil.toJsonStr(engineData));
|
// return daStationCollectionMapper.insertDaStationCollection(daStationCollection);
|
// }
|
|
|
@Override
|
public int insertDaStationCollection(DaStationCollection daStationCollection) {
|
String url = "http://172.40.161.71:8890/Interaction/CollectTrack";
|
OmOrderScheduling omOrderScheduling = new OmOrderScheduling();
|
// 创建EngineData对象并设置字段值
|
CollectTrack collectTrack = new CollectTrack();
|
|
omOrderScheduling.setSfcCode(daStationCollection.getSfcCode());
|
if(Objects.equals(daStationCollection.getLocationCode(), Constants.PLC1.toString()) ||
|
Objects.equals(daStationCollection.getLocationCode(), Constants.C005) ||
|
Objects.equals(daStationCollection.getLocationCode(), Constants.C060))
|
{omOrderScheduling.setRemarks("Head");}
|
else if(Objects.equals(daStationCollection.getLocationCode(), Constants.PLC2.toString()) ||
|
Objects.equals(daStationCollection.getLocationCode(), Constants.OP005) ||
|
Objects.equals(daStationCollection.getLocationCode(), Constants.OP310))
|
{omOrderScheduling.setRemarks("Body");}
|
else if(Objects.equals(daStationCollection.getLocationCode(), Constants.P010))
|
{omOrderScheduling.setRemarks("Pre");}
|
List<OmOrderScheduling> omOrderSchedulingList = omOrderSchedulingService.selectOmOrderSchedulingList(omOrderScheduling);
|
|
collectTrack.setOrderNumber(omOrderSchedulingList.get(0).getWorkOrderNo());
|
collectTrack.setStationName(daStationCollection.getLocationCode());
|
// 处理日期时间字段
|
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
collectTrack.setInsertTime(sdf.format(daStationCollection.getInboundTime()));
|
String factoryNumber = daStationCollection.getSfcCode();
|
collectTrack.setFactoryNumber(factoryNumber);
|
// EngineType设置为FactoryNumber去除后九位
|
// 假设此处为取factoryNumber的前部分作为EngineType
|
String engineType = daStationCollection.getSfcCode().length() > 9 ? daStationCollection.getSfcCode().substring(0, daStationCollection.getSfcCode().length() - 9) : daStationCollection.getSfcCode();
|
collectTrack.setEngineType(engineType);
|
// EngineNumber设置为FactoryNumber的后九位
|
// 假设此处为取factoryNumber的后九位字符
|
String engineNumber = daStationCollection.getSfcCode().length() >= 9 ? daStationCollection.getSfcCode().substring(daStationCollection.getSfcCode().length() - 9) : daStationCollection.getSfcCode();
|
collectTrack.setEngineNumber(engineNumber);
|
// CycleTime设置为outboundTime减去inboundTime的时间差(格式化为字符串)
|
long cycleTimeMillis = daStationCollection.getOutboundTime().getTime() - daStationCollection.getInboundTime().getTime();
|
long cycleTimeSeconds = cycleTimeMillis / 1000; // 假设以秒为单位
|
collectTrack.setCycleTime(String.valueOf(cycleTimeSeconds));
|
collectTrack.setFlag(Integer.parseInt(daStationCollection.getStatus()));
|
// 发送POST请求
|
try {
|
HttpResponse response = HttpRequest.post(url).body(JSONUtil.toJsonStr(collectTrack)).execute();
|
log.info("推送成功,响应报文: {}", response);
|
} catch (Exception e) {
|
// 记录日志
|
log.error("推送失败, sfcCode: {}",collectTrack.getFactoryNumber());
|
}
|
// 无论推送成功与否,都继续执行数据库插入操作
|
return daStationCollectionMapper.insertDaStationCollection(daStationCollection);
|
}
|
|
/**
|
* 修改过站采集
|
*
|
* @param daStationCollection 过站采集
|
* @return 结果
|
*/
|
@Override
|
public int updateDaStationCollection(DaStationCollection daStationCollection)
|
{
|
return daStationCollectionMapper.updateDaStationCollection(daStationCollection);
|
}
|
|
/**
|
* 批量删除过站采集
|
*
|
* @param ids 需要删除的过站采集主键
|
* @return 结果
|
*/
|
@Override
|
public int deleteDaStationCollectionByIds(Long[] ids)
|
{
|
return daStationCollectionMapper.deleteDaStationCollectionByIds(ids);
|
}
|
|
/**
|
* 删除过站采集信息
|
*
|
* @param id 过站采集主键
|
* @return 结果
|
*/
|
@Override
|
public int deleteDaStationCollectionById(Long id)
|
{
|
return daStationCollectionMapper.deleteDaStationCollectionById(id);
|
}
|
}
|