采购订单
一. 数据准备
四张表
- product 产品
- producttype 产品类型
- systemdictionarydetail 数据字典明细
- systemdictionarytype 数据字典类型
1.1 product
@Entity
@Table(name = "product")
public class Product extends BaseDomain{
private String name;
private String color;
private String pic;
private String smallPic;
private BigDecimal costPrice;
private BigDecimal salePrice;
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "types_id")
//产品类型
private ProductType types;
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "unit_id")
//单位 数据明细
private SystemDictionaryDetail unit;
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "brand_id")
//品牌
private SystemDictionaryDetail brand;
public ProductType getTypes() {
return types;
}
public void setTypes(ProductType types) {
this.types = types;
}
public SystemDictionaryDetail getUnit() {
return unit;
}
public void setUnit(SystemDictionaryDetail unit) {
this.unit = unit;
}
public SystemDictionaryDetail getBrand() {
return brand;
}
public void setBrand(SystemDictionaryDetail brand) {
this.brand = brand;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getColor() {
return color;
}
public void setColor(String color) {
this.color = color;
}
public String getPic() {
return pic;
}
public void setPic(String pic) {
this.pic = pic;
}
public String getSmallPic() {
return smallPic;
}
public void setSmallPic(String smallPic) {
this.smallPic = smallPic;
}
public BigDecimal getCostPrice() {
return costPrice;
}
public void setCostPrice(BigDecimal costPrice) {
this.costPrice = costPrice;
}
public BigDecimal getSalePrice() {
return salePrice;
}
public void setSalePrice(BigDecimal salePrice) {
this.salePrice = salePrice;
}
@Override
public String toString() {
return "Product{" +
"name='" + name + '\'' +
", color='" + color + '\'' +
", pic='" + pic + '\'' +
", smallPic='" + smallPic + '\'' +
", costPrice=" + costPrice +
", salePrice=" + salePrice +
", id=" + id +
'}';
}
}
1.2 ProductType
@Entity
@Table(name = "producttype")
public class ProductType extends BaseDomain{
private String name;
private String descs;
//自联
@ManyToOne(fetch= FetchType.LAZY)
@JoinColumn(name="parent_id")
private ProductType parent;
public ProductType getParent() {
return parent;
}
public void setParent(ProductType parent) {
this.parent = parent;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getDescs() {
return descs;
}
public void setDescs(String descs) {
this.descs = descs;
}
@Override
public String toString() {
return "ProductType{" +
"name='" + name + '\'' +
", descs='" + descs + '\'' +
", id=" + id +
'}';
}
}
1.3 SystemDictionaryDetail
@Entity
@Table(name = "systemdictionarydetail")
public class SystemDictionaryDetail extends BaseDomain{
private String name;
@ManyToOne
@JoinColumn(name = "types_id")
private SystemDictionaryType type;
public SystemDictionaryType getType() {
return type;
}
public void setType(SystemDictionaryType type) {
this.type = type;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
@Override
public String toString() {
return "SystemDictionaryDetail{" +
"name='" + name + '\'' +
", id=" + id +
'}';
}
}
1.4 SystemDictionaryType
@Entity
@Table(name = "systemdictionarytype")
public class SystemDictionaryType extends BaseDomain{
private String sn;
private String name;
public String getSn() {
return sn;
}
public void setSn(String sn) {
this.sn = sn;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
@Override
public String toString() {
return "SystemDictionaryType{" +
"sn='" + sn + '\'' +
", name='" + name + '\'' +
", id=" + id +
'}';
}
}
二. 采购订单
首先分析这些字段
1)每个字段的含义
2)这个字段从哪里来?
3)这个字段是否可以为null
2.1 Purchasebill 采购订单
//采购订单
@Entity
@Table(name = "purchasebill")
public class Purchasebill 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;
//供应商 optional不能为空 前台传
@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 = "buyer_id")
private Employee buyer;
//组合关系 级联用最高级的级联
@OneToMany(cascade = CascadeType.ALL, mappedBy = "bill", fetch = FetchType.LAZY, orphanRemoval = true)
private List<Purchasebillitem> items = new ArrayList<Purchasebillitem>();
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone = "GMT+8")
public Date getVdate() {
return vdate;
}
public void setVdate(Date vdate) {
this.vdate = vdate;
}
public BigDecimal getTotalAmount() {
return totalAmount;
}
public void setTotalAmount(BigDecimal totalAmount) {
this.totalAmount = totalAmount;
}
public BigDecimal getTotalNum() {
return totalNum;
}
public void setTotalNum(BigDecimal totalNum) {
this.totalNum = totalNum;
}
public Date getInputTime() {
return inputTime;
}
public void setInputTime(Date inputTime) {
this.inputTime = inputTime;
}
public Date getAuditorTime() {
return auditorTime;
}
public void setAuditorTime(Date auditorTime) {
this.auditorTime = auditorTime;
}
public Integer getStatus() {
return status;
}
public void setStatus(Integer status) {
this.status = status;
}
public Supplier getSupplier() {
return supplier;
}
public void setSupplier(Supplier supplier) {
this.supplier = supplier;
}
public Employee getAuditor() {
return auditor;
}
public void setAuditor(Employee auditor) {
this.auditor = auditor;
}
public Employee getInputUser() {
return inputUser;
}
public void setInputUser(Employee inputUser) {
this.inputUser = inputUser;
}
public Employee getBuyer() {
return buyer;
}
public void setBuyer(Employee buyer) {
this.buyer = buyer;
}
public List<Purchasebillitem> getItems() {
return items;
}
public void setItems(List<Purchasebillitem> items) {
this.items = items;
}
@Override
public String toString() {
return "Purchasebill{" +
"vdate=" + vdate +
", totalAmount=" + totalAmount +
", totalNum=" + totalNum +
", inputTime=" + inputTime +
", auditorTime=" + auditorTime +
", status=" + status +
", id=" + id +
'}';
}
}
2.2 Purchasebillitem 采购订单明细
@Entity
@Table(name = "purchasebillitem")
public class Purchasebillitem 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")
@JsonIgnore //忽略
private Purchasebill bill ;
public Product getProduct() {
return product;
}
public void setProduct(Product product) {
this.product = product;
}
public BigDecimal getPrice() {
return price;
}
public void setPrice(BigDecimal price) {
this.price = price;
}
public BigDecimal getNum() {
return num;
}
public void setNum(BigDecimal num) {
this.num = num;
}
public BigDecimal getAmount() {
return amount;
}
public void setAmount(BigDecimal amount) {
this.amount = amount;
}
public String getDescs() {
return descs;
}
public void setDescs(String descs) {
this.descs = descs;
}
public Purchasebill getBill() {
return bill;
}
public void setBill(Purchasebill bill) {
this.bill = bill;
}
@Override
public String toString() {
return "Purchasebillitem{" +
"price=" + price +
", num=" + num +
", amount=" + amount +
", descs='" + descs + '\'' +
", id=" + id +
'}';
}
}
三. 前台数据展示
3.1 purchasebill.jsp
<%--数据结构--%>
<table id="datagrid" class="easyui-datagrid"
data-options="url:'/purchasebill/page',fitColumns:true,singleSelect:true,fit:true,pagination:true,toolbar:'#toolbar'">
<thead>
<tr>
<th data-options="field:'vdate',width:100">交易时间</th>
<th data-options="field:'supplier',width:100,formatter:objFormat">供应商</th>
<th data-options="field:'buyer',width:100,formatter:objFormat">采购员</th>
<th data-options="field:'totalAmount',width:100">总金额</th>
<th data-options="field:'totalNum',width:100">总数量</th>
<th data-options="field:'status',width:100,formatter:statusFormat">状态</th>
</tr>
</thead>
</table>
js代码 主要把数据格式化展示出来
/供应商采购员格式化显示
function objFormat(v) {
return v?v.name||v.username:"";
}
//状态格式化显示
function statusFormat(v) {
if(v == 0){
return "<span style='color: #c90f16'>待审</span>";
}else if (v == 1){
return "<span style='color: #348017;'>已审</span>";
}else{
return "<s style='color: #a3af8f;'>作废</s>";
}
}
3.2 高级查询部分
3.2.1 前台部分
<%--高级搜索--%>
<form id="searchForm" method="post">
交易时间: <input name="beginDate" class="easyui-datebox" style="width:120px"> -
<input name="endDate" class="easyui-datebox" style="width:120px">
状态: <select class="easyui-combobox" name="status" style="width:100px;" panelHeight="auto">
<option value="">---所有---</option>
<option value="0">待审</option>
<option value="1">已审</option>
<option value="-1">作废</option>
</select>
<a href="#" data-method="search" class="easyui-linkbutton" iconCls="icon-search">查询</a>
</form>
3.3.2 后台实现
在查询时间的时候,因为把时间的格式化到了秒,所有在查询的时候会有一个小bug
此时需要把结束时间+1天,然后再把它的条件设置为小于
//查询条件
public class PurchasebillQuery extends BaseQuery{
//开始时间
private Date beginDate;
//结束时间
private Date endDate;
//状态
private Integer status;
@Override
public Specification createSpec(){
//结束时间加1天
if(endDate!=null){
endDate = DateUtils.addDays(endDate,1);
}
Specification<Purchasebill> spec = Specifications.<Purchasebill>and()
//如果不为空
.ge(beginDate!=null,"vdate",beginDate)
//前面时间加了一天,这边变成小于
.lt(endDate!=null,"vdate",endDate)
.eq(status!=null,"status",status)
.build();
return spec;
}
public Date getBeginDate() {
return beginDate;
}
@DateTimeFormat(pattern = "yyyy-MM-dd")
public void setBeginDate(Date beginDate) {
this.beginDate = beginDate;
}
public Date getEndDate() {
return endDate;
}
@DateTimeFormat(pattern = "yyyy-MM-dd")
public void setEndDate(Date endDate) {
this.endDate = endDate;
}
public Integer getStatus() {
return status;
}
public void setStatus(Integer status) {
this.status = status;
}
}