💎一站式轻松地调用各大LLM模型接口,支持GPT4、智谱、星火、月之暗面及文生图 广告
为了减少service层的代码量,进一步解耦,同时提高代码复用率,可使用节点翻译器完成复杂节点的实现逻辑。 例如 ~~~ @TranslateEnable @ApiModel(description = "订单列表查询接口返回报文返回内容节点") public class OrderListRsp extends RspData { @ApiModelProperty(value = "订单编号", required = true, position = 70) private Long tradeId; @Translate(translator=OrderItemsRspTranslator.class) @ApiModelProperty(value = "订单属性信息节点", required = false, position = 500) private List<OrderItemsRsp> orderItems; //set/get方法省略。。。 } ~~~ 返回报文需用@TranslateEnable进行标注,其中orderItems节点使用@Translate进行标注,并指定OrderItemsRspTranslator.class OrderItemsRspTranslator类就是orderItems节点的取值逻辑 ~~~ @Component public class OrderItemsRspTranslator extends BaseTranslator { @Resource(name = "sqlSessionDao") private BaseSqlSessionDao dao; @SuppressWarnings("unchecked") @Override public <T> T translate(Object sourceObject) { Long tradeId = (Long)sourceObject; List<OrderItemsRsp> orderItems = new ArrayList<OrderItemsRsp>(); //查询数据库 TfBTradePreItem cond = new TfBTradePreItem(); cond.setTradeId(tradeId).asCondition(); List<TfBTradePreItem> datas = dao.selectList(cond); //遍历 for (TfBTradePreItem tfBTradePreItem : datas) { OrderItemsRsp orderItemsRsp = new OrderItemsRsp(); orderItemsRsp.setAttrCode(tfBTradePreItem.getAttrCode()); orderItemsRsp.setAttrValue(tfBTradePreItem.getAttrValue()); orderItemsRsp.setAttrTypeCode(tfBTradePreItem.getAttrTypeCode()); orderItemsRsp.setStartDate(decodeTimestamp(tfBTradePreItem.getStartDate())); orderItemsRsp.setEndDate(decodeTimestamp(tfBTradePreItem.getEndDate())); orderItems.add(orderItemsRsp); } return (T) orderItems; } } ~~~ sourceObject是在service层注册的传参。 ~~~ // 注册OrderListRsp.orderItems节点翻译器入参 orderListRsp.registerPropertyTranslatorSourceObject("orderItems", row.getTradeId()); ~~~