|
@@ -4,7 +4,6 @@ namespace app\api\controller;
|
|
|
|
|
|
|
|
use app\common\controller\Api;
|
|
use app\common\controller\Api;
|
|
|
use think\Cache;
|
|
use think\Cache;
|
|
|
-use think\cache\driver\Redis;
|
|
|
|
|
use \think\Request;
|
|
use \think\Request;
|
|
|
use \think\Db;
|
|
use \think\Db;
|
|
|
/**
|
|
/**
|
|
@@ -630,7 +629,7 @@ class OrderSuperLoss extends Api
|
|
|
// if ($gy_data[$k]['intangible_loss'] < 0){
|
|
// if ($gy_data[$k]['intangible_loss'] < 0){
|
|
|
// $gy_data[$k]['total_waste'] = $gy_data[$k]['waste_quality'] + $gy_data[$k]['total_fp'];
|
|
// $gy_data[$k]['total_waste'] = $gy_data[$k]['waste_quality'] + $gy_data[$k]['total_fp'];
|
|
|
// }else{
|
|
// }else{
|
|
|
- $gy_data[$k]['total_waste'] = $gy_data[$k]['waste_quality'] + $gy_data[$k]['intangible_loss'] + $gy_data[$k]['total_fp'];
|
|
|
|
|
|
|
+ $gy_data[$k]['total_waste'] = $gy_data[$k]['waste_quality'] + $gy_data[$k]['intangible_loss'] + $gy_data[$k]['total_fp'];
|
|
|
// }
|
|
// }
|
|
|
//工序节损数
|
|
//工序节损数
|
|
|
$gy_data[$k]['loss'] = $item['Gy0_计划损耗']*$item['Gy0_ls']*$item['Gy0_ks'] - $gy_data[$k]['total_waste'];
|
|
$gy_data[$k]['loss'] = $item['Gy0_计划损耗']*$item['Gy0_ls']*$item['Gy0_ks'] - $gy_data[$k]['total_waste'];
|
|
@@ -1255,6 +1254,7 @@ class OrderSuperLoss extends Api
|
|
|
*/
|
|
*/
|
|
|
public function OneOrderSuperLoss($gdbh,$yjno)
|
|
public function OneOrderSuperLoss($gdbh,$yjno)
|
|
|
{
|
|
{
|
|
|
|
|
+// $param = $this->request->param();
|
|
|
$param = [
|
|
$param = [
|
|
|
'gdbh' => $gdbh,
|
|
'gdbh' => $gdbh,
|
|
|
'yjno' => $yjno
|
|
'yjno' => $yjno
|
|
@@ -1675,7 +1675,17 @@ class OrderSuperLoss extends Api
|
|
|
'车间名称' => $value['Gy0_SITE']
|
|
'车间名称' => $value['Gy0_SITE']
|
|
|
];
|
|
];
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
return $result;
|
|
return $result;
|
|
|
|
|
+// halt($result);
|
|
|
|
|
+// \db('工单_质量考核汇总')
|
|
|
|
|
+// ->where('Gy0_gdbh', $param['gdbh'])
|
|
|
|
|
+// ->where('印件及工序', $param['yjno'])
|
|
|
|
|
+// ->delete();
|
|
|
|
|
+// $sql = \db('工单_质量考核汇总')
|
|
|
|
|
+// ->fetchSql(true)
|
|
|
|
|
+// ->insertAll($result);
|
|
|
|
|
+// $res = \db()->query($sql);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@@ -1749,14 +1759,14 @@ class OrderSuperLoss extends Api
|
|
|
|
|
|
|
|
// 子查询:计算所有记录的 jjcp_sl 总和(入仓数量)
|
|
// 子查询:计算所有记录的 jjcp_sl 总和(入仓数量)
|
|
|
$subQuery = \db('成品入仓')
|
|
$subQuery = \db('成品入仓')
|
|
|
- ->alias('a_sub')
|
|
|
|
|
- ->field('
|
|
|
|
|
|
|
+ ->alias('a_sub')
|
|
|
|
|
+ ->field('
|
|
|
a_sub.jjcp_gdbh AS Gd_gdbh_sub,
|
|
a_sub.jjcp_gdbh AS Gd_gdbh_sub,
|
|
|
a_sub.jjcp_yjno AS jjcp_yjno_sub,
|
|
a_sub.jjcp_yjno AS jjcp_yjno_sub,
|
|
|
SUM(a_sub.jjcp_sl) AS warehousing_num
|
|
SUM(a_sub.jjcp_sl) AS warehousing_num
|
|
|
')
|
|
')
|
|
|
- ->group('a_sub.jjcp_gdbh, a_sub.jjcp_yjno')
|
|
|
|
|
- ->buildSql();
|
|
|
|
|
|
|
+ ->group('a_sub.jjcp_gdbh, a_sub.jjcp_yjno')
|
|
|
|
|
+ ->buildSql();
|
|
|
|
|
|
|
|
$list = \db('成品入仓')
|
|
$list = \db('成品入仓')
|
|
|
->alias('a')
|
|
->alias('a')
|
|
@@ -2069,28 +2079,20 @@ class OrderSuperLoss extends Api
|
|
|
//循环插入超节损数据
|
|
//循环插入超节损数据
|
|
|
public function orderLossData()
|
|
public function orderLossData()
|
|
|
{
|
|
{
|
|
|
- if ($this->request->isGet() === false) {
|
|
|
|
|
- $this->error('请求错误');
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
$param = $this->request->param();
|
|
$param = $this->request->param();
|
|
|
$where = [];
|
|
$where = [];
|
|
|
-
|
|
|
|
|
- // 创建查询条件
|
|
|
|
|
- if (!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_gdbh'] = $param['gdbh'];
|
|
|
$where['a.jjcp_yjno'] = $param['yjno'];
|
|
$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::name('成品入仓')
|
|
|
|
|
|
|
+ $where['a.jjcp_smb'] = ['like','末%'];
|
|
|
|
|
+ $list = \db('成品入仓')
|
|
|
->alias('a')
|
|
->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($where)
|
|
|
->where(function ($query) {
|
|
->where(function ($query) {
|
|
|
$query->where('c.仓库编号', '101')
|
|
$query->where('c.仓库编号', '101')
|
|
@@ -2099,68 +2101,26 @@ class OrderSuperLoss extends Api
|
|
|
->field('a.jjcp_gdbh,a.jjcp_yjno')
|
|
->field('a.jjcp_gdbh,a.jjcp_yjno')
|
|
|
->group('a.jjcp_gdbh,a.jjcp_yjno')
|
|
->group('a.jjcp_gdbh,a.jjcp_yjno')
|
|
|
->select();
|
|
->select();
|
|
|
-
|
|
|
|
|
- // Redis配置
|
|
|
|
|
- $options = [
|
|
|
|
|
- 'host' => '127.0.0.1',
|
|
|
|
|
- 'port' => 6379,
|
|
|
|
|
- 'password' => '',
|
|
|
|
|
- 'select' => 14,
|
|
|
|
|
- 'timeout' => 2, // 增加超时设置
|
|
|
|
|
- ];
|
|
|
|
|
-
|
|
|
|
|
- try {
|
|
|
|
|
- // 创建原生Redis连接
|
|
|
|
|
- $redis = new \Redis();
|
|
|
|
|
- $redis->connect($options['host'], $options['port'], $options['timeout']);
|
|
|
|
|
-
|
|
|
|
|
- if (!empty($options['password'])) {
|
|
|
|
|
- $redis->auth($options['password']);
|
|
|
|
|
- }
|
|
|
|
|
- $redis->select($options['select']);
|
|
|
|
|
-
|
|
|
|
|
- // 生成批次ID
|
|
|
|
|
- $batchId = 'batch_' . uniqid() . '_' . time();
|
|
|
|
|
- $totalTasks = count($list);
|
|
|
|
|
-
|
|
|
|
|
- // 使用管道操作
|
|
|
|
|
- $pipe = $redis->multi(\Redis::PIPELINE);
|
|
|
|
|
-
|
|
|
|
|
- // 设置批次信息
|
|
|
|
|
- $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));
|
|
|
|
|
|
|
+ $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++;
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
- // 执行管道
|
|
|
|
|
- $pipe->exec();
|
|
|
|
|
-
|
|
|
|
|
- } catch (\RedisException $e) {
|
|
|
|
|
- $this->error('Redis连接失败: ' . $e->getMessage());
|
|
|
|
|
- } catch (\Exception $e) {
|
|
|
|
|
- $this->error('队列操作失败: ' . $e->getMessage());
|
|
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
- $this->success('任务已加入队列处理', [
|
|
|
|
|
- 'batch_id' => $batchId,
|
|
|
|
|
- 'queue_count' => $redis->lLen('order_loss_queue')
|
|
|
|
|
- ]);
|
|
|
|
|
|
|
+ if ($i === 0){
|
|
|
|
|
+ $this->success('成功');
|
|
|
|
|
+ }else{
|
|
|
|
|
+ $this->error('失败');
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|