feat(forecast): 支持温湿度预测记录编辑与删除,修复组件调用并级联清理周期数据
这个提交包含在:
@@ -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) {
|
||||
|
||||
在新工单中引用
屏蔽一个用户