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

📄 webserviceimpl.java

📁 本系统可初步满足超市的收支管理
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
			{
				Dept d = (Dept)it.next();
				DeptVo dv = new DeptVo(d.getDeptId() , d.getDeptName() , d.getDescription());
				result.add(dv);
			}
			tran.commit();
			return result;
		}
		catch (Exception ee)
		{
			throw new WEBException("列出所有部门时出现异常,请重试");
		}
		finally
		{
			HibernateUtil.closeSession();
		}
	}

	/**
	 * 增加一笔收入
	 * @param daily 收入数量
	 * @param businessDate 业务日期
	 * @param lstModTimestamp 最后修改时间
	 * @param deptName 部门名
	 * @return 增加收入是否成功
	 */
	public boolean createIncome(Integer daily , String businessDate , String lstModTimestamp ,String deptName)throws WEBException
	{
		IncomeDao dd = null;
		try
		{
			dd = (IncomeDao)DaoFactory.instance().getDao("incomeDao");
			Session sess = HibernateUtil.currentSession();
			Transaction tran = sess.beginTransaction();
			Income d = new Income();
			d.setDaily(daily);
			d.setBusinessDate(businessDate);
			d.setLstModTimestamp(lstModTimestamp);
			List l = dd.findByName(sess , deptName);
			for (Iterator it = l.iterator(); it.hasNext() ; )
			{
				Dept dept = (Dept)it.next();
				if (dept.getDeptName().equals(deptName))
				{
					d.setDept(dept);
					dd.save(sess , d);
					tran.commit();
					HibernateUtil.closeSession();
					return true;
				}
			}		
			tran.commit();
			return false;
		}
		catch (Exception ee)
		{
			throw new WEBException("新增收入时出现异常,请重试");
		}
		finally
		{
			HibernateUtil.closeSession();
		}
	}

	/**
	 * 根据分页列出所有收入
	 * @param page 页码
	 * @return 指定页的所有收入
	 */
	public Collection showIncome(int page)throws WEBException
	{
		IncomeDao incomeDao = null;
		int beginPage = 0;
		int listPage = 0;
		if (page == 1)
		{
			beginPage = 0;
			listPage = beginPage + 10;
		}
		else
		{
			beginPage = page * 10;
			listPage = beginPage + 10;
		}
		Collection result = new ArrayList();
		try
		{
			incomeDao = (IncomeDao)DaoFactory.instance().getDao("incomeDao");
			Session sess = HibernateUtil.currentSession();
			Transaction tran = sess.beginTransaction();
			List l = incomeDao.findByShowIncome(sess , beginPage , listPage);
			for (Iterator it = l.iterator(); it.hasNext() ; )
			{
				Income d = (Income)it.next();
				String deptName = d.getDept().getDeptName();
				IncomeVo dv = new IncomeVo(d.getIncomeId() , d.getDaily() , d.getBusinessDate() , d.getLstModTimestamp() , deptName);
				result.add(dv);
			}
			tran.commit();
			return result;
		}
		catch (Exception ee)
		{
			throw new WEBException("查询收入时出现异常,请重试");
		}
		finally
		{
			HibernateUtil.closeSession();
		}
	}

	/**
	 * 修改收入
	 * @param incomeId 收入id
	 * @param daily 收入数量
	 * @param lstModTimestamp 最后修改时间
	 * @return 修改收入是否成功
	 */
	public boolean updateIncome(Integer incomeId , Integer daily ,String lstModTimestamp )throws WEBException
	{
		IncomeDao dd = null;
		try
		{
			dd = (IncomeDao)DaoFactory.instance().getDao("incomeDao");
			Session sess = HibernateUtil.currentSession();
			Transaction tran = sess.beginTransaction();
			Income d = dd.get(sess , incomeId);
			if (d != null)
			{
				d.setDaily(daily);
				d.setLstModTimestamp(lstModTimestamp);
				dd.update(sess , d);
				return true;
			}
			tran.commit();
			return false;
		}
		catch (Exception ee)
		{
			throw new WEBException("修改收入时出现异常,请重试");
		}
		finally
		{
			HibernateUtil.closeSession();
		}
	}

	/**
	 * 根据ID查询收入
	 * @param id 收入id
	 * @return 指定ID对应收入组成的集合
	 */
	public Collection showIncomeId(Integer id)throws WEBException
	{
		IncomeDao incomeDao = null;
		Collection result = new ArrayList();
		try
		{
			incomeDao = (IncomeDao)DaoFactory.instance().getDao("incomeDao");
			Session sess = HibernateUtil.currentSession();
			Transaction tran = sess.beginTransaction();
			Income d = incomeDao.get(sess , id);
			String deptName = d.getDept().getDeptName();
			IncomeVo dv = new IncomeVo(d.getIncomeId() , d.getDaily() , d.getBusinessDate() , d.getLstModTimestamp() , deptName);
			result.add(dv);
			tran.commit();
			return result;
		}
		catch (Exception ee)
		{
			throw new WEBException("无法获得指定的收入,请重试");
		}
		finally
		{
			HibernateUtil.closeSession();
		}
	}

	/**
	 * 登录系统
	 * @param username 登录系统所用的用户名
	 * @param password 登录系统所用的密码
	 * @return 登录是否成功
	 */
	public boolean login(String username , String password)throws WEBException
	{
		UserDao userDao = null;
		try
		{
			userDao = (UserDao)DaoFactory.instance().getDao("userDao");
			Session sess = HibernateUtil.currentSession();
			Transaction tran = sess.beginTransaction();
			User u = userDao.get(sess , username);
			if (u != null && u.getPassword().equals(password))
			{
				tran.commit();
				HibernateUtil.closeSession();
				return true;
			}
			tran.commit();
			return false;
		}
		catch (Exception ee)
		{
			throw new WEBException("登录系统出现异常,请重新登入");
		}
		finally
		{
			HibernateUtil.closeSession();
		}	
		
	}

	/**
	 * 增加一个帐单
	 * @param billDate 帐单日期
	 * @param billDueDate 帐单到期日期
	 * @param vendor 帐单对应的供货商
	 * @return 增加帐单是否成功
	 */	
	public boolean createBill(String billDate , String billDueDate , String vendor)throws WEBException
	{
		System.out.println("vendor=" + vendor);
		BillDao dd = null;
		try
		{
			dd = (BillDao)DaoFactory.instance().getDao("billDao");
			Session sess = HibernateUtil.currentSession();
			Transaction tran = sess.beginTransaction();
			Bill d = new Bill();
			d.setBillDate(billDate);
			d.setBillDueDate(billDueDate);
			List l = dd.findByNameToVendor(sess , vendor);
			for (Iterator it = l.iterator(); it.hasNext() ; )
			{
				Vendor v = (Vendor)it.next();
				if (v.getVendorName().equals(vendor))
				{
					d.setVendor(v);
					dd.save(sess , d);
					tran.commit();
					return true;
				}
			}
			tran.commit();
			HibernateUtil.closeSession();
			return false;
		}
		catch (Exception ee)
		{
			throw new WEBException("新增帐单时出现异常,请重试");
		}
		finally
		{
			HibernateUtil.closeSession();
		}
	}

	/**
	 * 根据供货商查询帐单
	 * @param vendor 供货商
	 * @return 该供货商对应的帐单
	 */
	public Collection showBillPayment(int page , String vendor)throws WEBException
	{
		BillDao billDao = null;
		int beginPage = 0;
		int listPage = 0;
		if (page == 1)
		{
			beginPage = 0;
			listPage = beginPage + 10;
		}
		else
		{
			beginPage = page * 10;
			listPage = beginPage + 10;
		}
		Collection result = new ArrayList();
		try
		{
			billDao = (BillDao)DaoFactory.instance().getDao("billDao");
			Session sess = HibernateUtil.currentSession();
			Transaction tran = sess.beginTransaction();
			List ll = billDao.findByNameToVendor(sess , vendor);
			for (Iterator itt = ll.iterator(); itt.hasNext() ; )
			{
				Vendor vvv = (Vendor)itt.next();
				if (vvv.getVendorName().equals(vendor))
				{
					int id = vvv.getVendorId();
					List l = billDao.findByVendorId(sess , id , beginPage , listPage);
					for (Iterator it = l.iterator(); it.hasNext() ; )
					{
						Bill v = (Bill)it.next();
						String vendorName = v.getVendor().getVendorName();
						if (v.getBillPaidFlag() == 0)
						{
							BillVo vv = new BillVo(v.getBillId() , v.getBillDate() , v.getBillDueDate() , 
								v.getBillPaidFlag() , vendorName);
							result.add(vv);
						}
					}
				}
			}
			tran.commit();
			return result;
		}
		catch (Exception ee)
		{
			throw new WEBException("查询帐单时出现异常,请重试");
		}
		finally
		{
			HibernateUtil.closeSession();
		}
	}

	/**
	 * 修改一个帐单
	 * @param id 帐单ID
	 * @return 修改帐单是否成功
	 */
	public boolean billUpdate(Integer id)throws WEBException
	{
		BillDao vd = null;
		try
		{
			vd = (BillDao)DaoFactory.instance().getDao("billDao");
			Session sess = HibernateUtil.currentSession();
			Transaction tran = sess.beginTransaction();
			Bill v = vd.get(sess , id);
			if (v != null)
			{
				v.setBillPaidFlag(1);
				vd.update(sess , v);
				tran.commit();
				HibernateUtil.closeSession();
				return true;
			}
			tran.commit();
			return false;
		}
		catch (Exception ee)
		{
			throw new WEBException("修改帐单时出现异常,请重试");
		}
		finally
		{
			HibernateUtil.closeSession();
		}
	}

	public Collection showBillAddDepItem()throws WEBException
	{
		IncomeDao incomeDao = null;
		Collection result = new ArrayList();
		try
		{
			incomeDao = (IncomeDao)DaoFactory.instance().getDao("incomeDao");
			Session sess = HibernateUtil.currentSession();
			Transaction tran = sess.beginTransaction();
			List l = incomeDao.findByShowIncome(sess);
			System.out.println("l=" + l);
			for (Iterator it = l.iterator(); it.hasNext() ; )
			{
				Income v = (Income)it.next();
				String deptName = v.getDept().getDeptName();
				IncomeVo dv = new IncomeVo(v.getIncomeId() , v.getDaily() , v.getBusinessDate() , v.getLstModTimestamp() , deptName);
				result.add(dv);
			}
			tran.commit();
			return result;
		}
		catch (Exception ee)
		{
			throw new WEBException("业务异常,请重新登入");
		}
		finally
		{
			HibernateUtil.closeSession();
		}
	}
}

⌨️ 快捷键说明

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