public String addComments() {
   this.book = services.getBook(isbn);
   String username =
       FacesContext.getCurrentInstance().getExternalContext().getUserPrincipal().getName();
   this.user = services.getUser(username);
   Comment com = new Comment();
   com.setComment(comments);
   com.setRating(score);
   com.setUsers(user);
   com.setBook(book);
   book.getComments().add(com);
   user.getComments().add(com);
   // services.addComments(com);
   services.updateUser(user);
   services.addBook(book);
   this.comments = "";
   // FacesContext.getCurrentInstance().getExternalContext().invalidateSession();
   return "index";
 }
Exemplo n.º 2
0
 /**
  * 接受翼支付传回数据
  *
  * @return
  * @throws Exception
  */
 public String bestPayNotify(Map<String, String[]> params) throws Exception {
   if (params != null) {
     Map<String, String> doParams = new HashMap<String, String>();
     for (Iterator<String> iter = params.keySet().iterator(); iter.hasNext(); ) {
       String name = (String) iter.next();
       String[] values = (String[]) params.get(name);
       String valueStr = "";
       for (int i = 0; i < values.length; i++) {
         valueStr = (i == values.length - 1) ? valueStr + values[i] : valueStr + values[i] + ",";
       }
       doParams.put(name, valueStr);
     }
     // 翼支付网关平台交易流水号
     String UPTRANSEQ = "";
     if (doParams.containsKey("UPTRANSEQ")) {
       UPTRANSEQ = doParams.get("UPTRANSEQ");
       Logger.debug("", "UPTRANSEQ:" + UPTRANSEQ);
     }
     String TRANDATE = "";
     if (doParams.containsKey("TRANDATE")) {
       // 翼支付返回日期
       TRANDATE = doParams.get("TRANDATE");
       Logger.debug("", "TRANDATE:" + TRANDATE);
     }
     String RETNCODE = "";
     if (doParams.containsKey("RETNCODE")) {
       // 翼支付返回状态码
       RETNCODE = doParams.get("RETNCODE");
       Logger.debug("", "RETNCODE:" + RETNCODE);
     }
     String RETNINFO = "";
     if (doParams.containsKey("RETNINFO")) {
       RETNINFO = doParams.get("RETNINFO");
       Logger.debug("", "RETNINFO:" + RETNINFO);
     }
     String ORDERREQTRANSEQ = "";
     if (doParams.containsKey("ORDERREQTRANSEQ")) {
       ORDERREQTRANSEQ = doParams.get("ORDERREQTRANSEQ");
       Logger.debug("", "ORDERREQTRANSEQ:" + ORDERREQTRANSEQ);
     }
     String ORDERSEQ = "";
     if (doParams.containsKey("ORDERSEQ")) {
       ORDERSEQ = doParams.get("ORDERSEQ");
       Logger.debug("", "ORDERSEQ:" + ORDERSEQ);
     }
     String ORDERAMOUNT = "";
     if (doParams.containsKey("ORDERAMOUNT")) {
       ORDERAMOUNT = doParams.get("ORDERAMOUNT");
       Logger.debug("", "ORDERAMOUNT:" + ORDERAMOUNT);
     }
     String SIGN = doParams.get("SIGN");
     if (doParams.get("ENCODETYPE").equals("1")) {
       String MAC =
           CryptTool.md5Digest(
               "UPTRANSEQ="
                   + UPTRANSEQ
                   + "&MERCHANTID="
                   + BestPayConfig.MERCHANTID
                   + "&ORDERSEQ="
                   + ORDERSEQ
                   + "&ORDERAMOUNT="
                   + ORDERAMOUNT
                   + "&RETNCODE="
                   + RETNCODE
                   + "&RETNINFO="
                   + RETNINFO
                   + "&TRANDATE="
                   + TRANDATE
                   + "&KEY="
                   + BestPayConfig.KEY);
       if (MAC.equals(SIGN)) {
         // 校验成功 更改订单的状态 变为已支付
         Orders order = ordersRepository.get(ORDERSEQ, ORDERREQTRANSEQ);
         if (order != null) {
           order.setStatus(1);
           order.setUptranseq(UPTRANSEQ);
           order.setTrandate(TRANDATE);
           order.setRetncode(RETNCODE);
           order.setRetninfo(RETNINFO);
           order.setSign(SIGN);
           order.setModifiedTime(new Timestamp(System.currentTimeMillis()));
           ordersRepository.save(order);
           // 支付成功 创建支付评论
           TaskSupport taskSupport = taskSupportRepository.findOne(order.getTaskSupportId());
           if (taskSupport != null) {
             Comment comment = new Comment();
             Task task = taskSupport.getTaskId();
             comment.setTaskId(task);
             User user = taskSupport.getUserId();
             comment.setUserId(user);
             comment.setContent(user.getNickName() + "支持了" + taskSupport.getSupportMoney() + "元。");
             comment.setType(CommentType.SUPPORT.ordinal());
             comment.setStatus(CommentStatusType.VALID.ordinal());
             comment.setCreatedTime(new Timestamp(System.currentTimeMillis()));
             commentRepository.save(comment);
           }
           return "UPTRANSEQ_" + UPTRANSEQ;
         }
       } else {
         Logger.error(LOG_TAG, "MAC:" + MAC + " 和SIGN:" + SIGN + "不匹配!!!");
       }
     }
   }
   return "";
 }