|
|
@@ -3,6 +3,7 @@
|
|
|
namespace app\api\controller;
|
|
|
|
|
|
use app\common\controller\Api;
|
|
|
+use think\Db;
|
|
|
|
|
|
/**
|
|
|
* 首页接口
|
|
|
@@ -50,7 +51,7 @@ class Index extends Api
|
|
|
if($bool===false) $this->error('订单数量存入redis失败','','000001');
|
|
|
$this->success('请求成功');
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
//查询Gy0_sj1不等于1900-01-01 00:00:00的数据
|
|
|
$data = db('工单_印件资料')->alias('y')
|
|
|
->join('工单_工艺资料 g','y.Yj_Gdbh = g.Gy0_gdbh AND y.yj_Yjno = g.Gy0_yjno')
|
|
|
@@ -155,8 +156,11 @@ class Index extends Api
|
|
|
$yscjDbToRedis = [];
|
|
|
|
|
|
//获取所有印刷车间
|
|
|
+ // $rows = db('设备_基本资料')
|
|
|
+ // ->where('使用部门','凹丝印车间')
|
|
|
+ // ->column('设备编号');
|
|
|
$rows = db('设备_基本资料')
|
|
|
- ->where('使用部门','印刷车间')
|
|
|
+ ->whereIn('使用部门', ['凹丝印车间', '胶印车间'])
|
|
|
->column('设备编号');
|
|
|
|
|
|
foreach($rows as $value){
|
|
|
@@ -227,33 +231,44 @@ class Index extends Api
|
|
|
public function getYscjByRedis()
|
|
|
{
|
|
|
$row = cache('yscjDbToRedis');
|
|
|
- $result['columns']=[
|
|
|
- ['name'=>'机台号','id'=>'jtbh','width'=>'11','autoWrap'=>"true",'textAlign'=>'left'],
|
|
|
- ['name'=>'在产工单号','id'=>'gdbh','width'=>'15','textAlign'=>'left'],
|
|
|
- ['name'=>'工单名称','id'=>'gdmc','width'=>'35','autoWrap'=>"true",'textAlign'=>'left'],
|
|
|
- ['name'=>'工序','id'=>'gx','width'=>'15','textAlign'=>'left'],
|
|
|
- ['name'=>'计划产量','id'=>'jhcl','width'=>'8','autoWrap'=>"true",'textAlign'=>'left'],
|
|
|
- ['name'=>'已完成产量','id'=>'wccl','width'=>'9','autoWrap'=>"true",'textAlign'=>'center'],
|
|
|
- ['name'=>'小时产能','id'=>'xscn','width'=>'8','autoWrap'=>"true",'textAlign'=>'center'],
|
|
|
- ['name'=>'机台状态','id'=>'status','width'=>'8','autoWrap'=>"true",'textAlign'=>'center'],
|
|
|
+
|
|
|
+ if (empty($row)) {
|
|
|
+ return json([
|
|
|
+ 'status' => 0,
|
|
|
+ 'msg' => '',
|
|
|
+ 'data' => [] // 或者可以返回 []
|
|
|
+ ]);
|
|
|
+ }
|
|
|
+
|
|
|
+ $result['columns'] = [
|
|
|
+ ['name' => '机台号', 'id' => 'jtbh', 'width' => '11', 'autoWrap' => "true", 'textAlign' => 'left'],
|
|
|
+ ['name' => '在产工单号', 'id' => 'gdbh', 'width' => '15', 'textAlign' => 'left'],
|
|
|
+ ['name' => '工单名称', 'id' => 'gdmc', 'width' => '35', 'autoWrap' => "true", 'textAlign' => 'left'],
|
|
|
+ ['name' => '工序', 'id' => 'gx', 'width' => '15', 'textAlign' => 'left'],
|
|
|
+ ['name' => '计划产量', 'id' => 'jhcl', 'width' => '8', 'autoWrap' => "true", 'textAlign' => 'left'],
|
|
|
+ ['name' => '已完成产量', 'id' => 'wccl', 'width' => '9', 'autoWrap' => "true", 'textAlign' => 'center'],
|
|
|
+ ['name' => '小时产能', 'id' => 'xscn', 'width' => '8', 'autoWrap' => "true", 'textAlign' => 'center'],
|
|
|
+ ['name' => '机台状态', 'id' => 'status', 'width' => '8', 'autoWrap' => "true", 'textAlign' => 'center'],
|
|
|
];
|
|
|
- if($row){
|
|
|
- foreach($row as $k=>$v){
|
|
|
- $result['rows'][$k]['jtbh']=$v['机台号'];
|
|
|
- $result['rows'][$k]['gdbh']=$v['在产工单号'];
|
|
|
- $result['rows'][$k]['gdmc']=$v['工单名称'];
|
|
|
- $result['rows'][$k]['gx']=$v['工序'];
|
|
|
- $result['rows'][$k]['jhcl'] = $v['计划产量'];
|
|
|
- $result['rows'][$k]['wccl'] = $v['已完成产量'];
|
|
|
- $result['rows'][$k]['xscn'] = $v['小时产能'];
|
|
|
- $result['rows'][$k]['status'] = $v['机台状态'];
|
|
|
- }
|
|
|
+
|
|
|
+ foreach ($row as $k => $v) {
|
|
|
+ $result['rows'][$k] = [
|
|
|
+ 'jtbh' => $v['机台号'],
|
|
|
+ 'gdbh' => $v['在产工单号'],
|
|
|
+ 'gdmc' => $v['工单名称'],
|
|
|
+ 'gx' => $v['工序'],
|
|
|
+ 'jhcl' => $v['计划产量'],
|
|
|
+ 'wccl' => $v['已完成产量'],
|
|
|
+ 'xscn' => $v['小时产能'],
|
|
|
+ 'status' => $v['机台状态'],
|
|
|
+ ];
|
|
|
}
|
|
|
-
|
|
|
- $res['status']=0;
|
|
|
- $res['msg']='';
|
|
|
- $res['data']=$result;
|
|
|
- return json($res);
|
|
|
+
|
|
|
+ return json([
|
|
|
+ 'status' => 0,
|
|
|
+ 'msg' => '',
|
|
|
+ 'data' => $result
|
|
|
+ ]);
|
|
|
}
|
|
|
|
|
|
//获取印后车间生产进度数据
|
|
|
@@ -282,7 +297,7 @@ class Index extends Api
|
|
|
$result['rows'][$k]['status'] = $v['机台状态'];
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
$res['status']=0;
|
|
|
$res['msg']='';
|
|
|
$res['data']=$result;
|
|
|
@@ -345,7 +360,7 @@ class Index extends Api
|
|
|
$result['categories'] = array_map('strval', array_keys($row[$jtbh]));
|
|
|
$result['series'][0]['data'] = array_values($row[$jtbh]);
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
$res['status']=0;
|
|
|
$res['msg']='';
|
|
|
$res['data']=$result;
|
|
|
@@ -354,10 +369,6 @@ class Index extends Api
|
|
|
|
|
|
/**
|
|
|
* 班组工作中心负荷
|
|
|
- * @return void
|
|
|
- * @throws \think\db\exception\DataNotFoundException
|
|
|
- * @throws \think\db\exception\ModelNotFoundException
|
|
|
- * @throws \think\exception\DbException
|
|
|
*/
|
|
|
public function bzDbToRedis()
|
|
|
{
|
|
|
@@ -422,7 +433,6 @@ class Index extends Api
|
|
|
|
|
|
/**
|
|
|
* 获取班组工作负荷数据
|
|
|
- * @return \think\response\Json
|
|
|
*/
|
|
|
public function getBzByRedis()
|
|
|
{
|
|
|
@@ -469,5 +479,233 @@ class Index extends Api
|
|
|
$res['data']=$result;
|
|
|
return json($res);
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 决策支持月度设备运行数据统计->班组(接口)
|
|
|
+ */
|
|
|
+ public function TeamsgGoups()
|
|
|
+ {
|
|
|
+ // 获取设备编组信息
|
|
|
+ $result = \db('设备_基本资料')
|
|
|
+ ->whereNotNull('设备编组')
|
|
|
+ ->group('设备编组')
|
|
|
+ ->column('rtrim(设备编组) as 设备编组');
|
|
|
+
|
|
|
+ $data = [
|
|
|
+ "columns" => [
|
|
|
+ ["id" => "subsys"]
|
|
|
+ ],
|
|
|
+ "rows" => []
|
|
|
+ ];
|
|
|
+
|
|
|
+ foreach ($result as $value) {
|
|
|
+ $data["rows"][] = ["subsys" => $value];
|
|
|
+ }
|
|
|
+
|
|
|
+ $res = [
|
|
|
+ 'status' => 0,
|
|
|
+ 'msg' => '',
|
|
|
+ 'data' => $data
|
|
|
+ ];
|
|
|
+ return json($res);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 决策支持月度设备运行数据统计->机台运行工时汇总(接口)
|
|
|
+ */
|
|
|
+ public function MonthlyEquipment() {
|
|
|
+ // 获取请求参数,默认为 '01、切纸机组'
|
|
|
+ $postData = input('post.dependence.item.subsys', '01、切纸机组');
|
|
|
+
|
|
|
+ // 查询条件
|
|
|
+ $where = [];
|
|
|
+ if (!empty($postData)) {
|
|
|
+ $where['设备编组'] = $postData;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 获取当前年月
|
|
|
+ $currentYearMonth = date('Y-m');
|
|
|
+ // 获取去年的同月
|
|
|
+ $lastYearMonth = date('Y-m', strtotime('-1 year'));
|
|
|
+
|
|
|
+ // 查询 **今年** 当月的数据
|
|
|
+ $currentData = \db('设备_基本资料')
|
|
|
+ ->alias('a')
|
|
|
+ ->join('设备_产量计酬 b', 'a.设备编号 = b.sczl_jtbh')
|
|
|
+ ->field([
|
|
|
+ 'a.设备编号' => '设备编号',
|
|
|
+ 'SUM(b.sczl_cl)' => '产量'
|
|
|
+ ])
|
|
|
+ ->where($where)
|
|
|
+ ->whereTime('b.sczl_rq', '>=', $currentYearMonth . '-01') // 查询当前月的第一天
|
|
|
+ ->whereTime('b.sczl_rq', '<', date('Y-m-d', strtotime('next month', strtotime($currentYearMonth . '-01')))) // 下个月的第一天
|
|
|
+ ->group('a.设备编号')
|
|
|
+ ->order('a.设备编号')
|
|
|
+ ->select();
|
|
|
+
|
|
|
+ // 查询 **去年** 同月的数据
|
|
|
+ $lastYearData = \db('设备_基本资料')
|
|
|
+ ->alias('a')
|
|
|
+ ->join('设备_产量计酬 b', 'a.设备编号 = b.sczl_jtbh')
|
|
|
+ ->field([
|
|
|
+ 'a.设备编号' => '设备编号',
|
|
|
+ 'SUM(b.sczl_cl)' => '产量'
|
|
|
+ ])
|
|
|
+ ->where($where)
|
|
|
+ ->whereTime('b.sczl_rq', '>=', $lastYearMonth . '-01') // 查询去年的同月第一天
|
|
|
+ ->whereTime('b.sczl_rq', '<', date('Y-m-d', strtotime('next month', strtotime($lastYearMonth . '-01')))) // 下个月的第一天
|
|
|
+ ->group('a.设备编号')
|
|
|
+ ->order('a.设备编号')
|
|
|
+ ->select();
|
|
|
+
|
|
|
+ // 格式化数据
|
|
|
+ $categories = [];
|
|
|
+ $currentYearSeries = [];
|
|
|
+ $lastYearSeries = [];
|
|
|
+
|
|
|
+ // 转换查询结果为关联数组,方便查找
|
|
|
+ $currentYearMap = [];
|
|
|
+ $lastYearMap = [];
|
|
|
+
|
|
|
+ foreach ($currentData as $item) {
|
|
|
+ $currentYearMap[$item['设备编号']] = $item['产量'];
|
|
|
+ }
|
|
|
+ foreach ($lastYearData as $item) {
|
|
|
+ $lastYearMap[$item['设备编号']] = $item['产量'];
|
|
|
+ }
|
|
|
+
|
|
|
+ // 统一设备编号,确保数据完整
|
|
|
+ $allDevices = array_unique(array_merge(array_keys($currentYearMap), array_keys($lastYearMap)));
|
|
|
+
|
|
|
+ foreach ($allDevices as $device) {
|
|
|
+ $categories[] = $device;
|
|
|
+ $currentYearSeries[] = isset($currentYearMap[$device]) ? intval($currentYearMap[$device]) : 0; // 今年产量
|
|
|
+ $lastYearSeries[] = isset($lastYearMap[$device]) ? intval($lastYearMap[$device]) : 0; // 去年产量
|
|
|
+ }
|
|
|
+
|
|
|
+ // 组织返回数据
|
|
|
+ $response = [
|
|
|
+ 'status' => 0,
|
|
|
+ 'msg' => '',
|
|
|
+ 'data' => [
|
|
|
+ 'categories' => $categories,
|
|
|
+ 'series' => [
|
|
|
+ [
|
|
|
+ 'name' => '今年产量',
|
|
|
+ 'data' => $currentYearSeries,
|
|
|
+ 'type' => 'bar',
|
|
|
+ 'yAxisIndex' => 0
|
|
|
+ ],
|
|
|
+ [
|
|
|
+ 'name' => '去年产量',
|
|
|
+ 'data' => $lastYearSeries,
|
|
|
+ 'type' => 'bar',
|
|
|
+ 'yAxisIndex' => 0
|
|
|
+ ]
|
|
|
+ ]
|
|
|
+ ]
|
|
|
+ ];
|
|
|
+
|
|
|
+ return json($response);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 决策支持月度设备运行数据统计->机台运行工时汇总列表(接口)
|
|
|
+ */
|
|
|
+ public function Equipmenttable(){
|
|
|
+ // 获取请求数据
|
|
|
+ $postData = input('post.dependence.item.subsys', '01、切纸机组');
|
|
|
+
|
|
|
+ $where = [];
|
|
|
+ if (!empty($postData)) {
|
|
|
+ $where['设备编组'] = $postData;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 获取当前月份
|
|
|
+ $mouth = date_create_from_format('Ym', date('Ym'))->format('Y-m');
|
|
|
+
|
|
|
+ // 查询设备数据
|
|
|
+ $list = \db('设备_基本资料')->alias('a')
|
|
|
+ ->join('设备_产量计酬 b', 'a.设备编号 = b.sczl_jtbh')
|
|
|
+ ->field([
|
|
|
+ 'a.设备编号' => '设备编号',
|
|
|
+ 'rtrim(a.设备名称)' => '设备名称',
|
|
|
+ 'SUM(b.sczl_cl)' => '产量',
|
|
|
+ 'SUM(b.sczl_设备运行工时)' => '设备运行工时',
|
|
|
+ 'SUM(b.sczl_保养工时)' => '保养工时',
|
|
|
+ 'SUM(b.sczl_打样总工时)' => '打样总工时',
|
|
|
+ 'SUM(b.sczl_打样工时)' => '打样补产工时',
|
|
|
+ 'SUM(b.sczl_装版总工时)' => '装板总工时',
|
|
|
+ 'SUM(b.sczl_装版工时)' => '装板补产工时',
|
|
|
+ 'SUM(b.sczl_异常停机工时)' => '异常停机工时'
|
|
|
+ ])
|
|
|
+ ->where($where)
|
|
|
+ ->whereTime('b.sczl_rq', $mouth)
|
|
|
+ ->group('a.设备编号')
|
|
|
+ ->order('a.设备编号')
|
|
|
+ ->select();
|
|
|
+
|
|
|
+ $rows = [];
|
|
|
+ foreach ($list as $item) {
|
|
|
+ $rows[] = [
|
|
|
+ 'subsys' => $item['设备编号'],
|
|
|
+ 'module' => $item['设备名称'],
|
|
|
+ 'business' => $item['产量'],
|
|
|
+ 'sbyxgs' => $item['设备运行工时'],
|
|
|
+ 'dyzgs' => $item['打样总工时'],
|
|
|
+ 'dybcgs' => $item['打样补产工时'],
|
|
|
+ 'zbzgs' => $item['装板总工时'],
|
|
|
+ 'zbbcgs' => $item['装板补产工时'],
|
|
|
+ 'yctjgs' => $item['异常停机工时']
|
|
|
+ ];
|
|
|
+ }
|
|
|
+
|
|
|
+ // 最终响应格式
|
|
|
+ $response = [
|
|
|
+ 'status' => 0,
|
|
|
+ 'msg' => '',
|
|
|
+ 'data' => [
|
|
|
+ 'total' => count($rows),
|
|
|
+ 'columns' => [
|
|
|
+ ['name' => '设备编号','id' => 'subsys'],
|
|
|
+ ['name' => '设备名称','id' => 'module'],
|
|
|
+ ['name' => '产量','id' => 'business'],
|
|
|
+ ['name' => '设备运行工时','id' => 'sbyxgs'],
|
|
|
+ ['name' => '打样总工时','id' => 'dyzgs'],
|
|
|
+ ['name' => '打样补产工时','id' => 'dybcgs'],
|
|
|
+ ['name' => '装板总工时','id' => 'zbzgs'],
|
|
|
+ ['name' => '装板补产工时','id' => 'zbbcgs'],
|
|
|
+ ['name' => '异常停机工时','id' => 'yctjgs',]
|
|
|
+ ],
|
|
|
+// 'superHeaders' => [
|
|
|
+// [
|
|
|
+// [
|
|
|
+// 'name' => '设备信息',
|
|
|
+// 'colspan' => 3
|
|
|
+// ],
|
|
|
+// [
|
|
|
+// 'name' => '工时统计',
|
|
|
+// 'colspan' => 2
|
|
|
+// ]
|
|
|
+// ]
|
|
|
+// ],
|
|
|
+ 'rows' => $rows
|
|
|
+ ]
|
|
|
+ ];
|
|
|
+ return json($response);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 工序产出率月统计报表(接口)
|
|
|
+ */
|
|
|
+ public function Monthlystatistical(){
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
}
|
|
|
|