From 4979f4392e679713f4294f709598b644bb313344 Mon Sep 17 00:00:00 2001 From: 15856 <15856818120@163.com> Date: Thu, 8 Aug 2024 14:00:38 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AF=B9=E5=8D=97=E7=BD=91=E7=9A=84=E4=BB=A3?= =?UTF-8?q?=E7=A0=81=E8=BF=9B=E8=A1=8C=E8=BF=81=E7=A7=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../bonus/sgzb/base/api/domain/MaMachine.java | 4 + sgzb-common/sgzb-common-core/pom.xml | 4 + .../common/core/constant/TokenConstants.java | 5 + .../sgzb/common/core/utils/HttpHelper.java | 138 +++++ .../sgzb/common/core/utils/StringHelper.java | 15 + .../controller/BmProjectLotController.java | 14 + .../base/domain/vo/BmProjectLotImport.java | 203 +++++++ .../sgzb/base/domain/vo/IotRecordVo.java | 50 ++ .../sgzb/base/mapper/BmProjectLotMapper.java | 3 + .../sgzb/base/mapper/IotMachineMapper.java | 24 + .../base/service/BmProjectLotService.java | 3 + .../service/impl/BmProjectLotServiceImpl.java | 21 +- .../service/impl/MaMachineServiceImpl.java | 30 +- .../mapper/base/BmProjectLotMapper.xml | 72 +++ .../mapper/base/IotMachineMapper.xml | 21 + .../sgzb/material/config/ExceptionEnum.java | 11 +- .../controller/IotMachineController.java | 190 ++++++ .../bonus/sgzb/material/domain/IotCodeVo.java | 20 + .../bonus/sgzb/material/domain/IotDto.java | 79 +++ .../sgzb/material/domain/IotLocationVo.java | 43 ++ .../sgzb/material/domain/IotRecordVo.java | 37 ++ .../bonus/sgzb/material/domain/IotTypeVo.java | 21 + .../com/bonus/sgzb/material/domain/IotVo.java | 62 ++ .../material/mapper/IotMachineMapper.java | 120 ++++ .../material/service/IotMachineService.java | 115 ++++ .../service/impl/IotMachineServiceImpl.java | 542 ++++++++++++++++++ .../mapper/material/IotMachineMapper.xml | 211 +++++++ 27 files changed, 2051 insertions(+), 7 deletions(-) create mode 100644 sgzb-common/sgzb-common-core/src/main/java/com/bonus/sgzb/common/core/utils/HttpHelper.java create mode 100644 sgzb-modules/sgzb-base/src/main/java/com/bonus/sgzb/base/domain/vo/BmProjectLotImport.java create mode 100644 sgzb-modules/sgzb-base/src/main/java/com/bonus/sgzb/base/domain/vo/IotRecordVo.java create mode 100644 sgzb-modules/sgzb-base/src/main/java/com/bonus/sgzb/base/mapper/IotMachineMapper.java create mode 100644 sgzb-modules/sgzb-base/src/main/resources/mapper/base/IotMachineMapper.xml create mode 100644 sgzb-modules/sgzb-material/src/main/java/com/bonus/sgzb/material/controller/IotMachineController.java create mode 100644 sgzb-modules/sgzb-material/src/main/java/com/bonus/sgzb/material/domain/IotCodeVo.java create mode 100644 sgzb-modules/sgzb-material/src/main/java/com/bonus/sgzb/material/domain/IotDto.java create mode 100644 sgzb-modules/sgzb-material/src/main/java/com/bonus/sgzb/material/domain/IotLocationVo.java create mode 100644 sgzb-modules/sgzb-material/src/main/java/com/bonus/sgzb/material/domain/IotRecordVo.java create mode 100644 sgzb-modules/sgzb-material/src/main/java/com/bonus/sgzb/material/domain/IotTypeVo.java create mode 100644 sgzb-modules/sgzb-material/src/main/java/com/bonus/sgzb/material/domain/IotVo.java create mode 100644 sgzb-modules/sgzb-material/src/main/java/com/bonus/sgzb/material/mapper/IotMachineMapper.java create mode 100644 sgzb-modules/sgzb-material/src/main/java/com/bonus/sgzb/material/service/IotMachineService.java create mode 100644 sgzb-modules/sgzb-material/src/main/java/com/bonus/sgzb/material/service/impl/IotMachineServiceImpl.java create mode 100644 sgzb-modules/sgzb-material/src/main/resources/mapper/material/IotMachineMapper.xml diff --git a/sgzb-api/sgzb-api-system/src/main/java/com/bonus/sgzb/base/api/domain/MaMachine.java b/sgzb-api/sgzb-api-system/src/main/java/com/bonus/sgzb/base/api/domain/MaMachine.java index a8e1ddff..8495f12c 100644 --- a/sgzb-api/sgzb-api-system/src/main/java/com/bonus/sgzb/base/api/domain/MaMachine.java +++ b/sgzb-api/sgzb-api-system/src/main/java/com/bonus/sgzb/base/api/domain/MaMachine.java @@ -243,5 +243,9 @@ public class MaMachine extends BaseEntity { /** 导出选中列表 */ private List dataCondition; + @ApiModelProperty(value = "绑定IOT设备数量") + private Integer IotNum; + @ApiModelProperty(value = "Iot定位设备编号") + private String iotCode; } diff --git a/sgzb-common/sgzb-common-core/pom.xml b/sgzb-common/sgzb-common-core/pom.xml index a9d7f429..74a5cede 100644 --- a/sgzb-common/sgzb-common-core/pom.xml +++ b/sgzb-common/sgzb-common-core/pom.xml @@ -118,6 +118,10 @@ org.projectlombok lombok + + org.apache.httpcomponents + httpclient + diff --git a/sgzb-common/sgzb-common-core/src/main/java/com/bonus/sgzb/common/core/constant/TokenConstants.java b/sgzb-common/sgzb-common-core/src/main/java/com/bonus/sgzb/common/core/constant/TokenConstants.java index 534ebe30..fbb52cfb 100644 --- a/sgzb-common/sgzb-common-core/src/main/java/com/bonus/sgzb/common/core/constant/TokenConstants.java +++ b/sgzb-common/sgzb-common-core/src/main/java/com/bonus/sgzb/common/core/constant/TokenConstants.java @@ -22,4 +22,9 @@ public class TokenConstants */ public final static String SECRET = "abcdefghijklmnopqrstuvwxyz"; + /** + * IOT设备登录token有效期 + */ + public static final String TOKEN_LOCATION = "token_location"; + } diff --git a/sgzb-common/sgzb-common-core/src/main/java/com/bonus/sgzb/common/core/utils/HttpHelper.java b/sgzb-common/sgzb-common-core/src/main/java/com/bonus/sgzb/common/core/utils/HttpHelper.java new file mode 100644 index 00000000..56f16009 --- /dev/null +++ b/sgzb-common/sgzb-common-core/src/main/java/com/bonus/sgzb/common/core/utils/HttpHelper.java @@ -0,0 +1,138 @@ +package com.bonus.sgzb.common.core.utils; + +import com.alibaba.fastjson2.JSON; +import com.alibaba.fastjson2.JSONObject; +import org.apache.http.HttpEntity; +import org.apache.http.client.methods.CloseableHttpResponse; +import org.apache.http.client.methods.HttpPost; +import org.apache.http.entity.StringEntity; +import org.apache.http.impl.client.CloseableHttpClient; +import org.apache.http.impl.client.HttpClients; +import org.apache.http.util.EntityUtils; + +import java.io.*; +import java.net.HttpURLConnection; +import java.net.MalformedURLException; +import java.net.URL; +import java.util.HashMap; +import java.util.Map; + +public class HttpHelper { + + public static String sendHttpPost(String url, String JSONBody) throws Exception { + + System.out.println("JSONBody-=========:" + JSONBody); + CloseableHttpClient httpClient = HttpClients.createDefault(); + HttpPost httpPost = new HttpPost(url); + httpPost.addHeader("Content-Type", "application/json"); + httpPost.setEntity(new StringEntity(JSONBody)); + CloseableHttpResponse response = httpClient.execute(httpPost); + HttpEntity entity = response.getEntity(); + String responseContent = EntityUtils.toString(entity, "UTF-8"); + response.close(); + httpClient.close(); + return responseContent; + } + + public static String doPost(String urlString,String param) { + HttpURLConnection connection = null; + InputStream is = null; + OutputStream os = null; + BufferedReader br = null; + String result = null; + try { + URL url = new URL(urlString); + // 通过远程url连接对象打开连接 + connection = (HttpURLConnection) url.openConnection(); + // 设置连接请求方式 + connection.setRequestMethod("POST"); + // 设置连接主机服务器超时时间:15000毫秒 + connection.setConnectTimeout(15000); + // 设置读取主机服务器返回数据超时时间:60000毫秒 + connection.setReadTimeout(60000); + + // 默认值为:false,当向远程服务器传送数据/写数据时,需要设置为true + connection.setDoOutput(true); + // 默认值为:true,当前向远程服务读取数据时,设置为true,该参数可有可无 + connection.setDoInput(true); + // 设置传入参数的格式:请求参数应该是 name1=value1&name2=value2 的形式。 + connection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded"); + // 设置鉴权信息:Authorization: Bearer da3efcbf-0845-4fe3-8aba-ee040be542c0 + connection.setRequestProperty("Authorization", "Bearer da3efcbf-0845-4fe3-8aba-ee040be542c0"); + // 通过连接对象获取一个输出流 + os = connection.getOutputStream(); + // 通过输出流对象将参数写出去/传输出去,它是通过字节数组写出的 + os.write(param.getBytes()); + // 通过连接对象获取一个输入流,向远程读取 + if (connection.getResponseCode() == 200) { + + is = connection.getInputStream(); + // 对输入流对象进行包装:charset根据工作项目组的要求来设置 + br = new BufferedReader(new InputStreamReader(is, "UTF-8")); + + StringBuffer sbf = new StringBuffer(); + String temp = null; + // 循环遍历一行一行读取数据 + while ((temp = br.readLine()) != null) { + sbf.append(temp); + sbf.append("\r\n"); + } + result = sbf.toString(); + } + } catch (MalformedURLException e) { + e.printStackTrace(); + } catch (IOException e) { + e.printStackTrace(); + } finally { + // 关闭资源 + if (null != br) { + try { + br.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } + if (null != os) { + try { + os.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } + if (null != is) { + try { + is.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } + // 断开与远程地址url的连接 + connection.disconnect(); + } + return result; + } + + public static String getIotToken() { + Map map=new HashMap<>(); + String redisCode = null; + map.put("type","USER"); + map.put("from","web"); + map.put("username","omni-demo"); + //采用md5加密 + map.put("password","7d8609761efffc818e5ed11531ea2507"); + String param = JSON.toJSONString(map); + String resultUser = HttpHelper.doPost("http://gps51.com/webapi?action=login",param); + if (resultUser == null){ + throw new RuntimeException("返回数据为空!!"); + } + JSONObject object = JSONObject.parseObject(resultUser); + if ("0".equals(object.getString("status"))){ + redisCode = object.getString("token"); + }else { + throw new RuntimeException("返回数据为空!!"); + } + return redisCode; + } + + +} \ No newline at end of file diff --git a/sgzb-common/sgzb-common-core/src/main/java/com/bonus/sgzb/common/core/utils/StringHelper.java b/sgzb-common/sgzb-common-core/src/main/java/com/bonus/sgzb/common/core/utils/StringHelper.java index 6ef72519..0eff7b52 100644 --- a/sgzb-common/sgzb-common-core/src/main/java/com/bonus/sgzb/common/core/utils/StringHelper.java +++ b/sgzb-common/sgzb-common-core/src/main/java/com/bonus/sgzb/common/core/utils/StringHelper.java @@ -3,6 +3,7 @@ package com.bonus.sgzb.common.core.utils; import org.apache.commons.lang3.StringUtils; import java.io.*; +import java.math.BigDecimal; import java.sql.Blob; import java.sql.SQLException; import java.util.List; @@ -226,4 +227,18 @@ public class StringHelper { return !isEmpty(str); } + public static Long conversionLong(String res) { + if (res == null) { + return null; + } + return Long.valueOf(res); + } + + public static BigDecimal conversionBigDecimal(String res) { + if (res == null) { + return null; + } + return new BigDecimal(res); + } + } diff --git a/sgzb-modules/sgzb-base/src/main/java/com/bonus/sgzb/base/controller/BmProjectLotController.java b/sgzb-modules/sgzb-base/src/main/java/com/bonus/sgzb/base/controller/BmProjectLotController.java index 166856c8..7736fa66 100644 --- a/sgzb-modules/sgzb-base/src/main/java/com/bonus/sgzb/base/controller/BmProjectLotController.java +++ b/sgzb-modules/sgzb-base/src/main/java/com/bonus/sgzb/base/controller/BmProjectLotController.java @@ -1,6 +1,7 @@ package com.bonus.sgzb.base.controller; import com.bonus.sgzb.base.domain.BmProjectLot; +import com.bonus.sgzb.base.domain.vo.BmProjectLotImport; import com.bonus.sgzb.base.service.BmProjectLotService; import com.bonus.sgzb.common.core.utils.poi.ExcelUtil; import com.bonus.sgzb.common.core.web.controller.BaseController; @@ -8,11 +9,13 @@ import com.bonus.sgzb.common.core.web.domain.AjaxResult; import com.bonus.sgzb.common.core.web.page.TableDataInfo; import com.bonus.sgzb.common.log.annotation.Log; import com.bonus.sgzb.common.log.enums.BusinessType; +import com.bonus.sgzb.common.security.annotation.RequiresPermissions; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; +import org.springframework.web.multipart.MultipartFile; import javax.servlet.http.HttpServletResponse; @@ -88,4 +91,15 @@ public class BmProjectLotController extends BaseController { return bmProjectLotService.updateBmProjectLot(bmProjectLot); } + @Log(title = "项目管理导入", businessType = BusinessType.IMPORT) + @RequiresPermissions("system:user:import") + @PostMapping("/importData") + public AjaxResult importData(MultipartFile file) throws Exception + { + ExcelUtil util = new ExcelUtil<>(BmProjectLotImport.class); + List bmProjectLotList = util.importExcel(file.getInputStream()); + String message = bmProjectLotService.importBmProjectLot(bmProjectLotList); + return success(message); + } + } diff --git a/sgzb-modules/sgzb-base/src/main/java/com/bonus/sgzb/base/domain/vo/BmProjectLotImport.java b/sgzb-modules/sgzb-base/src/main/java/com/bonus/sgzb/base/domain/vo/BmProjectLotImport.java new file mode 100644 index 00000000..fa5d3ac7 --- /dev/null +++ b/sgzb-modules/sgzb-base/src/main/java/com/bonus/sgzb/base/domain/vo/BmProjectLotImport.java @@ -0,0 +1,203 @@ +package com.bonus.sgzb.base.domain.vo; + + +import com.bonus.sgzb.common.core.annotation.Excel; +import lombok.Data; + + +@Data +public class BmProjectLotImport { + + /** + * 状态 + */ + @Excel(name = "状态") + private String examineStatus; + + /** + * 创建时间 + */ + @Excel(name = "提交时间") + private String createTime; + + /** + *项目类别 + */ + @Excel(name = "项目类别") + private String projectCategory; + + + /** + * 标段工程项目名称 + */ + @Excel(name = "项目名称") + private String lotName; + + /** + * 标段工程项目编号 + */ + @Excel(name = "项目编号") + private String lotCode; + + /** + * 是否框架项目 + */ + @Excel(name = "是否框架项目") + private String isFrameworkProject; + + /** + * 是否子项目 + */ + @Excel(name = "是否子项目") + private String isSubProject; + + /** + * 所属工程 + */ + @Excel(name = "父项目名称") + private String ownPro; + + /** + * 父项目编号 + */ + @Excel(name = "父项目编号") + private String ownProId; + + /** + * 项目状态 + */ + @Excel(name = "项目状态") + private String projectStatus; + + /** + * 业务来源 + */ + @Excel(name = "业务来源") + private String businessSource; + + /** + * 电压等级 + */ + @Excel(name = "电压等级") + private String voltageLevel; + + /** + * 联系人 + */ + @Excel(name = "提交人名称") + private String linkMan; + + /** + * 建设单位 + */ + @Excel(name = "建设单位") + private String constructionUnit; + + /** + * 实施单位 + */ + @Excel(name = "实施单位") + private String implementationUnit; + + /** + * 部门 + */ + @Excel(name = "部门") + private String department; + + /** + * 创建者公司 + */ + @Excel(name = "创建者公司") + private String creatorCompany; + + /** + * 设计单位 + */ + @Excel(name = "设计单位") + private String designUnit; + + /** + * 监理单位 + */ + @Excel(name = "监理单位") + private String constructionControlUnit; + + /** + * 计划开工日期 + */ + @Excel(name = "计划开工日期") + private String plannedStartDate; + + /** + * 计划竣工日期 + */ + @Excel(name = "计划竣工日期") + private String plannedCompletionDate; + + /** + * 项目类别ID + */ + @Excel(name = "项目类别ID") + private String projectCategoryId; + + /** + * 建设单位ID + */ + @Excel(name = "建设单位ID") + private String constructionUnitId; + + /** + * 实施单位ID + */ + @Excel(name = "实施单位ID") + private String implementationUnitId; + + /** + * 设计单位ID + */ + @Excel(name = "设计单位ID") + private String designUnitId; + + /** + * 监理单位ID + */ + @Excel(name = "监理单位ID") + private String constructionControlUnitId; + + /** + * 工程地点 + */ + @Excel(name = "工程地点") + private String projectLocation; + + /** + * 工程所在省 + */ + @Excel(name = "工程所在省") + private String projectLocationProvince; + + /** + * 工程所在市 + */ + @Excel(name = "工程所在市") + private String projectLocationCity; + + /** + * 结束时间 + */ + @Excel(name = "结束时间") + private String endTime; + + /** + * 建设单位类型 + */ + @Excel(name = "建设单位类型") + private String constructionUnitType; + + /** + * 建设单位统一社会信用代码 + */ + @Excel(name = "建设单位统一社会信用代码") + private String constructionUnitCode; +} diff --git a/sgzb-modules/sgzb-base/src/main/java/com/bonus/sgzb/base/domain/vo/IotRecordVo.java b/sgzb-modules/sgzb-base/src/main/java/com/bonus/sgzb/base/domain/vo/IotRecordVo.java new file mode 100644 index 00000000..a904d66b --- /dev/null +++ b/sgzb-modules/sgzb-base/src/main/java/com/bonus/sgzb/base/domain/vo/IotRecordVo.java @@ -0,0 +1,50 @@ +package com.bonus.sgzb.base.domain.vo; + +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + + +/** + * @Author ma_sh + * @create 2024/7/11 15:55 + * @Description iot绑定记录返回vo + */ +@Data +public class IotRecordVo { + + /** iot设备ID */ + @ApiModelProperty(value = "iot设备ID") + private Long id; + + @ApiModelProperty(value = "iot设备id") + private Long iotId; + + @ApiModelProperty(value = "绑定类型id") + private Long typeId; + + @ApiModelProperty(value = "绑定类型名称") + private String typeName; + + @ApiModelProperty(value = "设备编码") + private String maCode; + + @ApiModelProperty(value = "绑定时间") + private String bindTime; + + /** 解绑时间 */ + @ApiModelProperty(value = "解绑时间") + private String unBindTime; + + /** iot设备类型 */ + @ApiModelProperty(value = "iot设备类型") + private String iotType; + + /** iot设备类型名称 */ + @ApiModelProperty(value = "iot设备类型名称") + private String iotTypeName; + + /** iot设备编码 */ + @ApiModelProperty(value = "iot设备编码") + private String iotCode; + +} diff --git a/sgzb-modules/sgzb-base/src/main/java/com/bonus/sgzb/base/mapper/BmProjectLotMapper.java b/sgzb-modules/sgzb-base/src/main/java/com/bonus/sgzb/base/mapper/BmProjectLotMapper.java index 1b726dbb..aa5c4eb4 100644 --- a/sgzb-modules/sgzb-base/src/main/java/com/bonus/sgzb/base/mapper/BmProjectLotMapper.java +++ b/sgzb-modules/sgzb-base/src/main/java/com/bonus/sgzb/base/mapper/BmProjectLotMapper.java @@ -2,6 +2,7 @@ package com.bonus.sgzb.base.mapper; import com.bonus.sgzb.base.domain.BmProjectInfo; import com.bonus.sgzb.base.domain.BmProjectLot; +import com.bonus.sgzb.base.domain.vo.BmProjectLotImport; import org.apache.ibatis.annotations.Mapper; import java.util.List; @@ -21,4 +22,6 @@ public interface BmProjectLotMapper { public int deleteProjectLotById(Long lotId); BmProjectLot selectByName(String lotName); + + void projectLotImport(BmProjectLotImport bmProjectLotImport); } diff --git a/sgzb-modules/sgzb-base/src/main/java/com/bonus/sgzb/base/mapper/IotMachineMapper.java b/sgzb-modules/sgzb-base/src/main/java/com/bonus/sgzb/base/mapper/IotMachineMapper.java new file mode 100644 index 00000000..0c46e466 --- /dev/null +++ b/sgzb-modules/sgzb-base/src/main/java/com/bonus/sgzb/base/mapper/IotMachineMapper.java @@ -0,0 +1,24 @@ +package com.bonus.sgzb.base.mapper; + +import com.bonus.sgzb.base.domain.vo.IotRecordVo; +import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Param; + +import java.util.List; + +/** + * @Author ma_sh + * @create 2024/7/4 16:28 + * iot设备管理mapper层 + */ +@Mapper +public interface IotMachineMapper { + + /** + * 查询设备类型 + * @return + */ + List selectList(@Param("maCode") String maCode); + + +} diff --git a/sgzb-modules/sgzb-base/src/main/java/com/bonus/sgzb/base/service/BmProjectLotService.java b/sgzb-modules/sgzb-base/src/main/java/com/bonus/sgzb/base/service/BmProjectLotService.java index f5c9fbc0..bd1a150b 100644 --- a/sgzb-modules/sgzb-base/src/main/java/com/bonus/sgzb/base/service/BmProjectLotService.java +++ b/sgzb-modules/sgzb-base/src/main/java/com/bonus/sgzb/base/service/BmProjectLotService.java @@ -2,6 +2,7 @@ package com.bonus.sgzb.base.service; import com.bonus.sgzb.base.domain.BmProjectLot; +import com.bonus.sgzb.base.domain.vo.BmProjectLotImport; import com.bonus.sgzb.common.core.web.domain.AjaxResult; import java.util.List; @@ -19,4 +20,6 @@ public interface BmProjectLotService { public int deleteProjectLotById(Long lotId); + String importBmProjectLot(List bmProjectLotImportList); + } diff --git a/sgzb-modules/sgzb-base/src/main/java/com/bonus/sgzb/base/service/impl/BmProjectLotServiceImpl.java b/sgzb-modules/sgzb-base/src/main/java/com/bonus/sgzb/base/service/impl/BmProjectLotServiceImpl.java index 04d77d9b..4f92e5df 100644 --- a/sgzb-modules/sgzb-base/src/main/java/com/bonus/sgzb/base/service/impl/BmProjectLotServiceImpl.java +++ b/sgzb-modules/sgzb-base/src/main/java/com/bonus/sgzb/base/service/impl/BmProjectLotServiceImpl.java @@ -2,15 +2,20 @@ package com.bonus.sgzb.base.service.impl; import com.bonus.sgzb.base.domain.BmProjectLot; +import com.bonus.sgzb.base.domain.vo.BmProjectLotImport; import com.bonus.sgzb.base.mapper.BmProjectLotMapper; import com.bonus.sgzb.base.service.BmProjectLotService; +import com.bonus.sgzb.common.core.exception.ServiceException; import com.bonus.sgzb.common.core.utils.StringUtils; import com.bonus.sgzb.common.core.web.domain.AjaxResult; +import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; import java.util.List; +@Slf4j @Service public class BmProjectLotServiceImpl implements BmProjectLotService { @@ -59,5 +64,19 @@ public class BmProjectLotServiceImpl implements BmProjectLotService { return bmProjectLotMapper.deleteProjectLotById(lotId); } - + @Override + @Transactional + public String importBmProjectLot(List bmProjectLotImportList) { + log.info("BmProjectLotServiceImpl importBmProjectLot 导入开始------"); + if (bmProjectLotImportList.isEmpty()) + { + throw new ServiceException("导入项目管理数据不能为空!"); + } + //保存项目管理 + for (BmProjectLotImport bmProjectLotImport: bmProjectLotImportList) { + bmProjectLotMapper.projectLotImport(bmProjectLotImport); + } + log.info("BmProjectLotServiceImpl importBmProjectLot 导入结束------"); + return "导入成功"; + } } diff --git a/sgzb-modules/sgzb-base/src/main/java/com/bonus/sgzb/base/service/impl/MaMachineServiceImpl.java b/sgzb-modules/sgzb-base/src/main/java/com/bonus/sgzb/base/service/impl/MaMachineServiceImpl.java index 7d9744e1..2f945f81 100644 --- a/sgzb-modules/sgzb-base/src/main/java/com/bonus/sgzb/base/service/impl/MaMachineServiceImpl.java +++ b/sgzb-modules/sgzb-base/src/main/java/com/bonus/sgzb/base/service/impl/MaMachineServiceImpl.java @@ -6,10 +6,8 @@ import com.bonus.sgzb.base.api.domain.MaLabelBind; import com.bonus.sgzb.base.api.domain.SltAgreementApply; import com.bonus.sgzb.base.domain.BmProjectLot; import com.bonus.sgzb.base.domain.MaPropSet; -import com.bonus.sgzb.base.mapper.MaLabelBindMapper; -import com.bonus.sgzb.base.mapper.MaMachineMapper; -import com.bonus.sgzb.base.mapper.MaPropInfoMapper; -import com.bonus.sgzb.base.mapper.MaTypeMapper; +import com.bonus.sgzb.base.domain.vo.IotRecordVo; +import com.bonus.sgzb.base.mapper.*; import com.bonus.sgzb.base.service.MaMachineService; import com.bonus.sgzb.common.core.exception.ServiceException; import com.bonus.sgzb.common.security.utils.SecurityUtils; @@ -17,6 +15,7 @@ import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import javax.annotation.Resource; +import java.util.ArrayList; import java.util.Date; import java.util.List; @@ -35,10 +34,31 @@ public class MaMachineServiceImpl implements MaMachineService { @Resource private MaPropInfoMapper maPropInfoMapper; + @Resource + private IotMachineMapper iotMachineMapper; + @Override public List getMaMachine(MaMachine maMachine) { - return maMachineMapper.getMaMachine(maMachine); + List listMaMachine = new ArrayList<>(); + listMaMachine =maMachineMapper.getMaMachine(maMachine); + if (listMaMachine.size() > 0){ + for (MaMachine ma : listMaMachine) { + //根据机具编码查询iot设备 + List iotRecordVoList = iotMachineMapper.selectList(ma.getMaCode()); + ma.setIotNum(iotRecordVoList.size()); + //判断是否绑定了iot设备 + if (iotRecordVoList.size()>0){ + for (int i = 0; i < iotRecordVoList.size(); i++) { + //保存定位iot设备编码 + if ("125".equals(iotRecordVoList.get(i).getIotType())){ + ma.setIotCode(iotRecordVoList.get(i).getIotCode()); + } + } + } + } + } + return listMaMachine; } /** diff --git a/sgzb-modules/sgzb-base/src/main/resources/mapper/base/BmProjectLotMapper.xml b/sgzb-modules/sgzb-base/src/main/resources/mapper/base/BmProjectLotMapper.xml index 13279d02..6e318020 100644 --- a/sgzb-modules/sgzb-base/src/main/resources/mapper/base/BmProjectLotMapper.xml +++ b/sgzb-modules/sgzb-base/src/main/resources/mapper/base/BmProjectLotMapper.xml @@ -133,6 +133,78 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" sysdate() ) + + + insert into bm_project_lot ( + examine_status, + create_time, + project_category, + lot_name, + lot_code, + is_framework_project, + is_sub_project, + own_pro, + own_pro_Id, + project_status, + business_source, + voltage_level, + link_man, + construction_unit, + implementation_unit, + department, + creator_company, + design_unit, + construction_control_unit, + planned_start_date, + planned_completion_date, + project_category_id, + construction_unit_id, + implementation_unit_id, + design_unit_id, + construction_control_unit_id, + project_location, + project_location_province, + project_location_city, + end_time, + construction_unit_type, + construction_unit_code + + ) VALUES ( + #{examineStatus}, + #{createTime}, + #{projectCategory}, + #{lotName}, + #{lotCode}, + #{isFrameworkProject}, + #{isSubProject}, + #{ownPro}, + #{ownProId}, + #{projectStatus}, + #{businessSource}, + #{voltageLevel}, + #{linkMan}, + #{constructionUnit}, + #{implementationUnit}, + #{department}, + #{creatorCompany}, + #{designUnit}, + #{constructionControlUnit}, + #{plannedStartDate}, + #{plannedCompletionDate}, + #{projectCategoryId}, + #{constructionUnitId}, + #{implementationUnitId}, + #{designUnitId}, + #{constructionControlUnitId}, + #{projectLocation}, + #{projectLocationProvince}, + #{projectLocationCity}, + #{endTime}, + #{constructionUnitType}, + #{constructionUnitCode} + + ) + update bm_project_lot diff --git a/sgzb-modules/sgzb-base/src/main/resources/mapper/base/IotMachineMapper.xml b/sgzb-modules/sgzb-base/src/main/resources/mapper/base/IotMachineMapper.xml new file mode 100644 index 00000000..f47124b4 --- /dev/null +++ b/sgzb-modules/sgzb-base/src/main/resources/mapper/base/IotMachineMapper.xml @@ -0,0 +1,21 @@ + + + + + + + + + \ No newline at end of file diff --git a/sgzb-modules/sgzb-material/src/main/java/com/bonus/sgzb/material/config/ExceptionEnum.java b/sgzb-modules/sgzb-material/src/main/java/com/bonus/sgzb/material/config/ExceptionEnum.java index 61c96253..6b227025 100644 --- a/sgzb-modules/sgzb-material/src/main/java/com/bonus/sgzb/material/config/ExceptionEnum.java +++ b/sgzb-modules/sgzb-material/src/main/java/com/bonus/sgzb/material/config/ExceptionEnum.java @@ -12,9 +12,18 @@ import lombok.Getter; @AllArgsConstructor public enum ExceptionEnum { + PARAM_NULL(1001, "参数为空"), + IOT_CODE_DUPLICATE(1002, "设备编号重复"), + IOT_TO_DELETE(1003, "该iot设备绑定相关类型设备,无法删除"), + SUCCESS(200, "操作成功"), SAVE_TO_DATABASE(500, "新增保存失败,请联系管理员!!!"), DELETE_TO_DATABASE(500, "删除失败,请联系管理员!!!"), - UPDATE_TO_DATABASE(500, "修改失败,请联系管理员!!!"); + BIND_TO_DATABASE(500, "绑定失败,请联系管理员!!!"), + UN_BIND_TO_DATABASE(500, "解绑失败,请联系管理员!!!"), + UPDATE_TO_DATABASE(500, "修改失败,请联系管理员!!!"), + + RETURN_DATA_IS_EMPTY(501, "返回数据为空!!"), + IOT_ENCODING_ERROR(502, "输入的IOT编码有误,请输入正确的编码!!!"); private Integer code; diff --git a/sgzb-modules/sgzb-material/src/main/java/com/bonus/sgzb/material/controller/IotMachineController.java b/sgzb-modules/sgzb-material/src/main/java/com/bonus/sgzb/material/controller/IotMachineController.java new file mode 100644 index 00000000..992fa8f4 --- /dev/null +++ b/sgzb-modules/sgzb-material/src/main/java/com/bonus/sgzb/material/controller/IotMachineController.java @@ -0,0 +1,190 @@ +package com.bonus.sgzb.material.controller; + +import com.bonus.sgzb.common.core.web.controller.BaseController; +import com.bonus.sgzb.common.core.web.domain.AjaxResult; +import com.bonus.sgzb.common.core.web.page.TableDataInfo; +import com.bonus.sgzb.material.domain.IotDto; +import com.bonus.sgzb.material.domain.IotLocationVo; +import com.bonus.sgzb.material.domain.IotRecordVo; +import com.bonus.sgzb.material.domain.IotVo; +import com.bonus.sgzb.material.service.IotMachineService; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import lombok.extern.slf4j.Slf4j; +import org.springframework.validation.annotation.Validated; +import org.springframework.web.bind.annotation.*; + +import javax.annotation.Resource; +import java.util.List; + +/** + * @Author ma_sh + * @create 2024/7/4 16:23 + * iot设备管理控制层 + */ +@Api(tags = " iot设备管理控制层") +@RestController +@RequestMapping("/iotMachine") +@Slf4j +public class IotMachineController extends BaseController { + + + @Resource + private IotMachineService iotMachineService; + + /** + * 获取设备管理列表 + */ + @ApiOperation(value = "获取设备管理列表") + @GetMapping("/getIotList") + public TableDataInfo getIotList(IotDto iotDto) { + log.info("获取设备管理列表传参:{}", iotDto); + startPage(); + List list = iotMachineService.getIotList(iotDto); + return getDataTable(list); + } + + /** + * 添加或者修改设备 + * @param iotDto + * @return + */ + @ApiOperation("添加或者修改设备") + @PostMapping("/addOrUpdate") + public AjaxResult addOrUpdate(@Validated @RequestBody IotDto iotDto) { + log.info("添加或者修改设备传参:{}", iotDto); + if (iotDto.getIotId() != null) { + return iotMachineService.update(iotDto); + } + return iotMachineService.add(iotDto); + } + + /** + * 删除设备 + * @param iotId + * @return + */ + @ApiOperation(value = "删除设备") + @DeleteMapping("/deleteById/{iotId}") + public AjaxResult deleteByIds(@PathVariable("iotId") Long iotId) { + log.info("删除设备传参:{}", iotId); + return iotMachineService.deleteById(iotId); + } + + /** + * 绑定设备 + * @param iotDto + * @return + */ + @ApiOperation("绑定设备") + @PostMapping("/bind") + public AjaxResult bind(@Validated @RequestBody IotDto iotDto) { + log.info("绑定设备传参:{}", iotDto); + return iotMachineService.bind(iotDto); + } + + /** + * 绑定设备APP + * @param iotDto + * @return + */ + @ApiOperation("App绑定设备") + @PostMapping("/bindApp") + public AjaxResult bindApp(@Validated @RequestBody IotDto iotDto) { + log.info("绑定设备传参:{}", iotDto); + return iotMachineService.bindApp(iotDto); + } + + /** + * 解绑设备 + * @param iotDto + * @return + */ + @ApiOperation("解绑设备") + @PostMapping("/unbind") + public AjaxResult unbind(@Validated @RequestBody IotDto iotDto) { + log.info("解绑设备传参:{}", iotDto); + return iotMachineService.unbind(iotDto); + } + + /** + * 根据类型id查询设备绑定列表 + * @param iotDto + * @return + */ + @ApiOperation("根据类型id查询设备绑定列表") + @GetMapping("/getTypeList") + public TableDataInfo getTypeList(IotDto iotDto) { + startPage(); + log.info("根据类型id查询设备绑定列表传参:{}", iotDto); + List typeList = iotMachineService.getTypeList(iotDto); + return getDataTable(typeList); + } + + /** + * 根据iot设备类型查询设备编码 + * @param iotDto + * @return + */ + @ApiOperation("根据iot设备类型查询设备编码") + @GetMapping("/selectList") + public AjaxResult selectList(IotDto iotDto) { + log.info("根据iot设备类型查询设备编码:{}", iotDto); + return iotMachineService.selectList(iotDto); + } + + /** + * 根据iot设备获取绑定记录(分页) + * @param iotDto + * @return + */ + @ApiOperation("根据iot设备获取绑定记录(分页)") + @GetMapping("/getRecordList") + public TableDataInfo getRecordList(IotDto iotDto) { + startPage(); + log.info("根据iot设备获取绑定记录(分页):{}", iotDto); + List list = iotMachineService.getRecordList(iotDto); + return getDataTable(list); + } + + /** + * 根据iot设备获取绑定记录(全量不分页,供前端数据使用) + * @param iotDto + * @return + */ + @ApiOperation("根据iot设备获取绑定记录(全量不分页,供前端数据使用)") + @GetMapping("/getRecordListAll") + public AjaxResult getRecordListAll(IotDto iotDto) { + List list = iotMachineService.getRecordList(iotDto); + return AjaxResult.success(list); + } + + + @ApiOperation("获取定位") + @PostMapping("/getLocation") + public AjaxResult getLocation(@Validated @RequestBody IotDto iotDto) { + log.info("获取定位接口:{}", iotDto); + return iotMachineService.getLocation(iotDto); + } + + @ApiOperation("查询行程") + @PostMapping("/searchItinerary") + public AjaxResult searchItinerary(@Validated @RequestBody IotLocationVo iotLocationVo) { + log.info("查询行程接口:{}", iotLocationVo); + return iotMachineService.searchItinerary(iotLocationVo); + } + + @ApiOperation("查询停留点") + @PostMapping("/reportParkDetailByTime") + public AjaxResult reportParkDetailByTime(@Validated @RequestBody IotLocationVo iotLocationVo) { + log.info("查询停留点接口:{}", iotLocationVo); + return iotMachineService.reportParkDetailByTime(iotLocationVo); + } + + @ApiOperation("报警记录") + @PostMapping("/reportAlarm") + public AjaxResult reportAlarm(@Validated @RequestBody IotLocationVo iotLocationVo) { + log.info("报警记录接口:{}", iotLocationVo); + return iotMachineService.reportAlarm(iotLocationVo); + } +} diff --git a/sgzb-modules/sgzb-material/src/main/java/com/bonus/sgzb/material/domain/IotCodeVo.java b/sgzb-modules/sgzb-material/src/main/java/com/bonus/sgzb/material/domain/IotCodeVo.java new file mode 100644 index 00000000..2da585e8 --- /dev/null +++ b/sgzb-modules/sgzb-material/src/main/java/com/bonus/sgzb/material/domain/IotCodeVo.java @@ -0,0 +1,20 @@ +package com.bonus.sgzb.material.domain; + +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +/** + * @Author ma_sh + * @create 2024/7/11 15:21 + */ +@Data +public class IotCodeVo { + + /** iot设备ID */ + @ApiModelProperty(value = "iot设备ID") + private Long iotId; + + /** iot设备编码 */ + @ApiModelProperty(value = "iot设备编码") + private String iotCode; +} diff --git a/sgzb-modules/sgzb-material/src/main/java/com/bonus/sgzb/material/domain/IotDto.java b/sgzb-modules/sgzb-material/src/main/java/com/bonus/sgzb/material/domain/IotDto.java new file mode 100644 index 00000000..fea8c85d --- /dev/null +++ b/sgzb-modules/sgzb-material/src/main/java/com/bonus/sgzb/material/domain/IotDto.java @@ -0,0 +1,79 @@ +package com.bonus.sgzb.material.domain; + +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import java.util.Date; + +/** + * @Author ma_sh + * @create 2024/7/4 17:10 + * iot设备管理传参dto + */ +@Data +public class IotDto { + + /** iot设备ID */ + @ApiModelProperty(value = "iot设备ID") + private Long id; + + /** iot设备ID */ + @ApiModelProperty(value = "iot设备ID") + private Long iotId; + + /** 类型id */ + @ApiModelProperty(value = "类型id") + private Long typeId; + + /** 被绑定机具编号 */ + @ApiModelProperty(value = "被绑定机具编号") + private String maCode; + + /** iot设备类型 */ + @ApiModelProperty(value = "iot设备类型") + private String iotType; + + @ApiModelProperty(value = "iot设备类型id") + private String iotTypeId; + + /** iot设备编码 */ + @ApiModelProperty(value = "iot设备编码") + private String iotCode; + + /** iot设备状态 (0 在线, 1 下线)*/ + @ApiModelProperty(value = "iot设备状态 (0 在线, 1 下线)") + private int iotStatus; + + /** iot设备二维码 */ + @ApiModelProperty(value = "iot设备二维码") + private String qrCode; + + /** 创建人 */ + @ApiModelProperty(value = "创建人") + private String createBy; + + /** 创建时间 */ + @ApiModelProperty(value = "创建时间") + private Date createTime; + + /** 更新人 */ + @ApiModelProperty(value = "更新人") + private String updateBy; + + /** 更新时间 */ + @ApiModelProperty(value = "更新时间") + private Date updateTime; + + /** 绑定人 */ + @ApiModelProperty(value = "绑定人") + private String binder; + + /** 解绑人 */ + @ApiModelProperty(value = "解绑人") + private String unBinder; + + /** 关键字 */ + @ApiModelProperty(value = "关键字") + private String keyWord; + +} diff --git a/sgzb-modules/sgzb-material/src/main/java/com/bonus/sgzb/material/domain/IotLocationVo.java b/sgzb-modules/sgzb-material/src/main/java/com/bonus/sgzb/material/domain/IotLocationVo.java new file mode 100644 index 00000000..84afef08 --- /dev/null +++ b/sgzb-modules/sgzb-material/src/main/java/com/bonus/sgzb/material/domain/IotLocationVo.java @@ -0,0 +1,43 @@ +package com.bonus.sgzb.material.domain; + +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import java.math.BigDecimal; + +@Data +public class IotLocationVo { + + /** iot设备ID */ + @ApiModelProperty(value = "iot设备ID") + private Long iotId; + + /** 经度 */ + @ApiModelProperty(value = "经度") + private BigDecimal callon; + + /** 经度 */ + @ApiModelProperty(value = "纬度") + private BigDecimal callat; + + /** 开始时间 */ + @ApiModelProperty(value = "开始时间") + private String beginTime; + + /** 结束时间 */ + @ApiModelProperty(value = "结束时间") + private String endTime; + + /** 详细地址 */ + @ApiModelProperty(value = "详细地址") + private String address; + + + /** 报警时间 */ + @ApiModelProperty(value = "报警时间") + private String startAlarmTime; + + /** 报警内容 */ + @ApiModelProperty(value = "报警内容") + private String startAlarm; +} diff --git a/sgzb-modules/sgzb-material/src/main/java/com/bonus/sgzb/material/domain/IotRecordVo.java b/sgzb-modules/sgzb-material/src/main/java/com/bonus/sgzb/material/domain/IotRecordVo.java new file mode 100644 index 00000000..afe17e49 --- /dev/null +++ b/sgzb-modules/sgzb-material/src/main/java/com/bonus/sgzb/material/domain/IotRecordVo.java @@ -0,0 +1,37 @@ +package com.bonus.sgzb.material.domain; + +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + + +/** + * @Author ma_sh + * @create 2024/7/11 15:55 + * @Description iot绑定记录返回vo + */ +@Data +public class IotRecordVo { + + /** iot设备ID */ + @ApiModelProperty(value = "iot设备ID") + private Long id; + + @ApiModelProperty(value = "iot设备id") + private Long iotId; + + @ApiModelProperty(value = "绑定类型id") + private Long typeId; + + @ApiModelProperty(value = "绑定类型名称") + private String typeName; + + @ApiModelProperty(value = "设备编码") + private String maCode; + + @ApiModelProperty(value = "绑定时间") + private String bindTime; + + /** 解绑时间 */ + @ApiModelProperty(value = "解绑时间") + private String unBindTime; +} diff --git a/sgzb-modules/sgzb-material/src/main/java/com/bonus/sgzb/material/domain/IotTypeVo.java b/sgzb-modules/sgzb-material/src/main/java/com/bonus/sgzb/material/domain/IotTypeVo.java new file mode 100644 index 00000000..b99b9e5f --- /dev/null +++ b/sgzb-modules/sgzb-material/src/main/java/com/bonus/sgzb/material/domain/IotTypeVo.java @@ -0,0 +1,21 @@ +package com.bonus.sgzb.material.domain; + +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +/** + * @Author ma_sh + * @create 2024/7/11 14:57 + */ +@Data +public class IotTypeVo { + + @ApiModelProperty(value = "iot设备类型id") + private String iotTypeId; + + @ApiModelProperty(value = "父级id") + private String pId; + + @ApiModelProperty(value = "iot设备类型名称") + private String iotTypeName; +} diff --git a/sgzb-modules/sgzb-material/src/main/java/com/bonus/sgzb/material/domain/IotVo.java b/sgzb-modules/sgzb-material/src/main/java/com/bonus/sgzb/material/domain/IotVo.java new file mode 100644 index 00000000..db0af274 --- /dev/null +++ b/sgzb-modules/sgzb-material/src/main/java/com/bonus/sgzb/material/domain/IotVo.java @@ -0,0 +1,62 @@ +package com.bonus.sgzb.material.domain; + +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +/** + * @Author ma_sh + * @create 2024/7/4 17:00 + * iot设备管理返回vo + */ +@Data +public class IotVo { + + /** iot设备ID */ + @ApiModelProperty(value = "iot设备ID") + private Long id; + + /** iot设备ID */ + @ApiModelProperty(value = "iot设备ID") + private Long iotId; + + /** iot设备类型 */ + @ApiModelProperty(value = "iot设备类型") + private String iotType; + + /** iot设备类型名称 */ + @ApiModelProperty(value = "iot设备类型名称") + private String iotTypeName; + + /** iot设备编码 */ + @ApiModelProperty(value = "iot设备编码") + private String iotCode; + + /** iot设备状态 (0 在线, 1 下线)*/ + @ApiModelProperty(value = "iot设备状态 (0 在线, 1 下线)") + private int iotStatus; + + /** iot设备二维码 */ + @ApiModelProperty(value = "iot设备二维码") + private String qrCode; + + /** iot设备绑定状态 (0 已绑定、1 未绑定)*/ + @ApiModelProperty(value = "iot设备绑定状态 (0 已绑定、1 未绑定)") + private int bindStatus; + + /** 绑定人 */ + @ApiModelProperty(value = "绑定人") + private String binder; + + /** 绑定时间 */ + @ApiModelProperty(value = "绑定时间") + private String bindTime; + + /** 解绑人 */ + @ApiModelProperty(value = "解绑人") + private String unBinder; + + /** 解绑时间 */ + @ApiModelProperty(value = "解绑时间") + private String unBindTime; + +} diff --git a/sgzb-modules/sgzb-material/src/main/java/com/bonus/sgzb/material/mapper/IotMachineMapper.java b/sgzb-modules/sgzb-material/src/main/java/com/bonus/sgzb/material/mapper/IotMachineMapper.java new file mode 100644 index 00000000..3b64019e --- /dev/null +++ b/sgzb-modules/sgzb-material/src/main/java/com/bonus/sgzb/material/mapper/IotMachineMapper.java @@ -0,0 +1,120 @@ +package com.bonus.sgzb.material.mapper; + +import com.bonus.sgzb.material.domain.*; +import org.apache.ibatis.annotations.Mapper; + +import java.util.List; + +/** + * @Author ma_sh + * @create 2024/7/4 16:28 + * iot设备管理mapper层 + */ +@Mapper +public interface IotMachineMapper { + + /** + * 根据iotCode查询iotCode是否存在 + * @param iotDto + * @return + */ + IotVo selectIotCode(IotDto iotDto); + + /** + * 根据qrCode查询qrCode是否存在 + * @param qrCode + * @return + */ + int selectQrCode(String qrCode); + + /** + * 添加iot设备 + * @param iotDto + * @return + */ + int add(IotDto iotDto); + + /** + * 修改iot设备 + * @param iotDto + * @return + */ + int update(IotDto iotDto); + + /** + * 根据iotCode查询iotCode是否存在 + * @param iotDto + * @return + */ + List getIotList(IotDto iotDto); + + /** + * 根据iotId查询iotId是否存在 + * @param iotId + * @return + */ + IotVo selectById(Long iotId); + + /** + * 根据iotId删除iot设备 + * @param iotId + * @return + */ + int deleteById(Long iotId); + + /** + * 绑定iot设备 + * @param iotDto + * @return + */ + int bind(IotDto iotDto); + + /** + * 更新绑定状态 + * @param iotDto + * @return + */ + int updateBindStatus(IotDto iotDto); + + /** + * 解绑iot设备 + * @param iotDto + * @return + */ + int unbind(IotDto iotDto); + + /** + * 更新解绑状态 + * @param iotDto + * @return + */ + int updateUnBindStatus(IotDto iotDto); + + /** + * 根据类型id查询设备绑定列表 + * @param iotDto + * @return + */ + List getTypeList(IotDto iotDto); + + + /** + * 查询设备类型 + * @return + */ + List selectList(); + + /** + * 根据iotTypeId查询设备编码 + * @param iotTypeId + * @return + */ + List selectCodeList(String iotTypeId); + + /** + * 根据iotTypeId查询设备编码 + * @param iotDto + * @return + */ + List getRecordList(IotDto iotDto); +} diff --git a/sgzb-modules/sgzb-material/src/main/java/com/bonus/sgzb/material/service/IotMachineService.java b/sgzb-modules/sgzb-material/src/main/java/com/bonus/sgzb/material/service/IotMachineService.java new file mode 100644 index 00000000..6a4aad51 --- /dev/null +++ b/sgzb-modules/sgzb-material/src/main/java/com/bonus/sgzb/material/service/IotMachineService.java @@ -0,0 +1,115 @@ +package com.bonus.sgzb.material.service; + +import com.bonus.sgzb.common.core.web.domain.AjaxResult; +import com.bonus.sgzb.material.domain.IotDto; +import com.bonus.sgzb.material.domain.IotLocationVo; +import com.bonus.sgzb.material.domain.IotRecordVo; +import com.bonus.sgzb.material.domain.IotVo; + +import java.util.List; + +/** + * @Author ma_sh + * @create 2024/7/4 16:25 + * iot设备管理服务层 + */ +public interface IotMachineService { + + /** + * 添加设备 + * @param iotDto + * @return + */ + AjaxResult add(IotDto iotDto); + + /** + * 修改设备 + * @param iotDto + * @return + */ + AjaxResult update(IotDto iotDto); + + /** + * 获取设备列表 + * @param iotDto + * @return + */ + List getIotList(IotDto iotDto); + + /** + * 删除设备 + * @param iotId + * @return + */ + AjaxResult deleteById(Long iotId); + + /** + * 绑定设备 + * @param iotDto + * @return + */ + AjaxResult bind(IotDto iotDto); + + /** + * 解绑设备 + * @param iotDto + * @return + */ + AjaxResult unbind(IotDto iotDto); + + /** + * 根据类型id查询设备绑定列表 + * @param iotDto + * @return + */ + List getTypeList(IotDto iotDto); + + /** + * 根据iot设备类型查询设备编码 + * @param iotDto + * @return + */ + AjaxResult selectList(IotDto iotDto); + + /** + * 获取设备记录列表 + * @param iotDto + * @return + */ + List getRecordList(IotDto iotDto); + + /** + * 获取设备定位 + * @param iotDto + * @return + */ + AjaxResult getLocation(IotDto iotDto); + + /** + * 查询行程 + * @param iotLocationVo + * @return + */ + AjaxResult searchItinerary(IotLocationVo iotLocationVo); + + /** + * 查询停留点 + * @param iotLocationVo + * @return + */ + AjaxResult reportParkDetailByTime(IotLocationVo iotLocationVo); + + /** + * App绑定设备 + * @param iotDto + * @return + */ + AjaxResult bindApp(IotDto iotDto); + + /** + * 报警记录 + * @param iotLocationVo + * @return + */ + AjaxResult reportAlarm(IotLocationVo iotLocationVo); +} diff --git a/sgzb-modules/sgzb-material/src/main/java/com/bonus/sgzb/material/service/impl/IotMachineServiceImpl.java b/sgzb-modules/sgzb-material/src/main/java/com/bonus/sgzb/material/service/impl/IotMachineServiceImpl.java new file mode 100644 index 00000000..4dc783eb --- /dev/null +++ b/sgzb-modules/sgzb-material/src/main/java/com/bonus/sgzb/material/service/impl/IotMachineServiceImpl.java @@ -0,0 +1,542 @@ +package com.bonus.sgzb.material.service.impl; + +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONArray; +import com.alibaba.fastjson2.JSONObject; +import com.bonus.sgzb.common.core.constant.TokenConstants; +import com.bonus.sgzb.common.core.utils.HttpHelper; +import com.bonus.sgzb.common.core.utils.StringHelper; +import com.bonus.sgzb.common.core.web.domain.AjaxResult; +import com.bonus.sgzb.common.redis.service.RedisService; +import com.bonus.sgzb.common.security.utils.SecurityUtils; +import com.bonus.sgzb.material.config.ExceptionEnum; +import com.bonus.sgzb.material.config.FieldGenerator; +import com.bonus.sgzb.material.domain.*; +import com.bonus.sgzb.material.mapper.IotMachineMapper; +import com.bonus.sgzb.material.service.IotMachineService; +import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; +import org.springframework.transaction.interceptor.TransactionAspectSupport; + +import javax.annotation.Resource; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.concurrent.TimeUnit; + +/** + * iot设备管理实现层 + * @author ma_sh + */ +@Service +@Slf4j +public class IotMachineServiceImpl implements IotMachineService { + + @Resource + private IotMachineMapper iotMachineMapper; + + @Resource + private RedisService redisService; + + /** + * 添加设备-保存 + * + * @param iotDto + * @return + */ + @Override + public AjaxResult add(IotDto iotDto) { + if (iotDto == null || iotDto.getIotCode() == null || iotDto.getIotType() == null) { + return AjaxResult.error(ExceptionEnum.PARAM_NULL.getCode(), ExceptionEnum.PARAM_NULL.getMsg()); + } + //根据前端传入设备编号判重 + IotVo iotVo = iotMachineMapper.selectIotCode(iotDto); + if (iotVo != null) { + return AjaxResult.error(ExceptionEnum.IOT_CODE_DUPLICATE.getCode(), ExceptionEnum.IOT_CODE_DUPLICATE.getMsg()); + } + //后端生成二维码编号,需判重,确保表中数据唯一性 + String qrCode = FieldGenerator.generateField(); + // 设置最大尝试次数10,避免无限循环 + int maxAttempts = 10; + for (int attempt = 0; attempt < maxAttempts; attempt++) { + if (iotMachineMapper.selectQrCode(qrCode) == 0) { + iotDto.setQrCode(qrCode); + // 找到唯一的qrCode,退出循环 + break; + } else { + // 生成新的qrCode + qrCode = FieldGenerator.generateField(); + } + } + iotDto.setCreateBy(SecurityUtils.getLoginUser().getUserid().toString()); + try { + // 进行设备添加 + int res = iotMachineMapper.add(iotDto); + if (res == 0) { + // 如果添加失败,返回保存到数据库异常的错误信息 + throw new RuntimeException(ExceptionEnum.SAVE_TO_DATABASE.getMsg()); + } else { + // 添加成功,返回成功的消息和新增的记录数 + return AjaxResult.success(ExceptionEnum.SUCCESS.getMsg(), res); + } + } catch (Exception e) { + log.error("Error saving to database: " + e.getMessage()); + // 捕获所有异常,返回通用的数据库操作异常信息 + return AjaxResult.error(ExceptionEnum.SAVE_TO_DATABASE.getCode(), ExceptionEnum.SAVE_TO_DATABASE.getMsg()); + } + } + + /** + * 设备管理-修改 + * + * @param iotDto + * @return + */ + @Override + public AjaxResult update(IotDto iotDto) { + if (iotDto == null || iotDto.getIotId() == null) { + return AjaxResult.error(ExceptionEnum.PARAM_NULL.getCode(), ExceptionEnum.PARAM_NULL.getMsg()); + } + IotVo iotVo = iotMachineMapper.selectIotCode(iotDto); + if (iotVo != null && !iotVo.getIotId().equals(iotDto.getIotId())) { + return AjaxResult.error(ExceptionEnum.IOT_CODE_DUPLICATE.getCode(), ExceptionEnum.IOT_CODE_DUPLICATE.getMsg()); + } + iotDto.setUpdateBy(SecurityUtils.getLoginUser().getUserid().toString()); + try { + //设备修改 + int res = iotMachineMapper.update(iotDto); + if (res == 0) { + // 如果修改失败,返回修改到数据库异常的错误信息 + throw new RuntimeException(ExceptionEnum.UPDATE_TO_DATABASE.getMsg()); + } else { + // 修改成功,返回成功的消息和修改的记录数 + return AjaxResult.success(ExceptionEnum.SUCCESS.getMsg(), res); + } + } catch (Exception e) { + log.error("Error updating to database: " + e.getMessage()); + //捕获异常 + return AjaxResult.error(ExceptionEnum.UPDATE_TO_DATABASE.getCode(), ExceptionEnum.UPDATE_TO_DATABASE.getMsg()); + } + } + + /** + * 获取设备列表 + * + * @param iotDto + * @return + */ + @Override + public List getIotList(IotDto iotDto) { + return iotMachineMapper.getIotList(iotDto); + } + + /** + * 删除设备 + * + * @param iotId + * @return + */ + @Override + public AjaxResult deleteById(Long iotId) { + //先进行判断,绑定设备的iot设备无法删除 + IotVo iotVo = iotMachineMapper.selectById(iotId); + if (iotVo.getBindStatus() == 0) { + return AjaxResult.error(ExceptionEnum.IOT_TO_DELETE.getCode(), ExceptionEnum.IOT_TO_DELETE.getMsg()); + } + try { + // 执行设备删除操作 + int res = iotMachineMapper.deleteById(iotId); + if (res == 0) { + // 如果删除操作未成功,返回删除数据库异常的错误信息 + return AjaxResult.error(ExceptionEnum.DELETE_TO_DATABASE.getCode(), ExceptionEnum.DELETE_TO_DATABASE.getMsg()); + } else { + // 删除成功,返回成功的消息和受影响的记录数 + return AjaxResult.success(ExceptionEnum.SUCCESS.getMsg(), res); + } + } catch (Exception e) { + log.error("Error deleting from database: " + e.getMessage()); + // 捕获所有异常,返回通用的数据库操作异常信息 + return AjaxResult.error(ExceptionEnum.DELETE_TO_DATABASE.getCode(), ExceptionEnum.DELETE_TO_DATABASE.getMsg()); + } + } + + /** + * 绑定设备 + * + * @param iotDto + * @return + */ + @Override + @Transactional(rollbackFor = Exception.class) + public AjaxResult bind(IotDto iotDto) { + if (iotDto == null || iotDto.getIotId() == null || iotDto.getMaCode() == null) { + return AjaxResult.error(ExceptionEnum.PARAM_NULL.getCode(), ExceptionEnum.PARAM_NULL.getMsg()); + } + iotDto.setBinder(SecurityUtils.getLoginUser().getUserid().toString()); + int res; + try { + //绑定设备 + res = iotMachineMapper.bind(iotDto); + if (res == 0) { + throw new RuntimeException(ExceptionEnum.BIND_TO_DATABASE.getMsg()); + } + //更新绑定状态 + res = iotMachineMapper.updateBindStatus(iotDto); + if (res == 0) { + throw new RuntimeException(ExceptionEnum.UPDATE_TO_DATABASE.getMsg()); + } + } catch (Exception e) { + log.error("设备绑定异常:{}", e.getMessage()); + // 添加事务回滚逻辑,保证全部成功或者全部失败 + TransactionAspectSupport.currentTransactionStatus().setRollbackOnly(); + return AjaxResult.error(ExceptionEnum.UPDATE_TO_DATABASE.getCode(), ExceptionEnum.UPDATE_TO_DATABASE.getMsg()); + } + return AjaxResult.success(ExceptionEnum.SUCCESS.getMsg(), res); + } + + /** + * 解绑设备 + * + * @param iotDto + * @return + */ + @Override + @Transactional(rollbackFor = Exception.class) + public AjaxResult unbind(IotDto iotDto) { + if (iotDto == null || iotDto.getIotId() == null) { + return AjaxResult.error(ExceptionEnum.PARAM_NULL.getCode(), ExceptionEnum.PARAM_NULL.getMsg()); + } + iotDto.setUnBinder(SecurityUtils.getLoginUser().getUserid().toString()); + int res; + try { + //解绑设备 + res = iotMachineMapper.unbind(iotDto); + if (res == 0) { + throw new RuntimeException(ExceptionEnum.UN_BIND_TO_DATABASE.getMsg()); + } + //更新绑定状态 + res = iotMachineMapper.updateUnBindStatus(iotDto); + if (res == 0) { + throw new RuntimeException(ExceptionEnum.UPDATE_TO_DATABASE.getMsg()); + } + } catch (Exception e) { + log.error("设备解绑异常:{}", e.getMessage()); + // 添加事务回滚逻辑,保证入库全部成功或者全部失败 + TransactionAspectSupport.currentTransactionStatus().setRollbackOnly(); + return AjaxResult.error(ExceptionEnum.UPDATE_TO_DATABASE.getCode(), ExceptionEnum.UPDATE_TO_DATABASE.getMsg()); + } + return AjaxResult.success(ExceptionEnum.SUCCESS.getMsg(), res); + } + + /** + * 根据类型id查询设备绑定列表 + * + * @param iotDto + * @return + */ + @Override + public List getTypeList(IotDto iotDto) { + if (iotDto == null || iotDto.getMaCode() == null) { + throw new RuntimeException(ExceptionEnum.PARAM_NULL.getMsg()); + } + return iotMachineMapper.getTypeList(iotDto); + } + + /** + * 根据iot设备类型查询设备编码 + * + * @param iotDto + * @return + */ + @Override + public AjaxResult selectList(IotDto iotDto) { + if (iotDto != null && iotDto.getIotTypeId() != null) { + // 如果传入了iot设备类型,根据iot设备类型查询设备编码 + List iotCodeList = iotMachineMapper.selectCodeList(iotDto.getIotTypeId()); + return AjaxResult.success(iotCodeList); + } else { + // 如果iotDto为null或者iotDto的iotType为null,单独查询iot设备类型列表 + List iotTypeList = iotMachineMapper.selectList(); + return AjaxResult.success(iotTypeList); + } + } + + /** + * 查询iot绑定记录 + * + * @param iotDto + * @return + */ + @Override + public List getRecordList(IotDto iotDto) { + if (iotDto == null || iotDto.getIotId() == null) { + throw new RuntimeException(ExceptionEnum.PARAM_NULL.getMsg()); + } + return iotMachineMapper.getRecordList(iotDto); + } + + /** + * 获取定位 + * @param iotDto + * @return + */ + @Override + public AjaxResult getLocation(IotDto iotDto) { + log.info("getLocation:{}", iotDto); + if (iotDto == null || iotDto.getIotId() == null) { + throw new RuntimeException(ExceptionEnum.PARAM_NULL.getMsg()); + } + List list=new ArrayList<>(); + Map map=new HashMap<>(); + //从redis中获取token + String redisCode = redisService.getCacheObject(TokenConstants.TOKEN_LOCATION); + //如果token为空,先去调登录接口,获取token + if (redisCode == null){ + redisCode = HttpHelper.getIotToken(); + redisService.setCacheObject(TokenConstants.TOKEN_LOCATION,redisCode,23L, TimeUnit.HOURS); + } + map.clear(); + list.add(iotDto.getIotId().toString()); + map.put("deviceids",list); + String param = JSON.toJSONString(map); + String res = HttpHelper.doPost("http://gps51.com/webapi?action=lastposition&token="+redisCode,param); + //对返回的结果进行解析 + IotLocationVo iotLocationVo = resultDataHandler(res); + log.info("resultDataHandler:{}", iotLocationVo); + return AjaxResult.success(iotLocationVo); + } + + /** + * 查询行程 + * @param iotLocationVo + * @return + */ + @Override + public AjaxResult searchItinerary(IotLocationVo iotLocationVo) { + log.info("searchItinerary:{}", iotLocationVo); + if (iotLocationVo == null || iotLocationVo.getBeginTime() == null || iotLocationVo.getEndTime() == null) { + throw new RuntimeException(ExceptionEnum.PARAM_NULL.getMsg()); + } + Map map=new HashMap<>(); + //从redis中获取token + String redisCode = redisService.getCacheObject(TokenConstants.TOKEN_LOCATION); + //如果token为空,先去调登录接口,获取token + if (redisCode == null){ + redisCode = HttpHelper.getIotToken(); + redisService.setCacheObject(TokenConstants.TOKEN_LOCATION,redisCode,23L, TimeUnit.HOURS); + } + map.clear(); + map.put("deviceid",iotLocationVo.getIotId()); + map.put("begintime",iotLocationVo.getBeginTime()); + map.put("endtime",iotLocationVo.getEndTime()); + String param = JSON.toJSONString(map); + String res = HttpHelper.doPost("http://gps51.com/webapi?action=querytrips&token="+redisCode,param); + return AjaxResult.success(res); + } + + /** + * 查询停留点 + * @param iotLocationVo + * @return + */ + @Override + public AjaxResult reportParkDetailByTime(IotLocationVo iotLocationVo) { + + log.info("reportParkDetailByTime:{}", iotLocationVo); + if (iotLocationVo == null || iotLocationVo.getBeginTime() == null || iotLocationVo.getEndTime() == null) { + throw new RuntimeException(ExceptionEnum.PARAM_NULL.getMsg()); + } + Map map=new HashMap<>(); + //从redis中获取token + String redisCode = redisService.getCacheObject(TokenConstants.TOKEN_LOCATION); + //如果token为空,先去调登录接口,获取token + if (redisCode == null){ + redisCode = HttpHelper.getIotToken(); + redisService.setCacheObject(TokenConstants.TOKEN_LOCATION,redisCode,23L, TimeUnit.HOURS); + } + map.clear(); + map.put("deviceid",iotLocationVo.getIotId()); + map.put("begintime",iotLocationVo.getBeginTime()); + map.put("endtime",iotLocationVo.getEndTime()); + String param = JSON.toJSONString(map); + String res = HttpHelper.doPost("http://gps51.com/webapi?action=reportparkdetailbytime&token="+redisCode,param); + //对返回的结果进行解析 + List iotLocationVoList = resultReportParkDetailByTime(res); + log.info("resultDataHandler:{}", iotLocationVo); + return AjaxResult.success(iotLocationVoList); + } + + /** + * 解析停留点返回报文 + * @param res + * @return + */ + private List resultReportParkDetailByTime(String res) { + if (res == null) { + throw new RuntimeException(ExceptionEnum.RETURN_DATA_IS_EMPTY.getMsg()); + } + List iotLocationVoList = new ArrayList<>(); + JSONObject object = JSONObject.parseObject(res); + String cause = object.getString("cause"); + String status = object.getString("status"); + if ("OK".equals(cause) && "0".equals(status)) { + String records = object.getString("records"); + //判断返回结果是否为空 + if (records != null){ + JSONArray jsonArray = JSON.parseArray(records); + for (int i = 0; i < jsonArray.size(); i++) { + IotLocationVo iotLocationVo = new IotLocationVo(); + JSONObject jsonObject = JSONObject.from(jsonArray.getJSONObject(i)); + iotLocationVo.setBeginTime(jsonObject.getString("starttime")); + iotLocationVo.setEndTime(jsonObject.getString("endtime")); + iotLocationVo.setAddress(jsonObject.getString("address")); + iotLocationVoList.add(iotLocationVo); + } + } + } + return iotLocationVoList; + } + + /** + * 绑定设备APP + * @param iotDto + * @return + */ + @Override + @Transactional(rollbackFor = Exception.class) + public AjaxResult bindApp(IotDto iotDto) { + if (iotDto == null || iotDto.getIotCode() == null || iotDto.getMaCode() == null) { + return AjaxResult.error(ExceptionEnum.PARAM_NULL.getCode(), ExceptionEnum.PARAM_NULL.getMsg()); + } + + iotDto.setBinder(SecurityUtils.getLoginUser().getUserid().toString()); + //根据输入的iot编码查询iot设备 + IotVo iotVo = iotMachineMapper.selectIotCode(iotDto); + if (iotVo == null) { + return AjaxResult.error(ExceptionEnum.IOT_ENCODING_ERROR.getCode(), ExceptionEnum.IOT_ENCODING_ERROR.getMsg()); + } + iotDto.setIotId(iotVo.getIotId()); + int res; + try { + //绑定设备 + res = iotMachineMapper.bind(iotDto); + if (res == 0) { + throw new RuntimeException(ExceptionEnum.BIND_TO_DATABASE.getMsg()); + } + //更新绑定状态 + res = iotMachineMapper.updateBindStatus(iotDto); + if (res == 0) { + throw new RuntimeException(ExceptionEnum.UPDATE_TO_DATABASE.getMsg()); + } + } catch (Exception e) { + log.error("设备绑定异常:{}", e.getMessage()); + // 添加事务回滚逻辑,保证全部成功或者全部失败 + TransactionAspectSupport.currentTransactionStatus().setRollbackOnly(); + return AjaxResult.error(ExceptionEnum.UPDATE_TO_DATABASE.getCode(), ExceptionEnum.UPDATE_TO_DATABASE.getMsg()); + } + return AjaxResult.success(ExceptionEnum.SUCCESS.getMsg(), res); + } + + /** + * 报警记录 + * @param iotLocationVo + * @return + */ + @Override + public AjaxResult reportAlarm(IotLocationVo iotLocationVo) { + log.info("reportAlarm:{}", iotLocationVo); + if (iotLocationVo == null || iotLocationVo.getIotId() == null || iotLocationVo.getBeginTime() == null || iotLocationVo.getEndTime() == null) { + throw new RuntimeException(ExceptionEnum.PARAM_NULL.getMsg()); + } + + Map map=new HashMap<>(); + List list=new ArrayList<>(); + //从redis中获取token + String redisCode = redisService.getCacheObject(TokenConstants.TOKEN_LOCATION); + //如果token为空,先去调登录接口,获取token + if (redisCode == null){ + redisCode = HttpHelper.getIotToken(); + redisService.setCacheObject(TokenConstants.TOKEN_LOCATION,redisCode,23L, TimeUnit.HOURS); + } + map.clear(); + list.add(iotLocationVo.getIotId().toString()); + map.put("devices",list); + map.put("startday",iotLocationVo.getBeginTime()); + map.put("endday",iotLocationVo.getEndTime()); + //报警类型 + map.put("needalarm",""); + String param = JSON.toJSONString(map); + String res = HttpHelper.doPost("http://gps51.com/webapi?action=reportalarm&token="+redisCode,param); + //对返回的结果进行解析 + List iotLocationVoList = resultReportAlarm(res); + log.info("resultDataHandler:{}", iotLocationVo); + return AjaxResult.success(iotLocationVoList); + } + + /** + * 解析报警返回报文 + * @param res + * @return + */ + private List resultReportAlarm(String res) { + if (res == null) { + throw new RuntimeException(ExceptionEnum.RETURN_DATA_IS_EMPTY.getMsg()); + } + List iotLocationVoList = new ArrayList<>(); + JSONObject object = JSONObject.parseObject(res); + String cause = object.getString("cause"); + String status = object.getString("status"); + if ("OK".equals(cause) && "0".equals(status)) { + String records = object.getString("alarmrecords"); + //判断返回结果是否为空 + if (records != null){ + JSONArray jsonArray = JSON.parseArray(records); + for (int i = 0; i < jsonArray.size(); i++) { + JSONObject jsonObject = JSONObject.from(jsonArray.getJSONObject(i)); + IotLocationVo iotLocationVo = new IotLocationVo(); + iotLocationVo.setStartAlarmTime(jsonObject.getString("startalarmtime")); + iotLocationVo.setStartAlarm(jsonObject.getString("stralarm")); + iotLocationVoList.add(iotLocationVo); + } + } + } + return iotLocationVoList; + } + + + /** + * 解析定位返回报文 + * @param res + * @return + */ + private IotLocationVo resultDataHandler(String res) { + if (res == null) { + throw new RuntimeException(ExceptionEnum.RETURN_DATA_IS_EMPTY.getMsg()); + } + IotLocationVo iotLocationVo = new IotLocationVo(); + JSONObject object = JSONObject.parseObject(res); + String status = object.getString("status"); + String cause = object.getString("cause"); + if ("0".equals(status) && "OK".equals(cause)) { + String records = object.getString("records"); + //判断返回结果是否为空 + if (records != null){ + JSONArray jsonArray = JSON.parseArray(records); + for (int i = 0; i < jsonArray.size(); i++) { + JSONObject jsonObject = JSONObject.from(jsonArray.getJSONObject(i)); + iotLocationVo.setIotId(StringHelper.conversionLong(jsonObject.getString("deviceid"))); + iotLocationVo.setCallat(StringHelper.conversionBigDecimal(jsonObject.getString("callat"))); + iotLocationVo.setCallon(StringHelper.conversionBigDecimal(jsonObject.getString("callon"))); + } + } + } + return iotLocationVo; + } + + + + + +} diff --git a/sgzb-modules/sgzb-material/src/main/resources/mapper/material/IotMachineMapper.xml b/sgzb-modules/sgzb-material/src/main/resources/mapper/material/IotMachineMapper.xml new file mode 100644 index 00000000..d6fa5f6a --- /dev/null +++ b/sgzb-modules/sgzb-material/src/main/resources/mapper/material/IotMachineMapper.xml @@ -0,0 +1,211 @@ + + + + + + insert into iot_machine + + iot_type, + iot_code, + iot_status, + qr_code, + bind_status, + del_flag, + create_by, + create_time + + + #{iotType}, + #{iotCode}, + 0, + #{qrCode}, + 1, + 0, + #{createBy}, + NOW() + + + + + insert into iot_machine_bind + + iot_id, + type_id, + ma_code, + binder, + bind_time + + + #{iotId}, + #{typeId}, + #{maCode}, + #{binder}, + NOW() + + + + + UPDATE iot_machine + + iot_type = #{iotType}, + iot_code = #{iotCode}, + iot_status = #{iotStatus}, + update_by = #{updateBy}, + update_time = NOW() + + WHERE id = #{iotId} + + + + UPDATE iot_machine SET del_flag = '2' WHERE id = #{iotId} + + + UPDATE iot_machine SET bind_status = '0', update_time = NOW() WHERE id = #{iotId} + + + UPDATE iot_machine_bind SET unbinder = #{unBinder}, unbind_time = NOW() WHERE id = #{id} + + + UPDATE iot_machine SET bind_status = '1', update_time = NOW() WHERE id = #{iotId} + + + + + + + + + + + + + \ No newline at end of file