From 79a01ace1b9c66076d3772b98e4d0ecd00f8d38e Mon Sep 17 00:00:00 2001 From: Artur Date: Fri, 11 Oct 2024 14:00:21 +0200 Subject: [PATCH] Some changes in communications with algorytm --- .../assets/services/AssetFromAngular.java | 51 +++++++++++++++++-- .../artikus/assets/services/AssetService.java | 27 +--------- src/main/resources/application.properties | 2 +- 3 files changed, 49 insertions(+), 31 deletions(-) diff --git a/src/main/java/tk/artikus/assets/services/AssetFromAngular.java b/src/main/java/tk/artikus/assets/services/AssetFromAngular.java index 6355b60..2ba4004 100644 --- a/src/main/java/tk/artikus/assets/services/AssetFromAngular.java +++ b/src/main/java/tk/artikus/assets/services/AssetFromAngular.java @@ -1,12 +1,53 @@ package tk.artikus.assets.services; import lombok.Data; +import tk.artikus.assets.Asset; +import tk.artikus.assets.AssetDepreciationMethod; +import tk.artikus.assets.AssetLife; +import tk.artikus.assets.AssetLifeChange; +import tk.artikus.assets.tools.YearMonth; @Data public class AssetFromAngular { - String initialValueAsset; - String depreciationRate; - int year ; - int month ; - int factorValue; + + String initialValueAsset; + + int year; + int month; + AssetDepreciationMethod.Type type; + String depreciationRate; + String factorValue; + + Asset toAsset() { + + Asset asset = new Asset(); + AssetLife assetLife = new AssetLife(); + + YearMonth yearMonth = YearMonth.builder().year( year ).month( month ).build(); + asset.setStartOfDepreciation( yearMonth ); + + long lDepreciation = txtToLong( depreciationRate ); + long lFactor = txtToLong( factorValue ); + AssetDepreciationMethod assetDepreciationMethod = AssetDepreciationMethod.builder().type( type ) + .factor( 0, lFactor ).rate( 0, lDepreciation ).build(); + + asset.setFromYearDepreciationMethod( yearMonth.getYear(), assetDepreciationMethod ); + + long initialValue = txtToLong( initialValueAsset ); + + AssetLifeChange assetLifeChange = new AssetLifeChange( yearMonth.prev(), initialValue, 0, 0 ); + assetLife.registerChange( assetLifeChange ); + + asset.setLife( assetLife ); + + return asset; + } + + private long txtToLong( String value ) { + value = value.replace( ",", "" ); + float fInitial = Float.parseFloat( value ); + long lValue = (long) (fInitial * 100); + return lValue; + } + } diff --git a/src/main/java/tk/artikus/assets/services/AssetService.java b/src/main/java/tk/artikus/assets/services/AssetService.java index 30bbfb2..3e115fc 100644 --- a/src/main/java/tk/artikus/assets/services/AssetService.java +++ b/src/main/java/tk/artikus/assets/services/AssetService.java @@ -1,6 +1,5 @@ package tk.artikus.assets.services; -import java.math.BigDecimal; import java.util.Collection; import org.springframework.web.bind.annotation.CrossOrigin; @@ -12,12 +11,9 @@ import org.springframework.web.bind.annotation.RestController; import tk.artikus.assets.Asset; import tk.artikus.assets.AssetDepreciationAlgorithm; -import tk.artikus.assets.AssetDepreciationMethod; import tk.artikus.assets.AssetLife; -import tk.artikus.assets.AssetLifeChange; import tk.artikus.assets.AssetPlan; import tk.artikus.assets.AssetPlanPosition; -import tk.artikus.assets.tools.YearMonth; @RestController @RequestMapping(path = "/rest-api/assets/") @@ -28,21 +24,9 @@ public class AssetService { @ResponseBody public AssetDeprecations postResponseController(@RequestBody AssetFromAngular assetFromAngular) { - Asset asset = new Asset(); - AssetLife assetLife = new AssetLife(); - YearMonth yearMonth = YearMonth.builder().year(assetFromAngular.year).month(assetFromAngular.month).build(); - asset.setStartOfDepreciation(yearMonth); - - long lDepreciation = txtToLong( assetFromAngular.getDepreciationRate()); - AssetDepreciationMethod assetDepreciationMethod = AssetDepreciationMethod.builder() - .linear().factor(assetFromAngular.factorValue).rate( 0, lDepreciation ).build(); - asset.setFromYearDepreciationMethod(yearMonth.getYear(), assetDepreciationMethod ); - - long initialValue = txtToLong(assetFromAngular.getInitialValueAsset() ); - AssetLifeChange assetLifeChange = new AssetLifeChange(yearMonth, initialValue, 0, 0); - assetLife.registerChange(assetLifeChange); - asset.setLife(assetLife); + Asset asset = assetFromAngular.toAsset(); + AssetLife assetLife = asset.getLife(); AssetPlan assetPlan = new AssetPlan(); new AssetDepreciationAlgorithm( asset, assetLife, assetPlan ).calculate(); @@ -50,12 +34,5 @@ public class AssetService { return new AssetDeprecations(positions); } - private long txtToLong(String value) { - value = value.replace(",", ""); - float fInitial = Float.parseFloat(value); - long lValue = (long) (fInitial * 100); - return lValue; -} - } diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index 7f4cf9a..0b6026d 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -1,2 +1,2 @@ spring.application.name=angular-services -server.port=8800 \ No newline at end of file +server.port=8801 \ No newline at end of file