diff --git a/projects/fangjia-bkoff/src/main/java/com/fangjia/bkoff/controllers/ApiUserController.java b/projects/fangjia-bkoff/src/main/java/com/fangjia/bkoff/controllers/ApiUserController.java index 7df83ddd3..d9db99a40 100644 --- a/projects/fangjia-bkoff/src/main/java/com/fangjia/bkoff/controllers/ApiUserController.java +++ b/projects/fangjia-bkoff/src/main/java/com/fangjia/bkoff/controllers/ApiUserController.java @@ -46,68 +46,67 @@ import java.util.*; /** * api用户开通等管理controller - * + * * @author */ public class ApiUserController { - private ApiUserService apiUserService; - private UserService userService; - private ApiUserAuthorityService apiUserAuthorityService; - private OpenResourceService openResourceService; - private ServerAreaService serverAreaService; - private OpenResourceCountService openResourceCountService; - private OpenUriAnalyService openUriAnalyService; - private ApiUserCfgService apiUserCfgService; - private ApiInvokeStatisticalService apiInvokeStatisticalService; - private ApiVisitCountService apiVisitCountService; - private ApiCountCityService apiCountCityService; + private ApiUserService apiUserService; + private UserService userService; + private ApiUserAuthorityService apiUserAuthorityService; + private OpenResourceService openResourceService; + private ServerAreaService serverAreaService; + private OpenResourceCountService openResourceCountService; + private OpenUriAnalyService openUriAnalyService; + private ApiUserCfgService apiUserCfgService; + private ApiInvokeStatisticalService apiInvokeStatisticalService; + private ApiVisitCountService apiVisitCountService; + private ApiCountCityService apiCountCityService; + /** + * 所有api用户的信息展示 + * + * @param model + * @return + */ + public Object listAction(ApiUserModel model) { + /** + * open中公开出的接口资源 ApiUserAuthority 用户的权限信息 + * + * @param ApiUser + * :用户的资料信息 + * @param ApiUser + * :用户的appKey username、等资料 + */ + List apiUsers = this.apiUserService.findApiUsersByParamsSortDate(null); + List apiUserBoList = new ArrayList(); + for (ApiUser apiUser : apiUsers) { + User user = this.userService.findById(apiUser.getId()); + if (user == null) { + continue; + } + ApiUserBo bo = new ApiUserBo(); + bo.setAppKey(apiUser.getAppKey()); + if (null != user) { + bo.setUserId(user.getId()); + bo.setPassword(user.getPassword()); + bo.setUserName(user.getUserName()); + bo.setDisplayName(user.getDisplayName()); + } - /** - * 所有api用户的信息展示 - * - * @param model - * @return - */ - public Object listAction(ApiUserModel model) { - /** - * open中公开出的接口资源 ApiUserAuthority 用户的权限信息 - * - * @param ApiUser - * :用户的资料信息 - * @param ApiUser - * :用户的appKey username、等资料 - */ - List apiUsers = this.apiUserService.findApiUsersByParamsSortDate(null); - List apiUserBoList = new ArrayList(); - for (ApiUser apiUser : apiUsers) { - User user = this.userService.findById(apiUser.getId()); - if (user == null) { - continue; - } - ApiUserBo bo = new ApiUserBo(); - bo.setAppKey(apiUser.getAppKey()); - if(null != user){ - bo.setUserId(user.getId()); - bo.setPassword(user.getPassword()); - bo.setUserName(user.getUserName()); - bo.setDisplayName(user.getDisplayName()); - } - - bo.setSiteName(apiUser.getSiteName()); - bo.setStatus(apiUser.getStatus()); + bo.setSiteName(apiUser.getSiteName()); + bo.setStatus(apiUser.getStatus()); bo.setCompany(apiUser.getCompany()); - bo.setIsTest(apiUser.getIsTest()); - bo.setPurpose(apiUser.getPurpose()); - bo.setDeadTime(apiUser.getDeadTime()); - bo.setManager(apiUser.getManager()); - bo.setIsMonitor(apiUser.getIsMonitor()); + bo.setIsTest(apiUser.getIsTest()); + bo.setPurpose(apiUser.getPurpose()); + bo.setDeadTime(apiUser.getDeadTime()); + bo.setManager(apiUser.getManager()); + bo.setIsMonitor(apiUser.getIsMonitor()); - apiUserBoList.add(bo); - } + apiUserBoList.add(bo); + } - Collections.sort(apiUserBoList, new Comparator() { + Collections.sort(apiUserBoList, new Comparator() { @Override public int compare(ApiUserBo o1, ApiUserBo o2) { if (o1.getStatus() == 0) { @@ -118,482 +117,506 @@ public class ApiUserController { }); - model.setApiUserBoList(apiUserBoList); - return model; - } - - public Object openlistAction(ApiUserModel model) { - return model; - } - - public Object resetPwdAction(ApiUserModel model) { - JsonModel ret = new JsonModel(); - Map dataMap = new HashMap(); - dataMap.put("status", 0); - if (model.getUserId() != null) { - Map data = new HashMap(); - data.put("password", DigestUtils.md5Hex("123456")); - userService.updateById(data, model.getUserId()); - dataMap.put("status", 1); - } - ret.setJsonModel(dataMap); - return ret; - } + model.setApiUserBoList(apiUserBoList); + return model; + } - /** - * 新增api用户的信息 - * - * @param model - * @return - */ - public Object addAction(ApiUserModel model) { - return model; - } + public Object openlistAction(ApiUserModel model) { + return model; + } - public Object doAddAction(ApiUserModel model) throws Exception { - if (StringUtils.isBlank(model.getDisplayName()) || StringUtils.isBlank(model.getUserName()) - || StringUtils.isBlank(model.getPassword())) { - model.setMsg("昵称,用户名,密码不能为空"); - model.forward("/apiUser/add"); - return model; - } + public Object resetPwdAction(ApiUserModel model) { + JsonModel ret = new JsonModel(); + Map dataMap = new HashMap(); + dataMap.put("status", 0); + if (model.getUserId() != null) { + Map data = new HashMap(); + data.put("password", DigestUtils.md5Hex("123456")); + userService.updateById(data, model.getUserId()); + dataMap.put("status", 1); + } + ret.setJsonModel(dataMap); + return ret; + } - try { - List users = new ArrayList(); - User user = new User(); - user.setUserName(model.getUserName()); - user.setPassword(DigestUtils.md5Hex(model.getPassword())); - user.setDisplayName(model.getDisplayName()); - users.add(user); - Map userMap = this.userService.saveUser(users); - Long id = userMap.get(model.getUserName()); + /** + * 新增api用户的信息 + * + * @param model + * @return + */ + public Object addAction(ApiUserModel model) { + return model; + } - String appkey = DigestUtils.md5Hex(String.valueOf(id)) + DigestUtils.md5Hex(DigestUtils.md5Hex(String.valueOf(id))); - Date date = new Date(); - ApiUser apiUser = new ApiUser(); - apiUser.setId(id); - apiUser.setAppKey(appkey.toUpperCase()); - apiUser.setCreationDate(date); - apiUser.setSiteName(model.getSiteName()); + public Object doAddAction(ApiUserModel model) throws Exception { + if (StringUtils.isBlank(model.getDisplayName()) || StringUtils.isBlank(model.getUserName()) + || StringUtils.isBlank(model.getPassword())) { + model.setMsg("昵称,用户名,密码不能为空"); + model.forward("/apiUser/add"); + return model; + } + + try { + List users = new ArrayList(); + User user = new User(); + user.setUserName(model.getUserName()); + user.setPassword(DigestUtils.md5Hex(model.getPassword())); + user.setDisplayName(model.getDisplayName()); + users.add(user); + Map userMap = this.userService.saveUser(users); + Long id = userMap.get(model.getUserName()); + + String appkey = DigestUtils.md5Hex(String.valueOf(id)) + DigestUtils.md5Hex(DigestUtils.md5Hex(String.valueOf(id))); + Date date = new Date(); + ApiUser apiUser = new ApiUser(); + apiUser.setId(id); + apiUser.setAppKey(appkey.toUpperCase()); + apiUser.setCreationDate(date); + apiUser.setSiteName(model.getSiteName()); apiUser.setCompany(model.getCompany()); - apiUser.setStatus(0); - apiUser.setIsTest(model.getIsTest()); - apiUser.setPurpose(model.getPurpose()); - apiUser.setIp(model.getIp()); - apiUser.setEmail(model.getEmail()); - apiUser.setModificationDate(date); - apiUser.setDeadTime(model.getDeadTime()); - apiUser.setManager(model.getManager()); - apiUser.setIsMonitor(model.getIsMonitor()); - this.apiUserService.save(apiUser); - if(model.getEvaluateRate() != null && model.getEvaluateRate() != 0){ - ApiUserCfg apiUserCfg = new ApiUserCfg(); - apiUserCfg.setUserId(apiUser.getId()); - apiUserCfg.setCfgValue(model.getEvaluateRate()); - this.apiUserCfgService.save(apiUserCfg, ApiUserCfg.ApiUserCfgKey.EVALUATE_RATE); - } - model.setMsg("新建成功!"); - } catch (Exception e) { - e.printStackTrace(); - model.setMsg("新建失败!"); - } - model.redirect("/apiUser/add?msg=" + URLEncoder.encode(model.getMsg(), "UTF-8")); - return model; - } + apiUser.setStatus(0); + apiUser.setIsTest(model.getIsTest()); + apiUser.setPurpose(model.getPurpose()); + apiUser.setIp(model.getIp()); + apiUser.setEmail(model.getEmail()); + apiUser.setModificationDate(date); + apiUser.setDeadTime(model.getDeadTime()); + apiUser.setManager(model.getManager()); + apiUser.setIsMonitor(model.getIsMonitor()); + this.apiUserService.save(apiUser); + // 新增用户,默认挂牌价改为默认评估价 + model.setPriceType("evaluate"); + modifyUserCfg(id, ApiUserCfg.ApiUserCfgKey.PRICE_TYPE, model.getPriceType()); + if (model.getEvaluateRate() != null && model.getEvaluateRate() != 0) { + ApiUserCfg apiUserCfg = new ApiUserCfg(); + apiUserCfg.setUserId(apiUser.getId()); + apiUserCfg.setCfgValue(model.getEvaluateRate()); + this.apiUserCfgService.save(apiUserCfg, ApiUserCfg.ApiUserCfgKey.EVALUATE_RATE); + } + model.setMsg("新建成功!"); + } catch (Exception e) { + e.printStackTrace(); + model.setMsg("新建失败!"); + } + model.redirect("/apiUser/add?msg=" + URLEncoder.encode(model.getMsg(), "UTF-8")); + return model; + } - /** - * 编辑api用户信息 - * - * @param model - * @return - */ - public Object editAction(ApiUserModel model) { - ApiUser apiUser = this.apiUserService.findApiUserById(model.getUserId()); - User user = this.userService.findById(model.getUserId()); - ApiUserBo bo = new ApiUserBo(); - bo.setUserName(user.getUserName()); - bo.setAppKey(apiUser.getAppKey()); - bo.setUserId(user.getId()); - bo.setSiteName(user.getUserName()); - bo.setDisplayName(user.getDisplayName()); - bo.setIsTest(apiUser.getIsTest()); - bo.setPurpose(apiUser.getPurpose()); - bo.setSiteName(apiUser.getSiteName()); - bo.setIp(apiUser.getIp()); + /** + * 编辑api用户信息 + * + * @param model + * @return + */ + public Object editAction(ApiUserModel model) { + ApiUser apiUser = this.apiUserService.findApiUserById(model.getUserId()); + User user = this.userService.findById(model.getUserId()); + ApiUserBo bo = new ApiUserBo(); + bo.setUserName(user.getUserName()); + bo.setAppKey(apiUser.getAppKey()); + bo.setUserId(user.getId()); + bo.setSiteName(user.getUserName()); + bo.setDisplayName(user.getDisplayName()); + bo.setIsTest(apiUser.getIsTest()); + bo.setPurpose(apiUser.getPurpose()); + bo.setSiteName(apiUser.getSiteName()); + bo.setIp(apiUser.getIp()); bo.setCompany(apiUser.getCompany()); - bo.setEmail(apiUser.getEmail()); - bo.setDeadTime(apiUser.getDeadTime()); - bo.setManager(apiUser.getManager()); - bo.setIsMonitor(apiUser.getIsMonitor()); - ApiUserCfg apiUserCfg_rate = apiUserCfgService.findByUserId(apiUser.getId(), ApiUserCfg.ApiUserCfgKey.EVALUATE_RATE); - if(apiUserCfg_rate != null){ - bo.setEvaluateRate((Double) apiUserCfg_rate.getCfgValue()); - } + bo.setEmail(apiUser.getEmail()); + bo.setDeadTime(apiUser.getDeadTime()); + bo.setManager(apiUser.getManager()); + bo.setIsMonitor(apiUser.getIsMonitor()); + ApiUserCfg apiUserCfg_rate = apiUserCfgService.findByUserId(apiUser.getId(), ApiUserCfg.ApiUserCfgKey.EVALUATE_RATE); + if (apiUserCfg_rate != null) { + bo.setEvaluateRate((Double) apiUserCfg_rate.getCfgValue()); + } - ApiUserCfg apiUserCfg_pt = apiUserCfgService.findByUserId(apiUser.getId(), ApiUserCfg.ApiUserCfgKey.PRICE_TYPE); - if(apiUserCfg_pt != null && apiUserCfg_pt.getCfgValue() != null){ - bo.setPriceType(apiUserCfg_pt.getCfgValue().toString()); - } + ApiUserCfg apiUserCfg_pt = apiUserCfgService.findByUserId(apiUser.getId(), ApiUserCfg.ApiUserCfgKey.PRICE_TYPE); + if (apiUserCfg_pt != null && apiUserCfg_pt.getCfgValue() != null) { + bo.setPriceType(apiUserCfg_pt.getCfgValue().toString()); + } - model.setApiUserBo(bo); - if (StringUtils.isNotBlank(model.getMsg()) && model.getMsg().equals("success")) { - model.setMsg("更新成功!"); - } - return model; - } + model.setApiUserBo(bo); + if (StringUtils.isNotBlank(model.getMsg()) && model.getMsg().equals("success")) { + model.setMsg("更新成功!"); + } + return model; + } - /** - * 修改用户登录状态 - * - * @param model - * @return - */ - public Object statusAction(ApiUserModel model) { - ApiUser apiUser = this.apiUserService.findApiUserById(model.getUserId()); - apiUser.setStatus(model.getStatus()); - apiUserService.update(apiUser); - model.setViewType("redirect"); - apiUserAuthorityService.clearApiUserAuthorityCache(apiUser.getId()); - model.setViewParam("location", "/apiUser/list"); - return model; - } + /** + * 修改用户登录状态 + * + * @param model + * @return + */ + public Object statusAction(ApiUserModel model) { + ApiUser apiUser = this.apiUserService.findApiUserById(model.getUserId()); + apiUser.setStatus(model.getStatus()); + apiUserService.update(apiUser); + model.setViewType("redirect"); + apiUserAuthorityService.clearApiUserAuthorityCache(apiUser.getId()); + model.setViewParam("location", "/apiUser/list"); + return model; + } - /** - * 手动修改api用户appkey值 - * - * @param model - * @return - */ - public Object updateAction(ApiUserModel model) { - Long userId = model.getUserId(); - Map dataApiUser = new HashMap(); - dataApiUser.put("email", model.getEmail()); - dataApiUser.put("siteName", model.getSiteName()); - dataApiUser.put("ip", model.getIp()); + /** + * 手动修改api用户appkey值 + * + * @param model + * @return + */ + public Object updateAction(ApiUserModel model) { + Long userId = model.getUserId(); + Map dataApiUser = new HashMap(); + dataApiUser.put("email", model.getEmail()); + dataApiUser.put("siteName", model.getSiteName()); + dataApiUser.put("ip", model.getIp()); dataApiUser.put("company", model.getCompany()); - dataApiUser.put("isTest", model.getIsTest()); - dataApiUser.put("purpose", model.getPurpose()); - dataApiUser.put("deadTime", model.getDeadTime()); - dataApiUser.put("manager", model.getManager()); - dataApiUser.put("isMonitor", model.getIsMonitor()); - this.apiUserService.update(dataApiUser, userId); + dataApiUser.put("isTest", model.getIsTest()); + dataApiUser.put("purpose", model.getPurpose()); + dataApiUser.put("deadTime", model.getDeadTime()); + dataApiUser.put("manager", model.getManager()); + dataApiUser.put("isMonitor", model.getIsMonitor()); + this.apiUserService.update(dataApiUser, userId); - //ApiUserCfg.ApiUserCfgKey.EVALUATE_RATE - modifyUserCfg(userId, ApiUserCfg.ApiUserCfgKey.EVALUATE_RATE, model.getEvaluateRate()); - modifyUserCfg(userId, ApiUserCfg.ApiUserCfgKey.PRICE_TYPE, model.getPriceType()); + //ApiUserCfg.ApiUserCfgKey.EVALUATE_RATE + modifyUserCfg(userId, ApiUserCfg.ApiUserCfgKey.EVALUATE_RATE, model.getEvaluateRate()); + modifyUserCfg(userId, ApiUserCfg.ApiUserCfgKey.PRICE_TYPE, model.getPriceType()); - model.setViewType("redirect"); - //model.setViewParam("location", "/apiUser/edit?msg=sucess&userId=" + model.getUserId()); - model.setViewParam("location", "/apiUser/list"); - return model; - } + model.setViewType("redirect"); + //model.setViewParam("location", "/apiUser/edit?msg=sucess&userId=" + model.getUserId()); + model.setViewParam("location", "/apiUser/list"); + return model; + } - void modifyUserCfg(Long userId, ApiUserCfg.ApiUserCfgKey cfgKey, Object val) { - if(userId != null && cfgKey != null){ - ApiUserCfg apiUserCfg = this.apiUserCfgService.findByUserId(userId, cfgKey); - if(val == null || StringUtils.isEmpty(val.toString())) { - if(null != apiUserCfg){ - apiUserCfgService.delete(apiUserCfg, cfgKey); - } - return; - } + void modifyUserCfg(Long userId, ApiUserCfg.ApiUserCfgKey cfgKey, Object val) { + if (userId != null && cfgKey != null) { + ApiUserCfg apiUserCfg = this.apiUserCfgService.findByUserId(userId, cfgKey); + if (val == null || StringUtils.isEmpty(val.toString())) { + if (null != apiUserCfg) { + apiUserCfgService.delete(apiUserCfg, cfgKey); + } + return; + } - if(cfgKey == ApiUserCfg.ApiUserCfgKey.EVALUATE_RATE) { - try{ - double rate = Double.parseDouble(val.toString()); - if(Double.compare(rate, 0) == 0){ - if(null != apiUserCfg){ - apiUserCfgService.delete(apiUserCfg, cfgKey); - return; - } - } - }catch(Exception e){ - e.printStackTrace(); - } - } + if (cfgKey == ApiUserCfg.ApiUserCfgKey.EVALUATE_RATE) { + try { + double rate = Double.parseDouble(val.toString()); + if (Double.compare(rate, 0) == 0) { + if (null != apiUserCfg) { + apiUserCfgService.delete(apiUserCfg, cfgKey); + return; + } + } + } catch (Exception e) { + e.printStackTrace(); + } + } - if(null == apiUserCfg){ - apiUserCfg = new ApiUserCfg(); - } - apiUserCfg.setUserId(userId); - apiUserCfg.setCreatedDate(new Date()); - apiUserCfg.setCfgValue(val); - apiUserCfgService.save(apiUserCfg, cfgKey); - } - } + if (null == apiUserCfg) { + apiUserCfg = new ApiUserCfg(); + } + apiUserCfg.setUserId(userId); + apiUserCfg.setCreatedDate(new Date()); + apiUserCfg.setCfgValue(val); + apiUserCfgService.save(apiUserCfg, cfgKey); + } + } - /** - * 重置appkey值,默认为userid md5加上useridmd5再md5, 64位 - * - * @param model - * @return - */ - public Object resetAction(ApiUserModel model) { - String appkey = DigestUtils.md5Hex(String.valueOf(model.getUserId())) - + DigestUtils.md5Hex(DigestUtils.md5Hex(String.valueOf(model.getUserId()))); + /** + * 重置appkey值,默认为userid md5加上useridmd5再md5, 64位 + * + * @param model + * @return + */ + public Object resetAction(ApiUserModel model) { + String appkey = DigestUtils.md5Hex(String.valueOf(model.getUserId())) + + DigestUtils.md5Hex(DigestUtils.md5Hex(String.valueOf(model.getUserId()))); - Map data = new HashMap(); - data.put("appKey", appkey.toUpperCase()); - this.apiUserService.update(data, model.getUserId()); - model.setViewType("redirect"); - model.setViewParam("location", "/apiUser/edit?userId=" + model.getUserId()); - return model; - } + Map data = new HashMap(); + data.put("appKey", appkey.toUpperCase()); + this.apiUserService.update(data, model.getUserId()); + model.setViewType("redirect"); + model.setViewParam("location", "/apiUser/edit?userId=" + model.getUserId()); + return model; + } - public Object checkUserNameAction(ApiUserModel model) { - model.setViewType("json"); - model.setViewParam("config", null); - User user = userService.findByUserName(model.getUserName()); - if (user != null) { - model.setMsg("此用户名已经存在!"); - return model; - } - return model; - } + public Object checkUserNameAction(ApiUserModel model) { + model.setViewType("json"); + model.setViewParam("config", null); + User user = userService.findByUserName(model.getUserName()); + if (user != null) { + model.setMsg("此用户名已经存在!"); + return model; + } + return model; + } - public Object loadConfigAction(@Param(name="uri") String uri, @Param(name="userId") long userId){ - JsonModel json = new JsonModel(); - ApiJsonViewConfig config = apiUserAuthorityService.findViewConfig(userId, uri); - json.setJsonModel(config); - return json; - } + public Object loadConfigAction(@Param(name = "uri") String uri, @Param(name = "userId") long userId) { + JsonModel json = new JsonModel(); + ApiJsonViewConfig config = apiUserAuthorityService.findViewConfig(userId, uri); + json.setJsonModel(config); + return json; + } - public Object saveConfigAction(ApiJsonViewConfig config,@Param(name="fields") String fields){ - if(StringUtils.isNotBlank(fields)){ - List availableFields = new ArrayList(); - for(String field : fields.split("\r\n")){ - field = DataUtil.trim(field); - if(StringUtils.isNotBlank(field)){ - availableFields.add(field); - } - } - config.setFields(availableFields); - } - apiUserAuthorityService.saveViewConfig(config); - return new JsonModel(); - } + public Object saveConfigAction(ApiJsonViewConfig config, @Param(name = "fields") String fields) { + if (StringUtils.isNotBlank(fields)) { + List availableFields = new ArrayList(); + for (String field : fields.split("\r\n")) { + field = DataUtil.trim(field); + if (StringUtils.isNotBlank(field)) { + availableFields.add(field); + } + } + config.setFields(availableFields); + } + apiUserAuthorityService.saveViewConfig(config); + return new JsonModel(); + } - public Object cityAction(ApiUserModel model) throws IllegalAccessException { - ApiUser apiUser = this.apiUserService.findApiUserById(model.getUserId()); - User user = this.userService.findById(apiUser.getId()); - ApiUserAuthority apiUserAuthority=apiUserAuthorityService.findByUserId(model.getUserId()); - Map cityCreditMap=apiUserAuthority.getCityCreditMap(); - model.setDisplayName(user.getDisplayName() == null ? "" : user.getDisplayName()); - model.setCityFirstLetters(Arrays.asList(getCityFirstLetter())); - List serverAreaList = serverAreaService.findAll();// Load城市列表 - if (StringUtils.isBlank(model.getType()) || "all".equals(model.getType())) {// 字母分组列表 - model.setServerAreaList(null); - } else { // 首字母查询 - List> serverAreaLetterList = new ArrayList>();// Load城市列表 - for (ServerArea serverArea : serverAreaList) { - if (serverArea.getSpell().substring(0, 1).toUpperCase().equals(model.getType())) { - Map map=new HashMap (); - if(null!=cityCreditMap && cityCreditMap.get(serverArea.getDisplay())!=null){ - map.put("key0",serverArea); - java.text.DecimalFormat df =new java.text.DecimalFormat("######0.00"); - String rate=df.format(cityCreditMap.get(serverArea.getDisplay())); - map.put("key1",rate); - }else { - map.put("key0",serverArea); - map.put("key1",null); - } - serverAreaLetterList.add(map); - } - } - model.setServerAreaList(serverAreaLetterList); - } + public Object cityAction(ApiUserModel model) throws IllegalAccessException { + ApiUser apiUser = this.apiUserService.findApiUserById(model.getUserId()); + User user = this.userService.findById(apiUser.getId()); + ApiUserAuthority apiUserAuthority = apiUserAuthorityService.findByUserId(model.getUserId()); + Map cityCreditMap = apiUserAuthority.getCityCreditMap(); + model.setDisplayName(user.getDisplayName() == null ? "" : user.getDisplayName()); + model.setCityFirstLetters(Arrays.asList(getCityFirstLetter())); + List serverAreaList = serverAreaService.findAll();// Load城市列表 + if (StringUtils.isBlank(model.getType()) || "all".equals(model.getType())) {// 字母分组列表 + model.setServerAreaList(null); + } else { // 首字母查询 + List> serverAreaLetterList = new ArrayList>();// Load城市列表 + for (ServerArea serverArea : serverAreaList) { + if (serverArea.getSpell().substring(0, 1).toUpperCase().equals(model.getType())) { + Map map = new HashMap(); + if (null != cityCreditMap && cityCreditMap.get(serverArea.getDisplay()) != null) { + map.put("key0", serverArea); + java.text.DecimalFormat df = new java.text.DecimalFormat("######0.00"); + String rate = df.format(cityCreditMap.get(serverArea.getDisplay())); + map.put("key1", rate); + } else { + map.put("key0", serverArea); + map.put("key1", null); + } + serverAreaLetterList.add(map); + } + } + model.setServerAreaList(serverAreaLetterList); + } - StringBuffer openCitys = new StringBuffer();// Load城市列表 - if (StringUtils.isBlank(apiUser.getCity())) { - } else if ("all".equals(apiUser.getCity())) { - openCitys.append("全部城市"); - } else { - int cnt = 0; - if(StringUtils.isNotBlank(apiUser.getCity()) && !apiUser.getCity().endsWith(",")){ - apiUser.setCity(apiUser.getCity() + ","); - } - for (ServerArea serverArea : serverAreaList) { - if (apiUser.getCity().indexOf(serverArea.getSpell() + ",") > -1) { - cnt++; - if (cnt == 1) { - openCitys.append(serverArea.getDisplay()); - } else { - openCitys.append(","); - openCitys.append(serverArea.getDisplay()); - } - } - } - openCitys.append(";
共" + cnt + "个城市"); - } - model.setOpenCitys(openCitys.toString()); - model.setCitys(apiUser.getCity()); - return model; - } + StringBuffer openCitys = new StringBuffer();// Load城市列表 + if (StringUtils.isBlank(apiUser.getCity())) { + } else if ("all".equals(apiUser.getCity())) { + openCitys.append("全部城市"); + } else { + int cnt = 0; + if (StringUtils.isNotBlank(apiUser.getCity()) && !apiUser.getCity().endsWith(",")) { + apiUser.setCity(apiUser.getCity() + ","); + } + for (ServerArea serverArea : serverAreaList) { + if (apiUser.getCity().indexOf(serverArea.getSpell() + ",") > -1) { + cnt++; + if (cnt == 1) { + openCitys.append(serverArea.getDisplay()); + } else { + openCitys.append(","); + openCitys.append(serverArea.getDisplay()); + } + } + } + openCitys.append(";
共" + cnt + "个城市"); + } + model.setOpenCitys(openCitys.toString()); + model.setCitys(apiUser.getCity()); + return model; + } - public Object citySaveAction(ApiUserModel model) throws IllegalAccessException { - model.setViewType("json"); - model.setViewParam("config", null); - List serverAreaList = serverAreaService.findAll(); - ApiUser apiUser = this.apiUserService.findApiUserById(model.getUserId()); - ApiUserAuthority apiUserAuthority=apiUserAuthorityService.findByUserId(model.getUserId()); - Map cityCreditMap=apiUserAuthority.getCityCreditMap(); - if(null==cityCreditMap){ - cityCreditMap=new HashMap(); - } - if (model.getCitys().equals("all")) { - apiUser.setCity("all"); - apiUser.setCreationDate(apiUser.getCreationDate() == null ? new Date() : apiUser.getCreationDate()); - this.apiUserService.update(apiUser); - } else if (model.getCitys().equals("disAll")) { - apiUser.setCity(null); - apiUser.setCreationDate(apiUser.getCreationDate() == null ? new Date() : apiUser.getCreationDate()); - this.apiUserService.update(apiUser); - } else { - String _check_citys = model.getCitys() == null ? "" : model.getCitys(); - String _un_check_citys = model.getUnCheckCitys() == null ? "" : model.getUnCheckCitys(); - String displayNames= model.getDisplayName() == null ? "" : model.getDisplayName(); - String credits=model.getCredits() == null ? "" : model.getCredits(); - String uncitys=model.getUncitys() == null ? "" : model.getUncitys(); - String[] uncity = StringUtils.split(uncitys,"|"); - for(int i=0;i serverAreaList = serverAreaService.findAll(); + ApiUser apiUser = this.apiUserService.findApiUserById(model.getUserId()); + ApiUserAuthority apiUserAuthority = apiUserAuthorityService.findByUserId(model.getUserId()); + Map cityCreditMap = apiUserAuthority.getCityCreditMap(); + if (null == cityCreditMap) { + cityCreditMap = new HashMap(); + } + if (model.getCitys().equals("all")) { + apiUser.setCity("all"); + apiUser.setCreationDate(apiUser.getCreationDate() == null ? new Date() : apiUser.getCreationDate()); + this.apiUserService.update(apiUser); + } else if (model.getCitys().equals("disAll")) { + apiUser.setCity(null); + apiUser.setCreationDate(apiUser.getCreationDate() == null ? new Date() : apiUser.getCreationDate()); + this.apiUserService.update(apiUser); + } else { + String _check_citys = model.getCitys() == null ? "" : model.getCitys(); + String _un_check_citys = model.getUnCheckCitys() == null ? "" : model.getUnCheckCitys(); + String displayNames = model.getDisplayName() == null ? "" : model.getDisplayName(); + String credits = model.getCredits() == null ? "" : model.getCredits(); + String uncitys = model.getUncitys() == null ? "" : model.getUncitys(); + String[] uncity = StringUtils.split(uncitys, "|"); + for (int i = 0; i < uncity.length; i++) { + if (cityCreditMap.containsKey(uncity[i])) { + cityCreditMap.remove(uncity[i]); + } + } + if (StringUtils.isNotBlank(displayNames)) { + String[] display = StringUtils.split(displayNames, "|"); + String[] cre = StringUtils.split(credits, "|"); + for (int k = 0; k < display.length; k++) { + if (cre[k].equals("null")) { + cityCreditMap.remove(display[k]); + } else { + cityCreditMap.put(display[k], Double.parseDouble(cre[k])); + } + } + } + apiUserAuthority.setCityCreditMap(cityCreditMap); - String[] newCitys = StringUtils.split(_check_citys, ","); - for (String city : newCitys) { - if (citys.indexOf("," + city + ",") == -1) { - citys = citys + city + ","; - } - } - String[] delCitys = StringUtils.split(_un_check_citys, ","); - for (String city : delCitys) { - if (citys.indexOf("," + city + ",") > -1) { - citys = citys.replace(city + ",", ""); - } - } - citys = citys.replaceAll("^,","").replaceAll(",$",""); - apiUser.setCity(citys); - } - apiUser.setCreationDate(apiUser.getCreationDate() == null ? new Date() : apiUser.getCreationDate()); - this.apiUserService.update(apiUser); - - apiUserAuthorityService.update(apiUserAuthority); - } - return model; - } + if (StringUtils.isBlank(apiUser.getCity())) { + apiUser.setCity(model.getCitys()); + } else if (apiUser.getCity().equals("all")) { + StringBuffer citys = new StringBuffer(); + int _all = 0; + for (ServerArea serverArea : serverAreaList) { + if (_un_check_citys.indexOf(serverArea.getSpell()) == -1) { + _all++; + if (_all == 1) { + citys.append(serverArea.getSpell()); + } else { + citys.append(","); + citys.append(serverArea.getSpell()); + } + } + } + apiUser.setCity(citys.toString()); + } else { + String citys = apiUser.getCity(); + if (StringUtils.isBlank(citys)) { + citys = ","; + } else { + if (!citys.endsWith(",")) { + citys += ","; + } + if (!citys.startsWith(",")) { + citys = "," + citys; + } + } - /** - * 所有api用户的信息展示 - * - * @param model - * @return - */ - public Object authAction(ApiUserModel model) throws IllegalAccessException { - /** - * OpenResource open中公开出的接口资源 User 本地user ApiUserAuthority 用户的权限信息 - * - * @param ApiUser - * :用户的资料信息 - * @param AuthorityBo - * :用户的appKey username、等资料 - */ - List openResourceList = openResourceService.findAll(); - List authorityBoList = new ArrayList(); - ApiUserAuthority authority = apiUserAuthorityService.findByUserId(model.getUserId()); - if(authority == null){ - authority = new ApiUserAuthority(); - authority.setOpenResourseUris(new ArrayList()); - apiUserAuthorityService.save(authority); - } - User user = this.userService.findById(model.getUserId()); - model.setDisplayName(user.getDisplayName() == null ? "" : user.getDisplayName()); - Map urisMap = authority.getOpenResourseUrisMap(); - for (OpenResource openResource : openResourceList) { - AuthorityBo bo = new AuthorityBo(); - BeanUtils.copyProperties(openResource, bo); - if (authority != null) { - bo.setHasAuth(authority.getOpenResourseUris().contains(bo.getUri())); - model.setSupportLatLng(authority.isSupportLatLng()); - bo.setLimitCountMap(authority.getLimitCountMap()); - bo.setTotalCountMap(authority.getTotalCountMap()); - bo.setIsCheckCount(urisMap==null?0:(urisMap.get(bo.getUri())==null?0:urisMap.get(bo.getUri()))); - } - //apiVisitCountService.findApiVisitAllCount(user.getUserId(), null); - if(bo.isHasAuth()){ - long curVistedCount = apiVisitCountService.findApiVisitCountByDay(model.getUserId(), openResource.getUri(), DateUtil.truncateDay(new Date())); - long total = apiVisitCountService.findApiVisitAllCount(model.getUserId(), openResource.getUri(), DateUtil.truncateDay(new Date())); - bo.setCurVisitedCount(curVistedCount); - bo.setTotalVisitedCount(total); - } - - authorityBoList.add(bo); - } - model.setAuthority(authority); - model.setAuthorityBoList(authorityBoList); - return model; - } + String[] newCitys = StringUtils.split(_check_citys, ","); + for (String city : newCitys) { + if (citys.indexOf("," + city + ",") == -1) { + citys = citys + city + ","; + } + } + String[] delCitys = StringUtils.split(_un_check_citys, ","); + for (String city : delCitys) { + if (citys.indexOf("," + city + ",") > -1) { + citys = citys.replace(city + ",", ""); + } + } + citys = citys.replaceAll("^,", "").replaceAll(",$", ""); + apiUser.setCity(citys); + } + apiUser.setCreationDate(apiUser.getCreationDate() == null ? new Date() : apiUser.getCreationDate()); + this.apiUserService.update(apiUser); - public Object openuriAction(ApiUserModel model){ - List authorityBoList = new ArrayList(); - List openResourceList = openResourceService.findAll(); - String userId=model.getUserId().toString(); - for(OpenResource openResource:openResourceList){ - String uri=openResource.getUri(); - AuthorityBo bo = new AuthorityBo(); - BeanUtils.copyProperties(openResource, bo); - OpenResourceCount open= openResourceCountService.findByUserId(userId, uri); - Long count=0L; - if(open!=null && open.getCount()!=null){ - count=open.getCount(); - } - bo.setCount(count); - authorityBoList.add(bo); - } - Collections.sort(authorityBoList, new Comparator() { + apiUserAuthorityService.update(apiUserAuthority); + } + return model; + } + + /** + * 所有api用户的信息展示 + * + * @param model + * @return + */ + public Object authAction(ApiUserModel model) throws IllegalAccessException { + /** + * OpenResource open中公开出的接口资源 User 本地user ApiUserAuthority 用户的权限信息 + * + * @param ApiUser + * :用户的资料信息 + * @param AuthorityBo + * :用户的appKey username、等资料 + */ + List openResourceList = openResourceService.findAll(); + List authorityBoList = new ArrayList(); + ApiUserAuthority authority = apiUserAuthorityService.findByUserId(model.getUserId()); + if (authority == null) { + authority = new ApiUserAuthority(); + authority.setOpenResourseUris(new ArrayList()); + apiUserAuthorityService.save(authority); + } + User user = this.userService.findById(model.getUserId()); + model.setDisplayName(user.getDisplayName() == null ? "" : user.getDisplayName()); + Map urisMap = authority.getOpenResourseUrisMap(); + + // 用户有的uri + String flag = model.getMsg(); + List userResources = new ArrayList(); + + if ("0".equals(flag)) { + for (OpenResource openResource : openResourceList) { + if (!authority.getOpenResourseUris().contains(openResource.getUri())) { + userResources.add(openResource); + } + } + } else { + for (OpenResource openResource : openResourceList) { + if (authority.getOpenResourseUris().contains(openResource.getUri())) { + userResources.add(openResource); + } + } + } + + // 改成遍历用户有的uri + for (OpenResource openResource : userResources) { + AuthorityBo bo = new AuthorityBo(); + BeanUtils.copyProperties(openResource, bo); + if (authority != null) { + bo.setHasAuth(authority.getOpenResourseUris().contains(bo.getUri())); + bo.setHasAuth(authority.getOpenResourseUris().contains(bo.getUri())); + model.setSupportLatLng(authority.isSupportLatLng()); + bo.setLimitCountMap(authority.getLimitCountMap()); + bo.setTotalCountMap(authority.getTotalCountMap()); + bo.setIsCheckCount(urisMap == null ? 0 : (urisMap.get(bo.getUri()) == null ? 0 : urisMap.get(bo.getUri()))); + } + //apiVisitCountService.findApiVisitAllCount(user.getUserId(), null); + if (bo.isHasAuth()) { + long curVistedCount = apiVisitCountService.findApiVisitCountByDay(model.getUserId(), openResource.getUri(), DateUtil.truncateDay(new Date())); + long total = apiVisitCountService.findApiVisitAllCount(model.getUserId(), openResource.getUri(), DateUtil.truncateDay(new Date())); + bo.setCurVisitedCount(curVistedCount); + bo.setTotalVisitedCount(total); + } + + authorityBoList.add(bo); + } + model.setAuthority(authority); + model.setAuthorityBoList(authorityBoList); + return model; + } + + public Object openuriAction(ApiUserModel model) { + List authorityBoList = new ArrayList(); + List openResourceList = openResourceService.findAll(); + String userId = model.getUserId().toString(); + for (OpenResource openResource : openResourceList) { + String uri = openResource.getUri(); + AuthorityBo bo = new AuthorityBo(); + BeanUtils.copyProperties(openResource, bo); + OpenResourceCount open = openResourceCountService.findByUserId(userId, uri); + Long count = 0L; + if (open != null && open.getCount() != null) { + count = open.getCount(); + } + bo.setCount(count); + authorityBoList.add(bo); + } + Collections.sort(authorityBoList, new Comparator() { @Override public int compare(AuthorityBo o1, AuthorityBo o2) { if (o1.getCount() > o2.getCount()) { @@ -605,9 +628,9 @@ public class ApiUserController { } }); - model.setAuthorityBoList(authorityBoList); - return model; - } + model.setAuthorityBoList(authorityBoList); + return model; + } public Object saveAuthAction(ApiUserModel model, HttpServletRequest request) throws IllegalAccessException { @@ -640,13 +663,13 @@ public class ApiUserController { totalCountMap.put(model.getUri(), model.getSum()); authority.setTotalCountMap(totalCountMap); } - if(model.getIsCheckCount() !=null) { - Map urisMap = authority.getOpenResourseUrisMap(); - if(urisMap==null) { - urisMap = new HashMap(); - } - urisMap.put(model.getUri(), model.getIsCheckCount()); - authority.setOpenResourseUrisMap(urisMap); + if (model.getIsCheckCount() != null) { + Map urisMap = authority.getOpenResourseUrisMap(); + if (urisMap == null) { + urisMap = new HashMap(); + } + urisMap.put(model.getUri(), model.getIsCheckCount()); + authority.setOpenResourseUrisMap(urisMap); } if (model.isHasAuth() && !authority.getOpenResourseUris().contains(model.getUri())) { authority.getOpenResourseUris().add(model.getUri()); @@ -675,17 +698,17 @@ public class ApiUserController { List openResourceList = openResourceService.findAll(); boolean save = false; - if (authority == null) { + if (authority == null) { save = true; authority = new ApiUserAuthority(); } authority.setUserId(userId); authority.setSupportLatLng(model.isSupportLatLng()); - Map limit = string2map(model.getLimitCountMap()); - Map total = string2map(model.getTotalCountMap()); - Map uriMap = string2map(model.getOpenResourseUrisMap()); - authority.setLimitCountMap(limit); - authority.setTotalCountMap(total); + Map limit = string2map(model.getLimitCountMap()); + Map total = string2map(model.getTotalCountMap()); + Map uriMap = string2map(model.getOpenResourseUrisMap()); + authority.setLimitCountMap(limit); + authority.setTotalCountMap(total); List uris = new ArrayList(); for (OpenResource openResource : openResourceList) { if (model.getUri().indexOf(openResource.getUri()) > -1) { @@ -693,13 +716,13 @@ public class ApiUserController { } } authority.setOpenResourseUris(uris); - Map openResourseUrisMap = authority.getOpenResourseUrisMap(); - if(null!=uriMap&&!uriMap.isEmpty()) { - for(String url : uriMap.keySet()) { - openResourseUrisMap.put(url, uriMap.get(url)); + Map openResourseUrisMap = authority.getOpenResourseUrisMap(); + if (null != uriMap && !uriMap.isEmpty()) { + for (String url : uriMap.keySet()) { + openResourseUrisMap.put(url, uriMap.get(url)); } } - + if (save) { apiUserAuthorityService.update(authority); } else { @@ -708,1002 +731,1002 @@ public class ApiUserController { return model; } - public Object clickStatAction(ApiUserModel model) { - return model; - } - - public Object pandectAction(ApiUserModel model) throws Throwable{ - Date startDate = null; - Date endDate = null; - - if(model.getWay()==null){ - model.setWay(0); - } - if(StringUtils.isNotBlank(model.getQuery())){ - - startDate = DateUtil.add(DateUtil.formatToYYYYMMDD(new Date()), Integer.parseInt(model.getQuery())); - endDate = DateUtil.parseStringToDate(DateUtil.formatToYYYYMMDD(new Date())); - } - - if(StringUtils.isNotBlank(model.getBegDate())){ - startDate = DateUtil.parseStringToDate(model.getBegDate()); - } - if(StringUtils.isNotBlank(model.getEndDate())){ - endDate = DateUtil.parseStringToDate(model.getEndDate()); - } - - - if(startDate == null && endDate==null){ - startDate = DateUtil.add(DateUtil.formatToYYYYMMDD(new Date()), -8); - endDate = DateUtil.parseStringToDate(DateUtil.formatToYYYYMMDD(new Date())); - model.setQuery("-8"); - } - - - List analys = openUriAnalyService.findOpenUriAnalyLogs(model.getUserId(), null, startDate, endDate); - - if(startDate!= null && endDate!=null && startDate!=endDate && !model.getQuery().equals("-1")){ - Map map = new HashMap(); - List list = new ArrayList(); - for(OpenUriAnaly bo : analys){ - Integer count = (Integer) map.get(DateUtil.formatToYYYYMMDD(bo.getStatDate())); - if(count == null){ - if(!list.contains(bo.getStatDate())){ - list.add(bo.getStatDate()); - } - map.put(DateUtil.formatToYYYYMMDD(bo.getStatDate()), bo.getUrlClickCount()); - }else{ - map.put(DateUtil.formatToYYYYMMDD(bo.getStatDate()), count + bo.getUrlClickCount()); - } - - } - - Collections.sort(list); - if(model.getQuery().equals("-14")){ - List> ret = new ArrayList>(); - String d1 = DateUtil.formatToYYYYMMDD(startDate); - List times = null; - String d2 = DateUtil.formatToYYYYMMDD(endDate); - while(!d1.equals(d2)){ - if(ret.size()==0 ||times.size()==7){ - times = new ArrayList(); - ret.add(times); - } - times.add(d1); - d1 = DateUtil.formatToYYYYMMDD(DateUtil.add(DateUtil.parseStringToDate(d1), 1)); - } - List dates = ret.get(0); - List weeks = new ArrayList(); - for(String date : dates){ - String day = DateUtil.getWeekOfDate(date, new SimpleDateFormat("yyyy-MM-dd")); - weeks.add(day); - } - model.setxAxis(toXAxis2(weeks)); - model.setChartSeries(toSeries2(map, ret)); - - }else{ - model.setxAxis(toXAxis(list)); - model.setChartSeries(toSeries(map, list)); - } + public Object clickStatAction(ApiUserModel model) { + return model; + } - }else{ - int totalCount = 0; - for(OpenUriAnaly bo : analys){ - totalCount = totalCount + bo.getUrlClickCount(); - } - model.setTotalCount(totalCount); - } - - return model; - } - - private String toSeries(Map map, List list){ - String s = ""; - for(int i=0;i map, List> dates){ - String s = ""; - for(int k=0; k dateList = dates.get(k); - String temp = ""; - for(int i=0;i bos, List list){ - JSONArray ja = new JSONArray(); - for(Date temp : list){ - String tempStr = DateUtil.formatToYYYYMMDD(temp); - for(StatAnalyBo bo : bos){ - String dateStr = bo.getKey(); - if(dateStr.equals(tempStr)){ - ja.put(bo.getCount()); - break; - } - } - - } - return ja.toString(); - } - - - private String toXAxis(List list){ - String categories = ""; - for(int i=0;i list){ - String categories = ""; - for(int i=0;i cities; - if(StringUtils.isNotBlank(citys)){ - cities = Arrays.asList(StringUtils.split(citys,"|")); - }else{ - cities = new ArrayList(); - } - List analys = openUriAnalyService.findOpenUriAnalyLogs(model.getUserId(), null, startDate, endDate); - List bos = null; - List eachCityBos=null; - if(model.getWay() == null){ - model.setWay(1); - } + if (model.getWay() == null) { + model.setWay(0); + } + if (StringUtils.isNotBlank(model.getQuery())) { - if(model.getWay()==1){ - bos = createAnalyBosByUser(analys); - }else if(model.getWay() == 2){ - bos = createAnalyBosByLink(analys); - }else if(model.getWay() == 3){ - if(cities.size()!=0) { - List apiCountCities = apiCountCityService.findApiCountCity(cities, startDate, endDate); - eachCityBos = getEachCityBos(apiCountCities); - } - bos = createAnalyBosByLink(analys); - } - if(model.getWay()==1){ - long date = DateUtil.parseStringToDate("2016-11-23").getTime(); - if(startDate.getTime()>=date && endDate.getTime()>date){ - List apiInvokeStatisticalList = apiInvokeStatisticalService.findApiInvokeStatisticalList(model.getUserId(), startDate, endDate); - if(bos!=null){ - for (StatAnalyBo boTemp : bos) { - Integer userId = boTemp.getUserId(); - Integer successEffectiveTime=0; - Integer successInvalidTime=0; - Integer defeatTime=0; - for (ApiInvokeStatistical apiInvokeStatistical : apiInvokeStatisticalList) { - if(apiInvokeStatistical.getUserId().equals(userId.toString())){ - successEffectiveTime=successEffectiveTime+apiInvokeStatistical.getSuccessEffectiveTime(); - successInvalidTime=successInvalidTime+apiInvokeStatistical.getSuccessInvalidTime(); - defeatTime=defeatTime+apiInvokeStatistical.getDefeatTime(); - } - } - boTemp.setSuccessEffectiveTime(successEffectiveTime); - boTemp.setSuccessInvalidTime(successInvalidTime); - boTemp.setDefeatTime(defeatTime); - } - } - } - List userIds = new ArrayList(); - for (StatAnalyBo boTemp : bos) { - userIds.add(Long.valueOf(boTemp.getUserId())); - List apiVisitCounts = apiVisitCountService.findAllApiVisitCount(Long.valueOf(boTemp.getUserId()), null, startDate, endDate); - int total = 0; - for(ApiVisitCount apiVisitCount : apiVisitCounts){ - total += apiVisitCount.getVisitCount(); - } - boTemp.setBillingCount(total); - } + startDate = DateUtil.add(DateUtil.formatToYYYYMMDD(new Date()), Integer.parseInt(model.getQuery())); + endDate = DateUtil.parseStringToDate(DateUtil.formatToYYYYMMDD(new Date())); + } + + if (StringUtils.isNotBlank(model.getBegDate())) { + startDate = DateUtil.parseStringToDate(model.getBegDate()); + } + if (StringUtils.isNotBlank(model.getEndDate())) { + endDate = DateUtil.parseStringToDate(model.getEndDate()); + } + + + if (startDate == null && endDate == null) { + startDate = DateUtil.add(DateUtil.formatToYYYYMMDD(new Date()), -8); + endDate = DateUtil.parseStringToDate(DateUtil.formatToYYYYMMDD(new Date())); + model.setQuery("-8"); + } + + + List analys = openUriAnalyService.findOpenUriAnalyLogs(model.getUserId(), null, startDate, endDate); + + if (startDate != null && endDate != null && startDate != endDate && !model.getQuery().equals("-1")) { + Map map = new HashMap(); + List list = new ArrayList(); + for (OpenUriAnaly bo : analys) { + Integer count = (Integer) map.get(DateUtil.formatToYYYYMMDD(bo.getStatDate())); + if (count == null) { + if (!list.contains(bo.getStatDate())) { + list.add(bo.getStatDate()); + } + map.put(DateUtil.formatToYYYYMMDD(bo.getStatDate()), bo.getUrlClickCount()); + } else { + map.put(DateUtil.formatToYYYYMMDD(bo.getStatDate()), count + bo.getUrlClickCount()); + } + + } + + Collections.sort(list); + if (model.getQuery().equals("-14")) { + List> ret = new ArrayList>(); + String d1 = DateUtil.formatToYYYYMMDD(startDate); + List times = null; + String d2 = DateUtil.formatToYYYYMMDD(endDate); + while (!d1.equals(d2)) { + if (ret.size() == 0 || times.size() == 7) { + times = new ArrayList(); + ret.add(times); + } + times.add(d1); + d1 = DateUtil.formatToYYYYMMDD(DateUtil.add(DateUtil.parseStringToDate(d1), 1)); + } + List dates = ret.get(0); + List weeks = new ArrayList(); + for (String date : dates) { + String day = DateUtil.getWeekOfDate(date, new SimpleDateFormat("yyyy-MM-dd")); + weeks.add(day); + } + model.setxAxis(toXAxis2(weeks)); + model.setChartSeries(toSeries2(map, ret)); + + } else { + model.setxAxis(toXAxis(list)); + model.setChartSeries(toSeries(map, list)); + } + + } else { + int totalCount = 0; + for (OpenUriAnaly bo : analys) { + totalCount = totalCount + bo.getUrlClickCount(); + } + model.setTotalCount(totalCount); + } + + return model; + } + + private String toSeries(Map map, List list) { + String s = ""; + for (int i = 0; i < list.size(); i++) { + Date date = list.get(i); + int count = (Integer) map.get(DateUtil.formatToYYYYMMDD(date)); + if (i + 1 == list.size()) { + s = s + String.valueOf(count); + } else { + s = s + String.valueOf(count) + ","; + } + } + + return "{name:'访问量',data:[" + s + "]}"; + } + + private String toSeries2(Map map, List> dates) { + String s = ""; + for (int k = 0; k < dates.size(); k++) { + List dateList = dates.get(k); + String temp = ""; + for (int i = 0; i < dateList.size(); i++) { + String date = dateList.get(i); + int count = (Integer) map.get(date); + + if (i + 1 == dateList.size()) { + String name = "上周"; + if (k == 1) { + name = "最近7天"; + } + temp = "{name:'" + name + "',data:[" + temp + String.valueOf(count) + "]}"; + } else { + temp = temp + String.valueOf(count) + ","; + } + } + if (k == 1) { + s = s + "," + temp; + } else { + s = temp; + } + + } + + return s; + } + + private String toSeries(List bos, List list) { + JSONArray ja = new JSONArray(); + for (Date temp : list) { + String tempStr = DateUtil.formatToYYYYMMDD(temp); + for (StatAnalyBo bo : bos) { + String dateStr = bo.getKey(); + if (dateStr.equals(tempStr)) { + ja.put(bo.getCount()); + break; + } + } + + } + return ja.toString(); + } + + + private String toXAxis(List list) { + String categories = ""; + for (int i = 0; i < list.size(); i++) { + Date date = list.get(i); + //ja.put(DateUtil.formatToYYYYMMDD(date)); + if (i + 1 == list.size()) { + categories = categories + "'" + DateUtil.formatToYYYYMMDD(date) + "'"; + } else { + categories = categories + "'" + DateUtil.formatToYYYYMMDD(date) + "',"; + } + } + + return categories; + } + + private String toXAxis2(List list) { + String categories = ""; + for (int i = 0; i < list.size(); i++) { + String value = list.get(i); + //ja.put(DateUtil.formatToYYYYMMDD(date)); + if (i + 1 == list.size()) { + categories = categories + "'" + value + "'"; + } else { + categories = categories + "'" + value + "',"; + } + } + + return categories; + } + + public Object apiVisitStatAction(ApiUserModel model) { + Date startDate = null; + Date endDate = null; + if (StringUtils.isBlank(model.getBegDate()) && StringUtils.isBlank(model.getEndDate())) { + startDate = DateUtil.add(DateUtil.formatToYYYYMMDD(new Date()), -7); + endDate = DateUtil.parseStringToDate(DateUtil.formatToYYYYMMDD(new Date())); + } else { + if (StringUtils.isNotBlank(model.getBegDate())) { + startDate = DateUtil.parseStringToDate(model.getBegDate()); + } + if (StringUtils.isNotBlank(model.getEndDate())) { + endDate = DateUtil.parseStringToDate(model.getEndDate()); + } + + } + if (startDate != null) { + model.setBegDate(DateUtil.formatToYYYYMMDD(startDate)); + } + + if (endDate != null) { + model.setEndDate(DateUtil.formatToYYYYMMDD(endDate)); + } + + String citys = model.getCitys(); + List cities; + if (StringUtils.isNotBlank(citys)) { + cities = Arrays.asList(StringUtils.split(citys, "|")); + } else { + cities = new ArrayList(); + } + List analys = openUriAnalyService.findOpenUriAnalyLogs(model.getUserId(), null, startDate, endDate); + List bos = null; + List eachCityBos = null; + if (model.getWay() == null) { + model.setWay(1); + } + + if (model.getWay() == 1) { + bos = createAnalyBosByUser(analys); + } else if (model.getWay() == 2) { + bos = createAnalyBosByLink(analys); + } else if (model.getWay() == 3) { + if (cities.size() != 0) { + List apiCountCities = apiCountCityService.findApiCountCity(cities, startDate, endDate); + eachCityBos = getEachCityBos(apiCountCities); + } + bos = createAnalyBosByLink(analys); + } + if (model.getWay() == 1) { + long date = DateUtil.parseStringToDate("2016-11-23").getTime(); + if (startDate.getTime() >= date && endDate.getTime() > date) { + List apiInvokeStatisticalList = apiInvokeStatisticalService.findApiInvokeStatisticalList(model.getUserId(), startDate, endDate); + if (bos != null) { + for (StatAnalyBo boTemp : bos) { + Integer userId = boTemp.getUserId(); + Integer successEffectiveTime = 0; + Integer successInvalidTime = 0; + Integer defeatTime = 0; + for (ApiInvokeStatistical apiInvokeStatistical : apiInvokeStatisticalList) { + if (apiInvokeStatistical.getUserId().equals(userId.toString())) { + successEffectiveTime = successEffectiveTime + apiInvokeStatistical.getSuccessEffectiveTime(); + successInvalidTime = successInvalidTime + apiInvokeStatistical.getSuccessInvalidTime(); + defeatTime = defeatTime + apiInvokeStatistical.getDefeatTime(); + } + } + boTemp.setSuccessEffectiveTime(successEffectiveTime); + boTemp.setSuccessInvalidTime(successInvalidTime); + boTemp.setDefeatTime(defeatTime); + } + } + } + List userIds = new ArrayList(); + for (StatAnalyBo boTemp : bos) { + userIds.add(Long.valueOf(boTemp.getUserId())); + List apiVisitCounts = apiVisitCountService.findAllApiVisitCount(Long.valueOf(boTemp.getUserId()), null, startDate, endDate); + int total = 0; + for (ApiVisitCount apiVisitCount : apiVisitCounts) { + total += apiVisitCount.getVisitCount(); + } + boTemp.setBillingCount(total); + } + + List apiUsers = apiUserService.findApiUserByIds(userIds); + Map idUserMap = new HashMap(); + for (ApiUser apiUser : apiUsers) { + idUserMap.put(apiUser.getId(), apiUser); + } + for (StatAnalyBo boTemp : bos) { + ApiUser apiUser = idUserMap.get(Long.valueOf(boTemp.getUserId())); + if (apiUser != null) { + boTemp.setPurpose(apiUser.getPurpose()); + } + } + } + if (model.getWay() != 3) { + model.setStatAnalyBoList(sortStatAnaly(bos)); + model.setChartSeries(toChartString(bos)); + } else { + model.setChartSeries(toChartString(bos)); + model.setEachCityBoList(eachCityBos); + } + List resources = openResourceService.findOpenResource(null); + model.setResourceMap(converMapData(resources)); + return model; + } + + + public Object userVisitStatAction(ApiUserModel model) { + Date startDate = null; + Date endDate = null; + if (StringUtils.isNotBlank(model.getBegDate())) { + startDate = DateUtil.parseStringToDate(model.getBegDate()); + } + if (StringUtils.isNotBlank(model.getEndDate())) { + endDate = DateUtil.parseStringToDate(model.getEndDate()); + } + + List analys = openUriAnalyService.findOpenUriAnalyLogs(model.getUserId(), model.getUri(), startDate, endDate); + List bos = null; + + if (StringUtils.isBlank(model.getQuery()) && model.getWay() == 2) { + model.setQuery("uri"); + } else if (StringUtils.isBlank(model.getQuery()) && model.getWay() == 1) { + model.setQuery("user"); + } - List apiUsers = apiUserService.findApiUserByIds(userIds); - Map idUserMap = new HashMap(); - for(ApiUser apiUser : apiUsers){ - idUserMap.put(apiUser.getId(), apiUser); - } - for (StatAnalyBo boTemp : bos) { - ApiUser apiUser = idUserMap.get(Long.valueOf(boTemp.getUserId())); - if(apiUser != null){ - boTemp.setPurpose(apiUser.getPurpose()); - } - } - } - if(model.getWay()!=3) { - model.setStatAnalyBoList(sortStatAnaly(bos)); - model.setChartSeries(toChartString(bos)); - } - else { - model.setChartSeries(toChartString(bos)); - model.setEachCityBoList(eachCityBos); - } - List resources = openResourceService.findOpenResource(null); - model.setResourceMap(converMapData(resources)); - return model; - } - - - public Object userVisitStatAction(ApiUserModel model){ - Date startDate = null; - Date endDate = null; - if(StringUtils.isNotBlank(model.getBegDate())){ - startDate = DateUtil.parseStringToDate(model.getBegDate()); - } - if(StringUtils.isNotBlank(model.getEndDate())){ - endDate = DateUtil.parseStringToDate(model.getEndDate()); - } - - List analys = openUriAnalyService.findOpenUriAnalyLogs(model.getUserId(), model.getUri(), startDate, endDate); - List bos = null; - - if(StringUtils.isBlank(model.getQuery())&&model.getWay()==2){ - model.setQuery("uri"); - }else if(StringUtils.isBlank(model.getQuery())&&model.getWay()==1){ - model.setQuery("user"); - } - // if(model.getWay()==1){ // bos = createAnalyBosByUser(analys); // model.setChartSeries(toChartString(bos)); // }else if(model.getWay() == 2){ - if(model.getWay() == 2){ - User user = userService.findById(model.getUserId()); - if(user!=null){ - model.setUserName(user.getDisplayName()); - } - } - - if(model.getQuery().equals("uri")){ - bos = createAnalyBosByLink(analys); - model.setChartSeries(toChartString(bos)); - }if(model.getQuery().equals("day")){ - bos = createAnalyByCity(analys, "day"); - - List list = new ArrayList(); - - for(OpenUriAnaly bo : analys){ - if(!list.contains(bo.getStatDate())){ - list.add(bo.getStatDate()); - } - } - Collections.sort(list); - model.setxAxis(toXAxis(list)); - model.setChartSeries(toSeries(bos, list)); - - }else if(model.getQuery().equals("time")){ - bos = createAnalyByCity(analys, "time"); - model.setChartSeries(toChartString(bos)); - }else if(model.getQuery().equals("user")){ - bos = createAnalyBosByUser(analys); - model.setChartSeries(toChartString(bos)); - } - + if (model.getWay() == 2) { + User user = userService.findById(model.getUserId()); + if (user != null) { + model.setUserName(user.getDisplayName()); + } + } + + if (model.getQuery().equals("uri")) { + bos = createAnalyBosByLink(analys); + model.setChartSeries(toChartString(bos)); + } + if (model.getQuery().equals("day")) { + bos = createAnalyByCity(analys, "day"); + + List list = new ArrayList(); + + for (OpenUriAnaly bo : analys) { + if (!list.contains(bo.getStatDate())) { + list.add(bo.getStatDate()); + } + } + Collections.sort(list); + model.setxAxis(toXAxis(list)); + model.setChartSeries(toSeries(bos, list)); + + } else if (model.getQuery().equals("time")) { + bos = createAnalyByCity(analys, "time"); + model.setChartSeries(toChartString(bos)); + } else if (model.getQuery().equals("user")) { + bos = createAnalyBosByUser(analys); + model.setChartSeries(toChartString(bos)); + } + // } - - long date = DateUtil.parseStringToDate("2016-11-23").getTime(); - if("uri".equals(model.getQuery()) && startDate.getTime()>=date && endDate.getTime()>date){ - List apiInvokeStatisticalList = apiInvokeStatisticalService.findApiInvokeStatisticalList(model.getUserId(), startDate, endDate); - if(bos!=null && apiInvokeStatisticalList.size()>0){ - Map> resultMap = getCountByUri(apiInvokeStatisticalList); - for (StatAnalyBo boTemp : bos) { - String url = boTemp.getKey(); - boTemp.setSuccessEffectiveTime(resultMap.get(url).get("successEffectiveCount")); - boTemp.setSuccessInvalidTime(resultMap.get(url).get("successInvalidCount")); - boTemp.setDefeatTime(resultMap.get(url).get("defeatCount")); - } - } - } - for (StatAnalyBo boTemp : bos) { - List apiVisitCounts = apiVisitCountService.findAllApiVisitCount(model.getUserId(), boTemp.getKey(), startDate, endDate); - int total = 0; - for(ApiVisitCount apiVisitCount : apiVisitCounts){ - total += apiVisitCount.getVisitCount(); - } - boTemp.setBillingCount(total); - } - - List resources = openResourceService.findOpenResource(null); - model.setResourceMap(converMapData(resources)); - model.setStatAnalyBoList(sortStatAnaly(bos)); - - return model; - } - - public Object detailVisitStatAction(ApiUserModel model){ - Date startDate = null; - Date endDate = null; - if(StringUtils.isNotBlank(model.getBegDate())){ - startDate = DateUtil.parseStringToDate(model.getBegDate()); - } - if(StringUtils.isNotBlank(model.getEndDate())){ - endDate = DateUtil.parseStringToDate(model.getEndDate()); - } - - - List analys = openUriAnalyService.findOpenUriAnalyLogs(model.getUserId(), model.getUri(), startDate, endDate); - if(StringUtils.isBlank(model.getQuery())){ - model.setQuery("city"); - } - - List bos = null; - if(model.getQuery().equals("city")){ - bos = createAnalyByCity(analys, "city"); - }else if(model.getQuery().equals("time")){ - bos = createAnalyByCity(analys, "time"); - } - - model.setStatAnalyBoList(sortStatAnaly(bos)); - model.setChartSeries(toChartString(bos)); - - User user = userService.findById(model.getUserId()); - if(user!=null){ - model.setUserName(user.getDisplayName()); - }else{ - model.setUserName(model.getUserId().toString()); - } - return model; - } - public Object importExcelAction(HttpServletRequest request,ApiUserModel model){ - String citys=request.getParameter("city"); - String begDate=request.getParameter("begDate"); - String enDate=request.getParameter("endDate"); - Date startDate = null; - Date endDate = null; - if(StringUtils.isBlank(begDate) && StringUtils.isBlank(enDate)){ - startDate = DateUtil.add(DateUtil.formatToYYYYMMDD(new Date()), -7); - endDate = DateUtil.parseStringToDate(DateUtil.formatToYYYYMMDD(new Date())); - }else{ - if(StringUtils.isNotBlank(begDate)){ - startDate = DateUtil.parseStringToDate(begDate); - } - if(StringUtils.isNotBlank(enDate)){ - endDate = DateUtil.parseStringToDate(enDate); - } + long date = DateUtil.parseStringToDate("2016-11-23").getTime(); + if ("uri".equals(model.getQuery()) && startDate.getTime() >= date && endDate.getTime() > date) { + List apiInvokeStatisticalList = apiInvokeStatisticalService.findApiInvokeStatisticalList(model.getUserId(), startDate, endDate); + if (bos != null && apiInvokeStatisticalList.size() > 0) { + Map> resultMap = getCountByUri(apiInvokeStatisticalList); + for (StatAnalyBo boTemp : bos) { + String url = boTemp.getKey(); + boTemp.setSuccessEffectiveTime(resultMap.get(url).get("successEffectiveCount")); + boTemp.setSuccessInvalidTime(resultMap.get(url).get("successInvalidCount")); + boTemp.setDefeatTime(resultMap.get(url).get("defeatCount")); + } + } + } + for (StatAnalyBo boTemp : bos) { + List apiVisitCounts = apiVisitCountService.findAllApiVisitCount(model.getUserId(), boTemp.getKey(), startDate, endDate); + int total = 0; + for (ApiVisitCount apiVisitCount : apiVisitCounts) { + total += apiVisitCount.getVisitCount(); + } + boTemp.setBillingCount(total); + } - } - String Array[]=StringUtils.split(citys,"|"); - List cities=new ArrayList(); - if(Array!=null) { - for (int i = 0; i < Array.length; i++) { - cities.add(Array[i]); - } - } - List apiCountCities =null; - List eachCityBos=null; - if(cities.size()!=0) { - apiCountCities=apiCountCityService.findApiCountCity(cities, startDate, endDate); - eachCityBos = getEachCityBos(apiCountCities); - } + List resources = openResourceService.findOpenResource(null); + model.setResourceMap(converMapData(resources)); + model.setStatAnalyBoList(sortStatAnaly(bos)); - HSSFWorkbook workbook = new HSSFWorkbook(); - HSSFCellStyle cellStyle = workbook.createCellStyle(); - cellStyle.setAlignment(HSSFCellStyle.ALIGN_CENTER); - cellStyle.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER); - HSSFSheet sheet = workbook.createSheet("数据导出"); - HSSFRow row = sheet.createRow(0); - HSSFCell cell0 = row.createCell(0); - HSSFCell cell1 = row.createCell(1); - HSSFCell cell2 = row.createCell(2); - HSSFCell cell3= row.createCell(3); - HSSFCell cell4= row.createCell(4); - HSSFCell cell5= row.createCell(5); - cell0.setCellValue("城市"); - cell1.setCellValue("调用总量"); - cell2.setCellValue("成功调用次数"); - cell3.setCellValue("占比"); - cell4.setCellValue("失败调用次数"); - cell5.setCellValue("占比"); - if(null!=eachCityBos) { - for (int i = 0; i < eachCityBos.size(); i++) { - HSSFRow rows = sheet.createRow(i + 1); - HSSFCell cel0 = rows.createCell(0); - HSSFCell cel1 = rows.createCell(1); - HSSFCell cel2 = rows.createCell(2); - HSSFCell cel3 = rows.createCell(3); - HSSFCell cel4 = rows.createCell(4); - HSSFCell cel5 = rows.createCell(5); - cel0.setCellValue(eachCityBos.get(i).getCity()); - cel1.setCellValue(eachCityBos.get(i).getSumTime()); - cel2.setCellValue(eachCityBos.get(i).getSuccessTime()); - cel3.setCellValue(getFour(eachCityBos.get(i).getSuccessRate()) * 100 + "%"); - cel4.setCellValue(eachCityBos.get(i).getFailTime()); - cel5.setCellValue(getFour(eachCityBos.get(i).getFailRate()) * 100 + "%"); - } - } - HttpServletResponse response = ActionContext.getContext().getResponse(); - response.setCharacterEncoding("UTF-8"); - response.setContentType("application/x-download;charset=UTF-8"); - response.setHeader( "Content-Disposition", "attachment;filename=daochu.xls"); - try { - OutputStream os=response.getOutputStream(); - workbook.write(os); - os.flush(); - } catch (IOException e) { - e.printStackTrace(); - } - return null; - } - - private List sortApiBo(List bos){ - Collections.sort(bos, new Comparator() { - @Override - public int compare(OpenUriAnalyBo o1, OpenUriAnalyBo o2) { - if(o1.getUrlClickCount() > o2.getUrlClickCount()) { - return -1; - }else if(o1.getUrlClickCount() < o2.getUrlClickCount()) { - return 1; - } - return 0; - } - }); - - return bos; - } - private List sortStatAnaly(List bos){ - Collections.sort(bos, new Comparator() { - @Override - public int compare(StatAnalyBo o1, StatAnalyBo o2) { - if(o1.getCount() > o2.getCount()) { - return -1; - }else if(o1.getCount() < o2.getCount()) { - return 1; - } - return 0; - } - }); - - return bos; - } - private Map converMapData(List resources){ - Map map = new HashMap(); - for(OpenResource resource : resources){ - map.put(resource.getUri(), resource.getName()); - } - return map; - } - - - private List createAnalyBosByLink(List analys){ + return model; + } + + public Object detailVisitStatAction(ApiUserModel model) { + Date startDate = null; + Date endDate = null; + if (StringUtils.isNotBlank(model.getBegDate())) { + startDate = DateUtil.parseStringToDate(model.getBegDate()); + } + if (StringUtils.isNotBlank(model.getEndDate())) { + endDate = DateUtil.parseStringToDate(model.getEndDate()); + } - Map ret = new HashMap(); - Map> urlCodeMap = new HashMap>(); - int total = 0; - for(OpenUriAnaly openUriAnaly : analys){ - Integer temp = ret.get(openUriAnaly.getUrl()); - if(temp == null){ - ret.put(openUriAnaly.getUrl(), openUriAnaly.getUrlClickCount()); - }else{ - ret.put(openUriAnaly.getUrl(), temp + openUriAnaly.getUrlClickCount()); - } - Map codeMap = urlCodeMap.get(openUriAnaly.getUrl()); - if(codeMap == null){ - codeMap = new HashMap(); - urlCodeMap.put(openUriAnaly.getUrl(), codeMap); - } - Map analyCodeMap = openUriAnaly.getCodeMap(); - for(String code : analyCodeMap.keySet()){ - Integer count = (Integer) analyCodeMap.get(code); - if("200".equals(code)){ - Integer successCount = codeMap.get("successCount"); - if(successCount == null){ - codeMap.put("successCount", count); - }else{ - codeMap.put("successCount", successCount + count); - } - }else{ - Integer defeatCount = codeMap.get("defeatCount"); - if(defeatCount == null){ - codeMap.put("defeatCount", count); - }else{ - codeMap.put("defeatCount", defeatCount + count); - } - } - } - total = total + openUriAnaly.getUrlClickCount(); - } + List analys = openUriAnalyService.findOpenUriAnalyLogs(model.getUserId(), model.getUri(), startDate, endDate); + if (StringUtils.isBlank(model.getQuery())) { + model.setQuery("city"); + } - List bos = new ArrayList(); - int index = 0; - double totalPercent = 0; - for(String url : ret.keySet()){ - Integer count = ret.get(url); - double percent = 0; - if(index+1==ret.size()){ - percent = 100 - totalPercent; - }else{ - double a1 = count; - double val = a1*10000/(double)total; - percent = DataUtil.roundDouble(val/100, 2); - totalPercent = totalPercent + percent; - } - StatAnalyBo bo = new StatAnalyBo(); - bo.setKey(url); - bo.setCount(count); - bo.setPercent(percent); - Map codeMap = urlCodeMap.get(url); - bo.setSuccessTime(codeMap.get("successCount")); - bo.setDefeatTime(codeMap.get("defeatCount")); - if(codeMap.get("successCount") != null){ - bo.setSuccessRate(DataUtil.roundDouble((codeMap.get("successCount") * 100)/(double)count, 2)); - } - bos.add(bo); + List bos = null; + if (model.getQuery().equals("city")) { + bos = createAnalyByCity(analys, "city"); + } else if (model.getQuery().equals("time")) { + bos = createAnalyByCity(analys, "time"); + } - } - return bos; - } + model.setStatAnalyBoList(sortStatAnaly(bos)); + model.setChartSeries(toChartString(bos)); - private List getEachCityBos(List list){ - List eachCityBos=new ArrayList(); - Map> map=new HashMap>(); - for(ApiCountCity apiCountCity:list){ - if(map.containsKey(apiCountCity.getCity())){ - List list1=new ArrayList(); - List list2=map.get(apiCountCity.getCity()); - list1.add(list2.get(0)+apiCountCity.getSuccess()); - list1.add(list2.get(1)+apiCountCity.getFail()); - map.put(apiCountCity.getCity(),list1); - } - else { - List list1=new ArrayList(); - list1.add(apiCountCity.getSuccess()); - list1.add(apiCountCity.getFail()); - map.put(apiCountCity.getCity(),list1); - } - } - for(Object o:map.keySet()){ - List listm=map.get(o); - String city=o.toString(); - int success=listm.get(0); - int fail=listm.get(1); - int sum=success+fail; - double successTimeRate=getFour((double)success/(double)sum); - double failTimeRate=getFour((double)fail/(double)sum); - EachCityBo eachCityBo=new EachCityBo(); - eachCityBo.setCity(city); - eachCityBo.setSumTime(sum); - eachCityBo.setSuccessTime(success); - eachCityBo.setFailTime(fail); - eachCityBo.setSuccessRate(successTimeRate); - eachCityBo.setFailRate(failTimeRate); - eachCityBos.add(eachCityBo); - } - return eachCityBos; - } + User user = userService.findById(model.getUserId()); + if (user != null) { + model.setUserName(user.getDisplayName()); + } else { + model.setUserName(model.getUserId().toString()); + } + return model; + } - private double getFour(double m){ - BigDecimal b = new BigDecimal(m); - double f1 = b.setScale(4, BigDecimal.ROUND_HALF_UP).doubleValue(); - return f1; - } - - private List createAnalyByCity(List analys, String field){ - Map> ret = new HashMap>(); - int total = 0; - for(OpenUriAnaly openUriAnaly : analys){ - Map resultMap = null; - if(field.equals("day")){ - resultMap = (Map) ret.get(DateUtil.formatToYYYYMMDD(openUriAnaly.getStatDate())); - if(resultMap == null){ - resultMap = new HashMap(); - ret.put(DateUtil.formatToYYYYMMDD(openUriAnaly.getStatDate()), resultMap); - } - Integer count = (Integer) resultMap.get("count"); - if(count == null){ - resultMap.put("count", openUriAnaly.getUrlClickCount()); - }else{ - resultMap.put("count", count + openUriAnaly.getUrlClickCount()); - } - total = total + openUriAnaly.getUrlClickCount(); - }else{ - if(field.equals("city")){ - resultMap = openUriAnaly.getCityMap(); - }else if(field.equals("time")){ - resultMap = openUriAnaly.getTimeMap(); - } - Iterator it = resultMap.keySet().iterator(); - while(it.hasNext()){ - String key = it.next(); - int count = (Integer) resultMap.get(key); - Map dataMap = (Map) ret.get(key); - if(dataMap == null){ - dataMap = new HashMap(); - ret.put(key, dataMap); - dataMap.put("count", count); - }else{ - dataMap.put("count", (Integer) dataMap.get("count")+count); - } - total = total + count; - } - } - } - - - Iterator it = ret.keySet().iterator(); - - List bos = new ArrayList(); - int index = 0; - double totalPercent = 0; - while(it.hasNext()){ - String key = (String) it.next(); - Map detailMap = ret.get(key); - - int count = (Integer) detailMap.get("count"); - double percent = 0; - - if(index+1==ret.size()){ - percent = 100 - totalPercent; - }else{ - double a1 = count; - double val = a1*10000/(double)total; - int scale = 2; - percent = DataUtil.roundDouble(val/100, scale); - totalPercent = totalPercent + percent; - } - index++; - - StatAnalyBo bo = new StatAnalyBo(); - bo.setKey(key); - bo.setPercent(percent); - bo.setCount(count); - bos.add(bo); - } - - - return bos; - } - - private List createAnalyBosByUser(List analys){ - Map ret = new HashMap(); - - int total = 0; - for(OpenUriAnaly openUriAnaly : analys){ - OpenUriAnaly temp = ret.get(openUriAnaly.getApiUserId()); - if(temp == null){ - ret.put(openUriAnaly.getApiUserId(), openUriAnaly); - }else{ - temp.setUrlClickCount(temp.getUrlClickCount()+openUriAnaly.getUrlClickCount()); - ret.put(openUriAnaly.getApiUserId(), temp); - } - - total = total + openUriAnaly.getUrlClickCount(); - } - List bos = new ArrayList(); - Iterator it = ret.keySet().iterator(); - - List users = this.userService.findAllUsers(); - - int index = 0; - double totalPercent = 0; - while(it.hasNext()){ - OpenUriAnaly openUriAnaly = ret.get(it.next()); - - double percent = 0; - - if(index+1==ret.size()){ - percent = 100 - totalPercent; - }else{ - double a1 = openUriAnaly.getUrlClickCount(); - double val = a1*10000/(double)total; - int scale = 2; - percent = DataUtil.roundDouble(val/100, scale); - //percent = getPercent(percent, scale, val); - totalPercent = totalPercent + percent; - } - index++; - - String name = null; - for(User user : users){ - if(openUriAnaly.getApiUserId()==user.getId()){ - name = user.getDisplayName(); - break; - } - } - - StatAnalyBo bo = new StatAnalyBo(); - if(StringUtils.isNotBlank(name)){ - bo.setKey(name); - }else{ - bo.setKey(openUriAnaly.getApiUserId().toString()); - } - - bo.setCount(openUriAnaly.getUrlClickCount()); - bo.setPercent(percent); - bo.setUserId(openUriAnaly.getApiUserId()); - bos.add(bo); - } - return bos; - } - - private double getPercent(double percent, int scale, double val){ - if(percent==0){ - while(scale<=8){ - if(percent==0){ - scale = scale+1; - percent = DataUtil.roundDouble(val/100, scale); - }else{ - break; - } - } - } - return percent; - } - - private String toChartString(List bos, int way) { - JSONArray ja = new JSONArray(); - for (OpenUriAnalyBo bo : bos) { + public Object importExcelAction(HttpServletRequest request, ApiUserModel model) { + String citys = request.getParameter("city"); + String begDate = request.getParameter("begDate"); + String enDate = request.getParameter("endDate"); + Date startDate = null; + Date endDate = null; + if (StringUtils.isBlank(begDate) && StringUtils.isBlank(enDate)) { + startDate = DateUtil.add(DateUtil.formatToYYYYMMDD(new Date()), -7); + endDate = DateUtil.parseStringToDate(DateUtil.formatToYYYYMMDD(new Date())); + } else { + if (StringUtils.isNotBlank(begDate)) { + startDate = DateUtil.parseStringToDate(begDate); + } + if (StringUtils.isNotBlank(enDate)) { + endDate = DateUtil.parseStringToDate(enDate); + } + + } + String Array[] = StringUtils.split(citys, "|"); + List cities = new ArrayList(); + if (Array != null) { + for (int i = 0; i < Array.length; i++) { + cities.add(Array[i]); + } + } + List apiCountCities = null; + List eachCityBos = null; + if (cities.size() != 0) { + apiCountCities = apiCountCityService.findApiCountCity(cities, startDate, endDate); + eachCityBos = getEachCityBos(apiCountCities); + } + + HSSFWorkbook workbook = new HSSFWorkbook(); + HSSFCellStyle cellStyle = workbook.createCellStyle(); + cellStyle.setAlignment(HSSFCellStyle.ALIGN_CENTER); + cellStyle.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER); + HSSFSheet sheet = workbook.createSheet("数据导出"); + HSSFRow row = sheet.createRow(0); + HSSFCell cell0 = row.createCell(0); + HSSFCell cell1 = row.createCell(1); + HSSFCell cell2 = row.createCell(2); + HSSFCell cell3 = row.createCell(3); + HSSFCell cell4 = row.createCell(4); + HSSFCell cell5 = row.createCell(5); + cell0.setCellValue("城市"); + cell1.setCellValue("调用总量"); + cell2.setCellValue("成功调用次数"); + cell3.setCellValue("占比"); + cell4.setCellValue("失败调用次数"); + cell5.setCellValue("占比"); + if (null != eachCityBos) { + for (int i = 0; i < eachCityBos.size(); i++) { + HSSFRow rows = sheet.createRow(i + 1); + HSSFCell cel0 = rows.createCell(0); + HSSFCell cel1 = rows.createCell(1); + HSSFCell cel2 = rows.createCell(2); + HSSFCell cel3 = rows.createCell(3); + HSSFCell cel4 = rows.createCell(4); + HSSFCell cel5 = rows.createCell(5); + cel0.setCellValue(eachCityBos.get(i).getCity()); + cel1.setCellValue(eachCityBos.get(i).getSumTime()); + cel2.setCellValue(eachCityBos.get(i).getSuccessTime()); + cel3.setCellValue(getFour(eachCityBos.get(i).getSuccessRate()) * 100 + "%"); + cel4.setCellValue(eachCityBos.get(i).getFailTime()); + cel5.setCellValue(getFour(eachCityBos.get(i).getFailRate()) * 100 + "%"); + } + } + HttpServletResponse response = ActionContext.getContext().getResponse(); + response.setCharacterEncoding("UTF-8"); + response.setContentType("application/x-download;charset=UTF-8"); + response.setHeader("Content-Disposition", "attachment;filename=daochu.xls"); + try { + OutputStream os = response.getOutputStream(); + workbook.write(os); + os.flush(); + } catch (IOException e) { + e.printStackTrace(); + } + return null; + } + + private List sortApiBo(List bos) { + Collections.sort(bos, new Comparator() { + @Override + public int compare(OpenUriAnalyBo o1, OpenUriAnalyBo o2) { + if (o1.getUrlClickCount() > o2.getUrlClickCount()) { + return -1; + } else if (o1.getUrlClickCount() < o2.getUrlClickCount()) { + return 1; + } + return 0; + } + }); + + return bos; + } + + private List sortStatAnaly(List bos) { + Collections.sort(bos, new Comparator() { + @Override + public int compare(StatAnalyBo o1, StatAnalyBo o2) { + if (o1.getCount() > o2.getCount()) { + return -1; + } else if (o1.getCount() < o2.getCount()) { + return 1; + } + return 0; + } + }); + + return bos; + } + + private Map converMapData(List resources) { + Map map = new HashMap(); + for (OpenResource resource : resources) { + map.put(resource.getUri(), resource.getName()); + } + return map; + } + + + private List createAnalyBosByLink(List analys) { + + + Map ret = new HashMap(); + Map> urlCodeMap = new HashMap>(); + int total = 0; + for (OpenUriAnaly openUriAnaly : analys) { + Integer temp = ret.get(openUriAnaly.getUrl()); + if (temp == null) { + ret.put(openUriAnaly.getUrl(), openUriAnaly.getUrlClickCount()); + } else { + ret.put(openUriAnaly.getUrl(), temp + openUriAnaly.getUrlClickCount()); + } + Map codeMap = urlCodeMap.get(openUriAnaly.getUrl()); + if (codeMap == null) { + codeMap = new HashMap(); + urlCodeMap.put(openUriAnaly.getUrl(), codeMap); + } + Map analyCodeMap = openUriAnaly.getCodeMap(); + for (String code : analyCodeMap.keySet()) { + Integer count = (Integer) analyCodeMap.get(code); + if ("200".equals(code)) { + Integer successCount = codeMap.get("successCount"); + if (successCount == null) { + codeMap.put("successCount", count); + } else { + codeMap.put("successCount", successCount + count); + } + } else { + Integer defeatCount = codeMap.get("defeatCount"); + if (defeatCount == null) { + codeMap.put("defeatCount", count); + } else { + codeMap.put("defeatCount", defeatCount + count); + } + } + } + total = total + openUriAnaly.getUrlClickCount(); + } + + List bos = new ArrayList(); + int index = 0; + double totalPercent = 0; + for (String url : ret.keySet()) { + Integer count = ret.get(url); + double percent = 0; + if (index + 1 == ret.size()) { + percent = 100 - totalPercent; + } else { + double a1 = count; + double val = a1 * 10000 / (double) total; + percent = DataUtil.roundDouble(val / 100, 2); + totalPercent = totalPercent + percent; + } + StatAnalyBo bo = new StatAnalyBo(); + bo.setKey(url); + bo.setCount(count); + bo.setPercent(percent); + Map codeMap = urlCodeMap.get(url); + bo.setSuccessTime(codeMap.get("successCount")); + bo.setDefeatTime(codeMap.get("defeatCount")); + if (codeMap.get("successCount") != null) { + bo.setSuccessRate(DataUtil.roundDouble((codeMap.get("successCount") * 100) / (double) count, 2)); + } + bos.add(bo); + + } + return bos; + } + + private List getEachCityBos(List list) { + List eachCityBos = new ArrayList(); + Map> map = new HashMap>(); + for (ApiCountCity apiCountCity : list) { + if (map.containsKey(apiCountCity.getCity())) { + List list1 = new ArrayList(); + List list2 = map.get(apiCountCity.getCity()); + list1.add(list2.get(0) + apiCountCity.getSuccess()); + list1.add(list2.get(1) + apiCountCity.getFail()); + map.put(apiCountCity.getCity(), list1); + } else { + List list1 = new ArrayList(); + list1.add(apiCountCity.getSuccess()); + list1.add(apiCountCity.getFail()); + map.put(apiCountCity.getCity(), list1); + } + } + for (Object o : map.keySet()) { + List listm = map.get(o); + String city = o.toString(); + int success = listm.get(0); + int fail = listm.get(1); + int sum = success + fail; + double successTimeRate = getFour((double) success / (double) sum); + double failTimeRate = getFour((double) fail / (double) sum); + EachCityBo eachCityBo = new EachCityBo(); + eachCityBo.setCity(city); + eachCityBo.setSumTime(sum); + eachCityBo.setSuccessTime(success); + eachCityBo.setFailTime(fail); + eachCityBo.setSuccessRate(successTimeRate); + eachCityBo.setFailRate(failTimeRate); + eachCityBos.add(eachCityBo); + } + return eachCityBos; + } + + private double getFour(double m) { + BigDecimal b = new BigDecimal(m); + double f1 = b.setScale(4, BigDecimal.ROUND_HALF_UP).doubleValue(); + return f1; + } + + private List createAnalyByCity(List analys, String field) { + Map> ret = new HashMap>(); + int total = 0; + for (OpenUriAnaly openUriAnaly : analys) { + Map resultMap = null; + if (field.equals("day")) { + resultMap = (Map) ret.get(DateUtil.formatToYYYYMMDD(openUriAnaly.getStatDate())); + if (resultMap == null) { + resultMap = new HashMap(); + ret.put(DateUtil.formatToYYYYMMDD(openUriAnaly.getStatDate()), resultMap); + } + Integer count = (Integer) resultMap.get("count"); + if (count == null) { + resultMap.put("count", openUriAnaly.getUrlClickCount()); + } else { + resultMap.put("count", count + openUriAnaly.getUrlClickCount()); + } + total = total + openUriAnaly.getUrlClickCount(); + } else { + if (field.equals("city")) { + resultMap = openUriAnaly.getCityMap(); + } else if (field.equals("time")) { + resultMap = openUriAnaly.getTimeMap(); + } + Iterator it = resultMap.keySet().iterator(); + while (it.hasNext()) { + String key = it.next(); + int count = (Integer) resultMap.get(key); + Map dataMap = (Map) ret.get(key); + if (dataMap == null) { + dataMap = new HashMap(); + ret.put(key, dataMap); + dataMap.put("count", count); + } else { + dataMap.put("count", (Integer) dataMap.get("count") + count); + } + total = total + count; + } + } + } + + + Iterator it = ret.keySet().iterator(); + + List bos = new ArrayList(); + int index = 0; + double totalPercent = 0; + while (it.hasNext()) { + String key = (String) it.next(); + Map detailMap = ret.get(key); + + int count = (Integer) detailMap.get("count"); + double percent = 0; + + if (index + 1 == ret.size()) { + percent = 100 - totalPercent; + } else { + double a1 = count; + double val = a1 * 10000 / (double) total; + int scale = 2; + percent = DataUtil.roundDouble(val / 100, scale); + totalPercent = totalPercent + percent; + } + index++; + + StatAnalyBo bo = new StatAnalyBo(); + bo.setKey(key); + bo.setPercent(percent); + bo.setCount(count); + bos.add(bo); + } + + + return bos; + } + + private List createAnalyBosByUser(List analys) { + Map ret = new HashMap(); + + int total = 0; + for (OpenUriAnaly openUriAnaly : analys) { + OpenUriAnaly temp = ret.get(openUriAnaly.getApiUserId()); + if (temp == null) { + ret.put(openUriAnaly.getApiUserId(), openUriAnaly); + } else { + temp.setUrlClickCount(temp.getUrlClickCount() + openUriAnaly.getUrlClickCount()); + ret.put(openUriAnaly.getApiUserId(), temp); + } + + total = total + openUriAnaly.getUrlClickCount(); + } + List bos = new ArrayList(); + Iterator it = ret.keySet().iterator(); + + List users = this.userService.findAllUsers(); + + int index = 0; + double totalPercent = 0; + while (it.hasNext()) { + OpenUriAnaly openUriAnaly = ret.get(it.next()); + + double percent = 0; + + if (index + 1 == ret.size()) { + percent = 100 - totalPercent; + } else { + double a1 = openUriAnaly.getUrlClickCount(); + double val = a1 * 10000 / (double) total; + int scale = 2; + percent = DataUtil.roundDouble(val / 100, scale); + //percent = getPercent(percent, scale, val); + totalPercent = totalPercent + percent; + } + index++; + + String name = null; + for (User user : users) { + if (openUriAnaly.getApiUserId() == user.getId()) { + name = user.getDisplayName(); + break; + } + } + + StatAnalyBo bo = new StatAnalyBo(); + if (StringUtils.isNotBlank(name)) { + bo.setKey(name); + } else { + bo.setKey(openUriAnaly.getApiUserId().toString()); + } + + bo.setCount(openUriAnaly.getUrlClickCount()); + bo.setPercent(percent); + bo.setUserId(openUriAnaly.getApiUserId()); + bos.add(bo); + } + return bos; + } + + private double getPercent(double percent, int scale, double val) { + if (percent == 0) { + while (scale <= 8) { + if (percent == 0) { + scale = scale + 1; + percent = DataUtil.roundDouble(val / 100, scale); + } else { + break; + } + } + } + return percent; + } + + private String toChartString(List bos, int way) { + JSONArray ja = new JSONArray(); + for (OpenUriAnalyBo bo : bos) { JSONArray array = new JSONArray(); array.put(way == 1 ? bo.getName() : bo.getUrl()); array.put(bo.getPercent()); ja.put(array); - } - return ja.toString(); - } - - private String toChartString(List bos) { - JSONArray ja = new JSONArray(); - for (StatAnalyBo bo : bos) { - JSONArray array = new JSONArray(); - if(StringUtils.isNotBlank(bo.getKey())){ - if(bo.getKey().equals("level_0")){ - array.put("0s"); - }else if(bo.getKey().equals("level_1")){ - array.put("1s以下"); - }else if(bo.getKey().equals("level_2")){ - array.put("1-2s以下"); - }else if(bo.getKey().equals("level_3")){ - array.put("2-3s以下"); - }else if(bo.getKey().equals("level_4")){ - array.put("3s以上"); - }else if(bo.getKey().equals("level_100")){ - array.put("暂无数据"); - }else{ - array.put(bo.getKey()); - } - }else{ - array.put(bo.getUserId()); - } - - array.put(bo.getPercent()); - ja.put(array); - } - return ja.toString(); - } + } + return ja.toString(); + } - /** - * 页面查询条件 - * - * @return - */ - private String[] getCityFirstLetter() { - String[] cityFirstLetter = { "A", "B", "C", "D", "E", "F", "G", "H", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", - "T", "W", "X", "Y", "Z" }; - return cityFirstLetter; - } + private String toChartString(List bos) { + JSONArray ja = new JSONArray(); + for (StatAnalyBo bo : bos) { + JSONArray array = new JSONArray(); + if (StringUtils.isNotBlank(bo.getKey())) { + if (bo.getKey().equals("level_0")) { + array.put("0s"); + } else if (bo.getKey().equals("level_1")) { + array.put("1s以下"); + } else if (bo.getKey().equals("level_2")) { + array.put("1-2s以下"); + } else if (bo.getKey().equals("level_3")) { + array.put("2-3s以下"); + } else if (bo.getKey().equals("level_4")) { + array.put("3s以上"); + } else if (bo.getKey().equals("level_100")) { + array.put("暂无数据"); + } else { + array.put(bo.getKey()); + } + } else { + array.put(bo.getUserId()); + } - - private Map> getCountByUri(List apiInvokeStatisticalList){ - Map> resultMap = new HashMap>(); - for (ApiInvokeStatistical apiInvokeStatistical : apiInvokeStatisticalList) { - Map detailMap = resultMap.get(apiInvokeStatistical.getRequestURI()); - if(detailMap == null){ - detailMap = new HashMap(); - resultMap.put(apiInvokeStatistical.getRequestURI(), detailMap); - } - Integer successEffectiveCount = detailMap.get("successEffectiveCount"); - Integer successInvalidCount = detailMap.get("successInvalidCount"); - Integer defeatCount = detailMap.get("defeatCount"); - if(successEffectiveCount != null){ - successEffectiveCount = successEffectiveCount + apiInvokeStatistical.getSuccessEffectiveTime(); - }else{ - successEffectiveCount = apiInvokeStatistical.getSuccessEffectiveTime(); - } - if(successInvalidCount != null){ - successInvalidCount = successInvalidCount + apiInvokeStatistical.getSuccessInvalidTime(); - }else{ - successInvalidCount = apiInvokeStatistical.getSuccessInvalidTime();; - } - if(defeatCount != null){ - defeatCount = defeatCount + apiInvokeStatistical.getDefeatTime(); - }else{ - defeatCount = apiInvokeStatistical.getDefeatTime(); - } - - detailMap.put("successEffectiveCount", successEffectiveCount); - detailMap.put("successInvalidCount", successInvalidCount); - detailMap.put("defeatCount", defeatCount); - } - - return resultMap; - } - public void setApiUserService(ApiUserService apiUserService) { - this.apiUserService = apiUserService; - } + array.put(bo.getPercent()); + ja.put(array); + } + return ja.toString(); + } - public UserService getUserService() { - return userService; - } + /** + * 页面查询条件 + * + * @return + */ + private String[] getCityFirstLetter() { + String[] cityFirstLetter = {"A", "B", "C", "D", "E", "F", "G", "H", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", + "T", "W", "X", "Y", "Z"}; + return cityFirstLetter; + } - public void setUserService(UserService userService) { - this.userService = userService; - } - public void setApiUserAuthorityService(ApiUserAuthorityService apiUserAuthorityService) { - this.apiUserAuthorityService = apiUserAuthorityService; - } + private Map> getCountByUri(List apiInvokeStatisticalList) { + Map> resultMap = new HashMap>(); + for (ApiInvokeStatistical apiInvokeStatistical : apiInvokeStatisticalList) { + Map detailMap = resultMap.get(apiInvokeStatistical.getRequestURI()); + if (detailMap == null) { + detailMap = new HashMap(); + resultMap.put(apiInvokeStatistical.getRequestURI(), detailMap); + } + Integer successEffectiveCount = detailMap.get("successEffectiveCount"); + Integer successInvalidCount = detailMap.get("successInvalidCount"); + Integer defeatCount = detailMap.get("defeatCount"); + if (successEffectiveCount != null) { + successEffectiveCount = successEffectiveCount + apiInvokeStatistical.getSuccessEffectiveTime(); + } else { + successEffectiveCount = apiInvokeStatistical.getSuccessEffectiveTime(); + } + if (successInvalidCount != null) { + successInvalidCount = successInvalidCount + apiInvokeStatistical.getSuccessInvalidTime(); + } else { + successInvalidCount = apiInvokeStatistical.getSuccessInvalidTime(); + ; + } + if (defeatCount != null) { + defeatCount = defeatCount + apiInvokeStatistical.getDefeatTime(); + } else { + defeatCount = apiInvokeStatistical.getDefeatTime(); + } - public void setOpenResourceService(OpenResourceService openResourceService) { - this.openResourceService = openResourceService; - } + detailMap.put("successEffectiveCount", successEffectiveCount); + detailMap.put("successInvalidCount", successInvalidCount); + detailMap.put("defeatCount", defeatCount); + } - public void setServerAreaService(ServerAreaService serverAreaService) { - this.serverAreaService = serverAreaService; - } + return resultMap; + } - public void setApiVisitCountService(ApiVisitCountService apiVisitCountService) { - this.apiVisitCountService = apiVisitCountService; - } + public void setApiUserService(ApiUserService apiUserService) { + this.apiUserService = apiUserService; + } - public void setOpenResourceCountService( - OpenResourceCountService openResourceCountService) { - this.openResourceCountService = openResourceCountService; - } - - - public void setOpenUriAnalyService(OpenUriAnalyService openUriAnalyService) { - this.openUriAnalyService = openUriAnalyService; - } + public UserService getUserService() { + return userService; + } - public void setApiUserCfgService(ApiUserCfgService apiUserCfgService) { - this.apiUserCfgService = apiUserCfgService; - } + public void setUserService(UserService userService) { + this.userService = userService; + } - public ApiInvokeStatisticalService getApiInvokeStatisticalService() { - return apiInvokeStatisticalService; - } + public void setApiUserAuthorityService(ApiUserAuthorityService apiUserAuthorityService) { + this.apiUserAuthorityService = apiUserAuthorityService; + } - public void setApiInvokeStatisticalService( - ApiInvokeStatisticalService apiInvokeStatisticalService) { - this.apiInvokeStatisticalService = apiInvokeStatisticalService; - } + public void setOpenResourceService(OpenResourceService openResourceService) { + this.openResourceService = openResourceService; + } - public void setApiCountCityService(ApiCountCityService apiCountCityService) { - this.apiCountCityService = apiCountCityService; - } + public void setServerAreaService(ServerAreaService serverAreaService) { + this.serverAreaService = serverAreaService; + } - public Map string2map(String str) - { - Map map = new HashMap(); - String [] a = str.split(","); + public void setApiVisitCountService(ApiVisitCountService apiVisitCountService) { + this.apiVisitCountService = apiVisitCountService; + } - for (String i : a) - { - String [] b = i.split(":"); - if (b.length > 1) - { - map.put(b[0],Integer.parseInt(b[1])); - } - } - return map; - } + public void setOpenResourceCountService( + OpenResourceCountService openResourceCountService) { + this.openResourceCountService = openResourceCountService; + } - public Object priceRatingAction(ApiUserModel model) throws IllegalAccessException { - ApiUserAuthority apiUserAuthority = apiUserAuthorityService.findByUserId(model.getUserId()); - if (apiUserAuthority != null && apiUserAuthority.getPriceRatingMap() != null){ - model.setPriceRatingMap(apiUserAuthority.getPriceRatingMap()); - }else{ - Map map = new HashMap(); - map.put("one",0.61); - map.put("newOne",0.61); - map.put("two",0.61); - map.put("three",0.61); - map.put("four",0.61); - map.put("five",0.61); - model.setPriceRatingMap(map); - } - if ( apiUserAuthority != null && apiUserAuthority.getCreditLevelStatus() != null) { - model.setCreditLevelStatus(apiUserAuthority.getCreditLevelStatus()); - } - ApiUser apiUser = apiUserService.findApiUserById(model.getUserId()); - if (apiUser != null) { - if (apiUser.getCompany() != null) { - model.setCompany(apiUser.getCompany()); - } - } - model.setUserId(model.getUserId()); - return model; - } + public void setOpenUriAnalyService(OpenUriAnalyService openUriAnalyService) { + this.openUriAnalyService = openUriAnalyService; + } - public Object savePriceRateingAction(ApiUserModel model) throws IllegalAccessException { - ApiUserAuthority apiUserAuthority = apiUserAuthorityService.findByUserId(model.getUserId()); - Map map = new HashMap(); - map.put("one",model.getOne()); - map.put("newOne",model.getNewOne()); - map.put("two",model.getTwo()); - map.put("three",model.getThree()); - map.put("four",model.getFour()); - map.put("five",model.getFive()); - apiUserAuthority.setPriceRatingMap(map); - apiUserAuthority.setCreditLevelStatus(model.getCreditLevelStatus()); - apiUserAuthorityService.update(apiUserAuthority); - model.setViewType("redirect"); - model.setViewParam("location", "/apiUser/list"); - return model; - } + public void setApiUserCfgService(ApiUserCfgService apiUserCfgService) { + this.apiUserCfgService = apiUserCfgService; + } + + public ApiInvokeStatisticalService getApiInvokeStatisticalService() { + return apiInvokeStatisticalService; + } + + public void setApiInvokeStatisticalService( + ApiInvokeStatisticalService apiInvokeStatisticalService) { + this.apiInvokeStatisticalService = apiInvokeStatisticalService; + } + + public void setApiCountCityService(ApiCountCityService apiCountCityService) { + this.apiCountCityService = apiCountCityService; + } + + public Map string2map(String str) { + Map map = new HashMap(); + String[] a = str.split(","); + + for (String i : a) { + String[] b = i.split(":"); + if (b.length > 1) { + map.put(b[0], Integer.parseInt(b[1])); + } + } + return map; + } + + public Object priceRatingAction(ApiUserModel model) throws IllegalAccessException { + ApiUserAuthority apiUserAuthority = apiUserAuthorityService.findByUserId(model.getUserId()); + if (apiUserAuthority != null && apiUserAuthority.getPriceRatingMap() != null) { + model.setPriceRatingMap(apiUserAuthority.getPriceRatingMap()); + } else { + Map map = new HashMap(); + map.put("one", 0.61); + map.put("newOne", 0.61); + map.put("two", 0.61); + map.put("three", 0.61); + map.put("four", 0.61); + map.put("five", 0.61); + model.setPriceRatingMap(map); + } + if (apiUserAuthority != null && apiUserAuthority.getCreditLevelStatus() != null) { + model.setCreditLevelStatus(apiUserAuthority.getCreditLevelStatus()); + } + ApiUser apiUser = apiUserService.findApiUserById(model.getUserId()); + if (apiUser != null) { + if (apiUser.getCompany() != null) { + model.setCompany(apiUser.getCompany()); + } + } + model.setUserId(model.getUserId()); + + return model; + } + + public Object savePriceRateingAction(ApiUserModel model) throws IllegalAccessException { + ApiUserAuthority apiUserAuthority = apiUserAuthorityService.findByUserId(model.getUserId()); + Map map = new HashMap(); + map.put("one", model.getOne()); + map.put("newOne", model.getNewOne()); + map.put("two", model.getTwo()); + map.put("three", model.getThree()); + map.put("four", model.getFour()); + map.put("five", model.getFive()); + apiUserAuthority.setPriceRatingMap(map); + apiUserAuthority.setCreditLevelStatus(model.getCreditLevelStatus()); + apiUserAuthorityService.update(apiUserAuthority); + model.setViewType("redirect"); + model.setViewParam("location", "/apiUser/list"); + return model; + } } diff --git a/projects/fangjia-bkoff/src/main/webapp/apiUser/auth.ftl b/projects/fangjia-bkoff/src/main/webapp/apiUser/auth.ftl index 387007283..9e0ea31e6 100644 --- a/projects/fangjia-bkoff/src/main/webapp/apiUser/auth.ftl +++ b/projects/fangjia-bkoff/src/main/webapp/apiUser/auth.ftl @@ -10,7 +10,27 @@ <#include "/common_js.ftl" /> - + +<#-- 灏嗚〃澶村浐瀹�--> + @@ -31,12 +51,13 @@
- Ap + + API鏁伴噺锛� ${authorityBoList?size}涓� + + + <#if (apiUserBoList??&&apiUserBoList?size>0)> + <#list apiUserBoList as bo> + style="background-color:#C3C3C3"> + + + + + + + + + + + + + + + + +
uri - 鎻忚堪 + API鍚嶇О 鏄惁鏈夋潈闄�鍏ㄩ�� @@ -63,7 +84,7 @@ ${bo.uri!} - ${bo.description!} + ${bo.name!} checked id="auth_${bo_index + 1}" > diff --git a/projects/fangjia-bkoff/src/main/webapp/apiUser/list.ftl b/projects/fangjia-bkoff/src/main/webapp/apiUser/list.ftl index 37afef638..e16556d06 100644 --- a/projects/fangjia-bkoff/src/main/webapp/apiUser/list.ftl +++ b/projects/fangjia-bkoff/src/main/webapp/apiUser/list.ftl @@ -1,150 +1,179 @@ <#ftl attributes={"content_type":"text/html; charset=UTF-8"}> <#compress> - - - - - api鐢ㄦ埛鍒楄〃 - - <#include "/common_js.ftl" /> - - - <#include "/layout/header.ftl" /> -
- ${msg!''} - -
-
-
- 鍏辨湁鐢ㄦ埛${apiUserBoList?size}涓� -
- - - - - + + + + + api鐢ㄦ埛鍒楄〃 + + <#include "/common_js.ftl" /> + + <#-- 灏嗚〃澶村浐瀹�--> + + + + <#include "/layout/header.ftl" /> +
+ ${msg!''} + +
+
+
+ 鍏辨湁鐢ㄦ埛${apiUserBoList?size}涓� +
+
- ID - - 鏄电О -
+ + + + - - + + - + - + - - - - <#if (apiUserBoList??&&apiUserBoList?size>0)> - <#list apiUserBoList as bo> - style="background-color:#C3C3C3"> - - - - - - - - - - - - - - - - -
+ ID + + 鏄电О + 璐︽埛鐢ㄩ�� - username - - password - + username + + password + 閿�鍞礋璐d汉 鍏徃 - appKey - + appKey + 璐︽埛绫诲瀷 璐︽埛鐢ㄩ�� - 鏄惁鐩戞帶 - + 鏄惁鐩戞帶 + 鍒版湡鏃堕棿 - 鎿嶄綔 -
- ${bo.userId!} - - ${bo.displayName!} - - <#if bo.purpose?? && bo.purpose == 1> - API - <#elseif bo.purpose?? && bo.purpose == 2> - PDS - <#elseif bo.purpose?? && bo.purpose == 4> - 鎴跨敓娲� - - - ${bo.userName!} - - <#if bo.password?? && bo.password == t_util.md5Hex('123456')> - 鍒濆瀵嗙爜 - <#else> - ****** - - - ${bo.manager!} - - ${bo.company!} - - ${bo.appKey!} - - <#if bo.isTest==0> - 姝e紡璐︽埛 - <#else> - 娴嬭瘯璐︽埛 - - - <#if bo.purpose?? && bo.purpose == 1> - API - <#elseif bo.purpose?? && bo.purpose == 2> - PDS - <#elseif bo.purpose?? && bo.purpose == 4> - 鎴跨敓娲� - - - <#if bo.isMonitor==1> - 鏄� - <#else> - 鍚� - - - <#if bo.deadTime??> - ${bo.deadTime?string("yyyy骞碝M鏈坉d鏃�")} - - - 鏉冮檺鎺у埗 - 鍩庡競绠$悊 - 浠锋牸璇勭骇 - <#if bo.status==0> - 绂佺敤 - <#else> - 鍐嶅惎鐢� - -
-
-
- - +
+ 鎿嶄綔 +
+ ${bo.userId!} + + ${bo.displayName!} + + <#if bo.purpose?? && bo.purpose == 1> + API + <#elseif bo.purpose?? && bo.purpose == 2> + PDS + <#elseif bo.purpose?? && bo.purpose == 4> + 鎴跨敓娲� + + + ${bo.userName!} + + <#if bo.password?? && bo.password == t_util.md5Hex('123456')> + 鍒濆瀵嗙爜 + <#else> + ****** + + + ${bo.manager!} + + ${bo.company!} + + ${bo.appKey!} + + <#if bo.isTest==0> + 姝e紡璐︽埛 + <#else> + 娴嬭瘯璐︽埛 + + + <#if bo.purpose?? && bo.purpose == 1> + API + <#elseif bo.purpose?? && bo.purpose == 2> + PDS + <#elseif bo.purpose?? && bo.purpose == 4> + 鎴跨敓娲� + + + <#if bo.isMonitor==1> + 鏄� + <#else> + 鍚� + + + <#if bo.deadTime??> + ${bo.deadTime?string("yyyy骞碝M鏈坉d鏃�")} + + + API鏉冮檺鎺у埗 + 鏂板API + 鍩庡競绠$悊 + 浠锋牸璇勭骇 + <#if bo.status==0> + 绂佺敤 + <#else> + 鍐嶅惎鐢� + +
+
+ + + \ No newline at end of file diff --git a/projects/fangjia-bkoff/src/main/webapp/openResource/list.ftl b/projects/fangjia-bkoff/src/main/webapp/openResource/list.ftl index 9944cfa86..629c14ec4 100644 --- a/projects/fangjia-bkoff/src/main/webapp/openResource/list.ftl +++ b/projects/fangjia-bkoff/src/main/webapp/openResource/list.ftl @@ -8,6 +8,25 @@ .up {color: green;} #spinner{width:500px;height:100px;margin:30px 0 0 100px;text-align:center;padding-top:50px;border:2px solid #CCC;} #checkMsg{width:500px;margin:30px 0 0 100px;padding:10px 0 10px 50px;text-align:left;border:2px solid #CCC;} + + <#-- 灏嗚〃澶村浐瀹�--> + table { + width: 100%; + border-collapse: collapse; + table-layout: fixed; + } + + th, td { + border: 1px solid #dddddd; + text-align: left; + padding: 8px; + } + + th { + position: sticky; + top: 0; + background-color: #f2f2f2; + }