yangbin
2025-05-20 1cbbb341d22e3c46b15af65b6f97d738bae7ca95
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
165
166
167
168
169
170
171
172
173
174
175
176
177
178
package org.jeecg.modules.msi.webapi.service.impl;
 
import cn.hutool.core.date.DateUtil;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.apache.commons.lang3.StringUtils;
import org.jeecg.common.util.DateUtils;
import org.jeecg.modules.msi.webapi.entity.MsiWebapiJsonEntity;
import org.jeecg.modules.msi.webapi.mapper.MsiWebapiJsonMapper;
import org.jeecg.modules.msi.webapi.service.IMsiWebapiJsonService;
import org.jeecg.modules.msi.webapi.vo.DetailedListVo;
import org.jeecg.modules.msi.webapi.vo.MachineEquipentInfo;
import org.springframework.stereotype.Service;
 
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
 
@Service
public class MsiWebapiJsonServiceImpl extends ServiceImpl<MsiWebapiJsonMapper, MsiWebapiJsonEntity> implements IMsiWebapiJsonService {
 
 
    @Override
    public boolean saveTableAutomationOne(List<MachineEquipentInfo> data) {
        if (data ==null || data.isEmpty()) {
            return false;
        }
        List<String> listStatus = new ArrayList<>();
        List<String> listParameter = new ArrayList<>();
        for (MachineEquipentInfo machineInfo : data) {
            System.out.println(machineInfo);
            String stutus = listSqls(machineInfo);
            if (stutus != null && !stutus.equals("")) {
                listStatus.add(stutus);
            }
            String parameter = listSqlParameter(machineInfo);
            if (parameter != null && !parameter.equals("")) {
                listParameter.add(parameter);
            }
        }
        //状态数据
 
        return false;
    }
 
 
    /**
     *  插入到EquipmentLog
     * @param machineInfo
     * @return
     */
    public String listSqlParameter(MachineEquipentInfo machineInfo) {
        String listSqls = null;
        List<DetailedListVo> itemList = machineInfo.getItemList();
        Map<String ,DetailedListVo> itemMap = new HashMap<String ,DetailedListVo>();
        for (DetailedListVo item: itemList) {
            itemMap.put(item.getItemName(),item);
        }
        String sql = "insert into ";
        sql = sql + "ZDH_" + machineInfo.getMachineNo() + " ";
        sql = sql + "(EquipmentID,EquipmentName,CollectTime,runningStatus,spindleSpeed,feedRatio,runDuration,spindleDuration,progName,progStatus,toolNo) values (  ";
        //EquipmentID
        if (machineInfo.getMachineNo() == null ||  machineInfo.getMachineNo().equals("")) {
            return null;
        } else {
            sql = sql + "'" + machineInfo.getMachineNo() + "', ";
        }
        //EquipmentName
        sql = sql + null + ", ";
        //CollectTime
        if (machineInfo.getEndTime() != null) {
            sql = sql + "'" + DateUtils.formattedDate(machineInfo.getEndTime(),DateUtils.STR_DD_MM_YYYY,DateUtils.STR_DATE_TIME_SMALL) + "', ";
        } else {
            sql = sql + "'" + DateUtils.format(DateUtils.getDate(),DateUtils.STR_DATE_TIME) + "', ";
        }
        //runningStatus
        if (itemMap.containsKey("runningStatus")) {
            sql = sql + "'" + itemMap.get("runningStatus").getItemValue() + "', ";
        } else {
            sql = sql + null + ", ";
        }
        //spindleSpeed
        if (itemMap.containsKey("spindleSpeed")) {
            sql = sql + "'" + itemMap.get("spindleSpeed").getItemValue() + "', ";
        } else {
            sql = sql + null + ", ";
        }
        //runDuration
        if (itemMap.containsKey("runDuration")) {
            sql = sql + "'" + itemMap.get("runDuration").getItemValue() + "', ";
        } else {
            sql = sql + null + ", ";
        }
        //spindleDuration
        if (itemMap.containsKey("spindleDuration")) {
            sql = sql + "'" + itemMap.get("spindleDuration").getItemValue() + "', ";
        } else {
            sql = sql + null + ", ";
        }
        //progName
        if (itemMap.containsKey("spindleSpeed")) {
            sql = sql + "'" + itemMap.get("spindleSpeed").getItemValue() + "', ";
        } else {
            sql = sql + null + ", ";
        }
        //progStatus
        if (itemMap.containsKey("progStatus")) {
            sql = sql + "'" + itemMap.get("progStatus").getItemValue() + "', ";
        } else {
            sql = sql + null + ", ";
        }
        //toolNo
        if (itemMap.containsKey("toolNo")) {
            sql = sql + "'" + itemMap.get("toolNo").getItemValue() + "'  ";
        } else {
            sql = sql + null;
        }
 
        sql = sql + "); \n";
        if (StringUtils.isBlank(listSqls) ) {
            listSqls = sql;
        } else {
            listSqls += sql;
        }
        return listSqls;
    }
 
 
    /**
     *  插入到EquipmentLog
     * @param machineInfo
     * @return
     */
    public String listSqls(MachineEquipentInfo machineInfo) {
        String listSqls = null;
        List<DetailedListVo> itemList = machineInfo.getItemList();
        String sql = "insert into EquipmentLog (EquipmentID,EquipmentName,CollectTime,Oporation,Alarm) values ( ";
        if (machineInfo.getMachineNo() == null) {
            return null;
        } else {
            sql = sql + "'" + machineInfo.getMachineNo() + "', ";
        }
        sql = sql + null + ", ";
        if (machineInfo.getEndTime() != null) {
 
            sql = sql + "'" + DateUtils.formattedDate(machineInfo.getEndTime(),DateUtils.STR_DD_MM_YYYY,DateUtils.STR_DATE_TIME_SMALL) + "', ";
        } else {
            return null;
        }
        Map<String ,DetailedListVo> itemMap = new HashMap<String ,DetailedListVo>();
        for (DetailedListVo item: itemList) {
            itemMap.put(item.getItemName(),item);
        }
        if (itemMap.containsKey("runningStatus")) {
            int oporation = 0;
            switch (itemMap.get("runningStatus").getItemValue()) {
                case "0" : oporation =0;break;
                case "1" : oporation =2;break;
                case "2" : oporation =3;break;
                case "3" : oporation =2;break;
                case "4" : oporation =2;break;
                case "10" : oporation =2;break;
                case "13" : oporation =2;break;
                case "14" : oporation =2;break;
                case "10001" : oporation =2;break;
                default: break;
            }
            sql = sql + " " + oporation  + ", ";
        } else {
            return null;
        }
        sql = sql + null +   " ); \n";
        if (StringUtils.isBlank(listSqls) ) {
            listSqls = sql;
        }
        return listSqls;
    }
}