|
@@ -1,37 +1,32 @@
|
|
|
package com.izouma.nineth.web;
|
|
package com.izouma.nineth.web;
|
|
|
|
|
|
|
|
import com.izouma.nineth.domain.MetaUserGold;
|
|
import com.izouma.nineth.domain.MetaUserGold;
|
|
|
-import com.izouma.nineth.domain.MetaUserGoldRecord;
|
|
|
|
|
import com.izouma.nineth.dto.MetaRestResult;
|
|
import com.izouma.nineth.dto.MetaRestResult;
|
|
|
import com.izouma.nineth.dto.PageQuery;
|
|
import com.izouma.nineth.dto.PageQuery;
|
|
|
import com.izouma.nineth.exception.BusinessException;
|
|
import com.izouma.nineth.exception.BusinessException;
|
|
|
-import com.izouma.nineth.repo.MetaUserGoldRecordRepo;
|
|
|
|
|
import com.izouma.nineth.repo.MetaUserGoldRepo;
|
|
import com.izouma.nineth.repo.MetaUserGoldRepo;
|
|
|
-import com.izouma.nineth.repo.UserRepo;
|
|
|
|
|
import com.izouma.nineth.service.MetaUserGoldService;
|
|
import com.izouma.nineth.service.MetaUserGoldService;
|
|
|
import com.izouma.nineth.utils.ObjUtils;
|
|
import com.izouma.nineth.utils.ObjUtils;
|
|
|
import com.izouma.nineth.utils.excel.ExcelUtils;
|
|
import com.izouma.nineth.utils.excel.ExcelUtils;
|
|
|
import lombok.AllArgsConstructor;
|
|
import lombok.AllArgsConstructor;
|
|
|
-import org.apache.commons.collections.CollectionUtils;
|
|
|
|
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.data.domain.Page;
|
|
import org.springframework.data.domain.Page;
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
import java.io.IOException;
|
|
import java.io.IOException;
|
|
|
-import java.util.*;
|
|
|
|
|
|
|
+import java.util.List;
|
|
|
|
|
+import java.util.Objects;
|
|
|
|
|
|
|
|
@RestController
|
|
@RestController
|
|
|
@RequestMapping("/metaUserGold")
|
|
@RequestMapping("/metaUserGold")
|
|
|
@AllArgsConstructor
|
|
@AllArgsConstructor
|
|
|
|
|
+@Slf4j
|
|
|
public class MetaUserGoldController extends BaseController {
|
|
public class MetaUserGoldController extends BaseController {
|
|
|
private MetaUserGoldService metaUserGoldService;
|
|
private MetaUserGoldService metaUserGoldService;
|
|
|
|
|
|
|
|
private MetaUserGoldRepo metaUserGoldRepo;
|
|
private MetaUserGoldRepo metaUserGoldRepo;
|
|
|
|
|
|
|
|
- private MetaUserGoldRecordRepo metaUserGoldRecordRepo;
|
|
|
|
|
-
|
|
|
|
|
- private UserRepo userRepo;
|
|
|
|
|
-
|
|
|
|
|
//@PreAuthorize("hasRole('ADMIN')")
|
|
//@PreAuthorize("hasRole('ADMIN')")
|
|
|
@PostMapping("/save")
|
|
@PostMapping("/save")
|
|
|
public MetaUserGold save(@RequestBody MetaUserGold record) {
|
|
public MetaUserGold save(@RequestBody MetaUserGold record) {
|
|
@@ -69,23 +64,7 @@ public class MetaUserGoldController extends BaseController {
|
|
|
|
|
|
|
|
@PostMapping("/changeNum")
|
|
@PostMapping("/changeNum")
|
|
|
public MetaRestResult<MetaUserGold> changeNum(Long userId, int num) {
|
|
public MetaRestResult<MetaUserGold> changeNum(Long userId, int num) {
|
|
|
- MetaUserGold metaUserGold = metaUserGoldRepo.findByUserIdAndDel(userId, false);
|
|
|
|
|
- if (Objects.isNull(metaUserGold)) {
|
|
|
|
|
- return MetaRestResult.returnError(String.format("不存在用户[%S]记录", userId));
|
|
|
|
|
- }
|
|
|
|
|
- // 操作前金币数量
|
|
|
|
|
- int nowNum = metaUserGold.getNum();
|
|
|
|
|
- MetaUserGoldRecord metaUserGoldRecord = new MetaUserGoldRecord();
|
|
|
|
|
- metaUserGoldRecord.setUserId(userId);
|
|
|
|
|
- metaUserGoldRecord.setBeforeNum(nowNum);
|
|
|
|
|
- metaUserGoldRecord.setAfterNum(nowNum + num);
|
|
|
|
|
- metaUserGoldRecord.setOperationNum(num);
|
|
|
|
|
- metaUserGold.setNum(nowNum + num);
|
|
|
|
|
- if (metaUserGoldRecord.getAfterNum() < 0) {
|
|
|
|
|
- return MetaRestResult.returnError(String.format("用户[%S] 当前金币剩余[%S] 本次操作需要金币数量为[%S]", userId, nowNum, -num));
|
|
|
|
|
- }
|
|
|
|
|
- metaUserGoldRecordRepo.save(metaUserGoldRecord);
|
|
|
|
|
- return MetaRestResult.returnSuccess(metaUserGoldRepo.save(metaUserGold));
|
|
|
|
|
|
|
+ return metaUserGoldService.changeNum(userId, num);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
@GetMapping("/{userId}/queryNum")
|
|
@GetMapping("/{userId}/queryNum")
|
|
@@ -98,37 +77,13 @@ public class MetaUserGoldController extends BaseController {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
@GetMapping("/{userIds}/check")
|
|
@GetMapping("/{userIds}/check")
|
|
|
- private void checkUserId(@PathVariable String userIds) {
|
|
|
|
|
- String[] split = userIds.split(" ");
|
|
|
|
|
- Set<Long> set = new HashSet<>();
|
|
|
|
|
- Arrays.stream(split).forEach(userId -> {
|
|
|
|
|
- userRepo.findById(Long.parseLong(userId)).orElseThrow(new BusinessException(String.format("不存在id[%S]的用户", userId)));
|
|
|
|
|
- set.add(Long.parseLong(userId));
|
|
|
|
|
- });
|
|
|
|
|
- if(set.size() != split.length) {
|
|
|
|
|
- throw new BusinessException("存在重复用户id,请检查!");
|
|
|
|
|
- }
|
|
|
|
|
- List<MetaUserGold> metaUserGolds = metaUserGoldRepo.findAllByUserIdInAndDel(set, false);
|
|
|
|
|
- if (CollectionUtils.isNotEmpty(metaUserGolds)) {
|
|
|
|
|
- StringBuffer str = new StringBuffer();
|
|
|
|
|
- metaUserGolds.forEach(metaUserGold -> {
|
|
|
|
|
- str.append(metaUserGold.getUserId()).append(",");
|
|
|
|
|
- });
|
|
|
|
|
- throw new BusinessException(String.format("已经存在[%S]的数据", str.subSequence(0, str.length())));
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ public void checkUserId(@PathVariable String userIds) {
|
|
|
|
|
+ metaUserGoldService.checkUserId(userIds);
|
|
|
}
|
|
}
|
|
|
- @PostMapping("/{userIds}/init")
|
|
|
|
|
- private void initMetaUserGold(@PathVariable String userIds) {
|
|
|
|
|
- String[] split = userIds.split(" ");
|
|
|
|
|
- List<MetaUserGold> metaUserGolds = new ArrayList<>();
|
|
|
|
|
- List<MetaUserGoldRecord> metaUserGoldRecords = new ArrayList<>();
|
|
|
|
|
- Arrays.stream(split).forEach(userId -> {
|
|
|
|
|
- metaUserGolds.add(new MetaUserGold(Long.parseLong(userId), 0));
|
|
|
|
|
- metaUserGoldRecords.add(new MetaUserGoldRecord(Long.parseLong(userId), 0, 0, 0));
|
|
|
|
|
- });
|
|
|
|
|
- metaUserGoldRepo.saveAll(metaUserGolds);
|
|
|
|
|
- metaUserGoldRecordRepo.saveAll(metaUserGoldRecords);
|
|
|
|
|
|
|
|
|
|
|
|
+ @PostMapping("/{userIds}/init")
|
|
|
|
|
+ public void initMetaUserGold(@PathVariable String userIds) {
|
|
|
|
|
+ metaUserGoldService.initMetaUserGold(userIds);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|