|
|
@@ -427,6 +427,340 @@ class Decision extends Api
|
|
|
* @throws \think\db\exception\ModelNotFoundException
|
|
|
* @throws \think\exception\DbException
|
|
|
*/
|
|
|
+// public function ProcessOutputRate()
|
|
|
+// {
|
|
|
+// if ($this->request->isGet() === false){
|
|
|
+// $this->error('请求错误');
|
|
|
+// }
|
|
|
+// $param = $this->request->param();
|
|
|
+// if (empty($param)){
|
|
|
+// $this->error('参数错误');
|
|
|
+// }
|
|
|
+// //查询已经进入超节损的月份
|
|
|
+// $mouth = \db('工单_质量考核汇总')
|
|
|
+// ->where('sys_ny','like',$param['year'].'%')
|
|
|
+// ->column('distinct(sys_ny) as mouth');
|
|
|
+// //创建工序数组
|
|
|
+// $processType = ['胶印','卷凹','圆烫','圆切','烫金','模切','丝印','喷码','单凹'];
|
|
|
+// $result = $data = [];
|
|
|
+// foreach ($mouth as $key=>$value){
|
|
|
+// foreach ($processType as $item){
|
|
|
+// //查询进入超节损一年内所有数据
|
|
|
+// $list = \db('工单_质量考核汇总')
|
|
|
+// ->alias('a')
|
|
|
+// ->join('工单_工艺资料 b','a.Gy0_gdbh = b.Gy0_gdbh AND a.印件及工序 = b.Gy0_yjno AND a.工序 = b.Gy0_gxh')
|
|
|
+// ->join('工单_印件资料 c','a.Gy0_gdbh = c.Yj_Gdbh AND a.印件及工序 = c.yj_Yjno')
|
|
|
+// ->field('a.sys_ny,((sum(a.班组制程废品)/a.联数)+(sum(a.班组质检废品)/a.联数))/a.印件工序产量 as 废品率')
|
|
|
+// ->where('b.Gy0_gxmc','like',$item.'%')
|
|
|
+// ->where('a.sys_ny',$value)
|
|
|
+// ->group('a.Gy0_gdbh,b.Gy0_yjno,a.工序')
|
|
|
+// ->select();
|
|
|
+// $data[$value][$item] = $list;
|
|
|
+// }
|
|
|
+// }
|
|
|
+// $months = [
|
|
|
+// $param['year'].'01' => '01月',
|
|
|
+// $param['year'].'02' => '02月',
|
|
|
+// $param['year'].'03' => '03月',
|
|
|
+// $param['year'].'04' => '04月',
|
|
|
+// $param['year'].'05' => '05月',
|
|
|
+// $param['year'].'06' => '06月',
|
|
|
+// $param['year'].'07' => '07月',
|
|
|
+// $param['year'].'08' => '08月',
|
|
|
+// $param['year'].'09' => '09月',
|
|
|
+// $param['year'].'10' => '10月',
|
|
|
+// $param['year'].'11' => '11月',
|
|
|
+// $param['year'].'12' => '12月'
|
|
|
+// ];
|
|
|
+// //汇总数据
|
|
|
+// foreach ($processType as $index => $process) {
|
|
|
+// $result[$index] = array(
|
|
|
+// "工序类型" => $process,
|
|
|
+// "01月" => "",
|
|
|
+// "02月" => "",
|
|
|
+// "03月" => "",
|
|
|
+// "04月" => "",
|
|
|
+// "05月" => "",
|
|
|
+// "06月" => "",
|
|
|
+// "07月" => "",
|
|
|
+// "08月" => "",
|
|
|
+// "09月" => "",
|
|
|
+// "10月" => "",
|
|
|
+// "11月" => "",
|
|
|
+// "12月" => ""
|
|
|
+// );
|
|
|
+//
|
|
|
+// // 遍历月份
|
|
|
+// foreach ($months as $month => $monthName) {
|
|
|
+// if (isset($data[$month])){
|
|
|
+// $count = count($data[$month][$process]);
|
|
|
+// }
|
|
|
+//
|
|
|
+// $totalRate = 0;
|
|
|
+//
|
|
|
+// // 检查月份是否存在于数据中
|
|
|
+// if (isset($data[$month])) {
|
|
|
+// // 检查工序是否存在于月份数据中
|
|
|
+// if (isset($data[$month][$process])) {
|
|
|
+// // 累加废品率
|
|
|
+// foreach ($data[$month][$process] as $rate) {
|
|
|
+// $totalRate += floatval(1-$rate["废品率"]);
|
|
|
+// }
|
|
|
+// }
|
|
|
+// }
|
|
|
+// if ($count > 0){
|
|
|
+// $rateNumber = $totalRate/$count;
|
|
|
+// }
|
|
|
+// // 格式化为百分比字符串,保留两位小数
|
|
|
+// if ($totalRate > 0) {
|
|
|
+// $result[$index][$monthName] = sprintf("%.2f%%", $rateNumber * 100);
|
|
|
+// } else {
|
|
|
+// $result[$index][$monthName] = ""; // 如果没有数据,则为空字符串
|
|
|
+// }
|
|
|
+// }
|
|
|
+// }
|
|
|
+// foreach ($result as &$item) {
|
|
|
+// $total = 0;
|
|
|
+// $count = 0;
|
|
|
+//
|
|
|
+// // 遍历月份,计算总和和数量
|
|
|
+// for ($i = 1; $i <= 12; $i++) {
|
|
|
+// $month = sprintf("%02d月", $i); // 格式化月份,例如 "01月"
|
|
|
+// if (isset($item[$month]) && $item[$month] !== "") {
|
|
|
+// // 移除百分号,并将字符串转换为浮点数
|
|
|
+// $value = floatval(str_replace("%", "", $item[$month]));
|
|
|
+// $total += $value;
|
|
|
+// $count++;
|
|
|
+// }
|
|
|
+// }
|
|
|
+//
|
|
|
+// // 计算平均值
|
|
|
+// if ($count > 0) {
|
|
|
+// $average = $total / $count;
|
|
|
+// // 格式化为百分比字符串,保留两位小数
|
|
|
+// $item["平均值"] = sprintf("%.2f%%", $average);
|
|
|
+// } else {
|
|
|
+// $item["平均值"] = "0.00%"; // 如果没有数据,则为 0.00%
|
|
|
+// }
|
|
|
+// }
|
|
|
+// $this->success('成功',$result);
|
|
|
+// }
|
|
|
+// public function ProcessOutputRate()
|
|
|
+// {
|
|
|
+// if (!$this->request->isGet()) {
|
|
|
+// $this->error('请求错误');
|
|
|
+// }
|
|
|
+//
|
|
|
+// $param = $this->request->param();
|
|
|
+// if (empty($param)) {
|
|
|
+// $this->error('参数错误');
|
|
|
+// }
|
|
|
+//
|
|
|
+// // 新版工序结构
|
|
|
+// $processOrder = [
|
|
|
+// 1 => ['name' => '胶印工序', 'keys' => ['胶印', '上光']],
|
|
|
+// 2 => ['name' => '凹印工序', 'keys' => ['卷凹']],
|
|
|
+// 3 => ['name' => '圆烫工序', 'keys' => ['圆烫']],
|
|
|
+// 4 => ['name' => '圆切工序', 'keys' => ['圆切']],
|
|
|
+// 5 => ['name' => '烫模工序', 'keys' => ['烫金', '模切', '凹凸']],
|
|
|
+// 6 => ['name' => '丝印工序', 'keys' => ['丝印']],
|
|
|
+// 7 => ['name' => '喷码工序', 'keys' => ['喷码']],
|
|
|
+// 8 => ['name' => '单凹工序', 'keys' => ['单凹']]
|
|
|
+// ];
|
|
|
+//
|
|
|
+// // 获取存在数据的月份
|
|
|
+// $mouth = \db('工单_质量考核汇总')
|
|
|
+// ->where('sys_ny', 'like', $param['year'].'%')
|
|
|
+// ->column('distinct(sys_ny) as mouth');
|
|
|
+//
|
|
|
+// $data = [];
|
|
|
+// foreach ($mouth as $month) {
|
|
|
+// foreach ($processOrder as $processId => $process) {
|
|
|
+// $query = \db('工单_质量考核汇总')
|
|
|
+// ->alias('a')
|
|
|
+// ->join('工单_工艺资料 b', 'a.Gy0_gdbh = b.Gy0_gdbh AND a.印件及工序 = b.Gy0_yjno AND a.工序 = b.Gy0_gxh')
|
|
|
+// ->join('工单_印件资料 c', 'a.Gy0_gdbh = c.Yj_Gdbh AND a.印件及工序 = c.yj_Yjno')
|
|
|
+// ->join('成品入仓 d','a.Gy0_gdbh = d.jjcp_gdbh AND a.印件及工序 = d.jjcp_yjno')
|
|
|
+// ->field('a.sys_ny, ((SUM(a.班组制程废品)) + (SUM(a.班组分摊质检废品))) / a.印件工序产量 as 废品率')
|
|
|
+// ->where(function($query) use ($process) {
|
|
|
+// foreach ($process['keys'] as $key) {
|
|
|
+// $query->whereOr('a.工序名称', 'like', "%{$key}%");
|
|
|
+// }
|
|
|
+// })
|
|
|
+// ->where('d.jjcp_smb','like','末%')
|
|
|
+// ->where('a.sys_ny', $month)
|
|
|
+// ->group('a.Gy0_gdbh, b.Gy0_yjno, a.工序');
|
|
|
+//
|
|
|
+// $data[$month][$processId] = $query->select();
|
|
|
+// }
|
|
|
+// }
|
|
|
+// // 构建月份模板
|
|
|
+// $months = [
|
|
|
+// $param['year'].'01' => '01月',
|
|
|
+// $param['year'].'02' => '02月',
|
|
|
+// $param['year'].'03' => '03月',
|
|
|
+// $param['year'].'04' => '04月',
|
|
|
+// $param['year'].'05' => '05月',
|
|
|
+// $param['year'].'06' => '06月',
|
|
|
+// $param['year'].'07' => '07月',
|
|
|
+// $param['year'].'08' => '08月',
|
|
|
+// $param['year'].'09' => '09月',
|
|
|
+// $param['year'].'10' => '10月',
|
|
|
+// $param['year'].'11' => '11月',
|
|
|
+// $param['year'].'12' => '12月'
|
|
|
+// ];
|
|
|
+//
|
|
|
+// $result = [];
|
|
|
+// foreach ($processOrder as $processId => $process) {
|
|
|
+// $processData = [
|
|
|
+// "工序类型" => $process['name'],
|
|
|
+// "01月" => "",
|
|
|
+// "02月" => "",
|
|
|
+// "03月" =>"",
|
|
|
+// "04月" => "",
|
|
|
+// "05月" => "",
|
|
|
+// "06月" => "",
|
|
|
+// "07月" => "",
|
|
|
+// "08月" => "",
|
|
|
+// "09月" => "",
|
|
|
+// "10月" => "",
|
|
|
+// "11月" => "",
|
|
|
+// "12月" => "",
|
|
|
+// "平均值" => "0.00%"
|
|
|
+// ];
|
|
|
+//
|
|
|
+// $totalAnnual = 0;
|
|
|
+// $monthCount = 0;
|
|
|
+//
|
|
|
+// foreach ($months as $sysMonth => $monthName) {
|
|
|
+// $count = 0;
|
|
|
+// $totalRate = 0;
|
|
|
+//
|
|
|
+// if (isset($data[$sysMonth][$processId])) {
|
|
|
+// $records = $data[$sysMonth][$processId];
|
|
|
+// $count = count($records);
|
|
|
+//
|
|
|
+// foreach ($records as $record) {
|
|
|
+// $totalRate += floatval(1 - $record['废品率']);
|
|
|
+// }
|
|
|
+// }
|
|
|
+//
|
|
|
+// if ($count > 0) {
|
|
|
+// $rateValue = ($totalRate / $count) * 100;
|
|
|
+// $processData[$monthName] = sprintf("%.2f%%", $rateValue);
|
|
|
+// $totalAnnual += $rateValue;
|
|
|
+// $monthCount++;
|
|
|
+// } else {
|
|
|
+// $processData[$monthName] = "";
|
|
|
+// }
|
|
|
+// }
|
|
|
+//
|
|
|
+// // 计算年度平均值
|
|
|
+// if ($monthCount > 0) {
|
|
|
+// $processData['平均值'] = sprintf("%.2f%%", $totalAnnual / $monthCount);
|
|
|
+// }
|
|
|
+//
|
|
|
+// $result[] = $processData;
|
|
|
+// }
|
|
|
+//
|
|
|
+// $this->success('成功', $result);
|
|
|
+//}
|
|
|
+// public function ProcessOutputRate()
|
|
|
+// {
|
|
|
+// if (!$this->request->isGet()) {
|
|
|
+// $this->error('请求错误');
|
|
|
+// }
|
|
|
+//
|
|
|
+// $param = $this->request->param();
|
|
|
+// if (empty($param)) {
|
|
|
+// $this->error('参数错误');
|
|
|
+// }
|
|
|
+//
|
|
|
+// // 工序分类
|
|
|
+// $processOrder = [
|
|
|
+// 1 => ['name' => '胶印工序', 'keys' => ['胶印', '上光']],
|
|
|
+// 2 => ['name' => '凹印工序', 'keys' => ['卷凹']],
|
|
|
+// 3 => ['name' => '圆烫工序', 'keys' => ['圆烫']],
|
|
|
+// 4 => ['name' => '圆切工序', 'keys' => ['圆切']],
|
|
|
+// 5 => ['name' => '烫模工序', 'keys' => ['烫金', '模切', '凹凸']],
|
|
|
+// 6 => ['name' => '丝印工序', 'keys' => ['丝印']],
|
|
|
+// 7 => ['name' => '喷码工序', 'keys' => ['喷码']],
|
|
|
+// 8 => ['name' => '单凹工序', 'keys' => ['单凹']]
|
|
|
+// ];
|
|
|
+//
|
|
|
+// // 获取存在数据的月份
|
|
|
+// $monthsWithData = \db('工单_质量考核汇总')
|
|
|
+// ->where('sys_ny', 'like', $param['year'] . '%')
|
|
|
+// ->column('distinct(sys_ny) as month');
|
|
|
+//
|
|
|
+// // 初始化结果数组,按工序名称归类
|
|
|
+// $result = [];
|
|
|
+// foreach ($processOrder as $processId => $process) {
|
|
|
+// $result[$process['name']] = [
|
|
|
+// '01月' => '',
|
|
|
+// '02月' => '',
|
|
|
+// '03月' => '',
|
|
|
+// '04月' => '',
|
|
|
+// '05月' => '',
|
|
|
+// '06月' => '',
|
|
|
+// '07月' => '',
|
|
|
+// '08月' => '',
|
|
|
+// '09月' => '',
|
|
|
+// '10月' => '',
|
|
|
+// '11月' => '',
|
|
|
+// '12月' => '',
|
|
|
+// '平均值' => '0.00%'
|
|
|
+// ];
|
|
|
+// }
|
|
|
+//
|
|
|
+// // 遍历每个月份
|
|
|
+// foreach ($monthsWithData as $month) {
|
|
|
+// foreach ($processOrder as $processId => $process) {
|
|
|
+// // 查询该月份该工序的合格率数据
|
|
|
+// $query = \db('工单_质量考核汇总')
|
|
|
+// ->alias('a')
|
|
|
+// ->join('工单_工艺资料 b', 'a.Gy0_gdbh = b.Gy0_gdbh AND a.印件及工序 = b.Gy0_yjno AND a.工序 = b.Gy0_gxh')
|
|
|
+// ->join('工单_印件资料 c', 'a.Gy0_gdbh = c.Yj_Gdbh AND a.印件及工序 = c.yj_Yjno')
|
|
|
+// ->join('成品入仓 d', 'a.Gy0_gdbh = d.jjcp_gdbh AND a.印件及工序 = d.jjcp_yjno')
|
|
|
+// ->field('a.sys_ny,
|
|
|
+// (1 - ((SUM(a.班组制程废品) + SUM(a.班组分摊质检废品)) / SUM(a.班组产量))) * 100 as 合格率')
|
|
|
+// ->where(function ($query) use ($process) {
|
|
|
+// foreach ($process['keys'] as $key) {
|
|
|
+// $query->whereOr('a.工序名称', 'like', "%{$key}%");
|
|
|
+// }
|
|
|
+// })
|
|
|
+// ->where('d.jjcp_smb', 'like', '末%')
|
|
|
+// ->where('a.sys_ny', $month)
|
|
|
+// ->group('a.sys_ny');
|
|
|
+//
|
|
|
+// $records = $query->select();
|
|
|
+//
|
|
|
+// if (!empty($records)) {
|
|
|
+// $monthName = substr($month, 4, 2) . '月';
|
|
|
+// $result[$process['name']][$monthName] = sprintf("%.2f%%", $records[0]['合格率']);
|
|
|
+// }
|
|
|
+// }
|
|
|
+// }
|
|
|
+//
|
|
|
+// // 计算年度平均值
|
|
|
+// foreach ($result as $processName => &$processData) {
|
|
|
+// $totalAnnual = 0;
|
|
|
+// $monthCount = 0;
|
|
|
+//
|
|
|
+// foreach ($processData as $month => $rate) {
|
|
|
+// if ($month !== '平均值' && $rate !== '') {
|
|
|
+// $totalAnnual += floatval(str_replace('%', '', $rate));
|
|
|
+// $monthCount++;
|
|
|
+// }
|
|
|
+// }
|
|
|
+//
|
|
|
+// if ($monthCount > 0) {
|
|
|
+// $processData['平均值'] = sprintf("%.2f%%", $totalAnnual / $monthCount);
|
|
|
+// }
|
|
|
+// }
|
|
|
+//
|
|
|
+// $this->success('成功', array_values($result));
|
|
|
+// }
|
|
|
public function ProcessOutputRate()
|
|
|
{
|
|
|
if (!$this->request->isGet()) {
|
|
|
@@ -440,14 +774,14 @@ class Decision extends Api
|
|
|
|
|
|
// 工序分类
|
|
|
$processOrder = [
|
|
|
- 1 => ['name' => '胶印工序', 'keys' => ['胶印', '上光']],
|
|
|
- 2 => ['name' => '凹印工序', 'keys' => ['卷凹']],
|
|
|
- 3 => ['name' => '圆烫工序', 'keys' => ['圆烫']],
|
|
|
- 4 => ['name' => '圆切工序', 'keys' => ['圆切']],
|
|
|
- 5 => ['name' => '烫模工序', 'keys' => ['烫金', '模切', '凹凸']],
|
|
|
- 6 => ['name' => '丝印工序', 'keys' => ['丝印']],
|
|
|
- 7 => ['name' => '喷码工序', 'keys' => ['喷码']],
|
|
|
- 8 => ['name' => '单凹工序', 'keys' => ['单凹']]
|
|
|
+ 1 => ['name' => '胶印', 'keys' => ['胶印', '上光']],
|
|
|
+ 2 => ['name' => '卷凹', 'keys' => ['卷凹']],
|
|
|
+ 3 => ['name' => '圆烫', 'keys' => ['圆烫']],
|
|
|
+ 4 => ['name' => '圆切', 'keys' => ['圆切']],
|
|
|
+ 5 => ['name' => '烫模', 'keys' => ['烫金', '模切', '凹凸']],
|
|
|
+ 6 => ['name' => '丝印', 'keys' => ['丝印']],
|
|
|
+ 7 => ['name' => '喷码', 'keys' => ['喷码']],
|
|
|
+ 8 => ['name' => '单凹', 'keys' => ['单凹']]
|
|
|
];
|
|
|
|
|
|
// 获取存在数据的月份
|
|
|
@@ -521,7 +855,14 @@ class Decision extends Api
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- $this->success('成功', array_values($result));
|
|
|
+ // 转换为目标格式
|
|
|
+ $formattedData = [];
|
|
|
+ foreach ($result as $processName => $processData) {
|
|
|
+ $formattedData[] = array_merge(['工序类型' => $processName], $processData);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 返回JSON响应
|
|
|
+ $this->success('成功',$formattedData);
|
|
|
}
|
|
|
/**
|
|
|
* 获取年分数据
|
|
|
@@ -601,8 +942,7 @@ class Decision extends Api
|
|
|
// 执行查询
|
|
|
$rawList = isset($param['page'], $param['limit'])
|
|
|
? $query->page($param['page'])->limit($param['limit'])->select()
|
|
|
- : $query->fetchSql(true)->select();
|
|
|
- halt($rawList);
|
|
|
+ : $query->select();
|
|
|
// 处理分类标记
|
|
|
$processedList = [];
|
|
|
foreach ($rawList as $item) {
|