作者 钟来
正在显示 41 个修改的文件 包含 1679 行增加946 行删除
@@ -86,7 +86,6 @@ public class IotDeviceControlController { @@ -86,7 +86,6 @@ public class IotDeviceControlController {
86 { 86 {
87 return null; 87 return null;
88 } 88 }
89 - Map<String,Object> map = new HashMap<>();  
90 Map<String,Object> valueMap = new HashMap<>(); 89 Map<String,Object> valueMap = new HashMap<>();
91 valueMap.put("restart",restart); 90 valueMap.put("restart",restart);
92 Response response1 = HttpUtils.postJsonBody(url, formBody -> { 91 Response response1 = HttpUtils.postJsonBody(url, formBody -> {
  1 +package com.zhonglai.luhui.admin.controller.user;
  2 +
  3 +import java.util.List;
  4 +import javax.servlet.http.HttpServletResponse;
  5 +
  6 +import io.swagger.annotations.Api;
  7 +import io.swagger.annotations.ApiOperation;
  8 +import org.springframework.security.access.prepost.PreAuthorize;
  9 +import org.springframework.beans.factory.annotation.Autowired;
  10 +import org.springframework.web.bind.annotation.GetMapping;
  11 +import org.springframework.web.bind.annotation.PostMapping;
  12 +import org.springframework.web.bind.annotation.PutMapping;
  13 +import org.springframework.web.bind.annotation.DeleteMapping;
  14 +import org.springframework.web.bind.annotation.PathVariable;
  15 +import org.springframework.web.bind.annotation.RequestBody;
  16 +import org.springframework.web.bind.annotation.RequestMapping;
  17 +import org.springframework.web.bind.annotation.RestController;
  18 +import com.ruoyi.common.annotation.Log;
  19 +import com.ruoyi.common.core.controller.BaseController;
  20 +import com.ruoyi.common.core.domain.AjaxResult;
  21 +import com.ruoyi.common.enums.BusinessType;
  22 +import com.ruoyi.system.domain.UserTerminalGroup;
  23 +import com.ruoyi.system.service.IUserTerminalGroupService;
  24 +import com.ruoyi.common.utils.poi.ExcelUtil;
  25 +import com.ruoyi.common.core.page.TableDataInfo;
  26 +
  27 +/**
  28 + * 终端分组Controller
  29 + *
  30 + * @author 钟来
  31 + * @date 2022-11-22
  32 + */
  33 +@Api(tags = "终端分组")
  34 +@RestController
  35 +@RequestMapping("/user/UserTerminalGroup")
  36 +public class UserTerminalGroupController extends BaseController
  37 +{
  38 + @Autowired
  39 + private IUserTerminalGroupService userTerminalGroupService;
  40 +
  41 + /**
  42 + * 查询终端分组列表
  43 + */
  44 + @ApiOperation("查询终端分组列表")
  45 + @PreAuthorize("@ss.hasPermi('user:UserTerminalGroup:list')")
  46 + @GetMapping("/list")
  47 + public TableDataInfo list(UserTerminalGroup userTerminalGroup)
  48 + {
  49 + startPage();
  50 + List<UserTerminalGroup> list = userTerminalGroupService.selectUserTerminalGroupList(userTerminalGroup);
  51 + return getDataTable(list);
  52 + }
  53 +
  54 + /**
  55 + * 导出终端分组列表
  56 + */
  57 + @ApiOperation("导出终端分组列表")
  58 + @PreAuthorize("@ss.hasPermi('user:UserTerminalGroup:export')")
  59 + @Log(title = "终端分组", businessType = BusinessType.EXPORT)
  60 + @PostMapping("/export")
  61 + public void export(HttpServletResponse response, UserTerminalGroup userTerminalGroup)
  62 + {
  63 + List<UserTerminalGroup> list = userTerminalGroupService.selectUserTerminalGroupList(userTerminalGroup);
  64 + ExcelUtil<UserTerminalGroup> util = new ExcelUtil<UserTerminalGroup>(UserTerminalGroup.class);
  65 + util.exportExcel(response, list, "终端分组数据");
  66 + }
  67 +
  68 + /**
  69 + * 获取终端分组详细信息
  70 + */
  71 + @ApiOperation("获取终端分组详细信息")
  72 + @PreAuthorize("@ss.hasPermi('user:UserTerminalGroup:query')")
  73 + @GetMapping(value = "/{id}")
  74 + public AjaxResult getInfo(@PathVariable("id") Integer id)
  75 + {
  76 + return AjaxResult.success(userTerminalGroupService.selectUserTerminalGroupById(id));
  77 + }
  78 +
  79 + /**
  80 + * 新增终端分组
  81 + */
  82 + @ApiOperation("新增终端分组")
  83 + @PreAuthorize("@ss.hasPermi('user:UserTerminalGroup:add')")
  84 + @Log(title = "终端分组", businessType = BusinessType.INSERT)
  85 + @PostMapping
  86 + public AjaxResult add(@RequestBody UserTerminalGroup userTerminalGroup)
  87 + {
  88 + return toAjax(userTerminalGroupService.insertUserTerminalGroup(userTerminalGroup));
  89 + }
  90 +
  91 + /**
  92 + * 修改终端分组
  93 + */
  94 + @ApiOperation("修改终端分组")
  95 + @PreAuthorize("@ss.hasPermi('user:UserTerminalGroup:edit')")
  96 + @Log(title = "终端分组", businessType = BusinessType.UPDATE)
  97 + @PutMapping
  98 + public AjaxResult edit(@RequestBody UserTerminalGroup userTerminalGroup)
  99 + {
  100 + return toAjax(userTerminalGroupService.updateUserTerminalGroup(userTerminalGroup));
  101 + }
  102 +
  103 + /**
  104 + * 删除终端分组
  105 + */
  106 + @ApiOperation("删除终端分组")
  107 + @PreAuthorize("@ss.hasPermi('user:UserTerminalGroup:remove')")
  108 + @Log(title = "终端分组", businessType = BusinessType.DELETE)
  109 + @DeleteMapping("/{ids}")
  110 + public AjaxResult remove(@PathVariable Integer[] ids)
  111 + {
  112 + return toAjax(userTerminalGroupService.deleteUserTerminalGroupByIds(ids));
  113 + }
  114 +}
  1 +package com.zhonglai.luhui.admin.controller.user;
  2 +
  3 +import java.util.List;
  4 +import javax.servlet.http.HttpServletResponse;
  5 +
  6 +import io.swagger.annotations.Api;
  7 +import io.swagger.annotations.ApiOperation;
  8 +import org.springframework.security.access.prepost.PreAuthorize;
  9 +import org.springframework.beans.factory.annotation.Autowired;
  10 +import org.springframework.web.bind.annotation.GetMapping;
  11 +import org.springframework.web.bind.annotation.PostMapping;
  12 +import org.springframework.web.bind.annotation.PutMapping;
  13 +import org.springframework.web.bind.annotation.DeleteMapping;
  14 +import org.springframework.web.bind.annotation.PathVariable;
  15 +import org.springframework.web.bind.annotation.RequestBody;
  16 +import org.springframework.web.bind.annotation.RequestMapping;
  17 +import org.springframework.web.bind.annotation.RestController;
  18 +import com.ruoyi.common.annotation.Log;
  19 +import com.ruoyi.common.core.controller.BaseController;
  20 +import com.ruoyi.common.core.domain.AjaxResult;
  21 +import com.ruoyi.common.enums.BusinessType;
  22 +import com.ruoyi.system.domain.UserTerminalGroupRelation;
  23 +import com.ruoyi.system.service.IUserTerminalGroupRelationService;
  24 +import com.ruoyi.common.utils.poi.ExcelUtil;
  25 +import com.ruoyi.common.core.page.TableDataInfo;
  26 +
  27 +/**
  28 + * 终端分组关系Controller
  29 + *
  30 + * @author 钟来
  31 + * @date 2022-11-22
  32 + */
  33 +@Api(tags = "终端分组关系")
  34 +@RestController
  35 +@RequestMapping("/user/UserTerminalGroupRelation")
  36 +public class UserTerminalGroupRelationController extends BaseController
  37 +{
  38 + @Autowired
  39 + private IUserTerminalGroupRelationService userTerminalGroupRelationService;
  40 +
  41 + /**
  42 + * 查询终端分组关系列表
  43 + */
  44 + @ApiOperation("查询终端分组关系列表")
  45 + @PreAuthorize("@ss.hasPermi('user:UserTerminalGroupRelation:list')")
  46 + @GetMapping("/list")
  47 + public TableDataInfo list(UserTerminalGroupRelation userTerminalGroupRelation)
  48 + {
  49 + startPage();
  50 + List<UserTerminalGroupRelation> list = userTerminalGroupRelationService.selectUserTerminalGroupRelationList(userTerminalGroupRelation);
  51 + return getDataTable(list);
  52 + }
  53 +
  54 + /**
  55 + * 导出终端分组关系列表
  56 + */
  57 + @ApiOperation("导出终端分组关系列表")
  58 + @PreAuthorize("@ss.hasPermi('user:UserTerminalGroupRelation:export')")
  59 + @Log(title = "终端分组关系", businessType = BusinessType.EXPORT)
  60 + @PostMapping("/export")
  61 + public void export(HttpServletResponse response, UserTerminalGroupRelation userTerminalGroupRelation)
  62 + {
  63 + List<UserTerminalGroupRelation> list = userTerminalGroupRelationService.selectUserTerminalGroupRelationList(userTerminalGroupRelation);
  64 + ExcelUtil<UserTerminalGroupRelation> util = new ExcelUtil<UserTerminalGroupRelation>(UserTerminalGroupRelation.class);
  65 + util.exportExcel(response, list, "终端分组关系数据");
  66 + }
  67 +
  68 + /**
  69 + * 获取终端分组关系详细信息
  70 + */
  71 + @ApiOperation("获取终端分组关系详细信息")
  72 + @PreAuthorize("@ss.hasPermi('user:UserTerminalGroupRelation:query')")
  73 + @GetMapping(value = "/{id}")
  74 + public AjaxResult getInfo(@PathVariable("id") Integer id)
  75 + {
  76 + return AjaxResult.success(userTerminalGroupRelationService.selectUserTerminalGroupRelationById(id));
  77 + }
  78 +
  79 + /**
  80 + * 新增终端分组关系
  81 + */
  82 + @ApiOperation("新增终端分组关系")
  83 + @PreAuthorize("@ss.hasPermi('user:UserTerminalGroupRelation:add')")
  84 + @Log(title = "终端分组关系", businessType = BusinessType.INSERT)
  85 + @PostMapping
  86 + public AjaxResult add(@RequestBody UserTerminalGroupRelation userTerminalGroupRelation)
  87 + {
  88 + return toAjax(userTerminalGroupRelationService.insertUserTerminalGroupRelation(userTerminalGroupRelation));
  89 + }
  90 +
  91 + /**
  92 + * 修改终端分组关系
  93 + */
  94 + @ApiOperation("修改终端分组关系")
  95 + @PreAuthorize("@ss.hasPermi('user:UserTerminalGroupRelation:edit')")
  96 + @Log(title = "终端分组关系", businessType = BusinessType.UPDATE)
  97 + @PutMapping
  98 + public AjaxResult edit(@RequestBody UserTerminalGroupRelation userTerminalGroupRelation)
  99 + {
  100 + return toAjax(userTerminalGroupRelationService.updateUserTerminalGroupRelation(userTerminalGroupRelation));
  101 + }
  102 +
  103 + /**
  104 + * 删除终端分组关系
  105 + */
  106 + @ApiOperation("删除终端分组关系")
  107 + @PreAuthorize("@ss.hasPermi('user:UserTerminalGroupRelation:remove')")
  108 + @Log(title = "终端分组关系", businessType = BusinessType.DELETE)
  109 + @DeleteMapping("/{ids}")
  110 + public AjaxResult remove(@PathVariable Integer[] ids)
  111 + {
  112 + return toAjax(userTerminalGroupRelationService.deleteUserTerminalGroupRelationByIds(ids));
  113 + }
  114 +}
@@ -6,7 +6,6 @@ spring: @@ -6,7 +6,6 @@ spring:
6 druid: 6 druid:
7 # 主库数据源 7 # 主库数据源
8 master: 8 master:
9 -# url: jdbc:mysql://114.215.126.2:3306/ju_he_liao_tiao?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8  
10 url: jdbc:mysql://rm-wz9740un21f09iokuao.mysql.rds.aliyuncs.com:3306/mqtt_broker?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8 9 url: jdbc:mysql://rm-wz9740un21f09iokuao.mysql.rds.aliyuncs.com:3306/mqtt_broker?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8
11 username: luhui 10 username: luhui
12 password: Luhui586 11 password: Luhui586
1 package com.zhonglai.luhui.api; 1 package com.zhonglai.luhui.api;
2 2
  3 +import org.springframework.boot.SpringApplication;
  4 +import org.springframework.boot.autoconfigure.SpringBootApplication;
  5 +import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
  6 +import org.springframework.context.annotation.ComponentScan;
  7 +
  8 +@ComponentScan(basePackages = {
  9 + "com.ruoyi.common",
  10 + "com.ruoyi.system",
  11 + "com.ruoyi.framework",
  12 + "com.zhonglai.luhui.api.config",
  13 + "com.zhonglai.luhui.api.controller",
  14 +})
  15 +@SpringBootApplication(exclude = { DataSourceAutoConfiguration.class })
3 public class LhApiApplication { 16 public class LhApiApplication {
  17 + public static void main(String[] args) {
  18 + SpringApplication.run(LhApiApplication.class,args);
  19 + System.out.println("启动成功");
  20 + }
4 } 21 }
  1 +package com.zhonglai.luhui.api.config;
  2 +
  3 +import com.ruoyi.common.config.RuoYiConfig;
  4 +import io.swagger.annotations.ApiOperation;
  5 +import org.springframework.beans.factory.annotation.Autowired;
  6 +import org.springframework.context.annotation.Bean;
  7 +import org.springframework.context.annotation.Configuration;
  8 +import springfox.documentation.builders.ApiInfoBuilder;
  9 +import springfox.documentation.builders.PathSelectors;
  10 +import springfox.documentation.builders.RequestHandlerSelectors;
  11 +import springfox.documentation.service.ApiInfo;
  12 +import springfox.documentation.service.Contact;
  13 +import springfox.documentation.spi.DocumentationType;
  14 +import springfox.documentation.spring.web.plugins.Docket;
  15 +import springfox.documentation.swagger2.annotations.EnableSwagger2;
  16 +
  17 +
  18 +@Configuration
  19 +@EnableSwagger2
  20 +public class SwaggerConfig {
  21 + /** 系统基础配置 */
  22 + @Autowired
  23 + private RuoYiConfig ruoyiConfig;
  24 + @Bean
  25 + public Docket createRestApi() {
  26 + return new Docket(DocumentationType.SWAGGER_2)
  27 + .apiInfo(apiInfo())
  28 + .select()
  29 + .apis(RequestHandlerSelectors.withMethodAnnotation(ApiOperation.class))
  30 + .paths(PathSelectors.any())
  31 + .build();
  32 + }
  33 +
  34 + /**
  35 + * 添加摘要信息
  36 + */
  37 + private ApiInfo apiInfo()
  38 + {
  39 + // 用ApiInfoBuilder进行定制
  40 + return new ApiInfoBuilder()
  41 + // 设置标题
  42 + .title("标题:后台管理员端")
  43 + // 描述
  44 + .description("描述:用于通过mqtt发送指令控制PC端操作")
  45 + // 作者信息
  46 + .contact(new Contact(ruoyiConfig.getName(), null, null))
  47 + // 版本
  48 + .version("版本号:" + ruoyiConfig.getVersion())
  49 + .build();
  50 + }
  51 +
  52 +}
  1 +package com.zhonglai.luhui.api.controller;
  2 +
  3 +import java.util.List;
  4 +import javax.servlet.http.HttpServletResponse;
  5 +
  6 +import io.swagger.annotations.Api;
  7 +import io.swagger.annotations.ApiOperation;
  8 +import org.springframework.security.access.prepost.PreAuthorize;
  9 +import org.springframework.beans.factory.annotation.Autowired;
  10 +import org.springframework.web.bind.annotation.GetMapping;
  11 +import org.springframework.web.bind.annotation.PostMapping;
  12 +import org.springframework.web.bind.annotation.PutMapping;
  13 +import org.springframework.web.bind.annotation.DeleteMapping;
  14 +import org.springframework.web.bind.annotation.PathVariable;
  15 +import org.springframework.web.bind.annotation.RequestBody;
  16 +import org.springframework.web.bind.annotation.RequestMapping;
  17 +import org.springframework.web.bind.annotation.RestController;
  18 +import com.ruoyi.common.annotation.Log;
  19 +import com.ruoyi.common.core.controller.BaseController;
  20 +import com.ruoyi.common.core.domain.AjaxResult;
  21 +import com.ruoyi.common.enums.BusinessType;
  22 +import com.ruoyi.system.domain.UserTerminalGroup;
  23 +import com.ruoyi.system.service.IUserTerminalGroupService;
  24 +import com.ruoyi.common.utils.poi.ExcelUtil;
  25 +import com.ruoyi.common.core.page.TableDataInfo;
  26 +
  27 +/**
  28 + * 终端分组Controller
  29 + *
  30 + * @author 钟来
  31 + * @date 2022-11-22
  32 + */
  33 +@Api(tags = "终端分组")
  34 +@RestController
  35 +@RequestMapping("/user/UserTerminalGroup")
  36 +public class UserTerminalGroupController extends BaseController
  37 +{
  38 + @Autowired
  39 + private IUserTerminalGroupService userTerminalGroupService;
  40 +
  41 + /**
  42 + * 查询终端分组列表
  43 + */
  44 + @ApiOperation("查询终端分组列表")
  45 + @PreAuthorize("@ss.hasPermi('user:UserTerminalGroup:list')")
  46 + @GetMapping("/list")
  47 + public TableDataInfo list(UserTerminalGroup userTerminalGroup)
  48 + {
  49 + userTerminalGroup.setUser_info_id(getUserId().intValue());
  50 + startPage();
  51 + List<UserTerminalGroup> list = userTerminalGroupService.selectUserTerminalGroupList(userTerminalGroup);
  52 + return getDataTable(list);
  53 + }
  54 +
  55 + /**
  56 + * 导出终端分组列表
  57 + */
  58 + @ApiOperation("导出终端分组列表")
  59 + @PreAuthorize("@ss.hasPermi('user:UserTerminalGroup:export')")
  60 + @Log(title = "终端分组", businessType = BusinessType.EXPORT)
  61 + @PostMapping("/export")
  62 + public void export(HttpServletResponse response, UserTerminalGroup userTerminalGroup)
  63 + {
  64 + userTerminalGroup.setUser_info_id(getUserId().intValue());
  65 + List<UserTerminalGroup> list = userTerminalGroupService.selectUserTerminalGroupList(userTerminalGroup);
  66 + ExcelUtil<UserTerminalGroup> util = new ExcelUtil<UserTerminalGroup>(UserTerminalGroup.class);
  67 + util.exportExcel(response, list, "终端分组数据");
  68 + }
  69 +
  70 + /**
  71 + * 获取终端分组详细信息
  72 + */
  73 + @ApiOperation("获取终端分组详细信息")
  74 + @PreAuthorize("@ss.hasPermi('user:UserTerminalGroup:query')")
  75 + @GetMapping(value = "/{id}")
  76 + public AjaxResult getInfo(@PathVariable("id") Integer id)
  77 + {
  78 + return AjaxResult.success(userTerminalGroupService.selectUserTerminalGroupById(id));
  79 + }
  80 +
  81 + /**
  82 + * 新增终端分组
  83 + */
  84 + @ApiOperation("新增终端分组")
  85 + @PreAuthorize("@ss.hasPermi('user:UserTerminalGroup:add')")
  86 + @Log(title = "终端分组", businessType = BusinessType.INSERT)
  87 + @PostMapping
  88 + public AjaxResult add(@RequestBody UserTerminalGroup userTerminalGroup)
  89 + {
  90 + return toAjax(userTerminalGroupService.insertUserTerminalGroup(userTerminalGroup));
  91 + }
  92 +
  93 + /**
  94 + * 修改终端分组
  95 + */
  96 + @ApiOperation("修改终端分组")
  97 + @PreAuthorize("@ss.hasPermi('user:UserTerminalGroup:edit')")
  98 + @Log(title = "终端分组", businessType = BusinessType.UPDATE)
  99 + @PutMapping
  100 + public AjaxResult edit(@RequestBody UserTerminalGroup userTerminalGroup)
  101 + {
  102 + return toAjax(userTerminalGroupService.updateUserTerminalGroup(userTerminalGroup));
  103 + }
  104 +
  105 + /**
  106 + * 删除终端分组
  107 + */
  108 + @ApiOperation("删除终端分组")
  109 + @PreAuthorize("@ss.hasPermi('user:UserTerminalGroup:remove')")
  110 + @Log(title = "终端分组", businessType = BusinessType.DELETE)
  111 + @DeleteMapping("/{ids}")
  112 + public AjaxResult remove(@PathVariable Integer[] ids)
  113 + {
  114 + return toAjax(userTerminalGroupService.deleteUserTerminalGroupByIds(ids));
  115 + }
  116 +}
  1 +package com.zhonglai.luhui.api.controller;
  2 +
  3 +import java.util.List;
  4 +import javax.servlet.http.HttpServletResponse;
  5 +
  6 +import io.swagger.annotations.Api;
  7 +import io.swagger.annotations.ApiOperation;
  8 +import org.springframework.security.access.prepost.PreAuthorize;
  9 +import org.springframework.beans.factory.annotation.Autowired;
  10 +import org.springframework.web.bind.annotation.GetMapping;
  11 +import org.springframework.web.bind.annotation.PostMapping;
  12 +import org.springframework.web.bind.annotation.PutMapping;
  13 +import org.springframework.web.bind.annotation.DeleteMapping;
  14 +import org.springframework.web.bind.annotation.PathVariable;
  15 +import org.springframework.web.bind.annotation.RequestBody;
  16 +import org.springframework.web.bind.annotation.RequestMapping;
  17 +import org.springframework.web.bind.annotation.RestController;
  18 +import com.ruoyi.common.annotation.Log;
  19 +import com.ruoyi.common.core.controller.BaseController;
  20 +import com.ruoyi.common.core.domain.AjaxResult;
  21 +import com.ruoyi.common.enums.BusinessType;
  22 +import com.ruoyi.system.domain.UserTerminalGroupRelation;
  23 +import com.ruoyi.system.service.IUserTerminalGroupRelationService;
  24 +import com.ruoyi.common.utils.poi.ExcelUtil;
  25 +import com.ruoyi.common.core.page.TableDataInfo;
  26 +
  27 +/**
  28 + * 终端分组关系Controller
  29 + *
  30 + * @author 钟来
  31 + * @date 2022-11-22
  32 + */
  33 +@Api(tags = "终端分组关系")
  34 +@RestController
  35 +@RequestMapping("/user/UserTerminalGroupRelation")
  36 +public class UserTerminalGroupRelationController extends BaseController
  37 +{
  38 + @Autowired
  39 + private IUserTerminalGroupRelationService userTerminalGroupRelationService;
  40 +
  41 + /**
  42 + * 查询终端分组关系列表
  43 + */
  44 + @ApiOperation("查询终端分组关系列表")
  45 + @PreAuthorize("@ss.hasPermi('user:UserTerminalGroupRelation:list')")
  46 + @GetMapping("/list")
  47 + public TableDataInfo list(UserTerminalGroupRelation userTerminalGroupRelation)
  48 + {
  49 + userTerminalGroupRelation.setUser_info_id(getUserId().intValue());
  50 + startPage();
  51 + List<UserTerminalGroupRelation> list = userTerminalGroupRelationService.selectUserTerminalGroupRelationList(userTerminalGroupRelation);
  52 + return getDataTable(list);
  53 + }
  54 +
  55 + /**
  56 + * 导出终端分组关系列表
  57 + */
  58 + @ApiOperation("导出终端分组关系列表")
  59 + @PreAuthorize("@ss.hasPermi('user:UserTerminalGroupRelation:export')")
  60 + @Log(title = "终端分组关系", businessType = BusinessType.EXPORT)
  61 + @PostMapping("/export")
  62 + public void export(HttpServletResponse response, UserTerminalGroupRelation userTerminalGroupRelation)
  63 + {
  64 + List<UserTerminalGroupRelation> list = userTerminalGroupRelationService.selectUserTerminalGroupRelationList(userTerminalGroupRelation);
  65 + ExcelUtil<UserTerminalGroupRelation> util = new ExcelUtil<UserTerminalGroupRelation>(UserTerminalGroupRelation.class);
  66 + util.exportExcel(response, list, "终端分组关系数据");
  67 + }
  68 +
  69 + /**
  70 + * 获取终端分组关系详细信息
  71 + */
  72 + @ApiOperation("获取终端分组关系详细信息")
  73 + @PreAuthorize("@ss.hasPermi('user:UserTerminalGroupRelation:query')")
  74 + @GetMapping(value = "/{id}")
  75 + public AjaxResult getInfo(@PathVariable("id") Integer id)
  76 + {
  77 + return AjaxResult.success(userTerminalGroupRelationService.selectUserTerminalGroupRelationById(id));
  78 + }
  79 +
  80 + /**
  81 + * 新增终端分组关系
  82 + */
  83 + @ApiOperation("新增终端分组关系")
  84 + @PreAuthorize("@ss.hasPermi('user:UserTerminalGroupRelation:add')")
  85 + @Log(title = "终端分组关系", businessType = BusinessType.INSERT)
  86 + @PostMapping
  87 + public AjaxResult add(@RequestBody UserTerminalGroupRelation userTerminalGroupRelation)
  88 + {
  89 + return toAjax(userTerminalGroupRelationService.insertUserTerminalGroupRelation(userTerminalGroupRelation));
  90 + }
  91 +
  92 + /**
  93 + * 修改终端分组关系
  94 + */
  95 + @ApiOperation("修改终端分组关系")
  96 + @PreAuthorize("@ss.hasPermi('user:UserTerminalGroupRelation:edit')")
  97 + @Log(title = "终端分组关系", businessType = BusinessType.UPDATE)
  98 + @PutMapping
  99 + public AjaxResult edit(@RequestBody UserTerminalGroupRelation userTerminalGroupRelation)
  100 + {
  101 + return toAjax(userTerminalGroupRelationService.updateUserTerminalGroupRelation(userTerminalGroupRelation));
  102 + }
  103 +
  104 + /**
  105 + * 删除终端分组关系
  106 + */
  107 + @ApiOperation("删除终端分组关系")
  108 + @PreAuthorize("@ss.hasPermi('user:UserTerminalGroupRelation:remove')")
  109 + @Log(title = "终端分组关系", businessType = BusinessType.DELETE)
  110 + @DeleteMapping("/{ids}")
  111 + public AjaxResult remove(@PathVariable Integer[] ids)
  112 + {
  113 + return toAjax(userTerminalGroupRelationService.deleteUserTerminalGroupRelationByIds(ids));
  114 + }
  115 +}
  1 +restart.include.json=/com.alibaba.fastjson.*.jar
  1 +# 数据源配置
  2 +spring:
  3 + datasource:
  4 + type: com.alibaba.druid.pool.DruidDataSource
  5 + driverClassName: com.mysql.cj.jdbc.Driver
  6 + druid:
  7 + # 主库数据源
  8 + master:
  9 + url: jdbc:mysql://rm-wz9740un21f09iokuao.mysql.rds.aliyuncs.com:3306/mqtt_broker?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8
  10 + username: luhui
  11 + password: Luhui586
  12 + # 从库数据源
  13 + slave:
  14 + # 从数据源开关/默认关闭
  15 + enabled: false
  16 + url:
  17 + username:
  18 + password:
  19 + # 初始连接数
  20 + initialSize: 5
  21 + # 最小连接池数量
  22 + minIdle: 10
  23 + # 最大连接池数量
  24 + maxActive: 20
  25 + # 配置获取连接等待超时的时间
  26 + maxWait: 60000
  27 + # 配置间隔多久才进行一次检测,检测需要关闭的空闲连接,单位是毫秒
  28 + timeBetweenEvictionRunsMillis: 60000
  29 + # 配置一个连接在池中最小生存的时间,单位是毫秒
  30 + minEvictableIdleTimeMillis: 300000
  31 + # 配置一个连接在池中最大生存的时间,单位是毫秒
  32 + maxEvictableIdleTimeMillis: 900000
  33 + # 配置检测连接是否有效
  34 + validationQuery: SELECT 1 FROM DUAL
  35 + testWhileIdle: true
  36 + testOnBorrow: false
  37 + testOnReturn: false
  38 + webStatFilter:
  39 + enabled: true
  40 + statViewServlet:
  41 + enabled: true
  42 + # 设置白名单,不填则允许所有访问
  43 + allow:
  44 + url-pattern: /druid/*
  45 + # 控制台管理用户名和密码
  46 + login-username: ruoyi
  47 + login-password: 123456
  48 + filter:
  49 + stat:
  50 + enabled: true
  51 + # 慢SQL记录
  52 + log-slow-sql: true
  53 + slow-sql-millis: 1000
  54 + merge-sql: true
  55 + wall:
  56 + config:
  57 + multi-statement-allow: true
1 -# 项目相关配置 jhlt: # 名称 name: zhonglai # 版本 version: 3.8.2 # 版权年份 copyrightYear: 2022 # 实例演示开关 demoEnabled: true # 文件路径 示例( Windows配置D:/ruoyi/uploadPath,Linux配置 /home/ruoyi/uploadPath) profile: D:/ruoyi/uploadPath # 获取ip地址开关 addressEnabled: false # 验证码类型 math 数组计算 char 字符验证 captchaType: math # 开发环境配置 server: # 服务器的HTTP端口,默认为8080 port: 8080 servlet: # 应用的访问路径 context-path: / tomcat: # tomcat的URI编码 uri-encoding: UTF-8 # 连接数满后的排队数,默认为100 accept-count: 1000 threads: # tomcat最大线程数,默认为200 max: 800 # Tomcat启动初始化的线程数,默认值10 min-spare: 100 # 日志配置 logging: level: com.ruoyi: debug org.springframework: warn # Spring配置 spring: # 资源信息 messages: # 国际化资源文件路径 basename: i18n/messages profiles: active: druid # 文件上传 servlet: multipart: # 单个文件大小 max-file-size: 10MB # 设置总上传的文件大小 max-request-size: 20MB # 服务模块 devtools: restart: # 热部署开关 enabled: true # redis 配置 redis: # 地址 host: 47.112.163.61 # 端口,默认为6379 port: 9527 # 数据库索引 database: 1 # 密码 password: Luhui586 # 连接超时时间 timeout: 10s lettuce: pool: # 连接池中的最小空闲连接 min-idle: 0 # 连接池中的最大空闲连接 max-idle: 8 # 连接池的最大数据库连接数 max-active: 8 # #连接池最大阻塞等待时间(使用负值表示没有限制) max-wait: -1ms # token配置 token: # 令牌自定义标识 header: Authorization # 令牌密钥 secret: abcdefghijklmnopqrstuvwxyz # 令牌有效期(默认30分钟) expireTime: 1440 # MyBatis配置 mybatis: # 搜索指定包别名 typeAliasesPackage: com.ruoyi.**.domain # 配置mapper的扫描,找到所有的mapper.xml映射文件 mapperLocations: classpath*:mapper/**/*Mapper.xml # 加载全局的配置文件 configLocation: classpath:mybatis/mybatis-config.xml # PageHelper分页插件 pagehelper: helperDialect: mysql supportMethodsArguments: true params: count=countSql # Swagger配置 swagger: # 是否开启swagger enabled: true # 请求前缀 pathMapping: /dev-api # 防止XSS攻击 xss: # 过滤开关 enabled: true # 排除链接(多个用逗号分隔) excludes: /system/notice # 匹配链接 urlPatterns: /system/*,/monitor/*,/tool/* mqtt: client: device_life: 180 sys: ## // 对于登录login 注册register 验证码captchaImage 允许匿名访问 antMatchers: /login,/register,/captchaImage,/getCacheObject,/v2/api-docs,/tool/gen/generatorCodeFromDb  
  1 +# 项目相关配置 jhlt: # 名称 name: zhonglai # 版本 version: 3.8.2 # 版权年份 copyrightYear: 2022 # 实例演示开关 demoEnabled: true # 文件路径 示例( Windows配置D:/ruoyi/uploadPath,Linux配置 /home/ruoyi/uploadPath) profile: D:/ruoyi/uploadPath # 获取ip地址开关 addressEnabled: false # 验证码类型 math 数组计算 char 字符验证 captchaType: math # 开发环境配置 server: # 服务器的HTTP端口,默认为8080 port: 8080 servlet: # 应用的访问路径 context-path: / tomcat: # tomcat的URI编码 uri-encoding: UTF-8 # 连接数满后的排队数,默认为100 accept-count: 1000 threads: # tomcat最大线程数,默认为200 max: 800 # Tomcat启动初始化的线程数,默认值10 min-spare: 100 # 日志配置 logging: level: com.ruoyi: debug org.springframework: warn # Spring配置 spring: # 资源信息 messages: # 国际化资源文件路径 basename: i18n/messages profiles: active: druid # 文件上传 servlet: multipart: # 单个文件大小 max-file-size: 10MB # 设置总上传的文件大小 max-request-size: 20MB # 服务模块 devtools: restart: # 热部署开关 enabled: true # redis 配置 redis: # 地址 host: 47.112.163.61 # 端口,默认为6379 port: 9527 # 数据库索引 database: 1 # 密码 password: Luhui586 # 连接超时时间 timeout: 10s lettuce: pool: # 连接池中的最小空闲连接 min-idle: 0 # 连接池中的最大空闲连接 max-idle: 8 # 连接池的最大数据库连接数 max-active: 8 # #连接池最大阻塞等待时间(使用负值表示没有限制) max-wait: -1ms # token配置 token: # 令牌自定义标识 header: Authorization # 令牌密钥 secret: abcdefghijklmnopqrstuvwxyz # 令牌有效期(默认30分钟) expireTime: 1440 rediskey: lh-api # MyBatis配置 mybatis: # 搜索指定包别名 typeAliasesPackage: com.ruoyi.**.domain # 配置mapper的扫描,找到所有的mapper.xml映射文件 mapperLocations: classpath*:mapper/**/*Mapper.xml # 加载全局的配置文件 configLocation: classpath:mybatis/mybatis-config.xml # PageHelper分页插件 pagehelper: helperDialect: mysql supportMethodsArguments: true params: count=countSql # Swagger配置 swagger: # 是否开启swagger enabled: true # 请求前缀 pathMapping: /dev-api # 防止XSS攻击 xss: # 过滤开关 enabled: true # 排除链接(多个用逗号分隔) excludes: /system/notice # 匹配链接 urlPatterns: /system/*,/monitor/*,/tool/* mqtt: client: device_life: 180 sys: ## // 对于登录login 注册register 验证码captchaImage 允许匿名访问 antMatchers: /login,/register,/captchaImage,/getCacheObject,/v2/api-docs,/tool/gen/generatorCodeFromDb
  1 +#错误消息
  2 +not.null=* 必须填写
  3 +user.jcaptcha.error=验证码错误
  4 +user.jcaptcha.expire=验证码已失效
  5 +user.not.exists=用户不存在/密码错误
  6 +user.password.not.match=用户不存在/密码错误
  7 +user.password.retry.limit.count=密码输入错误{0}次
  8 +user.password.retry.limit.exceed=密码输入错误{0}次,帐户锁定10分钟
  9 +user.password.delete=对不起,您的账号已被删除
  10 +user.blocked=用户已封禁,请联系管理员
  11 +role.blocked=角色已封禁,请联系管理员
  12 +user.logout.success=退出成功
  13 +
  14 +length.not.valid=长度必须在{min}到{max}个字符之间
  15 +
  16 +user.username.not.valid=* 2到20个汉字、字母、数字或下划线组成,且必须以非数字开头
  17 +user.password.not.valid=* 5-50个字符
  18 +
  19 +user.email.not.valid=邮箱格式错误
  20 +user.mobile.phone.number.not.valid=手机号格式错误
  21 +user.login.success=登录成功
  22 +user.register.success=注册成功
  23 +user.notfound=请重新登录
  24 +user.forcelogout=管理员强制退出,请重新登录
  25 +user.unknown.error=未知错误,请重新登录
  26 +
  27 +##文件上传消息
  28 +upload.exceed.maxSize=上传的文件大小超出限制的文件大小!<br/>允许的文件最大大小是:{0}MB!
  29 +upload.filename.exceed.length=上传的文件名最长{0}个字符
  30 +
  31 +##权限
  32 +no.permission=您没有数据的权限,请联系管理员添加权限 [{0}]
  33 +no.create.permission=您没有创建数据的权限,请联系管理员添加权限 [{0}]
  34 +no.update.permission=您没有修改数据的权限,请联系管理员添加权限 [{0}]
  35 +no.delete.permission=您没有删除数据的权限,请联系管理员添加权限 [{0}]
  36 +no.export.permission=您没有导出数据的权限,请联系管理员添加权限 [{0}]
  37 +no.view.permission=您没有查看数据的权限,请联系管理员添加权限 [{0}]
  1 +<?xml version="1.0" encoding="UTF-8" ?>
  2 +<!DOCTYPE configuration
  3 +PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
  4 +"http://mybatis.org/dtd/mybatis-3-config.dtd">
  5 +<configuration>
  6 + <!-- 全局参数 -->
  7 + <settings>
  8 + <!-- 使全局的映射器启用或禁用缓存 -->
  9 + <setting name="cacheEnabled" value="true" />
  10 + <!-- 允许JDBC 支持自动生成主键 -->
  11 + <setting name="useGeneratedKeys" value="true" />
  12 + <!-- 配置默认的执行器.SIMPLE就是普通执行器;REUSE执行器会重用预处理语句(prepared statements);BATCH执行器将重用语句并执行批量更新 -->
  13 + <setting name="defaultExecutorType" value="SIMPLE" />
  14 + <!-- 指定 MyBatis 所用日志的具体实现 -->
  15 + <setting name="logImpl" value="SLF4J" />
  16 + <!-- 使用驼峰命名法转换字段 -->
  17 + <!-- <setting name="mapUnderscoreToCamelCase" value="true"/> -->
  18 + </settings>
  19 +
  20 +</configuration>
@@ -11,143 +11,23 @@ @@ -11,143 +11,23 @@
11 11
12 <artifactId>lh-central-control</artifactId> 12 <artifactId>lh-central-control</artifactId>
13 13
14 - <description>  
15 - 中控平台  
16 - </description>  
17 -  
18 <dependencies> 14 <dependencies>
19 - <!-- spring-boot-devtools --> 15 + <!-- spring-boot-devtools -->
20 <dependency> 16 <dependency>
21 <groupId>org.springframework.boot</groupId> 17 <groupId>org.springframework.boot</groupId>
22 <artifactId>spring-boot-devtools</artifactId> 18 <artifactId>spring-boot-devtools</artifactId>
23 <optional>true</optional> <!-- 表示依赖不会传递 --> 19 <optional>true</optional> <!-- 表示依赖不会传递 -->
24 </dependency> 20 </dependency>
25 - <!-- SpringBoot Web容器 -->  
26 - <dependency>  
27 - <groupId>org.springframework.boot</groupId>  
28 - <artifactId>spring-boot-starter-web</artifactId>  
29 - </dependency>  
30 <!-- Spring框架基本的核心工具 --> 21 <!-- Spring框架基本的核心工具 -->
31 <dependency> 22 <dependency>
32 <groupId>org.springframework</groupId> 23 <groupId>org.springframework</groupId>
33 <artifactId>spring-context-support</artifactId> 24 <artifactId>spring-context-support</artifactId>
34 </dependency> 25 </dependency>
35 - <!-- SpringWeb模块 -->  
36 - <dependency>  
37 - <groupId>org.springframework</groupId>  
38 - <artifactId>spring-web</artifactId>  
39 - </dependency>  
40 - <!-- servlet包 -->  
41 - <dependency>  
42 - <groupId>javax.servlet</groupId>  
43 - <artifactId>javax.servlet-api</artifactId>  
44 - </dependency>  
45 - <dependency>  
46 - <groupId>org.apache.commons</groupId>  
47 - <artifactId>commons-text</artifactId>  
48 - </dependency>  
49 -  
50 - <!-- 文档 -->  
51 - <dependency>  
52 - <groupId>io.springfox</groupId>  
53 - <artifactId>springfox-swagger2</artifactId>  
54 - <version>${swagger.version}</version>  
55 - <exclusions>  
56 - <exclusion>  
57 - <groupId>io.swagger</groupId>  
58 - <artifactId>swagger-models</artifactId>  
59 - </exclusion>  
60 - <exclusion>  
61 - <groupId>com.google.guava</groupId>  
62 - <artifactId>guava</artifactId>  
63 - </exclusion>  
64 - </exclusions>  
65 - </dependency>  
66 - <!--https://mvnrepository.com/artifact/io.swagger/swagger-models-->  
67 - <dependency>  
68 - <groupId>io.swagger</groupId>  
69 - <artifactId>swagger-models</artifactId>  
70 - <version>${swagger-models.version}</version>  
71 - </dependency>  
72 - <dependency>  
73 - <groupId>io.springfox</groupId>  
74 - <artifactId>springfox-swagger-ui</artifactId>  
75 - <version>${swagger.version}</version>  
76 - </dependency>  
77 - <!--&lt;!&ndash; https://mvnrepository.com/artifact/com.github.xiaoymin/swagger-bootstrap-ui &ndash;&gt;-->  
78 - <dependency>  
79 - <groupId>com.github.xiaoymin</groupId>  
80 - <artifactId>swagger-bootstrap-ui</artifactId>  
81 - <version>${swagger-ui.version}</version>  
82 - </dependency>  
83 -  
84 - <!-- mqtt -->  
85 - <dependency>  
86 - <groupId>org.eclipse.paho</groupId>  
87 - <artifactId>org.eclipse.paho.client.mqttv3</artifactId>  
88 - </dependency>  
89 -  
90 - <dependency>  
91 - <groupId>net.jodah</groupId>  
92 - <artifactId>expiringmap</artifactId>  
93 - </dependency>  
94 -  
95 -  
96 - <!-- 数据库 -->  
97 - <dependency>  
98 - <groupId>commons-dbcp</groupId>  
99 - <artifactId>commons-dbcp</artifactId>  
100 - <version>1.4</version>  
101 - </dependency>  
102 - <dependency>  
103 - <groupId>commons-dbutils</groupId>  
104 - <artifactId>commons-dbutils</artifactId>  
105 - <version>1.6</version>  
106 - </dependency>  
107 - <dependency>  
108 - <groupId>commons-pool</groupId>  
109 - <artifactId>commons-pool</artifactId>  
110 - <version>1.6</version>  
111 - </dependency>  
112 - <dependency>  
113 - <groupId>mysql</groupId>  
114 - <artifactId>mysql-connector-java</artifactId>  
115 - <version>8.0.17</version>  
116 - </dependency>  
117 -  
118 - <!-- 阿里JSON解析器 -->  
119 - <dependency>  
120 - <groupId>com.alibaba</groupId>  
121 - <artifactId>fastjson</artifactId>  
122 - </dependency>  
123 -  
124 - <!--常用工具类 -->  
125 - <dependency>  
126 - <groupId>org.apache.commons</groupId>  
127 - <artifactId>commons-lang3</artifactId>  
128 - </dependency>  
129 -  
130 - <!-- redis 缓存操作 -->  
131 - <dependency>  
132 - <groupId>org.springframework.boot</groupId>  
133 - <artifactId>spring-boot-starter-data-redis</artifactId>  
134 - <exclusions>  
135 - <exclusion>  
136 - <groupId>io.lettuce</groupId>  
137 - <artifactId>lettuce-core</artifactId>  
138 - </exclusion>  
139 - </exclusions>  
140 - </dependency>  
141 - <dependency>  
142 - <groupId>redis.clients</groupId>  
143 - <artifactId>jedis</artifactId>  
144 - </dependency>  
145 -  
146 - <!-- 通用工具--> 26 + <!-- 系统模块-->
147 <dependency> 27 <dependency>
148 <groupId>com.zhonglai.luhui</groupId> 28 <groupId>com.zhonglai.luhui</groupId>
149 - <artifactId>lh-domain</artifactId> 29 + <artifactId>ruoyi-common</artifactId>
150 </dependency> 30 </dependency>
151 -  
152 </dependencies> 31 </dependencies>
  32 +
153 </project> 33 </project>
  1 +package com.zhonglai.luhui.central.control;
  2 +
  3 +import com.alibaba.fastjson.JSONObject;
  4 +import com.ruoyi.common.core.domain.Message;
  5 +import com.ruoyi.common.core.domain.MessageCode;
  6 +import com.ruoyi.common.core.redis.RedisCache;
  7 +import com.ruoyi.common.utils.StringUtils;
  8 +import com.ruoyi.common.utils.html.HttpUtils;
  9 +import com.ruoyi.system.domain.IotDevice;
  10 +import okhttp3.Response;
  11 +import org.springframework.beans.factory.annotation.Autowired;
  12 +import org.springframework.stereotype.Service;
  13 +import org.springframework.web.bind.annotation.RequestBody;
  14 +
  15 +import java.io.IOException;
  16 +import java.util.HashMap;
  17 +import java.util.Map;
  18 +
  19 +@Service
  20 +public class DeviceControlService {
  21 + @Autowired
  22 + private RedisCache redisCache;
  23 + private String redisHostPath = "luhui:mqttservice:device:device:";
  24 +
  25 + @Autowired
  26 + private DeviceDBOperationService deviceDBOperationService;
  27 +
  28 + private IotDevice getRedisIotDevice(String imei)
  29 + {
  30 + return (IotDevice)redisCache.getCacheObject(redisHostPath+imei);
  31 + }
  32 +
  33 + /**
  34 + * 固件版本更新
  35 + * @param imei 主机imei
  36 + * @param firmwareVersion 版本号
  37 + * @param code 版本码
  38 + * @return
  39 + */
  40 + public Message firmwareUp(String imei,String firmwareVersion,Integer code)
  41 + {
  42 + IotDevice iotDevice = getRedisIotDevice(imei);
  43 + if(null == iotDevice || StringUtils.isEmpty(iotDevice.getListen_service_ip()))
  44 + {
  45 + return new Message(MessageCode.DEFAULT_FAIL_CODE,"设备不在线");
  46 + }
  47 + String url = "http://"+iotDevice.getListen_service_ip()+"device/control/"+imei;
  48 + Map<String,Object> valueMap = new HashMap<>();
  49 + valueMap.put("firmwareVersion",firmwareVersion);
  50 + valueMap.put("code",code);
  51 + return post(url, jsonObject -> jsonObject.put("0",valueMap));
  52 + }
  53 +
  54 + /**
  55 + * 设备重启
  56 + * @param imei 主机imei
  57 + * @param restart 1重启,2复位,3恢复出厂值
  58 + * @return
  59 + */
  60 + public Message restart(String imei ,Integer restart)
  61 + {
  62 + IotDevice iotDevice = getRedisIotDevice(imei);
  63 + if(null == iotDevice || StringUtils.isEmpty(iotDevice.getListen_service_ip()))
  64 + {
  65 + return new Message(MessageCode.DEFAULT_FAIL_CODE,"设备不在线");
  66 + }
  67 + String url = "http://"+iotDevice.getListen_service_ip()+"device/control/"+imei;
  68 + Map<String,Object> map = new HashMap<>();
  69 + Map<String,Object> valueMap = new HashMap<>();
  70 + valueMap.put("restart",restart);
  71 + return post(url, jsonObject -> jsonObject.put("0",valueMap));
  72 + }
  73 +
  74 + /**
  75 + * 获取指定设备版本信息
  76 + * @param imei 主机imei
  77 + * @return
  78 + * @throws IOException
  79 + */
  80 + public Message getFirmwareVersion(String imei) throws IOException {
  81 + IotDevice iotDevice = getRedisIotDevice(imei);
  82 + if(null == iotDevice || StringUtils.isEmpty(iotDevice.getListen_service_ip()))
  83 + {
  84 + return new Message(MessageCode.DEFAULT_FAIL_CODE,"设备不在线");
  85 + }
  86 + String url = "http://"+iotDevice.getListen_service_ip()+"device/getFirmwareVersion/"+iotDevice.getMqtt_username();
  87 + return postFrom(url, formBody -> {
  88 + });
  89 + }
  90 +
  91 + /**
  92 + * 强行断开链接
  93 + * @param imei 主机imei
  94 + * @return
  95 + * @throws IOException
  96 + */
  97 + public Message closeSession(String imei) {
  98 + IotDevice iotDevice = getRedisIotDevice(imei);
  99 + if(null == iotDevice || StringUtils.isEmpty(iotDevice.getListen_service_ip()))
  100 + {
  101 + return new Message(MessageCode.DEFAULT_FAIL_CODE,"设备不在线");
  102 + }
  103 + String url = "http://"+iotDevice.getListen_service_ip()+"device/closeSession/"+imei;
  104 + return postFrom(url, formBody -> {
  105 + });
  106 + }
  107 +
  108 + /**
  109 + * 删除主机
  110 + * @param imei 主机imei
  111 + * @return
  112 + */
  113 + public Message delIotDevice(String imei) {
  114 + IotDevice iotDevice = getRedisIotDevice(imei);
  115 + if(null == iotDevice || StringUtils.isEmpty(iotDevice.getListen_service_ip()))
  116 + {
  117 + return new Message(MessageCode.DEFAULT_FAIL_CODE,"设备不在线");
  118 + }
  119 + deviceDBOperationService.deleteIotDeviceByClient_id(imei);
  120 + deviceDBOperationService.deleteIotTerminalByDeviceId(imei);
  121 + if(StringUtils.isEmpty(iotDevice.getListen_service_ip()))
  122 + {
  123 + return new Message(MessageCode.DEFAULT_SUCCESS_CODE,"删除成功");
  124 + }
  125 + String url = "http://"+iotDevice.getListen_service_ip()+"device/delIotDevice/"+imei;
  126 +
  127 + return postFrom(url, formBody -> {
  128 + });
  129 + }
  130 +
  131 + /**
  132 + * 删除终端
  133 + * @param imei 主机imei
  134 + * @param number 终端编号
  135 + * @return
  136 + */
  137 + public Message delIotTerminal(String imei,String number) {
  138 + IotDevice iotDevice = getRedisIotDevice(imei);
  139 + if(null == iotDevice || StringUtils.isEmpty(iotDevice.getListen_service_ip()))
  140 + {
  141 + return new Message(MessageCode.DEFAULT_FAIL_CODE,"设备不在线");
  142 + }
  143 + deviceDBOperationService.deleteIotTerminalById(imei+"_"+number);
  144 + if(StringUtils.isEmpty(iotDevice.getListen_service_ip()))
  145 + {
  146 + return new Message(MessageCode.DEFAULT_SUCCESS_CODE,"删除成功");
  147 + }
  148 + String url = "http://"+iotDevice.getListen_service_ip()+"device/delIotTerminal/"+imei+"/"+number;
  149 +
  150 + return postFrom(url, formBody -> {
  151 + });
  152 + }
  153 +
  154 + /**
  155 + * 读取属性
  156 + * @param imei 主机imei
  157 + * @param sensor_number 传感器编号(0,1_1,10_1)
  158 + * @param attributes 属性集合(id1,id2,id3)
  159 + * @return
  160 + * @throws IOException
  161 + */
  162 + public Message readAttribute(String imei,String sensor_number,String attributes) throws IOException {
  163 + IotDevice iotDevice = getRedisIotDevice(imei);
  164 + if(null == iotDevice || StringUtils.isEmpty(iotDevice.getListen_service_ip()))
  165 + {
  166 + return new Message(MessageCode.DEFAULT_FAIL_CODE,"设备不在线");
  167 + }
  168 + String url = "http://"+iotDevice.getListen_service_ip()+"device/read/"+imei;
  169 + return post(url, jsonObject -> jsonObject.put(sensor_number,attributes));
  170 + }
  171 +
  172 + /**
  173 + * 设置主机自定义参数
  174 + * @param imei 主机imei
  175 + * @param summary 自定义数据json字符串
  176 + * @return
  177 + * @throws IOException
  178 + */
  179 + public Message upSummary(String imei,String summary) {
  180 + IotDevice iotDevice = getRedisIotDevice(imei);
  181 + if(null == iotDevice || StringUtils.isEmpty(iotDevice.getListen_service_ip()))
  182 + {
  183 + return new Message(MessageCode.DEFAULT_FAIL_CODE,"设备不在线");
  184 + }
  185 + String url = "http://"+iotDevice.getListen_service_ip()+"device/control/"+imei;
  186 + Map<String,Object> valueMap = new HashMap<>();
  187 + valueMap.put("summary",JSONObject.parseObject(summary));
  188 + return post(url, jsonObject -> jsonObject.put("0",valueMap));
  189 + }
  190 +
  191 + /**
  192 + * 修改指定终端属性
  193 + * @param imei 主机imei
  194 + * @param number 终端编号(如:1_1)
  195 + * @param config 配置参数json字符串
  196 + * @return
  197 + * @throws IOException
  198 + */
  199 + public Message upTerminalConfig(String imei,String number,@RequestBody Map<String,Object> config) throws IOException {
  200 + IotDevice iotDevice = getRedisIotDevice(imei);
  201 + if(null == iotDevice || StringUtils.isEmpty(iotDevice.getListen_service_ip()))
  202 + {
  203 + return new Message(MessageCode.DEFAULT_FAIL_CODE,"设备不在线");
  204 + }
  205 + String url = "http://"+iotDevice.getListen_service_ip()+"device/control/"+imei;
  206 + return post(url, jsonObject -> jsonObject.put(number,config));
  207 + }
  208 +
  209 + /**
  210 + * 批量修改终端属性
  211 + * @param imei 主机imei
  212 + * @param map 批量数据json字符串
  213 + * @return
  214 + * @throws IOException
  215 + */
  216 + public Message batchUpTerminalConfig(String imei,@RequestBody Map<String,Object> map) {
  217 + IotDevice iotDevice = getRedisIotDevice(imei);
  218 + if(null == iotDevice || StringUtils.isEmpty(iotDevice.getListen_service_ip()))
  219 + {
  220 + return new Message(MessageCode.DEFAULT_FAIL_CODE,"设备不在线");
  221 + }
  222 + String url = "http://"+iotDevice.getListen_service_ip()+"device/control/"+imei;
  223 + return post(url, jsonObject -> {
  224 + for (String key:map.keySet())
  225 + {
  226 + jsonObject.put(key, map.get(key));
  227 + }
  228 + });
  229 + }
  230 +
  231 +
  232 + private Message post(String url, HttpUtils.JsonBody jsonBody)
  233 + {
  234 + Response response = null;
  235 + try {
  236 + response = HttpUtils.postJsonBody(url, jsonBody);
  237 + if(null != response.body() && StringUtils.isNotEmpty(response.body().string()))
  238 + {
  239 + Message message = com.alibaba.fastjson.JSONObject.parseObject(response.body().string(),Message.class);
  240 + return message;
  241 + }
  242 + } catch (IOException e) {
  243 + return new Message(MessageCode.DEFAULT_FAIL_CODE,"指令转发失败请联系管理员");
  244 + }
  245 + return new Message(MessageCode.DEFAULT_FAIL_CODE,"指令执行失败请稍后重试");
  246 + }
  247 + private Message postFrom(String url,HttpUtils.FromBody fromBody )
  248 + {
  249 + Response response1 = null;
  250 + try {
  251 + response1 = HttpUtils.postFromBody(url, builder -> {
  252 + }, fromBody);
  253 + if(null != response1.body() && StringUtils.isNotEmpty(response1.body().string()))
  254 + {
  255 + Message message = com.alibaba.fastjson.JSONObject.parseObject(response1.body().string(),Message.class);
  256 + return message;
  257 + }
  258 + } catch (IOException e) {
  259 + return new Message(MessageCode.DEFAULT_FAIL_CODE,"指令转发失败请联系管理员");
  260 + }
  261 + return new Message(MessageCode.DEFAULT_FAIL_CODE,"指令执行失败请稍后重试");
  262 + }
  263 +
  264 +}
  1 +package com.zhonglai.luhui.central.control;
  2 +
  3 +public interface DeviceDBOperationService {
  4 + int deleteIotDeviceByClient_id(String imei);
  5 + int deleteIotTerminalByDeviceId(String imei);
  6 + int deleteIotTerminalById(String id);
  7 +}
1 -package com.zhonglai.luhui.central.control;  
2 -  
3 -public class LhCentralControlApplication {  
4 -}  
1 -package com.zhonglai.luhui.central.control.comm;  
2 -  
3 -  
4 -public class Message {  
5 - private int code;  
6 - private String message;  
7 - private Object data;  
8 -  
9 - public Message() {  
10 - }  
11 -  
12 - public Message(MessageCodeType code, String message, Object data) {  
13 - this.code = code.getCode();  
14 - this.message = message;  
15 - if (null == message || "".equals(message)) {  
16 - this.message = code.getMessage();  
17 - }  
18 -  
19 - this.data = data;  
20 - }  
21 -  
22 - public Message(MessageCodeType code, Object data) {  
23 - this.code = code.getCode();  
24 - this.message = code.getMessage();  
25 - this.data = data;  
26 - }  
27 -  
28 - public Message(MessageCodeType code, String message) {  
29 - this.code = code.getCode();  
30 - this.message = message;  
31 - this.data = null;  
32 - }  
33 -  
34 - public Message(MessageCodeType code) {  
35 - this.code = code.getCode();  
36 - this.message = code.getMessage();  
37 - }  
38 -  
39 - public void setCode(MessageCode messageCode )  
40 - {  
41 - code = messageCode.code;  
42 - }  
43 -  
44 - public void setCode(MessageCodeType code) {  
45 - this.code = code.getCode();  
46 - }  
47 -  
48 - public int getCode() {  
49 - return code;  
50 - }  
51 -  
52 - public void setCode(int code) {  
53 - this.code = code;  
54 - }  
55 -  
56 - public String getMessage() {  
57 - return message;  
58 - }  
59 -  
60 - public void setMessage(String message) {  
61 - this.message = message;  
62 - }  
63 -  
64 - public Object getData() {  
65 - return data;  
66 - }  
67 -  
68 - public void setData(Object data) {  
69 - this.data = data;  
70 - }  
71 -}  
1 -package com.zhonglai.luhui.central.control.comm;  
2 -  
3 -public enum MessageCode implements MessageCodeType{  
4 - DEFAULT_FAIL_CODE(0, "请求失败"),  
5 - DEFAULT_SUCCESS_CODE(1, "请求成功"),  
6 - SESSION_TIME_OUT(2, "会话超时,请刷新令牌"),  
7 - USER_INVALID(4, "用户失效,请重新登录"),  
8 - SYS_ERROR(3, "已知系统错误"),  
9 - REQUEST_METHOD_ERROR(6, "请求方式错误"),  
10 - REQUEST_PATH_ERROR(7, "请求路径错误"),  
11 - UNKNOWN_SYS_ERROR(5, "未知系统错误");  
12 -  
13 - public int code;  
14 - public String message;  
15 -  
16 - public int getCode() {  
17 - return this.code;  
18 - }  
19 -  
20 - public String getMessage() {  
21 - return this.message;  
22 - }  
23 -  
24 - private MessageCode(int code, String message) {  
25 - this.code = code;  
26 - this.message = message;  
27 - }  
28 -}  
1 -package com.zhonglai.luhui.central.control.comm;  
2 -  
3 -public interface MessageCodeType {  
4 - int getCode();  
5 -  
6 - String getMessage();  
7 -}  
1 -package com.zhonglai.luhui.central.control.comm;  
2 -  
3 -/**  
4 - * mqtt消息解析结果  
5 - */  
6 -public enum MqttAnalysisMessageResult {  
7 - /**  
8 - * 成功  
9 - */  
10 - Success,  
11 -  
12 - /**  
13 - * 失败  
14 - */  
15 - Fail,  
16 - /**  
17 - *topic异常  
18 - */  
19 - TopicException,  
20 -  
21 - /**  
22 - *设备不存在  
23 - */  
24 - DeviceDoesNotExist,  
25 -  
26 - /**  
27 - *payload解析异常  
28 - */  
29 - PayloadParsingException  
30 -}  
1 -package com.zhonglai.luhui.central.control.comm;  
2 -  
3 -  
4 -public class MyException extends RuntimeException{  
5 - private static final long serialVersionUID = 8827598182853467258L;  
6 - private Message errmge;  
7 -  
8 - public MyException(Message myMessage) {  
9 - super(myMessage.getMessage());  
10 - this.errmge = myMessage;  
11 - }  
12 -  
13 - public MyException(String message, Throwable cause) {  
14 - super(message, cause);  
15 - }  
16 - public MyException(String message) {  
17 - super(message);  
18 - }  
19 -  
20 -}  
1 -package com.zhonglai.luhui.central.control.comm;  
2 -  
3 -import org.slf4j.Logger;  
4 -import org.slf4j.LoggerFactory;  
5 -import org.springframework.beans.factory.annotation.Value;  
6 -import org.springframework.context.annotation.Configuration;  
7 -  
8 -import javax.annotation.PostConstruct;  
9 -  
10 -@Configuration  
11 -public class SysParameter {  
12 - private static Logger log = LoggerFactory.getLogger(SysParameter.class);  
13 -  
14 - public static String service_ip = ""; //服务所在地址  
15 -  
16 - @Value("${mqtt.topicconfig:/{{roleid}}/{{username}}/{{clientid}}/{{topicType}}/{{messageid}}}")  
17 - public String tempTopicconfig ; //topic 配置  
18 -  
19 - @Value("${mqtt.topics")  
20 - public String topics ; //topic  
21 -  
22 - public static String topicconfig ; //topic 配置  
23 -  
24 -  
25 - @PostConstruct  
26 - public void init() {  
27 - inittopicconfig();  
28 - }  
29 -  
30 - public void inittopicconfig()  
31 - {  
32 - topicconfig = tempTopicconfig;  
33 - }  
34 -  
35 -}  
1 -package com.zhonglai.luhui.central.control.comm;  
2 -  
3 -import org.apache.commons.lang3.StringUtils;  
4 -import org.slf4j.Logger;  
5 -import org.slf4j.LoggerFactory;  
6 -  
7 -import java.lang.reflect.Field;  
8 -import java.util.Optional;  
9 -  
10 -public class Topic {  
11 - private static final Logger log = LoggerFactory.getLogger(Topic.class);  
12 -  
13 - private String roleid;  
14 - private String username;  
15 - private String clientid;  
16 - private String topicType;  
17 - private String messageid;  
18 - private String payloadtype;  
19 -  
20 - public Topic() {  
21 - }  
22 -  
23 - public Topic(String roleid, String username, String clientid, String topicType, String payloadtype) {  
24 - this.roleid = roleid;  
25 - this.username = username;  
26 - this.clientid = clientid;  
27 - this.topicType = topicType;  
28 - this.payloadtype = payloadtype;  
29 - }  
30 -  
31 - public Topic(String roleid, String username, String clientid, String topicType, String messageid, String payloadtype) {  
32 - this.roleid = roleid;  
33 - this.username = username;  
34 - this.clientid = clientid;  
35 - this.topicType = topicType;  
36 - this.messageid = messageid;  
37 - this.payloadtype = payloadtype;  
38 - }  
39 -  
40 - public Topic(String topic)  
41 - {  
42 - topic = Optional.ofNullable(topic).orElseThrow(()->new MyException("topic为空"));  
43 - String[] sts = topic.split("/");  
44 - String[] config = SysParameter.topicconfig.split("/");  
45 - int number = sts.length;  
46 - if(number>config.length)  
47 - {  
48 - number = config.length;  
49 - }  
50 - for(int i=1;i<number;i++)  
51 - {  
52 - String cf = config[i].replace("{{","").replace("}}","");  
53 - try {  
54 - Field field = this.getClass().getDeclaredField(cf);  
55 - field.set(this,sts[i]);  
56 - } catch (NoSuchFieldException e) {  
57 - log.info("{}生成topic时没有属性{}",topic,cf);  
58 - } catch (IllegalAccessException e) {  
59 - log.info("{}生成topic时无法给{}赋值{}",topic,cf,sts[i]);  
60 - }  
61 - }  
62 -  
63 - if("ONLINE".equals(topicType.toUpperCase()))  
64 - {  
65 - this.payloadtype = "String";  
66 - }  
67 - }  
68 -  
69 - /**  
70 - * 生成缓存关键字  
71 - * @return  
72 - */  
73 - public String generateRedicKey()  
74 - {  
75 - return generate(":");  
76 - }  
77 -  
78 - /**  
79 - * 生成发送消息的topic  
80 - * @return  
81 - */  
82 - public String generateSendMessageTopic()  
83 - {  
84 - return "/"+generate("/");  
85 - }  
86 -  
87 - /**  
88 - * 生成客户端关键字  
89 - * @return  
90 - */  
91 - public String generateClienKey()  
92 - {  
93 - return "/"+generate("/");  
94 - }  
95 -  
96 - private String generate(String division)  
97 - {  
98 - String str = SysParameter.topicconfig;  
99 - if(StringUtils.isEmpty(roleid))  
100 - {  
101 - roleid = "2";  
102 - }  
103 - str = str.replace("/{{roleid}}",roleid+division);  
104 -  
105 - if(StringUtils.isEmpty(username))  
106 - {  
107 - username = "+";  
108 - }  
109 - str = str.replace("/{{username}}",username+division);  
110 -  
111 - if(StringUtils.isEmpty(clientid))  
112 - {  
113 - clientid = "+";  
114 - }  
115 - str = str.replace("/{{clientid}}",clientid+division);  
116 -  
117 - if(StringUtils.isEmpty(payloadtype))  
118 - {  
119 - payloadtype = "String";  
120 - }  
121 - str = str.replace("/{{payloadtype}}",payloadtype+division);  
122 -  
123 - if(StringUtils.isEmpty(topicType))  
124 - {  
125 - topicType = "PUT";  
126 - }  
127 - str = str.replace("/{{topicType}}",topicType+division);  
128 -  
129 - if(StringUtils.isNotEmpty(messageid))  
130 - {  
131 - str = str.replace("/{{messageid}}",messageid);  
132 - }  
133 -  
134 - return str;  
135 - }  
136 -  
137 - public String getRoleid() {  
138 - return roleid;  
139 - }  
140 -  
141 - public void setRoleid(String roleid) {  
142 - this.roleid = roleid;  
143 - }  
144 -  
145 - public String getUsername() {  
146 - return username;  
147 - }  
148 -  
149 - public void setUsername(String username) {  
150 - this.username = username;  
151 - }  
152 -  
153 - public String getClientid() {  
154 - return clientid;  
155 - }  
156 -  
157 - public void setClientid(String clientid) {  
158 - this.clientid = clientid;  
159 - }  
160 -  
161 - public String getTopicType() {  
162 - return topicType;  
163 - }  
164 -  
165 - public void setTopicType(String topicType) {  
166 - this.topicType = topicType;  
167 - }  
168 -  
169 - public String getMessageid() {  
170 - return messageid;  
171 - }  
172 -  
173 - public void setMessageid(String messageid) {  
174 - this.messageid = messageid;  
175 - }  
176 -  
177 - public String getPayloadtype() {  
178 - return payloadtype;  
179 - }  
180 -  
181 - public void setPayloadtype(String payloadtype) {  
182 - this.payloadtype = payloadtype;  
183 - }  
184 -}  
1 -package com.zhonglai.luhui.central.control.config;  
2 -  
3 -import org.springframework.beans.factory.annotation.Value;  
4 -import org.springframework.stereotype.Component;  
5 -  
6 -@Component  
7 -public class MqttConfig {  
8 - @Value("${mqtt.broker}")  
9 - private String broker;  
10 - @Value("${mqtt.clientId}")  
11 - private String clientId;  
12 - @Value("${mqtt.topics}")  
13 - private String topics;  
14 - @Value("${mqtt.username}")  
15 - private String username;  
16 - @Value("${mqtt.password}")  
17 - private String password;  
18 -  
19 - public String getBroker() {  
20 - return broker;  
21 - }  
22 -  
23 - public void setBroker(String broker) {  
24 - this.broker = broker;  
25 - }  
26 -  
27 - public String getClientId() {  
28 - return clientId;  
29 - }  
30 -  
31 - public void setClientId(String clientId) {  
32 - this.clientId = clientId;  
33 - }  
34 -  
35 - public String getTopics() {  
36 - return topics;  
37 - }  
38 -  
39 - public void setTopics(String topics) {  
40 - this.topics = topics;  
41 - }  
42 -  
43 - public String getUsername() {  
44 - return username;  
45 - }  
46 -  
47 - public void setUsername(String username) {  
48 - this.username = username;  
49 - }  
50 -  
51 - public String getPassword() {  
52 - return password;  
53 - }  
54 -  
55 - public void setPassword(String password) {  
56 - this.password = password;  
57 - }  
58 -}  
1 -package com.zhonglai.luhui.central.control.service;  
2 -  
3 -import com.ruoyi.system.domain.IotDevice;  
4 -  
5 -public interface DeviceService {  
6 - IotDevice getDeviceById(String clientId);  
7 -}  
1 -package com.zhonglai.luhui.central.control.service;  
2 -  
3 -import com.zhonglai.luhui.central.control.config.MqttConfig;  
4 -import com.zhonglai.luhui.central.control.util.ByteUtil;  
5 -import org.eclipse.paho.client.mqttv3.*;  
6 -import org.eclipse.paho.client.mqttv3.persist.MemoryPersistence;  
7 -import org.slf4j.Logger;  
8 -import org.slf4j.LoggerFactory;  
9 -import org.springframework.beans.factory.annotation.Autowired;  
10 -import org.springframework.stereotype.Service;  
11 -  
12 -import javax.annotation.PostConstruct;  
13 -  
14 -@Service  
15 -public class MqttClientService {  
16 - private Logger log = LoggerFactory.getLogger(MqttClientService.class);  
17 -  
18 - @Autowired  
19 - private MqttConfig mqttConfig;  
20 -  
21 - @Autowired  
22 - private MqttMessageArrivedService mqttMessageArrivedService;  
23 -  
24 - @Autowired  
25 - private MqttOperation mqttOperation;  
26 -  
27 - private MqttClient mqttclient;  
28 -  
29 - private MqttConnectOptions options;  
30 -  
31 - {  
32 - if(null == mqttclient)  
33 - {  
34 - try {  
35 - mqttclient = new MqttClient(mqttConfig.getBroker(), mqttConfig.getClientId(), new MemoryPersistence());  
36 - } catch (MqttException e) {  
37 - e.printStackTrace();  
38 - }  
39 - options = new MqttConnectOptions();  
40 - options.setCleanSession(true);  
41 - options.setConnectionTimeout(15);  
42 - //设置断开后重新连接  
43 - options.setAutomaticReconnect(true);  
44 - mqttclient.setCallback(new MqttCallbackExtended() {  
45 - @Override  
46 - public void connectComplete(boolean b, String s) {  
47 - log.info("连接成功");  
48 - try {  
49 - subscribe();  
50 - } catch (MqttException e) {  
51 - e.printStackTrace();  
52 - }  
53 - }  
54 -  
55 - @Override  
56 - public void connectionLost(Throwable cause) {  
57 - log.error("连接丢失",cause);  
58 - }  
59 -  
60 - @Override  
61 - public void messageArrived(String topic, MqttMessage message) {  
62 - log.info("接收到消息topc:{}, mqttMessage {},payload 十六进制 {}",topic,message, ByteUtil.hexStringToSpace(ByteUtil.toHexString(message.getPayload())));  
63 - mqttMessageArrivedService.analysisMessage(topic,message);  
64 - }  
65 -  
66 - @Override  
67 - public void deliveryComplete(IMqttDeliveryToken token) {  
68 - try {  
69 - log.info("成功发出消息 messageid{}",token.getMessage());  
70 - } catch (MqttException e) {  
71 - e.printStackTrace();  
72 - }  
73 - }  
74 - });  
75 - }  
76 -  
77 - }  
78 -  
79 - @PostConstruct  
80 - public void init() throws MqttException {  
81 - log.info("-----------终端数据模型配置成功--------------------");  
82 - connect();  
83 - log.info("-----------mqtt连接服务器成功--------------------");  
84 - subscribe();  
85 - log.info("-----------订阅{}成功--------------------",mqttConfig.getTopics());  
86 - }  
87 -  
88 - private void connect() throws MqttException {  
89 - options.setUserName(mqttConfig.getUsername());  
90 - options.setPassword(mqttConfig.getPassword().toCharArray());  
91 - mqttclient.connect(options);  
92 - }  
93 -  
94 - private void subscribe() throws MqttException {  
95 - mqttOperation.subscribe(mqttclient,mqttConfig.getTopics().split(","));  
96 - }  
97 -  
98 -}  
1 -package com.zhonglai.luhui.central.control.service;  
2 -  
3 -import com.ruoyi.system.domain.IotDevice;  
4 -import com.zhonglai.luhui.central.control.comm.MqttAnalysisMessageResult;  
5 -import com.zhonglai.luhui.central.control.comm.Topic;  
6 -import org.eclipse.paho.client.mqttv3.MqttMessage;  
7 -import org.slf4j.Logger;  
8 -import org.slf4j.LoggerFactory;  
9 -import org.springframework.beans.factory.annotation.Autowired;  
10 -import org.springframework.stereotype.Service;  
11 -  
12 -/**  
13 - * 数据解析业务  
14 - */  
15 -@Service  
16 -public class MqttMessageArrivedService {  
17 - @Autowired  
18 - private DeviceService deviceService ;  
19 -  
20 - private Logger log = LoggerFactory.getLogger(MqttMessageArrivedService.class);  
21 -  
22 - public MqttAnalysisMessageResult analysisMessage(String topicStr, MqttMessage message)  
23 - {  
24 - Topic topic = new Topic(topicStr);  
25 - if(null == topic)  
26 - {  
27 - log.error("消息{},解析出来的topic为空,不做解析",topicStr);  
28 - return MqttAnalysisMessageResult.TopicException;  
29 - }  
30 -  
31 - IotDevice iotDevice = deviceService.getDeviceById(topic.getClientid());  
32 - if(null == iotDevice)  
33 - {  
34 - log.info("设备{}不存在",topic.getClientid());  
35 - return MqttAnalysisMessageResult.DeviceDoesNotExist;  
36 - }  
37 -  
38 - //消息分发  
39 - try {  
40 -// messageDistribution();  
41 - }catch (Exception e)  
42 - {  
43 - log.info("消息解析异常",e);  
44 - return MqttAnalysisMessageResult.PayloadParsingException;  
45 - }  
46 -  
47 - return MqttAnalysisMessageResult.Success;  
48 - }  
49 -  
50 -}  
1 -package com.zhonglai.luhui.central.control.service;  
2 -  
3 -import org.eclipse.paho.client.mqttv3.MqttClient;  
4 -import org.eclipse.paho.client.mqttv3.MqttException;  
5 -import org.eclipse.paho.client.mqttv3.MqttMessage;  
6 -import org.springframework.stereotype.Service;  
7 -  
8 -import java.nio.ByteBuffer;  
9 -import java.nio.charset.Charset;  
10 -  
11 -@Service  
12 -public class MqttOperation {  
13 - public void subscribe(MqttClient mqttclient,String[] topicFilters) throws MqttException {  
14 - mqttclient.subscribe(topicFilters);  
15 - }  
16 -  
17 - public void publish(MqttClient mqttclient,String topic, MqttMessage message) throws MqttException {  
18 - mqttclient.publish(topic,message);  
19 - }  
20 -  
21 - public void publish(MqttClient mqttclient,String topic, String messageStr) throws MqttException {  
22 - MqttMessage message = new MqttMessage();  
23 - message.setPayload(messageStr.getBytes());  
24 - mqttclient.publish(topic,message);  
25 - }  
26 -  
27 - public void closeClient (MqttClient mqttclient,String clientId,String code,String messageStr) throws MqttException {  
28 - String topic = "SYSOPERATION/CLOSE";  
29 - MqttMessage message = new MqttMessage();  
30 - Charset charset = Charset.forName("utf-8");  
31 - ByteBuffer payload = charset.encode(clientId+","+code+","+messageStr);  
32 - message.setPayload(payload.array());  
33 - mqttclient.publish(topic,message);  
34 - }  
35 -}  
1 -package com.zhonglai.luhui.central.control.util;  
2 -  
3 -import java.util.Arrays;  
4 -  
5 -public class ByteUtil {  
6 - /**  
7 - * byte数组中取int数值,本方法适用于(低位在前,高位在后)的顺序,和和intToBytes()配套使用  
8 - *  
9 - * @param src  
10 - * byte数组  
11 - * @param offset  
12 - * 从数组的第offset位开始  
13 - * @return int数值  
14 - */  
15 - public static long bytesToLongASC(byte[] src, int offset,int lenth) {  
16 - int value = 0;  
17 - for(int i=0;i<lenth;i++)  
18 - {  
19 - value = value | ((src[offset+i] & 0xFF)<<(8*i));  
20 - }  
21 - return value;  
22 - }  
23 -  
24 - /**  
25 - * 把16进制字符串转换成字节数组  
26 - *  
27 - * @param hex  
28 - * @return  
29 - */  
30 - public static byte[] hexStringToByte(String hex) {  
31 - int len = (hex.length() / 2);  
32 - byte[] result = new byte[len];  
33 - char[] achar = hex.toCharArray();  
34 - for (int i = 0; i < len; i++) {  
35 - int pos = i * 2;  
36 - result[i] = (byte) (toByte(achar[pos]) << 4 | toByte(achar[pos + 1]));  
37 - }  
38 - return result;  
39 - }  
40 - private static byte toByte(char c) {  
41 - byte b = (byte) "0123456789ABCDEF".indexOf(c);  
42 - return b;  
43 - }  
44 -  
45 - /**  
46 - * 把16进制字符串转换成字节数组  
47 - *  
48 - * @param hex  
49 - * @return  
50 - */  
51 - public static String hexStringToSpace(String hex) {  
52 - if (null == hex) {  
53 - return null;  
54 - } else {  
55 - StringBuilder sb = new StringBuilder(hex.length() << 1);  
56 -  
57 - for(int i = 0; i < hex.length(); i+=2) {  
58 - sb.append(hex.substring(i,i+2)).append(" ");  
59 - }  
60 - return sb.toString();  
61 - }  
62 - }  
63 -  
64 - /**  
65 - * 把原数组加点目标数组后面  
66 - * @param dest 目标数组  
67 - * @param src 原数组  
68 - * @return  
69 - */  
70 - public static byte[] addBytes(byte[] dest,byte[] src )  
71 - {  
72 - int dl = dest.length;  
73 - int sl = src.length;  
74 - dest = Arrays.copyOf(dest, dl+sl);//数组扩容  
75 - System.arraycopy(src,0,dest,dl,src.length);  
76 - return dest;  
77 - }  
78 -  
79 - /**  
80 - * 将int数值转换为占四个字节的byte数组,本方法适用于(高位在前,低位在后)的顺序。 和bytesToInt2()配套使用  
81 - */  
82 - public static byte[] intToBytesDESC(long value,int lenth)  
83 - {  
84 - byte[] src = new byte[lenth];  
85 - for(int i=0;i<lenth;i++)  
86 - {  
87 - src[i] = (byte) ((value>>(8*(lenth-i-1))) & 0xFF);  
88 - }  
89 - return src;  
90 - }  
91 -  
92 - /**  
93 - * 将int数值转换为占四个字节的byte数组,本方法适用于(低位在前,高位在后)的顺序。 和bytesToInt()配套使用  
94 - * @param value  
95 - * 要转换的int值  
96 - * @return byte数组  
97 - */  
98 - public static byte[] intToBytesASC( long value,int lenth)  
99 - {  
100 - byte[] src = new byte[lenth];  
101 - for(int i=lenth;i>0;i--)  
102 - {  
103 - src[i-1] = (byte) ((value>>(8*(i-1))) & 0xFF);  
104 - }  
105 - return src;  
106 - }  
107 -  
108 - public static void main(String[] args) {  
109 - System.out.println(ByteUtil.toHexString( ByteUtil.intToBytesASC(2011239256,4)));  
110 - }  
111 -  
112 - /**  
113 - * ip转化位4byte  
114 - * @param ip  
115 - * @return  
116 - */  
117 - public static byte[] ipTo4Byte(String ip)  
118 - {  
119 - String[] ips = ip.split(".");  
120 - return new byte[]{(byte) Integer.parseInt(ips[0]),(byte) Integer.parseInt(ips[1]),(byte) Integer.parseInt(ips[2]),(byte) Integer.parseInt(ips[3])};  
121 - }  
122 -  
123 - /**  
124 - * byte数组中取int数值,本方法适用于(低位在后,高位在前)的顺序。和intToBytes2()配套使用  
125 - */  
126 - public static long bytesToLongDESC(byte[] src, int offset,int lenth) {  
127 - long value = 0;  
128 - for(int i=lenth;i>0;i--)  
129 - {  
130 - value = value | ((src[offset+(lenth-i)] & 0xFF)<<(8*(i-1)));  
131 - }  
132 - return value;  
133 - }  
134 -  
135 - private static final char[] hex = "0123456789abcdef".toCharArray();  
136 - public static String toHexString(byte[] bytes) {  
137 - if (null == bytes) {  
138 - return null;  
139 - } else {  
140 - StringBuilder sb = new StringBuilder(bytes.length << 1);  
141 -  
142 - for(int i = 0; i < bytes.length; ++i) {  
143 - sb.append(hex[(bytes[i] & 240) >> 4]).append(hex[bytes[i] & 15]);  
144 - }  
145 -  
146 - return sb.toString();  
147 - }  
148 - }  
149 -  
150 - /**  
151 - * 计算CRC16/Modbus校验码 低位在前,高位在后  
152 - *  
153 - * @param str 十六进制字符串  
154 - * @return  
155 - */  
156 - public static String getCRC16(String str) {  
157 - byte[] bytes = hexStringToByte(str);  
158 - return getCRC16(bytes);  
159 - }  
160 -  
161 - /**  
162 - * 计算CRC16/Modbus校验码 低位在前,高位在后  
163 - *  
164 - * @return  
165 - */  
166 - public static String getCRC16( byte[] bytes) {  
167 - int CRC = 0x0000ffff;  
168 - int POLYNOMIAL = 0x0000a001;  
169 -  
170 - int i, j;  
171 - for (i = 0; i < bytes.length; i++) {  
172 - CRC ^= ((int) bytes[i] & 0x000000ff);  
173 - for (j = 0; j < 8; j++) {  
174 - if ((CRC & 0x00000001) != 0) {  
175 - CRC >>= 1;  
176 - CRC ^= POLYNOMIAL;  
177 - } else {  
178 - CRC >>= 1;  
179 - }  
180 - }  
181 - }  
182 - String crc = Integer.toHexString(CRC);  
183 - if (crc.length() == 2) {  
184 - crc = "00" + crc;  
185 - } else if (crc.length() == 3) {  
186 - crc = "0" + crc;  
187 - }  
188 - crc = crc.substring(2, 4) + crc.substring(0, 2);  
189 - return crc.toUpperCase();  
190 - }  
191 -}  
  1 +package com.ruoyi.system.domain;
  2 +
  3 +import com.ruoyi.system.domain.tool.BaseEntity;
  4 +import io.swagger.annotations.ApiModel;
  5 +import io.swagger.annotations.ApiModelProperty;
  6 +import org.apache.commons.lang3.builder.ToStringBuilder;
  7 +import org.apache.commons.lang3.builder.ToStringStyle;
  8 +
  9 +/**
  10 + * 终端分组对象 user_terminal_group
  11 + *
  12 + * @author 钟来
  13 + * @date 2022-11-22
  14 + */
  15 +@ApiModel("终端分组")
  16 +public class UserTerminalGroup extends BaseEntity
  17 +{
  18 + private static final long serialVersionUID = 1L;
  19 +
  20 + /** 创建时间 */
  21 + @ApiModelProperty("创建时间")
  22 + private Integer create_time;
  23 +
  24 + /** 主键 */
  25 + @ApiModelProperty("主键")
  26 + private Integer id;
  27 +
  28 + /** 名称 */
  29 + @ApiModelProperty("名称")
  30 + private String name;
  31 +
  32 + /** 关联用户id */
  33 + @ApiModelProperty("关联用户id")
  34 + private Integer user_info_id;
  35 +
  36 + public void setCreate_time(Integer create_time)
  37 + {
  38 + this.create_time = create_time;
  39 + }
  40 +
  41 + public Integer getCreate_time()
  42 + {
  43 + return create_time;
  44 + }
  45 + public void setId(Integer id)
  46 + {
  47 + this.id = id;
  48 + }
  49 +
  50 + public Integer getId()
  51 + {
  52 + return id;
  53 + }
  54 + public void setName(String name)
  55 + {
  56 + this.name = name;
  57 + }
  58 +
  59 + public String getName()
  60 + {
  61 + return name;
  62 + }
  63 + public void setUser_info_id(Integer user_info_id)
  64 + {
  65 + this.user_info_id = user_info_id;
  66 + }
  67 +
  68 + public Integer getUser_info_id()
  69 + {
  70 + return user_info_id;
  71 + }
  72 +
  73 + @Override
  74 + public String toString() {
  75 + return new ToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE)
  76 + .append("create_time", getCreate_time())
  77 + .append("id", getId())
  78 + .append("name", getName())
  79 + .append("user_info_id", getUser_info_id())
  80 + .toString();
  81 + }
  82 +}
  1 +package com.ruoyi.system.domain;
  2 +
  3 +import com.ruoyi.system.domain.tool.BaseEntity;
  4 +import io.swagger.annotations.ApiModel;
  5 +import io.swagger.annotations.ApiModelProperty;
  6 +import org.apache.commons.lang3.builder.ToStringBuilder;
  7 +import org.apache.commons.lang3.builder.ToStringStyle;
  8 +
  9 +/**
  10 + * 终端分组关系对象 user_terminal_group_relation
  11 + *
  12 + * @author 钟来
  13 + * @date 2022-11-22
  14 + */
  15 +@ApiModel("终端分组关系")
  16 +public class UserTerminalGroupRelation extends BaseEntity
  17 +{
  18 + private static final long serialVersionUID = 1L;
  19 +
  20 + /** 创建时间 */
  21 + @ApiModelProperty("创建时间")
  22 + private Integer create_time;
  23 +
  24 + /** 主键 */
  25 + @ApiModelProperty("主键")
  26 + private Integer id;
  27 +
  28 + /** 分组id */
  29 + @ApiModelProperty("分组id")
  30 + private Integer iot_terminal_group_id;
  31 +
  32 + /** 分组名称 */
  33 + @ApiModelProperty("分组名称")
  34 + private String iot_terminal_group_name;
  35 +
  36 + /** 终端id */
  37 + @ApiModelProperty("终端id")
  38 + private String iot_terminal_id;
  39 +
  40 + /** 关联用户 */
  41 + @ApiModelProperty("关联用户")
  42 + private Integer user_info_id;
  43 +
  44 + public void setCreate_time(Integer create_time)
  45 + {
  46 + this.create_time = create_time;
  47 + }
  48 +
  49 + public Integer getCreate_time()
  50 + {
  51 + return create_time;
  52 + }
  53 + public void setId(Integer id)
  54 + {
  55 + this.id = id;
  56 + }
  57 +
  58 + public Integer getId()
  59 + {
  60 + return id;
  61 + }
  62 + public void setIot_terminal_group_id(Integer iot_terminal_group_id)
  63 + {
  64 + this.iot_terminal_group_id = iot_terminal_group_id;
  65 + }
  66 +
  67 + public Integer getIot_terminal_group_id()
  68 + {
  69 + return iot_terminal_group_id;
  70 + }
  71 + public void setIot_terminal_group_name(String iot_terminal_group_name)
  72 + {
  73 + this.iot_terminal_group_name = iot_terminal_group_name;
  74 + }
  75 +
  76 + public String getIot_terminal_group_name()
  77 + {
  78 + return iot_terminal_group_name;
  79 + }
  80 + public void setIot_terminal_id(String iot_terminal_id)
  81 + {
  82 + this.iot_terminal_id = iot_terminal_id;
  83 + }
  84 +
  85 + public String getIot_terminal_id()
  86 + {
  87 + return iot_terminal_id;
  88 + }
  89 + public void setUser_info_id(Integer user_info_id)
  90 + {
  91 + this.user_info_id = user_info_id;
  92 + }
  93 +
  94 + public Integer getUser_info_id()
  95 + {
  96 + return user_info_id;
  97 + }
  98 +
  99 + @Override
  100 + public String toString() {
  101 + return new ToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE)
  102 + .append("create_time", getCreate_time())
  103 + .append("id", getId())
  104 + .append("iot_terminal_group_id", getIot_terminal_group_id())
  105 + .append("iot_terminal_group_name", getIot_terminal_group_name())
  106 + .append("iot_terminal_id", getIot_terminal_id())
  107 + .append("user_info_id", getUser_info_id())
  108 + .toString();
  109 + }
  110 +}
@@ -41,6 +41,9 @@ public class TokenService @@ -41,6 +41,9 @@ public class TokenService
41 @Value("${token.expireTime}") 41 @Value("${token.expireTime}")
42 private int expireTime; 42 private int expireTime;
43 43
  44 + @Value("${token.rediskey}")
  45 + private int rediskey;
  46 +
44 protected static final long MILLIS_SECOND = 1000; 47 protected static final long MILLIS_SECOND = 1000;
45 48
46 protected static final long MILLIS_MINUTE = 60 * MILLIS_SECOND; 49 protected static final long MILLIS_MINUTE = 60 * MILLIS_SECOND;
@@ -221,6 +224,6 @@ public class TokenService @@ -221,6 +224,6 @@ public class TokenService
221 224
222 private String getTokenKey(String uuid) 225 private String getTokenKey(String uuid)
223 { 226 {
224 - return Constants.LOGIN_TOKEN_KEY + uuid; 227 + return Constants.LOGIN_TOKEN_KEY+rediskey+":" + uuid;
225 } 228 }
226 } 229 }
  1 +package com.ruoyi.system.mapper;
  2 +
  3 +import java.util.List;
  4 +import com.ruoyi.system.domain.UserTerminalGroup;
  5 +
  6 +/**
  7 + * 终端分组Mapper接口
  8 + *
  9 + * @author 钟来
  10 + * @date 2022-11-22
  11 + */
  12 +public interface UserTerminalGroupMapper
  13 +{
  14 + /**
  15 + * 查询终端分组
  16 + *
  17 + * @param id 终端分组主键
  18 + * @return 终端分组
  19 + */
  20 + public UserTerminalGroup selectUserTerminalGroupById(Integer id);
  21 +
  22 + /**
  23 + * 查询终端分组列表
  24 + *
  25 + * @param userTerminalGroup 终端分组
  26 + * @return 终端分组集合
  27 + */
  28 + public List<UserTerminalGroup> selectUserTerminalGroupList(UserTerminalGroup userTerminalGroup);
  29 +
  30 + /**
  31 + * 新增终端分组
  32 + *
  33 + * @param userTerminalGroup 终端分组
  34 + * @return 结果
  35 + */
  36 + public int insertUserTerminalGroup(UserTerminalGroup userTerminalGroup);
  37 +
  38 + /**
  39 + * 修改终端分组
  40 + *
  41 + * @param userTerminalGroup 终端分组
  42 + * @return 结果
  43 + */
  44 + public int updateUserTerminalGroup(UserTerminalGroup userTerminalGroup);
  45 +
  46 + /**
  47 + * 删除终端分组
  48 + *
  49 + * @param id 终端分组主键
  50 + * @return 结果
  51 + */
  52 + public int deleteUserTerminalGroupById(Integer id);
  53 +
  54 + /**
  55 + * 批量删除终端分组
  56 + *
  57 + * @param ids 需要删除的数据主键集合
  58 + * @return 结果
  59 + */
  60 + public int deleteUserTerminalGroupByIds(Integer[] ids);
  61 +}
  1 +package com.ruoyi.system.mapper;
  2 +
  3 +import java.util.List;
  4 +import com.ruoyi.system.domain.UserTerminalGroupRelation;
  5 +
  6 +/**
  7 + * 终端分组关系Mapper接口
  8 + *
  9 + * @author 钟来
  10 + * @date 2022-11-22
  11 + */
  12 +public interface UserTerminalGroupRelationMapper
  13 +{
  14 + /**
  15 + * 查询终端分组关系
  16 + *
  17 + * @param id 终端分组关系主键
  18 + * @return 终端分组关系
  19 + */
  20 + public UserTerminalGroupRelation selectUserTerminalGroupRelationById(Integer id);
  21 +
  22 + /**
  23 + * 查询终端分组关系列表
  24 + *
  25 + * @param userTerminalGroupRelation 终端分组关系
  26 + * @return 终端分组关系集合
  27 + */
  28 + public List<UserTerminalGroupRelation> selectUserTerminalGroupRelationList(UserTerminalGroupRelation userTerminalGroupRelation);
  29 +
  30 + /**
  31 + * 新增终端分组关系
  32 + *
  33 + * @param userTerminalGroupRelation 终端分组关系
  34 + * @return 结果
  35 + */
  36 + public int insertUserTerminalGroupRelation(UserTerminalGroupRelation userTerminalGroupRelation);
  37 +
  38 + /**
  39 + * 修改终端分组关系
  40 + *
  41 + * @param userTerminalGroupRelation 终端分组关系
  42 + * @return 结果
  43 + */
  44 + public int updateUserTerminalGroupRelation(UserTerminalGroupRelation userTerminalGroupRelation);
  45 +
  46 + /**
  47 + * 删除终端分组关系
  48 + *
  49 + * @param id 终端分组关系主键
  50 + * @return 结果
  51 + */
  52 + public int deleteUserTerminalGroupRelationById(Integer id);
  53 +
  54 + /**
  55 + * 批量删除终端分组关系
  56 + *
  57 + * @param ids 需要删除的数据主键集合
  58 + * @return 结果
  59 + */
  60 + public int deleteUserTerminalGroupRelationByIds(Integer[] ids);
  61 +}
  1 +package com.ruoyi.system.service;
  2 +
  3 +import java.util.List;
  4 +import com.ruoyi.system.domain.UserTerminalGroupRelation;
  5 +
  6 +/**
  7 + * 终端分组关系Service接口
  8 + *
  9 + * @author 钟来
  10 + * @date 2022-11-22
  11 + */
  12 +public interface IUserTerminalGroupRelationService
  13 +{
  14 + /**
  15 + * 查询终端分组关系
  16 + *
  17 + * @param id 终端分组关系主键
  18 + * @return 终端分组关系
  19 + */
  20 + public UserTerminalGroupRelation selectUserTerminalGroupRelationById(Integer id);
  21 +
  22 + /**
  23 + * 查询终端分组关系列表
  24 + *
  25 + * @param userTerminalGroupRelation 终端分组关系
  26 + * @return 终端分组关系集合
  27 + */
  28 + public List<UserTerminalGroupRelation> selectUserTerminalGroupRelationList(UserTerminalGroupRelation userTerminalGroupRelation);
  29 +
  30 + /**
  31 + * 新增终端分组关系
  32 + *
  33 + * @param userTerminalGroupRelation 终端分组关系
  34 + * @return 结果
  35 + */
  36 + public int insertUserTerminalGroupRelation(UserTerminalGroupRelation userTerminalGroupRelation);
  37 +
  38 + /**
  39 + * 修改终端分组关系
  40 + *
  41 + * @param userTerminalGroupRelation 终端分组关系
  42 + * @return 结果
  43 + */
  44 + public int updateUserTerminalGroupRelation(UserTerminalGroupRelation userTerminalGroupRelation);
  45 +
  46 + /**
  47 + * 批量删除终端分组关系
  48 + *
  49 + * @param ids 需要删除的终端分组关系主键集合
  50 + * @return 结果
  51 + */
  52 + public int deleteUserTerminalGroupRelationByIds(Integer[] ids);
  53 +
  54 + /**
  55 + * 删除终端分组关系信息
  56 + *
  57 + * @param id 终端分组关系主键
  58 + * @return 结果
  59 + */
  60 + public int deleteUserTerminalGroupRelationById(Integer id);
  61 +}
  1 +package com.ruoyi.system.service;
  2 +
  3 +import java.util.List;
  4 +import com.ruoyi.system.domain.UserTerminalGroup;
  5 +
  6 +/**
  7 + * 终端分组Service接口
  8 + *
  9 + * @author 钟来
  10 + * @date 2022-11-22
  11 + */
  12 +public interface IUserTerminalGroupService
  13 +{
  14 + /**
  15 + * 查询终端分组
  16 + *
  17 + * @param id 终端分组主键
  18 + * @return 终端分组
  19 + */
  20 + public UserTerminalGroup selectUserTerminalGroupById(Integer id);
  21 +
  22 + /**
  23 + * 查询终端分组列表
  24 + *
  25 + * @param userTerminalGroup 终端分组
  26 + * @return 终端分组集合
  27 + */
  28 + public List<UserTerminalGroup> selectUserTerminalGroupList(UserTerminalGroup userTerminalGroup);
  29 +
  30 + /**
  31 + * 新增终端分组
  32 + *
  33 + * @param userTerminalGroup 终端分组
  34 + * @return 结果
  35 + */
  36 + public int insertUserTerminalGroup(UserTerminalGroup userTerminalGroup);
  37 +
  38 + /**
  39 + * 修改终端分组
  40 + *
  41 + * @param userTerminalGroup 终端分组
  42 + * @return 结果
  43 + */
  44 + public int updateUserTerminalGroup(UserTerminalGroup userTerminalGroup);
  45 +
  46 + /**
  47 + * 批量删除终端分组
  48 + *
  49 + * @param ids 需要删除的终端分组主键集合
  50 + * @return 结果
  51 + */
  52 + public int deleteUserTerminalGroupByIds(Integer[] ids);
  53 +
  54 + /**
  55 + * 删除终端分组信息
  56 + *
  57 + * @param id 终端分组主键
  58 + * @return 结果
  59 + */
  60 + public int deleteUserTerminalGroupById(Integer id);
  61 +}
  1 +package com.ruoyi.system.service.impl;
  2 +
  3 +import java.util.List;
  4 +import org.springframework.beans.factory.annotation.Autowired;
  5 +import org.springframework.stereotype.Service;
  6 +import com.ruoyi.system.mapper.UserTerminalGroupRelationMapper;
  7 +import com.ruoyi.system.domain.UserTerminalGroupRelation;
  8 +import com.ruoyi.system.service.IUserTerminalGroupRelationService;
  9 +
  10 +/**
  11 + * 终端分组关系Service业务层处理
  12 + *
  13 + * @author 钟来
  14 + * @date 2022-11-22
  15 + */
  16 +@Service
  17 +public class UserTerminalGroupRelationServiceImpl implements IUserTerminalGroupRelationService
  18 +{
  19 + @Autowired
  20 + private UserTerminalGroupRelationMapper userTerminalGroupRelationMapper;
  21 +
  22 + /**
  23 + * 查询终端分组关系
  24 + *
  25 + * @param id 终端分组关系主键
  26 + * @return 终端分组关系
  27 + */
  28 + @Override
  29 + public UserTerminalGroupRelation selectUserTerminalGroupRelationById(Integer id)
  30 + {
  31 + return userTerminalGroupRelationMapper.selectUserTerminalGroupRelationById(id);
  32 + }
  33 +
  34 + /**
  35 + * 查询终端分组关系列表
  36 + *
  37 + * @param userTerminalGroupRelation 终端分组关系
  38 + * @return 终端分组关系
  39 + */
  40 + @Override
  41 + public List<UserTerminalGroupRelation> selectUserTerminalGroupRelationList(UserTerminalGroupRelation userTerminalGroupRelation)
  42 + {
  43 + return userTerminalGroupRelationMapper.selectUserTerminalGroupRelationList(userTerminalGroupRelation);
  44 + }
  45 +
  46 + /**
  47 + * 新增终端分组关系
  48 + *
  49 + * @param userTerminalGroupRelation 终端分组关系
  50 + * @return 结果
  51 + */
  52 + @Override
  53 + public int insertUserTerminalGroupRelation(UserTerminalGroupRelation userTerminalGroupRelation)
  54 + {
  55 + return userTerminalGroupRelationMapper.insertUserTerminalGroupRelation(userTerminalGroupRelation);
  56 + }
  57 +
  58 + /**
  59 + * 修改终端分组关系
  60 + *
  61 + * @param userTerminalGroupRelation 终端分组关系
  62 + * @return 结果
  63 + */
  64 + @Override
  65 + public int updateUserTerminalGroupRelation(UserTerminalGroupRelation userTerminalGroupRelation)
  66 + {
  67 + return userTerminalGroupRelationMapper.updateUserTerminalGroupRelation(userTerminalGroupRelation);
  68 + }
  69 +
  70 + /**
  71 + * 批量删除终端分组关系
  72 + *
  73 + * @param ids 需要删除的终端分组关系主键
  74 + * @return 结果
  75 + */
  76 + @Override
  77 + public int deleteUserTerminalGroupRelationByIds(Integer[] ids)
  78 + {
  79 + return userTerminalGroupRelationMapper.deleteUserTerminalGroupRelationByIds(ids);
  80 + }
  81 +
  82 + /**
  83 + * 删除终端分组关系信息
  84 + *
  85 + * @param id 终端分组关系主键
  86 + * @return 结果
  87 + */
  88 + @Override
  89 + public int deleteUserTerminalGroupRelationById(Integer id)
  90 + {
  91 + return userTerminalGroupRelationMapper.deleteUserTerminalGroupRelationById(id);
  92 + }
  93 +}
  1 +package com.ruoyi.system.service.impl;
  2 +
  3 +import java.util.List;
  4 +import org.springframework.beans.factory.annotation.Autowired;
  5 +import org.springframework.stereotype.Service;
  6 +import com.ruoyi.system.mapper.UserTerminalGroupMapper;
  7 +import com.ruoyi.system.domain.UserTerminalGroup;
  8 +import com.ruoyi.system.service.IUserTerminalGroupService;
  9 +
  10 +/**
  11 + * 终端分组Service业务层处理
  12 + *
  13 + * @author 钟来
  14 + * @date 2022-11-22
  15 + */
  16 +@Service
  17 +public class UserTerminalGroupServiceImpl implements IUserTerminalGroupService
  18 +{
  19 + @Autowired
  20 + private UserTerminalGroupMapper userTerminalGroupMapper;
  21 +
  22 + /**
  23 + * 查询终端分组
  24 + *
  25 + * @param id 终端分组主键
  26 + * @return 终端分组
  27 + */
  28 + @Override
  29 + public UserTerminalGroup selectUserTerminalGroupById(Integer id)
  30 + {
  31 + return userTerminalGroupMapper.selectUserTerminalGroupById(id);
  32 + }
  33 +
  34 + /**
  35 + * 查询终端分组列表
  36 + *
  37 + * @param userTerminalGroup 终端分组
  38 + * @return 终端分组
  39 + */
  40 + @Override
  41 + public List<UserTerminalGroup> selectUserTerminalGroupList(UserTerminalGroup userTerminalGroup)
  42 + {
  43 + return userTerminalGroupMapper.selectUserTerminalGroupList(userTerminalGroup);
  44 + }
  45 +
  46 + /**
  47 + * 新增终端分组
  48 + *
  49 + * @param userTerminalGroup 终端分组
  50 + * @return 结果
  51 + */
  52 + @Override
  53 + public int insertUserTerminalGroup(UserTerminalGroup userTerminalGroup)
  54 + {
  55 + return userTerminalGroupMapper.insertUserTerminalGroup(userTerminalGroup);
  56 + }
  57 +
  58 + /**
  59 + * 修改终端分组
  60 + *
  61 + * @param userTerminalGroup 终端分组
  62 + * @return 结果
  63 + */
  64 + @Override
  65 + public int updateUserTerminalGroup(UserTerminalGroup userTerminalGroup)
  66 + {
  67 + return userTerminalGroupMapper.updateUserTerminalGroup(userTerminalGroup);
  68 + }
  69 +
  70 + /**
  71 + * 批量删除终端分组
  72 + *
  73 + * @param ids 需要删除的终端分组主键
  74 + * @return 结果
  75 + */
  76 + @Override
  77 + public int deleteUserTerminalGroupByIds(Integer[] ids)
  78 + {
  79 + return userTerminalGroupMapper.deleteUserTerminalGroupByIds(ids);
  80 + }
  81 +
  82 + /**
  83 + * 删除终端分组信息
  84 + *
  85 + * @param id 终端分组主键
  86 + * @return 结果
  87 + */
  88 + @Override
  89 + public int deleteUserTerminalGroupById(Integer id)
  90 + {
  91 + return userTerminalGroupMapper.deleteUserTerminalGroupById(id);
  92 + }
  93 +}
  1 +<?xml version="1.0" encoding="UTF-8" ?>
  2 +<!DOCTYPE mapper
  3 +PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
  4 +"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
  5 +<mapper namespace="com.ruoyi.system.mapper.UserTerminalGroupMapper">
  6 +
  7 + <resultMap type="UserTerminalGroup" id="UserTerminalGroupResult">
  8 + <result property="create_time" column="create_time" />
  9 + <result property="id" column="id" />
  10 + <result property="name" column="name" />
  11 + <result property="user_info_id" column="user_info_id" />
  12 + </resultMap>
  13 +
  14 + <sql id="selectUserTerminalGroupVo">
  15 + select `create_time`, `id`, `name`, `user_info_id` from user_terminal_group
  16 + </sql>
  17 +
  18 + <select id="selectUserTerminalGroupList" parameterType="UserTerminalGroup" resultMap="UserTerminalGroupResult">
  19 + <include refid="selectUserTerminalGroupVo"/>
  20 + <where>
  21 + </where>
  22 + </select>
  23 +
  24 + <select id="selectUserTerminalGroupById" parameterType="Integer" resultMap="UserTerminalGroupResult">
  25 + <include refid="selectUserTerminalGroupVo"/>
  26 + where id = #{id}
  27 + </select>
  28 +
  29 + <insert id="insertUserTerminalGroup" parameterType="UserTerminalGroup" useGeneratedKeys="true" keyProperty="id">
  30 + insert into user_terminal_group
  31 + <trim prefix="(" suffix=")" suffixOverrides=",">
  32 + <if test="create_time != null">create_time,</if>
  33 + <if test="name != null">name,</if>
  34 + <if test="user_info_id != null">user_info_id,</if>
  35 + </trim>
  36 + <trim prefix="values (" suffix=")" suffixOverrides=",">
  37 + <if test="create_time != null">#{create_time},</if>
  38 + <if test="name != null">#{name},</if>
  39 + <if test="user_info_id != null">#{user_info_id},</if>
  40 + </trim>
  41 + </insert>
  42 +
  43 + <update id="updateUserTerminalGroup" parameterType="UserTerminalGroup">
  44 + update user_terminal_group
  45 + <trim prefix="SET" suffixOverrides=",">
  46 + <if test="create_time != null">create_time = #{create_time},</if>
  47 + <if test="name != null">name = #{name},</if>
  48 + <if test="user_info_id != null">user_info_id = #{user_info_id},</if>
  49 + </trim>
  50 + where id = #{id}
  51 + </update>
  52 +
  53 + <delete id="deleteUserTerminalGroupById" parameterType="Integer">
  54 + delete from user_terminal_group where id = #{id}
  55 + </delete>
  56 +
  57 + <delete id="deleteUserTerminalGroupByIds" parameterType="String">
  58 + delete from user_terminal_group where id in
  59 + <foreach item="id" collection="array" open="(" separator="," close=")">
  60 + #{id}
  61 + </foreach>
  62 + </delete>
  63 +</mapper>
  1 +<?xml version="1.0" encoding="UTF-8" ?>
  2 +<!DOCTYPE mapper
  3 +PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
  4 +"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
  5 +<mapper namespace="com.ruoyi.system.mapper.UserTerminalGroupRelationMapper">
  6 +
  7 + <resultMap type="UserTerminalGroupRelation" id="UserTerminalGroupRelationResult">
  8 + <result property="create_time" column="create_time" />
  9 + <result property="id" column="id" />
  10 + <result property="iot_terminal_group_id" column="iot_terminal_group_id" />
  11 + <result property="iot_terminal_group_name" column="iot_terminal_group_name" />
  12 + <result property="iot_terminal_id" column="iot_terminal_id" />
  13 + <result property="user_info_id" column="user_info_id" />
  14 + </resultMap>
  15 +
  16 + <sql id="selectUserTerminalGroupRelationVo">
  17 + select `create_time`, `id`, `iot_terminal_group_id`, `iot_terminal_group_name`, `iot_terminal_id`, `user_info_id` from user_terminal_group_relation
  18 + </sql>
  19 +
  20 + <select id="selectUserTerminalGroupRelationList" parameterType="UserTerminalGroupRelation" resultMap="UserTerminalGroupRelationResult">
  21 + <include refid="selectUserTerminalGroupRelationVo"/>
  22 + <where>
  23 + </where>
  24 + </select>
  25 +
  26 + <select id="selectUserTerminalGroupRelationById" parameterType="Integer" resultMap="UserTerminalGroupRelationResult">
  27 + <include refid="selectUserTerminalGroupRelationVo"/>
  28 + where id = #{id}
  29 + </select>
  30 +
  31 + <insert id="insertUserTerminalGroupRelation" parameterType="UserTerminalGroupRelation" useGeneratedKeys="true" keyProperty="id">
  32 + insert into user_terminal_group_relation
  33 + <trim prefix="(" suffix=")" suffixOverrides=",">
  34 + <if test="create_time != null">create_time,</if>
  35 + <if test="iot_terminal_group_id != null">iot_terminal_group_id,</if>
  36 + <if test="iot_terminal_group_name != null">iot_terminal_group_name,</if>
  37 + <if test="iot_terminal_id != null">iot_terminal_id,</if>
  38 + <if test="user_info_id != null">user_info_id,</if>
  39 + </trim>
  40 + <trim prefix="values (" suffix=")" suffixOverrides=",">
  41 + <if test="create_time != null">#{create_time},</if>
  42 + <if test="iot_terminal_group_id != null">#{iot_terminal_group_id},</if>
  43 + <if test="iot_terminal_group_name != null">#{iot_terminal_group_name},</if>
  44 + <if test="iot_terminal_id != null">#{iot_terminal_id},</if>
  45 + <if test="user_info_id != null">#{user_info_id},</if>
  46 + </trim>
  47 + </insert>
  48 +
  49 + <update id="updateUserTerminalGroupRelation" parameterType="UserTerminalGroupRelation">
  50 + update user_terminal_group_relation
  51 + <trim prefix="SET" suffixOverrides=",">
  52 + <if test="create_time != null">create_time = #{create_time},</if>
  53 + <if test="iot_terminal_group_id != null">iot_terminal_group_id = #{iot_terminal_group_id},</if>
  54 + <if test="iot_terminal_group_name != null">iot_terminal_group_name = #{iot_terminal_group_name},</if>
  55 + <if test="iot_terminal_id != null">iot_terminal_id = #{iot_terminal_id},</if>
  56 + <if test="user_info_id != null">user_info_id = #{user_info_id},</if>
  57 + </trim>
  58 + where id = #{id}
  59 + </update>
  60 +
  61 + <delete id="deleteUserTerminalGroupRelationById" parameterType="Integer">
  62 + delete from user_terminal_group_relation where id = #{id}
  63 + </delete>
  64 +
  65 + <delete id="deleteUserTerminalGroupRelationByIds" parameterType="String">
  66 + delete from user_terminal_group_relation where id in
  67 + <foreach item="id" collection="array" open="(" separator="," close=")">
  68 + #{id}
  69 + </foreach>
  70 + </delete>
  71 +</mapper>