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

📄 financialaccountaction.java

📁 EJB+Struts+Webservice实现的开放式基金管理系统
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
            }
        }
        return mapping.findForward(target);
    }

    /**
     *
     * @param mapping ActionMapping
     * @param form ActionForm
     * @param request HttpServletRequest
     * @param response HttpServletResponse
     * @return ActionForward
     */
    public ActionForward update(ActionMapping mapping,
                                ActionForm form,
                                HttpServletRequest request,
                                HttpServletResponse response) {
        String target = "success";
        String task = mapping.getParameter();
        DynaActionForm inputForm = null;
        FinancialAccountForm faForm = new FinancialAccountForm();
        String accountNo = "";
        Double amount = new Double(0);
        if (task.equals("updateStatus")) {
            faForm = (FinancialAccountForm) form;
            accountNo = (String) request.getParameter("accountNo");
        } else {
            inputForm = (DynaActionForm) form;
            accountNo = (String) inputForm.get("accountNo");
            amount = new Double(inputForm.get("amount").toString());
        }
        try {
            FinancialAccountDelegate faDelegate
                    = new FinancialAccountDelegate();
            FinancialAccountDto dto = null;
            try {
                dto = faDelegate.
                      financialAccountFindByPrimaryKey(new
                        Integer(accountNo));
            } catch (Exception e) {
                target = "failure";
                ActionErrors errors = new ActionErrors();
                errors.add("financialAccount.invalidaccount",
                           new
                           ActionError("financialAccount.invalidaccount"));
                saveErrors(request, errors);
                return mapping.findForward(target);

            }
            if (task.equals("addMoney")) {
                if (dto.getStatus().equalsIgnoreCase("冻结")) {
                    target = "failure";
                    ActionErrors errors = new ActionErrors();
                    errors.add("financialAccount.accountfrozen",
                               new
                               ActionError("financialAccount.accountfrozen"));
                    saveErrors(request, errors);
                    return mapping.findForward(target);

                }

                double finalAmount = dto.getFinancingAmount().doubleValue()
                                     + amount.doubleValue();
                dto.setFinancingAmount(new Double(finalAmount));
                faDelegate.updateFinancialAccount(dto);

                SalesDto sdto = (SalesDto) request.getSession().getAttribute(
                        "salesDto");
                log.info(dto.logData(
                "FINANCING ACCOUNT MONEY ADDED by sales having sales no="
                        + sdto.getSalesNo()));

            } else if (task.equals("takeMoney")) {
                String password = (String) inputForm.get("password");
                double amountToTakeOut = Double.parseDouble((String) inputForm.
                        get("amount"));
                if (!dto.getPassword().equals(password)) {
                    target = "failure";
                    ActionErrors errors = new ActionErrors();
                    errors.add("financialAccount.invalidpassword",
                               new
                               ActionError("financialAccount.invalidpassword"));
                    saveErrors(request, errors);
                    return mapping.findForward(target);
                } else if (dto.getStatus().equalsIgnoreCase("冻结")) {
                    target = "failure";
                    ActionErrors errors = new ActionErrors();
                    errors.add("financialAccount.accountfrozen",
                               new
                               ActionError("financialAccount.accountfrozen"));
                    saveErrors(request, errors);
                    return mapping.findForward(target);
                } else if (dto.getFinancingAmount().doubleValue()
                           <  amountToTakeOut) {
                    target = "failure";
                    ActionErrors errors = new ActionErrors();
                    errors.add("financialAccount.moreamountwithdrawn",
                               new
                               ActionError(
                                       "financialAccount.moreamountwithdrawn"));
                    saveErrors(request, errors);
                    return mapping.findForward(target);
                } else {
                    double finalAmount = dto.getFinancingAmount().doubleValue()
                                         - amount.doubleValue();
                    dto.setFinancingAmount(new Double(finalAmount));
                    faDelegate.updateFinancialAccount(dto);

                    SalesDto sdto = (SalesDto) request.getSession().
                                    getAttribute("salesDto");
                    log.info(dto.logData(
                  "FINANCING ACCOUNT MONEY TAKEN OUT by sales having sales no="
                  +  sdto.getSalesNo()));

                }
            } else if (task.equals("updateStatus")) {
                String currentStatus = request.getParameter("currentStatus");
                if (currentStatus.equalsIgnoreCase("正常")) {
                    dto.setStatus("冻结");
                } else {
                    dto.setStatus("正常");
                }
                faDelegate.updateFinancialAccount(dto);

                SalesDto sdto = (SalesDto) request.getSession().getAttribute(
                        "salesDto");
                log.info(dto.logData(
                "FINANCING ACCOUNT STATUS CHANGED by sales having sales no="
                        +  sdto.getSalesNo()));

            }
            //getting fresh dto to get the client no
            faForm.setFinancialAccountDto(dto);
            ClientDelegate cdel = new ClientDelegate();
            ClientDto cdto = cdel.clientFindByPrimaryKey(dto.getClientNo());
            faForm.setClientDto(cdto);
            faForm.setFinancialAccountDto(dto);
            request.setAttribute("financialAccountForm",
                                 faForm);
        } catch (Exception e) {
            target = "failure";
            ActionErrors errors = new ActionErrors();
            errors.add("financialAccount.invalid",
                       new ActionError("financialAccount.invalid"));
            saveErrors(request, errors);
            System.out.println("Error in updating client" + e);
        } finally {
            request.setAttribute("financialAccountForm ", faForm);
        }
        return mapping.findForward(target);
    }

    /**
     *
     * @param form DynaValidatorForm
     * @return FinancialAccountDto
     * @throws Exception e
     */
    private FinancialAccountDto getFinancialAccountDto(DynaValidatorForm form)
            throws Exception {

        Integer financialAccountNo = ((Integer) form.get("accountNo"));
        Integer clientNo = (Integer) form.get("clientNo");

        int intClientNo = clientNo.intValue();
        int intFinancialAccountNo = financialAccountNo.intValue();

        FinancialAccountDelegate fd = new FinancialAccountDelegate();
        if (intClientNo == 0 && intFinancialAccountNo != 0) {
            return fd.financialAccountFindByPrimaryKey(financialAccountNo);
        } else if (intClientNo != 0 && intFinancialAccountNo == 0) {
            return fd.financialAccountFindByClientNo(clientNo);
        } else if (intClientNo != 0 && intFinancialAccountNo != 0) {
            FinancialAccountDto financialAccountDto = fd.
                    financialAccountFindByClientNo(clientNo);
            if (financialAccountDto.getAccountNo().equals(financialAccountNo)) {
                return financialAccountDto;
            } else {
                throw new Exception("financialAccount Not Found");
            }
        } else {
            throw new Exception("financialAccount Not Found");
        }
    }

}

⌨️ 快捷键说明

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