package com.qianwen.mdc.collect.handler;
|
|
import java.util.Arrays;
|
import java.util.Date;
|
|
import org.slf4j.Logger;
|
import org.slf4j.LoggerFactory;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.stereotype.Component;
|
|
import com.qianwen.mdc.collect.cache.WorkstationCache;
|
import com.qianwen.mdc.collect.dto.PackedTelemetryData;
|
import com.qianwen.mdc.collect.entity.iotdb.DeviceState;
|
import com.qianwen.mdc.collect.entity.mgr.GlobalWcsOfRps;
|
import com.qianwen.mdc.collect.enums.FeedbackTimePointEnum;
|
import com.qianwen.mdc.collect.service.DeviceStateService;
|
|
@Component
|
public class DeviceStatusDataHandler implements TelemetryDataHandler {
|
private static final Logger log = LoggerFactory.getLogger(DeviceStatusDataHandler.class);
|
@Autowired
|
private WorkstationCache workstationCache;
|
//@Autowired
|
//private IotDBSessionConfig iotdbCfg;
|
//@Autowired
|
//private IotDBCommonService iotDBCommonService;
|
@Autowired
|
private DeviceStateService deviceStateService;
|
@Override
|
public void handleData(PackedTelemetryData data) {
|
DeviceState state = new DeviceState();
|
state.setTime(data.getTime());
|
state.setCalendarCode(data.getCalendarCode());
|
|
state.setFactoryDate(data.getFactoryDate());
|
state.setFactoryMonth(data.getFactoryMonth());
|
state.setFactoryWeek(data.getFactoryWeek());
|
state.setFactoryYear(data.getFactoryYear());
|
state.setIsFixPoint(false);
|
state.setIsSync(false);
|
state.setIsDeleted(false);
|
|
state.setEmployeeId(workstationCache.getBelongToEmployeeForWorkstation(data.getWorkstationId(), new Date(data.getTime())));
|
|
state.setFeedbackPointType(FeedbackTimePointEnum.NO_FEED_BACK_POINT.getValue());
|
//WorkstationState propertyData = (WorkstationState) Objects.requireNonNull(BeanUtil.copy(entity, WorkstationState.class));
|
state.setValueCollect(translateStatus(data.getValue()));
|
|
state.setWcs(state.getValueCollect());
|
state.setWorkstationId(data.getWorkstationId());
|
|
state.setShiftIndex(data.getShiftIndex());
|
state.setShiftTimeType(data.getShiftTimeType());
|
fillWorkStationCondition(data, state);
|
|
//insertState(state);
|
deviceStateService.saveDeviceStates(Arrays.asList(state));
|
|
log.info("设备状态保存完成");
|
}
|
|
private void fillWorkStationCondition(PackedTelemetryData data, DeviceState state) {
|
GlobalWcsOfRps wcsOfRps = workstationCache.getWorkstationWcsSetting(data.getWorkstationId(), data.getValue());
|
log.info("工况以及绩效信息:{}" ,wcsOfRps);
|
|
state.setRps(Integer.valueOf(wcsOfRps.getRps()));
|
state.setIsPlan(Integer.valueOf(wcsOfRps.getIsPlan()));
|
//log.info("获取包装工况以及绩效信息" + JsonUtil.toJson(workstationState));
|
|
}
|
|
int translateStatus(String statusVal) {
|
int oriStatus = Integer.valueOf(statusVal);
|
|
int result = oriStatus;
|
//西门子828d, cnc_run_status: 运行状态(0:RESET,1:STOP,2:HOLD,3:START,4:SPENDLE_CW_CCW,5:OTHER)
|
switch(oriStatus) {
|
case 3://START
|
result = 2;
|
break;
|
case 0://,reset
|
case 2://hold
|
result = 3;//3待机
|
break;
|
case 4:// SPENDLE_CW_CCW
|
result = 2;
|
break;
|
case 5://其他
|
result = oriStatus;
|
break;
|
default:
|
result = oriStatus;
|
}
|
log.info("statusconvert,ori={},result={}",oriStatus,result);
|
if(result == 0) {
|
result = 2;//
|
}
|
return result;
|
}
|
}
|