Action类:
package cn.grassinfo.ruianapi.base.action;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import cn.grassinfo.ruianapi.base.domain.TabMinuteData;
import cn.grassinfo.ruianapi.base.service.TabMinuteDataService;
import cn.grassinfo.ruianapi.common.action.MagicAction;
import cn.grassinfo.ruianapi.common.util.BeanMapper;
import jcifs.smb.SmbFile;
import net.sf.jasperreports.engine.type.JsonOperatorEnum;
/**
*
* @description:Keyword action
* @author: autoCode
* @history:
*/
@Controller
@RequestMapping("/base/tabMinuteData")
public class TabMinuteDataAction extends MagicAction<TabMinuteData,TabMinuteDataService> {
/*@Autowired
private TextService textService;*/
/**
* @author xp
* @Title: getTabMinuteDataList
* @Description: TODO 天气实况第一级消息响应
* @param @param request
* @param @param response
* @param @return
* @param @throws Exception
* @return JSONObject
* @throws
* @Date 2017年9月14日 下午8:28:28
*/
@RequestMapping(value = "/getTabMinuteDataList")
@ResponseBody
public JSONObject getTabMinuteDataList(HttpServletRequest request, HttpServletResponse response) throws Exception {
List<TabMinuteData> tabMinuteDataList = entityService.getTabMinuteDataList(getParameterMap(request));
TabMinuteData tam = tabMinuteDataList.get(0);
return BeanMapper.mapJson(tam,TabMinuteData.class);
}
@RequestMapping(value = "/getTabMinuteDryBulTemp24DataList")
@ResponseBody
public JSONObject getTabMinuteDryBulTemp24DataList(HttpServletRequest request, HttpServletResponse response) throws Exception {
List<TabMinuteData> tabMinuteDataList = entityService.getTabMinuteDryBulTemp24DataList(getParameterMap(request));
//TabMinuteData tam = tabMinuteDataList.get(0);
JSONArray a = (JSONArray) JSONObject.parse(JSONObject.toJSONString(tabMinuteDataList));
JSONObject o = new JSONObject();
o.put("rows", a);
return o;
}
}
Service类:
package cn.grassinfo.ruianapi.base.service;
import cn.grassinfo.ruianapi.base.domain.TabMinuteData;
import cn.grassinfo.ruianapi.base.mapper.TabMinuteDataMapper;
import net.ryian.orm.service.BaseService;
import net.ryian.orm.service.support.datasource.annotation.DataSource;
import org.springframework.stereotype.Component;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import java.util.List;
import java.util.Map;
/**
* @description:
* @author: autoCode
* @history:
*/
@Component
@DataSource("weather_ds")//dataSource配有有多数据源链接,该注解指向对应的数据库物理连接配置
public class TabMinuteDataService extends BaseService<TabMinuteData,TabMinuteDataMapper> {
/*@SuppressWarnings({ "unchecked", "rawtypes" })
public PageInfo<List<TabMinuteData>> getKeywordListPaged(Map<String, String> paramMap) {
String rowsStr = paramMap.get("rows") == null ? null : (String) paramMap.get("rows");
String pageStr = paramMap.get("page") == null ? null : (String) paramMap.get("page");
String pagination = paramMap.get("pagination") == null ? "true" : (String) paramMap.get("pagination");//判断是否需要分页
if(!pagination.equals("false"))
{
// 第几页
int page = 1;
// 每页显示数量
int rows = 10;
try {
page = pageStr != null ? Integer.valueOf(pageStr) : page;
rows = rowsStr != null ? Integer.valueOf(rowsStr) : rows;
} catch (Exception e) {
e.printStackTrace();
}
PageHelper.startPage(page, rows);
}
String statement = "getKeywordListPaged";
List<TabMinuteData> list = sqlSession.selectList(statement, paramMap);
return new PageInfo(list);
}*/
/**
* @author xp
* @Title: getTabMinuteDataList
* @Description: TODO 获取数据库最新的天气实况记录LIst
* @param @param paramMap
* @param @return
* @return List<TabMinuteData>
* @throws
* @Date 2017年9月4日 下午8:49:39
*/
public List<TabMinuteData> getTabMinuteDataList(Map<String, String> paramMap) {
String statement = "getTabMinuteDataList";
return sqlSession.selectList(statement, paramMap);
}
/**
* @author xp
* @Title: getTabMinuteDryBulTemp24DataList
* @Description: TODO 查询过去12小时的整点温度
* @param @param paramMap
* @param @return
* @return List<TabMinuteData>
* @throws
* @Date 2017年9月10日 下午3:48:10
*/
public List<TabMinuteData> getTabMinuteDryBulTemp24DataList(Map<String, String> paramMap) {
String statement = "getTabMinuteDryBulTemp24DataList";
return sqlSession.selectList(statement, paramMap);
}
/**
* @author xp
* @Title: getKeywordListByCreaxtor
* @Description: TODO 查询当前微信号下所有的关键字
* @param @param creator
* @param @return
* @return List<Keyword>
* @throws
* @Date 2017年8月2日 下午5:45:40
*/
/*public List<TabMinuteData> getKeywordListByWechatId(Long wechatId) {
Example example = new Example(Keyword.class);
Example.Criteria criteria = example.createCriteria();
criteria.andEqualTo("valid","1");
if (wechatId != null) {
criteria.andEqualTo("wechatId", wechatId);
}
return mapper.selectByExample(example);
}*/
}
mapper下的xml(TabMinuteData.xml)
<?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="cn.grassinfo.ruianapi.base.domain.TabMinuteData">
<resultMap type="cn.grassinfo.ruianapi.base.domain.TabMinuteData" id = "getTabMinuteDataListResultMap">
<result property = "stationNum" column = "StationNum"/><!--property对应domain类里面的属性名,column对应表里面的字段名-->
<result property = "observTimes" column = "ObservTimes"/>
<result property = "windDirect" column = "WindDirect"/>
<result property = "windVelocity" column = "WindVelocity"/>
<result property = "precipitation" column = "Precipitation"/>
<result property = "dryBulTemp" column = "DryBulTemp"/>
<result property = "maxTemp" column = "MaxTemp"/>
<result property = "minTemp" column = "MinTemp"/>
<result property="relHumidity" column="RelHumidity"/>
<result property="stationPress" column="StationPress"/>
<result property="visibility" column="Visibility"/>
</resultMap>
<!--实况天气数据-->
<select id="getTabMinuteDataList" resultMap="getTabMinuteDataListResultMap">
SELECT
t1.StationNum,
t1.ObservTimes,
t1.WindDirect,
t1.WindVelocity,
t1.Precipitation,
t1.DryBulTemp,
t1.MaxTemp,
t1.MinTemp,
t1.RelHumidity,
t1.StationPress,
t1.Visibility
FROM
tabMinuteData t1,
(
SELECT
StationNum,
MAX (ObservTimes) ObservTimes
FROM
tabMinuteData
WHERE
SUBSTRING (ObservTimes, 12, 1) IN ('0', '5')
<![CDATA[and ObservTimes <= #{observTimes}]]>
<if test="stationNum != null and stationNum != '' ">
and StationNum = #{stationNum}
</if>
GROUP BY
StationNum
) t2
WHERE
t1.StationNum = t2.StationNum
AND t1.ObservTimes = t2.ObservTimes
AND t1.DryBulTemp IS NOT NULL
<!-- <if test="userId != null and userId != '' ">
(select DISTINCT srw.wechat_id from sys_r_role_wechat srw where srw.role_id in (select role_id from sys_r_user_role sru where sru.user_id = #{userId}))
</if>
<if test="textName != null and textName != '' ">
AND a.text_name LIKE CONCAT(CONCAT('%', #{textName}),'%')
</if> -->
</select>
<!--过去24小时气温、风力风向、降水数据-->
<select id="getTabMinute12HDataList" resultMap="getTabMinuteDataListResultMap">
SELECT
DryBulTemp,
WindDirect,
WindVelocity,
Precipitation,
ObservTimes
FROM
tabMinuteData,
(
SELECT
MAX (ObservTimes) AS aa
FROM
tabMinuteData
WHERE
StationNum = '58752'
) h
WHERE
CAST (
SUBSTRING (ObservTimes, 1, 4) + '-' + SUBSTRING (ObservTimes, 5, 2) + '-' + SUBSTRING (ObservTimes, 7, 2) + ' ' + SUBSTRING (ObservTimes, 9, 2) + ':' + SUBSTRING (ObservTimes, 11, 2) AS datetime
) >= DATEADD(
HOUR,
- 24,
CAST (
SUBSTRING (h.aa, 1, 4) + '-' + SUBSTRING (h.aa, 5, 2) + '-' + SUBSTRING (h.aa, 7, 2) + ' ' + SUBSTRING (h.aa, 9, 2) + ':' + SUBSTRING (h.aa, 11, 2) AS datetime
)
)
AND SUBSTRING (ObservTimes, 11, 2) = '00'
AND StationNum = '58752'
<!-- <if test="userId != null and userId != '' ">
(select DISTINCT srw.wechat_id from sys_r_role_wechat srw where srw.role_id in (select role_id from sys_r_user_role sru where sru.user_id = #{userId}))
</if>
<if test="textName != null and textName != '' ">
AND a.text_name LIKE CONCAT(CONCAT('%', #{textName}),'%')
</if> -->
</select>
</mapper>