This commit is contained in:
AKurakin 2023-05-15 19:53:47 +03:00
parent 4bff19f9ba
commit 3fdc6b1dbc
5 changed files with 221 additions and 0 deletions

View file

@ -1,22 +1,30 @@
package ru.spcex.clearing.backendapi.controller.queue.payment;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import ru.clearing.classes.statics.data.payment.PaymentInstruction;
import ru.spcex.clearing.backendapi.controller.queue.AbstractQueueController;
import ru.spcex.clearing.backendapi.controller.request.cud.payment.PIClearingOutbondActionNew;
import ru.spcex.clearing.backendapi.controller.response.BasicSpcexResponse;
import ru.spcex.clearing.backendapi.controller.response.cud.CudResponse;
import ru.spcex.clearing.backendapi.controller.response.entity.CommonGetAllResponse;
import ru.spcex.clearing.backendapi.service.IOperator;
import ru.spcex.clearing.backendapi.service.IStateLoader;
import ru.spcex.clearing.imdg.IMDGDistributedNames;
import ru.spcex.clearing.platform.messaging.domain.Consts;
import java.util.Collection;
import java.util.Map;
import java.util.concurrent.ExecutionException;
@Controller
@RequestMapping("/payment-instructions")
@ -39,4 +47,14 @@ public class PaymentInstructionController extends AbstractQueueController {
response.fromEntity(all);
return response;
}
@ApiOperation(value = "Досрочное изъятие части денежных средств по договору")
@ApiResponses(value = {@ApiResponse(code = 200, message = "OK", response = CudResponse.class), @ApiResponse(code = 400, message = "Ошибка валидации", response = BasicSpcexResponse.class)})
@RequestMapping(value = "/clearing-outbound", method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
public CudResponse clearingOutboundAction(
@ApiParam(value = "Параметры команды в JSON формате.", required = true)
@RequestBody PIClearingOutbondActionNew piClearingOutbondAction) throws ExecutionException, InterruptedException {
return processRequest(Consts.PAYMENT_INSTRUCTION_CLEARING_OUTBOUND_ACTION, piClearingOutbondAction);
}
}

View file

@ -0,0 +1,114 @@
package ru.spcex.clearing.backendapi.controller.request.cud.payment;
import com.fasterxml.jackson.annotation.JsonProperty;
import io.swagger.annotations.ApiModelProperty;
import ru.spcex.clearing.backendapi.domain.actions.IAction;
import ru.spcex.clearing.backendapi.errors.BackEndError;
import ru.spcex.clearing.platform.messaging.domain.ActionType;
import ru.spcex.clearing.platform.messaging.domain.cud.payment.PIClearingOutbondActionNewRequest;
import ru.spcex.platform.utils.enumeration.EnumMessage;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
public class PIClearingOutbondActionNew implements IAction<PIClearingOutbondActionNewRequest> {
@ApiModelProperty(value = "Участник отправитель", example = "123")
@JsonProperty
public Long senderId;
@ApiModelProperty(value = "Участник получатель", example = "123")
@JsonProperty
public Long addresseeId;
@ApiModelProperty(value = "Назначение платежа", example = "Text ...")
@JsonProperty
public String paymentPurpose;
@ApiModelProperty(value = "Сумма отправителя", example = "123.45")
@JsonProperty
public BigDecimal creditLeg_amount;
@ApiModelProperty(value = "Наименование счета отправителя", example = "2001")
@JsonProperty
public Long creditLeg_accountId;
@ApiModelProperty(value = "Наименование счета получателя", example = "2002")
@JsonProperty
public Long debitLeg_accountId;
@Override
public Collection<EnumMessage> validate() {
List<EnumMessage> errors = new ArrayList<>();
if (this.senderId == null)
errors.add(new EnumMessage(BackEndError.ValidationError, "senderId"));
if (this.addresseeId == null)
errors.add(new EnumMessage(BackEndError.ValidationError, "addresseeId"));
return errors.isEmpty() ? Collections.emptyList() : errors;
}
@Override
public PIClearingOutbondActionNewRequest toRequest() {
var req = new PIClearingOutbondActionNewRequest();
req.setSenderId(this.senderId);
req.setAddresseeId(this.addresseeId);
req.setPaymentPurpose(this.paymentPurpose);
req.setCreditLeg_amount(this.creditLeg_amount);
req.setCreditLeg_accountId(this.creditLeg_accountId);
req.setDebitLeg_accountId(this.debitLeg_accountId);
return req;
}
@ApiModelProperty(hidden = true)
@Override
public ActionType getActionType() {
return ActionType.NEW;
}
public Long getSenderId() {
return senderId;
}
public void setSenderId(Long senderId) {
this.senderId = senderId;
}
public Long getAddresseeId() {
return addresseeId;
}
public void setAddresseeId(Long addresseeId) {
this.addresseeId = addresseeId;
}
public String getPaymentPurpose() {
return paymentPurpose;
}
public void setPaymentPurpose(String paymentPurpose) {
this.paymentPurpose = paymentPurpose;
}
public BigDecimal getCreditLeg_amount() {
return creditLeg_amount;
}
public void setCreditLeg_amount(BigDecimal creditLeg_amount) {
this.creditLeg_amount = creditLeg_amount;
}
public Long getCreditLeg_accountId() {
return creditLeg_accountId;
}
public void setCreditLeg_accountId(Long creditLeg_accountId) {
this.creditLeg_accountId = creditLeg_accountId;
}
public Long getDebitLeg_accountId() {
return debitLeg_accountId;
}
public void setDebitLeg_accountId(Long debitLeg_accountId) {
this.debitLeg_accountId = debitLeg_accountId;
}
}

View file

@ -6,8 +6,10 @@ import org.springframework.http.MediaType;
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
import ru.clearing.classes.statics.data.payment.PaymentInstruction;
import ru.spcex.clearing.backendapi.controller.queue.AbstractControllerTest;
import ru.spcex.clearing.backendapi.controller.request.cud.payment.PIClearingOutbondActionNew;
import ru.spcex.clearing.backendapi.controller.response.entity.CommonGetAllResponse;
import ru.spcex.clearing.imdg.IMDGDistributedNames;
import ru.spcex.clearing.platform.messaging.domain.Consts;
import java.math.BigDecimal;
import java.time.Instant;
@ -79,4 +81,20 @@ class PaymentInstructionControllerTest extends AbstractControllerTest {
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
.andExpect(content().json(writeValue(expected)));
}
@Test
void clearingOutboundAction() throws Exception {
//ARRANGE
PIClearingOutbondActionNew piClearingOutbondActionNew = new PIClearingOutbondActionNew();
piClearingOutbondActionNew.setSenderId(111L);
piClearingOutbondActionNew.setAddresseeId(222L);
piClearingOutbondActionNew.setPaymentPurpose("Check now.");
piClearingOutbondActionNew.setCreditLeg_amount(BigDecimal.valueOf(120.99));
piClearingOutbondActionNew.setCreditLeg_accountId(333L);
piClearingOutbondActionNew.setDebitLeg_accountId(335L);
//ACT and ASSERT
checkAddingByRestApi("/payment-instructions/clearing-outbound/", piClearingOutbondActionNew);
checkSendedMessegeFromKafka(Consts.PAYMENT_INSTRUCTION_CLEARING_OUTBOUND_ACTION, piClearingOutbondActionNew);
}
}

View file

@ -118,6 +118,8 @@ public interface Consts {
String REQUEST_INFO_UPDATE = "request-info-update";
String PAYMENT_INSTRUCTION_CLEARING_OUTBOUND_ACTION = "clearing-outbound-action";
String REGISTRY_SPLIT_DEPOSIT_ACTION = "registry-split-deposit-action";
String REGISTRY_COVERED_DEAL_REGISTER_NEW = "registry-covered-deal-register-new";
String REGISTRY_ADMITTED_DEAL_REGISTER_NEW = "registry-admitted-deal-register-new";

View file

@ -0,0 +1,69 @@
package ru.spcex.clearing.platform.messaging.domain.cud.payment;
import com.fasterxml.jackson.annotation.JsonProperty;
import java.math.BigDecimal;
public class PIClearingOutbondActionNewRequest {
@JsonProperty
private Long senderId;
@JsonProperty
private Long addresseeId;
@JsonProperty
private String paymentPurpose;
@JsonProperty
private BigDecimal creditLeg_amount;
@JsonProperty
private Long creditLeg_accountId;
@JsonProperty
private Long debitLeg_accountId;
public Long getSenderId() {
return senderId;
}
public void setSenderId(Long senderId) {
this.senderId = senderId;
}
public Long getAddresseeId() {
return addresseeId;
}
public void setAddresseeId(Long addresseeId) {
this.addresseeId = addresseeId;
}
public String getPaymentPurpose() {
return paymentPurpose;
}
public void setPaymentPurpose(String paymentPurpose) {
this.paymentPurpose = paymentPurpose;
}
public BigDecimal getCreditLeg_amount() {
return creditLeg_amount;
}
public void setCreditLeg_amount(BigDecimal creditLeg_amount) {
this.creditLeg_amount = creditLeg_amount;
}
public Long getCreditLeg_accountId() {
return creditLeg_accountId;
}
public void setCreditLeg_accountId(Long creditLeg_accountId) {
this.creditLeg_accountId = creditLeg_accountId;
}
public Long getDebitLeg_accountId() {
return debitLeg_accountId;
}
public void setDebitLeg_accountId(Long debitLeg_accountId) {
this.debitLeg_accountId = debitLeg_accountId;
}
}