74 lines
2.9 KiB
Plaintext
74 lines
2.9 KiB
Plaintext
|
|
package com.nationalelectric.greenH5;
|
||
|
|
|
||
|
|
import java.util.ArrayList;
|
||
|
|
import java.util.List;
|
||
|
|
import java.util.Map;
|
||
|
|
|
||
|
|
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.bizc.BaseServiceImpl;
|
||
|
|
import com.nationalelectric.greenH5.po.GreenUserInfo;
|
||
|
|
import com.sgcc.uap.persistence.IHibernateDao;
|
||
|
|
|
||
|
|
@Controller
|
||
|
|
@RequestMapping("/newsInfo")
|
||
|
|
public class NewsInfoController extends GreenBaseController {
|
||
|
|
/**
|
||
|
|
* HibernateDao逻辑构件
|
||
|
|
*/
|
||
|
|
@Autowired
|
||
|
|
IHibernateDao hibernateDao;
|
||
|
|
|
||
|
|
@Autowired
|
||
|
|
private BaseServiceImpl baseService;
|
||
|
|
|
||
|
|
/**
|
||
|
|
* 后勤发布查询
|
||
|
|
* @return
|
||
|
|
*/
|
||
|
|
@SuppressWarnings("unchecked")
|
||
|
|
@RequestMapping(value = "/query", method = RequestMethod.POST)
|
||
|
|
public @ResponseBody RestResult query(@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, "非法用户");
|
||
|
|
}
|
||
|
|
//分页
|
||
|
|
Integer pageSize = map.get("pageSize") == null ? 10 : Integer.parseInt(map.get("pageSize").toString());
|
||
|
|
Integer pageNum = map.get("pageNum") == null ? 1 : Integer.parseInt(map.get("pageNum").toString());
|
||
|
|
pageNum = (pageNum-1) * pageSize;
|
||
|
|
|
||
|
|
StringBuffer sql = new StringBuffer();
|
||
|
|
List<Object> params = new ArrayList<Object>();
|
||
|
|
sql.append(" select gn.id, gn.content,gn.choose_person choosePerson,gn.creator,gn.type, gn.`status`, ")
|
||
|
|
.append(" DATE_FORMAT(gn.gmt_created,'%Y-%m-%d %H:%i:%s') gmtCreated, ")
|
||
|
|
.append(" case gn.type when '1' then '通知通告' when '2' then '服务指南' when '3' then '温馨提示' else '' end type, ")
|
||
|
|
.append(" case gn.`status` when 0 then '未发布' when 1 then '已发布' else '' end `status1` ")
|
||
|
|
.append(" from green_hqfb_newsinfo gn where gn.is_deleted = 'N' and gn.`status` = 1 ORDER BY gn.gmt_created desc limit ?,? ");
|
||
|
|
params.add(pageNum);
|
||
|
|
params.add(pageSize);
|
||
|
|
|
||
|
|
List<Map<String,Object>> list = hibernateDao.queryForListWithSql(sql.toString(), params.toArray());
|
||
|
|
//获取图片地址
|
||
|
|
|
||
|
|
return new RestResult(Constant.SUCCESS,"成功", list);
|
||
|
|
} catch (Exception e) {
|
||
|
|
System.out.print(e.getMessage());
|
||
|
|
return new RestResult(Constant.FAILED, "提交失败");
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
}
|