⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 attendrecordserviceimpl.java

📁 oa办公系统
💻 JAVA
字号:
/**
 * FileName:AttendRecordServiceImpl.java,v 1.0 created in 2008-11-8 上午08:22:34
 * Created by Noel Han
 * Copyright (c) 2008 Ecjtu
 * All Rights Reserved.
 */
package cn.jx.ecjtu.oa.services.impl;

import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.text.MessageFormat;
import java.text.SimpleDateFormat;

import cn.jx.ecjtu.oa.ps.dao.AttendRecordDao;
import cn.jx.ecjtu.oa.ps.dao.DaoFactory;
import cn.jx.ecjtu.oa.ps.dao.LoginUserDao;
import cn.jx.ecjtu.oa.ps.pojo.AttendRecord;
import cn.jx.ecjtu.oa.ps.pojo.LoginUser;
import cn.jx.ecjtu.oa.services.AttendRecordService;

/**
 * @todo:Description
 * @author Noel Han
 * @version $Revision: 1.31 $
 * @since 1.0
 */
public class AttendRecordServiceImpl implements AttendRecordService {

	private AttendRecordDao attendRecordDaoImpl = (AttendRecordDao) DaoFactory
			.getDao(AttendRecordDao.class);

	private LoginUserDao loginUserDaoImpl = (LoginUserDao) DaoFactory
			.getDao(LoginUserDao.class);

	/**
	 * 审批
	 */
	public int censor(AttendRecord record, int statusId) {
		record.setStatusId(statusId);
		return attendRecordDaoImpl.update(record);
	}

	/**
	 * 删除提交的申请
	 */
	public int deleteApply(int recordId) {
		return attendRecordDaoImpl.remove(recordId);
	}

	/**
	 * 部门考勤统计 返回LoginUser与统计结果键值对的HashMap
	 */
	public HashMap<LoginUser, Integer> deptCount(List<Integer> userIds,
			String from, String to, int appTypeId) {
		
		HashMap<LoginUser, Integer> count = new HashMap<LoginUser, Integer>();
		
		if(from==null || from.equals("")){
			from = "00000000000000";
		}
		if(to==null || to.equals("")){
			to = "99999999999999";
		}
		
		if(userIds==null || userIds.size()==0){
			List list = loginUserDaoImpl.findAllUser();
			for(int i=0; i<list.size();i++){
				LoginUser user = (LoginUser)list.get(i);
				count.put(user,this.personCount(user.getId(), from, to, appTypeId));
			} 
		} else {
			for (int i = 0; i < userIds.size(); i++) {
				int userId = userIds.get(i);
				count.put(loginUserDaoImpl.findById(userId), this.personCount(
						userId, from, to, appTypeId));
			}
		}
		return count;
	}

	/**
	 * 部门考勤查询
	 */
	public List deptQuery(List<Integer> userIds, String from,
			String to, int appTypeId) {
		List records = new ArrayList();
		
		if(from==null || from.equals("")){
			from = "00000000000000";
		}
		if(to==null || to.equals("")){
			to = "99999999999999";
		}
		
		if(userIds==null || userIds.size()==0){
			List list = loginUserDaoImpl.findAllUser();
			for(int i=0; i<list.size();i++){
				int userId = ((LoginUser)list.get(i)).getId();
				records.addAll(this.personQuery(userId, from, to, appTypeId));
			} 
		} else {
			for(int i=0; i<userIds.size();i++){
				records.addAll(this.personQuery(userIds.get(i), from, to, appTypeId));
			}
		}
		return records;
	}

	public int modifyRecord(AttendRecord record) {
		return attendRecordDaoImpl.update(record);
	}

	/**
	 * 个人考勤统计,返回次数。
	 */
	public int personCount(int userId, String from, String to,
			int appTypeId) {
		int count=0;
		
		if(from==null || from.equals("")){
			from = "00000000000000";
		}
		if(to==null || to.equals("")){
			to = "99999999999999";
		}
		
		if(appTypeId == 0) {
			for (int i = 1; i <= 3; i++) {
				count+= attendRecordDaoImpl.count(userId, from,
						to, i);
			}
		}else if(appTypeId>=1 && appTypeId <=3 ){
			count = attendRecordDaoImpl.count(userId, from, to, appTypeId);
		}
		return count;
	}

	/**
	 * 个人考勤查询
	 */
	public List personQuery(int userId, String from, String to,
			int appTypeId) {
		List list = new ArrayList(); 
		
		if(from==null || from.equals("")){
			from = "00000000000000";
		}
		if(to==null || to.equals("")){
			to = "99999999999999";
		}
		
		if(appTypeId == 0){
			for(int i=1;i<=3;i++){
				List temp = attendRecordDaoImpl.find(userId, from, to, i);
				list.addAll(temp);
			}
		}else {
			list=attendRecordDaoImpl.find(userId, from, to, appTypeId);
		}
		return list;
	}

	/**
	 * 返回登记
	 */
	public int signBack(int recordId, String time) {
		AttendRecord record = attendRecordDaoImpl.findByRecordId(recordId);
		record.setBackTime(time);
		return attendRecordDaoImpl.update(record);
	}

	/**
	 * 提交申请
	 */
	public int submitApply(AttendRecord record) {
		return attendRecordDaoImpl.save(record);
	}

	/**
	 * 生成短信息
	 */
	public String getMsg(AttendRecord record) {
		String msgModel = attendRecordDaoImpl
				.getMsgModel(record.getAppTypeId());
		String realName = loginUserDaoImpl.findById(record.getUserId())
				.getRealName();
		String destination = record.getDestination();
		if (destination == null) {
			destination = "";
		}
		String toLeave = record.getToLeave();
		String toReturn = record.getToReturn();
		String temp = this.digit2String(toLeave);
		if (toLeave.lastIndexOf("000000") == 8) {
			toLeave = temp.substring(0, 10);
		}
		temp = this.digit2String(toReturn);
		if (toReturn.lastIndexOf("000000") == 8) {
			toReturn = temp.substring(0, 10);
		}
		// toLeave = this.
		String msg = MessageFormat.format(msgModel, new Object[] { realName,
				toLeave, toReturn, record.getDestination() });
		return msg;
	}

	/**
	 * 获取要进行返回登记得那条考勤记录,没有则返回null
	 */
	public AttendRecord getToSign(int userId) {
		return attendRecordDaoImpl.findToSign(userId);
	}

	/**
	 * 获取指定类型的待批申请
	 */
	public List getUnCensored(int appTypeId) {
		List list = new ArrayList();
		if(appTypeId == 0){
			for(int i=1;i<=3;i++){
				list.addAll(attendRecordDaoImpl.findByStatusAndType(1,i));
			}
		}else {
			list = attendRecordDaoImpl.findByStatusAndType(1, appTypeId);
		}
		return list;
	}

	/**
	 * 时间格式的转换 Date类型转换为yyyy-MM-dd HH:mm:ss格式
	 */
	public String date2String(Date date) {

		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		return sdf.format(date);
	}

	/**
	 * 时间格式的转换 Date类型转换为纯数字串
	 */
	public String date2Digit(Date date) {
		SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss");
		return sdf.format(date);
	}

	/**
	 * 时间格式的转换 yyyy-MM-dd HH:mm:ss格式转换为纯数字串
	 */
	public String string2Digit(String date) {
		if(date==null || date.equals("")){
			return date="";
		}
		String time = date.substring(0, 4) + date.substring(5, 7)
				+ date.substring(8, 10) + date.substring(11, 13)
				+ date.substring(14, 16) + date.substring(17);
		return time;
	}

	/**
	 * 时间格式的转换 纯数字串转换为yyyy-MM-dd HH:mm:ss格式
	 */
	public String digit2String(String digit) {
		String date = digit.substring(0, 4) + "-" + digit.substring(4, 6) + "-"
				+ digit.substring(6, 8) + " " + digit.substring(8, 10) + ":"
				+ digit.substring(10, 12) + ":" + digit.substring(12);
		return date;
	}

	/**
	 * 通过recordId查找记录
	 */
	public AttendRecord getSingleRecord(int recordId) {
		AttendRecord record = attendRecordDaoImpl.findByRecordId(recordId);
		return record;
	}

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -