一共涉及到4张表,仓库,入库订单.入库订单明细,即时库存
1.仓库实体类
@Entity
@Table(name="depot")
public class Depot extends BaseDomain {
private String name;
private BigDecimal maxCapacity;// 最大数量,参考值
private BigDecimal currentCapacity;;// 当前数量,参考值
private BigDecimal totalAmount;// 当前仓库里面的产品值多少钱
2.入库订单:组合关系的一方
@Entity
@Table(name="stockincomebill")
public class Stockincomebill extends BaseDomain {
private Date vdate;// 交易时间
private BigDecimal totalAmount; //总金额
private BigDecimal totalNum;//总数量
private Date inputTime = new Date();//录入时间
private Date auditorTime;//审核时间
/**
* 0待审,1已审,-1作废
*/
private Integer status = 0; //审核状态 默认未审
@ManyToOne(fetch = FetchType.LAZY, optional = false)
@JoinColumn(name = "supplier_id")
private Supplier supplier;// 供应商 多对一,非空
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "auditor_id")
private Employee auditor;// 审核员 多对一,可以为空
@ManyToOne(fetch = FetchType.LAZY, optional = false)
@JoinColumn(name = "inputUser_id")
private Employee inputUser;// 录入员 多对一,非空
@ManyToOne(fetch = FetchType.LAZY, optional = false)
@JoinColumn(name = "keeper_id")
private Employee keeper;// 仓管员 多对一,非空
@ManyToOne(fetch = FetchType.LAZY, optional = false)
@JoinColumn(name = "depot_id")
private Depot depot;// 仓库编号 多对一,非空
// 一般组合关系使用List
@OneToMany(cascade = CascadeType.ALL, mappedBy = "bill", fetch = FetchType.LAZY, orphanRemoval = true)
private List<Stockincomebillitem> items = new ArrayList<Stockincomebillitem>();
3.入库订单明细:组合关系的多方
@Entity
@Table(name="stockincomebillitem")
public class Stockincomebillitem extends BaseDomain {
private BigDecimal price;
private BigDecimal num;
private BigDecimal amount;
private String descs;
@ManyToOne(fetch = FetchType.LAZY, optional = false)
@JoinColumn(name = "product_id")
private Product product;//产品 多对一,非空
@ManyToOne(fetch = FetchType.LAZY, optional = false)
@JoinColumn(name = "bill_id")
private Stockincomebill bill;// 组合关系,非空
4.即时库存
private BigDecimal num;// 当前仓库的产品的数量
private BigDecimal amount;// 当前仓库的产品的小计
private BigDecimal price;// 当前仓库的产品的价格
private Date incomedate;// 入库时间
private Boolean warning = true;// 库存过多,过少自动发出库存预警
private BigDecimal topnum = new BigDecimal(100);// 最大库存量
private BigDecimal bottomnum = new BigDecimal(50);// 最小库存量
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "product_id")
private Product product;
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name="depot_id")
private Depot depot;
**2 测试保存 **
跟单文员(仓库员)登录进销存系统,先录入入库订单进行保存
仓库经理登录,进行入库订单审核 ,这是分开的,现在保存还没有审核经理和时间
public class StockincomebillServiceTest extends BaseTest {
@Autowired
private IStockincomebillService stockincomebillService;
@Test
public void testName() throws Exception{
//入库--进入stockincomebill 和stockincomeitem表 类似采购单保存
//创建入库主单
Stockincomebill bill = new Stockincomebill();
Depot depot = new Depot();
depot.setId(1L);
bill.setDepot(depot)