|
@@ -1,21 +1,181 @@
|
|
|
package cn.fastfun.controller.api;
|
|
|
|
|
|
import cn.fastfun.controller.dto.IndexStatDTO;
|
|
|
+import cn.fastfun.controller.param.BenchQueryDetailParam;
|
|
|
+import cn.fastfun.controller.param.BenchQueryParam;
|
|
|
+import cn.fastfun.controller.param.LibraryInQueryParam;
|
|
|
+import cn.fastfun.service.AppDeviceLogService;
|
|
|
+import cn.fastfun.service.AppDeviceService;
|
|
|
+import cn.fastfun.service.UtilService;
|
|
|
+import cn.fastfun.service.entity.AppDevice;
|
|
|
+import cn.fastfun.service.entity.AppDeviceLog;
|
|
|
+import cn.fastfun.util.DateUtils;
|
|
|
+import cn.fastfun.util.ObjectUtil;
|
|
|
import com.bridge.dto.ApiDTO;
|
|
|
+import com.bridge.dto.ApiPageDTO;
|
|
|
+import com.bridge.dto.QueryParam;
|
|
|
+import com.bridge.dto.QueryParamExp;
|
|
|
import io.swagger.annotations.Api;
|
|
|
import io.swagger.annotations.ApiOperation;
|
|
|
-import org.springframework.web.bind.annotation.PostMapping;
|
|
|
-import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
+import jdk.nashorn.internal.runtime.PropertyMap;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.springframework.data.domain.Page;
|
|
|
+import org.springframework.util.StringUtils;
|
|
|
+import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
+import javax.annotation.Resource;
|
|
|
+import javax.persistence.Query;
|
|
|
+import java.math.BigInteger;
|
|
|
+import java.text.SimpleDateFormat;
|
|
|
+import java.util.*;
|
|
|
+
|
|
|
+@Slf4j
|
|
|
@Api(tags = {"首页工作台"})
|
|
|
+@RestController
|
|
|
@RequestMapping("/api/v1")
|
|
|
public class IndexController {
|
|
|
+ @Resource(name = "appDeviceService")
|
|
|
+ AppDeviceService appDeviceService;
|
|
|
|
|
|
+ @Resource
|
|
|
+ AppDeviceLogService appDeviceLogService;
|
|
|
|
|
|
- @ApiOperation(value = "设备管理系统工作台")
|
|
|
- @PostMapping("stat")
|
|
|
+ @ApiOperation(value = "设备管理系统工作台 统计")
|
|
|
+ @PostMapping("sta")
|
|
|
public ApiDTO index() {
|
|
|
IndexStatDTO dto = new IndexStatDTO();
|
|
|
+
|
|
|
+ Date today = new Date();
|
|
|
+ Calendar calendar = new GregorianCalendar();
|
|
|
+ calendar.setTime(today);
|
|
|
+ calendar.add(calendar.DATE, +1);//把日期往后增加一天.整数往后推,负数往前移动
|
|
|
+ Date tomorrow = calendar.getTime();
|
|
|
+
|
|
|
+ SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd 00:00:00");
|
|
|
+
|
|
|
+
|
|
|
+ StringBuffer sql = new StringBuffer();
|
|
|
+
|
|
|
+ Long batteryTotal = appDeviceService.getCount();
|
|
|
+
|
|
|
+ sql.append("select count(0) from app_device where add_time > '")
|
|
|
+ .append(sdf.format(today)).append("' and add_time < '");
|
|
|
+
|
|
|
+ sql.append(sdf.format(tomorrow)).append("'");
|
|
|
+ log.info("SQL: {}", sql.toString());
|
|
|
+ Query q = appDeviceService.getQueryBySQL(sql.toString(), new HashMap<>());
|
|
|
+ Long batteryTodayRecord = ((BigInteger) q.getSingleResult()).longValue();
|
|
|
+
|
|
|
+ sql = new StringBuffer();
|
|
|
+ sql.append("select count(distinct sn) from app_device_log where add_time > '")
|
|
|
+ .append(sdf.format(today)).append("' and add_time < '");
|
|
|
+ sql.append(sdf.format(tomorrow)).append("' and (type=1 or type=5)");
|
|
|
+ log.info("SQL: {}", sql.toString());
|
|
|
+ q = appDeviceService.getQueryBySQL(sql.toString(), new HashMap<>());
|
|
|
+ Long batteryTodayInstorage = ((BigInteger) q.getSingleResult()).longValue();
|
|
|
+
|
|
|
+ sql = new StringBuffer();
|
|
|
+ sql.append("select count(distinct sn) from app_device_log where type=2 ");
|
|
|
+ log.info("SQL: {}", sql.toString());
|
|
|
+ q = appDeviceService.getQueryBySQL(sql.toString(), new HashMap<>());
|
|
|
+ Long batteryHistoryOutstorage = ((BigInteger) q.getSingleResult()).longValue();
|
|
|
+
|
|
|
+ sql = new StringBuffer();
|
|
|
+ sql.append("select count(0) from app_device where status=1 or status=2 ");
|
|
|
+ log.info("SQL: {}", sql.toString());
|
|
|
+ q = appDeviceService.getQueryBySQL(sql.toString(), new HashMap<>());
|
|
|
+ Long stock = ((BigInteger) q.getSingleResult()).longValue();
|
|
|
+
|
|
|
+ sql = new StringBuffer();
|
|
|
+ sql.append("select count(distinct sn) from app_device_log where type=5 ");
|
|
|
+ log.info("SQL: {}", sql.toString());
|
|
|
+ q = appDeviceService.getQueryBySQL(sql.toString(), new HashMap<>());
|
|
|
+ Long batteryHistoryHandle = ((BigInteger) q.getSingleResult()).longValue();
|
|
|
+
|
|
|
+
|
|
|
+ dto.setBatteryTodayRecord(batteryTodayRecord);
|
|
|
+ dto.setBatteryTotal(batteryTotal);
|
|
|
+ dto.setBatteryTodayInstorage(batteryTodayInstorage);
|
|
|
+ dto.setBatteryHistoryOutstorage(batteryHistoryOutstorage);
|
|
|
+ dto.setStock(stock);
|
|
|
+ dto.setBatteryHistoryHandle(batteryHistoryHandle);
|
|
|
return ApiDTO.ok(dto);
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ @ApiOperation(value = "工作台 查询")
|
|
|
+ @RequestMapping(value = "pageQuery", method = RequestMethod.POST)
|
|
|
+ public ApiPageDTO pageQuery(@RequestBody BenchQueryParam param) {
|
|
|
+ Page<AppDevice> devicePage = appDeviceService.findByParam(param);
|
|
|
+ devicePage.getContent().forEach(p -> {
|
|
|
+
|
|
|
+ appDeviceService.addImeiTitle(p);
|
|
|
+ });
|
|
|
+ return new ApiPageDTO(null, devicePage);
|
|
|
+ }
|
|
|
+
|
|
|
+ @ApiOperation(value = "工作台 查看详情")
|
|
|
+ @RequestMapping(value = "pageQuery/detail", method = RequestMethod.POST)
|
|
|
+ public ApiPageDTO pageQueryDetail(@RequestBody BenchQueryDetailParam param) {
|
|
|
+ AppDevice devicePage = appDeviceService.getOne(QueryParamExp.eq("sn", param.getSn()));
|
|
|
+ appDeviceService.addImeiTitle(devicePage);
|
|
|
+ HashMap<String, Object> res = new HashMap<>();
|
|
|
+
|
|
|
+ res.put("sn", devicePage.getSn());
|
|
|
+ res.put("imei", devicePage.getImei());
|
|
|
+ res.put("status", devicePage.getStatus());
|
|
|
+ res.put("deliverTime", devicePage.getDeliverTime());
|
|
|
+ res.put("instorageTime", devicePage.getInstorageTime());
|
|
|
+ res.put("transferTime", devicePage.getTransferTime());
|
|
|
+ res.put("transferBackTime", devicePage.getTransferBackTime());
|
|
|
+ res.put("outstorageTime", devicePage.getOutstorageTime());
|
|
|
+ res.put("handleTime", devicePage.getHandleTime());
|
|
|
+
|
|
|
+
|
|
|
+ if (devicePage.getStatus() == 2 || devicePage.getStatus() == 3){
|
|
|
+ QueryParam query = new QueryParam();
|
|
|
+ query.addParam(QueryParamExp.eq("sn", devicePage.getSn()));
|
|
|
+ query.addParam(QueryParamExp.eq("type", 2));
|
|
|
+ query.addParam(QueryParamExp.eq("addTime", devicePage.getTransferTime()));
|
|
|
+ Page<AppDeviceLog> deviceLogPage = appDeviceLogService.findByParam(query);
|
|
|
+ AppDeviceLog deviceLog = new AppDeviceLog();
|
|
|
+ if (!deviceLogPage.isEmpty()) {
|
|
|
+ deviceLog = deviceLogPage.getContent().get(0);
|
|
|
+ res.put("ownerId", deviceLog.getOutCustomId());
|
|
|
+ res.put("deviceType", deviceLog.getTfDeviceType());
|
|
|
+ res.put("used", deviceLog.getTfUsed());
|
|
|
+ res.put("describe", deviceLog.getTfDescribe());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (!StringUtils.isEmpty(devicePage.getHandleTime())){
|
|
|
+ QueryParam query = new QueryParam();
|
|
|
+ query.addParam(QueryParamExp.eq("sn", devicePage.getSn()));
|
|
|
+ query.addParam(QueryParamExp.eq("type", 5));
|
|
|
+ query.addParam(QueryParamExp.eq("addTime", devicePage.getHandleTime()));
|
|
|
+ Page<AppDeviceLog> deviceLogPage = appDeviceLogService.findByParam(query);
|
|
|
+ AppDeviceLog lastDeviceLogPage = new AppDeviceLog();
|
|
|
+ if (!deviceLogPage.isEmpty()) {
|
|
|
+ lastDeviceLogPage = deviceLogPage.getContent().get(0);
|
|
|
+ res.put("handleType", lastDeviceLogPage.getType());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ res.put("lastOnLineTime", 0);
|
|
|
+ res.put("lat", 0);
|
|
|
+ res.put("long", 0);
|
|
|
+ res.put("typeTitle", devicePage.getTypeTitle());
|
|
|
+ res.put("packTitle", devicePage.getPackTitle());
|
|
|
+ res.put("specTitle", devicePage.getSpecTitle());
|
|
|
+ res.put("expandTitle", devicePage.getExpandTitle());
|
|
|
+ res.put("batStatus", 0);
|
|
|
+ res.put("soc", 0);
|
|
|
+ res.put("current", 0);
|
|
|
+ res.put("temp", 0);
|
|
|
+ res.put("soh", 0);
|
|
|
+ res.put("odo", 0);
|
|
|
+ res.put("accumChargeTime",0);
|
|
|
+ res.put("cycleCount", 0);
|
|
|
+ List<Map<String, Object>> result = new ArrayList<>();
|
|
|
+ result.add(res);
|
|
|
+ return new ApiPageDTO(null, result);
|
|
|
}
|
|
|
}
|