/** @author nelson */
public class IKAnalyzerUtils {

  private IKAnalyzerUtils() {}

  private static final Logger logger = LogFactory.getInstance().getLogger(IKAnalyzerUtils.class);

  public static List<String> analyze(String content) {
    List<String> resultList = null;
    try {
      // 创建分词对象
      resultList = new ArrayList<String>(1);
      resultList.add(content);
      IKAnalyzer analyer = new IKAnalyzer(true);
      analyer.setUseSmart(true);
      StringReader reader = new StringReader(content);
      // 分词
      TokenStream tokenStream = analyer.tokenStream("", reader);
      CharTermAttribute term = tokenStream.getAttribute(CharTermAttribute.class);
      // 遍历分词数据
      while (tokenStream.incrementToken()) {
        if (!term.toString().isEmpty()) {
          resultList.add(term.toString());
        }
      }
      reader.close();

    } catch (IOException ex) {
      logger.error("分词出错", ex);
    }
    return resultList;
  }
}
/** @author nelson */
@ServiceConfig(
    act = ActionNames.inquirePageWeiSiteConfigList,
    importantParameters = {"session", "pageCount", "pageNo", "encryptType"},
    requestEncrypt = CryptEnum.AES,
    parametersWrapperType = ParameterWrapperTypeEnum.SIMPLE_MAP,
    responseEncrypt = CryptEnum.AES,
    responseType = ResponseTypeEnum.ENTITY_LIST_JSON_PAGE,
    terminalType = TerminalTypeEnum.WEB,
    requireLogin = LoginEnum.REQUIRE,
    returnParameters = {
      "weiSiteConfigId",
      "weiSiteName",
      "backgroupMusicURL",
      "keyword",
      "matchType",
      "telphone",
      "isDialOpen",
      "title",
      "backgroupImageURL",
      "companyId"
    },
    description = "分页查询WeiSiteConfig",
    validateParameters = {
      @Field(fieldName = "pageCount", fieldType = FieldTypeEnum.INT, description = "分页参数"),
      @Field(fieldName = "pageNo", fieldType = FieldTypeEnum.INT, description = "分页参数"),
      @Field(fieldName = "session", fieldType = FieldTypeEnum.CHAR1024, description = "session信息"),
      @Field(fieldName = "encryptType", fieldType = FieldTypeEnum.TYINT, description = "加密类型")
    })
public class InquirePageWeiSiteConfigListService implements Service {

  private Logger logger =
      LogFactory.getInstance().getLogger(InquirePageWeiSiteConfigListService.class);

  public void execute() {
    ApplicationContext applicationContext = ApplicationContext.CTX;
    Map<String, String> parameters = applicationContext.getSimpleMapParameters();
    logger.debug("parameters={}", parameters);
    String pageCount = parameters.get("pageCount");
    String pageNo = parameters.get("pageNo");
    EntityDao<WeiSiteConfig> entityDAO = applicationContext.getEntityDAO(EntityNames.weiSiteConfig);
    List<Condition> conditionList = new ArrayList<Condition>(0);

    PageModel enityPageMode =
        entityDAO.inquirePageByCondition(
            conditionList, Integer.parseInt(pageNo), Integer.parseInt(pageCount));
    List<WeiSiteConfig> entityList = enityPageMode.getDataList();
    if (entityList != null) {
      if (!entityList.isEmpty()) {
        applicationContext.setEntityList(entityList);
        applicationContext.setCount(enityPageMode.getTotalCount());
        applicationContext.setTotalPage(applicationContext.getTotalPage());
        applicationContext.success();
      } else {
        applicationContext.noData();
      }
    } else {
      throw new RollBackException("操作失败");
    }
  }
}
/** @author nelson */
@ServiceConfig(
    act = ActionNames.inquirePayFlowList,
    importantParameters = {"session", "encryptType"},
    requestEncrypt = CryptEnum.AES,
    parametersWrapperType = ParameterWrapperTypeEnum.SIMPLE_MAP,
    responseEncrypt = CryptEnum.AES,
    responseType = ResponseTypeEnum.ENTITY_LIST_JSON,
    terminalType = TerminalTypeEnum.WEB,
    requireLogin = LoginEnum.REQUIRE,
    returnParameters = {"payFlowId", "fromAccount", "toAccount", "money", "createTime"},
    description = "查询PayFlow配置",
    validateParameters = {
      @Field(fieldName = "session", fieldType = FieldTypeEnum.CHAR1024, description = "session信息"),
      @Field(fieldName = "encryptType", fieldType = FieldTypeEnum.TYINT, description = "加密类型")
    })
public class InquirePayFlowListService implements Service {

  private Logger logger = LogFactory.getInstance().getLogger(InquirePayFlowListService.class);

  public void execute() {
    ApplicationContext applicationContext = ApplicationContext.CTX;
    Map<String, String> parameters = applicationContext.getSimpleMapParameters();
    logger.debug("parameters={}", parameters);
    EntityDao<PayFlow> entityDAO = applicationContext.getEntityDAO(EntityNames.payFlow);
    List<Condition> conditionList = new ArrayList<Condition>(0);
    List<PayFlow> entityList = entityDAO.inquireByCondition(conditionList);
    if (entityList != null) {
      applicationContext.setEntityList(entityList);
      applicationContext.success();
    } else {
      throw new RollBackException("操作失败");
    }
  }
}
/** @author nelson */
@ServiceConfig(
    act = ActionNames.inquireResourcesMenuList,
    importantParameters = {"session", "encryptType"},
    requestEncrypt = CryptEnum.PLAIN,
    parametersWrapperType = ParameterWrapperTypeEnum.SIMPLE_MAP,
    responseEncrypt = CryptEnum.AES,
    responseType = ResponseTypeEnum.MAP_DATA_JSON,
    terminalType = TerminalTypeEnum.WEB,
    requireLogin = LoginEnum.REQUIRE,
    returnParameters = {"systemResource", "businessResource"},
    description = "查询Resources配置",
    validateParameters = {
      @Field(fieldName = "session", fieldType = FieldTypeEnum.CHAR1024, description = "session信息"),
      @Field(fieldName = "encryptType", fieldType = FieldTypeEnum.TYINT, description = "加密类型")
    })
public class InquireResourcesMenuListService implements Service {

  private Logger logger = LogFactory.getInstance().getLogger(InquireResourcesMenuListService.class);

  public void execute() {
    ApplicationContext applicationContext = ApplicationContext.CTX;
    Map<String, String> parameters = applicationContext.getSimpleMapParameters();
    long companyId = applicationContext.getUserId();
    logger.debug("parameters={}", parameters);
    EntityDao<Resources> entityDAO = applicationContext.getEntityDAO(EntityNames.resources);
    List<Condition> conditionList = new ArrayList<Condition>(0);
    Condition companyIdCondition =
        new Condition("companyId", ConditionTypeEnum.EQUAL, String.valueOf(companyId));
    conditionList.add(companyIdCondition);
    List<Resources> entityList = entityDAO.inquireByCondition(conditionList);
    if (entityList != null) {
      Map<String, String> resultMap;
      List<Map<String, String>> systemMapList = new ArrayList<Map<String, String>>(0);
      List<Map<String, String>> bussinessMapList = new ArrayList<Map<String, String>>(0);
      Map<String, String> resourceMap = null;
      for (Resources resources : entityList) {
        if (resources.getResourcesType() == SalesConstant.SYSTEM_RESOURCE_TYPE
            || resources.getResourcesType() == SalesConstant.CUSTOM_RESOURCE_TYPE
            || resources.getResourcesType() == SalesConstant.WEISITE_RESOURCE_TYPE) {
          resourceMap = new HashMap<String, String>(2);
          resourceMap.put("resourcesName", resources.getResourcesName());
          resourceMap.put("resourcesId", String.valueOf(resources.getResourcesId()));
          bussinessMapList.add(resourceMap);
        } else if (resources.getResourcesType() == SalesConstant.SINGLE__TEXT
            || resources.getResourcesType() == SalesConstant.SINGLE_IMAGE_TEXT
            || resources.getResourcesType() == SalesConstant.MULTI_IMAGE_TEXT) {
          resourceMap = new HashMap<String, String>(2);
          resourceMap.put("resourcesName", resources.getResourcesName());
          resourceMap.put("resourcesId", String.valueOf(resources.getResourcesId()));
          systemMapList.add(resourceMap);
        }
      }
      resultMap = new HashMap<String, String>(4, 1);
      resultMap.put("systemResource", JsonUtils.mapListToJsonArray(systemMapList));
      resultMap.put("businessResource", JsonUtils.mapListToJsonArray(bussinessMapList));
      applicationContext.setMapData(resultMap);
      applicationContext.success();
    }
  }
}
/** @author nelson */
@ServiceConfig(
    act = ActionNames.inquireWeiSiteConfigList,
    importantParameters = {"session", "encryptType"},
    requestEncrypt = CryptEnum.PLAIN,
    parametersWrapperType = ParameterWrapperTypeEnum.SIMPLE_MAP,
    responseEncrypt = CryptEnum.AES,
    responseType = ResponseTypeEnum.ENTITY_JSON,
    terminalType = TerminalTypeEnum.WEB,
    requireLogin = LoginEnum.REQUIRE,
    returnParameters = {
      "weiSiteConfigId",
      "weiSiteName",
      "backgroupMusicURL",
      "keyword",
      "matchType",
      "telphone",
      "isDialOpen",
      "title",
      "backgroupImageURL"
    },
    description = "查询WeiSiteConfig配置",
    validateParameters = {
      @Field(fieldName = "session", fieldType = FieldTypeEnum.CHAR1024, description = "session信息"),
      @Field(fieldName = "encryptType", fieldType = FieldTypeEnum.TYINT, description = "加密类型")
    })
public class InquireWeiSiteConfigListService implements Service {

  private Logger logger = LogFactory.getInstance().getLogger(InquireWeiSiteConfigListService.class);

  public void execute() {
    ApplicationContext applicationContext = ApplicationContext.CTX;
    Map<String, String> parameters = applicationContext.getSimpleMapParameters();
    long companyId = applicationContext.getUserId();
    logger.debug("parameters={}", parameters);
    EntityDao<WeiSiteConfig> entityDAO = applicationContext.getEntityDAO(EntityNames.weiSiteConfig);
    List<Condition> conditionList = new ArrayList<Condition>(0);
    Condition companyIdCondition =
        new Condition("companyId", ConditionTypeEnum.EQUAL, String.valueOf(companyId));
    conditionList.add(companyIdCondition);
    List<WeiSiteConfig> entityList = entityDAO.inquireByCondition(conditionList);
    if (entityList != null) {
      if (!entityList.isEmpty()) {
        applicationContext.setEntityData(entityList.get(0));
        applicationContext.success();
      } else {
        applicationContext.fail();
      }
    } else {
      throw new RollBackException("操作失败");
    }
  }
}
/** @author Administrator */
public class DateTimeUtils {

  private DateTimeUtils() {}

  private static final Logger logger = LogFactory.getInstance().getLogger(DateTimeUtils.class);
  private static final String weekDays[] = {"星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六"};

  public static long getTimesMorning() {
    Calendar cal = Calendar.getInstance();
    cal.setTimeInMillis(System.currentTimeMillis());
    cal.set(Calendar.HOUR_OF_DAY, 0);
    cal.set(Calendar.SECOND, 0);
    cal.set(Calendar.MINUTE, 0);
    cal.set(Calendar.MILLISECOND, 0);
    return cal.getTimeInMillis();
  }

  public static String getFormatTime(Timestamp datetime) {
    SimpleDateFormat sdf = new java.text.SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    String st = sdf.format(datetime); //
    return st.substring(st.length() - 8);
  }

  public static long getTimes(int hour, int second, int minute, int millsecond) {
    Calendar cal = Calendar.getInstance();
    cal.setTimeInMillis(System.currentTimeMillis());
    cal.set(Calendar.HOUR_OF_DAY, hour);
    cal.set(Calendar.SECOND, second);
    cal.set(Calendar.MINUTE, minute);
    cal.set(Calendar.MILLISECOND, millsecond);
    return cal.getTimeInMillis();
  }
  // 获得当天24点时间

  public static long getTimesNight() {
    Calendar cal = Calendar.getInstance();
    cal.setTimeInMillis(System.currentTimeMillis());
    cal.set(Calendar.HOUR_OF_DAY, 24);
    cal.set(Calendar.SECOND, 0);
    cal.set(Calendar.MINUTE, 0);
    cal.set(Calendar.MILLISECOND, 0);
    return cal.getTimeInMillis();
  }

  public static Timestamp str2Timestamp(String yyyymmddhhmmss) {
    Timestamp ts = Timestamp.valueOf(yyyymmddhhmmss);
    return ts;
  }

  public static String timestamp2Str(Timestamp datetime) {
    String st = "";
    if (datetime != null) {
      SimpleDateFormat sdf = new java.text.SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
      st = sdf.format(datetime); //
    }
    return st;
  }

  public static Timestamp long2Timestamp(long time) {
    return new Timestamp(time);
  }

  public static long getTimeStampSeconds(Timestamp datetime) {
    long millionSeconds = datetime.getTime();
    return millionSeconds / 1000l;
  }

  /**
   * 获取指定时间对应的毫秒数
   *
   * @param time "HH:mm:ss"
   * @return
   */
  public static long getTimeMillis(String time) {
    try {
      DateFormat dateFormat = new SimpleDateFormat("yy-MM-dd HH:mm:ss");
      DateFormat dayFormat = new SimpleDateFormat("yy-MM-dd");
      Date curDate = dateFormat.parse(dayFormat.format(new Date()) + " " + time);
      return curDate.getTime();
    } catch (ParseException e) {
      logger.error("解析日期出现问题", e);
    }
    return 0;
  }

  public static int getDateSeconds(String dateStr) {
    int dateSeconds = 0;
    try {
      DateFormat dayFormat = new SimpleDateFormat("yyyy-MM-dd");
      Date date = dayFormat.parse(dateStr);
      dateSeconds = (int) (date.getTime() / 1000l);
    } catch (ParseException ex) {
      logger.error("解析日期出现问题", ex);
    }
    return dateSeconds;
  }

  public static long getDateMillionSeconds(String dateStr) {
    long dateSeconds = 0;
    try {
      DateFormat dayFormat = new SimpleDateFormat("yyyy-MM-dd");
      Date date = dayFormat.parse(dateStr);
      dateSeconds = date.getTime();
    } catch (ParseException ex) {
      logger.error("解析日期出现问题", ex);
    }
    return dateSeconds;
  }

  public static String getWeekName(String dateStr) {
    Calendar calendar = Calendar.getInstance();
    calendar.setTimeInMillis(getDateMillionSeconds(dateStr));
    int dayOfWeek = calendar.get(Calendar.DAY_OF_WEEK) - 1;
    if (dayOfWeek < 0) {
      dayOfWeek = 0;
    }
    return weekDays[dayOfWeek];
  }

  public static int getWeekIndex(String dateStr) {

    Calendar calendar = Calendar.getInstance();
    calendar.setTimeInMillis(getDateMillionSeconds(dateStr));
    int dayOfWeek = calendar.get(Calendar.DAY_OF_WEEK) - 1;
    if (dayOfWeek < 0) {
      dayOfWeek = 0;
    }
    return dayOfWeek;
  }

  public static boolean isToday(Timestamp timestamp) {
    boolean isToday = false;
    if (timestamp != null) {
      long times = getTimes(23, 59, 59, 0);
      long now = timestamp.getTime();
      long diff = times - now;
      if (diff > 0) {
        long days = diff / (1000l * 60 * 60 * 24);
        if (days == 0) {
          isToday = true;
        }
      }
    }
    return isToday;
  }

  public static int getDay(Timestamp timestamp) {
    String st = "";
    if (timestamp != null) {
      SimpleDateFormat sdf = new java.text.SimpleDateFormat("yyyyMMdd");
      st = sdf.format(timestamp);
    }
    return Integer.parseInt(st);
  }

  public static int getLastDay() {
    Calendar calendar = Calendar.getInstance();
    calendar.add(Calendar.DATE, -1);
    Date date = calendar.getTime();
    SimpleDateFormat sdf = new java.text.SimpleDateFormat("yyyyMMdd");
    String st = sdf.format(date);
    return Integer.parseInt(st);
  }

  public static Timestamp getLastDayInTimestamp() {
    Calendar calendar = Calendar.getInstance();
    calendar.add(Calendar.DATE, -1);
    long time = calendar.getTimeInMillis();
    Timestamp timestamp = new Timestamp(time);
    return timestamp;
  }

  public static long getTimestampDiff(Timestamp firstTimestatmp, Timestamp secondTimestamp) {
    long firstTime = firstTimestatmp.getTime();
    long secondTime = secondTimestamp.getTime();
    return firstTime - secondTime;
  }

  //    public static int getAge(long birthday) {
  //        Date birthdayDate = new Date();
  //        birthdayDate.setTime(birthday);
  //        Date today = new Date();
  //        return today.getYear() - birthdayDate.getYear();
  //
  //    }
  public static int getAge(Integer birthday) {
    DateFormat dayFormat = new SimpleDateFormat("yyyyMMdd");
    Date date = new Date();
    try {
      date = dayFormat.parse(String.valueOf(birthday));
    } catch (ParseException ex) {
      logger.error("解析日期出现问题", ex);
    }
    Date today = new Date();
    return today.getYear() - date.getYear();
  }

  public static int getDateToInteger(String dateStr) {
    int result = 0;
    if (dateStr != null && !dateStr.isEmpty()) {
      result = Integer.parseInt(dateStr.replace("-", "").trim());
    }
    return result;
  }

  public static String convertDateFormat(Integer dateInteger, String format) {
    String result = "";
    if (dateInteger != null && dateInteger != 0) {
      if (format != null && !format.isEmpty()) {
        try {
          DateFormat dayFormat = new SimpleDateFormat("yyyyMMdd");
          Date date = dayFormat.parse(String.valueOf(dateInteger));
          SimpleDateFormat sdf = new java.text.SimpleDateFormat(format);
          result = sdf.format(date);
        } catch (ParseException ex) {
          logger.error("解析日期出现问题", ex);
        }
      }
    }
    return result;
  }

  public static int getDateInSecondes(Integer birthday) {
    int dateSeconds = 0;
    DateFormat dayFormat = new SimpleDateFormat("yyyyMMdd");
    Date date = new Date();
    try {
      date = dayFormat.parse(String.valueOf(birthday));
      dateSeconds = (int) (date.getTime() / 1000l);
    } catch (ParseException ex) {
      logger.error("解析日期出现问题", ex);
    }

    return dateSeconds;
  }

  public static String getWeek(long currentTime, int daysOfWeek) {
    Calendar cal = Calendar.getInstance();
    cal.setTimeInMillis(System.currentTimeMillis());
    cal.add(Calendar.DATE, daysOfWeek);
    DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    Timestamp timestamp = new Timestamp(cal.getTimeInMillis());
    return dateFormat.format(timestamp);
  }

  public static String getMonth(long currentTime, int month) {
    Calendar cal = Calendar.getInstance();
    cal.setTimeInMillis(System.currentTimeMillis());
    cal.add(Calendar.MONTH, month);
    DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    Timestamp timestamp = new Timestamp(cal.getTimeInMillis());
    return dateFormat.format(timestamp);
  }

  public static String getHour(long currentTime, int hours) {
    Calendar cal = Calendar.getInstance();
    cal.setTimeInMillis(System.currentTimeMillis());
    cal.add(Calendar.HOUR_OF_DAY, hours);
    DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    Timestamp timestamp = new Timestamp(cal.getTimeInMillis());
    return dateFormat.format(timestamp);
  }

  public static Timestamp getHourTimestamp(long currentTime, int hours) {
    Calendar cal = Calendar.getInstance();
    cal.setTimeInMillis(System.currentTimeMillis());
    cal.add(Calendar.HOUR_OF_DAY, hours);
    Timestamp timestamp = new Timestamp(cal.getTimeInMillis());
    return timestamp;
  }

  public static String currentDay() {
    Timestamp timestamp = new Timestamp(System.currentTimeMillis());
    DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    return dateFormat.format(timestamp);
  }

  public static String currentYYYYMMDDDay() {
    Timestamp timestamp = new Timestamp(System.currentTimeMillis());
    DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
    return dateFormat.format(timestamp);
  }

  public static String currentYYYYMMDay() {
    Timestamp timestamp = new Timestamp(System.currentTimeMillis());
    DateFormat dateFormat = new SimpleDateFormat("yyyy-MM");
    return dateFormat.format(timestamp);
  }
}
/** @author nelson */
@ServiceConfig(
    act = ActionNames.inquireWeiSiteImageById,
    importantParameters = {"session", "encryptType", "weiSiteImageId"},
    requestEncrypt = CryptEnum.AES,
    parametersWrapperType = ParameterWrapperTypeEnum.SIMPLE_MAP,
    responseEncrypt = CryptEnum.AES,
    responseType = ResponseTypeEnum.ENTITY_JSON,
    terminalType = TerminalTypeEnum.WEB,
    returnParameters = {
      "weiSiteImageId",
      "weiSiteImageName",
      "weiSiteImageDesc",
      "weiSiteImageURL",
      "weiSiteImageType",
      "companyId",
      "bindId"
    },
    description = "查询WeiSiteImage详细内容",
    validateParameters = {
      @Field(
          fieldName = "weiSiteImageId",
          fieldType = FieldTypeEnum.BIG_INT,
          description = "微站图片id"),
      @Field(
          fieldName = "weiSiteImageName",
          fieldType = FieldTypeEnum.CHAR36,
          description = "图片名称"),
      @Field(
          fieldName = "weiSiteImageDesc",
          fieldType = FieldTypeEnum.CHAR128,
          description = "图片描述"),
      @Field(
          fieldName = "weiSiteImageURL",
          fieldType = FieldTypeEnum.CHAR64,
          description = "图片的地址"),
      @Field(
          fieldName = "weiSiteImageType",
          fieldType = FieldTypeEnum.TYINT,
          description = "图片的类型"),
      @Field(fieldName = "companyId", fieldType = FieldTypeEnum.BIG_INT, description = "公司id"),
      @Field(fieldName = "bindId", fieldType = FieldTypeEnum.BIG_INT, description = "绑定的id"),
      @Field(fieldName = "session", fieldType = FieldTypeEnum.CHAR1024, description = "session类型"),
      @Field(fieldName = "encryptType", fieldType = FieldTypeEnum.TYINT, description = "加密类型")
    })
public class InquireWeiSiteImageByIdService implements Service {

  private Logger logger = LogFactory.getInstance().getLogger(InquireWeiSiteImageByIdService.class);

  public void execute() {
    ApplicationContext applicationContext = ApplicationContext.CTX;
    Map<String, String> parameters = applicationContext.getSimpleMapParameters();
    logger.debug("parameters={}", parameters);
    PrimaryKey primaryKey = new PrimaryKey();
    String weiSiteImageId = parameters.get("weiSiteImageId");
    primaryKey.putKeyField("weiSiteImageId", String.valueOf(weiSiteImageId));

    EntityDao<WeiSiteImage> entityDAO = applicationContext.getEntityDAO(EntityNames.weiSiteImage);
    WeiSiteImage entity = entityDAO.inqurieByKey(primaryKey);
    if (entity != null) {
      applicationContext.setEntityData(entity);
      applicationContext.success();
    } else {
      throw new RollBackException("操作失败");
    }
  }
}