Browse Source

‘新增txt修改接口’

曹鹤洋 2 years ago
parent
commit
72cc4a1a80
1 changed files with 182 additions and 1 deletions
  1. 182 1
      application/api/controller/Index.php

+ 182 - 1
application/api/controller/Index.php

@@ -22,7 +22,10 @@ class Index extends Api
         $this->success('请求成功');
         $this->success('请求成功');
     }
     }
 
 
-    //vocs
+    /**
+     * vocs
+     * 创建
+     */
     public function vocs()
     public function vocs()
     {
     {
         $req=$this->request->param();
         $req=$this->request->param();
@@ -186,4 +189,182 @@ class Index extends Api
 
 
         }
         }
     }
     }
+
+    /**
+     * vocs
+     * 修改
+     */
+    public function updateVocs()
+    {
+        $req=$this->request->param();
+        Log::record($req);
+
+        if($req[0]=='C'){
+            $time = date('Y/m/d H:i:s');
+            $res = [
+                'data_txt_name'             => trim(substr($req[1],strripos($req[1],'\\')+1)),
+                'name'                      => trim(substr($req[2],stripos($req[2],':')+1)),
+                'remak'                     => trim($req[3]),
+                'author'                    => trim(substr($req[4],stripos($req[4],':')+1,strripos($req[4],'序列号')-1-stripos($req[4],':'))),
+                'line'                      => trim(substr($req[4],strripos($req[4],':')+1)),
+                'instrument'                => trim(substr($req[5],stripos($req[5],':')+1,strripos($req[5],'位置')-1-stripos($req[5],':'))),
+                'position'                  => trim(substr($req[5],strripos($req[5],':')+1)),
+                'in_date'                   => trim(substr($req[6],stripos($req[6],':')+1,strripos($req[6],'进样次数')-1-stripos($req[6],':'))),
+                'in_times'                  => trim(substr($req[6],strripos($req[6],':')+1)),
+                'in_type'                   => trim(substr($req[7],stripos($req[7],':')+1)),
+                'gather_method'             => trim(substr($req[8],stripos($req[8],':')+1)),
+                'update_date_one'           => trim(substr($req[9],stripos($req[9],':')+1)),
+                'analysis_method'           => trim(substr($req[10],stripos($req[10],':')+1)),
+                'update_date_two'           => trim(substr($req[11],stripos($req[11],':')+1)),
+                'method_info'               => trim(substr($req[12],stripos($req[12],':')+1)),
+                'sort'                      => trim(substr($req[13],stripos($req[13],':')+1)),
+                'check_data_time'           => trim(substr($req[14],stripos($req[14],':')+1)),
+                'sample_product_factor'     => trim(substr($req[15],strripos($req[15],':')+1)),
+                'dilution_factor'           => trim(substr($req[16],strripos($req[16],':')+1)),
+                'signal_one'                => trim(substr($req[17],stripos($req[17],':')+1)),
+                'create'                    => $time,
+            ];
+
+            $id = db()->name('vocs_gather_txt_gc')->field('id')->where('data_txt_name',$res['data_txt_name'])->find();
+
+            if($id){
+                //开启事务
+                db()->startTrans();
+                try {
+                    //根据id修改主表数据
+                    $bool = db()->name('vocs_gather_txt_gc')->where('id',$id['id'])->update($res);
+                    if($bool){
+                        //根据pid删除子表数据
+                        db()->name('vocs_gather_txt_check_gc')->where('pid',$id['id'])->delete();
+
+                        //根据id新增子表数据
+                        $row = [];
+                        $j = 0;
+                        for($i = 18; $i < count($req); $i++){
+                            $str = trim($req[$i]);
+                            $arr = preg_split('/\s+/', $str);
+                            if (count($arr)==6){
+                                $row[$j]['pid'] = $id['id'];
+                                $row[$j]['time'] = $arr[0];
+                                $row[$j]['type'] = $arr[1];
+                                $row[$j]['peak_area'] = $arr[2];
+                                ($arr[3] == '-')?$row[$j]['val'] = '-':$row[$j]['val'] = floatval($arr[3]);
+                                ($arr[4] == '-')?$row[$j]['potency'] = '-':$row[$j]['potency'] = floatval($arr[4]);
+                                $row[$j]['chemical_compound'] = $arr[5];
+                                $row[$j]['create'] = $time;
+                            }else{
+                                $row[$j]['pid'] = $id['id'];
+                                $row[$j]['time'] = $arr[0];
+                                $row[$j]['type'] = '';
+                                $row[$j]['peak_area'] = $arr[1];
+                                ($arr[3] == '-')?$row[$j]['val'] = '-':$row[$j]['val'] = floatval($arr[2]);
+                                ($arr[4] == '-')?$row[$j]['potency'] = '-':$row[$j]['potency'] = floatval($arr[3]);
+                                $row[$j]['chemical_compound'] = $arr[4];
+                                $row[$j]['create'] = $time;
+                            }
+                            $j++;
+                        }
+
+                        //将检测数据插入子表vocs_gather_txt_check_gc
+                        db()->name('vocs_gather_txt_check_gc')->insertAll($row);
+                        //提交事务
+                        db()->commit();
+                        return json_encode(['code'=>'0','msg'=>'修改成功','time'=>$time,'data'=>[$res,$row]]);
+                    }
+
+
+                } catch (\Exception $e){
+                    //失败回滚
+                    db()->rollback();
+                    Log::record($e->getMessage());
+                    return $e->getMessage();
+                }
+            }else{
+                return '找不到记录';
+            }
+
+        }else{
+            $string = trim(substr($req[1],stripos($req[1],':')+1));
+            $bach = '';
+            if (preg_match('/\d+$/', $string, $matches)) {
+                $bach = $matches[0];
+            }
+            $name = str_replace($bach,'',$string);
+            $time = date('Y/m/d H:i:s');
+            $res = [
+                'data_txt_name'             => trim(substr($req[2],strripos($req[2],':')+1)),
+                'name'                      => $name,
+                'bach'                      => $bach,
+                'gather_time'               => trim(substr($req[3],stripos($req[3],':')+1)),
+                'data_txt_path'             => trim(substr($req[4],stripos($req[4],':')+1)),
+                'ALS'                       => trim(substr($req[5],stripos($req[5],':')+1,strripos($req[5],'样品乘积因子')-1-stripos($req[5],':'))),
+                'sample_product_factor'     => trim(substr($req[5],strripos($req[5],':')+1)),
+                'author'                    => trim(substr($req[6],stripos($req[6],':')+1)),
+                'other'                     => trim(substr($req[7],stripos($req[7],':')+1)),
+                'title'                     => trim(substr($req[8],stripos($req[8],':')+1)),
+                'quantify_time'             => trim(substr($req[9],stripos($req[9],':')+1)),
+                'quantify_method'           => trim(substr($req[10],stripos($req[10],':')+1)),
+                'last_quantify_time'        => trim(substr($req[11],stripos($req[11],':')+1)),
+                'response'                  => trim(substr($req[12],stripos($req[12],':')+1)),
+                'machine'                   => 1,
+                'create'                    => $time,
+            ];
+
+            $id = db()->name('vocs_gather_txt_gcms')->field('id')->where('data_txt_name',$res['data_txt_name'])->find();
+            if($id){
+                //开启事务
+                db()->startTrans();
+                try {
+                    //根据id修改主表数据
+                    $bool = db()->name('vocs_gather_txt_gcms')->where('id',$id['id'])->update($res);
+                    if($bool) {
+                        //根据pid删除子表数据
+                        db()->name('vocs_gather_txt_check_gcms')->where('pid', $id['id'])->delete();
+
+                        //根据id新增子表数据
+                        $row = [];
+                        $j = 0;
+                        for($i = 13; $i < count($req); $i++){
+                            $str = trim($req[$i]);
+                            $arr = preg_split('/\s+/', $str);
+                            if (count($arr)==8){
+                                $row[$j]['pid'] = $id['id'];
+                                $row[$j]['chemical_compound'] = $arr[1];
+                                $row[$j]['persist_time'] = $arr[2];
+                                $row[$j]['quantitative_ion'] = $arr[3];
+                                $row[$j]['response_value'] = $arr[4];
+                                $row[$j]['potency'] = $arr[5];
+                                $row[$j]['unit'] = $arr[6];
+                                $row[$j]['quanlitative_ion'] = $arr[7];
+                                $row[$j]['create'] = $time;
+                            }else{
+                                $row[$j]['pid'] = $id['id'];
+                                $row[$j]['chemical_compound'] = $arr[1];
+                                $row[$j]['persist_time'] = $arr[2];
+                                $row[$j]['quantitative_ion'] = $arr[3];
+                                $row[$j]['response_value'] = $arr[3];
+                                $row[$j]['potency'] = $arr[3];
+                                $row[$j]['unit'] = $arr[3];
+                                $row[$j]['quanlitative_ion'] = $arr[3];
+                                $row[$j]['create'] = $time;
+                            }
+                            $j++;
+                        }
+                        //将检测数据插入子表vocs_gather_txt_check_gc
+                        db()->name('vocs_gather_txt_check_gcms')->insertAll($row);
+                        //提交事务
+                        db()->commit();
+                        return json_encode(['code'=>'0','msg'=>'修改成功','time'=>$time,'data'=>[$res,$row]]);
+                    }
+                } catch (\Exception $e){
+                    //失败回滚
+                    db()->rollback();
+                    Log::record($e->getMessage());
+                    return $e->getMessage();
+                }
+            }else{
+                return '找不到记录';
+            }
+        }
+    }
 }
 }