Some changes in communications with algorytm

This commit is contained in:
Artur 2024-10-11 14:00:21 +02:00
parent f70433dad6
commit 79a01ace1b
3 changed files with 49 additions and 31 deletions

View File

@ -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;
}
}

View File

@ -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;
}
}

View File

@ -1,2 +1,2 @@
spring.application.name=angular-services
server.port=8800
server.port=8801