Browse Source

项目返回参与者id与name

Reiskuchen 5 năm trước cách đây
mục cha
commit
34ce23d1da

+ 0 - 16
fhKeeper/formulahousekeeper/management-platform/src/main/java/com/management/platform/controller/ParticipationController.java

@@ -1,15 +1,9 @@
 package com.management.platform.controller;
 
 
-import com.management.platform.service.ParticipationService;
-import com.management.platform.util.HttpRespMsg;
-import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RequestParam;
 import org.springframework.web.bind.annotation.RestController;
 
-import javax.servlet.http.HttpServletRequest;
-
 /**
  * <p>
  * 人员参与项目的情况 前端控制器
@@ -21,16 +15,6 @@ import javax.servlet.http.HttpServletRequest;
 @RestController
 @RequestMapping("/participation")
 public class ParticipationController {
-    @Autowired
-    private ParticipationService participationService;
 
-    /**
-     * 获取参加某项目的所有参与者id
-     * projectId 项目id
-     */
-    @RequestMapping("/get")
-    public HttpRespMsg getParticipation(@RequestParam Integer projectId, HttpServletRequest request) {
-        return participationService.getParticipation(projectId, request);
-    }
 }
 

+ 16 - 0
fhKeeper/formulahousekeeper/management-platform/src/main/java/com/management/platform/entity/vo/ProjectVO.java

@@ -0,0 +1,16 @@
+package com.management.platform.entity.vo;
+
+import com.management.platform.entity.Project;
+import lombok.Data;
+import lombok.EqualsAndHashCode;
+import lombok.experimental.Accessors;
+
+import java.util.List;
+import java.util.Map;
+
+@Data
+@EqualsAndHashCode(callSuper = false)
+@Accessors(chain = true)
+public class ProjectVO extends Project {
+    List<Map<String, Object>> participator;
+}

+ 2 - 1
fhKeeper/formulahousekeeper/management-platform/src/main/java/com/management/platform/mapper/ParticipationMapper.java

@@ -5,6 +5,7 @@ import com.management.platform.entity.Participation;
 import org.apache.ibatis.annotations.Param;
 
 import java.util.List;
+import java.util.Map;
 
 /**
  * <p>
@@ -15,5 +16,5 @@ import java.util.List;
  * @since 2020-02-12
  */
 public interface ParticipationMapper extends BaseMapper<Participation> {
-    List<String> getParticipator(@Param("projectId") Integer projectId);
+    List<Map<String, Object>> getParticipator(@Param("projectId") Integer projectId);
 }

+ 1 - 4
fhKeeper/formulahousekeeper/management-platform/src/main/java/com/management/platform/service/ParticipationService.java

@@ -2,9 +2,6 @@ package com.management.platform.service;
 
 import com.baomidou.mybatisplus.extension.service.IService;
 import com.management.platform.entity.Participation;
-import com.management.platform.util.HttpRespMsg;
-
-import javax.servlet.http.HttpServletRequest;
 
 /**
  * <p>
@@ -15,5 +12,5 @@ import javax.servlet.http.HttpServletRequest;
  * @since 2020-02-12
  */
 public interface ParticipationService extends IService<Participation> {
-    HttpRespMsg getParticipation(Integer projectId, HttpServletRequest request);
+
 }

+ 0 - 30
fhKeeper/formulahousekeeper/management-platform/src/main/java/com/management/platform/service/impl/ParticipationServiceImpl.java

@@ -3,15 +3,9 @@ package com.management.platform.service.impl;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.management.platform.entity.Participation;
 import com.management.platform.mapper.ParticipationMapper;
-import com.management.platform.mapper.ProjectMapper;
-import com.management.platform.mapper.UserMapper;
 import com.management.platform.service.ParticipationService;
-import com.management.platform.util.HttpRespMsg;
 import org.springframework.stereotype.Service;
 
-import javax.annotation.Resource;
-import javax.servlet.http.HttpServletRequest;
-
 /**
  * <p>
  * 人员参与项目的情况 服务实现类
@@ -23,28 +17,4 @@ import javax.servlet.http.HttpServletRequest;
 @Service
 public class ParticipationServiceImpl extends ServiceImpl<ParticipationMapper, Participation> implements ParticipationService {
 
-    @Resource
-    private UserMapper userMapper;
-    @Resource
-    private ProjectMapper projectMapper;
-    @Resource
-    private ParticipationMapper participationMapper;
-
-    //获取某个项目的所有参与者id
-    @Override
-    public HttpRespMsg getParticipation(Integer projectId, HttpServletRequest request) {
-        HttpRespMsg httpRespMsg = new HttpRespMsg();
-        try {
-            Integer companyId = userMapper.selectById(request.getHeader("Token")).getCompanyId();
-            if (projectMapper.selectById(projectId).getCompanyId().equals(companyId)) {
-                httpRespMsg.data = participationMapper.getParticipator(projectId);
-            } else {
-                httpRespMsg.setError("无法查看其他公司的项目");
-            }
-        } catch (NullPointerException e) {
-            httpRespMsg.setError("验证失败");
-            return httpRespMsg;
-        }
-        return httpRespMsg;
-    }
 }

+ 17 - 1
fhKeeper/formulahousekeeper/management-platform/src/main/java/com/management/platform/service/impl/ProjectServiceImpl.java

@@ -1,22 +1,26 @@
 package com.management.platform.service.impl;
 
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.management.platform.entity.Participation;
 import com.management.platform.entity.Project;
 import com.management.platform.entity.Report;
+import com.management.platform.entity.vo.ProjectVO;
 import com.management.platform.mapper.ParticipationMapper;
 import com.management.platform.mapper.ProjectMapper;
 import com.management.platform.mapper.ReportMapper;
 import com.management.platform.mapper.UserMapper;
 import com.management.platform.service.ProjectService;
 import com.management.platform.util.HttpRespMsg;
+import org.springframework.beans.BeanUtils;
 import org.springframework.stereotype.Service;
 
 import javax.annotation.Resource;
 import javax.servlet.http.HttpServletRequest;
 import java.math.BigDecimal;
+import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
@@ -64,8 +68,20 @@ public class ProjectServiceImpl extends ServiceImpl<ProjectMapper, Project> impl
         try {
             //通过公司id获取该公司所有的项目列表
             Integer companyId = userMapper.selectById(request.getHeader("Token")).getCompanyId();
-            httpRespMsg.data = projectMapper.selectPage(new Page<Project>(pageIndex, pageSize),
+            IPage<Project> projectIPage = projectMapper.selectPage(new Page<>(pageIndex, pageSize),
                     new QueryWrapper<Project>().eq("company_id", companyId));
+            List<Project> projectList = projectIPage.getRecords();
+            List<ProjectVO> list = new ArrayList<>();
+            for (Project project : projectList) {
+                ProjectVO projectVO = new ProjectVO();
+                BeanUtils.copyProperties(project, projectVO);
+                projectVO.setParticipator(participationMapper.getParticipator(projectVO.getId()));
+            }
+            Long total = projectIPage.getTotal();
+            Map<String, Object> map = new HashMap<>();
+            map.put("records", list);
+            map.put("total", total);
+            httpRespMsg.data = map;
         } catch (NullPointerException e) {
             httpRespMsg.setError("验证失败");
             return httpRespMsg;