悟心

成功不是将来才有的,而是从决定去做的那一刻起,持续累积而成。 上人生的旅途罢。前途很远,也很暗。然而不要怕。不怕的人的面前才有路。

  BlogJava :: 首页 :: 新随笔 :: 联系 :: 聚合  :: 管理 ::
  93 随笔 :: 1 文章 :: 103 评论 :: 0 Trackbacks
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](32NOT NULL,
    
[CREATE_TIME] [datetime] NULL,
    
[CREATE_USER] [varchar](20NULL,
    
[ROW_STATUS] [varchar](1NULL,
    
[UPDATE_TIME] [datetime] NULL,
    
[UPDATE_USER] [varchar](20NULL,
    
[CATEGORY] [varchar](40NULL,
    
[INITIAL_NUMBER] [numeric](100NULL,
    
[LAST_NUMBER] [numeric](100NULL,
    
[MAX_NUMBER] [numeric](100NULL,
    
[PREFIX_CHAR] [varchar](255NULL,
    
[REMARK] [varchar](40NULL,
    
[REMARKS] [varchar](250NULL,
    
[PERSTRING] [varchar](10NULL
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);

    }
posted on 2010-07-09 12:52 艾波 阅读(417) 评论(0)  编辑  收藏 所属分类: Java