Browse Source

bug修复

lmstack 3 years ago
parent
commit
1a56f74aab

+ 46 - 8
src/main/java/cn/fastfun/controller/api/ApiAppDeviceController.java

@@ -6,13 +6,11 @@ import cn.fastfun.service.AppDeviceLogService;
 import cn.fastfun.service.AppDeviceService;
 import cn.fastfun.service.SysExcelFieldService;
 import cn.fastfun.service.entity.AppDevice;
+import cn.fastfun.service.entity.AppDeviceLog;
 import cn.fastfun.util.DateUtils;
 import cn.fastfun.util.ObjectUtil;
 import cn.fastfun.util.VerifyUtil;
-import com.bridge.dto.ApiDTO;
-import com.bridge.dto.ApiPageDTO;
-import com.bridge.dto.IdParam;
-import com.bridge.dto.QueryParamExp;
+import com.bridge.dto.*;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
 import io.swagger.annotations.ApiParam;
@@ -25,6 +23,7 @@ import org.springframework.web.multipart.MultipartFile;
 
 import javax.annotation.Resource;
 import javax.servlet.http.HttpServletResponse;
+import java.math.BigInteger;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
@@ -68,7 +67,17 @@ public class ApiAppDeviceController {
             return ApiDTO.error(500, "该sn已经被录入", checkDuplicatedResultOnSn);
         }
         if (checkSnResult.equals("passed")) {
+            // 查询当前操作id的最大值
+            StringBuffer sql = new StringBuffer();
+            sql.append("SELECT COALESCE(MAX(operate_id),0) as max_opid from app_device where operate_id is not null");
+            log.info("SQL: {}", sql.toString());
+            ApiPageDTO page = appDeviceLogService.getListBySQL(sql.toString(), new HashMap<>(), new QueryParam());
+            List<Map<String, Object>> data = (List<Map<String, Object>>) page.getData();
+            BigInteger operateID = (BigInteger) data.get(0).get("max_opid");
+            operateID = operateID.add(BigInteger.valueOf(1));
+
             AppDevice entity = new AppDevice().fromFormParam(param);// 实体
+            entity.setOperateID(operateID.intValue());
             appDeviceService.save(entity);
             return ApiDTO.ok("保存成功");
         } else {
@@ -101,12 +110,12 @@ public class ApiAppDeviceController {
         return ApiDTO.ok(dto);
     }
 
-    @ApiOperation(value = "搜索 & 重置")
+    @ApiOperation(value = "设备录入 搜索 & 重置")
     @RequestMapping(value = "pageQuery", method = RequestMethod.POST)
     public ApiPageDTO batchNumPageQuery(@RequestBody DeviceBatchQueryParam param) {
 
         StringBuffer sql = new StringBuffer();
-        sql.append("select t1.batch_num,t1.sn,t1.imei,t1.deliver_time,count(0) as total,count(if(status = 1,true,null)) as in_storage,count(if(status = 2,true,null)) as transfer,");
+        sql.append("select t1.batch_num,t1.sn,t1.imei,t1.operate_id, t1.deliver_time,count(0) as total,count(if(status = 1,true,null)) as in_storage,count(if(status = 2,true,null)) as transfer,");
         sql.append("count(if(status = 3,true,null)) as out_storage,count(if(status = 4,true,null)) as handle,");
         sql.append("t1.add_time,t1.received_place from app_device t1");
 
@@ -114,7 +123,7 @@ public class ApiAppDeviceController {
             sql.append(" where t1.batch_num like '%").append(param.getBatchNum()).append("%'");
         }
 
-        sql.append(" group by t1.batch_num");
+        sql.append(" group by t1.operate_id");
         if (!StringUtils.isEmpty(param.getOrderBy())) {
             sql.append(param.getOrderBy());
         }
@@ -143,12 +152,41 @@ public class ApiAppDeviceController {
 
     @ApiOperation(value = "查看详情 --> 搜索 & 重置")
     @RequestMapping(value = "pageQuery/detail", method = RequestMethod.POST)
-    public ApiPageDTO devicePageQueryDetial(@RequestBody DeviceBatchQueryDetailParam param) {
+    public ApiPageDTO devicePageQueryDetial(@RequestBody DeviceOperateQueryParam param) {
 
         Page<AppDevice> devicePage = appDeviceService.findByParam(param);
         devicePage.getContent().forEach(p -> appDeviceService.addImeiTitle(p));
         return new ApiPageDTO(null, devicePage);
     }
 
+    @ApiOperation(value = "根据sn 查询相关信息")
+    @RequestMapping(value = "pageQuery/bySN", method = RequestMethod.POST)
+    public Map deviceSnPageQuery(@RequestBody SnQueryParam param) {
+        QueryParam query = new QueryParam();
+        query.addParam(QueryParamExp.desc("addTime"));
+        query.addParam(QueryParamExp.eq("type", 2));
+        query.addParam(QueryParamExp.eq("sn", param.getSn()));
+        Page<AppDeviceLog> deviceLogPage = appDeviceLogService.findByParam(query);
+        AppDeviceLog lastDeviceLogPage = deviceLogPage.getContent().get(0);
+
+
+        AppDevice device = appDeviceService.getOne(new QueryParamExp("sn", param.getSn()));
+
+        appDeviceService.addImeiTitle(device);
+        lastDeviceLogPage.appendFormDevice(device);
+        Map<String, Object> res = new HashMap<>();
+        res.put("sn", param.getSn());
+        res.put("pack_title", lastDeviceLogPage.getPackTitle());
+        res.put("chem_title", device.getSpecTitle());
+        res.put("type_title", device.getTypeTitle());
+        res.put("device_describe", lastDeviceLogPage.getTfDescribe());
+        res.put("device_use", lastDeviceLogPage.getTfUsed());
+        res.put("device_type", lastDeviceLogPage.getTfDeviceType());
+        res.put("device_owner", device.getOwnerId());
+        res.put("transfer_time", device.getTransferTime());
+        res.put("outstorage_time", device.getOutstorageTime());
+        return res;
+    }
+
 
 }

+ 87 - 27
src/main/java/cn/fastfun/controller/api/ApiAppDeviceLogController.java

@@ -53,7 +53,7 @@ public class ApiAppDeviceLogController {
     public ApiPageDTO inStorageBatchQuery(@RequestBody DeviceBatchQueryParam param) {
 
         StringBuffer sql = new StringBuffer();
-        sql.append("select t1.batch_num,t1.sn,t1.check_status,t1.imei,t1.deliver_time,count(0) as total,count(if(status = 1,true,null)) as in_storage,count(if(status = 2,true,null)) as transfer,");
+        sql.append("select t1.batch_num,t1.operate_id,t1.sn,t1.check_status,t1.imei,t1.deliver_time,count(0) as total,count(if(status = 1,true,null)) as in_storage,count(if(status = 2,true,null)) as transfer,");
         sql.append("count(if(status = 3,true,null)) as out_storage,count(if(status = 4,true,null)) as handle,");
         sql.append("t1.add_time,t1.received_place from app_device t1");
 
@@ -133,6 +133,7 @@ public class ApiAppDeviceLogController {
                 pTemp.put("type_title", device.getTypeTitle());
                 pTemp.put("pack_title", device.getPackTitle());
                 pTemp.put("batch_num", appDevice.getBatchNum());
+                pTemp.put("check_status", appDevice.getCheckStatus());
                 pTemp.put("status", appDevice.getStatus());
                 pTemp.put("received_place", appDevice.getReceivedPlace());
                 pTemp.put("deliver_time", DateUtils.toString(ObjectUtil.obj2Date(appDevice.getDeliverTime()), DateUtils.YMD));
@@ -154,14 +155,34 @@ public class ApiAppDeviceLogController {
     }
     @ApiOperation(value = "调回平台 ")
     @RequestMapping(value = "transferBack", method = RequestMethod.POST)
-    public ApiDTO transferBack(@RequestBody @ApiParam(name = "回调参数", value = "输入sn", required = true) TransferBySnQueryParam  param) {
+    public ApiDTO transferBack(@RequestBody @ApiParam(name = "回调参数", value = "输入sn", required = true) TransferFormParam  param) {
         deviceLogService.transferBack(param);
         return ApiDTO.ok();
     }
-    @ApiOperation(value = "设备调拨 搜索 & 重置")
+
+    @ApiOperation(value = "设备调拨 查看详情")
+    @RequestMapping(value = "transfer/detialQuery", method = RequestMethod.POST)
+    public ApiPageDTO transferDetialQuery(@RequestBody detialQueryParam param) {
+        QueryParam query = new QueryParam();
+
+        query.addParam(QueryParamExp.eq("operateID", param.getOperateID()));
+        query.addParam(QueryParamExp.eq("type", 2));
+        Page<AppDeviceLog> deviceLogPage = deviceLogService.findByParam(query);
+
+        deviceLogPage.getContent().forEach(p -> {
+            AppDevice device = new AppDevice();
+            device.setImei(p.getImei());
+            appDeviceService.addImeiTitle(device);
+            p.appendFormDevice(device);
+        });
+        return new ApiPageDTO(null, deviceLogPage);
+
+    }
+
+        @ApiOperation(value = "设备调拨 搜索 & 重置")
     @RequestMapping(value = "transfer/pageQuery", method = RequestMethod.POST)
     public ApiPageDTO transferPageQuery(@RequestBody LogTransferQueryParam param) {
-        StringBuffer sql = new StringBuffer("select t.batch_num,t.add_time,count(0) as total,t.tf_event,t.tf_device_type,t.tf_used,t.tf_describe,t.out_custom_id,t.operator,t.remarks from app_device_log t where t.type = 2");
+        StringBuffer sql = new StringBuffer("select t.batch_num,t.operate_id, t.add_time,count(0) as total,t.tf_event,t.tf_device_type,t.tf_used,t.tf_describe,t.out_custom_id,t.operator,t.remarks from app_device_log t where t.type = 2");
 
         // sn搜索
         if (!StringUtils.isEmpty(param.getSn())) {
@@ -173,7 +194,7 @@ public class ApiAppDeviceLogController {
             sql.append(StringUtils.isEmpty(param.getSn()) ? "where" : "and");
             sql.append(" t.tf_device_type = '").append(param.getType()).append("'");
         }
-        sql.append(" group by t.batch_num,t.add_time,t.tf_event,t.tf_device_type,t.tf_used,t.tf_describe,t.out_custom_id,t.operator,t.remarks");
+        sql.append(" group by t.operate_id");
         if (!StringUtils.isEmpty(param.getOrderBy())) {
             sql.append(param.getOrderBy());
         }
@@ -201,24 +222,19 @@ public class ApiAppDeviceLogController {
         if (!StringUtils.isEmpty(param)) {
             query.addParam(QueryParamExp.like("sn", "%".concat(param.getSn()).concat("%")));
         }
-        Page<AppDeviceLog> deviceLogPage = deviceLogService.findByParam(query);
-
-        deviceLogPage.getContent().forEach(p -> {
+        Page<AppDevice> devicePage = appDeviceService.findByParam(query);
 
-            // 查看自检状态
-            AppDevice device = new AppDevice();
-            device.setImei(p.getImei());
-            appDeviceService.addImeiTitle(device);
-            p.appendFormDevice(device);
+        devicePage.getContent().forEach(p -> {
+            appDeviceService.addImeiTitle(p);
         });
-        return new ApiPageDTO(null, deviceLogPage);
+        return new ApiPageDTO(null, devicePage);
     }
 
     @ApiOperation(value = "新增调拨 --> 选择批次 查询 & 重置")
     @RequestMapping(value = "transfer/byBatch/pageQuery", method = RequestMethod.POST)
     public ApiPageDTO transferByBatchPageQuery(@RequestBody DeviceBatchQueryParam param) {
         StringBuffer sql = new StringBuffer();
-        sql.append("select t1.batch_num,t1.sn,t1.imei,t1.deliver_time,count(0) as total,count(if(status = 1,true,null)) as in_storage,count(if(status = 2,true,null)) as transfer,");
+        sql.append("select t1.batch_num,t1.operate_id,t1.sn,t1.imei,t1.deliver_time,count(0) as total,count(if(status = 1,true,null)) as in_storage,count(if(status = 2,true,null)) as transfer,");
         sql.append("count(if(status = 3,true,null)) as out_storage,count(if(status = 4,true,null)) as handle,");
         sql.append("t1.add_time,t1.received_place from app_device t1");
 
@@ -287,10 +303,30 @@ public class ApiAppDeviceLogController {
         return ApiDTO.ok();
     }
 
+    @ApiOperation(value = "设备出库 查看详情")
+    @RequestMapping(value = "outstorage/detialQuery", method = RequestMethod.POST)
+    public ApiPageDTO outDetialQuery(@RequestBody detialQueryParam param) {
+        QueryParam query = new QueryParam();
+
+        query.addParam(QueryParamExp.eq("operateID", param.getOperateID()));
+        query.addParam(QueryParamExp.eq("type", 3));
+
+        Page<AppDeviceLog> deviceLogPage = deviceLogService.findByParam(query);
+
+        deviceLogPage.getContent().forEach(p -> {
+            AppDevice device = new AppDevice();
+            device.setImei(p.getImei());
+            appDeviceService.addImeiTitle(device);
+            p.appendFormDevice(device);
+        });
+        return new ApiPageDTO(null, deviceLogPage);
+
+    }
+
     @ApiOperation(value = "设备出库 搜索 & 重置")
     @RequestMapping(value = "outstorage/pageQuery", method = RequestMethod.POST)
     public ApiPageDTO outPageQuery(@RequestBody OutQueryParam param) {
-        StringBuffer sql = new StringBuffer("select t.batch_num,t.add_time,count(0) as total,t.out_type,t.receiver_name,t.receiver_phone,t.remarks,t.out_custom_id,t.operator,t.update_time from app_device_log t where t.type = 3");
+        StringBuffer sql = new StringBuffer("select t.batch_num,t1.operate_id,t.add_time,count(0) as total,t.out_type,t.receiver_name,t.receiver_phone,t.remarks,t.out_custom_id,t.operator,t.update_time from app_device_log t where t.type = 3");
 
         // sn搜索
         if (!StringUtils.isEmpty(param.getSn())) {
@@ -302,7 +338,7 @@ public class ApiAppDeviceLogController {
             sql.append(StringUtils.isEmpty(param.getSn()) ? "where" : "and");
             sql.append(" t.out_type = '").append(param.getOutType()).append("'");
         }
-        sql.append(" group by t.batch_num,t.add_time,t.out_type,t.receiver_name,t.receiver_phone,t.remarks,t.out_custom_id,t.operator,t.update_time");
+        sql.append(" group by t1.operate_id");
         if (!StringUtils.isEmpty(param.getOrderBy())) {
             sql.append(param.getOrderBy());
         }
@@ -340,16 +376,40 @@ public class ApiAppDeviceLogController {
 
     @ApiOperation(value = "批次出库 搜索 & 重置")
     @RequestMapping(value = "outstorage/byBatch/pageQuery", method = RequestMethod.POST)
-    public ApiPageDTO outByBatchPageQuery(@RequestBody OutByBatchQueryParam param) {
-        param.addParam(QueryParamExp.eq("type", 3));
-        Page<AppDeviceLog> deviceLogPage = deviceLogService.findByParam(param);
-        deviceLogPage.getContent().forEach(p -> {
-            AppDevice device = new AppDevice();
-            device.setImei(p.getImei());
-            appDeviceService.addImeiTitle(device);
-            p.appendFormDevice(device);
-        });
-        return new ApiPageDTO(null, deviceLogPage);
+    public ApiPageDTO outByBatchPageQuery(@RequestBody DeviceBatchQueryParam param) {
+        StringBuffer sql = new StringBuffer();
+        sql.append("select t1.batch_num,t1.operate_id,t1.sn,t1.imei,t1.deliver_time,count(0) as total,count(if(status = 1,true,null)) as in_storage,count(if(status = 2,true,null)) as transfer,");
+        sql.append("count(if(status = 3,true,null)) as out_storage,count(if(status = 4,true,null)) as handle,");
+        sql.append("t1.add_time,t1.received_place from app_device t1");
+
+        if (!StringUtils.isEmpty(param.getBatchNum())) {
+            sql.append(" where t1.batch_num like '%").append(param.getBatchNum()).append("%'");
+        }
+
+        sql.append(" group by t1.batch_num");
+        if (!StringUtils.isEmpty(param.getOrderBy())) {
+            sql.append(param.getOrderBy());
+        }
+        log.info("SQL: {}", sql.toString());
+
+        ApiPageDTO page = appDeviceService.getListBySQL(sql.toString(), new HashMap<>(), param);
+        if(null != page.getData()) {
+            // 组装数据
+            List<Map<String, Object>> list = (List<Map<String, Object>>) page.getData();
+            for (Map<String, Object> p : list) {
+                AppDevice device = new AppDevice();
+                device.setImei(ObjectUtil.obj2String(p.get("imei")));
+                appDeviceService.addImeiTitle(device);
+
+                p.put("type_title", device.getTypeTitle());
+                p.put("pack_title", device.getPackTitle());
+                p.put("deliver_time", DateUtils.toString(ObjectUtil.obj2Date(p.get("deliver_time")), DateUtils.YMD));
+                p.put("add_time", DateUtils.toString(ObjectUtil.obj2Date(p.get("add_time")), DateUtils.YMDHMS));
+                p.put("operator", "admin");
+            }
+            page.setData(list);
+        }
+        return page;
     }
 
     @ApiOperation(value = "新增处置")

+ 0 - 14
src/main/java/cn/fastfun/controller/param/BatchNumQueryParam.java

@@ -1,14 +0,0 @@
-package cn.fastfun.controller.param;
-
-import com.bridge.dto.QueryParam;
-import com.bridge.dto.QueryParamExp;
-import org.springframework.util.StringUtils;
-
-public class BatchNumQueryParam extends QueryParam {
-
-
-    public void setBatchNum(String batchNum) {
-        if (!StringUtils.isEmpty(batchNum))
-            addParam(QueryParamExp.eq("batchNum", batchNum));
-    }
-}

+ 6 - 0
src/main/java/cn/fastfun/controller/param/DeviceBatchQueryDetailParam.java

@@ -3,6 +3,7 @@ package cn.fastfun.controller.param;
 import com.bridge.dto.QueryParam;
 import com.bridge.dto.QueryParamExp;
 import io.swagger.annotations.ApiModelProperty;
+import io.swagger.models.auth.In;
 import lombok.Getter;
 import lombok.Setter;
 import org.springframework.util.CollectionUtils;
@@ -21,6 +22,11 @@ public class DeviceBatchQueryDetailParam extends QueryParam {
             addParam(QueryParamExp.eq("batchNum", batchNum));
     }
 
+    @ApiModelProperty(value = "操作号", name = "operateID", required = true)
+    public void setOperateID(Integer operateID) {
+        addParam(QueryParamExp.eq("operateID", operateID));
+    }
+
     @ApiModelProperty(value = "SN", name = "sn", required = true)
     public void setSn(String sn) {
         if (!StringUtils.isEmpty(sn))

+ 23 - 0
src/main/java/cn/fastfun/controller/param/DeviceOperateQueryParam.java

@@ -0,0 +1,23 @@
+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;
+
+@Setter
+@Getter
+public class DeviceOperateQueryParam extends QueryParam {
+
+    @ApiModelProperty(value = "操作号", name = "operateID", required = true)
+    public void setOperateID(Integer operateID) {
+        addParam(QueryParamExp.eq("operateID", operateID));
+    }
+
+
+}

+ 19 - 0
src/main/java/cn/fastfun/controller/param/SnQueryParam.java

@@ -0,0 +1,19 @@
+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.StringUtils;
+
+import java.util.List;
+
+@Setter
+@Getter
+public class SnQueryParam{
+
+
+    @ApiModelProperty(value = "设备编号", name = "sn")
+    public String  sn;
+}

+ 24 - 0
src/main/java/cn/fastfun/controller/param/detialQueryParam.java

@@ -0,0 +1,24 @@
+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.StringUtils;
+
+import java.util.Date;
+import java.util.List;
+
+@Setter
+@Getter
+public class detialQueryParam {
+
+    @ApiModelProperty(value = "操作号", name = "operateID", required = true)
+    Integer operateID;
+
+}
+
+

+ 1 - 1
src/main/java/cn/fastfun/service/AppDeviceLogService.java

@@ -24,7 +24,7 @@ public interface AppDeviceLogService extends JpaService<AppDeviceLog, String> {
      */
     void transfer(TransferFormParam param);
 
-    void transferBack(TransferBySnQueryParam  param);
+    void transferBack(TransferFormParam  param);
 
     /**
      * 设备出库

+ 28 - 0
src/main/java/cn/fastfun/service/entity/AppDevice.java

@@ -38,6 +38,10 @@ public class AppDevice extends DateEntity {
     @Column(name = "sn")
     private String sn;
 
+    @ApiModelProperty(value = "操作号", name = "operateID", required = true)
+    @Column(name = "operate_id")
+    private Integer operateID;
+
     @ApiModelProperty(value = "IMEI", name = "imei", required = true)
     @Column(name = "imei")
     private String imei;
@@ -79,6 +83,30 @@ public class AppDevice extends DateEntity {
     @Column(name = "deliver_time")
     private Date deliverTime;
 
+    @ApiModelProperty(value = "最新调拨时间", name = "transferTime", required = true)
+    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
+    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
+    @Column(name = "transfer_time")
+    private Date transferTime;
+
+    @ApiModelProperty(value = "最新回调时间", name = "transferBackTime", required = true)
+    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
+    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
+    @Column(name = "transferback_time")
+    private Date transferBackTime;
+
+    @ApiModelProperty(value = "最新出库时间", name = "outstorageTime", required = true)
+    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
+    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
+    @Column(name = "outstorage_time")
+    private Date outstorageTime;
+
+    @ApiModelProperty(value = "最新处理时间", name = "handleTime", required = true)
+    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
+    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
+    @Column(name = "handle_time")
+    private Date handleTime;
+
 
     @ApiModelProperty(value = "自检状态", name = "checkStatus", required = true)
     @Column(name = "check_status")

+ 16 - 5
src/main/java/cn/fastfun/service/entity/AppDeviceLog.java

@@ -17,6 +17,7 @@ import javax.persistence.Column;
 import javax.persistence.Entity;
 import javax.persistence.Table;
 import javax.persistence.Transient;
+import java.math.BigInteger;
 import java.util.Date;
 
 
@@ -35,6 +36,9 @@ public class AppDeviceLog extends DateEntity {
     @Column(name = "type")
     private Integer type;
 
+    @ApiModelProperty(value = "操作号", name = "operateID", required = true)
+    @Column(name = "operate_id")
+    private Integer operateID;
 
     @ApiModelProperty(value = "IMEI", name = "imei", required = true)
     @Column(name = "imei")
@@ -116,15 +120,16 @@ public class AppDeviceLog extends DateEntity {
     }
 
     // 入库属性
-    public AppDeviceLog toInStorage(Date addTime, String batchNum) {
+    public AppDeviceLog toInStorage(Date addTime, String batchNum, BigInteger operateID) {
         setType(1); // 入库
         setAddTime(addTime);
         setBatchNum(batchNum);
+        setOperateID(operateID.intValue());
         return this;
     }
 
     // 划拨
-    public AppDeviceLog toTransfer(TransferFormParam param, Date addTime, String batchNum) {
+    public AppDeviceLog toTransfer(TransferFormParam param, Date addTime, String batchNum, BigInteger operateID) {
         setType(2); // 划拨
         setTfEvent(param.getEvent()); //
         setTfDeviceType(param.getDeviceType());
@@ -133,35 +138,41 @@ public class AppDeviceLog extends DateEntity {
         setOutCustomId(param.getCustomId());
         setAddTime(addTime);
         setBatchNum(batchNum);
+        setOperateID(operateID.intValue());
         return this;
     }
 
     // 回调
-    public AppDeviceLog transferBack(TransferBySnQueryParam param, Date addTime, String batchNum) {
+    public AppDeviceLog transferBack(TransferFormParam param, Date addTime, String batchNum, BigInteger operateID) {
         setType(5); // 回调
+        setTfDeviceType(param.getDeviceType());
+        setTfDescribe(param.getDescribe());
         setAddTime(addTime);
         setBatchNum(batchNum);
+        setOperateID(operateID.intValue());
         return this;
     }
 
     // 出库
-    public AppDeviceLog outStorage(LibraryOutFormParam param, Date addTime, String batchNum) {
+    public AppDeviceLog outStorage(LibraryOutFormParam param, Date addTime, String batchNum, BigInteger operateID) {
         setType(3); // 出库
         setOutType(param.getOutType());
         setReceiverName(param.getReceiverName());
         setReceiverPhone(param.getReceiverPhone());
         setAddTime(addTime);
         setBatchNum(batchNum);
+        setOperateID(operateID.intValue());
         return this;
     }
 
     // 处置
-    public AppDeviceLog toHandle(HandelFormParam param, Date addTime, String batchNum) {
+    public AppDeviceLog toHandle(HandelFormParam param, Date addTime, String batchNum, BigInteger operateID) {
         setType(4);
         setHfEvent(param.getEvent());
         setHfHandleContent(param.getHandleContent());
         setAddTime(addTime);
         setBatchNum(batchNum);
+        setOperateID(operateID.intValue());
         return this;
     }
 

+ 94 - 18
src/main/java/cn/fastfun/service/impl/AppDeviceLogServiceImpl.java

@@ -6,20 +6,24 @@ import cn.fastfun.service.AppDeviceService;
 import cn.fastfun.service.entity.AppDevice;
 import cn.fastfun.service.entity.AppDeviceLog;
 import cn.fastfun.service.entity.AppImeiHistory;
+import com.bridge.dto.ApiDTO;
+import com.bridge.dto.ApiPageDTO;
+import com.bridge.dto.QueryParam;
 import com.bridge.dto.QueryParamExp;
 import com.bridge.exception.ApiRuntimeException;
 import com.bridge.service.JpaService;
 import com.bridge.service.impl.JpaServiceImp;
+import io.swagger.models.auth.In;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.stereotype.Service;
 import org.springframework.util.CollectionUtils;
 import org.springframework.util.StringUtils;
 
 import javax.annotation.Resource;
+import javax.persistence.Query;
 import javax.transaction.Transactional;
-import java.util.ArrayList;
-import java.util.Date;
-import java.util.List;
+import java.math.BigInteger;
+import java.util.*;
 import java.util.concurrent.atomic.AtomicBoolean;
 
 @Slf4j
@@ -29,6 +33,9 @@ public class AppDeviceLogServiceImpl extends JpaServiceImp<AppDeviceLog, String>
     @Resource
     AppDeviceService appDeviceService;
 
+    @Resource
+    AppDeviceLogService appDeviceLogService;
+
     //业务类
     @Resource(name = "appImeiHistoryService")
     JpaService<AppImeiHistory, String> appImeiHistoryService;
@@ -40,8 +47,17 @@ public class AppDeviceLogServiceImpl extends JpaServiceImp<AppDeviceLog, String>
         param.setSn(new ArrayList<>());
         deviceList.forEach(p -> param.getSn().add(p.getSn()));
         if (!CollectionUtils.isEmpty(param.getSn())) {
+            // 查询当前操作id的最大值
+            StringBuffer sql = new StringBuffer();
+            sql.append("SELECT COALESCE(MAX(operate_id),0) as max_opid from app_device_log where operate_id is not null");
+            log.info("SQL: {}", sql.toString());
+            ApiPageDTO page = appDeviceLogService.getListBySQL(sql.toString(), new HashMap<>(), new QueryParam());
+            List<Map<String, Object>> data = (List<Map<String, Object>>) page.getData();
+            BigInteger operateID = (BigInteger) data.get(0).get("max_opid");
+            operateID = operateID.add(BigInteger.valueOf(1));
             Date time = new Date();
 
+            BigInteger finalOperateID = operateID;
             param.getSn().forEach(p -> {
                 String batchNum;
                 AppDevice appDevice = appDeviceService.getOne(QueryParamExp.eq("sn", p));
@@ -50,7 +66,7 @@ public class AppDeviceLogServiceImpl extends JpaServiceImp<AppDeviceLog, String>
                 if (appDevice.getStatus() < 1) {
                     appDevice.setStatus(1); // 已入库
                     appDeviceService.save(appDevice);
-                    save(new AppDeviceLog(p, appDevice.getImei()).toInStorage(time, batchNum)); // 记录入库日志
+                    save(new AppDeviceLog(p, appDevice.getImei()).toInStorage(time, batchNum, finalOperateID)); // 记录入库日志
                 }
             });
         }
@@ -59,13 +75,24 @@ public class AppDeviceLogServiceImpl extends JpaServiceImp<AppDeviceLog, String>
     @Override
     @Transactional
     public void transfer(TransferFormParam param) {
-        if (CollectionUtils.isEmpty(param.getSn()) && !StringUtils.isEmpty(param.getBatchNum())) {
+        if (CollectionUtils.isEmpty(param.getSn()) && !CollectionUtils.isEmpty(param.getBatchNum())) {
             List<AppDevice> deviceList = appDeviceService.findAll(QueryParamExp.in("batchNum", param.getBatchNum().toArray(new String[]{})));
             param.setSn(new ArrayList<>());
             deviceList.forEach(p -> param.getSn().add(p.getSn()));
         }
+
         if (!CollectionUtils.isEmpty(param.getSn())) {
+            // 查询当前操作id的最大值
+            StringBuffer sql = new StringBuffer();
+            sql.append("SELECT COALESCE(MAX(operate_id),0) as max_opid from app_device_log where operate_id is not null");
+            log.info("SQL: {}", sql.toString());
+            ApiPageDTO page = appDeviceLogService.getListBySQL(sql.toString(), new HashMap<>(), new QueryParam());
+            List<Map<String, Object>> data = (List<Map<String, Object>>) page.getData();
+            BigInteger operateID = (BigInteger) data.get(0).get("max_opid");
+            operateID = operateID.add(BigInteger.valueOf(1));
             Date time = new Date();
+
+            BigInteger finalOperateID = operateID;
             AtomicBoolean allowTransfer = new AtomicBoolean(true);
             //批量调拨时,若有不符合调拨条件的电池,则停止本次批量调拨
 
@@ -75,10 +102,10 @@ public class AppDeviceLogServiceImpl extends JpaServiceImp<AppDeviceLog, String>
                     allowTransfer.set(false);
                     throw new ApiRuntimeException(p + "设备信息不存在!");
                 }
-//                if (1 != appDevice.getStatus() && 3 != appDevice.getStatus()) {
-//                    allowTransfer.set(false);
-//                    throw new ApiRuntimeException(p + "不是入库或出库状态,不能调拨!");
-//                }
+                if (1 != appDevice.getStatus() && 2 != appDevice.getStatus() && 3 != appDevice.getStatus()) {
+                    allowTransfer.set(false);
+                    throw new ApiRuntimeException(p + "不是入库或出库状态,不能调拨!");
+                }
                 if (1 != appDevice.getCheckStatus()) {
                     allowTransfer.set(false);
                     throw new ApiRuntimeException(p + "自检未通过,不能调拨!");
@@ -92,45 +119,83 @@ public class AppDeviceLogServiceImpl extends JpaServiceImp<AppDeviceLog, String>
                     return;
                 }
                 appDevice.setStatus(2); // 已划拨
+                appDevice.setTransferTime(time);
                 appDevice.setOwnerId(param.getCustomId()); // 设置归属
                 appDeviceService.save(appDevice);
-                save(new AppDeviceLog(p, appDevice.getImei()).toTransfer(param, time, batchNum)); // 记录划拨日志
+                save(new AppDeviceLog(p, appDevice.getImei()).toTransfer(param, time, batchNum, finalOperateID)); // 记录划拨日志
             });
         }
     }
 
     @Override
-    public void transferBack(TransferBySnQueryParam param) {
-        AppDevice appDevice = appDeviceService.getOne(QueryParamExp.eq("sn", param.getSn()));
+    public void transferBack(TransferFormParam param) {
+        AppDevice appDevice = appDeviceService.getOne(QueryParamExp.eq("sn", param.getSn().get(0)));
+        // 查询当前操作id的最大值
+        StringBuffer sql = new StringBuffer();
+        sql.append("SELECT COALESCE(MAX(operate_id),0) as max_opid from app_device_log where operate_id is not null");
+        log.info("SQL: {}", sql.toString());
+        ApiPageDTO page = appDeviceLogService.getListBySQL(sql.toString(), new HashMap<>(), new QueryParam());
+        List<Map<String, Object>> data = (List<Map<String, Object>>) page.getData();
+        BigInteger operateID = (BigInteger) data.get(0).get("max_opid");
+        operateID = operateID.add(BigInteger.valueOf(1));
         Date time = new Date();
+
+        BigInteger finalOperateID = operateID;
         String batchNum;
         if (null == appDevice) throw new ApiRuntimeException("设备信息不存在!");
         if (3 != appDevice.getStatus()) throw new ApiRuntimeException("设备不是出库状态!");
         batchNum = appDevice.getBatchNum();
         appDevice.setStatus(1); // 已入库
+        appDevice.setTransferBackTime(time);
         appDeviceService.save(appDevice);
-        save(new AppDeviceLog(appDevice.getSn(), appDevice.getImei()).transferBack(param, time, batchNum)); // 记录出库日志
+        save(new AppDeviceLog(appDevice.getSn(), appDevice.getImei()).transferBack(param, time, batchNum, finalOperateID)); // 记录出库日志
     }
 
     @Override
     @Transactional
     public void outStorage(LibraryOutFormParam param) {
-        if (StringUtils.isEmpty(param.getSn()) && !StringUtils.isEmpty(param.getBatchNum())) {
+        if (CollectionUtils.isEmpty(param.getSn()) && !CollectionUtils.isEmpty(param.getBatchNum())) {
             List<AppDevice> deviceList = appDeviceService.findAll(QueryParamExp.in("batchNum", param.getBatchNum().toArray(new String[]{})));
             param.setSn(new ArrayList<>());
             deviceList.forEach(p -> param.getSn().add(p.getSn()));
         }
+
         if (!CollectionUtils.isEmpty(param.getSn())) {
+            // 查询当前操作id的最大值
+            StringBuffer sql = new StringBuffer();
+            sql.append("SELECT COALESCE(MAX(operate_id),0) as max_opid from app_device_log where operate_id is not null");
+            log.info("SQL: {}", sql.toString());
+            ApiPageDTO page = appDeviceLogService.getListBySQL(sql.toString(), new HashMap<>(), new QueryParam());
+            List<Map<String, Object>> data = (List<Map<String, Object>>) page.getData();
+            BigInteger operateID = (BigInteger) data.get(0).get("max_opid");
+            operateID = operateID.add(BigInteger.valueOf(1));
             Date time = new Date();
+
+            //批量出库时,若有不符合出库条件的电池,则停止本次批量出库
+            AtomicBoolean allowTransfer = new AtomicBoolean(true);
+            param.getSn().forEach(p -> {
+                AppDevice appDevice = appDeviceService.getOne(QueryParamExp.eq("sn", p));
+                if (null == appDevice) {
+                    allowTransfer.set(false);
+                    throw new ApiRuntimeException(p + "设备信息不存在!");
+                }
+                if ( 2 != appDevice.getStatus() && 3 != appDevice.getStatus()) {
+                    allowTransfer.set(false);
+                    throw new ApiRuntimeException(p + "不是调拨状态,不能出库!");
+                }
+            });
+            BigInteger finalOperateID = operateID;
             param.getSn().forEach(p -> {
                 String batchNum;
                 AppDevice appDevice = appDeviceService.getOne(QueryParamExp.eq("sn", p));
-                if (null == appDevice) throw new ApiRuntimeException("设备信息不存在!");
-                if (2 != appDevice.getStatus()) throw new ApiRuntimeException("设备不是划拨状态!");
+                if (3 == appDevice.getStatus()) {
+                    return;
+                }
                 batchNum = appDevice.getBatchNum();
+                appDevice.setOutstorageTime(time);
                 appDevice.setStatus(3); // 已出库
                 appDeviceService.save(appDevice);
-                save(new AppDeviceLog(p, appDevice.getImei()).outStorage(param, time, batchNum)); // 记录出库日志
+                save(new AppDeviceLog(p, appDevice.getImei()).outStorage(param, time, batchNum, finalOperateID)); // 记录出库日志
             });
         }
     }
@@ -138,16 +203,27 @@ public class AppDeviceLogServiceImpl extends JpaServiceImp<AppDeviceLog, String>
     @Override
     @Transactional
     public void handle(HandelFormParam param) {
+        // 查询当前操作id的最大值
+        StringBuffer sql = new StringBuffer();
+        sql.append("SELECT COALESCE(MAX(operate_id),0) as max_opid from app_device_log where operate_id is not null");
+        log.info("SQL: {}", sql.toString());
+        ApiPageDTO page = appDeviceLogService.getListBySQL(sql.toString(), new HashMap<>(), new QueryParam());
+        List<Map<String, Object>> data = (List<Map<String, Object>>) page.getData();
+        BigInteger operateID = (BigInteger) data.get(0).get("max_opid");
+        operateID = operateID.add(BigInteger.valueOf(1));
         Date time = new Date();
+
+        BigInteger finalOperateID = operateID;
         param.getSn().forEach(p -> {
             String batchNum;
             AppDevice appDevice = appDeviceService.getOne(QueryParamExp.eq("sn", p));
             if (null == appDevice) throw new ApiRuntimeException("设备信息不存在!");
             if (1 != appDevice.getStatus()) throw new ApiRuntimeException("设备不是入库状态!");
             batchNum = appDevice.getBatchNum();
+            appDevice.setHandleTime(time);
             appDevice.setStatus(4); // 处置
             appDeviceService.save(appDevice);
-            save(new AppDeviceLog(p, appDevice.getImei()).toHandle(param, time, batchNum)); // 记录处置日志
+            save(new AppDeviceLog(p, appDevice.getImei()).toHandle(param, time, batchNum, finalOperateID)); // 记录处置日志
         });
     }
 }

+ 14 - 4
src/main/java/cn/fastfun/service/impl/AppDeviceServiceImp.java

@@ -1,6 +1,7 @@
 package cn.fastfun.service.impl;
 
 import cn.fastfun.controller.dto.DeviceAttrDTO;
+import cn.fastfun.service.AppDeviceLogService;
 import cn.fastfun.service.AppDeviceService;
 import cn.fastfun.service.ProductService;
 import cn.fastfun.service.entity.AppDevice;
@@ -8,6 +9,7 @@ import cn.fastfun.service.entity.Product;
 import cn.fastfun.service.repository.AppDeviceRepository;
 
 import com.bridge.dto.ApiPageDTO;
+import com.bridge.dto.QueryParam;
 import com.bridge.dto.QueryParamExp;
 import com.bridge.exception.ApiRuntimeException;
 import com.bridge.service.impl.JpaServiceImp;
@@ -16,10 +18,8 @@ import org.springframework.stereotype.Service;
 
 import javax.annotation.Resource;
 
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.List;
-import java.util.Map;
+import java.math.BigInteger;
+import java.util.*;
 
 /**
  * 服务实现类 Created by Bridge.
@@ -27,6 +27,7 @@ import java.util.Map;
 @Service("appDeviceService")
 public class AppDeviceServiceImp extends JpaServiceImp<AppDevice, String> implements AppDeviceService {
 
+
     @Resource
     AppDeviceRepository deviceRepository;
 
@@ -37,6 +38,14 @@ public class AppDeviceServiceImp extends JpaServiceImp<AppDevice, String> implem
     public void importDevice(List<Map<String, Object>> list) {
         List<AppDevice> devices = new ArrayList<>();
         DeviceAttrDTO diffAttrDTO = null;
+
+        // 查询当前操作id的最大值
+        StringBuffer sql = new StringBuffer();
+        sql.append("SELECT COALESCE(MAX(operate_id),0) as max_opid from app_device where operate_id is not null");
+        ApiPageDTO page = this.getListBySQL(sql.toString(), new HashMap<>(), new QueryParam());
+        List<Map<String, Object>> data = (List<Map<String, Object>>) page.getData();
+        BigInteger operateID = (BigInteger)data.get(0).get("max_opid");
+        operateID = operateID.add(BigInteger.valueOf(1));
         for (Map<String, Object> p : list) {
             AppDevice device = new AppDevice(p);
             if (null == device.getDeliverTime()) new ApiRuntimeException("发货时间读取错误");
@@ -54,6 +63,7 @@ public class AppDeviceServiceImp extends JpaServiceImp<AppDevice, String> implem
             if (!temp.getType().equals(diffAttrDTO.getType())) new ApiRuntimeException("存在不同的电池类型");
             if (!temp.getReceivedPlace().equals(diffAttrDTO.getReceivedPlace()))
                 throw new ApiRuntimeException("存在不同的收货地");
+            device.setOperateID(operateID.intValue());
             devices.add(device);
         }
         save(devices);