feat(testing): 增加质检报告独立编辑与详情页面,不再使用弹窗

这个提交包含在:
wikiboss
2026-11-02 14:19:14 +08:00
父节点 6f877be41a
当前提交 43da3cc0ee
共有 38 个文件被更改,包括 2371 次插入 和 301 次删除

查看文件

@@ -8,6 +8,7 @@ use app\common\model\GranaryModel;
use app\common\model\TestingModel;
use app\common\model\TestingParamsModel;
use think\Db;
use app\common\library\GranarySite;
/**
* 首页接口
@@ -35,17 +36,10 @@ class Index extends Api
public function granaryList(GranaryModel $granaryModel)
{
$site = $this->request->get('site', 'center');
if (!GranarySite::valid($site)) $this->error('无效库区');
$query = $granaryModel->field('province_id,city_id,update_time', true);
if ($site === 'xishui') {
$query->where('storage', 'like', '%习水%');
} else {
$query->where(function ($q) {
$q->where('storage', 'like', '%中心库%')
->whereOr('storage', 'not like', '%习水%')
->whereOr('storage', null);
});
}
$query->where('site', $site);
$list = $query->select();
// 数据处理
@@ -55,7 +49,7 @@ class Index extends Api
// Load saved rules in two queries rather than one query per granary.
$tests = TestingModel::with(['testingParams'])
->where('gid', 'in', array_column($list, 'id'))
->order('test_date DESC, id DESC')->select();
->order('is_demo ASC, test_date DESC, id DESC')->select();
$latestTests = [];
foreach ($tests as $test) {
$test = $test->toArray();
@@ -82,8 +76,6 @@ class Index extends Api
$v['storage_num'] = $content['storageNum'];
}
}
} elseif ($site === 'xishui') {
$list = $this->getXishuiDefaultList();
}
$coords = $this->getSiteCoords($site);
@@ -94,10 +86,19 @@ class Index extends Api
unset($granary);
}
if ($site === 'xishui') {
foreach ($list as &$granary) {
$key = 'xishui_' . $granary['num'];
$granary['screen_coord'] = isset($coords[$key]) ? $coords[$key] : null;
}
unset($granary);
}
$this->success('获取成功', [
'list' => $list,
'coords' => $coords,
'site' => $site
'site' => $site,
'site_name' => GranarySite::NAMES[$site],
'source' => 'database'
]);
}
@@ -264,9 +265,10 @@ class Index extends Api
*/
public function env()
{
$site = $this->request->get('site', 'center');
= ->request->get('site', 'center');
if (!GranarySite::valid()) ->error('无效库区');
$envData = [
= [
'center' => [
'site' => 'center',
'name' => '遵义直属库中心库区',
@@ -289,8 +291,29 @@ class Index extends Api
]
];
$data = isset($envData[$site]) ? $envData[$site] : $envData['center'];
$this->success('获取成功', $data);
= isset([]) ? [] : ['center'];
// 优先读取该库区最新一条人工录入或设定的温湿度快照
try {
= Db::name('grain_forecast')
->alias('f')
->join('granary g', 'f.gid = g.id')
->where('g.site', )
->order('f.id DESC')
->field('f.tm_i, f.hm_i, f.tm_o, f.hm_o, f.update_time')
->find();
if () {
['tm_i'] = (float)['tm_i'];
['hm_i'] = (float)['hm_i'];
['tm_o'] = (float)['tm_o'];
['hm_o'] = (float)['hm_o'];
['update_time'] = (int)['update_time'];
}
} catch (\Exception ) {
// 异常时安全兜底基准工况
}
->success('获取成功', );
}
/**
@@ -428,76 +451,4 @@ class Index extends Api
return $result;
}
/**
* 习水库预设数据列表
*/
protected function getXishuiDefaultList()
{
$list = [];
for ($i = 1; $i <= 8; $i++) {
$list[] = [
'id' => 100 + $i,
'name' => "{$i}号浅圆仓",
'storage' => '遵义直属库有限公司习水库区',
'num' => $i,
'granary_type' => 2,
'varieties' => ['type' => 'wheat', 'name' => '小麦'],
'content' => [
'code' => "XS-0{$i}",
'warehouseType' => '立式浅圆仓',
'capacity' => '6500',
'storageNum' => '5900',
'level' => '壹等',
'water' => '12.0%',
'impurity' => '0.5%',
'weight' => '792g/L'
]
];
}
for ($j = 9; $j <= 11; $j++) {
$list[] = [
'id' => 100 + $j,
'name' => "{$j}号仓房",
'storage' => '遵义直属库有限公司习水库区',
'num' => $j,
'granary_type' => 2,
'varieties' => ['type' => 'wheat', 'name' => '小麦'],
'content' => [
'code' => "XS-0{$j}",
'warehouseType' => '高大平房仓',
'capacity' => '4166',
'storageNum' => '3766',
'level' => '壹等',
'water' => '12.1%',
'impurity' => '0.5%',
'weight' => '790g/L'
]
];
}
return $list;
}
/**
* 辅助远程算法请求
*/
protected function callRemoteForecast($url, $params)
{
try {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($params));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_TIMEOUT, 2);
$output = curl_exec($ch);
curl_close($ch);
if (!empty($output)) {
$res = json_decode($output, true);
if (isset($res['code']) && $res['code'] == 200 && !empty($res['data'])) {
return $res['data'];
}
}
} catch (\Exception $e) {}
return null;
}
}