/** @param args */
  public static void main(String[] args) {
    Session session = HibernateUtility.getSession();
    Transaction tx = session.beginTransaction();

    EmployeePojo emp1 = new EmployeePojo();

    emp1.setName("Ramu");
    emp1.setSalary(1500);
    session.save(emp1);

    EmployeePojo emp2 = new EmployeePojo();

    emp2.setName("Rakesh");
    emp2.setSalary(2500);
    session.save(emp2);

    EmployeePojo emp3 = new EmployeePojo();

    emp3.setName("Ravi");
    emp3.setSalary(3500);
    session.save(emp3);

    tx.commit();
    session.close();
  }
  // public static void main(String[] args)
  public void create() {
    try {
      Session session = HibernateUtility.getSession();
      Context ctx = new InitialContext();
      UserTransaction tx = (UserTransaction) ctx.lookup("java:comp/UserTransaction");
      tx.begin();

      // Transaction tx=session.beginTransaction();
      EmployeePojo emp1 = new EmployeePojo();
      emp1.setEmpid(102);
      emp1.setName("shamu");
      emp1.setSalary(1500);
      session.save(emp1);

      EmployeePojo emp11 = new EmployeePojo();
      emp11.setEmpid(103);
      emp11.setName("nama");
      emp11.setSalary(2500);
      session.save(emp11);
      emp11.setSalary(6000);

      session.flush();
      tx.commit();
      // tx.commit();
      session.close();
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
 @RequestMapping("/addSaleRecord")
 @SignatureVerifyService
 @ResponseBody
 public JSONObject addSaleRecord(
     @RequestBody(required = false) String message,
     @RequestParam(value = "message", required = false) String messageGet) {
   JSONObject params = MessageParser.getParams(message, messageGet);
   JSONObject json = new JSONObject();
   try {
     String storeSid = params.containsKey("storeSid") ? params.getString("storeSid") : "1";
     String employeeSid =
         params.containsKey("employeeSid") ? params.getString("employeeSid") : "0";
     String promotionSid =
         params.containsKey("promotionSid") ? params.getString("promotionSid") : "0";
     double totalPrice = params.getDouble("totalPrice");
     double totalCost = params.getDouble("totalCost");
     double proportion = totalCost / totalPrice;
     String memberCardNo =
         params.containsKey("memberCardNo") ? params.getString("memberCardNo") : "";
     String costType = params.containsKey("costType") ? params.getString("costType") : "";
     if (!params.containsKey("goodsSns")) {
       json.put("success", false);
       json.put("errorCode", 403);
       json.put("message", "数据传输不完整,请检查后再试!");
       return json;
     }
     SaleRecordContentPojo content =
         new SaleRecordContentPojo(
             storeSid, employeeSid, memberCardNo, promotionSid, costType, totalPrice, totalCost);
     saleRecordContentService.addSaleRecordContent(content);
     String goodss = params.getString("goodsSns");
     String[] goodsSnArray = goodss.split("!#!");
     for (String goodsInfo : goodsSnArray) {
       try {
         String[] gs = goodsInfo.split("@");
         if (gs.length >= 2) {
           double goodsPrice = Double.valueOf(gs[0]);
           double goodsOriginalCost = goodsPrice * proportion;
           SaleRecordPojo saleRecord = new SaleRecordPojo();
           StorePojo store = new StorePojo();
           store.setSid(storeSid);
           saleRecord.setStore(store);
           EmployeePojo employee = new EmployeePojo();
           employee.setSid(employeeSid);
           saleRecord.setEmployee(employee);
           GoodsPojo goods = new GoodsPojo();
           goods.setSn(gs[1]);
           saleRecord.setGoods(goods);
           MemberPojo member = new MemberPojo();
           member.setCard_no(memberCardNo);
           saleRecord.setMember(member);
           saleRecord.setGoodsOriginalCost(goodsOriginalCost);
           saleRecord.setGoodsPrice(goodsPrice);
           PromotionPojo promotion = new PromotionPojo();
           promotion.setSid(promotionSid);
           saleRecord.setPromotion(promotion);
           SaleRecordDetailPojo detail =
               new SaleRecordDetailPojo(content.getSid(), gs[1], goodsOriginalCost, goodsPrice);
           saleRecordDetailService.addSaleRecordDetail(detail);
           saleService.addSaleRecord(saleRecord);
           goods = goodsService.getGoods(goods.getSn());
           inventoryService.reduceInventoryCount4Sale(storeSid, goods.getSid());
         }
       } catch (Exception e) {
         logger.error("存储错误", e);
       }
     }
     try {
       financeAccountService.updateFinanceAccount(costType, totalCost);
     } catch (Exception e) {
       logger.error("修改财务账户余额出错,修改账户类型{},添加金额{}", costType, totalCost, e);
     }
     try {
       if (memberCardNo != null && !memberCardNo.trim().isEmpty()) {
         memberService.addPointsForMember(memberCardNo, (int) totalCost);
       }
     } catch (Exception e) {
       logger.error("添加积分错误,会员卡号{},积分数{}", memberCardNo, (int) totalCost, e);
     }
   } catch (Exception e) {
     json.put("success", false);
     json.put("errorCode", 500);
     json.put("message", "服务器错误,请稍后再试!");
   }
   return json;
 }