Ejemplo n.º 1
0
  /**
   * ** 更新系统客户 信息,返回json给客户端
   *
   * @param _id
   * @param data
   * @param user_id
   * @param request
   * @param part_flg
   * @return
   */
  @RequestMapping(value = "/{_id}/update_part", method = RequestMethod.POST)
  @ResponseBody
  public Object update_part(
      @PathVariable String _id, Client client, HttpServletRequest request, String part_flg) {

    String user_id = client.getOwner_user_id();
    if (!this.isValidObjId(_id)) {
      return this.handleValidateFalse("非法的客户主键");
    }

    if (!this.isValidObjId(user_id)) {
      return this.handleValidateFalse("非法的用户");
    }

    if (!PartFlgEnum.isValidPartFlg(part_flg)) {
      return this.handleValidateFalse("非法的更新参数part_flg");
    }

    client.set_id_m(_id);

    String phone_info = request.getParameter("phone_info");
    String address_info = request.getParameter("address_info");
    String interesting_services = request.getParameter("interesting_service");

    List<Phone> phones =
        JsonUtil.getGson().fromJson(phone_info, new TypeToken<List<Phone>>() {}.getType());

    List<Address> addresses =
        JsonUtil.getGson().fromJson(address_info, new TypeToken<List<Address>>() {}.getType());

    List<String> interesting_service =
        JsonUtil.getGson()
            .fromJson(interesting_services, new TypeToken<List<String>>() {}.getType());

    client.setInteresting_service(interesting_service);
    client.setPhone_info(phones);
    client.setAddress_info(addresses);

    logger.debug("传入的用户对象\n{}", client);

    try {
      IModifyClientInfoService modifyClientService = getModifyService(part_flg);
      DBObject updateResult = modifyClientService.updatePart(null, client);

      logger.debug("更新后的结果[{}]", updateResult);

      RequestResult rr = new RequestResult();
      rr.setSuccess(true);
      rr.setMessage(_id);
      return rr;
    } catch (Exception e) {
      return this.handleException(e);
    }
  }
Ejemplo n.º 2
0
  /**
   * ** 添加
   *
   * @return
   */
  @RequestMapping(value = "/add", method = RequestMethod.POST)
  @ResponseBody
  public Object add(@Validated Client client, BindingResult br, HttpServletRequest request) {

    HttpServletRequestUtil.debugParams(request);

    String phone_info = request.getParameter("phone_info");
    String address_info = request.getParameter("address_info");
    String interesting_services = request.getParameter("interesting_service");

    List<Phone> phones =
        JsonUtil.getGson().fromJson(phone_info, new TypeToken<List<Phone>>() {}.getType());

    List<Address> addresses =
        JsonUtil.getGson().fromJson(address_info, new TypeToken<List<Address>>() {}.getType());

    List<String> interesting_service =
        JsonUtil.getGson()
            .fromJson(interesting_services, new TypeToken<List<String>>() {}.getType());

    client.setInteresting_service(interesting_service);
    client.setPhone_info(phones);
    client.setAddress_info(addresses);

    logger.debug("传入的用户对象\n{}", client);

    // String userId = this.getUserId();
    // if (StringUtil.isEmpty(userId)) {
    // return this.handleValidateFalse("所属用户id不能为空");
    // }
    //
    // client.setOwner_user_id(userId);

    if (br.hasErrors()) {
      return ErrorHandler.getRequestResultFromBindingResult(br);
    }
    try {
      // 1.校验是否已存在相同的类型码
      // boolean isExist = this.clientService
      // .isExistSameTypecode(client.getTypecode());
      // if (isExist) {
      // RequestResult rr = new RequestResult();
      // rr.setSuccess(false);
      // rr.setMessage("已经存在类型码【" + client.getTypecode().trim()
      // + "】的用户!");
      // return rr;
      // }

      // 2.新增
      client.setUseflg("1");
      String _id = this.clientService.add(client);

      RequestResult rr = new RequestResult();
      rr.setSuccess(true);
      rr.setMessage(_id);

      return rr;
    } catch (Exception e) {
      return this.handleException(e);
    }
  }