云悦智销项目09_采购订单CRUD

一.准备数据

完成下面几个类的基本CRUD
systemdictionarytype:数据字典类型
systemdictionarydetail:数据字典明细
Supplier:供应商
Product:产品

二.采购订单分析

开发的时候要先分析这些字段
每个字段的含义
这个字段从哪里来?
这个字段是否可以为null

2.1 采购订单

/**
 * 采购订单
 */
@Entity
@Table(name = "purchasebill")
public class PurchaseBill extends BaseDomain{

    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;
    }

    ...
}

2.2 采购订单明细

/**
 * 采购订单的明细
 */
@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 //生成json的时候忽略这个属性
    private PurchaseBill bill;// 组合关系,非空
    
    ...
}

三.数据展示

3.1 数据显示部分
purchasebill.js
function statusFomat(v) {
    if(v==0){
        return "<span style='color: red;'>待审核</span>";
    }else if(v==1){
        return "<span style='color: green;'>审核通过</span>";
    }else{
        return "<s style='color: grey;'>作废</s>";
    }
}
function objFormat(v) {
    if(v){
        return v.name || v.username || v.title;
    }
}
...

purchasebill.jsp

<table class="easyui-datagrid" id="purchaseBillDataGrid"
       data-options="url:'/purchasebill/page',fitColumns:true,singleSelect:true,fit:true,toolbar:'#toolbar',pagination:true">
    <thead>
    <tr>
        <th data-options="field:'vdate',width:100">交易时间</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:statusFomat">状态</th>
        <th data-options="field:'supplier',width:100,formatter:objFormat">供应商</th>
        <th data-options="field:'buyer',width:100,formatter:objFormat">采购员</th>
    </tr>
    </thead>
</table>

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.2.2 后台实现

public class PurchaseBillQuery extends BaseQuery {
    //开始时间
    private Date beginDate;
    //结束时间
    private Date endDate;
    //状态
    private Integer status;
    //查询的规则应该在查询对象中来创建
    @Override
    public Specification createSpec(){
        //如果结束时间存在,就要加一天
        if(endDate!=null){
            //生成一个新的值,会加一天
            endDate = DateUtils.addDays(endDate,1);
        }

        Specification<PurchaseBill> specification = Specifications.<PurchaseBill>and()
                .ge(beginDate!=null,"vdate",beginDate)
                //注意:结束时间加了一天(只需要小于它即可)
                .lt(endDate!=null,"vdate",endDate)
                .eq(status!=null,"status",status)
                .build();
        return specification;
    }
    ...
}

四.数据添加

添加的时候如果报空(不能为空)的问题,你懂的!

<form id="editForm" method="post">
    <input id="purchaseBillId" type="hidden" name="id" />
    <table>
        <tr>
            <td>交易时间</td>
            <td><input class="easyui-datebox"  name="vdate" data-options="required:true" /></td>
        </tr>
        <tr>
            <td>供应商</td>
            <td>
                <input class="easyui-combobox" name="supplier.id"
                       data-options="valueField:'id',textField:'name',url:'/supplier/findAll',panelHeight:'auto',required:true" />
            </td>
        </tr>
        <tr>
            <td>采购员</td>
            <td> <input class="easyui-combobox" name="buyer.id"
                        data-options="valueField:'id',textField:'username',url:'/employee/findBuyers',required:true" /></td>
        </tr>
    </table>
</form>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值