lyhzzz 2 роки тому
батько
коміт
3846259b03

+ 1 - 9
src/main/java/com/fdkankan/manage/controller/UserController.java

@@ -83,15 +83,7 @@ public class UserController {
             throw new BusinessException(ResultCode.MISSING_REQUIRED_PARAMETERS);
         }
         userIncrementService.add(param);
-        IncrementType incrementType = incrementTypeService.getById(param.getIncrementTypeId());
-        if(incrementType == null){
-            throw new BusinessException(ResultCode.INCREMENT_TYPE_EMPTY);
-        }
-        User user = userService.getById(param.getUserId());
-        if(user == null){
-            throw new BusinessException(ResultCode.USER_NOT_EXIST);
-        }
-        user.setDownloadNumTotal(user.getDownloadNumTotal() + incrementType.getDownloadNum());
+
         return ResultData.ok();
     }
 

+ 17 - 1
src/main/java/com/fdkankan/manage/service/impl/UserIncrementServiceImpl.java

@@ -6,6 +6,7 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.fdkankan.manage.common.ResultCode;
 import com.fdkankan.manage.entity.IncrementType;
+import com.fdkankan.manage.entity.User;
 import com.fdkankan.manage.exception.BusinessException;
 import com.fdkankan.common.response.PageInfo;
 import com.fdkankan.common.util.DateUtil;
@@ -15,6 +16,7 @@ import com.fdkankan.manage.mapper.IUserIncrementMapper;
 import com.fdkankan.manage.service.ICameraService;
 import com.fdkankan.manage.service.IIncrementTypeService;
 import com.fdkankan.manage.service.IUserIncrementService;
+import com.fdkankan.manage.service.IUserService;
 import com.fdkankan.manage.vo.request.UserIncrementParam;
 import com.fdkankan.manage.vo.response.GroupByCount;
 import com.fdkankan.manage.vo.response.UserIncrementVo;
@@ -40,6 +42,8 @@ public class UserIncrementServiceImpl extends ServiceImpl<IUserIncrementMapper,
     private ICameraService cameraService;
     @Autowired
     IIncrementTypeService incrementTypeService;
+    @Autowired
+    IUserService userService;
 
     @Override
     public Long getValidCountByUserId(Long userId) {
@@ -126,7 +130,19 @@ public class UserIncrementServiceImpl extends ServiceImpl<IUserIncrementMapper,
             userIncrement.setIncrementTypeId(param.getIncrementTypeId());
             userIncrementList.add(userIncrement);
         }
-        this.saveBatch(userIncrementList);
+
+        if(userIncrementList.size() >0){
+            this.saveBatch(userIncrementList);
+            IncrementType incrementType = incrementTypeService.getById(param.getIncrementTypeId());
+            if(incrementType == null){
+                throw new BusinessException(ResultCode.INCREMENT_TYPE_EMPTY);
+            }
+            User user = userService.getById(param.getUserId());
+            if(user == null){
+                throw new BusinessException(ResultCode.USER_NOT_EXIST);
+            }
+            user.setDownloadNumTotal(user.getDownloadNumTotal() + param.getCount() * incrementType.getDownloadNum());
+        }
     }
 
     @Override