USE [fa1]
GO
/****** 对象: Table [dbo].[SYS_SERIAL_NUMBER] 脚本日期: 07/09/2010 12:45:23 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [dbo].[SYS_SERIAL_NUMBER](
[ID] [varchar](32) NOT NULL,
[CREATE_TIME] [datetime] NULL,
[CREATE_USER] [varchar](20) NULL,
[ROW_STATUS] [varchar](1) NULL,
[UPDATE_TIME] [datetime] NULL,
[UPDATE_USER] [varchar](20) NULL,
[CATEGORY] [varchar](40) NULL,
[INITIAL_NUMBER] [numeric](10, 0) NULL,
[LAST_NUMBER] [numeric](10, 0) NULL,
[MAX_NUMBER] [numeric](10, 0) NULL,
[PREFIX_CHAR] [varchar](255) NULL,
[REMARK] [varchar](40) NULL,
[REMARKS] [varchar](250) NULL,
[PERSTRING] [varchar](10) NULL
) ON [PRIMARY]
GO
SET ANSI_PADDING OFF
GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'ID' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'SYS_SERIAL_NUMBER', @level2type=N'COLUMN',@level2name=N'ID'
GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'CREATE_TIME' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'SYS_SERIAL_NUMBER', @level2type=N'COLUMN',@level2name=N'CREATE_TIME'
GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'CREATE_USER' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'SYS_SERIAL_NUMBER', @level2type=N'COLUMN',@level2name=N'CREATE_USER'
GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'ROW_STATUS' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'SYS_SERIAL_NUMBER', @level2type=N'COLUMN',@level2name=N'ROW_STATUS'
GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'UPDATE_TIME' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'SYS_SERIAL_NUMBER', @level2type=N'COLUMN',@level2name=N'UPDATE_TIME'
GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'UPDATE_USER' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'SYS_SERIAL_NUMBER', @level2type=N'COLUMN',@level2name=N'UPDATE_USER'
GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'前缀' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'SYS_SERIAL_NUMBER', @level2type=N'COLUMN',@level2name=N'CATEGORY'
GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'起初号码' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'SYS_SERIAL_NUMBER', @level2type=N'COLUMN',@level2name=N'INITIAL_NUMBER'
GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'最后号码' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'SYS_SERIAL_NUMBER', @level2type=N'COLUMN',@level2name=N'LAST_NUMBER'
GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'最大的流水号' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'SYS_SERIAL_NUMBER', @level2type=N'COLUMN',@level2name=N'MAX_NUMBER'
GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'PREFIX_CHAR' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'SYS_SERIAL_NUMBER', @level2type=N'COLUMN',@level2name=N'PREFIX_CHAR'
GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'REMARK' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'SYS_SERIAL_NUMBER', @level2type=N'COLUMN',@level2name=N'REMARK'
GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'REMARKS' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'SYS_SERIAL_NUMBER', @level2type=N'COLUMN',@level2name=N'REMARKS'
GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'PERSTRING' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'SYS_SERIAL_NUMBER', @level2type=N'COLUMN',@level2name=N'PERSTRING'
GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'流水号' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'SYS_SERIAL_NUMBER'
import javax.annotation.Resource;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Table;
import com.spro.core.domain.IdEntity;
@Resource
@Entity
@Table(name = "SYS_SERIAL_NUMBER")
public class SerialNumber extends IdEntity {
private String category;//前缀
private Integer LastNumber;//流水号
private Integer MaxNumber;
private Integer InitialNumber;
private String Remark;
private String PrefixChar;
@Column(length = 40)
public String getCategory() {
return category;
}
public void setCategory(String category) {
this.category = category;
}
public Integer getLastNumber() {
return LastNumber;
}
public void setLastNumber(Integer lastNumber) {
LastNumber = lastNumber;
}
public Integer getMaxNumber() {
return MaxNumber;
}
public void setMaxNumber(Integer maxNumber) {
MaxNumber = maxNumber;
}
public Integer getInitialNumber() {
return InitialNumber;
}
public void setInitialNumber(Integer initialNumber) {
InitialNumber = initialNumber;
}
@Column(length = 40)
public String getRemark() {
return Remark;
}
public void setRemark(String remark) {
Remark = remark;
}
public String getPrefixChar() {
return PrefixChar;
}
public void setPrefixChar(String prefixChar) {
PrefixChar = prefixChar;
}
}
public String setSerialNumber(String category, int beginNum, int maxMum, int length) {
int lastNumber;
SerialNumber serialNumber = null;
String hql = "select s from SerialNumber s where category ='" + category + "'";
List list = serialNumberDao.find(hql);
if (list != null && list.size() > 0) {
serialNumber = (SerialNumber) list.get(0);
}
if (serialNumber == null) {
SerialNumber sm = new SerialNumber();
sm.setCategory(category);
sm.setLastNumber(beginNum);
sm.setInitialNumber(beginNum);
sm.setMaxNumber(maxMum);
serialNumberDao.save(sm);
lastNumber = beginNum;
} else {
System.out.println("serialNumber:" + serialNumber.getLastNumber());
if (serialNumber.getLastNumber().intValue() == serialNumber.getMaxNumber().intValue()) {
System.out.println("已经超过最大生成数。请管理员重新排定");
return null;
}
lastNumber = serialNumber.getLastNumber() + 1;
System.out.println("lastNumber:" + lastNumber);
serialNumber.setLastNumber(lastNumber);
serialNumberDao.save(serialNumber);
}
if (length == 0) {
return lastNumber + "";
}
return StringUtil.ZeroPer(lastNumber + "", length);
}