Commit cb2a1770 authored by 廖旭伟's avatar 廖旭伟

设备列表接口返回值增加设备状态统计数

parent 50ef48a5
package com.mortals.xhx.module.device.web; package com.mortals.xhx.module.device.web;
import com.mortals.framework.annotation.UnAuth;
import com.mortals.framework.common.Rest;
import com.mortals.framework.model.Context;
import com.mortals.framework.model.PageInfo;
import com.mortals.framework.model.Result;
import com.mortals.framework.web.BaseCRUDJsonBodyMappingController; import com.mortals.framework.web.BaseCRUDJsonBodyMappingController;
import com.mortals.xhx.module.device.model.DeviceEntity; import com.mortals.xhx.module.device.model.DeviceEntity;
import com.mortals.xhx.module.device.service.DeviceService; import com.mortals.xhx.module.device.service.DeviceService;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
import java.util.HashMap;
import java.util.Map;
/** /**
* 设备 * 设备
* *
...@@ -18,5 +28,58 @@ import org.springframework.web.bind.annotation.RestController; ...@@ -18,5 +28,58 @@ import org.springframework.web.bind.annotation.RestController;
@Slf4j @Slf4j
public class DeviceController extends BaseCRUDJsonBodyMappingController<DeviceService, DeviceEntity, Long> { public class DeviceController extends BaseCRUDJsonBodyMappingController<DeviceService, DeviceEntity, Long> {
@Override
@PostMapping({"list"})
@UnAuth
public Rest<Object> list(@RequestBody DeviceEntity query) {
Rest<Object> ret = new Rest();
Map<String, Object> model = new HashMap();
Context context = this.getContext();
String busiDesc = "查询" + this.getModuleDesc();
int code;
try {
PageInfo pageInfo = this.buildPageInfo(query);
this.doListBefore(query, model, context);
Result<DeviceEntity> result = this.getService().find(query, pageInfo, context);
model.put("data", result.getList());
int onlineTotal = 0;
int offlineTotal = 0;
int not_active = 0;
int stop_using = 0;
for(DeviceEntity deviceEntity:result.getList()){
if(deviceEntity.getDeviceStatus()==0){
not_active++;
}
if(deviceEntity.getDeviceStatus()==1){
offlineTotal++;
}
if(deviceEntity.getDeviceStatus()==2){
onlineTotal++;
}
if(deviceEntity.getEnabled()==0){
stop_using++;
}
}
model.put("online", onlineTotal);
model.put("offline", offlineTotal);
model.put("notActive", not_active);
model.put("stopUsing", stop_using);
model.put("pageInfo", result.getPageInfo());
this.parsePageInfo(model, result.getPageInfo());
code = this.doListAfter(query, model, context);
model.put("message_info", busiDesc + "成功");
this.recordSysLog(this.request, busiDesc + " 【成功】");
} catch (Exception var9) {
code = -1;
this.doException(this.request, busiDesc, model, var9);
}
this.init(model, context);
ret.setCode(code);
ret.setData(model);
ret.setDict(model.get("dict"));
ret.setMsg(model.get("message_info") == null ? "" : model.remove("message_info").toString());
return ret;
}
} }
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment