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

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

View File

@ -1,9 +1,9 @@
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.ProjectView;
import club.joylink.rtss.vo.client.PageVO;
import club.joylink.rtss.vo.client.org.CompanyVO;
import club.joylink.rtss.vo.project.*;
import java.util.List;
@ -56,7 +56,7 @@ public interface ProjectService {
/**
* 根据项目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.SimulationExceptionType;
import club.joylink.rtss.vo.client.PageVO;
import club.joylink.rtss.vo.client.org.CompanyVO;
import club.joylink.rtss.vo.project.*;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
@ -142,7 +143,7 @@ public class ProjectServiceImpl implements ProjectService {
}
@Override
public List<Org> projectOrgList(Long id) {
public List<CompanyVO> projectOrgList(Long id) {
Project project = projectDAO.selectByPrimaryKey(id);
if (project == null) {
throw new SimulationException(SimulationExceptionType.Illegal_Argument, "项目不存在");
@ -150,7 +151,8 @@ public class ProjectServiceImpl implements ProjectService {
List<OrgProject> orgProjectList = getOrgProjectList(List.of(project.getCode()));
if (!CollectionUtils.isEmpty(orgProjectList)) {
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();
}

View File

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