🌐Hello World !
BO(Business Object)层是一种用于处理业务逻辑的组件层。BO层主要负责封装和处理与业务相关的逻辑和数据操作,它通常位于应用程序的中间层,处于数据访问层(DAO层)和表示层(UI层)之间
需求分析:前端传递的时间类型为String类型,而我需要编写自定义sql进行联表查询,需要对时间类型进行转换为Timestamp类型和数据库匹配
- Controller
@GetMapping("list") @ApiOperation("拒付查询") public Result<PageResult<ResChargebackList>> list(ChargebackListQuery query) { return Result.succ(chargebackService.list(query)); }
- ChargebackListQuery(VO:request):接收前端参数并在不同层之间传递数据(前端请求参数)
@Data public class ChargebackListQuery extends PageQuery { @ApiModelProperty("XXX") private String merchantNo; @ApiModelProperty("XXX") private String uniqueId; @ApiModelProperty("XXX") private String transactionId; @ApiModelProperty("XXX") private String transactionCardBrand; @ApiModelProperty("XXX") private Integer chargebackType; @ApiModelProperty("XXX") private String chargebackArn; @ApiModelProperty("XXX") private Integer warnFromState; @ApiModelProperty("XXX") private String channelName; @ApiModelProperty("交易开始时间") private String transactionAtStartTime; @ApiModelProperty("交易结束时间") private String transactionAtEndTime; @ApiModelProperty("拒付开始时间") private String chargeBackAtStartTime; @ApiModelProperty("拒付结束时间") private String chargeBackAtEndTime; @ApiModelProperty("导入开始时间") private String createAtStartTime; @ApiModelProperty("导入结束时间") private String createAtEndTime; @ApiModelProperty("XXX") private Integer settleStatus; }
- ResChargebackList(VO:response):接收前端参数并在不同层之间传递数据(后端响应参数)
@Data @AllArgsConstructor @NoArgsConstructor @Builder public class ResChargebackList { protected Long id; @ApiModelProperty("XXX") protected String merchantNo; @ApiModelProperty("XXX") private Date transactionAt; @ApiModelProperty("XXX") protected String uniqueId; @ApiModelProperty("XXX") private String transactionCardBrand; @ApiModelProperty("XXX") private String transactionAmount; @ApiModelProperty("XXX") protected Date chargebackAt; @ApiModelProperty("XXX") protected String chargebackAmount; @ApiModelProperty("XXX") protected String chargebackCode; @ApiModelProperty("XXX") protected Integer chargebackType; @ApiModelProperty("XXX") protected String chargebackTypeValue; @ApiModelProperty("XXX") protected String chargebackArn; @ApiModelProperty("XXX") private String warnFromState; @ApiModelProperty("XXX") protected String channelRemark; @ApiModelProperty("XXX") protected String channelName; @ApiModelProperty("XXX") protected Date createAt; @ApiModelProperty("XXX") private String operator; @ApiModelProperty("XXX") private Integer settleStatus; }
- Service
public PageResult<ResChargebackList> list(ChargebackListQuery query) { // 将ChargebackListQuery对象转换为ChargebackListQueryBO对象 ChargebackListQueryBO convert = ChargebackListQueryBO.convert(query); // 查询交易退款列表 List<ResChargebackResponse> page = transactionChargebackRepo.queryList(convert); // 获取卡品牌列表 List<SystemCardBrandNmae> cardBrandNameList = systemCardBrandRepo.getCardList(); // 将查询结果进行转换和处理 List<ResChargebackList> collect = page.stream().map(bean -> new ResChargebackList( bean.getId(), bean.getMerchantNo(), bean.getTransactionAt(), bean.getUniqueId(), convertChargebackType(cardBrandNameList, bean.getTransactionCardBrand()), Amount.getInstance(bean.getTransactionCurrency(), bean.getTransactionAmount()).show(), bean.getChargebackAt(), Amount.getInstance(bean.getChargebackCurrency(), bean.getChargebackAmount()).show(), bean.getChargebackCode(), bean.getChargebackType(), ChargebackType.typeOf(bean.getChargebackType()).name, bean.getChargebackArn(), bean.getWarnFrom() == null ? EWarnFromStatus.NO.getValue() : EWarnFromStatus.YES.getValue(), bean.getChargebackRemark(), ManageTools.showChannel(bean.getCompanyCode(), bean.getChannelName()), bean.getCreateAt(), bean.getOperator(), bean.getSettleStatus() )).collect(Collectors.toList()); // 构建分页结果对象 return PageResult .<ResChargebackList>builder() .pageNo(Integer.parseInt(query.getPageNo())) .pageSize(Integer.parseInt(query.getPageSize())) .total(transactionChargebackRepo.chargebackCount(convert)) .items(collect) .build(); }
- BO(将前端传递的String时间,进行BO层转换为Timestamp类型,再传递给数据库处理)
@Data public class ChargebackListQueryBO { @ApiModelProperty("XXX") private String merchantNo; @ApiModelProperty("XXX") private String uniqueId; @ApiModelProperty("XXX") private String transactionId; @ApiModelProperty("XXX") private String transactionCardBrand; @ApiModelProperty("XXX") private Integer chargebackType; @ApiModelProperty("XXX") private String chargebackArn; @ApiModelProperty("XXX") private Integer warnFromState; @ApiModelProperty("XXX") private String channelName; @ApiModelProperty("交易开始时间") private Timestamp transactionAtStartTime; @ApiModelProperty("交易结束时间") private Timestamp transactionAtEndTime; @ApiModelProperty("拒付开始时间") private Timestamp chargeBackAtStartTime; @ApiModelProperty("拒付结束时间") private Timestamp chargeBackAtEndTime; @ApiModelProperty("导入开始时间") private Timestamp createAtStartTime; @ApiModelProperty("导入结束时间") private Timestamp createAtEndTime; @ApiModelProperty("XXX") private Integer settleStatus; private Integer offset; private Integer limit; public void setOffset(String pageNo, String pageSize) { this.offset = (Integer.parseInt(pageNo) - 1) * Integer.parseInt(pageSize); } public void setLimit(String pageSize) { this.limit = Integer.parseInt(pageSize); } public static ChargebackListQueryBO convert(ChargebackListQuery chargebackListQuery) { ChargebackListQueryBO chargebackListQueryBO = new ChargebackListQueryBO(); chargebackListQueryBO.setMerchantNo(chargebackListQuery.getMerchantNo()); chargebackListQueryBO.setUniqueId(chargebackListQuery.getUniqueId()); chargebackListQueryBO.setTransactionId(chargebackListQuery.getTransactionId()); chargebackListQueryBO.setTransactionCardBrand(chargebackListQuery.getTransactionCardBrand()); chargebackListQueryBO.setChargebackType(chargebackListQuery.getChargebackType()); chargebackListQueryBO.setChargebackArn(chargebackListQuery.getChargebackArn()); chargebackListQueryBO.setWarnFromState(chargebackListQuery.getWarnFromState()); chargebackListQueryBO.setChannelName(chargebackListQuery.getChannelName()); chargebackListQueryBO.setTransactionAtStartTime( chargebackListQuery.getTransactionAtStartTime() == null ? null : Timestamp.valueOf(chargebackListQuery.getTransactionAtStartTime().replace("+", " ")) ); chargebackListQueryBO.setTransactionAtEndTime( chargebackListQuery.getTransactionAtEndTime() == null ? null : Timestamp.valueOf(chargebackListQuery.getTransactionAtEndTime().replace("+", " ")) ); chargebackListQueryBO.setChargeBackAtStartTime( chargebackListQuery.getChargeBackAtStartTime() == null ? null : Timestamp.valueOf(chargebackListQuery.getChargeBackAtStartTime().replace("+", " ")) ); chargebackListQueryBO.setChargeBackAtEndTime( chargebackListQuery.getChargeBackAtEndTime() == null ? null : Timestamp.valueOf(chargebackListQuery.getChargeBackAtEndTime().replace("+", " ")) ); chargebackListQueryBO.setCreateAtStartTime( chargebackListQuery.getCreateAtStartTime() == null ? null : Timestamp.valueOf(chargebackListQuery.getCreateAtStartTime().replace("+", " ")) ); chargebackListQueryBO.setCreateAtEndTime( chargebackListQuery.getCreateAtEndTime() == null ? null : Timestamp.valueOf(chargebackListQuery.getCreateAtEndTime().replace("+", " ")) ); chargebackListQueryBO.setSettleStatus(chargebackListQuery.getSettleStatus()); chargebackListQueryBO.setOffset(chargebackListQuery.getPageNo(), chargebackListQuery.getPageSize()); chargebackListQueryBO.setLimit(chargebackListQuery.getPageSize()); return chargebackListQueryBO; } }
此案例:DAO/PO/REPO、Impl不做展示,代码太多了~
- DAO:Mapper
- PO:数据库中的实体或表的映射
- REPO、Impl:接口实现类
🌼 结语:创作不易,如果觉得博主的文章赏心悦目,还请——
点赞
👍收藏
??评论
📝