Commit 6e967f50 by tyfanchz

代码修改

1 parent 140aaf97
...@@ -7,7 +7,6 @@ import cn.com.glsx.smart.modules.model.ValidateGroups; ...@@ -7,7 +7,6 @@ import cn.com.glsx.smart.modules.model.ValidateGroups;
import cn.com.glsx.smart.modules.model.request.SmartProductQueryReq; import cn.com.glsx.smart.modules.model.request.SmartProductQueryReq;
import cn.com.glsx.smart.modules.model.request.SmartProductSaveReq; import cn.com.glsx.smart.modules.model.request.SmartProductSaveReq;
import cn.com.glsx.smart.modules.service.SmartProductService; import cn.com.glsx.smart.modules.service.SmartProductService;
import cn.hutool.core.bean.BeanUtil;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONArray;
import com.github.pagehelper.PageInfo; import com.github.pagehelper.PageInfo;
...@@ -45,8 +44,7 @@ public class ProductController { ...@@ -45,8 +44,7 @@ public class ProductController {
@GetMapping("/getPageList") @GetMapping("/getPageList")
public R getPageList(SmartProductQueryReq req) { public R getPageList(SmartProductQueryReq req) {
log.info("$$$$ /product/getPageList param: {}", JSON.toJSONString(req)); log.info("$$$$ /product/getPageList param: {}", JSON.toJSONString(req));
SmartProduct product = BeanUtil.toBean(req, SmartProduct.class); PageInfo<SmartProduct> pageInfo = productService.getPageList(req);
PageInfo<SmartProduct> pageInfo = productService.getPageList(product);
return R.ok().putPageData(pageInfo); return R.ok().putPageData(pageInfo);
} }
...@@ -59,8 +57,7 @@ public class ProductController { ...@@ -59,8 +57,7 @@ public class ProductController {
@GetMapping("/getList") @GetMapping("/getList")
public R getList(SmartProductQueryReq req) { public R getList(SmartProductQueryReq req) {
log.info("$$$$ /product/getList param: {}", JSON.toJSONString(req)); log.info("$$$$ /product/getList param: {}", JSON.toJSONString(req));
SmartProduct product = BeanUtil.toBean(req, SmartProduct.class); List<SmartProduct> productList = productService.getList(req);
List<SmartProduct> productList = productService.getList(product);
return R.ok().data(productList); return R.ok().data(productList);
} }
...@@ -96,8 +93,8 @@ public class ProductController { ...@@ -96,8 +93,8 @@ public class ProductController {
* @return 结果 * @return 结果
*/ */
@GetMapping("/getProductAndCategory") @GetMapping("/getProductAndCategory")
public R getProductAndCategory() { public R getProductTree() {
log.info("$$$$ /product/getProductAndCategory..."); log.info("$$$$ /product/getProductTree...");
JSONArray productTree = productService.getProductTree(); JSONArray productTree = productService.getProductTree();
return R.ok().data(productTree); return R.ok().data(productTree);
} }
...@@ -111,9 +108,8 @@ public class ProductController { ...@@ -111,9 +108,8 @@ public class ProductController {
@PostMapping("/save") @PostMapping("/save")
public R save(@RequestBody @Validated(ValidateGroups.Insert.class) SmartProductSaveReq req) { public R save(@RequestBody @Validated(ValidateGroups.Insert.class) SmartProductSaveReq req) {
log.info("$$$$ /product/save param: {}", JSON.toJSONString(req)); log.info("$$$$ /product/save param: {}", JSON.toJSONString(req));
SmartProduct product = BeanUtil.toBean(req, SmartProduct.class); int rows = productService.save(req);
Boolean success = productService.save(product); return R.ok().data(rows > 0);
return R.ok().data(success);
} }
/** /**
...@@ -150,7 +146,7 @@ public class ProductController { ...@@ -150,7 +146,7 @@ public class ProductController {
@PostMapping("/putOnOff") @PostMapping("/putOnOff")
public R putOnOff(@RequestParam Long id) { public R putOnOff(@RequestParam Long id) {
log.info("$$$$ /product/putOnOff param: {}", id); log.info("$$$$ /product/putOnOff param: {}", id);
Boolean success = productService.putOnOff(id); int rows = productService.putOnOff(id);
return R.ok().data(success); return R.ok().data(rows > 0);
} }
} }
...@@ -6,7 +6,6 @@ import cn.com.glsx.smart.modules.model.ValidateGroups; ...@@ -6,7 +6,6 @@ import cn.com.glsx.smart.modules.model.ValidateGroups;
import cn.com.glsx.smart.modules.model.request.SmartProductTypeQueryReq; import cn.com.glsx.smart.modules.model.request.SmartProductTypeQueryReq;
import cn.com.glsx.smart.modules.model.request.SmartProductTypeSaveReq; import cn.com.glsx.smart.modules.model.request.SmartProductTypeSaveReq;
import cn.com.glsx.smart.modules.service.SmartProductTypeService; import cn.com.glsx.smart.modules.service.SmartProductTypeService;
import cn.hutool.core.bean.BeanUtil;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
import com.github.pagehelper.PageInfo; import com.github.pagehelper.PageInfo;
import com.glsx.plat.core.web.R; import com.glsx.plat.core.web.R;
...@@ -43,8 +42,7 @@ public class ProductTypeController { ...@@ -43,8 +42,7 @@ public class ProductTypeController {
@GetMapping("/getPageList") @GetMapping("/getPageList")
public R getPageList(SmartProductTypeQueryReq req) { public R getPageList(SmartProductTypeQueryReq req) {
log.info("$$$$ /productType/getPageList param: {}", JSON.toJSONString(req)); log.info("$$$$ /productType/getPageList param: {}", JSON.toJSONString(req));
SmartProductType productType = BeanUtil.toBean(req, SmartProductType.class); PageInfo<SmartProductType> pageInfo = productTypeService.getPageList(req);
PageInfo<SmartProductType> pageInfo = productTypeService.getPageList(productType);
return R.ok().putPageData(pageInfo); return R.ok().putPageData(pageInfo);
} }
...@@ -57,8 +55,7 @@ public class ProductTypeController { ...@@ -57,8 +55,7 @@ public class ProductTypeController {
@GetMapping("/getList") @GetMapping("/getList")
public R getList(SmartProductTypeQueryReq req) { public R getList(SmartProductTypeQueryReq req) {
log.info("$$$$ /productType/getList param: {}", JSON.toJSONString(req)); log.info("$$$$ /productType/getList param: {}", JSON.toJSONString(req));
SmartProductType productType = BeanUtil.toBean(req, SmartProductType.class); List<SmartProductType> productTypeList = productTypeService.getList(req);
List<SmartProductType> productTypeList = productTypeService.getList(productType);
return R.ok().data(productTypeList); return R.ok().data(productTypeList);
} }
...@@ -83,9 +80,8 @@ public class ProductTypeController { ...@@ -83,9 +80,8 @@ public class ProductTypeController {
@PostMapping("/save") @PostMapping("/save")
public R save(@RequestBody @Validated(ValidateGroups.Insert.class) SmartProductTypeSaveReq req) { public R save(@RequestBody @Validated(ValidateGroups.Insert.class) SmartProductTypeSaveReq req) {
log.info("$$$$ /productType/save param: {}", JSON.toJSONString(req)); log.info("$$$$ /productType/save param: {}", JSON.toJSONString(req));
SmartProductType productType = BeanUtil.toBean(req, SmartProductType.class); int rows = productTypeService.save(req);
Boolean success = productTypeService.save(productType); return R.ok().data(rows > 0);
return R.ok().data(success);
} }
/** /**
......
package cn.com.glsx.smart.modules.controller; package cn.com.glsx.smart.modules.controller;
import java.util.ArrayList;
import java.util.List;
import cn.com.glsx.smart.modules.entity.SmartUserDevice; import cn.com.glsx.smart.modules.entity.SmartUserDevice;
import cn.com.glsx.smart.modules.entity.SmartUserRelation; import cn.com.glsx.smart.modules.entity.SmartUserRelation;
import cn.com.glsx.smart.modules.model.request.SmartUserDeviceQueryReq;
import cn.com.glsx.smart.modules.model.response.RemoteDeviceResp; import cn.com.glsx.smart.modules.model.response.RemoteDeviceResp;
import cn.com.glsx.smart.modules.service.SmartProductTypeService; import cn.com.glsx.smart.modules.service.SmartProductTypeService;
import cn.com.glsx.smart.modules.service.SmartUserDeviceService; import cn.com.glsx.smart.modules.service.SmartUserDeviceService;
...@@ -17,10 +20,12 @@ import lombok.extern.slf4j.Slf4j; ...@@ -17,10 +20,12 @@ import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections.CollectionUtils; import org.apache.commons.collections.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import java.util.ArrayList; import org.springframework.web.bind.annotation.RequestMethod;
import java.util.List; import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
/** /**
* 远程产品服务controller * 远程产品服务controller
...@@ -95,10 +100,10 @@ public class RemoteProductController { ...@@ -95,10 +100,10 @@ public class RemoteProductController {
*/ */
private List<RemoteDeviceResp> getRemoteDeviceV2(Long userId, Byte status) { private List<RemoteDeviceResp> getRemoteDeviceV2(Long userId, Byte status) {
List<RemoteDeviceResp> deviceRespList = new ArrayList<>(); List<RemoteDeviceResp> deviceRespList = new ArrayList<>();
SmartUserDevice record = new SmartUserDevice(); SmartUserDeviceQueryReq req = new SmartUserDeviceQueryReq();
record.setUserId(userId); req.setUserId(userId);
record.setType((byte)1); req.setType((byte)1);
List<SmartUserDevice> list = userDeviceService.getList(record); List<SmartUserDevice> list = userDeviceService.getList(req);
if(CollectionUtils.isEmpty(list)){ if(CollectionUtils.isEmpty(list)){
return deviceRespList; return deviceRespList;
} }
......
package cn.com.glsx.smart.modules.controller; package cn.com.glsx.smart.modules.controller;
import java.util.List;
import cn.com.glsx.smart.common.exception.ChejiaBusinessException; import cn.com.glsx.smart.common.exception.ChejiaBusinessException;
import cn.com.glsx.smart.common.exception.ResultEnum; import cn.com.glsx.smart.common.exception.ResultEnum;
import cn.com.glsx.smart.modules.entity.SmartUserDevice; import cn.com.glsx.smart.modules.entity.SmartUserDevice;
import cn.com.glsx.smart.modules.model.ValidateGroups;
import cn.com.glsx.smart.modules.model.request.SmartUserDeviceDeleteReq;
import cn.com.glsx.smart.modules.model.request.SmartUserDeviceQueryReq;
import cn.com.glsx.smart.modules.model.request.SmartUserDeviceSaveReq;
import cn.com.glsx.smart.modules.service.SmartUserDeviceService; import cn.com.glsx.smart.modules.service.SmartUserDeviceService;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
...@@ -10,9 +15,13 @@ import com.glsx.plat.common.utils.StringUtils; ...@@ -10,9 +15,13 @@ import com.glsx.plat.common.utils.StringUtils;
import com.glsx.plat.core.web.R; import com.glsx.plat.core.web.R;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*; import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import java.util.List; import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
/** /**
* <p>Description: 用户设备业务 * <p>Description: 用户设备业务
...@@ -35,7 +44,7 @@ public class UserDeviceController { ...@@ -35,7 +44,7 @@ public class UserDeviceController {
* @return 结果 * @return 结果
*/ */
@GetMapping("/getList") @GetMapping("/getList")
public R getList(SmartUserDevice req) { public R getList(SmartUserDeviceQueryReq req) {
log.info("$$$$ /userDevice/getList param: {}", JSON.toJSONString(req)); log.info("$$$$ /userDevice/getList param: {}", JSON.toJSONString(req));
if (req.getUserId() == null) { if (req.getUserId() == null) {
throw ChejiaBusinessException.create(ResultEnum.PARAM_EMPTY, "userId"); throw ChejiaBusinessException.create(ResultEnum.PARAM_EMPTY, "userId");
...@@ -51,7 +60,7 @@ public class UserDeviceController { ...@@ -51,7 +60,7 @@ public class UserDeviceController {
* @return 结果 * @return 结果
*/ */
@GetMapping("/getByDeviceId") @GetMapping("/getByDeviceId")
public R getByDeviceId(SmartUserDevice req) { public R getByDeviceId(SmartUserDeviceQueryReq req) {
log.info("$$$$ /userDevice/getByDeviceId param: {}", JSON.toJSONString(req)); log.info("$$$$ /userDevice/getByDeviceId param: {}", JSON.toJSONString(req));
if (StringUtils.isBlank(req.getDeviceId())) { if (StringUtils.isBlank(req.getDeviceId())) {
throw ChejiaBusinessException.create(ResultEnum.PARAM_EMPTY, "deviceId"); throw ChejiaBusinessException.create(ResultEnum.PARAM_EMPTY, "deviceId");
...@@ -67,11 +76,12 @@ public class UserDeviceController { ...@@ -67,11 +76,12 @@ public class UserDeviceController {
* @return 结果 * @return 结果
*/ */
@PostMapping("/save") @PostMapping("/save")
public R save(@RequestBody SmartUserDevice req) { public R save(@RequestBody @Validated(ValidateGroups.Insert.class)
SmartUserDeviceSaveReq req) {
log.info("$$$$ /userDevice/save param: {}", JSON.toJSONString(req)); log.info("$$$$ /userDevice/save param: {}", JSON.toJSONString(req));
if (StringUtils.isBlank(req.getDeviceId()) || req.getChannel() == null) { //if (StringUtils.isBlank(req.getDeviceId()) || req.getChannel() == null) {
throw ChejiaBusinessException.create(ResultEnum.PARAM_EMPTY, "deviceId, channel"); // throw ChejiaBusinessException.create(ResultEnum.PARAM_EMPTY, "deviceId, channel");
} //}
int rows = userDeviceService.save(req); int rows = userDeviceService.save(req);
return R.ok().data(rows > 0); return R.ok().data(rows > 0);
} }
...@@ -83,11 +93,12 @@ public class UserDeviceController { ...@@ -83,11 +93,12 @@ public class UserDeviceController {
* @return 结果 * @return 结果
*/ */
@PostMapping("/deleteDevice") @PostMapping("/deleteDevice")
public R deleteDevice(@RequestBody SmartUserDevice req) { public R deleteDevice(@RequestBody @Validated(ValidateGroups.Delete.class)
SmartUserDeviceDeleteReq req) {
log.info("$$$$ /userDevice/deleteDevice param: {}", JSON.toJSONString(req)); log.info("$$$$ /userDevice/deleteDevice param: {}", JSON.toJSONString(req));
if (StringUtils.isBlank(req.getDeviceId()) || req.getChannel() == null) { //if (StringUtils.isBlank(req.getDeviceId()) || req.getChannel() == null) {
throw ChejiaBusinessException.create(ResultEnum.PARAM_EMPTY, "deviceId, channel"); // throw ChejiaBusinessException.create(ResultEnum.PARAM_EMPTY, "deviceId, channel");
} //}
int rows = userDeviceService.deleteDevice(req); int rows = userDeviceService.deleteDevice(req);
return R.ok().data(rows > 0); return R.ok().data(rows > 0);
} }
......
package cn.com.glsx.smart.modules.mapper; package cn.com.glsx.smart.modules.mapper;
import java.util.List;
import cn.com.glsx.smart.modules.entity.SmartUserDevice; import cn.com.glsx.smart.modules.entity.SmartUserDevice;
import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Mapper;
import java.util.List;
/** /**
* <p>Description: * <p>Description:
* <p>Project: chejia-smart * <p>Project: chejia-smart
...@@ -16,11 +15,11 @@ import java.util.List; ...@@ -16,11 +15,11 @@ import java.util.List;
@Mapper @Mapper
public interface SmartUserDeviceMapper extends tk.mybatis.mapper.common.Mapper<SmartUserDevice> { public interface SmartUserDeviceMapper extends tk.mybatis.mapper.common.Mapper<SmartUserDevice> {
List<SmartUserDevice> getList(SmartUserDevice req); List<SmartUserDevice> getList(SmartUserDevice userDevice);
SmartUserDevice getByDeviceId(SmartUserDevice req); SmartUserDevice getByDeviceId(SmartUserDevice userDevice);
int deleteDevice(SmartUserDevice req); int deleteDevice(SmartUserDevice userDevice);
List<SmartUserDevice> findByParentId(String infrared_id); List<SmartUserDevice> findByParentId(String infrared_id);
} }
package cn.com.glsx.smart.modules.model.request;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import java.util.Date;
import cn.com.glsx.smart.modules.model.ValidateGroups;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import lombok.Data;
/**
* 车家智能用户设备表
*/
@Data
@JsonIgnoreProperties(ignoreUnknown = true)
public class SmartUserDeviceDeleteReq {
/**
* 第三方平台用户 ID
*/
private String uid;
/**
* 产品图标
*/
private String icon;
/**
* 标识ID
*/
private Long id;
/**
* 用户ID 关联smart_user_relation中id
*/
private Long userId;
/**
* 设备id(或者网关设备)
*/
@NotBlank(message = "deviceId不能为空", groups = ValidateGroups.Delete.class)
private String deviceId;
/**
* 设备名称
*/
private String deviceName;
/**
* 类型:1实体设备 2虚拟红外设备
*/
private Byte type;
/**
* 第三方平台标识 1涂鸦 2绿米
*/
@NotNull(message = "channel不能为空", groups = ValidateGroups.Delete.class)
private Byte channel;
/**
* 父设备id
*/
private String parentId;
/**
* 接入平台产品id
*/
private String platformProductId;
/**
* 创建时间
*/
private Date createTime;
/**
* 更新时间
*/
private Date updateTime;
private String typeId;
}
package cn.com.glsx.smart.modules.model.request;
import java.io.Serializable;
import java.util.Date;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import lombok.Data;
/**
* 车家智能用户设备表
*/
@Data
@JsonIgnoreProperties(ignoreUnknown = true)
public class SmartUserDeviceQueryReq implements Serializable {
/**
* 第三方平台用户 ID
*/
private String uid;
/**
* 产品图标
*/
private String icon;
/**
* 标识ID
*/
private Long id;
/**
* 用户ID 关联smart_user_relation中id
*/
private Long userId;
/**
* 设备id(或者网关设备)
*/
private String deviceId;
/**
* 设备名称
*/
private String deviceName;
/**
* 类型:1实体设备 2虚拟红外设备
*/
private Byte type;
/**
* 第三方平台标识 1涂鸦 2绿米
*/
private Byte channel;
/**
* 父设备id
*/
private String parentId;
/**
* 接入平台产品id
*/
private String platformProductId;
/**
* 创建时间
*/
private Date createTime;
/**
* 更新时间
*/
private Date updateTime;
private String typeId;
}
package cn.com.glsx.smart.modules.model.request;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import java.util.Date;
import cn.com.glsx.smart.modules.model.ValidateGroups;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import lombok.Data;
/**
* 车家智能用户设备表
*/
@Data
@JsonIgnoreProperties(ignoreUnknown = true)
public class SmartUserDeviceSaveReq {
/**
* 第三方平台用户 ID
*/
private String uid;
/**
* 产品图标
*/
private String icon;
/**
* 标识ID
*/
private Long id;
/**
* 用户ID 关联smart_user_relation中id
*/
private Long userId;
/**
* 设备id(或者网关设备)
*/
@NotBlank(message = "deviceId不能为空", groups = ValidateGroups.Insert.class)
private String deviceId;
/**
* 设备名称
*/
private String deviceName;
/**
* 类型:1实体设备 2虚拟红外设备
*/
private Byte type;
/**
* 第三方平台标识 1涂鸦 2绿米
*/
@NotNull(message = "channel不能为空", groups = ValidateGroups.Insert.class)
private Byte channel;
/**
* 父设备id
*/
private String parentId;
/**
* 接入平台产品id
*/
private String platformProductId;
/**
* 创建时间
*/
private Date createTime;
/**
* 更新时间
*/
private Date updateTime;
private String typeId;
}
package cn.com.glsx.smart.modules.model.response;
import java.util.Date;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import lombok.Data;
/**
* 车家智能用户设备表
*/
@Data
@JsonIgnoreProperties(ignoreUnknown = true)
public class SmartUserDeviceResp {
/**
* 第三方平台用户 ID
*/
private String uid;
/**
* 产品图标
*/
private String icon;
/**
* 标识ID
*/
private Long id;
/**
* 用户ID 关联smart_user_relation中id
*/
private Long userId;
/**
* 设备id(或者网关设备)
*/
private String deviceId;
/**
* 设备名称
*/
private String deviceName;
/**
* 类型:1实体设备 2虚拟红外设备
*/
private Byte type;
/**
* 第三方平台标识 1涂鸦 2绿米
*/
private Byte channel;
/**
* 父设备id
*/
private String parentId;
/**
* 接入平台产品id
*/
private String platformProductId;
/**
* 创建时间
*/
private Date createTime;
/**
* 更新时间
*/
private Date updateTime;
private String typeId;
}
package cn.com.glsx.smart.modules.service; package cn.com.glsx.smart.modules.service;
import java.util.List;
import cn.com.glsx.smart.modules.entity.SmartDeviceOrder; import cn.com.glsx.smart.modules.entity.SmartDeviceOrder;
import cn.com.glsx.smart.modules.entity.SmartProduct; import cn.com.glsx.smart.modules.entity.SmartProduct;
import cn.com.glsx.smart.modules.model.request.SmartProductQueryReq;
import cn.com.glsx.smart.modules.model.request.SmartProductSaveReq;
import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONArray;
import com.github.pagehelper.PageInfo; import com.github.pagehelper.PageInfo;
import java.util.List;
/** /**
* <p>Description: * <p>Description:
* <p>Project: chejia-smart * <p>Project: chejia-smart
...@@ -16,25 +17,21 @@ import java.util.List; ...@@ -16,25 +17,21 @@ import java.util.List;
*/ */
public interface SmartProductService { public interface SmartProductService {
PageInfo<SmartProduct> getPageList(SmartProduct product); PageInfo<SmartProduct> getPageList(SmartProductQueryReq req);
List<SmartProduct> getList(SmartProduct product); List<SmartProduct> getList(SmartProductQueryReq req);
List<SmartProduct> getByPlatProductIdList(List<String> list);
List<SmartProduct> getListByCondition(SmartProduct product); List<SmartProduct> getListByCondition(SmartProduct product);
SmartProduct getById(Long id); SmartProduct getById(Long id);
JSONArray getProductAndCategory();
JSONArray getProductTree(); JSONArray getProductTree();
Boolean save(SmartProduct product); int save(SmartProductSaveReq req);
List<SmartDeviceOrder> getCommandSetById(Long id); List<SmartDeviceOrder> getCommandSetById(Long id);
List<String> getSupportedCommands(String platformProductId); List<String> getSupportedCommands(String platformProductId);
Boolean putOnOff(Long id); int putOnOff(Long id);
} }
package cn.com.glsx.smart.modules.service; package cn.com.glsx.smart.modules.service;
import java.util.List;
import cn.com.glsx.smart.modules.entity.SmartProductType; import cn.com.glsx.smart.modules.entity.SmartProductType;
import cn.com.glsx.smart.modules.entity.SmartUserDevice; import cn.com.glsx.smart.modules.entity.SmartUserDevice;
import cn.com.glsx.smart.modules.model.request.SmartProductTypeQueryReq;
import cn.com.glsx.smart.modules.model.request.SmartProductTypeSaveReq;
import cn.com.glsx.smart.modules.model.response.RemoteDeviceResp; import cn.com.glsx.smart.modules.model.response.RemoteDeviceResp;
import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONArray;
import com.github.pagehelper.PageInfo; import com.github.pagehelper.PageInfo;
import java.util.List;
/** /**
* <p>Description: * <p>Description:
* <p>Project: chejia-smart * <p>Project: chejia-smart
...@@ -17,15 +18,13 @@ import java.util.List; ...@@ -17,15 +18,13 @@ import java.util.List;
*/ */
public interface SmartProductTypeService { public interface SmartProductTypeService {
PageInfo<SmartProductType> getPageList(SmartProductType productType); PageInfo<SmartProductType> getPageList(SmartProductTypeQueryReq req);
List<SmartProductType> getList(SmartProductType productType);
List<SmartProductType> getByIdList(List<Long> list); List<SmartProductType> getList(SmartProductTypeQueryReq req);
SmartProductType getById(Long id); SmartProductType getById(Long id);
Boolean save(SmartProductType productType); int save(SmartProductTypeSaveReq req);
List<SmartProductType> getListAndContent(List<Long> list); List<SmartProductType> getListAndContent(List<Long> list);
......
package cn.com.glsx.smart.modules.service; package cn.com.glsx.smart.modules.service;
import java.util.List;
import cn.com.glsx.smart.modules.entity.SmartUserDevice; import cn.com.glsx.smart.modules.entity.SmartUserDevice;
import cn.com.glsx.smart.modules.model.request.SmartUserDeviceDeleteReq;
import cn.com.glsx.smart.modules.model.request.SmartUserDeviceQueryReq;
import cn.com.glsx.smart.modules.model.request.SmartUserDeviceSaveReq;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import java.util.List;
/** /**
* <p>Description: * <p>Description:
* <p>Project: chejia-smart * <p>Project: chejia-smart
...@@ -14,13 +16,13 @@ import java.util.List; ...@@ -14,13 +16,13 @@ import java.util.List;
*/ */
public interface SmartUserDeviceService { public interface SmartUserDeviceService {
List<SmartUserDevice> getList(SmartUserDevice req); List<SmartUserDevice> getList(SmartUserDeviceQueryReq req);
SmartUserDevice getByDeviceId(SmartUserDevice req); SmartUserDevice getByDeviceId(SmartUserDeviceQueryReq req);
int save(SmartUserDevice req); int save(SmartUserDeviceSaveReq req);
int deleteDevice(SmartUserDevice req); int deleteDevice(SmartUserDeviceDeleteReq req);
String getUserBindKey(String token); String getUserBindKey(String token);
......
package cn.com.glsx.smart.modules.service.impl; package cn.com.glsx.smart.modules.service.impl;
import javax.annotation.Resource;
import java.util.Date;
import java.util.List;
import java.util.stream.Collectors;
import cn.com.glsx.smart.common.constant.Constants; import cn.com.glsx.smart.common.constant.Constants;
import cn.com.glsx.smart.common.enums.DeviceChannelEnum; import cn.com.glsx.smart.common.enums.DeviceChannelEnum;
import cn.com.glsx.smart.common.exception.ChejiaBusinessException; import cn.com.glsx.smart.common.exception.ChejiaBusinessException;
...@@ -10,8 +14,11 @@ import cn.com.glsx.smart.modules.entity.SmartSysCode; ...@@ -10,8 +14,11 @@ import cn.com.glsx.smart.modules.entity.SmartSysCode;
import cn.com.glsx.smart.modules.mapper.SmartDeviceOrderMapper; import cn.com.glsx.smart.modules.mapper.SmartDeviceOrderMapper;
import cn.com.glsx.smart.modules.mapper.SmartProductMapper; import cn.com.glsx.smart.modules.mapper.SmartProductMapper;
import cn.com.glsx.smart.modules.mapper.SmartSysCodeMapper; import cn.com.glsx.smart.modules.mapper.SmartSysCodeMapper;
import cn.com.glsx.smart.modules.model.request.SmartProductQueryReq;
import cn.com.glsx.smart.modules.model.request.SmartProductSaveReq;
import cn.com.glsx.smart.modules.service.BaseService; import cn.com.glsx.smart.modules.service.BaseService;
import cn.com.glsx.smart.modules.service.SmartProductService; import cn.com.glsx.smart.modules.service.SmartProductService;
import cn.hutool.core.bean.BeanUtil;
import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.github.pagehelper.PageInfo; import com.github.pagehelper.PageInfo;
...@@ -21,12 +28,6 @@ import org.springframework.beans.factory.annotation.Autowired; ...@@ -21,12 +28,6 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.stream.Collectors;
/** /**
* <p>Description: 产品列表业务 * <p>Description: 产品列表业务
* <p>Project: chejia-smart * <p>Project: chejia-smart
...@@ -49,13 +50,13 @@ public class SmartProductServiceImpl extends BaseService implements SmartProduct ...@@ -49,13 +50,13 @@ public class SmartProductServiceImpl extends BaseService implements SmartProduct
/** /**
* 获取产品列表。 * 获取产品列表。
* *
* @param product 请求体 * @param req 请求体
* @return 结果 * @return 结果
*/ */
@Override @Override
public PageInfo<SmartProduct> getPageList(SmartProduct product) { public PageInfo<SmartProduct> getPageList(SmartProductQueryReq req) {
super.startPagination(product); super.startPagination(req);
return PageInfo.of(this.getList(product)); return PageInfo.of(this.getList(req));
} }
@Override @Override
...@@ -64,16 +65,12 @@ public class SmartProductServiceImpl extends BaseService implements SmartProduct ...@@ -64,16 +65,12 @@ public class SmartProductServiceImpl extends BaseService implements SmartProduct
} }
@Override @Override
public List<SmartProduct> getList(SmartProduct product) { public List<SmartProduct> getList(SmartProductQueryReq req) {
SmartProduct product = BeanUtil.toBean(req, SmartProduct.class);
List<SmartProduct> productList = productMapper.getList(product); List<SmartProduct> productList = productMapper.getList(product);
return productList; return productList;
} }
@Override
public List<SmartProduct> getByPlatProductIdList(List<String> list) {
return productMapper.getByPlatProductIdList(list);
}
/** /**
* 根据 id 查询产品详情。 * 根据 id 查询产品详情。
* *
...@@ -95,62 +92,6 @@ public class SmartProductServiceImpl extends BaseService implements SmartProduct ...@@ -95,62 +92,6 @@ public class SmartProductServiceImpl extends BaseService implements SmartProduct
* @return 结果 * @return 结果
*/ */
@Override @Override
public JSONArray getProductAndCategory() {
SmartSysCode example = new SmartSysCode();
example.setDictType("smart_device");
List<SmartSysCode> categoryList = sysCodeMapper.getList(example);
List<SmartProduct> allProductList = productMapper.getAllProductList();
JSONArray resultList = new JSONArray();
if (CollectionUtils.isNotEmpty(categoryList)) {
// 筛选一级分类
List<SmartSysCode> firstCategoryList = categoryList.stream()
.filter(index -> index.getLevel() == 0).collect(Collectors.toList());
// 筛选二级分类
List<SmartSysCode> secondCategoryList = categoryList.stream()
.filter(index -> index.getLevel() == 1).collect(Collectors.toList());
// 一级分类数据
firstCategoryList.forEach(firstCategory -> {
JSONObject firstObj = new JSONObject();
firstObj.put("title", firstCategory.getDictValue());
List<JSONObject> firstItemList = new ArrayList<>();
// 获取此分类下的子分类
List<SmartSysCode> subCategoryList = secondCategoryList.stream()
.filter(inx -> inx.getParentKey().equals(firstCategory.getDictKey()))
.collect(Collectors.toList());
// 子分类数据
subCategoryList.forEach(subCategory -> {
JSONObject subObj = new JSONObject();
subObj.put("title", subCategory.getDictValue());
// 获取此分类下的产品
List<SmartProduct> productList = allProductList.stream()
.filter(pro -> pro.getCategoryKey().equals(subCategory.getDictKey()))
.collect(Collectors.toList());
// 映射产品信息
List<JSONObject> productInfoList = productList.stream()
.map(product -> {
JSONObject productObj = new JSONObject();
productObj.put("name", product.getProductName());
productObj.put("iconUrl", product.getIconUrl());
productObj.put("typeId", product.getTypeId());
productObj.put("shopProductId", product.getShopProductId());
return productObj;
}).collect(Collectors.toList());
subObj.put("list", productInfoList);
firstItemList.add(subObj);
});
firstObj.put("list", firstItemList);
resultList.add(firstObj);
});
}
return resultList;
}
/**
* <p>获取树状的产品数据。
*
* @return 结果
*/
@Override
public JSONArray getProductTree() { public JSONArray getProductTree() {
SmartSysCode example = new SmartSysCode(); SmartSysCode example = new SmartSysCode();
example.setDictType("smart_device"); example.setDictType("smart_device");
...@@ -163,17 +104,17 @@ public class SmartProductServiceImpl extends BaseService implements SmartProduct ...@@ -163,17 +104,17 @@ public class SmartProductServiceImpl extends BaseService implements SmartProduct
/** /**
* 保存产品。无则插入,有则更新。 * 保存产品。无则插入,有则更新。
* *
* @param product 产品 * @param req 产品
* @return 是否成功 * @return 是否成功
*/ */
@Override @Override
@Transactional @Transactional
public Boolean save(SmartProduct product) { public int save(SmartProductSaveReq req) {
boolean success; int rows;
Date now = new Date(); Date now = new Date();
SmartProduct product = BeanUtil.toBean(req, SmartProduct.class);
product.setUpdateTime(now); product.setUpdateTime(now);
product.setUpdateBy(0L); product.setUpdateBy(0L);
if (product.getId() == null) { if (product.getId() == null) {
int nameCount = productMapper.countByProductName(product.getProductName()); int nameCount = productMapper.countByProductName(product.getProductName());
if (nameCount > 0) { if (nameCount > 0) {
...@@ -181,17 +122,17 @@ public class SmartProductServiceImpl extends BaseService implements SmartProduct ...@@ -181,17 +122,17 @@ public class SmartProductServiceImpl extends BaseService implements SmartProduct
} }
product.setCreateTime(now); product.setCreateTime(now);
product.setCreateBy(0L); product.setCreateBy(0L);
success = productMapper.insertSelective(product) > 0; rows = productMapper.insertSelective(product);
} else { } else {
SmartProduct record = productMapper.selectByPrimaryKey(product.getId()); SmartProduct record = productMapper.selectByPrimaryKey(product.getId());
if (record != null) { if (record != null) {
success = productMapper.updateByPrimaryKeySelective(product) > 0; rows = productMapper.updateByPrimaryKeySelective(product);
} else { } else {
throw ChejiaBusinessException.create(ResultEnum.PRODUCT_NOT_FOUND); throw ChejiaBusinessException.create(ResultEnum.PRODUCT_NOT_FOUND);
} }
} }
return success; return rows;
} }
/** /**
...@@ -220,15 +161,15 @@ public class SmartProductServiceImpl extends BaseService implements SmartProduct ...@@ -220,15 +161,15 @@ public class SmartProductServiceImpl extends BaseService implements SmartProduct
*/ */
@Override @Override
@Transactional @Transactional
public Boolean putOnOff(Long id) { public int putOnOff(Long id) {
boolean success; int rows;
SmartProduct product = productMapper.selectByPrimaryKey(id); SmartProduct product = productMapper.selectByPrimaryKey(id);
if (product == null) { if (product == null) {
throw ChejiaBusinessException.create(ResultEnum.PRODUCT_NOT_FOUND); throw ChejiaBusinessException.create(ResultEnum.PRODUCT_NOT_FOUND);
} }
product.setStatus((byte) (product.getStatus() ^ 0b00000001)); product.setStatus((byte) (product.getStatus() ^ 0b00000001));
success = productMapper.updateByPrimaryKeySelective(product) > 0; rows = productMapper.updateByPrimaryKeySelective(product);
return success; return rows;
} }
/** /**
......
package cn.com.glsx.smart.modules.service.impl; package cn.com.glsx.smart.modules.service.impl;
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import cn.com.glsx.smart.common.constant.Constants; import cn.com.glsx.smart.common.constant.Constants;
import cn.com.glsx.smart.common.exception.ChejiaBusinessException; import cn.com.glsx.smart.common.exception.ChejiaBusinessException;
import cn.com.glsx.smart.common.exception.ResultEnum; import cn.com.glsx.smart.common.exception.ResultEnum;
...@@ -9,9 +17,12 @@ import cn.com.glsx.smart.modules.entity.SmartUserDevice; ...@@ -9,9 +17,12 @@ import cn.com.glsx.smart.modules.entity.SmartUserDevice;
import cn.com.glsx.smart.modules.mapper.SmartProductMapper; import cn.com.glsx.smart.modules.mapper.SmartProductMapper;
import cn.com.glsx.smart.modules.mapper.SmartProductTypeMapper; import cn.com.glsx.smart.modules.mapper.SmartProductTypeMapper;
import cn.com.glsx.smart.modules.mapper.SmartUserDeviceMapper; import cn.com.glsx.smart.modules.mapper.SmartUserDeviceMapper;
import cn.com.glsx.smart.modules.model.request.SmartProductTypeQueryReq;
import cn.com.glsx.smart.modules.model.request.SmartProductTypeSaveReq;
import cn.com.glsx.smart.modules.model.response.RemoteDeviceResp; import cn.com.glsx.smart.modules.model.response.RemoteDeviceResp;
import cn.com.glsx.smart.modules.service.BaseService; import cn.com.glsx.smart.modules.service.BaseService;
import cn.com.glsx.smart.modules.service.SmartProductTypeService; import cn.com.glsx.smart.modules.service.SmartProductTypeService;
import cn.hutool.core.bean.BeanUtil;
import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.github.pagehelper.PageInfo; import com.github.pagehelper.PageInfo;
...@@ -21,10 +32,6 @@ import org.springframework.beans.factory.annotation.Value; ...@@ -21,10 +32,6 @@ import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
import java.util.*;
import java.util.stream.Collectors;
/** /**
* <p>Description: 产品类型业务 * <p>Description: 产品类型业务
* <p>Project: chejia-smart * <p>Project: chejia-smart
...@@ -51,31 +58,27 @@ public class SmartProductTypeServiceImpl extends BaseService implements SmartPro ...@@ -51,31 +58,27 @@ public class SmartProductTypeServiceImpl extends BaseService implements SmartPro
/** /**
* 分页获取产品类型列表。 * 分页获取产品类型列表。
* *
* @param productType 请求 * @param req 请求
* @return 结果 * @return 结果
*/ */
@Override @Override
public PageInfo<SmartProductType> getPageList(SmartProductType productType) { public PageInfo<SmartProductType> getPageList(SmartProductTypeQueryReq req) {
super.startPagination(productType); super.startPagination(req);
return PageInfo.of(this.getList(productType)); return PageInfo.of(this.getList(req));
} }
/** /**
* 获取产品类型列表,不分页。 * 获取产品类型列表,不分页。
* *
* @param productType 请求 * @param req 请求
* @return 结果 * @return 结果
*/ */
@Override @Override
public List<SmartProductType> getList(SmartProductType productType) { public List<SmartProductType> getList(SmartProductTypeQueryReq req) {
SmartProductType productType = BeanUtil.toBean(req, SmartProductType.class);
return productTypeMapper.getList(productType); return productTypeMapper.getList(productType);
} }
@Override
public List<SmartProductType> getByIdList(List<Long> list) {
return productTypeMapper.getByIdList(list);
}
/** /**
* 根据 id 获取产品类型。 * 根据 id 获取产品类型。
* *
...@@ -94,17 +97,17 @@ public class SmartProductTypeServiceImpl extends BaseService implements SmartPro ...@@ -94,17 +97,17 @@ public class SmartProductTypeServiceImpl extends BaseService implements SmartPro
/** /**
* 保存产品类型。 * 保存产品类型。
* *
* @param productType 产品类型 * @param req 产品类型
* @return 是否成功 * @return 是否成功
*/ */
@Override @Override
@Transactional @Transactional
public Boolean save(SmartProductType productType) { public int save(SmartProductTypeSaveReq req) {
boolean success; int rows;
Date now = new Date(); Date now = new Date();
SmartProductType productType = BeanUtil.toBean(req, SmartProductType.class);
productType.setUpdateTime(now); productType.setUpdateTime(now);
productType.setUpdateBy(0L); productType.setUpdateBy(0L);
if (productType.getId() == null) { if (productType.getId() == null) {
int nameCount = productTypeMapper.countByProductTypeName(productType.getTypeName()); int nameCount = productTypeMapper.countByProductTypeName(productType.getTypeName());
if (nameCount > 0) { if (nameCount > 0) {
...@@ -112,17 +115,17 @@ public class SmartProductTypeServiceImpl extends BaseService implements SmartPro ...@@ -112,17 +115,17 @@ public class SmartProductTypeServiceImpl extends BaseService implements SmartPro
} }
productType.setCreateTime(now); productType.setCreateTime(now);
productType.setCreateBy(0L); productType.setCreateBy(0L);
success = productTypeMapper.insertSelective(productType) > 0; rows = productTypeMapper.insertSelective(productType);
} else { } else {
SmartProductType record = productTypeMapper.selectByPrimaryKey(productType.getId()); SmartProductType record = productTypeMapper.selectByPrimaryKey(productType.getId());
if (record != null) { if (record != null) {
success = productTypeMapper.updateByPrimaryKeySelective(productType) > 0; rows = productTypeMapper.updateByPrimaryKeySelective(productType);
} else { } else {
throw ChejiaBusinessException.create(ResultEnum.PRODUCT_TYPE_NOT_FOUND); throw ChejiaBusinessException.create(ResultEnum.PRODUCT_TYPE_NOT_FOUND);
} }
} }
return success; return rows;
} }
@Override @Override
......
package cn.com.glsx.smart.modules.service.impl; package cn.com.glsx.smart.modules.service.impl;
import javax.annotation.Resource;
import javax.transaction.Transactional;
import java.nio.charset.StandardCharsets;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import cn.com.glsx.smart.common.constant.Constants; import cn.com.glsx.smart.common.constant.Constants;
import cn.com.glsx.smart.common.exception.ChejiaBusinessException; import cn.com.glsx.smart.common.exception.ChejiaBusinessException;
import cn.com.glsx.smart.common.exception.ResultEnum; import cn.com.glsx.smart.common.exception.ResultEnum;
...@@ -11,8 +18,12 @@ import cn.com.glsx.smart.modules.mapper.SmartProductMapper; ...@@ -11,8 +18,12 @@ import cn.com.glsx.smart.modules.mapper.SmartProductMapper;
import cn.com.glsx.smart.modules.mapper.SmartUserChannelMapper; import cn.com.glsx.smart.modules.mapper.SmartUserChannelMapper;
import cn.com.glsx.smart.modules.mapper.SmartUserDeviceMapper; import cn.com.glsx.smart.modules.mapper.SmartUserDeviceMapper;
import cn.com.glsx.smart.modules.mapper.SmartUserRelationMapper; import cn.com.glsx.smart.modules.mapper.SmartUserRelationMapper;
import cn.com.glsx.smart.modules.model.request.SmartUserDeviceDeleteReq;
import cn.com.glsx.smart.modules.model.request.SmartUserDeviceQueryReq;
import cn.com.glsx.smart.modules.model.request.SmartUserDeviceSaveReq;
import cn.com.glsx.smart.modules.service.BaseService; import cn.com.glsx.smart.modules.service.BaseService;
import cn.com.glsx.smart.modules.service.SmartUserDeviceService; import cn.com.glsx.smart.modules.service.SmartUserDeviceService;
import cn.hutool.core.bean.BeanUtil;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.glsx.plat.common.utils.HttpUtils; import com.glsx.plat.common.utils.HttpUtils;
...@@ -22,14 +33,6 @@ import org.springframework.beans.factory.annotation.Autowired; ...@@ -22,14 +33,6 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import javax.transaction.Transactional;
import java.nio.charset.StandardCharsets;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/** /**
* <p>Description: 用户设备业务 * <p>Description: 用户设备业务
* <p>Project: chejia-smart * <p>Project: chejia-smart
...@@ -71,51 +74,54 @@ public class SmartUserDeviceServiceImpl extends BaseService implements SmartUser ...@@ -71,51 +74,54 @@ public class SmartUserDeviceServiceImpl extends BaseService implements SmartUser
private RedisService redisService; private RedisService redisService;
@Override @Override
public List<SmartUserDevice> getList(SmartUserDevice req) { public List<SmartUserDevice> getList(SmartUserDeviceQueryReq req) {
return userDeviceMapper.getList(req); SmartUserDevice userDevice = BeanUtil.toBean(req, SmartUserDevice.class);
return userDeviceMapper.getList(userDevice);
} }
@Override @Override
public SmartUserDevice getByDeviceId(SmartUserDevice req) { public SmartUserDevice getByDeviceId(SmartUserDeviceQueryReq req) {
SmartUserDevice userDevice = userDeviceMapper.getByDeviceId(req); SmartUserDevice userDevice = BeanUtil.toBean(req, SmartUserDevice.class);
if (userDevice == null) { SmartUserDevice savedUserDevice = userDeviceMapper.getByDeviceId(userDevice);
if (savedUserDevice == null) {
throw ChejiaBusinessException.create(ResultEnum.DEVICE_NOT_FOUND); throw ChejiaBusinessException.create(ResultEnum.DEVICE_NOT_FOUND);
} }
return userDevice; return savedUserDevice;
} }
@Override @Override
@Transactional @Transactional
public int save(SmartUserDevice req) { public int save(SmartUserDeviceSaveReq req) {
int rows; int rows;
Date now = new Date(); Date now = new Date();
SmartUserDevice record = new SmartUserDevice(); SmartUserDevice userDevice = BeanUtil.toBean(req, SmartUserDevice.class);
record.setDeviceId(req.getDeviceId()); SmartUserDevice example = new SmartUserDevice();
record.setChannel(req.getChannel()); example.setDeviceId(userDevice.getDeviceId());
SmartUserDevice savedUserDevice = userDeviceMapper.selectOne(record); example.setChannel(userDevice.getChannel());
SmartUserDevice savedUserDevice = userDeviceMapper.selectOne(example);
if (savedUserDevice == null) { if (savedUserDevice == null) {
if (StringUtils.isBlank(req.getUid())) { if (StringUtils.isBlank(userDevice.getUid())) {
throw ChejiaBusinessException.create(ResultEnum.PARAM_EMPTY, "uid"); throw ChejiaBusinessException.create(ResultEnum.PARAM_EMPTY, "uid");
} }
// 根据第三方用户 id 查询用户绑定信息 // 根据第三方用户 id 查询用户绑定信息
SmartUserChannel ucRecord = new SmartUserChannel(); SmartUserChannel ucExample = new SmartUserChannel();
ucRecord.setThirdId(req.getUid()); ucExample.setThirdId(userDevice.getUid());
SmartUserChannel savedUserChannel = userChannelMapper.selectOne(ucRecord); SmartUserChannel savedUserChannel = userChannelMapper.selectOne(ucExample);
if (savedUserChannel == null) { if (savedUserChannel == null) {
throw ChejiaBusinessException.create(ResultEnum.USER_NOT_FOUND); throw ChejiaBusinessException.create(ResultEnum.USER_NOT_FOUND);
} }
// 插入用户信息 // 插入用户信息
req.setUserId(savedUserChannel.getUserId()); userDevice.setUserId(savedUserChannel.getUserId());
req.setCreateTime(now); userDevice.setCreateTime(now);
req.setUpdateTime(now); userDevice.setUpdateTime(now);
rows = userDeviceMapper.insertSelective(req); rows = userDeviceMapper.insertSelective(userDevice);
// 订阅用户设备 // 订阅用户设备
this.subscribeDevice(req); this.subscribeDevice(userDevice);
} else { } else {
if (StringUtils.isBlank(req.getDeviceName())) { if (StringUtils.isBlank(userDevice.getDeviceName())) {
throw ChejiaBusinessException.create(ResultEnum.PARAM_EMPTY, "deviceName"); throw ChejiaBusinessException.create(ResultEnum.PARAM_EMPTY, "deviceName");
} }
savedUserDevice.setDeviceName(req.getDeviceName()); savedUserDevice.setDeviceName(userDevice.getDeviceName());
savedUserDevice.setUpdateTime(now); savedUserDevice.setUpdateTime(now);
rows = userDeviceMapper.updateByPrimaryKeySelective(savedUserDevice); rows = userDeviceMapper.updateByPrimaryKeySelective(savedUserDevice);
} }
...@@ -123,9 +129,10 @@ public class SmartUserDeviceServiceImpl extends BaseService implements SmartUser ...@@ -123,9 +129,10 @@ public class SmartUserDeviceServiceImpl extends BaseService implements SmartUser
} }
@Override @Override
public int deleteDevice(SmartUserDevice req) { public int deleteDevice(SmartUserDeviceDeleteReq req) {
int rows; int rows;
rows = userDeviceMapper.deleteDevice(req); SmartUserDevice userDevice = BeanUtil.toBean(req, SmartUserDevice.class);
rows = userDeviceMapper.deleteDevice(userDevice);
return rows; return rows;
} }
...@@ -170,19 +177,22 @@ public class SmartUserDeviceServiceImpl extends BaseService implements SmartUser ...@@ -170,19 +177,22 @@ public class SmartUserDeviceServiceImpl extends BaseService implements SmartUser
/** /**
* 订阅用户设备 * 订阅用户设备
* *
* @param req 请求 * @param userDevice 请求
*/ */
private void subscribeDevice(SmartUserDevice req) { private void subscribeDevice(SmartUserDevice userDevice) {
if (Constants.USER_CHANNEL_AQARA.equals(req.getChannel())) { if (Constants.USER_CHANNEL_AQARA.equals(userDevice.getChannel())) {
// 只有绿米的设备需要订阅 // 只有绿米的设备需要订阅
if (StringUtils.isBlank(req.getPlatformProductId())) { if (StringUtils.isBlank(userDevice.getPlatformProductId())) {
throw ChejiaBusinessException.create(ResultEnum.PARAM_EMPTY, "platformProductId"); throw ChejiaBusinessException.create(ResultEnum.PARAM_EMPTY,
"platformProductId");
} }
// 通过用户手机号获取用户 token // 通过用户手机号获取用户 token
SmartUserRelation userRelation = userRelationMapper.selectByPrimaryKey(req.getUserId()); SmartUserRelation userRelation = userRelationMapper.selectByPrimaryKey(
userDevice.getUserId());
String token = (String) redisService.get(userRelation.getPhone() + "_aqara"); String token = (String) redisService.get(userRelation.getPhone() + "_aqara");
// 查询支持的指令集 // 查询支持的指令集
List<String> commands = productMapper.getSupportedCommands(req.getPlatformProductId()); List<String> commands = productMapper.getSupportedCommands(
userDevice.getPlatformProductId());
log.info("$$$$ subscribeDevice commands = {}", JSON.toJSONString(commands)); log.info("$$$$ subscribeDevice commands = {}", JSON.toJSONString(commands));
if (!commands.isEmpty()) { if (!commands.isEmpty()) {
// 指令集不为空才订阅 // 指令集不为空才订阅
...@@ -191,7 +201,7 @@ public class SmartUserDeviceServiceImpl extends BaseService implements SmartUser ...@@ -191,7 +201,7 @@ public class SmartUserDeviceServiceImpl extends BaseService implements SmartUser
reqParam.put("token", token); reqParam.put("token", token);
// 请求 body // 请求 body
JSONObject reqData = new JSONObject(); JSONObject reqData = new JSONObject();
reqData.put("did", req.getDeviceId()); reqData.put("did", userDevice.getDeviceId());
reqData.put("attrs", commands); reqData.put("attrs", commands);
JSONObject reqObj = new JSONObject(); JSONObject reqObj = new JSONObject();
reqObj.put("data", reqData); reqObj.put("data", reqData);
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!