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

📄 contractaction.java

📁 sso呵呵
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
				if("contId".equals(tempItem.getFieldName())) contrID = tempItem.getString();
				else if("file".equals(tempItem.getFieldName()) && !tempItem.isFormField()) fileItem = tempItem;
			}
			contractAttach = getService();
//			System.out.println(">><< contId:*" + contrID + "*");
			// 保存附件
			addAttach(fileItem, contrID);
			//根据合同范本ID 重新得到合同范本 (起到的作用是刷新当前合同范本的附件列表)
			cont = contractAttach.getContractById(contrID);
		}catch(Exception e){
			S_LOGGER.error(e.getMessage());
		}

    	//组织合同类型
    	Map typeMap = buildType();
    	request.setAttribute("typeMap", typeMap);
		request.setAttribute("contract", cont);
//		System.out.println("<<<< ContractAction.uploadAttach()");
		return mapping.findForward("SUCCESS");
	}

	/**
	 *
	 * 方法描述 删除合同范本附件
	 * @param mapping
	 * @param form
	 * @param request
	 * @param response
	 * @return ActionForward "SUCCESS"
	 */
	public ActionForward delelteAttach(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response) {
//		System.out.println(">>>> ContractAction.delelteAttach");
		//资源ID
		String resourceId = request.getParameter("resId");
		String contrID = request.getParameter("contrID");
		IContractManager icont = null;
		try {
			//得到接口的实例
			icont = getService();
			//根据 资源的id 删除资源
			icont.delelteAttach(resourceId);
		}catch(Exception e){
			e.printStackTrace();
		}
		//根据合同范本ID 重新得到合同范本 (起到的作用是刷新当前合同范本的附件列表)
		Contract cont = icont.getContractById(contrID);
    	//组织合同类型
    	Map typeMap = buildType();
    	request.setAttribute("typeMap", typeMap);
		request.setAttribute("contract", cont);
//		System.out.println("<<<< ContractAction.delelteAttach()");
		return mapping.findForward("SUCCESS");
	}

	/**
	 *
	 * 方法描述 下载合同范本附件
	 * @param mapping
	 * @param form
	 * @param request
	 * @param response
	 * @return ActionForward Null
	 */
	public ActionForward downloadAttach(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response) {
//		System.out.println(">>>> ContractAction.downloadAttach()");
		//资源ID
		String resourceId = request.getParameter("resId");
		try {
			//得到接口的实例
			IContractManager icont = getService();
			//根据 资源的id 得到合同对象
			ContractAttach cont = (ContractAttach) icont.downloadAttach(resourceId);
			String fileName = cont.getName();

			if(fileName != null && fileName.equals("")){
				throw new IOException();
			}

			//设置回应对象的头
			response.setContentType("text/plain;charset=UTF-8");
			response.setHeader("Cache-Control", "public");
			response.setHeader("Content-Disposition", "attachment; filename=" + URLEncoder.encode(fileName, "UTF-8"));
			response.setBufferSize(100 * 1024);
			//输出回应对象的主体(attchment)
			InputStream file = null;
			try{
				file = new ByteArrayInputStream(cont.getFile());
			}catch(Exception e){
				S_LOGGER.error(e.getMessage());
			}
			ServletOutputStream out = response.getOutputStream();

			byte[] buf = new byte[128];
			int len;
			//向reponse里输出 文件的内容
			while((len = file.read(buf))>0){
				out.write(buf, 0, len);
			}
			// 关闭输出
			out.flush();
			out.close();
			file.close();
		} catch (Exception e){
			S_LOGGER.error(e.getMessage());
		}

//		System.out.println("<<<< ContractAction.downloadAttach()");
		return null;
	}

	/**
	 *
	 * 方法描述 初始化页面
	 * @param mapping
	 * @param form
	 * @param request
	 * @param response
	 * @return ActionForward "SUCCESS"
	 */
    public ActionForward initpage(ActionMapping mapping, ActionForm form,
            HttpServletRequest request, HttpServletResponse response) {

//    	System.out.println(">>>> ContractAction.initpage()");
    	//组织合同类型
    	Map typeMap = buildType();
    	request.setAttribute("typeMap", typeMap);
//    	System.out.println("<<<< ContractAction.initpage()");
    	return mapping.findForward("SUCCESS");
    }

    /**
     *
     * 方法描述 组织一个合同大类型下的数据集
     * @param mapping
     * @param form
     * @param request
     * @param response
     * @return
     */
    public ActionForward viewdata(ActionMapping mapping, ActionForm form,
            HttpServletRequest request, HttpServletResponse response) {
//	   	System.out.println(">>>> ContractAction.viewdata()");
	   	//请求合同大类型的ID
	   	String bigTypeID = request.getParameter("bigTypeID");
		//用于判断是不是管理员
		String admin = request.getParameter("admin");
	   	//合同大类型列表
		List bigTypes = null;
		//一个合同大类的小类型和小类型内的范本的数据集合
		BigType_SmallTypesBean bigTypeDates = null;
		try {
			IContractManager service = getService();
			bigTypes = service.getBigType();

//			System.out.println(">><< bigTypes:" + bigTypes);
			//判断是不是默认显示数据
			if(bigTypeID != null && bigTypes != null && bigTypes.size()>0 ){
//					System.out.println(">><< bigTypeID:" + bigTypeID);
					// 得到请求的合同大类型
					Map bitItem = service.getBigTypeByID(bigTypeID);
					// 组织对应的一个合同大类的数据集
					bigTypeDates = this.buildBigTypeDatas(bitItem);
			}else if(bigTypes != null && bigTypes.size()>0 ){
					//得到第一个合同大类型做为默认显示
					Map bitItem = (Map) bigTypes.get(0);
					//组织一个合同大类的数据集
					bigTypeDates = this.buildBigTypeDatas(bitItem);
			}
		} catch (Exception e) {
			e.printStackTrace();
		}

//		System.out.println("<<<< ContractAction.viewdata()");
		request.setAttribute("BIGTYPES", bigTypes);
		request.setAttribute("BIGTYPEDATAS", bigTypeDates);
		if(admin != null && admin.equals("true")){
			return mapping.findForward("ADMINVIEW");
		}else{
			return mapping.findForward("VIEW");
		}
    }

    /**
     *
     * 方法描述 组织一个合同大类型下的数据集
     * @param bitItem 一个合同大类型
     * @return BigType_SmallTypesBean
     */
    private BigType_SmallTypesBean buildBigTypeDatas(Map bitItem){

    	BigType_SmallTypesBean bigTypeDates = new BigType_SmallTypesBean(bitItem);
    	try {
        	IContractManager service = getService();
			//根据合同大类型得到合同小类型列表
			List smallTypes = service.getSmallTypeByBigType((String) bitItem.get("ID"));
			if(smallTypes.size()>0){
				SmallType_ContractsBean[] smallConts=new SmallType_ContractsBean[smallTypes.size()];
				for(int i=0; i<smallTypes.size(); i++){
					//得到小类型
					Map small = (Map)smallTypes.get(i);
					//新建一个小类型数据集
					SmallType_ContractsBean STCItem = new SmallType_ContractsBean(small);
					//得到当前小类型下的合同范本
					List contracts = service.getContractByType((String) small.get("ID"));
					if(contracts.size()>0){
						//设置合同范本小类型下的合同范本集
						STCItem.setContracts((Contract[]) contracts.toArray(new Contract[0]));
					}
					smallConts[i] = STCItem;
				}
				//将合同大类型数据集的合同小类型数据集
				bigTypeDates.setSmall_Contracts(smallConts);
			}
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return bigTypeDates;
    }


    private boolean addAttach(FileItem file, String contrID) throws Exception{
    	if("".equals(file.getName()) || "".equals(contrID)) return false;

    	// 单个附件大小
//		long t_oneattachsize = t_item.getSize();
		// 取得文件名和扩展名
		String fullName = file.getName();
		String fileName = fullName.substring(fullName.lastIndexOf("\\") + 1);
		//新建并设置附件对象的值
		ContractAttach contAttach = new ContractAttach();
		contAttach.setContr_id(contrID);
		contAttach.setName(fileName);
		contAttach.setFile(file.get());

		//调用模板层接口先上传附件;
		return getService().uploadAttach(contAttach);
    }

    /**
     *
     * 方法描述 组织合同类型(大类[map],小类[list])
     * @return 将大类型和小类型封装在一起的一个 Map
     */
    private Map buildType(){

    	HashMap typeMap = null;
		try {
	    	IContractManager service = getService();
	    	typeMap = new HashMap();
			//得到合同大类
			List bigList = service.getBigType();
			for(int i=0; i<bigList.size(); i++ ){
				Map bigType = (Map)bigList.get(i);
				//每一个合同大类 对应一组合同小类型 List ( List 内的元素还是Map Key("ID","NAME"))
				typeMap.put(bigType, service.getSmallTypeByBigType((String)bigType.get("ID")));
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return typeMap;
    }

	//得到服务
	private IContractManager getService() throws Exception{
		return (IContractManager) ServiceManager.getInstance().getService(IContractManager.class);
	}
}

⌨️ 快捷键说明

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