提交 f4e7fcb0 authored 作者: 林业通's avatar 林业通

智能家居修改

上级 d6f0c88b
package tech.glinfo.enbao.common.controller; package tech.glinfo.enbao.common.controller;
import com.baidu.aip.face.AipFace; import com.baidu.aip.face.AipFace;
import tech.glinfo.enbao.common.utils.BaiDuAPIUtils; import tech.glinfo.enbao.common.utils.BaiDuApiUtils;
import tech.glinfo.enbao.common.utils.R; import tech.glinfo.enbao.common.utils.R;
import org.json.JSONArray; import org.json.JSONArray;
import org.json.JSONObject; import org.json.JSONObject;
...@@ -19,7 +19,7 @@ public abstract class BdAbstractController { ...@@ -19,7 +19,7 @@ public abstract class BdAbstractController {
protected Logger logger = LoggerFactory.getLogger(getClass()); protected Logger logger = LoggerFactory.getLogger(getClass());
protected R baiduDetect(String image) { protected R baiduDetect(String image) {
AipFace apiFace = BaiDuAPIUtils.getApiFace(); AipFace apiFace = BaiDuApiUtils.getApiFace();
// 传入可选参数调用接口 // 传入可选参数调用接口
HashMap<String, String> options = new HashMap<String, String>(); HashMap<String, String> options = new HashMap<String, String>();
......
package tech.glinfo.enbao.common.utils;
import com.baidu.aip.face.AipFace;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;
/**
* 百度api工具类
*/
@ConfigurationProperties(prefix = "baidu")
@Component
public class BaiDuAPIUtils {
private Logger logger = LoggerFactory.getLogger(getClass());
private static String appId;
private static String apiKey;
private static String secretKey;
public static AipFace getApiFace() {
return ApiFaceUtils.instance;
}
private static class ApiFaceUtils {
public final static AipFace instance = new AipFace(appId, apiKey, secretKey);
}
public String getAppId() {
return appId;
}
public void setAppId(String appId) {
this.appId = appId;
}
public String getApiKey() {
return apiKey;
}
public void setApiKey(String apiKey) {
this.apiKey = apiKey;
}
public String getSecretKey() {
return secretKey;
}
public void setSecretKey(String secretKey) {
this.secretKey = secretKey;
}
}
...@@ -61,24 +61,26 @@ public class AppUserController extends AbstractController { ...@@ -61,24 +61,26 @@ public class AppUserController extends AbstractController {
@PostMapping("register") @PostMapping("register")
@ApiOperation("用户注册") @ApiOperation("用户注册")
@ApiLog("用户注册") @ApiLog("用户注册")
public R register(@RequestBody RegisterForm form){ public R register(@RequestBody WxRegisterForm form){
//表单校验 //表单校验
ValidatorUtils.validateEntity(form); ValidatorUtils.validateEntity(form);
AppUserEntity userEntity = otherAppUserService.queryByPhone(form.getPhone()); AppUserEntity userEntity = otherAppUserService.queryByPhone(form.getPhone());
if (userEntity != null) { if (userEntity != null) {
throw new RRException("手机号码已经注册过了"); return R.error("手机号码已经注册过了");
} }
String vcode = redisUtils.get(Constant.VCODE_KEY + Constant.VcodeType.REG.getValue() + "_" + form.getPhone()); /* String vcode = redisUtils.get(Constant.VCODE_KEY + Constant.VcodeType.REG.getValue() + "_" + form.getPhone());
if(!form.getVcode().equals(vcode)) { if(!form.getVcode().equals(vcode)) {
throw new RRException("验证码输入不正确"); throw new RRException("验证码输入不正确");
} }*/
AppUserEntity user = new AppUserEntity(); AppUserEntity user = new AppUserEntity();
user.setPhone(form.getPhone()); user.setPhone(form.getPhone());
user.setNickname(form.getNickname()); user.setNickname(form.getNickname());
user.setPassword(DigestUtils.sha256Hex(form.getPassword())); user.setOpenId(form.getOpenId());
user.setHeadImgUrl(form.getHeadImgUrl());
user.setPassword(DigestUtils.sha256Hex("123456"));
otherAppUserService.save(user); otherAppUserService.save(user);
ShFamilyEntity family = new ShFamilyEntity(); ShFamilyEntity family = new ShFamilyEntity();
family.setName("我的家"); family.setName("我的家");
...@@ -90,7 +92,12 @@ public class AppUserController extends AbstractController { ...@@ -90,7 +92,12 @@ public class AppUserController extends AbstractController {
member.setUserId(user.getId()); member.setUserId(user.getId());
member.setIsAdmin(1);//管理员 member.setIsAdmin(1);//管理员
shFamilyMemberService.save(member); shFamilyMemberService.save(member);
return R.ok(); String token = jwtUtils.generateToken(user.getId() +"#"+user.getPhone());
Map<String, Object> map = new HashMap<>();
map.put("token", token);
map.put("expire", jwtUtils.getExpire());
map.put("user", user);
return R.ok(map);
} }
@PostMapping("update") @PostMapping("update")
...@@ -236,23 +243,28 @@ public class AppUserController extends AbstractController { ...@@ -236,23 +243,28 @@ public class AppUserController extends AbstractController {
String clientId = (String) params.get("clientId"); String clientId = (String) params.get("clientId");
Integer role = (Integer) params.get("role"); Integer role = (Integer) params.get("role");
if (StringUtils.isNotEmpty(unionid)) {//微信登录 if (StringUtils.isNotEmpty(unionid)) {//苹果登录
//open_id 存unionID //open_id 存unionID
AppUserEntity user = otherAppUserService.getOne(new QueryWrapper<AppUserEntity>().eq("unionid", unionid)); AppUserEntity user = otherAppUserService.getOne(new QueryWrapper<AppUserEntity>().eq("unionid", unionid));
if (user != null) { if (user != null) {
// map.put("openId", openId); // map.put("openId", openId);
return R.ok(genTokenAndGetData(user, clientId, role)); return R.ok(genTokenAndGetData(user, clientId, role));
} else { } else {
return R.ok("当前微信暂未绑定任何账号!"); return R.error("当前Apple暂未绑定任何账号!");
} }
} else if (StringUtils.isNotEmpty(openid)) {//苹果登录 } else if (StringUtils.isNotEmpty(openid)) {//微信登录
//open_id 存unionID //open_id 存unionID
AppUserEntity user = otherAppUserService.getOne(new QueryWrapper<AppUserEntity>().eq("open_id", openid)); AppUserEntity user = otherAppUserService.getOne(new QueryWrapper<AppUserEntity>().eq("open_id", openid));
if (user != null) { if (user != null) {
// map.put("openId", openId); String token = jwtUtils.generateToken(user.getId() +"#"+user.getPhone());
return R.ok(genTokenAndGetData(user, clientId, role)); Map<String, Object> map = new HashMap<>();
map.put("token", token);
map.put("expire", jwtUtils.getExpire());
map.put("user", user);
return R.ok(map);
} else { } else {
return R.ok("当前Apple暂未绑定任何账号!"); return R.ok("当前微信暂未绑定任何账号!");
} }
} else { } else {
return R.error("缺少参数,请核查!"); return R.error("缺少参数,请核查!");
......
package tech.glinfo.enbao.modules.appuser.form;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import javax.validation.constraints.NotBlank;
/**
* 注册表单
*
* @author linzhenjie@gltech.com
*/
@Data
@ApiModel(value = "注册表单")
public class WxRegisterForm {
@ApiModelProperty(value = "手机号码")
@NotBlank(message="手机号码不能为空")
private String phone;
@ApiModelProperty(value = "昵称")
@NotBlank(message="昵称不能为空")
private String nickname;
@ApiModelProperty(value = "openId")
@NotBlank(message="openId不能为空")
private String openId;
@ApiModelProperty(value = "头像")
private String headImgUrl;
}
...@@ -302,7 +302,7 @@ public class LockParse implements IParse { ...@@ -302,7 +302,7 @@ public class LockParse implements IParse {
String content = datas.get("content"); String content = datas.get("content");
logger.info("上报试错告警" + content); logger.info("上报试错告警" + content);
int action = Integer.parseInt(content.substring(4, 6), 16); int action = Integer.parseInt(content.substring(4, 6), 16);
AppUserEntity userEntity = appUserService.getById(device.getPublisherId()); AppUserEntity userEntity = appUserService.getById(device.getUserId());
String tishi = action == 1 ? "指纹" : action == 2 ? "密码" : action == 3 ? "卡片" : action == 20 ? "人脸" : action == 21 ? "掌纹" : "未知"; String tishi = action == 1 ? "指纹" : action == 2 ? "密码" : action == 3 ? "卡片" : action == 20 ? "人脸" : action == 21 ? "掌纹" : "未知";
if (StringUtils.isNotBlank(userEntity.getThirdId())) { if (StringUtils.isNotBlank(userEntity.getThirdId())) {
mqProducer.sendPush(tishi + "多次开锁失败提示", "设备: " + device.getNumbering() + " " + tishi + "多次开锁失败提示", userEntity.getThirdId()); mqProducer.sendPush(tishi + "多次开锁失败提示", "设备: " + device.getNumbering() + " " + tishi + "多次开锁失败提示", userEntity.getThirdId());
...@@ -310,13 +310,13 @@ public class LockParse implements IParse { ...@@ -310,13 +310,13 @@ public class LockParse implements IParse {
} }
//处理设备期限使用标志 //处理设备期限使用标志
new Thread(new Runnable() { /*new Thread(new Runnable() {
@Override @Override
public void run() { public void run() {
logger.info("start handleEndTime"); logger.info("start handleEndTime");
timeParseUtils.handleEndTime(device.getId(), "06", device.getNumbering(), datas.get("cmd")); timeParseUtils.handleEndTime(device.getId(), "06", device.getNumbering(), datas.get("cmd"));
} }
}).start(); }).start();*/
return ws; return ws;
} }
......
...@@ -122,7 +122,7 @@ public class SpeakerParse implements IParse { ...@@ -122,7 +122,7 @@ public class SpeakerParse implements IParse {
redisUtils.set(AppContants.SPEAKER_FILE_SEND + device.getNumbering() + "-stopsend", 1, 5); redisUtils.set(AppContants.SPEAKER_FILE_SEND + device.getNumbering() + "-stopsend", 1, 5);
return null; return null;
} else if ("00".equals(datas.get("cmd"))) {//解析后的中文 } else if ("00".equals(datas.get("cmd"))) {//解析后的中文
parseText(device.getId(), device.getNumbering(), device.getSpareTwo(), content, null, device.getPublisherId()); parseText(device.getId(), device.getNumbering(), device.getSpareTwo(), content, null, device.getUserId());
return null; return null;
}else if("998".equals(datas.get("cmd"))) {//文件下发后状态 }else if("998".equals(datas.get("cmd"))) {//文件下发后状态
ShSpeakerSongEntity song = shSpeakerSongService.getById(content); ShSpeakerSongEntity song = shSpeakerSongService.getById(content);
......
...@@ -64,4 +64,12 @@ public class ShFamilyController { ...@@ -64,4 +64,12 @@ public class ShFamilyController {
return otherShFamilyService.delete(params, user); return otherShFamilyService.delete(params, user);
} }
@Login
@GetMapping("index")
@ApiOperation("首页")
@ApiLog("首页")
public R index(@RequestBody Map<String, Object> params, @LoginUser AppUserEntity user) {
return otherShFamilyService.index(user.getId(), Integer.valueOf((String) params.get("familyId")));
}
} }
\ No newline at end of file
...@@ -5,6 +5,7 @@ import org.apache.ibatis.annotations.Mapper; ...@@ -5,6 +5,7 @@ import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param; import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select; import org.apache.ibatis.annotations.Select;
import tech.glinfo.enbao.modules.sh.dto.ShFamilyDto; import tech.glinfo.enbao.modules.sh.dto.ShFamilyDto;
import tech.glinfo.enbao.modules.sh.dto.ShFamilyIndex;
import tech.glinfo.enbao.modules.sh.entity.ShDeviceEntity; import tech.glinfo.enbao.modules.sh.entity.ShDeviceEntity;
import tech.glinfo.enbao.modules.sh.entity.ShFamilyEntity; import tech.glinfo.enbao.modules.sh.entity.ShFamilyEntity;
...@@ -33,4 +34,6 @@ public interface OtherShFamilyDao extends BaseMapper<ShFamilyEntity> { ...@@ -33,4 +34,6 @@ public interface OtherShFamilyDao extends BaseMapper<ShFamilyEntity> {
ShFamilyDto familyInfo(@Param("params")Integer id); ShFamilyDto familyInfo(@Param("params")Integer id);
ShFamilyIndex index(@Param("userId")Integer userId, @Param("familyId")Integer familyId);
} }
package tech.glinfo.enbao.modules.sh.dto;
import lombok.Data;
/**
* @author lyt
* @date 2022/1/5 15:28
*/
@Data
public class ShDeviceIndex {
private Integer id;
private String name;
private String numbering;
private Integer onlineStatus;
private String pic;
}
package tech.glinfo.enbao.modules.sh.dto;
import lombok.Data;
import java.util.List;
/**
* @author lyt
* @date 2022/1/5 11:25
*/
@Data
public class ShFamilyIndex {
private Integer id;
private String name;
private List<ShDeviceIndex> devices;
private List<ShFamilyRoomIndex> rooms;
}
...@@ -12,4 +12,6 @@ public class ShFamilyMemberDto { ...@@ -12,4 +12,6 @@ public class ShFamilyMemberDto {
private Integer id; private Integer id;
private String nickname; private String nickname;
private Integer isAdmin;
} }
package tech.glinfo.enbao.modules.sh.dto;
import lombok.Data;
import java.util.List;
/**
* @author lyt
* @date 2022/1/5 11:25
*/
@Data
public class ShFamilyRoomIndex {
private Integer id;
private String name;
}
...@@ -22,4 +22,6 @@ public interface OtherShFamilyService extends IService<ShFamilyEntity> { ...@@ -22,4 +22,6 @@ public interface OtherShFamilyService extends IService<ShFamilyEntity> {
R list(AppUserEntity user); R list(AppUserEntity user);
R info(Integer id); R info(Integer id);
R index(Integer userId, Integer familyId);
} }
...@@ -9,6 +9,7 @@ import tech.glinfo.enbao.common.utils.StringUtils; ...@@ -9,6 +9,7 @@ import tech.glinfo.enbao.common.utils.StringUtils;
import tech.glinfo.enbao.modules.appuser.entity.AppUserEntity; import tech.glinfo.enbao.modules.appuser.entity.AppUserEntity;
import tech.glinfo.enbao.modules.sh.dao.OtherShFamilyDao; import tech.glinfo.enbao.modules.sh.dao.OtherShFamilyDao;
import tech.glinfo.enbao.modules.sh.dto.ShFamilyDto; import tech.glinfo.enbao.modules.sh.dto.ShFamilyDto;
import tech.glinfo.enbao.modules.sh.dto.ShFamilyIndex;
import tech.glinfo.enbao.modules.sh.entity.ShFamilyEntity; import tech.glinfo.enbao.modules.sh.entity.ShFamilyEntity;
import tech.glinfo.enbao.modules.sh.entity.ShFamilyMemberEntity; import tech.glinfo.enbao.modules.sh.entity.ShFamilyMemberEntity;
import tech.glinfo.enbao.modules.sh.service.OtherShFamilyService; import tech.glinfo.enbao.modules.sh.service.OtherShFamilyService;
...@@ -88,5 +89,11 @@ public class OtherShFamilyServiceImpl extends ServiceImpl<OtherShFamilyDao, ShFa ...@@ -88,5 +89,11 @@ public class OtherShFamilyServiceImpl extends ServiceImpl<OtherShFamilyDao, ShFa
return R.ok().put("family", family); return R.ok().put("family", family);
} }
@Override
public R index(Integer userId, Integer familyId) {
ShFamilyIndex index = this.baseMapper.index(userId, familyId);
return R.ok().put("data", index);
}
} }
...@@ -12,7 +12,7 @@ server: ...@@ -12,7 +12,7 @@ server:
spring: spring:
# 环境 dev|test|prod # 环境 dev|test|prod
profiles: profiles:
active: dev active: local
# jackson时间格式化 # jackson时间格式化
jackson: jackson:
time-zone: GMT+8 time-zone: GMT+8
...@@ -66,4 +66,23 @@ baidu: ...@@ -66,4 +66,23 @@ baidu:
apiKey: 45lWoxeKGTxjQTdliVSCj6G8 apiKey: 45lWoxeKGTxjQTdliVSCj6G8
secretKey: Mk7QVOthvwqxFHZvZ0X7gOOTMcUEBBS8 secretKey: Mk7QVOthvwqxFHZvZ0X7gOOTMcUEBBS8
# netty-socketio 配置
socketio:
host: 127.0.0.1
port: 8888
# 设置最大每帧处理数据的长度,防止他人利用大数据来攻击服务器
maxFramePayloadLength: 1048576
# 设置http交互最大内容长度
maxHttpContentLength: 1048576
# socket连接数大小(如只监听一个端口boss线程组为1即可)
bossCount: 1
workCount: 100
allowCustomRequests: true
# 协议升级超时时间(毫秒),默认10秒。HTTP握手升级为ws协议超时时间
upgradeTimeout: 1000000
# Ping消息超时时间(毫秒),默认60秒,这个时间间隔内没有接收到心跳消息就会发送超时事件
pingTimeout: 6000000
# Ping消息间隔(毫秒),默认25秒。客户端向服务器发送一条心跳消息间隔
pingInterval: 25000
...@@ -10,17 +10,58 @@ ...@@ -10,17 +10,58 @@
<collection property="members" ofType="tech.glinfo.enbao.modules.sh.dto.ShFamilyMemberDto" columnPrefix="item_"> <collection property="members" ofType="tech.glinfo.enbao.modules.sh.dto.ShFamilyMemberDto" columnPrefix="item_">
<result column="id" property="id"/> <result column="id" property="id"/>
<result column="nickname" property="nickname"/> <result column="nickname" property="nickname"/>
<result column="is_admin" property="isAdmin"/>
</collection>
</resultMap>
<resultMap id="familyIndexResultMap" type="tech.glinfo.enbao.modules.sh.dto.ShFamilyIndex">
<result column="id" property="id"/>
<result column="name" property="name"/>
<collection property="devices" ofType="tech.glinfo.enbao.modules.sh.dto.ShDeviceIndex" columnPrefix="device_">
<result column="id" property="id"/>
<result column="name" property="name"/>
<result column="numbering" property="numbering"/>
<result column="onlineStatus" property="onlineStatus"/>
<result column="pic" property="pic"/>
</collection>
<collection property="rooms" ofType="tech.glinfo.enbao.modules.sh.dto.ShFamilyRoomIndex" columnPrefix="room_">
<result column="id" property="id"/>
<result column="name" property="name"/>
</collection> </collection>
</resultMap> </resultMap>
<select id="familyInfo" resultMap="familyResultMap"> <select id="familyInfo" resultMap="familyResultMap">
SELECT a.id, a.name, COUNT(c.id) room, SELECT a.id, a.name, COUNT(c.id) room,
b.id item_id, b.id item_id,
d.nickname item_nickname d.nickname item_nickname,
b.is_admin item_isAdmin
FROM FROM
sh_family a, sh_family_member b, sh_family_room c, app_user d sh_family a, sh_family_member b, sh_family_room c, app_user d
WHERE WHERE
a.id = b.family_id AND a.id = c.family_id AND b.user_id = d.id AND a.id = ${id} a.id = b.family_id AND a.id = c.family_id AND b.user_id = d.id AND a.id = ${id}
</select> </select>
<select id="index" resultMap="familyIndexResultMap">
SELECT a.id, a.name,
b.id device_id,
b.name device_name,
b.numbering device_numbering,
b.online_status device_onlineStatus,
b.pic device_pic,
c.id room_id,
c.name room_name
FROM
sh_family a LEFT JOIN sh_device b ON a.id = b.family_id LEFT JOIN sh_family_room c ON a.id = c.family_id
WHERE
<choose>
<when test="familyId != null and familyId !=''">
a.id = ${familyId}
</when>
<otherwise>
a.id = (SELECT d.id FROM sh_family d WHERE d.user_id = ${userId} LIMIT 1)
</otherwise>
</choose>
</select>
</mapper> </mapper>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="tech.glinfo.enbao.modules.sysuser.dao.SysUserDao">
<!-- 可根据自己的需求,是否要使用 -->
<resultMap type="tech.glinfo.enbao.modules.sysuser.entity.SysUserEntity" id="sysUserMap">
<result property="userId" column="user_id"/>
<result property="username" column="username"/>
<result property="password" column="password"/>
<result property="salt" column="salt"/>
<result property="email" column="email"/>
<result property="mobile" column="mobile"/>
<result property="status" column="status"/>
<result property="type" column="type"/>
<result property="createUserId" column="create_user_id"/>
<result property="createTime" column="create_time"/>
</resultMap>
</mapper>
\ No newline at end of file
...@@ -16,6 +16,21 @@ CREATE TABLE `app_user` ( ...@@ -16,6 +16,21 @@ CREATE TABLE `app_user` (
KEY `app_user_phone` (`phone`) USING BTREE KEY `app_user_phone` (`phone`) USING BTREE
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='APP用户'; ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='APP用户';
DROP TABLE IF EXISTS `app_api_log`;
CREATE TABLE `app_api_log` (
`id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '主键id',
`userid` int(11) COMMENT '用户',
`phone` varchar(11) COMMENT '手机号码',
`operation` varchar(50) COMMENT '用户操作',
`method` varchar(200) COMMENT '请求方法',
`params` text COMMENT '请求参数',
`time` bigint NOT NULL COMMENT '执行时长(毫秒)',
`ip` varchar(64) COMMENT 'IP地址',
`create_date` datetime COMMENT '创建时间',
PRIMARY KEY (`id`),
KEY `app_api_log_phone` (`phone`) USING BTREE
) ENGINE=`InnoDB` DEFAULT CHARACTER SET utf8mb4 COMMENT='API日志';
CREATE TABLE `sh_category` ( CREATE TABLE `sh_category` (
`id` int(11) NOT NULL AUTO_INCREMENT, `id` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(64) DEFAULT NULL COMMENT '分类名称', `name` varchar(64) DEFAULT NULL COMMENT '分类名称',
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论