Merge branch 'feature/SCDD-220' into feature/SCDD-222-화면-데이터-api-개발

# Conflicts:
#	src/main/java/inc/sdt/controlcentermanagement/application/SlotRepositoryDelegate.java
#	src/main/java/inc/sdt/controlcentermanagement/infrastructure/nosql/SlotNoSQLRepository.java
#	src/main/java/inc/sdt/controlcentermanagement/infrastructure/nosql/SlotRepository.java
This commit is contained in:
ihyeon-yong 2023-09-11 09:43:05 +09:00
commit a97246b692
13 changed files with 214 additions and 7 deletions

View File

@ -5,7 +5,7 @@ plugins {
}
group = 'inc.sdt.controlcentermanagement'
version = '0.0.1'
version = '0.0.2'
java {
sourceCompatibility = '17'

View File

@ -1,4 +1,4 @@
aws ecr get-login-password --region ap-northeast-2 | docker login --username AWS --password-stdin 003960268191.dkr.ecr.ap-northeast-2.amazonaws.com
docker build --platform linux/amd64 -t control-center-management ../../
docker tag control-center-management:latest 003960268191.dkr.ecr.ap-northeast-2.amazonaws.com/sdt-cloud/control-center-management:0.0.1
docker push 003960268191.dkr.ecr.ap-northeast-2.amazonaws.com/sdt-cloud/control-center-management:0.0.1
docker tag control-center-management:latest 003960268191.dkr.ecr.ap-northeast-2.amazonaws.com/sdt-cloud/control-center-management:0.0.2
docker push 003960268191.dkr.ecr.ap-northeast-2.amazonaws.com/sdt-cloud/control-center-management:0.0.2

View File

@ -28,7 +28,7 @@ spec:
host: control-center-management.sdt-cloud.svc.cluster.local
match:
- uri:
prefix: "/chamber"
prefix: "/chambers"
corsPolicy:
maxAge: 1m
allowCredentials: true

View File

@ -5,6 +5,8 @@ PATCH http://13.209.39.139:32171/chamber/1/tube/toggle
Content-Type: application/json
Authorization: Bearer eyJhbGciOiJIUzI1NiJ9.eyJvcmdhbml6YXRpb25JZCI6ImQxZGJlYWExLWY5ZTUtNGE4OC1hMWM4LTYzMWQ4NTMyOWJmYyIsInJvbGVzIjpbIlJPTEVfQURNSU5JU1RSQVRPUiJdLCJpZCI6IjcyYTUxZDUwLTYwMDEtNDAwYy04NjNmLWZlOGU2OGE1MGExMCIsInN1YiI6InNhLmphbmdAc2R0LmluYyIsImlhdCI6MTY5NDEzNjg4OCwiZXhwIjoxNjk0MTQwNDg4fQ.likh7Ix7p4Yf2iwankLG71VGrgCDzQzhn9Z7QJK0blg
{"command": "ON"}
//{
// "command" : "OFF",
// "assetCode" : "NODEQ-TEST-1",
@ -14,4 +16,14 @@ Authorization: Bearer eyJhbGciOiJIUzI1NiJ9.eyJvcmdhbml6YXRpb25JZCI6ImQxZGJlYWExL
// ]
//}
{"command": "ON"}
### offset 제어
#PATCH http://localhost:8087/chambers/1/slots/1/tubes/1
PATCH http://13.209.39.139:32171/chambers/1/slots/1/tubes/1
Content-Type: application/json
Authorization: Bearer eyJhbGciOiJIUzI1NiJ9.eyJvcmdhbml6YXRpb25JZCI6ImQxZGJlYWExLWY5ZTUtNGE4OC1hMWM4LTYzMWQ4NTMyOWJmYyIsInJvbGVzIjpbIlJPTEVfQURNSU5JU1RSQVRPUiJdLCJpZCI6IjcyYTUxZDUwLTYwMDEtNDAwYy04NjNmLWZlOGU2OGE1MGExMCIsInN1YiI6InNhLmphbmdAc2R0LmluYyIsImlhdCI6MTY5NDE2NTE2NywiZXhwIjoxNjk0MTY4NzY3fQ.bNmcz1I-zGQHZLFS6h6lp0FgI4WwKppNdHEYUp9hiFc
{
"voltageOffset" : 1.5,
"ampereOffset": 1.1
}

View File

@ -37,6 +37,12 @@ class DefaultTubeService implements TubeService {
return slotRepositoryDelegate.get(chamberNumber);
}
@Override
public Slot get(String chamberNumber, String slotNumber) {
log.info("[get] chamberNumber: {}, slotNumber: {}", chamberNumber, slotNumber);
return slotRepositoryDelegate.get(chamberNumber, slotNumber);
}
@Override
public void controlByTubeCode(String authorization, Slot request) {
log.info("[controlByTubeCode] request: {}", request);
@ -93,6 +99,41 @@ class DefaultTubeService implements TubeService {
}));
}
@Override
public void adjustOffset(Slot slot, String code, Tube request) {
log.info("[adjustOffset] slot: {}, tube: {}", slot, request);
Slot slotData = this.get(slot.getChamberNumber(), slot.getSlotNumber());
Map<String, Tube> tubeMap = new LinkedHashMap<>();
slotData.getTube().forEach(tube -> tubeMap.put(tube.getCode(), tube));
Float oldVoltageOffset = null;
Float oldAmpereOffset = null;
for (Tube tube : slotData.getTube()) {
if (tube.getCode().equals(code)) {
oldVoltageOffset = tube.getVoltageOffset();
oldAmpereOffset = tube.getAmpereOffset();
}
}
Tube tube = Tube.builder()
.code(code)
.voltageOffset(request.getVoltageOffset() == null ? oldVoltageOffset : request.getVoltageOffset())
.ampereOffset(request.getAmpereOffset() == null ? oldAmpereOffset : request.getAmpereOffset())
.build();
tubeMap.put(code, tube);
List<Tube> list = tubeMap.values().stream().toList();
Slot param = Slot.builder()
.id(slotData.getId())
.assetCode(slotData.getAssetCode())
.chamberNumber(slot.getChamberNumber())
.slotNumber(slot.getSlotNumber())
.tube(list)
.build();
slotRepositoryDelegate.update(param);
}
private Map<String, Integer> tubeOffset() {
int offset = 0;
Map<String, Integer> tubeOffsetMap = new HashMap<>();

View File

@ -11,4 +11,6 @@ public interface SlotRepositoryDelegate {
List<Slot> get(String chamberNumber);
List<Slot> getAll();
Slot get(String chamberNumber, String slotNumber);
void update(Slot slot);
}

View File

@ -2,6 +2,7 @@ package inc.sdt.controlcentermanagement.application;
import inc.sdt.controlcentermanagement.domain.Command;
import inc.sdt.controlcentermanagement.domain.Slot;
import inc.sdt.controlcentermanagement.domain.Tube;
import java.util.List;
@ -10,6 +11,8 @@ import java.util.List;
*/
public interface TubeService {
List<Slot> get(String chamberNumber);
Slot get(String chamberNumber, String slotNumber);
void controlByTubeCode(String authorization, Slot request);
void controlAll(String authorization, List<Slot> slots, Command command);
void adjustOffset(Slot slot, String code, Tube tube);
}

View File

@ -36,4 +36,36 @@ public class Tube {
", ampereOffset=" + ampereOffset +
'}';
}
public static Builder builder() {
return new Builder();
}
public static final class Builder {
private String code;
private Float voltageOffset;
private Float ampereOffset;
private Builder() {
}
public Builder code(String code) {
this.code = code;
return this;
}
public Builder voltageOffset(Float voltageOffset) {
this.voltageOffset = voltageOffset;
return this;
}
public Builder ampereOffset(Float ampereOffset) {
this.ampereOffset = ampereOffset;
return this;
}
public Tube build() {
return new Tube(code, voltageOffset, ampereOffset);
}
}
}

View File

@ -55,4 +55,48 @@ public class SlotDocument {
", chamberNumber='" + chamberNumber + '\'' +
'}';
}
public static Builder builder() {
return new Builder();
}
public static final class Builder {
private String id;
private String slotNumber;
private String assetCode;
private List<TubeDocument> tube;
private String chamberNumber;
private Builder() {
}
public Builder id(String id) {
this.id = id;
return this;
}
public Builder slotNumber(String slotNumber) {
this.slotNumber = slotNumber;
return this;
}
public Builder assetCode(String assetCode) {
this.assetCode = assetCode;
return this;
}
public Builder tube(List<TubeDocument> tube) {
this.tube = tube;
return this;
}
public Builder chamberNumber(String chamberNumber) {
this.chamberNumber = chamberNumber;
return this;
}
public SlotDocument build() {
return new SlotDocument(id, slotNumber, assetCode, tube, chamberNumber);
}
}
}

View File

@ -41,6 +41,20 @@ public class SlotNoSQLRepository implements SlotRepositoryDelegate {
.toList();
}
@Override
public Slot get(String chamberNumber, String slotNumber) {
log.debug("[get] chamberNumber: {}, slotNumber: {}", chamberNumber, slotNumber);
SlotDocument slotDocument = slotRepository.findByChamberNumberAndSlotNumber(chamberNumber, slotNumber);
return this.to(slotDocument);
}
@Override
public void update(Slot slot) {
log.info("[update] slot: {}", slot);
SlotDocument slotDocument = this.from(slot);
slotRepository.save(slotDocument);
}
private Slot to(SlotDocument slotDocument) {
return Slot.builder()
.id(slotDocument.getId())
@ -53,4 +67,17 @@ public class SlotNoSQLRepository implements SlotRepositoryDelegate {
.toList())
.build();
}
private SlotDocument from(Slot slot) {
return SlotDocument.builder()
.id(slot.getId())
.slotNumber(slot.getSlotNumber())
.assetCode(slot.getAssetCode())
.chamberNumber(slot.getChamberNumber())
.tube(slot.getTube()
.stream()
.map(tube -> new TubeDocument(tube.getCode(), tube.getVoltageOffset(), tube.getAmpereOffset()))
.toList())
.build();
}
}

View File

@ -10,4 +10,5 @@ import java.util.List;
public interface SlotRepository extends MongoRepository<SlotDocument, String> {
List<SlotDocument> findAllByChamberNumber(String chamberNumber);
List<SlotDocument> findAllByOrderByChamberNumberAscSlotNumberAsc();
SlotDocument findByChamberNumberAndSlotNumber(String chamberNumber, String slotNumber);
}

View File

@ -34,4 +34,36 @@ public class TubeDocument {
", ampereOffset=" + ampereOffset +
'}';
}
public static Builder builder() {
return new Builder();
}
public static final class Builder {
private String code;
private Float voltageOffset;
private Float ampereOffset;
private Builder() {
}
public Builder code(String code) {
this.code = code;
return this;
}
public Builder voltageOffset(Float voltageOffset) {
this.voltageOffset = voltageOffset;
return this;
}
public Builder ampereOffset(Float ampereOffset) {
this.ampereOffset = ampereOffset;
return this;
}
public TubeDocument build() {
return new TubeDocument(code, voltageOffset, ampereOffset);
}
}
}

View File

@ -2,6 +2,7 @@ package inc.sdt.controlcentermanagement.presentation;
import inc.sdt.controlcentermanagement.application.TubeService;
import inc.sdt.controlcentermanagement.domain.Slot;
import inc.sdt.controlcentermanagement.domain.Tube;
import inc.sdt.controlcentermanagement.infrastructure.amqp.ResourceMapping;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -24,9 +25,9 @@ public class TubeController {
this.log = LoggerFactory.getLogger(TubeController.class);
}
@ResourceMapping(name = "Tube_Control", method = "PATCH", uri = "/chamber/{chamberNumber}/tube/toggle", description = "Tube On/Off 제어")
@ResourceMapping(name = "Tube_Control", method = "PATCH", uri = "/chambers/{chamberNumber}/tube/toggle", description = "Tube On/Off 제어")
@ResponseStatus(HttpStatus.OK)
@PatchMapping("/chamber/{chamberNumber}/tube/toggle")
@PatchMapping("/chambers/{chamberNumber}/tube/toggle")
public void toggle(@RequestHeader("Authorization") String authorization, @PathVariable String chamberNumber, @RequestBody Slot slot) {
log.info("[toggle] chamberNumber: {}, slot: {}", chamberNumber, slot);
List<Slot> slots = tubeService.get(chamberNumber);
@ -38,4 +39,16 @@ public class TubeController {
tubeService.controlAll(authorization, slots, slot.getCommand());
}
}
@ResourceMapping(name = "Tube_Offset_Control", method = "PATCH", uri = "/chambers/{chamberNumber}/slots/{slotNumber}/tubes/{code}", description = "Tube offset 설정")
@ResponseStatus(HttpStatus.OK)
@PatchMapping("/chambers/{chamberNumber}/slots/{slotNumber}/tubes/{code}")
public void adjustOffset(@PathVariable String chamberNumber, @PathVariable String slotNumber, @PathVariable String code, @RequestBody Tube tube) {
log.info("[adjustOffset] chamber: {}, slot: {}, tubeCode: {}, offset: {}", chamberNumber, slotNumber, code, tube);
Slot slot = Slot.builder()
.chamberNumber(chamberNumber)
.slotNumber(slotNumber)
.build();
tubeService.adjustOffset(slot, code, tube);
}
}