-
admin
2025-03-26 5e0888a8dc804a4df27ce033b6c3429e530a9ef9
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
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);
    }
}