话费整理tools with GOG 施工中

我MM在财务部里头作小会计,每个月回有一张CT发过来的话费清单.每个号码一行.
公司里头有很多个部门,每个部门还有若干电话,有些还有宽带的费用.
现在要做的是将CT的话费单按部门分类好,然后统计出每个部门每个月的话费,网路费.
原来这个工具是用cakephp做的,现在改用GOG 试试

更新:
1-19: 输出界面用的是jqgrid,补一个图

[img]/upload/attachment/70190/870d2fcd-deba-368a-980b-c6a165acf077.png[/img]


需要Excel的 java库 :[url=http://jxl.sourceforge.net/]JXL[/url]

3个域模型
Dept:部门
Phone:电话
Bill:单行的话费


class Dept {
String name
static hasMany = [phones:Phone]
}



class Phone {
String name
String number
String type
static belongsTo = [dept:Dept]
static hasMany = [bills:Bill]
}



class Bill {
float price
Date date = new Date()
static belongsTo = [phone:Phone]
}


处理excel的服务

class ExcelService {

boolean transactional = true
def errors =[]
def save(FileInputStream file) throws RuntimeException{
//数据起始行号
def start_row = 5
//电话号码列
def phone_offset=0
//默认话费列
def total_offset = 16
//取数据列的列名 实收,实际要入库的帐单列; 业务号码,帐单上面的号码列名. 用来确认列的序列(有时候电信给的这个帐单列数会有变动,有时17列,有时候又18列)
static final String TOTAL_COL_NAME = '实收'
static final String NUMBER_COL_NAME = '业务号码'
//记录行错误
def out_errors = []
//获取第一个sheet
Workbook workbook = Workbook.getWorkbook(file)
Sheet sheet = workbook.getSheet(0)
//获取日期,精确到月即可,在A3格中.表格数据:计费帐期:2008/12/01--2008/12/31
def date_m = sheet.getCell("A3").getContents()=~ /:(\d{4}\/\d{2}\/\d{2})--/
def date =(new SimpleDateFormat('yyyy/MM/dd').parse(date_m[0][1]))
//获取业务号码,实收栏位置
sheet.getRow(4).each{
if(it.getContents()==NUMBER_COL_NAME){
phone_offset = it.getColumn()
}
if(it.getContents()==TOTAL_COL_NAME){
total_offset = it.getColumn()
return
}
}
//遍历所有行
(start_row..<sheet.getRows()).each{
println it
def cells = sheet.getRow(it);
def number = cells[phone_offset].getContents()
def price =Float.parseFloat(cells[total_offset].getContents())
def phone= Phone.findByNumber(number)
println number
if(phone){
println phone.name+"[${it}]:number=${number},price=${price}"
phone.addToBills(price:price,date:date).save()
}else{
this.errors.add("行[${it}]:没有找到对应的号码[${number}]")
}
}
if(this.errors.size()){
throw new RuntimeException("多行没有找到对应的号码!")
}
}
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值