API接口“开通城市”增加可以通过省份选择
This commit is contained in:
+160
@@ -12,6 +12,7 @@ import com.fangjia.dal.mongo.fangjia.model.ServerArea;
|
||||
import com.fangjia.dal.mongo.model.ApiCountLog;
|
||||
import com.fangjia.dal.mongo.model.ApiInvokeStatistical;
|
||||
import com.fangjia.dal.mongo.model.ApiUserCfg;
|
||||
import com.fangjia.dal.mongo.model.RegionBlock;
|
||||
import com.fangjia.dal.mongo.model.bkoff.BkoffUsers;
|
||||
import com.fangjia.dal.mongo.open.model.ApiJsonViewConfig;
|
||||
import com.fangjia.dal.mongo.open.model.ApiUserAuthority;
|
||||
@@ -23,9 +24,11 @@ import com.fangjia.dal.mongo.tool.model.OpenUriAnaly;
|
||||
import com.fangjia.dal.sql.model.ApiUser;
|
||||
import com.fangjia.dal.sql.model.User;
|
||||
import com.fangjia.service.api.ApiUserCfgService;
|
||||
import com.fangjia.service.bo.ServerAreaBo;
|
||||
import com.fangjia.service.mongo.bkoff.ApiInvokeStatisticalService;
|
||||
import com.fangjia.service.mongo.bkoff.BkoffUsersService;
|
||||
import com.fangjia.service.mongo.fangjia.ApiCountLogService;
|
||||
import com.fangjia.service.mongo.fangjia.RegionBlockService;
|
||||
import com.fangjia.service.mongo.fangjia.ServerAreaService;
|
||||
import com.fangjia.service.open.*;
|
||||
import com.fangjia.service.sql.ApiUserService;
|
||||
@@ -80,6 +83,8 @@ public class ApiUserController {
|
||||
private BkoffUsersService bkoffUsersService;
|
||||
private ApiCountLogService apiCountLogService;
|
||||
|
||||
private RegionBlockService regionBlockService;
|
||||
|
||||
/**
|
||||
* 所有api用户的信息展示
|
||||
*
|
||||
@@ -461,6 +466,7 @@ public class ApiUserController {
|
||||
ApiUserAuthority apiUserAuthority = apiUserAuthorityService.findByUserId(model.getUserId());
|
||||
Map<String, Double> cityCreditMap = apiUserAuthority.getCityCreditMap();
|
||||
model.setDisplayName(user.getDisplayName() == null ? "" : user.getDisplayName());
|
||||
model.setProvinceList(getProvinceList());
|
||||
model.setCityFirstLetters(Arrays.asList(getCityFirstLetter()));
|
||||
List<ServerArea> serverAreaList = serverAreaService.findAll();// Load城市列表
|
||||
if (StringUtils.isBlank(model.getType()) || "all".equals(model.getType())) {// 字母分组列表
|
||||
@@ -481,6 +487,19 @@ public class ApiUserController {
|
||||
}
|
||||
serverAreaLetterList.add(map);
|
||||
}
|
||||
if (model.getType().equals(serverArea.getProvince())) {
|
||||
Map<String, Object> map = new HashMap<String, Object>();
|
||||
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);
|
||||
}
|
||||
@@ -1946,6 +1965,15 @@ public class ApiUserController {
|
||||
"T", "W", "X", "Y", "Z"};
|
||||
return cityFirstLetter;
|
||||
}
|
||||
private List<String> getProvinceList(){
|
||||
List<String> provinces = Arrays.asList(
|
||||
"山东", "福建", "河北", "河南", "湖北", "湖南", "江西", "海南",
|
||||
"黑龙江", "陕西", "贵州", "新疆", "江苏", "安徽", "西藏",
|
||||
"吉林", "山西", "甘肃", "宁夏", "四川", "浙江", "广西",
|
||||
"云南", "直辖市", "内蒙古", "辽宁", "广东", "青海"
|
||||
);
|
||||
return provinces;
|
||||
}
|
||||
|
||||
|
||||
private Map<String, Map<String, Integer>> getCountByUri(List<ApiInvokeStatistical> apiInvokeStatisticalList) {
|
||||
@@ -2104,6 +2132,65 @@ public class ApiUserController {
|
||||
return model;
|
||||
}
|
||||
|
||||
private Map<String, List<CityBo>> splitCityInProvince(List<ServerAreaBo> allCitys) {
|
||||
if (CollectionUtils.isEmpty(allCitys)) {
|
||||
return Collections.emptyMap();
|
||||
}
|
||||
List<RegionBlock> regionBlocks = regionBlockService.getRegionBlockList();
|
||||
Map<String, List<RegionBlock>> regionMap = new TreeMap<String, List<RegionBlock>>();
|
||||
for (RegionBlock regionBlock : regionBlocks) {
|
||||
List<RegionBlock> regionBlockList = regionMap.get(regionBlock.getCity());
|
||||
if (regionBlockList == null) {
|
||||
regionBlockList = new ArrayList<RegionBlock>();
|
||||
}
|
||||
regionBlockList.add(regionBlock);
|
||||
regionMap.put(regionBlock.getCity(), regionBlockList);
|
||||
}
|
||||
Map<String, List<CityBo>> ret = new HashMap<String, List<CityBo>>();
|
||||
for (ServerAreaBo city : allCitys) {
|
||||
|
||||
String province = "";
|
||||
if (city.getProvince() == null || city.getProvince() == "") {
|
||||
province = null;
|
||||
} else if (city.getProvince().equals("上海") || city.getProvince().equals("北京") || city.getProvince().equals("天津")
|
||||
|| city.getProvince().equals("重庆")) {
|
||||
province = "直辖市";
|
||||
} else {
|
||||
province = city.getProvince();
|
||||
}
|
||||
if (province != null) {
|
||||
|
||||
List<CityBo> cityBoList = ret.get(province);
|
||||
if (CollectionUtils.isEmpty(cityBoList)) {
|
||||
cityBoList = new ArrayList<CityBo>();
|
||||
}
|
||||
CityBo bo = new CityBo();
|
||||
BeanUtils.copyProperties(city, bo);
|
||||
|
||||
List<RegionBlock> getRegionBlock = regionMap.get(city.getDisplay());
|
||||
|
||||
if (getRegionBlock != null) {
|
||||
|
||||
for (int i = getRegionBlock.size() - 1; i >= 0; i--) {
|
||||
try {
|
||||
if (getRegionBlock.get(i).getRegionType() != null && getRegionBlock.get(i).getRegionType() != 2) {
|
||||
getRegionBlock.remove(i);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
bo.setCityRegion(getRegionBlock);
|
||||
cityBoList.add(bo);
|
||||
ret.put(province, cityBoList);
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
public void setBkoffUsersService(BkoffUsersService bkoffUsersService) {
|
||||
this.bkoffUsersService = bkoffUsersService;
|
||||
}
|
||||
@@ -2111,4 +2198,77 @@ public class ApiUserController {
|
||||
public void setApiCountLogService(ApiCountLogService apiCountLogService) {
|
||||
this.apiCountLogService = apiCountLogService;
|
||||
}
|
||||
|
||||
public void setRegionBlockService(RegionBlockService regionBlockService) {
|
||||
this.regionBlockService = regionBlockService;
|
||||
}
|
||||
|
||||
public class CityBo {
|
||||
private String id;
|
||||
private String display;
|
||||
private String spell;
|
||||
private String name;
|
||||
private List<RegionBlock> cityRegion;
|
||||
private int haveDistrict; // 0:没有 , > 0:有
|
||||
private Map<String, Integer> cityRegionHaveDistrict; // 区域有无小区统计 0:没有
|
||||
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(String id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getDisplay() {
|
||||
return display;
|
||||
}
|
||||
|
||||
public void setDisplay(String display) {
|
||||
this.display = display;
|
||||
}
|
||||
|
||||
public String getSpell() {
|
||||
return spell;
|
||||
}
|
||||
|
||||
public void setSpell(String spell) {
|
||||
this.spell = spell;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public List<RegionBlock> getCityRegion() {
|
||||
return cityRegion;
|
||||
}
|
||||
|
||||
public void setCityRegion(List<RegionBlock> cityRegion) {
|
||||
this.cityRegion = cityRegion;
|
||||
}
|
||||
|
||||
public int getHaveDistrict() {
|
||||
return haveDistrict;
|
||||
}
|
||||
|
||||
public void setHaveDistrict(int haveDistrict) {
|
||||
this.haveDistrict = haveDistrict;
|
||||
}
|
||||
|
||||
public Map<String, Integer> getCityRegionHaveDistrict() {
|
||||
return cityRegionHaveDistrict;
|
||||
}
|
||||
|
||||
public void setCityRegionHaveDistrict(Map<String, Integer> cityRegionHaveDistrict) {
|
||||
this.cityRegionHaveDistrict = cityRegionHaveDistrict;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -104,6 +104,8 @@ public class ApiUserModel extends BaseModel {
|
||||
private Integer isCheckCount;
|
||||
|
||||
private String openResourseUrisMap;
|
||||
|
||||
private List<String> provinceList;
|
||||
|
||||
public String getOpenResourseUrisMap() {
|
||||
return openResourseUrisMap;
|
||||
@@ -665,4 +667,12 @@ public class ApiUserModel extends BaseModel {
|
||||
public void setIsWarnExpired(Integer isWarnExpired) {
|
||||
this.isWarnExpired = isWarnExpired;
|
||||
}
|
||||
|
||||
public List<String> getProvinceList() {
|
||||
return provinceList;
|
||||
}
|
||||
|
||||
public void setProvinceList(List<String> provinceList) {
|
||||
this.provinceList = provinceList;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<#ftl attributes={"content_type":"text/html; charset=UTF-8"}>
|
||||
<#compress>
|
||||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
||||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
||||
<html xmlns="http://www.w3.org/1999/xhtml">
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
|
||||
@@ -18,45 +18,110 @@
|
||||
<input type="hidden" id="citys" value="${citys!}"></input>
|
||||
<div style="color: red;"><#if openCitys??&&openCitys?length gt 0>${displayName!''}已经开通${openCitys!}<#else>${displayName!''}尚未开通任何城市</#if>
|
||||
</div>
|
||||
<br/><br/><br/>
|
||||
<div style="color: red;">${message!}</div>
|
||||
<div style = "border-top:1px solid #DDD;border-bottom:1px solid #DDD;padding-top:5px; padding-left:20px;font-size:25px;">
|
||||
<div style="margin-bottom: 20px; text-align: center;">
|
||||
<button id="toggleToPinyin" >按拼音选</button>
|
||||
<button id="toggleToProvince" >按省份选</button>
|
||||
</div>
|
||||
<span id="provinceFilter" style="display: block; border: 1px solid #DDD; padding: 10px;">
|
||||
<a href = "city?userId=${userId!}">全部</a>
|
||||
<#list provinceList as provinceName>
|
||||
<a href="city?userId=${userId!}&type=${provinceName}&filter=province"
|
||||
<#if (province?? && province == provinceName)>style='background:#82C1EF;'</#if>>
|
||||
${provinceName}
|
||||
</a>
|
||||
</#list>
|
||||
</span>
|
||||
|
||||
<span id="pinyinFilter" style="display: none; border: 1px solid #DDD; padding: 10px;">
|
||||
<a href = "city?userId=${userId!}">全部</a>
|
||||
<#list cityFirstLetters as letter>
|
||||
<a href = "city?userId=${userId!}&type=${letter}" <#if (type?? && (type == '${letter}'))>style = 'background:#82C1EF;border: 1px solid #DDD;'</#if>>${letter}</a>
|
||||
<a href = "city?userId=${userId!}&type=${letter}&filter=province" <#if (type?? && (type == '${letter}'))>style = 'background:#82C1EF;border: 1px solid #DDD;'</#if>>${letter}</a>
|
||||
</#list>
|
||||
</div>
|
||||
|
||||
<div style="margin-top:35px;">
|
||||
</span>
|
||||
<div>
|
||||
|
||||
<#if serverAreaList??>
|
||||
<#assign submitId='_submit_button'>
|
||||
<#-- <#list serverAreaList as serverArea>
|
||||
<input type="checkbox" id="city_${serverArea.spell!}" <#if citys??&&(citys?index_of(serverArea.spell) gt -1||citys=='all') >checked </#if> />${serverArea.display!}
|
||||
</#list>-->
|
||||
<table align="center" border="1" width="60%">
|
||||
<tr>
|
||||
<td style="text-align: center;width: 50%;">城市</td>
|
||||
<td style="text-align: center;">可信度</td>
|
||||
</tr>
|
||||
<#list serverAreaList as map>
|
||||
|
||||
<#assign submitId='_submit_button'>
|
||||
<table align="center" border="1" width="60%">
|
||||
<tr>
|
||||
<td style="text-align: center; width: 50%;">
|
||||
<input type="checkbox" id="select_all" /> 全选
|
||||
</td>
|
||||
<td style="text-align: center;">可信度</td>
|
||||
</tr>
|
||||
<#list serverAreaList as map>
|
||||
<tr>
|
||||
<td> <input type="checkbox" id="city_${map['key0'].spell!}" <#if citys??&&(citys?index_of((map['key0'].spell + ",")) gt -1||citys=='all') >checked </#if> value="${map['key0'].display!}" />${map['key0'].display!}</td>
|
||||
<td style="text-align: center;"><input type="text" id="credit_${map['key0'].spell!}" value="${map['key1']!}"/></td>
|
||||
<td>
|
||||
<input type="checkbox" class="city_checkbox" id="city_${map['key0'].spell!}"
|
||||
<#if citys?? && (citys?index_of((map['key0'].spell + ",")) gt -1 || citys == 'all') >checked</#if>
|
||||
value="${map['key0'].display!}" />
|
||||
${map['key0'].display!}
|
||||
</td>
|
||||
<td style="text-align: center;">
|
||||
<input type="text" id="credit_${map['key0'].spell!}" value="${map['key1']!}" />
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
</#list>
|
||||
</table>
|
||||
</#list>
|
||||
</table>
|
||||
<#else>
|
||||
<#assign submitId='_submit_button_all'>
|
||||
<input type="checkbox" <#if citys??&&citys=='all'>checked</#if> id="_checkbox_select_all"/>全选
|
||||
<input type="checkbox" <#if citys?? && citys == 'all'>checked</#if> id="_checkbox_select_all" /> 全选
|
||||
</#if>
|
||||
<br/><br/><br/>
|
||||
<input type="button" id="${submitId!}" value="确定"/>
|
||||
</div>
|
||||
<br /><br /><br />
|
||||
|
||||
<input type="button" id="${submitId!}" value="确定" />
|
||||
</div>
|
||||
|
||||
</div>
|
||||
<script type="text/javascript" src="../js/apiUser/city.js"></script>
|
||||
<script>
|
||||
document.addEventListener('DOMContentLoaded', function () {
|
||||
const urlParams = new URLSearchParams(window.location.search);
|
||||
const filter = urlParams.get('filter') || 'pinyin'; // 默认为拼音
|
||||
|
||||
// 根据 URL 参数设置显示的过滤器
|
||||
if (filter === 'province') {
|
||||
document.getElementById('provinceFilter').style.display = 'block';
|
||||
document.getElementById('pinyinFilter').style.display = 'none';
|
||||
} else {
|
||||
document.getElementById('provinceFilter').style.display = 'none';
|
||||
document.getElementById('pinyinFilter').style.display = 'block';
|
||||
}
|
||||
|
||||
// 切换到按省份筛选
|
||||
document.getElementById('toggleToProvince').addEventListener('click', function () {
|
||||
document.getElementById('provinceFilter').style.display = 'block';
|
||||
document.getElementById('pinyinFilter').style.display = 'none';
|
||||
});
|
||||
|
||||
// 切换到按拼音筛选
|
||||
document.getElementById('toggleToPinyin').addEventListener('click', function () {
|
||||
document.getElementById('provinceFilter').style.display = 'none';
|
||||
document.getElementById('pinyinFilter').style.display = 'block';
|
||||
});
|
||||
|
||||
// 全选复选框点击事件
|
||||
const selectAllCheckbox = document.getElementById('select_all');
|
||||
const cityCheckboxes = document.querySelectorAll('.city_checkbox');
|
||||
|
||||
selectAllCheckbox.addEventListener('change', function () {
|
||||
const isChecked = selectAllCheckbox.checked;
|
||||
cityCheckboxes.forEach(function (checkbox) {
|
||||
checkbox.checked = isChecked;
|
||||
});
|
||||
});
|
||||
|
||||
// 子复选框点击事件,更新全选状态
|
||||
cityCheckboxes.forEach(function (checkbox) {
|
||||
checkbox.addEventListener('change', function () {
|
||||
const allChecked = Array.from(cityCheckboxes).every(cb => cb.checked);
|
||||
selectAllCheckbox.checked = allChecked;
|
||||
});
|
||||
});
|
||||
});
|
||||
</script>
|
||||
|
||||
|
||||
</body>
|
||||
</html>
|
||||
|
||||
Reference in New Issue
Block a user