lmstack преди 3 години
родител
ревизия
4f444d8a0b

+ 164 - 4
src/main/java/cn/fastfun/controller/api/IndexController.java

@@ -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);
     }
 }

+ 1 - 1
src/main/java/cn/fastfun/controller/dto/DevicePageStatDTO.java

@@ -32,7 +32,7 @@ public class DevicePageStatDTO {
     @ApiModelProperty(value = "可出库总量", name = "outStorageAble", required = true)
     private Long outStorageAble = 0l;
 
-    @ApiModelProperty(value = "已处置总量", name = "outStorageAble", required = true)
+    @ApiModelProperty(value = "已处置总量", name = "handle", required = true)
     private Long handle = 0l;
 
 }

+ 8 - 8
src/main/java/cn/fastfun/controller/dto/IndexStatDTO.java

@@ -17,20 +17,20 @@ public class IndexStatDTO {
     @ApiModelProperty(value = "配件总量", name = "partsTotal")
     private long partsTotal = 0;
 
-    @ApiModelProperty(value = "今日录入", name = "todayEnter")
-    private long todayEnter = 0;
+    @ApiModelProperty(value = "今日录入", name = "batteryTodayRecord")
+    private long batteryTodayRecord = 0;
 
-    @ApiModelProperty(value = "今日入库", name = "todayPut")
-    private long todayPut = 0;
+    @ApiModelProperty(value = "今日入库", name = "batteryTodayInstorage")
+    private long batteryTodayInstorage = 0;
 
-    @ApiModelProperty(value = "历史电池出库", name = "historyOutBattery")
-    private long historyOutBattery = 0;
+    @ApiModelProperty(value = "历史电池出库", name = "batteryHistoryOutstorage")
+    private long batteryHistoryOutstorage = 0;
 
     @ApiModelProperty(value = "历史配件出库", name = "historyOutParts")
     private long historyOutParts = 0;
 
-    @ApiModelProperty(value = "历史处置", name = "historyHandle")
-    private long historyHandle = 0;
+    @ApiModelProperty(value = "历史处置", name = "batteryHistoryHandle")
+    private long batteryHistoryHandle = 0;
 
     @ApiModelProperty(value = "库存", name = "stock")
     private long stock = 0;

+ 20 - 0
src/main/java/cn/fastfun/controller/param/BenchQueryDetailParam.java

@@ -0,0 +1,20 @@
+package cn.fastfun.controller.param;
+
+import com.bridge.dto.QueryParam;
+import com.bridge.dto.QueryParamExp;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Getter;
+import lombok.Setter;
+import org.springframework.util.CollectionUtils;
+import org.springframework.util.StringUtils;
+
+import java.util.List;
+
+@Getter
+@Setter
+public class BenchQueryDetailParam {
+
+
+    @ApiModelProperty(value = "SN号", name = "sn", required = true)
+    private String sn;
+}

+ 38 - 0
src/main/java/cn/fastfun/controller/param/BenchQueryParam.java

@@ -0,0 +1,38 @@
+package cn.fastfun.controller.param;
+
+import com.bridge.dto.QueryParam;
+import com.bridge.dto.QueryParamExp;
+import com.fasterxml.jackson.annotation.JsonFormat;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Getter;
+import lombok.Setter;
+import org.springframework.format.annotation.DateTimeFormat;
+import org.springframework.util.CollectionUtils;
+import org.springframework.util.StringUtils;
+
+import java.util.Date;
+import java.util.List;
+
+@Getter
+@Setter
+public class BenchQueryParam extends QueryParam{
+
+
+    @ApiModelProperty(value = "sn", name = "sn", required = true)
+    public void setSn(String sn) {
+        if (!StringUtils.isEmpty(sn))
+            addParam(QueryParamExp.like("sn", "%".concat(sn).concat("%")));
+    }
+
+    @ApiModelProperty(value = "设备类型", name = "checkStatus", example = "0, 0:未通过 ; 1:已通过;  空:全部")
+    private Integer checkStatus;
+
+    @ApiModelProperty(value = "设备状态", name = "status", example = "[], 0:未入库,1:已入库,2:已调拨,3:已出库,4:已处置")
+    public void setStatus(List<Integer> status) {
+        if (!CollectionUtils.isEmpty(status)) {
+            addParam(QueryParamExp.in("status", status.toArray(new Integer[]{})));
+        }
+    }
+
+
+}