diff --git a/integration-test/src/test/resources/third-project-person-api.http b/integration-test/src/test/resources/third-project-person-api.http new file mode 100644 index 0000000..458db63 --- /dev/null +++ b/integration-test/src/test/resources/third-project-person-api.http @@ -0,0 +1,12 @@ +### +POST localhost:8080/api/thirdPart/listProjectPeople +Accept: application/json +Content-Type: application/json +Authorization: Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJsb2dpblR5cGUiOiJsb2dpbiIsImxvZ2luSWQiOiJOVF9PTVNfV0VCOjkwMDA0MDAzMjIiLCJyblN0ciI6IndWbXF6d1VYWG5sZ2lHRm1MRmpHVXdzdGVac0xrbkpnIn0.fapfkozDj51dA2lFmCmIkv7ZFaLVOFGzn6OAyvndW1c + +{ + "thirdCode": "taizhou", + "thirdProjectId": "Jh0Cj4e%2BJhtDDYYdhmkV0flbxjUPOZXzS4z%2BAXKMf%2B8=", + "thirdUniquePersonIds": [], + "needThirdPerson": true +} diff --git a/riven-api/src/main/java/cn/axzo/riven/client/feign/ThirdPartPersonApi.java b/riven-api/src/main/java/cn/axzo/riven/client/feign/ThirdPartPersonApi.java index 9318341..7ecd89f 100644 --- a/riven-api/src/main/java/cn/axzo/riven/client/feign/ThirdPartPersonApi.java +++ b/riven-api/src/main/java/cn/axzo/riven/client/feign/ThirdPartPersonApi.java @@ -12,8 +12,10 @@ import lombok.NoArgsConstructor; import org.springframework.cloud.openfeign.FeignClient; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestParam; +import javax.validation.Valid; import java.util.List; import java.util.Set; @@ -40,6 +42,6 @@ public interface ThirdPartPersonApi { * @param param * @return */ - @PostMapping("/api/thirdPart/listPerson") - ApiResult> listThirdProjectPeople(ListThirdProjectPeopleReq param); + @PostMapping("/api/thirdPart/listProjectPeople") + ApiResult> listThirdProjectPeople(@RequestBody @Valid ListThirdProjectPeopleReq param); } diff --git a/riven-api/src/main/java/cn/axzo/riven/client/req/ListThirdProjectPeopleReq.java b/riven-api/src/main/java/cn/axzo/riven/client/req/ListThirdProjectPeopleReq.java index 11d2ef5..8951831 100644 --- a/riven-api/src/main/java/cn/axzo/riven/client/req/ListThirdProjectPeopleReq.java +++ b/riven-api/src/main/java/cn/axzo/riven/client/req/ListThirdProjectPeopleReq.java @@ -5,6 +5,7 @@ import lombok.Builder; import lombok.Data; import lombok.NoArgsConstructor; +import javax.validation.constraints.NotBlank; import java.io.Serializable; import java.util.Set; @@ -17,10 +18,12 @@ public class ListThirdProjectPeopleReq implements Serializable { /** * 三方名称code */ + @NotBlank(message = "thirdCode不能为空") private String thirdCode; /** * '三方项目编号' */ + @NotBlank(message = "thirdProjectId不能为空") private String thirdProjectId; /** * 三方人员唯一ID diff --git a/riven-third/src/main/java/cn/axzo/riven/third/controller/ThirdPartPersonController.java b/riven-third/src/main/java/cn/axzo/riven/third/controller/ThirdPartPersonController.java index e8c7ae5..8784df3 100644 --- a/riven-third/src/main/java/cn/axzo/riven/third/controller/ThirdPartPersonController.java +++ b/riven-third/src/main/java/cn/axzo/riven/third/controller/ThirdPartPersonController.java @@ -1,18 +1,30 @@ package cn.axzo.riven.third.controller; +import cn.axzo.basics.common.constant.enums.TableIsDeleteEnum; import cn.axzo.framework.domain.web.result.ApiResult; import cn.axzo.riven.client.common.enums.ThirdCodeEnum; import cn.axzo.riven.client.feign.ThirdPartPersonApi; import cn.axzo.riven.client.req.ListThirdProjectPeopleReq; import cn.axzo.riven.client.res.ThirdPartPersonRes; +import cn.axzo.riven.client.res.ThirdPersonRes; import cn.axzo.riven.client.res.ThirdProjectPersonRes; +import cn.axzo.riven.third.dao.ThirdPersonDao; +import cn.axzo.riven.third.dao.ThirdProjectPersonDao; +import cn.axzo.riven.third.entity.ThirdPerson; +import cn.axzo.riven.third.entity.ThirdProjectPerson; import cn.axzo.riven.third.service.ThirdPersonService; -import com.google.common.collect.ImmutableList; +import cn.hutool.core.bean.BeanUtil; +import cn.hutool.core.collection.CollUtil; +import cn.hutool.core.util.BooleanUtil; +import cn.hutool.core.util.StrUtil; import lombok.RequiredArgsConstructor; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.RestController; import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.function.Function; +import java.util.stream.Collectors; /** * @author zhongpeng @@ -23,18 +35,54 @@ import java.util.List; public class ThirdPartPersonController implements ThirdPartPersonApi { private final ThirdPersonService thirdPersonService; + private final ThirdProjectPersonDao thirdProjectPersonDao; + private final ThirdPersonDao thirdPersonDao; @Override public ApiResult getThirdPartPerson(Long personId, ThirdCodeEnum thirdCode) { - ThirdPartPersonRes thirdPartPersonRes = thirdPersonService.getThirdPartPerson(personId,thirdCode); + ThirdPartPersonRes thirdPartPersonRes = thirdPersonService.getThirdPartPerson(personId, thirdCode); return ApiResult.ok(thirdPartPersonRes); } @Override public ApiResult> listThirdProjectPeople(ListThirdProjectPeopleReq param) { - // TODO - return ApiResult.ok(ImmutableList.of()); + List result = thirdProjectPersonDao.lambdaQuery() + .eq(ThirdProjectPerson::getThirdCode, param.getThirdCode()) + .eq(ThirdProjectPerson::getThirdProjectId, param.getThirdProjectId()) + .in(CollUtil.isNotEmpty(param.getThirdUniquePersonIds()), ThirdProjectPerson::getThirdUniquePersonId, param.getThirdUniquePersonIds()) + .eq(ThirdProjectPerson::getIsDelete, TableIsDeleteEnum.NORMAL.value) + .list() + .stream().map(e -> BeanUtil.toBean(e, ThirdProjectPersonRes.class)) + .collect(Collectors.toList()); + assembleThirdPersonIfNeed(result, param); + return ApiResult.ok(result); + } + + private void assembleThirdPersonIfNeed(List result, ListThirdProjectPeopleReq param) { + if (result.isEmpty()) { + return; + } + if (!BooleanUtil.isTrue(param.getNeedThirdPerson())) { + return; + } + Set thirdPersonIds = result.stream() + .map(ThirdProjectPersonRes::getThirdUniquePersonId) + .filter(StrUtil::isNotBlank) + .collect(Collectors.toSet()); + if (thirdPersonIds.isEmpty()) { + return; + } + Map thirdPersonMap = thirdPersonDao.lambdaQuery() + .eq(ThirdPerson::getThirdCode, param.getThirdCode()) + .in(ThirdPerson::getThirdUniquePersonId, thirdPersonIds) + .eq(ThirdPerson::getIsDelete, TableIsDeleteEnum.NORMAL.value) + .list().stream() + .collect(Collectors.toMap(ThirdPerson::getThirdUniquePersonId, Function.identity())); + result.forEach(t -> { + ThirdPerson thirdPerson = thirdPersonMap.get(t.getThirdUniquePersonId()); + t.setThirdPersonRes(thirdPerson == null ? null : BeanUtil.toBean(thirdPerson, ThirdPersonRes.class)); + }); } }