コード例 #1
0
  /**
   * 更新客户资料信息
   *
   * @param request
   * @param response
   * @return
   * @throws Exception
   */
  public ModelAndView updateClient(HttpServletRequest request, HttpServletResponse response)
      throws Exception {
    System.out.println("更新客户资料");
    // 获取表单数据
    String clientId = request.getParameter("id");
    String name = request.getParameter("name");
    String sex = request.getParameter("sex");
    sex = "1".equals(sex) ? "女" : "男";
    String post = request.getParameter("post");
    String brithday = request.getParameter("brithday");
    String tel = request.getParameter("tel");
    String address = request.getParameter("address");

    Client client = clientAdminService.findClientById(Integer.parseInt(clientId));
    System.out.println("client : " + client);
    Map<String, Object> errors = new HashMap<String, Object>();
    Map<String, Object> models = new HashMap<String, Object>();
    // 修改资料
    try {
      // 校验表单数据
      if (isEmptyParam(name)) {
        System.out.println("请输入姓名??");
        errors.put("name", "请输入姓名");
      }
      if (errors.size() > 0) {
        models.put("client", client);
        models.put("errors", errors);
        return new ModelAndView(getClientInfoUpdateView(), models);
      }
      client.setName(name);
      client.setSex(sex);
      client.setPost(post);
      SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
      Date bdDate = brithday == null || brithday.trim().isEmpty() ? null : sdf.parse(brithday);
      client.setBrithday(bdDate);
      client.setTel(tel);
      client.setAddress(address);
      clientAdminService.updateInfo(client);
      models.put("message", "修改成功");
    } catch (Exception e) {
      errors.put("message", "修改失败");
      e.printStackTrace();
    }
    models.put("errors", errors);
    models.put("client", client);
    System.out.println(models.size() + "," + models);
    return new ModelAndView(getClientInfoUpdateView(), models);
  }
コード例 #2
0
  /**
   * 添加客户资料
   *
   * @param request
   * @param response
   * @return
   * @throws Exception
   */
  public ModelAndView addClient(HttpServletRequest request, HttpServletResponse response)
      throws Exception {
    System.out.println("添加客户资料");
    // 获取表单数据
    String name = request.getParameter("name");
    String sex = request.getParameter("sex");
    sex = isEmptyParam(sex) || "0".equals(sex) ? "男" : "女";
    String certificateType = request.getParameter("certificateType");
    String certificateNum = request.getParameter("certificateNum");
    String post = request.getParameter("post");
    String brithday = request.getParameter("brithday");
    String tel = request.getParameter("tel");
    String address = request.getParameter("address");
    String[] bankAccounts = request.getParameterValues("bankAccounts");

    Map<String, Object> errors = new HashMap<String, Object>();
    // 校验表单数据
    if (isEmptyParam(name)) {
      System.out.println("addClient请输入姓名");
      errors.put("name", "请输入姓名");
    }
    if (isEmptyParam(certificateType)) {
      errors.put("certificateType", "请选择证件类型");
    }
    if (isEmptyParam(certificateNum)) {
      errors.put("certificateNum", "请输入证件号码");
    }
    if (bankAccounts == null || bankAccounts.length < 1) {
      errors.put("bankAccounts", "请输入银行账号");
    }

    if (errors.size() > 0) {
      return new ModelAndView(getAddClientFormView(), "errors", errors);
    }
    // 开户
    try {
      Client client = new Client();
      client.setName(name);
      client.setSex(sex);
      client.setCertificateType(certificateType);
      client.setCertificateNum(certificateNum);
      client.setPost(post);
      SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
      Date bdDate = brithday == null || brithday.trim().isEmpty() ? null : sdf.parse(brithday);
      client.setBrithday(bdDate);
      client.setTel(tel);
      client.setAddress(address);
      client.setState(Client.OPEN); // 开户状态
      client.setOpenDate(new Date()); // 开户日期
      // 银行卡号
      for (String bankAccount : bankAccounts) {
        BankAccount account = new BankAccount(client, bankAccount);
        client.getBankAccounts().add(account);
      }
      System.out.println(client.getBankAccounts().size());
      clientAdminService.openingAccount(client);
      return new ModelAndView(getAddClientFormView(), "message", "添加成功");
    } catch (Exception e) {
      errors.put("message", "添加失败");
      return new ModelAndView(getAddClientFormView(), "errors", errors);
    }
  }