对南网的代码进行迁移
This commit is contained in:
parent
d5fc6ef059
commit
4979f4392e
|
|
@ -243,5 +243,9 @@ public class MaMachine extends BaseEntity {
|
|||
/** 导出选中列表 */
|
||||
private List<Long> dataCondition;
|
||||
|
||||
@ApiModelProperty(value = "绑定IOT设备数量")
|
||||
private Integer IotNum;
|
||||
|
||||
@ApiModelProperty(value = "Iot定位设备编号")
|
||||
private String iotCode;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -118,6 +118,10 @@
|
|||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.httpcomponents</groupId>
|
||||
<artifactId>httpclient</artifactId>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
|
|
|
|||
|
|
@ -22,4 +22,9 @@ public class TokenConstants
|
|||
*/
|
||||
public final static String SECRET = "abcdefghijklmnopqrstuvwxyz";
|
||||
|
||||
/**
|
||||
* IOT设备登录token有效期
|
||||
*/
|
||||
public static final String TOKEN_LOCATION = "token_location";
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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<String,Object> 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;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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<BmProjectLotImport> util = new ExcelUtil<>(BmProjectLotImport.class);
|
||||
List<BmProjectLotImport> bmProjectLotList = util.importExcel(file.getInputStream());
|
||||
String message = bmProjectLotService.importBmProjectLot(bmProjectLotList);
|
||||
return success(message);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
|
@ -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;
|
||||
|
||||
}
|
||||
|
|
@ -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);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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<IotRecordVo> selectList(@Param("maCode") String maCode);
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -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<BmProjectLotImport> bmProjectLotImportList);
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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<BmProjectLotImport> bmProjectLotImportList) {
|
||||
log.info("BmProjectLotServiceImpl importBmProjectLot 导入开始------");
|
||||
if (bmProjectLotImportList.isEmpty())
|
||||
{
|
||||
throw new ServiceException("导入项目管理数据不能为空!");
|
||||
}
|
||||
//保存项目管理
|
||||
for (BmProjectLotImport bmProjectLotImport: bmProjectLotImportList) {
|
||||
bmProjectLotMapper.projectLotImport(bmProjectLotImport);
|
||||
}
|
||||
log.info("BmProjectLotServiceImpl importBmProjectLot 导入结束------");
|
||||
return "导入成功";
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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<MaMachine> getMaMachine(MaMachine maMachine) {
|
||||
return maMachineMapper.getMaMachine(maMachine);
|
||||
List<MaMachine> listMaMachine = new ArrayList<>();
|
||||
listMaMachine =maMachineMapper.getMaMachine(maMachine);
|
||||
if (listMaMachine.size() > 0){
|
||||
for (MaMachine ma : listMaMachine) {
|
||||
//根据机具编码查询iot设备
|
||||
List<IotRecordVo> 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;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -133,6 +133,78 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||
sysdate()
|
||||
)
|
||||
</insert>
|
||||
|
||||
<insert id="projectLotImport">
|
||||
insert into bm_project_lot (
|
||||
<if test="examineStatus != null and examineStatus != '' ">examine_status,</if>
|
||||
<if test="createTime != null and createTime != '' ">create_time,</if>
|
||||
<if test="projectCategory != null and projectCategory != '' ">project_category,</if>
|
||||
<if test="lotName != null and lotName != '' ">lot_name,</if>
|
||||
<if test="lotCode != null and lotCode != '' ">lot_code,</if>
|
||||
<if test="isFrameworkProject != null and isFrameworkProject != '' ">is_framework_project,</if>
|
||||
<if test="isSubProject != null and isSubProject != ''">is_sub_project,</if>
|
||||
<if test="ownPro != null and ownPro != ''">own_pro,</if>
|
||||
<if test="ownProId != null and ownProId != ''">own_pro_Id,</if>
|
||||
<if test="projectStatus != null and projectStatus != ''">project_status,</if>
|
||||
<if test="businessSource != null and businessSource != ''">business_source,</if>
|
||||
<if test="voltageLevel != null and voltageLevel != ''">voltage_level,</if>
|
||||
<if test="linkMan != null and linkMan != ''">link_man,</if>
|
||||
<if test="constructionUnit != null and constructionUnit != ''">construction_unit,</if>
|
||||
<if test="implementationUnit != null and implementationUnit != ''">implementation_unit,</if>
|
||||
<if test="department != null and department != ''">department,</if>
|
||||
<if test="creatorCompany != null and creatorCompany != ''">creator_company,</if>
|
||||
<if test="designUnit != null and designUnit != ''">design_unit,</if>
|
||||
<if test="constructionControlUnit != null and constructionControlUnit != ''">construction_control_unit,</if>
|
||||
<if test="plannedStartDate != null and plannedStartDate != ''">planned_start_date,</if>
|
||||
<if test="plannedCompletionDate != null and plannedCompletionDate != ''">planned_completion_date,</if>
|
||||
<if test="projectCategoryId != null and projectCategoryId != ''">project_category_id,</if>
|
||||
<if test="constructionUnitId != null and constructionUnitId != ''">construction_unit_id,</if>
|
||||
<if test="implementationUnitId != null and implementationUnitId != ''">implementation_unit_id,</if>
|
||||
<if test="designUnitId != null and designUnitId != ''">design_unit_id,</if>
|
||||
<if test="constructionControlUnitId != null and constructionControlUnitId != ''">construction_control_unit_id,</if>
|
||||
<if test="projectLocation != null and projectLocation != ''">project_location,</if>
|
||||
<if test="projectLocationProvince != null and projectLocationProvince != ''">project_location_province,</if>
|
||||
<if test="projectLocationCity != null and projectLocationCity != ''">project_location_city,</if>
|
||||
<if test="endTime != null and endTime != ''">end_time,</if>
|
||||
<if test="constructionUnitType != null and constructionUnitType != ''">construction_unit_type,</if>
|
||||
<if test="constructionUnitCode != null and constructionUnitCode != ''">construction_unit_code</if>
|
||||
|
||||
) VALUES (
|
||||
<if test="examineStatus != null and examineStatus != '' ">#{examineStatus},</if>
|
||||
<if test="createTime != null and createTime != '' ">#{createTime},</if>
|
||||
<if test="projectCategory != null and projectCategory != '' ">#{projectCategory},</if>
|
||||
<if test="lotName != null and lotName != '' ">#{lotName},</if>
|
||||
<if test="lotCode != null and lotCode != '' ">#{lotCode},</if>
|
||||
<if test="isFrameworkProject != null and isFrameworkProject != '' ">#{isFrameworkProject},</if>
|
||||
<if test="isSubProject != null and isSubProject != ''">#{isSubProject},</if>
|
||||
<if test="ownPro != null and ownPro != ''">#{ownPro},</if>
|
||||
<if test="ownProId != null and ownProId != ''">#{ownProId},</if>
|
||||
<if test="projectStatus != null and projectStatus != ''">#{projectStatus},</if>
|
||||
<if test="businessSource != null and businessSource != ''">#{businessSource},</if>
|
||||
<if test="voltageLevel != null and voltageLevel != ''">#{voltageLevel},</if>
|
||||
<if test="linkMan != null and linkMan != ''">#{linkMan},</if>
|
||||
<if test="constructionUnit != null and constructionUnit != ''">#{constructionUnit},</if>
|
||||
<if test="implementationUnit != null and implementationUnit != ''">#{implementationUnit},</if>
|
||||
<if test="department != null and department != ''">#{department},</if>
|
||||
<if test="creatorCompany != null and creatorCompany != ''">#{creatorCompany},</if>
|
||||
<if test="designUnit != null and designUnit != ''">#{designUnit},</if>
|
||||
<if test="constructionControlUnit != null and constructionControlUnit != ''">#{constructionControlUnit},</if>
|
||||
<if test="plannedStartDate != null and plannedStartDate != ''">#{plannedStartDate},</if>
|
||||
<if test="plannedCompletionDate != null and plannedCompletionDate != ''">#{plannedCompletionDate},</if>
|
||||
<if test="projectCategoryId != null and projectCategoryId != ''">#{projectCategoryId},</if>
|
||||
<if test="constructionUnitId != null and constructionUnitId != ''">#{constructionUnitId},</if>
|
||||
<if test="implementationUnitId != null and implementationUnitId != ''">#{implementationUnitId},</if>
|
||||
<if test="designUnitId != null and designUnitId != ''">#{designUnitId},</if>
|
||||
<if test="constructionControlUnitId != null and constructionControlUnitId != ''">#{constructionControlUnitId},</if>
|
||||
<if test="projectLocation != null and projectLocation != ''">#{projectLocation},</if>
|
||||
<if test="projectLocationProvince != null and projectLocationProvince != ''">#{projectLocationProvince},</if>
|
||||
<if test="projectLocationCity != null and projectLocationCity != ''">#{projectLocationCity},</if>
|
||||
<if test="endTime != null and endTime != ''">#{endTime},</if>
|
||||
<if test="constructionUnitType != null and constructionUnitType != ''">#{constructionUnitType},</if>
|
||||
<if test="constructionUnitCode != null and constructionUnitCode != ''">#{constructionUnitCode}</if>
|
||||
|
||||
)
|
||||
</insert>
|
||||
|
||||
<update id="updateBmProjectLot" parameterType="com.bonus.sgzb.base.domain.BmProjectLot">
|
||||
update bm_project_lot
|
||||
|
|
|
|||
|
|
@ -0,0 +1,21 @@
|
|||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<!DOCTYPE mapper
|
||||
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.bonus.sgzb.base.mapper.IotMachineMapper">
|
||||
|
||||
|
||||
<select id="selectList" resultType="com.bonus.sgzb.base.domain.vo.IotRecordVo">
|
||||
SELECT
|
||||
im.iot_type,im.iot_code
|
||||
FROM
|
||||
iot_machine im
|
||||
left join iot_machine_bind imb on im.id = imb.iot_id
|
||||
WHERE
|
||||
imb.ma_code = #{maCode}
|
||||
AND im.bind_status='0'
|
||||
AND imb.unbinder IS NULL
|
||||
</select>
|
||||
|
||||
|
||||
</mapper>
|
||||
|
|
@ -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;
|
||||
|
||||
|
|
|
|||
|
|
@ -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<IotVo> 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<IotVo> 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<IotRecordVo> list = iotMachineService.getRecordList(iotDto);
|
||||
return getDataTable(list);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据iot设备获取绑定记录(全量不分页,供前端数据使用)
|
||||
* @param iotDto
|
||||
* @return
|
||||
*/
|
||||
@ApiOperation("根据iot设备获取绑定记录(全量不分页,供前端数据使用)")
|
||||
@GetMapping("/getRecordListAll")
|
||||
public AjaxResult getRecordListAll(IotDto iotDto) {
|
||||
List<IotRecordVo> 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);
|
||||
}
|
||||
}
|
||||
|
|
@ -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;
|
||||
}
|
||||
|
|
@ -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;
|
||||
|
||||
}
|
||||
|
|
@ -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;
|
||||
}
|
||||
|
|
@ -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;
|
||||
}
|
||||
|
|
@ -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;
|
||||
}
|
||||
|
|
@ -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;
|
||||
|
||||
}
|
||||
|
|
@ -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<IotVo> 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<IotVo> getTypeList(IotDto iotDto);
|
||||
|
||||
|
||||
/**
|
||||
* 查询设备类型
|
||||
* @return
|
||||
*/
|
||||
List<IotTypeVo> selectList();
|
||||
|
||||
/**
|
||||
* 根据iotTypeId查询设备编码
|
||||
* @param iotTypeId
|
||||
* @return
|
||||
*/
|
||||
List<IotCodeVo> selectCodeList(String iotTypeId);
|
||||
|
||||
/**
|
||||
* 根据iotTypeId查询设备编码
|
||||
* @param iotDto
|
||||
* @return
|
||||
*/
|
||||
List<IotRecordVo> getRecordList(IotDto iotDto);
|
||||
}
|
||||
|
|
@ -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<IotVo> 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<IotVo> getTypeList(IotDto iotDto);
|
||||
|
||||
/**
|
||||
* 根据iot设备类型查询设备编码
|
||||
* @param iotDto
|
||||
* @return
|
||||
*/
|
||||
AjaxResult selectList(IotDto iotDto);
|
||||
|
||||
/**
|
||||
* 获取设备记录列表
|
||||
* @param iotDto
|
||||
* @return
|
||||
*/
|
||||
List<IotRecordVo> 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);
|
||||
}
|
||||
|
|
@ -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<IotVo> 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<IotVo> 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<IotCodeVo> iotCodeList = iotMachineMapper.selectCodeList(iotDto.getIotTypeId());
|
||||
return AjaxResult.success(iotCodeList);
|
||||
} else {
|
||||
// 如果iotDto为null或者iotDto的iotType为null,单独查询iot设备类型列表
|
||||
List<IotTypeVo> iotTypeList = iotMachineMapper.selectList();
|
||||
return AjaxResult.success(iotTypeList);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询iot绑定记录
|
||||
*
|
||||
* @param iotDto
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public List<IotRecordVo> 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<String> list=new ArrayList<>();
|
||||
Map<String,Object> 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<String,Object> 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<String,Object> 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<IotLocationVo> iotLocationVoList = resultReportParkDetailByTime(res);
|
||||
log.info("resultDataHandler:{}", iotLocationVo);
|
||||
return AjaxResult.success(iotLocationVoList);
|
||||
}
|
||||
|
||||
/**
|
||||
* 解析停留点返回报文
|
||||
* @param res
|
||||
* @return
|
||||
*/
|
||||
private List<IotLocationVo> resultReportParkDetailByTime(String res) {
|
||||
if (res == null) {
|
||||
throw new RuntimeException(ExceptionEnum.RETURN_DATA_IS_EMPTY.getMsg());
|
||||
}
|
||||
List<IotLocationVo> 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<String,Object> map=new HashMap<>();
|
||||
List<String> 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<IotLocationVo> iotLocationVoList = resultReportAlarm(res);
|
||||
log.info("resultDataHandler:{}", iotLocationVo);
|
||||
return AjaxResult.success(iotLocationVoList);
|
||||
}
|
||||
|
||||
/**
|
||||
* 解析报警返回报文
|
||||
* @param res
|
||||
* @return
|
||||
*/
|
||||
private List<IotLocationVo> resultReportAlarm(String res) {
|
||||
if (res == null) {
|
||||
throw new RuntimeException(ExceptionEnum.RETURN_DATA_IS_EMPTY.getMsg());
|
||||
}
|
||||
List<IotLocationVo> 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;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,211 @@
|
|||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<!DOCTYPE mapper
|
||||
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.bonus.sgzb.material.mapper.IotMachineMapper">
|
||||
|
||||
<insert id="add">
|
||||
insert into iot_machine
|
||||
<trim prefix="(" suffix=")" suffixOverrides=",">
|
||||
<if test="iotType != null">iot_type,</if>
|
||||
<if test="iotCode != null and iotCode != ''">iot_code,</if>
|
||||
iot_status,
|
||||
<if test="qrCode != null">qr_code,</if>
|
||||
bind_status,
|
||||
del_flag,
|
||||
<if test="createBy != null">create_by,</if>
|
||||
create_time
|
||||
</trim>
|
||||
<trim prefix="values (" suffix=")" suffixOverrides=",">
|
||||
<if test="iotType != null">#{iotType},</if>
|
||||
<if test="iotCode != null and iotCode != ''">#{iotCode},</if>
|
||||
0,
|
||||
<if test="qrCode != null">#{qrCode},</if>
|
||||
1,
|
||||
0,
|
||||
<if test="createBy != null">#{createBy},</if>
|
||||
NOW()
|
||||
</trim>
|
||||
|
||||
</insert>
|
||||
<insert id="bind">
|
||||
insert into iot_machine_bind
|
||||
<trim prefix="(" suffix=")" suffixOverrides=",">
|
||||
<if test="iotId != null">iot_id,</if>
|
||||
<if test="typeId != null and typeId != ''">type_id,</if>
|
||||
<if test="maCode != null">ma_code,</if>
|
||||
<if test="binder != null">binder,</if>
|
||||
bind_time
|
||||
</trim>
|
||||
<trim prefix="values (" suffix=")" suffixOverrides=",">
|
||||
<if test="iotId != null">#{iotId},</if>
|
||||
<if test="typeId != null and typeId != ''">#{typeId},</if>
|
||||
<if test="maCode != null">#{maCode},</if>
|
||||
<if test="binder != null">#{binder},</if>
|
||||
NOW()
|
||||
</trim>
|
||||
</insert>
|
||||
|
||||
<update id="update">
|
||||
UPDATE iot_machine
|
||||
<trim prefix="SET" suffixOverrides=",">
|
||||
<if test="iotType != null ">iot_type = #{iotType},</if>
|
||||
<if test="iotCode != null">iot_code = #{iotCode},</if>
|
||||
<if test="iotStatus != null">iot_status = #{iotStatus},</if>
|
||||
<if test="updateBy != null">update_by = #{updateBy},</if>
|
||||
update_time = NOW()
|
||||
</trim>
|
||||
WHERE id = #{iotId}
|
||||
</update>
|
||||
|
||||
<update id="deleteById">
|
||||
UPDATE iot_machine SET del_flag = '2' WHERE id = #{iotId}
|
||||
</update>
|
||||
<update id="updateBindStatus">
|
||||
UPDATE iot_machine SET bind_status = '0', update_time = NOW() WHERE id = #{iotId}
|
||||
</update>
|
||||
<update id="unbind">
|
||||
UPDATE iot_machine_bind SET unbinder = #{unBinder}, unbind_time = NOW() WHERE id = #{id}
|
||||
</update>
|
||||
<update id="updateUnBindStatus">
|
||||
UPDATE iot_machine SET bind_status = '1', update_time = NOW() WHERE id = #{iotId}
|
||||
</update>
|
||||
|
||||
<select id="selectQrCode" resultType="java.lang.Integer">
|
||||
SELECT
|
||||
COUNT(*)
|
||||
FROM
|
||||
iot_machine
|
||||
WHERE
|
||||
del_flag = '0'
|
||||
AND qr_code = #{qrCode}
|
||||
</select>
|
||||
<select id="selectIotCode" resultType="com.bonus.sgzb.material.domain.IotVo">
|
||||
SELECT
|
||||
id AS iotId,
|
||||
iot_code AS iotCode,
|
||||
iot_type AS iotType,
|
||||
iot_status AS iotStatus,
|
||||
qr_code AS qrCode
|
||||
FROM
|
||||
iot_machine
|
||||
WHERE
|
||||
del_flag = '0'
|
||||
<if test="iotType != null and iotType != ''" >
|
||||
AND iot_type = #{iotType}
|
||||
</if>
|
||||
<if test="iotCode != null and iotCode != ''" >
|
||||
AND iot_code = #{iotCode}
|
||||
</if>
|
||||
</select>
|
||||
<select id="getIotList" resultType="com.bonus.sgzb.material.domain.IotVo">
|
||||
SELECT
|
||||
im.id AS iotId,
|
||||
im.iot_code AS iotCode,
|
||||
im.iot_type AS iotType,
|
||||
im.iot_status AS iotStatus,
|
||||
sd.name AS iotTypeName,
|
||||
im.qr_code AS qrCode,
|
||||
im.bind_status AS bindStatus
|
||||
FROM
|
||||
iot_machine im
|
||||
LEFT JOIN sys_dic sd on im.iot_type = sd.id
|
||||
WHERE
|
||||
del_flag = '0'
|
||||
<if test="keyWord != null and keyWord != ''">
|
||||
AND (iot_type like concat('%', #{keyWord}, '%') or
|
||||
iot_code like concat('%', #{keyWord}, '%')
|
||||
)
|
||||
</if>
|
||||
</select>
|
||||
<select id="selectById" resultType="com.bonus.sgzb.material.domain.IotVo">
|
||||
SELECT
|
||||
id AS iotId,
|
||||
iot_code AS iotCode,
|
||||
iot_type AS iotType,
|
||||
iot_status AS iotStatus,
|
||||
qr_code AS qrCode,
|
||||
bind_status AS bindStatus
|
||||
FROM
|
||||
iot_machine
|
||||
WHERE
|
||||
del_flag = '0'
|
||||
AND id = #{iotId}
|
||||
</select>
|
||||
<select id="getTypeList" resultType="com.bonus.sgzb.material.domain.IotVo">
|
||||
SELECT
|
||||
imb.id AS id,
|
||||
im.iot_type AS iotType,
|
||||
sd.name AS iotTypeName,
|
||||
im.iot_code AS iotCode,
|
||||
im.iot_status AS iotStatus,
|
||||
imb.iot_id AS iotId,
|
||||
imb.bind_time AS bindTime,
|
||||
im.bind_status AS bindStatus
|
||||
FROM
|
||||
iot_machine im
|
||||
LEFT JOIN sys_dic sd on im.iot_type = sd.id
|
||||
LEFT JOIN iot_machine_bind imb ON im.id = imb.iot_id
|
||||
WHERE
|
||||
im.del_flag = '0'
|
||||
AND im.bind_status = '0'
|
||||
AND imb.unbind_time IS NULL
|
||||
AND imb.ma_code = #{maCode}
|
||||
<if test="keyWord != null and keyWord != ''">
|
||||
AND (
|
||||
im.iot_type like concat('%', #{keyWord}, '%') or
|
||||
im.iot_code like concat('%', #{keyWord}, '%')
|
||||
)
|
||||
</if>
|
||||
</select>
|
||||
|
||||
<select id="selectList" resultType="com.bonus.sgzb.material.domain.IotTypeVo">
|
||||
SELECT
|
||||
id AS iotTypeId,
|
||||
p_id AS pId,
|
||||
name AS iotTypeName
|
||||
FROM
|
||||
sys_dic
|
||||
WHERE
|
||||
status = '0'
|
||||
AND p_id = '124'
|
||||
</select>
|
||||
<select id="selectCodeList" resultType="com.bonus.sgzb.material.domain.IotCodeVo">
|
||||
SELECT
|
||||
id AS iotId,
|
||||
iot_code AS iotCode
|
||||
FROM
|
||||
iot_machine
|
||||
WHERE
|
||||
del_flag = '0'
|
||||
AND iot_status = '0'
|
||||
AND bind_status = '1'
|
||||
AND iot_type = #{iotType}
|
||||
</select>
|
||||
<select id="getRecordList" resultType="com.bonus.sgzb.material.domain.IotRecordVo">
|
||||
SELECT
|
||||
imb.id AS id,
|
||||
mt1.type_name AS typeName,
|
||||
imb.ma_code AS maCode,
|
||||
imb.type_id AS typeId,
|
||||
imb.bind_time AS bindTime,
|
||||
imb.unbind_time AS unBindTime
|
||||
FROM
|
||||
iot_machine_bind imb
|
||||
LEFT JOIN ma_type mt ON imb.type_id = mt.type_id
|
||||
LEFT JOIN ma_type mt1 ON mt.parent_id = mt1.type_id
|
||||
LEFT JOIN ma_type mt2 ON mt1.parent_id = mt2.type_id
|
||||
LEFT JOIN ma_type mt3 ON mt2.parent_id = mt3.type_id
|
||||
LEFT JOIN iot_machine im ON imb.iot_id = im.id
|
||||
WHERE
|
||||
im.del_flag = '0'
|
||||
AND im.id = #{iotId}
|
||||
<if test="keyWord != null and keyWord != ''">
|
||||
AND (
|
||||
mt1.type_name like concat('%', #{keyWord}, '%') or
|
||||
imb.ma_code like concat('%', #{keyWord}, '%')
|
||||
)
|
||||
</if>
|
||||
</select>
|
||||
|
||||
</mapper>
|
||||
Loading…
Reference in New Issue