hz-zhhq-app-service/greenH5modul/.svn/pristine/1c/1c84f2159a60fd320176616c008...

68 lines
2.3 KiB
Plaintext

package com.nationalelectric.greenH5;
import java.sql.Timestamp;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import org.codehaus.jackson.map.ObjectMapper;
import org.codehaus.jackson.type.TypeReference;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import com.nationalelectirc.Constant.Constant;
import com.nationalelectirc.utils.RestResult;
import com.nationalelectric.greenH5.po.GreenFoodFeature;
import com.nationalelectric.greenH5.po.GreenUserInfo;
import com.sgcc.uap.persistence.IHibernateDao;
/**
* 首页数据查询
* @author Administrator
*
*/
@Controller
@RequestMapping("/home")
public class HomeController extends GreenBaseController{
/**
* HibernateDao逻辑构件
*/
@Autowired
IHibernateDao hibernateDao;
/**
* 查询首页数据
* @return
*/
@SuppressWarnings("unchecked")
@RequestMapping(value = "/info", method = RequestMethod.POST)
public @ResponseBody RestResult info(@RequestBody Object requestBody) {
try {
Map<String, Object> map = new ObjectMapper().convertValue(requestBody, new TypeReference<Map<String, Object>>(){});
String userId = map.get("userId") == null || "".equals(map.get("userId")) ? null : map.get("userId").toString();
GreenUserInfo info = getUserInfo(userId);
if (info == null) {
return new RestResult(Constant.FAILED, "非法用户");
}
StringBuffer sql = new StringBuffer();
sql.append("SELECT * FROM( select id as \"id\",title as \"title\", create_time as \"create_time\" from green_health_msg where is_del='1' and info_type='1' order by create_time desc) WHERE ROWNUM <=4");
//union ALL
//(select title from green_health_msg where is_del='1' and info_type='0' order by create_time desc LIMIT 2)
List<Map<String,Object>> list = hibernateDao.queryForListWithSql(sql.toString());
return new RestResult(Constant.SUCCESS, list);
} catch (Exception e) {
System.out.print(e.getMessage());
return new RestResult(Constant.FAILED, "提交失败");
}
}
}