@SecondaryTable

规格和分组价是一对多的关系, 所以使用@SecondaryTable注解后, 在查询SpecificationWithItemAndGroup实体时, 会出现重复数据. 在使用SpecificationWithItemAndGroup实体查询并且限制了关联表的条件可以锁定一个商品只出现一次, 如把groupId作为条件参与筛选

so, 注意@OneToMany和@SecondaryTable注解使用上的区别

@secondaryTable和hql中的leftjoin 然后对应一个实体表是等同的 见https://blog.csdn.net/asdfsadfasdfsa/article/details/79374873

@Entity
@Table(name = "item_specifications")
@SecondaryTable(name = "item_price_group_item_specification", pkJoinColumns = @PrimaryKeyJoinColumn(name = "item_specification_id"))
public class SpecificationWithItemAndGroup extends DefaultItemSpecification {
    @ManyToOne
    @JoinColumn(name = "item_Id", referencedColumnName = "id")
    @ApiModelProperty(value = "商品id")
    private ItemBreifInfo item;

    @Column(name = "trade_price")
    @ApiModelProperty(value = "当前进货价(保留字段,后续采购对接)")
    @ApiParam(hidden = true)
    @JsonSerialize(using = PriceSerializer.class)
    private Integer currentTradePrice;

    @Column(name = "current_gross_profit")
    @ApiModelProperty(value = "当前毛利率")
    @IntegerFormatter(retentionNum = 1)
    @JsonSerialize(using = IntegerSerializer.class)
    @JsonDeserialize(using = IntegerDeserializer.class)
    private Integer currentProfitPercent;

    @Column(name = "trade_modifiy_time")
    @ApiModelProperty(name = "商品进价的更新时间")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private LocalDateTime tradeModifyTime;

    @Transient
    @ApiModelProperty(value = "毛利预期(保留字段,后续采购对接)")
    private ProfitmarginExpection expection = ProfitmarginExpection.ALL_RIGHT;

    @Transient
    @ApiModelProperty(value = "当前毛利")
    @JsonSerialize(using = PriceSerializer.class)
    private Integer currentProfit;

    @Transient
    private List<GroupPriceBreifInfo> groupPrice;

    @Transient
    private List<PersonalPriceBriefInfo> personalPrice;

    @Setter
    @Getter
    @Column(name = "id", table = "item_price_group_item_specification")
    @ApiModelProperty("分组价表的id")
    private Long groupPriceId;

    @Setter
    @Getter
    @Column(name = "price_group_id", table = "item_price_group_item_specification")
    @ApiModelProperty("分组id")
    private String groupId;}

 

posted @ 2019-01-18 09:28  車輪の唄  阅读(40)  评论(0)    收藏  举报  来源