Преглед на файлове

计算批次调拨和批次出库的统计数值

su-lmstack преди 3 години
родител
ревизия
7282640bdf

+ 4 - 6
src/main/java/cn/fastfun/controller/api/ApiAppDeviceLogController.java

@@ -301,8 +301,7 @@ public class ApiAppDeviceLogController {
     @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.operator,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("select t1.batch_num,t1.operator,t1.operate_id,t1.sn,t1.imei,t1.deliver_time,count(0) as total,count(if(status = 1 and check_status = 1,true,null)) as transfer_able,count(if(status = 0 or status = 1,true,null)) as not_transfer,");
         sql.append("t1.add_time,t1.received_place from app_device t1");
 
         if (!StringUtils.isEmpty(param.getBatchNum())) {
@@ -459,12 +458,11 @@ public class ApiAppDeviceLogController {
     @RequestMapping(value = "outstorage/byBatch/pageQuery", method = RequestMethod.POST)
     public ApiPageDTO outByBatchPageQuery(@RequestBody DeviceBatchQueryParam param) {
         StringBuffer sql = new StringBuffer();
-        sql.append("select t1.batch_num,t1.operate_id,t1.operator,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 where t1.status = 2");
+        sql.append("select t1.batch_num,t1.operate_id,t1.operator,t1.sn,t1.imei,t1.deliver_time,count(0) as total,count(if(status = 2,true,null)) as outstorage_able,count(if(status = 0 or status = 1 or status = 2,true,null)) as not_outstorage,");
+        sql.append("t1.add_time,t1.received_place from app_device t1");
 
         if (!StringUtils.isEmpty(param.getBatchNum())) {
-            sql.append(" and t1.batch_num like '%").append(param.getBatchNum()).append("%'");
+            sql.append(" where t1.batch_num like '%").append(param.getBatchNum()).append("%'");
         }
 
         sql.append(" group by t1.operate_id");

+ 1 - 1
src/main/java/cn/fastfun/controller/param/LibraryOutFormParam.java

@@ -15,7 +15,7 @@ import java.util.List;
 public class LibraryOutFormParam {
 
     @ApiModelProperty(value = "批次号", name = "batchNum")
-    private List<String> batchNum;
+    private List<Integer> batchNum;
 
     @ApiModelProperty(value = "设备编号", name = "sn", required = true)
     private List<String> sn;

+ 1 - 1
src/main/java/cn/fastfun/controller/param/TransferFormParam.java

@@ -11,7 +11,7 @@ import java.util.List;
 public class TransferFormParam {
 
     @ApiModelProperty(value = "批次号", name = "batchNum")
-    private List<String> batchNum;
+    private List<Integer> batchNum;
     
     @ApiModelProperty(value = "设备编号", name = "sn")
     private List<String> sn;

+ 31 - 35
src/main/java/cn/fastfun/service/impl/AppDeviceLogServiceImpl.java

@@ -126,7 +126,7 @@ public class AppDeviceLogServiceImpl extends JpaServiceImp<AppDeviceLog, String>
     @Transactional
     public void transfer(TransferFormParam param) {
         if (CollectionUtils.isEmpty(param.getSn()) && !CollectionUtils.isEmpty(param.getBatchNum())) {
-            List<AppDevice> deviceList = appDeviceService.findAll(QueryParamExp.in("batchNum", param.getBatchNum().toArray(new String[]{})));
+            List<AppDevice> deviceList = appDeviceService.findAll(QueryParamExp.in("operateID", param.getBatchNum().toArray(new Integer[]{})));
             param.setSn(new ArrayList<>());
             deviceList.forEach(p -> param.getSn().add(p.getSn()));
         }
@@ -143,41 +143,38 @@ public class AppDeviceLogServiceImpl extends JpaServiceImp<AppDeviceLog, String>
             Date time = new Date();
 
             BigInteger finalOperateID = operateID;
-            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 + "设备信息不存在!");
+                    new ApiRuntimeException(p + "设备信息不存在!");
                 }
                 if (1 != appDevice.getStatus() && 2 != appDevice.getStatus()) {
-                    allowTransfer.set(false);
-                    throw new ApiRuntimeException(p + "不是入库状态,不能调拨!");
+                    new ApiRuntimeException(p + "不是入库状态,不能调拨!");
                 }
                 if (1 != appDevice.getCheckStatus()) {
-                    allowTransfer.set(false);
-                    throw new ApiRuntimeException(p + "自检未通过,不能调拨!");
+                    new ApiRuntimeException(p + "自检未通过,不能调拨!");
                 }
             });
             param.getSn().forEach(p -> {
                 String batchNum;
                 AppDevice appDevice = appDeviceService.getOne(QueryParamExp.eq("sn", p));
                 batchNum = appDevice.getBatchNum();
-                if (2 == appDevice.getStatus()) {
-                    return;
-                }
-                appDevice.setStatus(2); // 已划拨
-                appDevice.setTransferTime(time);
-                appDevice.setOwnerId(param.getCustomId()); // 设置归属
-                appDevice.setTfDescribe(param.getDescribe());
-                appDevice.setTfUsed(param.getUsed());
-                appDeviceService.save(appDevice);
+                // 将可调拨的电池进行调拨
+                if (1 == appDevice.getStatus() && 1 == appDevice.getCheckStatus()) {
+
+                    appDevice.setStatus(2); // 已划拨
+                    appDevice.setTransferTime(time);
+                    appDevice.setOwnerId(param.getCustomId()); // 设置归属
+                    appDevice.setTfDescribe(param.getDescribe());
+                    appDevice.setTfUsed(param.getUsed());
+                    appDeviceService.save(appDevice);
 
-                AppDeviceLog appDeviceLog = new AppDeviceLog(p, appDevice.getImei()).toTransfer(param, time, batchNum, finalOperateID);
-                appDeviceLog.setOperator(utilService.getUserName());
-                save(appDeviceLog); // 记录划拨日志
+                    AppDeviceLog appDeviceLog = new AppDeviceLog(p, appDevice.getImei()).toTransfer(param, time, batchNum, finalOperateID);
+                    appDeviceLog.setOperator(utilService.getUserName());
+                    save(appDeviceLog); // 记录划拨日志
+                }
             });
         }
     }
@@ -214,7 +211,7 @@ public class AppDeviceLogServiceImpl extends JpaServiceImp<AppDeviceLog, String>
     @Transactional
     public void outStorage(LibraryOutFormParam param) {
         if (CollectionUtils.isEmpty(param.getSn()) && !CollectionUtils.isEmpty(param.getBatchNum())) {
-            List<AppDevice> deviceList = appDeviceService.findAll(QueryParamExp.in("batchNum", param.getBatchNum().toArray(new String[]{})));
+            List<AppDevice> deviceList = appDeviceService.findAll(QueryParamExp.in("operateID", param.getBatchNum().toArray(new Integer[]{})));
             param.setSn(new ArrayList<>());
             deviceList.forEach(p -> param.getSn().add(p.getSn()));
         }
@@ -231,32 +228,31 @@ public class AppDeviceLogServiceImpl extends JpaServiceImp<AppDeviceLog, String>
             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 + "设备信息不存在!");
+                    new ApiRuntimeException(p + "设备信息不存在!");
                 }
                 if ( 2 != appDevice.getStatus() && 3 != appDevice.getStatus()) {
-                    allowTransfer.set(false);
-                    throw new ApiRuntimeException(p + "不是调拨状态,不能出库!");
+                    new ApiRuntimeException(p + "不是调拨状态,不能出库!");
                 }
             });
             BigInteger finalOperateID = operateID;
             param.getSn().forEach(p -> {
                 String batchNum;
                 AppDevice appDevice = appDeviceService.getOne(QueryParamExp.eq("sn", p));
-                if (3 == appDevice.getStatus()) {
-                    return;
+
+                // 将可出库的电池出库
+                if (2 == appDevice.getStatus()) {
+
+                    batchNum = appDevice.getBatchNum();
+                    appDevice.setOutstorageTime(time);
+                    appDevice.setStatus(3); // 已出库
+                    appDeviceService.save(appDevice);
+                    AppDeviceLog appDeviceLog = new AppDeviceLog(p, appDevice.getImei()).outStorage(param, time, batchNum, finalOperateID);
+                    appDeviceLog.setOperator(utilService.getUserName());
+                    save(appDeviceLog); // 记录出库日志
                 }
-                batchNum = appDevice.getBatchNum();
-                appDevice.setOutstorageTime(time);
-                appDevice.setStatus(3); // 已出库
-                appDeviceService.save(appDevice);
-                AppDeviceLog appDeviceLog = new AppDeviceLog(p, appDevice.getImei()).outStorage(param, time, batchNum, finalOperateID);
-                appDeviceLog.setOperator(utilService.getUserName());
-                save(appDeviceLog); // 记录出库日志
             });
         }
     }