예제 #1
0
  @Override
  public String execute(String data) {
    String json = "";
    String txCode = "";
    String status = "";
    SystemRequestVo req = null;
    SystemResponseVo resp = new SystemResponseVo();
    Gson gson = new Gson();
    // logger.debug("execute entry +++++++++++++++++++++");

    try {
      json = data;
      // logger.debug("json:" + json);

      // JSON轉換成物件
      if (!StringTK.isEmpty(json)) {
        req = (SystemRequestVo) gson.fromJson(json, SystemRequestVo.class);
      }

      // 取得交易代碼
      RequestTranslet reqTranslet = getRequestTranslet();

      // 取得交易代碼
      txCode = reqTranslet.getTxcode();
      SystemTranslet sys = new SystemTranslet(this);

      if (StringTK.equals(txCode, ApplicationConstant.TX_CODE_SYSTEM_SYNC)) {
        resp = sys.sync(req);
      } else {
        throw new Exception("交易代碼錯誤");
      }

      setToken(reqTranslet.getToken());

    } catch (Exception e) {
      logger.error("Error:" + e);
      status = e.getMessage();
      if (NullTK.isNull(resp)) {
        resp = new SystemResponseVo();
      }
      resp.setStatus(status);
    } finally {

    }

    // 轉換回傳物件為json
    json = gson.toJson(resp);
    // logger.debug("json:\n" + json);

    return json;
  }
예제 #2
0
  /**
   * 資料庫管理員初始化
   *
   * @throws Exception
   */
  public static synchronized void init() throws Exception {
    // logger.debug("DBManager: MyBatis init() entry");

    try {
      if (init) return;
      StringBuilder sb = new StringBuilder();
      String config = "";
      try {
        String webapp = ApplicationContext.getWebAppName();
        sb.append("\ngetWebAppName: " + webapp);

        config = ApplicationContext.getMyBatisConfig();

        if (StringTK.isEmpty(config)) {
          config = resource;
        }

        sb.append("\nMyBatis Config Path: " + config);
        if (StringTK.isEmpty(config)) {
          config = resource;
        }
        Reader reader = Resources.getResourceAsReader(config);
        sqlSessionFactory = new SqlSessionFactoryBuilder().build(reader);

        Environment evnir = sqlSessionFactory.getConfiguration().getEnvironment();
        sb.append("\nApplied Environment: " + evnir.getId());
        setEnvironment(evnir.getId());
        init = true;
      } catch (Exception e) {
        e.printStackTrace();
        logger.error(e.getMessage());
        throw e;
      } finally {

      }

      logger.debug(sb.toString() + "\nDBManager: Database MyBatis initail successful.");

    } catch (Exception e) {
      logger.error("DBManager: init() fail");
      logger.debug(e.getMessage());
      throw e;
    } finally {

    }
    // logger.debug("DBManager: init() exit");
  }
  /**
   * 插入新的傭金資料
   *
   * @param ProjectCommissionRequestVo vo
   * @return ProjectCommissionResponseVo
   * @throws Exception
   */
  public ProjectCommissionResponseVo newCommission(ProjectCommissionRequestVo vo) {

    ProjectCommissionResponseVo resp = new ProjectCommissionResponseVo();
    long newId = 0;
    String txStatus = "";
    boolean chk = false;
    String newPro = "";
    try {
      // logger.debug("newProjectCommission entry=======================");
      // logger.debug("ProjectCommissionRequestVo vo:" + vo);

      CommissionVo rvo = new CommissionVo();
      CommissionDao dao = new CommissionDao();

      rvo.setCost(vo.getCost());
      rvo.setProjectprice(vo.getProjectprice());
      rvo.setVoice_reward(vo.getVoice_reward());
      rvo.setVoice_data_reward(vo.getData_reward());
      rvo.setData_reward(vo.getData_reward());
      rvo.setBonus(vo.getBonus());
      rvo.setCost_gap(vo.getCost_gap());
      rvo.setRatesid(vo.getRatesid());

      newPro = StringTK.cleanInvalidString(Strings.nullToEmpty(vo.getPrmotion_code()));
      rvo.setPrmotion_code(newPro);

      // 插入新的傭金資料
      chk = dao.insert(rvo);

      if (!chk) {
        throw new Exception("EC001:新增專案主檔失敗");
      }

      newId = rvo.getId();
      View_project_commissionVo f = dao.viewFindByCommissionId(newId);

      List<View_project_commissionVo> list = new ArrayList<View_project_commissionVo>();
      list.add(f);
      resp.setTxCode(vo.getTxCode());
      resp.setData(list);
      resp.setTxStatus(ApplicationConstant.TX_SUCCESS); // 設定交易成功狀態		

    } catch (Exception e) {
      txStatus = e.getMessage();
      logger.error(e.getMessage());
      resp.setTxStatus(txStatus);
    } finally {
      try {
        String ac = getResource().getRequestTranslet().getAccount();
        long aUid = UsersTK.getIdFromAccount(ac);
        LogTK.info(aUid, LogTK.CATEGORY_PROJECT, "新增傭金資料:" + newId + "/" + resp.getTxStatus());
      } catch (Exception e) {

      }
    }

    return resp;
  }
예제 #4
0
 /**
  * 電信資費類型[NP]ID值 抓取系統設定 RATETAGS_FEE_DATA_ROOT_ID 的值
  *
  * @return long
  */
 private static synchronized long getNPID() {
   long id = 0;
   try {
     String value = SysconfigTK.find(ApplicationConstant.RATETAGS_TELERATES_NP_ROOT_ID);
     if (!StringTK.isEmpty(value)) {
       id = Long.parseLong(value);
     }
   } catch (Exception e) {
     logger.error(e);
   }
   return id;
 }
예제 #5
0
  public Project_aggregateVo find(String uuid) throws Exception {
    Project_aggregateVo akey = null;
    try {
      for (Project_aggregateVo v : _table) {
        if (StringTK.equals(uuid, v.getRuuid())) {
          akey = v;
          break;
        }
      }
    } catch (Exception e) {
      logger.error(e);
      throw e;
    }

    return akey;
  }
예제 #6
0
 /**
  * 清除\t\n與前後空白字元
  *
  * @param str
  * @return
  */
 public static String filterString(String str) {
   return StringTK.cleanInvalidString(Strings.nullToEmpty(str));
 }
  @Override
  public String execute(String data) {
    String json = "";
    String txCode = "";
    String status = "";
    UserRoleDataRequestVo req = null;
    UserRoleDataResponseVo resp = new UserRoleDataResponseVo();
    Gson gson = new Gson();

    try {
      json = data;
      logger.debug("json:" + json);

      if (StringTK.isEmpty(json)) {
        throw new Exception("ES002:訊息內容異常");
      }

      // JSON轉換成物件
      if (!StringTK.isEmpty(json)) {
        req = (UserRoleDataRequestVo) gson.fromJson(json, UserRoleDataRequestVo.class);
      }

      // 取得交易代碼
      txCode = req.getTxCode();
      UserRoleDataTranslet translet = null;

      logger.debug("getTxCode:" + req.getTxCode());
      logger.debug("getCid:" + req.getCid());

      switch (txCode) {
        case ApplicationConstant.TX_CODE_DATA_USERROLE_LIST:
          // checkSession();
          translet = new UserRoleDataTranslet(this);
          resp = translet.list(req);
          break;
        case ApplicationConstant.TX_CODE_DATA_USERROLE_LIST_ALL:
          // checkSession();
          translet = new UserRoleDataTranslet(this);
          resp = translet.listAll(req);
          break;
        case ApplicationConstant.TX_CODE_DATA_USERROLE_UPDATE:
          checkSession();
          translet = new UserRoleDataTranslet(this);
          resp = translet.update(req);
          break;

        default:
          throw new Exception("EN003:交易代碼錯誤");
      }

    } catch (Exception e) {
      logger.error("Error:" + e);
      status = e.getMessage();
      if (NullTK.isNull(resp)) {
        resp = new UserRoleDataResponseVo();
      }
      resp.setTxStatus(status);
    } finally {

    }

    // 轉換回傳物件為json
    if (!NullTK.isNull(resp)) {
      json = gson.toJson(resp);
    }
    logger.debug("json:\n" + json);
    return json;
  }
예제 #8
0
  /**
   * @param csv 匯入核心
   * @throws Exception
   */
  public void doImport(List<String[]> csv) throws Exception {
    try {

      initResource();

      String eorderno = "";
      String strProject = "";
      String imei = "";
      String itemno = "";
      String bcode = "";
      String cost = "";
      // String strStatus = "";
      // String issuestatus = "";
      int status = 0; // 0-未啟用 1-已啟用 2-作業處理中
      // FetOrderImeiCollection orderList = null;
      FetorderVo order = null;
      FetorderitemVo item = null;
      int imeiCount = 0;
      boolean isProject = false;
      List<FetimeiVo> imeiList = new ArrayList<FetimeiVo>();
      FetimeiVo fetimei = null;
      FetimeiitemVo fetimeiitem = null;
      int errOrderNotExistCount = 0;
      // int itemnoChangeCnt = 0;
      // FetimeihistoryVo imeiHistVo = null;

      // 產生IMEI 清單與匯入 IMEI進貨明細表
      List<FetorderimeiVo> imeilist = buildImeiCollection(csv);
      String key = "";
      String msg = "";
      // String oldItemno = "";
      // String newItemno = "";
      // 轉檔IMEI主檔 產生訂單彙總
      for (FetorderimeiVo imeivo : imeilist) {
        isProject = false;
        eorderno = imeivo.getEorderno();
        logger.info("EOrder No: " + eorderno);
        order = isOrderExist(eorderno);

        // 對應訂單是否存在
        if (NullTK.isNull(order)) {
          msg = "/查無訂單主檔 電子訂單編號:" + imeivo.getEorderno() + "/料號:" + imeivo.getItemno();
          logger.warn(msg);
          importmemo.append(msg + "\n");
          errOrderNotExistCount++;
          continue;
          // throw new Exception(msg);
        }

        // 查詢ITEM項目是否為專案機,以 電子訂單編號與料號抓取。
        key = imeivo.getEorderno() + imeivo.getItemno();
        item = isOrderItemExist(key);
        if (NullTK.isNull(order)) {
          msg = "/查無訂單明細主檔 電子訂單編號:" + imeivo.getEorderno() + "/料號:" + imeivo.getItemno();
          logger.warn(msg);
          importmemo.append(msg + "\n");
          errOrderNotExistCount++;
          // throw new Exception(msg);
          continue;
        }

        strProject = item.getSp();
        isProject = StringTK.equals("專", strProject) ? true : false;
        bcode = imeivo.getBcode();
        imei = imeivo.getImei();
        itemno = imeivo.getItemno();
        cost = Integer.toString(item.getPrice());
        status = imeivo.getStatus();

        // 回寫 訂單明細 店碼
        if (StringTK.isEmpty(order.getBcode())) {
          order.setBcode(bcode);
          orderDao.updateBCode(order);
          orderCache.put(eorderno, order);
        }

        // 專案機拋到 IMEI 主檔清單
        if (isProject) {
          fetimei = new FetimeiVo();
          fetimei.setImei(imei);
          fetimei.setItemno(itemno);
          fetimei.setEorderno(eorderno);
          fetimei.setBcode(bcode);
          fetimei.setCost(Integer.parseInt(cost));
          fetimei.setStatus(status);
          imeiList.add(fetimei);
        }
      }

      // IMEI主檔拋轉匯入
      logger.info("Import IMEI  ");
      for (FetimeiVo iv : imeiList) {
        // 檢查是否存在
        imei = iv.getImei();
        fetimei = fetimeiCache.get(imei);
        if (NullTK.isNull(fetimei)) {
          fetimei = iv;
          logger.info(">>>fetimei null");
          fetimeiDao.insert(fetimei);
          fetimeiCache.put(imei, fetimei);
        } else {
          fetimei.setCost(iv.getCost());
          if (fetimei.getStatus() != 1) { // 已啟用保留狀態
            fetimei.setStatus(status);
          }

          // 促代異動變更 料號紀錄
          /*oldItemno = fetimei.getItemno();
          newItemno = iv.getItemno();
          if(!StringTK.equals(oldItemno, newItemno)) {
          	logger.info(">>>IMEI拋轉促代異動 " + oldItemno + " => " + newItemno);
          	importmemo.append(">>>IMEI拋轉促代異動 " + oldItemno + " => " + newItemno);
          	imeiHistVo = new FetimeihistoryVo();
          	imeiHistVo.setImei(imei);
          	imeiHistVo.setItemno(oldItemno);
          	imeiHistDao.insert(imeiHistVo);

          	fetimei.setItemno(newItemno);
          	fetimeiDao.update(fetimei);
          	fetimeiCache.put(imei, fetimei);
          	itemnoChangeCnt++;
          }*/
        }

        // IMEI細項主檔匯入
        logger.debug("IMEI細項主檔匯入");
        fetimeiitem = fetimeiItemCache.get(imei);
        if (NullTK.isNull(fetimeiitem)) {
          fetimeiitem = new FetimeiitemVo();
          fetimeiitem.setImei(imei);
          fetimeiitem.setItemno(fetimei.getItemno());
          fetimeiItemDao.insert(fetimeiitem);
          fetimeiItemCache.put(imei, fetimeiitem);
        }

        imeiCount++;
      }

      logger.info("IMEI主檔拋轉共 " + imeiCount + " 筆");
      // logger.info("IMEI主檔拋轉促代異動共 " + itemnoChangeCnt + " 筆");
      importmemo.append("IMEI主檔拋轉共 " + imeiCount + " 筆\n");
      // importmemo.append("IMEI主檔拋轉促代異動共 " + itemnoChangeCnt + " 筆\n");

    } catch (Exception e) {
      logger.error("FetImeiImporter: doImport err:" + e);
      throw e;
    }
  }