当前正在与laravel进行Jira集成,任务是基于日期范围过滤器为项目生成时间记录报告,问题是一旦我应用了日期范围过滤器,刷新页面时总记录时间的值会不断变化,即使清除缓存后,值仍保持变化,无法理解它,当我尝试使用mysql查询浏览器时,同一查询的值保持不变。 下面是日期过滤器逻辑的代码,请查看并帮助我
// function in the controller
public function IssueLists($porject_name, Request $request)
{
$show_summary_table=0;
$summary_results =0;
$total_remaining_estimate_time = 0;
$developer_rate = DEVELOPER_RATE;
$set_daterange = false;
$interval_list = array(
'All time',
'This week',
'This month',
'This year',
'Last 3 months',
'Last 6 months',
'Last year'
);
$sortingFields = [
'orignal_estimate' => ['Orignal Estimated (hrs)', 'desc'],
'time_logged' => ['Total Hours Logged (hrs)', 'desc'],
'orignal_estimated_costs' => ['Original Estimate Cost', 'desc']
];
// check if we're sorting the table
$sortingField = $sortingDirection = null;
$interval_filter = Input::get('interval_filter');
$intfilters = 0;
if ($request->has('o') && $request->has('d')) {
$sortingField = $request->input('o');
$sortingDirection = $request->input('d');
$newD = ($request->input('d') == 'asc')? 'desc' : 'asc';
$sortingFields[$request->input('o')][1] = $newD;
}
$project_issues = $this->JiraIssuesService->getIssuesByProject($porject_name, $sortingField,$sortingDirection );
$jira_results = $project_issues;
// this date range is from the main page which is project list page searched with date range
$date_range=null;
if(isset($request['pjdate_range']))
{
$date_range = $request['pjdate_range'];
$set_daterange = true;
$jira_results = $this->JiraIssuesService->SearchIssuesByDateRange($porject_name, null,$date_range, $sortingField, $sortingDirection);
Redirect::back()->with('info', 'List of issues in '.$porject_name.'for the date range between '. $date_range);
}
else
{
Redirect::to('it_costs/Admin/issues_list')->with('info', 'List of issues in '.$porject_name );
}
$occupancyByDateRange = $dateRange = $interval = $action = false;
// Check interval_filter is set
if(isset($interval_filter) && $interval_filter!='all_time')
{
$intfilters=$interval_filter;
$project_issues = $this->JiraIssuesService->GetIssuesByIntervals($porject_name,$intfilters, $sortingField, $sortingDirection);
$jira_results = $project_issues;
}
if ($request->has('f.interval')) {
$interval = $request->input('f.interval');
}
if($request->input()!=null)
{
$input = $request->input();
if(isset($input[ 'f' ]['override_rate']))
{
$project_issues = $this->JiraIssuesService->getIssuesByProject($porject_name, $sortingField,$sortingDirection);
$jira_results = $project_issues;
$developer_rate = $input[ 'f' ]['dev_rate'];
Redirect::back()->with('info', 'List of issues in '.$porject_name .' @'.currency($developer_rate).'/hr');
}
// if the searched only with the label
if(isset($input[ 'f' ]['issue_label'])&& empty($input[ 'f' ]['project_name']) && empty($input[ 'f' ]['date_range']))
{
$label_search = $input[ 'f' ]['issue_label'];
$issues_by_label = $this->JiraIssuesService->getIssuesByLabel($label_search, $sortingField,$sortingDirection);
$total_remaining_estimate_time = $this->JiraIssuesService->getReaminingEstimateTime($issues_by_label);
$jira_results = $issues_by_label ;
$show_summary_table = 1;
$summary_results = $this->SummaryList($request);
// if the searched issues by status only
if(isset($input[ 'f' ]['status']) )
{
$show_summary_table = 0;
$status_search = $input[ 'f' ]['status'];
$issues_by_status = $this->JiraIssuesService->SearchIssuesByStatus($status_search,null,$label_search , $sortingField,$sortingDirection);
$jira_results =$issues_by_status ;
}
// check if the rate input is set or rate overridden
if(isset($input[ 'f' ]['override_rate']))
{
$developer_rate = $input[ 'f' ]['dev_rate'];
Redirect::back()->with('info', 'The search results for the Label '.$label_search .' @'.currency($developer_rate).'/hr');
}
else
{
Redirect::back()->with('info', 'The search results for the Label '.$label_search);
}
}
// if the searched only with the project name
if(isset($input[ 'f' ]['project_name']) && empty($input[ 'f' ]['issue_label']))
{
$project_search = $input[ 'f' ]['project_name'];
$issues_by_project = $this->JiraIssuesService->SearchIssuesByProject($project_search, $sortingField,$sortingDirection);
$jira_results = $issues_by_project ;
// if the searched issues by status only
if(isset($input[ 'f' ]['status']) )
{
$status_search = $input[ 'f' ]['status'];
$issues_by_status = $this->JiraIssuesService->SearchIssuesByStatus($status_search,$project_search,null , $sortingField,$sortingDirection);
$jira_results =$issues_by_status ;
}
if(isset($input[ 'f' ]['override_rate']))
{
$developer_rate = $input[ 'f' ]['dev_rate'];
Redirect::back()->with('info', 'The search results for '.$project_search .' @'.currency($developer_rate).'/hr');
}
else
{
Redirect::back()->with('info', 'The search results for '.$project_search );
}
}
// if the searched issues by status only
if(isset($input[ 'f' ]['status']) && empty($input[ 'f' ]['project_name']) && empty($input[ 'f' ]['issue_label']) )
{
$status_search = $input[ 'f' ]['status'];
$issues_by_status = $this->JiraIssuesService->SearchIssuesByStatus($status_search,null,null , $sortingField,$sortingDirection);
$jira_results =$issues_by_status ;
}
//if the seearch is performed with project and label name
if(isset($input[ 'f' ]['project_name']) && isset($input[ 'f' ]['issue_label']) )
{
$project_search = $input[ 'f' ]['project_name'];
$label_search = $input[ 'f' ]['issue_label'];
$issues_by_search = $this->JiraIssuesService->SearchIssues($project_search,$label_search);
$jira_results = $issues_by_search ;
if(isset($input[ 'f' ]['status']) )
{
$status_search = $input[ 'f' ]['status'];
$issues_by_status = $this->JiraIssuesService->SearchIssuesByStatus($status_search,$project_search,$label_search, $sortingField,$sortingDirection);
$jira_results =$issues_by_status ;
}
if(isset($input[ 'f' ]['override_rate']))
{
$developer_rate = $input[ 'f' ]['dev_rate'];
Redirect::back()->with('info', 'The search results for '.$project_search .' and ' . $label_search .' @ '.currency($developer_rate).'/hr');
}
else
{
Redirect::back()->with('info', 'The search results for '.$project_search .' and ' . $label_search );
}
}
// search for the date range and if other filters are searched along with the
// date range the below function will process it
if ($request->has('f.date_range'))
{
$dateRange = $request->input('f.date_range');
$set_daterange = true;
$issues_by_search = $this->JiraIssuesService->SearchIssuesByDateRange($porject_name, $input,null, $sortingField, $sortingDirection);
$jira_results= $issues_by_search;
Redirect::back()->with('info', 'List of issues for the date range between '. $dateRange);
}
}
return View::make( 'itcosts/issuelists',[
'search_filters' => $this->searchIssuesFields(),
'interval_list' => $interval_list,
'action' => $action,
'daterange' => $dateRange,
'pj_date_range'=>$date_range,
'project_name'=>$porject_name,
'show_summary_table'=>$show_summary_table,
'summary_results'=>$summary_results,
'developer_rate' =>$developer_rate,
'set_daterange' => $set_daterange,
'total_remaining_estimate'=>$total_remaining_estimate_time,
'rest_issues'=>$jira_results
]);
}
// Search issues with the adance filters
public function SearchIssuesByDateRange($project_name,$input=null,$pj_daterange=null,$sortingField=null,$sortingDirection=null)
{
$db_con = $this->JiraDbConnect();
// sorting
$order_by = "ORDER BY ji.ID DESC";
if ($sortingField && $sortingDirection) {
if($sortingField == 'orignal_estimated_costs') $sortingField = 'orignal_estimate';
if($sortingField == 'total_cost_incurred') $sortingField = 'time_logged';
if($sortingField == 'orignal_estimate') $sortingField = 'ji.TIMEORIGINALESTIMATE';
if($sortingField == 'time_logged') $sortingField = 'ji.TIMESPENT';
$order_by = "ORDER BY $sortingField $sortingDirection";
}
if(isset($input['f']['date_range']) || isset($pj_daterange))
{
if(!empty($input['f']['date_range']))
{
$date_range = explode("-", $input['f']['date_range']);
}
if(!empty($pj_daterange))
{
$date_range = explode("-", $pj_daterange);
}
$date_range_start = mydate_format($date_range[0], 'Y-m-d');
$date_range_end = mydate_format($date_range[1], 'Y-m-d');
$build_where_query = "pj.pname='".$project_name."'";
// check when project name filter is set
if(isset($input['f']['project_name']))
{
$pj_name = $input['f']['project_name'];
$build_where_query = "pj.pname='".$pj_name."'";
// check for other filters
if(isset($input['f']['issue_label']))
{
$label = $input['f']['issue_label'];
$build_where_query = "pj.pname='".$pj_name."'AND lb.LABEL='".$label."'";
}
if(isset($input[ 'f' ]['status']))
{
$status = $input[ 'f' ]['status'];
$build_where_query = "pj.pname='".$pj_name."'AND ji.issuestatus=".$status;
}
if(isset($input[ 'f' ]['status']) && isset($input['f']['issue_label']))
{
$build_where_query = "pj.pname='".$pj_name."'AND lb.LABEL='".$label."' AND ji.issuestatus=".$status;
}
}
// check if the label filter is set
if(isset($input['f']['issue_label']))
{
$label = $input['f']['issue_label'];
$build_where_query = "lb.LABEL='".$label."'";
if(isset($input['f']['project_name']))
{
$pj_name = $input['f']['project_name'];
$build_where_query = "pj.pname='".$pj_name."' AND lb.LABEL='".$label."'";
}
if(isset($input[ 'f' ]['status']))
{
$status = $input[ 'f' ]['status'];
$build_where_query = "lb.LABEL='".$label."' AND ji.issuestatus=".$status;
}
if(isset($input[ 'f' ]['status']) && isset($input['f']['project_name']))
{
$build_where_query = "pj.pname='".$pj_name."'AND lb.LABEL='".$label."' AND ji.issuestatus=".$status;
}
}
// check if the satus filter is set
if(isset($input[ 'f' ]['status']))
{
$status = $input['f']['status'];
$build_where_query = "ji.issuestatus='".$status."'";
if(isset($input['f']['project_name']))
{
$pj_name = $input['f']['project_name'];
$build_where_query = "pj.pname='".$pj_name."' AND ji.issuestatus=".$status; echo $build_where_query;
}
if(isset($input['f']['issue_label']))
{
$label = $input['f']['issue_label'];
$build_where_query = "lb.LABEL='".$label."' AND ji.issuestatus=".$status;
}
if(isset($input[ 'f' ]['issue_label']) && isset($input['f']['project_name']))
{
$build_where_query = "pj.pname='".$pj_name."'AND lb.LABEL='".$label."' AND ji.issuestatus=".$status;
}
}
$issues_list = $db_con->select("SELECT pj.pname, concat(pj.pkey, '-', ji.issuenum) as issue_key,ji.ID as issue_id,
DATE_FORMAT(ji.UPDATED, '%d-%m-%y') as updated_date,
DATE_FORMAT(ji.CREATED, '%d-%m-%y') as created_date,
GROUP_CONCAT(DISTINCT lb.LABEL) as issue_label,
ji.ASSIGNEE as assignee,
ji.SUMMARY as summary,
TIME_FORMAT(SEC_TO_TIME(ji.TIMEORIGINALESTIMATE),'%k:%i') as orignal_estimate,
TIME_FORMAT(SEC_TO_TIME(w.timeworked) ,'%k:%i') as time_logged,
isst.pname as status
FROM jiraissue ji
INNER JOIN project pj ON pj.ID = ji.PROJECT
INNER JOIN issuestatus isst ON ji.issuestatus=isst.ID
LEFT JOIN label lb on lb.ISSUE = ji.ID
LEFT JOIN worklog w on w.issueid = ji.ID
WHERE ($build_where_query AND (DATE(ji.CREATED) >= '".$date_range_start."' AND DATE(ji.CREATED) <= '".$date_range_end."'))
OR ($build_where_query AND (DATE(ji.UPDATED) >= '".$date_range_start."' AND DATE(ji.UPDATED) <= '".$date_range_end."'))
OR ($build_where_query AND ( DATE(w.CREATED) >= '".$date_range_start."' AND DATE(w.CREATED) <= '".$date_range_end."'))
OR ($build_where_query AND ( DATE(w.UPDATED) >= '".$date_range_start."' AND DATE(w.UPDATED) <= '".$date_range_end."'))
GROUP BY ji.ID $order_by "
);
}
return $issues_list;