Пример #1
0
 /** 保存添加和修改,对象的id不为空时,为修改,否则为添加 */
 @PageType(EnumPageType.JSONPAGE)
 @RequestMapping(value = "/save/json", method = RequestMethod.POST)
 @ResponseBody
 public DwzJson settlementSave(
     UserAgent userAgent,
     @RequestParam(required = false) String dwzId,
     @ModelAttribute("settlement") Settlement settlement,
     @RequestParam(required = false) String dwzId,
     ModelMap model) {
   DwzJson dwzJson;
   if (settlement == null) {
     dwzJson =
         new DwzJson(
             "300", this.messageSource.getMessage("operation.failed", null, this.getThisLocale()));
     return dwzJson;
   }
   if (settlement.getId() != null && settlement.getId() >= 0) {
     // 保存修改
     ServiceResult<Integer> result =
         settlementService.update(new ServiceRequest(settlement, userAgent));
     if (result.getErrorNO() != null) {
       dwzJson =
           new DwzJson(
               "300",
               this.messageSource.getMessage(
                   result.getErrorInfo(), result.getMsgArgs(), this.getThisLocale()));
     } else {
       dwzJson =
           new DwzJson(
               "200",
               this.messageSource.getMessage(
                   "operation.success", result.getMsgArgs(), this.getThisLocale()),
               StringUtils.isBlank(dwzId) ? "dwz_tab_settlement" : dwzId,
               "closeCurrent");
     }
   } else {
     // 保存新增
     ServiceResult<Settlement> result =
         settlementService.save(new ServiceRequest(settlement, userAgent));
     if (result.getErrorNO() != null) {
       dwzJson =
           new DwzJson(
               "300",
               this.messageSource.getMessage(
                   result.getErrorInfo(), result.getMsgArgs(), this.getThisLocale()));
     } else {
       dwzJson =
           new DwzJson(
               "200",
               this.messageSource.getMessage(
                   "operation.success", result.getMsgArgs(), this.getThisLocale()),
               StringUtils.isBlank(dwzId) ? "dwz_tab_settlement" : dwzId,
               "closeCurrent");
     }
   }
   return dwzJson;
 }
Пример #2
0
  /** 根据查询条件,批量删除 */
  @PageType(EnumPageType.JSONPAGE)
  @RequestMapping(value = "/delJson", method = RequestMethod.POST)
  public @ResponseBody DwzJson settlementDelBatch(
      @ModelAttribute("query") SettlementQuery query,
      @RequestParam(required = false) String dwzId,
      UserAgent userAgent,
      ModelMap model) {
    DwzJson dwzJson;
    // 将query.ids的条件合并到query.id_in中
    if (query != null && StringUtils.isNotBlank(query.getIds())) {
      List<Long> id_in = query.getIdsList();
      if (query.getId_in() == null) {
        query.setId_in(id_in);
      } else {
        query.getId_in().addAll(id_in);
      }
    }
    // 如果没有条件,就拒绝删除操作,以免所有数据被删掉.
    if (query == null || (query.getId_in() == null || query.getId_in().size() <= 0)) {
      dwzJson =
          new DwzJson(
              "300",
              this.getMessageSource()
                  .getMessage("delete.error.parameter.ids.null", null, this.getThisLocale()));
      return dwzJson;
    }

    ServiceResult<Integer> result = settlementService.remove(new ServiceRequest(query, userAgent));
    if (result.getErrorNO() != null) {
      dwzJson =
          new DwzJson(
              "300",
              this.messageSource.getMessage(
                  result.getErrorInfo(), result.getMsgArgs(), this.getThisLocale()));
    } else {
      if (result.getDataObj() > 0) {
        dwzJson =
            new DwzJson(
                "200",
                this.messageSource.getMessage(
                    "operation.success", result.getMsgArgs(), this.getThisLocale()),
                StringUtils.isBlank(dwzId) ? "dwz_tab_settlement" : dwzId);
      } else {
        dwzJson =
            new DwzJson(
                "300",
                this.getMessageSource()
                    .getMessage("delete.error", result.getMsgArgs(), this.getThisLocale()));
      }
    }

    return dwzJson;
  }
Пример #3
0
  /** 删除一个数据 */
  @PageType(EnumPageType.JSONPAGE)
  @RequestMapping(value = "/delJson/{id}")
  public @ResponseBody DwzJson settlementDel(
      @PathVariable("id") Long id,
      @RequestParam(required = false) String dwzId,
      UserAgent userAgent,
      ModelMap model) {
    DwzJson dwzJson;
    if (id == null || id < 0) {
      dwzJson =
          new DwzJson(
              "300",
              this.getMessageSource()
                  .getMessage("delete.error.parameter.ids.null", null, this.getThisLocale()));
      return dwzJson;
    }
    SettlementQuery query = new SettlementQuery();
    query.setId(id);
    ServiceResult<Integer> result = settlementService.remove(new ServiceRequest(query, userAgent));
    if (result.getErrorNO() != null) {
      dwzJson =
          new DwzJson(
              "300",
              this.messageSource.getMessage(
                  result.getErrorInfo(), result.getMsgArgs(), this.getThisLocale()));
    } else {
      if (result.getDataObj() > 0) {
        dwzJson =
            new DwzJson(
                "200",
                this.messageSource.getMessage(
                    "operation.success", result.getMsgArgs(), this.getThisLocale()),
                StringUtils.isBlank(dwzId) ? "dwz_tab_settlement" : dwzId);
      } else {
        dwzJson =
            new DwzJson(
                "300",
                this.getMessageSource()
                    .getMessage("delete.error", result.getMsgArgs(), this.getThisLocale()));
      }
    }

    return dwzJson;
  }