zhuyifan

fix

......@@ -70,6 +70,7 @@ public class LoginInterceptor implements HandlerInterceptor {
StpUtil.checkLogin();
final var enterpriseId = Convert.toInt(StpUtil.getExtra(CommonConstants.ENTERPRISE_ID));
final var loginSource = Convert.toInt(StpUtil.getExtra(CommonConstants.LOGIN_SOURCE));
final var userId = StpUtil.getExtra(CommonConstants.USER_ID);
if (loginSource.equals(LoginSourceEnum.CUSTOMER.getValue())) {
final var openId = Convert.toStr(StpUtil.getExtra(CommonConstants.OPEN_ID));
final var loginId = StpUtil.getLoginIdAsInt();
......@@ -115,8 +116,7 @@ public class LoginInterceptor implements HandlerInterceptor {
builder.id(loginId).enterpriseId(enterpriseId).name(operator.getName()).loginSource(LoginSourceEnum.KDS);
return true;
} else {
final var loginId = StpUtil.getLoginIdAsString();
builder.openId(loginId).enterpriseId(enterpriseId).loginSource(LoginSourceEnum.MINI_PROGRAM);
builder.id(userId == null ? null : Convert.toInt(userId)).openId(StpUtil.getLoginIdAsString()).enterpriseId(enterpriseId).loginSource(LoginSourceEnum.MINI_PROGRAM);
return true;
}
}
......
......@@ -75,7 +75,7 @@ public class ResourceInjector implements HandlerInterceptor {
log.info("Resource not found; id:{}", id);
throw ClientEndExceptions.ResourceNotFound.build("项目点不存在");
}
httpServletRequest.setAttribute(PathVariableResourceConstants.INJECTED_CLIENT, response);
httpServletRequest.setAttribute(PathVariableResourceConstants.INJECTED_CLIENT, response.getClient());
}
/*
......
......@@ -55,6 +55,9 @@ public class DinerDTO {
@NotNull(message = "班级不能为空")
private Integer classId;
@ApiModelProperty(value = "学号")
private String studentNo;
@ApiModelProperty(value = "姓名")
private String name;
}
......
......@@ -123,6 +123,9 @@ public class MealOrderServiceRpcClient {
}
public List<SingleDinerRpcResponse> getDinersByIds(int enterpriseId, List<Integer> dinerIds) {
if (CollectionUtils.isEmpty(dinerIds)) {
return Collections.emptyList();
}
return mealOrderServiceRpcBlockingStub.getDinersByIds(GetDinersByIdsRpcRequest.newBuilder()
.setEnterpriseId(enterpriseId)
.addAllIds(dinerIds)
......@@ -148,6 +151,9 @@ public class MealOrderServiceRpcClient {
}
public List<SingleGradeClassRpcResponse> getGradeClassesByIds(int enterpriseId, List<Integer> gradeClassIds) {
if (CollectionUtils.isEmpty(gradeClassIds)) {
return Collections.emptyList();
}
return mealOrderServiceRpcBlockingStub.getGradeClassesByIds(GetGradeClassesByIdsRpcRequest.newBuilder()
.setEnterpriseId(enterpriseId)
.addAllIds(gradeClassIds)
......@@ -167,6 +173,9 @@ public class MealOrderServiceRpcClient {
}
public List<SingleMealOrderRpcResponse> queryReserveMealOrdersByDinerIds(int enterpriseId, List<Integer> dinerIds) {
if (CollectionUtils.isEmpty(dinerIds)) {
return Collections.emptyList();
}
return mealOrderServiceRpcBlockingStub.queryReserveMealOrdersByDinerIds(QueryReserveMealOrdersByDinerIdsRpcRequest.newBuilder()
.setEnterpriseId(enterpriseId)
.addAllDinerIds(dinerIds)
......@@ -201,6 +210,9 @@ public class MealOrderServiceRpcClient {
}
public boolean deleteMpAccountDinerRefsByIds(int enterpriseId, List<Integer> ids) {
if (CollectionUtils.isEmpty(ids)) {
return false;
}
return mealOrderServiceRpcBlockingStub.deleteMpAccountDinerRefsByIds(DeleteMpAccountDinerRefsByIdsRpcRequest.newBuilder()
.setEnterpriseId(enterpriseId)
.addAllIds(ids)
......@@ -215,6 +227,9 @@ public class MealOrderServiceRpcClient {
}
public List<SingleMealMenuRecordRpcResponse> queryLatestMealMenuRecordsByClientIds(int enterpriseId, List<Integer> ids) {
if (CollectionUtils.isEmpty(ids)) {
return Collections.emptyList();
}
return mealOrderServiceRpcBlockingStub.queryLatestMealMenuRecordsByClientIds(QueryLatestMealMenuRecordsByClientIdsRpcRequest.newBuilder()
.setEnterpriseId(enterpriseId)
.addAllClientId(ids)
......@@ -255,8 +270,8 @@ public class MealOrderServiceRpcClient {
return mealOrderServiceRpcBlockingStub.queryMealOrdersByCondition(QueryMealOrdersByConditionRpcRequest.newBuilder()
.setEnterpriseId(enterpriseId)
.setShouldFilterAccountIds(accountId != null).addAccountIds(accountId == null ? 0 : accountId)
.setShouldFilterReserveDateStart(true).setReserveDateStart(reserveDateStart == null ? 0 : reserveDateStart)
.setShouldFilterReserveDateEnd(true).setReserveDateEnd(reserveDateEnd == null ? 0 : reserveDateEnd)
.setShouldFilterReserveDateStart(reserveDateStart != null).setReserveDateStart(reserveDateStart == null ? 0 : reserveDateStart)
.setShouldFilterReserveDateEnd(reserveDateEnd != null).setReserveDateEnd(reserveDateEnd == null ? 0 : reserveDateEnd)
.build()).getResponsesList();
}
}
......
......@@ -116,11 +116,11 @@ public class DinerServiceImpl implements DinerService {
throw ClientEndExceptions.IncorrectRequestValue.build(ErrorCodeEnum.CLIENT_CODE_NOT_EXISTS);
}
final var singleClientRpcResponse = clientsByCodes.get(0);
if (diner.getClientId() == singleClientRpcResponse.getId() && diner.getClassId() == updateDinerDTO.getClassId() && !diner.getName().equals(updateDinerDTO.getName())) {
if (diner.getClientId() == singleClientRpcResponse.getId() && diner.getClassId() == updateDinerDTO.getClassId() && diner.getStudentNo().equals(updateDinerDTO.getStudentNo()) && !diner.getName().equals(updateDinerDTO.getName())) {
mealOrderServiceRpcClient.updateDiner(loginInfo, DinerModification.newBuilder().setId(diner.getId()).setShouldUpdateName(true).setName(updateDinerDTO.getName()).build());
return;
}
final var diners = mealOrderServiceRpcClient.queryDinersByCondition(loginInfo.getEnterpriseId(), List.of(singleClientRpcResponse.getId()), List.of(updateDinerDTO.getClassId()), diner.getStudentNo());
final var diners = mealOrderServiceRpcClient.queryDinersByCondition(loginInfo.getEnterpriseId(), List.of(singleClientRpcResponse.getId()), List.of(updateDinerDTO.getClassId()), updateDinerDTO.getStudentNo());
if (!diners.isEmpty()) {
throw ClientEndExceptions.IncorrectRequestValue.build(ErrorCodeEnum.DINER_ALREADY_EXISTS);
}
......@@ -129,6 +129,7 @@ public class DinerServiceImpl implements DinerService {
.setShouldUpdateClientId(true).setClientId(singleClientRpcResponse.getId())
.setShouldUpdateClassId(updateDinerDTO.getClassId() != null).setClassId(updateDinerDTO.getClassId() == null ? diner.getClassId() : updateDinerDTO.getClassId())
.setShouldUpdateName(updateDinerDTO.getName() != null).setName(updateDinerDTO.getName() == null ? diner.getName() : updateDinerDTO.getName())
.setShouldUpdateStudentNo(updateDinerDTO.getStudentNo() != null).setStudentNo(updateDinerDTO.getStudentNo() == null ? diner.getStudentNo() : updateDinerDTO.getStudentNo())
.build());
}
......
......@@ -66,9 +66,10 @@ public class LoginServiceImpl implements LoginService {
} else {
mpAccountId = mpAccountByOpenId.getId();
}
Assert.isTrue(mpAccountId == 0, "创建小程序账号失败");
StpUtil.login(mpAccountId, SaLoginModel.create()
Assert.isTrue(mpAccountId != 0, "创建小程序账号失败");
StpUtil.login(loginDto.getOpenId(), SaLoginModel.create()
.setExtra(CommonConstants.ENTERPRISE_ID, loginDto.getEnterpriseId())
.setExtra(CommonConstants.USER_ID, mpAccountId)
.setExtra(CommonConstants.LOGIN_SOURCE, loginDto.getLoginSourceEnum().getValue())
.build());
return StpUtil.getTokenInfo();
......
......@@ -41,14 +41,15 @@ public class MealOrderServiceImpl implements MealOrderService {
final var loginInfo = LoginContextHolder.getLoginInfo();
var mealOrderRpcResponses = mealOrderServiceRpcClient.queryMealOrdersByCondition(loginInfo.getEnterpriseId(), loginInfo.getId(), null, null);
final var today = LocalDate.now();
final var startTimestamp = today.with(DayOfWeek.MONDAY).atStartOfDay().atZone(DateUtil.CHINA_ZONE).toInstant().toEpochMilli();
final var endTimestamp = today.with(DayOfWeek.SUNDAY).atTime(LocalTime.MAX).atZone(DateUtil.CHINA_ZONE).toInstant().toEpochMilli();
final var lastWeekStart = today.minusWeeks(1).with(DayOfWeek.MONDAY).atStartOfDay().atZone(DateUtil.CHINA_ZONE).toInstant().toEpochMilli();
final var lastWeekEnd = today.minusWeeks(1).with(DayOfWeek.SUNDAY).atTime(LocalTime.MAX).atZone(DateUtil.CHINA_ZONE).toInstant().toEpochMilli();
final var thisWeekStart = today.with(DayOfWeek.MONDAY).atStartOfDay().atZone(DateUtil.CHINA_ZONE).toInstant().toEpochMilli();
if (queryMealOrderDTO.getStatus() == QueryMealOrderStatusEnum.COMPLETED) {
mealOrderRpcResponses = mealOrderRpcResponses.stream().filter(e -> e.getReserveDate() < startTimestamp).toList();
mealOrderRpcResponses = mealOrderRpcResponses.stream().filter(e -> e.getReserveDate() < lastWeekStart).toList();
} else if (queryMealOrderDTO.getStatus() == QueryMealOrderStatusEnum.UNDER_WAY) {
mealOrderRpcResponses = mealOrderRpcResponses.stream().filter(e -> e.getReserveDate() >= startTimestamp && e.getReserveDate() <= endTimestamp).toList();
mealOrderRpcResponses = mealOrderRpcResponses.stream().filter(e -> e.getReserveDate() >= lastWeekStart && e.getReserveDate() <= lastWeekEnd).toList();
} else if (queryMealOrderDTO.getStatus() == QueryMealOrderStatusEnum.BE_BOOKED) {
mealOrderRpcResponses = mealOrderRpcResponses.stream().filter(e -> e.getReserveDate() > endTimestamp).toList();
mealOrderRpcResponses = mealOrderRpcResponses.stream().filter(e -> e.getReserveDate() > thisWeekStart).toList();
}
return mealOrderRpcResponses.stream().map(this::getMealOrderById).toList();
}
......