Bladeren bron

bug修复

lmstack 3 jaren geleden
bovenliggende
commit
735e6efe82

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

@@ -5,6 +5,7 @@ import cn.fastfun.controller.param.*;
 import cn.fastfun.service.AppDeviceLogService;
 import cn.fastfun.service.AppDeviceService;
 import cn.fastfun.service.SysExcelFieldService;
+import cn.fastfun.service.UtilService;
 import cn.fastfun.service.entity.AppDevice;
 import cn.fastfun.service.entity.AppDeviceLog;
 import cn.fastfun.util.DateUtils;
@@ -40,6 +41,9 @@ public class ApiAppDeviceController {
     @Resource(name = "appDeviceService")
     AppDeviceService appDeviceService;
 
+    @Resource
+    UtilService utilService;
+
     @Resource
     AppDeviceLogService appDeviceLogService;
 
@@ -78,6 +82,7 @@ public class ApiAppDeviceController {
 
             AppDevice entity = new AppDevice().fromFormParam(param);// 实体
             entity.setOperateID(operateID.intValue());
+            entity.setOperator(utilService.getUserName());
             appDeviceService.save(entity);
             return ApiDTO.ok("保存成功");
         } else {
@@ -155,7 +160,9 @@ public class ApiAppDeviceController {
     public ApiPageDTO devicePageQueryDetial(@RequestBody DeviceOperateQueryParam param) {
 
         Page<AppDevice> devicePage = appDeviceService.findByParam(param);
-        devicePage.getContent().forEach(p -> appDeviceService.addImeiTitle(p));
+        devicePage.getContent().forEach(p ->
+                appDeviceService.addImeiTitle(p)
+        );
         return new ApiPageDTO(null, devicePage);
     }
 

+ 19 - 31
src/main/java/cn/fastfun/controller/api/ApiAppDeviceLogController.java

@@ -93,11 +93,11 @@ public class ApiAppDeviceLogController {
     @RequestMapping(value = "instorage/batch/inStorageQuery", method = RequestMethod.POST)
     public ApiPageDTO inStorageBatchInStorageQuery(@RequestBody DeviceBatchQueryParam param) {
 
-        QueryParam query = new QueryParam();
+
         if (!StringUtils.isEmpty(param)) {
-            query.addParam(QueryParamExp.like("batchNum", "%".concat(param.getBatchNum()).concat("%")));
+            param.addParam(QueryParamExp.eq("batchNum", param.getBatchNum()));
         }
-        Page<AppDevice> devicePage = appDeviceService.findByParam(query);
+        Page<AppDevice> devicePage = appDeviceService.findByParam(param);
         devicePage.getContent().forEach(p -> {
             appDeviceService.addImeiTitle(p);
         });
@@ -165,17 +165,14 @@ public class ApiAppDeviceLogController {
     @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);
+        param.addParam(QueryParamExp.eq("operateID", param.getOperateID()));
+        param.addParam(QueryParamExp.eq("type", 2));
+        Page<AppDeviceLog> deviceLogPage = deviceLogService.findByParam(param);
 
         deviceLogPage.getContent().forEach(p -> {
             AppDevice device = new AppDevice();
             device.setImei(p.getImei());
             appDeviceService.addImeiTitle(device);
-            device.setImei(p.getImei());
-            appDeviceService.addImeiTitle(device);
             p.appendFormDevice(device);
             p.appendInTime(device);
         });
@@ -221,12 +218,9 @@ public class ApiAppDeviceLogController {
     @RequestMapping(value = "transfer/bySn/pageQuery", method = RequestMethod.POST)
     public ApiPageDTO transferBySnPageQuery(@RequestBody TransferBySnQueryParam param) {
 
-        QueryParam query = new QueryParam();
-        if (!StringUtils.isEmpty(param)) {
-            query.addParam(QueryParamExp.like("sn", "%".concat(param.getSn()).concat("%")));
-        }
-        query.addParam(QueryParamExp.eq("status", 1));
-        Page<AppDevice> devicePage = appDeviceService.findByParam(query);
+
+        param.addParam(QueryParamExp.eq("status", 1));
+        Page<AppDevice> devicePage = appDeviceService.findByParam(param);
 
         devicePage.getContent().forEach(p -> {
             QueryParam finalQuery = new QueryParam();
@@ -286,12 +280,12 @@ public class ApiAppDeviceLogController {
     @RequestMapping(value = "transfer/batch/detailQuery", method = RequestMethod.POST)
     public ApiPageDTO transferByBatchDetailQuery(@RequestBody DeviceBatchQueryParam param) {
 
-        QueryParam query = new QueryParam();
         if (!StringUtils.isEmpty(param)) {
-            query.addParam(QueryParamExp.like("batchNum", "%".concat(param.getBatchNum()).concat("%")));
+            param.addParam(QueryParamExp.like("batchNum", "%".concat(param.getBatchNum()).concat("%")));
         }
-        Page<AppDevice> devicePage = appDeviceService.findByParam(query);
+        Page<AppDevice> devicePage = appDeviceService.findByParam(param);
         devicePage.getContent().forEach(p -> {
+
             appDeviceService.addImeiTitle(p);
         });
         return new ApiPageDTO(null, devicePage);
@@ -301,12 +295,8 @@ public class ApiAppDeviceLogController {
     @RequestMapping(value = "transferBack/pageQuery", method = RequestMethod.POST)
     public ApiPageDTO transferBackPageQuery(@RequestBody TransferBySnQueryParam param) {
 
-        QueryParam query = new QueryParam();
-        if (!StringUtils.isEmpty(param)) {
-            query.addParam(QueryParamExp.like("sn", "%".concat(param.getSn()).concat("%")));
-        }
-        query.addParam(QueryParamExp.eq("status", 3));
-        Page<AppDevice> devicePage = appDeviceService.findByParam(query);
+        param.addParam(QueryParamExp.eq("status", 3));
+        Page<AppDevice> devicePage = appDeviceService.findByParam(param);
         return new ApiPageDTO(null, devicePage);
     }
 
@@ -321,10 +311,9 @@ public class ApiAppDeviceLogController {
     @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);
+        param.addParam(QueryParamExp.eq("operateID", param.getOperateID()));
+        param.addParam(QueryParamExp.eq("type", 3));
+        Page<AppDeviceLog> deviceLogPage = deviceLogService.findByParam(param);
 
         deviceLogPage.getContent().forEach(p -> {
             AppDevice device = new AppDevice();
@@ -379,11 +368,10 @@ public class ApiAppDeviceLogController {
     @RequestMapping(value = "outstorage/batch/detailQuery", method = RequestMethod.POST)
     public ApiPageDTO outByBatchDetailQuery(@RequestBody DeviceBatchQueryParam param) {
 
-        QueryParam query = new QueryParam();
         if (!StringUtils.isEmpty(param)) {
-            query.addParam(QueryParamExp.like("batchNum", "%".concat(param.getBatchNum()).concat("%")));
+            param.addParam(QueryParamExp.like("batchNum", "%".concat(param.getBatchNum()).concat("%")));
         }
-        Page<AppDevice> devicePage = appDeviceService.findByParam(query);
+        Page<AppDevice> devicePage = appDeviceService.findByParam(param);
         devicePage.getContent().forEach(p -> {
             appDeviceService.addImeiTitle(p);
         });

+ 9 - 3
src/main/java/cn/fastfun/controller/param/TransferBySnQueryParam.java

@@ -1,19 +1,25 @@
 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 TransferBySnQueryParam extends QueryParam {
-    
-    @ApiModelProperty(value = "设备编号", name = "sn")
-    private String sn;
 
+    //    @ApiModelProperty(value = "设备编号", name = "sn");
+    public void setSn(String sn) {
+        if (!StringUtils.isEmpty(sn)) {
+            addParam(QueryParamExp.like("sn", "%".concat(sn).concat("%")));
+        }
+
+    }
 }
 
 

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

@@ -14,7 +14,7 @@ import java.util.List;
 
 @Setter
 @Getter
-public class detialQueryParam {
+public class detialQueryParam extends QueryParam{
 
     @ApiModelProperty(value = "操作号", name = "operateID", required = true)
     Integer operateID;

+ 2 - 0
src/main/java/cn/fastfun/service/UtilService.java

@@ -45,4 +45,6 @@ public interface UtilService {
      */
     String getUserId();
 
+    String getUserName();
+
 }

+ 4 - 0
src/main/java/cn/fastfun/service/entity/AppDeviceLog.java

@@ -5,6 +5,7 @@ import cn.fastfun.controller.param.HandelFormParam;
 import cn.fastfun.controller.param.LibraryOutFormParam;
 import cn.fastfun.controller.param.TransferBySnQueryParam;
 import cn.fastfun.controller.param.TransferFormParam;
+import cn.fastfun.service.UtilService;
 import com.bridge.entity.DateEntity;
 import com.fasterxml.jackson.annotation.JsonFormat;
 import com.fasterxml.jackson.annotation.JsonIgnore;
@@ -16,6 +17,7 @@ import lombok.NoArgsConstructor;
 import lombok.Setter;
 import org.springframework.format.annotation.DateTimeFormat;
 
+import javax.annotation.Resource;
 import javax.persistence.Column;
 import javax.persistence.Entity;
 import javax.persistence.Table;
@@ -117,6 +119,8 @@ public class AppDeviceLog extends DateEntity {
     private String batchNum;
 
 
+
+
     public AppDeviceLog(String sn, String imei) {
         setSn(sn);
         setImei(imei);

+ 24 - 5
src/main/java/cn/fastfun/service/impl/AppDeviceLogServiceImpl.java

@@ -3,6 +3,7 @@ package cn.fastfun.service.impl;
 import cn.fastfun.controller.param.*;
 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.service.entity.AppImeiHistory;
@@ -36,6 +37,8 @@ public class AppDeviceLogServiceImpl extends JpaServiceImp<AppDeviceLog, String>
     @Resource
     AppDeviceLogService appDeviceLogService;
 
+    @Resource
+    UtilService utilService;
     //业务类
     @Resource(name = "appImeiHistoryService")
     JpaService<AppImeiHistory, String> appImeiHistoryService;
@@ -58,6 +61,7 @@ public class AppDeviceLogServiceImpl extends JpaServiceImp<AppDeviceLog, String>
             Date time = new Date();
 
             BigInteger finalOperateID = operateID;
+
             param.getSn().forEach(p -> {
                 String batchNum;
                 AppDevice appDevice = appDeviceService.getOne(QueryParamExp.eq("sn", p));
@@ -65,8 +69,12 @@ public class AppDeviceLogServiceImpl extends JpaServiceImp<AppDeviceLog, String>
                 batchNum = appDevice.getBatchNum();
                 if (appDevice.getStatus() < 1) {
                     appDevice.setStatus(1); // 已入库
+                    appDevice.setInstorageTime(time);
                     appDeviceService.save(appDevice);
-                    save(new AppDeviceLog(p, appDevice.getImei()).toInStorage(time, batchNum, finalOperateID)); // 记录入库日志
+
+                    AppDeviceLog appDeviceLog = new AppDeviceLog(p, appDevice.getImei()).toInStorage(time, batchNum, finalOperateID);
+                    appDeviceLog.setOperator(utilService.getUserName());
+                    save(appDeviceLog); // 记录入库日志
                 }
             });
         }
@@ -122,7 +130,10 @@ public class AppDeviceLogServiceImpl extends JpaServiceImp<AppDeviceLog, String>
                 appDevice.setTransferTime(time);
                 appDevice.setOwnerId(param.getCustomId()); // 设置归属
                 appDeviceService.save(appDevice);
-                save(new AppDeviceLog(p, appDevice.getImei()).toTransfer(param, time, batchNum, finalOperateID)); // 记录划拨日志
+
+                AppDeviceLog appDeviceLog = new AppDeviceLog(p, appDevice.getImei()).toTransfer(param, time, batchNum, finalOperateID);
+                appDeviceLog.setOperator(utilService.getUserName());
+                save(appDeviceLog); // 记录划拨日志
             });
         }
     }
@@ -149,7 +160,10 @@ public class AppDeviceLogServiceImpl extends JpaServiceImp<AppDeviceLog, String>
         appDevice.setStatus(1); // 已入库
         appDevice.setTransferBackTime(time);
         appDeviceService.save(appDevice);
-        save(new AppDeviceLog(appDevice.getSn(), appDevice.getImei()).transferBack(param, time, batchNum, finalOperateID)); // 记录出库日志
+
+        AppDeviceLog appDeviceLog = new AppDeviceLog(appDevice.getSn(), appDevice.getImei()).transferBack(param, time, batchNum, finalOperateID);
+        appDeviceLog.setOperator(utilService.getUserName());
+        save(appDeviceLog); // 记录调回日志
     }
 
     @Override
@@ -196,7 +210,9 @@ public class AppDeviceLogServiceImpl extends JpaServiceImp<AppDeviceLog, String>
                 appDevice.setOutstorageTime(time);
                 appDevice.setStatus(3); // 已出库
                 appDeviceService.save(appDevice);
-                save(new AppDeviceLog(p, appDevice.getImei()).outStorage(param, time, batchNum, finalOperateID)); // 记录出库日志
+                AppDeviceLog appDeviceLog = new AppDeviceLog(p, appDevice.getImei()).outStorage(param, time, batchNum, finalOperateID);
+                appDeviceLog.setOperator(utilService.getUserName());
+                save(appDeviceLog); // 记录出库日志
             });
         }
     }
@@ -224,7 +240,10 @@ public class AppDeviceLogServiceImpl extends JpaServiceImp<AppDeviceLog, String>
             appDevice.setHandleTime(time);
             appDevice.setStatus(4); // 处置
             appDeviceService.save(appDevice);
-            save(new AppDeviceLog(p, appDevice.getImei()).toHandle(param, time, batchNum, finalOperateID)); // 记录处置日志
+
+            AppDeviceLog appDeviceLog = new AppDeviceLog(p, appDevice.getImei()).toHandle(param, time, batchNum, finalOperateID);
+            appDeviceLog.setOperator(utilService.getUserName());
+            save(appDeviceLog); // 记录处置日志
         });
     }
 }

+ 22 - 3
src/main/java/cn/fastfun/service/impl/AppDeviceServiceImp.java

@@ -4,10 +4,12 @@ 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.UtilService;
 import cn.fastfun.service.entity.AppDevice;
 import cn.fastfun.service.entity.Product;
 import cn.fastfun.service.repository.AppDeviceRepository;
 
+import com.bridge.dto.ApiDTO;
 import com.bridge.dto.ApiPageDTO;
 import com.bridge.dto.QueryParam;
 import com.bridge.dto.QueryParamExp;
@@ -27,13 +29,18 @@ import java.util.*;
 @Service("appDeviceService")
 public class AppDeviceServiceImp extends JpaServiceImp<AppDevice, String> implements AppDeviceService {
 
-
+    //业务类
+    @Resource(name = "appDeviceService")
+    AppDeviceService appDeviceService;
     @Resource
     AppDeviceRepository deviceRepository;
 
     @Resource
     ProductService productService;
 
+    @Resource
+    UtilService utilService;
+
     @Override
     public void importDevice(List<Map<String, Object>> list) {
         List<AppDevice> devices = new ArrayList<>();
@@ -48,7 +55,7 @@ public class AppDeviceServiceImp extends JpaServiceImp<AppDevice, String> implem
         operateID = operateID.add(BigInteger.valueOf(1));
         for (Map<String, Object> p : list) {
             AppDevice device = new AppDevice(p);
-            if (null == device.getDeliverTime()) new ApiRuntimeException("发货时间读取错误");
+            if (null == device.getDeliverTime()) throw new ApiRuntimeException("发货时间读取错误");
             // 数据效验
             if (null == diffAttrDTO) {
                 diffAttrDTO = new DeviceAttrDTO(device.getBatchNum(), device.getSn());
@@ -63,13 +70,25 @@ 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("存在不同的收货地");
+
+            // 重复导入检查
+            List<AppDevice> checkDuplicatedResultOnImei = appDeviceService.findAll(
+                    QueryParamExp.eq("imei", device.getImei()));
+            if (!checkDuplicatedResultOnImei.isEmpty()) {
+                throw new ApiRuntimeException("imei:" + device.getImei() + "已经被录入");
+            }
+            List<AppDevice> checkDuplicatedResultOnSn = appDeviceService.findAll(
+                    QueryParamExp.eq("sn", device.getSn()));
+            if (!checkDuplicatedResultOnSn.isEmpty()) {
+                throw new ApiRuntimeException("sn:" + device.getSn() + "已经被录入");
+            }
             device.setOperateID(operateID.intValue());
+            device.setOperator(utilService.getUserName());
             devices.add(device);
         }
         save(devices);
     }
 
-
     public AppDeviceRepository getRepository() {
         return deviceRepository;
     }

+ 9 - 0
src/main/java/cn/fastfun/service/impl/UtilServiceImpl.java

@@ -131,6 +131,7 @@ public class UtilServiceImpl implements UtilService {
             }
             map.put("userId", t.getId());
             map.put("data", new Date());
+            map.put("userName", t.getUserName());
             if (loginFailed.containsKey(userName)) {
                 loginFailed.remove(userName);
                 loginFailedTime.remove(userName);
@@ -157,6 +158,14 @@ public class UtilServiceImpl implements UtilService {
         return String.valueOf(jwt.get("userId"));
     }
 
+    @Override
+    public String getUserName() {
+        HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
+        // 获得token
+        Map<String, Object> jwt = JwtUtil.parseJWT(request.getHeader("X-Token"), getSecretKey());
+        return String.valueOf(jwt.get("userName"));
+    }
+
     private LoginUser getUserForRedis(String userId) {
         if (StringUtils.isEmpty(userId))
             throw new ApiRuntimeException(501, "账号过期");