根据登录用户获取设备信息、滑动浇水、根据设备id获取更多浇水记录
This commit is contained in:
parent
1bd508cf13
commit
c85c489f89
|
@ -113,7 +113,7 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter
|
|||
// 过滤请求
|
||||
.authorizeRequests()
|
||||
// 对于登录login 注册register 验证码captchaImage 允许匿名访问
|
||||
.antMatchers("/login", "/register", "/captchaImage","/common/receive","/appCaptcha","/appCodeLogin").permitAll()
|
||||
.antMatchers("/login", "/register", "/captchaImage","/common/receive","/appCaptcha","/appCodeLogin","/app/**").permitAll()
|
||||
// 静态资源,可匿名访问
|
||||
.antMatchers(HttpMethod.GET, "/", "/*.html", "/**/*.html", "/**/*.css", "/**/*.js", "/profile/**").permitAll()
|
||||
.antMatchers("/swagger-ui.html", "/swagger-resources/**", "/webjars/**", "/*/api-docs", "/druid/**").permitAll()
|
||||
|
|
|
@ -0,0 +1,71 @@
|
|||
package com.ruoyi.device.app;
|
||||
|
||||
import com.ruoyi.common.core.controller.BaseController;
|
||||
import com.ruoyi.common.core.domain.AjaxResult;
|
||||
import com.ruoyi.common.core.page.TableDataInfo;
|
||||
import com.ruoyi.device.domain.AsDevice;
|
||||
import com.ruoyi.device.domain.AsWateringRecord;
|
||||
import com.ruoyi.device.service.IAsDeviceService;
|
||||
import com.ruoyi.device.service.IAsUserService;
|
||||
import com.ruoyi.device.service.IAsWateringRecordService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 用户信息
|
||||
*
|
||||
* @author ruoyi
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/app")
|
||||
public class AppController extends BaseController
|
||||
{
|
||||
@Resource
|
||||
private IAsUserService asUserService;
|
||||
|
||||
@Resource
|
||||
private IAsWateringRecordService asWateringRecordService;
|
||||
|
||||
@Autowired
|
||||
private IAsDeviceService asDeviceService;
|
||||
|
||||
|
||||
/**
|
||||
* 根据登录用户获取绑定设备
|
||||
*/
|
||||
@GetMapping("/getDeviceInfoByUser")
|
||||
public AjaxResult list(Long userId)
|
||||
{
|
||||
AsDevice device = asUserService.selectDeviceInfoByUser(userId);
|
||||
return AjaxResult.success(device);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 滑动浇水
|
||||
*/
|
||||
@GetMapping(value = "/watering/{deviceId}/{wateringSwitch}")
|
||||
public AjaxResult watering(@PathVariable("deviceId") Long deviceId,@PathVariable("wateringSwitch") Integer wateringSwitch)
|
||||
{
|
||||
AsDevice device = asDeviceService.selectAsDeviceByDeviceId(deviceId);
|
||||
return asDeviceService.watering(device,wateringSwitch);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据设备id获取更多浇水记录
|
||||
*/
|
||||
@GetMapping("/getWateringRecord")
|
||||
public TableDataInfo wateringRecord(String deviceId)
|
||||
{
|
||||
startPage();
|
||||
List<AsWateringRecord> asWateringRecords = asWateringRecordService.selectAsWateringRecordList(AsWateringRecord.builder().deviceId(Long.parseLong(deviceId)).build());
|
||||
return getDataTable(asWateringRecords);
|
||||
}
|
||||
|
||||
}
|
|
@ -4,9 +4,12 @@ import java.util.Date;
|
|||
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import com.ruoyi.common.annotation.Excel;
|
||||
import com.ruoyi.common.core.domain.BaseEntity;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
/**
|
||||
* 设备列表对象 as_device
|
||||
|
@ -16,6 +19,9 @@ import com.ruoyi.common.core.domain.BaseEntity;
|
|||
*/
|
||||
@Data
|
||||
@TableName(value = "as_device")
|
||||
@Builder
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class AsDevice extends BaseEntity
|
||||
{
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package com.ruoyi.device.service;
|
||||
|
||||
import com.ruoyi.common.core.domain.entity.AsUser;
|
||||
import com.ruoyi.device.domain.AsDevice;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
@ -177,4 +178,8 @@ public interface IAsUserService
|
|||
*/
|
||||
AsUser selectUserByPhone(String phone);
|
||||
|
||||
/**
|
||||
* 根据登录用户获取是否有绑定设备
|
||||
*/
|
||||
AsDevice selectDeviceInfoByUser(Long userId);
|
||||
}
|
||||
|
|
|
@ -14,6 +14,7 @@ import com.ruoyi.device.mapper.AsDeviceMapper;
|
|||
import com.ruoyi.device.mapper.AsUserMapper;
|
||||
import com.ruoyi.device.service.IAsUserService;
|
||||
import com.ruoyi.system.service.ISysConfigService;
|
||||
import org.apache.commons.lang3.ObjectUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
@ -383,4 +384,21 @@ public class AsUserServiceImpl implements IAsUserService
|
|||
public AsUser selectUserByPhone(String phone) {
|
||||
return asUserMapper.selectUserByPhone(phone);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据登录用户获取绑定设备
|
||||
* 根据登录用户获取是否有绑定设备,没有则显示添加设备页面,如果有则从列表中取一条记录展示
|
||||
* 土壤湿度,水流强度,是否离线等
|
||||
* @param userId 用户id
|
||||
* @return 用户设备信息
|
||||
*/
|
||||
@Override
|
||||
public AsDevice selectDeviceInfoByUser(Long userId) {
|
||||
AsDevice asDevice = AsDevice.builder().userId(userId).build();
|
||||
List<AsDevice> asDevices = asDeviceMapper.selectAsDeviceList(asDevice);
|
||||
if(ObjectUtils.isNotEmpty(asDevices) && asDevices.size() !=0 ){
|
||||
return asDevices.get(0);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,20 +8,31 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||
<result property="deviceId" column="device_id" />
|
||||
<result property="waterTime" column="water_time" />
|
||||
<result property="pulseMode" column="pulse_mode" />
|
||||
<result property="pulseModeParam" column="pulse_mode_param" />
|
||||
<result property="waterIntensity" column="water_intensity" />
|
||||
<result property="startMoisture" column="start_moisture" />
|
||||
<result property="endMoisture" column="end_moisture" />
|
||||
<result property="startMode" column="start_mode" />
|
||||
<result property="sprayingTime" column="spraying_time" />
|
||||
<result property="createTime" column="create_time" />
|
||||
<result property="userName" column="user_name" />
|
||||
</resultMap>
|
||||
|
||||
<sql id="selectAsWateringRecordVo">
|
||||
select device_id, water_time, pulse_mode, start_mode, spraying_time, user_name from as_watering_record
|
||||
select device_id, water_time, start_mode, spraying_time, pulse_mode, pulse_mode_param, water_intensity, start_moisture, end_moisture, user_name, create_time from as_watering_record
|
||||
</sql>
|
||||
|
||||
<select id="selectAsWateringRecordList" parameterType="AsWateringRecord" resultMap="AsWateringRecordResult">
|
||||
<include refid="selectAsWateringRecordVo"/>
|
||||
<where>
|
||||
<where>
|
||||
<if test="waterTime != null "> and water_time = #{waterTime}</if>
|
||||
<if test="startMode != null and startMode != ''"> and start_mode = #{startMode}</if>
|
||||
<if test="sprayingTime != null "> and spraying_time = #{sprayingTime}</if>
|
||||
<if test="pulseMode != null and pulseMode != ''"> and pulse_mode = #{pulseMode}</if>
|
||||
<if test="pulseModeParam != null and pulseModeParam != ''"> and pulse_mode_param = #{pulseModeParam}</if>
|
||||
<if test="waterIntensity != null "> and water_intensity = #{waterIntensity}</if>
|
||||
<if test="startMoisture != null "> and start_moisture = #{startMoisture}</if>
|
||||
<if test="endMoisture != null "> and end_moisture = #{endMoisture}</if>
|
||||
<if test="userName != null and userName != ''"> and user_name like concat('%', #{userName}, '%')</if>
|
||||
</where>
|
||||
</select>
|
||||
|
@ -30,33 +41,49 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||
<include refid="selectAsWateringRecordVo"/>
|
||||
where device_id = #{deviceId}
|
||||
</select>
|
||||
|
||||
|
||||
<insert id="insertAsWateringRecord" parameterType="AsWateringRecord" useGeneratedKeys="true" keyProperty="deviceId">
|
||||
insert into as_watering_record
|
||||
<trim prefix="(" suffix=")" suffixOverrides=",">
|
||||
<if test="waterTime != null">water_time,</if>
|
||||
<if test="pulseMode != null">pulse_mode,</if>
|
||||
<if test="startMode != null">start_mode,</if>
|
||||
<if test="sprayingTime != null">spraying_time,</if>
|
||||
<if test="pulseMode != null">pulse_mode,</if>
|
||||
<if test="pulseModeParam != null">pulse_mode_param,</if>
|
||||
<if test="waterIntensity != null">water_intensity,</if>
|
||||
<if test="startMoisture != null">start_moisture,</if>
|
||||
<if test="endMoisture != null">end_moisture,</if>
|
||||
<if test="userName != null">user_name,</if>
|
||||
</trim>
|
||||
<if test="createTime != null">create_time,</if>
|
||||
</trim>
|
||||
<trim prefix="values (" suffix=")" suffixOverrides=",">
|
||||
<if test="waterTime != null">#{waterTime},</if>
|
||||
<if test="pulseMode != null">#{pulseMode},</if>
|
||||
<if test="startMode != null">#{startMode},</if>
|
||||
<if test="sprayingTime != null">#{sprayingTime},</if>
|
||||
<if test="pulseMode != null">#{pulseMode},</if>
|
||||
<if test="pulseModeParam != null">#{pulseModeParam},</if>
|
||||
<if test="waterIntensity != null">#{waterIntensity},</if>
|
||||
<if test="startMoisture != null">#{startMoisture},</if>
|
||||
<if test="endMoisture != null">#{endMoisture},</if>
|
||||
<if test="userName != null">#{userName},</if>
|
||||
</trim>
|
||||
<if test="createTime != null">#{createTime},</if>
|
||||
</trim>
|
||||
</insert>
|
||||
|
||||
|
||||
<update id="updateAsWateringRecord" parameterType="AsWateringRecord">
|
||||
update as_watering_record
|
||||
<trim prefix="SET" suffixOverrides=",">
|
||||
<if test="waterTime != null">water_time = #{waterTime},</if>
|
||||
<if test="pulseMode != null">pulse_mode = #{pulseMode},</if>
|
||||
<if test="startMode != null">start_mode = #{startMode},</if>
|
||||
<if test="sprayingTime != null">spraying_time = #{sprayingTime},</if>
|
||||
<if test="pulseMode != null">pulse_mode = #{pulseMode},</if>
|
||||
<if test="pulseModeParam != null">pulse_mode_param = #{pulseModeParam},</if>
|
||||
<if test="waterIntensity != null">water_intensity = #{waterIntensity},</if>
|
||||
<if test="startMoisture != null">start_moisture = #{startMoisture},</if>
|
||||
<if test="endMoisture != null">end_moisture = #{endMoisture},</if>
|
||||
<if test="userName != null">user_name = #{userName},</if>
|
||||
<if test="createTime != null">create_time = #{createTime},</if>
|
||||
</trim>
|
||||
where device_id = #{deviceId}
|
||||
</update>
|
||||
|
|
Loading…
Reference in New Issue
Block a user