Skip to content

Commit

Permalink
adjust to apply jdk17 and springboot3
Browse files Browse the repository at this point in the history
  • Loading branch information
significantfrank committed Apr 24, 2024
1 parent 335e5f3 commit 58a3e21
Show file tree
Hide file tree
Showing 14 changed files with 698 additions and 710 deletions.
25 changes: 8 additions & 17 deletions cola-samples/charge/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,14 @@
<version>1.0.0-SNAPSHOT</version>

<properties>
<maven.compiler.target>1.8</maven.compiler.target>
<maven.compiler.source>1.8</maven.compiler.source>
<java.version>17</java.version>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>

<springfox.version>3.0.0</springfox.version>
<archunit.version>1.0.1</archunit.version>
<spring.boot.version>2.3.8.RELEASE</spring.boot.version>
<archunit.version>1.3.0</archunit.version>
<spring.boot.version>3.1.0</spring.boot.version>
</properties>

<dependencyManagement>
Expand All @@ -35,20 +36,9 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
Expand All @@ -58,7 +48,7 @@
</dependency>
<dependency>
<groupId>com.tngtech.archunit</groupId>
<artifactId>archunit</artifactId>
<artifactId>archunit-junit5</artifactId>
<version>${archunit.version}</version>
<scope>test</scope>
</dependency>
Expand All @@ -69,6 +59,7 @@
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>8.0.33</version>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

import com.huawei.charging.application.ChargeServiceI;
import com.huawei.charging.application.dto.*;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@Slf4j
Expand Down
Original file line number Diff line number Diff line change
@@ -1,90 +1,90 @@
package com.huawei.charging.application;

import com.huawei.charging.application.dto.*;
import com.huawei.charging.domain.account.Account;
import com.huawei.charging.domain.account.AccountDomainService;
import com.huawei.charging.domain.charge.CallType;
import com.huawei.charging.domain.charge.ChargeContext;
import com.huawei.charging.domain.charge.ChargeRecord;
import com.huawei.charging.domain.charge.Session;
import com.huawei.charging.domain.gateway.AccountGateway;
import com.huawei.charging.domain.gateway.ChargeGateway;
import com.huawei.charging.domain.gateway.SessionGateway;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

@Service
@Slf4j
public class ChargeServiceImpl implements ChargeServiceI {

@Resource
private SessionGateway sessionGateway;

@Resource
private AccountGateway accountGateway;

@Resource
private AccountDomainService accountDomainService;

@Resource
private ChargeGateway chargeGateway;

@Override
public Response begin(BeginSessionRequest request) {
Session session = request.toSession();
accountDomainService.canSessionStart(session);
sessionGateway.create(session);
log.debug("Session created successfully :" + session);
return Response.buildSuccess();
}

@Override
public Response charge(ChargeRequest request) {
log.debug("Do charge : " + request);
Session session = sessionGateway.get(request.getSessionId());
int durationToCharge = request.getDuration() - session.getChargedDuration();
List<ChargeRecord> chargeRecordList = new ArrayList<>();
chargeCalling(session, durationToCharge, chargeRecordList);
chargeCalled(session, durationToCharge, chargeRecordList);
chargeGateway.saveAll(chargeRecordList);
session.setChargedDuration(request.getDuration());
return Response.buildSuccess();
}

private void chargeCalling(Session session, int durationToCharge, List<ChargeRecord> chargeRecordList) {
Account callingAccount = accountGateway.getAccount(session.getCallingPhoneNo());
ChargeContext callingCtx = new ChargeContext(CallType.CALLING, session.getCallingPhoneNo(), session.getCalledPhoneNo(), durationToCharge);
callingCtx.session = session;
callingCtx.account = callingAccount;
chargeRecordList.addAll(callingAccount.charge(callingCtx));
}

private void chargeCalled(Session session, int durationToCharge, List<ChargeRecord> chargeRecordList) {
Account calledAccount = accountGateway.getAccount(session.getCalledPhoneNo());
ChargeContext calledCtx = new ChargeContext(CallType.CALLED, session.getCalledPhoneNo(), session.getCallingPhoneNo(), durationToCharge);
calledCtx.session = session;
calledCtx.account = calledAccount;
chargeRecordList.addAll(calledAccount.charge(calledCtx));
}

@Override
public Response end(EndSessionRequest request) {
charge(request.toChargeRequest());
sessionGateway.end(request.getSessionId());
return Response.buildSuccess();
}

@Override
public MultiResponse<ChargeRecordDto> listChargeRecords(String sessionId) {
List<ChargeRecord> chargeRecordList = chargeGateway.findBySessionId(sessionId);
List<ChargeRecordDto> chargeRecordDtoList = new ArrayList<>();
for (ChargeRecord chargeRecord : chargeRecordList) {
chargeRecordDtoList.add(ChargeRecordDto.fromEntity(chargeRecord));
}
return MultiResponse.of(chargeRecordDtoList);
}
}
package com.huawei.charging.application;

import com.huawei.charging.application.dto.*;
import com.huawei.charging.domain.account.Account;
import com.huawei.charging.domain.account.AccountDomainService;
import com.huawei.charging.domain.charge.CallType;
import com.huawei.charging.domain.charge.ChargeContext;
import com.huawei.charging.domain.charge.ChargeRecord;
import com.huawei.charging.domain.charge.Session;
import com.huawei.charging.domain.gateway.AccountGateway;
import com.huawei.charging.domain.gateway.ChargeGateway;
import com.huawei.charging.domain.gateway.SessionGateway;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
@Slf4j
public class ChargeServiceImpl implements ChargeServiceI {

@Resource
private SessionGateway sessionGateway;

@Resource
private AccountGateway accountGateway;

@Resource
private AccountDomainService accountDomainService;

@Resource
private ChargeGateway chargeGateway;

@Override
public Response begin(BeginSessionRequest request) {
Session session = request.toSession();
accountDomainService.canSessionStart(session);
sessionGateway.create(session);
log.debug("Session created successfully :" + session);
return Response.buildSuccess();
}

@Override
public Response charge(ChargeRequest request) {
log.debug("Do charge : " + request);
Session session = sessionGateway.get(request.getSessionId());
int durationToCharge = request.getDuration() - session.getChargedDuration();
List<ChargeRecord> chargeRecordList = new ArrayList<>();
chargeCalling(session, durationToCharge, chargeRecordList);
chargeCalled(session, durationToCharge, chargeRecordList);
chargeGateway.saveAll(chargeRecordList);
session.setChargedDuration(request.getDuration());
return Response.buildSuccess();
}

private void chargeCalling(Session session, int durationToCharge, List<ChargeRecord> chargeRecordList) {
Account callingAccount = accountGateway.getAccount(session.getCallingPhoneNo());
ChargeContext callingCtx = new ChargeContext(CallType.CALLING, session.getCallingPhoneNo(), session.getCalledPhoneNo(), durationToCharge);
callingCtx.session = session;
callingCtx.account = callingAccount;
chargeRecordList.addAll(callingAccount.charge(callingCtx));
}

private void chargeCalled(Session session, int durationToCharge, List<ChargeRecord> chargeRecordList) {
Account calledAccount = accountGateway.getAccount(session.getCalledPhoneNo());
ChargeContext calledCtx = new ChargeContext(CallType.CALLED, session.getCalledPhoneNo(), session.getCallingPhoneNo(), durationToCharge);
calledCtx.session = session;
calledCtx.account = calledAccount;
chargeRecordList.addAll(calledAccount.charge(calledCtx));
}

@Override
public Response end(EndSessionRequest request) {
charge(request.toChargeRequest());
sessionGateway.end(request.getSessionId());
return Response.buildSuccess();
}

@Override
public MultiResponse<ChargeRecordDto> listChargeRecords(String sessionId) {
List<ChargeRecord> chargeRecordList = chargeGateway.findBySessionId(sessionId);
List<ChargeRecordDto> chargeRecordDtoList = new ArrayList<>();
for (ChargeRecord chargeRecord : chargeRecordList) {
chargeRecordDtoList.add(ChargeRecordDto.fromEntity(chargeRecord));
}
return MultiResponse.of(chargeRecordDtoList);
}
}
Loading

0 comments on commit 58a3e21

Please sign in to comment.