Commit 0795da14 by 111-PC\111

[+]数据风控模块修改

1 parent a33cc9ce
...@@ -87,6 +87,9 @@ public class ChannelRiskDataController { ...@@ -87,6 +87,9 @@ public class ChannelRiskDataController {
@GetMapping("/findTimeInstallSheet") @GetMapping("/findTimeInstallSheet")
@ApiOperation(value = "查询省市区的每月安装单数") @ApiOperation(value = "查询省市区的每月安装单数")
public R findTimeInstallSheet(@RequestParam(required = false) String channelName, @RequestParam(required = false) String proviceName, @RequestParam(required = false) String cityName, @RequestParam(required = false) String timeRange) { public R findTimeInstallSheet(@RequestParam(required = false) String channelName, @RequestParam(required = false) String proviceName, @RequestParam(required = false) String cityName, @RequestParam(required = false) String timeRange) {
if (StringUtils.isEmpty(timeRange)) {
return R.error("请求参数错误,isExcep必传字段");
}
List<Map<String, String>> map = channelRiskDataService.findTimeInstallSheet(channelName, proviceName, cityName, timeRange); List<Map<String, String>> map = channelRiskDataService.findTimeInstallSheet(channelName, proviceName, cityName, timeRange);
return R.ok().data(map); return R.ok().data(map);
} }
......
...@@ -14,6 +14,9 @@ import org.springframework.stereotype.Service; ...@@ -14,6 +14,9 @@ import org.springframework.stereotype.Service;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Calendar;
import java.util.Collections;
import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.stream.Collectors; import java.util.stream.Collectors;
...@@ -61,13 +64,12 @@ public class ChannelRiskDataService { ...@@ -61,13 +64,12 @@ public class ChannelRiskDataService {
*/ */
public List<Map<String, String>> findRegInstallSheet(String channelName, String proviceName, String cityName, String timeRange) { public List<Map<String, String>> findRegInstallSheet(String channelName, String proviceName, String cityName, String timeRange) {
List<Map<String, String>> map = new ArrayList<>(); List<Map<String, String>> map = new ArrayList<>();
String monthNum = converMonthNum(timeRange);
if (StringUtils.isEmpty(proviceName) && StringUtils.isEmpty(cityName)) { if (StringUtils.isEmpty(proviceName) && StringUtils.isEmpty(cityName)) {
map = channelRiskDataMapper.findProInstallSheet(monthNum, channelName); map = channelRiskDataMapper.findProInstallSheet(timeRange, channelName);
} else if (StringUtils.isNotEmpty(proviceName)) { } else if (StringUtils.isNotEmpty(proviceName)) {
map = channelRiskDataMapper.findCityInstallSheet(proviceName, monthNum, channelName); map = channelRiskDataMapper.findCityInstallSheet(proviceName, timeRange, channelName);
} else if (StringUtils.isNotEmpty(cityName)) { } else if (StringUtils.isNotEmpty(cityName)) {
map = channelRiskDataMapper.findZoneInstallSheet(cityName, monthNum, channelName); map = channelRiskDataMapper.findZoneInstallSheet(cityName, timeRange, channelName);
} }
return map; return map;
} }
...@@ -81,16 +83,61 @@ public class ChannelRiskDataService { ...@@ -81,16 +83,61 @@ public class ChannelRiskDataService {
* @return List<Map < String, String>> * @return List<Map < String, String>>
*/ */
public List<Map<String, String>> findTimeInstallSheet(String channelName, String proviceName, String cityName, String timeRange) { public List<Map<String, String>> findTimeInstallSheet(String channelName, String proviceName, String cityName, String timeRange) {
List<Map<String, String>> map = new ArrayList<>(); List<Map<String, String>> finalMap = new ArrayList<>();
String monthNum = converMonthNum(timeRange); List<Map<String, String>> resultmap = new ArrayList<>();
//获取当前月份前多少个月
List<String> list = getMonthList(timeRange);
if (StringUtils.isEmpty(proviceName) && StringUtils.isEmpty(cityName)) { if (StringUtils.isEmpty(proviceName) && StringUtils.isEmpty(cityName)) {
map = channelRiskDataMapper.findTimeInstallSheet(monthNum, channelName); resultmap = channelRiskDataMapper.findTimeInstallSheet(timeRange, channelName);
} else if (StringUtils.isNotEmpty(proviceName)) { } else if (StringUtils.isNotEmpty(proviceName)) {
map = channelRiskDataMapper.findProTimeInstallSheet(proviceName, monthNum, channelName); resultmap = channelRiskDataMapper.findProTimeInstallSheet(proviceName, timeRange, channelName);
} else if (StringUtils.isNotEmpty(cityName)) { } else if (StringUtils.isNotEmpty(cityName)) {
map = channelRiskDataMapper.findCityTimeInstallSheet(cityName, monthNum, channelName); resultmap = channelRiskDataMapper.findCityTimeInstallSheet(cityName, timeRange, channelName);
} }
return map; List<String> xAxislist = resultmap.stream().map(index -> index.get("xAxis")).collect(Collectors.toList());
//添加没有值的月份并排序
List<Map<String, String>> finalResultmap = resultmap;
list.forEach(index->{
Map<String,String> defaultValue=new HashMap<>();
defaultValue.put("xAxis",index);
if(!xAxislist.contains(index)){
defaultValue.put("value","0");
}else{
finalResultmap.forEach(item->{
String xAxis = item.get("xAxis");
if(xAxis.equals(index)){
defaultValue.put("value",item.get("value"));
}
});
}
finalMap.add(defaultValue);
});
return finalMap;
}
/**
* 或者当前月份前多少个月
*
* @param timeRange
* @return
*/
public List<String> getMonthList(String timeRange) {
List<String> list = new ArrayList<>();
Calendar cal = Calendar.getInstance();
int month = cal.get(Calendar.MONTH) + 1 + 1;
int year = cal.get(Calendar.YEAR);
for (int i = 0; i < Integer.parseInt(timeRange); i++) {
month--;
if (month > 0) {
list.add(year + "年" + month + "月");
} else {
month = 12;
year--;
list.add(year + "年" + month + "月");
}
}
Collections.reverse(list);
return list;
} }
/** /**
...@@ -139,19 +186,4 @@ public class ChannelRiskDataService { ...@@ -139,19 +186,4 @@ public class ChannelRiskDataService {
return list; return list;
} }
/**
* 转化日期
*
* @param timeRange 日期范围
* @return String
*/
public String converMonthNum(String timeRange) {
String monthNum = null;
if (Constants.ONE_YEAR.equals(timeRange)) {
monthNum = "12";
} else if (Constants.HALF_YEAR.equals(timeRange)) {
monthNum = "6";
}
return monthNum;
}
} }
...@@ -86,7 +86,7 @@ ...@@ -86,7 +86,7 @@
<select id="findTimeInstallSheet" resultType="java.util.Map"> <select id="findTimeInstallSheet" resultType="java.util.Map">
select select
concat(DATE_FORMAT(gps_time,'%m'),'月份') as xAxis, DATE_FORMAT(gps_time,'%Y年%c月') as xAxis,
count(id) as value count(id) as value
from t_channel_risk_data from t_channel_risk_data
where type=0 where type=0
...@@ -96,12 +96,12 @@ ...@@ -96,12 +96,12 @@
<if test="channelName !=null and channelName !=''"> <if test="channelName !=null and channelName !=''">
and shop_name=#{channelName} and shop_name=#{channelName}
</if> </if>
group by xAxis group by xAxis ORDER BY gps_time
</select> </select>
<select id="findProTimeInstallSheet" resultType="java.util.Map"> <select id="findProTimeInstallSheet" resultType="java.util.Map">
select select
concat(DATE_FORMAT(gps_time,'%m'),'月份') as xAxis, DATE_FORMAT(gps_time,'%Y年%c月') as xAxis,
count(id) as value count(id) as value
from t_channel_risk_data from t_channel_risk_data
where type=0 where type=0
...@@ -112,12 +112,12 @@ ...@@ -112,12 +112,12 @@
and shop_name=#{channelName} and shop_name=#{channelName}
</if> </if>
and prov=#{proviceName} and prov=#{proviceName}
group by xAxis group by xAxis ORDER BY gps_time
</select> </select>
<select id="findCityTimeInstallSheet" resultType="java.util.Map"> <select id="findCityTimeInstallSheet" resultType="java.util.Map">
select select
concat(DATE_FORMAT(gps_time,'%m'),'月份') as xAxis, DATE_FORMAT(gps_time,'%Y年%c月') as xAxis,
count(id) as value count(id) as value
from t_channel_risk_data from t_channel_risk_data
where type=0 where type=0
...@@ -128,7 +128,7 @@ ...@@ -128,7 +128,7 @@
and shop_name=#{channelName} and shop_name=#{channelName}
</if> </if>
and city=#{cityName} and city=#{cityName}
group by xAxis group by xAxis ORDER BY gps_time
</select> </select>
<select id="findOutletsData" resultType="java.util.Map"> <select id="findOutletsData" resultType="java.util.Map">
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!