@SuppressWarnings("unchecked")
 @RequestMapping(value = "/saveOrder")
 public @ResponseBody ResponseVO saveOrder(
     String data, RedirectAttributes redirectAttributes, ModelMap model) {
   ResponseVO ovo = new ResponseVO();
   HttpSession session = getSession();
   String errorMsg = "";
   Row staff = (Row) session.getAttribute("staff");
   if (staff == null) {
     ovo = new ResponseVO(-1, "请重新登录");
     return ovo;
   }
   if (StringUtils.isEmptyOrNull(data)) {
     ovo = new ResponseVO(-1, "请求参数为空");
     return ovo;
   }
   String array[] = data.split(";");
   boolean isValid = true;
   DataSet batchDs = new DataSet();
   for (int i = 0; i < array.length; i++) {
     String itemArray[] = array[i].split(",");
     String code = itemArray[0];
     String num = itemArray[1];
     // 检查code 是否存在 num 是否足够
     Row row = userCouponService.findNotUsedByPayCode(code);
     if (row == null) {
       errorMsg += "消费验证码[" + code + "]不存在;";
       isValid = false;
       break;
     }
     String coupon_num = row.getString("num", "");
     int icoupon_num = Integer.parseInt(coupon_num);
     int inum = Integer.parseInt(num);
     int minus = icoupon_num - inum;
     if (minus < 0) {
       errorMsg += "消费验证码[" + code + "]的库存不足,实际有[" + icoupon_num + "],消费数量是[" + inum + "]张;";
       isValid = false;
       break;
     }
     Row temp = new Row();
     temp.put("code", code);
     temp.put("num", num);
     batchDs.add(temp);
   }
   if (!isValid) {
     ovo = new ResponseVO(-1, "请求参数错误:" + errorMsg);
     return ovo;
   }
   String sql = "";
   for (int i = 0; i < batchDs.size(); i++) {
     Row row = (Row) batchDs.get(i);
     String code = row.getString("code");
     String num = row.getString("num");
     sql = "update cxhl_user_coupon set num=num-" + num + " where pay_code='" + code + "' ";
     userCouponService.update(sql);
   }
   sql = "update cxhl_user_coupon set state=2 where num=0";
   userCouponService.update(sql);
   ovo = new ResponseVO(0, "支付成功");
   return ovo;
 }
Exemple #2
0
  @SuppressWarnings("unchecked")
  public DataSet getDeptPostionStaffTree() throws JException, SQLException {
    DataSet tempDs = new DataSet();
    DataSet treeDataSet = new DataSet();
    String sql = "select bureau_no, bureau_name from sm_bureau";

    tempDs = queryDataSet(sql);
    Row localRow2;
    for (int i = 0; i < tempDs.size(); i++) {
      Row tempRow = (Row) tempDs.get(i);
      localRow2 = new Row();
      localRow2.put("ID", "B" + tempRow.getString("bureau_no"));
      localRow2.put("NAME", tempRow.getString("bureau_name"));
      localRow2.put("UP_ID", "-1");
      localRow2.put("TYPE", "0");
      treeDataSet.add(localRow2);
    }

    //		 sql= "select posi_no, posi_name, site_no from sm_position where state=1";
    sql = "select posi_no, posi_name, site_no from sm_position ";
    tempDs = queryDataSet(sql);
    for (int i = 0; i < tempDs.size(); i++) {
      Row tempRow = (Row) tempDs.get(i);
      localRow2 = new Row();
      localRow2.put("ID", "P" + tempRow.getString("posi_no"));
      localRow2.put("NAME", tempRow.getString("posi_name"));
      localRow2.put("UP_ID", tempRow.getString("site_no"));
      localRow2.put("TYPE", "1");
      treeDataSet.add(localRow2);
    }

    sql = "select site_no, site_name, bureau_no from sm_site where up_site_no is null ";
    tempDs = queryDataSet(sql);
    for (int i = 0; i < tempDs.size(); i++) {
      Row tempRow = (Row) tempDs.get(i);
      localRow2 = new Row();
      localRow2.put("ID", tempRow.getString("site_no"));
      localRow2.put("NAME", tempRow.getString("site_name"));
      localRow2.put("UP_ID", "B" + tempRow.getString("bureau_no"));
      localRow2.put("TYPE", "0");
      treeDataSet.add(localRow2);
    }

    sql = "select site_no, site_name, up_site_no from sm_site where up_site_no is not null ";
    tempDs = queryDataSet(sql);
    for (int i = 0; i < tempDs.size(); i++) {
      Row tempRow = (Row) tempDs.get(i);
      localRow2 = new Row();
      localRow2.put("ID", tempRow.getString("site_no"));
      localRow2.put("NAME", tempRow.getString("site_name"));
      localRow2.put("UP_ID", tempRow.getString("up_site_no"));
      localRow2.put("TYPE", "0");
      treeDataSet.add(localRow2);
    }

    //   sql = "select a.real_name, a.staff_no,b.posi_no,a.site_no from sm_staff a left join
    // sm_staff_position b on a.staff_no=b.staff_no where a.state=1";
    sql =
        "select a.real_name, a.staff_no,b.posi_no,a.site_no from sm_staff a left join sm_staff_position b on a.staff_no=b.staff_no ";
    tempDs = queryDataSet(sql);
    for (int i = 0; i < tempDs.size(); i++) {
      Row tempRow = (Row) tempDs.get(i);
      localRow2 = new Row();
      localRow2.put("ID", "S" + tempRow.getString("staff_no"));
      localRow2.put("NAME", tempRow.getString("real_name"));
      if ((tempRow.getString("posi_no", null) == null)
          || (tempRow.getString("posi_no").trim().length() == 0))
        localRow2.put("UP_ID", tempRow.getString("site_no"));
      else {
        localRow2.put("UP_ID", "P" + tempRow.getString("posi_no"));
      }
      localRow2.put("TYPE", "4");
      treeDataSet.add(localRow2);
    }
    return treeDataSet;
  }