薪酬模块生成工资条

主要运用easyUI 、 Hibernate 、Servlet 。

1.动态生成标签页,

$(function(){
	//创建打开新标签页
	$(".easyui-linkbutton").click(function(){
		
		$("#img").panel('close');
		//获取组件的属性或内容
		var tab_title = $(this).text();//关键在this选择当前事件
		var tab_href = $(this).attr("title");
		var dd =  $(this).attr("id");
		//alert(tab_href);
		if($("#tt").tabs("exists",tab_title))
			{
				$("#tt").tabs("select",tab_title)
			}
		else if(dd=="dd")
			{
			$("#gz").dialog('open');
			
			}
		else
			{
				$("#tt").tabs('add',{
					title:tab_title,
					closable:true,
					//href:tab_href
					content:""
				});
			}
		
	});
	
})

  这里主要是用inframe来获取href,避免多个标签页同时打开产生冲突。

 

2.然后就是生成工资条的弹窗,

这里是根据考勤表里的状态来获取月份的,(0表示未生成工资条)

注意下拉框是通过URL、valueFeild、textFeild 把value的值传递的,参考:省市区三级联动

薪酬模块生成工资条_第1张图片

3.点击生成按钮后,需要加载数据,需要一段时间,所以加了个进度条

	
 	
 

  页面层





Insert title here


















   
   		


  生成工资条:

  薪酬模块生成工资条_第2张图片

获取下拉框月份的Servlet层

protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		//转码
		request.setCharacterEncoding("UTF-8");
		response.setCharacterEncoding("UTF-8");
		response.setContentType("text/html");
		
		//调用底层查询表月份的集合
		SPayDAO sp = new SPayDAO();
		List lss = sp.getMonth();
		//System.out.println(lss);
		
		List ls = new ArrayList();
		for(int i=0;i 
    
   

  提交from表单的select层

protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		//转码
		request.setCharacterEncoding("UTF-8");
		response.setCharacterEncoding("UTF-8");
		response.setContentType("text/html");
		
		//接受月份
		String date = request.getParameter("date");
		
		
		System.out.println("date="+date);
		String msg = "{'success':true,'message':'保存成功'}";
		if(date != null)
		{
			try
			{
				
				SPayDAO sp = new SPayDAO();
				sp.unite(date);
				
			}
			catch(Exception e)
			{
				 msg = "{'success':false,'message':'访问失败'}";
			}

			response.getWriter().print(msg);
		}
		else
		{
			 msg = "{'success':false,'message':'没有要生成的工资'}";
				response.getWriter().print(msg);
		}
				
	}

  DAO层

package com.hanqi.dao;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
import org.hibernate.cfg.Configuration;
import org.hibernate.service.ServiceRegistry;

import com.hanqi.entity.Basic;
import com.hanqi.entity.Deal;
import com.hanqi.entity.KqMonthkaoqin;
import com.hanqi.entity.Rank;
import com.hanqi.entity.Rate;
import com.hanqi.entity.SPay;

public class SPayDAO {
	
	Configuration  cfg = null;
	ServiceRegistry  sr = null;
	 SessionFactory sf = null;
	 Session  se =null;
	Transaction tr = null;
	
	public SPayDAO()//注册服务
	{
		//1.加载配置文件
				cfg = new Configuration().configure();
				//2.注册服务
				 sr = new  StandardServiceRegistryBuilder()
						.applySettings(cfg.getProperties()).build();
	}
	//初始化
	private void init()
	{
		try
		{
			sf= cfg.buildSessionFactory(sr);
		}
		catch(Exception e)
		{
			//1.加载配置文件
			cfg = new Configuration().configure();
			//2.注册服务
			 sr = new  StandardServiceRegistryBuilder()
					.applySettings(cfg.getProperties()).build();
			sf= cfg.buildSessionFactory(sr);
			
		}
		
		
		se = sf.openSession();
		tr = se.beginTransaction();//启动事物
		
	}
	//提交和释放
	private void destroy()
	{
		try
		{
		tr.commit();//提交事务
		
		}
		catch(Exception e)
		{
			//1.加载配置文件
			cfg = new Configuration().configure();
			//2.注册服务
			 sr = new  StandardServiceRegistryBuilder()
					.applySettings(cfg.getProperties()).build();
			sf= cfg.buildSessionFactory(sr);
			se = sf.openSession();
			tr = se.beginTransaction();
			tr.commit();//提交事务
		}
		
		se.close();
		sf.close();
	}
	
	//联合查询
	public void unite(String date)
	{
		 
		 
		
		double zhengchang = getZhengchangJiaban();
		 double zhoumo = getzhoumo();
		 double jiaqi = getJiaqi();
		 double  chidao = getChidao ();
		 double zaotui =  getZaotui();
		 double kuanggong = getKuanggong();
		 List rate = getRate();
		 init();
		 System.out.println("uwef="+date);
		 List lb = se.createQuery("from KqMonthkaoqin where zhuangtai= 0 and to_char(kaoqinmonth,'yyyy-MM')=?")
				 .setString(0, date).list() ;
		
		 System.out.println(lb);
		 SPay sp = new SPay();
		  for(KqMonthkaoqin k : lb)
		  {
			  sp.setPayid(date+k.getStaffid());//获取并写入工资表的薪资编号
			  
			  sp.setYuangongid(k.getStaffid());//获取员工id
			  sp.setEmployeename(getName(k.getStaffid()));;//员工姓名
			  //基本工资
			 
			  double jb = getSalary(Integer.parseInt(getLevels(k.getStaffid())));
			  sp.setJibengongzi( jb);
			
			  //加班总金额
			  double zc = zhengchang*k.getJiaban();
			  double zm = zhoumo*k.getZhoumojiaban();
			  double jq = jiaqi*(k.getJiejiarijiaban());
			  double z = zc+zm+jq ;
			  sp.setJiaban(z);
					  
					  
			  //请假
			  sp.setQingjia(k.getQingjia());
			  //迟到
			  sp.setChidao(chidao*(k.getChidao()));
			  //早退
			  sp.setZaotui(zaotui*(k.getZaotui()));
			  //旷工
			  sp.setKuanggong(kuanggong*k.getKuanggong());
			  //五险
			  sp.setWuxian(jb*0.1);
			  //公积金
			  sp.setGongjijin(jb*0.08);
			  //全勤
			  if(k.getChidao()!=0 || k.getZaotui() != 0 || k.getQingjia() != 0 ||k.getKuanggong() !=0)
			  {
				  sp.setQuanqin(getquanqin());
			  }
			  else
			  {
				  sp.setQuanqin(0);
			  }
			  //应发工资
			  double yingfa = jb+z-(jb*0.1+jb*0.08);
			  sp.setYingfa(yingfa);
			  
			  
			  //纳税
			 double nashui = 0;
			 //判断是否纳税
			 if(yingfa-rate.get(0).getStartpay()<=0)
			{
				
			}
			 else
			 {
				 for(int i=0; i getMonth()
	{
		init();
		List li = new ArrayList();
		li = se.createQuery("select distinct to_char(kaoqinmonth,'yyyy-MM') from KqMonthkaoqin where zhuangtai='0' ").list();
		
		 destroy();
		return li;
		
	}
	
	//根据考勤表的员工id查询员工表的姓名
	public String getName(String yuangongid)
	{
		init();
		String rtn = "";
		List li = new ArrayList();
		 li = se.createQuery("select name from Basic where yuangongid = ? ")
		  .setString(0, yuangongid)
		.list() ;
		
		if(li.size()>0)
		{
			rtn = li.get(0).toString();
		}
		 
		destroy();
		
		
		destroy();
		return rtn;
		
	}

	//根据员工编号查询员工等级
	public String getLevels(String yuangongid)
	{
		init();
		String rtn = "";
		List li = new ArrayList();
		 li = se.createQuery("select jibie from Basic where yuangongid = ? and zhuangtai = '在职'")
		  .setString(0, yuangongid)
		.list() ;
		
		if(li.size()>0)
		{
			rtn = li.get(0).toString();
		}
		 
		destroy();
		
		 return rtn;
		
	}

	//根据等级查询员工基本工资
	public int getSalary(int levels)
	{
		init();
		int rtn =0;
		
		List li = new ArrayList();
		li = se.createQuery("select salary from Rank where levels = ?")
				.setLong(0, levels).list();
		if(li.size()>0)
		{
			rtn = Integer.parseInt(li.get(0).toString());	
		}
		
		destroy();
		return rtn;
		
	}
	//查询全勤奖励
	public int getquanqin()
	{
		int rtn =0;
		
		init();
		
		List li = new ArrayList();
		
		li = se.createQuery("select quanqin from Deal where state='1'")
				.list();
		System.out.println("list.size = " + li.size());
		if(li.size()>0)
		{
			rtn = (Integer.parseInt(li.get(0).toString()));	
		}
		
		destroy();
		return rtn;
	}
//获取Deal表的正常加班单价
public int getZhengchangJiaban()
{
	int rtn =0;
	
	init();
	
	List li = new ArrayList();
	//查询启用状态下正常加班的金额
	li = se.createQuery("select zhengban from Deal where state='1'")
			.list();
	if(li.size()>0)
	{
		rtn = (Integer.parseInt(li.get(0).toString()));	
	}
	
	destroy();
	return rtn;
	
}
//获取周末加班单价
public int getzhoumo()
{
	int rtn =0;
	
	init();
	
	List li = new ArrayList();
	//查询启用状态下周末加班的金额
	li = se.createQuery("select zhouban from Deal where state='1'")
			.list();
	if(li.size()>0)
	{
		rtn = (Integer.parseInt(li.get(0).toString()));	
	}
	
	destroy();
	return rtn;
	
}

	//获取节假日加班
	public int getJiaqi()
	{
		int rtn =0;
		
		init();
		
		List li = new ArrayList();
		//查询启用状态下节假日加班的金额
		li = se.createQuery("select jieban from Deal where state='1'")
				.list();
		if(li.size()>0)
		{
			rtn = (Integer.parseInt(li.get(0).toString()));	
		}
		
		destroy();
		return rtn;
	}
	
	//获取迟到金额
	
	public int getChidao ()
	{

		int rtn =0;
		
		init();
		
		List li = new ArrayList();
		//查询启用状态下迟到一次的金额
		li = se.createQuery("select chidao from Deal where state='1'")
				.list();
		if(li.size()>0)
		{
			rtn = (Integer.parseInt(li.get(0).toString()));	
		}
		
		destroy();
		return rtn;
	}
	
	//获取早退
	public int getZaotui()
	{
		int rtn =0;
		
		init();
		
		List li = new ArrayList();
		//查询启用状态下迟到一次的金额
		li = se.createQuery("select zaotui from Deal where state='1'")
				.list();
		if(li.size()>0)
		{
			rtn = (Integer.parseInt(li.get(0).toString()));	
		}
		
		destroy();
		return rtn;
	}
	
	//获取旷工
	public int getKuanggong()
	{
		int rtn =0;
		
		init();
		
		List li = new ArrayList();
		//查询启用状态下旷工一次的金额
		li = se.createQuery("select kuanggong from Deal where state='1'")
				.list();
		if(li.size()>0)
		{
			rtn = (Integer.parseInt(li.get(0).toString()));	
		}
		
		destroy();
		return rtn;
	}
	
	
	
	//获取分页数据集合列表
		public List getPageList(int page , int rows,String sort,Map where)
		{
			init();
			//创建基础HQL语句
			String sql = "from SPay where 1=1";
			
			//判断传递的的参数
			String yuangongid =  where.get("yuangongid_s");
			
			if(yuangongid != null && !yuangongid.equals(""))
			{
				sql += " and yuangongid ";
			}
			//排序
					
			if(sort != null && !sort.equals(""))
				{
					sql += " order by " + sort;
				}
			
			//得到HQL
			//并判断查询条件
			Query q = se.createQuery(sql);
			
			if(yuangongid != null && !yuangongid.equals("") )
			{
			
				q.setString("yuangongid", yuangongid);//引号的内容必须跟上面引号后的别名一致
			}
			System.out.println("yuangongid="+yuangongid);
			
			 List rtn = new ArrayList(); 
			 rtn = q.setMaxResults(rows)//每页行数
					 .setFirstResult((page-1)*rows).list();//其实页码

			 destroy();
			return rtn;
		}
		
		
		
		
		
		
		
		//获取数据条数
		public int getTotal(Map where)
		{
			int rtn= 0;
			init();
			
			//创建基础HQL语句
			String sql = "select count(1) from  SPay where 1=1";
			
			//判断传递的的参数
			String yuangongid_s =  where.get("yuangongid_s");
			if(yuangongid_s != null && !yuangongid_s.equals(""))
			{
				sql += " and yuangongid  )";//and前面加空格
			}
			
			//得到HQL
			//并判断查询条件
			Query q = se.createQuery(sql);
					
			if(yuangongid_s != null && !yuangongid_s.equals("") )
			{
				
				q.setString("yuangongid", yuangongid_s);
				//引号的内容必须跟上面引号后的别名一致
				
			}
			
			
			//获取Query对对象,定义集合并实例化
			List lo = q.list();
			
			if(lo != null && lo.size() > 0)
			{
				rtn = Integer.parseInt(lo.get(0).toString());//转换成int并赋值
			}
			
			 destroy();
			
			
			return rtn;
		}
}
 
    
   

  DAO层主要是围绕着联合查询这个方法来的,通过给中小方法,获取其他表的数据,生成工资表SPay中的各个字段,然后添加,也就是一个添加的过程。

这个项目所遇到的一些问题:代码优化,逻辑还不够严谨。

转载于:https://www.cnblogs.com/liuyanzeng/p/6168704.html

你可能感兴趣的:(薪酬模块生成工资条)