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

📄 agentserviceimpl.java

📁 一个关于物流的管理系统
💻 JAVA
字号:
package com.shunshi.ssh.service;

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

import org.extremecomponents.table.limit.Limit;

import com.shunshi.ssh.dao.IAgentDao;
import com.shunshi.ssh.dao.IAllInfoDao;
import com.shunshi.ssh.entity.Agent;
import com.shunshi.ssh.entity.AllInfo;
import com.shunshi.ssh.entity.Page;
import com.shunshi.ssh.exception.AgentDaoException;
import com.shunshi.ssh.exception.AgentServiceException;

public class AgentServiceImpl implements IAgentService {
	private IAgentDao dao;
	private IAllInfoDao allInfoDao;
	public IAgentDao getDao() {
		return dao;
	}

	public void setDao(IAgentDao dao) {
		this.dao = dao;
	}

	public IAllInfoDao getAllInfoDao() {
		return allInfoDao;
	}

	public void setAllInfoDao(IAllInfoDao allInfoDao) {
		this.allInfoDao = allInfoDao;
	}

	public void addAgent(Agent agent) throws AgentServiceException {
		try {
			dao.add(agent);
		} catch (AgentDaoException e) {
			throw new AgentServiceException("代理信息添加出错");
		}

	}

	public void delete(int[] ids) throws AgentServiceException {
		for(int id:ids){
			try {
				dao.delete(id);
			} catch (AgentDaoException e) {
				throw new AgentServiceException("代理信息删除出错");
			}
			
		}

	}

	

	public Agent findById(int id) throws AgentServiceException {
		
		
		Agent a = null;
		try{
			a = dao.findById(id);
		} catch (AgentDaoException e) {
			throw new AgentServiceException("查找代理信息出错");
		}
		
		return a;
	}


	public List findByUser(int id) throws AgentServiceException {
		
		List l = null;
		try {
			l = dao.findByUserId(id);
		} catch (AgentDaoException e) {
			throw new AgentServiceException("查找用户信息出错");
		}
		
		return l;
	}
	
	public void updateState(int[] ids,int  state) throws AgentServiceException {
		for(int i=0;i<ids.length;i++){
			try {
				dao.updateState(ids[i], state);
			} catch (AgentDaoException e) {
				throw new AgentServiceException(e.getMessage());
			}
		}
	}

	public void updateAgent(Agent a) throws AgentServiceException {
		try {
			dao.updateAgent(a);
		} catch (AgentDaoException e) {
			throw new AgentServiceException("更新代理信息出错");
		}
		
	}


	public Page findByState(int state, Limit size, int totalRows)
			throws AgentServiceException {
		try{
			if (totalRows < 0) {
			totalRows = dao.getTotalRowsByState(state).intValue();
		}
			size.setRowAttributes(totalRows, Page.DEFAULT_PAGE_SIZE);	
		int[] startAndEnd= new int[]{size.getRowStart(),size.getCurrentRowsDisplayed()};
		
		List<Agent> agents=dao.findByState(state, startAndEnd[0],startAndEnd[1]);
		List agentInfos =new ArrayList();
		Integer order=new Integer(1);
		for(Agent a:agents){
			Map agentMap=new HashMap();
			agentMap.put("title",a.getTitle());
			agentMap.put("order", order++);
			agentMap.put("deadline",a.getDeadline());
			agentMap.put("userId",a.getUserId());
			if(1==a.getState())
				agentMap.put("state","等待审核");
			else if(2==a.getState())
				agentMap.put("state", "通过审核");
			else if(3==a.getState())
				agentMap.put("state", "等待回收");
			agentMap.put("id",a.getId());
			agentInfos.add(agentMap);
		}
		
		
		Page page = new Page(size.getRowStart(),totalRows,size.getPage(),agentInfos);
		return page;
		}catch(AgentDaoException e){
			throw new AgentServiceException(e.getMessage());
		}
		
	}

	public AllInfo getAllInfo() throws AgentServiceException {
		Agent agent=null;
		try {
			agent = dao.findByMaxId();
		} catch (AgentDaoException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		AllInfo info=new AllInfo();
		info.setName(agent.getTitle());
		info.setType("航空铁路代理信息");
		info.setClassType("agent");
		info.setUserId(agent.getUserId().longValue());
		info.setBid(agent.getId().longValue());
		return info;
	}

	public void saveAllInfo(AllInfo allInfo) throws AgentServiceException {
		allInfoDao.addInfo(allInfo);
		
	}

	public void deleteAllInfo(Agent agent) throws AgentServiceException {
		allInfoDao.deleteObject(agent);
	}

}

⌨️ 快捷键说明

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