package com.cweb.controller; import com.github.pagehelper.PageHelper; import com.github.pagehelper.PageInfo; import com.hai.common.exception.ErrorCode; import com.hai.common.exception.ErrorHelp; import com.hai.common.exception.SysCode; import com.hai.common.security.SessionObject; import com.hai.common.security.UserCenter; import com.hai.common.utils.ResponseMsgUtil; import com.hai.entity.BsMsg; import com.hai.model.HighUserModel; import com.hai.model.ResponseData; import com.hai.model.UserInfoModel; import com.hai.service.BsMsgService; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.*; import javax.annotation.Resource; import javax.servlet.http.HttpServletRequest; import java.util.Date; import java.util.HashMap; import java.util.List; import java.util.Map; /** * @author sum1dream */ @Controller @RequestMapping(value = "/bsMsg") @Api(value = "站内信") public class BsMsgController { Logger log = LoggerFactory.getLogger(BsMsgController.class); @Resource private BsMsgService bsMsgService; @Autowired private UserCenter userCenter; @RequestMapping(value = "/getMsgByList", method = RequestMethod.GET) @ResponseBody @ApiOperation(value = "查询站内信列表") public ResponseData getMsgByList( @RequestParam(value = "type", required = false) Integer type, @RequestParam(value = "jumpType", required = false) Integer jumpType, @RequestParam(value = "msgType", required = false) Integer msgType, @RequestParam(value = "title", required = false) String title, @RequestParam(value = "companyId", required = true) String companyId, @RequestParam(name = "pageNum", required = true) Integer pageNum, @RequestParam(name = "pageSize", required = true) Integer pageSize, HttpServletRequest request ) { try { SessionObject sessionObject = userCenter.getSessionObject(request); HighUserModel userInfoModel = (HighUserModel) sessionObject.getObject(); Map map = new HashMap<>(5); map.put("type", type); map.put("jumpType", jumpType); map.put("msgType", msgType); map.put("title", title); map.put("companyId" , companyId); PageHelper.startPage(pageNum,pageSize); List list = bsMsgService.getMsgByList(map); return ResponseMsgUtil.success(new PageInfo<>(list)); } catch (Exception e) { log.error("BsMsgController --> getMsgByList() error!", e); return ResponseMsgUtil.exception(e); } } @RequestMapping(value = "/checkMsg", method = RequestMethod.GET) @ResponseBody @ApiOperation(value = "查看站内信") public ResponseData checkMsg(@RequestParam(value = "msgId", required = false) Long msgId, HttpServletRequest request) { try { // 用户 SessionObject sessionObject = userCenter.getSessionObject(request); HighUserModel userInfoModel = (HighUserModel) sessionObject.getObject(); bsMsgService.checkMsg(userInfoModel.getHighUser(), msgId); return ResponseMsgUtil.success(null); } catch (Exception e) { log.error("HighOrderController -> addOrder() error!", e); return ResponseMsgUtil.exception(e); } } @RequestMapping(value = "/queryMsgByList", method = RequestMethod.GET) @ResponseBody @ApiOperation(value = "查询站内信列表") public ResponseData queryMsgByList( @RequestParam(value = "companyId", required = false) Long companyId, @RequestParam(value = "type", required = false) Long type, HttpServletRequest request) { try { // 用户 SessionObject sessionObject = userCenter.getSessionObject(request); HighUserModel userInfoModel = (HighUserModel) sessionObject.getObject(); Map mapUser = new HashMap<>(); mapUser.put("companyId" , companyId); mapUser.put("type" , type); mapUser.put("userId" , userInfoModel.getHighUser().getId()); mapUser.put("msgType" , 1); // 查询个人站内信 List userMsg = bsMsgService.queryMsgByList(mapUser); // 查询全局站内信 Map map = new HashMap<>(); map.put("companyId" , companyId); map.put("type" , type); map.put("msgType" , 2); // 查询个人站内信 List msgList = bsMsgService.queryMsgByList(map); msgList.addAll(userMsg); return ResponseMsgUtil.success(msgList); } catch (Exception e) { log.error("HighOrderController -> addOrder() error!", e); return ResponseMsgUtil.exception(e); } } }