예제 #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);
    }
  }
예제 #2
0
  /**
   * ** 更新系统用户 信息,返回json给客户端
   *
   * @param _id
   * @param client
   * @param br
   * @param request
   * @return
   */
  @RequestMapping(value = "/{_id}/update", method = RequestMethod.POST)
  @ResponseBody
  public Object update(
      @PathVariable String _id,
      @Validated Client client,
      BindingResult br,
      HttpServletRequest request) {

    if (br.hasErrors()) {
      return ErrorHandler.getRequestResultFromBindingResult(br);
    }

    try {
      client.set_id(_id);
      DBObject updateResult = this.clientService.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);
    }
  }
예제 #3
0
  /**
   * ** 下载整表,单sheet文件
   *
   * @param model
   * @param request
   * @param response
   * @return
   */
  @RequestMapping(value = "/download_clients", method = RequestMethod.POST)
  public void single(
      Model model,
      HttpServletRequest request,
      HttpServletResponse response,
      String titles,
      String fields,
      String fileName) {

    logger.debug("下载单sheet文件");
    HttpServletRequestUtil.debugParams(request);

    try {
      // 获取类
      List list = this.clientService.downLoadAllClientByUserId(this.getUserId());

      String[] titleNames = Client.getTitlesForDownLoad();
      String[] fieldNames = Client.getFieldsForDownLoad();
      Map<String, Integer> fieldWidths = Client.getWidthsForDownLoad();
      String sheetName = "sheet0";

      WorkbookConfig wcg = new WorkbookConfig();
      wcg.setWorkbookName(fileName);
      wcg.addSheetName(sheetName);
      wcg.addSheetField(sheetName, fieldNames);
      wcg.addSheetTitle(sheetName, titleNames);
      wcg.addSheetWidth(sheetName, fieldWidths);

      HSSFWorkbook wb = ExportUtils.createSingSheetHSSFWorkbook(wcg, list);

      ExportUtils.setHeader(response, fileName);
      // 获取输出流,写入excel 并关闭
      ServletOutputStream out = response.getOutputStream();

      wb.write(out);
      out.flush();
      out.close();

    } catch (Exception e) {
      e.printStackTrace();
    }
  }
예제 #4
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);
    }
  }