| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132 |
- package com.goafanti.app.controller;
- import java.lang.reflect.InvocationTargetException;
- import javax.servlet.http.HttpServletRequest;
- import org.apache.commons.lang3.StringUtils;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.web.bind.annotation.RequestMapping;
- import org.springframework.web.bind.annotation.RequestMethod;
- import org.springframework.web.bind.annotation.RestController;
- import com.goafanti.common.bo.Result;
- import com.goafanti.common.constant.AFTConstants;
- import com.goafanti.common.constant.ErrorConstants;
- import com.goafanti.common.controller.BaseApiController;
- import com.goafanti.common.model.MessageFromSystem;
- import com.goafanti.common.model.User;
- import com.goafanti.common.utils.DateUtils;
- import com.goafanti.core.shiro.token.TokenManager;
- import com.goafanti.message.bo.MessageListBo;
- import com.goafanti.message.service.MessageService;
- import com.goafanti.user.service.UserService;
- @RestController
- @RequestMapping(path = "/api/user/app", method = RequestMethod.GET)
- public class AppApiController extends BaseApiController {
- @Autowired
- private UserService userServiceImpl;
- @Autowired
- private MessageService messageServiceImpl;
-
- @RequestMapping(value = "/uploadImg",method = RequestMethod.POST)
- public Result uploadAvatar(HttpServletRequest req){
- Result res = new Result();
- String headPortraitUrl = handleFile(res, "/avatar/", false, req, "");
- if(TokenManager.getToken() instanceof User){
- User u = (User)TokenManager.getToken();
- u.setHeadPortraitUrl(headPortraitUrl);
- userServiceImpl.updateByPrimaryKeySelective(u);
- }
- res.setData(headPortraitUrl);
- return res;
- }
- @RequestMapping(value = "/updateUser",method = RequestMethod.POST)
- public Result updateUser(User u){
- Result res = new Result();
- if(null != u){
- u.setId(TokenManager.getUserId());
- userServiceImpl.updateByPrimaryKeySelective(u);
- }else{
- res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR));
- }
- return res;
- }
-
- @RequestMapping(value = "/logout",method = RequestMethod.GET)
- public Result logout(HttpServletRequest request){
- Result res = new Result();
- TokenManager.logout();
- return res;
- }
-
- @RequestMapping(value = "/userInfo",method = RequestMethod.GET)
- public Result userInfo(HttpServletRequest request){
- Result res = new Result();
- res.setData(userServiceImpl.selectBaseInfo());
- return res;
- }
-
- @RequestMapping(value = "/index", method = RequestMethod.GET)
- public Result index(){
- Result res = new Result();
- res.setData(messageServiceImpl.selectMessageWithGroup());
- return res;
- }
-
- @RequestMapping(value = "/listMessage", method = RequestMethod.POST)
- public Result listMessage(Integer subject,Integer sourceType,Integer pageNo,Integer pageSize){
- Result res = new Result();
- if(null == subject){
- res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "必须指定消息类型"));
- return res;
- }
- res.setData(messageServiceImpl.listPersonalMessage(subject,sourceType,pageNo,pageSize));
- return res;
- }
-
- /**
- * 同步绑定账号
- * @param uuid
- * @param registrationId
- * @param userName
- */
- @RequestMapping(value = "/synBindingAccount",method = RequestMethod.POST)
- private Result synBindingAccount(String uuid,String registrationId,String easemobName,String easemobPass){
- Result res = new Result();
- //更新 jpush_easemob_account
- messageServiceImpl.updateJpushEasemobAccount(uuid, registrationId, easemobName,easemobPass);
- return res;
- }
-
- /**
- * 读取消息
- * @param messageId
- * @throws IllegalAccessException
- * @throws InvocationTargetException
- */
- @RequestMapping(value = "/readMessage",method = RequestMethod.GET)
- private Result readMessage(String messageId){
- Result res = new Result();
- if(StringUtils.isBlank(messageId)){
- res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "消息编号为空"));
- return res;
- }
- //读取消息详情
- MessageFromSystem mfs = messageServiceImpl.selectSystemMessageDetail(messageId);
- MessageListBo bo = new MessageListBo();
- bo.setCreateTime(bo.getCreateTime()==null?"":DateUtils.formatDate(mfs.getCreateTime(), AFTConstants.YYYYMMDDHHMMSS));
- bo.setResourceType(String.valueOf(mfs.getResourceType()));
- bo.setSubject(String.valueOf(mfs.getSubject()));
- bo.setMessageId(mfs.getId());
- bo.setTitle(mfs.getTitle());
- bo.setBody(mfs.getBody());
- res.setData(bo);
- //更新 message_consumer
- messageServiceImpl.updateMessageConsumer(messageId);
- return res;
- }
- }
|