好吧,我有 2 个 groovy 格式的文件。
首先是Transfer.Groovy
package com.revengtest
class Transfer {
Date dateCreated
Date lastUpdated
Date transferDate
String number
Float latitude
Float longitude
TransactionMaster transactionMaster
Warehouse warehouseSource
Warehouse warehouseDest
String reffNo
String toString() { return number }
static hasMany = [transferItems: TransferItem]
static belongsTo = [TransactionMaster, Warehouse]
static mapping = {
version false
}
static constraints = {
transferDate nullable: true
number nullable: true, maxSize: 45
longitude nullable: true
latitude nullable: true
}
//this is the code to automatic create the number in transfer
def beforeInsert(){
Integer count= Transfer.count()+1
Integer width= transactionMaster.width
String c = sprintf("%0${width}d",count)
number = transactionMaster.code+"/"+c
}
}
接下来是 TransactionMaster.groovy
package com.revengtest
class TransactionMaster {
static constraints = {
numbering(inList:["Monthly","Yearly"])
}
String code
Date dateCreated
Date lastUpdated
String name
String numbering
Integer width
TransferType transferType
String toString() { return name }
static hasMany = [transfers: Transfer]
static belongsTo = [TransferType]
}
在这里我从我的网络上得到了图片
这是交易母版页
这是转移页面->
现在的问题,我想让数字在月份变化时返回 0001,所以如果日期是 2013-08-14,数字应该从 0001 重新开始。在我的代码中它仍然是 0003,知道如何制作它发生?多谢你们。