采购订单的分析:
准备domin:
package cn.itsource.domain;
import com.fasterxml.jackson.annotation.JsonFormat;
import org.springframework.format.annotation.DateTimeFormat;
import javax.persistence.*;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
@Entity//采购单
@Table(name = "purchasebill")
public class Purchasebill extends BaseDaomain{
private Date vdate;// 交易时间 -> 需要录入(时间set的时候加上@DateTimeFormat(pattern = "yyyy-MM-dd"))
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 = "buyer_id")
private Employee buyer;// 多对一,非空 采购员 -> 需要
// 一般组合关系使用List 采购订单明细
@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;
}
@DateTimeFormat(pattern = "yyyy-MM-dd")
public void setVdate(Date vdate) {
this.vdate = vdate;
}
@Entity//采购明细
@Table(name = "purchasebillitem")
public class Purchasebillitem extends BaseDaomain{
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 //生成json的时候忽略这个属性
private Purchasebill bill;// 组合关系,非空
@Entity//供货商
@Table(name="supplier")
public class Supplier extends BaseDaomain{
private String name;
query层:
public class PurchasebillQuery extends BaseQuery{
// //自身条件
// //自身条件
private Date beginDate ;//开始时间
private Date endDate;//结束时间
private String status;//审核状态
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone = "GMT+8")
public Date getBeginDate() {
return beginDate;
}
@DateTimeFormat(pattern = "yyyy-MM-dd")
public void setBeginDate(Date beginDate) {
this.beginDate = beginDate;
}
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone = "GMT+8")
public Date getEndDate() {
return endDate;
}
@DateTimeFormat(pattern = "yyyy-MM-dd")
public void setEndDate(Date endDate) {
this.endDate = endDate;
}
public String getStatus() {
return status;
}
public void setStatus(String status) {
this.status = status;
}
public Specification createSpecification() {
//处理结束时间
Date tempDate=null;
if(this.getEndDate() != null){
tempDate = DateUtils.addDays(this.getEndDate(), 1);
}
//ge 大于等 vdate>= beginDate and vdate< endDate+1
//高级查询
Specification<Purchasebill> specification = Specifications.<Purchasebill>and()
.ge(this.beginDate!=null,"vdate",this.getBeginDate())
.lt(this.endDate!=null,"vdate",this.getEndDate())
.eq(StringUtils.isNotBlank(this.status),"status",this.getStatus())
.build();
return specification;
}
}
public class PurchasebillitemQuery extends BaseQuery{
// //自身条件
private String name;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Specification createSpecification() {
Specification<Purchasebillitem> specification = Specifications.<Purchasebillitem>and()
.like(StringUtils.isNotBlank(this.getName()),"name", "%"+this.getName()+"%")
.build();
return specification;
}
}
public class SupplierQuery extends BaseQuery{
// //自身条件
private String name;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Specification createSpecification() {
Specification<Supplier> specification = Specifications.<Supplier>and()
.like(StringUtils.isNotBlank(this.getName()),"name", "%"+this.getName()+"%")
.build();
return specification;
}
}
repository层:
public interface PurchasebillRepository extends BaseRepository<Purchasebill,Long> {
}
public interface PurchasebillitemRepository extends BaseRepository<Purchasebillitem,Long> {
}
public interface SupplierRepository extends BaseRepository<Supplier,Long> {
}
serviec层
public interface IPurchasebillService extends IBaseService<Purchasebill,Long> {
}
实现:
@Service
public class PurchasebillServiceImpl extends BaseServiceImpl<Purchasebill,Long> implements IPurchasebillService {
}
public interface IPurchasebillitemService extends IBaseService<Purchasebillitem,Long> {
}
实现:
@Service
public class PurchasebilltiemServiceImpl extends BaseServiceImpl<Purchasebillitem,Long> implements IPurchasebillitemService {
}
public interface ISupplierService extends IBaseService<Supplier,Long> {
}
实现:
@Service
public class SupplierServiceImpl extends BaseServiceImpl<Supplier,Long> implements ISupplierService {
}
controller层:
package cn.itsource.web.controller;
import cn.itsource.domain.*;
import cn.itsource.query.PurchasebillQuery;
import cn.itsource.query.PurchasebillitemQuery;
import cn.itsource.service.IPurchasebillService;
import cn.itsource.util.AjaxResult;
import cn.itsource.util.PageUi;
import cn.itsource.util.UserContent;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import java.math.BigDecimal;
import java.util.Date;
import jav