1、灌溉记录从php获取
2、设备接口改成无需权限获取
This commit is contained in:
@ -1,6 +1,8 @@
|
||||
package com.fastbee.waterele.service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.fastbee.common.core.page.TableDataInfo;
|
||||
import com.fastbee.waterele.domain.MaGuangaiRecord;
|
||||
|
||||
/**
|
||||
@ -25,7 +27,7 @@ public interface IMaGuangaiRecordService
|
||||
* @param maGuangaiRecord 灌溉记录
|
||||
* @return 灌溉记录集合
|
||||
*/
|
||||
public List<MaGuangaiRecord> selectMaGuangaiRecordList(MaGuangaiRecord maGuangaiRecord);
|
||||
public TableDataInfo selectMaGuangaiRecordList(MaGuangaiRecord maGuangaiRecord);
|
||||
|
||||
/**
|
||||
* 新增灌溉记录
|
||||
|
@ -1,13 +1,27 @@
|
||||
package com.fastbee.waterele.service.impl;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
import cn.hutool.http.HttpUtil;
|
||||
import cn.hutool.json.JSON;
|
||||
import cn.hutool.json.JSONArray;
|
||||
import cn.hutool.json.JSONObject;
|
||||
import com.fastbee.common.core.page.PageDomain;
|
||||
import com.fastbee.common.core.page.TableDataInfo;
|
||||
import com.fastbee.common.core.page.TableSupport;
|
||||
import com.fastbee.common.utils.DateUtils;
|
||||
import com.fastbee.common.utils.StringUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import com.fastbee.waterele.mapper.MaGuangaiRecordMapper;
|
||||
import com.fastbee.waterele.domain.MaGuangaiRecord;
|
||||
import com.fastbee.waterele.service.IMaGuangaiRecordService;
|
||||
|
||||
import static com.fastbee.common.utils.PageUtils.startPage;
|
||||
|
||||
/**
|
||||
* 灌溉记录Service业务层处理
|
||||
*
|
||||
@ -39,11 +53,99 @@ public class MaGuangaiRecordServiceImpl implements IMaGuangaiRecordService
|
||||
* @return 灌溉记录
|
||||
*/
|
||||
@Override
|
||||
public List<MaGuangaiRecord> selectMaGuangaiRecordList(MaGuangaiRecord maGuangaiRecord)
|
||||
public TableDataInfo selectMaGuangaiRecordList(MaGuangaiRecord maGuangaiRecord)
|
||||
{
|
||||
return maGuangaiRecordMapper.selectMaGuangaiRecordList(maGuangaiRecord);
|
||||
//
|
||||
Long endTime = 0L;
|
||||
Long startTime = 0L;
|
||||
if(null == maGuangaiRecord.getParams()){
|
||||
endTime = new Date().getTime()/1000;
|
||||
startTime = endTime - 86400*3;
|
||||
}else{
|
||||
if(!maGuangaiRecord.getParams().containsKey("endCreateTime")){
|
||||
endTime = new Date().getTime()/1000;
|
||||
}else{
|
||||
endTime = DateUtils.dateTime(DateUtils.YYYY_MM_DD_HH_MM_SS,
|
||||
maGuangaiRecord.getParams().get("endCreateTime").toString()).getTime();
|
||||
}
|
||||
if(!maGuangaiRecord.getParams().containsKey("beginCreateTime")){
|
||||
startTime = endTime - 86400*3;
|
||||
}else{
|
||||
startTime = DateUtils.dateTime(DateUtils.YYYY_MM_DD_HH_MM_SS,
|
||||
maGuangaiRecord.getParams().get("beginCreateTime").toString()).getTime();
|
||||
}
|
||||
}
|
||||
Date startDate = new Date();
|
||||
startDate.setTime(startTime*1000);
|
||||
String startDateStr = DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS,startDate);
|
||||
Date endDate = new Date();
|
||||
endDate.setTime(endTime*1000);
|
||||
String endDateStr = DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS,endDate);
|
||||
String url = "https://zhwly.sdhzwl.cn/api/java/xinjiangup/getGuangaiRecord?devSn="
|
||||
+maGuangaiRecord.getDevSn()+"&startTime="+startDateStr+"&endTime="+endDateStr;
|
||||
String result =HttpUtil.get(url);
|
||||
|
||||
JSONObject jsonObject = new JSONObject(result);
|
||||
List<MaGuangaiRecord> list = new ArrayList<>();
|
||||
if(jsonObject != null){
|
||||
if(jsonObject.containsKey("code") && Integer.parseInt(jsonObject.get("code").toString()) == 200){
|
||||
if(jsonObject.containsKey("data") && jsonObject.get("data") != null){
|
||||
JSONArray dataList = (JSONArray)jsonObject.get("data");
|
||||
for (Object object : dataList) {
|
||||
JSONObject item = (JSONObject)object;
|
||||
MaGuangaiRecord record = new MaGuangaiRecord();
|
||||
record.setDevSn(item.get("dev_sn").toString());
|
||||
if(StringUtils.isNotEmpty(item.get("start_time").toString())){
|
||||
Date date = new Date(Long.parseLong(item.get("start_time").toString())*1000);
|
||||
record.setStartTime(date);
|
||||
}
|
||||
if(StringUtils.isNotEmpty(item.get("end_time").toString())){
|
||||
Date date = new Date(Long.parseLong(item.get("end_time").toString())*1000);
|
||||
record.setEndTime(date);
|
||||
}
|
||||
if(StringUtils.isNotEmpty(item.get("last_time").toString())){
|
||||
Date date = new Date(Long.parseLong(item.get("last_time").toString())*1000);
|
||||
record.setLastTime(date);
|
||||
}
|
||||
record.setCurEle(item.get("cur_ele").toString());
|
||||
record.setCardId(item.get("card_id").toString());
|
||||
record.setAreaCode(item.get("area_code").toString());
|
||||
record.setUserBalance(item.get("user_balance").toString());
|
||||
record.setCurFlow(item.get("cur_flow").toString());
|
||||
record.setCurEle(item.get("cur_ele").toString());
|
||||
record.setStatus(Integer.parseInt(item.get("status").toString()));
|
||||
if(StringUtils.isNotEmpty(item.get("create_time").toString())){
|
||||
Date date = new Date(Long.parseLong(item.get("create_time").toString())*1000);
|
||||
record.setCreateTime(date);
|
||||
}
|
||||
list.add(record);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
//
|
||||
PageDomain pageDomain = TableSupport.buildPageRequest();
|
||||
Integer pageNum = pageDomain.getPageNum();
|
||||
Integer pageSize = pageDomain.getPageSize();
|
||||
List<MaGuangaiRecord> subList = new ArrayList<>();
|
||||
if(list.size() > (pageNum-1)*pageSize){
|
||||
if(list.size() < pageNum*pageSize){
|
||||
subList = list.subList((pageNum-1)*pageSize, list.size());
|
||||
}else{
|
||||
subList = list.subList((pageNum-1)*pageSize, pageNum*pageSize);
|
||||
}
|
||||
}
|
||||
TableDataInfo tableDataInfo = new TableDataInfo();
|
||||
tableDataInfo.setMsg("获取成功");
|
||||
tableDataInfo.setTotal(list.size());
|
||||
tableDataInfo.setRows(subList);
|
||||
tableDataInfo.setCode(200);
|
||||
return tableDataInfo;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 新增灌溉记录
|
||||
*
|
||||
|
@ -37,7 +37,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
<if test="curFlow != null and curFlow != ''"> and cur_flow = #{curFlow}</if>
|
||||
<if test="curEle != null and curEle != ''"> and cur_ele = #{curEle}</if>
|
||||
<if test="status != null "> and status = #{status}</if>
|
||||
<if test="params.beginCreateTime != null and params.beginCreateTime != '' and params.endCreateTime != null and params.endCreateTime != ''"> and create_time between #{params.beginCreateTime} and #{params.endCreateTime}</if>
|
||||
<if test="params.beginCreateTime != null and params.beginCreateTime != ''
|
||||
and params.endCreateTime != null and params.endCreateTime != ''"> and create_time between #{params.beginCreateTime} and #{params.endCreateTime}</if>
|
||||
</where>
|
||||
</select>
|
||||
|
||||
|
Reference in New Issue
Block a user