ruby考勤分析-创新互联
BOSS要远程考勤。只有几个人而已。然后用AAU写了一个考勤的,RUBY这个是查询MYSQL,然后发送邮件到人事那边用的(以附件方式发)。代码如下。
为滨城等地区用户提供了全套网页设计制作服务,及滨城网站建设行业解决方案。主营业务为网站制作、网站建设、滨城网站设计,以传统方式定制建设网站,并提供域名空间备案等一条龙服务,秉承以专业、用心的态度为用户提供真诚的服务。我们深信只要达到每一位用户的要求,就会得到认可,从而选择与我们长期合作。这样,我们也可以走得更远!#!/usr/bin/ruby require 'mysql' require 'time' require 'net/smtp' require 'mailfactory' csv_str = "id,name,start work,get off work,hour\n" day = Time.now.strftime("%Y-%m-%d") filename = "/home/163/check_in/" + Time.now.to_s.split[0] + ".csv" db = Mysql.init db.options(Mysql::SET_CHARSET_NAME, 'utf8') db = Mysql.real_connect("192.168.1.4", "kq", "123123", "kq123", 3306) db.query("SET NAMES utf8") user = db.query("select * from username") def writefile(str,filename) aFile = File.new(filename,"w") aFile.puts str aFile.close end def sendmail(text, file) mail = MailFactory.new mail.from = "test@163.com" mail.subject = text mail.text = text mail.attach(file); mail.to = 'you@163.com' acct = 'test@163.com' domain = "163.com" pass = '123123' Net::SMTP.start('smtp.163.com', 25, domain, acct, pass, :login) do |smtp| smtp.send_message mail.to_s(),'test@163.com','you@163.com' end end while row = user.fetch_row do next if row[0] == '1' time_max = db.query("select max(time) from kqtime where time>\"#{day + " 06:00"}\" and time <\"#{day + " 23:00"}\" and userid=#{row[0]}").fetch_row[0] time_min = db.query("select min(time) from kqtime where time>\"#{day + " 06:00"}\" and time <\"#{day + " 23:00"}\" and userid=#{row[0]}").fetch_row[0] if time_min.nil? && time_max.nil? csv_str = csv_str + row[0] + "," + row[1] + ",,,0.0\n" elsif time_min.nil? csv_str = csv_str + row[0] + "," + row[1] + "," + time_min.to_s.split[-1][0..-4] + ",,0.0\n" elsif time_max.nil? csv_str = csv_str + row[0] + "," + row[1] + ",," + time_max.to_s.split[-1][0..-4] + ",0.0\n" else time_ok = Time.parse(time_max.to_s) - Time.parse(time_min.to_s) min = time_ok % (60) if time_ok < 3600 && time_min.to_s.split(':')[0][-2..-1].to_i < 13 csv_str = csv_str + row[0] + "," + row[1] + "," + time_min.to_s.split[-1][0..-4] + ",,0.0\n" elsif time_ok < 3600 && time_max.to_s.split(':')[0][-2..-1].to_i > 13 csv_str = csv_str + row[0] + "," + row[1] + ",," + time_max.to_s.split[-1][0..-4] + ",0.0\n" else min = time_ok % (60) if min < 15 min = time_ok.div(60).div(60) + 0.0 elsif min >= 15 && min < 45 min = time_ok.div(60).div(60) + 0.5 elsif min >= 45 min = time_ok.div(60).div(60) + 1.0 end csv_str = csv_str + row[0] + "," + row[1] + "," + time_min.to_s.split[-1][0..-4] + "," + time_max.to_s.split[-1][0..-4] + "," + min.to_s + "\n" end end end writefile(csv_str, filename) sendmail(Time.now.to_s.split[0] + " Check-In", filename)
另外有需要云服务器可以了解下创新互联scvps.cn,海内外云服务器15元起步,三天无理由+7*72小时售后在线,公司持有idc许可证,提供“云服务器、裸金属服务器、高防服务器、香港服务器、美国服务器、虚拟主机、免备案服务器”等云主机租用服务以及企业上云的综合解决方案,具有“安全稳定、简单易用、服务可用性高、性价比高”等特点与优势,专为企业上云打造定制,能够满足用户丰富、多元化的应用场景需求。
标题名称:ruby考勤分析-创新互联
网页URL:http://scyanting.com/article/cojsds.html