111 lines
3.8 KiB
Plaintext
111 lines
3.8 KiB
Plaintext
package com.nationalelectric.greenH5;
|
||
|
||
import java.util.List;
|
||
import java.util.Map;
|
||
|
||
import javax.annotation.Resource;
|
||
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.nationalelectirc.Constant.Constant;
|
||
import com.nationalelectirc.utils.RestResult;
|
||
import com.nationalelectric.greenH5.po.GreenUserInfo;
|
||
import com.sgcc.uap.persistence.IHibernateDao;
|
||
|
||
|
||
|
||
|
||
|
||
/**
|
||
* <b>概述</b>:<br>
|
||
* <p>
|
||
* <b>功能</b>:<br>
|
||
*
|
||
* @author dell
|
||
*/
|
||
@Controller
|
||
@RequestMapping("/greenNotice")
|
||
public class GreenNoticeController extends GreenBaseController {
|
||
/**
|
||
* 用户controller
|
||
*/
|
||
@Resource
|
||
private GreenUserInfoController greenUserInfoController;
|
||
|
||
/**
|
||
* HibernateDao逻辑构件
|
||
*/
|
||
@Autowired
|
||
IHibernateDao hibernateDao;
|
||
|
||
|
||
@RequestMapping(value = "/getMyNoticeList")
|
||
@ResponseBody
|
||
public RestResult getMyNoticeList(Map<String,Object> map) {
|
||
try {
|
||
String userId = map.get("userId").toString();
|
||
Integer pageNum = (Integer)map.get("pageNum");
|
||
Integer pageSize = (Integer)map.get("pageSize");
|
||
|
||
GreenUserInfo userInfo = getUserInfo(userId);
|
||
if (userInfo == null) {
|
||
return new RestResult(Constant.FAILED, "非法用户");
|
||
}
|
||
int limit = ((pageNum > 0 ? pageNum : 1) - 1) * pageSize;
|
||
pageSize = pageSize*pageNum;
|
||
|
||
String sql = "select * from (select rn.*,rownum rw from ( "
|
||
+ "SELECT id AS \"id\",title AS \"title\",text AS \"text\",url AS \"url\",user_id AS \"user_id\",read_status AS \"read_status\",read_time AS \"read_time\","
|
||
+ "delayed_status AS \"delayed_status\",delayed_time AS \"delayed_time\",create_time AS \"create_time\",create_by AS \"create_by\",is_deleted AS \"is_deleted\" from green_notice WHERE is_deleted='N' and user_id = ? ORDER BY create_time DESC"
|
||
+ ") rn )where rw>? and rw<=? ";//read_status ,
|
||
List<Map<String, Object>> list = hibernateDao.queryForListWithSql(sql, new Object[] { userId, limit, pageSize });
|
||
return new RestResult(Constant.SUCCESS, list);
|
||
} catch (Exception e) {
|
||
e.printStackTrace();
|
||
return new RestResult(Constant.FAILED, "查询失败");
|
||
}
|
||
}
|
||
@RequestMapping(value = "/updateNoticeRead")
|
||
@ResponseBody
|
||
public RestResult updateNoticeRead(Map<String,Object> map) {
|
||
try {
|
||
String id = map.get("id").toString();
|
||
String sql = "update green_notice set read_status=1 where id = ?";
|
||
hibernateDao.executeSqlUpdate(sql, new Object[] { id});
|
||
return new RestResult(Constant.SUCCESS, "已读");
|
||
} catch (Exception e) {
|
||
e.printStackTrace();
|
||
return new RestResult(Constant.FAILED, "查询失败");
|
||
}
|
||
}
|
||
|
||
@RequestMapping(value = "/getUnReadNum")
|
||
@ResponseBody
|
||
public RestResult getUnReadNum(Map<String,Object> map) {
|
||
try {
|
||
String userId = map.get("userId").toString();
|
||
String sql = " SELECT count(*) from green_notice WHERE is_deleted='N' and user_id =(select id from green_user_info where isc_id = ?) and read_status=0";
|
||
Integer unReadNum = hibernateDao.queryForIntWithSql(sql, new Object[] { userId });
|
||
return new RestResult(Constant.SUCCESS, unReadNum);
|
||
} catch (Exception e) {
|
||
e.printStackTrace();
|
||
return new RestResult(Constant.FAILED, "查询失败");
|
||
}
|
||
}
|
||
@RequestMapping(value = "/clearNoticeData")
|
||
@ResponseBody
|
||
public RestResult clearNoticeData(Map<String,Object> map) {
|
||
try {
|
||
String userId = map.get("userId").toString();
|
||
String sql = "update green_notice set read_status=1 WHERE is_deleted='N' and user_id = ? and read_status=0 ";
|
||
hibernateDao.executeSqlUpdate(sql, new Object[] {userId});
|
||
return new RestResult(Constant.SUCCESS, "成功");
|
||
} catch (Exception e) {
|
||
e.printStackTrace();
|
||
return new RestResult(Constant.FAILED, "失败");
|
||
}
|
||
}
|
||
}
|