Sfoglia il codice sorgente

Before a new Assignment is insertet a duplication check is performed

Manuel Gall 3 anni fa
parent
commit
6f6f419325
3 ha cambiato i file con 594 aggiunte e 22 eliminazioni
  1. 552 1
      server/json/Rectangle.json
  2. 40 19
      server/was.rb
  3. 2 2
      ui/imageSlicer.php

File diff suppressed because it is too large
+ 552 - 1
server/json/Rectangle.json


+ 40 - 19
server/was.rb

@@ -792,7 +792,13 @@ class SaveNewAssignment < Riddl::Implementation
       id = result[0][0] +1
     end
      
-    #puts form
+    #bring given pattern into correct string (initially pattern could be in different order than required)
+    pattern = [];
+    fullcode = JSON.parse( File.read(File.join(File.dirname(__dir__),"server/json/ProductCode.json")))
+    fullcode["pattern"].each do |child|
+      pattern.push(form["parts"][child["abk"]])
+    end
+    
 
     checkimage = $db.execute "SELECT * FROM assignments WHERE image = '#{form["img"]}'"
     #if image not stored create new assignment with pattern, otherwise only add pattern
@@ -815,13 +821,17 @@ class SaveNewAssignment < Riddl::Implementation
         maxID = maxID[0][0] +1
       end
       
-      form["parts"].each{ |key,val|
-          $db.execute("INSERT INTO patternassignments (ID, AssID, type, value) VALUES (?,?,?,?)", [checkimage[0][0], maxID, key, val])
-      }
-      $db.execute("INSERT INTO patternassignments (ID, AssID, type, value) VALUES (?,?,?,?)", [checkimage[0][0], maxID, "STATION", form["station"]])
-      $db.execute("INSERT INTO patternassignments (ID, AssID, type, value) VALUES (?,?,?,?)", [checkimage[0][0], maxID, "TEXT", form["assignmentText"]])
-      
-      ret = {:id => checkimage[0][0]}
+      #Search 4 assignment if none found add assignment
+      #pp ListAssignmentSearch::prepare(@a[0][:appconf]["wasurl"], pattern.join('.'), form["station"], form["assignmentText"])
+      if (!ListAssignmentSearch::prepare(@a[0][:appconf]["wasurl"], pattern.join('.'), form["station"], form["assignmentText"]).any?)   
+        form["parts"].each{ |key,val|
+            $db.execute("INSERT INTO patternassignments (ID, AssID, type, value) VALUES (?,?,?,?)", [checkimage[0][0], maxID, key, val])
+        }
+        $db.execute("INSERT INTO patternassignments (ID, AssID, type, value) VALUES (?,?,?,?)", [checkimage[0][0], maxID, "STATION", form["station"]])
+        $db.execute("INSERT INTO patternassignments (ID, AssID, type, value) VALUES (?,?,?,?)", [checkimage[0][0], maxID, "TEXT", form["assignmentText"]])
+        
+        ret = {:id => checkimage[0][0]}
+      end
       Riddl::Parameter::Complex.new('list','application/json',JSON::pretty_generate(ret))
     end
   end
@@ -878,10 +888,11 @@ class DeleteSingleAssignment < Riddl::Implementation
 end
 
 class ListAssignmentSearch < Riddl::Implementation
-  def response
   
+  
+    def self::prepare(appconf, pat, pat_station, pat_value)
     #https://centurio.work/customers/evva/was/ui/TransformProductCode.php?ProductCode=E.A.PZ.DZ-S.31.31.MP.SEP
-    pattern = JSON.parse(Net::HTTP.get URI(@a[0][:appconf]["wasurl"] + "ui/TransformProductCode.php?ProductCode=" + @p[0].value))
+    pattern = JSON.parse(Net::HTTP.get URI(appconf + "ui/TransformProductCode.php?ProductCode=" + pat))
     
     #remove empty entries from pattern
     pattern.each do |key, value|
@@ -931,21 +942,26 @@ class ListAssignmentSearch < Riddl::Implementation
       searchstring = searchstring + " AND " + pattern.keys[0] + ".ID == ValText.ID"   
       
       
-      searchstring = searchstring + " AND STATION.type == 'STATION'" + " AND STATION.value == '" + @p[1].value + "'"
-      searchstring = searchstring + " AND ValText.type == 'TEXT'"  + " AND ValText.value == '" + @p[2].value + "'"
-      
- 
+      searchstring = searchstring + " AND STATION.type == 'STATION'" + " AND STATION.value == '" + pat_station + "'"
+      searchstring = searchstring + " AND ValText.type == 'TEXT'"  + " AND ValText.value == '" + pat_value + "'"
       
       
-      searchstring = searchstring + " AND " + pattern.map{ |key, val| key + ".type == '" + key + "' AND (" + key + ".value == '"+ val +"' or " + key + ".value == '*' or " + key + ".value == '')"}.join(' AND ') + " ORDER BY ID ASC" 
+      searchstring = searchstring + " AND " + pattern.map{ |key, val|
+        #In case a value has the option "KeineAngabe" empty values are allowed
+        if(val.start_with?("KeineAngabe"))
+          key + ".type == '" + key + "' AND (" + key + ".value == '"+ val +"' or " + key + ".value == '*' or " + key + ".value == '')"
+        else
+          key + ".type == '" + key + "' AND (" + key + ".value == '"+ val +"' or " + key + ".value == '*')"
+        end
+        }.join(' AND ') + " ORDER BY ID ASC" 
       
       #puts searchstring;
     else
       searchstring = "SELECT * FROM "
       searchstring = searchstring + "patternassignments STATION , patternassignments ValText"
       searchstring = searchstring + " WHERE"    
-      searchstring = searchstring + " STATION.type == 'STATION'" + " AND STATION.value == '" + @p[1].value + "'"
-      searchstring = searchstring + " AND ValText.type == 'TEXT'"  + " AND ValText.value == '" + @p[2].value + "'"
+      searchstring = searchstring + " STATION.type == 'STATION'" + " AND STATION.value == '" + pat_station + "'"
+      searchstring = searchstring + " AND ValText.type == 'TEXT'"  + " AND ValText.value == '" + pat_value + "'"
       searchstring = searchstring + " AND ValText.AssID == STATION.AssID"
       searchstring = searchstring + " ORDER BY ID ASC"
     end
@@ -965,7 +981,12 @@ class ListAssignmentSearch < Riddl::Implementation
         end
       end
     end
-    
+    return ret
+
+  end
+  
+  def response
+    ret = ListAssignmentSearch::prepare(@a[0][:appconf]["wasurl"], @p[0].value, @p[1].value, @p[2].value)
     Riddl::Parameter::Complex.new('list','application/json',JSON::pretty_generate(ret))
   end
 end
@@ -1080,7 +1101,7 @@ server = Riddl::Server.new(File.join(__dir__,'/was.xml'), :host => 'localhost')
     end
     on resource 'assignments' do
       run GetAssignments if get
-      run SaveNewAssignment if post 'list'
+      run SaveNewAssignment, opts if post 'list'
       on resource 'search' do
         run ListAssignmentSearch, opts if get
       end

+ 2 - 2
ui/imageSlicer.php

@@ -44,9 +44,9 @@
         
         //check if file exists if so, create file with other name and return as json
         if(file_exists($filename)) {
-          $asocarray[$counter]["old"] = $filename;
+          $asocarray["override"][$counter]["old"] = $filename;
           $filename = $savelocation . "zwischen" . $counter . ".jpg";
-          $asocarray[$counter]["new"] = $filename;
+          $asocarray["override"][$counter]["new"] = $filename;
         }
       
         //echo $filename;