1. 心知天气
2. 设备改成是否展示默认
This commit is contained in:
parent
82e881ce1b
commit
d79ce1469b
|
@ -93,7 +93,7 @@ public class SysLoginController
|
|||
public AjaxResult getAppInfo()
|
||||
{
|
||||
AsUser user = SecurityUtils.getLoginUser().getAsUser();
|
||||
List<AsDevice> asDevices = asUserService.selectDeviceInfoByUser(user.getUserId(), null);
|
||||
List<AsDevice> asDevices = asUserService.selectDeviceInfoByUser(user.getUserId(),null);
|
||||
if(ObjectUtils.isNotEmpty(asDevices) && asDevices.size()!=0){
|
||||
user.setDeviceId(asDevices.get(0).getDeviceId());
|
||||
}
|
||||
|
|
|
@ -198,3 +198,5 @@ qiniu:
|
|||
expireSeconds: 600
|
||||
# 七牛云GET请求域名
|
||||
domain: https://lxnapi.ccttiot.com
|
||||
xinzhi:
|
||||
secretKey: SUhjj5BYa4pUe0o3D
|
||||
|
|
|
@ -17,6 +17,13 @@
|
|||
|
||||
<dependencies>
|
||||
|
||||
<!--中文转拼音-->
|
||||
<dependency>
|
||||
<groupId>com.belerweb</groupId>
|
||||
<artifactId>pinyin4j</artifactId>
|
||||
<version>2.5.0</version>
|
||||
</dependency>
|
||||
|
||||
<!-- 七牛云上传 -->
|
||||
<dependency>
|
||||
<groupId>com.qiniu</groupId>
|
||||
|
|
|
@ -0,0 +1,53 @@
|
|||
package com.ruoyi.common.utils.pinyin;
|
||||
|
||||
import net.sourceforge.pinyin4j.PinyinHelper;
|
||||
|
||||
public class PinyinUtils {
|
||||
|
||||
public static void main(String[] args) {
|
||||
String input = "你好,世界!";
|
||||
// 设置不带声调的输出选项
|
||||
net.sourceforge.pinyin4j.format.HanyuPinyinOutputFormat format = new net.sourceforge.pinyin4j.format.HanyuPinyinOutputFormat();
|
||||
format.setToneType(net.sourceforge.pinyin4j.format.HanyuPinyinToneType.WITHOUT_TONE);
|
||||
|
||||
StringBuilder output = new StringBuilder();
|
||||
for (char c : input.toCharArray()) {
|
||||
try {
|
||||
String[] pinyinArray = PinyinHelper.toHanyuPinyinStringArray(c, format);
|
||||
if (pinyinArray != null && pinyinArray.length > 0) {
|
||||
output.append(pinyinArray[0]).append(" ");
|
||||
} else {
|
||||
output.append(c).append(" ");
|
||||
}
|
||||
} catch (Exception e) {
|
||||
output.append(c).append(" ");
|
||||
}
|
||||
}
|
||||
|
||||
System.out.println(output.toString().trim()); // 输出结果:ni hao , shi jie !
|
||||
}
|
||||
/**
|
||||
* 中文转拼音
|
||||
*/
|
||||
public static String getPinyin(String chinese) {
|
||||
// 设置不带声调的输出选项
|
||||
net.sourceforge.pinyin4j.format.HanyuPinyinOutputFormat format = new net.sourceforge.pinyin4j.format.HanyuPinyinOutputFormat();
|
||||
format.setToneType(net.sourceforge.pinyin4j.format.HanyuPinyinToneType.WITHOUT_TONE);
|
||||
|
||||
StringBuilder output = new StringBuilder();
|
||||
for (char c : chinese.toCharArray()) {
|
||||
try {
|
||||
String[] pinyinArray = PinyinHelper.toHanyuPinyinStringArray(c, format);
|
||||
if (pinyinArray != null && pinyinArray.length > 0) {
|
||||
output.append(pinyinArray[0]).append("");
|
||||
} else {
|
||||
output.append(c).append("");
|
||||
}
|
||||
} catch (Exception e) {
|
||||
output.append(c).append("");
|
||||
}
|
||||
}
|
||||
return output.toString().trim();
|
||||
}
|
||||
|
||||
}
|
|
@ -113,7 +113,7 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter
|
|||
// 过滤请求
|
||||
.authorizeRequests()
|
||||
// 对于登录login 注册register 验证码captchaImage 允许匿名访问
|
||||
.antMatchers("/login","/wxlogin", "/register", "/captchaImage","/common/receive","/appCaptcha","/appCodeLogin","/app/**","/common/upload","/loginByopenid").permitAll()
|
||||
.antMatchers("/login","/wxlogin", "/register", "/captchaImage","/common/receive","/appCaptcha","/appCodeLogin","/app/**","/common/upload","/loginByopenid","/weather").permitAll()
|
||||
// 静态资源,可匿名访问
|
||||
.antMatchers(HttpMethod.GET, "/", "/*.html", "/**/*.html", "/**/*.css", "/**/*.js", "/profile/**").permitAll()
|
||||
.antMatchers("/swagger-ui.html", "/swagger-resources/**", "/webjars/**", "/*/api-docs", "/druid/**").permitAll()
|
||||
|
|
|
@ -5,6 +5,7 @@ import com.alibaba.fastjson2.JSONObject;
|
|||
import com.ruoyi.common.annotation.Log;
|
||||
import com.ruoyi.common.core.controller.BaseController;
|
||||
import com.ruoyi.common.core.domain.AjaxResult;
|
||||
import com.ruoyi.common.utils.ip.IpUtils;
|
||||
import com.ruoyi.device.domain.AsUserCollection;
|
||||
import com.ruoyi.common.core.page.TableDataInfo;
|
||||
import com.ruoyi.common.enums.BusinessType;
|
||||
|
@ -83,18 +84,24 @@ public class AppController extends BaseController
|
|||
* 根据登录用户获取绑定设备
|
||||
*/
|
||||
@GetMapping("/getDeviceInfoByUser")
|
||||
public AjaxResult list(Long userId,String deviceId)
|
||||
public AjaxResult list(Long userId,String isDefault)
|
||||
{
|
||||
List<AsDevice> device;
|
||||
if(StringUtils.isEmpty(deviceId) || "null".equals(deviceId)){
|
||||
device = asUserService.selectDeviceInfoByUser(userId,null);
|
||||
}else{
|
||||
device = asUserService.selectDeviceInfoByUser(userId,Long.parseLong(deviceId));
|
||||
}
|
||||
List<AsDevice> device = asUserService.selectDeviceInfoByUser(userId,isDefault);
|
||||
return AjaxResult.success(device);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 切换默认展示设备
|
||||
*/
|
||||
@PutMapping("/toggleDevice")
|
||||
public AjaxResult toggleDevice(Long userId,Long deviceId)
|
||||
{
|
||||
int i = asDeviceService.toggleDevice(userId,deviceId);
|
||||
return AjaxResult.success(i);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 滑动浇水
|
||||
*/
|
||||
|
@ -375,4 +382,15 @@ public class AppController extends BaseController
|
|||
return AjaxResult.success(isBand);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取天气信息
|
||||
*/
|
||||
@GetMapping("/weather")
|
||||
public AjaxResult weather()
|
||||
{
|
||||
//获取当前请求ip,用ip获取到归属地信息
|
||||
String ipAddr = IpUtils.getIpAddr();
|
||||
return AjaxResult.success(asDeviceService.getWeather(ipAddr));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -152,4 +152,8 @@ public class AsDevice extends BaseEntity
|
|||
/** 浇水模式:1-定时;2-智能土壤湿度;3-手动 */
|
||||
@Excel(name = "浇水模式")
|
||||
private String modeStr;
|
||||
|
||||
/** 是否默认展示:0-否,1-是 */
|
||||
@Excel(name = "是否默认展示")
|
||||
private String isDefault;
|
||||
}
|
||||
|
|
|
@ -0,0 +1,34 @@
|
|||
package com.ruoyi.device.domain.vo;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
public class IPVo {
|
||||
|
||||
private String status;
|
||||
private String t;
|
||||
private String set_cache_time;
|
||||
private List<IpData> data;
|
||||
|
||||
@Data
|
||||
public class IpData {
|
||||
private String ExtendedLocation;
|
||||
private String OriginQuery;
|
||||
private String appinfo;
|
||||
private int disp_type;
|
||||
private String fetchkey;
|
||||
private String location;
|
||||
private String origip;
|
||||
private String origipquery;
|
||||
private String resourceid;
|
||||
private int role_id;
|
||||
private int shareImage;
|
||||
private int showLikeShare;
|
||||
private String showlamp;
|
||||
private String titlecont;
|
||||
private String tplt;
|
||||
|
||||
}
|
||||
}
|
|
@ -0,0 +1,50 @@
|
|||
package com.ruoyi.device.domain.vo;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 天气响应类
|
||||
* */
|
||||
@Data
|
||||
public class WeatherResponse {
|
||||
private List<Weather> results;
|
||||
|
||||
@Data
|
||||
public static class Weather {
|
||||
private Location location;
|
||||
private List<DailyWeather> daily;
|
||||
private String last_update;
|
||||
}
|
||||
@Data
|
||||
public static class Location {
|
||||
private String id;
|
||||
private String name;
|
||||
private String country;
|
||||
private String path;
|
||||
private String timezone;
|
||||
private String timezone_offset;
|
||||
|
||||
}
|
||||
|
||||
@Data
|
||||
public static class DailyWeather {
|
||||
private String date;
|
||||
private String text_day;
|
||||
private String code_day;
|
||||
private String text_night;
|
||||
private String code_night;
|
||||
private String high;
|
||||
private String low;
|
||||
private String rainfall;
|
||||
private String precip;
|
||||
private String wind_direction;
|
||||
private String wind_direction_degree;
|
||||
private String wind_speed;
|
||||
private String wind_scale;
|
||||
private String humidity;
|
||||
|
||||
}
|
||||
}
|
|
@ -4,6 +4,7 @@ import java.util.List;
|
|||
|
||||
import com.ruoyi.common.core.domain.AjaxResult;
|
||||
import com.ruoyi.device.domain.AsDevice;
|
||||
import com.ruoyi.device.domain.vo.WeatherResponse;
|
||||
|
||||
/**
|
||||
* 设备列表Service接口
|
||||
|
@ -102,6 +103,14 @@ public interface IAsDeviceService
|
|||
*/
|
||||
Boolean isBand(String mac);
|
||||
|
||||
/**
|
||||
* 切换默认展示设备
|
||||
*/
|
||||
int toggleDevice(Long userId, Long deviceId);
|
||||
|
||||
|
||||
WeatherResponse getWeather(String ipAddr);
|
||||
|
||||
|
||||
// /**
|
||||
// * 构建命令
|
||||
|
|
|
@ -182,7 +182,7 @@ public interface IAsUserService
|
|||
/**
|
||||
* 根据登录用户获取是否有绑定设备
|
||||
*/
|
||||
List<AsDevice> selectDeviceInfoByUser(Long userId,Long deviceId);
|
||||
List<AsDevice> selectDeviceInfoByUser(Long userId,String isDefault);
|
||||
|
||||
/**
|
||||
* 计算下次定时时间
|
||||
|
|
|
@ -13,7 +13,11 @@ import com.ruoyi.common.utils.DateUtils;
|
|||
import com.ruoyi.common.utils.http.HttpUtils;
|
||||
import com.ruoyi.common.utils.onenet.IotUtil;
|
||||
import com.ruoyi.common.utils.onenet.Token;
|
||||
import com.ruoyi.common.utils.pinyin.PinyinUtils;
|
||||
import com.ruoyi.common.utils.spring.SpringUtils;
|
||||
import com.ruoyi.device.domain.*;
|
||||
import com.ruoyi.device.domain.vo.IPVo;
|
||||
import com.ruoyi.device.domain.vo.WeatherResponse;
|
||||
import com.ruoyi.device.mapper.*;
|
||||
import com.ruoyi.device.service.IAsDeviceService;
|
||||
import com.ruoyi.device.service.IAsTimerService;
|
||||
|
@ -21,7 +25,9 @@ import com.ruoyi.device.service.IAsUserService;
|
|||
import com.ruoyi.device.service.IAsWateringRecordService;
|
||||
import com.ruoyi.system.mapper.SysUserMapper;
|
||||
import lombok.SneakyThrows;
|
||||
import net.sourceforge.pinyin4j.PinyinHelper;
|
||||
import org.apache.commons.lang3.ObjectUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
|
@ -482,4 +488,60 @@ public class AsDeviceServiceImpl extends ServiceImpl<AsDeviceMapper, AsDevice> i
|
|||
int i = asDeviceMapper.isBandByMac(mac);
|
||||
return i>0;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 切换默认展示设备
|
||||
*/
|
||||
@Override
|
||||
public int toggleDevice(Long userId,Long deviceId) {
|
||||
asDeviceMapper.updateAsDevice(AsDevice.builder().deviceId(deviceId).isDefault("1").build());
|
||||
List<AsDevice> asDevices = asDeviceMapper.selectAsDeviceList(AsDevice.builder().userId(userId).isDefault("1").build());
|
||||
if(ObjectUtils.isNotEmpty(asDevices) && asDevices.size()>0){
|
||||
for(AsDevice device:asDevices){
|
||||
if(device.getDeviceId()!=deviceId){
|
||||
asDeviceMapper.updateAsDevice(AsDevice.builder().deviceId(device.getDeviceId()).isDefault("0").build());
|
||||
}
|
||||
}
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取天气信息
|
||||
*/
|
||||
@Override
|
||||
public WeatherResponse getWeather(String ipAddr) {
|
||||
String location = "";
|
||||
if(StringUtils.isNotEmpty(ipAddr)){
|
||||
/** 获取归属地 https://opendata.baidu.com/api.php?query=36.28.139.223&co=&resource_id=6006&oe=utf8*/
|
||||
String url = "https://opendata.baidu.com/api.php?query="+ ipAddr +"&co=&resource_id=6006&oe=utf8";
|
||||
String sendGet = HttpUtils.sendGet(url);
|
||||
logger.info("获取到ip响应:【{}】",sendGet);
|
||||
IPVo vo = JSONObject.parseObject(sendGet,IPVo.class);
|
||||
logger.info("转换成IPVo对象:【{}】",JSON.toJSONString(vo));
|
||||
List<IPVo.IpData> ipData = vo.getData();
|
||||
if(ObjectUtils.isNotEmpty(ipData) && ipData.size()>0){
|
||||
IPVo.IpData ip = ipData.get(0);
|
||||
String locationStr = ip.getLocation();
|
||||
//将location中去掉'电信','联通','移动'字符串后去掉空格,再将字符串中的省份去掉,再将字符串中的市去掉
|
||||
String location1 = locationStr.replace("电信","").replace("联通","").replace("移动","").replace(" ","").replace("市","");
|
||||
//将location中去掉省前面的(包括省字)字符串
|
||||
String location2 = location1.replace(location1.substring(0,location1.indexOf("省")+1),"");
|
||||
logger.info("获取到归属地:【{}】",location2);
|
||||
//将location2转成拼音
|
||||
location = PinyinUtils.getPinyin(location2);
|
||||
logger.info("转成拼音后:【{}】",location);
|
||||
}
|
||||
}
|
||||
if(StringUtils.isEmpty(location)){
|
||||
location = "beijing";
|
||||
}
|
||||
String weatherUrl = "https://api.seniverse.com/v3/weather/daily.json?key="+ SpringUtils.getRequiredProperty("xinzhi.secretKey")+"&location="+location+"&language=zh-Hans&unit=c&start=0&days=5";
|
||||
String weather = HttpUtils.sendGet(weatherUrl);
|
||||
logger.info("获取到天气响应:【{}】",weather);
|
||||
WeatherResponse weatherResponse = JSONObject.parseObject(weather, WeatherResponse.class);
|
||||
logger.info("转换成weatherResponse对象:【{}】",JSON.toJSONString(weatherResponse));
|
||||
return weatherResponse;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -433,13 +433,13 @@ public class AsUserServiceImpl implements IAsUserService
|
|||
* 根据登录用户获取绑定设备
|
||||
* 根据登录用户获取是否有绑定设备,没有则显示添加设备页面,如果有则从列表中取一条记录展示
|
||||
* 土壤湿度,水流强度,是否离线等
|
||||
* @param userId 用户id
|
||||
* @param userId 用户id 默认展示
|
||||
* @return 用户设备信息
|
||||
*/
|
||||
@SneakyThrows
|
||||
@Override
|
||||
public List<AsDevice> selectDeviceInfoByUser(Long userId,Long deviceId) {
|
||||
AsDevice asDevice = AsDevice.builder().userId(userId).deviceId(deviceId).build();
|
||||
public List<AsDevice> selectDeviceInfoByUser(Long userId,String isDefault) {
|
||||
AsDevice asDevice = AsDevice.builder().userId(userId).isDefault(isDefault).build();
|
||||
List<AsDevice> asDevices = asDeviceMapper.selectAsDeviceList(asDevice);
|
||||
// 查询onenet设备在线状态
|
||||
String sendUrl = iotUrl+ IotConstants.ADDS_COMMAND;
|
||||
|
|
|
@ -36,11 +36,12 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||
<result property="soilMoisture" column="soil_moisture" />
|
||||
<result property="waterIntensitySwitch" column="water_intensity_switch" />
|
||||
<result property="isNetwork" column="is_network" />
|
||||
<result property="isDefault" column="is_default" />
|
||||
<result property="modeStr" column="mode_str" />
|
||||
</resultMap>
|
||||
|
||||
<sql id="selectAsDeviceVo">
|
||||
select device_id, picture, device_name, classify_id, classify_name, model_id, model, mac, activation_time, online_status, user_id, user_name, nick_name, regular_watering, soil_moisture_open, soil_moisture_close, water_intensity, pulse_mode, pulse_mode_param, screen_rest_time, version, version_id, create_by, create_time, update_by, update_time, remark, regular_watering_json, soil_moisture, water_intensity_switch,is_network,mode_str from as_device
|
||||
select device_id, picture, device_name, classify_id, classify_name, model_id, model, mac, activation_time, online_status, user_id, user_name, nick_name, regular_watering, soil_moisture_open, soil_moisture_close, water_intensity, pulse_mode, pulse_mode_param, screen_rest_time, version, version_id, create_by, create_time, update_by, update_time, remark, regular_watering_json, soil_moisture, water_intensity_switch,is_network,is_default,mode_str from as_device
|
||||
</sql>
|
||||
|
||||
<select id="selectAsDeviceList" parameterType="AsDevice" resultMap="AsDeviceResult">
|
||||
|
@ -54,7 +55,9 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||
<if test="onlineStatus != null and onlineStatus != ''"> and online_status = #{onlineStatus}</if>
|
||||
<if test="nickName != null and nickName != ''"> and nick_name like concat('%', #{nickName}, '%')</if>
|
||||
<if test="userId != null "> and user_id = #{userId}</if>
|
||||
<if test="deviceId != null "> and device_id = #{deviceId}</if>
|
||||
<if test="modelId != null "> and model_id = #{modelId}</if>
|
||||
<if test="isDefault != null and isDefault != ''"> and is_default = #{isDefault}</if>
|
||||
</where>
|
||||
</select>
|
||||
|
||||
|
@ -173,6 +176,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||
<if test="waterIntensitySwitch != null">water_intensity_switch = #{waterIntensitySwitch},</if>
|
||||
<if test="status != null">status = #{status},</if>
|
||||
<if test="isNetwork != null">is_network = #{isNetwork},</if>
|
||||
<if test="isDefault != null">is_default = #{isDefault},</if>
|
||||
<if test="modeStr != null">mode_str = #{modeStr}</if>
|
||||
</trim>
|
||||
where device_id = #{deviceId}
|
||||
|
|
Loading…
Reference in New Issue
Block a user