我是靠谱客的博主 单纯发夹,最近开发中收集的这篇文章主要介绍有意思的代码,觉得挺不错的,现在分享给大家,希望可以做个参考。

概述

    将6个POJO中值整合到1个POJO中,大的POJO字段名和小的POJO不一致,实现做法

A:


public class JiupiOrder implements Serializable {
/**

* 订单编号

*/

private BigInteger id;

/**

* 仓库编号

*/

private Integer warehouse_Id;

/**

* 配送人编号

*/

private Integer delivery_Id;

/**

* 卸货人编号

*/

private Integer stevedore_Id;

/**

* 关联订单编号

*/

private BigInteger relatedOrder_Id;

/**

* 酒批订单类型:普通订单(0),分销商订单(1)

*/

private Integer jiupiOrderType;

/**

* 是否预售订单

*/

private Integer isPreSale;

/**

* 酒批订单来源:合作商转酒批(0), 酒批订单(1),

*/

private Integer jiupiOrderSource;

/**

* 仓管Id

*/

private Integer storeAdmin_Id;

/**

* 末次更新时间

*/

@IgnoreField

private Timestamp lastModifyTime;

B:

public class OrderItem implements Serializable {
private static final long serialVersionUID = 9049775047788595349L;

/**

* 订单项id

*/

private BigInteger id;

/**

* 订单ID

*/

private BigInteger orderId;

/**

* 订单项来源,XX活动

*/

private Integer sourceType;

/**

* 来源ID

*/

private BigInteger source_Id;

/**

* 普通商品(0),赠送商品(1),限时惠商品(2),加价购商品(3)

*/

private Integer productType;

/**

* 最后修改时间

*/

@IgnoreField

private Date lastModifyTime;

C:

public class OrderItemAmount implements Serializable {
private static final long serialVersionUID = 8889250027007274402L;


/**

* 订单项id

*/

private BigInteger id;

/**

* 订单ID

*/

private BigInteger orderId;

/**

* 商品优惠劵减价金额

*/

private BigDecimal reduceCouponAmount;

/**

* 商品红包减价金额

*/

private BigDecimal reduceBonusAmount;

/**

* 订单满减金额

*/

private BigDecimal reduceOrderAmount;

/**

* 产品总价折扣=产品总价减价+商品优惠劵减价金额+商品红包减价金额+订单满减金额

*/

private BigDecimal discount;

/**

* 产品总金额

*/

private BigDecimal totalAmount;

/**

* 产品实付总金额

*/

private BigDecimal payAmount;

/**

* 配送费

*/

private BigDecimal deliveryAmount;

/**

* 销售数量

*/

private Integer saleCount;

/**

* 销售数量小单位累计

*/

private Integer minUnitTotalCount;

/**

* 自提优惠金额

*/

private BigDecimal selfPickUpReduceAmount;

/**

* 兑奖红包减价金额

*/

private BigDecimal reduceRewardBonusAmount;

/**

* 优惠码优惠金额

*/

private BigDecimal reduceCouponCodeAmount;

/**

* 产品总价减价

*/

private BigDecimal reduceProductAmount;


/**

* 最后修改时间

*/

@IgnoreField

private Date lastModifyTime;

D:


public class OrderItemPrice implements Serializable{
private static final long serialVersionUID = -2470045089112016351L;

/**

* 订单项id

*/

private BigInteger id;

/**

* 订单ID

*/

private BigInteger orderId;

/**

* 销售价

*/

private BigDecimal sellPrice;

/**

* 销售价单位

*/

private String sellUnit;

/**

* 小单位价格

*/

private BigDecimal minUnitPrice;

/**

* 小单位名称

*/

private String minUnitName;


/**

* 最后修改时间

*/

@IgnoreField
private Date lastModifyTime;



E:

public class OrderItemProduct implements Serializable {
private static final long serialVersionUID = -1114462513568729767L;


/**

* 订单项id

*/

private BigInteger id;


/**

* 产品SKU id

*/

private BigInteger productId;


/**

* 产品销售规格ID

*/

private BigInteger ProductSaleSpec_Id;

/**

* 产品名称

*/

private String productName;


/**

* 销售规格系数

*/

private Integer saleSpecQuantity;


/**

* 销售规格单位

*/

private String sellUnit;


/**

* 包装规格

*/

private String productSpec;


/**

* 包装规格系数

*/

private Integer specQuantity;


/**

* 大单位

*/

private String packageName;


/**

* 小单位

*/

private String unitName;


/**

* 供应商id

*/

private Integer supplierId;


/**

* 销售模式

*/

private Integer saleMode;


/**

* 订单id

*/

private BigInteger orderId;


/**

* 产品业务类型,0,酒类,1,非酒类

*/

private Integer productBusinessClass;


/**

* 最后修改时间

*/

@IgnoreField

private Date lastModifyTime;



F:

public class Orders implements Serializable {
private static final long serialVersionUID = -1386379185614836343L;


/**

* 订单id

*/

private BigInteger id;


/**

* 城市id

*/

private Integer city_Id;


/**

* 订单编号

*/

private String orderNo;



/**

* 订单类型 1:酒批 2: 合作商

*/

private Integer orderType;


/**

* 订单类型 0:普通订单 1: 限时惠

*/

private Integer orderClassify;


/**

* 订单状态

*/

private Integer state;


/**

* 订单金额

*/

private BigDecimal orderAmount;


/**

* 省

*/

private String province;


/**

* 市

*/

private String city;


/**

* 区

*/

private String county;


/**

* 街道

*/

private String street;


/**

* 详细地址

*/

private String detailAddres;


/**

* 电话号码

*/

private String phone;


/**

* 是否测试订单

*/

private Boolean isTestOrder;


/**

* 用户id

*/

private Integer userId;


/**

* 经纪人id

*/

private Integer salemanId;


/**

* 配送模式

*/

private Integer deliveryMode;


/**

* 下单时间

*/

private Date orderCreateTime;


/**

* 下单审核时间

*/

private Date orderAuditTime;


/**

* 订单发货时间

*/

private Date orderDeliverTime;


/**

* 订单撤销时间

*/

private Date orderCancelTime;


/**

* 订单完成时间

*/

private Date orderCompleteTime;


/**

* 订单确认时间

*/

private Date orderConfirmTime;


/**

* 订单的提交批次

*/

private BigInteger OrderBatch_Id;

/**

* 用户名

*/

private String userName;


/**

* 用户手机号

*/

private String userMobileNo;


/**

* 客户的店铺名

*/

private String userCompanyName;


/**

* 经销商店铺ID

*/

private Integer shop_id;

/**

* 订单项数

*/

private Integer orderItemCount;


/**

* 最后修改时间

*/

@IgnoreField

private Date lastModifyTime;


/**

* 订单明细项

*/

private List<OrderItem> orderItemsList;

/**

* 订单明细项金额

*/

private List<OrderItemAmount> orderItemAmountList;

/**

* 订单明细项价格

*/

private List<OrderItemPrice> orderItemPriceList;

/**

* 订单明细项产品

*/

private List<OrderItemProduct> orderItemProductList;


/**

* 酒批订单

*/

private JiupiOrder jiupiOrder;

大表:

public class OrderDetailInfo implements Serializable {
private static final long serialVersionUID = -2033526992975029350L;


/**

* 订单id

*/

@OrderDetailInfoMapper(schema = OrderDetailInfoSchema.Order, fieldName = "id")
private BigInteger orderId;

/**

* 城市id

*/

@OrderDetailInfoMapper(schema = OrderDetailInfoSchema.Order, fieldName = "city_Id")
private Integer orderCityId;


/**

* 订单编号

*/

@OrderDetailInfoMapper(schema = OrderDetailInfoSchema.Order, fieldName = "orderNo")
private String orderNo;


/**

* 订单类型 1:酒批 2: 合作商

*/

@OrderDetailInfoMapper(schema = OrderDetailInfoSchema.Order, fieldName = "orderType")
private Integer orderType;


/**

* 订单类型 0:普通订单 1: 限时惠

*/

@OrderDetailInfoMapper(schema = OrderDetailInfoSchema.Order, fieldName = "orderClassify")
private Integer orderClassify;


/**

* 订单状态

*/

@OrderDetailInfoMapper(schema = OrderDetailInfoSchema.Order, fieldName = "state", fieldTranslateClass = {OrderStatusTranslate.class})
private Integer orderState;


/**

* 订单金额

*/

@OrderDetailInfoMapper(schema = OrderDetailInfoSchema.Order, fieldName = "orderAmount")
private BigDecimal orderAmount;


/**

* 省

*/

@OrderDetailInfoMapper(schema = OrderDetailInfoSchema.Order, fieldName = "province")
private String orderProvince;


/**

* 市

*/

@OrderDetailInfoMapper(schema = OrderDetailInfoSchema.Order, fieldName = "city")
private String orderCity;


/**

* 区

*/

@OrderDetailInfoMapper(schema = OrderDetailInfoSchema.Order, fieldName = "county")
private String orderCounty;


/**

* 街道

*/

@OrderDetailInfoMapper(schema = OrderDetailInfoSchema.Order, fieldName = "street")
private String orderStreet;


/**

* 详细地址

*/

@OrderDetailInfoMapper(schema = OrderDetailInfoSchema.Order, fieldName = "detailAddres")
private String orderDetailAddres;


/**

* 电话号码

*/

@OrderDetailInfoMapper(schema = OrderDetailInfoSchema.Order, fieldName = "phone")
private String orderPhone;


/**

* 是否测试订单

*/

@OrderDetailInfoMapper(schema = OrderDetailInfoSchema.Order, fieldName = "isTestOrder")
private Boolean isTestOrder;


/**

* 用户id

*/

@OrderDetailInfoMapper(schema = OrderDetailInfoSchema.Order, fieldName = "userId")
private Integer orderUserId;


/**

* 经纪人id

*/

@OrderDetailInfoMapper(schema = OrderDetailInfoSchema.Order, fieldName = "salemanId")
private Integer orderSalemanId;


/**

* 配送模式

*/

@OrderDetailInfoMapper(schema = OrderDetailInfoSchema.Order, fieldName = "deliveryMode")
private Integer orderDeliveryMode;


/**

* 下单时间

*/

@OrderDetailInfoMapper(schema = OrderDetailInfoSchema.Order, fieldName = "orderCreateTime")
private Date orderCreateTime;


/**

* 下单审核时间

*/

@OrderDetailInfoMapper(schema = OrderDetailInfoSchema.Order, fieldName = "orderAuditTime")
private Date orderAuditTime;


/**

* 订单发货时间

*/

@OrderDetailInfoMapper(schema = OrderDetailInfoSchema.Order, fieldName = "orderDeliverTime")
private Date orderDeliverTime;


/**

* 订单撤销时间

*/

@OrderDetailInfoMapper(schema = OrderDetailInfoSchema.Order, fieldName = "orderCancelTime")
private Date orderCancelTime;


/**

* 订单完成时间

*/

@OrderDetailInfoMapper(schema = OrderDetailInfoSchema.Order, fieldName = "orderCompleteTime")
private Date orderCompleteTime;


/**

* 订单确认时间

*/

@OrderDetailInfoMapper(schema = OrderDetailInfoSchema.Order, fieldName = "orderConfirmTime")
private Date orderConfirmTime;


/**

* 订单的提交批次

*/

@OrderDetailInfoMapper(schema = OrderDetailInfoSchema.Order, fieldName = "OrderBatch_Id")
private BigInteger OrderBatchId;

/**

* 用户名

*/

@OrderDetailInfoMapper(schema = OrderDetailInfoSchema.Order, fieldName = "userName")
private String orderUserName;


/**

* 用户手机号

*/

@OrderDetailInfoMapper(schema = OrderDetailInfoSchema.Order, fieldName = "userMobileNo")
private String orderUserMobileNo;


/**

* 客户的店铺名

*/

@OrderDetailInfoMapper(schema = OrderDetailInfoSchema.Order, fieldName = "userCompanyName")
private String orderUserCompanyName;


/**

* 经销商店铺ID

*/

@OrderDetailInfoMapper(schema = OrderDetailInfoSchema.Order, fieldName = "shop_id")
private Integer orderShopId;

/**

* 订单项数

*/

@OrderDetailInfoMapper(schema = OrderDetailInfoSchema.Order, fieldName = "orderItemCount")
private Integer orderItemCount;



/**

* 订单项id

*/

@OrderDetailInfoMapper(schema = OrderDetailInfoSchema.Item, fieldName = "id")
private BigInteger itemId;


/**

* 订单项来源,XX活动

*/

@OrderDetailInfoMapper(schema = OrderDetailInfoSchema.Item, fieldName = "sourceType")
private Integer itemSourceType;

/**

* 来源ID

*/

@OrderDetailInfoMapper(schema = OrderDetailInfoSchema.Item, fieldName = "source_Id")
private BigInteger itemSourceId;

/**

* 普通商品(0),赠送商品(1),限时惠商品(2),加价购商品(3)

*/

@OrderDetailInfoMapper(schema = OrderDetailInfoSchema.Item, fieldName = "productType")
private Integer itemProductType;



/**

* 商品优惠劵减价金额

*/

@OrderDetailInfoMapper(schema = OrderDetailInfoSchema.ItemAmount, fieldName = "reduceCouponAmount")
private BigDecimal itemReduceCouponAmount;

/**

* 商品红包减价金额

*/

@OrderDetailInfoMapper(schema = OrderDetailInfoSchema.ItemAmount, fieldName = "reduceBonusAmount")
private BigDecimal itemReduceBonusAmount;

/**

* 订单满减金额

*/

@OrderDetailInfoMapper(schema = OrderDetailInfoSchema.ItemAmount, fieldName = "reduceOrderAmount")
private BigDecimal itemReduceOrderAmount;

/**

* 产品总价折扣=产品总价减价+商品优惠劵减价金额+商品红包减价金额+订单满减金额

*/

@OrderDetailInfoMapper(schema = OrderDetailInfoSchema.ItemAmount, fieldName = "discount")
private BigDecimal itemDiscount;

/**

* 产品总金额

*/

@OrderDetailInfoMapper(schema = OrderDetailInfoSchema.ItemAmount, fieldName = "totalAmount")
private BigDecimal itemTotalAmount;

/**

* 产品实付总金额

*/

@OrderDetailInfoMapper(schema = OrderDetailInfoSchema.ItemAmount, fieldName = "payAmount")
private BigDecimal itemPayAmount;

/**

* 配送费

*/

@OrderDetailInfoMapper(schema = OrderDetailInfoSchema.ItemAmount, fieldName = "deliveryAmount")
private BigDecimal itemDeliveryAmount;

/**

* 销售数量

*/

@OrderDetailInfoMapper(schema = OrderDetailInfoSchema.ItemAmount, fieldName = "saleCount")
private Integer itemSaleCount;

/**

* 销售数量小单位累计

*/

@OrderDetailInfoMapper(schema = OrderDetailInfoSchema.ItemAmount, fieldName = "minUnitTotalCount")
private Integer itemMinUnitTotalCount;

/**

* 自提优惠金额

*/

@OrderDetailInfoMapper(schema = OrderDetailInfoSchema.ItemAmount, fieldName = "selfPickUpReduceAmount")
private BigDecimal itemSelfPickUpReduceAmount;

/**

* 兑奖红包减价金额

*/

@OrderDetailInfoMapper(schema = OrderDetailInfoSchema.ItemAmount, fieldName = "reduceRewardBonusAmount")
private BigDecimal itemReduceRewardBonusAmount;

/**

* 优惠码优惠金额

*/

@OrderDetailInfoMapper(schema = OrderDetailInfoSchema.ItemAmount, fieldName = "reduceCouponCodeAmount")
private BigDecimal itemReduceCouponCodeAmount;

/**

* 产品总价减价

*/

@OrderDetailInfoMapper(schema = OrderDetailInfoSchema.ItemAmount, fieldName = "reduceProductAmount")
private BigDecimal itemReduceProductAmount;



/**

* 销售价

*/

@OrderDetailInfoMapper(schema = OrderDetailInfoSchema.ItemPrice, fieldName = "sellPrice")
private BigDecimal itemSellPrice;

/**

* 销售价单位

*/

@OrderDetailInfoMapper(schema = OrderDetailInfoSchema.ItemPrice, fieldName = "sellUnit")
private String itemSellUnit;

/**

* 小单位价格

*/

@OrderDetailInfoMapper(schema = OrderDetailInfoSchema.ItemPrice, fieldName = "minUnitPrice")
private BigDecimal itemMinUnitPrice;

/**

* 小单位名称

*/

@OrderDetailInfoMapper(schema = OrderDetailInfoSchema.ItemPrice, fieldName = "minUnitName")
private String itemMinUnitName;



/**

* 产品SKU id

*/

@OrderDetailInfoMapper(schema = OrderDetailInfoSchema.ItemProduct, fieldName = "productId")
private BigInteger itemProductId;


/**

* 产品销售规格ID

*/

@OrderDetailInfoMapper(schema = OrderDetailInfoSchema.ItemProduct, fieldName = "ProductSaleSpec_Id")
private BigInteger itemProductSaleSpecId;

/**

* 产品名称

*/

@OrderDetailInfoMapper(schema = OrderDetailInfoSchema.ItemProduct, fieldName = "productName")
private String itemProductName;


/**

* 销售规格系数

*/

@OrderDetailInfoMapper(schema = OrderDetailInfoSchema.ItemProduct, fieldName = "saleSpecQuantity")
private Integer itemProductSaleSpecQuantity;


/**

* 销售规格单位

*/

@OrderDetailInfoMapper(schema = OrderDetailInfoSchema.ItemProduct, fieldName = "sellUnit")
private String itemProductSellUnit;


/**

* 包装规格

*/

@OrderDetailInfoMapper(schema = OrderDetailInfoSchema.ItemProduct, fieldName = "productSpec")
private String itemProductSpec;


/**

* 包装规格系数

*/

@OrderDetailInfoMapper(schema = OrderDetailInfoSchema.ItemProduct, fieldName = "specQuantity")
private Integer itemProductSpecQuantity;


/**

* 大单位

*/

@OrderDetailInfoMapper(schema = OrderDetailInfoSchema.ItemProduct, fieldName = "packageName")
private String itemProductPackageName;


/**

* 小单位

*/

@OrderDetailInfoMapper(schema = OrderDetailInfoSchema.ItemProduct, fieldName = "unitName")
private String itemProductUnitName;


/**

* 供应商id

*/

@OrderDetailInfoMapper(schema = OrderDetailInfoSchema.ItemProduct, fieldName = "supplierId")
private Integer itemProductSupplierId;


/**

* 销售模式

*/

@OrderDetailInfoMapper(schema = OrderDetailInfoSchema.ItemProduct, fieldName = "saleMode")
private Integer itemProductSaleMode;


/**

* 销售模式大类

*/

@OrderDetailInfoMapper(schema = OrderDetailInfoSchema.ItemProduct, fieldName = "saleMode", fieldTranslateClass = {OrderSaleModeCategoryTranslate.class})
private Integer itemProductSaleModeCategory;


/**

* 产品业务类型,0,酒类,1,非酒类

*/

@OrderDetailInfoMapper(schema = OrderDetailInfoSchema.ItemProduct, fieldName = "productBusinessClass")
private Integer itemProductBusinessClass;



/**

* 仓库编号

*/

@OrderDetailInfoMapper(schema = OrderDetailInfoSchema.Jiupi, fieldName = "warehouse_Id")
private Integer jiupiOrderWarehouseId;

/**

* 配送人编号

*/

@OrderDetailInfoMapper(schema = OrderDetailInfoSchema.Jiupi, fieldName = "delivery_Id")
private Integer jiupiOrderDeliveryId;

/**

* 卸货人编号

*/

@OrderDetailInfoMapper(schema = OrderDetailInfoSchema.Jiupi, fieldName = "stevedore_Id")
private Integer jiupiOrderStevedoreId;

/**

* 关联订单编号

*/

@OrderDetailInfoMapper(schema = OrderDetailInfoSchema.Jiupi, fieldName = "relatedOrder_Id")
private BigInteger jiupiOrderRelatedOrderId;

/**

* 酒批订单类型:普通订单(0),分销商订单(1)

*/

@OrderDetailInfoMapper(schema = OrderDetailInfoSchema.Jiupi, fieldName = "jiupiOrderType")
private Integer jiupiOrderType;

/**

* 是否预售订单

*/

@OrderDetailInfoMapper(schema = OrderDetailInfoSchema.Jiupi, fieldName = "isPreSale")
private Integer jiupiOrderIsPreSale;

/**

* 酒批订单来源:合作商转酒批(0), 酒批订单(1),

*/

@OrderDetailInfoMapper(schema = OrderDetailInfoSchema.Jiupi, fieldName = "jiupiOrderSource")
private Integer jiupiOrderSource;

/**

* 仓管Id

*/

@OrderDetailInfoMapper(schema = OrderDetailInfoSchema.Jiupi, fieldName = "storeAdmin_Id")
private Integer jiupiOrderStoreAdminId;

枚举类:


public enum OrderDetailInfoSchema {
Order("o"), Jiupi("j"), Item("i"), ItemAmount("a"), ItemPrice("p"), ItemProduct("u"), LastModifyFlag("f");


private String familyName;


private OrderDetailInfoSchema(String familyName) {
this.familyName = familyName;

}
@Override

public String toString() {
return familyName;

}
}

注解类:



@Target({ElementType.FIELD})
@Retention(RetentionPolicy.RUNTIME)
@Documented
public @interface OrderDetailInfoMapper {
/**

* 属于哪个列族

*

* @return

*/

OrderDetailInfoSchema schema();


/**

* 原表中的字段名称

*

* @return

*/

String fieldName();


/**

* 对应字段的转换类

*

* @return

*/

Class<? extends IFieldTranslate<?>>[] fieldTranslateClass() default {};
}

package com.yjp.himalaya.stream.model.business;

import java.lang.annotation.*;

/**
 * 标记update时是否是自己感兴趣的字段时忽略
 *
 */
@Target({ElementType.FIELD})
@Retention(RetentionPolicy.RUNTIME)
@Documented
public @interface IgnoreField {
boolean isIgnore() default true;
}

接口类:

package com.yjp.himalaya.stream.model.hbase;

public interface IFieldTranslate<Input> {
Object translate(Input inputObject);
}

接口现实类:


public class OrderSaleModeCategoryTranslate implements IFieldTranslate<OrderItemProduct> {
@Override

public Integer translate(OrderItemProduct inputObject) {
if (inputObject.getSaleMode() == 0 || inputObject.getSaleMode() == 4) {
return 1;

}
return null;

}
}

实现方法:

Map<OrderDetailInfoSchema, Map<String, Field>> enumMap = new HashMap<>(6);
Map<Class, OrderDetailInfoSchema> enumClass = new HashMap<>(6);

{
enumMap.put(OrderDetailInfoSchema.Order, new HashMap<>());

enumMap.put(OrderDetailInfoSchema.Jiupi, new HashMap<>());

enumMap.put(OrderDetailInfoSchema.Item, new HashMap<>());

enumMap.put(OrderDetailInfoSchema.ItemAmount, new HashMap<>());

enumMap.put(OrderDetailInfoSchema.ItemPrice, new HashMap<>());

enumMap.put(OrderDetailInfoSchema.ItemProduct, new HashMap<>());



enumClass.put(Orders.class, OrderDetailInfoSchema.Order);

enumClass.put(JiupiOrder.class, OrderDetailInfoSchema.Jiupi);

enumClass.put(OrderItem.class, OrderDetailInfoSchema.Item);

enumClass.put(OrderItemAmount.class, OrderDetailInfoSchema.ItemAmount);

enumClass.put(OrderItemPrice.class, OrderDetailInfoSchema.ItemPrice);

enumClass.put(OrderItemProduct.class, OrderDetailInfoSchema.ItemProduct);
}
protected List<OrderDetailInfo> buildHbaseObject(Orders orders) throws IllegalAccessException, InstantiationException, NoSuchFieldException, NoSuchMethodException, InvocationTargetException {
List<Field> transFields = new ArrayList<>();

Field[] infoFields = OrderDetailInfo.class.getDeclaredFields();

for (Field infoField : infoFields) {
OrderDetailInfoMapper orderDetailInfoMapper = infoField.getAnnotation(OrderDetailInfoMapper.class);

if (null != orderDetailInfoMapper) {
//field
字段映射中的字段名

String field = orderDetailInfoMapper.fieldName();

OrderDetailInfoSchema orderDetailInfoSchema = orderDetailInfoMapper.schema();

Class<? extends IFieldTranslate<?, ?>>[]
classes = orderDetailInfoMapper.fieldTranslateClass();

if (classes.length == 0) {
//将字段映射中的字段名 和本来的字段名关联

enumMap.get(orderDetailInfoSchema).put(field, infoField);

} else {
transFields.add(infoField);

}
}
}
int num = orders.getOrderItemsList().size();

List<OrderDetailInfo> orderDetailInfos = new ArrayList<>(num);

for (int i = 0; i < num; i++) {
OrderDetailInfo orderDetailInfo = new OrderDetailInfo();

assignmentOrderDetailInfo(orders.getOrderItemsList().get(i), orderDetailInfo);

assignmentOrderDetailInfo(orders.getOrderItemAmountList().get(i), orderDetailInfo);

assignmentOrderDetailInfo(orders.getOrderItemPriceList().get(i), orderDetailInfo);

assignmentOrderDetailInfo(orders.getOrderItemProductList().get(i), orderDetailInfo);

assignmentOrderDetailInfo(orders.getJiupiOrder(), orderDetailInfo);

assignmentOrderDetailInfo(orders, orderDetailInfo);

//用方法设值的字段

for (Field field : transFields) {
OrderDetailInfoSchema orderDetailInfoSchema = field.getAnnotation(OrderDetailInfoMapper.class).schema();

Class<? extends IFieldTranslate<?, ?>>[]
classes = field.getAnnotation(OrderDetailInfoMapper.class).fieldTranslateClass();

Object value = null;

for (Map.Entry<Class, OrderDetailInfoSchema> entry : enumClass.entrySet()) {
if (entry.getValue() == orderDetailInfoSchema) {
Method method = classes[0].getDeclaredMethod("translate");

value = method.invoke(entry.getKey());

break;

}
}
field.set(orderDetailInfo, value);

}
orderDetailInfos.add(orderDetailInfo);

}
//存成一个静态的mapping表


//先要根据四个item,把OrderDetailInfo创建出来


//反射order


//反射OrderDetailInfo


//根据order中的所有字段,排除ignorefield,剩余的字段全部根据OrderDetailInfo中的所有用于如下条件的枚举的字段(Order),然后根据对应的值进行反射设值。注意如果有转换方法,要先调用转换方法,再赋值


//然后再依次处理OrderItem, OrderItemProduct....


//最后把所有未用的字段用warning打印出来


return orderDetailInfos;
}
private OrderDetailInfo assignmentOrderDetailInfo(Object item, OrderDetailInfo orderDetailInfo) throws IllegalAccessException, NoSuchFieldException {
Field[] itemFields = item.getClass().getDeclaredFields();

HashMap<String, Field> itemMap = (HashMap<String, Field>) enumMap.get(enumClass.get(item.getClass()));

for (Field field : itemFields) {
IgnoreField ignoreField = field.getAnnotation(IgnoreField.class);

if (ignoreField == null) {
field.setAccessible(true);

//infoField
OrderDetailInfo中对应的字段

Field infoField = itemMap.get(field.getName());

if (infoField != null) {
//传入对象的字段的值 field

field.get(item);

infoField.setAccessible(true);

//赋值

infoField.set(orderDetailInfo, field.get(item));

} else {
LOG.warn("字段未映射{}", field);

}
}
}
return orderDetailInfo;
}


最后

以上就是单纯发夹为你收集整理的有意思的代码的全部内容,希望文章能够帮你解决有意思的代码所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(66)

评论列表共有 0 条评论

立即
投稿
返回
顶部