更改内容
This commit is contained in:
parent
9b599993af
commit
be6b1e2e69
@ -149,6 +149,31 @@ class Year extends Api
|
||||
}
|
||||
$createtime = null; // 无记录时显示0
|
||||
}
|
||||
$total_score = 0;
|
||||
if (($scoringYears[$period]['hospital_score'] ?? 0) > 0) {
|
||||
|
||||
$scoringrecord_status = 4;
|
||||
// 获取该年总加分和减分的分值
|
||||
$zongjiafenfenzhi = Db::name('addition_and_subtraction_records')
|
||||
->where('user_id', $id)
|
||||
->where('YEAR(createtime)', $period)
|
||||
->where('status', 2)
|
||||
->where('assessment_type', 1)
|
||||
->sum('score_value');
|
||||
|
||||
$zongjianfenfenzhi = Db::name('addition_and_subtraction_records')
|
||||
->where('user_id', $id)
|
||||
->where('YEAR(createtime)', $period)
|
||||
->where('status', 2)
|
||||
->where('assessment_type', 2)
|
||||
->sum('score_value');
|
||||
|
||||
$total_score = $scoringYears[$period]['self_score'] * 0.2
|
||||
+ $scoringYears[$period]['department_score'] * 0.4
|
||||
+ $scoringYears[$period]['party_branch_score'] * 0.4
|
||||
+ $zongjiafenfenzhi
|
||||
- $zongjianfenfenzhi;
|
||||
}
|
||||
|
||||
$result[] = [
|
||||
'year' => $period,
|
||||
@ -158,13 +183,14 @@ class Year extends Api
|
||||
'minus_score' => $scoringYears[$period]['minus_score'] ?? '',
|
||||
'self_score' => $scoringYears[$period]['self_score'] ?? '',
|
||||
'department_score' => $scoringYears[$period]['department_score'] ?? '',
|
||||
'party_branch_score' => $scoringYears[$period]['party_branch_score'] ?? '',
|
||||
'overall_party_score' => $scoringYears[$period]['overall_party_score'] ?? '',
|
||||
'hospital_score' => $scoringYears[$period]['hospital_score'] ?? '',
|
||||
'party_branch_score' => $scoringYears[$period]['party_branch_score'] ?? '',
|
||||
'overall_party_score' => $scoringYears[$period]['overall_party_score'] ?? '',
|
||||
'hospital_score' => $scoringYears[$period]['hospital_score'] ?? '',
|
||||
'if' => isset($scoringYears[$period]) ? 2 : 1,
|
||||
'if_period' => $if_period,
|
||||
'year_range' => "{$period}-01至{$period}-12",
|
||||
'createtime' => $createtime,
|
||||
'total_score' => $total_score,
|
||||
];
|
||||
}
|
||||
|
||||
@ -261,6 +287,11 @@ class Year extends Api
|
||||
if (!empty($insertData)) {
|
||||
$result = Db::name('scoringrecord')->strict(false)->insertAll($insertData);
|
||||
if ($result) {
|
||||
$user = Db::name('user')->where('id', $user_id)->find();
|
||||
$group_id = $user['group_id'];
|
||||
$mail_user = Db::name('user')->where('group_id', $group_id)->where('auth_group_id',4)->find();
|
||||
$mail_user_id = $mail_user['id'];
|
||||
Mail::createMail($mail_user_id,'您的科室下有年度自评待审核人员');
|
||||
return $this->success('数据插入成功', $result);
|
||||
} else {
|
||||
return $this->error('数据插入失败');
|
||||
@ -472,19 +503,22 @@ class Year extends Api
|
||||
$evaluation_schedule_id = $this->request->post('evaluation_schedule_id');
|
||||
$page = $this->request->post('page',1);
|
||||
$size = $this->request->post('size',10);
|
||||
$scoringrecord_status = $this->request->post('scoringrecord_status');
|
||||
$where = [];
|
||||
if(!$groupId){
|
||||
return $this->error('参数错误');
|
||||
}
|
||||
|
||||
if($user_id){
|
||||
$where['id'] = $user_id;
|
||||
}
|
||||
$where['group_id'] = $groupId;
|
||||
// return $this->success('查询成功', $where);
|
||||
|
||||
$result = Db::name('user')
|
||||
->where($where)
|
||||
->page($page,$size)
|
||||
->select();
|
||||
|
||||
$count = Db::name('user')
|
||||
->where($where)
|
||||
->count();
|
||||
@ -883,4 +917,187 @@ class Year extends Api
|
||||
$sortedResult = $this->sortByMonthDescending($result);
|
||||
return $this->success('请求成功', $sortedResult);
|
||||
}
|
||||
|
||||
public function data()
|
||||
{
|
||||
$time = $this->request->post('time', date('Y'));
|
||||
$group_id = $this->request->post('group_id');
|
||||
|
||||
// 统计总人数(添加时间筛选和分组)
|
||||
$totalUsers = Db::name('user')
|
||||
// ->where('year', $time)
|
||||
->where('group_id', $group_id)
|
||||
->count();
|
||||
|
||||
// 统计已考评人数(添加时间筛选和分组)
|
||||
$evaluatedUsers = Db::name('scoringrecord')
|
||||
// ->where('year', $time)
|
||||
->where('group_id', $group_id)
|
||||
->field('COUNT(DISTINCT user_id) as total')
|
||||
->find()['total'];
|
||||
|
||||
// 构建带筛选条件的复杂SQL
|
||||
$sql = "SELECT
|
||||
COUNT(*) AS total,
|
||||
SUM(CASE WHEN total_score >= 90 THEN 1 ELSE 0 END) AS excellent,
|
||||
SUM(CASE WHEN total_score >= 60 AND total_score < 90 THEN 1 ELSE 0 END) AS qualified,
|
||||
SUM(CASE WHEN total_score < 60 THEN 1 ELSE 0 END) AS unqualified
|
||||
FROM (
|
||||
SELECT
|
||||
u.id,
|
||||
COALESCE(
|
||||
(SUM(CASE WHEN sr.type = 1 THEN sr.self_score ELSE 0 END) * 0.2) +
|
||||
(SUM(CASE WHEN sr.type = 1 THEN sr.department_score ELSE 0 END) * 0.4) +
|
||||
(SUM(CASE WHEN sr.type = 1 THEN sr.party_branch_score ELSE 0 END) * 0.4) +
|
||||
SUM(CASE WHEN sr.type = 2 THEN sr.value ELSE 0 END),
|
||||
0) AS total_score
|
||||
FROM lr_user u
|
||||
LEFT JOIN lr_scoringrecord sr ON u.id = sr.user_id
|
||||
WHERE sr.term = :time AND sr.group_id = :group_id -- 添加筛选条件
|
||||
GROUP BY u.id
|
||||
) AS score_table";
|
||||
|
||||
// 使用参数绑定防止SQL注入
|
||||
$result = Db::query($sql, [
|
||||
'time' => $time,
|
||||
'group_id' => $group_id
|
||||
]);
|
||||
|
||||
// 计算比率(添加空值保护)
|
||||
$excellentRate = $totalUsers > 0 ? round(($result[0]['excellent'] ?? 0) / $totalUsers * 100, 2) : 0;
|
||||
$qualifiedRate = $totalUsers > 0 ? round(($result[0]['qualified'] ?? 0) / $totalUsers * 100, 2) : 0;
|
||||
$unqualifiedRate = $totalUsers > 0 ? round(($result[0]['unqualified'] ?? 0) / $totalUsers * 100, 2) : 0;
|
||||
|
||||
// 返回统计结果
|
||||
$res = [
|
||||
'total' => $totalUsers,
|
||||
'evaluated' => $evaluatedUsers,
|
||||
'unevaluated' => $totalUsers > 0 ? ($totalUsers - $evaluatedUsers) : 0, // 添加保护
|
||||
'excellent' => $result[0]['excellent'] ?? 0,
|
||||
'excellent_rate' => $excellentRate . '%',
|
||||
'qualified' => $result[0]['qualified'] ?? 0,
|
||||
'qualified_rate' => $qualifiedRate . '%',
|
||||
'unqualified' => $result[0]['unqualified'] ?? 0,
|
||||
'unqualified_rate' => $unqualifiedRate . '%'
|
||||
];
|
||||
|
||||
return $this->success('请求成功', $res);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// $time = $this->request->post('time', date('Y'));
|
||||
// $evaluation_schedule_id = $this->request->post('evaluation_schedule_id');
|
||||
|
||||
// // 统计总人数
|
||||
// $totalUsers = Db::name('user')->count();
|
||||
// return $this->success('统计完成', $totalUsers);
|
||||
// // 获取所有需要统计的用户列表
|
||||
// $users = Db::name('user')
|
||||
// ->where($where)
|
||||
// ->field('id,group_id,username')
|
||||
// ->select();
|
||||
|
||||
// $statistics = [
|
||||
// 'total' => $totalUsers,
|
||||
// 'evaluated' => 0,
|
||||
// 'unevaluated' => 0,
|
||||
// 'excellent' => 0,
|
||||
// 'good' => 0,
|
||||
// 'unqualified' => 0,
|
||||
// 'excellent_rate' => 0,
|
||||
// 'good_rate' => 0,
|
||||
// 'unqualified_rate' => 0
|
||||
// ];
|
||||
|
||||
// // 评分统计标准(需要根据实际业务调整阈值)
|
||||
// $scoreThresholds = [
|
||||
// 'excellent' => 90, // 优秀阈值
|
||||
// 'good' => 60, // 合格阈值
|
||||
// 'unqualified' => 0 // 不合格阈值
|
||||
// ];
|
||||
|
||||
// foreach ($users as &$user) {
|
||||
// // 获取用户评分记录
|
||||
// $scoringRecords = Db::name('scoringrecord')
|
||||
// ->where('user_id', $user['id'])
|
||||
// ->where($where)
|
||||
// ->select();
|
||||
|
||||
// // 获取用户加减分记录
|
||||
// $additionSubtraction = Db::name('addition_and_subtraction_records')
|
||||
// ->where('user_id', $user['id'])
|
||||
// ->where('YEAR(createtime)', $time)
|
||||
// ->where('status', 1) // 假设1为有效状态
|
||||
// ->sum('value');
|
||||
|
||||
// if (empty($scoringRecords)) {
|
||||
// $statistics['unevaluated']++;
|
||||
// continue;
|
||||
// }
|
||||
|
||||
// $statistics['evaluated']++;
|
||||
|
||||
// // 计算总分
|
||||
// $totalScore = 0;
|
||||
// foreach ($scoringRecords as $record) {
|
||||
// $totalScore += (
|
||||
// $record['self_score'] * 0.2 +
|
||||
// $record['department_score'] * 0.4 +
|
||||
// $record['party_branch_score'] * 0.4
|
||||
// );
|
||||
// }
|
||||
|
||||
// // 加上加减分项
|
||||
// $totalScore += $additionSubtraction ?: 0;
|
||||
|
||||
// // 统计分类
|
||||
// if ($totalScore >= $scoreThresholds['excellent']) {
|
||||
// $statistics['excellent']++;
|
||||
// } elseif ($totalScore >= $scoreThresholds['good']) {
|
||||
// $statistics['good']++;
|
||||
// } else {
|
||||
// $statistics['unqualified']++;
|
||||
// }
|
||||
// }
|
||||
|
||||
// // 计算比率
|
||||
// $totalEvaluated = $statistics['evaluated'];
|
||||
// if ($totalEvaluated > 0) {
|
||||
// $statistics['excellent_rate'] = round($statistics['excellent'] / $totalEvaluated * 100, 2);
|
||||
// $statistics['good_rate'] = round($statistics['good'] / $totalEvaluated * 100, 2);
|
||||
// $statistics['unqualified_rate'] = round($statistics['unqualified'] / $totalEvaluated * 100, 2);
|
||||
// }
|
||||
|
||||
// // 补充用户分组信息
|
||||
// $groupIds = array_column($users, 'group_id');
|
||||
// $groups = Db::name('user_group')->where('id', 'in', $groupIds)->column('id,name', 'id');
|
||||
|
||||
// foreach ($users as &$user) {
|
||||
// $user['group_name'] = $groups[$user['group_id']] ?? '未分组';
|
||||
// }
|
||||
|
||||
// return $this->success('统计完成', [
|
||||
// 'statistics' => $statistics,
|
||||
// 'users' => $users
|
||||
// ]);
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user