【查询项目关联组织时,过滤多余字段】

This commit is contained in:
weizhihong 2022-10-12 14:24:02 +08:00
parent ee8ad73e87
commit 1973bf3f24
4 changed files with 53 additions and 42 deletions

View File

@ -1,10 +1,10 @@
package club.joylink.rtss.controller.project; package club.joylink.rtss.controller.project;
import club.joylink.rtss.entity.Org;
import club.joylink.rtss.entity.project.Project; import club.joylink.rtss.entity.project.Project;
import club.joylink.rtss.entity.project.ProjectView; import club.joylink.rtss.entity.project.ProjectView;
import club.joylink.rtss.services.project.ProjectService; import club.joylink.rtss.services.project.ProjectService;
import club.joylink.rtss.vo.client.PageVO; import club.joylink.rtss.vo.client.PageVO;
import club.joylink.rtss.vo.client.org.CompanyVO;
import club.joylink.rtss.vo.project.*; import club.joylink.rtss.vo.project.*;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
@ -62,7 +62,7 @@ public class ProjectInfoController {
} }
@GetMapping("/{id}/orgList") @GetMapping("/{id}/orgList")
public List<Org> orgList(@PathVariable Long id) { public List<CompanyVO> orgList(@PathVariable Long id) {
return projectService.projectOrgList(id); return projectService.projectOrgList(id);
} }

View File

@ -1,9 +1,9 @@
package club.joylink.rtss.services.project; package club.joylink.rtss.services.project;
import club.joylink.rtss.entity.Org;
import club.joylink.rtss.entity.project.Project; import club.joylink.rtss.entity.project.Project;
import club.joylink.rtss.entity.project.ProjectView; import club.joylink.rtss.entity.project.ProjectView;
import club.joylink.rtss.vo.client.PageVO; import club.joylink.rtss.vo.client.PageVO;
import club.joylink.rtss.vo.client.org.CompanyVO;
import club.joylink.rtss.vo.project.*; import club.joylink.rtss.vo.project.*;
import java.util.List; import java.util.List;
@ -56,7 +56,7 @@ public interface ProjectService {
/** /**
* 根据项目ID获取与项目关联的所有组织信息 * 根据项目ID获取与项目关联的所有组织信息
*/ */
List<Org> projectOrgList(Long id); List<CompanyVO> projectOrgList(Long id);
/** /**
* 前端设置信息分页 * 前端设置信息分页

View File

@ -15,6 +15,7 @@ import club.joylink.rtss.entity.project.ProjectViewExample;
import club.joylink.rtss.simulation.cbtc.exception.SimulationException; import club.joylink.rtss.simulation.cbtc.exception.SimulationException;
import club.joylink.rtss.simulation.cbtc.exception.SimulationExceptionType; import club.joylink.rtss.simulation.cbtc.exception.SimulationExceptionType;
import club.joylink.rtss.vo.client.PageVO; import club.joylink.rtss.vo.client.PageVO;
import club.joylink.rtss.vo.client.org.CompanyVO;
import club.joylink.rtss.vo.project.*; import club.joylink.rtss.vo.project.*;
import com.github.pagehelper.Page; import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper; import com.github.pagehelper.PageHelper;
@ -142,7 +143,7 @@ public class ProjectServiceImpl implements ProjectService {
} }
@Override @Override
public List<Org> projectOrgList(Long id) { public List<CompanyVO> projectOrgList(Long id) {
Project project = projectDAO.selectByPrimaryKey(id); Project project = projectDAO.selectByPrimaryKey(id);
if (project == null) { if (project == null) {
throw new SimulationException(SimulationExceptionType.Illegal_Argument, "项目不存在"); throw new SimulationException(SimulationExceptionType.Illegal_Argument, "项目不存在");
@ -150,7 +151,8 @@ public class ProjectServiceImpl implements ProjectService {
List<OrgProject> orgProjectList = getOrgProjectList(List.of(project.getCode())); List<OrgProject> orgProjectList = getOrgProjectList(List.of(project.getCode()));
if (!CollectionUtils.isEmpty(orgProjectList)) { if (!CollectionUtils.isEmpty(orgProjectList)) {
List<Long> orgIdList = orgProjectList.stream().map(OrgProject::getOrgId).distinct().collect(Collectors.toList()); List<Long> orgIdList = orgProjectList.stream().map(OrgProject::getOrgId).distinct().collect(Collectors.toList());
return getOrgList(orgIdList); List<Org> orgList = getOrgList(orgIdList);
return orgList.stream().map(CompanyVO::simpleInfoVO).collect(Collectors.toList());
} }
return List.of(); return List.of();
} }

View File

@ -20,47 +20,56 @@ import java.util.List;
@NoArgsConstructor @NoArgsConstructor
public class CompanyVO { public class CompanyVO {
@JsonSerialize(using = ToStringSerializer.class) @JsonSerialize(using = ToStringSerializer.class)
private Long id; private Long id;
private String code; private String code;
/**公司名称*/ /**
@NotBlank(message = "公司名称不能为空") * 公司名称
private String name; */
@NotBlank(message = "公司名称不能为空")
private String name;
private List<String> projectCodes; private List<String> projectCodes;
public CompanyVO(Org entity) { public CompanyVO(Org entity) {
this.id = entity.getId(); this.id = entity.getId();
this.code = entity.getCode(); this.code = entity.getCode();
this.name = entity.getName(); this.name = entity.getName();
if (StringUtils.hasText(entity.getProjectCode())) { if (StringUtils.hasText(entity.getProjectCode())) {
this.projectCodes = Arrays.asList(entity.getProjectCode().split(",")); this.projectCodes = Arrays.asList(entity.getProjectCode().split(","));
} }
} }
public static List<CompanyVO> convert2VOList(List<Org> dataList) { public static CompanyVO simpleInfoVO(Org entity) {
List<CompanyVO> voList = new ArrayList<>(); CompanyVO companyVO = new CompanyVO();
for (Org entity : dataList) { companyVO.setId(entity.getId());
voList.add(new CompanyVO(entity)); companyVO.setName(entity.getName());
} return companyVO;
return voList; }
}
public static List<CompanyVO> convert2VOList(List<Org> dataList) {
List<CompanyVO> voList = new ArrayList<>();
for (Org entity : dataList) {
voList.add(new CompanyVO(entity));
}
return voList;
}
public Org toDB() { public Org toDB() {
Org entity = new Org(); Org entity = new Org();
entity.setId(this.id); entity.setId(this.id);
entity.setName(this.name); entity.setName(this.name);
entity.setProjectCode(getDBProjectCode()); entity.setProjectCode(getDBProjectCode());
return entity; return entity;
} }
@JsonIgnore @JsonIgnore
public String getDBProjectCode() { public String getDBProjectCode() {
if (!CollectionUtils.isEmpty(projectCodes)) { if (!CollectionUtils.isEmpty(projectCodes)) {
return String.join(",", projectCodes); return String.join(",", projectCodes);
} else { } else {
return null; return null;
} }
} }
} }