|
|
@@ -12,6 +12,8 @@ import com.zksy.pole.mapper.DgGatewayRegistrationMapper;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Component;
|
|
|
|
|
|
+import java.util.Date;
|
|
|
+
|
|
|
@Component
|
|
|
public class HandleCmdFactory {
|
|
|
@Autowired
|
|
|
@@ -32,11 +34,18 @@ public class HandleCmdFactory {
|
|
|
private HandleDgReportEnvironmentalDataCmd handleDgReportEnvironmentalDataCmd;
|
|
|
@Autowired
|
|
|
private HandleDgTimelyControlCmd handleDgTimelyControlCmd;
|
|
|
+
|
|
|
public String HandleCmd(String data) {
|
|
|
JSONObject jsonObject = JSONUtil.parseObj(data);
|
|
|
int cmd = jsonObject.getInt("cmd");
|
|
|
- if(jsonObject.getInt("timestamp") != null){
|
|
|
- jsonObject.set("date_time", DateUtil.parseDate(jsonObject.getStr("timestamp")));
|
|
|
+ if (jsonObject.getInt("timestamp") != null) {
|
|
|
+ Long timestamp = jsonObject.getLong("timestamp") * 1000;
|
|
|
+ Date date = new Date(timestamp);
|
|
|
+ jsonObject.set("date_time", DateUtil.formatDateTime(date));
|
|
|
+ }
|
|
|
+ String[] paramNames = {"params", "params2", "params3"};
|
|
|
+ for (String paramName : paramNames) {
|
|
|
+ convertToJsonString(jsonObject, paramName);
|
|
|
}
|
|
|
String s;
|
|
|
switch (cmd) {
|
|
|
@@ -68,7 +77,14 @@ public class HandleCmdFactory {
|
|
|
s = handleDgTimelyControlCmd.HandleCmdMethod(jsonObject.toBean(DgTimelyControl.class));
|
|
|
return s;
|
|
|
default:
|
|
|
- throw new CommonException("cmd有误或者没有对应的cmd处理", 500);
|
|
|
+ return null;
|
|
|
+// throw new CommonException("cmd有误或者没有对应的cmd处理", 500);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ private void convertToJsonString(JSONObject jsonObject, String paramName) {
|
|
|
+ Object value = jsonObject.get(paramName);
|
|
|
+ if (value != null) {
|
|
|
+ jsonObject.set(paramName, value.toString());
|
|
|
}
|
|
|
}
|
|
|
}
|