Quellcode durchsuchen

fix: buglist返回值没包装以及数据库时间戳时区错误

370774330@qq.com vor 5 Jahren
Ursprung
Commit
505e0773c3

+ 2 - 2
web/src/main/java/seecoder/devcloud/web/controller/project/BugListController.java

@@ -41,8 +41,8 @@ public class BugListController {
     @GetMapping("/list")
     @ApiOperation(value = "获取一个项目所有bug list", httpMethod = "GET")
     @ApiImplicitParam(value = "projectId", dataType = "int", paramType = "query")
-    List<BugListVO> list(@RequestParam("projectId") Integer projectId){
-        return bugListService.list(projectId);
+    public Response<List<BugListVO>> list(@RequestParam("projectId") Integer projectId){
+        return Response.buildSuccess(bugListService.list(projectId));
     }
 
     @PutMapping

+ 13 - 11
web/src/main/java/seecoder/devcloud/web/service/impl/project/BugListServiceImpl.java

@@ -18,9 +18,7 @@ import seecoder.devcloud.web.model.vo.project.BugListVO;
 import seecoder.devcloud.web.service.project.BugListService;
 
 import java.sql.Timestamp;
-import java.util.Date;
-import java.util.List;
-import java.util.Map;
+import java.util.*;
 import java.util.stream.Collectors;
 
 /**
@@ -52,29 +50,33 @@ public class BugListServiceImpl implements BugListService {
                 .description(vo.getDescription())
                 .timeToTake(vo.getTimeToTake())
                 .state(BugListStateEnum.CREATED)
+                .startTime(new Timestamp(System.currentTimeMillis()))
                 .priority(vo.getPriority())
-                .startTime(new Timestamp(new Date().getTime()))
                 .endTime(null)
                 .projectId(vo.getProjectId())
                 .build();
-        bugListMapper.insert(po, "startTime");
+        bugListMapper.insert(po);
     }
 
     @Override
     public List<BugListVO> list(Integer projectId) {
         List<BugListPO> bugs = bugListMapper.selectByProjectId(projectId);
         List<CommitPO> commits = commitMapper.selectByProjectIdAndType(projectId, CommitRelatedType.BUG_ID);
-        Map<Integer,List<CommitPO>> commitsMap = commits.stream().collect(Collectors.groupingBy(CommitPO::getRelatedId));
-        List<UserPO> users = userMapper.selectByIds(bugs.stream().map(BugListPO::getProcessorId).collect(Collectors.toList()));
-        Map<Integer,String> usernameMap = users.stream().collect(Collectors.toMap(UserPO::getId, UserPO::getUsername));
-        return bugs.stream().map(x->new BugListVO(x,commitsMap.get(x.getId()),usernameMap.get(x.getProcessorId()))).collect(Collectors.toList());
+        Map<Integer, List<CommitPO>> commitsMap = commits.stream().collect(Collectors.groupingBy(CommitPO::getRelatedId));
+        List<Integer> userIds = bugs.stream().map(x -> {
+            Integer userId = x.getProcessorId();
+            return userId != null? userId : -1;
+        }).filter(x -> x!=-1).collect(Collectors.toList());
+        List<UserPO> users = userIds.size()==0? new ArrayList<>() :userMapper.selectByIds(userIds);
+        Map<Integer, String> usernameMap = users.stream().collect(Collectors.toMap(UserPO::getId, UserPO::getUsername));
+        return bugs.stream().map(x -> new BugListVO(x, commitsMap.getOrDefault(x.getId(),new ArrayList<>()), usernameMap.getOrDefault(x.getProcessorId(), "no one"))).collect(Collectors.toList());
     }
 
 
     @Override
     public void updateBasicInfo(BugListUpdateBasicVO vo) {
         BugListPO po = BugListPO.builder().build();
-        BeanUtils.copyProperties(vo,po);
+        BeanUtils.copyProperties(vo, po);
         bugListMapper.update(po);
     }
 
@@ -82,7 +84,7 @@ public class BugListServiceImpl implements BugListService {
     public void updateState(CommitState state, Integer id) {
         BugListPO po = new BugListPO();
         po.setId(id);
-        switch (state){
+        switch (state) {
             case FIXING_ON:
                 po.setState(BugListStateEnum.PROCESSING);
                 break;