feat(forecast): 支持温湿度预测记录编辑与删除,修复组件调用并级联清理周期数据

这个提交包含在:
wikiboss
2026-11-02 14:55:36 +08:00
父节点 4a1e4f1d93
当前提交 f6e454a589
共有 8 个文件被更改,包括 284 次插入 和 61 次删除

查看文件

@@ -33,29 +33,29 @@ class Forecast extends GranaryBackend
}
}
unset($row);
$granaries = array_values(array_filter(GranarySite::granaries(->filterSites), function () { return in_array(['varieties'], ['小麦', '稻谷'], true); }));
if (!empty()) {
= array_column(, 'id');
= Db::name('grain_forecast')->where('gid', 'in', )
$granaries = array_values(array_filter(GranarySite::granaries($this->filterSites), function ($g) { return in_array($g['varieties'], ['小麦', '稻谷'], true); }));
if (!empty($granaries)) {
$gids = array_column($granaries, 'id');
$envRecords = Db::name('grain_forecast')->where('gid', 'in', $gids)
->field('gid,tm_i,hm_i,tm_o,hm_o,observed_date')->order('id DESC')->select();
= [];
foreach ( as ) {
if (!isset([['gid']])) {
[['gid']] = [
'tm_i' => (float)['tm_i'],
'hm_i' => (float)['hm_i'],
'tm_o' => (float)['tm_o'],
'hm_o' => (float)['hm_o'],
'observed_date' => ['observed_date']
$envMap = [];
foreach ($envRecords as $rec) {
if (!isset($envMap[$rec['gid']])) {
$envMap[$rec['gid']] = [
'tm_i' => (float)$rec['tm_i'],
'hm_i' => (float)$rec['hm_i'],
'tm_o' => (float)$rec['tm_o'],
'hm_o' => (float)$rec['hm_o'],
'observed_date' => $rec['observed_date']
];
}
}
foreach ( as &) {
['last_env'] = isset([['id']]) ? [['id']] : null;
foreach ($granaries as &$g) {
$g['last_env'] = isset($envMap[$g['id']]) ? $envMap[$g['id']] : null;
}
unset();
unset($g);
}
return json(['code' => 200, 'list' => , 'total' => , 'granaries' => ]);
return json(['code' => 200, 'list' => $list, 'total' => $total, 'granaries' => $granaries]);
}
public function detail()
@@ -76,6 +76,38 @@ class Forecast extends GranaryBackend
});
}
public function edit($ids = null)
{
return $this->write(function ($service) use ($ids) {
$id = $this->request->post('id/d', $ids ?: 0);
$id = $service->update($id, $this->request->post(), $this->auth->id);
$service->generate($id);
return $id;
});
}
public function dell($ids = null)
{
if (!$this->request->isPost()) return json(['code' => 405, 'msg' => '请使用POST提交']);
$id = $this->request->post('id', $ids ?: $this->request->get('id'));
if (empty($id)) return json(['code' => 400, 'msg' => '请指定要删除的记录编号']);
try {
$service = new GrainForecast();
$service->delete($id);
return json(['code' => 200, 'msg' => '删除成功']);
} catch (\InvalidArgumentException $e) {
return json(['code' => 400, 'msg' => $e->getMessage()]);
} catch (\Exception $e) {
\think\Log::record('Grain forecast delete: ' . $e->getMessage(), 'error');
return json(['code' => 500, 'msg' => '删除失败,请刷新后重试']);
}
}
public function del($ids = null)
{
return $this->dell($ids);
}
public function retry()
{
return $this->write(function ($service) {