1、前端页面工具模块手机归属地、实时天气、预报天气功能实现
This commit is contained in:
parent
a88db36285
commit
3cddc54fad
|
|
@ -34,3 +34,33 @@ export function getIdCardQuery(idCard) {
|
|||
method: 'get',
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
//获取手机归属地信息
|
||||
export function getMobileBelong(mobile) {
|
||||
return request({
|
||||
url: '/openapi/apitools/mobilebelong/'+mobile,
|
||||
method: 'get',
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
//获取实时天气信息
|
||||
export function getNowWeather(city) {
|
||||
return request({
|
||||
url: '/openapi/apitools/nowweather/'+city,
|
||||
method: 'get',
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
//获取预报天气信息
|
||||
export function getForecastWeather(city) {
|
||||
return request({
|
||||
url: '/openapi/apitools/forecastweather/'+city,
|
||||
method: 'get',
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -18,8 +18,8 @@
|
|||
v-loading="loading1"
|
||||
placement="bottom"
|
||||
width="400"
|
||||
trigger="manual"
|
||||
v-model="holidayVisible">
|
||||
|
||||
<div v-for="data in holidayData" v-loading="loading1">
|
||||
<span> {{ data.holidayName }} </span>
|
||||
<span> ------ </span>
|
||||
|
|
@ -28,6 +28,8 @@
|
|||
<span>还剩 <span style="color: red">{{ data.residueDays }}</span> 天</span>
|
||||
<el-divider><i class="el-icon-chat-round"></i></el-divider>
|
||||
</div>
|
||||
<el-button @click="close" icon="el-icon-close" circle plain size="mini"
|
||||
style="float: right"></el-button>
|
||||
<el-button type="primary" icon="el-icon-search" size="mini" @click="getHoliday()" slot="reference">
|
||||
搜索
|
||||
</el-button>
|
||||
|
|
@ -44,12 +46,15 @@
|
|||
v-loading="loading2"
|
||||
placement="bottom"
|
||||
width="988"
|
||||
trigger="manual"
|
||||
v-model="beautyPictureVisible">
|
||||
<el-image v-for="data in BeautyPictureData" v-loading="loading2"
|
||||
style="width: 192px; height: 108px"
|
||||
:src="data.imageUrl"
|
||||
:preview-src-list="pictureList">
|
||||
</el-image>
|
||||
<el-button @click="close" icon="el-icon-close" circle plain size="mini"
|
||||
style="float: right"></el-button>
|
||||
<el-button type="primary" icon="el-icon-search" size="mini" @click="getBeautyPicture()"
|
||||
slot="reference">搜索
|
||||
</el-button>
|
||||
|
|
@ -67,6 +72,7 @@
|
|||
v-loading="loading3"
|
||||
placement="right"
|
||||
width="400"
|
||||
trigger="manual"
|
||||
v-model="historyTodayVisible">
|
||||
|
||||
<div v-for="data in historyTodayData" v-loading="loading3">
|
||||
|
|
@ -79,7 +85,8 @@
|
|||
</span>
|
||||
<el-divider><i class="el-icon-chat-round"></i></el-divider>
|
||||
</div>
|
||||
|
||||
<el-button @click="close" icon="el-icon-close" circle plain size="mini"
|
||||
style="float: right"></el-button>
|
||||
<el-button type="primary" icon="el-icon-search" @click="getHistoryToday()" size="mini"
|
||||
slot="reference">搜索
|
||||
</el-button>
|
||||
|
|
@ -98,9 +105,9 @@
|
|||
</el-form-item>
|
||||
<el-form-item>
|
||||
<el-popover
|
||||
v-loading="loading4"
|
||||
placement="bottom"
|
||||
width="300"
|
||||
trigger="manual"
|
||||
v-model="idCardVisible">
|
||||
<el-card shadow="hover" v-loading="loading4">
|
||||
<div style="font-size: 12px">
|
||||
|
|
@ -118,6 +125,8 @@
|
|||
<hr>
|
||||
</div>
|
||||
</el-card>
|
||||
<el-button @click="close" icon="el-icon-close" circle plain size="mini"
|
||||
style="float: right"></el-button>
|
||||
<el-button type="primary" @click="getIdCardQuery('idCardForm')" slot="reference">搜索</el-button>
|
||||
</el-popover>
|
||||
</el-form-item>
|
||||
|
|
@ -137,36 +146,111 @@
|
|||
<el-row>
|
||||
<el-col :span="24">
|
||||
<div class="table2_col">
|
||||
|
||||
<div class="table2_col_div">
|
||||
<el-form :inline="true" class="">
|
||||
<el-form-item label="手机归属地" label-width="100px">
|
||||
<el-input placeholder="请输入手机号码"></el-input>
|
||||
<el-form :inline="true" :rules="rules" :model="mobileBelongForm" ref="mobileBelongForm">
|
||||
<el-form-item label="手机归属地" label-width="100px" prop="mobile">
|
||||
<el-input v-model="mobileBelongForm.mobile" placeholder="请输入手机号码"></el-input>
|
||||
</el-form-item>
|
||||
<el-form-item>
|
||||
<el-button type="primary">搜索</el-button>
|
||||
<el-popover
|
||||
placement="bottom"
|
||||
width="220"
|
||||
trigger="manual"
|
||||
v-model="mobileBelongVisible">
|
||||
<div v-loading="loading5">
|
||||
<el-result icon="info" title="手机归属地" :subTitle="mobileBelongData.carrier">
|
||||
</el-result>
|
||||
</div>
|
||||
<el-button @click="close" icon="el-icon-close" circle plain size="mini"
|
||||
style="float: right"></el-button>
|
||||
<el-button type="primary" slot="reference" @click="getMobileBelong('mobileBelongForm')">搜索</el-button>
|
||||
</el-popover>
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
</div>
|
||||
|
||||
<div class="table2_col_div">
|
||||
<el-form :inline="true" class="">
|
||||
<el-form-item label="实时天气" label-width="100px">
|
||||
<el-input placeholder="请输入城市名称"></el-input>
|
||||
<el-form :inline="true" :rules="rules" :model="nowWeatherForm" ref="nowWeatherForm">
|
||||
<el-form-item label="实时天气" label-width="100px" prop="city">
|
||||
<el-input v-model="nowWeatherForm.city" placeholder="请输入城市名称"></el-input>
|
||||
</el-form-item>
|
||||
<el-form-item>
|
||||
<el-button type="primary">搜索</el-button>
|
||||
<el-popover
|
||||
placement="bottom"
|
||||
width="250"
|
||||
trigger="manual"
|
||||
v-model="nowWeatherVisible">
|
||||
<div v-loading="loading6">
|
||||
<span>地理位置:{{ nowWeatherData.address }}</span><br>
|
||||
<span>空气湿度:<span style="color: red">{{ nowWeatherData.humidity }}</span></span><br>
|
||||
<span>实时温度:<span style="color: red">{{ nowWeatherData.temp }}</span></span><br>
|
||||
<span>实时风力:{{ nowWeatherData.winddirection }} {{ nowWeatherData.windpower }}</span><br>
|
||||
<span>
|
||||
<img :src="weather"
|
||||
style="width: 30px;height: 30px;float: left;">
|
||||
<span style="margin-left:40px;float: left;width: 30px;height: 30px; line-height: 30px;color: red">{{
|
||||
nowWeatherData.weather
|
||||
}}</span>
|
||||
</span>
|
||||
</div>
|
||||
<el-button @click="close" icon="el-icon-close" circle plain size="mini"
|
||||
style="float: right"></el-button>
|
||||
<el-button type="primary" slot="reference" @click="getNowWeather('nowWeatherForm')">搜索</el-button>
|
||||
</el-popover>
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
</div>
|
||||
|
||||
<div class="table2_col_div">
|
||||
<el-form :inline="true" class="">
|
||||
<el-form-item label="预报天气" label-width="100px">
|
||||
<el-input placeholder="请输入城市名称"></el-input>
|
||||
<el-form :inline="true" :rules="rules" :model="forecastWeatherForm" ref="forecastWeatherForm">
|
||||
<el-form-item label="预报天气" label-width="100px" prop="city">
|
||||
<el-input v-model="forecastWeatherForm.city" placeholder="请输入城市名称"></el-input>
|
||||
</el-form-item>
|
||||
<el-form-item>
|
||||
<el-button type="primary">搜索</el-button>
|
||||
<el-popover
|
||||
placement="left"
|
||||
width="300"
|
||||
trigger="manual"
|
||||
v-model="forecastWeatherVisible">
|
||||
<div v-loading="loading7">
|
||||
<el-card shadow="hover">
|
||||
<div slot="header" class="clearfix">
|
||||
<span>{{ forecastWeatherData.address }}</span>
|
||||
</div>
|
||||
<div v-for="(data,index) in forecastWeatherData.forecasts">
|
||||
<ul style="margin: 0 0; padding: 0 0 0 10px; list-style-type: none">
|
||||
<li>
|
||||
<span v-if="index===0">
|
||||
今天({{data.dayOfWeek}})
|
||||
</span>
|
||||
<span v-if="index===1">
|
||||
明天({{data.dayOfWeek}})
|
||||
</span>
|
||||
<span v-if="index===2">
|
||||
后天({{data.dayOfWeek}})
|
||||
</span>
|
||||
<span v-if="index===3">
|
||||
大后({{data.dayOfWeek}})
|
||||
</span>
|
||||
|
||||
<span style="color: red;margin-left: 10px;margin-right: 10px">
|
||||
{{data.nighttemp}}~{{data.daytemp}}
|
||||
</span>
|
||||
<span>
|
||||
{{data.dayweather}}
|
||||
</span>
|
||||
</li>
|
||||
</ul>
|
||||
<hr>
|
||||
</div>
|
||||
</el-card>
|
||||
</div>
|
||||
<el-button @click="close" icon="el-icon-close" circle plain size="mini"
|
||||
style="float: right"></el-button>
|
||||
<el-button type="primary" slot="reference"
|
||||
@click="getForecastWeather('forecastWeatherForm')">搜索
|
||||
</el-button>
|
||||
</el-popover>
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
</div>
|
||||
|
|
@ -213,7 +297,17 @@
|
|||
|
||||
<script>
|
||||
|
||||
import {getHoliday, getHistoryToday, getBeautyPicture, getIdCardQuery} from "@/api/business/openapi/apitools";
|
||||
import {
|
||||
getHoliday,
|
||||
getHistoryToday,
|
||||
getBeautyPicture,
|
||||
getIdCardQuery,
|
||||
getMobileBelong,
|
||||
getNowWeather,
|
||||
getForecastWeather,
|
||||
} from "@/api/business/openapi/apitools";
|
||||
|
||||
import weather from "@/assets/icons/weather/天气.png"
|
||||
|
||||
export default {
|
||||
name: "Apitools",
|
||||
|
|
@ -226,12 +320,24 @@ export default {
|
|||
pictureList: [], //单独存放图片路径
|
||||
historyTodayData: [],
|
||||
idCardData: {},
|
||||
mobileBelongData: {},
|
||||
nowWeatherData: {},
|
||||
forecastWeatherData: {},
|
||||
|
||||
|
||||
//-------------input框数据-------------------
|
||||
idCardForm: {
|
||||
idCard: ''
|
||||
},
|
||||
mobileBelongForm: {
|
||||
mobile: ''
|
||||
},
|
||||
nowWeatherForm: {
|
||||
city: ''
|
||||
},
|
||||
forecastWeatherForm: {
|
||||
city: ''
|
||||
},
|
||||
|
||||
|
||||
//------------控制弹出显示隐藏-----------------
|
||||
|
|
@ -239,6 +345,9 @@ export default {
|
|||
beautyPictureVisible: false,
|
||||
historyTodayVisible: false,
|
||||
idCardVisible: false,
|
||||
mobileBelongVisible: false,
|
||||
nowWeatherVisible: false,
|
||||
forecastWeatherVisible: false,
|
||||
|
||||
|
||||
//----------------遮罩层-------------------
|
||||
|
|
@ -246,16 +355,33 @@ export default {
|
|||
loading2: false,
|
||||
loading3: false,
|
||||
loading4: false,
|
||||
loading5: false,
|
||||
loading6: false,
|
||||
loading7: false,
|
||||
loading8: false,
|
||||
loading9: false,
|
||||
loading10: false,
|
||||
|
||||
|
||||
//---------------校验规则--------------------
|
||||
rules: {
|
||||
idCard: [
|
||||
{required: true, message: '请输入身份证号!!!', trigger: 'blur'},
|
||||
{required: true, validator: this.validatorIdNum, trigger: 'blur'},
|
||||
],
|
||||
}
|
||||
mobile: [
|
||||
{required: true, message: '请输入手机号码!!!', trigger: 'blur'},
|
||||
{required: true, validator: this.validatorPhone, trigger: 'blur'},
|
||||
],
|
||||
city: [
|
||||
{required: true, message: '请输入地名!!!', trigger: 'blur'},
|
||||
]
|
||||
|
||||
},
|
||||
|
||||
|
||||
//----------------其他参数-------------------
|
||||
weather,
|
||||
}
|
||||
},
|
||||
|
||||
|
|
@ -265,10 +391,105 @@ export default {
|
|||
,
|
||||
|
||||
methods: {
|
||||
//获取预报天气信息
|
||||
getForecastWeather(forecastWeatherForm) {
|
||||
this.$refs[forecastWeatherForm].validate((valid) => {
|
||||
this.forecastWeatherData = {}
|
||||
if (valid) {
|
||||
this.loading7 = true
|
||||
getForecastWeather(this.forecastWeatherForm.city).then(res => {
|
||||
this.loading7 = false
|
||||
this.forecastWeatherVisible = true
|
||||
this.forecastWeatherData = res.data
|
||||
}).catch(err => {
|
||||
this.loading7 = false
|
||||
})
|
||||
} else {
|
||||
return false
|
||||
}
|
||||
})
|
||||
|
||||
|
||||
},
|
||||
|
||||
//获取实时天气信息
|
||||
getNowWeather(nowWeatherForm) {
|
||||
this.$refs[nowWeatherForm].validate((valid) => {
|
||||
this.nowWeatherData = {}
|
||||
if (valid) {
|
||||
this.loading6 = true
|
||||
getNowWeather(this.nowWeatherForm.city).then(res => {
|
||||
this.loading6 = false
|
||||
this.nowWeatherVisible = true
|
||||
this.nowWeatherData = res.data
|
||||
}).catch(err => {
|
||||
this.loading6 = false
|
||||
})
|
||||
} else {
|
||||
return false
|
||||
}
|
||||
})
|
||||
},
|
||||
|
||||
//自定义rules校验方法:手机号校验
|
||||
validatorPhone(rule, value, callback) {
|
||||
if (value === '') {
|
||||
callback(new Error('手机号不能为空'))
|
||||
} else if (!/^1\d{10}$/.test(value)) {
|
||||
callback(new Error('手机号格式错误'))
|
||||
} else {
|
||||
callback()
|
||||
}
|
||||
},
|
||||
|
||||
//自定义rules校验方法:身份证校验
|
||||
validatorIdNum(rule, value, callback) {
|
||||
const reg = /(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/
|
||||
if (!value) {
|
||||
return callback(new Error('证件号码不能为空'))
|
||||
} else if (!reg.test(value)) {
|
||||
return callback(new Error('证件号码不正确'))
|
||||
} else {
|
||||
callback()
|
||||
}
|
||||
},
|
||||
|
||||
//关闭窗口
|
||||
close() {
|
||||
this.mobileBelongVisible = false;
|
||||
this.idCardVisible = false;
|
||||
this.historyTodayVisible = false;
|
||||
this.beautyPictureVisible = false;
|
||||
this.holidayVisible = false;
|
||||
this.nowWeatherVisible = false;
|
||||
this.forecastWeatherVisible = false;
|
||||
},
|
||||
|
||||
//获取手机归属地信息
|
||||
getMobileBelong(mobileBelongForm) {
|
||||
this.$refs[mobileBelongForm].validate((valid) => {
|
||||
this.mobileBelongData = {}
|
||||
if (valid) {
|
||||
this.mobileBelongVisible = true
|
||||
this.loading5 = true
|
||||
getMobileBelong(this.mobileBelongForm.mobile).then(res => {
|
||||
this.loading5 = false
|
||||
this.mobileBelongData = res.data
|
||||
}).catch(err => {
|
||||
this.loading5 = false
|
||||
})
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
//获取身份证信息
|
||||
getIdCardQuery(idCardForm) {
|
||||
this.$refs[idCardForm].validate((valid) => {
|
||||
this.idCardData = {}
|
||||
if (valid) {
|
||||
this.idCardVisible = true
|
||||
this.loading4 = true
|
||||
getIdCardQuery(this.idCardForm.idCard).then(res => {
|
||||
this.loading4 = false
|
||||
|
|
@ -280,37 +501,37 @@ export default {
|
|||
return false;
|
||||
}
|
||||
});
|
||||
}
|
||||
,
|
||||
},
|
||||
|
||||
//获取历史今天数据信息
|
||||
getHistoryToday() {
|
||||
this.loading3 = true
|
||||
this.historyTodayVisible = true
|
||||
getHistoryToday().then(res => {
|
||||
this.loading3 = false
|
||||
this.historyTodayData = res.data
|
||||
}).catch(err => {
|
||||
this.loading3 = false
|
||||
})
|
||||
}
|
||||
,
|
||||
},
|
||||
|
||||
//获取节假日信息
|
||||
getHoliday() {
|
||||
this.loading1 = true
|
||||
this.holidayVisible = true
|
||||
getHoliday().then(res => {
|
||||
this.loading1 = false
|
||||
this.holidayData = res.data
|
||||
}).catch(err => {
|
||||
this.loading3 = false
|
||||
})
|
||||
}
|
||||
,
|
||||
},
|
||||
|
||||
//获取mm图片信息
|
||||
getBeautyPicture() {
|
||||
this.loading2 = true
|
||||
this.pictureList = []
|
||||
this.beautyPictureVisible = true
|
||||
getBeautyPicture().then(res => {
|
||||
this.loading2 = false
|
||||
this.BeautyPictureData = res.data
|
||||
|
|
@ -321,8 +542,7 @@ export default {
|
|||
}).catch(err => {
|
||||
this.loading3 = false
|
||||
})
|
||||
}
|
||||
,
|
||||
},
|
||||
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,37 @@
|
|||
package com.xjs.utils;
|
||||
|
||||
/**
|
||||
* 星期处理工具类
|
||||
* @author xiejs
|
||||
* @since 2022-01-21
|
||||
*/
|
||||
public class WeekUtils {
|
||||
|
||||
public static String weekConvert(String week) {
|
||||
switch (week) {
|
||||
case "1":
|
||||
week="周一";
|
||||
break;
|
||||
case "2":
|
||||
week="周二";
|
||||
break;
|
||||
case "3":
|
||||
week="周三";
|
||||
break;
|
||||
case "4":
|
||||
week="周四";
|
||||
break;
|
||||
case "5":
|
||||
week="周五";
|
||||
break;
|
||||
case "6":
|
||||
week="周六";
|
||||
break;
|
||||
case "7":
|
||||
week="周日";
|
||||
break;
|
||||
}
|
||||
return week;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -43,11 +43,11 @@ public class ApiToolsController {
|
|||
}
|
||||
|
||||
|
||||
@GetMapping("mobilebelong")
|
||||
@GetMapping("mobilebelong/{mobile}")
|
||||
@ApiOperation("获取手机归属地信息")
|
||||
@Log(title = "获取手机归属地")
|
||||
@RequiresPermissions("open:apitools:mobilebelong")
|
||||
public R<ApiMobileBelong> getMobileBelongApiData(@RequestParam(name = "mobile") String mobile) {
|
||||
public R<ApiMobileBelong> getMobileBelongApiData(@PathVariable("mobile") String mobile) {
|
||||
boolean matches = Pattern.matches(MOBILE_REGEX, mobile);
|
||||
if (!matches) {
|
||||
return R.fail("请输入正确的手机号码!!!");
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@ import com.xjs.apitools.factory.ApiToolsFactory;
|
|||
import com.xjs.apitools.factory.impl.*;
|
||||
import com.xjs.apitools.service.ApiToolsService;
|
||||
import com.xjs.exception.ApiException;
|
||||
import com.xjs.utils.WeekUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
|
@ -18,7 +19,6 @@ import java.math.BigDecimal;
|
|||
import java.math.RoundingMode;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
|
|
@ -33,7 +33,7 @@ public class ApiToolsServiceImpl implements ApiToolsService {
|
|||
/**
|
||||
* 文件单位
|
||||
*/
|
||||
public static final String KB= "KB";
|
||||
public static final String KB = "KB";
|
||||
|
||||
private ApiToolsFactory<ApiHoliday, Object> holidayFactory;
|
||||
private ApiToolsFactory<ApiMobileBelong, RequestBody> mobileBelongFactory;
|
||||
|
|
@ -41,19 +41,19 @@ public class ApiToolsServiceImpl implements ApiToolsService {
|
|||
private ApiToolsFactory<ApiForecastWeather, RequestBody> forecastWeatherFactory;
|
||||
private ApiToolsFactory<ApiGarbageSorting, RequestBody> garbageSortingFactory;
|
||||
private ApiToolsFactory<ApiBeautyPicture, Object> beautyPictureFactory;
|
||||
private ApiToolsFactory<ApiHistoryToday,Object> historyTodayFactory;
|
||||
private ApiToolsFactory<ApiHistoryToday, Object> historyTodayFactory;
|
||||
|
||||
@Autowired
|
||||
@Qualifier("rollSimpleComplexFactory")
|
||||
private ApiToolsFactory<ApiSimpleComplex,RequestBody> simpleComplexFactory;
|
||||
private ApiToolsFactory<ApiSimpleComplex, RequestBody> simpleComplexFactory;
|
||||
|
||||
@Autowired
|
||||
@Qualifier("rollChineseDictFactory")
|
||||
private ApiToolsFactory<ApiChineseDict,RequestBody> chineseDictFactory;
|
||||
private ApiToolsFactory<ApiChineseDict, RequestBody> chineseDictFactory;
|
||||
|
||||
@Autowired
|
||||
@Qualifier("rollIdcardQueryFactory")
|
||||
private ApiToolsFactory<ApiIdcardQuery,RequestBody> idcardQueryFactory;
|
||||
private ApiToolsFactory<ApiIdcardQuery, RequestBody> idcardQueryFactory;
|
||||
|
||||
@Autowired
|
||||
public void setHolidayFactory(RollHolidayFactory rollHolidayFactory) {
|
||||
|
|
@ -94,7 +94,9 @@ public class ApiToolsServiceImpl implements ApiToolsService {
|
|||
@Override
|
||||
public List<ApiHoliday> getApiHolidayList() {
|
||||
List<ApiHoliday> apiHolidayList = holidayFactory.apiDataList();
|
||||
Optional.ofNullable(apiHolidayList).orElseThrow(ApiException::new);
|
||||
if (CollUtil.isEmpty(apiHolidayList)) {
|
||||
throw new ApiException("获取的节假日数据为空");
|
||||
}
|
||||
List<ApiHoliday> collect = apiHolidayList.stream().map(holidayFactory -> {
|
||||
if (holidayFactory.getResidueDays() >= 0) {
|
||||
if (holidayFactory.getLunarHoliday()) {
|
||||
|
|
@ -102,7 +104,7 @@ public class ApiToolsServiceImpl implements ApiToolsService {
|
|||
DateTime lunarDate = DateUtil.parseDate(holidayFactory.getLunarDate());
|
||||
ChineseDate chineseDate = new ChineseDate(lunarDate.toJdkDate());
|
||||
holidayFactory.setReturnDate(chineseDate.toString());
|
||||
}else {
|
||||
} else {
|
||||
holidayFactory.setReturnDate(holidayFactory.getDate());
|
||||
}
|
||||
return holidayFactory;
|
||||
|
|
@ -118,47 +120,65 @@ public class ApiToolsServiceImpl implements ApiToolsService {
|
|||
public ApiMobileBelong getApiMobileBelong(String mobile) {
|
||||
RequestBody requestBody = new RequestBody();
|
||||
requestBody.setMobile(mobile);
|
||||
return Optional.ofNullable(mobileBelongFactory.apiData(requestBody))
|
||||
.orElseThrow(ApiException::new);
|
||||
ApiMobileBelong apiMobileBelong = mobileBelongFactory.apiData(requestBody);
|
||||
if (Objects.isNull(apiMobileBelong)) {
|
||||
throw new ApiException("获取的手机归属地数据为空");
|
||||
}
|
||||
if (StringUtils.isEmpty(apiMobileBelong.getCarrier())) {
|
||||
apiMobileBelong.setCarrier("未找到,请重试");
|
||||
}
|
||||
return apiMobileBelong;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ApiNowWeather getNowWeather(String city) {
|
||||
RequestBody requestBody = new RequestBody();
|
||||
requestBody.setCity(city);
|
||||
return Optional.ofNullable(nowWeatherFactory.apiData(requestBody))
|
||||
.orElseThrow(ApiException::new);
|
||||
ApiNowWeather apiNowWeather = nowWeatherFactory.apiData(requestBody);
|
||||
if (Objects.isNull(apiNowWeather)) {
|
||||
throw new ApiException("获取的实时天气数据为空");
|
||||
}
|
||||
return apiNowWeather;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ApiForecastWeather getForecastWeather(String city) {
|
||||
RequestBody requestBody = new RequestBody();
|
||||
requestBody.setCity(city);
|
||||
return Optional.ofNullable(forecastWeatherFactory.apiData(requestBody))
|
||||
.orElseThrow(ApiException::new);
|
||||
ApiForecastWeather forecastWeather = forecastWeatherFactory.apiData(requestBody);
|
||||
if (Objects.isNull(forecastWeather)) {
|
||||
throw new ApiException("获取的预报天气数据为空");
|
||||
}
|
||||
this.weekConvert(forecastWeather);
|
||||
return forecastWeather;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ApiGarbageSorting getGarbageSorting(String name) {
|
||||
RequestBody requestBody = new RequestBody();
|
||||
requestBody.setName(name);
|
||||
return Optional.ofNullable(garbageSortingFactory.apiData(requestBody))
|
||||
.orElseThrow(ApiException::new);
|
||||
ApiGarbageSorting garbageSorting = garbageSortingFactory.apiData(requestBody);
|
||||
if (Objects.isNull(garbageSorting)) {
|
||||
throw new ApiException("获取的垃圾分类数据为空");
|
||||
}
|
||||
return garbageSorting;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ApiBeautyPicture> getBeautyPictureList() {
|
||||
List<ApiBeautyPicture> beautyPictureList = Optional.ofNullable(beautyPictureFactory.apiDataList())
|
||||
.orElseThrow(ApiException::new);
|
||||
beautyPictureList.forEach(bp ->{
|
||||
List<ApiBeautyPicture> apiBeautyPictureList = beautyPictureFactory.apiDataList();
|
||||
if (CollUtil.isEmpty(apiBeautyPictureList)) {
|
||||
throw new ApiException("获取的mm图片数据为空");
|
||||
}
|
||||
apiBeautyPictureList.forEach(bp -> {
|
||||
String imageFileLength = bp.getImageFileLength();
|
||||
if (StringUtils.isNotEmpty(imageFileLength)) {
|
||||
BigDecimal decimal = new BigDecimal(imageFileLength);
|
||||
BigDecimal divide = decimal.divide(new BigDecimal(1024), 0, RoundingMode.HALF_UP);
|
||||
bp.setImageFileLength(divide.toPlainString()+KB);
|
||||
bp.setImageFileLength(divide.toPlainString() + KB);
|
||||
}
|
||||
});
|
||||
return beautyPictureList;
|
||||
return apiBeautyPictureList;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -166,7 +186,7 @@ public class ApiToolsServiceImpl implements ApiToolsService {
|
|||
List<ApiHistoryToday> historyTodayList = historyTodayFactory.apiDataList();
|
||||
if (CollUtil.isNotEmpty(historyTodayList)) {
|
||||
return historyTodayList.stream().limit(7).collect(Collectors.toList());
|
||||
}else {
|
||||
} else {
|
||||
throw new ApiException("获取历史上的今天api调用异常!!!");
|
||||
}
|
||||
}
|
||||
|
|
@ -175,23 +195,47 @@ public class ApiToolsServiceImpl implements ApiToolsService {
|
|||
public ApiSimpleComplex getSimpleComplex(String content) {
|
||||
RequestBody requestBody = new RequestBody();
|
||||
requestBody.setContent(content);
|
||||
return simpleComplexFactory.apiData(requestBody);
|
||||
ApiSimpleComplex apiSimpleComplex = simpleComplexFactory.apiData(requestBody);
|
||||
if (Objects.isNull(apiSimpleComplex)) {
|
||||
throw new ApiException("获取的简繁转换数据为空");
|
||||
}
|
||||
return apiSimpleComplex;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ApiChineseDict getChineseDict(String content) {
|
||||
RequestBody requestBody = new RequestBody();
|
||||
requestBody.setContent(content);
|
||||
return chineseDictFactory.apiData(requestBody);
|
||||
|
||||
ApiChineseDict chineseDict = chineseDictFactory.apiData(requestBody);
|
||||
if (Objects.isNull(chineseDict)) {
|
||||
throw new ApiException("获取的汉语字典数据为空");
|
||||
}
|
||||
return chineseDict;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ApiIdcardQuery getIdcardQuery(String idcard) {
|
||||
RequestBody requestBody = new RequestBody();
|
||||
requestBody.setIdcard(idcard);
|
||||
return idcardQueryFactory.apiData(requestBody);
|
||||
ApiIdcardQuery apiIdcardQuery = idcardQueryFactory.apiData(requestBody);
|
||||
if (Objects.isNull(apiIdcardQuery)) {
|
||||
throw new ApiException("获取的身份证数据为空");
|
||||
}
|
||||
return apiIdcardQuery;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* week类型转换
|
||||
*/
|
||||
private void weekConvert(ApiForecastWeather weather) {
|
||||
List<Forecasts> forecastsList = weather.getForecasts();
|
||||
forecastsList.forEach(forecasts -> {
|
||||
String week = WeekUtils.weekConvert(forecasts.getDayOfWeek());
|
||||
forecasts.setDayOfWeek(week);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,6 +4,8 @@ import com.ruoyi.common.core.domain.R;
|
|||
import com.ruoyi.common.core.web.domain.AjaxResult;
|
||||
import com.ruoyi.common.log.annotation.Log;
|
||||
import com.ruoyi.common.security.annotation.RequiresLogin;
|
||||
import com.xjs.utils.WeekUtils;
|
||||
import com.xjs.weather.domain.Casts;
|
||||
import com.xjs.weather.domain.ForecastWeather;
|
||||
import com.xjs.weather.domain.NowWeather;
|
||||
import com.xjs.weather.service.WeatherService;
|
||||
|
|
@ -15,6 +17,7 @@ import org.springframework.web.bind.annotation.GetMapping;
|
|||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
|
|
@ -64,32 +67,11 @@ public class WeatherController {
|
|||
* week类型转换
|
||||
*/
|
||||
private void weekConvert(ForecastWeather forecastWeather) {
|
||||
forecastWeather.getCasts().forEach(cast -> {
|
||||
switch (cast.getWeek()) {
|
||||
case "1":
|
||||
cast.setWeek("周一");
|
||||
break;
|
||||
case "2":
|
||||
cast.setWeek("周二");
|
||||
break;
|
||||
case "3":
|
||||
cast.setWeek("周三");
|
||||
break;
|
||||
case "4":
|
||||
cast.setWeek("周四");
|
||||
break;
|
||||
case "5":
|
||||
cast.setWeek("周五");
|
||||
break;
|
||||
case "6":
|
||||
cast.setWeek("周六");
|
||||
break;
|
||||
case "7":
|
||||
cast.setWeek("周日");
|
||||
break;
|
||||
}
|
||||
List<Casts> casts = forecastWeather.getCasts();
|
||||
casts.forEach(cast -> {
|
||||
String week = WeekUtils.weekConvert(cast.getWeek());
|
||||
cast.setWeek(week);
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue