Commit 70a1b2a6 by tyfanchz

Merge remote-tracking branch 'origin/dev' into dev

2 parents 84f6e541 33a0049d
package com.glsx.admin.controller;
import com.glsx.admin.exception.BusinessException;
import com.glsx.admin.exception.ResultEnum;
import com.glsx.plat.common.utils.StringUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.BindingResult;
import org.springframework.validation.FieldError;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* @author think.wang
* @version 1.0.0
* @Title BaseController
* @Package com.glsx.admin.controller
* @Description controller基类
* @date 2021/3/17
*/
@Slf4j
public class BaseController {
/**
* hibernate-validator参数校验返回错误方法
*
* @param result
* @return
*/
public Map<String, String> getErrors(BindingResult result) {
Map<String, String> map = new HashMap<>();
List<FieldError> list = result.getFieldErrors();
for (FieldError error : list) {
map.put(error.getField(), error.getDefaultMessage());
}
return map;
}
/**
* 将请求参数进行校验,校验不成功则抛出 {@link BusinessException} 异常
*
* @param bindingResult Spring校验结果
*/
protected void checkRequestParam(BindingResult bindingResult) {
if (bindingResult.hasErrors()) {
Map<String, String> errorMap = this.getErrors(bindingResult);
Collection<String> values = errorMap.values();
String errorMsg = StringUtils.join(values, ";");
throw BusinessException.create(ResultEnum.PARAM_ERROR.getCode(), errorMsg);
}
}
}
package com.glsx.admin.controller;
import com.glsx.admin.pojo.request.ProductReq;
import com.glsx.admin.remote.IndexFeignClient;
import com.glsx.biz.user.common.entity.User;
import com.glsx.biz.user.service.UserService;
......@@ -7,9 +8,7 @@ import com.glsx.cloudframework.exception.ServiceException;
import com.glsx.plat.core.web.R;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;
/**
* @Title: IndexController.java
......@@ -29,7 +28,7 @@ public class IndexController {
private UserService userService;
@ResponseBody
@RequestMapping("home")
@RequestMapping("/home")
public R home(){
try {
User user = userService.getByUserId(92001768); //dubbo服务调用
......@@ -40,4 +39,13 @@ public class IndexController {
return R.ok().data(indexFeignClient.getHome()); //feign调用远程服务
}
@ResponseBody
@RequestMapping(value = "/getProduct", method = {RequestMethod.GET, RequestMethod.POST})
public R getProduct(@RequestParam("url") String url, @RequestParam("name") String name){
ProductReq product = new ProductReq();
product.setIconUrl(url);
product.setProductName(name);
return R.ok().data(indexFeignClient.getProduct(product)); //feign调用远程服务
}
}
package com.glsx.admin.controller;
import com.alibaba.fastjson.JSON;
import com.glsx.admin.pojo.GroupA;
import com.glsx.admin.pojo.request.SceneTemplateReq;
import com.glsx.admin.remote.SceneTemplateFeignClient;
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("/sceneTemplate")
public class SceneTemplateController extends BaseController{
@Autowired
private SceneTemplateFeignClient templateFeignClient;
@RequestMapping(value = "/getList", method = {RequestMethod.POST})
public R getList(@RequestBody SceneTemplateReq sceneTemplate) {
log.info("/sceneTemplate/getList param: {}", JSON.toJSONString(sceneTemplate));
return R.ok().data(templateFeignClient.getPageList(sceneTemplate));
}
@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));
}
@RequestMapping(value = "/save", method = {RequestMethod.POST})
public R save(@RequestBody @Validated(value = GroupA.class) SceneTemplateReq sceneTemplate, BindingResult result) {
log.info("新增调用/sceneTemplate/save param: {}", JSON.toJSONString(sceneTemplate));
this.checkRequestParam(result);
Long id = sceneTemplate.getId();
Date now = new Date();
if(id == null || id <= 0){ //新增
sceneTemplate.setCreateTime(now);
sceneTemplate.setUpdateBy(-1L);
templateFeignClient.add(sceneTemplate);
}else{
sceneTemplate.setUpdateTime(now);
sceneTemplate.setUpdateBy(-1L);
templateFeignClient.update(sceneTemplate);
}
return R.ok();
}
@RequestMapping(value = "/updateStatus", method = {RequestMethod.POST})
public R update(@RequestBody @Validated(value = Default.class) SceneTemplateReq sceneTemplate, BindingResult result) {
this.checkRequestParam(result);
log.info("更新调用/sceneTemplate/updateStatus param: {}", JSON.toJSONString(sceneTemplate));
Date now = new Date();
sceneTemplate.setUpdateTime(now);
sceneTemplate.setUpdateBy(-1L);
templateFeignClient.updateParam(sceneTemplate);
return R.ok();
}
}
......@@ -34,4 +34,15 @@ public class BusinessException extends RuntimeException {
public void setMessage(String message) {
this.message = message;
}
public static BusinessException create(int code, String message){
BusinessException businessException = new BusinessException();
businessException.code = code;
businessException.message = message;
return businessException;
}
public static BusinessException create(ResultEnum resultEnum) {
return create(resultEnum.getCode(), resultEnum.getMessage());
}
}
......@@ -40,11 +40,6 @@ public class BaseDTO {
*/
private String endTime;
/**
* 用户id
*/
private Long uid;
public int getPageIndex() {
return pageIndex;
}
......@@ -69,14 +64,6 @@ public class BaseDTO {
this.searchKey = searchKey;
}
public Long getUid() {
return uid;
}
public void setUid(Long uid) {
this.uid = uid;
}
public String getOrderBy() {
return orderBy;
}
......
package com.glsx.admin.pojo;
/**
* @author think.wang
* @version 1.0.0
* @Title GroupA
* @Package com.glsx.admin.pojo
* @Description Hibernate-validator的分组
* @date 2021/3/8
*/
public interface GroupA {
}
package com.glsx.admin.pojo.request;
import lombok.Data;
import java.util.Date;
/**
* <p>Description:
* <p>Project: chejia-smart
*
* @author wbh
* @date 2021-03-15
*/
/**
* 车家智能产品数据表
*/
@Data
public class ProductReq {
/**
* 图标 url
*/
private String iconUrl;
/**
* 产品类型名称
*/
private String typeName;
/**
* 接入平台名称
*/
private String platformName;
/**
* 配网模式名称
*/
private String networkName;
/**
* 标识ID
*/
private Long id;
/**
* 产品名称
*/
private String productName;
/**
* 图片ID 关联smart_sys_file中id
*/
private Long icon;
/**
* 产品类型ID 关联smart_product_type中id
*/
private Long typeId;
/**
* 商城产品id
*/
private String shopProductId;
/**
* 接入平台key 关联smart_sys_code中dict_key
*/
private String platformKey;
/**
* 接入平台产品id
*/
private String platformProductId;
/**
* 配网方式key 关联smart_sys_code中dict_key
*/
private String networkKey;
/**
* 状态:0下线 1上线
*/
private Byte status;
/**
* 备注
*/
private String remark;
/**
* 创建时间
*/
private Date createTime;
/**
* 创建人
*/
private Long createBy;
/**
* 更新时间
*/
private Date updateTime;
/**
* 更新人
*/
private Long updateBy;
}
package com.glsx.admin.pojo.request;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;
import java.util.Date;
import com.glsx.admin.pojo.BaseDTO;
import com.glsx.admin.pojo.GroupA;
import lombok.Data;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import javax.validation.groups.Default;
import java.util.Date;
import java.util.List;
/**
* <p>Description:
* <p>Project: chejia-smart
......@@ -20,33 +23,36 @@ import lombok.Data;
* 车家智能场景模板表
*/
@Data
@Table(name = "smart_scene_template")
public class SmartSceneTemplateReq {
public class SceneTemplateReq extends BaseDTO {
/**
* 标识ID
*/
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@NotNull(message = "id不能为空", groups = {Default.class})
private Long id;
/**
* 场景名称
*/
@NotEmpty(message = "sceneName不能为空", groups = {GroupA.class})
private String sceneName;
/**
* 场景类型key 关联smart_sys_code中dict_key
*/
@NotEmpty(message = "typeKey不能为空", groups = {GroupA.class})
private String typeKey;
/**
* 场景图标ID 关联smart_sys_file中id
*/
@NotNull(message = "icon不能为空", groups = {GroupA.class})
private Long icon;
/**
* 场景背景图ID 关联smart_sys_file中id
*/
@NotNull(message = "backPic不能为空", groups = {GroupA.class})
private Long backPic;
/**
......@@ -98,4 +104,9 @@ public class SmartSceneTemplateReq {
* 更新人
*/
private Long updateBy;
/**
* 模板list
*/
private List<TemplateParamReq> templateList;
}
......@@ -9,23 +9,16 @@ package com.glsx.admin.pojo.request;
*/
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;
import lombok.Data;
/**
* 车家智能场景模板参数表
*/
@Data
@Table(name = "smart_template_param")
public class SmartTemplateParamReq {
public class TemplateParamReq {
/**
* 标识ID
*/
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
/**
......
package com.glsx.admin.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.admin.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.admin.remote;
import com.glsx.admin.pojo.request.ProductReq;
import com.glsx.admin.remote.impl.IndexHystrix;
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;
......@@ -13,4 +15,8 @@ public interface IndexFeignClient {
@RequestMapping(value = "/home", method = {RequestMethod.GET})
String getHome();
@ResponseBody
@RequestMapping(value = "/getProduct", method = {RequestMethod.GET})
String getProduct(@RequestBody ProductReq product);
}
package com.glsx.admin.remote;
import com.github.pagehelper.PageInfo;
import com.glsx.admin.pojo.request.SceneTemplateReq;
import com.glsx.admin.pojo.response.SceneTemplateResp;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.cloud.openfeign.SpringQueryMap;
import org.springframework.web.bind.annotation.*;
/**
* <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/getPageList", method = {RequestMethod.GET})
PageInfo<SceneTemplateResp> getPageList(@SpringQueryMap SceneTemplateReq req);
@ResponseBody
@RequestMapping(value = "/sceneTemplate/getById", method = {RequestMethod.GET})
SceneTemplateResp getById(@RequestParam Long id);
@ResponseBody
@RequestMapping(value = "/sceneTemplate/add", method = {RequestMethod.POST})
boolean add(@RequestBody SceneTemplateReq req);
@ResponseBody
@RequestMapping(value = "/sceneTemplate/update", method = {RequestMethod.POST})
boolean update(@RequestBody SceneTemplateReq req);
@ResponseBody
@RequestMapping(value = "/sceneTemplate/updateParam", method = {RequestMethod.POST})
boolean updateParam(@RequestBody SceneTemplateReq req);
}
package com.glsx.admin.remote.impl;
import com.glsx.admin.pojo.request.ProductReq;
import com.glsx.admin.remote.IndexFeignClient;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
......@@ -21,4 +22,9 @@ public class IndexHystrix implements IndexFeignClient {
log.error("请求getHome()异常");
return "服务请求异常";
}
@Override
public String getProduct(ProductReq product) {
return "服务请求异常";
}
}
......@@ -2,9 +2,6 @@
spring.profiles.active=dev
server.servlet.context-path=/smartAdmin
# \u5F00\u542F\u7194\u65AD
feign.hystrix.enabled=true
#\u6307\u5B9Adate\u8F93\u51FA\u683C\u5F0F\u4E3Ayyyy-MM-dd HH:mm:ss
spring.jackson.date-format=yyyy-MM-dd HH:mm:ss
spring.jackson.time-zone=GMT+8
......@@ -18,6 +15,10 @@ logging.path=/data/java_log/jetty/smartService/chejia-smart-admin
feign.server.name=chejia-smart-service
feign.server.url=http://localhost:8209/smartService
feign.client.config.default.connect-timeout=20000
feign.client.config.default.read-timeout=20000
# \u5F00\u542F\u7194\u65AD
feign.hystrix.enabled=true
dubbo.registry.address=zookeeper://192.168.1.36:2181?init.timeout=60000
dubbo.registry.timeout=10000
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!