Advertisement
Guest User

Untitled

a guest
Jul 19th, 2019
560
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.44 KB | None | 0 0
  1. package com.albionstarterproject.controller;
  2.  
  3. import java.io.IOException;
  4. import java.util.HashMap;
  5. import java.util.Map;
  6.  
  7.  
  8. import org.json.JSONException;
  9. import org.springframework.stereotype.Controller;
  10. import org.springframework.ui.Model;
  11. import org.springframework.web.bind.annotation.GetMapping;
  12. import org.springframework.web.bind.annotation.RequestParam;
  13.  
  14. import com.albionstarterproject.service.GetPricesService;
  15.  
  16. @Controller
  17. public class T4HideRefineController {
  18.  
  19.    
  20.     @GetMapping("t4hide.html/calculate")
  21.     public String calculate(
  22.             @RequestParam(name = "returnRate") String returnRate,
  23.             @RequestParam(name = "amountOfRawMaterial") String amountOfRawMaterial,
  24.             @RequestParam(name = "priceOfRawMaterial") String priceOfRawMaterial,
  25.             @RequestParam(name = "amountOfRefinedResource") String amountOfRefinedResource,
  26.             @RequestParam(name = "priceOfRefinedResource") String priceOfRefinedResource,
  27.             @RequestParam(name = "refinedResourcePrice") String refinedResourcePrice,
  28.             @RequestParam(name = "totalRefined") String totalRefined, Model model) {
  29.  
  30.  
  31.         if (returnRate.equals(""))
  32.             returnRate = "15";
  33.         else if (Integer.parseInt(returnRate) > 55) {
  34.             totalRefined = "It is not possible to have " + returnRate + "% return rate!";
  35.         } else {
  36.             int amountOfRawMaterialInt = Integer.parseInt(amountOfRawMaterial);
  37.             while (amountOfRawMaterialInt % 4 != 0) amountOfRawMaterialInt--;
  38.             amountOfRawMaterialInt /= 4;
  39.             int total = amountOfRawMaterialInt;
  40.             int ret = Integer.parseInt(returnRate);
  41.             while (amountOfRawMaterialInt > 0) {
  42.                 amountOfRawMaterialInt = amountOfRawMaterialInt * ret / 100;
  43.                 total += amountOfRawMaterialInt;
  44.                
  45.             }
  46.             totalRefined = "" + total;
  47.             amountOfRefinedResource = totalRefined;
  48.         }
  49.         Map<String, String> map = new HashMap<>();
  50.         map.put("amountOfRawMaterial", amountOfRawMaterial);
  51.         map.put("priceOfRawMaterial", priceOfRawMaterial);
  52.         map.put("amountOfRefinedResource", amountOfRefinedResource);
  53.         map.put("priceOfRefinedResource", priceOfRefinedResource);
  54.         map.put("refinedResourcePrice", refinedResourcePrice);
  55.         map.put("totalRefined", totalRefined);
  56.         map.put("returnRate", returnRate);
  57.         model.addAllAttributes(map);
  58.        
  59.         model.addAttribute("profit", "34545");
  60.         model.addAttribute("spent", "34545");
  61.         model.addAttribute("income", "34545");
  62.        
  63.        
  64.        
  65.  
  66.         return "t4hide";
  67.     }
  68.  
  69.     @GetMapping("t4hide.html/getPrices")
  70.     public String getPrices(@RequestParam(name = "city") String city,
  71.             @RequestParam(name="rawMaterial") String rawMaterial,
  72.             @RequestParam(name="refinedMaterial") String refinedMaterial,
  73.             @RequestParam(name="refineResult") String refineResult,
  74.             @RequestParam(name="returnRate") String returnRate,
  75.             Model model) throws JSONException, IOException, InterruptedException {
  76.        
  77.         GetPricesService gps = new GetPricesService();
  78.        
  79.         if (city.equals("Fort Sterling")) city = "FortSterling";
  80.         model.addAttribute("priceOfRawMaterial", gps.getCityPrice("https://www.albion-online-data.com/api/v2/stats/prices/" + rawMaterial + "?locations=" + city));
  81.         model.addAttribute("priceOfRefinedResource", gps.getCityPrice("https://www.albion-online-data.com/api/v2/stats/prices/" + refinedMaterial + "?locations=" + city));
  82.         model.addAttribute("refinedResourcePrice", gps.getCityPrice("https://www.albion-online-data.com/api/v2/stats/prices/" + refineResult + "?locations=" + city));
  83.        
  84.        
  85.         System.out.println(returnRate);
  86.        
  87.  
  88.        
  89.         return "t4hide";
  90.     }
  91.  
  92. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement