|
@@ -2,8 +2,10 @@
|
|
|
|
|
|
namespace app\api\business;
|
|
|
|
|
|
+use app\api\exception\ApiException;
|
|
|
use app\api\model\Ccjc;
|
|
|
use app\api\model\Cyd;
|
|
|
+use app\api\model\SamplePesticides;
|
|
|
use app\api\model\TestPesticides;
|
|
|
|
|
|
class JcdBus
|
|
@@ -17,13 +19,32 @@ class JcdBus
|
|
|
return ['rows'=>$jcd_info,'total'=>$jcd_info_count];
|
|
|
}
|
|
|
|
|
|
- public function getModelItemBySampleID($sampel_id)
|
|
|
+ public function getJcdObjectItem($sampel_id)
|
|
|
{
|
|
|
//根据模型,需要先获取到task_id才能获取到model_id,最后获取检测项
|
|
|
$task_id = (new Cyd())->getCydInfoBySampleId($sampel_id)['task_id'];
|
|
|
$test_model_id = (new Ccjc())->getTaskInfoByTaskID($task_id)['test_model_id'];
|
|
|
- $model_item = (new TestPesticides())->getInfoByTestModelId($test_model_id);
|
|
|
- return $model_item;
|
|
|
+ $model_item = (new TestPesticides())->getInfoByTestModelId($test_model_id)->toArray();
|
|
|
+
|
|
|
+ //检索数据库中是否保存检测项信息,如果为空进行创建操作,如果存在进行读取操作
|
|
|
+ $data = [];
|
|
|
+ $data_num = 0;
|
|
|
+ $create_jcd_item=[];
|
|
|
+ foreach ($model_item as $k=>$v) {
|
|
|
+ //检索 是否存在,不存在则$item_is_set==null
|
|
|
+ $item_is_set = (new SamplePesticides())->getItemByTestIdAndSampleId($v['test_id'],$sampel_id);
|
|
|
+ if ($item_is_set==null){
|
|
|
+ $data[$k]['test_id'] = $v['test_id'];
|
|
|
+ $data[$k]['test_name'] = $v['test_name'];
|
|
|
+ $data[$k]['sample_id'] = $sampel_id;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //创建不存在的检测项
|
|
|
+ $create_jcd_item = (new SamplePesticides())->saveItem($data);
|
|
|
+ //获取检测单的信息
|
|
|
+ $item_info = (new SamplePesticides())->getItemBySampleId($sampel_id);
|
|
|
+
|
|
|
+ return $item_info;
|
|
|
}
|
|
|
|
|
|
//修改检测单状态,就是修改cyd表中的,test_status
|
|
@@ -37,7 +58,8 @@ class JcdBus
|
|
|
//保存检测单
|
|
|
public function saveJcdItem($sample_id, $pesticides){
|
|
|
//格式化数据
|
|
|
- $data = [];
|
|
|
+ $data = [];//需要保存的数据
|
|
|
+ $data_num =0;//一共有多少个需要保存的数据
|
|
|
foreach ($pesticides as $k0 =>$v0) {
|
|
|
$data [$k0]['test_name'] = $pesticides[$k0]['test_name'];
|
|
|
$data [$k0]['test_id'] = $pesticides[$k0]['test_id'];
|
|
@@ -49,9 +71,32 @@ class JcdBus
|
|
|
$data [$k0]['LOD'] = $pesticides[$k0]['LOD'];
|
|
|
$data [$k0]['LOQ'] = $pesticides[$k0]['LOQ'];
|
|
|
$data [$k0]['test_result'] = $pesticides[$k0]['test_result'];
|
|
|
+ $data [$k0]['enable_save'] = 1;//将enable_save置1,禁止后续修改
|
|
|
+ $data_num = $k0;
|
|
|
}
|
|
|
|
|
|
- return $data;
|
|
|
+ $disable_save_data=$enable_save_data=[];
|
|
|
+ //查找数据,如果enable_save==0,则无法保存,为null则可以保存
|
|
|
+
|
|
|
+ for ($i = 0; $i < ($data_num+1); $i++) {
|
|
|
+ $save_data = (new SamplePesticides())->getItemByTestIdAndSampleId($data[$i]['test_id'], $sample_id);
|
|
|
+
|
|
|
+ //如果enable_save为1不可以保存
|
|
|
+ if ($save_data['enable_save']==1) {
|
|
|
+ $disable_save_data[] = ['test_id' => $data[$i]['test_id'], 'sample_id' => $sample_id];
|
|
|
+ }
|
|
|
+ //如果enable_save为null可以保存
|
|
|
+ else if ($save_data['enable_save'] == null) {
|
|
|
+ (new SamplePesticides())->saveItemByTestIdAndSampleId($data[$i]['test_id'], $sample_id, $data[$i]);
|
|
|
+ $enable_save_data[] = ['test_id' => $data[$i]['test_id'], 'sample_id' => $sample_id];
|
|
|
+ }
|
|
|
+ else{
|
|
|
+ throw new ApiException(config('status.err_none_auth_upload_data'));
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return ['enable_upload_data'=>$enable_save_data,'disable_upload_data'=>$disable_save_data];
|
|
|
+
|
|
|
}
|
|
|
|
|
|
|