|
@@ -15,9 +15,7 @@ import com.ym.mec.biz.service.SysUserContractsService;
|
|
|
import com.ym.mec.common.controller.BaseController;
|
|
|
import com.ym.mec.common.entity.HttpResponseResult;
|
|
|
|
|
|
-import java.util.Comparator;
|
|
|
-import java.util.List;
|
|
|
-import java.util.Objects;
|
|
|
+import java.util.*;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
@RequestMapping("sysUserContracts")
|
|
@@ -31,27 +29,24 @@ public class SysUserContractsController extends BaseController {
|
|
|
@ApiOperation(value = "查询学生最新协议")
|
|
|
@GetMapping("/getLatest")
|
|
|
@PreAuthorize("@pcs.hasPermissions('sysUserContracts/getLatest')")
|
|
|
- public HttpResponseResult<SysUserContracts> getLatest(Integer userId, Integer version) {
|
|
|
+ public HttpResponseResult<List<SysUserContracts>> getLatest(Integer userId) {
|
|
|
|
|
|
// SysUserContracts sysUserContracts = sysUserContractsService.getLatestUserContract(userId);
|
|
|
List<SysUserContracts> sysUserContracts = sysUserContractsService.getUserAllContracts(userId);
|
|
|
- if(Objects.isNull(version)){
|
|
|
- version = 2;
|
|
|
- }
|
|
|
|
|
|
if(CollectionUtils.isEmpty(sysUserContracts)){
|
|
|
return failed("该学员尚未签署协议");
|
|
|
}
|
|
|
|
|
|
- Integer finalVersion = version;
|
|
|
- List<SysUserContracts> versionContracts = sysUserContracts.stream().filter(c -> c.getVersion().equals(finalVersion)).collect(Collectors.toList());
|
|
|
+ Map<Integer, List<SysUserContracts>> versionContractMap = sysUserContracts.stream().collect(Collectors.groupingBy(SysUserContracts::getVersion));
|
|
|
|
|
|
- if(CollectionUtils.isEmpty(versionContracts)){
|
|
|
- return failed("该学员尚未签署协议");
|
|
|
+ List<SysUserContracts> result = new ArrayList<>();
|
|
|
+ for (Map.Entry<Integer, List<SysUserContracts>> versionContractMapEntry : versionContractMap.entrySet()) {
|
|
|
+ versionContractMapEntry.getValue().sort(Comparator.comparing(SysUserContracts::getCreateTime).reversed());
|
|
|
+ result.add(versionContractMapEntry.getValue().get(0));
|
|
|
}
|
|
|
|
|
|
- versionContracts.sort(Comparator.comparing(SysUserContracts::getCreateTime).reversed());
|
|
|
- return succeed(versionContracts.get(0));
|
|
|
+ return succeed(result);
|
|
|
}
|
|
|
|
|
|
}
|