/** * 查詢是否有權限 */ @GetMapping(API_PREFIX+"/getPermissionLogCount") @Override public Integer getPermissionLogCount(String openId ,@RequestParam(value = "tournamentId",required = false,defaultValue = "") String tournamentId ,@RequestParam(value = "applicationType",required = false,defaultValue = "") String applicationType) { return permissionLogService.count( new LambdaQueryWrapper<PermissionLog>()
//相當於 select count(id)PermissionLog from where getApplicantOpenid = openId and ((getRoleType = "SYSTEM") or (getRoleType = "TOURNAMENT") or (getTournamentId = tournamentId and getApplicationType = applicationType and getIsApproved = “Y” ))
.eq(org.springblade.competition.entity.PermissionLog::getApplicantOpenid, openId)
.and(
wrapper1 -> wrapper1.eq(org.springblade.competition.entity.PermissionLog::getRoleType,"SYSTEM") // 賽事創建者 .or(wrapper -> wrapper.eq(org.springblade.competition.entity.PermissionLog::getRoleType,"TOURNAMENT") .eq(org.springblade.competition.entity.PermissionLog::getTournamentId,tournamentId) ) // TOURNAMENT/ACCOUNT/ALBUM .or(w->w.eq(org.springblade.competition.entity.PermissionLog::getTournamentId,tournamentId) .eq (org.springblade.competition.entity.PermissionLog::getApplicationType, applicationType) .eq(org.springblade.competition.entity.PermissionLog::getIsApproved,"Y") ) ) ); }
復雜一點的單表 最好還是寫一條sql