Esempio n. 1
0
  public CityTrl[] getCityCityList(String value, String countryId, String provinceId) {
    // System.out.println("bgn");
    if (!DwrPrivilegeFilter.isView(this.getClass().getName())) {
      return null;
    }
    if (value == null) value = "";
    Map param = new HashMap();
    WebContext webContext = WebContextFactory.get();
    HttpServletRequest request = webContext.getHttpServletRequest();
    UserResource ur = (UserResource) request.getSession().getAttribute("resource");
    StringBuilder sb = new StringBuilder("");
    if (StringUtil.isNotEmpty(provinceId)) {
      sb.append("and parent_id=").append(provinceId);
    } else if (StringUtil.isNotEmpty(countryId)) {
      sb.append("and parent_id in (select id from base_city where parent_id=")
          .append(countryId)
          .append(")");
    }

    param.put(
        "accessString",
        "language='"
            + ur.getLocale().toString()
            + "' and  ((name like '%"
            + value.trim()
            + "%') or (remark like '%"
            + value.trim()
            + "%'))  and  city_id in( select id from base_city where levelint=3 "
            + sb.toString()
            + ")");
    List<CityTrl> list = cityTrlService.selectByExample(param);
    if (list != null) {

      if (list.size() > 10) {
        list = list.subList(0, 10);
      }
      CityTrl[] cityTrlArray = new CityTrl[list.size()];
      list.toArray(cityTrlArray);
      // System.out.println("comp");
      return cityTrlArray;
    }
    return null;
  }
  public void writeLog(CoreModel model, String operateType) {
    String name = model.getClass().getName();
    Map<String, Object> param = new HashMap<String, Object>();
    param.put("className", name);
    param.put("outLog", "Y");
    List<Table> tableList =
        sqlSessionTemplate.selectList(
            "com.delmar.core.mybatis.sql.TableMapper.selectByExample", param);

    Table table = null;
    if (tableList != null && tableList.size() > 0) {
      table = tableList.get(0);
    }
    try {
      if (table != null) {
        param = new HashMap<String, Object>();
        param.put("tableId", table.getId());
        List<TableColumn> tableColumnList =
            sqlSessionTemplate.selectList(
                "com.delmar.core.mybatis.sql.TableColumnMapper.selectByExample", param);
        Map<String, Object> obj = new HashMap<String, Object>();
        if (tableColumnList != null) {
          for (TableColumn column : tableColumnList) {
            obj.put(
                column.getAttributeName(),
                PropertyUtils.getProperty(model, column.getAttributeName()));
          }
        }
        Changelog log = new Changelog();
        log.setOperateType(operateType);
        log.setCreated(new Date());
        log.setContext(gson.toJson(obj));

        if (request != null) {
          UserInterface user = (UserInterface) request.getSession().getAttribute("loginUser");
          if (user != null) {
            log.setUserId(user.getId());
            log.setUsername(user.getUsername());
          } else {
            String userName = SessionContent.getUserId(Thread.currentThread().getId());
            log.setUsername(userName);
          }
        } else {
          String userName = SessionContent.getUserId(Thread.currentThread().getId());
          log.setUsername(userName);
        }

        Object pk = PropertyUtils.getProperty(model, "id");
        if (pk != null) log.setPk((Integer) pk);
        if (StringUtil.isNotEmpty(table.getBuPk())) {
          Object buPk = PropertyUtils.getProperty(model, table.getBuPk());
          if (buPk != null) log.setBuPk(buPk.toString());
        }

        log.setTableId(table.getId());
        sqlSessionTemplate.insert("com.delmar.core.mybatis.sql.ChangelogMapper.insert", log);
      }

    } catch (Exception e) {
      logger.error("插入操作日志异常", e);
    }
  }