|
|
@@ -4,6 +4,7 @@ namespace app\api\controller;
|
|
|
|
|
|
use app\common\controller\Api;
|
|
|
use think\Cache;
|
|
|
+use think\cache\driver\Redis;
|
|
|
use \think\Request;
|
|
|
use \think\Db;
|
|
|
/**
|
|
|
@@ -1254,7 +1255,6 @@ class OrderSuperLoss extends Api
|
|
|
*/
|
|
|
public function OneOrderSuperLoss($gdbh,$yjno)
|
|
|
{
|
|
|
-// $param = $this->request->param();
|
|
|
$param = [
|
|
|
'gdbh' => $gdbh,
|
|
|
'yjno' => $yjno
|
|
|
@@ -1675,17 +1675,7 @@ class OrderSuperLoss extends Api
|
|
|
'车间名称' => $value['Gy0_SITE']
|
|
|
];
|
|
|
}
|
|
|
-
|
|
|
return $result;
|
|
|
-// halt($result);
|
|
|
-// \db('工单_质量考核汇总')
|
|
|
-// ->where('Gy0_gdbh', $param['gdbh'])
|
|
|
-// ->where('印件及工序', $param['yjno'])
|
|
|
-// ->delete();
|
|
|
-// $sql = \db('工单_质量考核汇总')
|
|
|
-// ->fetchSql(true)
|
|
|
-// ->insertAll($result);
|
|
|
-// $res = \db()->query($sql);
|
|
|
}
|
|
|
|
|
|
|
|
|
@@ -2079,20 +2069,26 @@ class OrderSuperLoss extends Api
|
|
|
//循环插入超节损数据
|
|
|
public function orderLossData()
|
|
|
{
|
|
|
+ if ($this->request->isGet() === false){
|
|
|
+ $this->error('请求错误');
|
|
|
+ }
|
|
|
$param = $this->request->param();
|
|
|
$where = [];
|
|
|
- if (isset($param['gdbh']) && isset($param['yjno']) && !empty($param['gdbh']) && !empty($param['yjno'])){
|
|
|
+ // 判断接收数据,创建查询条件
|
|
|
+ if (isset($param['gdbh']) && isset($param['yjno']) && !empty($param['gdbh']) && !empty($param['yjno'])) {
|
|
|
$where['a.jjcp_gdbh'] = $param['gdbh'];
|
|
|
$where['a.jjcp_yjno'] = $param['yjno'];
|
|
|
}
|
|
|
- if (isset($param['mouth'])){
|
|
|
- $where['a.jjcp_sj'] = ['like',$param['mouth'].'%'];
|
|
|
+ if (isset($param['mouth'])) {
|
|
|
+ $where['a.jjcp_sj'] = ['like', $param['mouth'] . '%'];
|
|
|
}
|
|
|
- $where['a.jjcp_smb'] = ['like','末%'];
|
|
|
- $list = \db('成品入仓')
|
|
|
+ $where['a.jjcp_smb'] = ['like', '末%'];
|
|
|
+
|
|
|
+ // 根据查询条件查询出需要计算超节损的工单和印件
|
|
|
+ $list = Db::name('成品入仓')
|
|
|
->alias('a')
|
|
|
- ->join('设备_产量计酬 b','a.jjcp_gdbh = b.sczl_gdbh AND a.jjcp_yjno = b.sczl_yjno')
|
|
|
- ->join('物料_收发记录 c','a.jjcp_gdbh = c.st_gdbh AND a.jjcp_cpdh = c.cpdh')
|
|
|
+ ->join('设备_产量计酬 b', 'a.jjcp_gdbh = b.sczl_gdbh AND a.jjcp_yjno = b.sczl_yjno')
|
|
|
+ ->join('物料_收发记录 c', 'a.jjcp_gdbh = c.st_gdbh AND a.jjcp_cpdh = c.cpdh')
|
|
|
->where($where)
|
|
|
->where(function ($query) {
|
|
|
$query->where('c.仓库编号', '101')
|
|
|
@@ -2101,29 +2097,52 @@ class OrderSuperLoss extends Api
|
|
|
->field('a.jjcp_gdbh,a.jjcp_yjno')
|
|
|
->group('a.jjcp_gdbh,a.jjcp_yjno')
|
|
|
->select();
|
|
|
- $i = 0;
|
|
|
- foreach ($list as $item){
|
|
|
- $result = $this->OneOrderSuperLoss($item['jjcp_gdbh'],$item['jjcp_yjno']);
|
|
|
- \db('工单_质量考核汇总')
|
|
|
- ->where('Gy0_gdbh', $item['jjcp_gdbh'])
|
|
|
- ->where('印件及工序', $item['jjcp_yjno'])
|
|
|
- ->delete();
|
|
|
- $sql = \db('工单_质量考核汇总')
|
|
|
- ->fetchSql(true)
|
|
|
- ->insertAll($result);
|
|
|
- $res = \db()->query($sql);
|
|
|
- if ($res === false){
|
|
|
- $i++;
|
|
|
+
|
|
|
+ // 创建redis
|
|
|
+ $redis = new \Redis();
|
|
|
+ $redis->connect('127.0.0.1', 6379, 0);
|
|
|
+ $redis->auth('');
|
|
|
+ $redis->select(14);
|
|
|
+
|
|
|
+ // 生成批次ID
|
|
|
+ $batchId = 'batch_' . uniqid() . '_' . time();
|
|
|
+ $totalTasks = count($list);
|
|
|
+
|
|
|
+ //设置队列信息
|
|
|
+ $pipe = $redis->pipeline();
|
|
|
+ try {
|
|
|
+ // 设置批次信息
|
|
|
+ $pipe->hmset("batch:{$batchId}", [
|
|
|
+ 'total' => $totalTasks,
|
|
|
+ 'processed' => 0,
|
|
|
+ 'status' => 'processing',
|
|
|
+ 'created_at' => date('Y-m-d H:i:s')
|
|
|
+ ]);
|
|
|
+ $pipe->expire("batch:{$batchId}", 3600);
|
|
|
+
|
|
|
+ // 批量添加任务
|
|
|
+ foreach ($list as $item) {
|
|
|
+ $task = [
|
|
|
+ 'batch_id' => $batchId,
|
|
|
+ 'gdbh' => $item['jjcp_gdbh'],
|
|
|
+ 'yjno' => $item['jjcp_yjno'],
|
|
|
+ 'retries' => 0
|
|
|
+ ];
|
|
|
+ $pipe->rpush('order_loss_queue', json_encode($task));
|
|
|
}
|
|
|
+
|
|
|
+ // 执行管道
|
|
|
+ $pipe->exec();
|
|
|
+ } catch (\Exception $e) {
|
|
|
+ $pipe->discard();
|
|
|
+ $this->error('队列操作失败: ' . $e->getMessage());
|
|
|
}
|
|
|
- if ($i === 0){
|
|
|
- $this->success('成功');
|
|
|
- }else{
|
|
|
- $this->error('失败');
|
|
|
- }
|
|
|
+
|
|
|
+ $this->success('任务已加入队列处理', [
|
|
|
+ 'batch_id' => $batchId,
|
|
|
+ 'queue_count' => $redis->llen('order_loss_queue')]);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
-
|