Commit 8b4d97ba by wnb0128

车家智能移动端V1.0.0 场景数据功能开发--think.wang

1 parent a8bf69e2
......@@ -8,4 +8,9 @@ public interface Constant {
String DEFAULT_CHARSET = "UTF-8"; //默认字符集
String DEFAULT_PASSWORD = "123456";
String SCENE_CLASSIFICATION = "scene_classification"; //场景分类
Byte ONLINE = 1; //上线
Byte OFFLINE = 0; //下线
}
package com.glsx.api.controller;
import com.alibaba.fastjson.JSON;
import com.glsx.api.exception.BusinessException;
import com.glsx.api.exception.ResultEnum;
import com.glsx.api.pojo.GroupA;
import com.glsx.api.pojo.request.SceneReq;
import com.glsx.api.remote.SceneFeignClient;
import com.glsx.plat.core.web.R;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import javax.validation.groups.Default;
import java.util.Date;
/**
* <p>Description:场景数据接口
* <p>Project: chejia-smart
*
* @author wbh
* @date 2021-03-15
*/
@Slf4j
@RestController
@RequestMapping("/scene")
public class SceneController extends BaseController{
@Autowired
private SceneFeignClient sceneFeignClient;
@RequestMapping(value = "/getList", method = {RequestMethod.POST})
public R getList(@RequestBody SceneReq req) {
log.info("/scene/getList param: {}", JSON.toJSONString(req));
if(req.getUserId() == null || req.getUserId() <= 0){
throw BusinessException.create(ResultEnum.PARAM_ERROR);
}
return R.ok().data(sceneFeignClient.getList(req));
}
@RequestMapping(value = "/getById", method = {RequestMethod.GET, RequestMethod.POST})
public R getById(@RequestBody @Validated(value = Default.class) SceneReq req, BindingResult result) {
this.checkRequestParam(result);
Long id = req.getId();
log.info("/scene/getById param: {}", id);
return R.ok().data(sceneFeignClient.getById(id));
}
@RequestMapping(value = "/save", method = {RequestMethod.POST})
public R save(@RequestBody @Validated(value = GroupA.class) SceneReq req, BindingResult result) {
log.info("新增调用/scene/save param: {}", JSON.toJSONString(req));
this.checkRequestParam(result);
Long id = req.getId();
Date now = new Date();
if(id == null || id <= 0){ //新增
req.setCreateTime(now);
sceneFeignClient.add(req);
}else{
req.setUpdateTime(now);
sceneFeignClient.update(req);
}
return R.ok();
}
}
package com.glsx.api.controller;
import com.glsx.api.constant.Constant;
import com.glsx.api.pojo.request.SceneTemplateReq;
import com.glsx.api.pojo.request.SysCodeReq;
import com.glsx.api.pojo.response.SceneTemplateResp;
import com.glsx.api.pojo.response.SysCodeResp;
import com.glsx.api.remote.SceneTemplateFeignClient;
import com.glsx.api.remote.SysCodeFeignClient;
import com.glsx.plat.core.web.R;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import javax.validation.groups.Default;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* <p>Description:
* <p>Project: chejia-smart
*
* @author wbh
* @date 2021-03-15
*/
@Slf4j
@RestController
@RequestMapping("/sceneTemplate")
public class SceneTemplateController extends BaseController{
@Autowired
private SceneTemplateFeignClient templateFeignClient;
@Autowired
private SysCodeFeignClient codeFeignClient;
@RequestMapping(value = "/getList", method = {RequestMethod.GET, RequestMethod.POST})
public R getList() {
//获取分类代码集
SysCodeReq req = new SysCodeReq();
req.setDictType(Constant.SCENE_CLASSIFICATION);
List<SysCodeResp> list = codeFeignClient.getListByCondition(req);
Map<String, List<SceneTemplateResp>> map = new HashMap<>();
SceneTemplateReq templateReq = new SceneTemplateReq();
for (SysCodeResp codeResp: list) {
templateReq.setTypeKey(codeResp.getDictKey());
templateReq.setStatus(Constant.ONLINE);
map.put(codeResp.getDictValue(), templateFeignClient.getList(templateReq));
}
return R.ok().data(map);
}
@RequestMapping(value = "/getById", method = {RequestMethod.GET, RequestMethod.POST})
public R getById(@RequestBody @Validated(value = Default.class) SceneTemplateReq sceneTemplate, BindingResult result) {
this.checkRequestParam(result);
Long id = sceneTemplate.getId();
log.info("/sceneTemplate/getById param: {}", id);
return R.ok().data(templateFeignClient.getById(id));
}
}
package com.glsx.api.pojo.request;
import lombok.Data;
/**
* 车家智能用户场景数据表
*/
@Data
public class SceneDataReq {
/**
* 标识ID
*/
private Long id;
/**
* 场景ID 关联smart_scene中id
*/
private Long sceneId;
/**
* 类型 1触发条件 2执行内容
*/
private Byte type;
/**
* 排序
*/
private Byte sort;
/**
* 参数key
*/
private String paramKey;
/**
* 参数值 数组对象
*/
private String paramValue;
}
package com.glsx.api.pojo.request;
import com.glsx.api.pojo.GroupA;
import lombok.Data;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import javax.validation.groups.Default;
import java.io.Serializable;
import java.util.Date;
import java.util.List;
/**
* 车家智能用户场景表
*/
@Data
public class SceneReq implements Serializable {
/**
* 标识ID
*/
@NotNull(message = "id不能为空", groups = {Default.class})
private Long id;
/**
* 用户ID 关联smart_user_relation中id
*/
private Long userId;
/**
* 场景名称
*/
@NotEmpty(message = "sceneName不能为空", groups = {GroupA.class})
private String sceneName;
/**
* 场景类型key 关联smart_sys_code中dict_key
*/
private String typeKey;
/**
* 场景图标ID 关联smart_sys_file中id
*/
private Long icon;
/**
* 场景图标
*/
private String iconUrl;
/**
* 场景背景图ID 关联smart_sys_file中id
*/
private Long backPic;
/**
* 场景背景图
*/
private String backPicUrl;
/**
* 查看次数
*/
private Long viewTimes;
/**
* 场景描述
*/
private String description;
/**
* 条件规则 1任一条件 2全部条件
*/
private Byte conditionRule;
/**
* 执行周期 1每天 2工作日 3法定节假日
*/
private Byte executeCycle;
/**
* 状态:0下线 1上线
*/
private Byte status;
/**
* 备注
*/
private String remark;
/**
* 创建时间
*/
private Date createTime;
/**
* 更新时间
*/
private Date updateTime;
/**
* 场景关系数据
*/
private List<SceneDataReq> dataList;
}
package com.glsx.api.pojo.request;
import lombok.Data;
import javax.validation.constraints.NotNull;
import javax.validation.groups.Default;
import java.util.Date;
import java.util.List;
/**
* 车家智能场景模板表
*/
@Data
public class SceneTemplateReq {
/**
* 标识ID
*/
@NotNull(message = "id不能为空", groups = {Default.class})
private Long id;
/**
* 场景名称
*/
private String sceneName;
/**
* 场景类型key 关联smart_sys_code中dict_key
*/
private String typeKey;
/**
* 场景图标ID 关联smart_sys_file中id
*/
private Long icon;
/**
* 场景背景图ID 关联smart_sys_file中id
*/
private Long backPic;
/**
* 查看次数
*/
private Long viewTimes;
/**
* 场景描述
*/
private String description;
/**
* 条件规则 1任一条件 2全部条件
*/
private Byte conditionRule;
/**
* 执行周期 1每天 2工作日 3法定节假日
*/
private Byte executeCycle;
/**
* 状态:0下线 1上线
*/
private Byte status;
/**
* 备注
*/
private String remark;
/**
* 创建时间
*/
private Date createTime;
/**
* 创建人
*/
private Long createBy;
/**
* 更新时间
*/
private Date updateTime;
/**
* 更新人
*/
private Long updateBy;
/**
* 模板list
*/
private List<TemplateParamReq> templateList;
}
package com.glsx.api.pojo.request;
import lombok.Data;
/**
* 车家智能系统代码集表
*/
@Data
public class SysCodeReq{
/**
* 标识ID
*/
private Long id;
/**
* 字典类型
*/
private String dictType;
/**
* 字典键值
*/
private String dictKey;
/**
* 字典值
*/
private String dictValue;
/**
* 父级键值
*/
private String parentKey;
/**
* 排序
*/
private Byte sort;
/**
* 状态:0下线 1上线
*/
private Byte status;
/**
* 分级
*/
private Byte level;
}
package com.glsx.api.pojo.request;
import lombok.Data;
/**
* 车家智能场景模板参数表
*/
@Data
public class TemplateParamReq {
/**
* 标识ID
*/
private Long id;
/**
* 模板ID 关联smart_scene_template中id
*/
private Long templateId;
/**
* 类型 1触发条件 2执行内容
*/
private Byte type;
/**
* 排序
*/
private Byte sort;
/**
* 参数key
*/
private String paramKey;
/**
* 模板值 数组对象
*/
private String paramValue;
}
package com.glsx.api.pojo.response;
import lombok.Data;
/**
* 车家智能用户场景数据表
*/
@Data
public class SceneDataResp {
/**
* 标识ID
*/
private Long id;
/**
* 场景ID 关联smart_scene中id
*/
private Long sceneId;
/**
* 类型 1触发条件 2执行内容
*/
private Byte type;
/**
* 排序
*/
private Byte sort;
/**
* 参数key
*/
private String paramKey;
/**
* 参数值 数组对象
*/
private String paramValue;
}
package com.glsx.api.pojo.response;
import com.glsx.api.pojo.request.SceneDataReq;
import lombok.Data;
import java.io.Serializable;
import java.util.List;
/**
* 车家智能用户场景表
*/
@Data
public class SceneResp implements Serializable {
/**
* 标识ID
*/
private Long id;
/**
* 场景名称
*/
private String sceneName;
/**
* 场景图标
*/
private String iconUrl;
/**
* 场景背景图
*/
private String backPicUrl;
/**
* 查看次数
*/
private Long viewTimes;
/**
* 场景描述
*/
private String description;
/**
* 条件规则 1任一条件 2全部条件
*/
private Byte conditionRule;
/**
* 执行周期 1每天 2工作日 3法定节假日
*/
private Byte executeCycle;
/**
* 场景关系数据
*/
private List<SceneDataReq> dataList;
}
package com.glsx.api.pojo.response;
import lombok.Data;
import java.util.Date;
import java.util.List;
/**
* <p>Description:
* <p>Project: chejia-smart
*
* @author wbh
* @date 2021-03-15
*/
/**
* 车家智能场景模板表
*/
@Data
public class SceneTemplateResp {
/**
* 标识ID
*/
private Long id;
/**
* 场景名称
*/
private String sceneName;
/**
* 场景类型key 关联smart_sys_code中dict_key
*/
private String typeKey;
/**
* 场景图标ID 关联smart_sys_file中id
*/
private Long icon;
/**
* 场景图标
*/
private String iconUrl;
/**
* 场景背景图ID 关联smart_sys_file中id
*/
private Long backPic;
/**
* 场景背景图
*/
private String backPicUrl;
/**
* 查看次数
*/
private Long viewTimes;
/**
* 场景描述
*/
private String description;
/**
* 条件规则 1任一条件 2全部条件
*/
private Byte conditionRule;
/**
* 执行周期 1每天 2工作日 3法定节假日
*/
private Byte executeCycle;
/**
* 状态:0下线 1上线
*/
private Byte status;
/**
* 备注
*/
private String remark;
/**
* 创建时间
*/
private Date createTime;
/**
* 创建人
*/
private Long createBy;
/**
* 更新时间
*/
private Date updateTime;
/**
* 更新人
*/
private Long updateBy;
/**
* 模板list
*/
private List<TemplateParamResp> templateList;
}
package com.glsx.api.pojo.response;
import lombok.Data;
import java.util.Date;
/**
* <p>Description:
* <p>Project: chejia-smart
*
* @author wbh
* @date 2021-03-15
*/
/**
* 车家智能系统代码集表
*/
@Data
public class SysCodeResp {
/**
* 标识ID
*/
private Long id;
/**
* 字典类型
*/
private String dictType;
/**
* 字典键值
*/
private String dictKey;
/**
* 字典值
*/
private String dictValue;
/**
* 父级键值
*/
private String parentKey;
/**
* 排序
*/
private Byte sort;
/**
* 状态:0下线 1上线
*/
private Byte status;
/**
* 分级
*/
private Byte level;
/**
* 备注
*/
private String remark;
/**
* 创建时间
*/
private Date createTime;
/**
* 创建人
*/
private Long createBy;
/**
* 更新时间
*/
private Date updateTime;
/**
* 更新人
*/
private Long updateBy;
}
package com.glsx.api.pojo.response;
/**
* <p>Description:
* <p>Project: chejia-smart
*
* @author wbh
* @date 2021-03-15
*/
import lombok.Data;
/**
* 车家智能场景模板参数表
*/
@Data
public class TemplateParamResp {
/**
* 标识ID
*/
private Long id;
/**
* 模板ID 关联smart_scene_template中id
*/
private Long templateId;
/**
* 类型 1触发条件 2执行内容
*/
private Byte type;
/**
* 排序
*/
private Byte sort;
/**
* 参数key
*/
private String paramKey;
/**
* 模板值 数组对象
*/
private String paramValue;
}
package com.glsx.api.remote;
import com.glsx.api.pojo.request.SceneReq;
import com.glsx.api.pojo.response.SceneResp;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.*;
import java.util.List;
/**
* <p>Description:
* <p>Project: chejia-smart
*
* @author think.wang
* @date 2021-03-16
*/
@FeignClient(name = "${feign.server.name}",url = "${feign.server.url}")
public interface SceneFeignClient {
@ResponseBody
@RequestMapping(value = "/scene/getList", method = {RequestMethod.POST})
List<SceneResp> getList(@RequestBody SceneReq req);
@ResponseBody
@RequestMapping(value = "/scene/getById", method = {RequestMethod.GET})
SceneResp getById(@RequestParam("id") Long id);
@ResponseBody
@RequestMapping(value = "/scene/add", method = {RequestMethod.POST})
boolean add(@RequestBody SceneReq req);
@ResponseBody
@RequestMapping(value = "/scene/update", method = {RequestMethod.POST})
boolean update(@RequestBody SceneReq req);
}
package com.glsx.api.remote;
import com.glsx.api.pojo.request.SceneTemplateReq;
import com.glsx.api.pojo.response.SceneTemplateResp;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.*;
import java.util.List;
/**
* <p>Description:
* <p>Project: chejia-smart
*
* @author think.wang
* @date 2021-03-16
*/
@FeignClient(name = "${feign.server.name}",url = "${feign.server.url}")
public interface SceneTemplateFeignClient {
@ResponseBody
@RequestMapping(value = "/sceneTemplate/getList", method = {RequestMethod.GET})
List<SceneTemplateResp> getList(@RequestBody SceneTemplateReq req);
@ResponseBody
@RequestMapping(value = "/sceneTemplate/getById", method = {RequestMethod.GET})
SceneTemplateResp getById(@RequestParam("id") Long id);
}
package com.glsx.api.remote;
import com.glsx.api.pojo.request.SysCodeReq;
import com.glsx.api.pojo.response.SysCodeResp;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import java.util.List;
/**
* <p>Description:
* <p>Project: chejia-smart
*
* @author think.wang
* @date 2021-03-16
*/
@FeignClient(name = "${feign.server.name}",url = "${feign.server.url}")
public interface SysCodeFeignClient {
@ResponseBody
@RequestMapping(value = "/sysCode/getListByCondition", method = {RequestMethod.POST})
List<SysCodeResp> getListByCondition(@RequestBody SysCodeReq req);
}
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!