From 7e73daaa00b590166cf0089f2f1bb3b5dda61167 Mon Sep 17 00:00:00 2001 From: PeiYY Date: Wed, 21 Oct 2020 11:42:57 +0800 Subject: [PATCH] =?UTF-8?q?add=20=E5=AE=98=E7=BD=91=E5=8D=A1=E6=94=AF?= =?UTF-8?q?=E4=BB=98/=E8=B4=B7=E6=AC=BE=E7=94=B3=E8=AF=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../descriptor/LoanApplicationDescriptor.java | 44 ++++++++ .../domain/entity/LoanApplication.java | 76 +++++++++++++ .../domain/entity/LoanApplicationStatus.java | 90 +++++++++++++++ .../request/ModifyLoanApplicationRequest.java | 34 ++++++ .../repository/LoanApplicationRepository.java | 17 +++ .../service/LoanApplicationService.java | 18 +++ .../web/RestLoanApplicationController.java | 43 ++++++++ .../web/RestLoanApplicationsController.java | 44 ++++++++ .../command/ModifyLoanApplicationCommand.java | 23 ++++ .../LoanApplicationRepositoryImpl.java | 35 ++++++ .../service/LoanApplicationServiceImpl.java | 54 +++++++++ .../LoanApplicationMapper.java | 31 ++++++ .../SendingApplyToWechatMessageListener.java | 16 ++- .../domain/entity/PartnerApplyType.java | 104 ++++++++++++++++++ .../repository/PartnerApplyRepository.java | 7 ++ .../domain/service/PartnerApplyService.java | 7 ++ .../web/RestPartnerApplyController.java | 46 ++++++++ .../domain/web/command/PartnerApplyInfo.java | 104 ++++++++++++++++++ .../PartnerApplyRepositoryImpl.java | 20 ++++ .../service/PartnerApplyServiceImpl.java | 79 +++++++++++++ .../PageListRepresentation.java | 33 ++++++ .../loanapplication/LoanApplicationMapper.xml | 34 ++++++ 22 files changed, 956 insertions(+), 3 deletions(-) create mode 100644 src/main/java/au/com/royalpay/payment/manage/loanapplicaiton/domain/descriptor/LoanApplicationDescriptor.java create mode 100644 src/main/java/au/com/royalpay/payment/manage/loanapplicaiton/domain/entity/LoanApplication.java create mode 100644 src/main/java/au/com/royalpay/payment/manage/loanapplicaiton/domain/entity/LoanApplicationStatus.java create mode 100644 src/main/java/au/com/royalpay/payment/manage/loanapplicaiton/domain/entity/request/ModifyLoanApplicationRequest.java create mode 100644 src/main/java/au/com/royalpay/payment/manage/loanapplicaiton/domain/repository/LoanApplicationRepository.java create mode 100644 src/main/java/au/com/royalpay/payment/manage/loanapplicaiton/domain/service/LoanApplicationService.java create mode 100644 src/main/java/au/com/royalpay/payment/manage/loanapplicaiton/domain/web/RestLoanApplicationController.java create mode 100644 src/main/java/au/com/royalpay/payment/manage/loanapplicaiton/domain/web/RestLoanApplicationsController.java create mode 100644 src/main/java/au/com/royalpay/payment/manage/loanapplicaiton/domain/web/command/ModifyLoanApplicationCommand.java create mode 100644 src/main/java/au/com/royalpay/payment/manage/loanapplicaiton/infrastructure/repository/LoanApplicationRepositoryImpl.java create mode 100644 src/main/java/au/com/royalpay/payment/manage/loanapplicaiton/infrastructure/service/LoanApplicationServiceImpl.java create mode 100644 src/main/java/au/com/royalpay/payment/manage/mappers/loanapplication/LoanApplicationMapper.java create mode 100644 src/main/java/au/com/royalpay/payment/manage/officialwebsit/domain/entity/PartnerApplyType.java create mode 100644 src/main/java/au/com/royalpay/payment/manage/officialwebsit/domain/repository/PartnerApplyRepository.java create mode 100644 src/main/java/au/com/royalpay/payment/manage/officialwebsit/domain/service/PartnerApplyService.java create mode 100644 src/main/java/au/com/royalpay/payment/manage/officialwebsit/domain/web/RestPartnerApplyController.java create mode 100644 src/main/java/au/com/royalpay/payment/manage/officialwebsit/domain/web/command/PartnerApplyInfo.java create mode 100644 src/main/java/au/com/royalpay/payment/manage/officialwebsit/infrastructure/repository/PartnerApplyRepositoryImpl.java create mode 100644 src/main/java/au/com/royalpay/payment/manage/officialwebsit/infrastructure/service/PartnerApplyServiceImpl.java create mode 100644 src/main/java/au/com/royalpay/payment/manage/support/representation/PageListRepresentation.java create mode 100644 src/main/resources/au/com/royalpay/payment/manage/mappers/loanapplication/LoanApplicationMapper.xml diff --git a/src/main/java/au/com/royalpay/payment/manage/loanapplicaiton/domain/descriptor/LoanApplicationDescriptor.java b/src/main/java/au/com/royalpay/payment/manage/loanapplicaiton/domain/descriptor/LoanApplicationDescriptor.java new file mode 100644 index 000000000..543ba9454 --- /dev/null +++ b/src/main/java/au/com/royalpay/payment/manage/loanapplicaiton/domain/descriptor/LoanApplicationDescriptor.java @@ -0,0 +1,44 @@ +package au.com.royalpay.payment.manage.loanapplicaiton.domain.descriptor; + +import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.NoArgsConstructor; +import lombok.experimental.Accessors; + +import java.sql.Timestamp; + +/** + * 贷款申请信息描述 + */ +@Data +@Accessors(chain = true) +@NoArgsConstructor +@EqualsAndHashCode(callSuper = false) +public class LoanApplicationDescriptor { + + private String id; + + private Timestamp createTime; + + private String clientId; + + private String name; + + private String phone; + + private String email; + + private String businessName; + + private String industry; + + /** + * 处理状态 + */ + private String status; + + /** + * 备注信息 + */ + private String remark; +} diff --git a/src/main/java/au/com/royalpay/payment/manage/loanapplicaiton/domain/entity/LoanApplication.java b/src/main/java/au/com/royalpay/payment/manage/loanapplicaiton/domain/entity/LoanApplication.java new file mode 100644 index 000000000..4ad6d9099 --- /dev/null +++ b/src/main/java/au/com/royalpay/payment/manage/loanapplicaiton/domain/entity/LoanApplication.java @@ -0,0 +1,76 @@ +package au.com.royalpay.payment.manage.loanapplicaiton.domain.entity; + +import au.com.royalpay.payment.manage.loanapplicaiton.domain.descriptor.LoanApplicationDescriptor; +import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.NoArgsConstructor; +import lombok.experimental.Accessors; + +import java.sql.Timestamp; + +/** + * 贷款申请信息 + */ +@Data +@Accessors(chain = true) +@NoArgsConstructor +@EqualsAndHashCode(callSuper = false) +public class LoanApplication { + + private String id; + + private Timestamp createTime; + + private Timestamp modifyTime; + + private String creator; + + private String modifier; + + private String clientId; + + /** + * 联系人姓名 + */ + private String name; + /** + * 联系人手机 + */ + private String phone; + /** + * 联系人邮箱 + */ + private String email; + /** + * 商业名称 + */ + private String businessName; + /** + * 行业 + */ + private String industry; + + /** + * 处理状态 + */ + private LoanApplicationStatus status; + + /** + * 备注信息 + */ + private String remark; + + public LoanApplicationDescriptor describe() { + return new LoanApplicationDescriptor() + .setId(this.id) + .setClientId(this.clientId) + .setCreateTime(this.createTime) + .setName(this.name) + .setPhone(this.phone) + .setEmail(this.email) + .setBusinessName(this.businessName) + .setIndustry(this.industry) + .setStatus(this.status.description()) + .setRemark(this.remark); + } +} diff --git a/src/main/java/au/com/royalpay/payment/manage/loanapplicaiton/domain/entity/LoanApplicationStatus.java b/src/main/java/au/com/royalpay/payment/manage/loanapplicaiton/domain/entity/LoanApplicationStatus.java new file mode 100644 index 000000000..1177745a1 --- /dev/null +++ b/src/main/java/au/com/royalpay/payment/manage/loanapplicaiton/domain/entity/LoanApplicationStatus.java @@ -0,0 +1,90 @@ +package au.com.royalpay.payment.manage.loanapplicaiton.domain.entity; + +/** + * 贷款申请状态 0:待处理、1:处理中、2:已处理 + */ +public enum LoanApplicationStatus { + + /** + * 待处理 + */ + READY { + @Override + public int code() { + return 0; + } + + @Override + public String value() { + return "READY"; + } + + @Override + public String description() { + return "待处理"; + } + }, + /** + * 处理中 + */ + PROCESSING { + @Override + public int code() { + return 1; + } + + @Override + public String value() { + return "PROCESSING"; + } + + @Override + public String description() { + return "处理中"; + } + }, + /** + * 已处理 + */ + COMPLETED { + @Override + public int code() { + return 2; + } + + @Override + public String value() { + return "COMPLETED"; + } + + @Override + public String description() { + return "已处理"; + } + }; + + /** + * 获取代码。 + * + * @return 代码 + */ + public abstract int code(); + + /** + * 获取代码对应的值。 + * + * @return 代码值 + */ + public abstract String value(); + + public abstract String description(); + + public static LoanApplicationStatus codeOf(int code) { + for (LoanApplicationStatus status : LoanApplicationStatus.values()) { + if (status.code() == code) { + return status; + } + } + return LoanApplicationStatus.READY; + } +} diff --git a/src/main/java/au/com/royalpay/payment/manage/loanapplicaiton/domain/entity/request/ModifyLoanApplicationRequest.java b/src/main/java/au/com/royalpay/payment/manage/loanapplicaiton/domain/entity/request/ModifyLoanApplicationRequest.java new file mode 100644 index 000000000..1ca7c3a17 --- /dev/null +++ b/src/main/java/au/com/royalpay/payment/manage/loanapplicaiton/domain/entity/request/ModifyLoanApplicationRequest.java @@ -0,0 +1,34 @@ +package au.com.royalpay.payment.manage.loanapplicaiton.domain.entity.request; + +import au.com.royalpay.payment.manage.loanapplicaiton.domain.entity.LoanApplicationStatus; +import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.NoArgsConstructor; +import lombok.experimental.Accessors; + +@Data +@Accessors(chain = true) +@NoArgsConstructor +@EqualsAndHashCode(callSuper = false) +public class ModifyLoanApplicationRequest { + + private String id; + + /** + * 状态信息 + */ + private Integer status; + + /** + * 备注信息 + */ + private String remark; + + public ModifyLoanApplicationRequest build(String id, String status, String remark) { + return new ModifyLoanApplicationRequest() + .setId(id) + .setStatus(LoanApplicationStatus.valueOf(status).code()) + .setRemark(remark); + } + +} diff --git a/src/main/java/au/com/royalpay/payment/manage/loanapplicaiton/domain/repository/LoanApplicationRepository.java b/src/main/java/au/com/royalpay/payment/manage/loanapplicaiton/domain/repository/LoanApplicationRepository.java new file mode 100644 index 000000000..ce8303faf --- /dev/null +++ b/src/main/java/au/com/royalpay/payment/manage/loanapplicaiton/domain/repository/LoanApplicationRepository.java @@ -0,0 +1,17 @@ +package au.com.royalpay.payment.manage.loanapplicaiton.domain.repository; + +import au.com.royalpay.payment.manage.loanapplicaiton.domain.entity.LoanApplication; +import au.com.royalpay.payment.manage.loanapplicaiton.domain.entity.request.ModifyLoanApplicationRequest; +import com.github.miemiedev.mybatis.paginator.domain.PageBounds; +import com.github.miemiedev.mybatis.paginator.domain.PageList; + +import java.util.Map; + +public interface LoanApplicationRepository { + + PageList listPagedLoanApplication(Map params, PageBounds pageBounds); + + LoanApplication getById(String id); + + void changeLoanApplication(ModifyLoanApplicationRequest request); +} diff --git a/src/main/java/au/com/royalpay/payment/manage/loanapplicaiton/domain/service/LoanApplicationService.java b/src/main/java/au/com/royalpay/payment/manage/loanapplicaiton/domain/service/LoanApplicationService.java new file mode 100644 index 000000000..983705096 --- /dev/null +++ b/src/main/java/au/com/royalpay/payment/manage/loanapplicaiton/domain/service/LoanApplicationService.java @@ -0,0 +1,18 @@ +package au.com.royalpay.payment.manage.loanapplicaiton.domain.service; + +import au.com.royalpay.payment.manage.loanapplicaiton.domain.descriptor.LoanApplicationDescriptor; +import au.com.royalpay.payment.manage.loanapplicaiton.domain.web.command.ModifyLoanApplicationCommand; +import au.com.royalpay.payment.manage.support.representation.PageListRepresentation; +import com.github.miemiedev.mybatis.paginator.domain.PageBounds; + +import java.util.Map; + +public interface LoanApplicationService { + + PageListRepresentation listPagedLoanApplication(Map params, PageBounds pageBounds); + + LoanApplicationDescriptor getById(String id); + + void changeLoanApplication(String id, ModifyLoanApplicationCommand command); + +} diff --git a/src/main/java/au/com/royalpay/payment/manage/loanapplicaiton/domain/web/RestLoanApplicationController.java b/src/main/java/au/com/royalpay/payment/manage/loanapplicaiton/domain/web/RestLoanApplicationController.java new file mode 100644 index 000000000..9786e57f4 --- /dev/null +++ b/src/main/java/au/com/royalpay/payment/manage/loanapplicaiton/domain/web/RestLoanApplicationController.java @@ -0,0 +1,43 @@ +package au.com.royalpay.payment.manage.loanapplicaiton.domain.web; + +import au.com.royalpay.payment.manage.loanapplicaiton.domain.descriptor.LoanApplicationDescriptor; +import au.com.royalpay.payment.manage.loanapplicaiton.domain.service.LoanApplicationService; +import au.com.royalpay.payment.manage.loanapplicaiton.domain.web.command.ModifyLoanApplicationCommand; +import org.springframework.web.bind.annotation.*; + +import javax.annotation.Resource; + +/** + * 贷款申请资源 + */ +@RestController +@RequestMapping(value = "/partners") +public class RestLoanApplicationController { + + @Resource + private LoanApplicationService applicationService; + + /** + * 获取贷款申请详情 + * + * @param id 编号 + * @return + */ + @RequestMapping(value = "/loanApplications/{id}", method = RequestMethod.GET) + public LoanApplicationDescriptor getLoanApplication(@PathVariable("id") String id) { + return applicationService.getById(id); + } + + /** + * 更新贷款申请信息 + * + * @param id 编号 + * @param command 入参 + */ + @RequestMapping(value = "/loanApplications/{id}", method = RequestMethod.PUT) + public void changeLoanApplication(@PathVariable("id") String id, + @RequestBody ModifyLoanApplicationCommand command) { + applicationService.changeLoanApplication(id, command); + } + +} diff --git a/src/main/java/au/com/royalpay/payment/manage/loanapplicaiton/domain/web/RestLoanApplicationsController.java b/src/main/java/au/com/royalpay/payment/manage/loanapplicaiton/domain/web/RestLoanApplicationsController.java new file mode 100644 index 000000000..bc35affac --- /dev/null +++ b/src/main/java/au/com/royalpay/payment/manage/loanapplicaiton/domain/web/RestLoanApplicationsController.java @@ -0,0 +1,44 @@ +package au.com.royalpay.payment.manage.loanapplicaiton.domain.web; + +import au.com.royalpay.payment.manage.loanapplicaiton.domain.descriptor.LoanApplicationDescriptor; +import au.com.royalpay.payment.manage.loanapplicaiton.domain.service.LoanApplicationService; +import au.com.royalpay.payment.manage.support.representation.PageListRepresentation; +import com.github.miemiedev.mybatis.paginator.domain.Order; +import com.github.miemiedev.mybatis.paginator.domain.PageBounds; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; + +import javax.annotation.Resource; +import javax.validation.constraints.Min; +import java.util.Map; + +/** + * 贷款申请列表资源 + */ +@RestController +@RequestMapping(value = "/partners") +public class RestLoanApplicationsController { + + @Resource + private LoanApplicationService applicationService; + + /** + * 贷款申请分页列表 + * + * @param params + * @param page + * @param pageSize + * @return + */ + @RequestMapping(value = "/loanApplications", method = RequestMethod.GET) + public Object listPagedLoanApplication(@RequestParam Map params, + @Min(1) @RequestParam(value = "page", required = false, defaultValue = "1") int page, + @Min(1) @RequestParam(value = "pageSize", required = false, defaultValue = "10") int pageSize) { + PageBounds pageBounds = new PageBounds(page, pageSize, Order.formString("create_time.desc")); + PageListRepresentation result = applicationService.listPagedLoanApplication(params, pageBounds); + return result; + } + +} diff --git a/src/main/java/au/com/royalpay/payment/manage/loanapplicaiton/domain/web/command/ModifyLoanApplicationCommand.java b/src/main/java/au/com/royalpay/payment/manage/loanapplicaiton/domain/web/command/ModifyLoanApplicationCommand.java new file mode 100644 index 000000000..716111cfd --- /dev/null +++ b/src/main/java/au/com/royalpay/payment/manage/loanapplicaiton/domain/web/command/ModifyLoanApplicationCommand.java @@ -0,0 +1,23 @@ +package au.com.royalpay.payment.manage.loanapplicaiton.domain.web.command; + + +import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.NoArgsConstructor; +import lombok.experimental.Accessors; + +import javax.validation.constraints.NotBlank; + +@Data +@Accessors(chain = true) +@NoArgsConstructor +@EqualsAndHashCode(callSuper = false) +public class ModifyLoanApplicationCommand { + + @NotBlank(message = "error.payment.valid.param_missing") + private String remark; + + @NotBlank(message = "error.payment.valid.param_missing") + private String status; + +} diff --git a/src/main/java/au/com/royalpay/payment/manage/loanapplicaiton/infrastructure/repository/LoanApplicationRepositoryImpl.java b/src/main/java/au/com/royalpay/payment/manage/loanapplicaiton/infrastructure/repository/LoanApplicationRepositoryImpl.java new file mode 100644 index 000000000..91120ce89 --- /dev/null +++ b/src/main/java/au/com/royalpay/payment/manage/loanapplicaiton/infrastructure/repository/LoanApplicationRepositoryImpl.java @@ -0,0 +1,35 @@ +package au.com.royalpay.payment.manage.loanapplicaiton.infrastructure.repository; + +import au.com.royalpay.payment.manage.loanapplicaiton.domain.entity.LoanApplication; +import au.com.royalpay.payment.manage.loanapplicaiton.domain.entity.request.ModifyLoanApplicationRequest; +import au.com.royalpay.payment.manage.loanapplicaiton.domain.repository.LoanApplicationRepository; +import au.com.royalpay.payment.manage.mappers.loanapplication.LoanApplicationMapper; +import com.github.miemiedev.mybatis.paginator.domain.PageBounds; +import com.github.miemiedev.mybatis.paginator.domain.PageList; +import org.springframework.stereotype.Repository; + +import javax.annotation.Resource; +import java.util.Map; + +@Repository +public class LoanApplicationRepositoryImpl implements LoanApplicationRepository { + + @Resource + private LoanApplicationMapper mapper; + + @Override + public PageList listPagedLoanApplication(Map params, PageBounds pageBounds) { + return mapper.listPagedLoanApplication(params, pageBounds); + } + + @Override + public LoanApplication getById(String id) { + return mapper.findById(id); + } + + @Override + public void changeLoanApplication(ModifyLoanApplicationRequest request) { + mapper.updateLoanApplication(request); + } + +} diff --git a/src/main/java/au/com/royalpay/payment/manage/loanapplicaiton/infrastructure/service/LoanApplicationServiceImpl.java b/src/main/java/au/com/royalpay/payment/manage/loanapplicaiton/infrastructure/service/LoanApplicationServiceImpl.java new file mode 100644 index 000000000..79606ba95 --- /dev/null +++ b/src/main/java/au/com/royalpay/payment/manage/loanapplicaiton/infrastructure/service/LoanApplicationServiceImpl.java @@ -0,0 +1,54 @@ +package au.com.royalpay.payment.manage.loanapplicaiton.infrastructure.service; + +import au.com.royalpay.payment.manage.loanapplicaiton.domain.descriptor.LoanApplicationDescriptor; +import au.com.royalpay.payment.manage.loanapplicaiton.domain.entity.LoanApplication; +import au.com.royalpay.payment.manage.loanapplicaiton.domain.entity.request.ModifyLoanApplicationRequest; +import au.com.royalpay.payment.manage.loanapplicaiton.domain.repository.LoanApplicationRepository; +import au.com.royalpay.payment.manage.loanapplicaiton.domain.service.LoanApplicationService; +import au.com.royalpay.payment.manage.loanapplicaiton.domain.web.command.ModifyLoanApplicationCommand; +import au.com.royalpay.payment.manage.support.representation.PageListRepresentation; +import au.com.royalpay.payment.tools.exceptions.BadRequestException; +import com.github.miemiedev.mybatis.paginator.domain.PageBounds; +import com.github.miemiedev.mybatis.paginator.domain.PageList; +import org.springframework.stereotype.Service; + +import javax.annotation.Resource; +import java.util.Map; + +@Service +public class LoanApplicationServiceImpl implements LoanApplicationService { + + @Resource + private LoanApplicationRepository repository; + + @Override + public PageListRepresentation listPagedLoanApplication(Map params, PageBounds pageBounds) { + PageList loanApplications = repository.listPagedLoanApplication(params, pageBounds); + PageList loanApplicationDescriptors = new PageList<>(loanApplications.getPaginator()); + loanApplications.forEach(item -> { + loanApplicationDescriptors.add(item.describe()); + }); + return new PageListRepresentation<>(loanApplicationDescriptors); + } + + @Override + public LoanApplicationDescriptor getById(String id) { + LoanApplication application = this.getLoanApplication(id); + return application.describe(); + } + + @Override + public void changeLoanApplication(String id, ModifyLoanApplicationCommand command) { + LoanApplication application = this.getLoanApplication(id); + repository.changeLoanApplication(new ModifyLoanApplicationRequest().build(application.getId(), command.getStatus(), command.getRemark())); + } + + private LoanApplication getLoanApplication(String id) { + LoanApplication application = repository.getById(id); + if (application == null) { + throw new BadRequestException("Loan is not exist"); + } + return application; + } + +} diff --git a/src/main/java/au/com/royalpay/payment/manage/mappers/loanapplication/LoanApplicationMapper.java b/src/main/java/au/com/royalpay/payment/manage/mappers/loanapplication/LoanApplicationMapper.java new file mode 100644 index 000000000..3e171fb34 --- /dev/null +++ b/src/main/java/au/com/royalpay/payment/manage/mappers/loanapplication/LoanApplicationMapper.java @@ -0,0 +1,31 @@ +package au.com.royalpay.payment.manage.mappers.loanapplication; + +import au.com.royalpay.payment.manage.loanapplicaiton.domain.entity.LoanApplication; +import au.com.royalpay.payment.manage.loanapplicaiton.domain.entity.request.ModifyLoanApplicationRequest; +import com.alibaba.fastjson.JSONObject; +import com.github.miemiedev.mybatis.paginator.domain.PageBounds; +import com.github.miemiedev.mybatis.paginator.domain.PageList; +import com.yixsoft.support.mybatis.autosql.annotations.AutoMapper; +import com.yixsoft.support.mybatis.autosql.annotations.AutoSql; +import com.yixsoft.support.mybatis.autosql.annotations.SqlType; +import org.apache.ibatis.annotations.Param; + +import java.util.Map; + +@AutoMapper(tablename = "sys_clients_loans_apply", pkName = "id") +public interface LoanApplicationMapper { + + PageList listPagedLoanApplication(Map params, PageBounds pageBounds); + + @AutoSql(SqlType.INSERT) + void save(JSONObject request); + + LoanApplication findById(@Param("id") String id); + + @AutoSql(SqlType.UPDATE) + void updateLoanApplication(ModifyLoanApplicationRequest request); + + @AutoSql(SqlType.DELETE) + void deleteLoanApplication(@Param("id") String id); + +} diff --git a/src/main/java/au/com/royalpay/payment/manage/merchants/events/listeners/SendingApplyToWechatMessageListener.java b/src/main/java/au/com/royalpay/payment/manage/merchants/events/listeners/SendingApplyToWechatMessageListener.java index f39a72ace..9725e960c 100644 --- a/src/main/java/au/com/royalpay/payment/manage/merchants/events/listeners/SendingApplyToWechatMessageListener.java +++ b/src/main/java/au/com/royalpay/payment/manage/merchants/events/listeners/SendingApplyToWechatMessageListener.java @@ -2,6 +2,7 @@ package au.com.royalpay.payment.manage.merchants.events.listeners; import au.com.royalpay.payment.manage.mappers.system.ManagerMapper; import au.com.royalpay.payment.manage.merchants.events.ClientApplyEvent; +import au.com.royalpay.payment.manage.officialwebsit.domain.entity.PartnerApplyType; import au.com.royalpay.payment.tools.connections.mpsupport.MpWechatApi; import au.com.royalpay.payment.tools.connections.mpsupport.MpWechatApiProvider; import au.com.royalpay.payment.tools.connections.mpsupport.beans.TemplateMessage; @@ -9,7 +10,6 @@ import au.com.royalpay.payment.tools.env.PlatformEnvironment; import org.apache.commons.lang3.time.DateFormatUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import org.springframework.beans.factory.annotation.Value; import org.springframework.context.ApplicationListener; import org.springframework.stereotype.Service; @@ -31,7 +31,7 @@ public class SendingApplyToWechatMessageListener implements ApplicationListener< public void onApplicationEvent(ClientApplyEvent event) { List managerOpenIds = managerMapper.listOpenIdsOfCompliances(); String uri = "/partners/application/partner_apply_info/" + event.getApplyInfo().getString("client_apply_id"); - String loginUrl = PlatformEnvironment.getEnv().concatUrl("/global/userstatus/manager_signin_wechat")+"?target="+uri; + String loginUrl = PlatformEnvironment.getEnv().concatUrl("/global/userstatus/manager_signin_wechat") + "?target=" + uri; logger.info("sending new client request to wechat binded compliances"); for (String wxOpenid : managerOpenIds) { try { @@ -45,7 +45,17 @@ public class SendingApplyToWechatMessageListener implements ApplicationListener< private TemplateMessage initTemplate(ClientApplyEvent event, String loginUrl, String wxOpenid, String templateId) { TemplateMessage msg = new TemplateMessage(wxOpenid, templateId, loginUrl); - msg.put("first", "有新商户提交了开通申请,请审核", "#ff0000"); + if (event.getApplyInfo().containsKey("type")) { + String type = event.getApplyInfo().getString("type"); + if (PartnerApplyType.typeOf(type).isCard()) { + msg.put("first", "有新商户提交了卡支付开通申请,请审核", "#ff0000"); + } + if (PartnerApplyType.typeOf(type).isLoans()) { + msg.put("first", "有新商户提交了贷款开通申请,请审核", "#ff0000"); + } + } else { + msg.put("first", "有新商户提交了开通申请,请审核", "#ff0000"); + } msg.put("keyword1", "商户开通申请", "#0000ff"); msg.put("keyword2", event.getApplyInfo().getString("company_name"), "#000000"); msg.put("keyword3", DateFormatUtils.format(event.getTimestamp(), "yyyy-MM-dd HH:mm:ss,z"), "#000000"); diff --git a/src/main/java/au/com/royalpay/payment/manage/officialwebsit/domain/entity/PartnerApplyType.java b/src/main/java/au/com/royalpay/payment/manage/officialwebsit/domain/entity/PartnerApplyType.java new file mode 100644 index 000000000..604c61fa8 --- /dev/null +++ b/src/main/java/au/com/royalpay/payment/manage/officialwebsit/domain/entity/PartnerApplyType.java @@ -0,0 +1,104 @@ +package au.com.royalpay.payment.manage.officialwebsit.domain.entity; + +/** + * 申请类型:0,CARD 卡支付;1,LOANS 贷款申请 + */ +public enum PartnerApplyType { + + /** + * 卡支付 + */ + CARD { + @Override + public int code() { + return 0; + } + + @Override + public String value() { + return "CARD"; + } + + @Override + public String description() { + return "卡支付"; + } + + @Override + public boolean isCard() { + return true; + } + + @Override + public boolean isLoans() { + return false; + } + }, + /** + * 贷款申请 + */ + LOANS { + @Override + public int code() { + return 1; + } + + @Override + public String value() { + return "LOANS"; + } + + @Override + public String description() { + return "贷款申请"; + } + + @Override + public boolean isCard() { + return false; + } + + @Override + public boolean isLoans() { + return true; + } + }; + + /** + * 获取代码。 + * + * @return 代码 + */ + public abstract int code(); + + /** + * 获取代码对应的值。 + * + * @return 代码值 + */ + public abstract String value(); + + public abstract String description(); + + public static PartnerApplyType codeOf(int code) { + for (PartnerApplyType status : PartnerApplyType.values()) { + if (status.code() == code) { + return status; + } + } + return PartnerApplyType.CARD; + } + + public static PartnerApplyType typeOf(String type) { + for (PartnerApplyType status : PartnerApplyType.values()) { + if (status.value().equalsIgnoreCase(type)) { + return status; + } + } + return PartnerApplyType.CARD; + } + + public abstract boolean isCard(); + + public abstract boolean isLoans(); +} diff --git a/src/main/java/au/com/royalpay/payment/manage/officialwebsit/domain/repository/PartnerApplyRepository.java b/src/main/java/au/com/royalpay/payment/manage/officialwebsit/domain/repository/PartnerApplyRepository.java new file mode 100644 index 000000000..742d71afe --- /dev/null +++ b/src/main/java/au/com/royalpay/payment/manage/officialwebsit/domain/repository/PartnerApplyRepository.java @@ -0,0 +1,7 @@ +package au.com.royalpay.payment.manage.officialwebsit.domain.repository; + +import com.alibaba.fastjson.JSONObject; + +public interface PartnerApplyRepository { + void save(JSONObject applyInfo); +} diff --git a/src/main/java/au/com/royalpay/payment/manage/officialwebsit/domain/service/PartnerApplyService.java b/src/main/java/au/com/royalpay/payment/manage/officialwebsit/domain/service/PartnerApplyService.java new file mode 100644 index 000000000..517571e68 --- /dev/null +++ b/src/main/java/au/com/royalpay/payment/manage/officialwebsit/domain/service/PartnerApplyService.java @@ -0,0 +1,7 @@ +package au.com.royalpay.payment.manage.officialwebsit.domain.service; + +import au.com.royalpay.payment.manage.officialwebsit.domain.web.command.PartnerApplyInfo; + +public interface PartnerApplyService { + void applyPartner(PartnerApplyInfo apply); +} diff --git a/src/main/java/au/com/royalpay/payment/manage/officialwebsit/domain/web/RestPartnerApplyController.java b/src/main/java/au/com/royalpay/payment/manage/officialwebsit/domain/web/RestPartnerApplyController.java new file mode 100644 index 000000000..5147109a3 --- /dev/null +++ b/src/main/java/au/com/royalpay/payment/manage/officialwebsit/domain/web/RestPartnerApplyController.java @@ -0,0 +1,46 @@ +package au.com.royalpay.payment.manage.officialwebsit.domain.web; + +import au.com.royalpay.payment.manage.officialwebsit.domain.service.PartnerApplyService; +import au.com.royalpay.payment.manage.officialwebsit.domain.web.command.PartnerApplyInfo; +import au.com.royalpay.payment.tools.env.PlatformEnvironment; +import au.com.royalpay.payment.tools.exceptions.BadRequestException; +import au.com.royalpay.payment.tools.http.HttpUtils; +import org.springframework.validation.Errors; +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.RestController; + +import javax.annotation.Resource; +import javax.servlet.http.HttpServletResponse; +import javax.validation.Valid; + +/** + * 卡支付/贷款申请资源 + */ +@RestController +@RequestMapping("/partners") +public class RestPartnerApplyController { + + @Resource + private PartnerApplyService applyService; + + + /** + * 卡支付/贷款申请入口 + * + * @param apply + * @param errors + * @param response + * @throws Exception + */ + @RequestMapping(value = "/website/application", method = RequestMethod.POST) + public void applyPartner(@RequestBody @Valid PartnerApplyInfo apply, + Errors errors, HttpServletResponse response) throws Exception { + if (!PlatformEnvironment.getEnv().enablePartnerApply()) { + throw new BadRequestException("商户自主申请暂时关闭. Merchant Apply disabled at the moment."); + } + HttpUtils.handleValidErrors(errors); + applyService.applyPartner(apply); + } +} diff --git a/src/main/java/au/com/royalpay/payment/manage/officialwebsit/domain/web/command/PartnerApplyInfo.java b/src/main/java/au/com/royalpay/payment/manage/officialwebsit/domain/web/command/PartnerApplyInfo.java new file mode 100644 index 000000000..baa320260 --- /dev/null +++ b/src/main/java/au/com/royalpay/payment/manage/officialwebsit/domain/web/command/PartnerApplyInfo.java @@ -0,0 +1,104 @@ +package au.com.royalpay.payment.manage.officialwebsit.domain.web.command; + +/** + * 卡支付/贷款申请信息请求入参 + */ +public class PartnerApplyInfo { + /** + * 前缀name + */ + private String firstName; + /** + * 后缀name + */ + private String surname; + /** + * 手机号 + */ + private String phoneNumber; + /** + * email + */ + private String emailAddress; + /** + * 公司名称 + */ + private String businessName; + /** + *行业 + */ + private String industry; + /** + * 申请类型:0,CARD 卡支付;1,LOANS 贷款申请 + */ + private String type; + + public String getFirstName() { + return firstName; + } + + public void setFirstName(String firstName) { + this.firstName = firstName; + } + + public String getSurname() { + return surname; + } + + public void setSurname(String surname) { + this.surname = surname; + } + + public String getPhoneNumber() { + return phoneNumber; + } + + public void setPhoneNumber(String phoneNumber) { + this.phoneNumber = phoneNumber; + } + + public String getEmailAddress() { + return emailAddress; + } + + public void setEmailAddress(String emailAddress) { + this.emailAddress = emailAddress; + } + + public String getBusinessName() { + return businessName; + } + + public void setBusinessName(String businessName) { + this.businessName = businessName; + } + + public String getIndustry() { + return industry; + } + + public void setIndustry(String industry) { + this.industry = industry; + } + + public String getType() { + return type; + } + + public void setType(String type) { + this.type = type; + } + + @Override + public String toString() { + return "PartnerApplyInfo{" + + "firstName='" + firstName + '\'' + + ", Surname='" + surname + '\'' + + ", phoneNumber='" + phoneNumber + '\'' + + ", emailAddress='" + emailAddress + '\'' + + ", businessName='" + businessName + '\'' + + ", industry='" + industry + '\'' + + ", type='" + type + '\'' + + '}'; + } +} diff --git a/src/main/java/au/com/royalpay/payment/manage/officialwebsit/infrastructure/repository/PartnerApplyRepositoryImpl.java b/src/main/java/au/com/royalpay/payment/manage/officialwebsit/infrastructure/repository/PartnerApplyRepositoryImpl.java new file mode 100644 index 000000000..ff39a81a9 --- /dev/null +++ b/src/main/java/au/com/royalpay/payment/manage/officialwebsit/infrastructure/repository/PartnerApplyRepositoryImpl.java @@ -0,0 +1,20 @@ +package au.com.royalpay.payment.manage.officialwebsit.infrastructure.repository; + +import au.com.royalpay.payment.manage.mappers.loanapplication.LoanApplicationMapper; +import au.com.royalpay.payment.manage.officialwebsit.domain.repository.PartnerApplyRepository; +import com.alibaba.fastjson.JSONObject; +import org.springframework.stereotype.Repository; + +import javax.annotation.Resource; + +@Repository +public class PartnerApplyRepositoryImpl implements PartnerApplyRepository { + + @Resource + private LoanApplicationMapper mapper; + + @Override + public void save(JSONObject applyInfo) { + mapper.save(applyInfo); + } +} diff --git a/src/main/java/au/com/royalpay/payment/manage/officialwebsit/infrastructure/service/PartnerApplyServiceImpl.java b/src/main/java/au/com/royalpay/payment/manage/officialwebsit/infrastructure/service/PartnerApplyServiceImpl.java new file mode 100644 index 000000000..62e0742e3 --- /dev/null +++ b/src/main/java/au/com/royalpay/payment/manage/officialwebsit/infrastructure/service/PartnerApplyServiceImpl.java @@ -0,0 +1,79 @@ +package au.com.royalpay.payment.manage.officialwebsit.infrastructure.service; + +import au.com.royalpay.payment.manage.loanapplicaiton.domain.entity.LoanApplicationStatus; +import au.com.royalpay.payment.manage.mappers.system.ClientApplyMapper; +import au.com.royalpay.payment.manage.merchants.events.ClientApplyEvent; +import au.com.royalpay.payment.manage.officialwebsit.domain.entity.PartnerApplyType; +import au.com.royalpay.payment.manage.officialwebsit.domain.repository.PartnerApplyRepository; +import au.com.royalpay.payment.manage.officialwebsit.domain.service.PartnerApplyService; +import au.com.royalpay.payment.manage.officialwebsit.domain.web.command.PartnerApplyInfo; +import com.alibaba.fastjson.JSONObject; +import lombok.extern.slf4j.Slf4j; +import org.springframework.context.ApplicationEventPublisher; +import org.springframework.context.ApplicationEventPublisherAware; +import org.springframework.stereotype.Service; + +import javax.annotation.Resource; +import java.util.UUID; + +@Slf4j +@Service +public class PartnerApplyServiceImpl implements PartnerApplyService, ApplicationEventPublisherAware { + + @Resource + private ClientApplyMapper clientApplyMapper; + + @Resource + private PartnerApplyRepository applyRepository; + + @Resource + private ApplicationEventPublisher publisher; + + @Override + public void setApplicationEventPublisher(ApplicationEventPublisher applicationEventPublisher) { + this.publisher = applicationEventPublisher; + } + + @Override + public void applyPartner(PartnerApplyInfo apply) { + PartnerApplyType applyType = PartnerApplyType.typeOf(apply.getType()); + if (applyType.isCard()) { + JSONObject applyInfo = this.buildCardPaymentApplyInfo(apply); + clientApplyMapper.save(applyInfo); + publisher.publishEvent(new ClientApplyEvent(this, applyInfo)); + } + if (applyType.isLoans()) { + JSONObject applyInfo = this.buildLoansApplyInfo(apply); + applyRepository.save(applyInfo); + publisher.publishEvent(new ClientApplyEvent(this, applyInfo)); + } + + } + + private JSONObject buildLoansApplyInfo(PartnerApplyInfo apply) { + JSONObject result = new JSONObject(); + String name = apply.getFirstName() + " " + apply.getSurname(); + result.put("id", UUID.randomUUID().toString()); + result.put("name", name); + result.put("phone", apply.getPhoneNumber()); + result.put("email", apply.getEmailAddress()); + result.put("industry", apply.getIndustry()); + result.put("business_name", apply.getBusinessName()); + result.put("status", LoanApplicationStatus.READY.code()); + return result; + } + + private JSONObject buildCardPaymentApplyInfo(PartnerApplyInfo apply) { + JSONObject result = new JSONObject(); + String name = apply.getFirstName() + " " + apply.getSurname(); + result.put("client_apply_id", UUID.randomUUID().toString()); + result.put("contact_person", name); + result.put("contact_phone", apply.getPhoneNumber()); + result.put("contact_email", apply.getEmailAddress()); + result.put("company_name", apply.getBusinessName()); + result.put("industry", apply.getIndustry()); + result.put("type", 1); + return result; + } + +} diff --git a/src/main/java/au/com/royalpay/payment/manage/support/representation/PageListRepresentation.java b/src/main/java/au/com/royalpay/payment/manage/support/representation/PageListRepresentation.java new file mode 100644 index 000000000..910e10da0 --- /dev/null +++ b/src/main/java/au/com/royalpay/payment/manage/support/representation/PageListRepresentation.java @@ -0,0 +1,33 @@ +package au.com.royalpay.payment.manage.support.representation; + +import com.github.miemiedev.mybatis.paginator.domain.PageList; +import com.github.miemiedev.mybatis.paginator.domain.Paginator; + +public class PageListRepresentation { + + private PageList data; + + private Paginator pagination; + + public PageListRepresentation(PageList pageList) { + this.data = pageList; + this.pagination = pageList.getPaginator(); + + } + + public PageList getData() { + return data; + } + + public void setData(PageList data) { + this.data = data; + } + + public Paginator getPagination() { + return pagination; + } + + public void setPagination(Paginator pagination) { + this.pagination = pagination; + } +} diff --git a/src/main/resources/au/com/royalpay/payment/manage/mappers/loanapplication/LoanApplicationMapper.xml b/src/main/resources/au/com/royalpay/payment/manage/mappers/loanapplication/LoanApplicationMapper.xml new file mode 100644 index 000000000..e01308a94 --- /dev/null +++ b/src/main/resources/au/com/royalpay/payment/manage/mappers/loanapplication/LoanApplicationMapper.xml @@ -0,0 +1,34 @@ + + + + + + + + + + + + + + + + + + + + + + + + +