From ad3fa87564cb16ffb1a310119232dc420c90b0fe Mon Sep 17 00:00:00 2001 From: ma <1062634917@qq.com> Date: Wed, 12 May 2021 14:43:58 +0800 Subject: [PATCH] =?UTF-8?q?=E5=9B=AD=E5=8C=BA=E8=AE=BE=E5=A4=87=E5=A2=9E?= =?UTF-8?q?=E5=8A=A0=E6=91=84=E5=83=8F=E5=A4=B4=E5=9C=B0=E5=9D=80=E5=AD=97?= =?UTF-8?q?=E6=AE=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ccsens/logistics/api/DebugController.java | 32 +++--- .../ccsens/logistics/bean/dto/HttpDto.java | 22 ++++ .../bean/po/LogisticsParkEquipment.java | 11 ++ .../po/LogisticsParkEquipmentExample.java | 70 ++++++++++++ .../ccsens/logistics/service/HttpService.java | 106 ++++++++++++++++++ .../logistics/service/IHttpService.java | 13 +++ .../LogisticsParkEquipmentMapper.xml | 28 ++++- 7 files changed, 263 insertions(+), 19 deletions(-) create mode 100644 logistics/src/main/java/com/ccsens/logistics/bean/dto/HttpDto.java create mode 100644 logistics/src/main/java/com/ccsens/logistics/service/HttpService.java create mode 100644 logistics/src/main/java/com/ccsens/logistics/service/IHttpService.java diff --git a/logistics/src/main/java/com/ccsens/logistics/api/DebugController.java b/logistics/src/main/java/com/ccsens/logistics/api/DebugController.java index 9de023ec..d16eb76e 100644 --- a/logistics/src/main/java/com/ccsens/logistics/api/DebugController.java +++ b/logistics/src/main/java/com/ccsens/logistics/api/DebugController.java @@ -5,6 +5,8 @@ import com.ccsens.logistics.bean.po.LogisticsCarRecord; import com.ccsens.logistics.bean.po.LogisticsEnvironmentRecord; import com.ccsens.logistics.persist.dao.LogisticsCarRecordDao; import com.ccsens.logistics.persist.dao.LogisticsEnvironmentRecordDao; +import com.ccsens.logistics.service.HttpService; +import com.ccsens.logistics.service.IHttpService; import com.ccsens.util.JsonResponse; import io.swagger.annotations.Api; import io.swagger.annotations.ApiImplicitParams; @@ -27,26 +29,28 @@ public class DebugController { private LogisticsCarRecordDao carRecordDao; @Resource private Snowflake snowflake; + @Resource + private IHttpService iHttpService; @ApiOperation(value = "/测试添加假数据",notes = "") @ApiImplicitParams({ }) @RequestMapping(value="",produces = {"application/json;charset=UTF-8"}) public JsonResponse getSmsCode(HttpServletRequest request) throws Exception { - Long currentTime = 1620632535000L; - for (int i = 0; i < 100; i++) { - Byte carType = Math.random()*10 < 5 ? (byte)0 :(byte) 1; - LogisticsCarRecord logisticsCarRecord = new LogisticsCarRecord(); - logisticsCarRecord.setId(snowflake.nextId()); - logisticsCarRecord.setCarWeight(RandomUtils.nextLong(1,9)); - logisticsCarRecord.setLicensePlate("未知"); - logisticsCarRecord.setCarType(carType); - logisticsCarRecord.setInOut(carType); - logisticsCarRecord.setRecordTime(currentTime); - currentTime = currentTime-86400000; - carRecordDao.insertSelective(logisticsCarRecord); - } - +// Long currentTime = 1620632535000L; +// for (int i = 0; i < 100; i++) { +// Byte carType = Math.random()*10 < 5 ? (byte)0 :(byte) 1; +// LogisticsCarRecord logisticsCarRecord = new LogisticsCarRecord(); +// logisticsCarRecord.setId(snowflake.nextId()); +// logisticsCarRecord.setCarWeight(RandomUtils.nextLong(1,9)); +// logisticsCarRecord.setLicensePlate("未知"); +// logisticsCarRecord.setCarType(carType); +// logisticsCarRecord.setInOut(carType); +// logisticsCarRecord.setRecordTime(currentTime); +// currentTime = currentTime-86400000; +// carRecordDao.insertSelective(logisticsCarRecord); +// } + iHttpService.getTemperatureAndHumidity(); return JsonResponse.newInstance().ok("测试"); } diff --git a/logistics/src/main/java/com/ccsens/logistics/bean/dto/HttpDto.java b/logistics/src/main/java/com/ccsens/logistics/bean/dto/HttpDto.java new file mode 100644 index 00000000..803d9b24 --- /dev/null +++ b/logistics/src/main/java/com/ccsens/logistics/bean/dto/HttpDto.java @@ -0,0 +1,22 @@ +package com.ccsens.logistics.bean.dto; + +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +/** + * @author 马 + */ +@Data +public class HttpDto { + + @Data + @ApiModel("温湿度登录接口") + public static class Login{ + @ApiModelProperty("账号") + private String loginName; + @ApiModelProperty("密码") + private String password; + } + +} diff --git a/logistics/src/main/java/com/ccsens/logistics/bean/po/LogisticsParkEquipment.java b/logistics/src/main/java/com/ccsens/logistics/bean/po/LogisticsParkEquipment.java index 6e8d8d8d..969d1d0a 100644 --- a/logistics/src/main/java/com/ccsens/logistics/bean/po/LogisticsParkEquipment.java +++ b/logistics/src/main/java/com/ccsens/logistics/bean/po/LogisticsParkEquipment.java @@ -14,6 +14,8 @@ public class LogisticsParkEquipment implements Serializable { private Long parkId; + private String equipmentLocation; + private Date createdAt; private Date updatedAt; @@ -62,6 +64,14 @@ public class LogisticsParkEquipment implements Serializable { this.parkId = parkId; } + public String getEquipmentLocation() { + return equipmentLocation; + } + + public void setEquipmentLocation(String equipmentLocation) { + this.equipmentLocation = equipmentLocation == null ? null : equipmentLocation.trim(); + } + public Date getCreatedAt() { return createdAt; } @@ -97,6 +107,7 @@ public class LogisticsParkEquipment implements Serializable { sb.append(", equipmentNumber=").append(equipmentNumber); sb.append(", equipmentType=").append(equipmentType); sb.append(", parkId=").append(parkId); + sb.append(", equipmentLocation=").append(equipmentLocation); sb.append(", createdAt=").append(createdAt); sb.append(", updatedAt=").append(updatedAt); sb.append(", recStatus=").append(recStatus); diff --git a/logistics/src/main/java/com/ccsens/logistics/bean/po/LogisticsParkEquipmentExample.java b/logistics/src/main/java/com/ccsens/logistics/bean/po/LogisticsParkEquipmentExample.java index ad3cd99c..c4febe80 100644 --- a/logistics/src/main/java/com/ccsens/logistics/bean/po/LogisticsParkEquipmentExample.java +++ b/logistics/src/main/java/com/ccsens/logistics/bean/po/LogisticsParkEquipmentExample.java @@ -425,6 +425,76 @@ public class LogisticsParkEquipmentExample { return (Criteria) this; } + public Criteria andEquipmentLocationIsNull() { + addCriterion("equipment_location is null"); + return (Criteria) this; + } + + public Criteria andEquipmentLocationIsNotNull() { + addCriterion("equipment_location is not null"); + return (Criteria) this; + } + + public Criteria andEquipmentLocationEqualTo(String value) { + addCriterion("equipment_location =", value, "equipmentLocation"); + return (Criteria) this; + } + + public Criteria andEquipmentLocationNotEqualTo(String value) { + addCriterion("equipment_location <>", value, "equipmentLocation"); + return (Criteria) this; + } + + public Criteria andEquipmentLocationGreaterThan(String value) { + addCriterion("equipment_location >", value, "equipmentLocation"); + return (Criteria) this; + } + + public Criteria andEquipmentLocationGreaterThanOrEqualTo(String value) { + addCriterion("equipment_location >=", value, "equipmentLocation"); + return (Criteria) this; + } + + public Criteria andEquipmentLocationLessThan(String value) { + addCriterion("equipment_location <", value, "equipmentLocation"); + return (Criteria) this; + } + + public Criteria andEquipmentLocationLessThanOrEqualTo(String value) { + addCriterion("equipment_location <=", value, "equipmentLocation"); + return (Criteria) this; + } + + public Criteria andEquipmentLocationLike(String value) { + addCriterion("equipment_location like", value, "equipmentLocation"); + return (Criteria) this; + } + + public Criteria andEquipmentLocationNotLike(String value) { + addCriterion("equipment_location not like", value, "equipmentLocation"); + return (Criteria) this; + } + + public Criteria andEquipmentLocationIn(List values) { + addCriterion("equipment_location in", values, "equipmentLocation"); + return (Criteria) this; + } + + public Criteria andEquipmentLocationNotIn(List values) { + addCriterion("equipment_location not in", values, "equipmentLocation"); + return (Criteria) this; + } + + public Criteria andEquipmentLocationBetween(String value1, String value2) { + addCriterion("equipment_location between", value1, value2, "equipmentLocation"); + return (Criteria) this; + } + + public Criteria andEquipmentLocationNotBetween(String value1, String value2) { + addCriterion("equipment_location not between", value1, value2, "equipmentLocation"); + return (Criteria) this; + } + public Criteria andCreatedAtIsNull() { addCriterion("created_at is null"); return (Criteria) this; diff --git a/logistics/src/main/java/com/ccsens/logistics/service/HttpService.java b/logistics/src/main/java/com/ccsens/logistics/service/HttpService.java new file mode 100644 index 00000000..f437be2a --- /dev/null +++ b/logistics/src/main/java/com/ccsens/logistics/service/HttpService.java @@ -0,0 +1,106 @@ +package com.ccsens.logistics.service; + +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONObject; +import com.ccsens.logistics.bean.dto.HttpDto; +import com.ccsens.util.CodeEnum; +import com.ccsens.util.JsonResponse; +import com.ccsens.util.PropUtil; +import com.ccsens.util.RestTemplateUtil; +import com.ccsens.util.exception.BaseException; +import lombok.extern.slf4j.Slf4j; +import org.apache.http.Header; +import org.apache.http.HttpResponse; +import org.apache.http.client.ClientProtocolException; +import org.apache.http.client.HttpClient; +import org.apache.http.client.methods.HttpGet; +import org.apache.http.impl.client.CloseableHttpClient; +import org.apache.http.impl.client.HttpClients; +import org.apache.http.util.EntityUtils; +import org.apache.http.HttpEntity; +import org.springframework.http.ResponseEntity; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Propagation; +import org.springframework.transaction.annotation.Transactional; + +import java.io.IOException; +import java.net.URI; +import java.net.URISyntaxException; +import java.util.Arrays; +import java.util.Map; + +/** + * @author 马 + */ +@Slf4j +@Service +@Transactional(propagation = Propagation.REQUIRED,rollbackFor = Exception.class) +public class HttpService implements IHttpService{ + + @Override + public void getTemperatureAndHumidity() { + try { + HttpDto.Login login = new HttpDto.Login(); + login.setLoginName("jnrstest"); + login.setPassword("jnrstest321"); + //调取登录接口 获取userId + String userId = getUserId(login); + String body = getBody(userId); + + }catch (Exception e){ + e.printStackTrace(); + } + + } + + /** + * 温湿度登录接口 获取设备的userId 调用其他接口 + * @param login 账号密码 + * @return userId + */ + public String getUserId(HttpDto.Login login){ + String requestUrl = "http://www.0531yun.cn/wsjc/app/Login"; + String s = RestTemplateUtil.postBody(requestUrl, login); + JsonResponse a = JSONObject.parseObject(s, JsonResponse.class); + JSONObject data = a.getData(); + String userId = data.getString("userId"); + return userId; + } + + + + public static String getBody(String userId) throws IOException { + try { + String url = "http://www.0531yun.cn/app/GetUserDeviceGroups"; + HttpGet get = new HttpGet(url); + get.setHeader("userId",userId); + HttpClient httpClient = HttpClients.createDefault(); + HttpResponse response = httpClient.execute(get); + return getResult(response); + } catch (ClientProtocolException e) { + e.printStackTrace(); + } catch (IOException e) { + e.printStackTrace(); + } + return null; + } + + public static String getResult(HttpResponse response) throws IOException { + // 获取状态码 + int code = response.getStatusLine().getStatusCode(); + System.out.println(code); + // 获取body + HttpEntity entity = response.getEntity(); + String body = EntityUtils.toString(entity); + System.out.println(body); + // 获取头信息 + Header[] allHeaders = response.getAllHeaders(); + String headers = Arrays.toString(allHeaders); + System.out.println(headers); + + // 返回body + return body; + } + + +} diff --git a/logistics/src/main/java/com/ccsens/logistics/service/IHttpService.java b/logistics/src/main/java/com/ccsens/logistics/service/IHttpService.java new file mode 100644 index 00000000..4e14506f --- /dev/null +++ b/logistics/src/main/java/com/ccsens/logistics/service/IHttpService.java @@ -0,0 +1,13 @@ +package com.ccsens.logistics.service; + +/** + * @author 马 + */ +public interface IHttpService { + + /** + * 获取温度和湿度 + */ + void getTemperatureAndHumidity(); + +} diff --git a/logistics/src/main/resources/mapper_raw/LogisticsParkEquipmentMapper.xml b/logistics/src/main/resources/mapper_raw/LogisticsParkEquipmentMapper.xml index 96520adf..7d477b5c 100644 --- a/logistics/src/main/resources/mapper_raw/LogisticsParkEquipmentMapper.xml +++ b/logistics/src/main/resources/mapper_raw/LogisticsParkEquipmentMapper.xml @@ -7,6 +7,7 @@ + @@ -70,7 +71,8 @@ - id, name, equipment_number, equipment_type, park_id, created_at, updated_at, rec_status + id, name, equipment_number, equipment_type, park_id, equipment_location, created_at, + updated_at, rec_status