/** 添加 */
  public void onAdd() {
    try {
      // biRedPointsShowAdd.setGoodsId(gmGoodsInfo.getGoodsId());
      if (preSubmitCheck(biRedPointsShowAdd).equals(false)) {
        return;
      }

      biRedPointsShowAdd.setGoodsId(gmGoodsInfoShowAdd.getGoodsId());
      biRedPointsShowAdd.setCrtDate(ToolUtil.getStrLastUpdDate()); // 创建日期YYYY-MM-DD
      biRedPointsShowAdd.setCrtTime(ToolUtil.getStrLastUpdTime()); // 创建时间HH:mm:ss
      biRedPointsShowAdd.setCrtOperId(operManager.getOperInfo().getOperId()); // 创建者ID
      biRedPointsShowAdd.setOrigin(EnuOrigin.ORIGIN_0.getCode()); // 数据来源:0_系统录入;1_系统外导入

      impBpPointsDtl(biRedPointsShowAdd, null, "add"); // 导入BpPointsDtl表
      updBpCusts(biRedPointsShowAdd.getCustNo()); // 更新BpCusts表的累计减少积分数、累计积分数
      impGmGoodsDtl(biRedPointsShowAdd, "add"); // 导入GmGoodsDtl表
      updateGmGoodsInfoStorQty(
          biRedPointsShowAdd.getGoodsId(), biRedPointsShowAdd.getGoodsQty()); // 更新GmGoodsInfo表在库数量
      MessageUtil.addInfo("添加成功!");
      gmGoodsInfoShowAdd = new GmGoodsInfo();
      biRedPointsShowAdd = new BpRedPointsShow();
      onQryForAdd();
    } catch (Exception e) {
      logger.error("添加失败!", e);
      MessageUtil.addError("添加失败!" + e.getMessage());
    }
  }
 @PostConstruct
 public void init() {
   try {
     Map<String, String> params =
         FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap();
     String action = params.get("action");
     if (action != null) {
       if ("imp".equals(action)) {
         impDate = ToolUtil.getStrLastUpdDate();
         biRedPointsShowQry = new BpRedPointsShow();
       } else if ("qry".equals(action)) {
         txndate = ToolUtil.getStrLastUpdDate();
         biRedPointsShowQry = new BpRedPointsShow();
       } else if ("add".equals(action)) {
         gmGoodsService.init();
         // gmGoodsSelItmList=bpRedPointsService.getGmGoodsInfoSelItmList();
         gmGoodsInfoList = gmGoodsService.getGmGoodsInfoList();
         // gmGoodsInfo=new GmGoodsInfo();
         biRedPointsShowAdd = new BpRedPointsShow();
         onQryForAdd();
       }
     }
   } catch (Exception e) {
     logger.error("初始化失败!", e);
   }
 }
  /**
   * 导入BpPointsDtl表
   *
   * @param bpRedPointsShowPara
   * @param otherTxnsn
   */
  private void impBpPointsDtl(BpRedPointsShow bpRedPointsShowPara, Long otherTxnsn, String action) {
    try {
      BpPointsDtl bpPointsDtlTmp = new BpPointsDtl();
      bpPointsDtlTmp.setTxndate(bpRedPointsShowPara.getTxndate()); // 数据日期
      bpPointsDtlTmp.setCustNo(bpRedPointsShowPara.getCustNo()); // 客户号
      bpPointsDtlTmp.setPointsType(EnuPointsType.POINTS_TYPE_50.getCode()); // 积分类型
      bpPointsDtlTmp.setPoints(
          ToolUtil.getNegativeBigDecimal(bpRedPointsShowPara.getPoints())); // 积分
      bpPointsDtlTmp.setCrtDate(ToolUtil.getStrLastUpdDate()); // 创建日期YYYY-MM-DD
      bpPointsDtlTmp.setCrtTime(ToolUtil.getStrLastUpdTime()); // 创建时间HH:mm:ss
      bpPointsDtlTmp.setCrtOperId(operManager.getOperInfo().getOperId()); // 创建者ID
      if ("imp".equals(action)) { // 导入
        bpPointsDtlTmp.setOrigin(EnuOrigin.ORIGIN_1.getCode()); // 数据来源:0_系统录入;1_系统外导入
        bpPointsDtlTmp.setOtherTxnsn(otherTxnsn); // 外部系统流水号
      } else { // 添加
        bpPointsDtlTmp.setOrigin(EnuOrigin.ORIGIN_0.getCode()); // 数据来源:0_系统录入;1_系统外导入
      }

      Long strSeqNo = (platformService.obtainSeqNo("POINTS_DTL_SEQNO"));
      bpPointsDtlTmp.setTxnsn(strSeqNo); // 交易流水号
      String strBillNoTmp = ToolUtil.getStrToday() + "02" + strSeqNo;
      bpPointsDtlTmp.setBillNo(strBillNoTmp);
      // 回带订单号
      bpRedPointsShowPara.setBillNo(strBillNoTmp);
      bpPointsDtlService.insertSelective(bpPointsDtlTmp);
    } catch (Exception e) {
      logger.error("BpPointsDtl导入失败!", e);
    }
  }
  private Boolean preSubmitCheck(BpRedPointsShow bpRedPointsShowPara) {
    if (ToolUtil.getStrIgnoreNull(gmGoodsInfoShowAdd.getGoodsId()).length() == 0) {
      MessageUtil.addError("物品号不能为空,请输入物品号!");
      return false;
    }

    List<BpCusts> gmBpCustsTmp = bpCustsService.getBpCustListByID(bpRedPointsShowPara.getCustNo());
    if (gmBpCustsTmp == null || gmBpCustsTmp.size() <= 0) {
      MessageUtil.addError("该客户(" + bpRedPointsShowPara.getCustNo() + ")不存在,请确认您输入的客户号!");
      return false;
    }
    List<GmGoodsInfo> gmGoodsInfoListTmp =
        gmGoodsInfoService.getGmGoodsInfoListByID(gmGoodsInfoShowAdd.getGoodsId());
    if (gmGoodsInfoListTmp == null || gmGoodsInfoListTmp.size() <= 0) {
      MessageUtil.addError("该物品(" + gmGoodsInfoShowAdd.getGoodsId() + ")不存在,请确认您输入的物品号!");
      return false;
    }
    BigDecimal bdCumuPoints = ToolUtil.getBdIgnoreNull(gmBpCustsTmp.get(0).getCumuPoints());
    if (bdCumuPoints.compareTo(ToolUtil.getBdIgnoreNull(bpRedPointsShowPara.getPoints())) < 0) {
      MessageUtil.addError("该客户剩余积分(" + bdCumuPoints + ")不足本次捐赠,请确认您本次捐赠操作是否正确?");
      return false;
    }
    Long storQty = ToolUtil.getLongIgnoreNull(gmGoodsInfoListTmp.get(0).getStorQty());
    if (storQty < bpRedPointsShowPara.getGoodsQty()) {
      MessageUtil.addError("该物品库存量(" + storQty + ")不足本次捐赠,请确认您本次捐赠操作是否正确?");
      return false;
    }
    return true;
  }
  /** 导入 */
  public void onImp() {
    try {
      if (file == null) {
        MessageUtil.addError("请选择要导入的.txt文件!");
        return;
      }

      if (!file.getFileName().endsWith(".txt")) {
        MessageUtil.addError("文件格式错误,请选择.txt文件!");
        return;
      }

      String line; // 每行数据
      String[] colData; // 每列数据
      int impCnt = 0; // 导入笔数
      int result = 0; // 执行插入数据的结果
      int lines = 0; // 总笔数
      BpRedPointsShow bpRedPointsShow;
      BufferedReader br = new BufferedReader(new InputStreamReader(file.getInputstream(), "GBK"));
      try {
        while ((line = br.readLine()) != null) {
          lines++;
          colData = line.split("\\|");
          bpRedPointsShow = new BpRedPointsShow();
          bpRedPointsShow.setTxndate(colData[0]); // 数据日期
          bpRedPointsShow.setCustNo(colData[1]); // 客户代码
          bpRedPointsShow.setPoints(new BigDecimal(colData[2])); // 减少积分
          bpRedPointsShow.setGoodsId(colData[3]); // 兑换礼品ID
          bpRedPointsShow.setCrtDate(ToolUtil.getStrLastUpdDate()); // 创建日期YYYY-MM-DD
          bpRedPointsShow.setCrtTime(ToolUtil.getStrLastUpdTime()); // 创建时间HH:mm:ss
          bpRedPointsShow.setCrtOperId(operManager.getOperInfo().getOperId()); // 创建者ID
          bpRedPointsShow.setOrigin(EnuOrigin.ORIGIN_1.getCode()); // 数据来源:0_系统录入;1_系统外导入
          /* result = biRedPointsService.insertSelective(bpRedPointsShow);
          if (result > 0) {
              impCnt++;
          } else {
              continue;
          }*/

          impBpPointsDtl(bpRedPointsShow, Long.valueOf(colData[4]), "imp"); // 导入BpPointsDtl表
          updBpCusts(); // 更新BpCusts表的累计减少积分数、累计积分数
          impGmGoodsDtl(bpRedPointsShow, "imp"); // 导入GmGoodsDtl表
          updateGmGoodsInfoStorQty(bpRedPointsShow.getGoodsId()); // 更新GmGoodsInfo表在库数量
        }
      } finally {
        br.close();
      }

      if (impCnt > 0) {
        MessageUtil.addInfo("导入成功!总共" + lines + " 笔,导入" + impCnt + "笔。");
        onQryImp(false);
      }
    } catch (Exception e) {
      logger.error("导入失败!", e);
      MessageUtil.addError("导入失败!" + e.getMessage());
    }
  }
Пример #6
0
  /** 导入 */
  public void onImp(File file) throws Exception {
    logger.info("----------BiCardsTask导入开始" + ToolUtil.getStrLastUpdDatetime() + "----------");
    BufferedReader br = new BufferedReader(new FileReader(file));
    Map<String, Integer> result = biCardsService.imp(br, operId);
    int lines = result.get("lines"); // 总笔数
    int impCnt = result.get("impCnt"); // 导入笔数
    int existsCnt = result.get("existsCnt"); // 重复笔数

    if (existsCnt > 0) {
      logger.info("总共" + lines + " 笔,导入" + impCnt + "笔,重复" + existsCnt + "笔。");
    }

    if (impCnt > 0) {
      if (existsCnt == 0) {
        logger.info("导入成功!总共" + lines + " 笔,导入" + impCnt + "笔。");
      }
    }
    logger.info("----------BiCardsTask导入结束" + ToolUtil.getStrLastUpdDatetime() + "----------");
  }
Пример #7
0
  public void runTask() throws JobExecutionException {
    boolean isExists = false;
    try {
      String improot = PropertyManager.getProperty("improot");
      String impbk = PropertyManager.getProperty("impbk");

      // 遍历导入文件夹
      File directory = new File(improot);
      if (directory != null && directory.exists()) {
        File[] list = directory.listFiles();
        if (list != null) {
          for (File f : list) {
            // xfkmx+yyyyMMdd.txt文件存在的处理
            if (!f.isDirectory() && f.getName().startsWith("xfkmx")) {
              isExists = true;
              onImp(f); // 导入BiCards表
              Path path = Paths.get(impbk, ToolUtil.getStrLastUpdDate());
              File file = path.toFile();
              if (!file.exists()) { // 如果本地文件夹不存在则创建
                file.mkdirs();
              }
              Path source = Paths.get(f + "");
              Path target = Paths.get(impbk, ToolUtil.getStrLastUpdDate(), f.getName());
              Files.move(source, target, StandardCopyOption.REPLACE_EXISTING); // 移动文件到备份目录
              break;
            }
          }
        }
      }
    } catch (Exception e) {
      logger.error("BiCardsTask自动导入失败。", e);
      throw new JobExecutionException("BiCardsTask自动导入失败。" + e == null ? "" : e.getMessage(), e);
    }

    // 导入文件不存在的处理
    if (!isExists) {
      logger.error("BiCardsTask自动导入失败,导入文件不存在。");
      throw new JobExecutionException("BiCardsTask自动导入失败,导入文件不存在。");
    }
  }
  /**
   * 导入GmGoodsDtl表
   *
   * @param bpRedPointsShowPara
   * @param action
   */
  private void impGmGoodsDtl(BpRedPointsShow bpRedPointsShowPara, String action) {
    try {
      GmGoodsDtl gmGoodsDtlTmp = new GmGoodsDtl();
      gmGoodsDtlTmp.setTxndate(bpRedPointsShowPara.getTxndate()); // 发生日期:入库/出库日期YYYY-MM-DD
      gmGoodsDtlTmp.setGoodsId(bpRedPointsShowPara.getGoodsId()); // 物品ID
      gmGoodsDtlTmp.setInOutType(EnuInOutType.IN_OUT_TYPE_1.getCode()); // 出入库标志:0_入库;1_出库
      gmGoodsDtlTmp.setQty(-(bpRedPointsShowPara.getGoodsQty())); // 数量:入库为正,出库为负
      gmGoodsDtlTmp.setCrtDate(ToolUtil.getStrLastUpdDate()); // 创建日期YYYY-MM-DD
      gmGoodsDtlTmp.setCrtTime(ToolUtil.getStrLastUpdTime()); // 创建时间HH:mm:ss
      gmGoodsDtlTmp.setCrtOperId(operManager.getOperInfo().getOperId()); // 创建者ID
      gmGoodsDtlTmp.setRecVer(0L); // 记录版本号:初始记录,版本号为0
      if ("imp".equals(action)) { // 导入
        gmGoodsDtlTmp.setOrigin(EnuOrigin.ORIGIN_1.getCode()); // 数据来源:0_系统录入;1_系统外导入
      } else { // 添加
        gmGoodsDtlTmp.setOrigin(EnuOrigin.ORIGIN_0.getCode()); // 数据来源:0_系统录入;1_系统外导入
      }

      gmGoodsDtlTmp.setTxnsn(platformService.obtainSeqNo("POINTS_DTL_SEQNO")); // 交易流水号
      gmGoodsDtlTmp.setBillNo(bpRedPointsShowPara.getBillNo());
      bpPointsDtlService.insertSelective(gmGoodsDtlTmp);
    } catch (Exception e) {
      logger.error("GmGoodsDtl导入失败!", e);
    }
  }
 private void onQryForAdd() {
   BpRedPointsShow bpRedPointsShowTmp = new BpRedPointsShow();
   bpRedPointsShowTmp.setCrtDate(ToolUtil.getStrLastUpdDate());
   bpRedPointsShowTmp.setOrigin(EnuOrigin.ORIGIN_0.getCode());
   bpRedPointsShowList = bpPointsDtlService.selectForAddByModelShow(bpRedPointsShowTmp);
 }